diff --git a/src/main/java/com/loafle/overflow/module/meta/model/MetaInfraVendor.java b/src/main/java/com/loafle/overflow/module/meta/model/MetaInfraVendor.java index ce96cda..b786c78 100644 --- a/src/main/java/com/loafle/overflow/module/meta/model/MetaInfraVendor.java +++ b/src/main/java/com/loafle/overflow/module/meta/model/MetaInfraVendor.java @@ -59,12 +59,18 @@ public class MetaInfraVendor { MetaInfraVendor vendor = new MetaInfraVendor(); + if(osName == null || osName.length() <= 0) { + vendor.setId(28); // FIXME: Unknown + return vendor; + } if(osName.equals("Windows")) { - vendor.setId(25); + vendor.setId(26); } else if(osName.equals("Linux")) { - vendor.setId(27); // ubuntu + vendor.setId(28); // ubuntu + } else { + vendor.setId(28); // FIXME: Unknown } return vendor; diff --git a/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java b/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java index f8e4ad3..5b9b66c 100644 --- a/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java +++ b/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java @@ -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.infra.dao.*; 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.probe.model.Probe; import com.loafle.overflow.module.target.dao.TargetDAO; @@ -22,121 +25,150 @@ import java.util.List; public class TargetDiscoveryService { @Autowired - private TargetDAO targetDAO; + private TargetService targetService; @Autowired - private InfraMachineDAO infraMachineDAO; + private InfraMachineService infraMachineService; @Autowired - private InfraOSDAO infraOSDAO; + private InfraOSService infraOSService; @Autowired - private InfraHostDAO infraHostDAO; + private InfraHostService infraHostService; @Autowired - private InfraDAO infraDAO; + private com.loafle.overflow.module.infra.service.InfraService infraService; @Autowired - private InfraOSPortDAO infraOSPortDAO; + private InfraOSPortService infraOSPortService; @Autowired - private InfraServiceDAO infraServiceDAO; + private InfraServiceService infraServiceService; + + @Transactional + public void saveAllTarget(List 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 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); // this.infraDAO.save(infraByHost); -// + // if(host.isTarget()) { // Target targetHost = new Target(); //// targetHost.setInfra(infraByHost); //// targetHost.setProbe(probe); // this.targetDAO.save(targetHost); // } -// -// if(host.getPorts() == null) { -// continue; -// } -// -// for(Port port : host.getPorts()) { -// -// InfraOSPort infraOSPort = new InfraOSPort(); -// infraOSPort.setOs(infraOS); -// infraOSPort.setPort(port.getPortNumber()); -// infraOSPort.setPortType("UDP"); -// if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { -// infraOSPort.setPortType("TCP"); -// } -// if (port.getPortType() == PortType.TLS) { -// infraOSPort.setTlsType(true); -// } -// infraOSPort.setVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber())); -// this.infraOSPortDAO.save(infraOSPort); -// + + if(host.getPorts() == null) { + continue; + } + + for(Port port : host.getPorts()) { + + InfraOSPort infraOSPort = new InfraOSPort(); + infraOSPort.setOs(infraOS); + infraOSPort.setPort(port.getPortNumber()); + infraOSPort.setPortType("UDP"); + infraOSPort.setProbe(probe); + infraOSPort.setInfraType(typePort); + if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { + infraOSPort.setPortType("TCP"); + } + if (port.getPortType() == PortType.TLS) { + infraOSPort.setTlsType(true); + } + infraOSPort.setVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber())); + this.infraOSPortService.regist(infraOSPort); + // Infra infraByPort = Infra.CreateInfraByType(infraOSPort.getId(), InfraOSPort.class); // this.infraDAO.save(infraByPort); -// -// if(port.getServices() == null) { -// continue; -// } -// -// for(com.loafle.overflow.module.discovery.model.Service service : port.getServices()) { -// -// InfraService infraService = new InfraService(); -// infraService.setHost(infraHost); -// infraService.setPort(port.getPortNumber()); -// infraService.setPortType("UDP"); -// if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { -// infraService.setPortType("TCP"); -// } -// if (port.getPortType() == PortType.TLS) { -// infraService.setTlsType(true); -// } -// infraService.setVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); -// this.infraServiceDAO.save(infraService); -// + + if(port.getServices() == null) { + continue; + } + + for(com.loafle.overflow.module.discovery.model.Service service : port.getServices()) { + + InfraService infraService = new InfraService(); + infraService.setHost(infraHost); + infraService.setPort(port.getPortNumber()); + infraService.setPortType("UDP"); + infraService.setInfraType(typeService); + infraService.setProbe(probe); + if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { + infraService.setPortType("TCP"); + } + if (port.getPortType() == PortType.TLS) { + infraService.setTlsType(true); + } + 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); // this.infraDAO.save(infraByService); -// -// if(service.isTarget()) { -// Target targetService = new Target(); -//// targetService.setInfra(infraByService); -//// targetService.setProbe(probe); -// this.targetDAO.save(targetService); -// } -// -// } -// -// } -// -// -// } -// -// } + + + + } + + } + + + } + + } }