Добавлен эндпоинт для запуска pcap
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
src/main/resources/static/*
|
src/main/resources/static/*
|
||||||
|
*.pcap
|
||||||
|
|
||||||
HELP.md
|
HELP.md
|
||||||
.gradle
|
.gradle
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ services:
|
|||||||
DB_NAME: ${PACKMATE_DB_NAME:-packmate}
|
DB_NAME: ${PACKMATE_DB_NAME:-packmate}
|
||||||
INTERFACE: ${PACKMATE_INTERFACE}
|
INTERFACE: ${PACKMATE_INTERFACE}
|
||||||
LOCAL_IP: ${PACKMATE_LOCAL_IP}
|
LOCAL_IP: ${PACKMATE_LOCAL_IP}
|
||||||
|
MODE: ${PACKMATE_MODE:-LIVE}
|
||||||
|
PCAP_FILE: ${PACKMATE_PCAP_FILE}
|
||||||
WEB_LOGIN: ${PACKMATE_WEB_LOGIN:-BinaryBears}
|
WEB_LOGIN: ${PACKMATE_WEB_LOGIN:-BinaryBears}
|
||||||
WEB_PASSWORD: ${PACKMATE_WEB_PASSWORD:-123456}
|
WEB_PASSWORD: ${PACKMATE_WEB_PASSWORD:-123456}
|
||||||
env_file:
|
env_file:
|
||||||
@@ -21,6 +23,7 @@ services:
|
|||||||
"java", "-Djava.net.preferIPv4Stack=true", "-Djava.net.preferIPv4Addresses=true",
|
"java", "-Djava.net.preferIPv4Stack=true", "-Djava.net.preferIPv4Addresses=true",
|
||||||
"-jar", "/app/app.jar", "--spring.datasource.url=jdbc:postgresql://127.0.0.1:65001/$${DB_NAME}",
|
"-jar", "/app/app.jar", "--spring.datasource.url=jdbc:postgresql://127.0.0.1:65001/$${DB_NAME}",
|
||||||
"--spring.datasource.username=$${DB_USER}", "--spring.datasource.password=$${DB_PASSWORD}",
|
"--spring.datasource.username=$${DB_USER}", "--spring.datasource.password=$${DB_PASSWORD}",
|
||||||
|
"--capture-mode=$${MODE}", "--pcap-file=$${PCAP_FILE}",
|
||||||
"--interface-name=$${INTERFACE}", "--local-ip=$${LOCAL_IP}", "--account-login=$${WEB_LOGIN}",
|
"--interface-name=$${INTERFACE}", "--local-ip=$${LOCAL_IP}", "--account-login=$${WEB_LOGIN}",
|
||||||
"--account-password=$${WEB_PASSWORD}", "--server.port=65000", "--server.address=0.0.0.0"
|
"--account-password=$${WEB_PASSWORD}", "--server.port=65000", "--server.address=0.0.0.0"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ import org.springframework.boot.SpringApplication;
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import ru.serega6531.packmate.pcap.PcapWorker;
|
import ru.serega6531.packmate.model.enums.CaptureMode;
|
||||||
|
import ru.serega6531.packmate.service.PcapService;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class PackmateApplication {
|
public class PackmateApplication {
|
||||||
@@ -14,15 +15,18 @@ public class PackmateApplication {
|
|||||||
@Value("${enable-capture}")
|
@Value("${enable-capture}")
|
||||||
private boolean enableCapture;
|
private boolean enableCapture;
|
||||||
|
|
||||||
|
@Value("${capture-mode}")
|
||||||
|
private CaptureMode captureMode;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(PackmateApplication.class, args);
|
SpringApplication.run(PackmateApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventListener(ApplicationReadyEvent.class)
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
public void afterStartup(ApplicationReadyEvent event) throws PcapNativeException {
|
public void afterStartup(ApplicationReadyEvent event) throws PcapNativeException {
|
||||||
if (enableCapture) {
|
if (enableCapture && captureMode == CaptureMode.LIVE) {
|
||||||
final PcapWorker pcapWorker = event.getApplicationContext().getBean(PcapWorker.class);
|
final PcapService pcapService = event.getApplicationContext().getBean(PcapService.class);
|
||||||
pcapWorker.start();
|
pcapService.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package ru.serega6531.packmate;
|
package ru.serega6531.packmate.configuration;
|
||||||
|
|
||||||
import org.pcap4j.core.PcapNativeException;
|
import org.pcap4j.core.PcapNativeException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -15,6 +15,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
|||||||
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
||||||
|
import ru.serega6531.packmate.WebSocketHandler;
|
||||||
import ru.serega6531.packmate.model.enums.CaptureMode;
|
import ru.serega6531.packmate.model.enums.CaptureMode;
|
||||||
import ru.serega6531.packmate.pcap.FilePcapWorker;
|
import ru.serega6531.packmate.pcap.FilePcapWorker;
|
||||||
import ru.serega6531.packmate.pcap.LivePcapWorker;
|
import ru.serega6531.packmate.pcap.LivePcapWorker;
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package ru.serega6531.packmate.controller;
|
||||||
|
|
||||||
|
import org.pcap4j.core.PcapNativeException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import ru.serega6531.packmate.service.PcapService;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/pcap/")
|
||||||
|
public class PcapController {
|
||||||
|
|
||||||
|
private final PcapService service;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public PcapController(PcapService service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/started")
|
||||||
|
public boolean started() {
|
||||||
|
return service.isStarted();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRunning() {
|
||||||
|
return true; //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/start")
|
||||||
|
public void start() throws PcapNativeException {
|
||||||
|
service.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -42,6 +42,7 @@ public class FilePcapWorker extends AbstractPcapWorker {
|
|||||||
log.error("Pcap read", e);
|
log.error("Pcap read", e);
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
} catch (EOFException e) {
|
} catch (EOFException e) {
|
||||||
|
log.info("All packets processed");
|
||||||
stop();
|
stop();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -54,6 +55,7 @@ public class FilePcapWorker extends AbstractPcapWorker {
|
|||||||
pcap.close();
|
pcap.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("Intercept stopped");
|
//TODO закрывать все стримы
|
||||||
|
log.info("Pcap closed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package ru.serega6531.packmate.service;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.pcap4j.core.PcapNativeException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.serega6531.packmate.pcap.PcapWorker;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PcapService {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private boolean started = false;
|
||||||
|
|
||||||
|
private final PcapWorker worker;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public PcapService(PcapWorker worker) {
|
||||||
|
this.worker = worker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void start() throws PcapNativeException {
|
||||||
|
if(!started) {
|
||||||
|
started = true;
|
||||||
|
worker.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ spring:
|
|||||||
enable-capture: true
|
enable-capture: true
|
||||||
capture-mode: LIVE # LIVE, FILE
|
capture-mode: LIVE # LIVE, FILE
|
||||||
interface-name: enp0s31f6
|
interface-name: enp0s31f6
|
||||||
|
pcap-file: file.pcap
|
||||||
local-ip: "192.168.0.125"
|
local-ip: "192.168.0.125"
|
||||||
account-login: BinaryBears
|
account-login: BinaryBears
|
||||||
account-password: 123456
|
account-password: 123456
|
||||||
|
|||||||
Reference in New Issue
Block a user