added discovery result after

This commit is contained in:
snoop 2017-08-22 19:24:34 +09:00
parent 586539bc31
commit 472da00b42
2 changed files with 132 additions and 94 deletions

View File

@ -59,12 +59,18 @@ public class MetaInfraVendor {
MetaInfraVendor vendor = new MetaInfraVendor(); MetaInfraVendor vendor = new MetaInfraVendor();
if(osName == null || osName.length() <= 0) {
vendor.setId(28); // FIXME: Unknown
return vendor;
}
if(osName.equals("Windows")) { if(osName.equals("Windows")) {
vendor.setId(25); vendor.setId(26);
} }
else if(osName.equals("Linux")) { else if(osName.equals("Linux")) {
vendor.setId(27); // ubuntu vendor.setId(28); // ubuntu
} else {
vendor.setId(28); // FIXME: Unknown
} }
return vendor; return vendor;

View File

@ -5,6 +5,9 @@ import com.loafle.overflow.module.discovery.model.Port;
import com.loafle.overflow.module.discovery.type.PortType; import com.loafle.overflow.module.discovery.type.PortType;
import com.loafle.overflow.module.infra.dao.*; import com.loafle.overflow.module.infra.dao.*;
import com.loafle.overflow.module.infra.model.*; import com.loafle.overflow.module.infra.model.*;
import com.loafle.overflow.module.infra.model.InfraService;
import com.loafle.overflow.module.infra.service.*;
import com.loafle.overflow.module.meta.model.MetaInfraType;
import com.loafle.overflow.module.meta.model.MetaInfraVendor; import com.loafle.overflow.module.meta.model.MetaInfraVendor;
import com.loafle.overflow.module.probe.model.Probe; import com.loafle.overflow.module.probe.model.Probe;
import com.loafle.overflow.module.target.dao.TargetDAO; import com.loafle.overflow.module.target.dao.TargetDAO;
@ -22,121 +25,150 @@ import java.util.List;
public class TargetDiscoveryService { public class TargetDiscoveryService {
@Autowired @Autowired
private TargetDAO targetDAO; private TargetService targetService;
@Autowired @Autowired
private InfraMachineDAO infraMachineDAO; private InfraMachineService infraMachineService;
@Autowired @Autowired
private InfraOSDAO infraOSDAO; private InfraOSService infraOSService;
@Autowired @Autowired
private InfraHostDAO infraHostDAO; private InfraHostService infraHostService;
@Autowired @Autowired
private InfraDAO infraDAO; private com.loafle.overflow.module.infra.service.InfraService infraService;
@Autowired @Autowired
private InfraOSPortDAO infraOSPortDAO; private InfraOSPortService infraOSPortService;
@Autowired @Autowired
private InfraServiceDAO infraServiceDAO; private InfraServiceService infraServiceService;
@Transactional
public void saveAllTarget(List<Host> hosts, Probe probe) {
MetaInfraType typeMachine = new MetaInfraType();
typeMachine.setId(1); // 1 = Machine;
MetaInfraType typeOS = new MetaInfraType();
typeOS.setId(3); // 3 = Os
MetaInfraType typeHost = new MetaInfraType();
typeHost.setId(2); // 2 = Host
MetaInfraType typePort = new MetaInfraType();
typePort.setId(6);
MetaInfraType typeService = new MetaInfraType();
typeService.setId(7);
for(Host host : hosts) {
InfraMachine infraMachine = new InfraMachine();
infraMachine.setProbe(probe);
infraMachine.setInfraType(typeMachine);
this.infraMachineService.regist(infraMachine);
InfraOS infraOS = new InfraOS();
infraOS.setMachine(infraMachine);
infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
infraOS.setInfraType(typeOS);
infraOS.setProbe(probe);
this.infraOSService.regist(infraOS);
InfraHost infraHost = new InfraHost();
infraHost.setIp(host.getIp());
infraHost.setMac(host.getMac());
infraHost.setOs(infraOS);
infraHost.setInfraType(typeHost);
infraHost.setProbe(probe);
if(host.isTarget()) {
Target target = new Target();
target.setDisplayName(String.valueOf(host.getIp()) + "-Host");
this.targetService.regist(target);
infraHost.setTarget(target);
}
this.infraHostService.regist(infraHost);
// @Transactional
// public void saveAllTarget(List<Host> hosts, Probe probe) {
//
// for(Host host : hosts) {
//
// InfraMachine infraMachine = new InfraMachine();
//// infraMachine.setProbe(probe);
// this.infraMachineDAO.save(infraMachine);
//
// Infra infraByMachine = Infra.CreateInfraByType(infraMachine.getId(), InfraMachine.class);
// this.infraDAO.save(infraByMachine);
//
//
// InfraOS infraOS = new InfraOS();
//// infraOS.setMachine(infraMachine);
//// infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
// this.infraOSDAO.save(infraOS);
//
// Infra infraByOS = Infra.CreateInfraByType(infraOS.getId(), InfraOS.class);
// this.infraDAO.save(infraByOS);
//
//
// InfraHost infraHost = new InfraHost();
// infraHost.setIp(host.getIp());
// infraHost.setMac(host.getMac());
//// infraHost.setOs(infraOS);
// this.infraHostDAO.save(infraHost);
//
// Infra infraByHost = Infra.CreateInfraByType(infraHost.getId(), InfraHost.class); // Infra infraByHost = Infra.CreateInfraByType(infraHost.getId(), InfraHost.class);
// this.infraDAO.save(infraByHost); // this.infraDAO.save(infraByHost);
//
// if(host.isTarget()) { // if(host.isTarget()) {
// Target targetHost = new Target(); // Target targetHost = new Target();
//// targetHost.setInfra(infraByHost); //// targetHost.setInfra(infraByHost);
//// targetHost.setProbe(probe); //// targetHost.setProbe(probe);
// this.targetDAO.save(targetHost); // this.targetDAO.save(targetHost);
// } // }
//
// if(host.getPorts() == null) { if(host.getPorts() == null) {
// continue; continue;
// } }
//
// for(Port port : host.getPorts()) { for(Port port : host.getPorts()) {
//
// InfraOSPort infraOSPort = new InfraOSPort(); InfraOSPort infraOSPort = new InfraOSPort();
// infraOSPort.setOs(infraOS); infraOSPort.setOs(infraOS);
// infraOSPort.setPort(port.getPortNumber()); infraOSPort.setPort(port.getPortNumber());
// infraOSPort.setPortType("UDP"); infraOSPort.setPortType("UDP");
// if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { infraOSPort.setProbe(probe);
// infraOSPort.setPortType("TCP"); infraOSPort.setInfraType(typePort);
// } if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) {
// if (port.getPortType() == PortType.TLS) { infraOSPort.setPortType("TCP");
// infraOSPort.setTlsType(true); }
// } if (port.getPortType() == PortType.TLS) {
// infraOSPort.setVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber())); infraOSPort.setTlsType(true);
// this.infraOSPortDAO.save(infraOSPort); }
// infraOSPort.setVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber()));
this.infraOSPortService.regist(infraOSPort);
// Infra infraByPort = Infra.CreateInfraByType(infraOSPort.getId(), InfraOSPort.class); // Infra infraByPort = Infra.CreateInfraByType(infraOSPort.getId(), InfraOSPort.class);
// this.infraDAO.save(infraByPort); // this.infraDAO.save(infraByPort);
//
// if(port.getServices() == null) { if(port.getServices() == null) {
// continue; continue;
// } }
//
// for(com.loafle.overflow.module.discovery.model.Service service : port.getServices()) { for(com.loafle.overflow.module.discovery.model.Service service : port.getServices()) {
//
// InfraService infraService = new InfraService(); InfraService infraService = new InfraService();
// infraService.setHost(infraHost); infraService.setHost(infraHost);
// infraService.setPort(port.getPortNumber()); infraService.setPort(port.getPortNumber());
// infraService.setPortType("UDP"); infraService.setPortType("UDP");
// if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { infraService.setInfraType(typeService);
// infraService.setPortType("TCP"); infraService.setProbe(probe);
// } if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) {
// if (port.getPortType() == PortType.TLS) { infraService.setPortType("TCP");
// infraService.setTlsType(true); }
// } if (port.getPortType() == PortType.TLS) {
// infraService.setVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); infraService.setTlsType(true);
// this.infraServiceDAO.save(infraService); }
// infraService.setVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
if(service.isTarget()) {
Target targetService = new Target();
targetService.setDisplayName(service.getServiceName() + "-Service");
this.targetService.regist(targetService);
infraService.setTarget(targetService);
}
this.infraServiceService.regist(infraService);
// Infra infraByService = Infra.CreateInfraByType(infraService.getId(), InfraService.class); // Infra infraByService = Infra.CreateInfraByType(infraService.getId(), InfraService.class);
// this.infraDAO.save(infraByService); // this.infraDAO.save(infraByService);
//
// if(service.isTarget()) {
// Target targetService = new Target();
//// targetService.setInfra(infraByService); }
//// targetService.setProbe(probe);
// this.targetDAO.save(targetService); }
// }
//
// } }
//
// } }
//
//
// }
//
// }
} }