Добавлена возможность выключения перехвата пакетов
This commit is contained in:
@@ -54,6 +54,6 @@ public class ApplicationConfiguration extends WebSecurityConfigurerAdapter imple
|
||||
|
||||
@Override
|
||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||
registry.addHandler(webSocketHandler, "/ws").withSockJS();
|
||||
registry.addHandler(webSocketHandler, "/api/ws").withSockJS();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ru.serega6531.packmate;
|
||||
|
||||
import org.pcap4j.core.PcapNativeException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
@@ -11,14 +12,19 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
@EnableScheduling
|
||||
public class PackmateApplication {
|
||||
|
||||
@Value("${enable-capture}")
|
||||
private boolean enableCapture;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(PackmateApplication.class, args);
|
||||
}
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void afterStartup(ApplicationReadyEvent event) throws PcapNativeException {
|
||||
final PcapWorker pcapWorker = event.getApplicationContext().getBean(PcapWorker.class);
|
||||
pcapWorker.start();
|
||||
if(enableCapture) {
|
||||
final PcapWorker pcapWorker = event.getApplicationContext().getBean(PcapWorker.class);
|
||||
pcapWorker.start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.serega6531.packmate.model.CtfService;
|
||||
import ru.serega6531.packmate.model.Protocol;
|
||||
import ru.serega6531.packmate.model.UnfinishedStream;
|
||||
import ru.serega6531.packmate.service.ServicesService;
|
||||
import ru.serega6531.packmate.service.StreamService;
|
||||
|
||||
@@ -16,7 +16,7 @@ public class UdpStreamsSaver {
|
||||
this.pcapWorker = pcapWorker;
|
||||
}
|
||||
|
||||
@Scheduled(fixedRateString = "PT${udp-stream-check-interval}S")
|
||||
@Scheduled(fixedRateString = "PT${udp-stream-check-interval}S", initialDelayString = "PT${udp-stream-check-interval}S")
|
||||
public void saveStreams() {
|
||||
final int streamsClosed = pcapWorker.closeUdpStreams();
|
||||
if(streamsClosed > 0) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package ru.serega6531.packmate;
|
||||
package ru.serega6531.packmate.model;
|
||||
|
||||
public enum Protocol {
|
||||
TCP, UDP
|
||||
@@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import ru.serega6531.packmate.Protocol;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
|
||||
@@ -2,7 +2,6 @@ package ru.serega6531.packmate.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import ru.serega6531.packmate.Protocol;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ public class ServicesService {
|
||||
}
|
||||
|
||||
public void deleteByPort(int port) {
|
||||
log.info("Удален сервис на порту {}", port);
|
||||
repository.deleteById(port);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.serega6531.packmate.model.Packet;
|
||||
import ru.serega6531.packmate.model.Pattern;
|
||||
import ru.serega6531.packmate.model.Stream;
|
||||
import ru.serega6531.packmate.model.UnfinishedStream;
|
||||
import ru.serega6531.packmate.model.*;
|
||||
import ru.serega6531.packmate.repository.StreamRepository;
|
||||
|
||||
import java.util.*;
|
||||
@@ -42,17 +39,25 @@ public class StreamService {
|
||||
|
||||
@Transactional
|
||||
public void saveNewStream(UnfinishedStream unfinishedStream, List<Packet> packets) {
|
||||
Stream stream = new Stream();
|
||||
stream.setProtocol(unfinishedStream.getProtocol());
|
||||
stream.setStartTimestamp(packets.get(0).getTimestamp());
|
||||
stream.setEndTimestamp(packets.get(packets.size() - 1).getTimestamp());
|
||||
stream.setService(servicesService.findService(
|
||||
final Optional<CtfService> serviceOptional = servicesService.findService(
|
||||
localIp,
|
||||
unfinishedStream.getFirstIp().getHostAddress(),
|
||||
unfinishedStream.getFirstPort(),
|
||||
unfinishedStream.getSecondIp().getHostAddress(),
|
||||
unfinishedStream.getSecondPort()
|
||||
).get());
|
||||
);
|
||||
|
||||
if (!serviceOptional.isPresent()) {
|
||||
log.info("Не удалось сохранить стрим: сервиса на порту {} или {} не существует",
|
||||
unfinishedStream.getFirstPort(), unfinishedStream.getSecondPort());
|
||||
return;
|
||||
}
|
||||
|
||||
Stream stream = new Stream();
|
||||
stream.setProtocol(unfinishedStream.getProtocol());
|
||||
stream.setStartTimestamp(packets.get(0).getTimestamp());
|
||||
stream.setEndTimestamp(packets.get(packets.size() - 1).getTimestamp());
|
||||
stream.setService(serviceOptional.get());
|
||||
|
||||
Stream savedStream = save(stream);
|
||||
|
||||
@@ -74,7 +79,7 @@ public class StreamService {
|
||||
|
||||
public Stream save(Stream stream) {
|
||||
Stream saved;
|
||||
if(stream.getId() == null) {
|
||||
if (stream.getId() == null) {
|
||||
saved = repository.save(stream);
|
||||
log.info("Создан стрим с id {}", saved.getId());
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user