From 5fec46feeb00efcad33f8ba1628d22cdb7e095af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=B0=E6=8B=BE=E5=A3=B9?= <30471543+er10yi@users.noreply.github.com> Date: Wed, 8 Sep 2021 17:33:29 +0800 Subject: [PATCH] Delete center directory --- center/Dockerfile | 4 - center/pom.xml | 199 --- .../com/tiji/center/ApplicationConfig.java | 30 - .../com/tiji/center/CenterApplication.java | 36 - .../tiji/center/MonitorApplicationRunner.java | 266 ---- .../com/tiji/center/WebSecurityConfig.java | 28 - .../com/tiji/center/aspect/AssessAspect.java | 36 - .../com/tiji/center/aspect/WebLogAspect.java | 48 - .../center/controller/AgentController.java | 122 -- .../center/controller/AssetipController.java | 475 ------ .../controller/AssetportController.java | 350 ----- .../controller/BaseExceptionHandler.java | 48 - .../controller/CategorysecondController.java | 154 -- .../controller/CategorytopController.java | 139 -- .../center/controller/CharController.java | 245 ---- .../controller/CheckresultController.java | 317 ---- .../controller/CheckresultVulnController.java | 159 -- .../center/controller/ContactController.java | 140 -- .../ContactProjectinfoController.java | 163 --- .../center/controller/CronjobController.java | 228 --- .../center/controller/DemocodeController.java | 149 -- .../controller/DepartmentController.java | 240 ---- .../DictionarypasswordController.java | 196 --- .../DictionaryusernameController.java | 197 --- .../controller/DomainwhitelistController.java | 174 --- .../center/controller/HostController.java | 263 ---- .../controller/ImvulnnotifyController.java | 284 ---- .../controller/IpportwhitelistController.java | 142 -- .../controller/IpwhitelistController.java | 307 ---- .../center/controller/LoginController.java | 149 -- .../controller/NmapconfigController.java | 149 -- .../controller/NotifylogController.java | 121 -- .../controller/PluginCheckerController.java | 36 - .../PluginassetserviceController.java | 148 -- .../PluginassetversionController.java | 143 -- .../controller/PluginconfigController.java | 438 ------ .../center/controller/ProjectController.java | 130 -- .../controller/ProjectinfoController.java | 459 ------ .../ProjectportwhitelistController.java | 140 -- .../ProjectvulnnotifyController.java | 109 -- .../center/controller/RiskportController.java | 182 --- .../controller/RiskserviceController.java | 181 --- .../controller/RiskversionController.java | 182 --- .../controller/SendmailconfigController.java | 109 -- .../center/controller/SolutionController.java | 148 -- .../controller/StatisticsController.java | 109 -- .../center/controller/TaskController.java | 377 ----- .../center/controller/TaskipController.java | 152 -- .../TaskpluginconfigController.java | 227 --- .../center/controller/TaskportController.java | 165 --- .../controller/TitlewhitelistController.java | 183 --- .../tiji/center/controller/UrlController.java | 166 --- .../center/controller/UserController.java | 155 -- .../controller/UseragentController.java | 202 --- .../center/controller/VulnController.java | 362 ----- .../controller/VulnkeywordController.java | 158 -- .../VulnpluginconfigController.java | 180 --- .../center/controller/WebinfoController.java | 231 --- .../java/com/tiji/center/dao/AgentDao.java | 29 - .../java/com/tiji/center/dao/AssetipDao.java | 62 - .../com/tiji/center/dao/AssetportDao.java | 61 - .../tiji/center/dao/CategorysecondDao.java | 24 - .../com/tiji/center/dao/CategorytopDao.java | 22 - .../com/tiji/center/dao/CheckresultDao.java | 29 - .../tiji/center/dao/CheckresultVulnDao.java | 25 - .../java/com/tiji/center/dao/ContactDao.java | 24 - .../center/dao/ContactProjectinfoDao.java | 32 - .../java/com/tiji/center/dao/CronjobDao.java | 14 - .../java/com/tiji/center/dao/DemocodeDao.java | 26 - .../com/tiji/center/dao/DepartmentDao.java | 23 - .../center/dao/DictionarypasswordDao.java | 27 - .../center/dao/DictionaryusernameDao.java | 27 - .../tiji/center/dao/DomainwhitelistDao.java | 26 - .../java/com/tiji/center/dao/HostDao.java | 34 - .../com/tiji/center/dao/ImvulnnotifyDao.java | 14 - .../tiji/center/dao/IpportwhitelistDao.java | 28 - .../com/tiji/center/dao/IpwhitelistDao.java | 29 - .../com/tiji/center/dao/NmapconfigDao.java | 25 - .../com/tiji/center/dao/NotifylogDao.java | 21 - .../center/dao/PluginassetserviceDao.java | 32 - .../center/dao/PluginassetversionDao.java | 34 - .../com/tiji/center/dao/PluginconfigDao.java | 28 - .../java/com/tiji/center/dao/ProjectDao.java | 28 - .../com/tiji/center/dao/ProjectinfoDao.java | 36 - .../center/dao/ProjectportwhitelistDao.java | 28 - .../tiji/center/dao/ProjectvulnnotifyDao.java | 14 - .../java/com/tiji/center/dao/RiskportDao.java | 24 - .../com/tiji/center/dao/RiskserviceDao.java | 23 - .../com/tiji/center/dao/RiskversionDao.java | 24 - .../tiji/center/dao/SendmailconfigDao.java | 14 - .../java/com/tiji/center/dao/SolutionDao.java | 26 - .../com/tiji/center/dao/StatisticsDao.java | 103 -- .../java/com/tiji/center/dao/TaskDao.java | 33 - .../java/com/tiji/center/dao/TaskipDao.java | 171 --- .../tiji/center/dao/TaskpluginconfigDao.java | 35 - .../java/com/tiji/center/dao/TaskportDao.java | 34 - .../tiji/center/dao/TitlewhitelistDao.java | 26 - .../main/java/com/tiji/center/dao/UrlDao.java | 29 - .../java/com/tiji/center/dao/UserDao.java | 23 - .../com/tiji/center/dao/UseragentDao.java | 27 - .../java/com/tiji/center/dao/VulnDao.java | 23 - .../com/tiji/center/dao/VulnkeywordDao.java | 29 - .../tiji/center/dao/VulnpluginconfigDao.java | 28 - .../java/com/tiji/center/dao/WebinfoDao.java | 27 - .../MasterDataSourceConfiguration.java | 58 - .../center/dispatcher/TargetIpSlicer.java | 203 --- .../exception/AssessDeniedException.java | 15 - .../exception/ExpiredTokenException.java | 15 - .../exception/IllegalTokenException.java | 15 - .../tiji/center/exception/LoginException.java | 16 - .../com/tiji/center/filter/JwtFilter.java | 95 -- .../java/com/tiji/center/mq/IMReceiver.java | 113 -- .../tiji/center/mq/ScanResultReceiver.java | 385 ----- .../main/java/com/tiji/center/pojo/Agent.java | 97 -- .../java/com/tiji/center/pojo/Assetip.java | 183 --- .../java/com/tiji/center/pojo/Assetport.java | 202 --- .../com/tiji/center/pojo/Categorysecond.java | 58 - .../com/tiji/center/pojo/Categorytop.java | 48 - .../com/tiji/center/pojo/Checkresult.java | 161 --- .../com/tiji/center/pojo/CheckresultVuln.java | 58 - .../java/com/tiji/center/pojo/Contact.java | 77 - .../tiji/center/pojo/ContactProjectinfo.java | 58 - .../java/com/tiji/center/pojo/Cronjob.java | 62 - .../java/com/tiji/center/pojo/Democode.java | 68 - .../java/com/tiji/center/pojo/Department.java | 48 - .../tiji/center/pojo/Dictionarypassword.java | 49 - .../tiji/center/pojo/Dictionaryusername.java | 49 - .../com/tiji/center/pojo/Domainwhitelist.java | 48 - .../main/java/com/tiji/center/pojo/Host.java | 150 -- .../com/tiji/center/pojo/Imvulnnotify.java | 166 --- .../com/tiji/center/pojo/Ipportwhitelist.java | 78 - .../com/tiji/center/pojo/Ipwhitelist.java | 68 - .../java/com/tiji/center/pojo/Nmapconfig.java | 68 - .../java/com/tiji/center/pojo/Notifylog.java | 109 -- .../tiji/center/pojo/Pluginassetservice.java | 58 - .../tiji/center/pojo/Pluginassetversion.java | 58 - .../com/tiji/center/pojo/Pluginconfig.java | 106 -- .../java/com/tiji/center/pojo/Project.java | 50 - .../com/tiji/center/pojo/Projectinfo.java | 121 -- .../center/pojo/Projectportwhitelist.java | 77 - .../tiji/center/pojo/Projectvulnnotify.java | 41 - .../java/com/tiji/center/pojo/Riskport.java | 50 - .../com/tiji/center/pojo/Riskservice.java | 48 - .../com/tiji/center/pojo/Riskversion.java | 48 - .../com/tiji/center/pojo/Sendmailconfig.java | 137 -- .../java/com/tiji/center/pojo/Solution.java | 78 - .../java/com/tiji/center/pojo/Statistics.java | 296 ---- .../main/java/com/tiji/center/pojo/Task.java | 280 ---- .../java/com/tiji/center/pojo/Taskip.java | 78 - .../tiji/center/pojo/Taskpluginconfig.java | 59 - .../java/com/tiji/center/pojo/Taskport.java | 118 -- .../com/tiji/center/pojo/Titlewhitelist.java | 48 - .../main/java/com/tiji/center/pojo/Url.java | 68 - .../main/java/com/tiji/center/pojo/User.java | 85 -- .../java/com/tiji/center/pojo/Useragent.java | 48 - .../main/java/com/tiji/center/pojo/Vuln.java | 98 -- .../com/tiji/center/pojo/Vulnkeyword.java | 58 - .../tiji/center/pojo/Vulnpluginconfig.java | 58 - .../java/com/tiji/center/pojo/Webinfo.java | 212 --- .../AgentHeartbeatMonitorScheduler.java | 142 -- .../center/schedule/AssetNotifyScheduler.java | 356 ----- .../schedule/ExecuteCheckTaskScheduler.java | 33 - .../ExecuteTotalCheckTaskScheduler.java | 33 - .../schedule/ExecuteWorkTaskScheduler.java | 56 - .../schedule/MidnightTaskScheduler.java | 66 - .../center/schedule/StatisticsScheduler.java | 90 -- .../schedule/TaskStatusMonitorScheduler.java | 144 -- .../center/schedule/VulnNotifyScheduler.java | 389 ----- .../center/schedule/quartz/QuartzJob.java | 57 - .../schedule/quartz/QuartzJobService.java | 110 -- .../com/tiji/center/service/AgentService.java | 197 --- .../tiji/center/service/AssetipService.java | 361 ----- .../tiji/center/service/AssetportService.java | 406 ------ .../center/service/CategorysecondService.java | 187 --- .../center/service/CategorytopService.java | 154 -- .../center/service/CheckresultService.java | 283 ---- .../service/CheckresultVulnService.java | 176 --- .../service/ContactProjectinfoService.java | 195 --- .../tiji/center/service/ContactService.java | 168 --- .../tiji/center/service/CronjobService.java | 148 -- .../tiji/center/service/DemocodeService.java | 172 --- .../center/service/DepartmentService.java | 154 -- .../service/DictionarypasswordService.java | 163 --- .../service/DictionaryusernameService.java | 162 --- .../service/DomainwhitelistService.java | 171 --- .../com/tiji/center/service/HostService.java | 257 ---- .../center/service/ImvulnnotifyService.java | 162 --- .../service/IpportwhitelistService.java | 213 --- .../center/service/IpwhitelistService.java | 181 --- .../center/service/NmapconfigService.java | 186 --- .../tiji/center/service/NotifylogService.java | 181 --- .../service/PluginassetserviceService.java | 197 --- .../service/PluginassetversionService.java | 198 --- .../center/service/PluginconfigService.java | 209 --- .../tiji/center/service/ProjectService.java | 169 --- .../center/service/ProjectinfoService.java | 263 ---- .../service/ProjectportwhitelistService.java | 195 --- .../service/ProjectvulnnotifyService.java | 133 -- .../tiji/center/service/RiskportService.java | 153 -- .../center/service/RiskserviceService.java | 155 -- .../center/service/RiskversionService.java | 154 -- .../center/service/SendmailconfigService.java | 170 --- .../tiji/center/service/SolutionService.java | 175 --- .../center/service/StatisticsService.java | 498 ------- .../center/service/TaskDispatcherService.java | 973 ------------- .../com/tiji/center/service/TaskService.java | 387 ----- .../tiji/center/service/TaskipService.java | 342 ----- .../service/TaskpluginconfigService.java | 218 --- .../tiji/center/service/TaskportService.java | 251 ---- .../center/service/TitlewhitelistService.java | 159 -- .../com/tiji/center/service/UrlService.java | 217 --- .../com/tiji/center/service/UserService.java | 198 --- .../tiji/center/service/UseragentService.java | 172 --- .../com/tiji/center/service/VulnService.java | 205 --- .../center/service/VulnkeywordService.java | 196 --- .../service/VulnpluginconfigService.java | 207 --- .../tiji/center/service/WebinfoService.java | 244 ---- .../tiji/center/thread/DNSResolveThread.java | 50 - .../com/tiji/center/util/HostNameUtil.java | 149 -- .../java/com/tiji/center/util/JwtUtil.java | 67 - .../java/com/tiji/center/util/NotifyUtil.java | 343 ----- .../java/com/tiji/center/util/TijiHelper.java | 1275 ----------------- .../com/tiji/center/util/WhitelistUtil.java | 142 -- center/src/main/resources/logback-spring.xml | 162 --- 224 files changed, 31708 deletions(-) delete mode 100755 center/Dockerfile delete mode 100755 center/pom.xml delete mode 100755 center/src/main/java/com/tiji/center/ApplicationConfig.java delete mode 100755 center/src/main/java/com/tiji/center/CenterApplication.java delete mode 100755 center/src/main/java/com/tiji/center/MonitorApplicationRunner.java delete mode 100755 center/src/main/java/com/tiji/center/WebSecurityConfig.java delete mode 100755 center/src/main/java/com/tiji/center/aspect/AssessAspect.java delete mode 100755 center/src/main/java/com/tiji/center/aspect/WebLogAspect.java delete mode 100755 center/src/main/java/com/tiji/center/controller/AgentController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/AssetipController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/AssetportController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/BaseExceptionHandler.java delete mode 100755 center/src/main/java/com/tiji/center/controller/CategorysecondController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/CategorytopController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/CharController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/CheckresultController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/CheckresultVulnController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/ContactController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/ContactProjectinfoController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/CronjobController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/DemocodeController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/DepartmentController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/DictionarypasswordController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/DictionaryusernameController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/DomainwhitelistController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/HostController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/ImvulnnotifyController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/IpportwhitelistController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/IpwhitelistController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/LoginController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/NmapconfigController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/NotifylogController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/PluginCheckerController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/PluginassetserviceController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/PluginassetversionController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/PluginconfigController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/ProjectController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/ProjectinfoController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/ProjectportwhitelistController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/ProjectvulnnotifyController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/RiskportController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/RiskserviceController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/RiskversionController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/SendmailconfigController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/SolutionController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/StatisticsController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/TaskController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/TaskipController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/TaskpluginconfigController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/TaskportController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/TitlewhitelistController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/UrlController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/UserController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/UseragentController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/VulnController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/VulnkeywordController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/VulnpluginconfigController.java delete mode 100755 center/src/main/java/com/tiji/center/controller/WebinfoController.java delete mode 100755 center/src/main/java/com/tiji/center/dao/AgentDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/AssetipDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/AssetportDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/CategorysecondDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/CategorytopDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/CheckresultDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/CheckresultVulnDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/ContactDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/ContactProjectinfoDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/CronjobDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/DemocodeDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/DepartmentDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/DictionarypasswordDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/DictionaryusernameDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/DomainwhitelistDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/HostDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/ImvulnnotifyDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/IpportwhitelistDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/IpwhitelistDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/NmapconfigDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/NotifylogDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/PluginassetserviceDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/PluginassetversionDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/PluginconfigDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/ProjectDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/ProjectinfoDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/ProjectportwhitelistDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/ProjectvulnnotifyDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/RiskportDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/RiskserviceDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/RiskversionDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/SendmailconfigDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/SolutionDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/StatisticsDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/TaskDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/TaskipDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/TaskpluginconfigDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/TaskportDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/TitlewhitelistDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/UrlDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/UserDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/UseragentDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/VulnDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/VulnkeywordDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/VulnpluginconfigDao.java delete mode 100755 center/src/main/java/com/tiji/center/dao/WebinfoDao.java delete mode 100755 center/src/main/java/com/tiji/center/datasource/MasterDataSourceConfiguration.java delete mode 100755 center/src/main/java/com/tiji/center/dispatcher/TargetIpSlicer.java delete mode 100755 center/src/main/java/com/tiji/center/exception/AssessDeniedException.java delete mode 100755 center/src/main/java/com/tiji/center/exception/ExpiredTokenException.java delete mode 100755 center/src/main/java/com/tiji/center/exception/IllegalTokenException.java delete mode 100755 center/src/main/java/com/tiji/center/exception/LoginException.java delete mode 100755 center/src/main/java/com/tiji/center/filter/JwtFilter.java delete mode 100755 center/src/main/java/com/tiji/center/mq/IMReceiver.java delete mode 100755 center/src/main/java/com/tiji/center/mq/ScanResultReceiver.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Agent.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Assetip.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Assetport.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Categorysecond.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Categorytop.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Checkresult.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/CheckresultVuln.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Contact.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/ContactProjectinfo.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Cronjob.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Democode.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Department.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Dictionarypassword.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Dictionaryusername.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Domainwhitelist.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Host.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Imvulnnotify.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Ipportwhitelist.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Ipwhitelist.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Nmapconfig.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Notifylog.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Pluginassetservice.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Pluginassetversion.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Pluginconfig.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Project.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Projectinfo.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Projectportwhitelist.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Projectvulnnotify.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Riskport.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Riskservice.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Riskversion.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Sendmailconfig.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Solution.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Statistics.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Task.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Taskip.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Taskpluginconfig.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Taskport.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Titlewhitelist.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Url.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/User.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Useragent.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Vuln.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Vulnkeyword.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Vulnpluginconfig.java delete mode 100755 center/src/main/java/com/tiji/center/pojo/Webinfo.java delete mode 100755 center/src/main/java/com/tiji/center/schedule/AgentHeartbeatMonitorScheduler.java delete mode 100755 center/src/main/java/com/tiji/center/schedule/AssetNotifyScheduler.java delete mode 100755 center/src/main/java/com/tiji/center/schedule/ExecuteCheckTaskScheduler.java delete mode 100755 center/src/main/java/com/tiji/center/schedule/ExecuteTotalCheckTaskScheduler.java delete mode 100755 center/src/main/java/com/tiji/center/schedule/ExecuteWorkTaskScheduler.java delete mode 100755 center/src/main/java/com/tiji/center/schedule/MidnightTaskScheduler.java delete mode 100755 center/src/main/java/com/tiji/center/schedule/StatisticsScheduler.java delete mode 100755 center/src/main/java/com/tiji/center/schedule/TaskStatusMonitorScheduler.java delete mode 100755 center/src/main/java/com/tiji/center/schedule/VulnNotifyScheduler.java delete mode 100755 center/src/main/java/com/tiji/center/schedule/quartz/QuartzJob.java delete mode 100755 center/src/main/java/com/tiji/center/schedule/quartz/QuartzJobService.java delete mode 100755 center/src/main/java/com/tiji/center/service/AgentService.java delete mode 100755 center/src/main/java/com/tiji/center/service/AssetipService.java delete mode 100755 center/src/main/java/com/tiji/center/service/AssetportService.java delete mode 100755 center/src/main/java/com/tiji/center/service/CategorysecondService.java delete mode 100755 center/src/main/java/com/tiji/center/service/CategorytopService.java delete mode 100755 center/src/main/java/com/tiji/center/service/CheckresultService.java delete mode 100755 center/src/main/java/com/tiji/center/service/CheckresultVulnService.java delete mode 100755 center/src/main/java/com/tiji/center/service/ContactProjectinfoService.java delete mode 100755 center/src/main/java/com/tiji/center/service/ContactService.java delete mode 100755 center/src/main/java/com/tiji/center/service/CronjobService.java delete mode 100755 center/src/main/java/com/tiji/center/service/DemocodeService.java delete mode 100755 center/src/main/java/com/tiji/center/service/DepartmentService.java delete mode 100755 center/src/main/java/com/tiji/center/service/DictionarypasswordService.java delete mode 100755 center/src/main/java/com/tiji/center/service/DictionaryusernameService.java delete mode 100755 center/src/main/java/com/tiji/center/service/DomainwhitelistService.java delete mode 100755 center/src/main/java/com/tiji/center/service/HostService.java delete mode 100755 center/src/main/java/com/tiji/center/service/ImvulnnotifyService.java delete mode 100755 center/src/main/java/com/tiji/center/service/IpportwhitelistService.java delete mode 100755 center/src/main/java/com/tiji/center/service/IpwhitelistService.java delete mode 100755 center/src/main/java/com/tiji/center/service/NmapconfigService.java delete mode 100755 center/src/main/java/com/tiji/center/service/NotifylogService.java delete mode 100755 center/src/main/java/com/tiji/center/service/PluginassetserviceService.java delete mode 100755 center/src/main/java/com/tiji/center/service/PluginassetversionService.java delete mode 100755 center/src/main/java/com/tiji/center/service/PluginconfigService.java delete mode 100755 center/src/main/java/com/tiji/center/service/ProjectService.java delete mode 100755 center/src/main/java/com/tiji/center/service/ProjectinfoService.java delete mode 100755 center/src/main/java/com/tiji/center/service/ProjectportwhitelistService.java delete mode 100755 center/src/main/java/com/tiji/center/service/ProjectvulnnotifyService.java delete mode 100755 center/src/main/java/com/tiji/center/service/RiskportService.java delete mode 100755 center/src/main/java/com/tiji/center/service/RiskserviceService.java delete mode 100755 center/src/main/java/com/tiji/center/service/RiskversionService.java delete mode 100755 center/src/main/java/com/tiji/center/service/SendmailconfigService.java delete mode 100755 center/src/main/java/com/tiji/center/service/SolutionService.java delete mode 100755 center/src/main/java/com/tiji/center/service/StatisticsService.java delete mode 100755 center/src/main/java/com/tiji/center/service/TaskDispatcherService.java delete mode 100755 center/src/main/java/com/tiji/center/service/TaskService.java delete mode 100755 center/src/main/java/com/tiji/center/service/TaskipService.java delete mode 100755 center/src/main/java/com/tiji/center/service/TaskpluginconfigService.java delete mode 100755 center/src/main/java/com/tiji/center/service/TaskportService.java delete mode 100755 center/src/main/java/com/tiji/center/service/TitlewhitelistService.java delete mode 100755 center/src/main/java/com/tiji/center/service/UrlService.java delete mode 100755 center/src/main/java/com/tiji/center/service/UserService.java delete mode 100755 center/src/main/java/com/tiji/center/service/UseragentService.java delete mode 100755 center/src/main/java/com/tiji/center/service/VulnService.java delete mode 100755 center/src/main/java/com/tiji/center/service/VulnkeywordService.java delete mode 100755 center/src/main/java/com/tiji/center/service/VulnpluginconfigService.java delete mode 100755 center/src/main/java/com/tiji/center/service/WebinfoService.java delete mode 100755 center/src/main/java/com/tiji/center/thread/DNSResolveThread.java delete mode 100755 center/src/main/java/com/tiji/center/util/HostNameUtil.java delete mode 100755 center/src/main/java/com/tiji/center/util/JwtUtil.java delete mode 100755 center/src/main/java/com/tiji/center/util/NotifyUtil.java delete mode 100755 center/src/main/java/com/tiji/center/util/TijiHelper.java delete mode 100755 center/src/main/java/com/tiji/center/util/WhitelistUtil.java delete mode 100755 center/src/main/resources/logback-spring.xml diff --git a/center/Dockerfile b/center/Dockerfile deleted file mode 100755 index 9fe921f..0000000 --- a/center/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM openjdk -ENTRYPOINT ["java", "-jar", "/centerapp.jar"] -ARG JAR_FILE -ADD ${JAR_FILE} /centerapp.jar \ No newline at end of file diff --git a/center/pom.xml b/center/pom.xml deleted file mode 100755 index 793994a..0000000 --- a/center/pom.xml +++ /dev/null @@ -1,199 +0,0 @@ - - 4.0.0 - - com.tiji - MagiCude - 1.0-SNAPSHOT - - center - - - 15 - - 192.168.12.138:5000 - 1.4.13 - 8.0.22 - 3.11 - 0.9.1 - 4.1.2 - 4.1.2 - 1.2.4 - 1.3.8.1 - 4.5.13 - 2.8.6 - 3.2.2 - 0.9.3 - - - - centerapp - - - - - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - - com.spotify - dockerfile-maven-plugin - ${dockerfile-maven-plugin.version} - - - default - - - build - push - - - - - ${docker.repository}/${project.artifactId} - ${project.version} - - - target/${project.build.finalName}.jar - - - - - - - - - - - com.tiji - common - 1.0-SNAPSHOT - compile - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - - - - - - - - - - - mysql - mysql-connector-java - ${mysql-connector-java.version} - - - - - org.springframework.boot - spring-boot-starter-data-redis - - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-client - - - org.springframework.boot - spring-boot-starter-amqp - - - - io.jsonwebtoken - jjwt - ${jjwt.version} - - - - org.springframework.boot - spring-boot-starter-quartz - - - org.springframework.boot - spring-boot-starter-aop - - - - org.apache.poi - poi - ${poi.version} - - - - org.apache.poi - poi-ooxml - ${poi-ooxml.version} - - - org.springframework.boot - spring-boot-starter-mail - - - - com.alibaba - druid-spring-boot-starter - ${druid-spring-boot-starter.version} - - - - com.github.eagle6688 - devutility.internal - ${devutility.internal.version} - provided - - - org.apache.httpcomponents - httpclient - ${httpclient.version} - - - - com.google.code.gson - gson - ${gson.version} - - - - dnsjava - dnsjava - ${dnsjava.version} - - - - org.roaringbitmap - RoaringBitmap - ${RoaringBitmap.version} - - - - diff --git a/center/src/main/java/com/tiji/center/ApplicationConfig.java b/center/src/main/java/com/tiji/center/ApplicationConfig.java deleted file mode 100755 index 534c401..0000000 --- a/center/src/main/java/com/tiji/center/ApplicationConfig.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.tiji.center; - -import com.tiji.center.filter.JwtFilter; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author 贰拾壹 - * @create 2019-09-05 15:29 - */ -@Configuration -public class ApplicationConfig extends WebMvcConfigurationSupport { - - @Autowired - private JwtFilter jwtFilter; - - @Override - public void addInterceptors(InterceptorRegistry registry) { - //拦截所有请求 - String[] addPathPatterns = {"/**"}; - //不需要拦截的请求 - String[] excludePathPatterns = {"/user/login", "/pluginchecker"}; - registry.addInterceptor(jwtFilter).addPathPatterns(addPathPatterns).excludePathPatterns(excludePathPatterns); - } -} diff --git a/center/src/main/java/com/tiji/center/CenterApplication.java b/center/src/main/java/com/tiji/center/CenterApplication.java deleted file mode 100755 index 9f9d8f7..0000000 --- a/center/src/main/java/com/tiji/center/CenterApplication.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.tiji.center; - -import com.tiji.center.util.JwtUtil; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -//import org.springframework.cloud.netflix.eureka.EnableEurekaClient; -import org.springframework.cloud.netflix.eureka.EnableEurekaClient; -import org.springframework.context.annotation.Bean; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import util.IdWorker; - -@SpringBootApplication -@EnableEurekaClient -public class CenterApplication { - - public static void main(String[] args) { - //解决邮件附件名过长被截断的问题 - System.getProperties().setProperty("mail.mime.splitlongparameters", "false"); - SpringApplication.run(CenterApplication.class, args); - } - - @Bean - public IdWorker idWorker() { - return new IdWorker(1, 1); - } - - @Bean - public JwtUtil jwtUtil() { - return new JwtUtil(); - } - - @Bean - public BCryptPasswordEncoder bCryptPasswordEncoder() { - return new BCryptPasswordEncoder(); - } -} diff --git a/center/src/main/java/com/tiji/center/MonitorApplicationRunner.java b/center/src/main/java/com/tiji/center/MonitorApplicationRunner.java deleted file mode 100755 index ebfb17f..0000000 --- a/center/src/main/java/com/tiji/center/MonitorApplicationRunner.java +++ /dev/null @@ -1,266 +0,0 @@ -package com.tiji.center; - -import com.tiji.center.pojo.Cronjob; -import com.tiji.center.pojo.Task; -import com.tiji.center.schedule.*; -import com.tiji.center.schedule.quartz.QuartzJob; -import com.tiji.center.schedule.quartz.QuartzJobService; -import com.tiji.center.service.*; -import com.tiji.center.util.TijiHelper; -import org.quartz.Job; -import org.quartz.JobKey; -import org.quartz.SchedulerException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Component; -import org.xbill.DNS.Record; -import org.xbill.DNS.*; -import util.ExcpUtil; -import util.IdWorker; - -import java.io.IOException; -import java.net.*; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - - -/** - * @author 贰拾壹 - * 启动时运行的方法 - * @create 2019-09-30 10:15 - */ -@Component -public class MonitorApplicationRunner implements ApplicationRunner { - private final static Logger logger = LoggerFactory.getLogger(MonitorApplicationRunner.class); - @Autowired - private QuartzJobService quartzJobService; - @Autowired - private TaskService taskService; - @Autowired - private CronjobService cronjobService; - @Autowired - private DictionaryusernameService dictionaryusernameService; - @Autowired - private DictionarypasswordService dictionarypasswordService; - @Autowired - private UseragentService useragentService; - @Autowired - private RedisTemplate redisTemplate; - @Autowired - private IdWorker idWorker; - - @Override - public void run(ApplicationArguments args) { - - try { - //设置Http辅助验证关键词 - setHttpValidateKey(); - - //刷新redis中的用户名密码字典 - freshDictUsernameRedisCache(); - //刷新redis中的UserAgent - freshUserAgentRedisCache(); - - //每10秒,监控所有任务状态 - Cronjob taskStatusMonitor = cronjobService.findByName("任务状态监控"); - if (!Objects.isNull(taskStatusMonitor.getCronexpression()) && !taskStatusMonitor.getCronexpression().isEmpty()) { - runScheduler(taskStatusMonitor.getCronexpression(), TaskStatusMonitorScheduler.class); - } - - //每5分钟,监控agent心跳包 - Cronjob agentHeartbeatMonitor = cronjobService.findByName("agent心跳包监控"); - if (!Objects.isNull(agentHeartbeatMonitor.getCronexpression()) && !agentHeartbeatMonitor.getCronexpression().isEmpty()) { - runScheduler(agentHeartbeatMonitor.getCronexpression(), AgentHeartbeatMonitorScheduler.class); - } - //凌晨3点,凌晨执行的所有任务都丢这里 - //dns解析获取hostname - //nse结果获取hostname - //根据ip更新白名单 - //根据项目更新白名单 - Cronjob midnightTask = cronjobService.findByName("每天执行一次的任务"); - if (!Objects.isNull(midnightTask.getCronexpression()) && !midnightTask.getCronexpression().isEmpty()) { - runScheduler(midnightTask.getCronexpression(), MidnightTaskScheduler.class); - } - //早上7:33,发资产报告 - Cronjob assetNotify = cronjobService.findByName("邮件资产报告"); - if (!Objects.isNull(assetNotify.getCronexpression()) && !assetNotify.getCronexpression().isEmpty()) { - runScheduler(assetNotify.getCronexpression(), AssetNotifyScheduler.class); - } - //早上7:03,发漏洞报告 - Cronjob vulnNotify = cronjobService.findByName("邮件漏洞报告"); - if (!Objects.isNull(vulnNotify.getCronexpression()) && !vulnNotify.getCronexpression().isEmpty()) { - runScheduler(vulnNotify.getCronexpression(), VulnNotifyScheduler.class); - } - //早上6点,统计报表数据 - Cronjob statistics = cronjobService.findByName("统计报表数据"); - if (!Objects.isNull(statistics.getCronexpression()) && !statistics.getCronexpression().isEmpty()) { - runScheduler(statistics.getCronexpression(), StatisticsScheduler.class); - } - //默认每30秒,取IM消息,并调用钉钉,企微群机器人发送 - Cronjob imNotify = cronjobService.findByName("IM通知"); - runScheduler(imNotify.getCronexpression(), IMNotifyScheduler.class); - - //恢复所有非子任务的cron任务 - resumeCronTask(); - - //dns辅助验证 - try { - startDNSServer(); - } catch (SocketException e) { - logger.error("startDNSServer Exception here: " + ExcpUtil.buildErrorMessage(e)); - } - } catch (Exception e) { - logger.error("MonitorApplicationRunner Exception here: " + ExcpUtil.buildErrorMessage(e)); - } - } - - private void resumeCronTask() throws SchedulerException { - //查询所有非子任务的cron任务 - List cronTaskList = taskService.findAllByCrontaskIsTrueAndTaskparentidIsNull(); - for (Task task : cronTaskList) { - String taskId = task.getId(); - String worktype = task.getWorktype(); - String taskTargetIp = task.getTargetip(); - String taskWorkType = task.getWorktype(); - - if (!Objects.isNull(worktype) && !worktype.isEmpty()) { - String cronExpression = task.getCronexpression(); - if (!Objects.isNull(cronExpression) && !cronExpression.isEmpty()) { - String jobKeyName = "jobKeyName_" + taskId; - String jobKeyGroup = "jobKeyGroup_" + taskId; - JobKey jobKey = JobKey.jobKey(jobKeyName, jobKeyGroup); - if ("mass".equals(worktype) || "mass2Nmap".equals(worktype) || "nmap".equals(worktype)) { - Map jobDataMap = new HashMap<>(); - jobDataMap.put("taskId", taskId); - jobDataMap.put("taskTargetIp", taskTargetIp); - jobDataMap.put("taskWorkType", taskWorkType); - //jobDataMap.put("taskInfo", taskInfo); - - QuartzJob quartzJob = new QuartzJob(jobKey, cronExpression, jobDataMap, ExecuteWorkTaskScheduler.class); - quartzJobService.scheduleJob(quartzJob); - } - boolean checkTask = "nse".equals(worktype) || "selfd".equals(worktype) || "httpp".equals(worktype); - if (checkTask) { - Map jobDataMap = new HashMap<>(); - jobDataMap.put("taskId", taskId); - - if ("assetip".equals(task.getTargetip())) { - QuartzJob quartzJob = new QuartzJob(jobKey, cronExpression, jobDataMap, ExecuteTotalCheckTaskScheduler.class); - quartzJobService.scheduleJob(quartzJob); - } else { - QuartzJob quartzJob = new QuartzJob(jobKey, cronExpression, jobDataMap, ExecuteCheckTaskScheduler.class); - quartzJobService.scheduleJob(quartzJob); - } - - } - } - } - } - } - - private void runScheduler(String cronExpression, Class jobClass) throws SchedulerException { - String jobKeyName = "jobKeyName_" + jobClass.getSimpleName(); - String jobKeyGroup = "jobKeyGroup_" + jobClass.getSimpleName(); - JobKey jobKey = JobKey.jobKey(jobKeyName, jobKeyGroup); - QuartzJob quartzJob = new QuartzJob(jobKey, cronExpression, null, jobClass); - quartzJobService.scheduleJob(quartzJob); - - } - - /** - * 设置用户名密码字典 - */ - private void freshDictUsernameRedisCache() { - String redisDictUsername = "dictUsernameList_"; - String redisDictPassword = "dictPasswordList_"; - redisTemplate.delete(redisDictUsername); - redisTemplate.delete(redisDictPassword); - List allUsername = dictionaryusernameService.findAllUsername(); - List allPassword = dictionarypasswordService.findAllPassword(); - if (!allUsername.isEmpty()) { - redisTemplate.opsForList().leftPushAll(redisDictUsername, allUsername); - } - if (!allPassword.isEmpty()) { - redisTemplate.opsForList().leftPushAll(redisDictPassword, allPassword); - } - } - - /** - * 设置ua - */ - private void freshUserAgentRedisCache() { -// String redisUserAgent = "userAgentList_"; - String redisUserAgent = "userAgentSet_"; - redisTemplate.delete(redisUserAgent); - List allUserAgent = useragentService.findAllDistinctUserAgentList(); - allUserAgent.parallelStream().forEach(ua -> redisTemplate.opsForSet().add(redisUserAgent, ua)); -// if (!allUserAgent.isEmpty()) { -// redisTemplate.opsForList().leftPushAll(redisUserAgent, allUserAgent); -// } - } - - - /** - * 设置Http辅助验证关键词 - */ - private void setHttpValidateKey() { - redisTemplate.opsForValue().set("HttpValidateKey_", idWorker.nextId() + ""); - } - - /** - * 启动DNS辅助验证服务 - */ - private void startDNSServer() throws SocketException { - DatagramSocket socket = new DatagramSocket(53); - new Thread(() -> { - InetAddress sourceIpAddr; - int sourcePort; - while (true) { - try { - byte[] buffer = new byte[1024]; - DatagramPacket request = new DatagramPacket(buffer, buffer.length); - socket.receive(request); - sourceIpAddr = request.getAddress(); - sourcePort = request.getPort(); - Message message = new Message(request.getData()); - Record question = message.getQuestion(); - String domain = question.getName().toString(); - logger.info("============= DNS Query Start ================="); - logger.info("sourceIpAddr: " + sourceIpAddr); - logger.info("sourcePort: " + sourcePort); - logger.info("message: " + message); - logger.info("question: " + question); - logger.info("domain: " + domain); - logger.info("============= DNS Query End ================="); - try { - //正常域名 - sendResponse(socket, sourceIpAddr, sourcePort, message, question, Address.getByName(domain)); - } catch (UnknownHostException e) { - //未知域名,全部指向本机ip,用于selfd插件dns辅助验证自定义域名 - sendResponse(socket, sourceIpAddr, sourcePort, message, question, InetAddress.getLocalHost()); - } - } catch (IOException e) { - logger.error("MonitorApplicationRunner DNSServer Exception: " + ExcpUtil.buildErrorMessage(e)); - } - } - }).start(); - - } - - private void sendResponse(DatagramSocket socket, InetAddress targetIp, int targetPort, Message message, Record record, InetAddress inetAddress) throws IOException { - Record answer = new ARecord(record.getName(), record.getDClass(), 64, inetAddress); - message.getHeader().setFlag(Flags.AA); - message.getHeader().setFlag(Flags.QR); - message.addRecord(answer, Section.ANSWER); - byte[] buffer = message.toWire(); - DatagramPacket response = new DatagramPacket(buffer, buffer.length, targetIp, targetPort); - socket.send(response); - } -} diff --git a/center/src/main/java/com/tiji/center/WebSecurityConfig.java b/center/src/main/java/com/tiji/center/WebSecurityConfig.java deleted file mode 100755 index fb68447..0000000 --- a/center/src/main/java/com/tiji/center/WebSecurityConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.tiji.center; - -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.config.http.SessionCreationPolicy; - -/** - * @author 贰拾壹 - * @create 2019-09-05 14:31 - */ -@Configuration -@EnableWebSecurity -public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - @Override - protected void configure(HttpSecurity http) throws Exception { - http - .csrf().disable() - .httpBasic().disable() - .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() - .authorizeRequests() - //所有资源允许匿名访问,权限校验由jwtFilter进行 - .antMatchers("/**").permitAll() - .anyRequest().authenticated(); - } -} diff --git a/center/src/main/java/com/tiji/center/aspect/AssessAspect.java b/center/src/main/java/com/tiji/center/aspect/AssessAspect.java deleted file mode 100755 index 6aa7044..0000000 --- a/center/src/main/java/com/tiji/center/aspect/AssessAspect.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.tiji.center.aspect; - -import com.tiji.center.exception.AssessDeniedException; -import io.jsonwebtoken.Claims; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; -import org.aspectj.lang.annotation.Pointcut; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import javax.servlet.http.HttpServletRequest; - -/** - * @author 贰拾壹 - * @create 2020-05-09 11:12 - */ -@Aspect -@Component -public class AssessAspect { - @Autowired - private HttpServletRequest request; - - //用户管理需要管理员权限 - @Pointcut("execution(public * com.tiji.center.controller.UserController.*(..))") - public void controllerUser() { - } - - @Before("controllerUser()") - public void beforeUserController() { - Claims claims = (Claims) request.getAttribute("admin_claims"); - if (claims == null) { - //没有权限 - throw new AssessDeniedException("无权访问"); - } - } -} diff --git a/center/src/main/java/com/tiji/center/aspect/WebLogAspect.java b/center/src/main/java/com/tiji/center/aspect/WebLogAspect.java deleted file mode 100755 index beaefaf..0000000 --- a/center/src/main/java/com/tiji/center/aspect/WebLogAspect.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.tiji.center.aspect; - -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; -import org.aspectj.lang.annotation.Pointcut; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; -import org.springframework.web.context.request.RequestAttributes; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -import javax.servlet.http.HttpServletRequest; -import java.util.Arrays; - -/** - * @author 贰拾壹 - * @create 2019-10-11 10:29 - */ -@Aspect -@Component -public class WebLogAspect { - private final static Logger logger = LoggerFactory.getLogger(WebLogAspect.class); - - //controller日志记录 - @Pointcut("execution(public * com.tiji.center.controller.*.*(..))")//切入点描述 这个是controller包的切入点 - public void controllerLog() { - } - - @Before("controllerLog()") //在切入点的方法run之前要干的 - public void logBeforeController(JoinPoint joinPoint) { - - RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();//这个RequestContextHolder是Springmvc提供来获得请求的东西 - assert requestAttributes != null; - HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); - - logger.info( - request.getRemoteAddr() + " " + - request.getMethod() + " " + - request.getRequestURI() + " " + - request.getHeader("User-Agent") + " " + - request.getHeader("Referer") + " " + - Arrays.toString(joinPoint.getArgs()) + " " + - joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName() - ); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/AgentController.java b/center/src/main/java/com/tiji/center/controller/AgentController.java deleted file mode 100755 index 85bd8d4..0000000 --- a/center/src/main/java/com/tiji/center/controller/AgentController.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Agent; -import com.tiji.center.service.AgentService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; - -/** - * agent控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/agent") -public class AgentController { - - @Autowired - private AgentService agentService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", agentService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", agentService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = agentService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult<>(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", agentService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param agent - */ - @PostMapping - public Result add(@RequestBody Agent agent) { - agentService.add(agent); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param agent - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Agent agent, @PathVariable String id) { - agent.setId(id); - agentService.update(agent); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - agentService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - agentService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } - -} diff --git a/center/src/main/java/com/tiji/center/controller/AssetipController.java b/center/src/main/java/com/tiji/center/controller/AssetipController.java deleted file mode 100755 index 63e534b..0000000 --- a/center/src/main/java/com/tiji/center/controller/AssetipController.java +++ /dev/null @@ -1,475 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.*; -import com.tiji.center.pojo.category.CategoryTab; -import com.tiji.center.service.*; -import com.tiji.center.util.TijiHelper; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import util.IdWorker; -import util.IpRange2Ips; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.*; - -/** - * assetip控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/assetip") -public class AssetipController { - - @Autowired - private AssetipService assetipService; - @Autowired - private AssetportService assetportService; - @Autowired - private IdWorker idWorker; - @Autowired - private HostService hostService; - - @Autowired - private CheckresultService checkresultService; - @Autowired - private CheckresultVulnService checkresultVulnService; - @Autowired - private WebinfoService webinfoService; - @Autowired - private UrlService urlService; - @Autowired - private ProjectinfoService projectinfoService; - @Autowired - private WebrawdataService webrawdataService; - @Autowired - private RedisTemplate redisTemplate; - @Autowired - private CategoryTabService categoryTabService; - @Autowired - private AssetipAppsysHostdomainService assetipAppsysHostdomainService; - @Autowired - private AppsystemService appsystemService; - private String categoryCacheKey = "categoryTabCache"; - private String categoryIdNameKey = "categoryTabIdNameCache"; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", assetipService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - Assetip assetip = assetipService.findById(id); - String projectinfoid = assetip.getProjectinfoid(); - if (!StringUtils.isEmpty(projectinfoid)) { - Projectinfo projectinfo = projectinfoService.findById(projectinfoid); - assetip.setProjectname(projectinfo.getProjectname()); - } - - String tabbitmap = assetip.getTabbitmap(); - List categoryTabList = new ArrayList<>(); - if (!StringUtils.isEmpty(tabbitmap)) { - List resultList = new ArrayList<>(); - String[] splitTabs = tabbitmap.split(","); - if (redisTemplate.hasKey(categoryIdNameKey)) { - for (String tabid : splitTabs) { - resultList.add((String) redisTemplate.opsForHash().get(categoryIdNameKey, tabid)); - } - } else { - for (String tabid : splitTabs) { - CategoryTab categoryTab = categoryTabService.findById(Long.parseLong(tabid)); - if (!Objects.isNull(categoryTab)) { - String categoryTabName = categoryTab.getName(); - if (!StringUtils.isEmpty(categoryTabName)) { - resultList.add(categoryTabName); - } - } - } - } - for (String tabid : splitTabs) { - CategoryTab categoryTab = categoryTabService.findById(Long.parseLong(tabid)); - categoryTabList.add(categoryTab); - } - assetip.setTabname(String.valueOf(resultList).replaceAll("[\\[\\]]", "")); - } - - StringBuilder appsysNameBuilder = new StringBuilder(); - List hostdomainList = assetipAppsysHostdomainService.findByAssetipid(id); - for (AssetipAppsysHostdomain hostdomain : hostdomainList) { - String appsysid = hostdomain.getAppsysid(); - if (!StringUtils.isEmpty(appsysid)) { - Appsystem appsystem = appsystemService.findById(appsysid); - if (!Objects.isNull(appsystem)) { - String appsystemName = appsystem.getName(); - appsysNameBuilder.append(appsystemName).append(","); - } - } - } - assetip.setAppsysname(appsysNameBuilder.toString()); - - assetip.setTabList(categoryTabList); - return new Result(true, StatusCode.OK, "查询成功", assetip); - } - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = assetipService.findSearch(searchMap, page, size); - Map idNameMap = new HashMap<>(); - pageList.stream().parallel().forEach(assetip -> { - String projectinfoid = assetip.getProjectinfoid(); - if (!StringUtils.isEmpty(projectinfoid)) { - Projectinfo projectinfo = projectinfoService.findById(projectinfoid); - if (!Objects.isNull(projectinfo)) { - assetip.setProjectname(projectinfo.getProjectname()); - } - } - String assetipId = assetip.getId(); - - List countResultList = assetipService.findCountByIds(Collections.singletonList(assetipId)); - String ipaddressv4 = assetip.getIpaddressv4(); - if (!StringUtils.isEmpty(ipaddressv4)) { - assetip.setIpaddressv4(ipaddressv4); - } - if (!"0:0:0:0".equals(countResultList.get(0))) { - assetip.setStatistic(countResultList.get(0)); - } else { - assetip.setIpaddressv4(ipaddressv4); - } - String tabbitmap = assetip.getTabbitmap(); - if (!StringUtils.isEmpty(tabbitmap)) { - List resultList = new ArrayList<>(); - String[] splitTabs = tabbitmap.split(","); - if (redisTemplate.hasKey(categoryIdNameKey)) { - for (String id : splitTabs) { - resultList.add((String) redisTemplate.opsForHash().get(categoryIdNameKey, id)); - } - } else { - for (String id : splitTabs) { - CategoryTab categoryTab = categoryTabService.findById(Long.parseLong(id)); - if (!Objects.isNull(categoryTab)) { - String categoryTabName = categoryTab.getName(); - if (!StringUtils.isEmpty(categoryTabName)) { - resultList.add(categoryTabName); - idNameMap.put(id, categoryTabName); - } - } - } - } - assetip.setTabname(String.valueOf(resultList).replaceAll("[\\[\\]]", "")); - } - }); - if (!idNameMap.isEmpty()) { - redisTemplate.opsForHash().putAll(categoryIdNameKey, idNameMap); - } - return new Result(true, StatusCode.OK, "查询成功", new PageResult<>(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", assetipService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param assetip - */ - @PostMapping - public Result add(@RequestBody Assetip assetip) { - if (Objects.isNull(assetip.getPassivetime())) { - String ipaddressv4 = assetip.getIpaddressv4(); - Assetip assetipInDb = assetipService.findByIpaddressv4AndPassivetimeIsNull(ipaddressv4); - if (Objects.isNull(assetipInDb)) { - assetipService.add(assetip); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:ip重复"); - } - } else { - return new Result(false, StatusCode.ERROR, "增加失败:无法直接新增已下线ip,请直接将资产ip下线"); - } - } - - /** - * 修改 - * - * @param assetip - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Assetip assetip, @PathVariable String id) { - assetip.setId(id); - String sourceTabbitMap = assetip.getTabbitmap(); - if (!StringUtils.isEmpty(sourceTabbitMap)) { - String[] strings = sourceTabbitMap.split(","); - Set set = new TreeSet<>(Arrays.asList(strings)); - assetip.setTabbitmap(set.toString().replaceAll("[\\[\\]\\s]", "")); - } - assetipService.update(assetip); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * 资产ip, 资产端口, 主机信息, 位置信息, 漏洞检测结果, web信息, url信息 - * - * @param id - */ - - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - assetipService.deleteById(id); - //删除中间表 - assetipAppsysHostdomainService.deleteAllByAssetipid(id); - //删除资产端口 - List assetportList = assetportService.deleteAllByAssetipid(id); - //删除主机信息 - hostService.deleteAllByAssetipid(id); - assetportList.forEach(assetport -> { - String assetportId = assetport.getId(); - //删除漏洞检测结果 - List checkresultList = checkresultService.deleteAllByAssetportid(assetportId); - //删除web信息 - List webinfoList = webinfoService.deleteAllByPortid(assetportId); - checkresultList.forEach(checkresult -> { - String checkresultId = checkresult.getId(); - //删除检测结果的同时,删除中间表关联 - checkresultVulnService.deleteAllByCheckresultid(checkresultId); - }); - //删除url信息 - webinfoList.forEach(webinfo -> { - String webinfoId = webinfo.getId(); - //删除原始响应和头信息 - webrawdataService.deleteAllByWebinfoid(webinfoId); - urlService.deleteAllByWebinfoid(webinfoId); - }); - }); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 批量导入ip端口 - */ - @PostMapping(value = "/batchAdd") - public Result batchAdd(@RequestParam("file") MultipartFile file) { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!fileContentType.equals("text/plain")) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!suffix.equals("txt")) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - - Map> resultMap = new LinkedHashMap<>(); - String line; - Date date = new Date(); - Set ipSet = new HashSet<>(); - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8));) { - while ((line = bf.readLine()) != null) { - //有端口 - if (line.contains("[[")) { - line = line.replaceAll("\\[\\[", "@"); - line = line.replaceAll("],\\s?\\[", "!"); - line = line.replaceAll("]]", ""); - String ipp = line.split("@")[0]; - String servers = line.split("@")[1]; - List serverList = Arrays.asList(servers.split("!")); - Set resultSet = new HashSet<>(serverList); - if (resultMap.containsKey(ipp)) { - Set set = resultMap.get(ipp); - set.addAll(resultSet); - resultMap.put(ipp, set); - } else { - resultMap.put(ipp, resultSet); - } - } else { - //20201012 新增 增加无端口的ip导入格式 - //没有端口,新增ip - ipSet.addAll(IpRange2Ips.genIp(line)); - } - - } - } catch (IOException ignored) { - } - if (!resultMap.isEmpty()) { - TijiHelper.batchNmapScanResult2AssetDB(assetipService, assetportService, hostService, idWorker, resultMap); - } - if (!ipSet.isEmpty()) { - ipSet.forEach(ip -> { - Assetip assetip = assetipService.findByIpaddressv4AndPassivetimeIsNull(ip); - String assetipId; - //ip不存在,新增 - if (Objects.isNull(assetip)) { - assetipId = idWorker.nextId() + ""; - assetipService.add(new Assetip(assetipId, null, ip, null, false, false, date, null, null)); - } - }); - } - return new Result(true, StatusCode.OK, "ip端口已上传处理,请稍后查看"); - - } - - /** - * 根据ids数组查询 - * - * @param ids - * @return - */ - @PostMapping(value = "/ids") - public Result findByAssetIpIds(@RequestBody String[] ids) { - return new Result(true, StatusCode.OK, "查询成功", assetipService.findByIds(ids)); - } - - /** - * 批量导入部门ip - */ - @RequestMapping(value = "/projectinfoip/batchAdd", method = RequestMethod.POST) - public Result batchAddProjectinfoIp(@RequestParam("file") MultipartFile file) { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!fileContentType.equals("text/plain")) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!suffix.equals("txt")) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - - String line; - //20201012 优化 去除bf.close,bf放到try中 - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { - Date date = new Date(); - while ((line = bf.readLine()) != null) { - String projectinfoName = line.split("\\|")[0]; - String ipRange = line.split("\\|")[1]; - Projectinfo projectinfo = projectinfoService.findByProjectname(projectinfoName); - String projectInfoId; - if (Objects.isNull(projectinfo)) { - projectInfoId = idWorker.nextId() + ""; - projectinfoService.add(new Projectinfo(projectInfoId, null, projectinfoName, false, false, date, false)); - } else { - projectInfoId = projectinfo.getId(); - } - - Set ipSet = IpRange2Ips.genIp(ipRange); - ipSet.forEach(ip -> { - Assetip assetip = assetipService.findByIpaddressv4AndPassivetimeIsNull(ip); - String assetipId; - //System.out.println(projectInfoId + " = " + ip); - //20201012 移除 移除如果ip不存在,会新增 - //ip不存在,新增 - if (Objects.isNull(assetip)) { - //assetipId = idWorker.nextId() + ""; - //assetipService.add(new Assetip(assetipId, projectInfoId, ip, null, false, false, date, null, null)); - } else { - //ip存在 - //projectInfoId = assetip.getProjectinfoid(); - //没有项目信息 - if (Objects.isNull(assetip.getProjectinfoid()) || assetip.getProjectinfoid().isEmpty()) { - assetip.setProjectinfoid(projectInfoId); - assetipService.update(assetip); - } - } - }); - } - } catch (IOException ignored) { - } - - return new Result(true, StatusCode.OK, "项目信息ip已上传处理,请稍后查看"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - assetipService.deleteAllByIds(ids); - ids.forEach(id -> { - //删除中间表 - assetipAppsysHostdomainService.deleteAllByAssetipid(id); - //删除资产端口 - List assetportList = assetportService.deleteAllByAssetipid(id); - //删除主机信息 - hostService.deleteAllByAssetipid(id); - assetportList.forEach(assetport -> { - String assetportId = assetport.getId(); - //删除漏洞检测结果 - List checkresultList = checkresultService.deleteAllByAssetportid(assetportId); - //删除web信息 - List webinfoList = webinfoService.deleteAllByPortid(assetportId); - checkresultList.forEach(checkresult -> { - String checkresultId = checkresult.getId(); - //删除检测结果的同时,删除中间表关联 - checkresultVulnService.deleteAllByCheckresultid(checkresultId); - }); - //删除url信息 - webinfoList.forEach(webinfo -> { - String webinfoId = webinfo.getId(); - //删除原始响应和头信息 - webrawdataService.deleteAllByWebinfoid(webinfoId); - urlService.deleteAllByWebinfoid(webinfoId); - }); - }); - }); - return new Result(true, StatusCode.OK, "删除成功"); - } - -} diff --git a/center/src/main/java/com/tiji/center/controller/AssetportController.java b/center/src/main/java/com/tiji/center/controller/AssetportController.java deleted file mode 100755 index 4f1979e..0000000 --- a/center/src/main/java/com/tiji/center/controller/AssetportController.java +++ /dev/null @@ -1,350 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.*; -import com.tiji.center.pojo.category.CategoryTab; -import com.tiji.center.service.*; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.*; - -import java.util.*; - -/** - * assetport控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/assetport") -public class AssetportController { - - @Autowired - private AssetportService assetportService; - - @Autowired - private AssetipService assetipService; - - @Autowired - private CheckresultService checkresultService; - @Autowired - private CheckresultVulnService checkresultVulnService; - @Autowired - private WebinfoService webinfoService; - @Autowired - private UrlService urlService; - @Autowired - private RedisTemplate redisTemplate; - @Autowired - private CategoryTabService categoryTabService; - @Autowired - private AssetipAppsysHostdomainService assetipAppsysHostdomainService; - @Autowired - private AppsystemService appsystemService; - private String categoryCacheKey = "categoryTabCache"; - private String categoryIdNameKey = "categoryTabIdNameCache"; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", assetportService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - Assetport assetport = assetportService.findById(id); - String tabbitmap = assetport.getTabbitmap(); - List categoryTabList = new ArrayList<>(); - if (!StringUtils.isEmpty(tabbitmap)) { - List resultList = new ArrayList<>(); - String[] splitTabs = tabbitmap.split(","); - if (redisTemplate.hasKey(categoryIdNameKey)) { - for (String tabid : splitTabs) { - resultList.add((String) redisTemplate.opsForHash().get(categoryIdNameKey, tabid)); - } - } else { - for (String tabid : splitTabs) { - CategoryTab categoryTab = categoryTabService.findById(Long.parseLong(tabid)); - if (!Objects.isNull(categoryTab)) { - String categoryTabName = categoryTab.getName(); - if (!StringUtils.isEmpty(categoryTabName)) { - resultList.add(categoryTabName); - } - } - } - } - for (String tabid : splitTabs) { - CategoryTab categoryTab = categoryTabService.findById(Long.parseLong(tabid)); - categoryTabList.add(categoryTab); - } - assetport.setTabname(String.valueOf(resultList).replaceAll("[\\[\\]]", "")); - } - - StringBuilder appsysNameBuilder = new StringBuilder(); - List hostdomainList = assetipAppsysHostdomainService.findByAssetportid(id); - for (AssetipAppsysHostdomain hostdomain : hostdomainList) { - String appsysid = hostdomain.getAppsysid(); - if (!StringUtils.isEmpty(appsysid)) { - Appsystem appsystem = appsystemService.findById(appsysid); - if (!Objects.isNull(appsystem)) { - String appsystemName = appsystem.getName(); - appsysNameBuilder.append(appsystemName).append(","); - } - } - } - assetport.setAppsysname(appsysNameBuilder.toString()); - - - assetport.setTabList(categoryTabList); - return new Result(true, StatusCode.OK, "查询成功", assetport); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - //根据ip查询端口 - List assetipIdList = new ArrayList<>(); - if (searchMap.containsKey("assetip")) { - //ip -> assetportid - String ipaddressv4 = (String) searchMap.get("assetip"); - Map ipSearchMap = new HashMap<>(); - ipSearchMap.put("ipaddressv4", ipaddressv4); - List assetipList = assetipService.findSearch(ipSearchMap); - assetipList.forEach(ip -> { - String ipId = ip.getId(); - assetipIdList.add(ipId); - }); - searchMap.put("assetipid", assetipIdList); - } - - - Page pageList = assetportService.findSearch(searchMap, page, size); - Map idNameMap = new HashMap<>(); - pageList.stream().parallel().forEach(assetport -> { - String assetipid = assetport.getAssetipid(); - if (!StringUtils.isEmpty(assetipid)) { - Assetip assetip = assetipService.findById(assetipid); - if (!Objects.isNull(assetip)) { - assetport.setAssetipid(assetip.getIpaddressv4()); - } - } - String assetportId = assetport.getId(); - List countResultList = assetportService.findCountByIds(Collections.singletonList(assetportId)); - String port = assetport.getPort(); - if (!StringUtils.isEmpty(port)) { - assetport.setPort(port); - } - if (!"0:0".equals(countResultList.get(0))) { - assetport.setStatistic(countResultList.get(0)); - } - - String tabbitmap = assetport.getTabbitmap(); - if (!StringUtils.isEmpty(tabbitmap)) { - List resultList = new ArrayList<>(); - String[] splitTabs = tabbitmap.split(","); - if (redisTemplate.hasKey(categoryIdNameKey)) { - for (String id : splitTabs) { - resultList.add((String) redisTemplate.opsForHash().get(categoryIdNameKey, id)); - } - } else { - for (String id : splitTabs) { - CategoryTab categoryTab = categoryTabService.findById(Long.parseLong(id)); - if (!Objects.isNull(categoryTab)) { - String categoryTabName = categoryTab.getName(); - if (!StringUtils.isEmpty(categoryTabName)) { - resultList.add(categoryTabName); - } - } - } - } - assetport.setTabname(String.valueOf(resultList).replaceAll("[\\[\\]]", "")); - } - - }); - if (!idNameMap.isEmpty()) { - redisTemplate.opsForHash().putAll(categoryIdNameKey, idNameMap); - } - return new Result(true, StatusCode.OK, "查询成功", new PageResult<>(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", assetportService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param assetport - */ - @PostMapping - public Result add(@RequestBody Assetport assetport) { - if (Objects.isNull(assetport.getDowntime())) { - String port = assetport.getPort(); - Assetport assetportInDb = assetportService.findByAssetipidAndPortAndDowntimeIsNull(assetport.getAssetipid(), port); - if (Objects.isNull(assetportInDb)) { - assetportService.add(assetport); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:端口重复"); - } - } else { - return new Result(false, StatusCode.ERROR, "增加失败:无法直接新增已关闭端口,请直接将资产端口关闭"); - } - } - - /** - * 修改 - * - * @param assetport - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Assetport assetport, @PathVariable String id) { - assetport.setId(id); - String sourceTabbitMap = assetport.getTabbitmap(); - if (!StringUtils.isEmpty(sourceTabbitMap)) { - String[] strings = sourceTabbitMap.split(","); - Set set = new TreeSet<>(Arrays.asList(strings)); - assetport.setTabbitmap(set.toString().replaceAll("[\\[\\]\\s]", "")); - } - assetportService.update(assetport); - return new Result(true, StatusCode.OK, "修改成功"); - } - - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - assetportService.deleteById(id); - //中间件表置空 - assetportService.updateMiddByAssetportidSetAssetportid2Null(id); - //删除漏洞检测结果 - List checkresultList = checkresultService.deleteAllByAssetportid(id); - //删除web信息 - List webinfoList = webinfoService.deleteAllByPortid(id); - checkresultList.forEach(checkresult -> { - String checkresultId = checkresult.getId(); - //删除检测结果的同时,删除中间表关联 - checkresultVulnService.deleteAllByCheckresultid(checkresultId); - }); - //删除url信息 - webinfoList.forEach(webinfo -> { - String webinfoId = webinfo.getId(); - urlService.deleteAllByWebinfoid(webinfoId); - }); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据id数组查询 - * - * @param ids - * @return - */ - @PostMapping(value = "/ids") - public Result findByAssetIpIds(@RequestBody String[] ids) { - return new Result(true, StatusCode.OK, "查询成功", assetportService.findByIds(ids)); - } - - /** - * 查询service并去重 - * - * @return List - */ - @RequestMapping(value = "/service", method = RequestMethod.GET) - public Result findAllDistinctService() { - return new Result(true, StatusCode.OK, "查询成功", assetportService.findAllDistinctService()); - } - - /** - * 查询version并去重 - * - * @return List - */ - @RequestMapping(value = "/version", method = RequestMethod.GET) - public Result findAllDistinctVersion() { - return new Result(true, StatusCode.OK, "查询成功", assetportService.findAllDistinctVersion()); - } - - /** - * 根据assetipid查询 - * - * @param assetipid assetipid - * @return - */ - @RequestMapping(value = "/assetip/{assetipid}", method = RequestMethod.GET) - public Result findAllByAssetipid(@PathVariable String assetipid) { - return new Result(true, StatusCode.OK, "查询成功", assetportService.findAllByAssetipid(assetipid)); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - assetportService.deleteAllByIds(ids); - ids.forEach(id -> { - //删除漏洞检测结果 - List checkresultList = checkresultService.deleteAllByAssetportid(id); - //删除web信息 - List webinfoList = webinfoService.deleteAllByPortid(id); - checkresultList.forEach(checkresult -> { - String checkresultId = checkresult.getId(); - //删除检测结果的同时,删除中间表关联 - checkresultVulnService.deleteAllByCheckresultid(checkresultId); - }); - //删除url信息 - webinfoList.forEach(webinfo -> { - String webinfoId = webinfo.getId(); - urlService.deleteAllByWebinfoid(webinfoId); - }); - }); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据id数组查询数量 - * - * @param countbyids - * @return - */ - @RequestMapping(value = "/countbyids", method = RequestMethod.POST) - public Result findCountByIds(@RequestBody List countbyids) { - return new Result(true, StatusCode.OK, "查询成功", assetportService.findCountByIds(countbyids)); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/BaseExceptionHandler.java b/center/src/main/java/com/tiji/center/controller/BaseExceptionHandler.java deleted file mode 100755 index c5e9dea..0000000 --- a/center/src/main/java/com/tiji/center/controller/BaseExceptionHandler.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.tiji.center.controller; - -import entity.Result; -import entity.StatusCode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; -import util.ExcpUtil; - -import java.util.Objects; - -/** - * 统一异常处理类 - * - * @author 贰拾壹 - */ -@ControllerAdvice -public class BaseExceptionHandler { - private final static Logger logger = LoggerFactory.getLogger(BaseExceptionHandler.class); - - @ExceptionHandler(value = Exception.class) - @ResponseBody - public Result error(Exception e) { - if (!Objects.isNull(e)) { - logger.error(ExcpUtil.buildErrorMessage(e)); - //e.printStackTrace(); - - if (e.toString().contains("ObjectAlreadyExistsException")) { - return new Result(false, StatusCode.REMOTE_ERROR, "cron任务已存在"); - } - if ("无权访问".equals(e.getMessage())) { - return new Result(false, StatusCode.ACCESS_ERROR, "无权访问"); - } - if ("token已过期".equals(e.getMessage())) { - return new Result(false, StatusCode.TOKEN_EXPIRED_ERROR, "token已过期"); - } - if ("非法token".equals(e.getMessage())) { - return new Result(false, StatusCode.ILLEGAL_TOKEN_ERROR, "非法token"); - } - if ("未登录".equals(e.getMessage())) { - return new Result(false, StatusCode.ACCESS_ERROR, "未登录"); - } - } - return new Result(false, StatusCode.ERROR, "执行出错"); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/CategorysecondController.java b/center/src/main/java/com/tiji/center/controller/CategorysecondController.java deleted file mode 100755 index 4aebb4c..0000000 --- a/center/src/main/java/com/tiji/center/controller/CategorysecondController.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Categorysecond; -import com.tiji.center.pojo.Categorytop; -import com.tiji.center.service.CategorysecondService; -import com.tiji.center.service.CategorytopService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * categorysecond控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/categorysecond") -public class CategorysecondController { - - @Autowired - private CategorysecondService categorysecondService; - @Autowired - private CategorytopService categorytopService; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", categorysecondService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", categorysecondService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = categorysecondService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(categorysecond -> { - String categorytopid = categorysecond.getCategorytopid(); - if (!StringUtils.isEmpty(categorytopid)) { - Categorytop categorytop = categorytopService.findById(categorytopid); - if (!Objects.isNull(categorytop)) { - categorysecond.setCategorytopid(categorytop.getName()); - } - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", categorysecondService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param categorysecond - */ - @PostMapping - public Result add(@RequestBody Categorysecond categorysecond) { - //categorysecondService.add(categorysecond); - //return new Result(true, StatusCode.OK,"增加成功"); - String categorysecondName = categorysecond.getName(); - Categorysecond categorysecondInDb = categorysecondService.findByName(categorysecondName); - if (Objects.isNull(categorysecondInDb)) { - categorysecondService.add(categorysecond); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:二级分类名称重复"); - } - } - - /** - * 修改 - * - * @param categorysecond - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Categorysecond categorysecond, @PathVariable String id) { - categorysecond.setId(id); - categorysecondService.update(categorysecond); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - categorysecondService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - categorysecondService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据id数组查询 - * - * @param ids - * @return - */ - @PostMapping(value = "/ids") - public Result findByCategorysecondIds(@RequestBody String[] ids) { - return new Result(true, StatusCode.OK, "查询成功", categorysecondService.findByIds(ids)); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/CategorytopController.java b/center/src/main/java/com/tiji/center/controller/CategorytopController.java deleted file mode 100755 index 96a0ef2..0000000 --- a/center/src/main/java/com/tiji/center/controller/CategorytopController.java +++ /dev/null @@ -1,139 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Categorysecond; -import com.tiji.center.pojo.Categorytop; -import com.tiji.center.service.CategorysecondService; -import com.tiji.center.service.CategorytopService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * categorytop控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/categorytop") -public class CategorytopController { - - @Autowired - private CategorytopService categorytopService; - @Autowired - private CategorysecondService categorysecondService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", categorytopService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", categorytopService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = categorytopService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", categorytopService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param categorytop - */ - @PostMapping - public Result add(@RequestBody Categorytop categorytop) { - String categorytopName = categorytop.getName(); - Categorytop categorytopInDb = categorytopService.findByName(categorytopName); - if (Objects.isNull(categorytopInDb)) { - categorytopService.add(categorytop); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:名称重复"); - } - - } - - /** - * 修改 - * - * @param categorytop - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Categorytop categorytop, @PathVariable String id) { - categorytop.setId(id); - categorytopService.update(categorytop); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - categorytopService.deleteById(id); - //同时把second的topid置空 - Categorysecond categorysecond = categorysecondService.findByCategorytopid(id); - if (!Objects.isNull(categorysecond)) { - categorysecond.setCategorytopid(null); - categorysecondService.update(categorysecond); - } - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - categorysecondService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/CharController.java b/center/src/main/java/com/tiji/center/controller/CharController.java deleted file mode 100755 index 8e585fc..0000000 --- a/center/src/main/java/com/tiji/center/controller/CharController.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.service.StatisticsService; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * char控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/char") -public class CharController { - - @Autowired - private StatisticsService statisticsService; - - /** - * 查询ip端口数 - * - * @return - */ - @RequestMapping(value = "/ipportcount", method = RequestMethod.GET) - public Result findIpPortCount() { - List ipPortCountList = statisticsService.findIpPortCount(); - return getResult(ipPortCountList); - } - - /** - * 查询未下线ip端口数 - * - * @return - */ - @RequestMapping(value = "/ipportcountonline", method = RequestMethod.GET) - public Result findIpPortCountOnline() { - List ipPortCountList = statisticsService.findIpPortCountOnline(); - return getResult(ipPortCountList); - } - - public Result getResult(List ipPortCountList) { - Map singleMap; - List> resulList = new ArrayList<>(); - for (String ipportcount : ipPortCountList) { - singleMap = new HashMap<>(); - String name = ipportcount.split(",")[0]; - String value = ipportcount.split(",")[1]; - singleMap.put("name", name); - singleMap.put("value", value); - resulList.add(singleMap); - } - return new Result(true, StatusCode.OK, "查询成功", resulList); - } - - - /** - * 查询服务数 - * - * @return - */ - @RequestMapping(value = "/servicecount", method = RequestMethod.GET) - public Result findServiceCount() { - List ipPortCountList = statisticsService.findServiceCount(); - return getResult(ipPortCountList); - } - - /** - * 查询未下线服务数 - * - * @return - */ - @RequestMapping(value = "/servicecountonline", method = RequestMethod.GET) - public Result findServiceCountOnline() { - List ipPortCountList = statisticsService.findServiceCountOnline(); - return getResult(ipPortCountList); - } - - /** - * 查询版本 - * - * @return - */ - @RequestMapping(value = "/versioncount", method = RequestMethod.GET) - public Result findVersionCount() { - List ipPortCountList = statisticsService.findVersionCount(); - return getResult(ipPortCountList); - } - - /** - * 查询未下线版本数 - * - * @return - */ - @RequestMapping(value = "/versioncountonline", method = RequestMethod.GET) - public Result findVersionCountOnline() { - List ipPortCountList = statisticsService.findVersionCountOnline(); - return getResult(ipPortCountList); - } - - /** - * 查询webinfo中server数 - * - * @return - */ - @RequestMapping(value = "/webinfoservercount", method = RequestMethod.GET) - public Result findWebinfoServerCount() { - List ipPortCountList = statisticsService.findWebinfoServerCount(); - return getResult(ipPortCountList); - } - - /** - * 查询高危端口数 - * - * @return - */ - @RequestMapping(value = "/riskportcount", method = RequestMethod.GET) - public Result findRiskPortCount() { - List ipPortCountList = statisticsService.findRiskPortCount(); - return getResult(ipPortCountList); - } - - /** - * 查询未下线高危端口数 - * - * @return - */ - @RequestMapping(value = "/riskportcountonline", method = RequestMethod.GET) - public Result findRiskPortCountOnline() { - List ipPortCountList = statisticsService.findRiskPortCountOnline(); - return getResult(ipPortCountList); - } - - /** - * 查询高危服务数 - * - * @return - */ - @RequestMapping(value = "/riskservicecount", method = RequestMethod.GET) - public Result findRiskServiceCount() { - List ipPortCountList = statisticsService.findRiskServiceCount(); - return getResult(ipPortCountList); - } - - /** - * 查询未下线高危服务数 - * - * @return - */ - @RequestMapping(value = "/riskservicecountonline", method = RequestMethod.GET) - public Result findRiskServiceCountOnline() { - List ipPortCountList = statisticsService.findRiskServiceCountOnline(); - return getResult(ipPortCountList); - } - - /** - * 查询高危版本数 - * - * @return - */ - @RequestMapping(value = "/riskversioncount", method = RequestMethod.GET) - public Result findRiskVersionCount() { - List ipPortCountList = statisticsService.findRiskVersionCount(); - return getResult(ipPortCountList); - } - - /** - * 查询未下线高危版本数 - * - * @return - */ - @RequestMapping(value = "/riskversioncountonline", method = RequestMethod.GET) - public Result findRiskVersionCountOnline() { - List ipPortCountList = statisticsService.findRiskVersionCountOnline(); - return getResult(ipPortCountList); - } - - - /** - * 查询所有风险数 - * - * @return - */ - @RequestMapping(value = "/riskcount", method = RequestMethod.GET) - public Result findRiskCount() { - List ipPortCountList = statisticsService.findRiskCount(); - return getResult(ipPortCountList); - } - - - /** - * 查询未修复风险数 - * - * @return - */ - @RequestMapping(value = "/riskcountonline", method = RequestMethod.GET) - public Result findRiskCountOnline() { - List ipPortCountList = statisticsService.findRiskCountOnline(); - return getResult(ipPortCountList); - } - - /** - * 查询所有漏洞数 - * - * @return - */ - @RequestMapping(value = "/riskvulncount", method = RequestMethod.GET) - public Result findRiskVulnCount() { - List ipPortCountList = statisticsService.findRiskVulnCount(); - return getResult(ipPortCountList); - } - - - /** - * 查询未修复漏洞数 - * - * @return - */ - @RequestMapping(value = "/riskvulncountonline", method = RequestMethod.GET) - public Result findRiskVulnCountOnline() { - List ipPortCountList = statisticsService.findRiskVulnCountOnline(); - return getResult(ipPortCountList); - } - - /** - * 查询statistics - * - * @return - */ - @RequestMapping(value = "/statistics", method = RequestMethod.GET) - public Result findAllStatistics() { - return new Result(true, StatusCode.OK, "查询成功", statisticsService.findAll()); - } - -} diff --git a/center/src/main/java/com/tiji/center/controller/CheckresultController.java b/center/src/main/java/com/tiji/center/controller/CheckresultController.java deleted file mode 100755 index ef7a8d9..0000000 --- a/center/src/main/java/com/tiji/center/controller/CheckresultController.java +++ /dev/null @@ -1,317 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.*; -import com.tiji.center.service.*; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.*; -import util.IdWorker; - -import java.util.*; - -/** - * checkresult控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/checkresult") -public class CheckresultController { - - @Autowired - private CheckresultService checkresultService; - @Autowired - private CheckresultVulnService checkresultVulnService; - @Autowired - private AssetportService assetportService; - @Autowired - private AssetipService assetipService; - @Autowired - private VulnService vulnService; - @Autowired - private IdWorker idWorker; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", checkresultService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - Checkresult checkresult = checkresultService.findById(id); - String assetportid = checkresult.getAssetportid(); - Assetport assetport = assetportService.findById(assetportid); - String assetipid = assetport.getAssetipid(); - checkresult.setAssetipid(assetipid); - - List checkresultVulnList = checkresultVulnService.findAllByCheckresultid(id); - String vulnid = checkresultVulnList.get(0).getVulnid(); - checkresult.setVulnid(vulnid); - - return new Result(true, StatusCode.OK, "查询成功", checkresult); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - //根据ip查询漏洞 - List vulnPortIdList = new ArrayList<>(); - if (searchMap.containsKey("assetip")) { - //ip -> assetportid - String ipaddressv4 = (String) searchMap.get("assetip"); - Map ipSearchMap = new HashMap<>(); - ipSearchMap.put("ipaddressv4", ipaddressv4); - List assetipList = assetipService.findSearch(ipSearchMap); - assetipList.forEach(ip -> { - String ipId = ip.getId(); - List assetportList = assetportService.findAllByAssetipid(ipId); - assetportList.forEach(assetport -> { - String assetportId = assetport.getId(); - List checkresultList = checkresultService.findAllByAssetportid(assetportId); - checkresultList.forEach(checkresult -> { - String checkresultAssetportid = checkresult.getAssetportid(); - vulnPortIdList.add(checkresultAssetportid); - }); - }); - - }); - searchMap.put("assetportid", vulnPortIdList); - } - - //根据端口查询漏洞 - if (searchMap.containsKey("assetport")) { - String port = (String) searchMap.get("assetport"); - Map portSearchMap = new HashMap<>(); - portSearchMap.put("port", port); - List assetportList = assetportService.findSearch(portSearchMap); - assetportList.forEach(assetport -> { - String assetportId = assetport.getId(); - List checkresultList = checkresultService.findAllByAssetportid(assetportId); - checkresultList.forEach(checkresult -> { - String checkresultAssetportid = checkresult.getAssetportid(); - vulnPortIdList.add(checkresultAssetportid); - }); - }); - searchMap.put("assetportid", vulnPortIdList); - } - - //根据漏洞名称查询漏洞 - if (searchMap.containsKey("vulname")) { - String vulname = (String) searchMap.get("vulname"); - Map vulNameSearchMap = new HashMap<>(); - vulNameSearchMap.put("name", vulname); - List vulnList = vulnService.findSearch(vulNameSearchMap); - List checkResultIdList = new LinkedList<>(); - vulnList.forEach(vuln -> { - String vulnId = vuln.getId(); - checkResultIdList.addAll(checkresultVulnService.findAllCheckResultIdByVulnid(vulnId)); - - }); - searchMap.put("id", checkResultIdList); - } - - Page pageList = checkresultService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(checkresult -> { - String id = checkresult.getId(); - String assetportid = checkresult.getAssetportid(); - Assetport assetport = assetportService.findById(assetportid); - checkresult.setAssetportid(assetport.getPort()); - String assetipid = assetport.getAssetipid(); - - Assetip assetip = assetipService.findById(assetipid); - checkresult.setAssetip(assetip.getIpaddressv4()); - - - List checkresultVulnList = checkresultVulnService.findAllByCheckresultid(id); - String vulnid = checkresultVulnList.get(0).getVulnid(); - Vuln vuln = vulnService.findById(vulnid); - checkresult.setVulname(vuln.getName()); - - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", checkresultService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param checkresult - */ - @PostMapping - public Result add(@RequestBody Checkresult checkresult) { - String assetipid = checkresult.getAssetipid(); - String assetportid = checkresult.getAssetportid(); - System.out.println("assetportid: " + assetportid); - if (StringUtils.isEmpty(checkresult.getVulnid()) || StringUtils.isEmpty(assetportid) || StringUtils.isEmpty(assetipid)) { - return new Result(false, StatusCode.ERROR, "ip端口漏洞名称不能为空"); - } - Assetport assetport = assetportService.findByIdAndAndAssetipidAndDowntimeIsNull(assetportid, assetipid); - if (Objects.isNull(assetport)) { - String portTemp = assetportid; - assetportid = idWorker.nextId() + ""; - assetportService.add(new Assetport(assetportid, assetipid, portTemp, null, null, null, null, null, null, new Date(), null, null)); - } else { - assetportid = assetport.getId(); - } - String checkresultid = idWorker.nextId() + ""; - checkresult.setId(checkresultid); - checkresult.setAssetportid(assetportid); - checkresultVulnService.add(new CheckresultVuln(idWorker.nextId() + "", checkresultid, checkresult.getVulnid())); - checkresultService.add(checkresult); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param checkresult - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Checkresult checkresult, @PathVariable String id) { - checkresult.setId(id); - if (StringUtils.isEmpty(checkresult.getVulnid()) || StringUtils.isEmpty(checkresult.getAssetportid()) || StringUtils.isEmpty(checkresult.getAssetipid())) { - return new Result(false, StatusCode.ERROR, "ip端口漏洞名称不能为空"); - } - checkresultService.update(checkresult); - return new Result(true, StatusCode.OK, "修改成功"); - } - - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - checkresultService.deleteById(id); - //删除检测结果的同时,删除中间表关联 - checkresultVulnService.deleteAllByCheckresultid(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据assetportid查询 - * - * @param assetportid assetportid - * @return - */ - @RequestMapping(value = "/assetport/{assetportid}", method = RequestMethod.GET) - public Result findAllByAssetportid(@PathVariable String assetportid) { - List checkresultList = checkresultService.findAllByAssetportid(assetportid); - checkresultList.stream().parallel().forEach(checkresult -> { - String id = checkresult.getId(); - List vulnList = checkresultVulnService.findAllByCheckresultid(id); - if (!vulnList.isEmpty()) { - String vulnid = vulnList.get(0).getVulnid(); - Vuln vuln = vulnService.findById(vulnid); - if (!Objects.isNull(vuln)) { - String vulnName = vuln.getName(); - if (!StringUtils.isEmpty(vulnName)) { - checkresult.setVulname(vulnName); - } - } - } - }); - return new Result(true, StatusCode.OK, "查询成功", checkresultList); - } - - /** - * 根据ids查询漏洞 - * - * @param ids ids - * @return id-漏洞名称 - */ - @PostMapping(value = "/ids") - public Result findAllByIds(@RequestBody String[] ids) { - return new Result(true, StatusCode.OK, "查询成功", checkresultService.findAllByIds(ids)); - } - - /** - * 根据assetportids查询 - * - * @param assetportids assetportids - * @return - */ - @RequestMapping(value = "/assetportids/{assetportids}", method = RequestMethod.GET) - public Result findAllByAssetportIds(@PathVariable String[] assetportids) { - List checkresultList = checkresultService.findAllByAssetportIds(assetportids); - checkresultList.stream().parallel().forEach(checkresult -> { - String id = checkresult.getId(); - List vulnList = checkresultVulnService.findAllByCheckresultid(id); - if (!vulnList.isEmpty()) { - String vulnid = vulnList.get(0).getVulnid(); - Vuln vuln = vulnService.findById(vulnid); - if (!Objects.isNull(vuln)) { - String vulnName = vuln.getName(); - if (!StringUtils.isEmpty(vulnName)) { - checkresult.setVulname(vulnName); - } - } - } - }); - return new Result(true, StatusCode.OK, "查询成功", checkresultList); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - checkresultService.deleteAllByIds(ids); - ids.forEach(id -> { -// checkresultService.deleteById(id); - //删除检测结果的同时,删除中间表关联 - checkresultVulnService.deleteAllByCheckresultid(id); - }); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据id查询漏洞 - * - * @param id - * @return 漏洞名称 - */ - @RequestMapping(value = "/vulname/{id}", method = RequestMethod.GET) - public Result findVulNameById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", checkresultService.findVulNameById(id)); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/CheckresultVulnController.java b/center/src/main/java/com/tiji/center/controller/CheckresultVulnController.java deleted file mode 100755 index e82cc63..0000000 --- a/center/src/main/java/com/tiji/center/controller/CheckresultVulnController.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Checkresult; -import com.tiji.center.pojo.CheckresultVuln; -import com.tiji.center.pojo.Vuln; -import com.tiji.center.service.CheckresultService; -import com.tiji.center.service.CheckresultVulnService; -import com.tiji.center.service.VulnService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.Map; -import java.util.Objects; - -/** - * checkresultVuln控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/checkresultVuln") -public class CheckresultVulnController { - - @Autowired - private CheckresultVulnService checkresultVulnService; - @Autowired - private CheckresultService checkresultService; - @Autowired - private VulnService vulnService; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", checkresultVulnService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", checkresultVulnService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = checkresultVulnService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(checkresultVuln -> { - String vulnid = checkresultVuln.getVulnid(); - String checkresultid = checkresultVuln.getCheckresultid(); - if (!StringUtils.isEmpty(vulnid)) { - Vuln vuln = vulnService.findById(vulnid); - if (!Objects.isNull(vuln)) { - checkresultVuln.setVulnid(vuln.getName()); - } - } - if (!StringUtils.isEmpty(checkresultid)) { - Checkresult checkresult = checkresultService.findById(checkresultid); - if (!Objects.isNull(checkresult)) { - checkresultVuln.setCheckresultid(checkresult.getName()); - } - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", checkresultVulnService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param checkresultVuln - */ - @PostMapping - public Result add(@RequestBody CheckresultVuln checkresultVuln) { - checkresultVulnService.add(checkresultVuln); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param checkresultVuln - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody CheckresultVuln checkresultVuln, @PathVariable String id) { - checkresultVuln.setId(id); - checkresultVulnService.update(checkresultVuln); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - checkresultVulnService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody String[] ids) { - for (String id : ids) { - checkresultVulnService.deleteById(id); - } - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据id数组查询 - * - * @param ids - * @return - */ - @PostMapping(value = "/ids") - public Result findByAssetIpIds(@RequestBody String[] ids) { - return new Result(true, StatusCode.OK, "查询成功", checkresultVulnService.findByIds(ids)); - } - -} diff --git a/center/src/main/java/com/tiji/center/controller/ContactController.java b/center/src/main/java/com/tiji/center/controller/ContactController.java deleted file mode 100755 index 382bbae..0000000 --- a/center/src/main/java/com/tiji/center/controller/ContactController.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Contact; -import com.tiji.center.pojo.ContactProjectinfo; -import com.tiji.center.service.ContactProjectinfoService; -import com.tiji.center.service.ContactService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; -import util.IdWorker; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * contact控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/contact") -public class ContactController { - - @Autowired - private ContactService contactService; - - @Autowired - private ContactProjectinfoService contactProjectinfoService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", contactService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", contactService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = contactService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", contactService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param contact - */ - @PostMapping - public Result add(@RequestBody Contact contact) { - Contact contactInDb = contactService.findByNameAndEmail(contact.getName(), contact.getEmail()); - if (Objects.isNull(contactInDb)) { - contactService.add(contact); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:联系人和邮箱重复"); - } - } - - /** - * 修改 - * - * @param contact - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Contact contact, @PathVariable String id) { - contact.setId(id); - contactService.update(contact); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - contactService.deleteById(id); - //删除联系人的同时,删除与项目信息关联 - contactProjectinfoService.deleteAllByContactid(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - contactService.deleteAllByIds(ids); - ids.forEach(id -> { - //删除联系人的同时,删除与项目信息关联 - contactProjectinfoService.deleteAllByContactid(id); - }); - return new Result(true, StatusCode.OK, "删除成功"); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/ContactProjectinfoController.java b/center/src/main/java/com/tiji/center/controller/ContactProjectinfoController.java deleted file mode 100755 index 357be1f..0000000 --- a/center/src/main/java/com/tiji/center/controller/ContactProjectinfoController.java +++ /dev/null @@ -1,163 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Contact; -import com.tiji.center.pojo.ContactProjectinfo; -import com.tiji.center.pojo.Department; -import com.tiji.center.pojo.Projectinfo; -import com.tiji.center.service.ContactProjectinfoService; -import com.tiji.center.service.ContactService; -import com.tiji.center.service.ProjectinfoService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * contactProjectinfo控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/contactProjectinfo") -public class ContactProjectinfoController { - - @Autowired - private ContactProjectinfoService contactProjectinfoService; - @Autowired - private ContactService contactService; - @Autowired - private ProjectinfoService projectinfoService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", contactProjectinfoService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", contactProjectinfoService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = contactProjectinfoService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(contactProjectinfo -> { - String contactid = contactProjectinfo.getContactid(); - if (!StringUtils.isEmpty(contactid)) { - Contact contact = contactService.findById(contactid); - if (!Objects.isNull(contact)) { - contactProjectinfo.setContactid(contact.getName()); - } - } - String projectinfoid = contactProjectinfo.getProjectinfoid(); - if (!StringUtils.isEmpty(projectinfoid)) { - Projectinfo projectinfo = projectinfoService.findById(projectinfoid); - if (!Objects.isNull(projectinfo)) { - contactProjectinfo.setProjectinfoid(projectinfo.getProjectname()); - } - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", contactProjectinfoService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param contactProjectinfo - */ - @PostMapping - public Result add(@RequestBody ContactProjectinfo contactProjectinfo) { - ContactProjectinfo contactProjectinfoInDb = contactProjectinfoService.findByContactidAndProjectinfoid(contactProjectinfo.getContactid(), contactProjectinfo.getProjectinfoid()); - if (Objects.isNull(contactProjectinfoInDb)) { - contactProjectinfoService.add(contactProjectinfo); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:联系人和项目信息重复"); - } - } - - /** - * 修改 - * - * @param contactProjectinfo - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody ContactProjectinfo contactProjectinfo, @PathVariable String id) { - contactProjectinfo.setId(id); - contactProjectinfoService.update(contactProjectinfo); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - contactProjectinfoService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - contactProjectinfoService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据projectinfoid查询 - * - * @param projectinfoid projectinfoid - * @return - */ - @RequestMapping(value = "/projectinfo/{projectinfoid}", method = RequestMethod.GET) - public Result findAllByProjectinfoid(@PathVariable String projectinfoid) { - return new Result(true, StatusCode.OK, "查询成功", contactProjectinfoService.findAllByProjectinfoid(projectinfoid)); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/CronjobController.java b/center/src/main/java/com/tiji/center/controller/CronjobController.java deleted file mode 100755 index 3a2b502..0000000 --- a/center/src/main/java/com/tiji/center/controller/CronjobController.java +++ /dev/null @@ -1,228 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Cronjob; -import com.tiji.center.schedule.quartz.QuartzJob; -import com.tiji.center.schedule.quartz.QuartzJobService; -import com.tiji.center.service.CronjobService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.apache.commons.lang3.StringUtils; -import org.quartz.*; -import org.quartz.impl.triggers.CronTriggerImpl; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.*; - -/** - * cronjob控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/cronjob") -public class CronjobController { - - private static final Map JOB_CLASS_STRING_WHITELIST_MAP; - - static { - JOB_CLASS_STRING_WHITELIST_MAP = new HashMap<>(); - JOB_CLASS_STRING_WHITELIST_MAP.put("任务状态监控", "TaskStatusMonitor"); - JOB_CLASS_STRING_WHITELIST_MAP.put("agent心跳包监控", "AgentHeartbeatMonitor"); - JOB_CLASS_STRING_WHITELIST_MAP.put("邮件资产报告", "AssetNotify"); - JOB_CLASS_STRING_WHITELIST_MAP.put("邮件漏洞报告", "VulnNotify"); - JOB_CLASS_STRING_WHITELIST_MAP.put("每天执行一次的任务", "MidnightTask"); - JOB_CLASS_STRING_WHITELIST_MAP.put("统计报表数据", "Statistics"); - JOB_CLASS_STRING_WHITELIST_MAP.put("IM通知", "IMNotify"); - } - - @Autowired - private CronjobService cronjobService; - @Autowired - private QuartzJobService quartzJobService; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", cronjobService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", cronjobService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = cronjobService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(cronjob -> { - String cronjobName = cronjob.getName(); - String jobClassString = JOB_CLASS_STRING_WHITELIST_MAP.get(cronjobName); - String jobClassName = jobClassString + "Scheduler"; - try { - String triggerStates = quartzJobService.getTriggerStates(jobClassName); - cronjob.setJobstate(triggerStates); - } catch (SchedulerException ignored) { - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", cronjobService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param cronjob - */ - //@PostMapping - public Result add(@RequestBody Cronjob cronjob) { - cronjobService.add(cronjob); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改,先删除,后增加 - * - * @param cronjob - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Cronjob cronjob, @PathVariable String id) throws ClassNotFoundException, SchedulerException, ParseException { - String cronjobName = cronjob.getName(); - if (!JOB_CLASS_STRING_WHITELIST_MAP.containsKey(cronjobName)) { - return new Result(false, StatusCode.ERROR, "修改失败"); - } - - String cronExpression = cronjob.getCronexpression(); - if (!CronExpression.isValidExpression(cronExpression)) { - return new Result(false, StatusCode.ERROR, "修改失败:Cron表达式错误"); - } - boolean errIM = lessThanMinInterval("IM通知", cronjobName, cronExpression, 4L); - if (errIM) { - return new Result(false, StatusCode.ERROR, "IM通知时间间隔不能小于4秒"); - } - boolean errAssetMail = lessThanMinInterval("邮件资产报告", cronjobName, cronExpression, 600L); - if (errAssetMail) { - return new Result(false, StatusCode.ERROR, "邮件资产报告时间间隔不能小于10分钟"); - } - boolean errVulnMail = lessThanMinInterval("邮件漏洞报告", cronjobName, cronExpression, 600L); - if (errVulnMail) { - return new Result(false, StatusCode.ERROR, "邮件漏洞报告时间间隔不能小于10分钟"); - } - boolean errHeartbeat = lessThanMinInterval("agent心跳包监控", cronjobName, cronExpression, 60L); - if (errHeartbeat) { - return new Result(false, StatusCode.ERROR, "时间间隔不能小于1分钟"); - } - cronjob.setId(id); - cronjobService.update(cronjob); - String jobClassString = JOB_CLASS_STRING_WHITELIST_MAP.get(cronjobName); - String jobClassName = jobClassString + "Scheduler"; - - String jobKeyName = "jobKeyName_" + jobClassName; - String jobKeyGroup = "jobKeyGroup_" + jobClassName; - Class jobClass = (Class) Class.forName("com.tiji.center.schedule." + jobClassName); - JobKey jobKey = JobKey.jobKey(jobKeyName, jobKeyGroup); - - quartzJobService.deleteJob(jobKey); - QuartzJob quartzJob = new QuartzJob(jobKey, cronExpression, null, jobClass); - - quartzJobService.scheduleJob(quartzJob); - return new Result(true, StatusCode.OK, "修改成功"); - } - - private boolean lessThanMinInterval(String sourceCronjobName, String targetCronjobName, String cronExpression, Long minInterval) throws ParseException { - if (sourceCronjobName.equals(targetCronjobName)) { - CronTriggerImpl cronTriggerImpl = new CronTriggerImpl(); - cronTriggerImpl.setCronExpression(cronExpression); - List dates = TriggerUtils.computeFireTimes(cronTriggerImpl, null, 2); - long interval = dates.get(1).getTime() - dates.get(0).getTime(); - return interval < minInterval * 1000; - } - return false; - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) throws SchedulerException { - //cronjobService.deleteById(id); - Cronjob cronjob = cronjobService.findById(id); - if (Objects.isNull(cronjob)) { - return new Result(false, StatusCode.ERROR, "删除失败"); - } - String cronjobName = cronjob.getName(); - if (!JOB_CLASS_STRING_WHITELIST_MAP.containsKey(cronjobName)) { - return new Result(false, StatusCode.ERROR, "删除失败"); - } - String jobClassString = JOB_CLASS_STRING_WHITELIST_MAP.get(cronjobName); - String jobClassName = jobClassString + "Scheduler"; - - String jobKeyName = "jobKeyName_" + jobClassName; - String jobKeyGroup = "jobKeyGroup_" + jobClassName; - JobKey jobKey = JobKey.jobKey(jobKeyName, jobKeyGroup); - quartzJobService.deleteJob(jobKey); - - cronjob.setCronexpression(null); - cronjobService.update(cronjob); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * cronExpression模拟解析 - */ - @RequestMapping(value = "/parse", method = RequestMethod.POST) - public Result parse(@RequestBody Map searchMap) throws ParseException { - String cronExpression = (String) searchMap.get("cronExpression"); - if (StringUtils.isEmpty(cronExpression) || !CronExpression.isValidExpression(cronExpression)) { - return new Result(false, StatusCode.ERROR, "解析失败:Cron表达式错误"); - } - List resultList = new ArrayList<>(); - CronTriggerImpl cronTriggerImpl = new CronTriggerImpl(); - cronTriggerImpl.setCronExpression(cronExpression); - List dates = TriggerUtils.computeFireTimes(cronTriggerImpl, null, 10); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date dateNow = new Date(); - String now = sdf.format(dateNow); - resultList.add(now); - for (Date date : dates) { - resultList.add(sdf.format(date)); - } - return new Result(true, StatusCode.OK, "解析成功", resultList); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/DemocodeController.java b/center/src/main/java/com/tiji/center/controller/DemocodeController.java deleted file mode 100755 index 66a23cf..0000000 --- a/center/src/main/java/com/tiji/center/controller/DemocodeController.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Democode; -import com.tiji.center.pojo.Vuln; -import com.tiji.center.service.DemocodeService; -import com.tiji.center.service.VulnService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * democode控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/democode") -public class DemocodeController { - - @Autowired - private DemocodeService democodeService; - - @Autowired - private VulnService vulnService; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", democodeService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", democodeService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = democodeService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(democode -> { - String vulnid = democode.getVulnid(); - if (!StringUtils.isEmpty(vulnid)) { - Vuln vuln = vulnService.findById(vulnid); - if(!Objects.isNull(vuln)){ - democode.setVulnid(vuln.getName()); - } - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", democodeService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param democode - */ - @PostMapping - public Result add(@RequestBody Democode democode) { - democodeService.add(democode); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param democode - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Democode democode, @PathVariable String id) { - democode.setId(id); - democodeService.update(democode); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - democodeService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - democodeService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据vulnId查询 - * - * @param vulnId vulnId - * @return - */ - @RequestMapping(value = "/vuln/{vulnId}", method = RequestMethod.GET) - public Result findAllByVulnId(@PathVariable String vulnId) { - return new Result(true, StatusCode.OK, "查询成功", democodeService.findAllByVulnId(vulnId)); - } - - -} diff --git a/center/src/main/java/com/tiji/center/controller/DepartmentController.java b/center/src/main/java/com/tiji/center/controller/DepartmentController.java deleted file mode 100755 index d4e922b..0000000 --- a/center/src/main/java/com/tiji/center/controller/DepartmentController.java +++ /dev/null @@ -1,240 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Contact; -import com.tiji.center.pojo.ContactProjectinfo; -import com.tiji.center.pojo.Department; -import com.tiji.center.pojo.Projectinfo; -import com.tiji.center.service.ContactProjectinfoService; -import com.tiji.center.service.ContactService; -import com.tiji.center.service.DepartmentService; -import com.tiji.center.service.ProjectinfoService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import util.IdWorker; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.*; - -/** - * department控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/department") -public class DepartmentController { - - @Autowired - private DepartmentService departmentService; - @Autowired - private IdWorker idWorker; - @Autowired - private ProjectinfoService projectinfoService; - @Autowired - private ContactService contactService; - @Autowired - private ContactProjectinfoService contactProjectinfoService; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", departmentService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", departmentService.findById(id)); - } - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = departmentService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", departmentService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param department - */ - @PostMapping - public Result add(@RequestBody Department department) { - String departmentname = department.getDepartmentname(); - Department departmentInDb = departmentService.findByDepartmentname(departmentname); - if (Objects.isNull(departmentInDb)) { - departmentService.add(department); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:部门名称重复"); - } - } - - /** - * 修改 - * - * @param department - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Department department, @PathVariable String id) { - department.setId(id); - departmentService.update(department); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - departmentService.deleteById(id); - //将项目组的部门id置空 - projectinfoService.updateProjectInfoByDepartidSetDepartid2Null(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - departmentService.deleteAllByIds(ids); - ids.forEach(id -> { - //将项目组的部门id置空 - projectinfoService.updateProjectInfoByDepartidSetDepartid2Null(id); - }); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 批量导入部门项目信息联系人 - */ - @PostMapping(value = "/batchAdd") - public Result batchAdd(@RequestParam("file") MultipartFile file) { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!fileContentType.equals("text/plain")) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!suffix.equals("txt")) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - - String line; - Set tempSet = new HashSet<>(); - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8));) { - while ((line = bf.readLine()) != null) { - tempSet.add(line); - } - } catch (IOException ignored) { - } - tempSet.forEach(infoLine -> { - String departmentname = infoLine.split("\\|")[0]; - String projectinfoname = infoLine.split("\\|")[1]; - String name = infoLine.split("\\|")[2]; - String email = infoLine.split("\\|")[3]; - String phone = infoLine.split("\\|")[4]; - if (!Objects.isNull(departmentname) && !departmentname.isEmpty()) { - //部门不存在,直接新增 - Department department = departmentService.findByDepartmentname(departmentname); - String departmentId; - if (Objects.isNull(department)) { - departmentId = idWorker.nextId() + ""; - departmentService.add(new Department(departmentId, departmentname)); - } else { - //部门存在 - departmentId = department.getId(); - } - if (!Objects.isNull(projectinfoname) && !projectinfoname.isEmpty()) { - Projectinfo projectinfo = projectinfoService.findByDepartmentidAndProjectname(departmentId, projectinfoname); - String projectinfoId; - //部门不存在当前项目信息,直接新增 - if (Objects.isNull(projectinfo)) { - projectinfoId = idWorker.nextId() + ""; - projectinfoService.add(new Projectinfo(projectinfoId, departmentId, projectinfoname, false, false, new Date(), false)); - } else { - //项目信息存在 - projectinfoId = projectinfo.getId(); - } - - if (!Objects.isNull(name) && !name.isEmpty() && !Objects.isNull(email) && !email.isEmpty()) { - Contact contact = contactService.findByNameAndEmail(name, email); - String contactId; - //联系人不存在 - //新增联系人、联系人项目信息关联 - if (Objects.isNull(contact)) { - contactId = idWorker.nextId() + ""; - contactService.add(new Contact(contactId, name, email, phone)); - contactProjectinfoService.add(new ContactProjectinfo(idWorker.nextId() + "", contactId, projectinfoId)); - } else { - //联系人存在 - contactId = contact.getId(); - //更新联系人项目信息关联 - contactProjectinfoService.add(new ContactProjectinfo(idWorker.nextId() + "", contactId, projectinfoId)); - //更新电话 - if (!Objects.isNull(phone) && !phone.isEmpty() && !phone.equals("暂无")) { - //没有电话,更新电话 - if (Objects.isNull(contact.getPhone())) { - contact.setPhone(phone); - contactService.update(contact); - } - } - } - } - } - } - }); - return new Result(true, StatusCode.OK, "部门项目信息联系人已上传处理,请稍后查看"); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/DictionarypasswordController.java b/center/src/main/java/com/tiji/center/controller/DictionarypasswordController.java deleted file mode 100755 index 400c8ee..0000000 --- a/center/src/main/java/com/tiji/center/controller/DictionarypasswordController.java +++ /dev/null @@ -1,196 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Dictionarypassword; -import com.tiji.center.service.DictionarypasswordService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import util.IdWorker; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * dictionarypassword控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/dictionarypassword") -public class DictionarypasswordController { - - @Autowired - private DictionarypasswordService dictionarypasswordService; - @Autowired - private IdWorker idWorker; - @Autowired - private RedisTemplate redisTemplate; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", dictionarypasswordService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", dictionarypasswordService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = dictionarypasswordService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", dictionarypasswordService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param dictionarypassword - */ - @PostMapping - public Result add(@RequestBody Dictionarypassword dictionarypassword) { - String password = dictionarypassword.getPassword(); - Dictionarypassword dictionarypasswordInDb = dictionarypasswordService.findByPassword(password); - if (Objects.isNull(dictionarypasswordInDb)) { - dictionarypasswordService.add(dictionarypassword); - //更新redis缓存 - freshDictPasswdRedisCache(); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "字典密码重复"); - } - } - - /** - * 修改 - * - * @param dictionarypassword - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Dictionarypassword dictionarypassword, @PathVariable String id) { - dictionarypassword.setId(id); - dictionarypasswordService.update(dictionarypassword); - //更新redis缓存 - freshDictPasswdRedisCache(); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - dictionarypasswordService.deleteById(id); - //更新redis缓存 - freshDictPasswdRedisCache(); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - dictionarypasswordService.deleteAllByIds(ids); - //更新redis缓存 - freshDictPasswdRedisCache(); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 批量导入字典 - */ - @PostMapping(value = "/batchAdd") - public Result batchAddDictionaryPassword(@RequestParam("file") MultipartFile file) { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!"text/plain".equals(fileContentType)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!"txt".equals(suffix)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String line; - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8));) { - while ((line = bf.readLine()) != null) { - Dictionarypassword password = dictionarypasswordService.findByPassword(line); - if (Objects.isNull(password)) { - dictionarypasswordService.add(new Dictionarypassword(idWorker.nextId() + "", line)); - } - } - } catch (IOException ignored) { - } - //更新redis缓存 - freshDictPasswdRedisCache(); - return new Result(true, StatusCode.OK, "字典密码已上传处理,请稍后查看"); - } - - private void freshDictPasswdRedisCache() { - String redisDictPassword = "dictPasswordList_"; - redisTemplate.delete(redisDictPassword); - List allPassword = dictionarypasswordService.findAllPassword(); - if (!allPassword.isEmpty()) { - redisTemplate.opsForList().leftPushAll(redisDictPassword, allPassword); - } - //redisTemplate.opsForValue().set(redisDictPassword, allPassword); - - //如果设置过期时间,发任务时,如果缓存过期了,要重新加载数据到redis,有点多此一举 - //redisTemplate.expire(redisDictPassword, 2, TimeUnit.HOURS); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/DictionaryusernameController.java b/center/src/main/java/com/tiji/center/controller/DictionaryusernameController.java deleted file mode 100755 index db44c6f..0000000 --- a/center/src/main/java/com/tiji/center/controller/DictionaryusernameController.java +++ /dev/null @@ -1,197 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Dictionaryusername; -import com.tiji.center.service.DictionaryusernameService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import util.IdWorker; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * dictionaryusername控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/dictionaryusername") -public class DictionaryusernameController { - - @Autowired - private DictionaryusernameService dictionaryusernameService; - @Autowired - private IdWorker idWorker; - @Autowired - private RedisTemplate redisTemplate; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", dictionaryusernameService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", dictionaryusernameService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = dictionaryusernameService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", dictionaryusernameService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param dictionaryusername - */ - @PostMapping - public Result add(@RequestBody Dictionaryusername dictionaryusername) { - - String username = dictionaryusername.getUsername(); - Dictionaryusername dictionaryusernameInDb = dictionaryusernameService.findByUsername(username); - if (Objects.isNull(dictionaryusernameInDb)) { - dictionaryusernameService.add(dictionaryusername); - //更新redis缓存 - freshDictUsernameRedisCache(); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "字典用户名重复"); - } - } - - /** - * 修改 - * - * @param dictionaryusername - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Dictionaryusername dictionaryusername, @PathVariable String id) { - dictionaryusername.setId(id); - dictionaryusernameService.update(dictionaryusername); - //更新redis缓存 - freshDictUsernameRedisCache(); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - dictionaryusernameService.deleteById(id); - //更新redis缓存 - freshDictUsernameRedisCache(); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - dictionaryusernameService.deleteAllByIds(ids); - //更新redis缓存 - freshDictUsernameRedisCache(); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 批量导入字典 - */ - @PostMapping(value = "/batchAdd") - public Result batchAddDictionaryUsername(@RequestParam("file") MultipartFile file) { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!"text/plain".equals(fileContentType)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!"txt".equals(suffix)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String line; - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { - while ((line = bf.readLine()) != null) { - Dictionaryusername username = dictionaryusernameService.findByUsername(line); - if (Objects.isNull(username)) { - dictionaryusernameService.add(new Dictionaryusername(idWorker.nextId() + "", line)); - } - } - } catch (IOException ignored) { - } - //更新redis缓存 - freshDictUsernameRedisCache(); - return new Result(true, StatusCode.OK, "字典用户名已上传处理,请稍后查看"); - } - - private void freshDictUsernameRedisCache() { - String redisDictUsername = "dictUsernameList_"; - redisTemplate.delete(redisDictUsername); - List allUsername = dictionaryusernameService.findAllUsername(); - if (!allUsername.isEmpty()) { - redisTemplate.opsForList().leftPushAll(redisDictUsername, allUsername); - } - //redisTemplate.opsForValue().set(redisDictUsername, allUsername); - //如果设置过期时间,发任务时,如果缓存过期了,要重新加载数据到redis,有点多此一举 - //redisTemplate.expire(redisDictUsername, 2, TimeUnit.HOURS); - - } -} diff --git a/center/src/main/java/com/tiji/center/controller/DomainwhitelistController.java b/center/src/main/java/com/tiji/center/controller/DomainwhitelistController.java deleted file mode 100755 index 2b77119..0000000 --- a/center/src/main/java/com/tiji/center/controller/DomainwhitelistController.java +++ /dev/null @@ -1,174 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Domainwhitelist; -import com.tiji.center.service.DomainwhitelistService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import util.IdWorker; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * domainwhitelist控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/domainwhitelist") -public class DomainwhitelistController { - - @Autowired - private DomainwhitelistService domainwhitelistService; - @Autowired - private IdWorker idWorker; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", domainwhitelistService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", domainwhitelistService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = domainwhitelistService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", domainwhitelistService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param domainwhitelist - */ - @PostMapping - public Result add(@RequestBody Domainwhitelist domainwhitelist) { - String domain = domainwhitelist.getDomain(); - Domainwhitelist domainInDb = domainwhitelistService.findByDomain(domain); - if (Objects.isNull(domainInDb)) { - domainwhitelistService.add(domainwhitelist); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:域名重复"); - } - } - - /** - * 修改 - * - * @param domainwhitelist - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Domainwhitelist domainwhitelist, @PathVariable String id) { - domainwhitelist.setId(id); - domainwhitelistService.update(domainwhitelist); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - domainwhitelistService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - domainwhitelistService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 批量导域名白名单 - */ - @PostMapping(value = "/batchAdd") - public Result batchAdd(@RequestParam("file") MultipartFile file) { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!"text/plain".equals(fileContentType)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!"txt".equals(suffix)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - - - String line; - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { - while ((line = bf.readLine()) != null) { - Domainwhitelist domainwhitelist = domainwhitelistService.findByDomain(line); - if (Objects.isNull(domainwhitelist)) { - domainwhitelistService.add(new Domainwhitelist(idWorker.nextId() + "", line)); - } - } - } catch (IOException ignored) { - } - return new Result(true, StatusCode.OK, "域名白名单已上传处理,请稍后查看"); - - } -} diff --git a/center/src/main/java/com/tiji/center/controller/HostController.java b/center/src/main/java/com/tiji/center/controller/HostController.java deleted file mode 100755 index 56a8efc..0000000 --- a/center/src/main/java/com/tiji/center/controller/HostController.java +++ /dev/null @@ -1,263 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.*; -import com.tiji.center.service.*; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import util.IdWorker; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.*; - -/** - * host控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/host") -public class HostController { - - @Autowired - private HostService hostService; - - - @Autowired - private AssetipService assetipService; - - @Autowired - private IdWorker idWorker; - - @Autowired - private AssetportService assetportService; - - @Autowired - private AssetipAppsysHostdomainService assetipAppsysHostdomainService; - - @Autowired - private AppsystemService appsystemService; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", hostService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", hostService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - //根据ip查询主机 - List assetipIdList = new ArrayList<>(); - if (searchMap.containsKey("assetip")) { - //ip -> assetportid - String ipaddressv4 = (String) searchMap.get("assetip"); - Map ipSearchMap = new HashMap<>(); - ipSearchMap.put("ipaddressv4", ipaddressv4); - List assetipList = assetipService.findSearch(ipSearchMap); - assetipList.forEach(ip -> { - String ipId = ip.getId(); - assetipIdList.add(ipId); - }); - searchMap.put("assetipid", assetipIdList); - } - - Page pageList = hostService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(host -> { - String assetipid = host.getAssetipid(); - if (!StringUtils.isEmpty(assetipid)) { - Assetip assetip = assetipService.findById(assetipid); - if (!Objects.isNull(assetip)) { - host.setAssetipid(assetip.getIpaddressv4()); - } - } - StringBuilder appsysNameBuilder = new StringBuilder(); - List hostdomainList = assetipAppsysHostdomainService.findByAssetipid(assetipid); - for (AssetipAppsysHostdomain hostdomain : hostdomainList) { - String appsysid = hostdomain.getAppsysid(); - if (!StringUtils.isEmpty(appsysid)) { - Appsystem appsystem = appsystemService.findById(appsysid); - if (!Objects.isNull(appsystem)) { - String appsystemName = appsystem.getName(); - appsysNameBuilder.append(appsystemName).append(","); - } - } - } - host.setAppsysname(appsysNameBuilder.toString()); - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult<>(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", hostService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param host - */ - @PostMapping - public Result add(@RequestBody Host host) { - String hostname = host.getHostname(); - Host hostInDb = hostService.findByAssetipidAndHostname(host.getAssetipid(), hostname); - if (Objects.isNull(hostInDb)) { - hostService.add(host); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:ip和主机名重复"); - } - } - - /** - * 修改 - * - * @param host - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Host host, @PathVariable String id) { - host.setId(id); - hostService.update(host); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - hostService.deleteById(id); - //将中间表的域名id置空 - assetipAppsysHostdomainService.updateMiddByHostidSetHostid2Null(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 批量导入ip主机名 - */ - - @PostMapping(value = "/batchAdd") - public Result batchAdd(@RequestParam("file") MultipartFile file) throws IOException { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!fileContentType.equals("text/plain")) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!suffix.equals("txt")) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - - String line; - Date date = new Date(); - List hostList = new ArrayList<>(); - List assetipListList = new ArrayList<>(); - Set tempSet = new HashSet<>(); - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { - while ((line = bf.readLine()) != null) { - tempSet.add(line); - } - } catch (IOException ignored) { - } - tempSet.forEach(infoLine -> { - String ip = infoLine.split(":")[0]; - String hostname = infoLine.split(":")[1]; - Assetip assetip = assetipService.findByIpaddressv4AndPassivetimeIsNull(ip); - String temp = hostname.split("\\.")[0]; - String owner = temp.substring(temp.indexOf("-") + 1); - if (assetip != null) { - //20201012 修复 修复ip主机名,主机名重复时,导入失败问题 - String assetipId = assetip.getId(); - Host hostnameInDb = hostService.findByAssetipidAndHostname(assetipId, hostname); - if (Objects.isNull(hostnameInDb)) { - Host host = new Host(idWorker.nextId() + "", assetipId, null, hostname, null, null, null, owner, date, null); - hostList.add(host); - } - } else { - String assetipId = idWorker.nextId() + ""; - //20201012 修复 修复ip主机名,主机名重复时,导入失败问题 - Host hostnameInDb = hostService.findByAssetipidAndHostname(assetipId, hostname); - if (Objects.isNull(hostnameInDb)) { - hostList.add(new Host(idWorker.nextId() + "", assetipId, null, hostname, null, null, null, owner, date, null)); - } - assetipService.add(new Assetip(assetipId, null, ip, null, false, false, date, null, null)); - } - }); - if (!hostList.isEmpty()) { - hostService.batchAdd(hostList); - } - return new Result(true, StatusCode.OK, "ip主机名已上传处理,请稍后查看"); - } - - /** - * 根据assetipid查询 - * - * @param assetipid assetipid - * @return - */ - @RequestMapping(value = "/assetip/{assetipid}", method = RequestMethod.GET) - public Result findAllByAssetipid(@PathVariable String assetipid) { - return new Result(true, StatusCode.OK, "查询成功", hostService.findAllByAssetipid(assetipid)); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - hostService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/ImvulnnotifyController.java b/center/src/main/java/com/tiji/center/controller/ImvulnnotifyController.java deleted file mode 100755 index e282412..0000000 --- a/center/src/main/java/com/tiji/center/controller/ImvulnnotifyController.java +++ /dev/null @@ -1,284 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Imvulnnotify; -import com.tiji.center.pojo.Notifylog; -import com.tiji.center.pojo.Sendmailconfig; -import com.tiji.center.service.ImvulnnotifyService; -import com.tiji.center.service.NotifylogService; -import com.tiji.center.service.SendmailconfigService; -import com.tiji.center.util.NotifyUtil; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.mail.javamail.JavaMailSenderImpl; -import org.springframework.web.bind.annotation.*; -import util.IdWorker; - -import java.lang.reflect.Field; -import java.util.*; -import java.util.concurrent.TimeUnit; - -/** - * imvulnnotify控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/imvulnnotify") -public class ImvulnnotifyController { - - @Autowired - private ImvulnnotifyService imvulnnotifyService; - @Autowired - private NotifylogService notifylogService; - @Autowired - private RedisTemplate redisTemplate; - @Autowired - private IdWorker idWorker; - @Autowired - JavaMailSenderImpl mailSender; - @Autowired - private SendmailconfigService sendmailconfigService; - private final String imvulnnotifyKey = "imvulnnotify"; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", imvulnnotifyService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", imvulnnotifyService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = imvulnnotifyService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", imvulnnotifyService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param imvulnnotify - */ - @PostMapping - public Result add(@RequestBody Imvulnnotify imvulnnotify) { - imvulnnotifyService.add(imvulnnotify); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param imvulnnotify - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Imvulnnotify imvulnnotify, @PathVariable String id) { - redisTemplate.delete(imvulnnotifyKey); - for (Field field : imvulnnotify.getClass().getDeclaredFields()) { - field.setAccessible(true); - if (!"id".equals(field.getName())) { - redisTemplate.delete(field.getName()); - } - } - imvulnnotify.setId(id); - imvulnnotifyService.update(imvulnnotify); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - imvulnnotifyService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 钉钉群机器人测试消息 - * - * @return - */ - @GetMapping(value = "/sendding") - public Result sendDingTalkTest() { - Date date = new Date(); - String dtSendFlag = "dtSendFlag"; - Boolean dtFlagExist = redisTemplate.hasKey(dtSendFlag); - if (!Objects.isNull(dtFlagExist) && dtFlagExist) { - return new Result(false, StatusCode.ERROR, "发送失败:发送测试消息需要间隔10秒"); - } else { - try { - Map imvulnnotifyMap = new HashMap<>(); - Imvulnnotify imvulnnotify = imvulnnotifyService.findAll().get(0); - String secret = imvulnnotify.getSecret(); - String dingtalkmessageurl = imvulnnotify.getDingtalkmessageurl(); - String risk = imvulnnotify.getRisk(); - String infoMsg = ""; - if (StringUtils.isEmpty(risk)) { - infoMsg = ",请注意,风险等级未设置,漏洞将无法推送到群里"; - } - if (StringUtils.isEmpty(secret) || StringUtils.isEmpty(dingtalkmessageurl)) { - return new Result(false, StatusCode.ERROR, "发送失败:签名密钥,Webhook地址配置错误"); - } - for (Field field : imvulnnotify.getClass().getDeclaredFields()) { - field.setAccessible(true); - if (!"id".equals(field.getName())) { - Object o = field.get(imvulnnotify); - if (o instanceof Boolean) { - if ("true".equals(o.toString())) { - o = "true"; - } else { - o = ""; - } - } - imvulnnotifyMap.put(field.getName(), o); - } - } - NotifyUtil.sendDingTalk(idWorker, notifylogService, "钉钉群机器人测试消息", imvulnnotifyMap, date); - - redisTemplate.opsForValue().set(dtSendFlag, dtSendFlag); - redisTemplate.expire(dtSendFlag, 10, TimeUnit.SECONDS); - return new Result(true, StatusCode.OK, "测试消息已发送,如果未收到消息,可前往提醒日志查看异常记录" + infoMsg); - } catch (Exception e) { - notifylogService.add(new Notifylog(idWorker.nextId() + "", "D", "钉钉group", null, "钉钉群机器人测试消息发送失败", false, e.getMessage(), date)); - return new Result(false, StatusCode.ERROR, "发送失败:可前往提醒日志查看异常消息"); - } - - } - } - - /** - * 企微群机器人测试消息 - * - * @return - */ - @GetMapping(value = "/sendcorwc") - public Result sendCorWechatTest() { - Date date = new Date(); - String corWcSendFlag = "corWcSendFlag"; - Boolean wcFlagExist = redisTemplate.hasKey(corWcSendFlag); - if (!Objects.isNull(wcFlagExist) && wcFlagExist) { - return new Result(false, StatusCode.ERROR, "发送失败:发送测试消息需要间隔10秒"); - } else { - try { - Map imvulnnotifyMap = new HashMap<>(); - Imvulnnotify imvulnnotify = imvulnnotifyService.findAll().get(0); - String wechatmessageurl = imvulnnotify.getWechatmessageurl(); - String risk = imvulnnotify.getRisk(); - String infoMsg = ""; - if (StringUtils.isEmpty(risk)) { - infoMsg = ",请注意,风险等级未设置,漏洞将无法推送到群里"; - } - if (StringUtils.isEmpty(wechatmessageurl)) { - return new Result(false, StatusCode.ERROR, "发送失败:Webhook地址配置错误"); - } - for (Field field : imvulnnotify.getClass().getDeclaredFields()) { - field.setAccessible(true); - if (!"id".equals(field.getName())) { - Object o = field.get(imvulnnotify); - if (o instanceof Boolean) { - if ("true".equals(o.toString())) { - o = "true"; - } else { - o = ""; - } - } - imvulnnotifyMap.put(field.getName(), o); - } - } - NotifyUtil.sendWeChet(idWorker, notifylogService, "企微群机器人测试消息", imvulnnotifyMap, date); - redisTemplate.opsForValue().set(corWcSendFlag, corWcSendFlag); - redisTemplate.expire(corWcSendFlag, 10, TimeUnit.SECONDS); - return new Result(true, StatusCode.OK, "测试消息已发送,如果未收到消息,可前往提醒日志查看异常记录" + infoMsg); - } catch (Exception e) { - notifylogService.add(new Notifylog(idWorker.nextId() + "", "W", "企微group", null, "企微群机器人测试消息发送失败", false, e.getMessage(), date)); - return new Result(false, StatusCode.ERROR, "发送失败:可前往提醒日志查看异常记录"); - } - } - } - - /** - * 默认提醒邮箱列表发送测试邮件 - * - * @return - */ - @GetMapping(value = "/sendemail") - public Result sendEmailTest() { - Date date = new Date(); - String emailSendFlag = "emailSendFlag"; - Boolean emailFlagExist = redisTemplate.hasKey(emailSendFlag); - if (!Objects.isNull(emailFlagExist) && emailFlagExist) { - return new Result(false, StatusCode.ERROR, "发送失败:发送测试邮件需要间隔15秒"); - } else { - try { - Sendmailconfig sendmailconfig = sendmailconfigService.findAll().get(0); - String sendFrom = sendmailconfig.getSendfrom(); - String sendTo = sendmailconfig.getSendto(); - //设置邮箱信息 - mailSender.setHost(sendmailconfig.getSendhost()); - mailSender.setUsername(sendFrom); - mailSender.setPassword(sendmailconfig.getSendpassword()); - String[] sendToArray = sendTo.split(","); - String risk = sendmailconfig.getSendtorisk(); - String infoMsg = ""; - if (StringUtils.isEmpty(risk)) { - infoMsg = ",请注意,风险等级未设置,漏洞报告无法发送"; - } - if (sendToArray.length == 0 || StringUtils.isEmpty(sendFrom) || StringUtils.isEmpty(sendTo)) { - return new Result(false, StatusCode.ERROR, "发送失败:邮箱host,账号,密码/授权码,提醒邮箱列表配置错误"); - } - for (String mail : sendToArray) { - NotifyUtil.sendSimpleMail(mailSender, sendFrom, mail, "魔方测试邮件", "魔方测试邮件"); - } - notifylogService.add(new Notifylog(idWorker.nextId() + "", "E", "默认收件人列表", null, "魔方测试邮件", true, null, date)); - redisTemplate.opsForValue().set(emailSendFlag, emailSendFlag); - redisTemplate.expire(emailSendFlag, 15, TimeUnit.SECONDS); - return new Result(true, StatusCode.OK, "测试邮件已发送,如果未收到邮件,可前往提醒日志查看异常记录" + infoMsg); - } catch (Exception e) { - notifylogService.add(new Notifylog(idWorker.nextId() + "", "E", "默认收件人列表", null, "默认提醒邮箱列表测试邮件发送失败", false, e.getMessage(), date)); - return new Result(false, StatusCode.ERROR, "发送失败:可前往提醒日志查看异常记录"); - } - } - } -} diff --git a/center/src/main/java/com/tiji/center/controller/IpportwhitelistController.java b/center/src/main/java/com/tiji/center/controller/IpportwhitelistController.java deleted file mode 100755 index 0984c34..0000000 --- a/center/src/main/java/com/tiji/center/controller/IpportwhitelistController.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Ipportwhitelist; -import com.tiji.center.pojo.Ipwhitelist; -import com.tiji.center.service.IpportwhitelistService; -import com.tiji.center.service.IpwhitelistService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * ipportwhitelist控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/ipportwhitelist") -public class IpportwhitelistController { - - @Autowired - private IpportwhitelistService ipportwhitelistService; - @Autowired - private IpwhitelistService ipwhitelistService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", ipportwhitelistService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", ipportwhitelistService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = ipportwhitelistService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(ipportwhitelist -> { - String ipwhitelistid = ipportwhitelist.getIpwhitelistid(); - if(!StringUtils.isEmpty(ipwhitelistid)){ - Ipwhitelist ipwhitelist = ipwhitelistService.findById(ipwhitelistid); - if(!Objects.isNull(ipwhitelist)){ - ipportwhitelist.setIpwhitelistid(ipwhitelist.getIp()); - } - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", ipportwhitelistService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param ipportwhitelist - */ - @PostMapping - public Result add(@RequestBody Ipportwhitelist ipportwhitelist) { - String port = ipportwhitelist.getPort(); - Ipportwhitelist ipportwhitelistInDb = ipportwhitelistService.findByIpwhitelistidAndPort(ipportwhitelist.getIpwhitelistid(), port); - if (Objects.isNull(ipportwhitelistInDb)) { - ipportwhitelistService.add(ipportwhitelist); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:端口重复"); - } - } - - /** - * 修改 - * - * @param ipportwhitelist - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Ipportwhitelist ipportwhitelist, @PathVariable String id) { - ipportwhitelist.setId(id); - ipportwhitelistService.update(ipportwhitelist); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - ipportwhitelistService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - ipportwhitelistService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/IpwhitelistController.java b/center/src/main/java/com/tiji/center/controller/IpwhitelistController.java deleted file mode 100755 index 5d62bd9..0000000 --- a/center/src/main/java/com/tiji/center/controller/IpwhitelistController.java +++ /dev/null @@ -1,307 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Assetip; -import com.tiji.center.pojo.Assetport; -import com.tiji.center.pojo.Ipportwhitelist; -import com.tiji.center.pojo.Ipwhitelist; -import com.tiji.center.service.AssetipService; -import com.tiji.center.service.AssetportService; -import com.tiji.center.service.IpportwhitelistService; -import com.tiji.center.service.IpwhitelistService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import util.IdWorker; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * ipwhitelist控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/ipwhitelist") -public class IpwhitelistController { - - @Autowired - private IpwhitelistService ipwhitelistService; - @Autowired - private IdWorker idWorker; - - @Autowired - private IpportwhitelistService ipportwhitelistService; - - @Autowired - private AssetipService assetipService; - @Autowired - private AssetportService assetportService; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", ipwhitelistService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", ipwhitelistService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = ipwhitelistService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", ipwhitelistService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param ipwhitelist - */ - @PostMapping - public Result add(@RequestBody Ipwhitelist ipwhitelist) { - String ip = ipwhitelist.getIp(); - Ipwhitelist ipwhitelistInDb = ipwhitelistService.findByIp(ip); - if (Objects.isNull(ipwhitelistInDb)) { - ipwhitelistService.add(ipwhitelist); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:ip重复"); - } - } - - /** - * 修改 - * - * @param ipwhitelist - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Ipwhitelist ipwhitelist, @PathVariable String id) { - ipwhitelist.setId(id); - ipwhitelistService.update(ipwhitelist); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - ipwhitelistService.deleteById(id); - //删除端口白名单 - ipportwhitelistService.deleteAllByipwhitelistid(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - ipwhitelistService.deleteAllByIds(ids); - ids.forEach(id -> { - //删除端口白名单 - ipportwhitelistService.deleteAllByipwhitelistid(id); - }); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 批量导入ip端口白名单 - */ - @PostMapping(value = "/batchAdd") - public Result batchAdd(@RequestParam("file") MultipartFile file) throws IOException { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!fileContentType.equals("text/plain")) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!suffix.equals("txt")) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - - String line; - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { - while ((line = bf.readLine()) != null) { - String ip = line.split("\\|")[0]; - String port = line.split("\\|")[1]; - boolean checkWhitelist = line.split("\\|")[2].equals("1"); - boolean notifyWhitelist = line.split("\\|")[3].equals("1"); - //端口为空,ip白名单 - if (Objects.isNull(port) || port.isEmpty()) { - Ipwhitelist ipwhitelist = ipwhitelistService.findByIp(ip); - //不在数据库中 - if (Objects.isNull(ipwhitelist)) { - ipwhitelistService.add(new Ipwhitelist(idWorker.nextId() + "", ip, checkWhitelist, notifyWhitelist)); - } else { - ipwhitelist.setCheckwhitelist(checkWhitelist); - ipwhitelist.setNotifywhitelist(notifyWhitelist); - ipwhitelistService.update(ipwhitelist); - //删除端口白名单 - ipportwhitelistService.deleteAllByipwhitelistid(ipwhitelist.getId()); - } - } else { - //端口白名单 - Ipwhitelist ipwhitelist = ipwhitelistService.findByIp(ip); - //不在数据库中 - String ipwhitelistId = idWorker.nextId() + ""; - if (Objects.isNull(ipwhitelist)) { - ipwhitelistService.add(new Ipwhitelist(ipwhitelistId, ip, false, false)); - ipportwhitelistService.add(new Ipportwhitelist(idWorker.nextId() + "", ipwhitelistId, port, checkWhitelist, notifyWhitelist)); - } else { - //在数据库中,新增端口 - ipwhitelistId = ipwhitelist.getId(); - //如果是端口白名单,则ip白名单置空 - if (checkWhitelist) { - ipwhitelist.setCheckwhitelist(false); - ipwhitelistService.add(ipwhitelist); - } - if (notifyWhitelist) { - ipwhitelist.setNotifywhitelist(false); - ipwhitelistService.add(ipwhitelist); - } - Ipportwhitelist ipportwhitelist = ipportwhitelistService.findByIpwhitelistidAndPort(ipwhitelistId, port); - if (Objects.isNull(ipportwhitelist)) { - ipportwhitelistService.add(new Ipportwhitelist(idWorker.nextId() + "", ipwhitelistId, port, checkWhitelist, notifyWhitelist)); - } else { - ipportwhitelist.setCheckwhitelist(checkWhitelist); - ipportwhitelist.setNotifywhitelist(notifyWhitelist); - ipportwhitelistService.update(ipportwhitelist); - } - } - } - - } - } catch (IOException ignored) { - } - return new Result(true, StatusCode.OK, "ip端口白名单已上传处理,请稍后查看"); - - } - - /** - * 更新资产库中ip端口白名单 - * - * @return - */ - @GetMapping(value = "/batchUpdate") - public Result batchUpdate() { - List assetipList = new ArrayList<>(); - List assetPortList = new ArrayList<>(); - List ipwhitelistList = ipwhitelistService.findAll(); - ipwhitelistList.forEach(ipwhitelist -> { - String ipwhitelistId = ipwhitelist.getId(); - String ip = ipwhitelist.getIp(); - Boolean ipCheckwhitelist = ipwhitelist.getCheckwhitelist(); - Boolean ipNotifywhitelist = ipwhitelist.getNotifywhitelist(); - Assetip assetip = assetipService.findByIpaddressv4AndPassivetimeIsNull(ip); - //当前ip在数据库中 - if (!Objects.isNull(assetip)) { - String assetIpId = assetip.getId(); - - List whitelistPortList = ipportwhitelistService.findAllPortByIpwhitelistid(ipwhitelistId); - //没有白名单端口,直接更新ip - if (whitelistPortList.isEmpty()) { - assetip.setCheckwhitelist(ipCheckwhitelist); - assetip.setAssetnotifywhitelist(ipNotifywhitelist); - assetipList.add(assetip); - //assetipService.update(assetip); - } else { - //有白名单端口,ip白名单置空 - if (ipCheckwhitelist) { - assetip.setCheckwhitelist(false); - assetipList.add(assetip); - } - if (ipNotifywhitelist) { - assetip.setAssetnotifywhitelist(false); - assetipList.add(assetip); - } - //assetipService.update(assetip); - //根据白名单端口,遍历资产库端口,如果白名单端口列表包含数据库端口,则判断白名单 - //根据ip编号获取端口列表 - List assetportList = assetportService.findAllByAssetipidAndDowntimeIsNull(assetIpId); - if (!assetportList.isEmpty()) { - assetportList.forEach(assetport -> { - String dbPort = assetport.getPort(); - //当前端口在白名单whitelistPortList中,加白 - if (whitelistPortList.contains(dbPort)) { - Ipportwhitelist ipportwhitelist = ipportwhitelistService.findByIpwhitelistidAndPort(ipwhitelistId, dbPort); - Boolean portCheckwhitelist = ipportwhitelist.getCheckwhitelist(); - Boolean portNotifywhitelist = ipportwhitelist.getNotifywhitelist(); - assetport.setCheckwhitelist(portCheckwhitelist); - assetport.setAssetnotifywhitelist(portNotifywhitelist); - assetPortList.add(assetport); - } - }); - } - } - } - }); - // 批量更新 - if (!assetPortList.isEmpty()) { - assetportService.batchAdd(assetPortList); - } - //批量更新 - if (!assetipList.isEmpty()) { - assetipService.batchAdd(assetipList); - } - return new Result(true, StatusCode.OK, "资产库ip端口白名单已在后台处理,请稍后查看"); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/LoginController.java b/center/src/main/java/com/tiji/center/controller/LoginController.java deleted file mode 100755 index fc4127e..0000000 --- a/center/src/main/java/com/tiji/center/controller/LoginController.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.User; -import com.tiji.center.service.DictionarypasswordService; -import com.tiji.center.service.UserService; -import com.tiji.center.util.JwtUtil; -import entity.Result; -import entity.StatusCode; -import io.jsonwebtoken.Claims; -import io.jsonwebtoken.ExpiredJwtException; -import io.jsonwebtoken.JwtException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; -import java.util.*; - -/** - * @author 贰拾壹 - * @create 2020-01-08 11:33 - */ -@RestController -@CrossOrigin -@RequestMapping("/user") -public class LoginController { - - @Autowired - private UserService userService; - @Autowired - private JwtUtil jwtUtil; - @Autowired - private HttpServletRequest request; - @Autowired - private DictionarypasswordService dictionarypasswordService; - - /** - * 登录 - * 返回token - */ - /* - * { - * "code": 20000, - * "data": { - * "token": "admin" - * } - * } - */ - @RequestMapping(value = "/login", method = RequestMethod.POST) - public Result login(@RequestBody User user) { - //认证 - User loginUser = userService.login(user); - - if (loginUser == null) { - //登录失败 - return new Result(false, StatusCode.LOGIN_ERROR, "登录失败:用户名或密码错误"); - } else { - //登录成功 - //判断是否有效 - Boolean active = loginUser.getActive(); - if (Objects.isNull(active) || !active) { - return new Result(false, StatusCode.LOGIN_ERROR, "登录失败:用户已失效"); - } - //判断是否首次登陆 - Date lastdate = loginUser.getLastdate(); - - if (!Objects.isNull(lastdate)) { - List allPassword = dictionarypasswordService.findAllPassword(); - //非首次登陆,密码在密码字典中 - if (allPassword.contains(user.getPassword())) { - return new Result(false, StatusCode.LOGIN_ERROR, "登录失败:当前密码在密码字典中且首次登录后未修改密码,请将数据库user表当前用户的lastdate置空,再重新登录"); - } - } - - //授权 - String token; - Boolean admin = loginUser.getAdmin(); - if (!Objects.isNull(admin) && admin) { - //管理员 - token = jwtUtil.createJWT(loginUser.getId(), loginUser.getUsername(), "admin"); - } else { - //普通用户 - token = jwtUtil.createJWT(loginUser.getId(), loginUser.getUsername(), "user"); - } - - Map data = new HashMap<>(); - data.put("token", token); - - //记录登录日期 - loginUser.setLastdate(new Date()); - userService.update(loginUser); - return new Result(true, StatusCode.OK, "登录成功", data); - } - } - - /** - * 根据token返回用户信息 - * - * @return - */ - /* - * { - * "code": 20000, - * "data": { - * "name": "admin", - * "avatar": "" - * } - * } - */ - @RequestMapping(value = "/info", method = RequestMethod.GET) - public Result getInfo() { - String token = request.getParameter("token"); - try { - Claims body; - body = jwtUtil.parseJWT(token); - //Token合法 - Object roles = body.get("roles"); - Object userId = body.get("jti"); - Object userName = body.get("sub"); - User user = userService.findById((String) userId); - Map data = new HashMap<>(); - data.put("name", user.getUsername()); - data.put("avatar", user.getAvatar()); - return new Result(true, StatusCode.OK, "", data); - } catch (ExpiredJwtException e) { - return new Result(true, StatusCode.TOKEN_EXPIRED_ERROR, "token已过期"); - } catch (JwtException e) { - return new Result(true, StatusCode.ILLEGAL_TOKEN_ERROR, "非法token"); - } - - } - - @RequestMapping(value = "/logout", method = RequestMethod.POST) - public Result logout() { - String authInRequestHeader = request.getHeader("Authorization"); - try { - Claims body; - String token = authInRequestHeader.substring(7); - body = jwtUtil.parseJWT(token); - //Token合法 - //TODO 以下回到session时代 - //当前toten加到黑名单 - //然后Request的时候要判断token是否在黑名单...有点麻烦..先不搞 - return new Result(true, StatusCode.OK, "成功退出"); - } catch (JwtException e) { - //直接退出 - return new Result(true, StatusCode.OK, "成功退出"); - } - } -} diff --git a/center/src/main/java/com/tiji/center/controller/NmapconfigController.java b/center/src/main/java/com/tiji/center/controller/NmapconfigController.java deleted file mode 100755 index 4dfc7f4..0000000 --- a/center/src/main/java/com/tiji/center/controller/NmapconfigController.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Nmapconfig; -import com.tiji.center.pojo.Task; -import com.tiji.center.service.NmapconfigService; -import com.tiji.center.service.TaskService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * nmapconfig控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/nmapconfig") -public class NmapconfigController { - - @Autowired - private NmapconfigService nmapconfigService; - @Autowired - private TaskService taskService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", nmapconfigService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", nmapconfigService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = nmapconfigService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(nmapconfig -> { - String taskid = nmapconfig.getTaskid(); - if (!StringUtils.isEmpty(taskid)) { - Task task = taskService.findById(taskid); - if (!Objects.isNull(task)) { - nmapconfig.setTaskid(task.getName()); - } - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", nmapconfigService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param nmapconfig - */ - @PostMapping - public Result add(@RequestBody Nmapconfig nmapconfig) { - nmapconfigService.add(nmapconfig); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param nmapconfig - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Nmapconfig nmapconfig, @PathVariable String id) { - nmapconfig.setId(id); - nmapconfigService.update(nmapconfig); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - nmapconfigService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据taskID查询 - * - * @param taskId taskId - * @return - */ - @RequestMapping(value = "/task/{taskId}", method = RequestMethod.GET) - public Result findByTaskId(@PathVariable String taskId) { - return new Result(true, StatusCode.OK, "查询成功", nmapconfigService.findByTaskid(taskId)); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - nmapconfigService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } - - -} diff --git a/center/src/main/java/com/tiji/center/controller/NotifylogController.java b/center/src/main/java/com/tiji/center/controller/NotifylogController.java deleted file mode 100755 index 5ff37a3..0000000 --- a/center/src/main/java/com/tiji/center/controller/NotifylogController.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Notifylog; -import com.tiji.center.service.NotifylogService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; - -/** - * notifylog控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/notifylog") -public class NotifylogController { - - @Autowired - private NotifylogService notifylogService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", notifylogService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", notifylogService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = notifylogService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", notifylogService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param notifylog - */ - @PostMapping - public Result add(@RequestBody Notifylog notifylog) { - notifylogService.add(notifylog); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param notifylog - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Notifylog notifylog, @PathVariable String id) { - notifylog.setId(id); - notifylogService.update(notifylog); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - notifylogService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - notifylogService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/PluginCheckerController.java b/center/src/main/java/com/tiji/center/controller/PluginCheckerController.java deleted file mode 100755 index 991a98f..0000000 --- a/center/src/main/java/com/tiji/center/controller/PluginCheckerController.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.tiji.center.controller; - -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.web.bind.annotation.*; - -/** - * PluginCheckerController - * - * @author 贰拾壹 - * @create 2020-08-08 18:29 - */ - -@RestController -@CrossOrigin -@RequestMapping("/pluginchecker") - -public class PluginCheckerController { - - @Autowired - private RedisTemplate redisTemplate; - - /** - * 插件HTTP辅助验证 - * - * @return - */ - @GetMapping - public Result check() { - //从redis获取key,并返回 - String httpValidateKey = redisTemplate.opsForValue().get("HttpValidateKey_"); - return new Result(true, StatusCode.OK, "存在漏洞, vulnerable", httpValidateKey); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/PluginassetserviceController.java b/center/src/main/java/com/tiji/center/controller/PluginassetserviceController.java deleted file mode 100755 index 642263a..0000000 --- a/center/src/main/java/com/tiji/center/controller/PluginassetserviceController.java +++ /dev/null @@ -1,148 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Pluginassetservice; -import com.tiji.center.pojo.Pluginconfig; -import com.tiji.center.service.PluginassetserviceService; -import com.tiji.center.service.PluginconfigService; -import com.tiji.center.service.VulnService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * assetservice控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/pluginassetservice") -public class PluginassetserviceController { - - @Autowired - private PluginassetserviceService pluginassetserviceService; - @Autowired - private PluginconfigService pluginconfigService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", pluginassetserviceService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", pluginassetserviceService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = pluginassetserviceService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(pluginassetservice -> { - String pluginconfigid = pluginassetservice.getPluginconfigid(); - if (!StringUtils.isEmpty(pluginconfigid)) { - Pluginconfig pluginconfig = pluginconfigService.findById(pluginconfigid); - if (!Objects.isNull(pluginconfig)) { - pluginassetservice.setPluginconfigid(pluginconfig.getName()); - } - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", pluginassetserviceService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param assetservice - */ - @PostMapping - public Result add(@RequestBody Pluginassetservice assetservice) { - pluginassetserviceService.add(assetservice); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param assetservice - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Pluginassetservice assetservice, @PathVariable String id) { - assetservice.setId(id); - pluginassetserviceService.update(assetservice); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - pluginassetserviceService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - pluginassetserviceService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据pluginId查询 - * - * @param pluginId pluginId - * @return - */ - @RequestMapping(value = "/plugin/{pluginId}", method = RequestMethod.GET) - public Result findAllByPluginId(@PathVariable String pluginId) { - return new Result(true, StatusCode.OK, "查询成功", pluginassetserviceService.findAllByPluginId(pluginId)); - } - -} diff --git a/center/src/main/java/com/tiji/center/controller/PluginassetversionController.java b/center/src/main/java/com/tiji/center/controller/PluginassetversionController.java deleted file mode 100755 index c68be09..0000000 --- a/center/src/main/java/com/tiji/center/controller/PluginassetversionController.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Pluginassetversion; -import com.tiji.center.pojo.Pluginconfig; -import com.tiji.center.service.PluginassetversionService; -import com.tiji.center.service.PluginconfigService; -import com.tiji.center.service.VulnService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * assetversion控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/pluginassetversion") -public class PluginassetversionController { - - @Autowired - private PluginassetversionService pluginassetversionService; - @Autowired - private PluginconfigService pluginconfigService; - - /** - * 查询全部数据 - * - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", pluginassetversionService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = pluginassetversionService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(Pluginassetversion -> { - String pluginconfigid = Pluginassetversion.getPluginconfigid(); - if (!StringUtils.isEmpty(pluginconfigid)) { - Pluginconfig pluginconfig = pluginconfigService.findById(pluginconfigid); - if (!Objects.isNull(pluginconfig)) { - Pluginassetversion.setPluginconfigid(pluginconfig.getName()); - } - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", pluginassetversionService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param assetversion - */ - @PostMapping - public Result add(@RequestBody Pluginassetversion assetversion) { - pluginassetversionService.add(assetversion); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param assetversion - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Pluginassetversion assetversion, @PathVariable String id) { - assetversion.setId(id); - pluginassetversionService.update(assetversion); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - pluginassetversionService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - pluginassetversionService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据pluginId查询 - * - * @param pluginId pluginId - * @return - */ - @RequestMapping(value = "/plugin/{pluginId}", method = RequestMethod.GET) - public Result findAllByPluginId(@PathVariable String pluginId) { - return new Result(true, StatusCode.OK, "查询成功", pluginassetversionService.findAllByPluginId(pluginId)); - } - -} diff --git a/center/src/main/java/com/tiji/center/controller/PluginconfigController.java b/center/src/main/java/com/tiji/center/controller/PluginconfigController.java deleted file mode 100755 index 09faa2b..0000000 --- a/center/src/main/java/com/tiji/center/controller/PluginconfigController.java +++ /dev/null @@ -1,438 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.*; -import com.tiji.center.service.*; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import util.IdWorker; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * pluginconfig控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/pluginconfig") -public class PluginconfigController { - - @Autowired - private PluginconfigService pluginconfigService; - - @Autowired - private IdWorker idWorker; - - - @Autowired - private PluginassetserviceService pluginassetserviceService; - @Autowired - private PluginassetversionService pluginassetversionService; - @Autowired - private VulnkeywordService vulnkeywordService; - @Autowired - private VulnpluginconfigService vulnpluginconfigService; - @Autowired - private VulnService vulnService; - @Autowired - private TaskpluginconfigService taskpluginconfigService; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", pluginconfigService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", pluginconfigService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = pluginconfigService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", pluginconfigService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param pluginconfig - */ - @PostMapping - public Result add(@RequestBody Pluginconfig pluginconfig) { - if (Objects.isNull(pluginconfig.getTimeout()) || pluginconfig.getTimeout().isEmpty()) { - pluginconfig.setTimeout("0"); - } - pluginconfigService.add(pluginconfig); - return new Result(true, StatusCode.OK, "增加成功", pluginconfig.getId()); - } - - /** - * 修改 - * - * @param pluginconfig - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Pluginconfig pluginconfig, @PathVariable String id) { - pluginconfig.setId(id); - pluginconfigService.update(pluginconfig); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - pluginconfigService.deleteById(id); - - //删除资产服务 - pluginassetserviceService.deleteAllByPluginconfigid(id); - - //删除资产版本 - pluginassetversionService.deleteAllByPluginconfigid(id); - - //删除漏洞关键词 - vulnkeywordService.deleteAllByPluginconfigid(id); - //删除漏洞插件配置关联 - vulnpluginconfigService.deleteAllByPluginconfigid(id); - - //删除任务已启用插件 - taskpluginconfigService.deleteAllByPluginconfigid(id); - - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - pluginconfigService.deleteAllByIds(ids); - ids.forEach(id -> { - //删除资产服务 - pluginassetserviceService.deleteAllByPluginconfigid(id); - - //删除资产版本 - pluginassetversionService.deleteAllByPluginconfigid(id); - - //删除漏洞关键词 - vulnkeywordService.deleteAllByPluginconfigid(id); - //删除漏洞插件配置关联 - vulnpluginconfigService.deleteAllByPluginconfigid(id); - - //删除任务已启用插件 - taskpluginconfigService.deleteAllByPluginconfigid(id); - - }); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 批量导入插件配置(selfd不包含代码) - */ - @PostMapping(value = "/batchAdd") - public Result batchAdd(@RequestParam("file") MultipartFile file) throws IOException { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!"text/plain".equals(fileContentType)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!"txt".equals(suffix)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String line; - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { - while ((line = bf.readLine()) != null) { - String[] pluginConfigArr = line.split("\\|"); - String pluginName = pluginConfigArr[0]; - String pluginArgs = pluginConfigArr[1]; - String pluginRisk = pluginConfigArr[2]; - String pluginType = pluginConfigArr[3]; - String pluginValidateType = pluginConfigArr[4]; - String pluginTimeout = pluginConfigArr[5]; - - String assetServiceName = pluginConfigArr[6]; - String assetVersionName = pluginConfigArr[7]; - String vulnKeywordName = pluginConfigArr[8]; - String vulnName = pluginConfigArr[9]; - - String pluginConfigId; - Pluginconfig dbPluginConfig = pluginconfigService.findByNameAndType(pluginName, pluginType); - if (Objects.isNull(dbPluginConfig)) { - //插件不存在,新增一个插件 - pluginConfigId = idWorker.nextId() + ""; - if (Objects.isNull(pluginTimeout) || pluginTimeout.isEmpty()) { - pluginTimeout = "0"; - } - pluginconfigService.add(new Pluginconfig(pluginConfigId, pluginName, pluginArgs, pluginRisk, pluginType, pluginValidateType, pluginTimeout, null)); - - if (!assetServiceName.isEmpty()) { - pluginassetserviceService.add(new Pluginassetservice(idWorker.nextId() + "", pluginConfigId, assetServiceName)); - } - //资产版本 - if (!assetVersionName.isEmpty()) { - pluginassetversionService.add(new Pluginassetversion(idWorker.nextId() + "", pluginConfigId, assetVersionName)); - } - //漏洞关键字 - if (!vulnKeywordName.isEmpty()) { - vulnkeywordService.add(new Vulnkeyword(idWorker.nextId() + "", pluginConfigId, vulnKeywordName)); - } - //插件与漏洞关联 - //没有明确漏洞名称,直接关联默认漏洞 - Vuln vulnInDb; - if ("默认".equals(vulnName)) { - vulnInDb = vulnService.findByName(vulnName + pluginRisk); - } else { - //有漏洞名称 - vulnInDb = vulnService.findByName(vulnName); - //漏洞名称不在漏洞wiki,还是关联默认漏洞 - if (Objects.isNull(vulnInDb)) { - vulnInDb = vulnService.findByName("默认" + pluginRisk); - } - } - vulnpluginconfigService.add(new Vulnpluginconfig(idWorker.nextId() + "", vulnInDb.getId(), pluginConfigId)); - - } else { - //插件存在,服务、版本、关键字不存在则新增,存在不做处理 - pluginConfigId = dbPluginConfig.getId(); - if (!assetServiceName.isEmpty() && Objects.isNull(pluginassetserviceService.findByPluginconfigidAndService(pluginConfigId, assetServiceName))) { - pluginassetserviceService.add(new Pluginassetservice(idWorker.nextId() + "", pluginConfigId, assetServiceName)); - } - //资产版本 - if (!assetVersionName.isEmpty() && Objects.isNull(pluginassetversionService.findByPluginconfigidAndService(pluginConfigId, assetVersionName))) { - pluginassetversionService.add(new Pluginassetversion(idWorker.nextId() + "", pluginConfigId, assetVersionName)); - } - //漏洞关键字 - if (!vulnKeywordName.isEmpty() && Objects.isNull(vulnkeywordService.findByPluginconfigidAndService(pluginConfigId, vulnKeywordName))) { - vulnkeywordService.add(new Vulnkeyword(idWorker.nextId() + "", pluginConfigId, vulnKeywordName)); - } - //插件与漏洞关联 - //已明确漏洞名称,更新关联漏洞 - if (!"默认".equals(vulnName)) { - Vuln vulnDefault = vulnService.findByName("默认" + pluginRisk); - Vuln vulnInDb = vulnService.findByName(vulnName); - if (!Objects.isNull(vulnInDb)) { - Vulnpluginconfig vulnpluginconfig = vulnpluginconfigService.findByVulnidAndPluginconfigid(vulnDefault.getId(), pluginConfigId); - if (!Objects.isNull(vulnpluginconfig)) { - vulnpluginconfig.setVulnid(vulnInDb.getId()); - vulnpluginconfigService.update(vulnpluginconfig); - } - - } - } - } - } - } catch (IOException ignored) { - } - - return new Result(true, StatusCode.OK, "插件配置已上传处理,请稍后查看"); - - } - - - /** - * 批量导入包含插件代码的selfd插件配置 - */ - @RequestMapping(value = "/batchAddSelfd", method = RequestMethod.POST) - public Result batchAddSelfd(@RequestParam("file") MultipartFile[] multipartFiles) throws IOException { - StringBuilder sb = new StringBuilder(); - int FilesLength = multipartFiles.length; - if (FilesLength == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - if (FilesLength > 51) { - return new Result(false, StatusCode.ERROR, "文件超50个"); - } - for (MultipartFile file : multipartFiles) { - String originalFilename = file.getOriginalFilename(); - if (file.getSize() == 0) { - sb.append(originalFilename).append("文件为空").append(";"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - sb.append(originalFilename).append("文件大小不能超过 3M").append(";"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!"text/plain".equals(fileContentType)) { - sb.append(originalFilename).append("文件只能是 txt 格式").append(";"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!"txt".equals(suffix)) { - sb.append(originalFilename).append("文件只能是 txt 格式"); - } - } - if (sb.length() != 0) { - return new Result(false, StatusCode.ERROR, sb.toString()); - } - - - for (MultipartFile file : multipartFiles) { - - StringBuilder codeStringBuilder = new StringBuilder(); - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { - String line; - while ((line = bf.readLine()) != null) { - codeStringBuilder.append(line).append("\n"); - } - } catch (IOException ignored) { - } - String[] pluginConfigArr = codeStringBuilder.toString().split("\\|"); - String pluginName = pluginConfigArr[0]; - String pluginArgs = pluginConfigArr[1]; - String pluginRisk = pluginConfigArr[2]; - String pluginType = pluginConfigArr[3]; - String pluginValidateType = pluginConfigArr[4]; - String pluginTimeout = pluginConfigArr[5]; - - String assetServiceName = pluginConfigArr[6]; - String assetVersionName = pluginConfigArr[7]; - String vulnKeywordName = pluginConfigArr[8]; - String vulnName = pluginConfigArr[9]; - String pluginCode = null; - if (pluginConfigArr.length == 11) { - pluginCode = pluginConfigArr[10]; - } - - String pluginConfigId; - Pluginconfig dbPluginConfig = pluginconfigService.findByNameAndType(pluginName, pluginType); - if (Objects.isNull(dbPluginConfig)) { - //插件不存在,新增一个插件 - pluginConfigId = idWorker.nextId() + ""; - if (Objects.isNull(pluginTimeout) || pluginTimeout.isEmpty()) { - pluginTimeout = "0"; - } - pluginconfigService.add(new Pluginconfig(pluginConfigId, pluginName, pluginArgs, pluginRisk, pluginType, pluginValidateType, pluginTimeout, pluginCode)); - - if (!assetServiceName.isEmpty()) { - pluginassetserviceService.add(new Pluginassetservice(idWorker.nextId() + "", pluginConfigId, assetServiceName)); - } - //资产版本 - if (!assetVersionName.isEmpty()) { - pluginassetversionService.add(new Pluginassetversion(idWorker.nextId() + "", pluginConfigId, assetVersionName)); - } - //漏洞关键字 - if (!vulnKeywordName.isEmpty()) { - vulnkeywordService.add(new Vulnkeyword(idWorker.nextId() + "", pluginConfigId, vulnKeywordName)); - } - //插件与漏洞关联 - //没有明确漏洞名称,直接关联默认漏洞 - Vuln vulnInDb; - if ("默认".equals(vulnName)) { - vulnInDb = vulnService.findByName(vulnName + pluginRisk); - } else { - //有漏洞名称 - vulnInDb = vulnService.findByName(vulnName); - //漏洞名称不在漏洞wiki,还是关联默认漏洞 - if (Objects.isNull(vulnInDb)) { - vulnInDb = vulnService.findByName("默认" + pluginRisk); - } - } - vulnpluginconfigService.add(new Vulnpluginconfig(idWorker.nextId() + "", vulnInDb.getId(), pluginConfigId)); - - } else { - //插件存在,服务、版本、关键字不存在则新增,存在不做处理 - pluginConfigId = dbPluginConfig.getId(); - if (!assetServiceName.isEmpty() && Objects.isNull(pluginassetserviceService.findByPluginconfigidAndService(pluginConfigId, assetServiceName))) { - pluginassetserviceService.add(new Pluginassetservice(idWorker.nextId() + "", pluginConfigId, assetServiceName)); - } - //资产版本 - if (!assetVersionName.isEmpty() && Objects.isNull(pluginassetversionService.findByPluginconfigidAndService(pluginConfigId, assetVersionName))) { - pluginassetversionService.add(new Pluginassetversion(idWorker.nextId() + "", pluginConfigId, assetVersionName)); - } - //漏洞关键字 - if (!vulnKeywordName.isEmpty() && Objects.isNull(vulnkeywordService.findByPluginconfigidAndService(pluginConfigId, vulnKeywordName))) { - vulnkeywordService.add(new Vulnkeyword(idWorker.nextId() + "", pluginConfigId, vulnKeywordName)); - } - //插件与漏洞关联 - //已明确漏洞名称,更新关联漏洞 - if (!"默认".equals(vulnName)) { - Vuln vulnDefault = vulnService.findByName("默认" + pluginRisk); - Vuln vulnInDb = vulnService.findByName(vulnName); - if (!Objects.isNull(vulnInDb)) { - Vulnpluginconfig vulnpluginconfig = vulnpluginconfigService.findByVulnidAndPluginconfigid(vulnDefault.getId(), pluginConfigId); - if (!Objects.isNull(vulnpluginconfig)) { - vulnpluginconfig.setVulnid(vulnInDb.getId()); - vulnpluginconfigService.update(vulnpluginconfig); - } - - } - } - - //插件代码 - if (!Objects.isNull(pluginCode)) { - if (!pluginCode.isEmpty() && (Objects.isNull(dbPluginConfig.getPlugincode())) || dbPluginConfig.getPlugincode().isEmpty()) { - dbPluginConfig.setPlugincode(pluginCode); - pluginconfigService.update(dbPluginConfig); - } - } - - } - } - return new Result(true, StatusCode.OK, "selfd插件配置已上传处理,请稍后查看"); - - } - - -} diff --git a/center/src/main/java/com/tiji/center/controller/ProjectController.java b/center/src/main/java/com/tiji/center/controller/ProjectController.java deleted file mode 100755 index 4179c81..0000000 --- a/center/src/main/java/com/tiji/center/controller/ProjectController.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Project; -import com.tiji.center.service.ProjectService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * project控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/project") -public class ProjectController { - - @Autowired - private ProjectService projectService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", projectService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", projectService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = projectService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", projectService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param project - */ - @PostMapping - public Result add(@RequestBody Project project) { - String name = project.getName(); - Project projectInDb = projectService.findByIName(name); - if (Objects.isNull(projectInDb)) { - projectService.add(project); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:项目名称重复"); - } - } - - /** - * 修改 - * - * @param project - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Project project, @PathVariable String id) { - project.setId(id); - projectService.update(project); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - projectService.deleteById(id); - //删除任务的项目id - projectService.updateTaskByProjectIdSetProjectid2Null(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - projectService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/ProjectinfoController.java b/center/src/main/java/com/tiji/center/controller/ProjectinfoController.java deleted file mode 100755 index ee5df96..0000000 --- a/center/src/main/java/com/tiji/center/controller/ProjectinfoController.java +++ /dev/null @@ -1,459 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.*; -import com.tiji.center.service.*; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import util.IdWorker; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.*; - -/** - * projectinfo控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/projectinfo") -public class ProjectinfoController { - - @Autowired - private ProjectinfoService projectinfoService; - - @Autowired - private ContactProjectinfoService contactProjectinfoService; - @Autowired - private ProjectportwhitelistService projectportwhitelistService; - @Autowired - private AssetipService assetipService; - @Autowired - private AssetportService assetportService; - @Autowired - private DepartmentService departmentService; - @Autowired - private IdWorker idWorker; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", projectinfoService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - //departmentidname - Projectinfo projectinfo = projectinfoService.findById(id); - projectinfo.setDepartmentidname(projectinfo.getDepartmentid()); - return new Result(true, StatusCode.OK, "查询成功", projectinfo); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @Autowired - private ContactService contactService; - - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = projectinfoService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(projectinfo -> { - StringBuilder stringBuilder = new StringBuilder(); - String departmentid = projectinfo.getDepartmentid(); - if (!StringUtils.isEmpty(departmentid)) { - Department department = departmentService.findById(departmentid); - if (!Objects.isNull(department)) { - projectinfo.setDepartmentid(department.getDepartmentname()); - } - } - String id = projectinfo.getId(); - List contactProjectinfoList = contactProjectinfoService.findAllByProjectinfoid(id); - contactProjectinfoList.forEach(contactProjectinfo -> { - String contactid = contactProjectinfo.getContactid(); - Contact contact = contactService.findById(contactid); - if (!Objects.isNull(contact)) { - stringBuilder.append(contact.getName()).append(" \n"); - } - }); - projectinfo.setContact(stringBuilder.toString()); - }); - - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", projectinfoService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param projectinfo - */ - @PostMapping - public Result add(@RequestBody Projectinfo projectinfo) { - String projectname = projectinfo.getProjectname(); - String departmentidSubmit = projectinfo.getDepartmentid(); - String departmentid; - if (!StringUtils.isEmpty(departmentidSubmit)) { - Department department = departmentService.findById(departmentidSubmit); - if (Objects.isNull(department)) { - departmentid = idWorker.nextId() + ""; - Department departmentInDb = departmentService.findByDepartmentname(departmentidSubmit); - if (Objects.isNull(departmentInDb)) { - departmentService.add(new Department(departmentid, departmentidSubmit)); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:部门名称重复"); - } - } else { - departmentid = department.getId(); - } - } else { - departmentid = null; - } - - Projectinfo projectinfoInDb = projectinfoService.findByDepartmentidAndProjectname(departmentid, projectname); - if (Objects.isNull(projectinfoInDb)) { - String id = projectinfo.getId(); - if (Objects.isNull(id)) { - id = idWorker.nextId() + ""; - projectinfo.setId(id); - } - projectinfo.setDepartmentid(departmentid); - projectinfoService.add(projectinfo); - return new Result(true, StatusCode.OK, "增加成功", id); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:部门和项目组重复"); - } - } - - /** - * 修改 - * - * @param projectinfo - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Projectinfo projectinfo, @PathVariable String id) { - projectinfo.setId(id); - String projectname = projectinfo.getProjectname(); - String departmentidSubmit = projectinfo.getDepartmentid(); - String departmentid; - if (!StringUtils.isEmpty(departmentidSubmit)) { - Department department = departmentService.findById(departmentidSubmit); - if (Objects.isNull(department)) { - departmentid = idWorker.nextId() + ""; - String departmentname = departmentidSubmit; - Department departmentInDb = departmentService.findByDepartmentname(departmentname); - if (Objects.isNull(departmentInDb)) { - departmentService.add(new Department(departmentid, departmentidSubmit)); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:部门名称重复"); - } - } else { - departmentid = department.getId(); - } - } else { - departmentid = null; - } - Projectinfo projectinfoOld = projectinfoService.findById(id); - if(projectinfo.getProjectname().equals(projectinfoOld.getProjectname())){ - projectinfo.setDepartmentid(departmentid); - projectinfoService.update(projectinfo); - return new Result(true, StatusCode.OK, "修改成功"); - }else { - Projectinfo projectinfoInDb = projectinfoService.findByDepartmentidAndProjectname(departmentid, projectname); - if (Objects.isNull(projectinfoInDb)) { - projectinfo.setDepartmentid(departmentid); - projectinfoService.update(projectinfo); - return new Result(true, StatusCode.OK, "修改成功"); - } else { - return new Result(false, StatusCode.ERROR, "修改失败:部门和项目组重复"); - } - } - - - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - projectinfoService.deleteById(id); - //删除项目信息的同时,删除与联系人关联 - contactProjectinfoService.deleteAllByProjectinfoid(id); - //删除项目信息的同时,删除项目信息-端口白名单 - projectportwhitelistService.deleteAllByProjectinfoid(id); - //将资产ip的projectinfoid置空 - assetipService.updateAssetipByProjectinfoidSetProjectinfoid2Null(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - projectinfoService.deleteAllByIds(ids); - ids.forEach(id -> { - //删除项目信息的同时,删除与联系人关联 - contactProjectinfoService.deleteAllByProjectinfoid(id); - //删除项目信息的同时,删除项目信息-端口白名单 - projectportwhitelistService.deleteAllByProjectinfoid(id); - //将资产ip的projectinfoid置空 - assetipService.updateAssetipByProjectinfoidSetProjectinfoid2Null(id); - }); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 批量导入项目信息端口白名单 - */ - @PostMapping(value = "/batchAdd") - public Result batchAdd(@RequestParam("file") MultipartFile file) throws IOException { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!"text/plain".equals(fileContentType)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!"txt".equals(suffix)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - - String line; - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { - while ((line = bf.readLine()) != null) { - String projectInfoName = line.split("\\|")[0]; - String port = line.split("\\|")[1]; - boolean checkWhitelist = "1".equals(line.split("\\|")[2]); - boolean notifyWhitelist = "1".equals(line.split("\\|")[3]); - //端口为空,projectInfo白名单 - if (Objects.isNull(port) || port.isEmpty()) { - Projectinfo projectInfo = projectinfoService.findByProjectname(projectInfoName); - //不在数据库中 - if (Objects.isNull(projectInfo)) { - //此时没有部门,需要手动维护 - projectinfoService.add(new Projectinfo(idWorker.nextId() + "", null, projectInfoName, checkWhitelist, notifyWhitelist, new Date(), false)); - } else { - projectInfo.setCheckwhitelist(checkWhitelist); - projectInfo.setNotifywhitelist(notifyWhitelist); - projectinfoService.update(projectInfo); - //删除端口白名单 - projectportwhitelistService.deleteAllByProjectinfoid(projectInfo.getId()); - } - } else { - //端口白名单 - Projectinfo projectInfo = projectinfoService.findByProjectname(projectInfoName); - //不在数据库中 - String projectInfoId = idWorker.nextId() + ""; - if (Objects.isNull(projectInfo)) { - projectinfoService.add(new Projectinfo(projectInfoId, null, projectInfoName, false, false, new Date(), false)); - projectportwhitelistService.add(new Projectportwhitelist(idWorker.nextId() + "", projectInfoId, port, checkWhitelist, notifyWhitelist)); - } else { - //在数据库中,新增端口 - projectInfoId = projectInfo.getId(); - //如果是端口白名单,则projectInfo白名单置空 - if (checkWhitelist) { - projectInfo.setCheckwhitelist(false); - projectinfoService.add(projectInfo); - } - if (notifyWhitelist) { - projectInfo.setNotifywhitelist(false); - projectinfoService.add(projectInfo); - } - Projectportwhitelist projectportwhitelist = projectportwhitelistService.findByProjectinfoidAndPort(projectInfoId, port); - if (Objects.isNull(projectportwhitelist)) { - projectportwhitelistService.add(new Projectportwhitelist(idWorker.nextId() + "", projectInfoId, port, checkWhitelist, notifyWhitelist)); - } else { - projectportwhitelist.setCheckwhitelist(checkWhitelist); - projectportwhitelist.setNotifywhitelist(notifyWhitelist); - projectportwhitelistService.update(projectportwhitelist); - } - } - } - - } - } catch (IOException ignored) { - } - return new Result(true, StatusCode.OK, "项目信息端口白名单已上传处理,请稍后查看"); - - } - - - /** - * 更新资产库中项目信息端口白名单 - * - * @return - */ - @GetMapping(value = "/batchUpdate") - public Result batchUpdate() { - - List projectinfoList = projectinfoService.findAll(); - List assetipList = new ArrayList<>(); - List assetPortList = new ArrayList<>(); - projectinfoList.forEach(projectinfo -> { - String projectinfoid = projectinfo.getId(); - Boolean projectCheckwhitelist = projectinfo.getCheckwhitelist(); - Boolean projectNotifywhitelist = projectinfo.getNotifywhitelist(); - - List whitelistProjectPortList = projectportwhitelistService.findAllPortByProjectinfoid(projectinfoid); - //覆盖ip白名单,且没有白名单端口,直接更新当前项目的所有ip - if (projectinfo.getOverrideipwhitelist() && whitelistProjectPortList.isEmpty()) { - assetipService.updateByProjectinfoidAndCheckwhitelistAndAssetNotifywhitelist(projectinfoid, projectCheckwhitelist, projectNotifywhitelist); - } else { - //有白名单端口 - //查找当前项目的所有ip - Map searchMap = new HashMap<>(); - searchMap.put("projectinfoid", projectinfoid); - //根据项目id获取ip列表 - List searchAssetIpList = assetipService.findSearch(searchMap); - searchAssetIpList.forEach(assetip -> { - //ip白名单置空 - if (projectCheckwhitelist) { - assetip.setCheckwhitelist(false); - assetipList.add(assetip); - } - if (projectNotifywhitelist) { - assetip.setAssetnotifywhitelist(false); - assetipList.add(assetip); - } - - String assetIpId = assetip.getId(); - //根据ip编号获取端口列表 - List assetportList = assetportService.findAllByAssetipidAndDowntimeIsNull(assetIpId); - if (!assetportList.isEmpty()) { - assetportList.forEach(assetport -> { - String port = assetport.getPort(); - //当前端口在白名单whitelistProjectPortList中,加白 - if (whitelistProjectPortList.contains(port)) { - Projectportwhitelist projectportwhitelist = projectportwhitelistService.findByProjectinfoidAndPort(projectinfoid, port); - Boolean portCheckwhitelist = projectportwhitelist.getCheckwhitelist(); - Boolean portNotifywhitelist = projectportwhitelist.getNotifywhitelist(); - assetport.setCheckwhitelist(portCheckwhitelist); - assetport.setAssetnotifywhitelist(portNotifywhitelist); - assetPortList.add(assetport); - } - }); - } - }); - } - }); - //批量更新 - if (!assetPortList.isEmpty()) { - assetportService.batchAdd(assetPortList); - } - //批量更新 - if (!assetipList.isEmpty()) { - assetipService.batchAdd(assetipList); - } - return new Result(true, StatusCode.OK, "项目信息端口白名单已在后台处理,请稍后查看"); - } - - /** - * 根据id数组查询 - * - * @param ids - * @return - */ - @PostMapping(value = "/ids") - public Result findByAssetIpIds(@RequestBody String[] ids) { - return new Result(true, StatusCode.OK, "查询成功", projectinfoService.findByIds(ids)); - } - - /** - * 根据id查询联系人 - * - * @param id - * @return - */ - @RequestMapping(value = "/contact/{id}", method = RequestMethod.GET) - public Result findAllContactById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", projectinfoService.findAllContactById(id)); - } - - /** - * 根据项目信息id和联系人id,新增关联 - * - * @param projectinfoIdAndContactId - * @return - */ - @RequestMapping(value = "/contact", method = RequestMethod.POST) - public Result addContact(@RequestBody String[] projectinfoIdAndContactId) { - String projectinfoId = projectinfoIdAndContactId[0]; - String contactId = projectinfoIdAndContactId[1]; - if (!StringUtils.isEmpty((projectinfoId)) && !StringUtils.isEmpty((contactId))) { - ContactProjectinfo contactProjectinfo = contactProjectinfoService.findByContactidAndProjectinfoid(contactId, projectinfoId); - if (Objects.isNull(contactProjectinfo)) { - projectinfoService.addContact(projectinfoIdAndContactId); - return new Result(true, StatusCode.OK, "新增成功"); - } else { - return new Result(false, StatusCode.ERROR, "已存在负责人"); - } - } - return new Result(false, StatusCode.ERROR, "新增失败"); - } - - /** - * 根据contacid和projectinfoid删除 - * - * @param ids - */ - - @RequestMapping(value = "/delcontact", method = RequestMethod.POST) - public Result deleteContact(@RequestBody List ids) { - String id = ids.get(1); - String contactid = ids.get(0); - contactProjectinfoService.deleteByContactidAndProjectinfoid(id, contactid); - return new Result(true, StatusCode.OK, "删除成功"); - } - -} diff --git a/center/src/main/java/com/tiji/center/controller/ProjectportwhitelistController.java b/center/src/main/java/com/tiji/center/controller/ProjectportwhitelistController.java deleted file mode 100755 index c1dd2d0..0000000 --- a/center/src/main/java/com/tiji/center/controller/ProjectportwhitelistController.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Projectinfo; -import com.tiji.center.pojo.Projectportwhitelist; -import com.tiji.center.service.ProjectinfoService; -import com.tiji.center.service.ProjectportwhitelistService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * projectportwhitelist控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/projectportwhitelist") -public class ProjectportwhitelistController { - - @Autowired - private ProjectportwhitelistService projectportwhitelistService; - @Autowired - private ProjectinfoService projectinfoService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", projectportwhitelistService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", projectportwhitelistService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = projectportwhitelistService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(projectportwhitelist -> { - String projectinfoid = projectportwhitelist.getProjectinfoid(); - if (!StringUtils.isEmpty(projectinfoid)) { - Projectinfo projectinfo = projectinfoService.findById(projectinfoid); - projectportwhitelist.setProjectinfoid(projectinfo.getProjectname()); - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", projectportwhitelistService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param projectportwhitelist - */ - @PostMapping - public Result add(@RequestBody Projectportwhitelist projectportwhitelist) { - String port = projectportwhitelist.getPort(); - Projectportwhitelist projectportwhitelistInDb = projectportwhitelistService.findByProjectinfoidAndPort(projectportwhitelist.getProjectinfoid(), port); - if (Objects.isNull(projectportwhitelistInDb)) { - projectportwhitelistService.add(projectportwhitelist); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:端口重复"); - } - } - - /** - * 修改 - * - * @param projectportwhitelist - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Projectportwhitelist projectportwhitelist, @PathVariable String id) { - projectportwhitelist.setId(id); - projectportwhitelistService.update(projectportwhitelist); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - projectportwhitelistService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - projectportwhitelistService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/ProjectvulnnotifyController.java b/center/src/main/java/com/tiji/center/controller/ProjectvulnnotifyController.java deleted file mode 100755 index f7369e2..0000000 --- a/center/src/main/java/com/tiji/center/controller/ProjectvulnnotifyController.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Projectvulnnotify; -import com.tiji.center.service.ProjectvulnnotifyService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.Map; - -/** - * projectvulnnotify控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/projectvulnnotify") -public class ProjectvulnnotifyController { - - @Autowired - private ProjectvulnnotifyService projectvulnnotifyService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", projectvulnnotifyService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", projectvulnnotifyService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = projectvulnnotifyService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", projectvulnnotifyService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param projectvulnnotify - */ - @PostMapping - public Result add(@RequestBody Projectvulnnotify projectvulnnotify) { - projectvulnnotifyService.add(projectvulnnotify); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param projectvulnnotify - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Projectvulnnotify projectvulnnotify, @PathVariable String id) { - projectvulnnotify.setId(id); - projectvulnnotifyService.update(projectvulnnotify); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - projectvulnnotifyService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - -} diff --git a/center/src/main/java/com/tiji/center/controller/RiskportController.java b/center/src/main/java/com/tiji/center/controller/RiskportController.java deleted file mode 100755 index 66482a1..0000000 --- a/center/src/main/java/com/tiji/center/controller/RiskportController.java +++ /dev/null @@ -1,182 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Riskport; -import com.tiji.center.service.RiskportService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import util.IdWorker; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * riskport控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/riskport") -public class RiskportController { - - @Autowired - private RiskportService riskportService; - @Autowired - private IdWorker idWorker; - @Autowired - private RedisTemplate redisTemplate; - private String riskPortSetKey = "riskPortSet"; - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", riskportService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", riskportService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = riskportService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", riskportService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param riskport - */ - @PostMapping - public Result add(@RequestBody Riskport riskport) { - String port = riskport.getPort(); - Riskport riskportInDb = riskportService.findByPort(port); - if (Objects.isNull(riskportInDb)) { - riskportService.add(riskport); - redisTemplate.delete(riskPortSetKey); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:端口重复"); - } - } - - /** - * 修改 - * - * @param riskport - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Riskport riskport, @PathVariable String id) { - riskport.setId(id); - riskportService.update(riskport); - redisTemplate.delete(riskPortSetKey); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - riskportService.deleteById(id); - redisTemplate.delete(riskPortSetKey); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - riskportService.deleteAllByIds(ids); - redisTemplate.delete(riskPortSetKey); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 批量导入高危端口 - */ - @PostMapping(value = "/batchAdd") - public Result batchAdd(@RequestParam("file") MultipartFile file) { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!"text/plain".equals(fileContentType)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!"txt".equals(suffix)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - - String line; - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { - while ((line = bf.readLine()) != null) { - Riskport riskport = riskportService.findByPort(line); - if (Objects.isNull(riskport)) { - riskportService.add(new Riskport(idWorker.nextId() + "", line)); - } - } - } catch (IOException ignored) { - } - redisTemplate.delete(riskPortSetKey); - return new Result(true, StatusCode.OK, "高危端口已上传处理,请稍后查看"); - - } - -} diff --git a/center/src/main/java/com/tiji/center/controller/RiskserviceController.java b/center/src/main/java/com/tiji/center/controller/RiskserviceController.java deleted file mode 100755 index 67bbec7..0000000 --- a/center/src/main/java/com/tiji/center/controller/RiskserviceController.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Riskservice; -import com.tiji.center.service.RiskserviceService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import util.IdWorker; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * riskservice控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/riskservice") -public class RiskserviceController { - - @Autowired - private RiskserviceService riskserviceService; - @Autowired - private IdWorker idWorker; - @Autowired - private RedisTemplate redisTemplate; - private String riskServiceSetKey = "riskServiceSet"; - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", riskserviceService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", riskserviceService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = riskserviceService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", riskserviceService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param riskservice - */ - @PostMapping - public Result add(@RequestBody Riskservice riskservice) { - String service = riskservice.getService(); - Riskservice riskserviceInDb = riskserviceService.findByService(service); - if (Objects.isNull(riskserviceInDb)) { - riskserviceService.add(riskservice); - redisTemplate.delete(riskServiceSetKey); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:服务重复"); - } - } - - /** - * 修改 - * - * @param riskservice - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Riskservice riskservice, @PathVariable String id) { - riskservice.setId(id); - riskserviceService.update(riskservice); - redisTemplate.delete(riskServiceSetKey); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - riskserviceService.deleteById(id); - redisTemplate.delete(riskServiceSetKey); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - riskserviceService.deleteAllByIds(ids); - redisTemplate.delete(riskServiceSetKey); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 批量导入高危服务 - */ - @PostMapping(value = "/batchAdd") - public Result batchAdd(@RequestParam("file") MultipartFile file) { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!"text/plain".equals(fileContentType)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!"txt".equals(suffix)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - - String line; - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { - while ((line = bf.readLine()) != null) { - Riskservice riskservice = riskserviceService.findByService(line); - if (Objects.isNull(riskservice)) { - riskserviceService.add(new Riskservice(idWorker.nextId() + "", line)); - } - } - } catch (IOException ignored) { - } - redisTemplate.delete(riskServiceSetKey); - return new Result(true, StatusCode.OK, "高危服务已上传处理,请稍后查看"); - - } -} diff --git a/center/src/main/java/com/tiji/center/controller/RiskversionController.java b/center/src/main/java/com/tiji/center/controller/RiskversionController.java deleted file mode 100755 index 7774eb8..0000000 --- a/center/src/main/java/com/tiji/center/controller/RiskversionController.java +++ /dev/null @@ -1,182 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Riskversion; -import com.tiji.center.service.RiskversionService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import util.IdWorker; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * riskversion控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/riskversion") -public class RiskversionController { - - @Autowired - private RiskversionService riskversionService; - @Autowired - private IdWorker idWorker; - @Autowired - private RedisTemplate redisTemplate; - private String riskVersionSetKey = "riskVersionSet"; - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", riskversionService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", riskversionService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = riskversionService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", riskversionService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param riskversion - */ - @PostMapping - public Result add(@RequestBody Riskversion riskversion) { - String version = riskversion.getVersion(); - Riskversion riskversionInDb = riskversionService.findByVersion(version); - if (Objects.isNull(riskversionInDb)) { - riskversionService.add(riskversion); - redisTemplate.delete(riskVersionSetKey); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:版本重复"); - } - } - - /** - * 修改 - * - * @param riskversion - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Riskversion riskversion, @PathVariable String id) { - riskversion.setId(id); - riskversionService.update(riskversion); - redisTemplate.delete(riskVersionSetKey); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - riskversionService.deleteById(id); - redisTemplate.delete(riskVersionSetKey); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - riskversionService.deleteAllByIds(ids); - redisTemplate.delete(riskVersionSetKey); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 批量导入高危服务 - */ - @PostMapping(value = "/batchAdd") - public Result batchAdd(@RequestParam("file") MultipartFile file) { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!"text/plain".equals(fileContentType)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!"txt".equals(suffix)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - - String line; - //20201012 优化 去除bf.close,bf放到try中 - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { - while ((line = bf.readLine()) != null) { - Riskversion riskversion = riskversionService.findByVersion(line); - if (Objects.isNull(riskversion)) { - riskversionService.add(new Riskversion(idWorker.nextId() + "", line)); - } - } - } catch (IOException ignored) { - } - redisTemplate.delete(riskVersionSetKey); - return new Result(true, StatusCode.OK, "高危版本已上传处理,请稍后查看"); - - } -} diff --git a/center/src/main/java/com/tiji/center/controller/SendmailconfigController.java b/center/src/main/java/com/tiji/center/controller/SendmailconfigController.java deleted file mode 100755 index 245f692..0000000 --- a/center/src/main/java/com/tiji/center/controller/SendmailconfigController.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Sendmailconfig; -import com.tiji.center.service.SendmailconfigService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.Map; - -/** - * sendmailconfig控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/sendmailconfig") -public class SendmailconfigController { - - @Autowired - private SendmailconfigService sendmailconfigService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", sendmailconfigService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", sendmailconfigService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = sendmailconfigService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", sendmailconfigService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param sendmailconfig - */ - @PostMapping - public Result add(@RequestBody Sendmailconfig sendmailconfig) { - sendmailconfigService.add(sendmailconfig); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param sendmailconfig - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Sendmailconfig sendmailconfig, @PathVariable String id) { - sendmailconfig.setId(id); - sendmailconfigService.update(sendmailconfig); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - sendmailconfigService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - -} diff --git a/center/src/main/java/com/tiji/center/controller/SolutionController.java b/center/src/main/java/com/tiji/center/controller/SolutionController.java deleted file mode 100755 index 5199e5d..0000000 --- a/center/src/main/java/com/tiji/center/controller/SolutionController.java +++ /dev/null @@ -1,148 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Solution; -import com.tiji.center.pojo.Vuln; -import com.tiji.center.service.SolutionService; -import com.tiji.center.service.VulnService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * solution控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/solution") -public class SolutionController { - - @Autowired - private SolutionService solutionService; - @Autowired - private VulnService vulnService; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", solutionService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", solutionService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = solutionService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(Solution -> { - String vulnid = Solution.getVulnid(); - if (!StringUtils.isEmpty(vulnid)) { - Vuln vuln = vulnService.findById(vulnid); - if (!Objects.isNull(vuln)) { - Solution.setVulnid(vuln.getName()); - } - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", solutionService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param solution - */ - @PostMapping - public Result add(@RequestBody Solution solution) { - solutionService.add(solution); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param solution - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Solution solution, @PathVariable String id) { - solution.setId(id); - solutionService.update(solution); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - solutionService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - solutionService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据vulnId查询 - * - * @param vulnId vulnId - * @return - */ - @RequestMapping(value = "/vuln/{vulnId}", method = RequestMethod.GET) - public Result findAllByVulnId(@PathVariable String vulnId) { - return new Result(true, StatusCode.OK, "查询成功", solutionService.findAllByVulnId(vulnId)); - } - - -} diff --git a/center/src/main/java/com/tiji/center/controller/StatisticsController.java b/center/src/main/java/com/tiji/center/controller/StatisticsController.java deleted file mode 100755 index e73e9fc..0000000 --- a/center/src/main/java/com/tiji/center/controller/StatisticsController.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Statistics; -import com.tiji.center.service.StatisticsService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.Map; - -/** - * statistics控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/statistics") -public class StatisticsController { - - @Autowired - private StatisticsService statisticsService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", statisticsService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", statisticsService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = statisticsService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", statisticsService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param statistics - */ - @PostMapping - public Result add(@RequestBody Statistics statistics) { - statisticsService.add(statistics); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param statistics - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Statistics statistics, @PathVariable String id) { - statistics.setId(id); - statisticsService.update(statistics); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - statisticsService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - -} diff --git a/center/src/main/java/com/tiji/center/controller/TaskController.java b/center/src/main/java/com/tiji/center/controller/TaskController.java deleted file mode 100755 index a3fef1c..0000000 --- a/center/src/main/java/com/tiji/center/controller/TaskController.java +++ /dev/null @@ -1,377 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Agent; -import com.tiji.center.pojo.Nmapconfig; -import com.tiji.center.pojo.Project; -import com.tiji.center.pojo.Task; -import com.tiji.center.schedule.ExecuteCheckTaskScheduler; -import com.tiji.center.schedule.ExecuteWorkTaskScheduler; -import com.tiji.center.schedule.quartz.QuartzJob; -import com.tiji.center.schedule.quartz.QuartzJobService; -import com.tiji.center.service.*; -import com.tiji.center.util.TijiHelper; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.quartz.*; -import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.*; -import util.IdWorker; - -import java.text.ParseException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - - -/** - * task控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/task") -public class TaskController { - - @Autowired - private TaskService taskService; - - @Autowired - private TaskDispatcherService taskDispatcherService; - - @Autowired - private NmapconfigService nmapconfigService; - - @Autowired - private QuartzJobService quartzJobService; - - @Autowired - private IdWorker idWorker; - - @Autowired - private AgentService agentService; - @Autowired - private TaskpluginconfigService taskpluginconfigService; - @Autowired - private RabbitMessagingTemplate rabbitMessagingTemplate; - @Autowired - private ProjectService projectService; - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", taskService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", taskService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = taskService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(task -> { - String taskparentid = task.getTaskparentid(); - if (!StringUtils.isEmpty(taskparentid)) { - Task task1 = taskService.findById(taskparentid); - task.setTaskparentid(task1.getName()); - } - - String taskId = task.getId(); - String projectid = task.getProjectid(); - if (!StringUtils.isEmpty(projectid)) { - Project project = projectService.findById(projectid); - if (!Objects.isNull(project)) { - task.setProjectid(project.getName()); - } - } - List childTaskList = taskService.findAllByTaskparentid(taskId); - String name = task.getName(); - if (!StringUtils.isEmpty(name)) { - task.setStatistic(String.valueOf(childTaskList.size())); - } - Double taskPercent = taskService.getTaskPercent(taskId); - task.setPercentage(String.valueOf(taskPercent)); - try { - String triggerStates = quartzJobService.getTriggerStates(taskId); - task.setJobstate(triggerStates); - } catch (SchedulerException ignored) { - } - - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult<>(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", taskService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param task - */ - @PostMapping - public Result add(@RequestBody Task task) { - String taskId = ""; - if (Objects.isNull(task.getId())) { - taskId = idWorker.nextId() + ""; - task.setId(taskId); - } - taskService.add(task); - if ("mass2Nmap".equals(task.getWorktype()) || "nse".equals(task.getWorktype()) || "selfd".equals(task.getWorktype())) { - return new Result(true, StatusCode.OK, "增加成功", taskId); - } else { - return new Result(true, StatusCode.OK, "增加成功"); - } - - } - - /** - * 修改 - * - * @param task - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Task task, @PathVariable String id) { - task.setId(id); - taskService.update(task); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - //nmap配置在service层删除 - taskService.deleteById(id); - //删除任务插件配置 - taskpluginconfigService.deleteAllByTaskid(id); - //删除子任务 - taskService.deleteAllByTaskparentid(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据taskId开始任务 - * - * @param id - * @return - */ - @RequestMapping(value = "/execute/{id}", method = RequestMethod.GET) - public Result executeTask(@PathVariable String id) throws SchedulerException, InterruptedException, ParseException { - List onlineAgentList = agentService.findAllByOnline(true); - if (onlineAgentList.isEmpty()) { - return new Result(false, StatusCode.ERROR, "没有agent在线"); - } - Map taskInfo = new HashMap<>(); - Task task = taskService.findById(id); - String taskTargetIp = task.getTargetip(); - String taskWorkType = task.getWorktype(); - boolean crontask = task.getCrontask(); - - //非cron任务,直接执行任务 - if (!crontask) { - //对资产库中的所有whitelist为false的ip进行nse/selfd/httpp - if ("assetip".equals(taskTargetIp) && ("nse".equals(taskWorkType) || "selfd".equals(taskWorkType) || "httpp".equals(taskWorkType))) { - taskDispatcherService.executeTotalCheck(id); - } else { - //标准任务 - //判断有没有nmap的配置 - if ("mass2Nmap".equals(taskWorkType)) { - Nmapconfig nmapconfig = nmapconfigService.findByTaskid(id); - if (Objects.isNull(nmapconfig)) { - return new Result(false, StatusCode.ERROR, "失败:nmap配置为空"); - } - } - taskInfo = taskDispatcherService.executeWork(id); - } - } else { - //cron任务,进行schedule - String cronExpression = task.getCronexpression(); - if (Objects.isNull(cronExpression) || cronExpression.isEmpty()) { - return new Result(false, StatusCode.ERROR, "失败:Cron表达式为空"); - } - if (!CronExpression.isValidExpression(cronExpression)) { - return new Result(false, StatusCode.ERROR, "失败:Cron表达式错误"); - } - String jobKeyName = "jobKeyName_" + id; - String jobKeyGroup = "jobKeyGroup_" + id; - JobKey jobKey = JobKey.jobKey(jobKeyName, jobKeyGroup); - Map jobDataMap = new HashMap<>(); - jobDataMap.put("taskId", id); - jobDataMap.put("taskTargetIp", taskTargetIp); - jobDataMap.put("taskWorkType", taskWorkType); - //jobDataMap.put("taskInfo", taskInfo); - - QuartzJob quartzJob = new QuartzJob(jobKey, cronExpression, jobDataMap, ExecuteWorkTaskScheduler.class); - quartzJobService.scheduleJob(quartzJob); - - taskInfo.putAll(TijiHelper.cronParseResult(cronExpression)); - } - return new Result(true, StatusCode.OK, "成功开始", taskInfo); - } - - /** - * 根据taskId开始check任务 - * - * @param id - * @return - */ - @RequestMapping(value = "/execute/check/{id}", method = RequestMethod.GET) - public Result executeCheck(@PathVariable String id) throws SchedulerException, ParseException { - List onlineAgentList = agentService.findAllByOnline(true); - if (onlineAgentList.isEmpty()) { - return new Result(false, StatusCode.ERROR, "没有agent在线"); - } - Map taskInfo = new HashMap<>(); - Task task = taskService.findById(id); - //非cron任务,直接执行任务 - boolean crontask = task.getCrontask(); - if (!crontask) { - taskDispatcherService.executeCheck(id); - } else { - //cron任务,进行schedule - String cronExpression = task.getCronexpression(); - if (Objects.isNull(cronExpression) || cronExpression.isEmpty()) { - throw new RuntimeException("Cron表达式为空"); - } - if (!CronExpression.isValidExpression(cronExpression)) { - throw new RuntimeException("Cron表达式错误"); - } - String jobKeyName = "jobKeyName_" + id; - String jobKeyGroup = "jobKeyGroup_" + id; - JobKey jobKey = JobKey.jobKey(jobKeyName, jobKeyGroup); - Map jobDataMap = new HashMap<>(); - jobDataMap.put("taskId", id); - - QuartzJob quartzJob = new QuartzJob(jobKey, cronExpression, jobDataMap, ExecuteCheckTaskScheduler.class); - quartzJobService.scheduleJob(quartzJob); - taskInfo.putAll(TijiHelper.cronParseResult(cronExpression)); - - } - return new Result(true, StatusCode.OK, "成功开始", taskInfo); - } - - /** - * 根据taskId停止任务,并删除计划任务 - * - * @param id - * @return - */ - @RequestMapping(value = "/stop/{id}", method = RequestMethod.GET) - public Result stopTask(@PathVariable String id) throws SchedulerException { - taskDispatcherService.stopMutilTaskAndDeleteSchedule(id); - return new Result(true, StatusCode.OK, "成功结束", "任务已停止, 并删除计划任务"); - } - - /** - * 根据taskId获取任务状态 - * - * @param id - * @return - */ - @RequestMapping(value = "/status/{id}", method = RequestMethod.GET) - public Result getTaskStatus(@PathVariable String id) { - Map taskStatus = taskDispatcherService.getMutilTaskStatus(id); - return new Result(true, StatusCode.OK, "任务状态", taskStatus); - } - - /** - * 根据taskId重新开始任务 - * - * @param id - * @return - */ - @RequestMapping(value = "/repeat/{id}", method = RequestMethod.GET) - public Result repeatTask(@PathVariable String id) throws InterruptedException { - List onlineAgentList = agentService.findAllByOnline(true); - if (onlineAgentList.isEmpty()) { - return new Result(false, StatusCode.ERROR, "没有agent在线"); - } - Map taskInfo = taskDispatcherService.repeat(id); - return new Result(true, StatusCode.OK, "成功开始", taskInfo); - } - - - /** - * 根据taskId删除schedule任务,不终止当前任务 - * - * @param id - * @return - */ - @RequestMapping(value = "/schedule/{id}", method = RequestMethod.DELETE) - public Result stopScheduleTask(@PathVariable String id) throws SchedulerException { - String jobKeyName = "jobKeyName_" + id; - String jobKeyGroup = "jobKeyGroup_" + id; - JobKey jobKey = JobKey.jobKey(jobKeyName, jobKeyGroup); - quartzJobService.deleteJob(jobKey); - Task task = taskService.findById(id); - task.setCrontask(false); - taskService.update(task); - return new Result(true, StatusCode.OK, "成功删除", "计划任务已删除"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - taskService.deleteAllByIds(ids); - ids.forEach(id -> { - //nmap配置在service层删除 - //删除任务插件配置 - taskpluginconfigService.deleteAllByTaskid(id); - }); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据taskId获取任务状态 - * - * @param id - * @return - */ - @RequestMapping(value = "/statuspercent/{id}", method = RequestMethod.GET) - public Result getTaskStatusPercent(@PathVariable String id) { - Map taskStatus = taskDispatcherService.getTaskStatusPercent(id); - return new Result(true, StatusCode.OK, "任务状态", taskStatus); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/TaskipController.java b/center/src/main/java/com/tiji/center/controller/TaskipController.java deleted file mode 100755 index 86f6573..0000000 --- a/center/src/main/java/com/tiji/center/controller/TaskipController.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Task; -import com.tiji.center.pojo.Taskip; -import com.tiji.center.service.TaskService; -import com.tiji.center.service.TaskipService; -import com.tiji.center.service.TaskportService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * taskip控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/taskip") -public class TaskipController { - - @Autowired - private TaskipService taskipService; - @Autowired - private TaskportService taskportService; - @Autowired - private TaskService taskService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", taskipService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", taskipService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = taskipService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(taskip -> { - String taskid = taskip.getTaskid(); - Task task = taskService.findById(taskid); - if (!Objects.isNull(task)) { - taskip.setTaskid(task.getName()); - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", taskipService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param taskip - */ - @PostMapping - public Result add(@RequestBody Taskip taskip) { - taskipService.add(taskip); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param taskip - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Taskip taskip, @PathVariable String id) { - taskip.setId(id); - taskipService.update(taskip); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - taskipService.deleteById(id); - //删除资产端口 - taskportService.deleteAllByTaskipid(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据id数组查询 - * - * @param ids - * @return - */ - @PostMapping(value = "/ids") - public Result findByAssetIpIds(@RequestBody String[] ids) { - return new Result(true, StatusCode.OK, "查询成功", taskipService.findByIds(ids)); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - taskipService.deleteAllByIds(ids); - ids.forEach(id -> { - //删除资产端口 - taskportService.deleteAllByTaskipid(id); - }); - return new Result(true, StatusCode.OK, "删除成功"); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/TaskpluginconfigController.java b/center/src/main/java/com/tiji/center/controller/TaskpluginconfigController.java deleted file mode 100755 index 2b3e657..0000000 --- a/center/src/main/java/com/tiji/center/controller/TaskpluginconfigController.java +++ /dev/null @@ -1,227 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Pluginconfig; -import com.tiji.center.pojo.Task; -import com.tiji.center.pojo.Taskip; -import com.tiji.center.pojo.Taskpluginconfig; -import com.tiji.center.service.PluginconfigService; -import com.tiji.center.service.TaskService; -import com.tiji.center.service.TaskpluginconfigService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.*; -import util.IdWorker; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * taskpluginconfig控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/taskpluginconfig") -public class TaskpluginconfigController { - - @Autowired - private TaskpluginconfigService taskpluginconfigService; - @Autowired - private IdWorker idWorker; - @Autowired - private TaskService taskService; - - @Autowired - private PluginconfigService pluginconfigService; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", taskpluginconfigService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", taskpluginconfigService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = taskpluginconfigService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(taskpluginconfig -> { - String taskid = taskpluginconfig.getTaskid(); - if (!StringUtils.isEmpty(taskid)) { - Task task = taskService.findById(taskid); - if (!Objects.isNull(task)) { - taskpluginconfig.setTaskid(task.getName()); - } - } - String pluginconfigid = taskpluginconfig.getPluginconfigid(); - if (!StringUtils.isEmpty(pluginconfigid)) { - Pluginconfig pluginconfig = pluginconfigService.findById(pluginconfigid); - if (!Objects.isNull(pluginconfig)) { - taskpluginconfig.setPluginconfigid(pluginconfig.getName()); - } - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", taskpluginconfigService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param taskpluginconfig - */ - @PostMapping - public Result add(@RequestBody Taskpluginconfig taskpluginconfig) { - String taskid = taskpluginconfig.getTaskid(); - String pluginconfigid = taskpluginconfig.getPluginconfigid(); - Taskpluginconfig taskidAndPluginconfigid = taskpluginconfigService.findByTaskidAndPluginconfigid(taskid, pluginconfigid); - if (Objects.isNull(taskidAndPluginconfigid)) { - taskpluginconfigService.add(taskpluginconfig); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败"); - } - } - - /** - * 修改 - * - * @param taskpluginconfig - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Taskpluginconfig taskpluginconfig, @PathVariable String id) { - String taskid = taskpluginconfig.getTaskid(); - String pluginconfigid = taskpluginconfig.getPluginconfigid(); - Taskpluginconfig taskidAndPluginconfigid = taskpluginconfigService.findByTaskidAndPluginconfigid(taskid, pluginconfigid); - if (Objects.isNull(taskidAndPluginconfigid)) { - taskpluginconfig.setId(id); - taskpluginconfigService.update(taskpluginconfig); - return new Result(true, StatusCode.OK, "修改成功"); - } else { - return new Result(false, StatusCode.ERROR, "修改失败"); - } - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - taskpluginconfigService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - taskpluginconfigService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据taskid查询 - * - * @param taskid - * @return - */ - @RequestMapping(value = "/task/{taskid}", method = RequestMethod.GET) - public Result findAllByTaskid(@PathVariable String taskid) { - return new Result(true, StatusCode.OK, "查询成功", taskpluginconfigService.findPluginconfigidByTaskid(taskid)); - } - - - /** - * 根据taskid和pluginids批量增加 - * - * @param ids - */ - @RequestMapping(value = "/plugin/ids", method = RequestMethod.POST) - public Result addAllByIds(@RequestBody String[] ids) { - String taskid = ids[0]; - boolean addFlag = false; - for (int i = 1; i < ids.length; i++) { - String pluginconfigid = ids[i]; - Taskpluginconfig taskidAndPluginconfigid = taskpluginconfigService.findByTaskidAndPluginconfigid(taskid, pluginconfigid); - if (Objects.isNull(taskidAndPluginconfigid)) { - taskpluginconfigService.add(new Taskpluginconfig(idWorker.nextId() + "", taskid, pluginconfigid)); - addFlag = true; - } - } - if (addFlag) { - return new Result(true, StatusCode.OK, "启用成功"); - } else { - return new Result(false, StatusCode.ERROR, "启用失败"); - - } - } - - /** - * 根据taskid删除 - * - * @param id - */ - @RequestMapping(value = "/task/{id}", method = RequestMethod.DELETE) - public Result deleteAllByTaskid(@PathVariable String id) { - taskpluginconfigService.deleteAllByTaskid(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据taskid和pluginids批量删除 - * - * @param ids - */ - @RequestMapping(value = "/task/ids", method = RequestMethod.POST) - public Result deleteAllIds(@RequestBody List ids) { - String taskid = ids.get(0); - ids.parallelStream().forEach(pluginconfigid -> { - taskpluginconfigService.deleteAllByTaskidAndPluginconfigid(taskid, pluginconfigid); - }); - return new Result(true, StatusCode.OK, "禁用成功"); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/TaskportController.java b/center/src/main/java/com/tiji/center/controller/TaskportController.java deleted file mode 100755 index aa4201f..0000000 --- a/center/src/main/java/com/tiji/center/controller/TaskportController.java +++ /dev/null @@ -1,165 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.*; -import com.tiji.center.service.TaskService; -import com.tiji.center.service.TaskipService; -import com.tiji.center.service.TaskportService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; - -import org.springframework.web.bind.annotation.*; - -import java.util.*; - -/** - * taskport控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/taskport") -public class TaskportController { - - @Autowired - private TaskportService taskportService; - @Autowired - private TaskipService taskipService; - @Autowired - private TaskService taskService; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", taskportService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", taskportService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - - //根据任务名称查询端口 - List taskPortIdList = new ArrayList<>(); - if (searchMap.containsKey("taskid")) { - //ip -> assetportid - String taskid = (String) searchMap.get("taskid"); - Map ipSearchMap = new HashMap<>(); - ipSearchMap.put("taskid", taskid); - List taskipList = taskipService.findSearch(ipSearchMap); - taskipList.forEach(taskip -> { - String taskipId = taskip.getId(); - List taskportList = taskportService.findByTaskipid(taskipId); - taskportList.forEach(taskport -> { - taskPortIdList.add(taskport.getId()); - }); - - }); - searchMap.put("id", taskPortIdList); - } - - System.out.println("taskPortIdList " + taskPortIdList); - Page pageList = taskportService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(taskport -> { - String taskipid = taskport.getTaskipid(); - if (!StringUtils.isEmpty(taskipid)) { - Taskip taskip = taskipService.findById(taskipid); - if (!Objects.isNull(taskip)) { - taskport.setTaskipid(taskip.getIpaddressv4()); - String taskid = taskip.getTaskid(); - if (!StringUtils.isEmpty(taskid)) { - Task task = taskService.findById(taskid); - if (!Objects.isNull(task)) { - taskport.setTaskname(task.getName()); - } - } - } - } - - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", taskportService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param taskport - */ - @PostMapping - public Result add(@RequestBody Taskport taskport) { - taskportService.add(taskport); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param taskport - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Taskport taskport, @PathVariable String id) { - taskport.setId(id); - taskportService.update(taskport); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - taskportService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - taskportService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } - -} diff --git a/center/src/main/java/com/tiji/center/controller/TitlewhitelistController.java b/center/src/main/java/com/tiji/center/controller/TitlewhitelistController.java deleted file mode 100755 index c45a54c..0000000 --- a/center/src/main/java/com/tiji/center/controller/TitlewhitelistController.java +++ /dev/null @@ -1,183 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Titlewhitelist; -import com.tiji.center.service.TitlewhitelistService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import util.IdWorker; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * titlewhitelist控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/titlewhitelist") -public class TitlewhitelistController { - - @Autowired - private TitlewhitelistService titlewhitelistService; - @Autowired - private IdWorker idWorker; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", titlewhitelistService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", titlewhitelistService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = titlewhitelistService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", titlewhitelistService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param titlewhitelist - */ - @PostMapping - public Result add(@RequestBody Titlewhitelist titlewhitelist) { - String title = titlewhitelist.getTitle(); - Titlewhitelist titleInDb = titlewhitelistService.findByTitle(title); - if (Objects.isNull(titleInDb)) { - titlewhitelistService.add(titlewhitelist); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:标题重复"); - } - } - - /** - * 修改 - * - * @param titlewhitelist - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Titlewhitelist titlewhitelist, @PathVariable String id) { - titlewhitelist.setId(id); - titlewhitelistService.update(titlewhitelist); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - titlewhitelistService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - titlewhitelistService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 批量导入标题白名单 - */ - @PostMapping(value = "/batchAdd") - public Result batchAdd(@RequestParam("file") MultipartFile file) throws IOException { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!"text/plain".equals(fileContentType)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!"txt".equals(suffix)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - - String line; - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8));) { - while ((line = bf.readLine()) != null) { - Titlewhitelist titlewhitelist = titlewhitelistService.findByTitle(line); - if (Objects.isNull(titlewhitelist)) { - titlewhitelistService.add(new Titlewhitelist(idWorker.nextId() + "", line)); - } - } - } catch (IOException ignored) { - } - return new Result(true, StatusCode.OK, "标题白名单已上传处理,请稍后查看"); - - } - - /** - * 删除 - * - * @param title - */ - @RequestMapping(value = "/title/{title}", method = RequestMethod.DELETE) - public Result deleteByTitle(@PathVariable String title) { - titlewhitelistService.deleteByTitle(title); - return new Result(true, StatusCode.OK, "删除成功"); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/UrlController.java b/center/src/main/java/com/tiji/center/controller/UrlController.java deleted file mode 100755 index 5e38bbb..0000000 --- a/center/src/main/java/com/tiji/center/controller/UrlController.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Url; -import com.tiji.center.service.UrlService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; - -/** - * url控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/url") -public class UrlController { - - @Autowired - private UrlService urlService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", urlService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", urlService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = urlService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", urlService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param url - */ - @PostMapping - public Result add(@RequestBody Url url) { - urlService.add(url); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param url - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Url url, @PathVariable String id) { - url.setId(id); - urlService.update(url); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - urlService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - urlService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据webinfoid查询 - * - * @param webinfoid webinfoid - * @return - */ - @RequestMapping(value = "/webinfo/{webinfoid}", method = RequestMethod.GET) - public Result findAllByWebinfoid(@PathVariable String webinfoid) { - return new Result(true, StatusCode.OK, "查询成功", urlService.findAllByWebinfoid(webinfoid)); - } - - /** - * 根据webinfoids查询所有链接pojo - * - * @param webinfoids - * @return - */ - @RequestMapping(value = "/webinfo", method = RequestMethod.POST) - public Result findAllByWebinfoIds(@RequestBody String[] webinfoids) { - return new Result(true, StatusCode.OK, "查询成功", urlService.findAllByWebinfoids(webinfoids)); - } - - /** - * 根据webinfoids查询所有链接pojo,webinfoid替换成端口 - * - * @param webinfoids - * @return - */ - @RequestMapping(value = "/webinfoids2port", method = RequestMethod.POST) - public Result findAllByWebinfoIds2Port(@RequestBody String[] webinfoids) { - return new Result(true, StatusCode.OK, "查询成功", urlService.findAllByWebinfoIds2Port(webinfoids)); - } - - /** - * 根据webinfoid查询 - * - * @param webinfoid webinfoid - * @return - */ - @RequestMapping(value = "/links/{webinfoid}", method = RequestMethod.GET) - public Result findLinksByWebinfoId(@PathVariable String webinfoid) { - return new Result(true, StatusCode.OK, "查询成功", urlService.findLinksByWebinfoId(webinfoid)); - } - -} diff --git a/center/src/main/java/com/tiji/center/controller/UserController.java b/center/src/main/java/com/tiji/center/controller/UserController.java deleted file mode 100755 index 4294d3d..0000000 --- a/center/src/main/java/com/tiji/center/controller/UserController.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.User; -import com.tiji.center.service.DictionarypasswordService; -import com.tiji.center.service.UserService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - - -/** - * user控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/user") -public class UserController { - - @Autowired - private UserService userService; - @Autowired - private BCryptPasswordEncoder bCryptPasswordEncoder; - @Autowired - private DictionarypasswordService dictionarypasswordService; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", userService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", userService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = userService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", userService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param user - */ - @PostMapping - public Result add(@RequestBody User user) { - String password = user.getPassword(); - if (Objects.isNull(password) || password.isEmpty() || password.length() < 8) { - return new Result(false, StatusCode.ERROR, "密码为空或长度少于8位"); - } - List allPassword = dictionarypasswordService.findAllPassword(); - if (allPassword.contains(password)) { - return new Result(false, StatusCode.ERROR, "密码在密码字典中,请重新设置"); - } - - userService.add(user); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param user - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody User user, @PathVariable String id) { - user.setId(id); - String oldPassword = user.getPassword(); - if (Objects.isNull(oldPassword) || oldPassword.isEmpty() || oldPassword.length() < 8) { - return new Result(false, StatusCode.ERROR, "密码为空或长度少于8位"); - } - if (oldPassword.startsWith("$2a$10$")) { - User user1 = userService.findById(id); - user.setPassword(user1.getPassword()); - } else { - //非BCrypt加密的,改密码 - List allPassword = dictionarypasswordService.findAllPassword(); - if (allPassword.contains(oldPassword)) { - return new Result(false, StatusCode.ERROR, "密码在密码字典中,请重新设置"); - } - String newPassword = bCryptPasswordEncoder.encode(oldPassword); - user.setPassword(newPassword); - } - - userService.update(user); - return new Result(true, StatusCode.OK, "修改成功"); - } - - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - userService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - userService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/UseragentController.java b/center/src/main/java/com/tiji/center/controller/UseragentController.java deleted file mode 100755 index 1be2160..0000000 --- a/center/src/main/java/com/tiji/center/controller/UseragentController.java +++ /dev/null @@ -1,202 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Useragent; -import com.tiji.center.service.UseragentService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import util.IdWorker; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * useragent控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/useragent") -public class UseragentController { - - @Autowired - private UseragentService useragentService; - @Autowired - private IdWorker idWorker; - @Autowired - private RedisTemplate redisTemplate; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", useragentService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", useragentService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = useragentService.findSearch(searchMap, page, size); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", useragentService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param useragent - */ - @PostMapping - public Result add(@RequestBody Useragent useragent) { - String ua = useragent.getUseragent(); - Useragent useragentInDb = useragentService.findByUseragent(ua); - if (Objects.isNull(useragentInDb)) { - useragentService.add(useragent); - //更新redis缓存 - freshUserAgentRedisCache(); - return new Result(true, StatusCode.OK, "增加成功"); - } else { - return new Result(false, StatusCode.ERROR, "增加失败:ua重复"); - } - } - - /** - * 修改 - * - * @param useragent - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Useragent useragent, @PathVariable String id) { - useragent.setId(id); - useragentService.update(useragent); - //更新redis缓存 - freshUserAgentRedisCache(); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - useragentService.deleteById(id); - //更新redis缓存 - freshUserAgentRedisCache(); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - useragentService.deleteAllByIds(ids); - //更新redis缓存 - freshUserAgentRedisCache(); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 批量导入ua - */ - @PostMapping(value = "/batchAdd") - public Result batchAdd(@RequestParam("file") MultipartFile file) throws IOException { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!"text/plain".equals(fileContentType)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!"txt".equals(suffix)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - - //List useragentList = new ArrayList<>(); - - String line; - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { - while ((line = bf.readLine()) != null) { - Useragent useragent = useragentService.findByUseragent(line); - if (Objects.isNull(useragent)) { - useragentService.add(new Useragent(idWorker.nextId() + "", line)); - } - } - } - //if (!useragentList.isEmpty()) { - // useragentService.batchAdd(useragentList); - //} - //更新redis缓存 - freshUserAgentRedisCache(); - return new Result(true, StatusCode.OK, "ua已上传处理,请稍后查看"); - - } - - /** - * 设置ua - */ - private void freshUserAgentRedisCache() { - - String redisUserAgent = "userAgentSet_"; - redisTemplate.delete(redisUserAgent); - List allUserAgent = useragentService.findAllDistinctUserAgentList(); - allUserAgent.parallelStream().forEach(ua -> redisTemplate.opsForSet().add(redisUserAgent, ua)); - } - -} diff --git a/center/src/main/java/com/tiji/center/controller/VulnController.java b/center/src/main/java/com/tiji/center/controller/VulnController.java deleted file mode 100755 index f741bf1..0000000 --- a/center/src/main/java/com/tiji/center/controller/VulnController.java +++ /dev/null @@ -1,362 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.*; -import com.tiji.center.service.*; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import util.IdWorker; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.*; - -/** - * vuln控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/vuln") -public class VulnController { - - @Autowired - private VulnService vulnService; - @Autowired - private IdWorker idWorker; - @Autowired - private CategorytopService categorytopService; - @Autowired - private CategorysecondService categorysecondService; - @Autowired - private DemocodeService democodeService; - @Autowired - private SolutionService solutionService; - @Autowired - private VulnpluginconfigService vulnpluginconfigService; - - @Autowired - private PluginconfigService pluginconfigService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", vulnService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", vulnService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = vulnService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(vuln -> { - String categorysecondid = vuln.getCategorysecondid(); - if (!StringUtils.isAllEmpty(categorysecondid)) { - Categorysecond categorysecond = categorysecondService.findById(categorysecondid); - if(!Objects.isNull(categorysecond)){ - vuln.setCategorysecondid(categorysecond.getName()); - } - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", vulnService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param vuln - */ - @PostMapping - public Result add(@RequestBody Vuln vuln) { - String name = vuln.getName(); - Vuln vulnInDb = vulnService.findByName(name); - if (Objects.isNull(vulnInDb)) { - if (Objects.isNull(vuln.getId())) { - String vulnId = idWorker.nextId() + ""; - vuln.setId(vulnId); - vulnService.add(vuln); - return new Result(true, StatusCode.OK, "增加成功", vulnId); - } else { - vulnService.add(vuln); - return new Result(true, StatusCode.OK, "增加成功"); - } - } else { - return new Result(false, StatusCode.ERROR, "增加失败:名称重复"); - } - } - - /** - * 修改 - * - * @param vuln - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Vuln vuln, @PathVariable String id) { - vuln.setId(id); - vulnService.update(vuln); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - vulnService.deleteById(id); - //删除示例代码 - democodeService.deleteAllByVulnId(id); - //删除解决方案 - solutionService.deleteAllByVulnId(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - vulnService.deleteAllByIds(ids); - ids.forEach(id -> { - //删除示例代码 - democodeService.deleteAllByVulnId(id); - //删除解决方案 - solutionService.deleteAllByVulnId(id); - }); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 批量导入漏洞分类 - */ - @RequestMapping(value = "/category", method = RequestMethod.POST) - public Result batchAddCategory(@RequestParam("file") MultipartFile file) throws IOException { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!"text/plain".equals(fileContentType)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!"txt".equals(suffix)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String line; - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8));) { - while ((line = bf.readLine()) != null) { - if (line.contains(":")) { - //一级分类 - String top = line.split(":")[0]; - String second; - String[] secondArr; - String topId = idWorker.nextId() + ""; - if (line.contains("|")) { - second = line.split(":")[1]; - secondArr = second.split("\\|"); - } else { - //没有二级分类,当前一级分类就是二级分类 - secondArr = new String[]{top}; - } - //top - Categorytop categorytop = categorytopService.findByName(top); - if (Objects.isNull(categorytop)) { - categorytopService.add(new Categorytop(topId, top)); - } else { - topId = categorytop.getId(); - } - if (secondArr.length != 0) { - //second - for (String secondName : secondArr) { - Categorysecond categorysecond = categorysecondService.findByName(secondName); - //没有second直接新增 - if (Objects.isNull(categorysecond)) { - String secondId = idWorker.nextId() + ""; - categorysecondService.add(new Categorysecond(secondId, topId, secondName)); - } else { - //有second,修改topid - categorysecond.setCategorytopid(topId); - categorysecondService.update(categorysecond); - } - } - } - } - } - } catch (IOException ignored) { - } - return new Result(true, StatusCode.OK, "漏洞分类已上传处理,请稍后查看"); - - } - - /** - * 批量导入漏洞详情 - */ - @RequestMapping(value = "/detail", method = RequestMethod.POST) - public Result batchAddDetail(@RequestParam("file") MultipartFile file) throws IOException { - if (Objects.isNull(file) || file.getSize() == 0) { - return new Result(false, StatusCode.ERROR, "文件为空"); - } - long fileSize = file.getSize(); - if (fileSize / 1024 / 1024 > 3) { - return new Result(false, StatusCode.ERROR, "文件大小不能超过 3M"); - } - String fileContentType = file.getContentType(); - assert fileContentType != null; - if (!"text/plain".equals(fileContentType)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String fileOriginalFilename = file.getOriginalFilename(); - assert fileOriginalFilename != null; - String suffix = fileOriginalFilename.substring(fileOriginalFilename.lastIndexOf(".") + 1); - if (!"txt".equals(suffix)) { - return new Result(false, StatusCode.ERROR, "文件只能是 txt 格式"); - } - String line; - try (BufferedReader bf = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { - while ((line = bf.readLine()) != null) { - - String[] vulnDetailArr = line.split("\\|"); - String name = vulnDetailArr[0]; - String desc = vulnDetailArr[1]; - String risk = vulnDetailArr[2]; - String referer = vulnDetailArr[3]; - String impact = vulnDetailArr[4]; - - String top = vulnDetailArr[5]; - - String second = vulnDetailArr[6]; - - String vulnDemoCode = vulnDetailArr[7]; - String poc = vulnDetailArr[8]; - - String solution = vulnDetailArr[9]; - String codedemo = vulnDetailArr[10]; - String configdemo = vulnDetailArr[11]; - - String pulginName = ""; - if (vulnDetailArr.length > 12) { - pulginName = vulnDetailArr[12]; - } - String[] pluginArr = new String[0]; - if (pulginName.length() != 0) { - //多个插件 - if (pulginName.contains("、")) { - pluginArr = pulginName.split("、"); - } else { - //只有一个插件 - pluginArr = new String[]{pulginName}; - } - } - Categorytop categorytopByName = categorytopService.findByName(top); - //当前分类不在一级分类中,新增一个分类 - String topId = idWorker.nextId() + ""; - if (Objects.isNull(categorytopByName) && !top.isEmpty()) { - categorytopService.add(new Categorytop(topId, top)); - } else { - topId = categorytopByName.getId(); - } - - Categorysecond categorysecondByName = categorysecondService.findByName(second); - //当前分类不在二级分类中,新增一个分类 - String secondId; - if (Objects.isNull(categorysecondByName) && !second.isEmpty()) { - secondId = idWorker.nextId() + ""; - categorysecondService.add(new Categorysecond(secondId, topId, second)); - } else if (!Objects.isNull(categorysecondByName)) { - secondId = categorysecondByName.getId(); - } else { - secondId = idWorker.nextId() + ""; - } - - //当前漏洞不在数据库中,新增 - Vuln vuln = vulnService.findByName(name); - if (Objects.isNull(vuln)) { - String vulnId = idWorker.nextId() + ""; - vulnService.add(new Vuln(vulnId, secondId, name, desc, risk, referer, impact)); - - if (!vulnDemoCode.isEmpty()) { - democodeService.add(new Democode(idWorker.nextId() + "", vulnId, vulnDemoCode, poc)); - } - - solutionService.add(new Solution(idWorker.nextId() + "", vulnId, solution, codedemo, configdemo)); - //有插件,添加关联 - if (pluginArr.length != 0) { - for (String plugin : pluginArr) { - Pluginconfig pluginconfigByName = pluginconfigService.findByName(plugin); - if (!Objects.isNull(pluginconfigByName)) { - vulnpluginconfigService.add(new Vulnpluginconfig(idWorker.nextId() + "", vulnId, pluginconfigByName.getId())); - } - } - } - } - } - } catch (IOException ignored) { - } - return new Result(true, StatusCode.OK, "漏洞详情已上传处理,请稍后查看"); - - } - - /** - * 根据id数组查询 - * - * @param ids - * @return - */ - @PostMapping(value = "/ids") - public Result findByAssetIpIds(@RequestBody String[] ids) { - return new Result(true, StatusCode.OK, "查询成功", vulnService.findByIds(ids)); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/VulnkeywordController.java b/center/src/main/java/com/tiji/center/controller/VulnkeywordController.java deleted file mode 100755 index 750b093..0000000 --- a/center/src/main/java/com/tiji/center/controller/VulnkeywordController.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Pluginconfig; -import com.tiji.center.pojo.Vulnkeyword; -import com.tiji.center.service.PluginconfigService; -import com.tiji.center.service.VulnService; -import com.tiji.center.service.VulnkeywordService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * vulnkeyword控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/vulnkeyword") -public class VulnkeywordController { - - @Autowired - private VulnkeywordService vulnkeywordService; - @Autowired - private PluginconfigService pluginconfigService; - - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", vulnkeywordService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", vulnkeywordService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = vulnkeywordService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(Vulnkeyword -> { - String pluginconfigid = Vulnkeyword.getPluginconfigid(); - if (!StringUtils.isEmpty(pluginconfigid)) { - Pluginconfig pluginconfig = pluginconfigService.findById(pluginconfigid); - if (!Objects.isNull(pluginconfig)) { - Vulnkeyword.setPluginconfigid(pluginconfig.getName()); - } - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", vulnkeywordService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param vulnkeyword - */ - @PostMapping - public Result add(@RequestBody Vulnkeyword vulnkeyword) { - vulnkeywordService.add(vulnkeyword); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param vulnkeyword - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Vulnkeyword vulnkeyword, @PathVariable String id) { - vulnkeyword.setId(id); - vulnkeywordService.update(vulnkeyword); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - vulnkeywordService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - vulnkeywordService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据pluginId查询 - * - * @param pluginId pluginId - * @return - */ - @RequestMapping(value = "/plugin/{pluginId}", method = RequestMethod.GET) - public Result findAllByPluginId(@PathVariable String pluginId) { - return new Result(true, StatusCode.OK, "查询成功", vulnkeywordService.findAllByPluginId(pluginId)); - } - - /** - * 查询所有keyword并去重 - * - * @return List - */ - @RequestMapping(value = "/plugin", method = RequestMethod.GET) - public Result findAllDistinctVersion() { - return new Result(true, StatusCode.OK, "查询成功", vulnkeywordService.findAllDistinctVulnKeyword()); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/VulnpluginconfigController.java b/center/src/main/java/com/tiji/center/controller/VulnpluginconfigController.java deleted file mode 100755 index dad021c..0000000 --- a/center/src/main/java/com/tiji/center/controller/VulnpluginconfigController.java +++ /dev/null @@ -1,180 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.Checkresult; -import com.tiji.center.pojo.Pluginconfig; -import com.tiji.center.pojo.Vuln; -import com.tiji.center.pojo.Vulnpluginconfig; -import com.tiji.center.service.PluginconfigService; -import com.tiji.center.service.VulnService; -import com.tiji.center.service.VulnpluginconfigService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * vulnpluginconfig控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/vulnpluginconfig") -public class VulnpluginconfigController { - - @Autowired - private VulnpluginconfigService vulnpluginconfigService; - @Autowired - private VulnService vulnService; - @Autowired - private PluginconfigService pluginconfigService; - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", vulnpluginconfigService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", vulnpluginconfigService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - Page pageList = vulnpluginconfigService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(Vulnpluginconfig -> { - String vulnid = Vulnpluginconfig.getVulnid(); - if (!StringUtils.isEmpty(vulnid)) { - Vuln vuln = vulnService.findById(vulnid); - if (!Objects.isNull(vuln)) { - Vulnpluginconfig.setVulnid(vuln.getName()); - } - } - String pluginconfigid = Vulnpluginconfig.getPluginconfigid(); - if (!StringUtils.isEmpty(pluginconfigid)) { - Pluginconfig pluginconfig = pluginconfigService.findById(pluginconfigid); - if (!Objects.isNull(pluginconfig)) { - Vulnpluginconfig.setPluginconfigid(pluginconfig.getName()); - } - } - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", vulnpluginconfigService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param vulnpluginconfig - */ - @PostMapping - public Result add(@RequestBody Vulnpluginconfig vulnpluginconfig) { - vulnpluginconfigService.add(vulnpluginconfig); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param vulnpluginconfig - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Vulnpluginconfig vulnpluginconfig, @PathVariable String id) { - vulnpluginconfig.setId(id); - vulnpluginconfigService.update(vulnpluginconfig); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - vulnpluginconfigService.deleteById(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - vulnpluginconfigService.deleteAllByIds(ids); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据pluginId查询所有漏洞名称 - * - * @param pluginId pluginId - * @return - */ - @RequestMapping(value = "/plugin/{pluginId}", method = RequestMethod.GET) - public Result findAllByPluginId(@PathVariable String pluginId) { - return new Result(true, StatusCode.OK, "查询成功", vulnpluginconfigService.findAllByPluginconfigid(pluginId)); - } - - /** - * 根据pluginId 删除 - * - * @param pluginId pluginId - * @return - */ - @RequestMapping(value = "/plugin/{pluginId}", method = RequestMethod.DELETE) - public Result deleteAllByPluginId(@PathVariable String pluginId) { - vulnpluginconfigService.deleteAllByPluginconfigid(pluginId); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据pluginId vulnid删除 - * - * @param pluginId vulnId - * @return - */ - @RequestMapping(value = "/plugin/{pluginId}/{vulnId}", method = RequestMethod.DELETE) - public Result deleteByPluginIdVulnId(@PathVariable String pluginId,@PathVariable String vulnId) { - vulnpluginconfigService.deleteByPluginIdVulnId(pluginId,vulnId); - return new Result(true, StatusCode.OK, "删除成功"); - } -} diff --git a/center/src/main/java/com/tiji/center/controller/WebinfoController.java b/center/src/main/java/com/tiji/center/controller/WebinfoController.java deleted file mode 100755 index ab2988e..0000000 --- a/center/src/main/java/com/tiji/center/controller/WebinfoController.java +++ /dev/null @@ -1,231 +0,0 @@ -package com.tiji.center.controller; - -import com.tiji.center.pojo.*; -import com.tiji.center.service.*; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.*; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * webinfo控制器层 - * - * @author 贰拾壹 - */ -@RestController -@CrossOrigin -@RequestMapping("/webinfo") -public class WebinfoController { - - @Autowired - private WebinfoService webinfoService; - @Autowired - private UrlService urlService; - @Autowired - private AssetportService assetportService; - @Autowired - private AssetipService assetipService; - @Autowired - private WebrawdataService webrawdataService; - - /** - * 查询全部数据 - * - * @return - */ - @GetMapping - public Result findAll() { - return new Result(true, StatusCode.OK, "查询成功", webinfoService.findAll()); - } - - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping(value = "/{id}") - public Result findById(@PathVariable String id) { - return new Result(true, StatusCode.OK, "查询成功", webinfoService.findById(id)); - } - - - /** - * 分页+多条件查询 - * - * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 - * @return 分页结果 - */ - @PostMapping(value = "/search/{page}/{size}") - public Result findSearch(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) { - //根据ip查询webinfo - List assetPortIdList = new ArrayList<>(); - if (searchMap.containsKey("assetip")) { - //ip -> assetportid - String ipaddressv4 = (String) searchMap.get("assetip"); - Map ipSearchMap = new HashMap<>(); - ipSearchMap.put("ipaddressv4", ipaddressv4); - List assetipList = assetipService.findSearch(ipSearchMap); - assetipList.forEach(ip -> { - String ipId = ip.getId(); - List assetportList = assetportService.findAllByAssetipid(ipId); - assetportList.forEach(assetport -> { - String assetportId = assetport.getId(); - List webinfoList = webinfoService.findAllByAssetportid(assetportId); - webinfoList.forEach(webinfo -> { - String webinfoPortid = webinfo.getPortid(); - assetPortIdList.add(webinfoPortid); - }); - }); - - }); - searchMap.put("portid", assetPortIdList); - } - - //根据端口查询webinfo - if (searchMap.containsKey("assetport")) { - String port = (String) searchMap.get("assetport"); - Map portSearchMap = new HashMap<>(); - portSearchMap.put("port", port); - List assetportList = assetportService.findSearch(portSearchMap); - assetportList.forEach(assetport -> { - String assetportId = assetport.getId(); - List webinfoList = webinfoService.findAllByAssetportid(assetportId); - webinfoList.forEach(webinfo -> { - String webinfoPortid = webinfo.getPortid(); - assetPortIdList.add(webinfoPortid); - }); - }); - searchMap.put("portid", assetPortIdList); - } - - Page pageList = webinfoService.findSearch(searchMap, page, size); - pageList.stream().parallel().forEach(webinfo -> { - String id = webinfo.getId(); - String assetportid = webinfo.getPortid(); - Assetport assetport = assetportService.findById(assetportid); - webinfo.setPortid(assetport.getPort()); - String assetipid = assetport.getAssetipid(); - - Assetip assetip = assetipService.findById(assetipid); - webinfo.setAssetip(assetip.getIpaddressv4()); - - - List allByWebinfoid = urlService.findAllByWebinfoid(id); - StringBuilder stringBuilder = new StringBuilder(); - allByWebinfoid.forEach(url -> { - stringBuilder.append(url.getName()).append("==").append(url.getUrl()).append("<+>\n"); - }); - webinfo.setUrl(stringBuilder.toString()); - - StringBuilder headerBuilder = new StringBuilder(); - StringBuilder responseBuilder = new StringBuilder(); - List webrawdataList = webrawdataService.findAllByWebinfoid(id); - webrawdataList.forEach(webrawdata -> { - headerBuilder.append(webrawdata.getHeader()); - responseBuilder.append(webrawdata.getResponse()); - }); - - webinfo.setHeader(headerBuilder.toString()); - webinfo.setResponse(responseBuilder.toString()); - }); - return new Result(true, StatusCode.OK, "查询成功", new PageResult<>(pageList.getTotalElements(), pageList.getContent())); - } - - /** - * 根据条件查询 - * - * @param searchMap - * @return - */ - @PostMapping(value = "/search") - public Result findSearch(@RequestBody Map searchMap) { - return new Result(true, StatusCode.OK, "查询成功", webinfoService.findSearch(searchMap)); - } - - /** - * 增加 - * - * @param webinfo - */ - @PostMapping - public Result add(@RequestBody Webinfo webinfo) { - webinfoService.add(webinfo); - return new Result(true, StatusCode.OK, "增加成功"); - } - - /** - * 修改 - * - * @param webinfo - */ - @PutMapping(value = "/{id}") - public Result update(@RequestBody Webinfo webinfo, @PathVariable String id) { - webinfo.setId(id); - webinfoService.update(webinfo); - return new Result(true, StatusCode.OK, "修改成功"); - } - - /** - * 删除 - * - * @param id - */ - @DeleteMapping(value = "/{id}") - public Result delete(@PathVariable String id) { - webinfoService.deleteById(id); - //删除web信息同时,删除url - urlService.deleteAllByWebinfoid(id); - //删除原始响应和头信息 - webrawdataService.deleteAllByWebinfoid(id); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据ids批量删除 - * - * @param ids - */ - @PostMapping(value = "/deleteids") - public Result deleteAllByIds(@RequestBody List ids) { - webinfoService.deleteAllByIds(ids); - ids.forEach(id -> { - //删除web信息同时,删除url - urlService.deleteAllByWebinfoid(id); - //删除原始响应和头信息 - webrawdataService.deleteAllByWebinfoid(id); - }); - return new Result(true, StatusCode.OK, "删除成功"); - } - - /** - * 根据assetportid查询 - * - * @param assetportid assetportid - * @return - */ - @GetMapping(value = "/assetport/{assetportid}") - public Result findAllByAssetportid(@PathVariable String assetportid) { - return new Result(true, StatusCode.OK, "查询成功", webinfoService.findAllByAssetportid(assetportid)); - } - - /** - * 根据assetportids查询 - * - * @param assetportids assetportids - * @return - */ - @RequestMapping(value = "/assetportids/{assetportids}", method = RequestMethod.GET) - public Result findAllByAssetportIds(@PathVariable String[] assetportids) { - return new Result(true, StatusCode.OK, "查询成功", webinfoService.findAllByAssetportIds(assetportids)); - } -} diff --git a/center/src/main/java/com/tiji/center/dao/AgentDao.java b/center/src/main/java/com/tiji/center/dao/AgentDao.java deleted file mode 100755 index c9dae96..0000000 --- a/center/src/main/java/com/tiji/center/dao/AgentDao.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Agent; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * agent数据访问接口 - * - * @author 贰拾壹 - */ -public interface AgentDao extends JpaRepository, JpaSpecificationExecutor { - Agent findByNameAndIpaddress(String name, String ipaddress); - - @Modifying - @Query(value = "UPDATE `tb_agent` SET `online` = FALSE", nativeQuery = true) - void updateAgentSetOnlineFalse(); - - List findAllByOnline(Boolean online); - - @Modifying - @Query(value = "DELETE FROM `tb_agent` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/AssetipDao.java b/center/src/main/java/com/tiji/center/dao/AssetipDao.java deleted file mode 100755 index 33de719..0000000 --- a/center/src/main/java/com/tiji/center/dao/AssetipDao.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Assetip; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * assetip数据访问接口 - * - * @author 贰拾壹 - */ -public interface AssetipDao extends JpaRepository, JpaSpecificationExecutor { - - Assetip findByIpaddressv4AndPassivetimeIsNull(String ip); - - List findAllByPassivetimeIsNull(); - - @Query(value = "select distinct ipaddressv4 from Assetip where passivetime is null") - List findAllDistinctIpaddressv4ListAndPassivetimeIsNull(); - - //for test - //getContactByIp - @Query(value = "SELECT taip.ipaddressv4,tpi.projectname,tcn.name,tcn.email FROM tb_assetip taip,tb_contact tcn ,tb_projectinfo tpi WHERE tcn.projectinfoid=taip.projectinfoid and tpi.id=tcn.projectinfoid and ipaddressv4=?1", nativeQuery = true) - List findContactInfoByIpv4(String ipaddressv4); - - Assetip findByIdAndCheckwhitelistIsFalseAndPassivetimeIsNull(String id); - - - @Modifying - @Query(value = "UPDATE tb_assetip taip SET taip.checkwhitelist=?2 , taip.assetnotifywhitelist=?3 WHERE taip.projectinfoid=?1", nativeQuery = true) - void updateByProjectinfoidAndCheckwhitelistAndAssetNotifywhitelist(String projectinfoid, Boolean checkwhitelist, Boolean assetNotifywhitelist); - - @Modifying - @Query(value = "UPDATE tb_assetip SET projectinfoid = null WHERE projectinfoid=?1", nativeQuery = true) - void updateAssetipByProjectinfoidSetProjectinfoid2Null(String projectinfoid); - - @Modifying - @Query(value = "UPDATE tb_assetip SET projectinfoid = null", nativeQuery = true) - void updateAssetipSetProjectinfoidNull(); - - @Modifying - @Query(value = "DELETE FROM `tb_assetip` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - - @Query(value = "SELECT taip.id,COUNT(*) as portCount FROM tb_assetip taip,tb_assetport tp WHERE tp.assetipid = taip.id and taip.id in (?1) GROUP BY taip.id", nativeQuery = true) - List findPortCountByIds(List ids); - - @Query(value = "SELECT taip.id,COUNT(*) as portCount FROM tb_assetip taip,tb_assetport tp WHERE tp.assetipid = taip.id and taip.id in (?1) and ISNULL(tp.downtime) GROUP BY taip.id", nativeQuery = true) - List findPortCountOnlineByIds(List ids); - - @Query(value = "SELECT tp.assetipid,COUNT(*) as vulnCount FROM tb_assetport tp,tb_checkresult tcl WHERE tcl.assetportid IN(tp.id) and tp.assetipid IN (?1) GROUP BY tp.assetipid", nativeQuery = true) - List findVulnCountByIds(List ids); - - - @Query(value = "SELECT tp.assetipid,COUNT(*) as vulnCount FROM tb_assetport tp,tb_checkresult tcl WHERE tcl.assetportid IN(tp.id) and tp.assetipid IN (?1) and ISNULL(tcl.passivetime) GROUP BY tp.assetipid", nativeQuery = true) - List findVulnCountOnlineByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/AssetportDao.java b/center/src/main/java/com/tiji/center/dao/AssetportDao.java deleted file mode 100755 index 09ac9c3..0000000 --- a/center/src/main/java/com/tiji/center/dao/AssetportDao.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Assetport; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * assetport数据访问接口 - * - * @author 贰拾壹 - */ -public interface AssetportDao extends JpaRepository, JpaSpecificationExecutor { - - List findAllByServiceAndServiceIsNullAndCheckwhitelistIsFalseAndDowntimeIsNull(String service); - - List findByVersionLikeAndDowntimeIsNull(String assetVersion); - - List findByServiceLikeAndDowntimeIsNull(String assetService); - - List findAllByAssetipidAndDowntimeIsNull(String assetipid); - - Assetport findByAssetipidAndPortAndDowntimeIsNull(String assetipid, String assetport); - - Assetport findByIdAndAndAssetipidAndDowntimeIsNull(String id, String assetipid); - - List findByServiceLikeAndDowntimeIsNullAndCheckwhitelistIsFalseAndStateEquals(String version, String state); - - List findByVersionLikeAndDowntimeIsNullAndCheckwhitelistIsFalseAndStateEquals(String version, String state); - - List deleteAllByAssetipid(String assetipid); - - // @Query(value = "SELECT DISTINCT service FROM `tb_assetport` WHERE not regexp_like(service,'[,?]+') ORDER BY service",nativeQuery = true) - @Query(value = "SELECT DISTINCT service FROM `tb_assetport` ORDER BY service", nativeQuery = true) - List findAllDistinctService(); - - // @Query(value = "SELECT DISTINCT version FROM `tb_assetport` WHERE not regexp_like(version,'[,?]+') ORDER BY version",nativeQuery = true) - @Query(value = "SELECT DISTINCT version FROM `tb_assetport` ORDER BY version", nativeQuery = true) - List findAllDistinctVersion(); - - List findAllByAssetipid(String assetipid); - - List findAllByVersionAndServiceIsNullAndCheckwhitelistIsFalseAndDowntimeIsNull(String version); - - @Modifying - @Query(value = "DELETE FROM `tb_assetport` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - - @Query(value = "SELECT tp.id,COUNT(*) as vulnCount FROM tb_assetport tp,tb_checkresult tcl WHERE tcl.assetportid IN(tp.id) and tp.id in(?1) GROUP BY tp.id ", nativeQuery = true) - List findVulnCountByIds(List ids); - - @Query(value = "SELECT tp.id,COUNT(*) as vulnCount FROM tb_assetport tp,tb_checkresult tcl WHERE tcl.assetportid IN(tp.id) and ISNULL(tcl.passivetime) and tp.id in(?1) GROUP BY tp.id ", nativeQuery = true) - List findVulnCountOnlineByIds(List ids); - - @Modifying - @Query(value = "UPDATE tb_assetip_appsys_hostdomain SET assetportid =null WHERE assetportid=?1", nativeQuery = true) - void updateMiddByAssetportidSetAssetportid2Null(String id); -} diff --git a/center/src/main/java/com/tiji/center/dao/CategorysecondDao.java b/center/src/main/java/com/tiji/center/dao/CategorysecondDao.java deleted file mode 100755 index 4cc51b4..0000000 --- a/center/src/main/java/com/tiji/center/dao/CategorysecondDao.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Categorysecond; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * categorysecond数据访问接口 - * - * @author 贰拾壹 - */ -public interface CategorysecondDao extends JpaRepository, JpaSpecificationExecutor { - Categorysecond findByName(String name); - - Categorysecond findByCategorytopid(String categorytopid); - - @Modifying - @Query(value = "DELETE FROM `tb_categorysecond` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); -} diff --git a/center/src/main/java/com/tiji/center/dao/CategorytopDao.java b/center/src/main/java/com/tiji/center/dao/CategorytopDao.java deleted file mode 100755 index 30a4608..0000000 --- a/center/src/main/java/com/tiji/center/dao/CategorytopDao.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Categorytop; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * categorytop数据访问接口 - * - * @author 贰拾壹 - */ -public interface CategorytopDao extends JpaRepository, JpaSpecificationExecutor { - Categorytop findByName(String name); - - @Modifying - @Query(value = "DELETE FROM `tb_categorytop` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); -} diff --git a/center/src/main/java/com/tiji/center/dao/CheckresultDao.java b/center/src/main/java/com/tiji/center/dao/CheckresultDao.java deleted file mode 100755 index 794177c..0000000 --- a/center/src/main/java/com/tiji/center/dao/CheckresultDao.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Checkresult; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * checkresult数据访问接口 - * - * @author 贰拾壹 - */ -public interface CheckresultDao extends JpaRepository, JpaSpecificationExecutor { - Checkresult findByAssetportidAndNameAndPassivetimeIsNull(String assetPortId, String pluginName); - - List findAllByName(String name); - - List deleteAllByAssetportid(String assetportId); - - List findAllByAssetportid(String assetportid); - - @Modifying - @Query(value = "DELETE FROM `tb_checkresult` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/CheckresultVulnDao.java b/center/src/main/java/com/tiji/center/dao/CheckresultVulnDao.java deleted file mode 100755 index 733a8dd..0000000 --- a/center/src/main/java/com/tiji/center/dao/CheckresultVulnDao.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.CheckresultVuln; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * checkresultVuln数据访问接口 - * - * @author 贰拾壹 - */ -public interface CheckresultVulnDao extends JpaRepository, JpaSpecificationExecutor { - List findAllByCheckresultid(String checkresultid); - - void deleteAllByCheckresultid(String checkresultid); - - List findAllByVulnid(String id); - - @Query(value = "SELECT checkresultid FROM `tb_checkresult_vuln` WHERE vulnid=?1", nativeQuery = true) - List findAllCheckResultIdByVulnid(String id); - -} diff --git a/center/src/main/java/com/tiji/center/dao/ContactDao.java b/center/src/main/java/com/tiji/center/dao/ContactDao.java deleted file mode 100755 index ea04e1f..0000000 --- a/center/src/main/java/com/tiji/center/dao/ContactDao.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Contact; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * contact数据访问接口 - * - * @author 贰拾壹 - */ -public interface ContactDao extends JpaRepository, JpaSpecificationExecutor { - - Contact findByNameAndEmail(String name, String email); - - @Modifying - @Query(value = "DELETE FROM `tb_contact` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/ContactProjectinfoDao.java b/center/src/main/java/com/tiji/center/dao/ContactProjectinfoDao.java deleted file mode 100755 index 73ab49b..0000000 --- a/center/src/main/java/com/tiji/center/dao/ContactProjectinfoDao.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.ContactProjectinfo; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * contactProjectinfo数据访问接口 - * - * @author 贰拾壹 - */ -public interface ContactProjectinfoDao extends JpaRepository, JpaSpecificationExecutor { - - void deleteAllByContactid(String contactid); - - void deleteAllByProjectinfoid(String projectinfoid); - - List findAllByProjectinfoid(String projectinfoid); - - ContactProjectinfo findByContactidAndProjectinfoid(String contactid, String projectinfoid); - - @Modifying - @Query(value = "DELETE FROM `tb_contact_projectinfo` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - - void deleteByContactidAndProjectinfoid(String contactid, String projectinfoid); - -} diff --git a/center/src/main/java/com/tiji/center/dao/CronjobDao.java b/center/src/main/java/com/tiji/center/dao/CronjobDao.java deleted file mode 100755 index 4cdc6a7..0000000 --- a/center/src/main/java/com/tiji/center/dao/CronjobDao.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Cronjob; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; - -/** - * cronjob数据访问接口 - * - * @author 贰拾壹 - */ -public interface CronjobDao extends JpaRepository, JpaSpecificationExecutor { - Cronjob findByName(String name); -} diff --git a/center/src/main/java/com/tiji/center/dao/DemocodeDao.java b/center/src/main/java/com/tiji/center/dao/DemocodeDao.java deleted file mode 100755 index f203693..0000000 --- a/center/src/main/java/com/tiji/center/dao/DemocodeDao.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Democode; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * democode数据访问接口 - * - * @author 贰拾壹 - */ -public interface DemocodeDao extends JpaRepository, JpaSpecificationExecutor { - - List findAllByVulnid(String vulnId); - - void deleteAllByVulnid(String vulnId); - - @Modifying - @Query(value = "DELETE FROM `tb_democode` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/DepartmentDao.java b/center/src/main/java/com/tiji/center/dao/DepartmentDao.java deleted file mode 100755 index e0d7e39..0000000 --- a/center/src/main/java/com/tiji/center/dao/DepartmentDao.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Department; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * department数据访问接口 - * - * @author 贰拾壹 - */ -public interface DepartmentDao extends JpaRepository, JpaSpecificationExecutor { - - Department findByDepartmentname(String departmentname); - - @Modifying - @Query(value = "DELETE FROM `tb_department` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); -} diff --git a/center/src/main/java/com/tiji/center/dao/DictionarypasswordDao.java b/center/src/main/java/com/tiji/center/dao/DictionarypasswordDao.java deleted file mode 100755 index e27deab..0000000 --- a/center/src/main/java/com/tiji/center/dao/DictionarypasswordDao.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Dictionarypassword; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * dictionarypassword数据访问接口 - * - * @author 贰拾壹 - */ -public interface DictionarypasswordDao extends JpaRepository, JpaSpecificationExecutor { - - Dictionarypassword findByPassword(String password); - - @Query(value = "SELECT `password` FROM `tb_dictionarypassword`", nativeQuery = true) - List findAllPassword(); - - - @Modifying - @Query(value = "DELETE FROM `tb_dictionarypassword` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); -} diff --git a/center/src/main/java/com/tiji/center/dao/DictionaryusernameDao.java b/center/src/main/java/com/tiji/center/dao/DictionaryusernameDao.java deleted file mode 100755 index fd54ce9..0000000 --- a/center/src/main/java/com/tiji/center/dao/DictionaryusernameDao.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Dictionaryusername; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * dictionaryusername数据访问接口 - * - * @author 贰拾壹 - */ -public interface DictionaryusernameDao extends JpaRepository, JpaSpecificationExecutor { - - Dictionaryusername findByUsername(String username); - - @Query(value = "SELECT username FROM `tb_dictionaryusername`", nativeQuery = true) - List findAllUsername(); - - @Modifying - @Query(value = "DELETE FROM `tb_dictionaryusername` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/DomainwhitelistDao.java b/center/src/main/java/com/tiji/center/dao/DomainwhitelistDao.java deleted file mode 100755 index 1d4b9e5..0000000 --- a/center/src/main/java/com/tiji/center/dao/DomainwhitelistDao.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Domainwhitelist; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * domainwhitelist数据访问接口 - * - * @author 贰拾壹 - */ -public interface DomainwhitelistDao extends JpaRepository, JpaSpecificationExecutor { - - @Query(value = "SELECT DISTINCT domain FROM `tb_domainwhitelist`", nativeQuery = true) - List findAllDistinct(); - - Domainwhitelist findByDomain(String domain); - - @Modifying - @Query(value = "DELETE FROM `tb_domainwhitelist` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); -} diff --git a/center/src/main/java/com/tiji/center/dao/HostDao.java b/center/src/main/java/com/tiji/center/dao/HostDao.java deleted file mode 100755 index 800f96d..0000000 --- a/center/src/main/java/com/tiji/center/dao/HostDao.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Host; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * host数据访问接口 - * - * @author 贰拾壹 - */ -public interface HostDao extends JpaRepository, JpaSpecificationExecutor { - - List findByassetipid(String assetipid); - - void deleteAllByAssetipid(String assetipid); - - Host findByHostname(String hostname); - - Host findByMacaddress(String macaddress); - - List findAllByAssetipid(String assetipid); - - Host findByAssetipidAndHostname(String assetipid, String hostname); - - @Modifying - @Query(value = "DELETE FROM `tb_host` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/ImvulnnotifyDao.java b/center/src/main/java/com/tiji/center/dao/ImvulnnotifyDao.java deleted file mode 100755 index 725b32f..0000000 --- a/center/src/main/java/com/tiji/center/dao/ImvulnnotifyDao.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Imvulnnotify; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; - -/** - * imvulnnotify数据访问接口 - * - * @author 贰拾壹 - */ -public interface ImvulnnotifyDao extends JpaRepository, JpaSpecificationExecutor { - -} diff --git a/center/src/main/java/com/tiji/center/dao/IpportwhitelistDao.java b/center/src/main/java/com/tiji/center/dao/IpportwhitelistDao.java deleted file mode 100755 index 93989d9..0000000 --- a/center/src/main/java/com/tiji/center/dao/IpportwhitelistDao.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Ipportwhitelist; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * ipportwhitelist数据访问接口 - * - * @author 贰拾壹 - */ -public interface IpportwhitelistDao extends JpaRepository, JpaSpecificationExecutor { - Ipportwhitelist findByIpwhitelistidAndPort(String ipwhitelistid, String port); - - @Query(value = "SELECT tiwl.port FROM `tb_ipportwhitelist` tiwl WHERE tiwl.ipwhitelistid=?1", nativeQuery = true) - List findAllPortByIpwhitelistid(String ipwhitelistid); - - void deleteAllByipwhitelistid(String ipwhitelistid); - - @Modifying - @Query(value = "DELETE FROM `tb_ipportwhitelist` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/IpwhitelistDao.java b/center/src/main/java/com/tiji/center/dao/IpwhitelistDao.java deleted file mode 100755 index 58d5126..0000000 --- a/center/src/main/java/com/tiji/center/dao/IpwhitelistDao.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Ipwhitelist; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * ipwhitelist数据访问接口 - * - * @author 贰拾壹 - */ -public interface IpwhitelistDao extends JpaRepository, JpaSpecificationExecutor { - - @Query(value = "SELECT DISTINCT tipwl.ip FROM `tb_ipwhitelist` tipwl WHERE tipwl.id NOT IN (SELECT tpwl.ipwhitelistid FROM tb_portwhitelist tpwl )", nativeQuery = true) - List findAllIpNoPorts(); - - @Query(value = "SELECT * FROM `tb_ipwhitelist` tipwl WHERE tipwl.id IN (SELECT tpwl.ipwhitelistid FROM tb_portwhitelist tpwl )", nativeQuery = true) - List findAllIpHasPorts(); - - Ipwhitelist findByIp(String ip); - - @Modifying - @Query(value = "DELETE FROM `tb_ipwhitelist` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); -} diff --git a/center/src/main/java/com/tiji/center/dao/NmapconfigDao.java b/center/src/main/java/com/tiji/center/dao/NmapconfigDao.java deleted file mode 100755 index 8f0d420..0000000 --- a/center/src/main/java/com/tiji/center/dao/NmapconfigDao.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Nmapconfig; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * nmapconfig数据访问接口 - * - * @author 贰拾壹 - */ -public interface NmapconfigDao extends JpaRepository, JpaSpecificationExecutor { - Nmapconfig findByTaskid(String taskid); - - void deleteAllByTaskid(String taskid); - - @Modifying - @Query(value = "DELETE FROM `tb_nmapconfig` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/NotifylogDao.java b/center/src/main/java/com/tiji/center/dao/NotifylogDao.java deleted file mode 100755 index b05414f..0000000 --- a/center/src/main/java/com/tiji/center/dao/NotifylogDao.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Notifylog; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * notifylog数据访问接口 - * - * @author 贰拾壹 - */ -public interface NotifylogDao extends JpaRepository, JpaSpecificationExecutor { - - @Modifying - @Query(value = "DELETE FROM `tb_notifylog` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); -} diff --git a/center/src/main/java/com/tiji/center/dao/PluginassetserviceDao.java b/center/src/main/java/com/tiji/center/dao/PluginassetserviceDao.java deleted file mode 100755 index 2a0bb30..0000000 --- a/center/src/main/java/com/tiji/center/dao/PluginassetserviceDao.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Pluginassetservice; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * assetservice数据访问接口 - * - * @author 贰拾壹 - */ -public interface PluginassetserviceDao extends JpaRepository, JpaSpecificationExecutor { - Pluginassetservice findByPluginconfigidAndAssetservice(String pluginConfigId, String serviceName); - - void deleteAllByPluginconfigid(String pluginconfigId); - - List findAllByPluginconfigid(String pluginconfigid); - - @Query(value = "SELECT " + - "tpas.* FROM tb_pluginassetservice tpas " + - "WHERE tpas.pluginconfigid IN (SELECT pluginconfigid FROM `tb_taskpluginconfig` WHERE taskid = ?1)", nativeQuery = true) - List findPluginassetserviceByTaskid(String taskId); - - @Modifying - @Query(value = "DELETE FROM `tb_pluginassetservice` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/PluginassetversionDao.java b/center/src/main/java/com/tiji/center/dao/PluginassetversionDao.java deleted file mode 100755 index 95511c3..0000000 --- a/center/src/main/java/com/tiji/center/dao/PluginassetversionDao.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Pluginassetversion; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * assetversion数据访问接口 - * - * @author 贰拾壹 - */ -public interface PluginassetversionDao extends JpaRepository, JpaSpecificationExecutor { - Pluginassetversion findByPluginconfigidAndAssetversion(String pluginConfigId, String versionName); - - void deleteAllByPluginconfigid(String pluginconfigId); - - List findAllByPluginconfigid(String pluginconfigid); - - - @Query(value = - "SELECT " + - "tpav.* FROM tb_pluginassetversion tpav " + - "WHERE tpav.pluginconfigid IN (SELECT pluginconfigid FROM `tb_taskpluginconfig` WHERE taskid = ?1)", nativeQuery = true) - List findPluginassetversionByTaskid(String taskId); - - @Modifying - @Query(value = "DELETE FROM `tb_pluginassetversion` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/PluginconfigDao.java b/center/src/main/java/com/tiji/center/dao/PluginconfigDao.java deleted file mode 100755 index ec2ad5d..0000000 --- a/center/src/main/java/com/tiji/center/dao/PluginconfigDao.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Pluginconfig; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * pluginconfig数据访问接口 - * - * @author 贰拾壹 - */ -public interface PluginconfigDao extends JpaRepository, JpaSpecificationExecutor { - - Pluginconfig findByName(String pluginConfigName); - - Pluginconfig findByNameAndType(String pluginConfigName, String pluginConfigType); - - Pluginconfig findByIdAndType(String id, String type); - - @Modifying - @Query(value = "DELETE FROM `tb_pluginconfig` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/ProjectDao.java b/center/src/main/java/com/tiji/center/dao/ProjectDao.java deleted file mode 100755 index a08e585..0000000 --- a/center/src/main/java/com/tiji/center/dao/ProjectDao.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Project; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * project数据访问接口 - * - * @author 贰拾壹 - */ -public interface ProjectDao extends JpaRepository, JpaSpecificationExecutor { - - Project findByName(String name); - - @Modifying - @Query(value = "DELETE FROM `tb_project` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - - @Modifying - @Query(value = "UPDATE tb_task SET projectid = NULL WHERE projectid=?1", nativeQuery = true) - void updateTaskByProjectIdSetProjectid2Null(String projectid); - -} diff --git a/center/src/main/java/com/tiji/center/dao/ProjectinfoDao.java b/center/src/main/java/com/tiji/center/dao/ProjectinfoDao.java deleted file mode 100755 index b4c2a1d..0000000 --- a/center/src/main/java/com/tiji/center/dao/ProjectinfoDao.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Assetip; -import com.tiji.center.pojo.Projectinfo; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * projectinfo数据访问接口 - * - * @author 贰拾壹 - */ -public interface ProjectinfoDao extends JpaRepository, JpaSpecificationExecutor { - Projectinfo findByProjectname(String ProjectName); - - @Query(value = - "SELECT id,projectname FROM tb_projectinfo;", nativeQuery = true) - List findIdAndProjectname(); - - Projectinfo findByDepartmentidAndProjectname(String departmentid, String projectname); - - - @Modifying - @Query(value = "DELETE FROM `tb_projectinfo` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - - @Modifying - @Query(value = "UPDATE tb_projectinfo SET departmentid =NULL WHERE departmentid=?1", nativeQuery = true) - void updateProjectInfoByDepartidSetDepartid2Null(String departid); -} diff --git a/center/src/main/java/com/tiji/center/dao/ProjectportwhitelistDao.java b/center/src/main/java/com/tiji/center/dao/ProjectportwhitelistDao.java deleted file mode 100755 index e75cf83..0000000 --- a/center/src/main/java/com/tiji/center/dao/ProjectportwhitelistDao.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Projectportwhitelist; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * projectportwhitelist数据访问接口 - * - * @author 贰拾壹 - */ -public interface ProjectportwhitelistDao extends JpaRepository, JpaSpecificationExecutor { - - Projectportwhitelist findByProjectinfoidAndPort(String projectInfoId, String port); - - void deleteAllByProjectinfoid(String projectinfoid); - - @Query(value = "SELECT tppwl.`port` FROM tb_projectportwhitelist tppwl WHERE tppwl.projectinfoid=?1", nativeQuery = true) - List findAllPortByProjectinfoid(String projectinfoid); - - @Modifying - @Query(value = "DELETE FROM `tb_projectportwhitelist` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); -} diff --git a/center/src/main/java/com/tiji/center/dao/ProjectvulnnotifyDao.java b/center/src/main/java/com/tiji/center/dao/ProjectvulnnotifyDao.java deleted file mode 100755 index 6804fd7..0000000 --- a/center/src/main/java/com/tiji/center/dao/ProjectvulnnotifyDao.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Projectvulnnotify; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; - -/** - * projectvulnnotify数据访问接口 - * - * @author 贰拾壹 - */ -public interface ProjectvulnnotifyDao extends JpaRepository, JpaSpecificationExecutor { - -} diff --git a/center/src/main/java/com/tiji/center/dao/RiskportDao.java b/center/src/main/java/com/tiji/center/dao/RiskportDao.java deleted file mode 100755 index 09d1956..0000000 --- a/center/src/main/java/com/tiji/center/dao/RiskportDao.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Riskport; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * riskport数据访问接口 - * - * @author 贰拾壹 - */ -public interface RiskportDao extends JpaRepository, JpaSpecificationExecutor { - - Riskport findByPort(String port); - - @Modifying - @Query(value = "DELETE FROM `tb_riskport` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/RiskserviceDao.java b/center/src/main/java/com/tiji/center/dao/RiskserviceDao.java deleted file mode 100755 index ec033fd..0000000 --- a/center/src/main/java/com/tiji/center/dao/RiskserviceDao.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Riskservice; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * riskservice数据访问接口 - * - * @author 贰拾壹 - */ -public interface RiskserviceDao extends JpaRepository, JpaSpecificationExecutor { - - Riskservice findByService(String service); - - @Modifying - @Query(value = "DELETE FROM `tb_riskservice` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); -} diff --git a/center/src/main/java/com/tiji/center/dao/RiskversionDao.java b/center/src/main/java/com/tiji/center/dao/RiskversionDao.java deleted file mode 100755 index bbf451c..0000000 --- a/center/src/main/java/com/tiji/center/dao/RiskversionDao.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Riskversion; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * riskversion数据访问接口 - * - * @author 贰拾壹 - */ -public interface RiskversionDao extends JpaRepository, JpaSpecificationExecutor { - - Riskversion findByVersion(String version); - - @Modifying - @Query(value = "DELETE FROM `tb_riskversion` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/SendmailconfigDao.java b/center/src/main/java/com/tiji/center/dao/SendmailconfigDao.java deleted file mode 100755 index 0861604..0000000 --- a/center/src/main/java/com/tiji/center/dao/SendmailconfigDao.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Sendmailconfig; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; - -/** - * sendmailconfig数据访问接口 - * - * @author 贰拾壹 - */ -public interface SendmailconfigDao extends JpaRepository, JpaSpecificationExecutor { - -} diff --git a/center/src/main/java/com/tiji/center/dao/SolutionDao.java b/center/src/main/java/com/tiji/center/dao/SolutionDao.java deleted file mode 100755 index e37d839..0000000 --- a/center/src/main/java/com/tiji/center/dao/SolutionDao.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Solution; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * solution数据访问接口 - * - * @author 贰拾壹 - */ -public interface SolutionDao extends JpaRepository, JpaSpecificationExecutor { - - List findAllByVulnid(String vulnId); - - void deleteAllByVulnid(String vulnId); - - @Modifying - @Query(value = "DELETE FROM `tb_solution` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/StatisticsDao.java b/center/src/main/java/com/tiji/center/dao/StatisticsDao.java deleted file mode 100755 index f8b8ec9..0000000 --- a/center/src/main/java/com/tiji/center/dao/StatisticsDao.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Statistics; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * statistics数据访问接口 - * - * @author 贰拾壹 - */ -public interface StatisticsDao extends JpaRepository, JpaSpecificationExecutor { - - @Query(value = "SELECT taip.ipaddressv4,COUNT(*) as portCount FROM tb_assetip taip,tb_assetport tp WHERE tp.assetipid = taip.id GROUP BY taip.ipaddressv4 ORDER BY portCount desc LIMIT 0,100", nativeQuery = true) - List findIpPortCount(); - - @Query(value = "SELECT taip.ipaddressv4,COUNT(*) as portCount FROM tb_assetip taip,tb_assetport tp WHERE tp.assetipid = taip.id and tp.downtime IS null and taip.passivetime is NULL GROUP BY taip.ipaddressv4 ORDER BY portCount desc LIMIT 0,100", nativeQuery = true) - List findIpPortCountOnline(); - - @Query(value = "SELECT tp.service,COUNT(*) serviceCount FROM tb_assetport tp GROUP BY tp.service ORDER BY serviceCount desc", nativeQuery = true) - List findServiceCount(); - - @Query(value = "SELECT tp.service,COUNT(*) serviceCount FROM tb_assetport tp WHERE tp.downtime IS null GROUP BY tp.service ORDER BY serviceCount desc", nativeQuery = true) - List findServiceCountOnline(); - - @Query(value = "SELECT tp.version,COUNT(*) versionCount FROM tb_assetport tp GROUP BY tp.version ORDER BY versionCount desc", nativeQuery = true) - List findVersionCount(); - - @Query(value = "SELECT tp.version,COUNT(*) versionCount FROM tb_assetport tp WHERE tp.downtime IS null GROUP BY tp.version ORDER BY versionCount desc", nativeQuery = true) - List findVersionCountOnline(); - - @Query(value = "SELECT twb.`server`,COUNT(*) serverCount FROM tb_webinfo twb GROUP BY twb.`server` ORDER BY serverCount desc", nativeQuery = true) - List findWebinfoServerCount(); - - @Query(value = "SELECT tp.`port`,COUNT(*) portCount FROM tb_assetport tp WHERE tp.`port` IN (SELECT DISTINCT trp.`port` FROM tb_riskport trp) GROUP BY tp.`port` ORDER BY portCount desc", nativeQuery = true) - List findRiskPortCount(); - - @Query(value = "SELECT tp.`port`,COUNT(*) portCount FROM tb_assetport tp WHERE tp.`port` IN (SELECT DISTINCT trp.`port` FROM tb_riskport trp) and tp.downtime IS null GROUP BY tp.`port` ORDER BY portCount desc", nativeQuery = true) - List findRiskPortCountOnline(); - - @Query(value = "SELECT tp.service,COUNT(*) serviceCount FROM tb_assetport tp WHERE tp.service IN (SELECT DISTINCT trs.service FROM tb_riskservice trs) GROUP BY tp.service ORDER BY serviceCount desc", nativeQuery = true) - List findRiskServiceCount(); - - @Query(value = "SELECT tp.service,COUNT(*) serviceCount FROM tb_assetport tp WHERE tp.service IN (SELECT DISTINCT trs.service FROM tb_riskservice trs) and tp.downtime IS null GROUP BY tp.service ORDER BY serviceCount desc", nativeQuery = true) - List findRiskServiceCountOnline(); - - @Query(value = "SELECT tp.version,COUNT(*) versionCount FROM tb_assetport tp WHERE tp.version IN (SELECT DISTINCT trv.version FROM tb_riskversion trv) GROUP BY tp.version ORDER BY versionCount desc", nativeQuery = true) - List findRiskVersionCount(); - - @Query(value = "SELECT tp.version,COUNT(*) versionCount FROM tb_assetport tp WHERE tp.version IN (SELECT DISTINCT trv.version FROM tb_riskversion trv) and tp.downtime IS null GROUP BY tp.version ORDER BY versionCount desc", nativeQuery = true) - List findRiskVersionCountOnline(); - - @Query(value = "SELECT tcr.risk,COUNT(*) riskCount FROM tb_checkresult tcr GROUP BY tcr.risk ORDER BY riskCount desc", nativeQuery = true) - List findRiskCount(); - - @Query(value = "SELECT tcr.risk,COUNT(*) riskCount FROM tb_checkresult tcr WHERE tcr.passivetime IS NULL GROUP BY tcr.risk ORDER BY riskCount desc", nativeQuery = true) - List findRiskCountOnline(); - - @Query(value = "SELECT (SELECT tv.name FROM tb_vuln tv WHERE tv.id = tcrv.vulnid) as \"vulnname\",COUNT(vulnid) AS vulnCount FROM `tb_checkresult_vuln` tcrv GROUP BY tcrv.vulnid ORDER BY vulnCount desc", nativeQuery = true) - List findRiskVulnCount(); - - @Query(value = "SELECT (SELECT tv.name FROM tb_vuln tv WHERE tv.id = tcrv.vulnid) as \"vulnname\",COUNT(vulnid) AS vulnCount FROM `tb_checkresult_vuln` tcrv WHERE tcrv.checkresultid IN (SELECT tcr.id FROM tb_checkresult tcr WHERE tcr.passivetime IS NULL) GROUP BY tcrv.vulnid ORDER BY vulnCount desc", nativeQuery = true) - List findRiskVulnCountOnline(); - - @Query(value = "SELECT COUNT(*) FROM tb_assetip", nativeQuery = true) - String findIpCount(); - - @Query(value = "SELECT COUNT(*) FROM tb_assetip WHERE passivetime is NULL", nativeQuery = true) - String findIpCountOnline(); - - @Query(value = "SELECT COUNT(*) FROM tb_assetport", nativeQuery = true) - String findPortCount(); - - @Query(value = "SELECT COUNT(*) FROM tb_assetport WHERE downtime is NULL", nativeQuery = true) - String findPortCountOnline(); - - @Query(value = "SELECT tcr.risk,COUNT(*) riskCount FROM tb_checkresult tcr GROUP BY tcr.risk ORDER BY FIELD(tcr.risk,\"致命\",\"严重\",\"高危\",\"中危\",\"低危\",\"信息\")", nativeQuery = true) - List findCheckresultCount(); - - @Query(value = "SELECT tcr.risk,COUNT(*) riskCount FROM tb_checkresult tcr WHERE tcr.passivetime IS NULL GROUP BY tcr.risk ORDER BY FIELD(tcr.risk,\"致命\",\"严重\",\"高危\",\"中危\",\"低危\",\"信息\")", nativeQuery = true) - List findCheckresultCountOnline(); - - @Query(value = "SELECT COUNT(*) portCount FROM tb_assetport tp WHERE tp.`port` IN (SELECT DISTINCT trp.`port` FROM tb_riskport trp)", nativeQuery = true) - String findRiskportCount(); - - @Query(value = "SELECT COUNT(*) portCount FROM tb_assetport tp WHERE tp.`port` IN (SELECT DISTINCT trp.`port` FROM tb_riskport trp) and tp.downtime IS null", nativeQuery = true) - String findRiskportCountOnline(); - - @Query(value = "SELECT COUNT(*) serviceCount FROM tb_assetport tp WHERE tp.service IN (SELECT DISTINCT trs.service FROM tb_riskservice trs)", nativeQuery = true) - String findRiskserviceCount(); - - @Query(value = "SELECT COUNT(*) serviceCount FROM tb_assetport tp WHERE tp.service IN (SELECT DISTINCT trs.service FROM tb_riskservice trs) and tp.downtime IS null", nativeQuery = true) - String findRiskserviceCountOnline(); - - @Query(value = "SELECT COUNT(*) versionCount FROM tb_assetport tp WHERE tp.version IN (SELECT DISTINCT trv.version FROM tb_riskversion trv)", nativeQuery = true) - String findRiskversionCount(); - - @Query(value = "SELECT COUNT(*) versionCount FROM tb_assetport tp WHERE tp.version IN (SELECT DISTINCT trv.version FROM tb_riskversion trv) and tp.downtime IS null", nativeQuery = true) - String findRiskversionCountOnline(); -} diff --git a/center/src/main/java/com/tiji/center/dao/TaskDao.java b/center/src/main/java/com/tiji/center/dao/TaskDao.java deleted file mode 100755 index 1ee7954..0000000 --- a/center/src/main/java/com/tiji/center/dao/TaskDao.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Task; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * task数据访问接口 - * - * @author 贰拾壹 - */ -public interface TaskDao extends JpaRepository, JpaSpecificationExecutor { - List findAllByEndtimeIsNullAndStarttimeIsNotNull(); - - List findAllByWorktypeAndEndtimeIsNotNullAndStarttimeIsNotNull(String worktype); - - List findAllByCrontaskIsTrueAndTaskparentidIsNull(); - - List findAllByTaskparentid(String taskparentid); - - Task findByName(String name); - - @Modifying - @Query(value = "DELETE FROM `tb_task` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - - void deleteAllByTaskparentid(String taskParentId); - -} diff --git a/center/src/main/java/com/tiji/center/dao/TaskipDao.java b/center/src/main/java/com/tiji/center/dao/TaskipDao.java deleted file mode 100755 index d5c0fb2..0000000 --- a/center/src/main/java/com/tiji/center/dao/TaskipDao.java +++ /dev/null @@ -1,171 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Taskip; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * taskip数据访问接口 - * 所有多表的sql语句都写在这里 - * - * @author 贰拾壹 - */ -public interface TaskipDao extends JpaRepository, JpaSpecificationExecutor { - List findByTaskid(String taskId); - - Taskip findByTaskidAndIpaddressv4(String taskid, String ipaddressv4); - - List findAllByTaskidAndCheckwhitelistIsFalse(String taskid); - - @Query(value = - "SELECT " + - "tip.ipaddressv4,tp.port " + - "FROM tb_taskip tip, tb_taskport tp " + - "WHERE tp.taskipid=tip.id and tip.taskid=?1", nativeQuery = true) - List findTaskIpAndPort(String taskId); - - - @Query(value = "SELECT " + - "ta.id,ta.ipaddressv4,tp.`port`,tp.service " + - "FROM tb_taskip ta,tb_taskport tp " + - "WHERE tp.taskipid = ta.id and tp.state=\"open\" and tp.checkwhitelist IS FALSE and tp.service like ?2 and taskid=?1 ", nativeQuery = true) - List findAllByServiceLikeAndCheckwhitelistIsFalse(String taskId, String serviceLike); - - @Query(value = - "SELECT " + - "ta.id,ta.ipaddressv4,tp.`port`,tp.service " + - "FROM tb_taskip ta,tb_taskport tp " + - "WHERE tp.taskipid = ta.id and tp.state=\"open\" and tp.checkwhitelist IS FALSE and tp.service is NULL and taskid=?1", nativeQuery = true) - List findByTaskidAndServiceIsNullAndCheckwhitelistIsFalse(String taskId); - - - @Query(value = - "SELECT " + - "ta.ipaddressv4,tp.`port`,tp.service,tp.version " + - "FROM tb_taskip ta,tb_taskport tp " + - "WHERE tp.taskipid = ta.id and tp.state=\"open\" and ta.checkwhitelist IS FALSE and tp.checkwhitelist IS FALSE and ta.taskid=?1 and tp.service like ?2", nativeQuery = true) - List findByTaskidAndServiceLikeAndCheckwhitelistIsFalse(String taskId, String serviceLike); - - @Query(value = - "SELECT " + - "ta.ipaddressv4,tp.`port`,tp.service,tp.version " + - "FROM tb_taskip ta,tb_taskport tp " + - "WHERE tp.taskipid = ta.id and tp.state=\"open\" and ta.checkwhitelist IS FALSE and tp.checkwhitelist IS FALSE and ta.taskid=?1 and tp.version like ?2", nativeQuery = true) - List findByTaskidAndVersionLikeAndCheckwhitelistIsFalse(String taskId, String versionLike); - - - @Query(value = - "SELECT " + - "tcp.`name` \"tcpname\",tcs.`name` \"tcsname\", " + - "tv.`name` \"tvname\",tv.risk \"tvrisk\", " + - "taip.ipaddressv4,DATE_FORMAT(taip.activetime,'%Y-%m-%d %H:%i:%s') \"taipactivetime\",DATE_FORMAT(taip.passivetime,'%Y-%m-%d %H:%i:%s') \"taippassivetime\", " + - "tap.`port`,tap.service,tap.version,DATE_FORMAT(tap.uptime,'%Y-%m-%d %H:%i:%s'),DATE_FORMAT(tap.downtime,'%Y-%m-%d %H:%i:%s'), " + - "tcr.`name` \"tcrname\",tcr.result,DATE_FORMAT(tcr.activetime,'%Y-%m-%d %H:%i:%s') \"tcractivetime\", " + - "tv.description,tv.refer,tv.impactscope, " + - "ts.solution,ts.codedemo,ts.configdemo, " + - "taip.projectinfoid " + - "FROM tb_assetip taip, tb_assetport tap,tb_checkresult tcr,tb_checkresult_vuln tcvm,tb_vuln tv,tb_solution ts,tb_categorytop tcp, tb_categorysecond tcs " + - "WHERE tap.assetipid=taip.id and tcr.assetportid=tap.id and tv.id=tcvm.vulnid and tcvm.checkresultid=tcr.id and ts.vulnid=tv.id " + - "and tcvm.checkresultid=tcr.id and tv.categorysecondid=tcs.id and tcs.categorytopid=tcp.id " + - "and tcr.passivetime IS NULL " + - "ORDER BY FIELD(tv.risk,\"致命\",\"严重\",\"高危\",\"中危\",\"低危\",\"信息\")", nativeQuery = true) - List findAllVulns(); - - @Query(value = - "SELECT " + - "taip.ipaddressv4,tp.`port`,tp.protocol,tp.state,tp.service,tp.version,tp.uptime,tp.changedtime, " + - "IF(tp.`port` IN (SELECT `port` FROM tb_riskport),1,NULL) \"riskport\", " + - "IF(tp.service IN (SELECT service FROM tb_riskservice),1,NULL) \"riskservice\", " + - "IF(tp.version IN (SELECT version FROM tb_riskversion),1,NULL) \"riskversion\", " + - "taip.projectinfoid " + - "FROM tb_assetip taip,tb_assetport tp " + - "WHERE tp.assetipid = taip.id " + - "and taip.assetnotifywhitelist IS FALSE and tp.assetnotifywhitelist IS FALSE " + - "and taip.passivetime IS NULL and tp.downtime IS NULL " + - "ORDER BY taip.ipaddressv4,tp.service ", nativeQuery = true) - List findAllAssets(); - - @Query(value = - "SELECT COUNT(*) " + - "FROM tb_assetip taip,tb_assetport tp " + - "WHERE tp.assetipid = taip.id " + - "and taip.assetnotifywhitelist IS FALSE and tp.assetnotifywhitelist IS FALSE " + - "and taip.passivetime IS NULL and tp.downtime IS NULL ", nativeQuery = true) - long findAllAssetsCount(); - - @Query(value = - "SELECT " + - "taip.ipaddressv4,tp.`port`,tp.protocol,tp.state,tp.service,tp.version," + - "DATE_FORMAT(tp.uptime,'%Y-%m-%d %H:%i:%s'),DATE_FORMAT(tp.changedtime,'%Y-%m-%d %H:%i:%s'), " + - "IF(tp.`port` IN (SELECT `port` FROM tb_riskport),1,NULL) \"riskport\", " + - "IF(tp.service IN (SELECT service FROM tb_riskservice),1,NULL) \"riskservice\", " + - "IF(tp.version IN (SELECT version FROM tb_riskversion),1,NULL) \"riskversion\", " + - "taip.projectinfoid " + - "FROM tb_assetip taip,tb_assetport tp " + - "WHERE tp.assetipid = taip.id " + - "and taip.assetnotifywhitelist IS FALSE and tp.assetnotifywhitelist IS FALSE " + - "and taip.passivetime IS NULL and tp.downtime IS NULL " + - "LIMIT ?1,?2 ", nativeQuery = true) - List> findAllAssetsByPage(long offset, long rows); - - @Query(value = - "SELECT \n" + - "taip.ipaddressv4,tp.`port`,tp.protocol,tp.state,tp.service,tp.version, \n" + - "DATE_FORMAT(tp.uptime,'%Y-%m-%d %H:%i:%s') \"uptime\",DATE_FORMAT(tp.changedtime,'%Y-%m-%d %H:%i:%s') \"changedtime\", \n" + - "IF(tp.`port` IN (SELECT `port` FROM tb_riskport),1,NULL) \"riskport\", \n" + - "IF(tp.service IN (SELECT service FROM tb_riskservice),1,NULL) \"riskservice\", \n" + - "IF(tp.version IN (SELECT version FROM tb_riskversion),1,NULL) \"riskversion\", \n" + - "IF(taip.projectinfoid IN (SELECT projectinfoid FROM tb_projectinfo),(SELECT tpi.projectname FROM tb_projectinfo tpi WHERE tpi.id = taip.projectinfoid),NULL) \"projectinfoName\",\n" + - "(select group_concat(tc.`name` SEPARATOR \";\") from tb_contact tc,tb_contact_projectinfo tcp,tb_projectinfo tpi where tcp.contactid = tc.id and taip.projectinfoid = tpi.id and tpi.id = tcp.projectinfoid) \"contactname\",\n" + - "(select group_concat(tc.email SEPARATOR \";\") from tb_contact tc,tb_contact_projectinfo tcp,tb_projectinfo tpi where tcp.contactid = tc.id and taip.projectinfoid = tpi.id and tpi.id = tcp.projectinfoid) \"contactemail\",\n" + - "(select group_concat(tc.phone SEPARATOR \";\") from tb_contact tc,tb_contact_projectinfo tcp,tb_projectinfo tpi where tcp.contactid = tc.id and taip.projectinfoid = tpi.id and tpi.id = tcp.projectinfoid) \"contactphone\"\n" + - "FROM tb_assetip taip,tb_assetport tp \n" + - "WHERE tp.assetipid = taip.id \n" + - "and taip.assetnotifywhitelist IS FALSE and tp.assetnotifywhitelist IS FALSE \n" + - "and taip.passivetime IS NULL and tp.downtime IS NULL \n" + - "LIMIT ?1,?2", nativeQuery = true) - List> findAllAssetsByPageNew(long offset, long rows); - - @Query(value = "SELECT tpp.ipaddressv4 FROM tb_assetip tpp WHERE tpp.id in(select taip.id from tb_assetip taip where taip.id not in (select tp.assetipid from tb_assetport tp)) ", nativeQuery = true) - List findAllAssetipNoPort(); - - @Query(value = - "SELECT COUNT(*) FROM `tb_checkresult` WHERE passivetime is NULL", nativeQuery = true) - long findAllVulnsCount(); - - @Query(value = - "SELECT DISTINCTROW\n" + - "tcp.`name` \"一级分类\",tcs.`name` \"二级分类\",\n" + - "tv.`name` \"漏洞名称\",\n" + - "tv.risk \"风险\",\n" + - "taip.ipaddressv4,\n" + - "DATE_FORMAT(taip.activetime,'%Y-%m-%d %H:%i:%s') \"ip上线时间\",DATE_FORMAT(taip.passivetime,'%Y-%m-%d %H:%i:%s') \"ip下线时间\",\n" + - "tap.`port`,tap.service,tap.version,DATE_FORMAT(tap.uptime,'%Y-%m-%d %H:%i:%s') \"端口发现时间\",DATE_FORMAT(tap.downtime,'%Y-%m-%d %H:%i:%s') \"端口关闭时间\",\n" + - "(select group_concat(tcr.`name` SEPARATOR \";\") from tb_checkresult tcr ,tb_checkresult_vuln tcvm,tb_vuln tv where tcr.assetportid=tap.id and tv.id=tcvm.vulnid and tcvm.checkresultid=tcr.id and tcr.passivetime IS NULL) \"检测插件\",\n" + - "(select group_concat(tcr.`result` SEPARATOR \";\") from tb_checkresult tcr ,tb_checkresult_vuln tcvm,tb_vuln tv where tcr.assetportid=tap.id and tv.id=tcvm.vulnid and tcvm.checkresultid=tcr.id and tcr.passivetime IS NULL) \"检测结果\",\n" + - "(select group_concat(DATE_FORMAT(tcr.`activetime`,'%Y-%m-%d %H:%i:%s') SEPARATOR \";\") from tb_checkresult tcr ,tb_checkresult_vuln tcvm,tb_vuln tv where tcr.assetportid=tap.id and tv.id=tcvm.vulnid and tcvm.checkresultid=tcr.id and tcr.passivetime IS NULL) \"漏洞发现时间\",\n" + - "tv.description,tv.refer,tv.impactscope,\n" + - "(select group_concat(ts.solution SEPARATOR \";\") from tb_solution ts where ts.vulnid=tv.id) \"solution\",\n" + - "(select group_concat(ts.codedemo SEPARATOR \";\") from tb_solution ts where ts.vulnid=tv.id) \"codedemo\",\n" + - "(select group_concat(ts.configdemo SEPARATOR \";\") from tb_solution ts where ts.vulnid=tv.id) \"configdemo\",\n" + - "IF(taip.projectinfoid IN (SELECT projectinfoid FROM tb_projectinfo),(SELECT tpi.projectname FROM tb_projectinfo tpi WHERE tpi.id = taip.projectinfoid),NULL) \"projectinfoName\" ,\n" + - "(select group_concat(tc.`name` SEPARATOR \";\") from tb_contact tc,tb_contact_projectinfo tcp,tb_projectinfo tpi where tcp.contactid = tc.id and taip.projectinfoid = tpi.id and tpi.id = tcp.projectinfoid) \"contactname\",\n" + - "(select group_concat(tc.email SEPARATOR \";\") from tb_contact tc,tb_contact_projectinfo tcp,tb_projectinfo tpi where tcp.contactid = tc.id and taip.projectinfoid = tpi.id and tpi.id = tcp.projectinfoid) \"contactemail\",\n" + - "(select group_concat(tc.phone SEPARATOR \";\") from tb_contact tc,tb_contact_projectinfo tcp,tb_projectinfo tpi where tcp.contactid = tc.id and taip.projectinfoid = tpi.id and tpi.id = tcp.projectinfoid) \"contactphone\" \n" + - "FROM tb_assetip taip, tb_assetport tap,tb_checkresult tcr,tb_checkresult_vuln tcvm,tb_vuln tv,tb_categorytop tcp, tb_categorysecond tcs \n" + - "WHERE tap.assetipid=taip.id and tcr.assetportid=tap.id and tv.id=tcvm.vulnid and tcvm.checkresultid=tcr.id\n" + - "and tcvm.checkresultid=tcr.id and tv.categorysecondid=tcs.id and tcs.categorytopid=tcp.id\n" + - "and tcr.passivetime IS NULL\n" + - "ORDER BY FIELD(tv.risk,\"致命\",\"严重\",\"高危\",\"中危\",\"低危\",\"信息\"),taip.ipaddressv4 \n" + - "LIMIT ?1,?2", nativeQuery = true) - List> findAllVulnsByPage(long offset, long rows); - - @Modifying - @Query(value = "DELETE FROM `tb_taskip` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/TaskpluginconfigDao.java b/center/src/main/java/com/tiji/center/dao/TaskpluginconfigDao.java deleted file mode 100755 index 5452e2e..0000000 --- a/center/src/main/java/com/tiji/center/dao/TaskpluginconfigDao.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Taskpluginconfig; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * taskpluginconfig数据访问接口 - * - * @author 贰拾壹 - */ -public interface TaskpluginconfigDao extends JpaRepository, JpaSpecificationExecutor { - Taskpluginconfig findByTaskidAndPluginconfigid(String taskid, String pluginconfigid); - - List findAllByTaskid(String taskid); - - - @Query(value = "SELECT pluginconfigid FROM `tb_taskpluginconfig` WHERE taskid=?1", nativeQuery = true) - List findPluginconfigidByTaskid(String taskid); - - void deleteAllByTaskid(String taskid); - - void deleteAllByTaskidAndPluginconfigid(String taskid, String pluginconfigid); - - void deleteAllByPluginconfigid(String pluginconfigid); - - @Modifying - @Query(value = "DELETE FROM `tb_taskpluginconfig` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/TaskportDao.java b/center/src/main/java/com/tiji/center/dao/TaskportDao.java deleted file mode 100755 index 4f66255..0000000 --- a/center/src/main/java/com/tiji/center/dao/TaskportDao.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Taskport; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * taskport数据访问接口 - * - * @author 贰拾壹 - */ -public interface TaskportDao extends JpaRepository, JpaSpecificationExecutor { - - List findByTaskipidAndState(String taskIpId, String state); - - Taskport findByTaskipidAndPort(String taskipid, String taskport); - - List findByTaskipid(String taskIpId); - - List findByTaskipidAndServiceAndState(String taskipid, String service, String state); - - List findByTaskipidAndVersionAndState(String taskipid, String version, String state); - - void deleteAllByTaskipid(String taskipid); - - @Modifying - @Query(value = "DELETE FROM `tb_taskport` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/TitlewhitelistDao.java b/center/src/main/java/com/tiji/center/dao/TitlewhitelistDao.java deleted file mode 100755 index 44280d4..0000000 --- a/center/src/main/java/com/tiji/center/dao/TitlewhitelistDao.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Titlewhitelist; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * titlewhitelist数据访问接口 - * - * @author 贰拾壹 - */ -public interface TitlewhitelistDao extends JpaRepository, JpaSpecificationExecutor { - - Titlewhitelist findByTitle(String title); - - @Modifying - @Query(value = "DELETE FROM `tb_titlewhitelist` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - - void deleteByTitle(String title); - -} diff --git a/center/src/main/java/com/tiji/center/dao/UrlDao.java b/center/src/main/java/com/tiji/center/dao/UrlDao.java deleted file mode 100755 index 6a1703d..0000000 --- a/center/src/main/java/com/tiji/center/dao/UrlDao.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Url; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * url数据访问接口 - * - * @author 贰拾壹 - */ -public interface UrlDao extends JpaRepository, JpaSpecificationExecutor { - - - @Query(value = "SELECT `name`,url FROM `tb_url` WHERE webinfoid = ?1", nativeQuery = true) - List findByWebinfoid(String webinfoid); - - void deleteAllByWebinfoid(String webinfoid); - - List findAllByWebinfoid(String webinfoid); - - @Modifying - @Query(value = "DELETE FROM `tb_url` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); -} diff --git a/center/src/main/java/com/tiji/center/dao/UserDao.java b/center/src/main/java/com/tiji/center/dao/UserDao.java deleted file mode 100755 index b5dc9d1..0000000 --- a/center/src/main/java/com/tiji/center/dao/UserDao.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.User; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * user数据访问接口 - * - * @author 贰拾壹 - */ -public interface UserDao extends JpaRepository, JpaSpecificationExecutor { - - User findByUsername(String username); - - @Modifying - @Query(value = "DELETE FROM `tb_user` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); -} diff --git a/center/src/main/java/com/tiji/center/dao/UseragentDao.java b/center/src/main/java/com/tiji/center/dao/UseragentDao.java deleted file mode 100755 index 2162340..0000000 --- a/center/src/main/java/com/tiji/center/dao/UseragentDao.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Useragent; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * useragent数据访问接口 - * - * @author 贰拾壹 - */ -public interface UseragentDao extends JpaRepository, JpaSpecificationExecutor { - - @Query(value = "select distinct useragent from Useragent") - List findAllDistinctUserAgentList(); - - Useragent findByUseragent(String ua); - - @Modifying - @Query(value = "DELETE FROM `tb_useragent` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - -} diff --git a/center/src/main/java/com/tiji/center/dao/VulnDao.java b/center/src/main/java/com/tiji/center/dao/VulnDao.java deleted file mode 100755 index 59b3a5e..0000000 --- a/center/src/main/java/com/tiji/center/dao/VulnDao.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Vuln; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * vuln数据访问接口 - * - * @author 贰拾壹 - */ -public interface VulnDao extends JpaRepository, JpaSpecificationExecutor { - - Vuln findByName(String name); - - @Modifying - @Query(value = "DELETE FROM `tb_vuln` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); -} diff --git a/center/src/main/java/com/tiji/center/dao/VulnkeywordDao.java b/center/src/main/java/com/tiji/center/dao/VulnkeywordDao.java deleted file mode 100755 index dc76ff6..0000000 --- a/center/src/main/java/com/tiji/center/dao/VulnkeywordDao.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Vulnkeyword; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * vulnkeyword数据访问接口 - * - * @author 贰拾壹 - */ -public interface VulnkeywordDao extends JpaRepository, JpaSpecificationExecutor { - Vulnkeyword findByPluginconfigidAndKeyword(String pluginConfigId, String vulnKeywordName); - - void deleteAllByPluginconfigid(String pluginconfigId); - - List findAllByPluginconfigid(String pluginconfigid); - - @Query(value = "SELECT DISTINCT keyword FROM tb_vulnkeyword ORDER BY keyword", nativeQuery = true) - List findAllDistinctVulnKeyword(); - - @Modifying - @Query(value = "DELETE FROM `tb_vulnkeyword` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); -} diff --git a/center/src/main/java/com/tiji/center/dao/VulnpluginconfigDao.java b/center/src/main/java/com/tiji/center/dao/VulnpluginconfigDao.java deleted file mode 100755 index d0d13ce..0000000 --- a/center/src/main/java/com/tiji/center/dao/VulnpluginconfigDao.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Vulnpluginconfig; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * vulnpluginconfig数据访问接口 - * - * @author 贰拾壹 - */ -public interface VulnpluginconfigDao extends JpaRepository, JpaSpecificationExecutor { - List findAllByPluginconfigid(String pluginConfigId); - - void deleteAllByPluginconfigid(String pluginconfigId); - - Vulnpluginconfig findByVulnidAndPluginconfigid(String vulnid, String pluginconfigid); - - @Modifying - @Query(value = "DELETE FROM `tb_vulnpluginconfig` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); - - void deleteByPluginconfigidAndVulnid(String pluginId, String vulnId); -} diff --git a/center/src/main/java/com/tiji/center/dao/WebinfoDao.java b/center/src/main/java/com/tiji/center/dao/WebinfoDao.java deleted file mode 100755 index 34279ff..0000000 --- a/center/src/main/java/com/tiji/center/dao/WebinfoDao.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.tiji.center.dao; - -import com.tiji.center.pojo.Webinfo; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -/** - * webinfo数据访问接口 - * - * @author 贰拾壹 - */ -public interface WebinfoDao extends JpaRepository, JpaSpecificationExecutor { - - List findByPortid(String portId); - - List deleteAllByPortid(String assetportId); - - List findAllByPortid(String assetportid); - - @Modifying - @Query(value = "DELETE FROM `tb_webinfo` WHERE id IN(?1)", nativeQuery = true) - void deleteAllByIds(List ids); -} diff --git a/center/src/main/java/com/tiji/center/datasource/MasterDataSourceConfiguration.java b/center/src/main/java/com/tiji/center/datasource/MasterDataSourceConfiguration.java deleted file mode 100755 index dbbc62c..0000000 --- a/center/src/main/java/com/tiji/center/datasource/MasterDataSourceConfiguration.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.tiji.center.datasource; - -import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; -import devutility.internal.util.PropertiesUtils; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.transaction.PlatformTransactionManager; - -import javax.sql.DataSource; -import java.util.Properties; - -/** - * @author 贰拾壹 - * @create 2019-12-09 15:18 - */ - - -@Configuration -@EnableJpaRepositories(basePackages = "com.tiji.center.dao", entityManagerFactoryRef = "masterEntityManagerFactory", transactionManagerRef = "masterTransactionManager") -public class MasterDataSourceConfiguration { - @Primary - @Bean - @ConfigurationProperties("spring.datasource.druid.master") - public DataSource masterDataSource() { - return DruidDataSourceBuilder.create().build(); - } - - @Bean - @ConfigurationProperties("spring.datasource.druid.master.jpa") - public Properties masterJpaProperties() { - return new Properties(); - } - - @Primary - @Bean - public LocalContainerEntityManagerFactoryBean masterEntityManagerFactory() { - LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); - localContainerEntityManagerFactoryBean.setDataSource(masterDataSource()); - localContainerEntityManagerFactoryBean.setPackagesToScan("com.tiji.center.pojo"); - localContainerEntityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); - localContainerEntityManagerFactoryBean.setJpaPropertyMap(PropertiesUtils.toMap(masterJpaProperties())); - return localContainerEntityManagerFactoryBean; - } - - //master需要指定事务管理器 @Transactional(value = "masterTransactionManager") - @Bean - public PlatformTransactionManager masterTransactionManager() { - JpaTransactionManager transactionManager = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory(masterEntityManagerFactory().getObject()); - return transactionManager; - } -} \ No newline at end of file diff --git a/center/src/main/java/com/tiji/center/dispatcher/TargetIpSlicer.java b/center/src/main/java/com/tiji/center/dispatcher/TargetIpSlicer.java deleted file mode 100755 index 44abc55..0000000 --- a/center/src/main/java/com/tiji/center/dispatcher/TargetIpSlicer.java +++ /dev/null @@ -1,203 +0,0 @@ -package com.tiji.center.dispatcher; - -import com.tiji.center.pojo.Assetip; -import com.tiji.center.pojo.Assetport; -import com.tiji.center.pojo.Task; -import com.tiji.center.service.AssetipService; -import com.tiji.center.service.AssetportService; -import com.tiji.center.service.TaskService; -import com.tiji.center.service.TaskipService; -import com.tiji.center.util.TijiHelper; -import org.apache.commons.lang3.StringUtils; -import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate; -import org.springframework.data.redis.core.RedisTemplate; -import util.NameSuffix; - -import java.util.*; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - -/** - * 目标ip分组进redis - */ - -public class TargetIpSlicer { - - public static String slice(String targetId, Map taskInfo, AssetipService assetipService, TaskipService taskipService, TaskService taskService, AssetportService assetportService, RedisTemplate redisTemplate, RabbitMessagingTemplate rabbitMessagingTemplate, double agentCount) throws InterruptedException { - String nameSuffix = "_" + NameSuffix.gen(); - //Redis - String rawIPSet = "rawIPSet" + nameSuffix;//原始目标IP - String excludeIPSet = "excludeIPSet" + nameSuffix;//排除的IP - String targetIPSet = "targetIPSet" + nameSuffix; //目标IP - String sliceIPList = "sliceIPList" + nameSuffix;//分组IP - Task task = taskService.findById(targetId); - //ip无端口,全端口扫描任务 - String targetip = task.getTargetip(); - if ("ipNoPort".equals(targetip)) { - List allAssetipNoPort = taskipService.findAllAssetipNoPort(); - System.out.println("allAssetipNoPort " + allAssetipNoPort); - if (allAssetipNoPort.isEmpty()) - return null; - TijiHelper.target2Redis(allAssetipNoPort.toString().replaceAll("[\\[\\]\\s]", ""), redisTemplate, rawIPSet); - } else if ("unknownPortSerVer".equals(targetip) || "ipAllPort".equals(targetip)) { - //ip有端口,端口服务未知 - //未知服务/版本的端口 => mass2Nmap模式的二次扫描 => 丢给mq - //获取所有asset service的ip和端口:为空、null、tcpwrapped、unknown、包含? - List assetportList = new ArrayList<>(); - - Map searchMap = new HashMap<>(); - searchMap.put("state", "open"); - searchMap.put("checkwhitelist", false); - searchMap.put("downtime", null); - - if ("unknownPortSerVer".equals(targetip)) { - searchMap.put("service", "tcpwrapped"); - assetportList.addAll(assetportService.findSearch(searchMap)); - searchMap.put("service", "unknown"); - assetportList.addAll(assetportService.findSearch(searchMap)); - searchMap.put("service", "?"); - assetportList.addAll(assetportService.findSearch(searchMap)); - searchMap.put("service", "null"); - assetportList.addAll(assetportService.findSearch(searchMap)); - //为空的service - assetportList.addAll(assetportService.findAllByServiceAndServiceIsNullAndCheckwhitelistIsFalseAndDowntimeIsNull(null)); - - //获取所有asset verison:为空、null - //version - searchMap.put("version", "null"); - //为空的version - assetportList.addAll(assetportService.findAllByVersionAndServiceIsNullAndCheckwhitelistIsFalseAndDowntimeIsNull(null)); - } - if ("ipAllPort".equals(targetip)) { - assetportList.addAll(assetportService.findSearch(searchMap)); - } - - if (assetportList.isEmpty()) - return null; - List resultAssetportList = new ArrayList<>(); - assetportList.parallelStream().forEach(assetport -> { - String assetipid = assetport.getAssetipid(); - String port = assetport.getPort(); - Assetip assetip = assetipService.findByIdAndCheckwhitelistIsFalseAndPassivetimeIsNull(assetipid); - if (!Objects.isNull(assetip)) { - String ipaddressv4 = assetip.getIpaddressv4(); - resultAssetportList.add(ipaddressv4 + "," + port); - } - }); - //得到未知服务的ip -port - sliceIPList = "sliceIPList_" + targetId; - Map> ipAndPortRTempMap = new LinkedHashMap<>(); - BlockingQueue ipAndPortQueue = new LinkedBlockingQueue<>(); - Map> ipAndPortResultMap = TijiHelper.ipAndPortList2Map(resultAssetportList); - TijiHelper.iPWithSamePorts2OneGroup(ipAndPortRTempMap, ipAndPortResultMap, ipAndPortQueue); - - for (Map.Entry> entry : ipAndPortRTempMap.entrySet()) { - String ips = StringUtils.join(entry.getValue(), ","); - if (ips != null) { - ipAndPortQueue.put(ips.replaceAll(",", " ") + " -p" + entry.getKey()); - } - } - for (String ipAndPort : ipAndPortQueue) { - redisTemplate.opsForList().leftPush(sliceIPList, ipAndPort); - } - - //设置当前分组大小 - redisTemplate.opsForValue().set("sliceIPListSize_" + targetId, String.valueOf(redisTemplate.opsForList().size(sliceIPList))); - Map taskConfig = new HashMap<>(); - taskConfig.put("status", "start"); - taskConfig.put("taskId", targetId); - taskConfig.put("workType", task.getWorktype()); - taskConfig.put("sliceIPList", sliceIPList); - taskConfig.put("threadNumber", task.getThreadnumber()); - taskConfig.put("singleIpScanTime", task.getSingleipscantime()); - taskConfig.put("additionOption", task.getAdditionoption()); - - task.setStarttime(new Date()); - taskService.update(task); - - //分组数存入redis - double sliceIPListSize = redisTemplate.opsForList().size(sliceIPList); - //向上取整,确保所有的agent取出的数量大于等于总数 - double maxSliceSize = Math.ceil(sliceIPListSize / agentCount); - - taskConfig.put("maxSliceSize", String.valueOf(maxSliceSize)); - - rabbitMessagingTemplate.convertAndSend("tijifanout", "", taskConfig); - return sliceIPList; - } else if (task.getAdditionoption().contains("-sn")) { - for (String targetIp : targetip.split(",")) { - redisTemplate.opsForList().leftPush(sliceIPList, targetIp); - } - return sliceIPList; - } else { - TijiHelper.target2Redis(task.getTargetip(), redisTemplate, rawIPSet); - } - - //去除excludeIP中redis目标key - String srcKey; - //保存数据库中的ipv4 - List dbIpv4List = new LinkedList<>(); - boolean dBIPAsExcludeIP = false; - if (task.getDbipisexcludeip().equals(true)) { - //获取所有ip - dbIpv4List = assetipService.findAllDistinctIpaddressv4ListAndPassivetimeIsNull(); - dBIPAsExcludeIP = true; - } - long temp = 0; - //已知资产IP作为白名单 - if (dBIPAsExcludeIP && dbIpv4List.size() != 0) { - //存入excludeIPSet中 - for (String ip : dbIpv4List) { - redisTemplate.opsForSet().add(excludeIPSet, ip); - } - //for test - temp = redisTemplate.opsForSet().size(excludeIPSet); - } - String excludeip = task.getExcludeip(); - //task.getExcludeip()不为空,Excludeip有IP白名单 - if (!Objects.isNull(excludeip)) { - //ExcludeIP存入redis Set, excludeIPSet - TijiHelper.target2Redis(excludeip, redisTemplate, excludeIPSet); - //去除rawIPSet中的excludeIPSet,并保存到targetIPSet - redisTemplate.opsForSet().differenceAndStore(rawIPSet, excludeIPSet, targetIPSet); - srcKey = targetIPSet; - } else {//没有需要排除的IP,rawIP就是targetIP - srcKey = rawIPSet; - } - - //除sliceIPList外,其他设置10秒过期 - //sliceIPList会被pop掉 - redisTemplate.expire(excludeIPSet, 15, TimeUnit.SECONDS); - redisTemplate.expire(rawIPSet, 15, TimeUnit.SECONDS); - redisTemplate.expire(targetIPSet, 15, TimeUnit.SECONDS); - - //将targetIPSet分组,存入sliceIPList - - - if (redisTemplate.opsForSet().size(srcKey) != 0) { - TijiHelper.targetIPSet2SliceIPSet(task.getWorktype(), task.getTargetport(), sliceIPList, srcKey, redisTemplate, task.getIpslicesize(), task.getPortslicesize()); - //for test - System.out.println("总IP:" + redisTemplate.opsForSet().size(rawIPSet)); - if (dBIPAsExcludeIP) { - System.out.println("exclude.ip排除IP:" + "DB中assetIp"); - } else { - System.out.println("exclude.ip排除IP:" + redisTemplate.opsForSet().members(excludeIPSet)); - } - - System.out.println("DB中排除IP数:" + temp); - System.out.println("剩余目标IP:" + redisTemplate.opsForSet().size(srcKey)); - - taskInfo.put("总IP数", redisTemplate.opsForSet().size(rawIPSet).toString()); - if (dBIPAsExcludeIP) { - taskInfo.put("排除IP", "DB中assetIp"); - } else { - taskInfo.put("排除IP", redisTemplate.opsForSet().members(excludeIPSet).toString()); - } - taskInfo.put("DB中排除IP数", String.valueOf(temp)); - taskInfo.put("剩余目标IP数", redisTemplate.opsForSet().size(srcKey).toString()); - return sliceIPList; - } - return null; - } -} diff --git a/center/src/main/java/com/tiji/center/exception/AssessDeniedException.java b/center/src/main/java/com/tiji/center/exception/AssessDeniedException.java deleted file mode 100755 index d4aed6c..0000000 --- a/center/src/main/java/com/tiji/center/exception/AssessDeniedException.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.tiji.center.exception; - -/** - * @author 贰拾壹 - * @create 2020-01-08 11:40 - */ -public class AssessDeniedException extends RuntimeException { - public AssessDeniedException() { - super(); - } - - public AssessDeniedException(String message) { - super(message); - } -} diff --git a/center/src/main/java/com/tiji/center/exception/ExpiredTokenException.java b/center/src/main/java/com/tiji/center/exception/ExpiredTokenException.java deleted file mode 100755 index 6abcaae..0000000 --- a/center/src/main/java/com/tiji/center/exception/ExpiredTokenException.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.tiji.center.exception; - -/** - * @author 贰拾壹 - * @create 2020-01-08 12:01 - */ -public class ExpiredTokenException extends RuntimeException { - public ExpiredTokenException() { - super(); - } - - public ExpiredTokenException(String message) { - super(message); - } -} diff --git a/center/src/main/java/com/tiji/center/exception/IllegalTokenException.java b/center/src/main/java/com/tiji/center/exception/IllegalTokenException.java deleted file mode 100755 index 29e5b09..0000000 --- a/center/src/main/java/com/tiji/center/exception/IllegalTokenException.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.tiji.center.exception; - -/** - * @author 贰拾壹 - * @create 2020-01-08 12:01 - */ -public class IllegalTokenException extends RuntimeException { - public IllegalTokenException() { - super(); - } - - public IllegalTokenException(String message) { - super(message); - } -} diff --git a/center/src/main/java/com/tiji/center/exception/LoginException.java b/center/src/main/java/com/tiji/center/exception/LoginException.java deleted file mode 100755 index c9ea65e..0000000 --- a/center/src/main/java/com/tiji/center/exception/LoginException.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.tiji.center.exception; - -/** - * @author 贰拾壹 - * @create 2020-01-08 12:59 - */ -public class LoginException extends RuntimeException { - public LoginException() { - super(); - } - - public LoginException(String message) { - super(message); - } -} - diff --git a/center/src/main/java/com/tiji/center/filter/JwtFilter.java b/center/src/main/java/com/tiji/center/filter/JwtFilter.java deleted file mode 100755 index 03519ca..0000000 --- a/center/src/main/java/com/tiji/center/filter/JwtFilter.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.tiji.center.filter; - - -import com.tiji.center.exception.ExpiredTokenException; -import com.tiji.center.exception.IllegalTokenException; -import com.tiji.center.exception.LoginException; -import com.tiji.center.util.JwtUtil; -import io.jsonwebtoken.Claims; -import io.jsonwebtoken.ExpiredJwtException; -import io.jsonwebtoken.JwtException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.web.servlet.HandlerInterceptor; -import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.Objects; - -/** - * JWT权限拦截器 - * - * @author 贰拾壹 - * @create 2019-09-05 15:27 - */ -@Component -public class JwtFilter implements HandlerInterceptor { - - @Autowired - private JwtUtil jwtUtil; - - /** - * 进行Controller的方法之前执行 - * - * @param request - * @param response - * @param handler - * @return - */ - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { - String method = request.getMethod(); - if (method.equals("OPTIONS")) { - return true; - } - String authInRequestHeader = request.getHeader("Authorization"); - if (!Objects.isNull(authInRequestHeader) && authInRequestHeader.startsWith("Bearer") && authInRequestHeader.length() > 6) { - String token = authInRequestHeader.substring(7); - - //解析Token字符串是否合法(是否过期) - Claims body; - try { - body = jwtUtil.parseJWT(token); - } catch (ExpiredJwtException e) { - throw new ExpiredTokenException("token已过期"); - } catch (JwtException e) { - throw new IllegalTokenException("非法token"); - } - - //Token合法 - Object roles = body.get("roles"); - Object userId = body.get("jti"); - Object userName = body.get("sub"); - //System.out.println("auth: " + authInRequestHeader); - //System.out.println("body: " + body); - //System.out.println("roles: " + roles); - //System.out.println("userId: " + userId); - //System.out.println("userName: " + userName); - //标记roles - if ("admin".equals(roles)) { - request.setAttribute("admin_claims", body); - } - if ("user".equals(roles)) { - request.setAttribute("user_claims", body); - } - } else { - //未登录,跳转到登录页面 - //response.sendRedirect(request.getContextPath()+"user/login"); - //response.getWriter().write("login"); - throw new LoginException("未登录"); - //return false; - } - //放行 - return true; - } - - @Override - //记录日志 - public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { - - HandlerInterceptor.super.afterCompletion(request, response, handler, ex); - } -} - diff --git a/center/src/main/java/com/tiji/center/mq/IMReceiver.java b/center/src/main/java/com/tiji/center/mq/IMReceiver.java deleted file mode 100755 index 82b70e3..0000000 --- a/center/src/main/java/com/tiji/center/mq/IMReceiver.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.tiji.center.mq; - -import com.tiji.center.pojo.*; -import com.tiji.center.service.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.amqp.rabbit.annotation.RabbitHandler; -import org.springframework.amqp.rabbit.annotation.RabbitListener; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; -import util.ExcpUtil; - -import java.util.*; - -/** - * @author 贰拾壹 - * @create 2019-11-12 15:17 - */ -@Component -@RabbitListener(queues = "imresult") -public class IMReceiver { - private final static Logger logger = LoggerFactory.getLogger(IMReceiver.class); - @Autowired - private VulnService vulnService; - @Autowired - private ContactService contactService; - @Autowired - private ProjectinfoService projectinfoService; - @Autowired - private ContactProjectinfoService contactProjectinfoService; - @Autowired - private RedisTemplate redisTemplate; - - @RabbitHandler - public void getMessage(Map resultMap) { - try { - if (!resultMap.isEmpty()) { - String imResultKey = "imResultList"; - String projectinfoid = (String) resultMap.get("projectinfoid"); - String risk = (String) resultMap.get("risk"); - String ip = (String) resultMap.get("ip"); - String port = (String) resultMap.get("port"); - String protocol = (String) resultMap.get("protocol"); - String service = (String) resultMap.get("service"); - String version = (String) resultMap.get("version"); - String pluginName = (String) resultMap.get("pluginName"); - - List vulnResultList = new ArrayList<>(); - if (!Objects.isNull(resultMap.get("vulnIdList"))) { - List vulnIdList = (List) resultMap.get("vulnIdList"); - for (String vulnId : vulnIdList) { - Vuln vuln = vulnService.findById(vulnId); - vulnResultList.add(vuln.getName()); - } - } - - String result; - //漏洞 - if (!StringUtils.isEmpty(risk)) { - result = "**" + vulnResultList + "**" + " " + risk + " " + ip + " " + port + " " + service + " " + version + " " + pluginName; - } else { - //资产 - if(StringUtils.isEmpty(protocol)){ - protocol=""; - } - if(StringUtils.isEmpty(service)){ - service=""; - } - if(StringUtils.isEmpty(version)){ - version=""; - } - result = ip + " " + port + " " + protocol + " " + service + " " + version; - } - - List nameList = new ArrayList<>(); - //有项目编号 - if (!Objects.isNull(projectinfoid)) { - Map searchMap = new HashMap<>(); - searchMap.put("projectinfoid", projectinfoid); - List contactProjectinfoList = contactProjectinfoService.findSearch(searchMap); - List contactList = new ArrayList<>(); - for (ContactProjectinfo contactProjectinfo : contactProjectinfoList) { - String contactid = contactProjectinfo.getContactid(); - contactList.add(contactService.findById(contactid)); - } - for (Contact contact : contactList) { - String name = contact.getName(); - nameList.add(name); - } - } - - //im通知默认联系人 - String projectName = null; - if (!Objects.isNull(projectinfoid)) { - Projectinfo projectinfo = projectinfoService.findById(projectinfoid); - if (!Objects.isNull(projectinfo)) { - projectName = projectinfo.getProjectname(); - } - } - if (Objects.isNull(projectName)) { - projectName = ""; - } - String resultWithContact = result + " " + projectName + " " + nameList; - //先进先出 - redisTemplate.opsForList().leftPush(imResultKey, resultWithContact); - } - } catch (Exception e) { - logger.error("IMReceiver Exception here: " + ExcpUtil.buildErrorMessage(e)); - } - } -} diff --git a/center/src/main/java/com/tiji/center/mq/ScanResultReceiver.java b/center/src/main/java/com/tiji/center/mq/ScanResultReceiver.java deleted file mode 100755 index 9b60f65..0000000 --- a/center/src/main/java/com/tiji/center/mq/ScanResultReceiver.java +++ /dev/null @@ -1,385 +0,0 @@ -package com.tiji.center.mq; - -import com.tiji.center.pojo.*; -import com.tiji.center.service.*; -import com.tiji.center.util.TijiHelper; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.amqp.rabbit.annotation.RabbitHandler; -import org.springframework.amqp.rabbit.annotation.RabbitListener; -import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Component; -import util.ExcpUtil; -import util.IdWorker; - -import java.util.*; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - -/** - * @author 贰拾壹 - * @create 2019-07-03 15:30 - */ - -@Component -@RabbitListener(queues = "scanresult") -public class ScanResultReceiver { - - private final static Logger logger = LoggerFactory.getLogger(ScanResultReceiver.class); - @Autowired - private TaskService taskService; - @Autowired - private TaskipService taskipService; - @Autowired - private TaskportService taskportService; - @Autowired - private AssetipService assetipService; - @Autowired - private AssetportService assetportService; - @Autowired - private RedisTemplate redisTemplate; - @Autowired - private RabbitMessagingTemplate rabbitMessagingTemplate; - @Autowired - private IdWorker idWorker; - @Autowired - private PluginconfigService pluginconfigService; - @Autowired - private CheckresultService checkresultService; - @Autowired - private CheckresultVulnService checkresultVulnService; - @Autowired - private VulnpluginconfigService vulnpluginconfigService; - @Autowired - private VulnkeywordService vulnkeywordService; - @Autowired - private WebinfoService webinfoService; - @Autowired - private TitlewhitelistService titlewhitelistService; - @Autowired - private DomainwhitelistService domainwhitelistService; - @Autowired - private UrlService urlService; - @Autowired - private NmapconfigService nmapconfigService; - @Autowired - private ImvulnnotifyService imvulnnotifyService; - @Autowired - private AgentService agentService; - @Autowired - private HostService hostService; - @Autowired - private WebrawdataService webrawdataService; - @Autowired - private RiskportService riskportService; - @Autowired - private RiskserviceService riskserviceService; - @Autowired - private RiskversionService riskversionService; - - - @RabbitHandler - public void getMessage(Map resultMap) { - try { - if (!Objects.isNull(resultMap) && !resultMap.isEmpty()) { - - String workType = resultMap.get("workType"); - String taskId = resultMap.get("taskId"); - String scanResult = resultMap.get("scanResult"); - - - //用于清除redis缓存、runningTaskMap已完成任务 - //监控当前任务信息 - //总任务数 - String totalTaskListName = "totalTaskList_" + taskId; - //已完成任务数 - String accomplishTaskListName = "accomplishTaskList_" + taskId; - //正在进行的,没有操作到这个.. - String workingTaskListName = "workingTaskList_" + taskId; - //分组大小 - String sliceIPListSizeName = "sliceIPListSize_" + taskId; - //任务状态标志 - String taskStatusName = "taskStatus_" + taskId; - - String task_status = redisTemplate.opsForValue().get(taskStatusName); - - long totalTaskListSize = redisTemplate.opsForList().size(totalTaskListName); - long accomplishTaskListSize = redisTemplate.opsForList().size(accomplishTaskListName); - long workingTaskListSize = redisTemplate.opsForList().size(workingTaskListName); - //计算working的任务 - //working = total - accomplish - //redisTemplate.opsForSet().differenceAndStore(totalTaskListName, accomplishTaskListName, workingTaskListName); - - - List totalTaskList = redisTemplate.opsForList().range(totalTaskListName, 0, -1); - //System.out.println("totalTaskList: " + totalTaskList); - List accomplishTaskList = redisTemplate.opsForList().range(accomplishTaskListName, 0, -1); - totalTaskList.removeAll(accomplishTaskList); - if (!totalTaskList.isEmpty()) { - System.out.println("working: " + totalTaskList); - } - - boolean secondTaskFlag = false; - - //进度监控 - if (redisTemplate.hasKey(sliceIPListSizeName)) { - long sliceIPListSize = Long.parseLong(redisTemplate.opsForValue().get(sliceIPListSizeName)); - double taskPercentStatus = (double) accomplishTaskListSize / sliceIPListSize; - //System.out.println("sliceIPListSize:" + sliceIPListSize); - System.out.printf("task %s progress %f\n", taskId, taskPercentStatus); - //if (accomplishTaskListSize == totalTaskListSize && accomplishTaskListSize != 0 && workingTaskListSize == 0) { - //accomplishTaskListSize等于总分组数sliceIPList,任务结束 - if (accomplishTaskListSize == sliceIPListSize) { - System.out.printf("task %s finished\n", taskId); - if (!workType.equals("mass2Nmap")) { - //记录任务结束时间 - Task task = taskService.findById(taskId); - task.setEndtime(new Date()); - taskService.update(task); - } -// redisTemplate.delete("ip_" + taskId); -// redisTemplate.delete("port_" + taskId); -// redisTemplate.delete("cmd_" + taskId); -// redisTemplate.delete("nginxRawVersion_"+taskId + taskId); -// redisTemplate.delete("timeout_" + taskId); - redisTemplate.delete(totalTaskListName); - //redisTemplate.delete(accomplishTaskListName); - if (workType.equals("mass2Nmap")) { - redisTemplate.delete(accomplishTaskListName); - } else { - redisTemplate.expire(accomplishTaskListName, 15, TimeUnit.SECONDS); - } - //redisTemplate.delete(workingTaskListName); - redisTemplate.delete(sliceIPListSizeName); - - //如果任务结束,给agent发结束信息,runningTaskMap删除已完成任务 - //redisTemplate.delete(accomplishTaskListName); - if (!workType.equals("mass2Nmap")) { - Map taskConfig = new HashMap<>(); - taskConfig.put("status", "removeAccomplishTask"); - taskConfig.put("taskId", taskId); - rabbitMessagingTemplate.convertAndSend("tijifanout", "", taskConfig); - } - if (workType.equals("mass2Nmap")) { - secondTaskFlag = true; - } - } - } - - - //mass2Nmap模式下,当前任务被终止 - if (!Objects.isNull(task_status) && task_status.equals("exit")) { - secondTaskFlag = false; - //remove flag - //redisTemplate.delete(taskStatusName); - //mass2Nmap下,删除退出的进程 - //好像agent可以删掉.... - //redisTemplate.expire(accomplishTaskListName, 15, TimeUnit.SECONDS); - - redisTemplate.expire(taskStatusName, 15, TimeUnit.SECONDS); - } - if (Objects.isNull(task_status)) { - switch (workType) { - case "mass": { - if (!Objects.isNull(scanResult)) { - Set riskPortSet = new HashSet<>(); - Set riskServiceSet = new HashSet<>(); - Set riskVersionSet = new HashSet<>(); - riskInfo2Set(riskPortSet, riskServiceSet, riskVersionSet); - - Map> massResultMap = TijiHelper.ipAndPortList2Map(scanResult); - //mysql入库 - TijiHelper.massScanResult2DB(massResultMap, taskipService, taskportService, idWorker, taskId); - //任务结果,合并到资产库 - if (taskService.findById(taskId).getMerge2asset()) { - TijiHelper.massScanResult2AssetDB(assetipService, assetportService, idWorker, rabbitMessagingTemplate, riskPortSet, riskServiceSet, riskVersionSet, massResultMap); - } - } - break; - } - case "nmap": { - if (!Objects.isNull(scanResult)) { - Set riskPortSet = new HashSet<>(); - Set riskServiceSet = new HashSet<>(); - Set riskVersionSet = new HashSet<>(); - riskInfo2Set(riskPortSet, riskServiceSet, riskVersionSet); - - Map, Set> nmapResultMap = TijiHelper.nmapResult2Map(scanResult); - //mysql入库 - TijiHelper.nmapScanResult2DB(nmapResultMap, taskipService, taskportService, idWorker, taskId); - //任务结果,合并到资产库 - if (taskService.findById(taskId).getMerge2asset()) { - TijiHelper.nmapScanResult2AssetDB(assetipService, assetportService, hostService, idWorker, rabbitMessagingTemplate, riskPortSet, riskServiceSet, riskVersionSet, nmapResultMap); - } - } - break; - } - case "mass2Nmap": - if (!Objects.isNull(scanResult)) { - Set riskPortSet = new HashSet<>(); - Set riskServiceSet = new HashSet<>(); - Set riskVersionSet = new HashSet<>(); - riskInfo2Set(riskPortSet, riskServiceSet, riskVersionSet); - //mass - //第一次用mass扫 - Map> massResultMap1 = TijiHelper.ipAndPortList2Map(scanResult); - //mysql入库 - TijiHelper.massScanResult2DB(massResultMap1, taskipService, taskportService, idWorker, taskId); - //任务结果,合并到资产库 - if (taskService.findById(taskId).getMerge2asset()) { - TijiHelper.massScanResult2AssetDB(assetipService, assetportService, idWorker, rabbitMessagingTemplate, riskPortSet, riskServiceSet, riskVersionSet, massResultMap1); - } - //当前任务已经结束或未被终止,发送第二次任务 - if (secondTaskFlag) { - List onlineAgentList = agentService.findAllByOnline(true); - int agentCount; - if (onlineAgentList.isEmpty()) { - break; - } else { - agentCount = onlineAgentList.size(); - } - Map taskConfig = new HashMap<>(); - String sliceIPList = "sliceIPList_" + taskId; - //taskip数据库获取当前任务的ip和端口,即masscan扫描之后的ip和端口 - List ipAndPortList = taskipService.findTaskIpAndPort(taskId); - - //System.out.println("ipAndPortList:" + ipAndPortList.size()); - //ipAndPortList.forEach(System.out::println); - if (ipAndPortList.isEmpty()) { - //没有扫到端口,结束任务 - Task task = taskService.findById(taskId); - redisTemplate.delete(totalTaskListName); - redisTemplate.delete(sliceIPListSizeName); - task.setEndtime(new Date()); - - taskConfig.put("status", "removeAccomplishTask"); - taskConfig.put("taskId", taskId); - rabbitMessagingTemplate.convertAndSend("tijifanout", "", taskConfig); - taskService.update(task); - break; - } - Map> ipAndPortResultMap; - Map> ipAndPortRTempMap = new LinkedHashMap<>(); - ipAndPortResultMap = TijiHelper.ipAndPortList2Map(ipAndPortList); - BlockingQueue ipAndPortQueue = new LinkedBlockingQueue<>(); - TijiHelper.iPWithSamePorts2OneGroup(ipAndPortRTempMap, ipAndPortResultMap, ipAndPortQueue); - for (Map.Entry> entry : ipAndPortRTempMap.entrySet()) { - String ips = StringUtils.join(entry.getValue(), ","); - ipAndPortQueue.put(ips.replaceAll(",", " ") + " -p" + entry.getKey()); - } - for (String ipAndPort : ipAndPortQueue) { - redisTemplate.opsForList().leftPush(sliceIPList, ipAndPort); - } - - //设置当前分组大小 - redisTemplate.opsForValue().set("sliceIPListSize_" + taskId, String.valueOf(redisTemplate.opsForList().size(sliceIPList))); - - taskConfig.put("status", "start"); - taskConfig.put("taskId", taskId); - taskConfig.put("workType", "nmap"); - taskConfig.put("sliceIPList", sliceIPList); - - - Task task = taskService.findById(taskId); - String taskParentId = task.getTaskparentid(); - String nmapConfigId = taskId; - if (!Objects.isNull(taskParentId) && !taskParentId.isEmpty()) { - nmapConfigId = taskParentId; - } - Nmapconfig nmapconfig = nmapconfigService.findByTaskid(nmapConfigId); - taskConfig.put("threadNumber", nmapconfig.getThreadnumber()); - taskConfig.put("singleIpScanTime", nmapconfig.getSingleipscantime()); - taskConfig.put("additionOption", nmapconfig.getAdditionoption()); - - //分组数存入redis - double sliceIPListSize = redisTemplate.opsForList().size(sliceIPList); - //向上取整,确保所有的agent取出的数量大于等于总数 - double maxSliceSize = Math.ceil(sliceIPListSize / agentCount); - taskConfig.put("maxSliceSize", String.valueOf(maxSliceSize)); - - //任务丢给MQ - rabbitMessagingTemplate.convertAndSend("tijifanout", "", taskConfig); - - } - } - break; - case "nse": - if (!Objects.isNull(scanResult)) { - if (scanResult.contains("-p") && scanResult.contains("Starting")) { - TijiHelper.nseResultParser(assetipService, assetportService, idWorker, pluginconfigService, checkresultService, vulnkeywordService, checkresultVulnService, vulnpluginconfigService, imvulnnotifyService, redisTemplate, rabbitMessagingTemplate, scanResult); - } - } - break; - case "selfd": - if (!Objects.isNull(scanResult)) { - TijiHelper.selfdResultParser(assetipService, assetportService, idWorker, pluginconfigService, checkresultService, vulnkeywordService, checkresultVulnService, vulnpluginconfigService, imvulnnotifyService, redisTemplate, rabbitMessagingTemplate, resultMap, scanResult); - } - break; - case "httpp": - TijiHelper.httppResult2Db(webinfoService, urlService, idWorker, titlewhitelistService, domainwhitelistService, webrawdataService, resultMap, scanResult); - break; - default: - break; - } - } - } - } catch (Exception e) { - logger.error("ScanResultReceiver Exception here: " + ExcpUtil.buildErrorMessage(e)); - } - - } - - private void riskInfo2Set(Set riskPortSet, Set riskServiceSet, Set riskVersionSet) { - String riskPortSetKey = "riskPortSet"; - String riskServiceSetKey = "riskServiceSet"; - String riskVersionSetKey = "riskVersionSet"; - String riskassetnotifyKey = "riskassetnotify"; - Boolean riskassetnotifyFlagExist = redisTemplate.hasKey(riskassetnotifyKey); - Boolean assetnotifyFlag = false; - if (!Objects.isNull(riskassetnotifyFlagExist) && riskassetnotifyFlagExist) { - String riskassetnotify = redisTemplate.opsForValue().get(riskassetnotifyKey); - if (!Objects.isNull(riskassetnotify) && "true".equals(riskassetnotify)) { - assetnotifyFlag = true; - } - } - if (assetnotifyFlag) { - Boolean riskPortSetFlagExist = redisTemplate.hasKey(riskPortSetKey); - if (!Objects.isNull(riskPortSetFlagExist) && riskPortSetFlagExist) { - riskPortSet.addAll(redisTemplate.opsForSet().members(riskPortSetKey)); - } else { - List riskportList = riskportService.findAll(); - riskportList.parallelStream().forEach(riskport -> { - String port = riskport.getPort(); - redisTemplate.opsForSet().add(riskPortSetKey, port); - riskPortSet.add(port); - }); - } - Boolean riskServiceSetFlagExist = redisTemplate.hasKey(riskServiceSetKey); - if (!Objects.isNull(riskServiceSetFlagExist) && riskServiceSetFlagExist) { - riskServiceSet.addAll(redisTemplate.opsForSet().members(riskServiceSetKey)); - } else { - List riskserviceList = riskserviceService.findAll(); - riskserviceList.parallelStream().forEach(riskservice -> { - String service = riskservice.getService(); - redisTemplate.opsForSet().add(riskServiceSetKey, service); - riskServiceSet.add(service); - }); - } - Boolean riskVersionSetFlagExist = redisTemplate.hasKey(riskVersionSetKey); - if (!Objects.isNull(riskVersionSetFlagExist) && riskVersionSetFlagExist) { - riskVersionSet.addAll(redisTemplate.opsForSet().members(riskVersionSetKey)); - } else { - List riskversionList = riskversionService.findAll(); - riskversionList.parallelStream().forEach(riskversion -> { - String service = riskversion.getVersion(); - redisTemplate.opsForSet().add(riskVersionSetKey, service); - riskVersionSet.add(service); - }); - } - } - } -} \ No newline at end of file diff --git a/center/src/main/java/com/tiji/center/pojo/Agent.java b/center/src/main/java/com/tiji/center/pojo/Agent.java deleted file mode 100755 index 6e390b9..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Agent.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * agent实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_agent") -public class Agent implements Serializable { - @Id - private String id;//agent编号 - - - private String name;//agent名称 - private String nmappath;//nmap路径 - private String masspath;//mass路径 - private String ipaddress;//ip地址 - private Boolean online;//在线 - private String timeouts;//超时次数 - - public Agent() { - } - - public Agent(String id, String name, String nmappath, String masspath, String ipaddress, Boolean online, String timeouts) { - this.id = id; - this.name = name; - this.nmappath = nmappath; - this.masspath = masspath; - this.ipaddress = ipaddress; - this.online = online; - this.timeouts = timeouts; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getNmappath() { - return nmappath; - } - - public void setNmappath(String nmappath) { - this.nmappath = nmappath; - } - - public String getMasspath() { - return masspath; - } - - public void setMasspath(String masspath) { - this.masspath = masspath; - } - - public String getIpaddress() { - return ipaddress; - } - - public void setIpaddress(String ipaddress) { - this.ipaddress = ipaddress; - } - - public Boolean getOnline() { - return online; - } - - public void setOnline(Boolean online) { - this.online = online; - } - - public String getTimeouts() { - return timeouts; - } - - public void setTimeouts(String timeouts) { - this.timeouts = timeouts; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Assetip.java b/center/src/main/java/com/tiji/center/pojo/Assetip.java deleted file mode 100755 index 98fd7a3..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Assetip.java +++ /dev/null @@ -1,183 +0,0 @@ -package com.tiji.center.pojo; - -import com.tiji.center.pojo.category.CategoryTab; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Transient; -import java.io.Serializable; -import java.util.Date; -import java.util.List; - -/** - * assetip实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_assetip") -public class Assetip implements Serializable { - - @Id - private String id;//资产ip编号 - - @Transient - private String statistic; - @Transient - private String projectname; - - private String projectinfoid;//联系表编号 - private String ipaddressv4;//ip地址 - private String ipaddressv6;//ipaddressv6 - private Boolean checkwhitelist;//安全检测白名单 - private Boolean assetnotifywhitelist;//资产提醒白名单 - private java.util.Date activetime;//ip发现时间 - private java.util.Date passivetime;//ip下线时间 - private String remark;//备注 - //标签bitmap - private String tabbitmap; - //标签名 - @Transient - private String tabname; - //标签 - @Transient - private List tabList; - @Transient - //应用系统名称 - private String appsysname; - public Assetip() { - } - - public Assetip(String id, String projectinfoid, String ipaddressv4, String ipaddressv6, Boolean checkwhitelist, Boolean assetnotifywhitelist, Date activetime, Date passivetime, String remark) { - this.id = id; - this.projectinfoid = projectinfoid; - this.ipaddressv4 = ipaddressv4; - this.ipaddressv6 = ipaddressv6; - this.checkwhitelist = checkwhitelist; - this.assetnotifywhitelist = assetnotifywhitelist; - this.activetime = activetime; - this.passivetime = passivetime; - this.remark = remark; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getStatistic() { - return statistic; - } - - public void setStatistic(String statistic) { - this.statistic = statistic; - } - - public String getProjectname() { - return projectname; - } - - public void setProjectname(String projectname) { - this.projectname = projectname; - } - - public String getProjectinfoid() { - return projectinfoid; - } - - public void setProjectinfoid(String projectinfoid) { - this.projectinfoid = projectinfoid; - } - - public String getIpaddressv4() { - return ipaddressv4; - } - - public void setIpaddressv4(String ipaddressv4) { - this.ipaddressv4 = ipaddressv4; - } - - public String getIpaddressv6() { - return ipaddressv6; - } - - public void setIpaddressv6(String ipaddressv6) { - this.ipaddressv6 = ipaddressv6; - } - - public Boolean getCheckwhitelist() { - return checkwhitelist; - } - - public void setCheckwhitelist(Boolean checkwhitelist) { - this.checkwhitelist = checkwhitelist; - } - - public Boolean getAssetnotifywhitelist() { - return assetnotifywhitelist; - } - - public void setAssetnotifywhitelist(Boolean assetnotifywhitelist) { - this.assetnotifywhitelist = assetnotifywhitelist; - } - - public java.util.Date getActivetime() { - return activetime; - } - - public void setActivetime(java.util.Date activetime) { - this.activetime = activetime; - } - - public java.util.Date getPassivetime() { - return passivetime; - } - - public void setPassivetime(java.util.Date passivetime) { - this.passivetime = passivetime; - } - - public String getRemark() { - return remark; - } - - public void setRemark(String remark) { - this.remark = remark; - } - - public String getTabbitmap() { - return tabbitmap; - } - - public void setTabbitmap(String tabbitmap) { - this.tabbitmap = tabbitmap; - } - - public String getTabname() { - return tabname; - } - - public void setTabname(String tabname) { - this.tabname = tabname; - } - - public List getTabList() { - return tabList; - } - - public void setTabList(List tabList) { - this.tabList = tabList; - } - - public String getAppsysname() { - return appsysname; - } - - public void setAppsysname(String appsysname) { - this.appsysname = appsysname; - } -} diff --git a/center/src/main/java/com/tiji/center/pojo/Assetport.java b/center/src/main/java/com/tiji/center/pojo/Assetport.java deleted file mode 100755 index 11f053e..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Assetport.java +++ /dev/null @@ -1,202 +0,0 @@ -package com.tiji.center.pojo; - -import com.tiji.center.pojo.category.CategoryTab; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Transient; -import java.io.Serializable; -import java.util.Date; -import java.util.List; - -/** - * assetport实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_assetport") -public class Assetport implements Serializable { - - @Id - private String id;//端口编号 - - @Transient - private String statistic; - - private String assetipid;//资产ip编号 - private String port;//端口 - private String protocol;//端口协议 - private String state;//端口开放状态 - private String service;//端口服务 - private String version;//服务版本 - private Boolean checkwhitelist;//安全检测白名单 - private Boolean assetnotifywhitelist;//资产提醒白名单 - private java.util.Date uptime;//端口发现时间 - private java.util.Date downtime;//端口关闭时间 - private java.util.Date changedtime;//修改时间 - //标签bitmap - private String tabbitmap; - //标签名 - @Transient - private String tabname; - //标签 - @Transient - private List tabList; - public Assetport() { - } - @Transient - //应用系统名称 - private String appsysname; - public Assetport(String id, String assetipid, String port, String protocol, String state, String service, String version, Boolean checkwhitelist, Boolean assetnotifywhitelist, Date uptime, Date downtime, Date changedtime) { - this.id = id; - this.assetipid = assetipid; - this.port = port; - this.protocol = protocol; - this.state = state; - this.service = service; - this.version = version; - this.checkwhitelist = checkwhitelist; - this.assetnotifywhitelist = assetnotifywhitelist; - this.uptime = uptime; - this.downtime = downtime; - this.changedtime = changedtime; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getStatistic() { - return statistic; - } - - public void setStatistic(String statistic) { - this.statistic = statistic; - } - - public String getAssetipid() { - return assetipid; - } - - public void setAssetipid(String assetipid) { - this.assetipid = assetipid; - } - - public String getPort() { - return port; - } - - public void setPort(String port) { - this.port = port; - } - - public String getProtocol() { - return protocol; - } - - public void setProtocol(String protocol) { - this.protocol = protocol; - } - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public String getService() { - return service; - } - - public void setService(String service) { - this.service = service; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public Boolean getCheckwhitelist() { - return checkwhitelist; - } - - public void setCheckwhitelist(Boolean checkwhitelist) { - this.checkwhitelist = checkwhitelist; - } - - public Boolean getAssetnotifywhitelist() { - return assetnotifywhitelist; - } - - public void setAssetnotifywhitelist(Boolean assetnotifywhitelist) { - this.assetnotifywhitelist = assetnotifywhitelist; - } - - public Date getUptime() { - return uptime; - } - - public void setUptime(Date uptime) { - this.uptime = uptime; - } - - public Date getDowntime() { - return downtime; - } - - public void setDowntime(Date downtime) { - this.downtime = downtime; - } - - public Date getChangedtime() { - return changedtime; - } - - public void setChangedtime(Date changedtime) { - this.changedtime = changedtime; - } - - public String getTabbitmap() { - return tabbitmap; - } - - public void setTabbitmap(String tabbitmap) { - this.tabbitmap = tabbitmap; - } - - public String getTabname() { - return tabname; - } - - public void setTabname(String tabname) { - this.tabname = tabname; - } - - public List getTabList() { - return tabList; - } - - public void setTabList(List tabList) { - this.tabList = tabList; - } - - public String getAppsysname() { - return appsysname; - } - - public void setAppsysname(String appsysname) { - this.appsysname = appsysname; - } -} diff --git a/center/src/main/java/com/tiji/center/pojo/Categorysecond.java b/center/src/main/java/com/tiji/center/pojo/Categorysecond.java deleted file mode 100755 index be6365f..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Categorysecond.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * categorysecond实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_categorysecond") -public class Categorysecond implements Serializable { - - @Id - private String id;//漏洞二级分类编号 - - - private String categorytopid;//漏洞一级分类编号 - private String name;//漏洞二级分类类型 - - public Categorysecond() { - } - - public Categorysecond(String id, String categorytopid, String name) { - this.id = id; - this.categorytopid = categorytopid; - this.name = name; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getCategorytopid() { - return categorytopid; - } - - public void setCategorytopid(String categorytopid) { - this.categorytopid = categorytopid; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Categorytop.java b/center/src/main/java/com/tiji/center/pojo/Categorytop.java deleted file mode 100755 index 1526d2c..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Categorytop.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * categorytop实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_categorytop") -public class Categorytop implements Serializable { - - @Id - private String id;//漏洞一级分类编号 - - - private String name;//漏洞一级分类名称 - - public Categorytop() { - } - - public Categorytop(String id, String name) { - this.id = id; - this.name = name; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Checkresult.java b/center/src/main/java/com/tiji/center/pojo/Checkresult.java deleted file mode 100755 index 5bc1aad..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Checkresult.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Transient; -import java.io.Serializable; -import java.util.Date; - -/** - * checkresult实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_checkresult") -public class Checkresult implements Serializable { - - @Id - private String id;//检测结果编号 - - - - @Transient - private String assetip; - @Transient - private String assetipid; - @Transient - private String vulname; - @Transient - private String vulnid; - @Transient - private String assetport;//端口 - - private String assetportid;//端口编号 - private String name;//检测结果名称 - private String result;//检测结果 - private String risk;//缺陷风险级别 - private java.util.Date activetime;//缺陷发现时间 - private java.util.Date passivetime;//缺陷修复时间 - private String remark;//备注 - - public Checkresult() { - } - - public Checkresult(String id, String assetportid, String name, String result, String risk, Date activetime, Date passivetime, String remark) { - this.id = id; - this.assetportid = assetportid; - this.name = name; - this.result = result; - this.risk = risk; - this.activetime = activetime; - this.passivetime = passivetime; - this.remark = remark; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getAssetip() { - return assetip; - } - - public void setAssetip(String assetip) { - this.assetip = assetip; - } - - public String getVulname() { - return vulname; - } - - public String getAssetport() { - return assetport; - } - - public void setAssetport(String assetport) { - this.assetport = assetport; - } - - public void setVulname(String vulname) { - this.vulname = vulname; - } - - public String getAssetportid() { - return assetportid; - } - - public void setAssetportid(String assetportid) { - this.assetportid = assetportid; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getResult() { - return result; - } - - public void setResult(String result) { - this.result = result; - } - - public String getRisk() { - return risk; - } - - public void setRisk(String risk) { - this.risk = risk; - } - - public Date getActivetime() { - return activetime; - } - - public void setActivetime(Date activetime) { - this.activetime = activetime; - } - - public Date getPassivetime() { - return passivetime; - } - - public void setPassivetime(Date passivetime) { - this.passivetime = passivetime; - } - - public String getRemark() { - return remark; - } - - public void setRemark(String remark) { - this.remark = remark; - } - - public String getAssetipid() { - return assetipid; - } - - public void setAssetipid(String assetipid) { - this.assetipid = assetipid; - } - - public String getVulnid() { - return vulnid; - } - - public void setVulnid(String vulnid) { - this.vulnid = vulnid; - } -} - diff --git a/center/src/main/java/com/tiji/center/pojo/CheckresultVuln.java b/center/src/main/java/com/tiji/center/pojo/CheckresultVuln.java deleted file mode 100755 index 76667f4..0000000 --- a/center/src/main/java/com/tiji/center/pojo/CheckresultVuln.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * checkresultVuln实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_checkresult_vuln") -public class CheckresultVuln implements Serializable { - - @Id - private String id;//编号 - - - private String checkresultid;//检测结果编号 - private String vulnid;//漏洞编号 - - public CheckresultVuln() { - } - - public CheckresultVuln(String id, String checkresultid, String vulnid) { - this.id = id; - this.checkresultid = checkresultid; - this.vulnid = vulnid; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getCheckresultid() { - return checkresultid; - } - - public void setCheckresultid(String checkresultid) { - this.checkresultid = checkresultid; - } - - public String getVulnid() { - return vulnid; - } - - public void setVulnid(String vulnid) { - this.vulnid = vulnid; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Contact.java b/center/src/main/java/com/tiji/center/pojo/Contact.java deleted file mode 100755 index 4e7826b..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Contact.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Transient; -import java.io.Serializable; - -/** - * contact实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_contact") -public class Contact implements Serializable { - - @Id - private String id;//编号 - - @Transient - private String projectinfoid; - private String name;//联系人 - private String email;//邮箱 - private String phone;//电话,座机或手机 - - public Contact() { - } - - public Contact(String id, String name, String email, String phone) { - this.id = id; - this.name = name; - this.email = email; - this.phone = phone; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getProjectinfoid() { - return projectinfoid; - } - - public void setProjectinfoid(String projectinfoid) { - this.projectinfoid = projectinfoid; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone; - } - -} diff --git a/center/src/main/java/com/tiji/center/pojo/ContactProjectinfo.java b/center/src/main/java/com/tiji/center/pojo/ContactProjectinfo.java deleted file mode 100755 index 8927e7f..0000000 --- a/center/src/main/java/com/tiji/center/pojo/ContactProjectinfo.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * contactProjectinfo实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_contact_projectinfo") -public class ContactProjectinfo implements Serializable { - - @Id - private String id;//编号 - - - private String contactid;//联系编号 - private String projectinfoid;//项目信息编号 - - public ContactProjectinfo() { - } - - public ContactProjectinfo(String id, String contactid, String projectinfoid) { - this.id = id; - this.contactid = contactid; - this.projectinfoid = projectinfoid; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getContactid() { - return contactid; - } - - public void setContactid(String contactid) { - this.contactid = contactid; - } - - public String getProjectinfoid() { - return projectinfoid; - } - - public void setProjectinfoid(String projectinfoid) { - this.projectinfoid = projectinfoid; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Cronjob.java b/center/src/main/java/com/tiji/center/pojo/Cronjob.java deleted file mode 100755 index d234482..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Cronjob.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Transient; -import java.io.Serializable; - -/** - * cronjob实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_cronjob") -public class Cronjob implements Serializable { - - @Id - private String id;//编号 - - - @Transient - private String jobstate; - - private String name;//名称 - private String cronexpression;//cron表达式 - - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getJobstate() { - return jobstate; - } - - public void setJobstate(String jobstate) { - this.jobstate = jobstate; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getCronexpression() { - return cronexpression; - } - - public void setCronexpression(String cronexpression) { - this.cronexpression = cronexpression; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Democode.java b/center/src/main/java/com/tiji/center/pojo/Democode.java deleted file mode 100755 index 714753e..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Democode.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * democode实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_democode") -public class Democode implements Serializable { - - @Id - private String id;//漏洞示例代码编号 - - - private String vulnid;//漏洞编号 - private String democode;//漏洞示例代码 - private String poc;//漏洞poc - - public Democode() { - } - - public Democode(String id, String vulnid, String democode, String poc) { - this.id = id; - this.vulnid = vulnid; - this.democode = democode; - this.poc = poc; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getVulnid() { - return vulnid; - } - - public void setVulnid(String vulnid) { - this.vulnid = vulnid; - } - - public String getDemocode() { - return democode; - } - - public void setDemocode(String democode) { - this.democode = democode; - } - - public String getPoc() { - return poc; - } - - public void setPoc(String poc) { - this.poc = poc; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Department.java b/center/src/main/java/com/tiji/center/pojo/Department.java deleted file mode 100755 index ee54fbc..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Department.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * department实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_department") -public class Department implements Serializable { - - @Id - private String id;//编号 - - - private String departmentname;//部门名称 - - public Department() { - } - - public Department(String id, String departmentname) { - this.id = id; - this.departmentname = departmentname; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getDepartmentname() { - return departmentname; - } - - public void setDepartmentname(String departmentname) { - this.departmentname = departmentname; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Dictionarypassword.java b/center/src/main/java/com/tiji/center/pojo/Dictionarypassword.java deleted file mode 100755 index 1ce5a2d..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Dictionarypassword.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * dictionarypassword实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_dictionarypassword") -public class Dictionarypassword implements Serializable { - - @Id - private String id;//字典编号 - - - private String password;//字典密码 - - public Dictionarypassword() { - } - - public Dictionarypassword(String id, String password) { - this.id = id; - this.password = password; - } - - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Dictionaryusername.java b/center/src/main/java/com/tiji/center/pojo/Dictionaryusername.java deleted file mode 100755 index 84dda89..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Dictionaryusername.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * dictionaryusername实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_dictionaryusername") -public class Dictionaryusername implements Serializable { - - @Id - private String id;//字典编号 - - - private String username;//字典用户名 - - public Dictionaryusername() { - } - - public Dictionaryusername(String id, String username) { - this.id = id; - this.username = username; - } - - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Domainwhitelist.java b/center/src/main/java/com/tiji/center/pojo/Domainwhitelist.java deleted file mode 100755 index 73596a2..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Domainwhitelist.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * domainwhitelist实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_domainwhitelist") -public class Domainwhitelist implements Serializable { - - @Id - private String id;//参数编号 - - - private String domain;//域名 - - public Domainwhitelist() { - } - - public Domainwhitelist(String id, String domain) { - this.id = id; - this.domain = domain; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getDomain() { - return domain; - } - - public void setDomain(String domain) { - this.domain = domain; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Host.java b/center/src/main/java/com/tiji/center/pojo/Host.java deleted file mode 100755 index 3ad909f..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Host.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Transient; -import java.io.Serializable; -import java.util.Date; - -/** - * host实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_host") -public class Host implements Serializable { - - @Id - private String id;//主机编号 - - - private String assetipid;//资产ip编号 - private String macaddress;//mac地址 - private String hostname;//主机名 - private String subdomain;//子域名 - private String ostype;//操作系统类型 - private String osversion;//操作系统版本 - private String type;//主机类型 - private String owner;//主机所有者 - private java.util.Date activetime;//主机发现时间 - private String remark;//备注,标记非dns反向解析 - - @Transient - //应用系统名称 - private String appsysname; - - - public Host() { - } - - public Host(String id, String assetipid, String macaddress, String hostname, String ostype, String osversion, String type, String owner, Date activetime, String remark) { - this.id = id; - this.assetipid = assetipid; - this.macaddress = macaddress; - this.hostname = hostname; - this.ostype = ostype; - this.osversion = osversion; - this.type = type; - this.owner = owner; - this.activetime = activetime; - this.remark = remark; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getAssetipid() { - return assetipid; - } - - public void setAssetipid(String assetipid) { - this.assetipid = assetipid; - } - - public String getMacaddress() { - return macaddress; - } - - public void setMacaddress(String macaddress) { - this.macaddress = macaddress; - } - - public String getHostname() { - return hostname; - } - - public void setHostname(String hostname) { - this.hostname = hostname; - } - - public String getOstype() { - return ostype; - } - - public void setOstype(String ostype) { - this.ostype = ostype; - } - - public String getOsversion() { - return osversion; - } - - public void setOsversion(String osversion) { - this.osversion = osversion; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getOwner() { - return owner; - } - - public void setOwner(String owner) { - this.owner = owner; - } - - public java.util.Date getActivetime() { - return activetime; - } - - public void setActivetime(java.util.Date activetime) { - this.activetime = activetime; - } - - public String getRemark() { - return remark; - } - - public void setRemark(String remark) { - this.remark = remark; - } - - public String getAppsysname() { - return appsysname; - } - - public void setAppsysname(String appsysname) { - this.appsysname = appsysname; - } - - public String getSubdomain() { - return subdomain; - } - - public void setSubdomain(String subdomain) { - this.subdomain = subdomain; - } -} diff --git a/center/src/main/java/com/tiji/center/pojo/Imvulnnotify.java b/center/src/main/java/com/tiji/center/pojo/Imvulnnotify.java deleted file mode 100755 index c8830b5..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Imvulnnotify.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * imvulnnotify实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_imvulnnotify") -public class Imvulnnotify implements Serializable { - - @Id - private String id;//编号 - - private Boolean dingtalknotify;//是否开启通知 - private Boolean dingtalknotifyall;//是否提醒所有人 - private String secret;//秘钥 - private String dingtalkmessageurl;//消息地址 - private String dingtalkreceiver;//接收人列表 - - private Boolean wechatnotify;//是否开启通知 - private Boolean wechatnotifyall;//是否提醒所有人 - private String wechatmessageurl;//消息地址 - private String wechatreceiver;//接收人列表 - - private Boolean riskassetnotify;//新增高危资产是否实时推送到群 - - private String risk;//风险等级 - private String messagetitle;//消息标题 - private String messageprefix;//消息前缀 - private String messagesuffix;//消息后缀 - private String messagecharset;//消息编码 - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public Boolean getDingtalknotify() { - return dingtalknotify; - } - - public void setDingtalknotify(Boolean dingtalknotify) { - this.dingtalknotify = dingtalknotify; - } - - public Boolean getDingtalknotifyall() { - return dingtalknotifyall; - } - - public void setDingtalknotifyall(Boolean dingtalknotifyall) { - this.dingtalknotifyall = dingtalknotifyall; - } - - public String getSecret() { - return secret; - } - - public void setSecret(String secret) { - this.secret = secret; - } - - public String getDingtalkmessageurl() { - return dingtalkmessageurl; - } - - public void setDingtalkmessageurl(String dingtalkmessageurl) { - this.dingtalkmessageurl = dingtalkmessageurl; - } - - public String getDingtalkreceiver() { - return dingtalkreceiver; - } - - public void setDingtalkreceiver(String dingtalkreceiver) { - this.dingtalkreceiver = dingtalkreceiver; - } - - public Boolean getWechatnotify() { - return wechatnotify; - } - - public void setWechatnotify(Boolean wechatnotify) { - this.wechatnotify = wechatnotify; - } - - public Boolean getWechatnotifyall() { - return wechatnotifyall; - } - - public void setWechatnotifyall(Boolean wechatnotifyall) { - this.wechatnotifyall = wechatnotifyall; - } - - public String getWechatmessageurl() { - return wechatmessageurl; - } - - public void setWechatmessageurl(String wechatmessageurl) { - this.wechatmessageurl = wechatmessageurl; - } - - public String getWechatreceiver() { - return wechatreceiver; - } - - public void setWechatreceiver(String wechatreceiver) { - this.wechatreceiver = wechatreceiver; - } - - public String getRisk() { - return risk; - } - - public void setRisk(String risk) { - this.risk = risk; - } - - public String getMessagetitle() { - return messagetitle; - } - - public void setMessagetitle(String messagetitle) { - this.messagetitle = messagetitle; - } - - public String getMessageprefix() { - return messageprefix; - } - - public void setMessageprefix(String messageprefix) { - this.messageprefix = messageprefix; - } - - public String getMessagesuffix() { - return messagesuffix; - } - - public void setMessagesuffix(String messagesuffix) { - this.messagesuffix = messagesuffix; - } - - public String getMessagecharset() { - return messagecharset; - } - - public void setMessagecharset(String messagecharset) { - this.messagecharset = messagecharset; - } - - public Boolean getRiskassetnotify() { - return riskassetnotify; - } - - public void setRiskassetnotify(Boolean riskassetnotify) { - this.riskassetnotify = riskassetnotify; - } -} diff --git a/center/src/main/java/com/tiji/center/pojo/Ipportwhitelist.java b/center/src/main/java/com/tiji/center/pojo/Ipportwhitelist.java deleted file mode 100755 index 7f5cf04..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Ipportwhitelist.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * ipportwhitelist实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_ipportwhitelist") -public class Ipportwhitelist implements Serializable { - - @Id - private String id;//编号 - - - private String ipwhitelistid;//ip白名单编号 - private String port;//端口 - private Boolean checkwhitelist;//检测白名单 - private Boolean notifywhitelist;//提醒白名单 - - public Ipportwhitelist() { - } - - public Ipportwhitelist(String id, String ipwhitelistid, String port, Boolean checkwhitelist, Boolean notifywhitelist) { - this.id = id; - this.ipwhitelistid = ipwhitelistid; - this.port = port; - this.checkwhitelist = checkwhitelist; - this.notifywhitelist = notifywhitelist; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getIpwhitelistid() { - return ipwhitelistid; - } - - public void setIpwhitelistid(String ipwhitelistid) { - this.ipwhitelistid = ipwhitelistid; - } - - public String getPort() { - return port; - } - - public void setPort(String port) { - this.port = port; - } - - public Boolean getCheckwhitelist() { - return checkwhitelist; - } - - public void setCheckwhitelist(Boolean checkwhitelist) { - this.checkwhitelist = checkwhitelist; - } - - public Boolean getNotifywhitelist() { - return notifywhitelist; - } - - public void setNotifywhitelist(Boolean notifywhitelist) { - this.notifywhitelist = notifywhitelist; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Ipwhitelist.java b/center/src/main/java/com/tiji/center/pojo/Ipwhitelist.java deleted file mode 100755 index 1ca4d02..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Ipwhitelist.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * ipwhitelist实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_ipwhitelist") -public class Ipwhitelist implements Serializable { - - @Id - private String id;//编号 - - - private String ip;//ip - private Boolean checkwhitelist;//检测白名单 - private Boolean notifywhitelist;//提醒白名单 - - public Ipwhitelist() { - } - - public Ipwhitelist(String id, String ip, Boolean checkwhitelist, Boolean notifywhitelist) { - this.id = id; - this.ip = ip; - this.checkwhitelist = checkwhitelist; - this.notifywhitelist = notifywhitelist; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getIp() { - return ip; - } - - public void setIp(String ip) { - this.ip = ip; - } - - public Boolean getCheckwhitelist() { - return checkwhitelist; - } - - public void setCheckwhitelist(Boolean checkwhitelist) { - this.checkwhitelist = checkwhitelist; - } - - public Boolean getNotifywhitelist() { - return notifywhitelist; - } - - public void setNotifywhitelist(Boolean notifywhitelist) { - this.notifywhitelist = notifywhitelist; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Nmapconfig.java b/center/src/main/java/com/tiji/center/pojo/Nmapconfig.java deleted file mode 100755 index 7cd52d4..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Nmapconfig.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * nmapconfig实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_nmapconfig") -public class Nmapconfig implements Serializable { - - @Id - private String id;//nmap配置编号 - - - private String taskid;//任务编号 - private String threadnumber;//线程数量,在mass2Nmap模式下使用 - private String singleipscantime;//单个ip扫描次数,在mass2Nmap模式下使用 - private String additionoption;//附加选项,在mass2Nmap模式下使用 - - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTaskid() { - return taskid; - } - - public void setTaskid(String taskid) { - this.taskid = taskid; - } - - public String getThreadnumber() { - return threadnumber; - } - - public void setThreadnumber(String threadnumber) { - this.threadnumber = threadnumber; - } - - public String getSingleipscantime() { - return singleipscantime; - } - - public void setSingleipscantime(String singleipscantime) { - this.singleipscantime = singleipscantime; - } - - public String getAdditionoption() { - return additionoption; - } - - public void setAdditionoption(String additionoption) { - this.additionoption = additionoption; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Notifylog.java b/center/src/main/java/com/tiji/center/pojo/Notifylog.java deleted file mode 100755 index 3dd923f..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Notifylog.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; -import java.util.Date; - -/** - * notifylog实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_notifylog") -public class Notifylog implements Serializable { - - @Id - private String id;//编号 - - - private String type;//类型 - private String recipient;//接收人 - private String receiveuser;//接收账户 - private String content;//内容 - private Boolean success;//发送成功 - private String exception;//异常消息 - private java.util.Date sendtime;//发送时间 - - public Notifylog() { - } - - public Notifylog(String id, String type, String recipient, String receiveuser, String content, Boolean success, String exception, Date sendtime) { - this.id = id; - this.type = type; - this.recipient = recipient; - this.receiveuser = receiveuser; - this.content = content; - this.success = success; - this.exception = exception; - this.sendtime = sendtime; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getRecipient() { - return recipient; - } - - public void setRecipient(String recipient) { - this.recipient = recipient; - } - - public String getReceiveuser() { - return receiveuser; - } - - public void setReceiveuser(String receiveuser) { - this.receiveuser = receiveuser; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public Boolean getSuccess() { - return success; - } - - public void setSuccess(Boolean success) { - this.success = success; - } - - public String getException() { - return exception; - } - - public void setException(String exception) { - this.exception = exception; - } - - public java.util.Date getSendtime() { - return sendtime; - } - - public void setSendtime(java.util.Date sendtime) { - this.sendtime = sendtime; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Pluginassetservice.java b/center/src/main/java/com/tiji/center/pojo/Pluginassetservice.java deleted file mode 100755 index b178609..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Pluginassetservice.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * assetservice实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_pluginassetservice") -public class Pluginassetservice implements Serializable { - - @Id - private String id;//资产服务编号 - - - private String pluginconfigid;//插件配置编号 - private String assetservice;//资产服务 - - public Pluginassetservice() { - } - - public Pluginassetservice(String id, String pluginconfigid, String assetservice) { - this.id = id; - this.pluginconfigid = pluginconfigid; - this.assetservice = assetservice; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getPluginconfigid() { - return pluginconfigid; - } - - public void setPluginconfigid(String pluginconfigid) { - this.pluginconfigid = pluginconfigid; - } - - public String getAssetservice() { - return assetservice; - } - - public void setAssetservice(String assetservice) { - this.assetservice = assetservice; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Pluginassetversion.java b/center/src/main/java/com/tiji/center/pojo/Pluginassetversion.java deleted file mode 100755 index 938fde0..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Pluginassetversion.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * assetversion实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_pluginassetversion") -public class Pluginassetversion implements Serializable { - - @Id - private String id;//资产版本编号 - - - private String pluginconfigid;//插件配置编号 - private String assetversion;//资产版本 - - public Pluginassetversion() { - } - - public Pluginassetversion(String id, String pluginconfigid, String assetversion) { - this.id = id; - this.pluginconfigid = pluginconfigid; - this.assetversion = assetversion; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getPluginconfigid() { - return pluginconfigid; - } - - public void setPluginconfigid(String pluginconfigid) { - this.pluginconfigid = pluginconfigid; - } - - public String getAssetversion() { - return assetversion; - } - - public void setAssetversion(String assetversion) { - this.assetversion = assetversion; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Pluginconfig.java b/center/src/main/java/com/tiji/center/pojo/Pluginconfig.java deleted file mode 100755 index 2e62a0a..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Pluginconfig.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * pluginconfig实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_pluginconfig") -public class Pluginconfig implements Serializable { - - @Id - private String id;//插件配置编号 - - - private String name;//插件名称 - private String args;//插件参数 - private String risk;//插件风险级别 - private String type;//插件类型:nse或者自定义 - private String validatetype;//http辅助验证或dns辅助验证 - private String timeout;//插件超时 - private String plugincode;//插件代码 - - public Pluginconfig() { - } - - public Pluginconfig(String id, String name, String args, String risk, String type, String validatetype, String timeout, String plugincode) { - this.id = id; - this.name = name; - this.args = args; - this.risk = risk; - this.type = type; - this.validatetype = validatetype; - this.timeout = timeout; - this.plugincode = plugincode; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getArgs() { - return args; - } - - public void setArgs(String args) { - this.args = args; - } - - public String getRisk() { - return risk; - } - - public void setRisk(String risk) { - this.risk = risk; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getTimeout() { - return timeout; - } - - public void setTimeout(String timeout) { - this.timeout = timeout; - } - - public String getPlugincode() { - return plugincode; - } - - public void setPlugincode(String plugincode) { - this.plugincode = plugincode; - } - - public String getValidatetype() { - return validatetype; - } - - public void setValidatetype(String validatetype) { - this.validatetype = validatetype; - } -} diff --git a/center/src/main/java/com/tiji/center/pojo/Project.java b/center/src/main/java/com/tiji/center/pojo/Project.java deleted file mode 100755 index 590e527..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Project.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * project实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_project") -public class Project implements Serializable { - - @Id - private String id;//项目编号 - - - private String name;//项目名称 - private String description;//项目描述 - - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Projectinfo.java b/center/src/main/java/com/tiji/center/pojo/Projectinfo.java deleted file mode 100755 index 8c75504..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Projectinfo.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Transient; -import java.io.Serializable; -import java.util.Date; - -/** - * projectinfo实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_projectinfo") -public class Projectinfo implements Serializable { - - @Id - private String id;//编号 - - - @Transient - private String contact; - @Transient - private String departmentidname; - - private String departmentid;//部门编号 - private String projectname;//项目名称 - private Boolean checkwhitelist;//检测白名单 - private Boolean notifywhitelist;//提醒白名单 - private java.util.Date inserttime;//插入时间 - private Boolean overrideipwhitelist;//覆盖ip白名单,默认为false,如果为true,则会对项目下所有的ip进行白名单 - - public Projectinfo() { - } - - public Projectinfo(String id, String departmentid, String projectname, Boolean checkwhitelist, Boolean notifywhitelist, Date inserttime, Boolean overrideipwhitelist) { - this.id = id; - this.departmentid = departmentid; - this.projectname = projectname; - this.checkwhitelist = checkwhitelist; - this.notifywhitelist = notifywhitelist; - this.inserttime = inserttime; - this.overrideipwhitelist = overrideipwhitelist; - } - - - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getContact() { - return contact; - } - - public void setContact(String contact) { - this.contact = contact; - } - - public String getDepartmentid() { - return departmentid; - } - - public void setDepartmentid(String departmentid) { - this.departmentid = departmentid; - } - - public String getProjectname() { - return projectname; - } - - public void setProjectname(String projectname) { - this.projectname = projectname; - } - - public Boolean getCheckwhitelist() { - return checkwhitelist; - } - - public void setCheckwhitelist(Boolean checkwhitelist) { - this.checkwhitelist = checkwhitelist; - } - - public Boolean getNotifywhitelist() { - return notifywhitelist; - } - - public void setNotifywhitelist(Boolean notifywhitelist) { - this.notifywhitelist = notifywhitelist; - } - - public java.util.Date getInserttime() { - return inserttime; - } - - public void setInserttime(java.util.Date inserttime) { - this.inserttime = inserttime; - } - - public Boolean getOverrideipwhitelist() { - return overrideipwhitelist; - } - - public void setOverrideipwhitelist(Boolean overrideipwhitelist) { - this.overrideipwhitelist = overrideipwhitelist; - } - - public String getDepartmentidname() { - return departmentidname; - } - - public void setDepartmentidname(String departmentidname) { - this.departmentidname = departmentidname; - } -} diff --git a/center/src/main/java/com/tiji/center/pojo/Projectportwhitelist.java b/center/src/main/java/com/tiji/center/pojo/Projectportwhitelist.java deleted file mode 100755 index ddd0ff4..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Projectportwhitelist.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * projectportwhitelist实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_projectportwhitelist") -public class Projectportwhitelist implements Serializable { - - @Id - private String id;//编号 - - - private String projectinfoid;//项目信息编号 - private String port;//端口 - private Boolean checkwhitelist;//检测白名单 - private Boolean notifywhitelist;//提醒白名单 - - public Projectportwhitelist() { - } - - public Projectportwhitelist(String id, String projectinfoid, String port, Boolean checkwhitelist, Boolean notifywhitelist) { - this.id = id; - this.projectinfoid = projectinfoid; - this.port = port; - this.checkwhitelist = checkwhitelist; - this.notifywhitelist = notifywhitelist; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getProjectinfoid() { - return projectinfoid; - } - - public void setProjectinfoid(String projectinfoid) { - this.projectinfoid = projectinfoid; - } - - public String getPort() { - return port; - } - - public void setPort(String port) { - this.port = port; - } - - public Boolean getCheckwhitelist() { - return checkwhitelist; - } - - public void setCheckwhitelist(Boolean checkwhitelist) { - this.checkwhitelist = checkwhitelist; - } - - public Boolean getNotifywhitelist() { - return notifywhitelist; - } - - public void setNotifywhitelist(Boolean notifywhitelist) { - this.notifywhitelist = notifywhitelist; - } - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Projectvulnnotify.java b/center/src/main/java/com/tiji/center/pojo/Projectvulnnotify.java deleted file mode 100755 index 103af9f..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Projectvulnnotify.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * projectvulnnotify实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_projectvulnnotify") -public class Projectvulnnotify implements Serializable { - - @Id - private String id;//编号 - - - private String risk;//风险等级 - - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getRisk() { - return risk; - } - - public void setRisk(String risk) { - this.risk = risk; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Riskport.java b/center/src/main/java/com/tiji/center/pojo/Riskport.java deleted file mode 100755 index d98e3ff..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Riskport.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * riskport实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_riskport") -public class Riskport implements Serializable { - - @Id - private String id;//编号 - - - private String port;//高危端口 - - public Riskport() { - - } - - public Riskport(String id, String port) { - this.id = id; - this.port = port; - } - - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getPort() { - return port; - } - - public void setPort(String port) { - this.port = port; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Riskservice.java b/center/src/main/java/com/tiji/center/pojo/Riskservice.java deleted file mode 100755 index 41ed0b2..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Riskservice.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * riskservice实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_riskservice") -public class Riskservice implements Serializable { - - @Id - private String id;//编号 - - - private String service;//高危服务 - - public Riskservice() { - } - - public Riskservice(String id, String service) { - this.id = id; - this.service = service; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getService() { - return service; - } - - public void setService(String service) { - this.service = service; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Riskversion.java b/center/src/main/java/com/tiji/center/pojo/Riskversion.java deleted file mode 100755 index 0ad35db..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Riskversion.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * riskversion实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_riskversion") -public class Riskversion implements Serializable { - - @Id - private String id;//编号 - - - private String version;//高危版本 - - public Riskversion() { - } - - public Riskversion(String id, String version) { - this.id = id; - this.version = version; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Sendmailconfig.java b/center/src/main/java/com/tiji/center/pojo/Sendmailconfig.java deleted file mode 100755 index bfbb35f..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Sendmailconfig.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * sendmailconfig实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_sendmailconfig") -public class Sendmailconfig implements Serializable { - - @Id - private String id;//编号 - - - private String sendhost;//邮箱host - private String sendpassword;//密码 - private String sendfrom;//发件人 - private String sendto;//提醒邮箱,强制提醒,不管是否在提醒白名单里,提醒包括所有资产和在收件人列表接收漏洞风险中的漏洞 - private String sendtorisk;//收件人列表接收漏洞风险 - private String vulnsubject;//漏洞邮件主题 - private String assetsubject;//资产邮件主题 - private String vulncontent;//漏洞邮件内容 - private String assetcontent;//资产邮件内容 - private String excelauthor;//excel作者 - - public Sendmailconfig() { - } - - public Sendmailconfig(String id, String sendhost, String sendpassword, String sendfrom, String sendto, String sendtorisk, String vulnsubject, String assetsubject, String vulncontent, String assetcontent, String excelauthor) { - this.id = id; - this.sendhost = sendhost; - this.sendpassword = sendpassword; - this.sendfrom = sendfrom; - this.sendto = sendto; - this.sendtorisk = sendtorisk; - this.vulnsubject = vulnsubject; - this.assetsubject = assetsubject; - this.vulncontent = vulncontent; - this.assetcontent = assetcontent; - this.excelauthor = excelauthor; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getSendhost() { - return sendhost; - } - - public void setSendhost(String sendhost) { - this.sendhost = sendhost; - } - - public String getSendpassword() { - return sendpassword; - } - - public void setSendpassword(String sendpassword) { - this.sendpassword = sendpassword; - } - - public String getSendfrom() { - return sendfrom; - } - - public void setSendfrom(String sendfrom) { - this.sendfrom = sendfrom; - } - - public String getSendto() { - return sendto; - } - - public void setSendto(String sendto) { - this.sendto = sendto; - } - - public String getSendtorisk() { - return sendtorisk; - } - - public void setSendtorisk(String sendtorisk) { - this.sendtorisk = sendtorisk; - } - - public String getVulnsubject() { - return vulnsubject; - } - - public void setVulnsubject(String vulnsubject) { - this.vulnsubject = vulnsubject; - } - - public String getAssetsubject() { - return assetsubject; - } - - public void setAssetsubject(String assetsubject) { - this.assetsubject = assetsubject; - } - - public String getVulncontent() { - return vulncontent; - } - - public void setVulncontent(String vulncontent) { - this.vulncontent = vulncontent; - } - - public String getAssetcontent() { - return assetcontent; - } - - public void setAssetcontent(String assetcontent) { - this.assetcontent = assetcontent; - } - - public String getExcelauthor() { - return excelauthor; - } - - public void setExcelauthor(String excelauthor) { - this.excelauthor = excelauthor; - } - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Solution.java b/center/src/main/java/com/tiji/center/pojo/Solution.java deleted file mode 100755 index 707ce65..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Solution.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * solution实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_solution") -public class Solution implements Serializable { - - @Id - private String id;//修复方案编号 - - - private String vulnid;//漏洞编号 - private String solution;//修复方案 - private String codedemo;//修复代码示例 - private String configdemo;//修复配置示例 - - public Solution() { - } - - public Solution(String id, String vulnid, String solution, String codedemo, String configdemo) { - this.id = id; - this.vulnid = vulnid; - this.solution = solution; - this.codedemo = codedemo; - this.configdemo = configdemo; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getVulnid() { - return vulnid; - } - - public void setVulnid(String vulnid) { - this.vulnid = vulnid; - } - - public String getSolution() { - return solution; - } - - public void setSolution(String solution) { - this.solution = solution; - } - - public String getCodedemo() { - return codedemo; - } - - public void setCodedemo(String codedemo) { - this.codedemo = codedemo; - } - - public String getConfigdemo() { - return configdemo; - } - - public void setConfigdemo(String configdemo) { - this.configdemo = configdemo; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Statistics.java b/center/src/main/java/com/tiji/center/pojo/Statistics.java deleted file mode 100755 index 5506fd3..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Statistics.java +++ /dev/null @@ -1,296 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * statistics实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_statistics") -public class Statistics implements Serializable { - - @Id - private String id;//编号 - - - private String ipcount;//ip数 - private String ipcountonline;//未下线ip数 - private String portcount;//端口数 - private String portcountonline;//未下线端口数 - private String checkresultcount;//检测结果数 - private String checkresultcountonline;//未修复检测结果数 - private String infocount;//信息检测结果数 - private String lowcount;//低危检测结果数 - private String mediumcount;//中危检测结果数 - private String highcount;//高危检测结果数 - private String criticalcount;//严重检测结果数 - private String fatalcount;//致命检测结果数 - private String infocountonline;//未修复信息检测结果数 - private String lowcountonline;//未修复低危检测结果数 - private String mediumcountonline;//未修复中危检测结果数 - private String highcountonline;//未修复高危检测结果数 - private String criticalcountonline;//未修复严重检测结果数 - private String fatalcountonline;//未修复致命检测结果数 - private String riskportcount;//高危端口数 - private String riskportcountonline;//未下线高危端口数 - private String riskservicecount;//高危服务数 - private String riskservicecountonline;//未下线高危服务数 - private String riskversioncount;//高危版本数 - private String riskversioncountonline;//未下线高危版本数 - private java.util.Date updatetime;//更新时间 - - - public Statistics() { - } - - public Statistics(String id, String ipcount, String ipcountonline, String portcount, String portcountonline, - String checkresultcount, String checkresultcountonline, String infocount, String lowcount, - String mediumcount, String highcount, String criticalcount, String fatalcount, - String infocountonline, String lowcountonline, String mediumcountonline, String highcountonline, - String criticalcountonline, String fatalcountonline, - String riskportcount, String riskportcountonline, String riskservicecount, String riskservicecountonline, String riskversioncount, String riskversioncountonline, - java.util.Date updatetime) { - this.id = id; - this.ipcount = ipcount; - this.ipcountonline = ipcountonline; - this.portcount = portcount; - this.portcountonline = portcountonline; - this.checkresultcount = checkresultcount; - this.checkresultcountonline = checkresultcountonline; - this.infocount = infocount; - this.lowcount = lowcount; - this.mediumcount = mediumcount; - this.highcount = highcount; - this.criticalcount = criticalcount; - this.fatalcount = fatalcount; - this.infocountonline = infocountonline; - this.lowcountonline = lowcountonline; - this.mediumcountonline = mediumcountonline; - this.highcountonline = highcountonline; - this.criticalcountonline = criticalcountonline; - this.fatalcountonline = fatalcountonline; - this.riskportcount = riskportcount; - this.riskportcountonline = riskportcountonline; - this.riskservicecount = riskservicecount; - this.riskservicecountonline = riskservicecountonline; - this.riskversioncount = riskversioncount; - this.riskversioncountonline = riskversioncountonline; - this.updatetime = updatetime; - } - - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getIpcount() { - return ipcount; - } - - public void setIpcount(String ipcount) { - this.ipcount = ipcount; - } - - public String getIpcountonline() { - return ipcountonline; - } - - public void setIpcountonline(String ipcountonline) { - this.ipcountonline = ipcountonline; - } - - public String getPortcount() { - return portcount; - } - - public void setPortcount(String portcount) { - this.portcount = portcount; - } - - public String getPortcountonline() { - return portcountonline; - } - - public void setPortcountonline(String portcountonline) { - this.portcountonline = portcountonline; - } - - public String getCheckresultcount() { - return checkresultcount; - } - - public void setCheckresultcount(String checkresultcount) { - this.checkresultcount = checkresultcount; - } - - public String getCheckresultcountonline() { - return checkresultcountonline; - } - - public void setCheckresultcountonline(String checkresultcountonline) { - this.checkresultcountonline = checkresultcountonline; - } - - public String getInfocount() { - return infocount; - } - - public void setInfocount(String infocount) { - this.infocount = infocount; - } - - public String getLowcount() { - return lowcount; - } - - public void setLowcount(String lowcount) { - this.lowcount = lowcount; - } - - public String getMediumcount() { - return mediumcount; - } - - public void setMediumcount(String mediumcount) { - this.mediumcount = mediumcount; - } - - public String getHighcount() { - return highcount; - } - - public void setHighcount(String highcount) { - this.highcount = highcount; - } - - public String getCriticalcount() { - return criticalcount; - } - - public void setCriticalcount(String criticalcount) { - this.criticalcount = criticalcount; - } - - public String getFatalcount() { - return fatalcount; - } - - public void setFatalcount(String fatalcount) { - this.fatalcount = fatalcount; - } - - public String getInfocountonline() { - return infocountonline; - } - - public void setInfocountonline(String infocountonline) { - this.infocountonline = infocountonline; - } - - public String getLowcountonline() { - return lowcountonline; - } - - public void setLowcountonline(String lowcountonline) { - this.lowcountonline = lowcountonline; - } - - public String getMediumcountonline() { - return mediumcountonline; - } - - public void setMediumcountonline(String mediumcountonline) { - this.mediumcountonline = mediumcountonline; - } - - public String getHighcountonline() { - return highcountonline; - } - - public void setHighcountonline(String highcountonline) { - this.highcountonline = highcountonline; - } - - public String getCriticalcountonline() { - return criticalcountonline; - } - - public void setCriticalcountonline(String criticalcountonline) { - this.criticalcountonline = criticalcountonline; - } - - public String getFatalcountonline() { - return fatalcountonline; - } - - public void setFatalcountonline(String fatalcountonline) { - this.fatalcountonline = fatalcountonline; - } - - public String getRiskportcount() { - return riskportcount; - } - - public void setRiskportcount(String riskportcount) { - this.riskportcount = riskportcount; - } - - public String getRiskportcountonline() { - return riskportcountonline; - } - - public void setRiskportcountonline(String riskportcountonline) { - this.riskportcountonline = riskportcountonline; - } - - public String getRiskservicecount() { - return riskservicecount; - } - - public void setRiskservicecount(String riskservicecount) { - this.riskservicecount = riskservicecount; - } - - public String getRiskservicecountonline() { - return riskservicecountonline; - } - - public void setRiskservicecountonline(String riskservicecountonline) { - this.riskservicecountonline = riskservicecountonline; - } - - public String getRiskversioncount() { - return riskversioncount; - } - - public void setRiskversioncount(String riskversioncount) { - this.riskversioncount = riskversioncount; - } - - public String getRiskversioncountonline() { - return riskversioncountonline; - } - - public void setRiskversioncountonline(String riskversioncountonline) { - this.riskversioncountonline = riskversioncountonline; - } - - public java.util.Date getUpdatetime() { - return updatetime; - } - - public void setUpdatetime(java.util.Date updatetime) { - this.updatetime = updatetime; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Task.java b/center/src/main/java/com/tiji/center/pojo/Task.java deleted file mode 100755 index cd0906f..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Task.java +++ /dev/null @@ -1,280 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Transient; -import java.io.Serializable; -import java.util.Date; - -/** - * task实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_task") -public class Task implements Serializable { - - @Id - private String id;//任务编号 - - @Transient - private String statistic; - @Transient - private String percentage; - @Transient - private String jobstate; - - private String taskparentid;//任务父编号 - private String projectid;//项目编号 - private String name;//任务名称 - private String description;//任务描述 - private String cronexpression;//cron表达式 - private Boolean crontask;//cron任务 - private java.util.Date starttime;//任务开始时间 - private java.util.Date endtime;//任务结束时间 - private String worktype;//任务类型 - private String checktype;//检测类型 - private String threadnumber;//线程数量 - private String singleipscantime;//单个ip扫描次数 - private String additionoption;//任务附加选项 - private String rate;//扫描速率 - private String targetip;//目标ip - private String targetport;//目标端口,为空为所有端口,regular为nmap默认端口,端口格式:80,443 - private String excludeip;//排除ip - private String ipslicesize;//分组大小 - private String portslicesize;//端口分组大小,nmap全端口模式时,如果该字段有值,则进行端口分组,分组大小范围:1000-10000 - private Boolean dbipisexcludeip;//db中ip作为排除ip - private Boolean merge2asset;//扫描结果合并到资产 - - public Task() { - } - - public Task(String id, String taskparentid, String projectid, String name, String description, String cronexpression, Boolean crontask, Date starttime, Date endtime, String worktype, String checktype, String threadnumber, String singleipscantime, String additionoption, String rate, String targetip, String targetport, String excludeip, String ipslicesize, String portslicesize, Boolean dbipisexcludeip, Boolean merge2asset) { - this.id = id; - this.taskparentid = taskparentid; - this.projectid = projectid; - this.name = name; - this.description = description; - this.cronexpression = cronexpression; - this.crontask = crontask; - this.starttime = starttime; - this.endtime = endtime; - this.worktype = worktype; - this.checktype = checktype; - this.threadnumber = threadnumber; - this.singleipscantime = singleipscantime; - this.additionoption = additionoption; - this.rate = rate; - this.targetip = targetip; - this.targetport = targetport; - this.excludeip = excludeip; - this.ipslicesize = ipslicesize; - this.portslicesize = portslicesize; - this.dbipisexcludeip = dbipisexcludeip; - this.merge2asset = merge2asset; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getStatistic() { - return statistic; - } - - public void setStatistic(String statistic) { - this.statistic = statistic; - } - - public String getJobstate() { - return jobstate; - } - - public void setJobstate(String jobstate) { - this.jobstate = jobstate; - } - - public String getPercentage() { - return percentage; - } - - public void setPercentage(String percentage) { - this.percentage = percentage; - } - - public String getTaskparentid() { - return taskparentid; - } - - public void setTaskparentid(String taskparentid) { - this.taskparentid = taskparentid; - } - - public String getProjectid() { - return projectid; - } - - public void setProjectid(String projectid) { - this.projectid = projectid; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getCronexpression() { - return cronexpression; - } - - public void setCronexpression(String cronexpression) { - this.cronexpression = cronexpression; - } - - public Boolean getCrontask() { - return crontask; - } - - public void setCrontask(Boolean crontask) { - this.crontask = crontask; - } - - public java.util.Date getStarttime() { - return starttime; - } - - public void setStarttime(java.util.Date starttime) { - this.starttime = starttime; - } - - public java.util.Date getEndtime() { - return endtime; - } - - public void setEndtime(java.util.Date endtime) { - this.endtime = endtime; - } - - public String getWorktype() { - return worktype; - } - - public void setWorktype(String worktype) { - this.worktype = worktype; - } - - public String getChecktype() { - return checktype; - } - - public void setChecktype(String checktype) { - this.checktype = checktype; - } - - public String getThreadnumber() { - return threadnumber; - } - - public void setThreadnumber(String threadnumber) { - this.threadnumber = threadnumber; - } - - public String getSingleipscantime() { - return singleipscantime; - } - - public void setSingleipscantime(String singleipscantime) { - this.singleipscantime = singleipscantime; - } - - public String getAdditionoption() { - return additionoption; - } - - public void setAdditionoption(String additionoption) { - this.additionoption = additionoption; - } - - public String getRate() { - return rate; - } - - public void setRate(String rate) { - this.rate = rate; - } - - public String getTargetip() { - return targetip; - } - - public void setTargetip(String targetip) { - this.targetip = targetip; - } - - public String getTargetport() { - return targetport; - } - - public void setTargetport(String targetport) { - this.targetport = targetport; - } - - public String getExcludeip() { - return excludeip; - } - - public void setExcludeip(String excludeip) { - this.excludeip = excludeip; - } - - public String getIpslicesize() { - return ipslicesize; - } - - public void setIpslicesize(String ipslicesize) { - this.ipslicesize = ipslicesize; - } - - public String getPortslicesize() { - return portslicesize; - } - - public void setPortslicesize(String portslicesize) { - this.portslicesize = portslicesize; - } - - public Boolean getDbipisexcludeip() { - return dbipisexcludeip; - } - - public void setDbipisexcludeip(Boolean dbipisexcludeip) { - this.dbipisexcludeip = dbipisexcludeip; - } - - public Boolean getMerge2asset() { - return merge2asset; - } - - public void setMerge2asset(Boolean merge2asset) { - this.merge2asset = merge2asset; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Taskip.java b/center/src/main/java/com/tiji/center/pojo/Taskip.java deleted file mode 100755 index a722777..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Taskip.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * taskip实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_taskip") -public class Taskip implements Serializable { - - @Id - private String id;//资产ip编号 - - - private String taskid;//任务编号 - private String ipaddressv4;//ip地址 - private String ipaddressv6;//ipaddressv6 - private Boolean checkwhitelist;//安全检测白名单 - - public Taskip() { - } - - public Taskip(String id, String taskid, String ipaddressv4, String ipaddressv6, Boolean checkwhitelist) { - this.id = id; - this.taskid = taskid; - this.ipaddressv4 = ipaddressv4; - this.ipaddressv6 = ipaddressv6; - this.checkwhitelist = checkwhitelist; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTaskid() { - return taskid; - } - - public void setTaskid(String taskid) { - this.taskid = taskid; - } - - public String getIpaddressv4() { - return ipaddressv4; - } - - public void setIpaddressv4(String ipaddressv4) { - this.ipaddressv4 = ipaddressv4; - } - - public String getIpaddressv6() { - return ipaddressv6; - } - - public void setIpaddressv6(String ipaddressv6) { - this.ipaddressv6 = ipaddressv6; - } - - public Boolean getCheckwhitelist() { - return checkwhitelist; - } - - public void setCheckwhitelist(Boolean checkwhitelist) { - this.checkwhitelist = checkwhitelist; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Taskpluginconfig.java b/center/src/main/java/com/tiji/center/pojo/Taskpluginconfig.java deleted file mode 100755 index a227fea..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Taskpluginconfig.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * taskpluginconfig实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_taskpluginconfig") -public class Taskpluginconfig implements Serializable { - - @Id - private String id;//编号 - - - private String taskid;//任务编号 - private String pluginconfigid;//插件编号 - - public Taskpluginconfig() { - } - - public Taskpluginconfig(String id, String taskid, String pluginconfigid) { - this.id = id; - this.taskid = taskid; - this.pluginconfigid = pluginconfigid; - } - - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTaskid() { - return taskid; - } - - public void setTaskid(String taskid) { - this.taskid = taskid; - } - - public String getPluginconfigid() { - return pluginconfigid; - } - - public void setPluginconfigid(String pluginconfigid) { - this.pluginconfigid = pluginconfigid; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Taskport.java b/center/src/main/java/com/tiji/center/pojo/Taskport.java deleted file mode 100755 index 2cda135..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Taskport.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Transient; -import java.io.Serializable; - -/** - * taskport实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_taskport") -public class Taskport implements Serializable { - - @Id - private String id;//端口编号 - - - @Transient - private String taskname; - - private String taskipid;//资产ip编号 - private String port;//端口 - private String protocol;//端口协议 - private String state;//端口开放状态 - private String service;//端口服务 - private String version;//服务版本 - private Boolean checkwhitelist;//安全检测白名单 - - public Taskport() { - } - - public Taskport(String id, String taskipid, String port, String protocol, String state, String service, String version, Boolean checkwhitelist) { - this.id = id; - this.taskipid = taskipid; - this.port = port; - this.protocol = protocol; - this.state = state; - this.service = service; - this.version = version; - this.checkwhitelist = checkwhitelist; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTaskname() { - return taskname; - } - - public void setTaskname(String taskname) { - this.taskname = taskname; - } - - public String getTaskipid() { - return taskipid; - } - - public void setTaskipid(String taskipid) { - this.taskipid = taskipid; - } - - public String getPort() { - return port; - } - - public void setPort(String port) { - this.port = port; - } - - public String getProtocol() { - return protocol; - } - - public void setProtocol(String protocol) { - this.protocol = protocol; - } - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public String getService() { - return service; - } - - public void setService(String service) { - this.service = service; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public Boolean getCheckwhitelist() { - return checkwhitelist; - } - - public void setCheckwhitelist(Boolean checkwhitelist) { - this.checkwhitelist = checkwhitelist; - } -} diff --git a/center/src/main/java/com/tiji/center/pojo/Titlewhitelist.java b/center/src/main/java/com/tiji/center/pojo/Titlewhitelist.java deleted file mode 100755 index 958fb6a..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Titlewhitelist.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * titlewhitelist实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_titlewhitelist") -public class Titlewhitelist implements Serializable { - - @Id - private String id;//参数编号 - - - private String title;//标题 - - public Titlewhitelist() { - } - - public Titlewhitelist(String id, String title) { - this.id = id; - this.title = title; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Url.java b/center/src/main/java/com/tiji/center/pojo/Url.java deleted file mode 100755 index 5043c79..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Url.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * url实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_url") -public class Url implements Serializable { - - @Id - private String id;//url编号 - - - private String webinfoid;//web信息编号 - private String name;//名称 - private String url;//url - - public Url() { - } - - public Url(String id, String webinfoid, String name, String url) { - this.id = id; - this.webinfoid = webinfoid; - this.name = name; - this.url = url; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getWebinfoid() { - return webinfoid; - } - - public void setWebinfoid(String webinfoid) { - this.webinfoid = webinfoid; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/User.java b/center/src/main/java/com/tiji/center/pojo/User.java deleted file mode 100755 index 28fc796..0000000 --- a/center/src/main/java/com/tiji/center/pojo/User.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * user实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_user") -public class User implements Serializable { - - @Id - private String id;//用户编号 - - - private String username;//用户名 - private String password;//密码 - private Boolean admin;//是否管理员 - private Boolean active;//是否有效 - private String avatar;//头像地址 - private java.util.Date lastdate;//最后登录时间 - - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public Boolean getAdmin() { - return admin; - } - - public void setAdmin(Boolean admin) { - this.admin = admin; - } - - public Boolean getActive() { - return active; - } - - public void setActive(Boolean active) { - this.active = active; - } - - public String getAvatar() { - return avatar; - } - - public void setAvatar(String avatar) { - this.avatar = avatar; - } - - public java.util.Date getLastdate() { - return lastdate; - } - - public void setLastdate(java.util.Date lastdate) { - this.lastdate = lastdate; - } - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Useragent.java b/center/src/main/java/com/tiji/center/pojo/Useragent.java deleted file mode 100755 index e74f64d..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Useragent.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * useragent实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_useragent") -public class Useragent implements Serializable { - - @Id - private String id;//编号 - - - private String useragent;//useragent - - public Useragent() { - } - - public Useragent(String id, String useragent) { - this.id = id; - this.useragent = useragent; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getUseragent() { - return useragent; - } - - public void setUseragent(String useragent) { - this.useragent = useragent; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Vuln.java b/center/src/main/java/com/tiji/center/pojo/Vuln.java deleted file mode 100755 index bf5cbd0..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Vuln.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * vuln实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_vuln") -public class Vuln implements Serializable { - - @Id - private String id;//漏洞编号 - - - private String categorysecondid;//漏洞二级分类编号 - private String name;//漏洞名称 - private String description;//漏洞描述 - private String risk;//漏洞风险级别 - private String refer;//参考 - private String impactscope;//impactscope - - public Vuln() { - } - - public Vuln(String id, String categorysecondid, String name, String description, String risk, String refer, String impactscope) { - this.id = id; - this.categorysecondid = categorysecondid; - this.name = name; - this.description = description; - this.risk = risk; - this.refer = refer; - this.impactscope = impactscope; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getCategorysecondid() { - return categorysecondid; - } - - public void setCategorysecondid(String categorysecondid) { - this.categorysecondid = categorysecondid; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getRisk() { - return risk; - } - - public void setRisk(String risk) { - this.risk = risk; - } - - public String getRefer() { - return refer; - } - - public void setRefer(String refer) { - this.refer = refer; - } - - public String getImpactscope() { - return impactscope; - } - - public void setImpactscope(String impactscope) { - this.impactscope = impactscope; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Vulnkeyword.java b/center/src/main/java/com/tiji/center/pojo/Vulnkeyword.java deleted file mode 100755 index 59c9258..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Vulnkeyword.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * vulnkeyword实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_vulnkeyword") -public class Vulnkeyword implements Serializable { - - @Id - private String id;//漏洞关键字编号 - - - private String pluginconfigid;//插件配置编号 - private String keyword;//漏洞关键字 - - public Vulnkeyword() { - } - - public Vulnkeyword(String id, String pluginconfigid, String keyword) { - this.id = id; - this.pluginconfigid = pluginconfigid; - this.keyword = keyword; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getPluginconfigid() { - return pluginconfigid; - } - - public void setPluginconfigid(String pluginconfigid) { - this.pluginconfigid = pluginconfigid; - } - - public String getKeyword() { - return keyword; - } - - public void setKeyword(String keyword) { - this.keyword = keyword; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Vulnpluginconfig.java b/center/src/main/java/com/tiji/center/pojo/Vulnpluginconfig.java deleted file mode 100755 index 0c82244..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Vulnpluginconfig.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * vulnpluginconfig实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_vulnpluginconfig") -public class Vulnpluginconfig implements Serializable { - - @Id - private String id;//编号 - - - private String vulnid;//漏洞编号 - private String pluginconfigid;//插件配置编号 - - public Vulnpluginconfig() { - } - - public Vulnpluginconfig(String id, String vulnid, String pluginconfigid) { - this.id = id; - this.vulnid = vulnid; - this.pluginconfigid = pluginconfigid; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getVulnid() { - return vulnid; - } - - public void setVulnid(String vulnid) { - this.vulnid = vulnid; - } - - public String getPluginconfigid() { - return pluginconfigid; - } - - public void setPluginconfigid(String pluginconfigid) { - this.pluginconfigid = pluginconfigid; - } - - -} diff --git a/center/src/main/java/com/tiji/center/pojo/Webinfo.java b/center/src/main/java/com/tiji/center/pojo/Webinfo.java deleted file mode 100755 index f4c558d..0000000 --- a/center/src/main/java/com/tiji/center/pojo/Webinfo.java +++ /dev/null @@ -1,212 +0,0 @@ -package com.tiji.center.pojo; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Transient; -import java.io.Serializable; -import java.util.Date; - -/** - * webinfo实体类 - * - * @author 贰拾壹 - */ -@Entity -@Table(name = "tb_webinfo") -public class Webinfo implements Serializable { - - @Id - private String id;//web信息编号 - - - @Transient - private String assetip; - @Transient - private String url; - - @Transient - private String assetport;//端口 - - @Transient - private String header; - @Transient - private String response; - - - private String portid;//端口编号 - private String titlewhitelistid;//标题白名单编号 - private String title;//页面标题 - private String bodychildrenstextcontent;//body子节点文本内容 - private String server;//响应头中的服务 - private String xpoweredby;//xpoweredby - private String setcookie;//设置cookie - private String wwwauthenticate;//认证方式 - private String appname;//appname - private String appversion;//应用版本 - private String devlanguage;//devlanguage - private java.util.Date crawltime;//页面抓取时间 - - public Webinfo() { - } - - public Webinfo(String id, String portid, String titlewhitelistid, String title, String bodychildrenstextcontent, String server, String xpoweredby, String setcookie, String wwwauthenticate, String appname, String appversion, String devlanguage, Date crawltime) { - this.id = id; - this.portid = portid; - this.titlewhitelistid = titlewhitelistid; - this.title = title; - this.bodychildrenstextcontent = bodychildrenstextcontent; - this.server = server; - this.xpoweredby = xpoweredby; - this.setcookie = setcookie; - this.wwwauthenticate = wwwauthenticate; - this.appname = appname; - this.appversion = appversion; - this.devlanguage = devlanguage; - this.crawltime = crawltime; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getAssetip() { - return assetip; - } - - public void setAssetip(String assetip) { - this.assetip = assetip; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getAssetport() { - return assetport; - } - - public void setAssetport(String assetport) { - this.assetport = assetport; - } - - public String getPortid() { - return portid; - } - - public void setPortid(String portid) { - this.portid = portid; - } - - public String getTitlewhitelistid() { - return titlewhitelistid; - } - - public void setTitlewhitelistid(String titlewhitelistid) { - this.titlewhitelistid = titlewhitelistid; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getBodychildrenstextcontent() { - return bodychildrenstextcontent; - } - - public void setBodychildrenstextcontent(String bodychildrenstextcontent) { - this.bodychildrenstextcontent = bodychildrenstextcontent; - } - - public String getServer() { - return server; - } - - public void setServer(String server) { - this.server = server; - } - - public String getXpoweredby() { - return xpoweredby; - } - - public void setXpoweredby(String xpoweredby) { - this.xpoweredby = xpoweredby; - } - - public String getSetcookie() { - return setcookie; - } - - public void setSetcookie(String setcookie) { - this.setcookie = setcookie; - } - - public String getWwwauthenticate() { - return wwwauthenticate; - } - - public void setWwwauthenticate(String wwwauthenticate) { - this.wwwauthenticate = wwwauthenticate; - } - - public String getAppname() { - return appname; - } - - public void setAppname(String appname) { - this.appname = appname; - } - - public String getAppversion() { - return appversion; - } - - public void setAppversion(String appversion) { - this.appversion = appversion; - } - - public String getDevlanguage() { - return devlanguage; - } - - public void setDevlanguage(String devlanguage) { - this.devlanguage = devlanguage; - } - - public java.util.Date getCrawltime() { - return crawltime; - } - - public void setCrawltime(java.util.Date crawltime) { - this.crawltime = crawltime; - } - - public String getHeader() { - return header; - } - - public void setHeader(String header) { - this.header = header; - } - - public String getResponse() { - return response; - } - - public void setResponse(String response) { - this.response = response; - } -} diff --git a/center/src/main/java/com/tiji/center/schedule/AgentHeartbeatMonitorScheduler.java b/center/src/main/java/com/tiji/center/schedule/AgentHeartbeatMonitorScheduler.java deleted file mode 100755 index 84c2513..0000000 --- a/center/src/main/java/com/tiji/center/schedule/AgentHeartbeatMonitorScheduler.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.tiji.center.schedule; - -import com.tiji.center.pojo.Agent; -import com.tiji.center.service.AgentService; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.messaging.Message; -import util.ExcpUtil; -import util.IdWorker; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * @author 贰拾壹 - * @create 2019-09-30 10:32 - */ -public class AgentHeartbeatMonitorScheduler implements Job { - private final static Logger logger = LoggerFactory.getLogger(AgentHeartbeatMonitorScheduler.class); - @Autowired - private RabbitMessagingTemplate rabbitMessagingTemplate; - @Autowired - private AgentService agentService; - @Autowired - private IdWorker idWorker; - - @Override - public void execute(JobExecutionContext jobExecutionContext) { - try { - List agentList1 = agentService.findAll(); - for (Agent agent : agentList1) { - int timeouts = Integer.parseInt(agent.getTimeouts()); - if (timeouts == 5) { - if (agent.getOnline()) { - agent.setOnline(false); - agent.setTimeouts("5"); - agentService.update(agent); - } - } else if (timeouts < 5) { - if (!agent.getOnline()) { - agent.setTimeouts(++timeouts + ""); - agentService.update(agent); - } - } - } - - Message agentConfigMessage = rabbitMessagingTemplate.receive("agentconfig"); - - boolean flag1 = false; - boolean flag2; - if (Objects.isNull(agentConfigMessage)) { - flag1 = true; - } else { - //将所有agent的online标志置为false - agentService.updateAgentSetOnlineFalse(); - getAgentConfigMessage(agentConfigMessage); - //TijiHelper.getAgentConfigMessage(agentService,idWorker,agentConfigMessage); - //getAgentConfigMessage(agentConfigMessage); - } - flag2 = getHeartbeat(); - if (flag1 && flag2) { - List agentList = agentService.findAll(); - for (Agent agent : agentList) { - if (agent.getOnline()) { - agent.setOnline(false); - agentService.update(agent); - } - } - System.out.println("no agent online"); - } - System.out.println("sending heartbeat"); - sendHeartbeat(); - } catch (Exception e) { - logger.error("AgentHeartbeatMonitorScheduler Exception here: " + ExcpUtil.buildErrorMessage(e)); - } - } - - - //TODO 处理agent cpu和内存状态 - private void getAgentConfigMessage(Message agentConfigMessage) { - if (!Objects.isNull(agentConfigMessage)) { - Map agentConfig = (Map) agentConfigMessage.getPayload(); - String agentName = agentConfig.get("agentName"); - String nmapPath = agentConfig.get("nmapPath"); - String massPath = agentConfig.get("massPath"); - String online = agentConfig.get("online"); - String ipAddress = agentConfig.get("ipAddress"); - String onlineFlag = online + ipAddress; - - if (!Objects.isNull(agentName) && !Objects.isNull(nmapPath) && !Objects.isNull(massPath) && !Objects.isNull(online)) { - Agent dbAgent = agentService.findByNameAndIpaddress(agentName, ipAddress); - //新增一个agent记录 - if (Objects.isNull(dbAgent)) { - agentService.add(new Agent(idWorker.nextId() + "", agentName, nmapPath, massPath, ipAddress, true, "0")); - } - } - // - if (!Objects.isNull(online)) { - List agentList = agentService.findAll(); - for (Agent agent : agentList) { - String name = agent.getName(); - String ipaddress = agent.getIpaddress(); - if (!onlineFlag.equals(name + ipaddress)) { - //agent.setOnline(false); - } else { - agent.setOnline(true); - agent.setTimeouts("0"); - } - agentService.update(agent); - } - } - } - } - - private boolean getHeartbeat() { - while (true) { - Message agentConfigMessage = rabbitMessagingTemplate.receive("agentconfig"); - if (!Objects.isNull(agentConfigMessage)) { - getAgentConfigMessage(agentConfigMessage); - //TijiHelper.getAgentConfigMessage(agentService,idWorker,agentConfigMessage); - } else { - return true; - } - } - } - - private void sendHeartbeat() { - List agentList = agentService.findAll(); - if (!agentList.isEmpty()) { - Map taskConfig = new HashMap<>(); - taskConfig.put("status", "heartbeat"); - //rabbitMessagingTemplate.convertAndSend("heartbeatfanout", "", taskConfig); - rabbitMessagingTemplate.convertAndSend("tijifanout", "", taskConfig); - } - } -} diff --git a/center/src/main/java/com/tiji/center/schedule/AssetNotifyScheduler.java b/center/src/main/java/com/tiji/center/schedule/AssetNotifyScheduler.java deleted file mode 100755 index 425e9d7..0000000 --- a/center/src/main/java/com/tiji/center/schedule/AssetNotifyScheduler.java +++ /dev/null @@ -1,356 +0,0 @@ -package com.tiji.center.schedule; - -import com.tiji.center.pojo.Notifylog; -import com.tiji.center.pojo.Sendmailconfig; -import com.tiji.center.service.NotifylogService; -import com.tiji.center.service.SendmailconfigService; -import com.tiji.center.service.TaskipService; -import com.tiji.center.util.NotifyUtil; -import org.apache.poi.ooxml.POIXMLProperties; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.xssf.streaming.SXSSFWorkbook; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.quartz.DisallowConcurrentExecution; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.quartz.PersistJobDataAfterExecution; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.mail.javamail.JavaMailSenderImpl; -import util.ExcpUtil; -import util.IdWorker; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.time.LocalDate; -import java.time.LocalTime; -import java.util.*; - -/** - * @author 贰拾壹 - * @create 2019-11-05 17:39 - */ -@DisallowConcurrentExecution -@PersistJobDataAfterExecution -public class AssetNotifyScheduler implements Job { - private final static Logger logger = LoggerFactory.getLogger(AssetNotifyScheduler.class); - @Autowired - JavaMailSenderImpl mailSender; - //统一所有报告和单个报告的时间戳 - LocalTime localTime = LocalTime.now(); - private final String timePrefix = LocalDate.now().toString().replace("-", "") + "-" + localTime.getHour() + localTime.getMinute() + " "; - @Autowired - private TaskipService taskipService; - @Autowired - private SendmailconfigService sendmailconfigService; - @Autowired - private NotifylogService notifylogService; - @Autowired - private IdWorker idWorker; - - @Override - public void execute(JobExecutionContext jobExecutionContext) { - List notifyLogList = new ArrayList<>(); - Date date = new Date(); - try { - long allAssetsCount = taskipService.findAllAssetsCount(); - if (allAssetsCount > 0) { - //发报告 - List sendmailconfigList = sendmailconfigService.findAll(); - Sendmailconfig sendmailconfig = sendmailconfigList.get(0); - String sendFrom = sendmailconfig.getSendfrom(); - String sendTo = sendmailconfig.getSendto(); - String[] sendToArray = sendTo.split(","); - String sendMailConfigAssetSubject = sendmailconfig.getAssetsubject(); - String sendMailConfigAssetContent = sendmailconfig.getAssetcontent(); - String author = sendmailconfig.getExcelauthor(); - - //设置邮箱信息 - mailSender.setHost(sendmailconfig.getSendhost()); - mailSender.setUsername(sendFrom); - mailSender.setPassword(sendmailconfig.getSendpassword()); - - //资产报告表头 - String lastFileName = "资产报告"; - String[] titleArraysWithContact = new String[]{"ip", "端口", "协议", "状态", "服务", "版本", "端口发现时间", "端口信息变更时间", "高危端口", "高危服务", "高危版本", "项目", "联系人列表", "联系邮箱列表", "联系电话列表"}; - - //ide运行用这个 - //String path = this.getClass().getClassLoader().getResource("").getPath() + "report/asset/"; - //jar包部署用这个 - String path = "report/asset/"; - File file1 = new File(path); - if (!file1.exists()) { - file1.mkdirs(); - } - - long pageSize = 1000; - - //所有资产报告 - String firstFileNameAll = "所有"; - String fileNameAll = timePrefix + firstFileNameAll + "-" + lastFileName + ".xlsx"; - File fileAll = new File(path + fileNameAll); - db2Excel(pageSize, author, firstFileNameAll, lastFileName, titleArraysWithContact, fileAll,notifyLogList); - - //有联系人资产报告 - String firstFileNameAllWithContact = "有项目联系人"; - String fileNameAllWithContact = timePrefix + firstFileNameAllWithContact + "-" + lastFileName + ".xlsx"; - File fileAllWithContact = new File(path + fileNameAllWithContact); - db2Excel(pageSize, author, firstFileNameAllWithContact, lastFileName, titleArraysWithContact, fileAllWithContact,notifyLogList); - - //无联系人资产报告 - String firstFileNameAllNoContact = "无项目联系人"; - String fileNameAllNoContact = timePrefix + firstFileNameAllNoContact + "-" + lastFileName + ".xlsx"; - File fileAllNoContact = new File(path + fileNameAllNoContact); - db2Excel(pageSize, author, firstFileNameAllNoContact, lastFileName, titleArraysWithContact, fileAllNoContact,notifyLogList); - - //发邮件 - Map fileMap = new LinkedHashMap<>(); - fileMap.put(fileAll.getName(), fileAll); - fileMap.put(fileAllWithContact.getName(), fileAllWithContact); - fileMap.put(fileAllNoContact.getName(), fileAllNoContact); - if (!fileMap.isEmpty()) { - //20201221默认提醒增加提醒日志 - for (String mail : sendToArray) { - try { - NotifyUtil.sendMailWithAttach(mailSender, sendFrom, mail, sendMailConfigAssetSubject, sendMailConfigAssetContent, fileMap); - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "E", null, mail, fileNameAll + " " + fileNameAllWithContact + " " + fileNameAllNoContact, true, null, date)); - } catch (Exception e) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "E", null, mail, fileNameAll + " " + fileNameAllWithContact + " " + fileNameAllNoContact, false, "默认提醒邮箱资产报告发送失败,异常消息:" + e.getMessage(), date)); - logger.info("all asset notify Exception here: " + e); - } - } - } - fileMap.clear(); - - //项目负责人 - //分页导出资产数据 - //long allAssetsCount = taskipService.findAllAssetsCount(); - - //100条测试用 - //long allAssetsCount = 1000; - //long pageSize = 50; - long loopSize = (long) Math.ceil(allAssetsCount / (double) pageSize); - long offset = 0; - - String[] titleArrays = new String[]{"ip", "端口", "协议", "状态", "服务", "版本", "端口发现时间", "端口信息变更时间", "高危端口", "高危服务", "高危版本"}; - - Map> totalResultMap = new LinkedHashMap<>(); - Map> contactMap = new HashMap<>(); - for (long step = 0; step < loopSize; step++) { - List> allAssetsByPage = taskipService.findAllAssetsByPageNew(offset, pageSize); - for (List singleResultList : allAssetsByPage) { - - if (!Objects.isNull(singleResultList.get(11))) { - String projectInfoName = singleResultList.get(11); - String contactNameString = singleResultList.get(12); - String contactEmailString = singleResultList.get(13); - //关联 项目名称 - 联系人信息 - if (!Objects.isNull(contactNameString)) { - List contactList = new ArrayList<>(); - String[] contactNameArray = contactNameString.split(";"); - for (int i = 0; i < contactNameArray.length; i++) { - contactList.add(contactNameArray[i] + "-+-" + contactEmailString.split(";")[i]); - } - contactMap.put(projectInfoName, contactList); - } - - if (!totalResultMap.containsKey(projectInfoName)) { - //当前不存在,新建并写到Excel - XSSFWorkbook workbook1 = new XSSFWorkbook(); - POIXMLProperties xmlProps = workbook1.getProperties(); - POIXMLProperties.CoreProperties coreProps = xmlProps.getCoreProperties(); - coreProps.setCreator(author); - Workbook workbook = new SXSSFWorkbook(workbook1, 100, true, true); - //Workbook workbook = new SXSSFWorkbook(); - - Sheet sheet = workbook.createSheet(projectInfoName); - //设置标题 - NotifyUtil.setSheetHeaderTitle(sheet, titleArrays); - //写数据 - int index = 1; - index = writeCellData(sheet, index, singleResultList, false); - - //添加当前id,并新建 - Map projectInfoIdMap = new HashMap<>(); - projectInfoIdMap.put(projectInfoName + "sheet", sheet); - projectInfoIdMap.put(projectInfoName + "workbook", workbook); - projectInfoIdMap.put(projectInfoName + "index", index); - totalResultMap.put(projectInfoName, projectInfoIdMap); - } else { - //添加到已存在的 - Map projectInfoIdMap = totalResultMap.get(projectInfoName); - Sheet sheet = (Sheet) projectInfoIdMap.get(projectInfoName + "sheet"); - - Workbook workbook = (Workbook) projectInfoIdMap.get(projectInfoName + "workbook"); - //写数据 - int index = (int) projectInfoIdMap.get(projectInfoName + "index"); - index = writeCellData(sheet, index, singleResultList, false); - - projectInfoIdMap.put(projectInfoName + "sheet", sheet); - projectInfoIdMap.put(projectInfoName + "workbook", workbook); - projectInfoIdMap.put(projectInfoName + "index", index); - totalResultMap.put(projectInfoName, projectInfoIdMap); - } - - } - } - offset = offset + pageSize; - } - - - Map projectInfoNameAndFileMap = new LinkedHashMap<>(); - //写到文件 - Set>> entries = totalResultMap.entrySet(); - for (Map.Entry> entry : entries) { - - String projectInfoName = entry.getKey(); - Map projectInfoIdMap = entry.getValue(); - - Workbook workbookInMap = (Workbook) projectInfoIdMap.get(projectInfoName + "workbook"); - Sheet sheetInMap = (Sheet) projectInfoIdMap.get(projectInfoName + "sheet"); - - String fileName = timePrefix + sheetInMap.getSheetName() + "-" + lastFileName + ".xlsx"; - //String path = this.getClass().getClassLoader().getResource("").getPath() + "report/asset/"; - File file = new File(path + fileName); - try (FileOutputStream fileOutputStream = new FileOutputStream(file);) { - // 导出 - workbookInMap.write(fileOutputStream); - workbookInMap.close(); - } catch (IOException e) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "E", null, null, null, false, "资产报告无法写入文件,异常消息:" + e.getMessage(), date)); - logger.info("File2disk Asset owner Exception here: " + e); - } - projectInfoNameAndFileMap.put(projectInfoName, file); - - } - - //将文件与项目人联系方式绑定 - Map> projectInfoAndContactWithFilelistMap = new LinkedHashMap<>(); - Set> entrySet = projectInfoNameAndFileMap.entrySet(); - for (Map.Entry entry : entrySet) { - String projectInfoName = entry.getKey(); - File file = (File) entry.getValue(); - List contactList = contactMap.get(projectInfoName); - if (!Objects.isNull(contactList)) { - for (String contactNameEmailString : contactList) { - if (!projectInfoAndContactWithFilelistMap.containsKey(contactNameEmailString)) { - List fileList = new LinkedList<>(); - fileList.add(file); - projectInfoAndContactWithFilelistMap.put(contactNameEmailString, fileList); - } else { - List fileList = projectInfoAndContactWithFilelistMap.get(contactNameEmailString); - fileList.add(file); - projectInfoAndContactWithFilelistMap.put(contactNameEmailString, fileList); - } - } - } - } - totalResultMap.clear(); - //发邮件 - NotifyUtil.sendMail2ProjectOwner(sendFrom, sendMailConfigAssetSubject, sendMailConfigAssetContent, projectInfoAndContactWithFilelistMap, mailSender, notifylogService, idWorker); - } - - } catch (Exception e) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "E", null, null, null, false, "默认提醒邮箱资产报告发送失败,异常消息:" + e.getMessage(), date)); - logger.error("AssetNotifyScheduler Exception here: " + ExcpUtil.buildErrorMessage(e)); - } - notifylogService.batchAdd(notifyLogList); - } - - private void db2Excel(long pageSize, String author, String firstFileName, String lastFileName, String[] titleArraysWithContact, File file, List notifyLogList) { - //分页导出资产数据 - long allAssetsCount = taskipService.findAllAssetsCount(); - if (allAssetsCount > 0) { - XSSFWorkbook workbook1 = new XSSFWorkbook(); - POIXMLProperties xmlProps = workbook1.getProperties(); - POIXMLProperties.CoreProperties coreProps = xmlProps.getCoreProperties(); - coreProps.setCreator(author); - Workbook workbook = new SXSSFWorkbook(workbook1, 100, true, true); - try (FileOutputStream fileOutputStream = new FileOutputStream(file);) { - //long pageSize = 100; - - //1000条测试用 - //long allAssetsCount = 1000; - //long pageSize = 50; - long loopSize = (long) Math.ceil(allAssetsCount / (double) pageSize); - long offset = 0; - int index = 1; - int sheetRow = 0; - int sheetTab = 1; - - - for (long step = 0; step < loopSize; step++) { - List> allAssetsByPage = taskipService.findAllAssetsByPageNew(offset, pageSize); - for (List singleResultList : allAssetsByPage) { - - String sheetName = firstFileName + lastFileName + "-" + sheetTab; - Sheet sheet = workbook.getSheet(sheetName); - if (Objects.isNull(sheet)) { - sheet = workbook.createSheet(sheetName); - NotifyUtil.setSheetHeaderTitle(sheet, titleArraysWithContact); - } - //最大行1048576-1,分页 - if (sheetRow == 1048575) { - sheetTab++; - sheet = workbook.createSheet(firstFileName + lastFileName + "-" + sheetTab); - //设置标题 - NotifyUtil.setSheetHeaderTitle(sheet, titleArraysWithContact); - sheetRow = 0; - index = 1; - } - - if ("所有".equals(firstFileName)) { - index = writeCellData(sheet, index, singleResultList, true); - sheetRow++; - } - if ("有项目联系人".equals(firstFileName) && !Objects.isNull(singleResultList.get(11))) { - index = writeCellData(sheet, index, singleResultList, true); - sheetRow++; - } - if ("无项目联系人".equals(firstFileName) && Objects.isNull(singleResultList.get(11))) { - index = writeCellData(sheet, index, singleResultList, true); - sheetRow++; - } - } - offset = offset + pageSize; - } - - fileOutputStream.flush(); - workbook.write(fileOutputStream); - workbook.close(); - } catch (IOException e) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "E", null, null, null, false, "资产导出到Excel失败,异常消息:" + e.getMessage(), new Date())); - logger.info("asset report 2Excel Exception here: " + e); - } - } - } - - //设置内容 - private int writeCellData(Sheet sheet, int index, List singleResultList, boolean allData) { - Row row; - row = sheet.createRow(index++); - NotifyUtil.setCellData(sheet, row, 0, singleResultList.get(0)); - NotifyUtil.setCellData(sheet, row, 1, singleResultList.get(1)); - NotifyUtil.setCellData(sheet, row, 2, singleResultList.get(2)); - NotifyUtil.setCellData(sheet, row, 3, singleResultList.get(3)); - NotifyUtil.setCellData(sheet, row, 4, singleResultList.get(4)); - NotifyUtil.setCellData(sheet, row, 5, singleResultList.get(5)); - NotifyUtil.setCellData(sheet, row, 6, singleResultList.get(6)); - NotifyUtil.setCellData(sheet, row, 7, singleResultList.get(7)); - NotifyUtil.setCellData(sheet, row, 8, singleResultList.get(8)); - NotifyUtil.setCellData(sheet, row, 9, singleResultList.get(9)); - NotifyUtil.setCellData(sheet, row, 10, singleResultList.get(10)); - - if (allData && !Objects.isNull(singleResultList.get(11))) { - NotifyUtil.setCellData(sheet, row, 11, singleResultList.get(11)); - NotifyUtil.setCellData(sheet, row, 12, singleResultList.get(12)); - NotifyUtil.setCellData(sheet, row, 13, singleResultList.get(13)); - NotifyUtil.setCellData(sheet, row, 14, singleResultList.get(14)); - } - return index; - } -} diff --git a/center/src/main/java/com/tiji/center/schedule/ExecuteCheckTaskScheduler.java b/center/src/main/java/com/tiji/center/schedule/ExecuteCheckTaskScheduler.java deleted file mode 100755 index 4b92253..0000000 --- a/center/src/main/java/com/tiji/center/schedule/ExecuteCheckTaskScheduler.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.tiji.center.schedule; - - -import com.tiji.center.service.TaskDispatcherService; -import org.quartz.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import util.ExcpUtil; - -/** - * @author 贰拾壹 - */ -@DisallowConcurrentExecution -@PersistJobDataAfterExecution -public class ExecuteCheckTaskScheduler implements Job { - - private final static Logger logger = LoggerFactory.getLogger(ExecuteCheckTaskScheduler.class); - @Autowired - private TaskDispatcherService taskDispatcherService; - - @Override - public void execute(JobExecutionContext jobExecutionContext) { - try { - JobDetail jobDetail = jobExecutionContext.getJobDetail(); - JobDataMap jobDataMap = jobDetail.getJobDataMap(); - String taskId = (String) jobDataMap.get("taskId"); - taskDispatcherService.executeCheck(taskId); - } catch (Exception e) { - logger.error("ExecuteCheckTaskScheduler Exception here: " + ExcpUtil.buildErrorMessage(e)); - } - } -} diff --git a/center/src/main/java/com/tiji/center/schedule/ExecuteTotalCheckTaskScheduler.java b/center/src/main/java/com/tiji/center/schedule/ExecuteTotalCheckTaskScheduler.java deleted file mode 100755 index ce4831d..0000000 --- a/center/src/main/java/com/tiji/center/schedule/ExecuteTotalCheckTaskScheduler.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.tiji.center.schedule; - - -import com.tiji.center.service.TaskDispatcherService; -import org.quartz.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import util.ExcpUtil; - -/** - * @author 贰拾壹 - */ -@DisallowConcurrentExecution -@PersistJobDataAfterExecution -public class ExecuteTotalCheckTaskScheduler implements Job { - - private final static Logger logger = LoggerFactory.getLogger(AgentHeartbeatMonitorScheduler.class); - @Autowired - private TaskDispatcherService taskDispatcherService; - - @Override - public void execute(JobExecutionContext jobExecutionContext) { - try { - JobDetail jobDetail = jobExecutionContext.getJobDetail(); - JobDataMap jobDataMap = jobDetail.getJobDataMap(); - String taskId = (String) jobDataMap.get("taskId"); - taskDispatcherService.executeTotalCheck(taskId); - } catch (Exception e) { - logger.error("ExecuteTotalCheckTaskScheduler Exception here: " + ExcpUtil.buildErrorMessage(e)); - } - } -} diff --git a/center/src/main/java/com/tiji/center/schedule/ExecuteWorkTaskScheduler.java b/center/src/main/java/com/tiji/center/schedule/ExecuteWorkTaskScheduler.java deleted file mode 100755 index 4508760..0000000 --- a/center/src/main/java/com/tiji/center/schedule/ExecuteWorkTaskScheduler.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.tiji.center.schedule; - - -import com.tiji.center.pojo.Nmapconfig; -import com.tiji.center.service.NmapconfigService; -import com.tiji.center.service.TaskDispatcherService; -import org.quartz.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import util.ExcpUtil; - -import java.util.Objects; - -/** - * @author 贰拾壹 - */ -@DisallowConcurrentExecution -@PersistJobDataAfterExecution -public class ExecuteWorkTaskScheduler implements Job { - - private final static Logger logger = LoggerFactory.getLogger(ExecuteWorkTaskScheduler.class); - @Autowired - private TaskDispatcherService taskDispatcherService; - @Autowired - private NmapconfigService nmapconfigService; - - @Override - public void execute(JobExecutionContext jobExecutionContext) { - try { - JobDetail jobDetail = jobExecutionContext.getJobDetail(); - JobDataMap jobDataMap = jobDetail.getJobDataMap(); - String taskId = (String) jobDataMap.get("taskId"); - String taskTargetIp = (String) jobDataMap.get("taskTargetIp"); - String taskWorkType = (String) jobDataMap.get("taskWorkType"); - if ("assetip".equals(taskTargetIp) && ("nse".equals(taskWorkType) || "selfd".equals(taskWorkType) || "httpp".equals(taskWorkType))) { - taskDispatcherService.executeTotalCheck(taskId); - } else { - //标准任务 - if ("mass2Nmap".equals(taskWorkType)) { - Nmapconfig nmapconfig = nmapconfigService.findByTaskid(taskId); - if (Objects.isNull(nmapconfig)) { - throw new RuntimeException("nmap配置为空"); - } - } - try { - taskDispatcherService.executeWork(taskId); - } catch (InterruptedException e) { - logger.info("taskDispatcherService Exception here: " + e); - } - } - } catch (Exception e) { - logger.error("ExecuteWorkTaskScheduler Exception here: " + ExcpUtil.buildErrorMessage(e)); - } - } -} diff --git a/center/src/main/java/com/tiji/center/schedule/MidnightTaskScheduler.java b/center/src/main/java/com/tiji/center/schedule/MidnightTaskScheduler.java deleted file mode 100755 index 7c8f3a5..0000000 --- a/center/src/main/java/com/tiji/center/schedule/MidnightTaskScheduler.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.tiji.center.schedule; - - -import com.tiji.center.service.*; -import com.tiji.center.util.HostNameUtil; -import com.tiji.center.util.WhitelistUtil; -import org.quartz.DisallowConcurrentExecution; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.quartz.PersistJobDataAfterExecution; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import util.ExcpUtil; -import util.IdWorker; - -import java.util.Date; - -/** - * @author 贰拾壹 - */ -@DisallowConcurrentExecution -@PersistJobDataAfterExecution -public class MidnightTaskScheduler implements Job { - - private final static Logger logger = LoggerFactory.getLogger(MidnightTaskScheduler.class); - @Autowired - private AssetipService assetipService; - @Autowired - private AssetportService assetportService; - @Autowired - private HostService hostService; - @Autowired - private IdWorker idWorker; - @Autowired - private CheckresultService checkresultService; - @Autowired - private ProjectinfoService projectinfoService; - @Autowired - private IpwhitelistService ipwhitelistService; - @Autowired - private IpportwhitelistService ipportwhitelistService; - @Autowired - private ProjectportwhitelistService projectportwhitelistService; - - @Override - public void execute(JobExecutionContext jobExecutionContext) { - try { - //dns解析获取hostname - try { - HostNameUtil.dnsResolver(assetipService, hostService, idWorker, new Date()); - } catch (InterruptedException e) { - logger.info("dnsResolver Exception here: " + e); - } - //nse结果获取hostname - HostNameUtil.nseResultParser(assetportService, checkresultService, hostService, idWorker, new Date()); - - //根据ip更新白名单 - WhitelistUtil.markIpWhitelist(assetipService, assetportService, ipwhitelistService, ipportwhitelistService); - //根据项目更新白名单 - WhitelistUtil.markProjectInfoWhitelist(projectinfoService, assetipService, assetportService, projectportwhitelistService); - } catch (Exception e) { - logger.error("MidnightTaskScheduler Exception here: " + ExcpUtil.buildErrorMessage(e)); - } - } -} diff --git a/center/src/main/java/com/tiji/center/schedule/StatisticsScheduler.java b/center/src/main/java/com/tiji/center/schedule/StatisticsScheduler.java deleted file mode 100755 index 761fb77..0000000 --- a/center/src/main/java/com/tiji/center/schedule/StatisticsScheduler.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.tiji.center.schedule; - - -import com.tiji.center.pojo.Statistics; -import com.tiji.center.service.StatisticsService; -import org.quartz.DisallowConcurrentExecution; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.quartz.PersistJobDataAfterExecution; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import util.ExcpUtil; -import util.IdWorker; - -import java.util.Date; -import java.util.Map; -import java.util.Objects; - -/** - * @author 贰拾壹 - */ -@DisallowConcurrentExecution -@PersistJobDataAfterExecution -public class StatisticsScheduler implements Job { - - private final static Logger logger = LoggerFactory.getLogger(StatisticsScheduler.class); - @Autowired - private StatisticsService statisticsService; - @Autowired - private IdWorker idWorker; - - @Override - public void execute(JobExecutionContext jobExecutionContext) { - try { - - //Statistics统计数据更新 - String ipCount = statisticsService.findIpCount(); - String ipCountOnline = statisticsService.findIpCountOnline(); - String portCount = statisticsService.findPortCount(); - String portCountOnline = statisticsService.findPortCountOnline(); - - Map checkresultCountMap = statisticsService.findCheckresultCountMap(); - Map checkresultCountOnlineMap = statisticsService.findCheckresultCountOnlineMap(); - - String riskportCount = statisticsService.findRiskportCount(); - String riskportCountOnline = statisticsService.findRiskportCountOnline(); - String riskserviceCount = statisticsService.findRiskserviceCount(); - String riskserviceCountOnline = statisticsService.findRiskserviceCountOnline(); - String riskversionCount = statisticsService.findRiskversionCount(); - String riskversionCountOnline = statisticsService.findRiskversionCountOnline(); - - long fatalLong = parseRiskCount2Long(checkresultCountMap, "致命"); - long criticalLong = parseRiskCount2Long(checkresultCountMap, "严重"); - long highLong = parseRiskCount2Long(checkresultCountMap, "高危"); - long mediumLong = parseRiskCount2Long(checkresultCountMap, "中危"); - long lowLong = parseRiskCount2Long(checkresultCountMap, "低危"); - long infoLong = parseRiskCount2Long(checkresultCountMap, "信息"); - - - long fatalLongOnline = parseRiskCount2Long(checkresultCountOnlineMap, "致命"); - long criticalLongOnline = parseRiskCount2Long(checkresultCountOnlineMap, "严重"); - long highLongOnline = parseRiskCount2Long(checkresultCountOnlineMap, "高危"); - long mediumLongOnline = parseRiskCount2Long(checkresultCountOnlineMap, "中危"); - long lowLongOnline = parseRiskCount2Long(checkresultCountOnlineMap, "低危"); - long infoLongOnline = parseRiskCount2Long(checkresultCountOnlineMap, "信息"); - - long checkresultCount = fatalLong + criticalLong + highLong + mediumLong + lowLong + infoLong; - long checkresultCountOnline = fatalLongOnline + criticalLongOnline + highLongOnline + mediumLongOnline + lowLongOnline + infoLongOnline; - - Statistics statistics = new Statistics(idWorker.nextId() + "", - ipCount, ipCountOnline, portCount, portCountOnline, - String.valueOf(checkresultCount), String.valueOf(checkresultCountOnline), - String.valueOf(infoLong), String.valueOf(lowLong), String.valueOf(mediumLong), String.valueOf(highLong), String.valueOf(criticalLong), String.valueOf(fatalLong), - String.valueOf(infoLongOnline), String.valueOf(lowLongOnline), String.valueOf(mediumLongOnline), String.valueOf(highLongOnline), String.valueOf(criticalLongOnline), String.valueOf(fatalLongOnline), - String.valueOf(riskportCount), String.valueOf(riskportCountOnline), String.valueOf(riskserviceCount), String.valueOf(riskserviceCountOnline), String.valueOf(riskversionCount), String.valueOf(riskversionCountOnline), - new Date()); - statisticsService.add(statistics); - - } catch (Exception e) { - logger.error("StatisticsScheduler Exception here: " + ExcpUtil.buildErrorMessage(e)); - } - } - - public long parseRiskCount2Long(Map checkresultCountMap, String risk) { - String riskInMap = checkresultCountMap.get(risk); - return Objects.isNull(riskInMap) ? 0 : Long.parseLong(riskInMap); - - } -} diff --git a/center/src/main/java/com/tiji/center/schedule/TaskStatusMonitorScheduler.java b/center/src/main/java/com/tiji/center/schedule/TaskStatusMonitorScheduler.java deleted file mode 100755 index 162358f..0000000 --- a/center/src/main/java/com/tiji/center/schedule/TaskStatusMonitorScheduler.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.tiji.center.schedule; - -import com.tiji.center.pojo.Task; -import com.tiji.center.service.TaskService; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import util.ExcpUtil; - -import java.util.*; - - -/** - * @author 贰拾壹 - * @create 2019-09-30 10:32 - */ -public class TaskStatusMonitorScheduler implements Job { - private final static Logger logger = LoggerFactory.getLogger(TaskStatusMonitorScheduler.class); - @Autowired - private TaskService taskService; - @Autowired - private RedisTemplate redisTemplate; - @Autowired - private RabbitMessagingTemplate rabbitMessagingTemplate; - - @Override - public void execute(JobExecutionContext jobExecutionContext) { - try { - //监控总任务信息 - //遍历所有starttime不为null的id,防止未刷新结束任务信息 - List startTimeNotNullTaskList = taskService.findAllByEndtimeIsNullAndStarttimeIsNotNull(); - List endTaskList = taskService.findAllByWorktypeAndEndtimeIsNotNullAndStarttimeIsNotNull("selfd"); - endTaskList.addAll(taskService.findAllByWorktypeAndEndtimeIsNotNullAndStarttimeIsNotNull("httpp")); - ///加nmap - endTaskList.addAll(taskService.findAllByWorktypeAndEndtimeIsNotNullAndStarttimeIsNotNull("nmap")); - - if (!startTimeNotNullTaskList.isEmpty()) { - for (Task task : startTimeNotNullTaskList) { - String worktype = task.getWorktype(); - //if (!worktype.equals("mass2Nmap")) { - String taskIdTotal = task.getId(); - //已完成任务数 - String accomplishTaskListNameTotal = "accomplishTaskList_" + taskIdTotal; - //分组大小 - String sliceIPListSizeNameTotal = "sliceIPListSize_" + taskIdTotal; - //总任务数 - String totalTaskListNameTotal = "totalTaskList_" + taskIdTotal; - //正在进行的,没有操作到这个.. - String workingTaskListNameTotal = "workingTaskList_" + taskIdTotal; - - System.out.println("TaskStatusMonitorScheduler running for taskId: " + taskIdTotal); - Boolean aBoolean = redisTemplate.hasKey(sliceIPListSizeNameTotal); - if (!Objects.isNull(aBoolean) && aBoolean) { - long accomplishTaskListSizeTotal = redisTemplate.opsForList().size(accomplishTaskListNameTotal); - long sliceIPListSizeTotal = Long.parseLong(redisTemplate.opsForValue().get(sliceIPListSizeNameTotal)); - System.out.println("accomplishTaskListSizeTotal: " + accomplishTaskListSizeTotal); - System.out.println("sliceIPListSizeTotal: " + sliceIPListSizeTotal); - - if (accomplishTaskListSizeTotal != 0 && accomplishTaskListSizeTotal == sliceIPListSizeTotal) { - if (!"mass2Nmap".equals(worktype)) { - System.out.println("TaskStatusMonitorScheduler update task endtime " + task.getId()); - //如果任务结束,给agent发结束信息,runningTaskMap删除已完成任务 - Map taskConfig = new HashMap<>(); - taskConfig.put("status", "removeAccomplishTask"); - taskConfig.put("taskId", task.getId()); - rabbitMessagingTemplate.convertAndSend("tijifanout", "", taskConfig); - - redisTemplate.delete(totalTaskListNameTotal); - redisTemplate.delete(accomplishTaskListNameTotal); - //redisTemplate.delete(workingTaskListNameTotal); - redisTemplate.delete(sliceIPListSizeNameTotal); -// redisTemplate.delete("ip_" + taskIdTotal); -// redisTemplate.delete("port_" + taskIdTotal); -// redisTemplate.delete("cmd_" + taskIdTotal); -// redisTemplate.delete("nginxRawVersion_"+taskIdTotal); -// redisTemplate.delete("timeout_" + taskIdTotal); - task.setEndtime(new Date()); - taskService.update(task); - } - if ("mass2Nmap".equals(worktype)) { - //防止任务结束后,scanResultReceiver接收不到最后的结果,不能更新secondTaskFlag - Map resultMap = new HashMap<>(); - resultMap.put("workType", "mass2Nmap"); - resultMap.put("taskId", taskIdTotal); - resultMap.put("scanResult", "mass2Nmap"); - rabbitMessagingTemplate.convertAndSend("scanresult", resultMap); - } - } - //结果不受影响 - //if (worktype.equals("mass") || worktype.equals("mass2Nmap") || worktype.equals("nmap") || worktype.equals("nse")) { - // //if (worktype.equals("mass") || worktype.equals("nmap") || worktype.equals("nse")) { - // if (!redisTemplate.hasKey(sliceIPListSizeNameTotal) && !redisTemplate.hasKey(workingTaskListNameTotal)) { - // System.out.println("TaskStatusMonitorScheduler update task endtime " + task.getId()); - // redisTemplate.delete(accomplishTaskListNameTotal); - // redisTemplate.delete(sliceIPListSizeNameTotal); - // task.setEndtime(new Date()); - // taskService.update(task); - // } - //} else { - // //httpp selfd 手动停止时会有残留 - // if (!redisTemplate.hasKey(sliceIPListSizeNameTotal)) { - // System.out.println("TaskStatusMonitorScheduler remove redis cache " + task.getId()); - // redisTemplate.delete(accomplishTaskListNameTotal); - // } - //} - // - } - - } - } - if (!endTaskList.isEmpty()) { - for (Task task : endTaskList) { - //httpp selfd 手动停止时会有线程残留,清除redis缓存 - //加nmap - String worktype = task.getWorktype(); - String taskIdTotal = task.getId(); - //已完成任务数 - String accomplishTaskListNameTotal = "accomplishTaskList_" + taskIdTotal; - //分组大小 - String sliceIPListSizeNameTotal = "sliceIPListSize_" + taskIdTotal; - //总任务数 - String totalTaskListNameTotal = "totalTaskList_" + taskIdTotal; - //正在进行的,没有操作到这个.. - String workingTaskListNameTotal = "workingTaskList_" + taskIdTotal; - if (("selfd".equals(worktype) || "httpp".equals(worktype) || "nmap".equals(worktype)) && (task.getStarttime() != null && task.getEndtime() != null) && (!redisTemplate.hasKey(sliceIPListSizeNameTotal) && redisTemplate.hasKey(accomplishTaskListNameTotal))) { - redisTemplate.delete(accomplishTaskListNameTotal); -// redisTemplate.delete("ip_" + taskIdTotal); -// redisTemplate.delete("port_" + taskIdTotal); -// redisTemplate.delete("cmd_" + taskIdTotal); -// redisTemplate.delete("nginxRawVersion_"+taskIdTotal); -// redisTemplate.delete("timeout_" + taskIdTotal); - redisTemplate.delete(totalTaskListNameTotal); - } - } - } - } catch (Exception e) { - logger.error("TaskStatusMonitorScheduler Exception here: " + ExcpUtil.buildErrorMessage(e)); - } - } -} diff --git a/center/src/main/java/com/tiji/center/schedule/VulnNotifyScheduler.java b/center/src/main/java/com/tiji/center/schedule/VulnNotifyScheduler.java deleted file mode 100755 index fe1a4b6..0000000 --- a/center/src/main/java/com/tiji/center/schedule/VulnNotifyScheduler.java +++ /dev/null @@ -1,389 +0,0 @@ -package com.tiji.center.schedule; - -import com.tiji.center.pojo.Notifylog; -import com.tiji.center.pojo.Projectvulnnotify; -import com.tiji.center.pojo.Sendmailconfig; -import com.tiji.center.service.NotifylogService; -import com.tiji.center.service.ProjectvulnnotifyService; -import com.tiji.center.service.SendmailconfigService; -import com.tiji.center.service.TaskipService; -import com.tiji.center.util.NotifyUtil; -import org.apache.commons.lang3.StringUtils; -import org.apache.poi.ooxml.POIXMLProperties; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.xssf.streaming.SXSSFWorkbook; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.quartz.DisallowConcurrentExecution; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.quartz.PersistJobDataAfterExecution; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.mail.javamail.JavaMailSenderImpl; -import util.ExcpUtil; -import util.IdWorker; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.time.LocalDate; -import java.time.LocalTime; -import java.util.*; - -/** - * @author 贰拾壹 - * @create 2019-11-05 17:39 - */ -@DisallowConcurrentExecution -@PersistJobDataAfterExecution -public class VulnNotifyScheduler implements Job { - private final static Logger logger = LoggerFactory.getLogger(VulnNotifyScheduler.class); - @Autowired - JavaMailSenderImpl mailSender; - //统一所有报告和单个报告的时间戳 - LocalTime localTime = LocalTime.now(); - @Autowired - private TaskipService taskipService; - @Autowired - private ProjectvulnnotifyService projectvulnnotifyService; - @Autowired - private SendmailconfigService sendmailconfigService; - @Autowired - private NotifylogService notifylogService; - @Autowired - private IdWorker idWorker; - private String timePrefix = LocalDate.now().toString().replace("-", "") + "-" + localTime.getHour() + localTime.getMinute() + " "; - - - @Override - public void execute(JobExecutionContext jobExecutionContext) { - List notifyLogList = new ArrayList<>(); - Date date = new Date(); - try { - //分页导出资产数据 - long allAssetsCount = taskipService.findAllVulnsCount(); - if (allAssetsCount > 0) { - //然后才发报告 - List projectvulnnotifyList = projectvulnnotifyService.findAll(); - String projectVulnNotifyRisk = projectvulnnotifyList.get(0).getRisk(); - List sendmailconfigList = sendmailconfigService.findAll(); - Sendmailconfig sendmailconfig = sendmailconfigList.get(0); - String sendFrom = sendmailconfig.getSendfrom(); - String sendTo = sendmailconfig.getSendto(); - String[] sendToArray = sendTo.split(","); - String sendmailconfigVulnsubject = sendmailconfig.getVulnsubject(); - String sendmailconfigVulncontent = sendmailconfig.getVulncontent(); - String author = sendmailconfig.getExcelauthor(); - String sendtorisk = sendmailconfig.getSendtorisk(); - - if(StringUtils.isEmpty(sendtorisk)){ - notifylogService.add(new Notifylog(idWorker.nextId() + "", "E", null, null, null, false, "默认提醒邮箱漏洞报告发送失败,异常消息:风险等级未定义", date)); - return; - } - //设置邮箱信息 - mailSender.setHost(sendmailconfig.getSendhost()); - mailSender.setUsername(sendFrom); - mailSender.setPassword(sendmailconfig.getSendpassword()); - - String lastFileName = "漏洞报告"; - String[] titleArraysWithContact = new String[]{"一级分类", "二级分类", "漏洞名称", "风险", "ip", "ip上线时间", "ip下线时间", "端口", "服务", "版本", "端口发现时间", "端口关闭时间", "检测插件列表", "检测结果列表", "漏洞发现时间", "漏洞描述", "参考", "影响范围", "解决方案", "解决方案代码示例", "解决方案配置示例", "项目", "联系人列表", "联系邮箱列表", "联系电话列表"}; - //ide运行用这个 - //String path = this.getClass().getClassLoader().getResource("").getPath() + "report/vuln/"; - //jar包部署用这个 - String path = "report/vuln/"; - File file1 = new File(path); - if (!file1.exists()) { - boolean mkdirs = file1.mkdirs(); - } - - long pageSize = 1000; - - //所有漏洞报告 - String firstFileNameAll = "所有"; - String fileNameAll = timePrefix + firstFileNameAll + "-" + lastFileName + ".xlsx"; - File fileAll = new File(path + fileNameAll); - db2Excel(pageSize, author, firstFileNameAll, lastFileName, titleArraysWithContact, fileAll, sendtorisk,notifyLogList); - //有联系人漏洞报告 - String firstFileNameAllWithContact = "有项目联系人"; - String fileNameAllWithContact = timePrefix + firstFileNameAllWithContact + "-" + lastFileName + ".xlsx"; - File fileAllWithContact = new File(path + fileNameAllWithContact); - db2Excel(pageSize, author, firstFileNameAllWithContact, lastFileName, titleArraysWithContact, fileAllWithContact, sendtorisk,notifyLogList); - //无联系人漏洞报告 - String firstFileNameAllNoContact = "无项目联系人"; - String fileNameAllNoContact = timePrefix + firstFileNameAllNoContact + "-" + lastFileName + ".xlsx"; - File fileAllNoContact = new File(path + fileNameAllNoContact); - db2Excel(pageSize, author, firstFileNameAllNoContact, lastFileName, titleArraysWithContact, fileAllNoContact, sendtorisk,notifyLogList); - //发邮件 - Map fileMap = new LinkedHashMap<>(); - fileMap.put(fileAll.getName(), fileAll); - fileMap.put(fileAllWithContact.getName(), fileAllWithContact); - fileMap.put(fileAllNoContact.getName(), fileAllNoContact); - if (!fileMap.isEmpty()) { - //20201221默认提醒增加提醒日志 - for (String mail : sendToArray) { - try { - NotifyUtil.sendMailWithAttach(mailSender, sendFrom, mail, sendmailconfigVulnsubject, sendmailconfigVulncontent, fileMap); - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "E", null, mail, fileNameAll + " " + fileNameAllWithContact + " " + fileNameAllNoContact, true, null, date)); - //System.out.println("sending ..."); - } catch (Exception e) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "E", null, mail, fileNameAll + " " + fileNameAllWithContact + " " + fileNameAllNoContact, false, "默认提醒邮箱漏洞报告发送失败,异常消息:" + e.getMessage(), date)); - logger.info("all vuln notify Exception here: " + e); - } - } - } - fileMap.clear(); - - //项目负责人 - //分页导出检查结果数据 - - //分页导出资产数据 - //long allAssetsCount = taskipService.findAllAssetsCount(); - - //100条测试用 - //long allAssetsCount = 100; - //long pageSize = 50; - long loopSize = (long) Math.ceil(allAssetsCount / (double) pageSize); - long offset = 0; - - String[] titleArraysWithoutContact = new String[]{"一级分类", "二级分类", "漏洞名称", "风险", "ip", "ip上线时间", "ip下线时间", "端口", "服务", "版本", "端口发现时间", "端口关闭时间", "检测插件列表", "检测结果列表", "漏洞发现时间", "漏洞描述", "参考", "影响范围", "解决方案", "解决方案代码示例", "解决方案配置示例"}; - - Map> totalResultMap = new LinkedHashMap<>(); - Map> contactMap = new HashMap<>(); - for (long step = 0; step < loopSize; step++) { - List> allVulnsByPage = taskipService.findAllVulnsByPage(offset, pageSize); - for (List singleResultList : allVulnsByPage) { - String tvrisk = singleResultList.get(3); - //risk在db中才写到表格 - if (projectVulnNotifyRisk.contains(tvrisk)) { - if (!Objects.isNull(singleResultList.get(21))) { - String projectInfoName = singleResultList.get(21); - String contactNameString = singleResultList.get(22); - String contactEmailString = singleResultList.get(23); - //关联 项目名称 - 联系人信息 - if (!Objects.isNull(contactNameString)) { - List contactList = new ArrayList<>(); - String[] contactNameArray = contactNameString.split(";"); - for (int i = 0; i < contactNameArray.length; i++) { - contactList.add(contactNameArray[i] + "-+-" + contactEmailString.split(";")[i]); - } - contactMap.put(projectInfoName, contactList); - } - - if (!totalResultMap.containsKey(projectInfoName)) { - - //当前不存在,新建并写到Excel - XSSFWorkbook workbook1 = new XSSFWorkbook(); - POIXMLProperties xmlProps = workbook1.getProperties(); - POIXMLProperties.CoreProperties coreProps = xmlProps.getCoreProperties(); - coreProps.setCreator(author); - Workbook workbook = new SXSSFWorkbook(workbook1, 100, true, true); - //Workbook workbook = new SXSSFWorkbook(); - - Sheet sheet = workbook.createSheet(projectInfoName); - //设置标题 - NotifyUtil.setSheetHeaderTitle(sheet, titleArraysWithoutContact); - //写数据 - int index = 1; - index = writeCellData(sheet, index, singleResultList, false); - - //添加当前id,并新建 - Map projectInfoIdMap = new HashMap<>(); - projectInfoIdMap.put(projectInfoName + "sheet", sheet); - projectInfoIdMap.put(projectInfoName + "workbook", workbook); - projectInfoIdMap.put(projectInfoName + "index", index); - totalResultMap.put(projectInfoName, projectInfoIdMap); - } else { - //添加到已存在的 - Map projectInfoIdMap = totalResultMap.get(projectInfoName); - Sheet sheet = (Sheet) projectInfoIdMap.get(projectInfoName + "sheet"); - - Workbook workbook = (Workbook) projectInfoIdMap.get(projectInfoName + "workbook"); - //写数据 - int index = (int) projectInfoIdMap.get(projectInfoName + "index"); - index = writeCellData(sheet, index, singleResultList, false); - - projectInfoIdMap.put(projectInfoName + "sheet", sheet); - projectInfoIdMap.put(projectInfoName + "workbook", workbook); - projectInfoIdMap.put(projectInfoName + "index", index); - totalResultMap.put(projectInfoName, projectInfoIdMap); - } - } - } - } - offset = offset + pageSize; - } - - - Map projectInfoNameAndFileMap = new LinkedHashMap<>(); - //写到文件 - Set>> entries = totalResultMap.entrySet(); - for (Map.Entry> entry : entries) { - - String projectInfoName = entry.getKey(); - Map projectInfoIdMap = entry.getValue(); - - Workbook workbookInMap = (Workbook) projectInfoIdMap.get(projectInfoName + "workbook"); - Sheet sheetInMap = (Sheet) projectInfoIdMap.get(projectInfoName + "sheet"); - - String fileName = timePrefix + sheetInMap.getSheetName() + "-" + lastFileName + ".xlsx"; - File file = new File(path + fileName); - //String path = this.getClass().getClassLoader().getResource("").getPath() + "report/vuln/"; - if (!file.exists()) { - file1.mkdirs(); - } - try (FileOutputStream fileOutputStream = new FileOutputStream(file);) { - // 导出 - workbookInMap.write(fileOutputStream); - workbookInMap.close(); - } catch (IOException e) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "E", null, null, null, false, "漏洞报告无法写入文件,异常消息:" + e.getMessage(), date)); - logger.info("File2disk Vuln owner Exception here: " + e); - } - - projectInfoNameAndFileMap.put(projectInfoName, file); - - } - - //将文件与项目人联系方式绑定 - Map> projectInfoAndContactWithFilelistMap = new LinkedHashMap<>(); - Set> entrySet = projectInfoNameAndFileMap.entrySet(); - for (Map.Entry entry : entrySet) { - String projectInfoName = entry.getKey(); - File file = (File) entry.getValue(); - List contactList = contactMap.get(projectInfoName); - if (!Objects.isNull(contactList)) { - for (String contactNameEmailString : contactList) { - if (!projectInfoAndContactWithFilelistMap.containsKey(contactNameEmailString)) { - List fileList = new LinkedList<>(); - fileList.add(file); - projectInfoAndContactWithFilelistMap.put(contactNameEmailString, fileList); - } else { - List fileList = projectInfoAndContactWithFilelistMap.get(contactNameEmailString); - fileList.add(file); - projectInfoAndContactWithFilelistMap.put(contactNameEmailString, fileList); - } - } - } - } - totalResultMap.clear(); - //发邮件 - NotifyUtil.sendMail2ProjectOwner(sendFrom, sendmailconfigVulnsubject, sendmailconfigVulncontent, projectInfoAndContactWithFilelistMap, mailSender, notifylogService, idWorker); - } - } catch (Exception e) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "E", null, null, null, false, "默认提醒邮箱漏洞报告发送失败,异常消息:" + e.getMessage(), date)); - logger.error("VulnNotifyScheduler Exception here: " + ExcpUtil.buildErrorMessage(e)); - } - notifylogService.batchAdd(notifyLogList); - } - - public void db2Excel(long pageSize, String author, String firstFileName, String lastFileName, String[] titleArraysWithContact, File file, String sendtorisk,List notifyLogList) { - //分页导出资产数据 - long allAssetsCount = taskipService.findAllVulnsCount(); - if (allAssetsCount > 0) { - XSSFWorkbook workbook1 = new XSSFWorkbook(); - POIXMLProperties xmlProps = workbook1.getProperties(); - POIXMLProperties.CoreProperties coreProps = xmlProps.getCoreProperties(); - coreProps.setCreator(author); - Workbook workbook = new SXSSFWorkbook(workbook1, 100, true, true); - - try (FileOutputStream fileOutputStream = new FileOutputStream(file);) { - //long pageSize = 100; - - //100条测试用 - //long allAssetsCount = 100; - //long pageSize = 50; - long loopSize = (long) Math.ceil(allAssetsCount / (double) pageSize); - long offset = 0; - int index = 1; - int sheetRow = 0; - int sheetTab = 1; - - for (long step = 0; step < loopSize; step++) { - //List> allVulnsByPage = taskipService.findAllAssetsByPage(offset, pageSize); - List> allVulnsByPage = taskipService.findAllVulnsByPage(offset, pageSize); - for (List singleResultList : allVulnsByPage) { - String tvrisk = singleResultList.get(3); - //risk在db中才写到表格 - if (sendtorisk.contains(tvrisk)) { - String sheetName = firstFileName + lastFileName + "-" + sheetTab; - Sheet sheet = workbook.getSheet(sheetName); - if (Objects.isNull(sheet)) { - sheet = workbook.createSheet(sheetName); - NotifyUtil.setSheetHeaderTitle(sheet, titleArraysWithContact); - } - //最大行1048576-1,分页 - if (sheetRow == 1048575) { - sheetTab++; - sheet = workbook.createSheet(firstFileName + lastFileName + "-" + sheetTab); - //设置标题 - NotifyUtil.setSheetHeaderTitle(sheet, titleArraysWithContact); - sheetRow = 0; - index = 1; - } - - if ("所有".equals(firstFileName)) { - index = writeCellData(sheet, index, singleResultList, true); - sheetRow++; - } - if ("有项目联系人".equals(firstFileName) && !Objects.isNull(singleResultList.get(21))) { - index = writeCellData(sheet, index, singleResultList, true); - sheetRow++; - } - if ("无项目联系人".equals(firstFileName) && Objects.isNull(singleResultList.get(21))) { - index = writeCellData(sheet, index, singleResultList, true); - sheetRow++; - } - } - } - offset = offset + pageSize; - } - - fileOutputStream.flush(); - workbook.write(fileOutputStream); - workbook.close(); - } catch (IOException e) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "E", null, null, null, false, "漏洞导出到Excel失败,异常消息:" + e.getMessage(), new Date())); - logger.info("vuln report 2Excel Exception here: " + e); - } - } - } - - //设置内容 - public int writeCellData(Sheet sheet, int index, List singleResultList, boolean allData) { - Row row; - row = sheet.createRow(index++); - NotifyUtil.setCellData(sheet, row, 0, singleResultList.get(0)); - NotifyUtil.setCellData(sheet, row, 1, singleResultList.get(1)); - NotifyUtil.setCellData(sheet, row, 2, singleResultList.get(2)); - NotifyUtil.setCellData(sheet, row, 3, singleResultList.get(3)); - NotifyUtil.setCellData(sheet, row, 4, singleResultList.get(4)); - NotifyUtil.setCellData(sheet, row, 5, singleResultList.get(5)); - NotifyUtil.setCellData(sheet, row, 6, singleResultList.get(6)); - NotifyUtil.setCellData(sheet, row, 7, singleResultList.get(7)); - NotifyUtil.setCellData(sheet, row, 8, singleResultList.get(8)); - NotifyUtil.setCellData(sheet, row, 9, singleResultList.get(9)); - NotifyUtil.setCellData(sheet, row, 10, singleResultList.get(10)); - NotifyUtil.setCellData(sheet, row, 11, singleResultList.get(11)); - NotifyUtil.setCellData(sheet, row, 12, singleResultList.get(12)); - NotifyUtil.setCellData(sheet, row, 13, singleResultList.get(13)); - NotifyUtil.setCellData(sheet, row, 14, singleResultList.get(14)); - NotifyUtil.setCellData(sheet, row, 15, singleResultList.get(15)); - NotifyUtil.setCellData(sheet, row, 16, singleResultList.get(16)); - NotifyUtil.setCellData(sheet, row, 17, singleResultList.get(17)); - NotifyUtil.setCellData(sheet, row, 18, singleResultList.get(18)); - NotifyUtil.setCellData(sheet, row, 19, singleResultList.get(19)); - NotifyUtil.setCellData(sheet, row, 20, singleResultList.get(20)); - - if (allData && !Objects.isNull(singleResultList.get(21))) { - NotifyUtil.setCellData(sheet, row, 21, singleResultList.get(21)); - NotifyUtil.setCellData(sheet, row, 22, singleResultList.get(22)); - NotifyUtil.setCellData(sheet, row, 23, singleResultList.get(23)); - NotifyUtil.setCellData(sheet, row, 24, singleResultList.get(24)); - } - return index; - } - -} diff --git a/center/src/main/java/com/tiji/center/schedule/quartz/QuartzJob.java b/center/src/main/java/com/tiji/center/schedule/quartz/QuartzJob.java deleted file mode 100755 index 13d205b..0000000 --- a/center/src/main/java/com/tiji/center/schedule/quartz/QuartzJob.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.tiji.center.schedule.quartz; - -import org.quartz.Job; -import org.quartz.JobKey; - -import java.util.Map; - -public class QuartzJob { - - - private JobKey jobKey;//job名字和分组名 - private String cronExpression;//cron表达式 - private Map jobDataMap;//元数据 - private Class jobClass;//执行的类 - - public QuartzJob() { - } - - public QuartzJob(JobKey jobKey, String cronExpression, Map jobDataMap, Class jobClass) { - this.jobKey = jobKey; - this.cronExpression = cronExpression; - this.jobDataMap = jobDataMap; - this.jobClass = jobClass; - } - - public JobKey getJobKey() { - return jobKey; - } - - public void setJobKey(JobKey jobKey) { - this.jobKey = jobKey; - } - - public String getCronExpression() { - return cronExpression; - } - - public void setCronExpression(String cronExpression) { - this.cronExpression = cronExpression; - } - - public Map getJobDataMap() { - return jobDataMap; - } - - public void setJobDataMap(Map jobDataMap) { - this.jobDataMap = jobDataMap; - } - - public Class getJobClass() { - return jobClass; - } - - public void setJobClass(Class jobClass) { - this.jobClass = jobClass; - } -} diff --git a/center/src/main/java/com/tiji/center/schedule/quartz/QuartzJobService.java b/center/src/main/java/com/tiji/center/schedule/quartz/QuartzJobService.java deleted file mode 100755 index 665a58c..0000000 --- a/center/src/main/java/com/tiji/center/schedule/quartz/QuartzJobService.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.tiji.center.schedule.quartz; - -import ch.qos.logback.classic.util.LogbackMDCAdapter; -import org.quartz.*; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.LinkedHashMap; -import java.util.Map; - - -@Service -public class QuartzJobService { - - @Autowired - private Scheduler scheduler; - private static final Map jobStateMap = new LinkedHashMap<>(); - - static { - jobStateMap.put("BLOCKED", "阻塞"); - jobStateMap.put("COMPLETE", "完成"); - jobStateMap.put("ERROR", "出错"); - jobStateMap.put("NONE", ""); - jobStateMap.put("NORMAL", "正常"); - jobStateMap.put("PAUSED", "暂停"); - - jobStateMap.put("4", "阻塞"); - jobStateMap.put("2", "完成"); - jobStateMap.put("3", "出错"); - jobStateMap.put("-1", ""); - jobStateMap.put("0", "正常"); - jobStateMap.put("1", "暂停"); - } - - /** - * scheduleJob - * - * @param quartzJob - */ - public void scheduleJob(QuartzJob quartzJob) throws SchedulerException { - JobKey jobKey = quartzJob.getJobKey(); - JobDataMap jobDataMap = getJobDataMap(quartzJob.getJobDataMap()); - Class jobClass = quartzJob.getJobClass(); - String cron = quartzJob.getCronExpression(); - JobDetail jobDetail = getJobDetail(jobKey, jobDataMap, jobClass); - Trigger trigger = getTrigger(jobKey, jobDataMap, cron); - scheduler.scheduleJob(jobDetail, trigger); - } - - /** - * deleteJob - * - * @param jobKey - */ - public void deleteJob(JobKey jobKey) throws SchedulerException { - scheduler.deleteJob(jobKey); - } - - - /** - * getJobDetail - * - * @param jobKey - * @param jobDataMap - * @param jobClass - */ - public JobDetail getJobDetail(JobKey jobKey, JobDataMap jobDataMap, Class jobClass) { - return JobBuilder.newJob(jobClass) - .withIdentity(jobKey) - .setJobData(jobDataMap) - .usingJobData(jobDataMap) - .requestRecovery() - .storeDurably() - .build(); - } - - - /** - * getTrigger - * - * @param jobKey - * @param jobDataMap - * @param cronExpression - */ - public Trigger getTrigger(JobKey jobKey, JobDataMap jobDataMap, String cronExpression) { - return TriggerBuilder.newTrigger() - .withIdentity(jobKey.getName(), jobKey.getGroup()) - .withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)) - .usingJobData(jobDataMap) - .build(); - } - - - public JobDataMap getJobDataMap(Map dataMap) { - return dataMap == null ? new JobDataMap() : new JobDataMap(dataMap); - } - - - /** - * @param jobName 根据jobName获取job的状态 - */ - public String getTriggerStates(String jobName) throws SchedulerException { - String jobKeyName = "jobKeyName_" + jobName; - String jobKeyGroup = "jobKeyGroup_" + jobName; - JobKey jobKey = JobKey.jobKey(jobKeyName, jobKeyGroup); - TriggerKey triggerKey = TriggerKey.triggerKey(jobKey.getName(), jobKey.getGroup()); - String state = String.valueOf(scheduler.getTriggerState(triggerKey)); - return jobStateMap.get(state); - } -} diff --git a/center/src/main/java/com/tiji/center/service/AgentService.java b/center/src/main/java/com/tiji/center/service/AgentService.java deleted file mode 100755 index d9bfdab..0000000 --- a/center/src/main/java/com/tiji/center/service/AgentService.java +++ /dev/null @@ -1,197 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.AgentDao; -import com.tiji.center.pojo.Agent; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * agent服务层 - * - * @author 贰拾壹 - */ -@Service -public class AgentService { - - @Autowired - private AgentDao agentDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return agentDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return agentDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return agentDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Agent findById(String id) { - return agentDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param agent - */ - public void add(Agent agent) { - if (Objects.isNull(agent.getId())) { - agent.setId(idWorker.nextId() + ""); - } - if (Objects.isNull(agent.getOnline())) { - agent.setOnline(false); - } - agentDao.save(agent); - } - - /** - * 修改 - * - * @param agent - */ - public void update(Agent agent) { - agentDao.save(agent); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - agentDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - agentDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // agent编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // agent名称 - if (searchMap.get("name") != null && !"".equals(searchMap.get("name"))) { - predicateList.add(cb.like(root.get("name").as(String.class), "%" + searchMap.get("name") + "%")); - } - // nmap路径 - if (searchMap.get("nmappath") != null && !"".equals(searchMap.get("nmappath"))) { - predicateList.add(cb.like(root.get("nmappath").as(String.class), "%" + searchMap.get("nmappath") + "%")); - } - // mass路径 - if (searchMap.get("masspath") != null && !"".equals(searchMap.get("masspath"))) { - predicateList.add(cb.like(root.get("masspath").as(String.class), "%" + searchMap.get("masspath") + "%")); - } - // ip地址 - if (searchMap.get("ipaddress") != null && !"".equals(searchMap.get("ipaddress"))) { - predicateList.add(cb.like(root.get("ipaddress").as(String.class), "%" + searchMap.get("ipaddress") + "%")); - } - //在线 - if (searchMap.get("online") != null && !"".equals(searchMap.get("online"))) { - predicateList.add(cb.equal(root.get("online").as(Boolean.class), (searchMap.get("online")))); - } - // 超时次数 - if (searchMap.get("timeouts") != null && !"".equals(searchMap.get("timeouts"))) { - predicateList.add(cb.like(root.get("timeouts").as(String.class), "%" + searchMap.get("timeouts") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[0])); - - }; - - } - - /** - * 根据name,ipaddress查询agent - * - * @param name - * @return - */ - public Agent findByNameAndIpaddress(String name, String ipaddress) { - return agentDao.findByNameAndIpaddress(name, ipaddress); - } - - - /** - * 将agent的online标志置false - * - * @return - */ - @Transactional(value = "masterTransactionManager") - public void updateAgentSetOnlineFalse() { - agentDao.updateAgentSetOnlineFalse(); - } - - /** - * 查询online的agent - * - * @return - */ - public List findAllByOnline(Boolean online) { - return agentDao.findAllByOnline(online); - } - -} diff --git a/center/src/main/java/com/tiji/center/service/AssetipService.java b/center/src/main/java/com/tiji/center/service/AssetipService.java deleted file mode 100755 index 94f7b47..0000000 --- a/center/src/main/java/com/tiji/center/service/AssetipService.java +++ /dev/null @@ -1,361 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.AssetipDao; -import com.tiji.center.pojo.Assetip; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.*; - -/** - * assetip服务层 - * - * @author 贰拾壹 - */ -@Service -public class AssetipService { - - @Autowired - private AssetipDao assetipDao; - - @Autowired - private IdWorker idWorker; - - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return assetipDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return assetipDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return assetipDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Assetip findById(String id) { - return assetipDao.findById(id).isPresent() ? assetipDao.findById(id).get() : null; - } - - /** - * 增加 - * - * @param assetip - */ - public void add(Assetip assetip) { - if (Objects.isNull(assetip.getId())) { - assetip.setId(idWorker.nextId() + ""); - } - if (Objects.isNull(assetip.getCheckwhitelist())) { - assetip.setCheckwhitelist(false); - } - if (Objects.isNull(assetip.getAssetnotifywhitelist())) { - assetip.setAssetnotifywhitelist(false); - } - assetipDao.save(assetip); - } - - /** - * 修改 - * - * @param assetip - */ - public void update(Assetip assetip) { - assetipDao.save(assetip); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - assetipDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - assetipDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 资产ip编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 项目信息编号 - if (searchMap.get("projectinfoid") != null && !"".equals(searchMap.get("projectinfoid"))) { - predicateList.add(cb.equal(root.get("projectinfoid").as(String.class), searchMap.get("projectinfoid"))); - } - - // ipv4精准 - if (searchMap.get("ipv4") != null && !"".equals(searchMap.get("ipv4"))) { - predicateList.add(cb.equal(root.get("ipaddressv4").as(String.class), searchMap.get("ipv4"))); - } - - // ipv4地址 - if (searchMap.get("ipaddressv4") != null && !"".equals(searchMap.get("ipaddressv4"))) { - predicateList.add(cb.like(root.get("ipaddressv4").as(String.class), "%" + searchMap.get("ipaddressv4") + "%")); - } - // ipv6地址 - if (searchMap.get("ipaddressv6") != null && !"".equals(searchMap.get("ipaddressv6"))) { - predicateList.add(cb.like(root.get("ipaddressv6").as(String.class), "%" + searchMap.get("ipaddressv6") + "%")); - } - // 备注 - if (searchMap.get("remark") != null && !"".equals(searchMap.get("remark"))) { - predicateList.add(cb.like(root.get("remark").as(String.class), "%" + searchMap.get("remark") + "%")); - } - //安全检测白名单 - if (searchMap.get("checkwhitelist") != null && !"".equals(searchMap.get("checkwhitelist"))) { - predicateList.add(cb.equal(root.get("checkwhitelist").as(Boolean.class), (searchMap.get("checkwhitelist")))); - } - //资产提醒白名单 - if (searchMap.get("assetnotifywhitelist") != null && !"".equals(searchMap.get("assetnotifywhitelist"))) { - predicateList.add(cb.equal(root.get("assetnotifywhitelist").as(Boolean.class), searchMap.get("assetnotifywhitelist"))); - } - //ip发现时间 - if (searchMap.get("activetime") != null && !"".equals(searchMap.get("activetime"))) { - List activetimeList = (List) searchMap.get("activetime"); - //开始 - predicateList.add(cb.greaterThanOrEqualTo(root.get("activetime").as(String.class), activetimeList.get(0))); - //结束 - predicateList.add(cb.lessThanOrEqualTo(root.get("activetime").as(String.class), activetimeList.get(1))); - //predicateList.add(cb.like(root.get("activetime").as(String.class), "%" + searchMap.get("activetime") + "%")); - } - //ip下线时间 - if (searchMap.get("passivetime") != null && !"".equals(searchMap.get("passivetime"))) { - List passivetimeList = (List) searchMap.get("passivetime"); - //开始 - predicateList.add(cb.greaterThanOrEqualTo(root.get("passivetime").as(String.class), passivetimeList.get(0))); - //结束 - predicateList.add(cb.lessThanOrEqualTo(root.get("passivetime").as(String.class), passivetimeList.get(1))); - //predicateList.add(cb.like(root.get("passivetime").as(String.class), "%" + searchMap.get("passivetime") + "%")); - } - // 标签bitmap - if (!StringUtils.isEmpty(searchMap.get("tabbitmap"))) { - predicateList.add(cb.like(root.get("tabbitmap").as(String.class), "%" + searchMap.get("tabbitmap") + "%")); - } - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - - /** - * 批量增加 - * - * @param assetipList - */ - public void batchAdd(List assetipList) { - assetipDao.saveAll(assetipList); - } - - - /** - * 查询所有Passivetime为空的ipv4 - * - * @return Assetip list - */ - public List findAllIpv4ByPassivetimeIsNull() { - return assetipDao.findAllByPassivetimeIsNull(); - } - - /** - * 查询所有未下线的ipv4 - * - * @return String list - */ - public List findAllDistinctIpaddressv4ListAndPassivetimeIsNull() { - return assetipDao.findAllDistinctIpaddressv4ListAndPassivetimeIsNull(); - } - - - /** - * 根据ip查询passivetime为空的ip - * - * @return Assetip - */ - public Assetip findByIpaddressv4AndPassivetimeIsNull(String ip) { - return assetipDao.findByIpaddressv4AndPassivetimeIsNull(ip); - } - - /** - * 根据ip查询passivetime为空的ip - * - * @return List - */ - //for test - //getContactByIp - public List findContactInfoByIpv4(String ip) { - return assetipDao.findContactInfoByIpv4(ip); - } - - /** - * 根据ID查询未下线且不在check白名单的ip - * - * @param id - * @return - */ - public Assetip findByIdAndCheckwhitelistIsFalseAndPassivetimeIsNull(String id) { - return assetipDao.findByIdAndCheckwhitelistIsFalseAndPassivetimeIsNull(id); - } - - - /** - * 修改 - * - * @param projectinfoid - * @param checkwhitelist - * @param assetNotifywhitelist - */ - @Transactional(value = "masterTransactionManager") - public void updateByProjectinfoidAndCheckwhitelistAndAssetNotifywhitelist(String projectinfoid, Boolean checkwhitelist, Boolean assetNotifywhitelist) { - assetipDao.updateByProjectinfoidAndCheckwhitelistAndAssetNotifywhitelist(projectinfoid, checkwhitelist, assetNotifywhitelist); - } - - /** - * 根据id数组查询 - * - * @param ids - * @return - */ - public List findByIds(String[] ids) { - List assetIpIdAndIpList = new ArrayList<>(); - for (String assetIpId : ids) { - Assetip assetip = findById(assetIpId); - if (Objects.isNull(assetip)) { - assetIpIdAndIpList.add(assetIpId + "-" + null); - } else { - assetIpIdAndIpList.add(assetIpId + "-" + assetip.getIpaddressv4()); - } - } - return assetIpIdAndIpList.isEmpty() ? null : assetIpIdAndIpList; - } - - - /** - * 根据projectinfoid将projectinfoid置空 - * - * @param projectinfoid - * @return - */ - @Transactional(value = "masterTransactionManager") - public void updateAssetipByProjectinfoidSetProjectinfoid2Null(String projectinfoid) { - assetipDao.updateAssetipByProjectinfoidSetProjectinfoid2Null(projectinfoid); - } - - /** - * 将所有projectinfoid置空 - */ - @Transactional(value = "masterTransactionManager") - public void updateAssetipSetProjectinfoidNull() { - assetipDao.updateAssetipSetProjectinfoidNull(); - } - - /** - * 根据id数组查询数量 - * - * @param ids - * @return - */ - public List findCountByIds(List ids) { - List idAndCount = new ArrayList<>(); - List portCountList = assetipDao.findPortCountByIds(ids); - List portCountOnlineList = assetipDao.findPortCountOnlineByIds(ids); - List vulnCountList = assetipDao.findVulnCountByIds(ids); - List vulnCountOnlineList = assetipDao.findVulnCountOnlineByIds(ids); - - Map idPortCountMap = new LinkedHashMap<>(); - Map idPortCountOnlineMap = new LinkedHashMap<>(); - Map idVulnCountMap = new LinkedHashMap<>(); - Map idVulnCountOnlineMap = new LinkedHashMap<>(); - // id - portcount - portCountList.parallelStream().forEach(temp -> { - String id = temp.split(",")[0]; - String portCount = temp.split(",")[1]; - idPortCountMap.put(id, portCount); - }); - portCountOnlineList.parallelStream().forEach(temp -> { - String id = temp.split(",")[0]; - String portCount = temp.split(",")[1]; - idPortCountOnlineMap.put(id, portCount); - }); - vulnCountList.parallelStream().forEach(temp -> { - String id = temp.split(",")[0]; - String vulnCount = temp.split(",")[1]; - idVulnCountMap.put(id, vulnCount); - }); - vulnCountOnlineList.parallelStream().forEach(temp -> { - String id = temp.split(",")[0]; - String vulnCount = temp.split(",")[1]; - idVulnCountOnlineMap.put(id, vulnCount); - }); - - // id - vuln count - ids.forEach(id -> { - String temp; - temp = idPortCountMap.getOrDefault(id, "0"); - temp += ":" + idPortCountOnlineMap.getOrDefault(id, "0"); - temp += ":" + idVulnCountMap.getOrDefault(id, "0"); - temp += ":" + idVulnCountOnlineMap.getOrDefault(id, "0"); - idAndCount.add(temp); - - }); - return idAndCount.isEmpty() ? null : idAndCount; - } - - -} diff --git a/center/src/main/java/com/tiji/center/service/AssetportService.java b/center/src/main/java/com/tiji/center/service/AssetportService.java deleted file mode 100755 index 0d703db..0000000 --- a/center/src/main/java/com/tiji/center/service/AssetportService.java +++ /dev/null @@ -1,406 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.AssetportDao; -import com.tiji.center.pojo.Assetport; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.*; - -/** - * assetport服务层 - * - * @author 贰拾壹 - */ -@Service -public class AssetportService { - - @Autowired - private AssetportDao assetportDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return assetportDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return assetportDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return assetportDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Assetport findById(String id) { - return assetportDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param assetport - */ - public void add(Assetport assetport) { - if (Objects.isNull(assetport.getId())) { - assetport.setId(idWorker.nextId() + ""); - } - if (Objects.isNull(assetport.getCheckwhitelist())) { - assetport.setCheckwhitelist(false); - } - if (Objects.isNull(assetport.getAssetnotifywhitelist())) { - assetport.setAssetnotifywhitelist(false); - } - assetportDao.save(assetport); - } - - /** - * 修改 - * - * @param assetport - */ - public void update(Assetport assetport) { - assetportDao.save(assetport); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - assetportDao.deleteById(id); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 端口编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 资产ip编号 - //if (searchMap.get("assetipid") != null && !"".equals(searchMap.get("assetipid"))) { - // predicateList.add(cb.equal(root.get("assetipid").as(String.class), searchMap.get("assetipid"))); - //} - if (searchMap.get("assetipid") != null && !"".equals(searchMap.get("assetipid"))) { - predicateList.add(cb.in(root.get("assetipid")).value(searchMap.get("assetipid"))); - } - // 端口 - if (searchMap.get("port") != null && !"".equals(searchMap.get("port"))) { - predicateList.add(cb.like(root.get("port").as(String.class), "%" + searchMap.get("port") + "%")); - } - // 端口协议 - if (searchMap.get("protocol") != null && !"".equals(searchMap.get("protocol"))) { - predicateList.add(cb.like(root.get("protocol").as(String.class), "%" + searchMap.get("protocol") + "%")); - } - // 端口开放状态 - if (searchMap.get("state") != null && !"".equals(searchMap.get("state"))) { - predicateList.add(cb.like(root.get("state").as(String.class), "%" + searchMap.get("state") + "%")); - } - // 端口服务 - if (searchMap.get("service") != null && !"".equals(searchMap.get("service"))) { - predicateList.add(cb.like(root.get("service").as(String.class), "%" + searchMap.get("service") + "%")); - } - // 服务版本 - if (searchMap.get("version") != null && !"".equals(searchMap.get("version"))) { - predicateList.add(cb.like(root.get("version").as(String.class), "%" + searchMap.get("version") + "%")); - } - //安全检测白名单 - if (searchMap.get("checkwhitelist") != null && !"".equals(searchMap.get("checkwhitelist"))) { - predicateList.add(cb.equal(root.get("checkwhitelist").as(Boolean.class), searchMap.get("checkwhitelist"))); - } - //资产提醒白名单 - if (searchMap.get("assetnotifywhitelist") != null && !"".equals(searchMap.get("assetnotifywhitelist"))) { - predicateList.add(cb.equal(root.get("assetnotifywhitelist").as(Boolean.class), searchMap.get("assetnotifywhitelist"))); - } - - //端口发现时间 - if (searchMap.get("uptime") != null && !"".equals(searchMap.get("uptime"))) { - List uptimeList = (List) searchMap.get("uptime"); - //开始 - predicateList.add(cb.greaterThanOrEqualTo(root.get("uptime").as(String.class), uptimeList.get(0))); - //结束 - predicateList.add(cb.lessThanOrEqualTo(root.get("uptime").as(String.class), uptimeList.get(1))); - } - - //端口关闭时间 - if (searchMap.get("downtime") != null && !"".equals(searchMap.get("downtime"))) { - List downtimeList = (List) searchMap.get("downtime"); - //开始 - predicateList.add(cb.greaterThanOrEqualTo(root.get("downtime").as(String.class), downtimeList.get(0))); - //结束 - predicateList.add(cb.lessThanOrEqualTo(root.get("downtime").as(String.class), downtimeList.get(1))); - } - //端口修改时间 - if (searchMap.get("changedtime") != null && !"".equals(searchMap.get("changedtime"))) { - List changedtimeList = (List) searchMap.get("changedtime"); - //开始 - predicateList.add(cb.greaterThanOrEqualTo(root.get("changedtime").as(String.class), changedtimeList.get(0))); - //结束 - predicateList.add(cb.lessThanOrEqualTo(root.get("changedtime").as(String.class), changedtimeList.get(1))); - } - - // 标签bitmap - if (!StringUtils.isEmpty(searchMap.get("tabbitmap"))) { - predicateList.add(cb.like(root.get("tabbitmap").as(String.class), "%" + searchMap.get("tabbitmap") + "%")); - } - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - - /** - * 批量增加 - * - * @param portList - */ - public void batchAdd(List portList) { - assetportDao.saveAll(portList); - } - - /** - * 根据assetipid,port查询未下线的端口 - * - * @param assetipid - * @param port - * @return Assetport - */ - public Assetport findByAssetipidAndPortAndDowntimeIsNull(String assetipid, String port) { - return assetportDao.findByAssetipidAndPortAndDowntimeIsNull(assetipid, port); - } - - /** - * 根据id,assetipid查询未下线的端口 - * - * @param - * @param id - * @return assetipid - */ - public Assetport findByIdAndAndAssetipidAndDowntimeIsNull(String id, String assetipid) { - return assetportDao.findByIdAndAndAssetipidAndDowntimeIsNull(id, assetipid); - } - - /** - * 根据assetipid所有查询未下线的端口 - * - * @param assetipid - * @return List - */ - public List findAllByAssetipidAndDowntimeIsNull(String assetipid) { - return assetportDao.findAllByAssetipidAndDowntimeIsNull(assetipid); - } - - /** - * 根据service查询未下线的端口 - * - * @param assetService - * @return List - */ - public List findByServiceLikeAndDowntimeIsNull(String assetService) { - return assetportDao.findByServiceLikeAndDowntimeIsNull(assetService); - } - - /** - * 根据version查询未下线的端口 - * - * @param assetVersion - * @return List - */ - public List findByVersionLikeAndDowntimeIsNull(String assetVersion) { - return assetportDao.findByVersionLikeAndDowntimeIsNull(assetVersion); - } - - - /** - * 查询所有service为空且未下线的端口 - * - * @return - */ - public List findAllByServiceAndServiceIsNullAndCheckwhitelistIsFalseAndDowntimeIsNull(String service) { - return assetportDao.findAllByServiceAndServiceIsNullAndCheckwhitelistIsFalseAndDowntimeIsNull(service); - } - - /** - * 查询所有version为空且未下线的端口 - * - * @return - */ - public List findAllByVersionAndServiceIsNullAndCheckwhitelistIsFalseAndDowntimeIsNull(String version) { - return assetportDao.findAllByVersionAndServiceIsNullAndCheckwhitelistIsFalseAndDowntimeIsNull(version); - } - - - public List findByVersionLikeAndDowntimeIsNullAndCheckwhitelistIsFalseAndStateEquals(String versionName, String state) { - return assetportDao.findByVersionLikeAndDowntimeIsNullAndCheckwhitelistIsFalseAndStateEquals(versionName, state); - } - - public List findByServiceLikeAndDowntimeIsNullAndCheckwhitelistIsFalseAndStateEquals(String serviceName, String state) { - return assetportDao.findByServiceLikeAndDowntimeIsNullAndCheckwhitelistIsFalseAndStateEquals(serviceName, state); - } - - /** - * 根据id数组查询 - * - * @param ids - * @return - */ - public List findByIds(String[] ids) { - List assetPortIdAndAssetIpIdList = new ArrayList<>(); - - for (String assetportid : ids) { - Assetport assetport = findById(assetportid); - if (Objects.isNull(assetport)) { - assetPortIdAndAssetIpIdList.add(assetportid + "-" + null + "-" + null); - } else { - assetPortIdAndAssetIpIdList.add(assetportid + "-" + assetport.getAssetipid() + "-" + assetport.getPort()); - } - } - return assetPortIdAndAssetIpIdList.isEmpty() ? null : assetPortIdAndAssetIpIdList; - } - - /** - * 根据assetipid批量删除 - * - * @param assetipid - */ - @Transactional(value = "masterTransactionManager") - public List deleteAllByAssetipid(String assetipid) { - return assetportDao.deleteAllByAssetipid(assetipid); - } - - - /** - * 查询service并去重 - * - * @return List - */ - public List findAllDistinctService() { - return assetportDao.findAllDistinctService(); - } - - /** - * 查询version并去重 - * - * @return List - */ - public List findAllDistinctVersion() { - return assetportDao.findAllDistinctVersion(); - } - - /** - * 根据assetipid查询 - * - * @param assetipid assetipid - * @return - */ - - public List findAllByAssetipid(String assetipid) { - return assetportDao.findAllByAssetipid(assetipid); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - assetportDao.deleteAllByIds(ids); - } - - /** - * 根据id数组查询数量 - * - * @param ids - * @return - */ - public List findCountByIds(List ids) { - List idAndCount = new ArrayList<>(); - List vulnCountList = assetportDao.findVulnCountByIds(ids); - List vulnCountOnlineList = assetportDao.findVulnCountOnlineByIds(ids); - - Map idVulnCountMap = new LinkedHashMap<>(); - Map idVulnCountOnlineMap = new LinkedHashMap<>(); - - vulnCountList.parallelStream().forEach(temp -> { - String id = temp.split(",")[0]; - String vulnCount = temp.split(",")[1]; - idVulnCountMap.put(id, vulnCount); - }); - vulnCountOnlineList.parallelStream().forEach(temp -> { - String id = temp.split(",")[0]; - String vulnCount = temp.split(",")[1]; - idVulnCountOnlineMap.put(id, vulnCount); - }); - - // id - vuln count - vuln count online - ids.forEach(id -> { - String temp; - temp = idVulnCountMap.getOrDefault(id, "0"); - temp += ":" + idVulnCountOnlineMap.getOrDefault(id, "0"); - idAndCount.add(temp); - - }); - return idAndCount.isEmpty() ? null : idAndCount; - } - - - /** - * 根据id将中间表的端口编号置空 - * - * @param id - * @return - */ - @Transactional(value = "masterTransactionManager") - public void updateMiddByAssetportidSetAssetportid2Null(String id) { - assetportDao.updateMiddByAssetportidSetAssetportid2Null(id); - } -} diff --git a/center/src/main/java/com/tiji/center/service/CategorysecondService.java b/center/src/main/java/com/tiji/center/service/CategorysecondService.java deleted file mode 100755 index f1979e9..0000000 --- a/center/src/main/java/com/tiji/center/service/CategorysecondService.java +++ /dev/null @@ -1,187 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.CategorysecondDao; -import com.tiji.center.pojo.Categorysecond; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * categorysecond服务层 - * - * @author 贰拾壹 - */ -@Service -public class CategorysecondService { - - @Autowired - private CategorysecondDao categorysecondDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return categorysecondDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return categorysecondDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return categorysecondDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Categorysecond findById(String id) { - return categorysecondDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param categorysecond - */ - public void add(Categorysecond categorysecond) { - if (Objects.isNull(categorysecond.getId())) { - categorysecond.setId(idWorker.nextId() + ""); - } - categorysecondDao.save(categorysecond); - } - - /** - * 修改 - * - * @param categorysecond - */ - public void update(Categorysecond categorysecond) { - categorysecondDao.save(categorysecond); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - categorysecondDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - categorysecondDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 漏洞二级分类编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 漏洞一级分类编号 - if (searchMap.get("categorytopid") != null && !"".equals(searchMap.get("categorytopid"))) { - predicateList.add(cb.like(root.get("categorytopid").as(String.class), "%" + searchMap.get("categorytopid") + "%")); - } - // 漏洞二级分类类型 - if (searchMap.get("name") != null && !"".equals(searchMap.get("name"))) { - predicateList.add(cb.like(root.get("name").as(String.class), "%" + searchMap.get("name") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据name查询实体 - * - * @param name - * @return - */ - public Categorysecond findByName(String name) { - return categorysecondDao.findByName(name); - } - - /** - * 根据id数组查询 - * - * @param ids - * @return - */ - public List findByIds(String[] ids) { - List assetIpIdAndIpList = new ArrayList<>(); - for (String id : ids) { - Categorysecond categorysecond = findById(id); - if (Objects.isNull(categorysecond)) { - assetIpIdAndIpList.add(id + "-" + null); - } else { - assetIpIdAndIpList.add(id + "-" + categorysecond.getName()); - } - } - return assetIpIdAndIpList.isEmpty() ? null : assetIpIdAndIpList; - } - - /** - * 根据categorytopid查询实体 - * - * @param categorytopid - * @return - */ - public Categorysecond findByCategorytopid(String categorytopid) { - return categorysecondDao.findByCategorytopid(categorytopid); - } - -} diff --git a/center/src/main/java/com/tiji/center/service/CategorytopService.java b/center/src/main/java/com/tiji/center/service/CategorytopService.java deleted file mode 100755 index 2d5f43c..0000000 --- a/center/src/main/java/com/tiji/center/service/CategorytopService.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.CategorytopDao; -import com.tiji.center.pojo.Categorytop; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * categorytop服务层 - * - * @author 贰拾壹 - */ -@Service -public class CategorytopService { - - @Autowired - private CategorytopDao categorytopDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return categorytopDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return categorytopDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return categorytopDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Categorytop findById(String id) { - return categorytopDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param categorytop - */ - public void add(Categorytop categorytop) { - if (Objects.isNull(categorytop.getId())) { - categorytop.setId(idWorker.nextId() + ""); - } - categorytopDao.save(categorytop); - } - - /** - * 修改 - * - * @param categorytop - */ - public void update(Categorytop categorytop) { - categorytopDao.save(categorytop); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - categorytopDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - categorytopDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 漏洞一级分类编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 漏洞一级分类名称 - if (searchMap.get("name") != null && !"".equals(searchMap.get("name"))) { - predicateList.add(cb.like(root.get("name").as(String.class), "%" + (String) searchMap.get("name") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - - /** - * 根据name查询实体 - * - * @param name - * @return - */ - public Categorytop findByName(String name) { - return categorytopDao.findByName(name); - } -} diff --git a/center/src/main/java/com/tiji/center/service/CheckresultService.java b/center/src/main/java/com/tiji/center/service/CheckresultService.java deleted file mode 100755 index 1fc0c51..0000000 --- a/center/src/main/java/com/tiji/center/service/CheckresultService.java +++ /dev/null @@ -1,283 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.CheckresultDao; -import com.tiji.center.pojo.Assetport; -import com.tiji.center.pojo.Checkresult; -import com.tiji.center.pojo.CheckresultVuln; -import com.tiji.center.pojo.Vuln; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.Path; -import javax.persistence.criteria.Predicate; -import java.util.*; - -/** - * checkresult服务层 - * - * @author 贰拾壹 - */ -@Service -public class CheckresultService { - - @Autowired - private CheckresultDao checkresultDao; - - @Autowired - private IdWorker idWorker; - - @Autowired - private CheckresultVulnService checkresultVulnService; - @Autowired - private VulnService vulnService; - @Autowired - private AssetportService assetportService; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return checkresultDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return checkresultDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return checkresultDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Checkresult findById(String id) { - return checkresultDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param checkresult - */ - public void add(Checkresult checkresult) { - if (Objects.isNull(checkresult.getId())) { - checkresult.setId(idWorker.nextId() + ""); - } - checkresultDao.save(checkresult); - } - - /** - * 修改 - * - * @param checkresult - */ - public void update(Checkresult checkresult) { - checkresultDao.save(checkresult); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - checkresultDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - checkresultDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList<>(); - // 检测结果编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.in(root.get("id")).value(searchMap.get("id"))); - } - // 端口编号 - if (searchMap.get("assetportid") != null && !"".equals(searchMap.get("assetportid"))) { - predicateList.add(cb.in(root.get("assetportid")).value(searchMap.get("assetportid"))); - } - // 检测结果名称 - if (searchMap.get("name") != null && !"".equals(searchMap.get("name"))) { - predicateList.add(cb.like(root.get("name").as(String.class), "%" + searchMap.get("name") + "%")); - } - // 检测结果 - if (searchMap.get("result") != null && !"".equals(searchMap.get("result"))) { - predicateList.add(cb.like(root.get("result").as(String.class), "%" + searchMap.get("result") + "%")); - } - // 缺陷风险级别 - if (searchMap.get("risk") != null && !"".equals(searchMap.get("risk"))) { - predicateList.add(cb.like(root.get("risk").as(String.class), "%" + searchMap.get("risk") + "%")); - } - - //发现时间 - if (searchMap.get("activetime") != null && !"".equals(searchMap.get("activetime"))) { - List activetimeList = (List) searchMap.get("activetime"); - //开始 - predicateList.add(cb.greaterThanOrEqualTo(root.get("activetime").as(String.class), activetimeList.get(0))); - //结束 - predicateList.add(cb.lessThanOrEqualTo(root.get("activetime").as(String.class), activetimeList.get(1))); - } - - //修复时间 - if (searchMap.get("passivetime") != null && !"".equals(searchMap.get("passivetime"))) { - List passivetimeList = (List) searchMap.get("passivetime"); - //开始 - predicateList.add(cb.greaterThanOrEqualTo(root.get("passivetime").as(String.class), passivetimeList.get(0))); - //结束 - predicateList.add(cb.lessThanOrEqualTo(root.get("passivetime").as(String.class), passivetimeList.get(1))); - } - - // 备注 - if (searchMap.get("remark") != null && !"".equals(searchMap.get("remark"))) { - predicateList.add(cb.like(root.get("remark").as(String.class), "%" + searchMap.get("remark") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[0])); - - }; - - } - - /** - * 根据assetPortId、插件Name查询未修复的漏洞端口 - * - * @param assetPortId - * @param pluginName - * @return Checkresult - */ - public Checkresult findByAssetportidAndNameAndPassivetimeIsNull(String assetPortId, String pluginName) { - return checkresultDao.findByAssetportidAndNameAndPassivetimeIsNull(assetPortId, pluginName); - } - - - /** - * 根据name查询实体 - * - * @param name - * @return - */ - public List findAllByName(String name) { - return checkresultDao.findAllByName(name); - } - - - /** - * 根据assetportId批量删除 - * - * @param assetportId - */ - @Transactional(value = "masterTransactionManager") - public List deleteAllByAssetportid(String assetportId) { - return checkresultDao.deleteAllByAssetportid(assetportId); - } - - /** - * 根据assetportid查询 - * - * @param assetportid assetportid - * @return - */ - public List findAllByAssetportid(String assetportid) { - return checkresultDao.findAllByAssetportid(assetportid); - } - - - /** - * 根据ids查询漏洞 - * - * @param ids ids - * @return id-漏洞名称 - */ - public List findAllByIds(String[] ids) { - List resultList = new LinkedList<>(); - for (String id : ids) { - List allByCheckresultid = checkresultVulnService.findAllByCheckresultid(id); - if (!allByCheckresultid.isEmpty()) { - allByCheckresultid.parallelStream().forEach(checkresultVuln -> { - String vulnid = checkresultVuln.getVulnid(); - Vuln vuln = vulnService.findById(vulnid); - if (Objects.isNull(vuln)) { - resultList.add(id + "-" + null); - } else { - resultList.add(id + "-" + vuln.getName()); - } - - }); - } - } - return resultList; - } - - /** - * 根据assetportids查询 - * - * @param assetportids assetportids - * @return - */ - public List findAllByAssetportIds(String[] assetportids) { - List resultList = new LinkedList<>(); - for (String id : assetportids) { - List checkresultList = checkresultDao.findAllByAssetportid(id); - checkresultList.parallelStream().forEach(checkresult -> { - String assetportid = checkresult.getAssetportid(); - Assetport assetport = assetportService.findById(assetportid); - checkresult.setAssetportid(assetport.getPort()); - resultList.add(checkresult); - }); - } - return resultList; - } - - public String findVulNameById(String id) { - List checkresultVulnList = checkresultVulnService.findAllByCheckresultid(id); - String vulnid = checkresultVulnList.get(0).getVulnid(); - return vulnService.findById(vulnid).getName(); - } -} diff --git a/center/src/main/java/com/tiji/center/service/CheckresultVulnService.java b/center/src/main/java/com/tiji/center/service/CheckresultVulnService.java deleted file mode 100755 index 1bb8086..0000000 --- a/center/src/main/java/com/tiji/center/service/CheckresultVulnService.java +++ /dev/null @@ -1,176 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.CheckresultVulnDao; -import com.tiji.center.pojo.CheckresultVuln; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * checkresultVuln服务层 - * - * @author 贰拾壹 - */ -@Service -public class CheckresultVulnService { - - @Autowired - private CheckresultVulnDao checkresultVulnDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return checkresultVulnDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return checkresultVulnDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return checkresultVulnDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public CheckresultVuln findById(String id) { - return checkresultVulnDao.findById(id).isPresent() ? checkresultVulnDao.findById(id).get() : null; - } - - /** - * 增加 - * - * @param checkresultVuln - */ - public void add(CheckresultVuln checkresultVuln) { - if (Objects.isNull(checkresultVuln.getId())) { - checkresultVuln.setId(idWorker.nextId() + ""); - } - checkresultVulnDao.save(checkresultVuln); - } - - /** - * 修改 - * - * @param checkresultVuln - */ - public void update(CheckresultVuln checkresultVuln) { - checkresultVulnDao.save(checkresultVuln); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - checkresultVulnDao.deleteById(id); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.equal(root.get("id").as(String.class), searchMap.get("id"))); - } - // 检测结果编号 - if (searchMap.get("checkresultid") != null && !"".equals(searchMap.get("checkresultid"))) { - predicateList.add(cb.equal(root.get("checkresultid").as(String.class), searchMap.get("checkresultid"))); - } - // 漏洞编号 - if (searchMap.get("vulnid") != null && !"".equals(searchMap.get("vulnid"))) { - predicateList.add(cb.equal(root.get("vulnid").as(String.class), searchMap.get("vulnid"))); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据id数组查询 - * - * @param ids - * @return - */ - public List findByIds(String[] ids) { - List checkresultVulnIdList = new ArrayList<>(); - for (String checkresultid : ids) { - List checkresultVulnList = checkresultVulnDao.findAllByCheckresultid(checkresultid); - if (Objects.isNull(checkresultVulnList)) { - checkresultVulnIdList.add(checkresultid + "-" + null); - } else { - for (CheckresultVuln checkresultVuln : checkresultVulnList) { - checkresultVulnIdList.add(checkresultid + "-" + checkresultVuln.getVulnid()); - } - } - } - return checkresultVulnIdList.isEmpty() ? null : checkresultVulnIdList; - } - - /** - * 删除 - * - * @param checkresultid - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByCheckresultid(String checkresultid) { - checkresultVulnDao.deleteAllByCheckresultid(checkresultid); - } - - public List findAllByCheckresultid(String id) { - return checkresultVulnDao.findAllByCheckresultid(id); - } - - public List findAllCheckResultIdByVulnid(String id) { - return checkresultVulnDao.findAllCheckResultIdByVulnid(id); - } -} diff --git a/center/src/main/java/com/tiji/center/service/ContactProjectinfoService.java b/center/src/main/java/com/tiji/center/service/ContactProjectinfoService.java deleted file mode 100755 index fe7f2e8..0000000 --- a/center/src/main/java/com/tiji/center/service/ContactProjectinfoService.java +++ /dev/null @@ -1,195 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.ContactProjectinfoDao; -import com.tiji.center.pojo.ContactProjectinfo; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * contactProjectinfo服务层 - * - * @author 贰拾壹 - */ -@Service -public class ContactProjectinfoService { - - @Autowired - private ContactProjectinfoDao contactProjectinfoDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return contactProjectinfoDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return contactProjectinfoDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return contactProjectinfoDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public ContactProjectinfo findById(String id) { - return contactProjectinfoDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param contactProjectinfo - */ - public void add(ContactProjectinfo contactProjectinfo) { - if (Objects.isNull(contactProjectinfo.getId())) { - contactProjectinfo.setId(idWorker.nextId() + ""); - } - contactProjectinfoDao.save(contactProjectinfo); - } - - /** - * 修改 - * - * @param contactProjectinfo - */ - public void update(ContactProjectinfo contactProjectinfo) { - contactProjectinfoDao.save(contactProjectinfo); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - contactProjectinfoDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - contactProjectinfoDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 联系编号 - if (searchMap.get("contactid") != null && !"".equals(searchMap.get("contactid"))) { - predicateList.add(cb.equal(root.get("contactid").as(String.class), searchMap.get("contactid"))); - } - // 项目信息编号 - if (searchMap.get("projectinfoid") != null && !"".equals(searchMap.get("projectinfoid"))) { - predicateList.add(cb.equal(root.get("projectinfoid").as(String.class), searchMap.get("projectinfoid"))); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 删除 - * - * @param contactid - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByContactid(String contactid) { - contactProjectinfoDao.deleteAllByContactid(contactid); - } - - /** - * 删除 - * - * @param projectinfoid - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByProjectinfoid(String projectinfoid) { - contactProjectinfoDao.deleteAllByProjectinfoid(projectinfoid); - } - - /** - * 根据projectinfoid查询 - * - * @param projectinfoid - * @return - */ - public List findAllByProjectinfoid(String projectinfoid) { - return contactProjectinfoDao.findAllByProjectinfoid(projectinfoid); - } - - /** - * 根据contactid、projectinfoid查询 - * - * @param contactid - * @param projectinfoid - * @return - */ - public ContactProjectinfo findByContactidAndProjectinfoid(String contactid, String projectinfoid) { - return contactProjectinfoDao.findByContactidAndProjectinfoid(contactid, projectinfoid); - } - - @Transactional(value = "masterTransactionManager") - public void deleteByContactidAndProjectinfoid(String id, String contactid) { - contactProjectinfoDao.deleteByContactidAndProjectinfoid(id, contactid); - } - - -} diff --git a/center/src/main/java/com/tiji/center/service/ContactService.java b/center/src/main/java/com/tiji/center/service/ContactService.java deleted file mode 100755 index ea1855b..0000000 --- a/center/src/main/java/com/tiji/center/service/ContactService.java +++ /dev/null @@ -1,168 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.ContactDao; -import com.tiji.center.pojo.Contact; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * contact服务层 - * - * @author 贰拾壹 - */ -@Service -public class ContactService { - - @Autowired - private ContactDao contactDao; - - @Autowired - private IdWorker idWorker; - - @Autowired - private ContactProjectinfoService contactProjectinfoService; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return contactDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return contactDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return contactDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Contact findById(String id) { - return contactDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param contact - */ - public void add(Contact contact) { - if (Objects.isNull(contact.getId())) { - contact.setId(idWorker.nextId() + ""); - } - contactDao.save(contact); - } - - /** - * 修改 - * - * @param contact - */ - public void update(Contact contact) { - contactDao.save(contact); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - contactDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - contactDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (root, query, cb) -> { - List predicateList = new ArrayList<>(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 联系人 - if (searchMap.get("name") != null && !"".equals(searchMap.get("name"))) { - predicateList.add(cb.like(root.get("name").as(String.class), "%" + searchMap.get("name") + "%")); - } - // 邮箱 - if (searchMap.get("email") != null && !"".equals(searchMap.get("email"))) { - predicateList.add(cb.like(root.get("email").as(String.class), "%" + searchMap.get("email") + "%")); - } - // 电话,座机或手机 - if (searchMap.get("phone") != null && !"".equals(searchMap.get("phone"))) { - predicateList.add(cb.like(root.get("phone").as(String.class), "%" + searchMap.get("phone") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - - /** - * 根据name和email查询实体 - * - * @param name - * @param email - * @return - */ - public Contact findByNameAndEmail(String name, String email) { - return contactDao.findByNameAndEmail(name, email); - } - - -} diff --git a/center/src/main/java/com/tiji/center/service/CronjobService.java b/center/src/main/java/com/tiji/center/service/CronjobService.java deleted file mode 100755 index c73cca4..0000000 --- a/center/src/main/java/com/tiji/center/service/CronjobService.java +++ /dev/null @@ -1,148 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.CronjobDao; -import com.tiji.center.pojo.Cronjob; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * cronjob服务层 - * - * @author 贰拾壹 - */ -@Service -public class CronjobService { - - @Autowired - private CronjobDao cronjobDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return cronjobDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return cronjobDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return cronjobDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Cronjob findById(String id) { - return cronjobDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param cronjob - */ - public void add(Cronjob cronjob) { - if (Objects.isNull(cronjob.getId())) { - cronjob.setId(idWorker.nextId() + ""); - } - cronjobDao.save(cronjob); - } - - /** - * 修改 - * - * @param cronjob - */ - public void update(Cronjob cronjob) { - cronjobDao.save(cronjob); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - cronjobDao.deleteById(id); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 名称 - if (searchMap.get("name") != null && !"".equals(searchMap.get("name"))) { - predicateList.add(cb.like(root.get("name").as(String.class), "%" + (String) searchMap.get("name") + "%")); - } - // cron表达式 - if (searchMap.get("cronexpression") != null && !"".equals(searchMap.get("cronexpression"))) { - predicateList.add(cb.like(root.get("cronexpression").as(String.class), "%" + (String) searchMap.get("cronexpression") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据name查询实体 - * - * @param name - * @return - */ - public Cronjob findByName(String name) { - return cronjobDao.findByName(name); - } - - -} diff --git a/center/src/main/java/com/tiji/center/service/DemocodeService.java b/center/src/main/java/com/tiji/center/service/DemocodeService.java deleted file mode 100755 index 303d01d..0000000 --- a/center/src/main/java/com/tiji/center/service/DemocodeService.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.DemocodeDao; -import com.tiji.center.pojo.Democode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * democode服务层 - * - * @author 贰拾壹 - */ -@Service -public class DemocodeService { - - @Autowired - private DemocodeDao democodeDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return democodeDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return democodeDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return democodeDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Democode findById(String id) { - return democodeDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param democode - */ - public void add(Democode democode) { - if (Objects.isNull(democode.getId())) { - democode.setId(idWorker.nextId() + ""); - } - democodeDao.save(democode); - } - - /** - * 修改 - * - * @param democode - */ - public void update(Democode democode) { - democodeDao.save(democode); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - democodeDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - democodeDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 漏洞示例代码编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 漏洞编号 - if (searchMap.get("vulnid") != null && !"".equals(searchMap.get("vulnid"))) { - predicateList.add(cb.equal(root.get("vulnid").as(String.class), searchMap.get("vulnid"))); - } - // 漏洞示例代码 - if (searchMap.get("democode") != null && !"".equals(searchMap.get("democode"))) { - predicateList.add(cb.like(root.get("democode").as(String.class), "%" + (String) searchMap.get("democode") + "%")); - } - // 漏洞poc - if (searchMap.get("poc") != null && !"".equals(searchMap.get("poc"))) { - predicateList.add(cb.like(root.get("poc").as(String.class), "%" + (String) searchMap.get("poc") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据vulnId查询 - * - * @param vulnId - * @return - */ - public List findAllByVulnId(String vulnId) { - return democodeDao.findAllByVulnid(vulnId); - } - - /** - * 根据vulnId批量删除 - * - * @param vulnId - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByVulnId(String vulnId) { - democodeDao.deleteAllByVulnid(vulnId); - } - -} diff --git a/center/src/main/java/com/tiji/center/service/DepartmentService.java b/center/src/main/java/com/tiji/center/service/DepartmentService.java deleted file mode 100755 index 10d55fd..0000000 --- a/center/src/main/java/com/tiji/center/service/DepartmentService.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.DepartmentDao; -import com.tiji.center.pojo.Department; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * department服务层 - * - * @author 贰拾壹 - */ -@Service -public class DepartmentService { - - @Autowired - private DepartmentDao departmentDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return departmentDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return departmentDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return departmentDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Department findById(String id) { - return departmentDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param department - */ - public void add(Department department) { - if (Objects.isNull(department.getId())) { - department.setId(idWorker.nextId() + ""); - } - departmentDao.save(department); - } - - /** - * 修改 - * - * @param department - */ - public void update(Department department) { - departmentDao.save(department); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - departmentDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - departmentDao.deleteAllByIds(ids); - } - - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 部门名称 - if (searchMap.get("departmentname") != null && !"".equals(searchMap.get("departmentname"))) { - predicateList.add(cb.like(root.get("departmentname").as(String.class), "%" + searchMap.get("departmentname") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据部门名称查询 - * - * @return - */ - public Department findByDepartmentname(String departmentname) { - return departmentDao.findByDepartmentname(departmentname); - } - -} diff --git a/center/src/main/java/com/tiji/center/service/DictionarypasswordService.java b/center/src/main/java/com/tiji/center/service/DictionarypasswordService.java deleted file mode 100755 index 0e0b16b..0000000 --- a/center/src/main/java/com/tiji/center/service/DictionarypasswordService.java +++ /dev/null @@ -1,163 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.DictionarypasswordDao; -import com.tiji.center.pojo.Dictionarypassword; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * dictionarypassword服务层 - * - * @author 贰拾壹 - */ -@Service -public class DictionarypasswordService { - - @Autowired - private DictionarypasswordDao dictionarypasswordDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return dictionarypasswordDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return dictionarypasswordDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return dictionarypasswordDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Dictionarypassword findById(String id) { - return dictionarypasswordDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param dictionarypassword - */ - public void add(Dictionarypassword dictionarypassword) { - if (Objects.isNull(dictionarypassword.getId())) { - dictionarypassword.setId(idWorker.nextId() + ""); - } - dictionarypasswordDao.save(dictionarypassword); - } - - /** - * 修改 - * - * @param dictionarypassword - */ - public void update(Dictionarypassword dictionarypassword) { - dictionarypasswordDao.save(dictionarypassword); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - dictionarypasswordDao.deleteById(id); - } - - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - dictionarypasswordDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList<>(); - // 字典编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 字典密码 - if (searchMap.get("password") != null && !"".equals(searchMap.get("password"))) { - predicateList.add(cb.like(root.get("password").as(String.class), "%" + searchMap.get("password") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据password查询实体 - * - * @param password - * @return - */ - public Dictionarypassword findByPassword(String password) { - return dictionarypasswordDao.findByPassword(password); - } - - /** - * 查询所有password - * - * @return - */ - public List findAllPassword() { - return dictionarypasswordDao.findAllPassword(); - } -} diff --git a/center/src/main/java/com/tiji/center/service/DictionaryusernameService.java b/center/src/main/java/com/tiji/center/service/DictionaryusernameService.java deleted file mode 100755 index 684de4e..0000000 --- a/center/src/main/java/com/tiji/center/service/DictionaryusernameService.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.DictionaryusernameDao; -import com.tiji.center.pojo.Dictionaryusername; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * dictionaryusername服务层 - * - * @author 贰拾壹 - */ -@Service -public class DictionaryusernameService { - - @Autowired - private DictionaryusernameDao dictionaryusernameDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return dictionaryusernameDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return dictionaryusernameDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return dictionaryusernameDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Dictionaryusername findById(String id) { - return dictionaryusernameDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param dictionaryusername - */ - public void add(Dictionaryusername dictionaryusername) { - if (Objects.isNull(dictionaryusername.getId())) { - dictionaryusername.setId(idWorker.nextId() + ""); - } - dictionaryusernameDao.save(dictionaryusername); - } - - /** - * 修改 - * - * @param dictionaryusername - */ - public void update(Dictionaryusername dictionaryusername) { - dictionaryusernameDao.save(dictionaryusername); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - dictionaryusernameDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - dictionaryusernameDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 字典编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 字典用户名 - if (searchMap.get("username") != null && !"".equals(searchMap.get("username"))) { - predicateList.add(cb.like(root.get("username").as(String.class), "%" + (String) searchMap.get("username") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据username查询实体 - * - * @param username - * @return - */ - public Dictionaryusername findByUsername(String username) { - return dictionaryusernameDao.findByUsername(username); - } - - /** - * 查询所有username - * - * @return - */ - public List findAllUsername() { - return dictionaryusernameDao.findAllUsername(); - } -} diff --git a/center/src/main/java/com/tiji/center/service/DomainwhitelistService.java b/center/src/main/java/com/tiji/center/service/DomainwhitelistService.java deleted file mode 100755 index 44a2952..0000000 --- a/center/src/main/java/com/tiji/center/service/DomainwhitelistService.java +++ /dev/null @@ -1,171 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.DomainwhitelistDao; -import com.tiji.center.pojo.Domainwhitelist; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * domainwhitelist服务层 - * - * @author 贰拾壹 - */ -@Service -public class DomainwhitelistService { - - @Autowired - private DomainwhitelistDao domainwhitelistDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return domainwhitelistDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return domainwhitelistDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return domainwhitelistDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Domainwhitelist findById(String id) { - return domainwhitelistDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param domainwhitelist - */ - public void add(Domainwhitelist domainwhitelist) { - if (Objects.isNull(domainwhitelist.getId())) { - domainwhitelist.setId(idWorker.nextId() + ""); - } - domainwhitelistDao.save(domainwhitelist); - } - - /** - * 修改 - * - * @param domainwhitelist - */ - public void update(Domainwhitelist domainwhitelist) { - domainwhitelistDao.save(domainwhitelist); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - domainwhitelistDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - domainwhitelistDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 参数编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 域名 - if (searchMap.get("domain") != null && !"".equals(searchMap.get("domain"))) { - predicateList.add(cb.like(root.get("domain").as(String.class), "%" + (String) searchMap.get("domain") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 查询全部列表 - * - * @return - */ - public List findAllDistinct() { - return domainwhitelistDao.findAllDistinct(); - } - - /** - * 根据domain查询实体 - * - * @param domain - * @return - */ - public Domainwhitelist findByDomain(String domain) { - return domainwhitelistDao.findByDomain(domain); - } - - /** - * 批量增加 - * - * @param domainwhitelistList - */ - public void batchAdd(List domainwhitelistList) { - domainwhitelistDao.saveAll(domainwhitelistList); - } -} diff --git a/center/src/main/java/com/tiji/center/service/HostService.java b/center/src/main/java/com/tiji/center/service/HostService.java deleted file mode 100755 index 41a8047..0000000 --- a/center/src/main/java/com/tiji/center/service/HostService.java +++ /dev/null @@ -1,257 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.HostDao; -import com.tiji.center.pojo.Host; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * host服务层 - * - * @author 贰拾壹 - */ -@Service -public class HostService { - - @Autowired - private HostDao hostDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return hostDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return hostDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return hostDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Host findById(String id) { - return hostDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param host - */ - public void add(Host host) { - if (Objects.isNull(host.getId())) { - host.setId(idWorker.nextId() + ""); - } - hostDao.save(host); - } - - /** - * 修改 - * - * @param host - */ - public void update(Host host) { - hostDao.save(host); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - hostDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - hostDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 主机编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 资产ip编号 - //if (searchMap.get("assetipid") != null && !"".equals(searchMap.get("assetipid"))) { - // predicateList.add(cb.like(root.get("assetipid").as(String.class), "%" + searchMap.get("assetipid") + "%")); - //} - if (searchMap.get("assetipid") != null && !"".equals(searchMap.get("assetipid"))) { - predicateList.add(cb.in(root.get("assetipid")).value(searchMap.get("assetipid"))); - } - - // mac地址 - if (searchMap.get("macaddress") != null && !"".equals(searchMap.get("macaddress"))) { - predicateList.add(cb.like(root.get("macaddress").as(String.class), "%" + searchMap.get("macaddress") + "%")); - } - // 主机名 - if (searchMap.get("hostname") != null && !"".equals(searchMap.get("hostname"))) { - predicateList.add(cb.like(root.get("hostname").as(String.class), "%" + searchMap.get("hostname") + "%")); - } - // 子域名 - if (searchMap.get("subdomain") != null && !"".equals(searchMap.get("subdomain"))) { - predicateList.add(cb.like(root.get("subdomain").as(String.class), "%" + searchMap.get("subdomain") + "%")); - } - // 操作系统类型 - if (searchMap.get("ostype") != null && !"".equals(searchMap.get("ostype"))) { - predicateList.add(cb.like(root.get("ostype").as(String.class), "%" + searchMap.get("ostype") + "%")); - } - // 操作系统版本 - if (searchMap.get("osversion") != null && !"".equals(searchMap.get("osversion"))) { - predicateList.add(cb.like(root.get("osversion").as(String.class), "%" + searchMap.get("osversion") + "%")); - } - // 主机类型 - if (searchMap.get("type") != null && !"".equals(searchMap.get("type"))) { - predicateList.add(cb.like(root.get("type").as(String.class), "%" + searchMap.get("type") + "%")); - } - // 主机所有者 - if (searchMap.get("owner") != null && !"".equals(searchMap.get("owner"))) { - predicateList.add(cb.like(root.get("owner").as(String.class), "%" + searchMap.get("owner") + "%")); - } - //端口发现时间 - if (searchMap.get("activetime") != null && !"".equals(searchMap.get("activetime"))) { - List activetimeList = (List) searchMap.get("activetime"); - //开始 - predicateList.add(cb.greaterThanOrEqualTo(root.get("activetime").as(String.class), activetimeList.get(0))); - //结束 - predicateList.add(cb.lessThanOrEqualTo(root.get("activetime").as(String.class), activetimeList.get(1))); - //predicateList.add(cb.like(root.get("activetime").as(String.class), "%" + searchMap.get("activetime") + "%")); - } - // 备注,标记非dns反向解析 - if (searchMap.get("remark") != null && !"".equals(searchMap.get("remark"))) { - predicateList.add(cb.like(root.get("remark").as(String.class), "%" + searchMap.get("remark") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 批量增加 - * - * @param hostList - */ - public void batchAdd(List hostList) { - hostDao.saveAll(hostList); - } - - /** - * 根据assetipid查询实体 - * - * @param assetipid - * @return - */ - public List findByAssetIpId(String assetipid) { - return hostDao.findByassetipid(assetipid); - } - - /** - * 根据assetipid批量删除 - * - * @param assetipid - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByAssetipid(String assetipid) { - hostDao.deleteAllByAssetipid(assetipid); - } - - /** - * 根据hostname查询实体 - * - * @param hostname - * @return - */ - public Host findByHostname(String hostname) { - return hostDao.findByHostname(hostname); - } - /** - * 根据macaddress查询实体 - * - * @param macaddress - * @return - */ - public Host findByMacaddress(String macaddress) { - return hostDao.findByMacaddress(macaddress); - } - - /** - * 根据assetipid查询 - * - * @param assetipid assetipid - * @return - */ - public List findAllByAssetipid(String assetipid) { - return hostDao.findAllByAssetipid(assetipid); - } - - /** - * 根据assetipid查询 - * - * @param assetipid assetipid - * @param hostname hostname - * @return - */ - public Host findByAssetipidAndHostname(String assetipid, String hostname) { - return hostDao.findByAssetipidAndHostname(assetipid, hostname); - } -} diff --git a/center/src/main/java/com/tiji/center/service/ImvulnnotifyService.java b/center/src/main/java/com/tiji/center/service/ImvulnnotifyService.java deleted file mode 100755 index 1033ad3..0000000 --- a/center/src/main/java/com/tiji/center/service/ImvulnnotifyService.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.ImvulnnotifyDao; -import com.tiji.center.pojo.Imvulnnotify; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * imvulnnotify服务层 - * - * @author 贰拾壹 - */ -@Service -public class ImvulnnotifyService { - - @Autowired - private ImvulnnotifyDao imvulnnotifyDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return imvulnnotifyDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return imvulnnotifyDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return imvulnnotifyDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Imvulnnotify findById(String id) { - return imvulnnotifyDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param imvulnnotify - */ - public void add(Imvulnnotify imvulnnotify) { - if (Objects.isNull(imvulnnotify.getId())) { - imvulnnotify.setId(idWorker.nextId() + ""); - } - imvulnnotifyDao.save(imvulnnotify); - } - - /** - * 修改 - * - * @param imvulnnotify - */ - public void update(Imvulnnotify imvulnnotify) { - imvulnnotifyDao.save(imvulnnotify); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - imvulnnotifyDao.deleteById(id); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 秘钥 - if (searchMap.get("secret") != null && !"".equals(searchMap.get("secret"))) { - predicateList.add(cb.like(root.get("secret").as(String.class), "%" + (String) searchMap.get("secret") + "%")); - } - // 风险等级 - if (searchMap.get("risk") != null && !"".equals(searchMap.get("risk"))) { - predicateList.add(cb.like(root.get("risk").as(String.class), "%" + (String) searchMap.get("risk") + "%")); - } - // 接收人列表 - if (searchMap.get("receiver") != null && !"".equals(searchMap.get("receiver"))) { - predicateList.add(cb.like(root.get("receiver").as(String.class), "%" + (String) searchMap.get("receiver") + "%")); - } - // 消息地址 - if (searchMap.get("messageurl") != null && !"".equals(searchMap.get("messageurl"))) { - predicateList.add(cb.like(root.get("messageurl").as(String.class), "%" + (String) searchMap.get("messageurl") + "%")); - } - // 消息标题 - if (searchMap.get("messagetitle") != null && !"".equals(searchMap.get("messagetitle"))) { - predicateList.add(cb.like(root.get("messagetitle").as(String.class), "%" + (String) searchMap.get("messagetitle") + "%")); - } - // 消息前缀 - if (searchMap.get("messageprefix") != null && !"".equals(searchMap.get("messageprefix"))) { - predicateList.add(cb.like(root.get("messageprefix").as(String.class), "%" + (String) searchMap.get("messageprefix") + "%")); - } - // 消息后缀 - if (searchMap.get("messagesuffix") != null && !"".equals(searchMap.get("messagesuffix"))) { - predicateList.add(cb.like(root.get("messagesuffix").as(String.class), "%" + (String) searchMap.get("messagesuffix") + "%")); - } - // 消息编码 - if (searchMap.get("messagecharset") != null && !"".equals(searchMap.get("messagecharset"))) { - predicateList.add(cb.like(root.get("messagecharset").as(String.class), "%" + (String) searchMap.get("messagecharset") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - -} diff --git a/center/src/main/java/com/tiji/center/service/IpportwhitelistService.java b/center/src/main/java/com/tiji/center/service/IpportwhitelistService.java deleted file mode 100755 index 6ed5b25..0000000 --- a/center/src/main/java/com/tiji/center/service/IpportwhitelistService.java +++ /dev/null @@ -1,213 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.IpportwhitelistDao; -import com.tiji.center.pojo.Ipportwhitelist; -import com.tiji.center.pojo.Ipwhitelist; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * ipportwhitelist服务层 - * - * @author 贰拾壹 - */ -@Service -public class IpportwhitelistService { - - @Autowired - private IpportwhitelistDao ipportwhitelistDao; - - @Autowired - private IdWorker idWorker; - @Autowired - private IpwhitelistService ipwhitelistService; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return ipportwhitelistDao.findAll(); - } - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return ipportwhitelistDao.findAll(specification, pageRequest); - } - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return ipportwhitelistDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Ipportwhitelist findById(String id) { - return ipportwhitelistDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param ipportwhitelist - */ - public void add(Ipportwhitelist ipportwhitelist) { - if (Objects.isNull(ipportwhitelist.getId())) { - ipportwhitelist.setId(idWorker.nextId() + ""); - } - if (Objects.isNull(ipportwhitelist.getCheckwhitelist())) { - ipportwhitelist.setCheckwhitelist(false); - } - if (Objects.isNull(ipportwhitelist.getNotifywhitelist())) { - ipportwhitelist.setNotifywhitelist(false); - } - ipportwhitelistDao.save(ipportwhitelist); - - //去掉ip白名单 - Ipwhitelist ipwhitelist = ipwhitelistService.findById(ipportwhitelist.getIpwhitelistid()); - if (ipportwhitelist.getCheckwhitelist()) { - ipwhitelist.setCheckwhitelist(false); - } - if (ipportwhitelist.getNotifywhitelist()) { - ipwhitelist.setNotifywhitelist(false); - } - ipwhitelistService.update(ipwhitelist); - } - - /** - * 修改 - * - * @param ipportwhitelist - */ - public void update(Ipportwhitelist ipportwhitelist) { - ipportwhitelistDao.save(ipportwhitelist); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - ipportwhitelistDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - ipportwhitelistDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 端口 - if (searchMap.get("port") != null && !"".equals(searchMap.get("port"))) { - predicateList.add(cb.like(root.get("port").as(String.class), "%" + searchMap.get("port") + "%")); - } - // ip白名单编号 - if (searchMap.get("ipwhitelistid") != null && !"".equals(searchMap.get("ipwhitelistid"))) { - predicateList.add(cb.equal(root.get("ipwhitelistid").as(String.class), searchMap.get("ipwhitelistid"))); - } - //检测白名单 - if (searchMap.get("checkwhitelist") != null && !"".equals(searchMap.get("checkwhitelist"))) { - predicateList.add(cb.equal(root.get("checkwhitelist").as(Boolean.class), searchMap.get("checkwhitelist"))); - } - //提醒白名单 - if (searchMap.get("notifywhitelist") != null && !"".equals(searchMap.get("notifywhitelist"))) { - predicateList.add(cb.equal(root.get("notifywhitelist").as(Boolean.class), searchMap.get("notifywhitelist"))); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 批量增加 - * - * @param ipportwhitelistList - */ - public void batchAdd(List ipportwhitelistList) { - ipportwhitelistDao.saveAll(ipportwhitelistList); - } - - /** - * 根据ipwhitelistid、port查询实体 - * - * @param ipwhitelistid - * @param port - * @return - */ - public Ipportwhitelist findByIpwhitelistidAndPort(String ipwhitelistid, String port) { - return ipportwhitelistDao.findByIpwhitelistidAndPort(ipwhitelistid, port); - } - - - /** - * 根据ipwhitelistid查询所有端口 - * - * @param ipwhitelistid - * @return - */ - public List findAllPortByIpwhitelistid(String ipwhitelistid) { - return ipportwhitelistDao.findAllPortByIpwhitelistid(ipwhitelistid); - } - - /** - * 根据ipwhitelistid批量删除 - * - * @param ipwhitelistid - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByipwhitelistid(String ipwhitelistid) { - ipportwhitelistDao.deleteAllByipwhitelistid(ipwhitelistid); - } -} diff --git a/center/src/main/java/com/tiji/center/service/IpwhitelistService.java b/center/src/main/java/com/tiji/center/service/IpwhitelistService.java deleted file mode 100755 index 1e57270..0000000 --- a/center/src/main/java/com/tiji/center/service/IpwhitelistService.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.IpwhitelistDao; -import com.tiji.center.pojo.Ipwhitelist; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * ipwhitelist服务层 - * - * @author 贰拾壹 - */ -@Service -public class IpwhitelistService { - - @Autowired - private IpwhitelistDao ipwhitelistDao; - - @Autowired - private IdWorker idWorker; - @Autowired - private IpportwhitelistService ipportwhitelistService; - - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return ipwhitelistDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return ipwhitelistDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return ipwhitelistDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Ipwhitelist findById(String id) { - return ipwhitelistDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param ipwhitelist - */ - public void add(Ipwhitelist ipwhitelist) { - if (Objects.isNull(ipwhitelist.getId())) { - ipwhitelist.setId(idWorker.nextId() + ""); - } - if (Objects.isNull(ipwhitelist.getCheckwhitelist())) { - ipwhitelist.setCheckwhitelist(false); - } - if (Objects.isNull(ipwhitelist.getNotifywhitelist())) { - ipwhitelist.setNotifywhitelist(false); - } - ipwhitelistDao.save(ipwhitelist); - } - - /** - * 修改 - * - * @param ipwhitelist - */ - public void update(Ipwhitelist ipwhitelist) { - ipwhitelistDao.save(ipwhitelist); - } - - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - ipwhitelistDao.deleteById(id); - //同时删除ip-端口白名单 - ipportwhitelistService.deleteAllByipwhitelistid(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - ipwhitelistDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // ip - if (searchMap.get("ip") != null && !"".equals(searchMap.get("ip"))) { - predicateList.add(cb.like(root.get("ip").as(String.class), "%" + (String) searchMap.get("ip") + "%")); - } - //检测白名单 - if (searchMap.get("checkwhitelist") != null && !"".equals(searchMap.get("checkwhitelist"))) { - predicateList.add(cb.equal(root.get("checkwhitelist").as(Boolean.class), searchMap.get("checkwhitelist"))); - } - //提醒白名单 - if (searchMap.get("notifywhitelist") != null && !"".equals(searchMap.get("notifywhitelist"))) { - predicateList.add(cb.equal(root.get("notifywhitelist").as(Boolean.class), searchMap.get("notifywhitelist"))); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 批量增加 - * - * @param ipWhitelistList - */ - public void batchAdd(List ipWhitelistList) { - ipwhitelistDao.saveAll(ipWhitelistList); - } - - /** - * 查根据ip查询 - * - * @return - */ - public Ipwhitelist findByIp(String ip) { - return ipwhitelistDao.findByIp(ip); - } -} diff --git a/center/src/main/java/com/tiji/center/service/NmapconfigService.java b/center/src/main/java/com/tiji/center/service/NmapconfigService.java deleted file mode 100755 index 3a249e6..0000000 --- a/center/src/main/java/com/tiji/center/service/NmapconfigService.java +++ /dev/null @@ -1,186 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.NmapconfigDao; -import com.tiji.center.pojo.Nmapconfig; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * nmapconfig服务层 - * - * @author 贰拾壹 - */ -@Service -public class NmapconfigService { - - @Autowired - private NmapconfigDao nmapconfigDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return nmapconfigDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return nmapconfigDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return nmapconfigDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Nmapconfig findById(String id) { - return nmapconfigDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param nmapconfig - */ - public void add(Nmapconfig nmapconfig) { - if (Objects.isNull(nmapconfig.getId())) { - nmapconfig.setId(idWorker.nextId() + ""); - } - if (Objects.isNull(nmapconfig.getThreadnumber()) || nmapconfig.getThreadnumber().isEmpty()) { - nmapconfig.setThreadnumber("10"); - } - if (Objects.isNull(nmapconfig.getSingleipscantime()) || nmapconfig.getSingleipscantime().isEmpty()) { - nmapconfig.setSingleipscantime("1"); - } - if (Objects.isNull(nmapconfig.getAdditionoption())) { - nmapconfig.setAdditionoption("-Pn -n -sV --max-retries=1"); - } - nmapconfigDao.save(nmapconfig); - } - - /** - * 修改 - * - * @param nmapconfig - */ - public void update(Nmapconfig nmapconfig) { - nmapconfigDao.save(nmapconfig); - } - - /** - * 删除 - * - * @param id - */ - @Transactional(value = "masterTransactionManager") - public void deleteById(String id) { - nmapconfigDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - nmapconfigDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // nmap配置编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 任务编号 - if (searchMap.get("taskid") != null && !"".equals(searchMap.get("taskid"))) { - predicateList.add(cb.like(root.get("taskid").as(String.class), "%" + (String) searchMap.get("taskid") + "%")); - } - // 线程数量,在mass2Nmap模式下使用 - if (searchMap.get("threadnumber") != null && !"".equals(searchMap.get("threadnumber"))) { - predicateList.add(cb.like(root.get("threadnumber").as(String.class), "%" + (String) searchMap.get("threadnumber") + "%")); - } - // 单个ip扫描次数,在mass2Nmap模式下使用 - if (searchMap.get("singleipscantime") != null && !"".equals(searchMap.get("singleipscantime"))) { - predicateList.add(cb.like(root.get("singleipscantime").as(String.class), "%" + (String) searchMap.get("singleipscantime") + "%")); - } - // 附加选项,在mass2Nmap模式下使用 - if (searchMap.get("additionoption") != null && !"".equals(searchMap.get("additionoption"))) { - predicateList.add(cb.like(root.get("additionoption").as(String.class), "%" + (String) searchMap.get("additionoption") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据taskid查询实体 - * - * @param taskid - * @return - */ - public Nmapconfig findByTaskid(String taskid) { - return nmapconfigDao.findByTaskid(taskid); - } - - /** - * 根据taskid删除实体 - * - * @param Taskid - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByTaskid(String Taskid) { - nmapconfigDao.deleteAllByTaskid(Taskid); - } - -} diff --git a/center/src/main/java/com/tiji/center/service/NotifylogService.java b/center/src/main/java/com/tiji/center/service/NotifylogService.java deleted file mode 100755 index 08360d3..0000000 --- a/center/src/main/java/com/tiji/center/service/NotifylogService.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.NotifylogDao; -import com.tiji.center.pojo.Notifylog; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * notifylog服务层 - * - * @author 贰拾壹 - */ -@Service -public class NotifylogService { - - @Autowired - private NotifylogDao notifylogDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return notifylogDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return notifylogDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return notifylogDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Notifylog findById(String id) { - return notifylogDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param notifylog - */ - public void add(Notifylog notifylog) { - if (Objects.isNull(notifylog.getId())) { - notifylog.setId(idWorker.nextId() + ""); - } - notifylogDao.save(notifylog); - } - - /** - * 修改 - * - * @param notifylog - */ - public void update(Notifylog notifylog) { - notifylogDao.save(notifylog); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - notifylogDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - notifylogDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 类型 - if (searchMap.get("type") != null && !"".equals(searchMap.get("type"))) { - predicateList.add(cb.like(root.get("type").as(String.class), "%" + (String) searchMap.get("type") + "%")); - } - // 接收人 - if (searchMap.get("recipient") != null && !"".equals(searchMap.get("recipient"))) { - predicateList.add(cb.like(root.get("recipient").as(String.class), "%" + (String) searchMap.get("recipient") + "%")); - } - // 接收账户 - if (searchMap.get("receiveuser") != null && !"".equals(searchMap.get("receiveuser"))) { - predicateList.add(cb.like(root.get("receiveuser").as(String.class), "%" + (String) searchMap.get("receiveuser") + "%")); - } - // 内容 - if (searchMap.get("content") != null && !"".equals(searchMap.get("content"))) { - predicateList.add(cb.like(root.get("content").as(String.class), "%" + (String) searchMap.get("content") + "%")); - } - //发送成功 - if (searchMap.get("success") != null && !"".equals(searchMap.get("success"))) { - predicateList.add(cb.equal(root.get("success").as(Boolean.class), (searchMap.get("success")))); - } - // 异常消息 - if (searchMap.get("exception") != null && !"".equals(searchMap.get("exception"))) { - predicateList.add(cb.like(root.get("exception").as(String.class), "%" + (String) searchMap.get("exception") + "%")); - } - //发送时间 - if (searchMap.get("sendtime") != null && !"".equals(searchMap.get("sendtime"))) { - List sendtimeList = (List) searchMap.get("sendtime"); - //开始 - predicateList.add(cb.greaterThanOrEqualTo(root.get("sendtime").as(String.class), sendtimeList.get(0))); - //结束 - predicateList.add(cb.lessThanOrEqualTo(root.get("sendtime").as(String.class), sendtimeList.get(1))); - } - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - - /** - * 批量增加 - * - * @param notifylogList - */ - public void batchAdd(List notifylogList) { - notifylogDao.saveAll(notifylogList); - } - -} diff --git a/center/src/main/java/com/tiji/center/service/PluginassetserviceService.java b/center/src/main/java/com/tiji/center/service/PluginassetserviceService.java deleted file mode 100755 index e58cf86..0000000 --- a/center/src/main/java/com/tiji/center/service/PluginassetserviceService.java +++ /dev/null @@ -1,197 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.PluginassetserviceDao; -import com.tiji.center.pojo.Pluginassetservice; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * assetservice服务层 - * - * @author 贰拾壹 - */ -@Service -public class PluginassetserviceService { - - @Autowired - private PluginassetserviceDao pluginassetserviceDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return pluginassetserviceDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return pluginassetserviceDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return pluginassetserviceDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Pluginassetservice findById(String id) { - return pluginassetserviceDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param assetservice - */ - public void add(Pluginassetservice assetservice) { - if (Objects.isNull(assetservice.getId())) { - assetservice.setId(idWorker.nextId() + ""); - } - pluginassetserviceDao.save(assetservice); - } - - /** - * 修改 - * - * @param assetservice - */ - public void update(Pluginassetservice assetservice) { - pluginassetserviceDao.save(assetservice); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - pluginassetserviceDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - pluginassetserviceDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 资产服务编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.equal(root.get("id").as(String.class), searchMap.get("id"))); - } - // 插件配置编号 - if (searchMap.get("pluginconfigid") != null && !"".equals(searchMap.get("pluginconfigid"))) { - predicateList.add(cb.equal(root.get("pluginconfigid").as(String.class), searchMap.get("pluginconfigid"))); - } - // 资产服务 - if (searchMap.get("assetservice") != null && !"".equals(searchMap.get("assetservice"))) { - predicateList.add(cb.like(root.get("assetservice").as(String.class), "%" + searchMap.get("assetservice") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 批量增加 - * - * @param assetServiceList - */ - public void batchAdd(List assetServiceList) { - pluginassetserviceDao.saveAll(assetServiceList); - } - - /** - * 根据pluginConfigI和serviceName查询实体 - * - * @param pluginConfigId - * @param serviceName - * @return - */ - public Pluginassetservice findByPluginconfigidAndService(String pluginConfigId, String serviceName) { - return pluginassetserviceDao.findByPluginconfigidAndAssetservice(pluginConfigId, serviceName); - } - - /** - * 根据pluginconfigId批量删除 - * - * @param pluginconfigId - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByPluginconfigid(String pluginconfigId) { - pluginassetserviceDao.deleteAllByPluginconfigid(pluginconfigId); - } - - /** - * 根据pluginId查询 - * - * @param pluginconfigid pluginId - * @return - */ - public List findAllByPluginId(String pluginconfigid) { - return pluginassetserviceDao.findAllByPluginconfigid(pluginconfigid); - } - - - /** - * 根据taskId查询任务开启的插件 - * - * @return - */ - public List findPluginassetserviceByTaskid(String taskId) { - return pluginassetserviceDao.findPluginassetserviceByTaskid(taskId); - } -} diff --git a/center/src/main/java/com/tiji/center/service/PluginassetversionService.java b/center/src/main/java/com/tiji/center/service/PluginassetversionService.java deleted file mode 100755 index eb26249..0000000 --- a/center/src/main/java/com/tiji/center/service/PluginassetversionService.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.PluginassetversionDao; -import com.tiji.center.pojo.Pluginassetversion; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * assetversion服务层 - * - * @author 贰拾壹 - */ -@Service -public class PluginassetversionService { - - @Autowired - private PluginassetversionDao pluginassetversionDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return pluginassetversionDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return pluginassetversionDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return pluginassetversionDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Pluginassetversion findById(String id) { - return pluginassetversionDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param assetversion - */ - public void add(Pluginassetversion assetversion) { - if (Objects.isNull(assetversion.getId())) { - assetversion.setId(idWorker.nextId() + ""); - } - pluginassetversionDao.save(assetversion); - } - - /** - * 修改 - * - * @param assetversion - */ - public void update(Pluginassetversion assetversion) { - pluginassetversionDao.save(assetversion); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - pluginassetversionDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - pluginassetversionDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 资产版本编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 插件配置编号 - if (searchMap.get("pluginconfigid") != null && !"".equals(searchMap.get("pluginconfigid"))) { - predicateList.add(cb.like(root.get("pluginconfigid").as(String.class), "%" + (String) searchMap.get("pluginconfigid") + "%")); - } - // 资产版本 - if (searchMap.get("assetversion") != null && !"".equals(searchMap.get("assetversion"))) { - predicateList.add(cb.like(root.get("assetversion").as(String.class), "%" + (String) searchMap.get("assetversion") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 批量增加 - * - * @param assetVersionList - */ - public void batchAdd(List assetVersionList) { - pluginassetversionDao.saveAll(assetVersionList); - } - - - /** - * 根据pluginConfigI和versionName查询实体 - * - * @param pluginConfigId - * @param versionName - * @return - */ - public Pluginassetversion findByPluginconfigidAndService(String pluginConfigId, String versionName) { - return pluginassetversionDao.findByPluginconfigidAndAssetversion(pluginConfigId, versionName); - } - - /** - * 根据pluginconfigId批量删除 - * - * @param pluginconfigId - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByPluginconfigid(String pluginconfigId) { - pluginassetversionDao.deleteAllByPluginconfigid(pluginconfigId); - } - - /** - * 根据pluginId查询 - * - * @param pluginconfigid pluginconfigid - * @return - */ - public List findAllByPluginId(String pluginconfigid) { - return pluginassetversionDao.findAllByPluginconfigid(pluginconfigid); - } - - - /** - * 根据taskId查询任务开启的插件 - * - * @return - */ - public List findPluginassetversionByTaskid(String taskId) { - return pluginassetversionDao.findPluginassetversionByTaskid(taskId); - } -} diff --git a/center/src/main/java/com/tiji/center/service/PluginconfigService.java b/center/src/main/java/com/tiji/center/service/PluginconfigService.java deleted file mode 100755 index fed24a4..0000000 --- a/center/src/main/java/com/tiji/center/service/PluginconfigService.java +++ /dev/null @@ -1,209 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.PluginconfigDao; -import com.tiji.center.pojo.Pluginconfig; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * pluginconfig服务层 - * - * @author 贰拾壹 - */ -@Service -public class PluginconfigService { - - @Autowired - private PluginconfigDao pluginconfigDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return pluginconfigDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return pluginconfigDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return pluginconfigDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Pluginconfig findById(String id) { - return pluginconfigDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param pluginconfig - */ - public void add(Pluginconfig pluginconfig) { - if (Objects.isNull(pluginconfig.getId())) { - pluginconfig.setId(idWorker.nextId() + ""); - } - pluginconfigDao.save(pluginconfig); - } - - /** - * 修改 - * - * @param pluginconfig - */ - public void update(Pluginconfig pluginconfig) { - pluginconfigDao.save(pluginconfig); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - pluginconfigDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - pluginconfigDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 插件配置编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 插件名称 - if (searchMap.get("name") != null && !"".equals(searchMap.get("name"))) { - predicateList.add(cb.like(root.get("name").as(String.class), "%" + searchMap.get("name") + "%")); - } - // 插件参数 - if (searchMap.get("args") != null && !"".equals(searchMap.get("args"))) { - predicateList.add(cb.like(root.get("args").as(String.class), "%" + searchMap.get("args") + "%")); - } - // 插件风险级别 - if (searchMap.get("risk") != null && !"".equals(searchMap.get("risk"))) { - predicateList.add(cb.like(root.get("risk").as(String.class), "%" + searchMap.get("risk") + "%")); - } - // 插件类型:nse或者自定义 - if (searchMap.get("type") != null && !"".equals(searchMap.get("type"))) { - predicateList.add(cb.like(root.get("type").as(String.class), "%" + searchMap.get("type") + "%")); - } - // 插件超时 - if (searchMap.get("timeout") != null && !"".equals(searchMap.get("timeout"))) { - predicateList.add(cb.like(root.get("timeout").as(String.class), "%" + searchMap.get("timeout") + "%")); - } - // 插件代码 - if (searchMap.get("plugincode") != null && !"".equals(searchMap.get("plugincode"))) { - predicateList.add(cb.like(root.get("plugincode").as(String.class), "%" + searchMap.get("plugincode") + "%")); - } - // 辅助验证类型 - if (searchMap.get("validatetype") != null && !"".equals(searchMap.get("validatetype"))) { - predicateList.add(cb.like(root.get("validatetype").as(String.class), "%" + searchMap.get("plugincode") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 批量增加 - * - * @param pluginConfigList - */ - public void batchAdd(List pluginConfigList) { - pluginconfigDao.saveAll(pluginConfigList); - } - - - /** - * 根据pluginConfigName和pluginConfigType查询Pluginconfig - * - * @param pluginConfigName - * @param pluginConfigType - */ - public Pluginconfig findByNameAndType(String pluginConfigName, String pluginConfigType) { - return pluginconfigDao.findByNameAndType(pluginConfigName, pluginConfigType); - } - - - /** - * 根据pluginConfigName和pluginConfigType查询Pluginconfig - * - * @param pluginConfigName - */ - public Pluginconfig findByName(String pluginConfigName) { - return pluginconfigDao.findByName(pluginConfigName); - } - - /** - * 根据ID查询实体 - * - * @param id - * @param type - * @return - */ - public Pluginconfig findByIdAndType(String id, String type) { - return pluginconfigDao.findByIdAndType(id, type); - } - -} diff --git a/center/src/main/java/com/tiji/center/service/ProjectService.java b/center/src/main/java/com/tiji/center/service/ProjectService.java deleted file mode 100755 index 4f307b3..0000000 --- a/center/src/main/java/com/tiji/center/service/ProjectService.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.ProjectDao; -import com.tiji.center.pojo.Project; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * project服务层 - * - * @author 贰拾壹 - */ -@Service -public class ProjectService { - - @Autowired - private ProjectDao projectDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return projectDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return projectDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return projectDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Project findById(String id) { - return projectDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param project - */ - public void add(Project project) { - if (Objects.isNull(project.getId())) { - project.setId(idWorker.nextId() + ""); - } - projectDao.save(project); - } - - /** - * 修改 - * - * @param project - */ - public void update(Project project) { - projectDao.save(project); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - projectDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - projectDao.deleteAllByIds(ids); - ids.forEach(this::updateTaskByProjectIdSetProjectid2Null); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 项目编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 项目名称 - if (searchMap.get("name") != null && !"".equals(searchMap.get("name"))) { - predicateList.add(cb.like(root.get("name").as(String.class), "%" + (String) searchMap.get("name") + "%")); - } - // 项目描述 - if (searchMap.get("description") != null && !"".equals(searchMap.get("description"))) { - predicateList.add(cb.like(root.get("description").as(String.class), "%" + (String) searchMap.get("description") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据name查询实体 - * - * @param name - * @return - */ - public Project findByIName(String name) { - return projectDao.findByName(name); - } - - /** - * 根据projectid将projectid置空 - * - * @param projectid - * @return - */ - @Transactional(value = "masterTransactionManager") - public void updateTaskByProjectIdSetProjectid2Null(String projectid) { - projectDao.updateTaskByProjectIdSetProjectid2Null(projectid); - } -} diff --git a/center/src/main/java/com/tiji/center/service/ProjectinfoService.java b/center/src/main/java/com/tiji/center/service/ProjectinfoService.java deleted file mode 100755 index e412ecd..0000000 --- a/center/src/main/java/com/tiji/center/service/ProjectinfoService.java +++ /dev/null @@ -1,263 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.ProjectinfoDao; -import com.tiji.center.pojo.Contact; -import com.tiji.center.pojo.ContactProjectinfo; -import com.tiji.center.pojo.Projectinfo; -import entity.Result; -import entity.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.*; - -/** - * projectinfo服务层 - * - * @author 贰拾壹 - */ -@Service -public class ProjectinfoService { - - @Autowired - private ProjectinfoDao projectinfoDao; - @Autowired - private IdWorker idWorker; - - @Autowired - private ContactProjectinfoService contactProjectinfoService; - @Autowired - private ContactService contactService; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { return projectinfoDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return projectinfoDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return projectinfoDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Projectinfo findById(String id) { - return projectinfoDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param projectinfo - */ - public void add(Projectinfo projectinfo) { - - if (Objects.isNull(projectinfo.getCheckwhitelist())) { - projectinfo.setCheckwhitelist(false); - } - if (Objects.isNull(projectinfo.getNotifywhitelist())) { - projectinfo.setNotifywhitelist(false); - } - if (Objects.isNull(projectinfo.getOverrideipwhitelist())) { - projectinfo.setOverrideipwhitelist(false); - } - if (Objects.isNull(projectinfo.getInserttime())) { - projectinfo.setInserttime(new Date()); - } - projectinfoDao.save(projectinfo); - } - - /** - * 修改 - * - * @param projectinfo - */ - public void update(Projectinfo projectinfo) { - projectinfoDao.save(projectinfo); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - projectinfoDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - projectinfoDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 部门编号 - if (searchMap.get("departmentid") != null && !"".equals(searchMap.get("departmentid"))) { - predicateList.add(cb.equal(root.get("departmentid").as(String.class), searchMap.get("departmentid"))); - } - // 项目名称 - if (searchMap.get("projectname") != null && !"".equals(searchMap.get("projectname"))) { - predicateList.add(cb.like(root.get("projectname").as(String.class), "%" + searchMap.get("projectname") + "%")); - } - //安全检测白名单 - if (searchMap.get("checkwhitelist") != null && !"".equals(searchMap.get("checkwhitelist"))) { - - predicateList.add(cb.equal(root.get("checkwhitelist").as(Boolean.class), (searchMap.get("checkwhitelist")))); - } - //提醒白名单 - if (searchMap.get("notifywhitelist") != null && !"".equals(searchMap.get("notifywhitelist"))) { - - predicateList.add(cb.equal(root.get("notifywhitelist").as(Boolean.class), (searchMap.get("notifywhitelist")))); - } - //覆盖ip白名单 - if (searchMap.get("overrideipwhitelist") != null && !"".equals(searchMap.get("overrideipwhitelist"))) { - - predicateList.add(cb.equal(root.get("overrideipwhitelist").as(Boolean.class), (searchMap.get("overrideipwhitelist")))); - } - //ip发现时间 - if (searchMap.get("inserttime") != null && !"".equals(searchMap.get("inserttime"))) { - List inserttimeList = (List) searchMap.get("inserttime"); - //开始 - predicateList.add(cb.greaterThanOrEqualTo(root.get("inserttime").as(String.class), inserttimeList.get(0))); - //结束 - predicateList.add(cb.lessThanOrEqualTo(root.get("inserttime").as(String.class), inserttimeList.get(1))); - //predicateList.add(cb.like(root.get("inserttime").as(String.class), "%" + searchMap.get("inserttime") + "%")); - } - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - - /** - * 根据ProjectName查询实体 - * - * @param ProjectName - * @return - */ - public Projectinfo findByProjectname(String ProjectName) { - return projectinfoDao.findByProjectname(ProjectName); - } - - - /** - * 根据ProjectName查询实体 - * - * @param departmentid - * @param projectname - * @return - */ - public Projectinfo findByDepartmentidAndProjectname(String departmentid, String projectname) { - return projectinfoDao.findByDepartmentidAndProjectname(departmentid, projectname); - } - - - /** - * 根据id数组查询 - * - * @param ids - * @return - */ - public List findByIds(String[] ids) { - List projectInfoIdAndNameList = new ArrayList<>(); - for (String projectInfoId : ids) { - Projectinfo projectinfo = findById(projectInfoId); - if (Objects.isNull(projectinfo)) { - projectInfoIdAndNameList.add(projectInfoId + "-" + null); - } else { - projectInfoIdAndNameList.add(projectInfoId + "-" + projectinfo.getProjectname()); - } - } - return projectInfoIdAndNameList.isEmpty() ? null : projectInfoIdAndNameList; - } - - public List findAllContactById(String id) { - List resultList = new ArrayList<>(); - List contactProjectinfoList = contactProjectinfoService.findAllByProjectinfoid(id); - contactProjectinfoList.parallelStream().forEach(contactProjectinfo -> { - String contactid = contactProjectinfo.getContactid(); - Contact contact = contactService.findById(contactid); - resultList.add(contact); - }); - return resultList; - } - - /** - * 根据项目信息id和联系人id,新增关联 - * - * @param projectinfoIdAndContactId - * @return - */ - public void addContact(String[] projectinfoIdAndContactId) { - contactProjectinfoService.add(new ContactProjectinfo(idWorker.nextId()+"",projectinfoIdAndContactId[1],projectinfoIdAndContactId[0])); - } - - /** - * 根据departid将departid置空 - * - * @param departid - * @return - */ - @Transactional(value = "masterTransactionManager") - public void updateProjectInfoByDepartidSetDepartid2Null(String departid) { - projectinfoDao.updateProjectInfoByDepartidSetDepartid2Null(departid); - } -} diff --git a/center/src/main/java/com/tiji/center/service/ProjectportwhitelistService.java b/center/src/main/java/com/tiji/center/service/ProjectportwhitelistService.java deleted file mode 100755 index 233a68b..0000000 --- a/center/src/main/java/com/tiji/center/service/ProjectportwhitelistService.java +++ /dev/null @@ -1,195 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.ProjectportwhitelistDao; -import com.tiji.center.pojo.Projectportwhitelist; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * projectportwhitelist服务层 - * - * @author 贰拾壹 - */ -@Service -public class ProjectportwhitelistService { - - @Autowired - private ProjectportwhitelistDao projectportwhitelistDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return projectportwhitelistDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return projectportwhitelistDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return projectportwhitelistDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Projectportwhitelist findById(String id) { - return projectportwhitelistDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param projectportwhitelist - */ - public void add(Projectportwhitelist projectportwhitelist) { - if (Objects.isNull(projectportwhitelist.getId())) { - projectportwhitelist.setId(idWorker.nextId() + ""); - } - if (Objects.isNull(projectportwhitelist.getCheckwhitelist())) { - projectportwhitelist.setCheckwhitelist(false); - } - if (Objects.isNull(projectportwhitelist.getNotifywhitelist())) { - projectportwhitelist.setNotifywhitelist(false); - } - projectportwhitelistDao.save(projectportwhitelist); - } - - /** - * 修改 - * - * @param projectportwhitelist - */ - public void update(Projectportwhitelist projectportwhitelist) { - projectportwhitelistDao.save(projectportwhitelist); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - projectportwhitelistDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - projectportwhitelistDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 项目信息编号 - if (searchMap.get("projectinfoid") != null && !"".equals(searchMap.get("projectinfoid"))) { - predicateList.add(cb.like(root.get("projectinfoid").as(String.class), "%" + searchMap.get("projectinfoid") + "%")); - } - // 端口 - if (searchMap.get("port") != null && !"".equals(searchMap.get("port"))) { - predicateList.add(cb.like(root.get("port").as(String.class), "%" + searchMap.get("port") + "%")); - } - //安全检测白名单 - if (searchMap.get("checkwhitelist") != null && !"".equals(searchMap.get("checkwhitelist"))) { - - predicateList.add(cb.equal(root.get("checkwhitelist").as(Boolean.class), (searchMap.get("checkwhitelist")))); - } - //提醒白名单 - if (searchMap.get("notifywhitelist") != null && !"".equals(searchMap.get("notifywhitelist"))) { - - predicateList.add(cb.equal(root.get("notifywhitelist").as(Boolean.class), (searchMap.get("notifywhitelist")))); - } - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - - /** - * 根据projectInfoId、port查询实体 - * - * @param projectInfoId - * @param port - * @return - */ - public Projectportwhitelist findByProjectinfoidAndPort(String projectInfoId, String port) { - return projectportwhitelistDao.findByProjectinfoidAndPort(projectInfoId, port); - } - - /** - * 根据projectinfoid批量删除 - * - * @param projectinfoid - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByProjectinfoid(String projectinfoid) { - projectportwhitelistDao.deleteAllByProjectinfoid(projectinfoid); - } - - /** - * 根据projectinfoid查询所有端口 - * - * @param projectinfoid - * @return - */ - public List findAllPortByProjectinfoid(String projectinfoid) { - return projectportwhitelistDao.findAllPortByProjectinfoid(projectinfoid); - } - -} diff --git a/center/src/main/java/com/tiji/center/service/ProjectvulnnotifyService.java b/center/src/main/java/com/tiji/center/service/ProjectvulnnotifyService.java deleted file mode 100755 index fc581ca..0000000 --- a/center/src/main/java/com/tiji/center/service/ProjectvulnnotifyService.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.ProjectvulnnotifyDao; -import com.tiji.center.pojo.Projectvulnnotify; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * projectvulnnotify服务层 - * - * @author 贰拾壹 - */ -@Service -public class ProjectvulnnotifyService { - - @Autowired - private ProjectvulnnotifyDao projectvulnnotifyDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return projectvulnnotifyDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return projectvulnnotifyDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return projectvulnnotifyDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Projectvulnnotify findById(String id) { - return projectvulnnotifyDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param projectvulnnotify - */ - public void add(Projectvulnnotify projectvulnnotify) { - if (Objects.isNull(projectvulnnotify.getId())) { - projectvulnnotify.setId(idWorker.nextId() + ""); - } - projectvulnnotifyDao.save(projectvulnnotify); - } - - /** - * 修改 - * - * @param projectvulnnotify - */ - public void update(Projectvulnnotify projectvulnnotify) { - projectvulnnotifyDao.save(projectvulnnotify); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - projectvulnnotifyDao.deleteById(id); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 风险等级 - if (searchMap.get("risk") != null && !"".equals(searchMap.get("risk"))) { - predicateList.add(cb.like(root.get("risk").as(String.class), "%" + (String) searchMap.get("risk") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - -} diff --git a/center/src/main/java/com/tiji/center/service/RiskportService.java b/center/src/main/java/com/tiji/center/service/RiskportService.java deleted file mode 100755 index 7dbc5f7..0000000 --- a/center/src/main/java/com/tiji/center/service/RiskportService.java +++ /dev/null @@ -1,153 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.RiskportDao; -import com.tiji.center.pojo.Riskport; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * riskport服务层 - * - * @author 贰拾壹 - */ -@Service -public class RiskportService { - - @Autowired - private RiskportDao riskportDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return riskportDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return riskportDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return riskportDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Riskport findById(String id) { - return riskportDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param riskport - */ - public void add(Riskport riskport) { - if (Objects.isNull(riskport.getId())) { - riskport.setId(idWorker.nextId() + ""); - } - riskportDao.save(riskport); - } - - /** - * 修改 - * - * @param riskport - */ - public void update(Riskport riskport) { - riskportDao.save(riskport); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - riskportDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - riskportDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 高危端口 - if (searchMap.get("port") != null && !"".equals(searchMap.get("port"))) { - predicateList.add(cb.like(root.get("port").as(String.class), "%" + (String) searchMap.get("port") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据port查询实体 - * - * @param port - * @return - */ - public Riskport findByPort(String port) { - return riskportDao.findByPort(port); - } -} diff --git a/center/src/main/java/com/tiji/center/service/RiskserviceService.java b/center/src/main/java/com/tiji/center/service/RiskserviceService.java deleted file mode 100755 index e6b6d29..0000000 --- a/center/src/main/java/com/tiji/center/service/RiskserviceService.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.RiskserviceDao; -import com.tiji.center.pojo.Riskservice; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * riskservice服务层 - * - * @author 贰拾壹 - */ -@Service -public class RiskserviceService { - - @Autowired - private RiskserviceDao riskserviceDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return riskserviceDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return riskserviceDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return riskserviceDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Riskservice findById(String id) { - return riskserviceDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param riskservice - */ - public void add(Riskservice riskservice) { - if (Objects.isNull(riskservice.getId())) { - riskservice.setId(idWorker.nextId() + ""); - } - riskserviceDao.save(riskservice); - } - - /** - * 修改 - * - * @param riskservice - */ - public void update(Riskservice riskservice) { - riskserviceDao.save(riskservice); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - riskserviceDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - riskserviceDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList<>(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 高危服务 - if (searchMap.get("service") != null && !"".equals(searchMap.get("service"))) { - predicateList.add(cb.like(root.get("service").as(String.class), "%" + (String) searchMap.get("service") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - - /** - * 根据service查询实体 - * - * @param service - * @return - */ - public Riskservice findByService(String service) { - return riskserviceDao.findByService(service); - } - -} diff --git a/center/src/main/java/com/tiji/center/service/RiskversionService.java b/center/src/main/java/com/tiji/center/service/RiskversionService.java deleted file mode 100755 index b3ed155..0000000 --- a/center/src/main/java/com/tiji/center/service/RiskversionService.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.RiskversionDao; -import com.tiji.center.pojo.Riskversion; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * riskversion服务层 - * - * @author 贰拾壹 - */ -@Service -public class RiskversionService { - - @Autowired - private RiskversionDao riskversionDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return riskversionDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return riskversionDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return riskversionDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Riskversion findById(String id) { - return riskversionDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param riskversion - */ - public void add(Riskversion riskversion) { - if (Objects.isNull(riskversion.getId())) { - riskversion.setId(idWorker.nextId() + ""); - } - riskversionDao.save(riskversion); - } - - /** - * 修改 - * - * @param riskversion - */ - public void update(Riskversion riskversion) { - riskversionDao.save(riskversion); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - riskversionDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - riskversionDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 高危版本 - if (searchMap.get("version") != null && !"".equals(searchMap.get("version"))) { - predicateList.add(cb.like(root.get("version").as(String.class), "%" + (String) searchMap.get("version") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据version查询实体 - * - * @param version - * @return - */ - public Riskversion findByVersion(String version) { - return riskversionDao.findByVersion(version); - } - -} diff --git a/center/src/main/java/com/tiji/center/service/SendmailconfigService.java b/center/src/main/java/com/tiji/center/service/SendmailconfigService.java deleted file mode 100755 index 71957d0..0000000 --- a/center/src/main/java/com/tiji/center/service/SendmailconfigService.java +++ /dev/null @@ -1,170 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.SendmailconfigDao; -import com.tiji.center.pojo.Sendmailconfig; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * sendmailconfig服务层 - * - * @author 贰拾壹 - */ -@Service -public class SendmailconfigService { - - @Autowired - private SendmailconfigDao sendmailconfigDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return sendmailconfigDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return sendmailconfigDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return sendmailconfigDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Sendmailconfig findById(String id) { - return sendmailconfigDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param sendmailconfig - */ - public void add(Sendmailconfig sendmailconfig) { - if (Objects.isNull(sendmailconfig.getId())) { - sendmailconfig.setId(idWorker.nextId() + ""); - } - sendmailconfigDao.save(sendmailconfig); - } - - /** - * 修改 - * - * @param sendmailconfig - */ - public void update(Sendmailconfig sendmailconfig) { - sendmailconfigDao.save(sendmailconfig); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - sendmailconfigDao.deleteById(id); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 邮箱host - if (searchMap.get("sendhost") != null && !"".equals(searchMap.get("sendhost"))) { - predicateList.add(cb.like(root.get("sendhost").as(String.class), "%" + (String) searchMap.get("sendhost") + "%")); - } - // 密码 - if (searchMap.get("sendpassword") != null && !"".equals(searchMap.get("sendpassword"))) { - predicateList.add(cb.like(root.get("sendpassword").as(String.class), "%" + (String) searchMap.get("sendpassword") + "%")); - } - - // 发件人 - if (searchMap.get("sendfrom") != null && !"".equals(searchMap.get("sendfrom"))) { - predicateList.add(cb.like(root.get("sendfrom").as(String.class), "%" + (String) searchMap.get("sendfrom") + "%")); - } - //提醒邮箱,强制提醒,不管是否在提醒白名单里,提醒包括所有资产和在收件人列表接收漏洞风险中的漏洞 - if (searchMap.get("sendto") != null && !"".equals(searchMap.get("sendto"))) { - predicateList.add(cb.like(root.get("sendto").as(String.class), "%" + (String) searchMap.get("sendto") + "%")); - } - //收件人列表接收漏洞风险 - if (searchMap.get("sendtorisk") != null && !"".equals(searchMap.get("sendtorisk"))) { - predicateList.add(cb.like(root.get("sendtorisk").as(String.class), "%" + (String) searchMap.get("sendtorisk") + "%")); - } - // 漏洞邮件主题 - if (searchMap.get("vulnsubject") != null && !"".equals(searchMap.get("vulnsubject"))) { - predicateList.add(cb.like(root.get("vulnsubject").as(String.class), "%" + (String) searchMap.get("vulnsubject") + "%")); - } - // 资产邮件主题 - if (searchMap.get("assetsubject") != null && !"".equals(searchMap.get("assetsubject"))) { - predicateList.add(cb.like(root.get("assetsubject").as(String.class), "%" + (String) searchMap.get("assetsubject") + "%")); - } - // 漏洞邮件内容 - if (searchMap.get("vulncontent") != null && !"".equals(searchMap.get("vulncontent"))) { - predicateList.add(cb.like(root.get("vulncontent").as(String.class), "%" + (String) searchMap.get("vulncontent") + "%")); - } - // 资产邮件内容 - if (searchMap.get("assetcontent") != null && !"".equals(searchMap.get("assetcontent"))) { - predicateList.add(cb.like(root.get("assetcontent").as(String.class), "%" + (String) searchMap.get("assetcontent") + "%")); - } - // excel作者 - if (searchMap.get("excelauthor") != null && !"".equals(searchMap.get("excelauthor"))) { - predicateList.add(cb.like(root.get("excelauthor").as(String.class), "%" + (String) searchMap.get("excelauthor") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - -} diff --git a/center/src/main/java/com/tiji/center/service/SolutionService.java b/center/src/main/java/com/tiji/center/service/SolutionService.java deleted file mode 100755 index b94b1f2..0000000 --- a/center/src/main/java/com/tiji/center/service/SolutionService.java +++ /dev/null @@ -1,175 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.SolutionDao; -import com.tiji.center.pojo.Solution; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * solution服务层 - * - * @author 贰拾壹 - */ -@Service -public class SolutionService { - - @Autowired - private SolutionDao solutionDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return solutionDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return solutionDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return solutionDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Solution findById(String id) { - return solutionDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param solution - */ - public void add(Solution solution) { - if (Objects.isNull(solution.getId())) { - solution.setId(idWorker.nextId() + ""); - } - solutionDao.save(solution); - } - - /** - * 修改 - * - * @param solution - */ - public void update(Solution solution) { - solutionDao.save(solution); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - solutionDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - solutionDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 修复方案编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 漏洞编号 - if (searchMap.get("vulnid") != null && !"".equals(searchMap.get("vulnid"))) { - predicateList.add(cb.like(root.get("vulnid").as(String.class), "%" + (String) searchMap.get("vulnid") + "%")); - } - // 修复方案 - if (searchMap.get("solution") != null && !"".equals(searchMap.get("solution"))) { - predicateList.add(cb.like(root.get("solution").as(String.class), "%" + (String) searchMap.get("solution") + "%")); - } - // 修复代码示例 - if (searchMap.get("codedemo") != null && !"".equals(searchMap.get("codedemo"))) { - predicateList.add(cb.like(root.get("codedemo").as(String.class), "%" + (String) searchMap.get("codedemo") + "%")); - } - // 修复配置示例 - if (searchMap.get("configdemo") != null && !"".equals(searchMap.get("configdemo"))) { - predicateList.add(cb.like(root.get("configdemo").as(String.class), "%" + (String) searchMap.get("configdemo") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据vulnId查询 - * - * @param vulnId - * @return - */ - public List findAllByVulnId(String vulnId) { - return solutionDao.findAllByVulnid(vulnId); - } - - /** - * 根据vulnId批量删除 - * - * @param vulnId - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByVulnId(String vulnId) { - solutionDao.deleteAllByVulnid(vulnId); - } -} diff --git a/center/src/main/java/com/tiji/center/service/StatisticsService.java b/center/src/main/java/com/tiji/center/service/StatisticsService.java deleted file mode 100755 index 12d3879..0000000 --- a/center/src/main/java/com/tiji/center/service/StatisticsService.java +++ /dev/null @@ -1,498 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.StatisticsDao; -import com.tiji.center.pojo.Statistics; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.*; - -/** - * statistics服务层 - * - * @author 贰拾壹 - */ -@Service -public class StatisticsService { - - @Autowired - private StatisticsDao statisticsDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return statisticsDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return statisticsDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return statisticsDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Statistics findById(String id) { - return statisticsDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param statistics - */ - public void add(Statistics statistics) { - if (Objects.isNull(statistics.getId())) { - statistics.setId(idWorker.nextId() + ""); - } - statisticsDao.save(statistics); - } - - /** - * 修改 - * - * @param statistics - */ - public void update(Statistics statistics) { - statisticsDao.save(statistics); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - statisticsDao.deleteById(id); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // ip数 - if (searchMap.get("ipcount") != null && !"".equals(searchMap.get("ipcount"))) { - predicateList.add(cb.like(root.get("ipcount").as(String.class), "%" + (String) searchMap.get("ipcount") + "%")); - } - // 未下线ip数 - if (searchMap.get("ipcountonline") != null && !"".equals(searchMap.get("ipcountonline"))) { - predicateList.add(cb.like(root.get("ipcountonline").as(String.class), "%" + (String) searchMap.get("ipcountonline") + "%")); - } - // 端口数 - if (searchMap.get("portcount") != null && !"".equals(searchMap.get("portcount"))) { - predicateList.add(cb.like(root.get("portcount").as(String.class), "%" + (String) searchMap.get("portcount") + "%")); - } - // 未下线端口数 - if (searchMap.get("portcountonline") != null && !"".equals(searchMap.get("portcountonline"))) { - predicateList.add(cb.like(root.get("portcountonline").as(String.class), "%" + (String) searchMap.get("portcountonline") + "%")); - } - // 检测结果数 - if (searchMap.get("checkresultcount") != null && !"".equals(searchMap.get("checkresultcount"))) { - predicateList.add(cb.like(root.get("checkresultcount").as(String.class), "%" + (String) searchMap.get("checkresultcount") + "%")); - } - // 未修复检测结果数 - if (searchMap.get("checkresultcountonline") != null && !"".equals(searchMap.get("checkresultcountonline"))) { - predicateList.add(cb.like(root.get("checkresultcountonline").as(String.class), "%" + (String) searchMap.get("checkresultcountonline") + "%")); - } - // 信息检测结果数 - if (searchMap.get("infocount") != null && !"".equals(searchMap.get("infocount"))) { - predicateList.add(cb.like(root.get("infocount").as(String.class), "%" + (String) searchMap.get("infocount") + "%")); - } - // 低危检测结果数 - if (searchMap.get("lowcount") != null && !"".equals(searchMap.get("lowcount"))) { - predicateList.add(cb.like(root.get("lowcount").as(String.class), "%" + (String) searchMap.get("lowcount") + "%")); - } - // 中危检测结果数 - if (searchMap.get("mediumcount") != null && !"".equals(searchMap.get("mediumcount"))) { - predicateList.add(cb.like(root.get("mediumcount").as(String.class), "%" + (String) searchMap.get("mediumcount") + "%")); - } - // 高危检测结果数 - if (searchMap.get("highcount") != null && !"".equals(searchMap.get("highcount"))) { - predicateList.add(cb.like(root.get("highcount").as(String.class), "%" + (String) searchMap.get("highcount") + "%")); - } - // 严重检测结果数 - if (searchMap.get("criticalcount") != null && !"".equals(searchMap.get("criticalcount"))) { - predicateList.add(cb.like(root.get("criticalcount").as(String.class), "%" + (String) searchMap.get("criticalcount") + "%")); - } - // 致命检测结果数 - if (searchMap.get("fatalcount") != null && !"".equals(searchMap.get("fatalcount"))) { - predicateList.add(cb.like(root.get("fatalcount").as(String.class), "%" + (String) searchMap.get("fatalcount") + "%")); - } - // 未修复信息检测结果数 - if (searchMap.get("infocountonline") != null && !"".equals(searchMap.get("infocountonline"))) { - predicateList.add(cb.like(root.get("infocountonline").as(String.class), "%" + (String) searchMap.get("infocountonline") + "%")); - } - // 未修复低危检测结果数 - if (searchMap.get("lowcountonline") != null && !"".equals(searchMap.get("lowcountonline"))) { - predicateList.add(cb.like(root.get("lowcountonline").as(String.class), "%" + (String) searchMap.get("lowcountonline") + "%")); - } - // 未修复中危检测结果数 - if (searchMap.get("mediumcountonline") != null && !"".equals(searchMap.get("mediumcountonline"))) { - predicateList.add(cb.like(root.get("mediumcountonline").as(String.class), "%" + (String) searchMap.get("mediumcountonline") + "%")); - } - // 未修复高危检测结果数 - if (searchMap.get("highcountonline") != null && !"".equals(searchMap.get("highcountonline"))) { - predicateList.add(cb.like(root.get("highcountonline").as(String.class), "%" + (String) searchMap.get("highcountonline") + "%")); - } - // 未修复严重检测结果数 - if (searchMap.get("criticalcountonline") != null && !"".equals(searchMap.get("criticalcountonline"))) { - predicateList.add(cb.like(root.get("criticalcountonline").as(String.class), "%" + (String) searchMap.get("criticalcountonline") + "%")); - } - // 未修复致命检测结果数 - if (searchMap.get("fatalcountonline") != null && !"".equals(searchMap.get("fatalcountonline"))) { - predicateList.add(cb.like(root.get("fatalcountonline").as(String.class), "%" + (String) searchMap.get("fatalcountonline") + "%")); - } - // 高危端口数 - if (searchMap.get("riskportcount") != null && !"".equals(searchMap.get("riskportcount"))) { - predicateList.add(cb.like(root.get("riskportcount").as(String.class), "%" + (String) searchMap.get("riskportcount") + "%")); - } - // 未下线高危端口数 - if (searchMap.get("riskportcountonline") != null && !"".equals(searchMap.get("riskportcountonline"))) { - predicateList.add(cb.like(root.get("riskportcountonline").as(String.class), "%" + (String) searchMap.get("riskportcountonline") + "%")); - } - // 高危服务数 - if (searchMap.get("riskservicecount") != null && !"".equals(searchMap.get("riskservicecount"))) { - predicateList.add(cb.like(root.get("riskservicecount").as(String.class), "%" + (String) searchMap.get("riskservicecount") + "%")); - } - // 未下线高危服务数 - if (searchMap.get("riskservicecountonline") != null && !"".equals(searchMap.get("riskservicecountonline"))) { - predicateList.add(cb.like(root.get("riskservicecountonline").as(String.class), "%" + (String) searchMap.get("riskservicecountonline") + "%")); - } - // 高危版本数 - if (searchMap.get("riskversioncount") != null && !"".equals(searchMap.get("riskversioncount"))) { - predicateList.add(cb.like(root.get("riskversioncount").as(String.class), "%" + (String) searchMap.get("riskversioncount") + "%")); - } - // 未下线高危版本数 - if (searchMap.get("riskversioncountonline") != null && !"".equals(searchMap.get("riskversioncountonline"))) { - predicateList.add(cb.like(root.get("riskversioncountonline").as(String.class), "%" + (String) searchMap.get("riskversioncountonline") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据查询ip的端口数 - * - * @return - */ - public List findIpPortCount() { - return statisticsDao.findIpPortCount(); - } - - /** - * 查询未下线ip的端口数 - * - * @return - */ - public List findIpPortCountOnline() { - return statisticsDao.findIpPortCountOnline(); - } - - /** - * 查询高危端口数量 - * - * @return - */ - public List findRiskPortCount() { - return statisticsDao.findRiskPortCount(); - } - - /** - * 查询未下线高危端口数量 - * - * @return - */ - public List findRiskPortCountOnline() { - return statisticsDao.findRiskPortCountOnline(); - } - - /** - * 查询高危服务数量 - * - * @return - */ - public List findRiskServiceCount() { - return statisticsDao.findRiskServiceCount(); - } - - /** - * 查询未下线高危服务数量 - * - * @return - */ - public List findRiskServiceCountOnline() { - return statisticsDao.findRiskServiceCountOnline(); - } - - /** - * 查询高危版本数量 - * - * @return - */ - public List findRiskVersionCount() { - return statisticsDao.findRiskVersionCount(); - } - - /** - * 查询未下线高危版本数量 - * - * @return - */ - public List findRiskVersionCountOnline() { - return statisticsDao.findRiskVersionCountOnline(); - } - - /** - * 查询服务数量 - * - * @return - */ - public List findServiceCount() { - return statisticsDao.findServiceCount(); - } - - /** - * 查询未下线服务数量 - * - * @return - */ - public List findServiceCountOnline() { - return statisticsDao.findServiceCountOnline(); - } - - /** - * 查询version数量 - * - * @return - */ - public List findVersionCount() { - return statisticsDao.findVersionCount(); - } - - /** - * 查询未下线version数量 - * - * @return - */ - public List findVersionCountOnline() { - return statisticsDao.findVersionCountOnline(); - } - - /** - * 查询webinfo中server数量 - * - * @return - */ - public List findWebinfoServerCount() { - return statisticsDao.findWebinfoServerCount(); - } - - /** - * 查询所有风险数 - * - * @return - */ - public List findRiskCount() { - return statisticsDao.findRiskCount(); - } - - /** - * 查询未修复风险数 - * - * @return - */ - public List findRiskCountOnline() { - return statisticsDao.findRiskCountOnline(); - } - - /** - * 查询所有漏洞数 - * - * @return - */ - public List findRiskVulnCount() { - return statisticsDao.findRiskVulnCount(); - } - - /** - * 查询未修复漏洞数 - * - * @return - */ - public List findRiskVulnCountOnline() { - return statisticsDao.findRiskVulnCountOnline(); - } - - /** - * 查询ip数 - * - * @return - */ - public String findIpCount() { - return statisticsDao.findIpCount(); - } - - /** - * 查询未下线ip数 - * - * @return - */ - public String findIpCountOnline() { - return statisticsDao.findIpCountOnline(); - } - - /** - * 查询端口数 - * - * @return - */ - public String findPortCount() { - return statisticsDao.findPortCount(); - } - - /** - * 查询未下线端口数 - * - * @return - */ - public String findPortCountOnline() { - return statisticsDao.findPortCountOnline(); - } - - /** - * 查询检测结果数 - * - * @return - */ - public Map findCheckresultCountMap() { - List checkresultCountList = statisticsDao.findCheckresultCount(); - Map checkresultCountMap = new HashMap<>(); - for (String checkresultCount : checkresultCountList) { - String risk = checkresultCount.split(",")[0]; - String count = checkresultCount.split(",")[1]; - checkresultCountMap.put(risk, count); - } - return checkresultCountMap; - } - - /** - * 查询未修复检测结果数 - * - * @return - */ - public Map findCheckresultCountOnlineMap() { - List checkresultCountOnlineList = statisticsDao.findCheckresultCountOnline(); - Map checkresultCountMap = new HashMap<>(); - for (String checkresultCount : checkresultCountOnlineList) { - String risk = checkresultCount.split(",")[0]; - String count = checkresultCount.split(",")[1]; - checkresultCountMap.put(risk, count); - } - return checkresultCountMap; - } - - - /** - * 查询高危端口数 - * - * @return - */ - public String findRiskportCount() { - return statisticsDao.findRiskportCount(); - } - - /** - * 查询未下线高危端口数 - * - * @return - */ - public String findRiskportCountOnline() { - return statisticsDao.findRiskportCountOnline(); - } - - /** - * 查询高危服务数 - * - * @return - */ - public String findRiskserviceCount() { - return statisticsDao.findRiskserviceCount(); - } - - /** - * 查询未下线高危服务数 - * - * @return - */ - public String findRiskserviceCountOnline() { - return statisticsDao.findRiskserviceCountOnline(); - } - - /** - * 查询高危版本数 - * - * @return - */ - public String findRiskversionCount() { - return statisticsDao.findRiskversionCount(); - } - - /** - * 查询未下线高危版本数 - * - * @return - */ - public String findRiskversionCountOnline() { - return statisticsDao.findRiskversionCountOnline(); - } - -} diff --git a/center/src/main/java/com/tiji/center/service/TaskDispatcherService.java b/center/src/main/java/com/tiji/center/service/TaskDispatcherService.java deleted file mode 100755 index cbbd480..0000000 --- a/center/src/main/java/com/tiji/center/service/TaskDispatcherService.java +++ /dev/null @@ -1,973 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dispatcher.TargetIpSlicer; -import com.tiji.center.pojo.*; -import com.tiji.center.schedule.quartz.QuartzJobService; -import com.tiji.center.util.TijiHelper; -import org.quartz.JobKey; -import org.quartz.SchedulerException; -import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; -import util.IdWorker; - -import java.text.DecimalFormat; -import java.util.*; - -/** - * @author 贰拾壹 - * @create 2019-09-18 10:53 - */ -@Service -public class TaskDispatcherService { - @Autowired - private TaskService taskService; - - - @Autowired - private RedisTemplate redisTemplate; - - @Autowired - private RabbitMessagingTemplate rabbitMessagingTemplate; - @Autowired - private IdWorker idWorker; - @Autowired - private UseragentService useragentService; - - @Autowired - private AssetipService assetipService; - @Autowired - private AssetportService assetportService; - - @Autowired - private PluginconfigService pluginconfigService; - - @Autowired - private PluginassetserviceService pluginassetserviceService; - @Autowired - private PluginassetversionService pluginassetversionService; - - @Autowired - private TaskipService taskipService; - @Autowired - private QuartzJobService quartzJobService; - - @Autowired - private AgentService agentService; - /** - * 根据taskId对资产库执行check任务 - * synchronized 防止定时任务同时启动时丢任务 - * - * @param oldTaskId - * @return - */ - @Autowired - private TaskpluginconfigService taskpluginconfigService; - /** - * 根据taskId重新开始任务 - * - * @param taskId - * @return - */ - @Autowired - private NmapconfigService nmapconfigService; - - /** - * 根据taskId执行任务 - * synchronized 防止定时任务同时启动时丢任务 - * - * @param taskId - * @return - */ - public synchronized Map executeWork(String taskId) throws InterruptedException { - Map taskInfo = new LinkedHashMap<>(); - int agentCount; - List onlineAgentList = agentService.findAllByOnline(true); - if (onlineAgentList.isEmpty()) { - return null; - } else { - agentCount = onlineAgentList.size(); - } - - Task task = taskService.findById(taskId); - //任务未执行过,执行新任务 - if (Objects.isNull(task.getStarttime()) && Objects.isNull(task.getEndtime())) { - Map taskConfig; - String taskWorkType = task.getWorktype(); - //mass、mass2Nmap、nmap - if ("mass".equals(taskWorkType) || "mass2Nmap".equals(taskWorkType) || "nmap".equals(taskWorkType)) { - //ip分组,进redis - String sliceIPList = TargetIpSlicer.slice(taskId, taskInfo, assetipService, taskipService, taskService, assetportService, redisTemplate, rabbitMessagingTemplate, agentCount); - if (!Objects.isNull(sliceIPList)) { - //分组数存入redis - double sliceIPListSize = redisTemplate.opsForList().size(sliceIPList); - //向上取整,确保所有的agent取出的数量大于等于总数 - double maxSliceSize = Math.ceil(sliceIPListSize / agentCount); - - redisTemplate.opsForValue().set("sliceIPListSize_" + taskId, String.valueOf(redisTemplate.opsForList().size(sliceIPList))); - taskConfig = pojoTask2TaskConfigMap(taskId, sliceIPList, task); - //记录任务开始时间 - task.setStarttime(new Date()); - taskService.update(task); - //任务丢给MQ - taskConfig.put("maxSliceSize", String.valueOf(maxSliceSize)); - rabbitMessagingTemplate.convertAndSend("tijifanout", "", taskConfig); - //rabbitMessagingTemplate.convertAndSend(taskWorkType + "fanout", "", taskConfig); - } else { - taskInfo.put("目标ip为空", "目标ip为空"); - } - } - } else { - //已执行过,重复任务 - taskInfo = repeat(taskId); - } - - return taskInfo; - } - - /** - * work任务结束,发送check任务 - * 根据taskId执行check任务 - * synchronized 防止定时任务同时启动时丢任务 - * - * @param taskId - * @return - */ - public synchronized Map executeCheck(String taskId) { - Map taskInfo = new LinkedHashMap<>(); - int agentCount; - List onlineAgentList = agentService.findAllByOnline(true); - if (onlineAgentList.isEmpty()) { - return null; - } else { - agentCount = onlineAgentList.size(); - } - - Task task = taskService.findById(taskId); - String taskWorkType = task.getWorktype(); - //结束时间不为空,任务已完成 - if (("mass2Nmap".equals(taskWorkType) || "nmap".equals(taskWorkType)) && (!Objects.isNull(task.getStarttime()) && !Objects.isNull(task.getEndtime()))) { - //进行check任务 - // nse,selfd,httpp - String taskCheckType = task.getChecktype(); - Set nseSet = new TreeSet<>(); - Set selfdSet = new TreeSet<>(); - if (taskCheckType.contains("nse") || taskCheckType.contains("selfd")) { - //获取所有插件 - //根据插件的service确定ip和端口 - List pluginAssetServiceList; - List taskidInTaskpluginConfig = taskpluginconfigService.findAllByTaskid(taskId); - if (taskidInTaskpluginConfig.isEmpty()) { - pluginAssetServiceList = pluginassetserviceService.findAll(); - } else { - pluginAssetServiceList = pluginassetserviceService.findPluginassetserviceByTaskid(taskId); - } - //List pluginAssetServiceList = pluginassetserviceService.findAll(); - if (!pluginAssetServiceList.isEmpty()) { - pluginAssetServiceList.forEach(pluginassetservice -> { - String pluginConfigId = pluginassetservice.getPluginconfigid(); - //根据插件的service确定插件 - String serviceName = pluginassetservice.getAssetservice(); - //根据service获取开放端口列表 - plugin2NseAndSelfdSet(nseSet, selfdSet, pluginconfigService, pluginConfigId, taskId, "service", serviceName); - }); - } - //根据插件的version确定ip和端口 - List pluginAssetVersionList; - taskidInTaskpluginConfig = taskpluginconfigService.findAllByTaskid(taskId); - if (taskidInTaskpluginConfig.isEmpty()) { - pluginAssetVersionList = pluginassetversionService.findAll(); - } else { - pluginAssetVersionList = pluginassetversionService.findPluginassetversionByTaskid(taskId); - } - - - //List pluginAssetVersionList = pluginassetversionService.findAll(); - if (!pluginAssetVersionList.isEmpty()) { - pluginAssetVersionList.forEach(pluginassetversion -> { - String pluginConfigId = pluginassetversion.getPluginconfigid(); - String versionName = pluginassetversion.getAssetversion(); - //根据version获取开放端口列表 - plugin2NseAndSelfdSet(nseSet, selfdSet, pluginconfigService, pluginConfigId, taskId, "version", versionName); - }); - } - } - - //有nse - if (taskCheckType.contains("nse") && !nseSet.isEmpty()) { - sendNewTask(task, "nse", redisTemplate, taskService, nseSet, agentCount); - } - //有selfd - if (taskCheckType.contains("selfd") && !selfdSet.isEmpty()) { - sendNewTask(task, "selfd", redisTemplate, taskService, selfdSet, agentCount); - } - //有httpp - if (taskCheckType.contains("httpp")) { - Set httpLikeOrUnsureServiceSet = getTaskPortHttpLikeOrUnsureService(taskId, taskipService); - if (httpLikeOrUnsureServiceSet.isEmpty()) - return null; - sendNewTask(task, "httpp", redisTemplate, taskService, httpLikeOrUnsureServiceSet, agentCount); - } - taskInfo.put(taskWorkType, "成功开始"); - return taskInfo; - } - return null; - } - - public void plugin2NseAndSelfdSet(Set nseSet, Set selfdSet, PluginconfigService pluginconfigService, String pluginConfigId, String taskId, String searchKey, String searchValue) { - List ipAndPortList; - if ("service".equals(searchKey)) { - ipAndPortList = taskipService.findByTaskidAndServiceLikeAndCheckwhitelistIsFalse(taskId, searchValue); - } else { - ipAndPortList = taskipService.findByTaskidAndVersionLikeAndCheckwhitelistIsFalse(taskId, searchValue); - } - - Pluginconfig pluginconfig = pluginconfigService.findById(pluginConfigId); - String pluginConfigName = pluginconfig.getName(); - String pluginConfigType = pluginconfig.getType(); - String pluginConfigArgs = pluginconfig.getArgs(); - String pluginConfigTimeout = pluginconfig.getTimeout(); - String pluginConfigPlugincode = pluginconfig.getPlugincode(); - String pluginConfigValidateType = pluginconfig.getValidatetype(); - - if (!ipAndPortList.isEmpty()) { - ipAndPortList.forEach(ipAndPort -> { - String ipv4 = ipAndPort.split(",")[0]; - String taskPortName = ipAndPort.split(",")[1]; - if ("selfd".equals(pluginConfigType)) { - //貌似service没啥用 - String taskServiceName = ipAndPort.split(",")[2]; - String taskVersionName = ipAndPort.split(",")[3]; - - //ip|port|pluginName|args|timeout|service|version - selfdSet.add(ipv4 + "<=-=>" + taskPortName + "<=-=>" + pluginConfigName + "<=-=>" + pluginConfigArgs + "<=-=>" + pluginConfigTimeout + "<=-=>" + pluginConfigPlugincode + "<=-=>" + pluginConfigValidateType + "<=-=>" + taskServiceName + "<=-=>" + taskVersionName); - } - //nse插件 - if ("nse".equals(pluginConfigType)) { - //192.168.1.1 -p21 --script ftp-anon --script-args ftp-anon.maxlist=0 - if (Objects.isNull(pluginConfigArgs) || pluginConfigArgs.isEmpty()) { - nseSet.add(ipv4 + " -p" + taskPortName + " --script " + pluginConfigName); - } else { - nseSet.add(ipv4 + " -p" + taskPortName + " --script " + pluginConfigName + " --script-args " + pluginConfigArgs); - } - } - }); - } - } - - public void sendNewTask(Task task, String workType, RedisTemplate redisTemplate, TaskService taskService, Collection target, int agentCount) { - Task newTask = getNewTask(task, workType); - taskService.add(newTask); - String newTaskId = newTask.getId(); - String sliceIPListName = workType + "SliceIPList_" + newTaskId; - target.forEach(singleCommand -> { - redisTemplate.opsForList().leftPush(sliceIPListName, singleCommand); - }); - //设置当前分组大小 - double sliceIPListSize = redisTemplate.opsForList().size(sliceIPListName); - redisTemplate.opsForValue().set("sliceIPListSize_" + newTaskId, String.valueOf(redisTemplate.opsForList().size(sliceIPListName))); - Map taskConfig = pojoTask2TaskConfigMap(newTaskId, sliceIPListName, newTask); - //记录任务开始时间 - newTask.setStarttime(new Date()); - taskService.update(newTask); - //任务丢给MQ - - //向上取整,确保所有的agent取出的数量大于等于总数 - double maxSliceSize = Math.ceil(sliceIPListSize / agentCount); - - taskConfig.put("maxSliceSize", String.valueOf(maxSliceSize)); - rabbitMessagingTemplate.convertAndSend("tijifanout", "", taskConfig); - //rabbitMessagingTemplate.convertAndSend(workType + "fanout", "", taskConfig); - } - - public Task getNewTask(Task oldTask, String workType) { - String newTaskId = idWorker.nextId() + ""; - Task newTask = new Task(newTaskId, oldTask.getId(), oldTask.getProjectid(), oldTask.getName(), oldTask.getDescription(), oldTask.getCronexpression(), oldTask.getCrontask(), null, null, - workType, workType, oldTask.getThreadnumber(), oldTask.getSingleipscantime(), oldTask.getAdditionoption(), oldTask.getRate(), oldTask.getTargetip(), - oldTask.getTargetport(), oldTask.getExcludeip(), oldTask.getIpslicesize(), oldTask.getPortslicesize(), oldTask.getDbipisexcludeip(), oldTask.getMerge2asset()); - newTask.setId(newTaskId); - //taskplugin复制一份旧的插件数据到新的task - if ("nse".equals(oldTask.getWorktype()) || "selfd".equals(oldTask.getWorktype())) { - List taskpluginconfigList = new ArrayList<>(); - List allByTaskid = taskpluginconfigService.findAllByTaskid(oldTask.getId()); - allByTaskid.forEach(taskpluginconfig -> { - taskpluginconfigList.add(new Taskpluginconfig(idWorker.nextId() + "", newTaskId, taskpluginconfig.getPluginconfigid())); - }); - taskpluginconfigService.batchAdd(taskpluginconfigList); - } - - return newTask; - } - - //获取所有asset service的ip和端口:like http(http、https、httpx)、为空、null、tcpwrapped、unknown、包含? - private Set getAssetPortHttpLikeOrUnsureService(AssetipService assetipService, AssetportService assetportService) { - List assetportList = new ArrayList<>(); - - Map searchMap = new HashMap<>(); - searchMap.put("state", "open"); - searchMap.put("checkwhitelist", false); - searchMap.put("downtime", null); - - searchMap.put("service", "http"); - assetportList.addAll(assetportService.findSearch(searchMap)); - searchMap.put("service", "tcpwrapped"); - assetportList.addAll(assetportService.findSearch(searchMap)); - searchMap.put("service", "unknown"); - assetportList.addAll(assetportService.findSearch(searchMap)); - searchMap.put("service", "?"); - assetportList.addAll(assetportService.findSearch(searchMap)); - searchMap.put("service", "null"); - assetportList.addAll(assetportService.findSearch(searchMap)); - //为空的service - assetportList.addAll(assetportService.findAllByServiceAndServiceIsNullAndCheckwhitelistIsFalseAndDowntimeIsNull(null)); - - Set assetportSet = new HashSet<>(); - assetportList.parallelStream().forEach(assetport -> { - String assetipid = assetport.getAssetipid(); - String port = assetport.getPort(); - String service = assetport.getService(); - //Assetip assetip = assetipService.findById(assetipid); - Assetip assetip = assetipService.findByIdAndCheckwhitelistIsFalseAndPassivetimeIsNull(assetipid); - if (!Objects.isNull(assetip)) { - String ipaddressv4 = assetip.getIpaddressv4(); - String assetportId = assetport.getId(); - if (!Objects.isNull(service)) { - if (service.contains("https") || service.contains("ssl/http")) { - //https or https? - assetportSet.add(assetportId + "|" + "https://" + ipaddressv4 + ":" + port); - } else { - //others - assetportSet.add(assetportId + "|" + "http://" + ipaddressv4 + ":" + port); - } - } else { - //service 为null - assetportSet.add(assetportId + "|" + "http://" + ipaddressv4 + ":" + port); - } - } - }); - return assetportSet; - } - - //获取所有task service的ip和端口:like http(http、https、httpx)、为空、null、tcpwrapped、unknown、包含? - private Set getTaskPortHttpLikeOrUnsureService(String taskId, TaskipService taskipService) { - List taskIdAndIpAndPortList = taskipService.findAllByServiceLikeAndCheckwhitelistIsFalse(taskId, "http"); - taskIdAndIpAndPortList.addAll(taskipService.findAllByServiceLikeAndCheckwhitelistIsFalse(taskId, "tcpwrapped")); - taskIdAndIpAndPortList.addAll(taskipService.findAllByServiceLikeAndCheckwhitelistIsFalse(taskId, "unknown")); - taskIdAndIpAndPortList.addAll(taskipService.findAllByServiceLikeAndCheckwhitelistIsFalse(taskId, "?")); - taskIdAndIpAndPortList.addAll(taskipService.findAllByServiceLikeAndCheckwhitelistIsFalse(taskId, "null")); - //为空的service - taskIdAndIpAndPortList.addAll(taskipService.findByTaskidAndServiceIsNullAndCheckwhitelistIsFalse(taskId)); - - Set taskPortSet = new HashSet<>(); - taskIdAndIpAndPortList.parallelStream().forEach(taskIdAndIpAndPort -> { - String taskid = taskIdAndIpAndPort.split(",")[0]; - String taskip = taskIdAndIpAndPort.split(",")[1]; - String port = taskIdAndIpAndPort.split(",")[2]; - String service = taskIdAndIpAndPort.split(",")[3]; - //String taskPortId = taskPort.getId(); - //如果是taskPortId,则记录进webinfo时,端口的id是task的 - //改成assetPortId - //TODO 后续新增task的webinfo、checkresult之类的表?貌似没必要 - Assetip assetip = assetipService.findByIpaddressv4AndPassivetimeIsNull(taskip); - Assetport assetport = assetportService.findByAssetipidAndPortAndDowntimeIsNull(assetip.getId(), port); - if (!Objects.isNull(assetport)) { - String assetPortId = assetport.getId(); - if (!Objects.isNull(service)) { - if (service.contains("https") || service.contains("ssl/http")) { - //https or https? - taskPortSet.add(assetPortId + "|" + "https://" + taskip + ":" + port); - } else { - //others - taskPortSet.add(assetPortId + "|" + "http://" + taskip + ":" + port); - } - } else { - taskPortSet.add(assetPortId + "|" + "http://" + taskip + ":" + port); - } - } - }); - return taskPortSet; - } - - public Map pojoTask2TaskConfigMap(String taskId, String sliceIPList, Task task) { - String taskWorkType = task.getWorktype(); - Map taskConfig = new LinkedHashMap<>(); - taskConfig.put("status", "start"); - taskConfig.put("taskId", taskId); - taskConfig.put("workType", taskWorkType); - taskConfig.put("threadNumber", task.getThreadnumber()); - taskConfig.put("sliceIPList", sliceIPList); - taskConfig.put("singleIpScanTime", task.getSingleipscantime()); - taskConfig.put("additionOption", task.getAdditionoption()); - if ("mass".equals(taskWorkType) || "nmap".equals(taskWorkType) || "mass2Nmap".equals(taskWorkType)) { - taskConfig.put("targetPort", task.getTargetport()); - taskConfig.put("rate", task.getRate()); - } -// if (taskWorkType.equals("httpp")) { -// String userAgent; -// //每次任务随机UA -// List userAgentList = useragentService.findAllDistinctUserAgentList(); -// if (userAgentList.isEmpty()) { -// userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"; -// } else { -// Collections.shuffle(userAgentList); -// userAgent = userAgentList.get(0); -// } -// taskConfig.put("userAgent", userAgent); -// } - return taskConfig; - } - - public synchronized void executeTotalCheck(String oldTaskId) { - int agentCount; - List onlineAgentList = agentService.findAllByOnline(true); - if (onlineAgentList.isEmpty()) { - return; - } else { - System.out.println(onlineAgentList.size()); - agentCount = onlineAgentList.size(); - } - - double sliceIPListSize; - Map taskConfig; - Task oldTask = taskService.findById(oldTaskId); - String taskWorkType = oldTask.getWorktype(); - Task task; - String taskId; - if (Objects.isNull(oldTask.getStarttime())) { - task = oldTask; - taskId = oldTaskId; - } else { - task = getNewTask(oldTask, taskWorkType); - task.setCrontask(false); - task.setChecktype(null); - taskId = task.getId(); - } - switch (taskWorkType) { - case "nse": - //对资产库所有ip进行nse - Set nseSet = new TreeSet<>(); - //获取所有插件 - //根据插件的service确定插件 - List assetserviceList; - - //taskId 不在taskpluginconfig中,则没有配置插件,启用所有插件 - List taskidInTaskpluginConfig = taskpluginconfigService.findAllByTaskid(taskId); - if (taskidInTaskpluginConfig.isEmpty()) { - assetserviceList = pluginassetserviceService.findAll(); - } else { - assetserviceList = pluginassetserviceService.findPluginassetserviceByTaskid(taskId); - } - - //List assetserviceList = pluginassetserviceService.findAll(); - if (!assetserviceList.isEmpty()) { - assetserviceList.forEach(assetservice -> { - String pluginconfigid = assetservice.getPluginconfigid(); - Pluginconfig pluginconfig = pluginconfigService.findById(pluginconfigid); - String pluginconfigName = pluginconfig.getName(); - String pluginconfigType = pluginconfig.getType(); - String pluginconfigArgs = pluginconfig.getArgs(); - String serviceName = assetservice.getAssetservice(); - //根据service获取未下线且安全检测白名单为false的端口列表 - Map searchMap = new HashMap<>(); - searchMap.put("service", serviceName); - searchMap.put("state", "open"); - searchMap.put("checkwhitelist", false); - searchMap.put("downtime", null); - List assetportList = assetportService.findSearch(searchMap); - //List assetportList = assetportService.findByServiceLikeAndDowntimeIsNullAndWhitelistIsFalse(serviceName); - if (!assetportList.isEmpty()) { - assetportList.parallelStream().forEach(assetport -> { - String assetipid = assetport.getAssetipid(); - //Assetip assetip = assetipService.findById(assetipid); - Assetip assetip = assetipService.findByIdAndCheckwhitelistIsFalseAndPassivetimeIsNull(assetipid); - if (!Objects.isNull(assetip)) { - String ipv4 = assetip.getIpaddressv4(); - String assetPortName = assetport.getPort(); - //nse插件 - if ("nse".equals(pluginconfigType)) { - //192.168.1.1 -p21 --script ftp-anon --script-args ftp-anon.maxlist=0 - if (Objects.isNull(pluginconfigArgs) || pluginconfigArgs.isEmpty()) { - nseSet.add(ipv4 + " -p" + assetPortName + " --script " + pluginconfigName); - } else { - nseSet.add(ipv4 + " -p" + assetPortName + " --script " + pluginconfigName + " --script-args " + pluginconfigArgs); - } - } - } - }); - } - }); - } - List assetversionList; - - taskidInTaskpluginConfig = taskpluginconfigService.findAllByTaskid(taskId); - if (taskidInTaskpluginConfig.isEmpty()) { - assetversionList = pluginassetversionService.findAll(); - } else { - assetversionList = pluginassetversionService.findPluginassetversionByTaskid(taskId); - } - - //根据插件的version确定ip和端口 - //List assetversionList = pluginassetversionService.findAll(); - if (!assetversionList.isEmpty()) { - assetversionList.forEach(assetversion -> { - String pluginconfigid = assetversion.getPluginconfigid(); - Pluginconfig pluginconfig = pluginconfigService.findById(pluginconfigid); - String pluginconfigName = pluginconfig.getName(); - String pluginconfigType = pluginconfig.getType(); - String pluginconfigArgs = pluginconfig.getArgs(); - String versionName = assetversion.getAssetversion(); - //根据version获取未下线端口列表 - Map searchMap = new HashMap<>(); - searchMap.put("version", versionName); - searchMap.put("state", "open"); - searchMap.put("checkwhitelist", false); - searchMap.put("downtime", null); - List assetportList = assetportService.findSearch(searchMap); - //List assetportList = assetportService.findByVersionLikeAndDowntimeIsNullAndWhitelistIsFalse(versionName); - if (!assetportList.isEmpty()) { - assetportList.parallelStream().forEach(assetport -> { - String assetipid = assetport.getAssetipid(); - //Assetip assetip = assetipService.findById(assetipid); - Assetip assetip = assetipService.findByIdAndCheckwhitelistIsFalseAndPassivetimeIsNull(assetipid); - if (!Objects.isNull(assetip)) { - String ipv4 = assetip.getIpaddressv4(); - String assetPortName = assetport.getPort(); - //nse插件 - if ("nse".equals(pluginconfigType)) { - //192.168.1.1 -p21 --script ftp-anon --script-args ftp-anon.maxlist=0 - if (Objects.isNull(pluginconfigArgs) || pluginconfigArgs.isEmpty()) { - nseSet.add(ipv4 + " -p" + assetPortName + " --script " + pluginconfigName); - } else { - nseSet.add(ipv4 + " -p" + assetPortName + " --script " + pluginconfigName + " --script-args " + pluginconfigArgs); - } - } - } - }); - } - }); - } - if (nseSet.isEmpty()) { - taskpluginconfigService.deleteAllByTaskid(taskId); - return; - } - //写到redis - String nseSliceIPList = "nseSliceIPList_" + taskId; - nseSet.forEach(nseCommand -> { - redisTemplate.opsForList().leftPush(nseSliceIPList, nseCommand); - }); - //设置当前分组大小 - sliceIPListSize = redisTemplate.opsForList().size(nseSliceIPList); - redisTemplate.opsForValue().set("sliceIPListSize_" + taskId, String.valueOf(redisTemplate.opsForList().size(nseSliceIPList))); - taskConfig = pojoTask2TaskConfigMap(taskId, nseSliceIPList, task); - break; - case "selfd": - //查询资产库中所有未下线的ip - Set selfdSet = new TreeSet<>(); - - //taskId 不在taskpluginconfig中,则没有配置插件,启用所有插件 - taskidInTaskpluginConfig = taskpluginconfigService.findAllByTaskid(taskId); - if (taskidInTaskpluginConfig.isEmpty()) { - assetserviceList = pluginassetserviceService.findAll(); - } else { - assetserviceList = pluginassetserviceService.findPluginassetserviceByTaskid(taskId); - } - //获取所有插件 - //根据插件的service确定插件 - //assetserviceList = pluginassetserviceService.findAll(); - if (!assetserviceList.isEmpty()) { - assetserviceList.forEach(assetservice -> { - String pluginconfigid = assetservice.getPluginconfigid(); - Pluginconfig pluginconfig = pluginconfigService.findById(pluginconfigid); - String pluginconfigName = pluginconfig.getName(); - String pluginconfigType = pluginconfig.getType(); - String pluginconfigArgs = pluginconfig.getArgs(); - String pluginconfigTimeout = pluginconfig.getTimeout(); - String pluginconfigPlugincode = pluginconfig.getPlugincode(); - String pluginConfigValidateType = pluginconfig.getValidatetype(); - - //应该是这里,如果插件的service为空,则启用所有插件 - String serviceName = assetservice.getAssetservice(); - //根据service获取未下线且安全检测白名单为false的端口列表 - Map searchMap = new HashMap<>(); - searchMap.put("service", serviceName); - searchMap.put("state", "open"); - searchMap.put("checkwhitelist", false); - searchMap.put("downtime", null); - List assetportList = assetportService.findSearch(searchMap); - //List assetportList = assetportService.findByServiceLikeAndDowntimeIsNullAndCheckwhitelistIsFalseAndStateEquals(serviceName,"open"); - if (!assetportList.isEmpty()) { - assetportList.parallelStream().forEach(assetport -> { - String assetipid = assetport.getAssetipid(); - //Assetip assetip = assetipService.findById(assetipid); - Assetip assetip = assetipService.findByIdAndCheckwhitelistIsFalseAndPassivetimeIsNull(assetipid); - if (!Objects.isNull(assetip)) { - if ("selfd".equals(pluginconfigType)) { - //貌似service没啥用 - String ipv4 = assetip.getIpaddressv4(); - String assetPortName = assetport.getPort(); - String assetServiceName = assetport.getService(); - String assetVersionName = assetport.getVersion(); - - //ip|port|pluginName|args|timeout|service|version - selfdSet.add(ipv4 + "<=-=>" + assetPortName + "<=-=>" + pluginconfigName + "<=-=>" + pluginconfigArgs + "<=-=>" + pluginconfigTimeout + "<=-=>" + pluginconfigPlugincode + "<=-=>" + pluginConfigValidateType + "<=-=>" + assetServiceName + "<=-=>" + assetVersionName); - - } - } - }); - } - }); - } - - if (taskidInTaskpluginConfig.isEmpty()) { - assetversionList = pluginassetversionService.findAll(); - } else { - assetversionList = pluginassetversionService.findPluginassetversionByTaskid(taskId); - } - - //根据插件的version确定ip和端口 - //assetversionList = pluginassetversionService.findAll(); - if (!assetversionList.isEmpty()) { - assetversionList.forEach(assetversion -> { - String pluginconfigid = assetversion.getPluginconfigid(); - Pluginconfig pluginconfig = pluginconfigService.findById(pluginconfigid); - String pluginconfigName = pluginconfig.getName(); - String pluginconfigType = pluginconfig.getType(); - String pluginconfigArgs = pluginconfig.getArgs(); - String pluginconfigTimeout = pluginconfig.getTimeout(); - String pluginconfigPlugincode = pluginconfig.getPlugincode(); - String pluginConfigValidateType = pluginconfig.getValidatetype(); - - String versionName = assetversion.getAssetversion(); - //根据version获取未下线端口列表 - Map searchMap = new HashMap<>(); - searchMap.put("version", versionName); - searchMap.put("state", "open"); - searchMap.put("checkwhitelist", false); - searchMap.put("downtime", null); - List assetportList = assetportService.findSearch(searchMap); - //List assetportList = assetportService.findByVersionLikeAndDowntimeIsNullAndCheckwhitelistIsFalseAndStateEquals(versionName,"open"); - if (!assetportList.isEmpty()) { - assetportList.parallelStream().forEach(assetport -> { - String assetipid = assetport.getAssetipid(); - //Assetip assetip = assetipService.findById(assetipid); - Assetip assetip = assetipService.findByIdAndCheckwhitelistIsFalseAndPassivetimeIsNull(assetipid); - if (!Objects.isNull(assetip)) { - if ("selfd".equals(pluginconfigType)) { - //貌似service没啥用 - String ipv4 = assetip.getIpaddressv4(); - String assetPortName = assetport.getPort(); - String assetServiceName = assetport.getService(); - String assetVersionName = assetport.getVersion(); - - //ip|port|pluginName|args|timeout|service|version - selfdSet.add(ipv4 + "<=-=>" + assetPortName + "<=-=>" + pluginconfigName + "<=-=>" + pluginconfigArgs + "<=-=>" + pluginconfigTimeout + "<=-=>" + pluginconfigPlugincode + "<=-=>" + pluginConfigValidateType + "<=-=>" + assetServiceName + "<=-=>" + assetVersionName); - } - } - }); - } - }); - } - if (selfdSet.isEmpty()) { - return; - } - //写到redis - String selfdSliceIPList = "selfdSliceIPList_" + taskId; - //pluginconfigid|ip|port|pluginName|args|timeout - //127.0.0.1|6379|RedisInfo|info|1000 - selfdSet.forEach(selfdCommand -> { - redisTemplate.opsForList().leftPush(selfdSliceIPList, selfdCommand); - }); - //设置当前分组大小 - sliceIPListSize = redisTemplate.opsForList().size(selfdSliceIPList); - redisTemplate.opsForValue().set("sliceIPListSize_" + taskId, String.valueOf(redisTemplate.opsForList().size(selfdSliceIPList))); - taskConfig = pojoTask2TaskConfigMap(taskId, selfdSliceIPList, task); - break; - case "httpp": - //从数据库中获取http like - Set httpLikeOrUnsureServiceSet = getAssetPortHttpLikeOrUnsureService(assetipService, assetportService); - String httppSliceIPList = "httppSliceIPList_" + taskId; - if (httpLikeOrUnsureServiceSet.isEmpty()) - return; - httpLikeOrUnsureServiceSet.forEach(singleHttp -> { - redisTemplate.opsForList().leftPush(httppSliceIPList, singleHttp); - }); - //设置当前分组大小 - sliceIPListSize = redisTemplate.opsForList().size(httppSliceIPList); - redisTemplate.opsForValue().set("sliceIPListSize_" + taskId, String.valueOf(redisTemplate.opsForList().size(httppSliceIPList))); - taskConfig = pojoTask2TaskConfigMap(taskId, httppSliceIPList, task); - break; - default: - return; - } - //记录任务开始时间 - task.setStarttime(new Date()); - //清空任务结束时间 - //task.setEndtime(null); - taskService.update(task); - - //向上取整,确保所有的agent取出的数量大于等于总数 - double maxSliceSize = Math.ceil(sliceIPListSize / agentCount); - - //任务丢给MQ - taskConfig.put("maxSliceSize", String.valueOf(maxSliceSize)); - rabbitMessagingTemplate.convertAndSend("tijifanout", "", taskConfig); - //rabbitMessagingTemplate.convertAndSend(taskWorkType + "fanout", "", taskConfig); - } - - /** - * 根据taskId停止任务并删除计划任务 - * - * @param taskId - * @return - */ - public synchronized void stopMutilTaskAndDeleteSchedule(String taskId) throws SchedulerException { - List taskChildList = taskService.findAllByTaskparentid(taskId); - if (taskChildList.isEmpty()) { - stopSingleTaskAndDeleteSchedule(taskId); - } else { - stopSingleTaskAndDeleteSchedule(taskId); - for (Task childTask : taskChildList) { - String childTaskId = childTask.getId(); - stopSingleTaskAndDeleteSchedule(childTaskId); - } - } - - } - - private void stopSingleTaskAndDeleteSchedule(String taskId) throws SchedulerException { - //删除计划任务 - String jobKeyName = "jobKeyName_" + taskId; - String jobKeyGroup = "jobKeyGroup_" + taskId; - JobKey jobKey = JobKey.jobKey(jobKeyName, jobKeyGroup); - quartzJobService.deleteJob(jobKey); - - //停止任务 - Task task = taskService.findById(taskId); - - Map taskConfig = new HashMap<>(); - //任务丢给agent - taskConfig.put("taskId", taskId); - taskConfig.put("status", "stop"); - - - //取消crontask标记 - task.setCrontask(false); - //记录任务结束时间 - if (!Objects.isNull(task.getStarttime()) && Objects.isNull(task.getEndtime())) { - task.setEndtime(new Date()); - } - taskService.update(task); - rabbitMessagingTemplate.convertAndSend("tijifanout", "", taskConfig); - //rabbitMessagingTemplate.convertAndSend(task.getWorktype() + "fanout", "", taskConfig); - } - - /** - * 根据taskId获取任务状态 - * - * @param taskId - * @return - */ - public Map getMutilTaskStatus(String taskId) { - Map taskStatus = new LinkedHashMap<>(); - Task task = taskService.findById(taskId); - //未开始,starttime和endtime都为空 - if (Objects.isNull(task.getStarttime()) && Objects.isNull(task.getEndtime())) { - taskStatus.put("任务未开始", taskId); - //正在运行,starttime不为空,endtime空 - } else if (!Objects.isNull(task.getStarttime()) && Objects.isNull(task.getEndtime())) { - taskStatus.put("任务状态", getSingleTaskStatus(taskId, redisTemplate)); - //已完成 - } else if (!Objects.isNull(task.getStarttime()) && !Objects.isNull(task.getEndtime())) { - //判断子任务 - List taskChildList = taskService.findAllByTaskparentid(taskId); - //没有子任务 - if (taskChildList.isEmpty()) { - taskStatus.put("任务已完成", taskId); - - if (!redisTemplate.hasKey("sliceIPListSize_" + taskId)) { - //查询状态时清除已完成,防止任务被终结,但accomplishTaskList缓存没清除 - redisTemplate.delete("accomplishTaskList_" + taskId); - } - - //taskStatus.put("taskcomplicated", taskId); - } else { - taskChildList.forEach(childTask -> { - String childTaskId = childTask.getId(); - Map childTaskStatus = new LinkedHashMap<>(); - //子任务已完成 - if (!Objects.isNull(childTask.getStarttime()) && !Objects.isNull(childTask.getEndtime())) { - childTaskStatus.put("子任务已完成", childTaskId); - - if (!redisTemplate.hasKey("sliceIPListSize_" + taskId)) { - //查询状态时清除已完成,防止任务被终结,但accomplishTaskList缓存没清除 - redisTemplate.delete("accomplishTaskList_" + taskId); - } - - taskStatus.put("子任务状态" + childTaskId, childTaskStatus); - } else { - taskStatus.put("子任务状态" + childTaskId, getSingleTaskStatus(childTaskId, redisTemplate)); - } - }); - } - } - return taskStatus; - } - - //监控任务状态 - private Map getSingleTaskStatus(String taskId, RedisTemplate redisTemplate) { - Map taskStatus = new LinkedHashMap<>(); - //总任务数 - String totalTaskListName = "totalTaskList_" + taskId; - //已完成任务数 - String accomplishTaskListName = "accomplishTaskList_" + taskId; - //正在进行的,没有操作到这个.. - String workingTaskListName = "workingTaskList_" + taskId; - //分组大小 - String sliceIPListSizeName = "sliceIPListSize_" + taskId; - - - if (!redisTemplate.hasKey(sliceIPListSizeName)) { - //任务未在进行 - taskStatus.put("任务未在进行", taskId); - } else { - long totalTaskListSize = redisTemplate.opsForList().size(totalTaskListName); - long accomplishTaskListSize = redisTemplate.opsForList().size(accomplishTaskListName); - long workingTaskListSize = redisTemplate.opsForList().size(workingTaskListName); - - //正在进行等于 totalTaskList与accomplishTaskList的差集 - //redisTemplate.opsForList().differenceAndStore(totalTaskListName, accomplishTaskListName, workingTaskListName); - // - List totalTaskList = redisTemplate.opsForList().range(totalTaskListName, 0, -1); - List accomplishTaskList = redisTemplate.opsForList().range(accomplishTaskListName, 0, -1); - //正在进行 = 总任务 - 已完成 - //计算后,totalTaskList 就是 working task - if (totalTaskList != null && accomplishTaskList != null) { - totalTaskList.removeAll(accomplishTaskList); - } - taskStatus.put("已完成", String.valueOf(accomplishTaskListSize)); - //taskStatus.put("进行中", String.valueOf(workingTaskListSize)); - String worktype = taskService.findById(taskId).getWorktype(); - //为啥之前把nse给去掉了?不记得了 -// if (!worktype.equals("nse") && !worktype.equals("selfd") && !worktype.equals("httpp")) { - //修改插件核心,自定义插件也有PID了,执行文件的方式才有,Jep的方式与之前类似 - if (!"httpp".equals(worktype) && !"selfd".equals(worktype)) { - taskStatus.put("进行中", String.valueOf(totalTaskList.size())); - taskStatus.put("进行中PID", totalTaskList.toString()); - } - - if (redisTemplate.hasKey(sliceIPListSizeName)) { - //进度监控 - long sliceIPListSize = Long.parseLong(redisTemplate.opsForValue().get(sliceIPListSizeName)); - double taskPercentStatus = (double) accomplishTaskListSize / sliceIPListSize; - taskStatus.put("总数", String.valueOf(sliceIPListSize)); - taskStatus.put("剩余", String.valueOf(sliceIPListSize - accomplishTaskListSize)); - taskStatus.put("进度", String.valueOf(taskPercentStatus)); - //accomplishTaskListSize等于总分组数sliceIPList,任务结束 - if (accomplishTaskListSize == sliceIPListSize) { - taskStatus.put("任务结束", taskId); - } - } - } - return taskStatus; - } - - public synchronized Map repeat(String taskId) throws InterruptedException { - int agentCount; - List onlineAgentList = agentService.findAllByOnline(true); - if (onlineAgentList.isEmpty()) { - return null; - } else { - agentCount = onlineAgentList.size(); - } - - Task oldTask = taskService.findById(taskId); - String newTaskId = idWorker.nextId() + ""; - if ("mass2Nmap".equals(oldTask.getWorktype())) { - Nmapconfig oldNmapconfig = nmapconfigService.findByTaskid(taskId); - String nmapconfigId = idWorker.nextId() + ""; - String threadnumber = oldNmapconfig.getThreadnumber(); - String singleipscantime = oldNmapconfig.getSingleipscantime(); - String additionoption = oldNmapconfig.getAdditionoption(); - - Nmapconfig newNmapconfig = new Nmapconfig(); - newNmapconfig.setId(nmapconfigId); - newNmapconfig.setThreadnumber(threadnumber); - newNmapconfig.setSingleipscantime(singleipscantime); - newNmapconfig.setAdditionoption(additionoption); - newNmapconfig.setTaskid(newTaskId); - nmapconfigService.add(newNmapconfig); - } - - - Task newTask = new Task(newTaskId, taskId, oldTask.getProjectid(), oldTask.getName(), "repeatTask", oldTask.getCronexpression(), false, new Date(), null, - oldTask.getWorktype(), oldTask.getChecktype(), oldTask.getThreadnumber(), oldTask.getSingleipscantime(), oldTask.getAdditionoption(), oldTask.getRate(), oldTask.getTargetip(), - oldTask.getTargetport(), oldTask.getExcludeip(), oldTask.getIpslicesize(), oldTask.getPortslicesize(), oldTask.getDbipisexcludeip(), oldTask.getMerge2asset()); - newTask.setId(newTaskId); - taskService.add(newTask); - - Map taskInfo = new LinkedHashMap<>(); - //ip分组,进redis - String sliceIPList = TargetIpSlicer.slice(newTaskId, taskInfo, assetipService, taskipService, taskService, assetportService, redisTemplate, rabbitMessagingTemplate, agentCount); - Map taskConfig = pojoTask2TaskConfigMap(newTaskId, sliceIPList, newTask); - - //分组数存入redis - double sliceIPListSize = redisTemplate.opsForList().size(sliceIPList); - redisTemplate.opsForValue().set("sliceIPListSize_" + newTaskId, String.valueOf(redisTemplate.opsForList().size(sliceIPList))); - //向上取整,确保所有的agent取出的数量大于等于总数 - double maxSliceSize = Math.ceil(sliceIPListSize / agentCount); - taskConfig.put("maxSliceSize", String.valueOf(maxSliceSize)); - - rabbitMessagingTemplate.convertAndSend("tijifanout", "", taskConfig); - //rabbitMessagingTemplate.convertAndSend(newTask.getWorktype() + "fanout", "", taskConfig); - taskInfo.put("new task id", newTaskId); - return taskInfo; - } - - public Map getTaskStatusPercent(String taskId) { - Map taskStatus = new LinkedHashMap<>(); - //总任务数 - String totalTaskListName = "totalTaskList_" + taskId; - //已完成任务数 - String accomplishTaskListName = "accomplishTaskList_" + taskId; - //分组大小 - String sliceIPListSizeName = "sliceIPListSize_" + taskId; - - double taskPercent = 0; - Task task = taskService.findById(taskId); - //未开始,starttime和endtime都为空 - if (Objects.isNull(task.getStarttime()) && Objects.isNull(task.getEndtime())) { - taskPercent = 0; - } else if (!Objects.isNull(task.getStarttime()) && Objects.isNull(task.getEndtime())) { - long accomplishTaskListSize = redisTemplate.opsForList().size(accomplishTaskListName); - if (redisTemplate.hasKey(sliceIPListSizeName)) { - long sliceIPListSize = Long.parseLong(redisTemplate.opsForValue().get(sliceIPListSizeName)); - double taskPercentStatus = (double) accomplishTaskListSize / sliceIPListSize; - DecimalFormat b = new DecimalFormat("#.000000"); - taskPercent = Double.parseDouble(b.format(taskPercentStatus)) * 100; - if (accomplishTaskListSize == sliceIPListSize || taskPercentStatus > 100) { - taskPercent = 100; - } - taskStatus.put("总数", (double) sliceIPListSize); - taskStatus.put("已完成", (double) accomplishTaskListSize); - List totalTaskList = redisTemplate.opsForList().range(totalTaskListName, 0, -1); - List accomplishTaskList = redisTemplate.opsForList().range(accomplishTaskListName, 0, -1); - //正在进行 = 总任务 - 已完成 - //计算后,totalTaskList 就是 working task - if (totalTaskList != null && accomplishTaskList != null) { - totalTaskList.removeAll(accomplishTaskList); - } - String worktype = taskService.findById(taskId).getWorktype(); - if (!"httpp".equals(worktype) && !"selfd".equals(worktype)) { - assert totalTaskList != null; - taskStatus.put("进行中", (double) totalTaskList.size()); - taskStatus.put("PID", totalTaskList); - } - } - } else if (!Objects.isNull(task.getStarttime()) && !Objects.isNull(task.getEndtime())) { - taskPercent = 100; - } - taskStatus.put("percentage", taskPercent); - return taskStatus; - } -} diff --git a/center/src/main/java/com/tiji/center/service/TaskService.java b/center/src/main/java/com/tiji/center/service/TaskService.java deleted file mode 100755 index ac2e206..0000000 --- a/center/src/main/java/com/tiji/center/service/TaskService.java +++ /dev/null @@ -1,387 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.TaskDao; -import com.tiji.center.pojo.Assetport; -import com.tiji.center.pojo.Host; -import com.tiji.center.pojo.Task; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Expression; -import javax.persistence.criteria.Predicate; -import java.text.DecimalFormat; -import java.util.*; - -/** - * task服务层 - * - * @author 贰拾壹 - */ -@Service -public class TaskService { - - @Autowired - private TaskDao taskDao; - - @Autowired - private IdWorker idWorker; - @Autowired - private NmapconfigService nmapconfigService; - @Autowired - private RedisTemplate redisTemplate; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return taskDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return taskDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return taskDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Task findById(String id) { - return taskDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param task - */ - public void add(Task task) { - if (Objects.isNull(task.getId())) { - task.setId(idWorker.nextId() + ""); - } - //新增任务时设置默认值,后续丢到AOP? - if ((task.getWorktype().equals("mass") || task.getWorktype().equals("mass2Nmap")) && (Objects.isNull(task.getRate()) || task.getRate().isEmpty())) { - task.setRate("1000"); - } - - if (Objects.isNull(task.getIpslicesize()) || task.getIpslicesize().isEmpty()) { - if ((task.getWorktype().equals("nmap") || task.getWorktype().equals("mass2Nmap") || task.getWorktype().equals("mass")) && !task.getTargetip().equals("unknownPortSerVer") && !task.getTargetip().equals("ipAllPort")) { - task.setIpslicesize("255"); - } - } - - if ((Objects.isNull(task.getAdditionoption()) || task.getAdditionoption().isEmpty())) { - if (task.getWorktype().equals("nmap") || task.getWorktype().equals("nse")) { - if (task.getTargetip().equals("unknownPortSerVer") || task.getTargetip().equals("ipAllPort")) { - // 不能带open..否则扫不到关掉端口 - task.setAdditionoption("-Pn -sV --max-retries=1"); - } else { - task.setAdditionoption("-Pn -sV --max-retries=1 --open"); - } - } else { - task.setAdditionoption(""); - } - } - - if (Objects.isNull(task.getCrontask())) { - task.setCrontask(false); - } - if (Objects.isNull(task.getDbipisexcludeip())) { - task.setDbipisexcludeip(false); - } - if (Objects.isNull(task.getMerge2asset())) { - task.setMerge2asset(true); - } - if (Objects.isNull(task.getThreadnumber()) || task.getThreadnumber().isEmpty()) { - task.setThreadnumber("4"); - } - if (Objects.isNull(task.getSingleipscantime()) || task.getSingleipscantime().isEmpty()) { - task.setSingleipscantime("1"); - } - - - if (task.getWorktype().equals("nmap") && (Objects.isNull(task.getTargetport()) || task.getTargetport().isEmpty())) { - if ((Objects.isNull(task.getPortslicesize()) || task.getPortslicesize().isEmpty()) && !task.getTargetip().equals("unknownPortSerVer") && !task.getTargetip().equals("ipAllPort")) { - task.setPortslicesize("1000"); - } - } - taskDao.save(task); - } - - /** - * 修改 - * - * @param task - */ - public void update(Task task) { - taskDao.save(task); - } - - /** - * 删除 - * - * @param id - */ - @Transactional(value = "masterTransactionManager") - public void deleteById(String id) { - nmapconfigService.deleteAllByTaskid(id); - taskDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - ids.forEach(id -> { - Task task = findById(id); - deleteAllByTaskparentid(id); - if (task.getWorktype().equals("mass2Nmap")) { - //根据taskId删除nmap配置 - nmapconfigService.deleteAllByTaskid(id); - } - }); - taskDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 任务编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 任务父编号 - if (searchMap.get("taskparentid") != null && !"".equals(searchMap.get("taskparentid"))) { - //if (searchMap.get("taskparentid") != null) { - if (searchMap.get("taskparentid").equals("notall")) { - predicateList.add(cb.isNull(root.get("taskparentid").as(String.class))); - } else { - predicateList.add(cb.like(root.get("taskparentid").as(String.class), "%" + searchMap.get("taskparentid") + "%")); - } - } else { - - } - // 项目编号 - if (searchMap.get("projectid") != null && !"".equals(searchMap.get("projectid"))) { - predicateList.add(cb.like(root.get("projectid").as(String.class), "%" + searchMap.get("projectid") + "%")); - } - // 任务名称 - if (searchMap.get("name") != null && !"".equals(searchMap.get("name"))) { - predicateList.add(cb.like(root.get("name").as(String.class), "%" + searchMap.get("name") + "%")); - } - // 任务描述 - if (searchMap.get("description") != null && !"".equals(searchMap.get("description"))) { - predicateList.add(cb.like(root.get("description").as(String.class), "%" + searchMap.get("description") + "%")); - } - // cron表达式 - if (searchMap.get("cronexpression") != null && !"".equals(searchMap.get("cronexpression"))) { - predicateList.add(cb.like(root.get("cronexpression").as(String.class), "%" + searchMap.get("cronexpression") + "%")); - } - //cron任务 - if (searchMap.get("crontask") != null && !"".equals(searchMap.get("crontask"))) { - predicateList.add(cb.equal(root.get("crontask").as(Boolean.class), (searchMap.get("crontask")))); - } - //任务开始时间 - if (searchMap.get("starttime") != null && !"".equals(searchMap.get("starttime"))) { - List starttimeList = (List) searchMap.get("starttime"); - //开始 - predicateList.add(cb.greaterThanOrEqualTo(root.get("starttime").as(String.class), starttimeList.get(0))); - //结束 - predicateList.add(cb.lessThanOrEqualTo(root.get("starttime").as(String.class), starttimeList.get(1))); - } - //任务结束时间 - if (searchMap.get("endtime") != null && !"".equals(searchMap.get("endtime"))) { - List endtimeList = (List) searchMap.get("endtime"); - //开始 - predicateList.add(cb.greaterThanOrEqualTo(root.get("endtime").as(String.class), endtimeList.get(0))); - //结束 - predicateList.add(cb.lessThanOrEqualTo(root.get("endtime").as(String.class), endtimeList.get(1))); - } - // 任务类型 - if (searchMap.get("worktype") != null && !"".equals(searchMap.get("worktype"))) { - predicateList.add(cb.like(root.get("worktype").as(String.class), "%" + searchMap.get("worktype") + "%")); - } - // 检测类型 - if (searchMap.get("checktype") != null && !"".equals(searchMap.get("checktype"))) { - predicateList.add(cb.like(root.get("checktype").as(String.class), "%" + searchMap.get("checktype") + "%")); - } - // 线程数量 - if (searchMap.get("threadnumber") != null && !"".equals(searchMap.get("threadnumber"))) { - predicateList.add(cb.like(root.get("threadnumber").as(String.class), "%" + searchMap.get("threadnumber") + "%")); - } - // 单个ip扫描次数 - if (searchMap.get("singleipscantime") != null && !"".equals(searchMap.get("singleipscantime"))) { - predicateList.add(cb.like(root.get("singleipscantime").as(String.class), "%" + searchMap.get("singleipscantime") + "%")); - } - // 任务附加选项 - if (searchMap.get("additionoption") != null && !"".equals(searchMap.get("additionoption"))) { - predicateList.add(cb.like(root.get("additionoption").as(String.class), "%" + searchMap.get("additionoption") + "%")); - } - // 扫描速率 - if (searchMap.get("rate") != null && !"".equals(searchMap.get("rate"))) { - predicateList.add(cb.like(root.get("rate").as(String.class), "%" + searchMap.get("rate") + "%")); - } - // 目标ip - if (searchMap.get("targetip") != null && !"".equals(searchMap.get("targetip"))) { - predicateList.add(cb.like(root.get("targetip").as(String.class), "%" + searchMap.get("targetip") + "%")); - } - // 目标端口,为空为所有端口,regular为nmap默认端口,端口格式:80,443 - if (searchMap.get("targetport") != null && !"".equals(searchMap.get("targetport"))) { - predicateList.add(cb.like(root.get("targetport").as(String.class), "%" + searchMap.get("targetport") + "%")); - } - // 排除ip - if (searchMap.get("excludeip") != null && !"".equals(searchMap.get("excludeip"))) { - predicateList.add(cb.like(root.get("excludeip").as(String.class), "%" + searchMap.get("excludeip") + "%")); - } - // 分组大小 - if (searchMap.get("ipslicesize") != null && !"".equals(searchMap.get("ipslicesize"))) { - predicateList.add(cb.like(root.get("ipslicesize").as(String.class), "%" + searchMap.get("ipslicesize") + "%")); - } - // 端口分组大小,nmap全端口模式时,如果该字段有值,则进行端口分组,分组大小范围:1000-10000 - if (searchMap.get("portslicesize") != null && !"".equals(searchMap.get("portslicesize"))) { - predicateList.add(cb.like(root.get("portslicesize").as(String.class), "%" + searchMap.get("portslicesize") + "%")); - } - //db中ip作为排除ip - if (searchMap.get("dbipisexcludeip") != null && !"".equals(searchMap.get("dbipisexcludeip"))) { - predicateList.add(cb.equal(root.get("dbipisexcludeip").as(Boolean.class), (searchMap.get("dbipisexcludeip")))); - } - //扫描结果合并到资产 - if (searchMap.get("merge2asset") != null && !"".equals(searchMap.get("merge2asset"))) { - predicateList.add(cb.equal(root.get("merge2asset").as(Boolean.class), (searchMap.get("merge2asset")))); - } - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 查询starttime不为空的task - * - * @return - */ - public List findAllByEndtimeIsNullAndStarttimeIsNotNull() { - return taskDao.findAllByEndtimeIsNullAndStarttimeIsNotNull(); - } - - - /** - * 根据worktype查询starttime endtime不为空的task - * - * @return - */ - public List findAllByWorktypeAndEndtimeIsNotNullAndStarttimeIsNotNull(String worktype) { - return taskDao.findAllByWorktypeAndEndtimeIsNotNullAndStarttimeIsNotNull(worktype); - } - - /** - * 查询所有crontask - * - * @return - */ - public List findAllByCrontaskIsTrueAndTaskparentidIsNull() { - return taskDao.findAllByCrontaskIsTrueAndTaskparentidIsNull(); - } - - /** - * 根据taskParentId查询实体 - * - * @param taskParentId - * @return - */ - public List findAllByTaskparentid(String taskParentId) { - return taskDao.findAllByTaskparentid(taskParentId); - } - - /** - * 根据name查询实体 - * - * @param name - * @return - */ - public Task findByName(String name) { - return taskDao.findByName(name); - } - - /** - * 根据id - * - * @param taskParentId - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByTaskparentid(String taskParentId) { - taskDao.deleteAllByTaskparentid(taskParentId); - } - - /** - * 根据taskId获取状态 - * - * @param taskId - * @return - */ - public Double getTaskPercent(String taskId) { - String accomplishTaskListName = "accomplishTaskList_" + taskId; - String sliceIPListSizeName = "sliceIPListSize_" + taskId; - double taskPercent = 0; - Task task = findById(taskId); - if (Objects.isNull(task.getStarttime()) && Objects.isNull(task.getEndtime())) { - taskPercent = 0; - } else if (!Objects.isNull(task.getStarttime()) && Objects.isNull(task.getEndtime())) { - long accomplishTaskListSize = redisTemplate.opsForList().size(accomplishTaskListName); - if (redisTemplate.hasKey(sliceIPListSizeName)) { - long sliceIPListSize = Long.parseLong(redisTemplate.opsForValue().get(sliceIPListSizeName)); - double taskPercentStatus = (double) accomplishTaskListSize / sliceIPListSize; - DecimalFormat b = new DecimalFormat("#.000000"); - taskPercent = Double.parseDouble(b.format(taskPercentStatus)) * 100; - if (accomplishTaskListSize == sliceIPListSize || taskPercentStatus > 100) { - taskPercent = 100; - } - } - } else if (!Objects.isNull(task.getStarttime()) && !Objects.isNull(task.getEndtime())) { - taskPercent = 100; - } - return taskPercent; - } -} diff --git a/center/src/main/java/com/tiji/center/service/TaskipService.java b/center/src/main/java/com/tiji/center/service/TaskipService.java deleted file mode 100755 index eaffd89..0000000 --- a/center/src/main/java/com/tiji/center/service/TaskipService.java +++ /dev/null @@ -1,342 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.TaskipDao; -import com.tiji.center.pojo.Taskip; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * taskip服务层 - * - * @author 贰拾壹 - */ -@Service -public class TaskipService { - - @Autowired - private TaskipDao taskipDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return taskipDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return taskipDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return taskipDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Taskip findById(String id) { - return taskipDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param taskip - */ - public void add(Taskip taskip) { - if (Objects.isNull(taskip.getId())) { - taskip.setId(idWorker.nextId() + ""); - } - if (Objects.isNull(taskip.getCheckwhitelist())) { - taskip.setCheckwhitelist(false); - } - taskipDao.save(taskip); - } - - /** - * 修改 - * - * @param taskip - */ - public void update(Taskip taskip) { - taskipDao.save(taskip); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - taskipDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - taskipDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 资产ip编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 任务编号 - if (searchMap.get("taskid") != null && !"".equals(searchMap.get("taskid"))) { - predicateList.add(cb.like(root.get("taskid").as(String.class), "%" + searchMap.get("taskid") + "%")); - } - // ip地址 - if (searchMap.get("ipaddressv4") != null && !"".equals(searchMap.get("ipaddressv4"))) { - predicateList.add(cb.like(root.get("ipaddressv4").as(String.class), "%" + searchMap.get("ipaddressv4") + "%")); - } - // ipaddressv6 - if (searchMap.get("ipaddressv6") != null && !"".equals(searchMap.get("ipaddressv6"))) { - predicateList.add(cb.like(root.get("ipaddressv6").as(String.class), "%" + searchMap.get("ipaddressv6") + "%")); - } - //安全检测白名单 - if (searchMap.get("checkwhitelist") != null && !"".equals(searchMap.get("checkwhitelist"))) { - predicateList.add(cb.equal(root.get("checkwhitelist").as(Boolean.class), (searchMap.get("checkwhitelist")))); - } - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 批量增加 - * - * @param assetipList - */ - public void batchAdd(List assetipList) { - taskipDao.saveAll(assetipList); - } - - - /** - * 根据taskID查询实体 - * - * @param taskId - * @return - */ - public List findByTaskId(String taskId) { - return taskipDao.findByTaskid(taskId); - } - - /** - * 根据taskid和ipaddressv4查询ip - * - * @return Taskip - */ - public Taskip findByTaskidAndIpaddressv4(String taskid, String ipaddressv4) { - return taskipDao.findByTaskidAndIpaddressv4(taskid, ipaddressv4); - } - - /** - * 根据taskid查询ip和端口 - * - * @return List - */ - public List findTaskIpAndPort(String taskid) { - return taskipDao.findTaskIpAndPort(taskid); - } - - - /** - * 根据taskID查询不在check白名单的实体 - * - * @param taskId - * @return - */ - public List findAllByTaskidAndCheckwhitelistIsFalse(String taskId) { - return taskipDao.findAllByTaskidAndCheckwhitelistIsFalse(taskId); - } - - /** - * findAllByHttpLike,state="open" - * - * @param taskId - * @return - */ - public List findAllByServiceLikeAndCheckwhitelistIsFalse(String taskId, String serviceLike) { - return taskipDao.findAllByServiceLikeAndCheckwhitelistIsFalse(taskId, "%" + serviceLike + "%"); - } - - /** - * 查询所有service为空的端口 - * - * @param taskId - * @return - */ - public List findByTaskidAndServiceIsNullAndCheckwhitelistIsFalse(String taskId) { - return taskipDao.findByTaskidAndServiceIsNullAndCheckwhitelistIsFalse(taskId); - } - - /** - * 根据taskId查询所有不在check白名单的,按照searchKey like searchValue的ip和端口、service、version,state="open" - * - * @param taskId - * @return - */ - public List findByTaskidAndServiceLikeAndCheckwhitelistIsFalse(String taskId, String serviceLike) { - return taskipDao.findByTaskidAndServiceLikeAndCheckwhitelistIsFalse(taskId, serviceLike); - } - - /** - * 根据taskId查询所有不在check白名单的,按照searchKey like searchValue的ip和端口、service、version ,state="open" - * - * @param taskId - * @return - */ - public List findByTaskidAndVersionLikeAndCheckwhitelistIsFalse(String taskId, String versionLike) { - return taskipDao.findByTaskidAndVersionLikeAndCheckwhitelistIsFalse(taskId, versionLike); - } - - - /** - * 查询未下线的ip所有漏洞 - * - * @return - */ - public List findAllVulns() { - return taskipDao.findAllVulns(); - } - - /** - * 查询未下线的ip,不在白名单的资产 - * - * @return - */ - public List findAllAssets() { - return taskipDao.findAllAssets(); - } - - /** - * 查询需要发邮件资产的数量 - * - * @return - */ - public long findAllAssetsCount() { - return taskipDao.findAllAssetsCount(); - } - - /** - * 分页查询未下线的ip,不在白名单的资产 - * - * @return - */ - public List> findAllAssetsByPage(long offset, long rows) { - return taskipDao.findAllAssetsByPage(offset, rows); - } - - /** - * 分页查询未下线的ip,不在白名单的资产 - * - * @return - */ - public List> findAllAssetsByPageNew(long offset, long rows) { - return taskipDao.findAllAssetsByPageNew(offset, rows); - } - - - /** - * 根据id数组查询 - * - * @param ids - * @return - */ - public List findByIds(String[] ids) { - List taskIpIdAndIpList = new ArrayList<>(); - for (String taskIpId : ids) { - Taskip taskip = findById(taskIpId); - if (Objects.isNull(taskip)) { - taskIpIdAndIpList.add(taskIpId + "-" + null); - } else { - taskIpIdAndIpList.add(taskIpId + "-" + taskip.getIpaddressv4()); - } - } - return taskIpIdAndIpList.isEmpty() ? null : taskIpIdAndIpList; - } - - /** - * 查询所有没有端口的ip - * - * @return - */ - public List findAllAssetipNoPort() { - return taskipDao.findAllAssetipNoPort(); - } - - - /** - * 查询未修复的检查结果数量 - * - * @return - */ - public long findAllVulnsCount() { - return taskipDao.findAllVulnsCount(); - } - - /** - * 分页查询未修复的检查结果 - * - * @return - */ - public List> findAllVulnsByPage(long offset, long rows) { - return taskipDao.findAllVulnsByPage(offset, rows); - } - - -} diff --git a/center/src/main/java/com/tiji/center/service/TaskpluginconfigService.java b/center/src/main/java/com/tiji/center/service/TaskpluginconfigService.java deleted file mode 100755 index 6af7ee7..0000000 --- a/center/src/main/java/com/tiji/center/service/TaskpluginconfigService.java +++ /dev/null @@ -1,218 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.TaskpluginconfigDao; -import com.tiji.center.pojo.Taskpluginconfig; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * taskpluginconfig服务层 - * - * @author 贰拾壹 - */ -@Service -public class TaskpluginconfigService { - - @Autowired - private TaskpluginconfigDao taskpluginconfigDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return taskpluginconfigDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return taskpluginconfigDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return taskpluginconfigDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Taskpluginconfig findById(String id) { - return taskpluginconfigDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param taskpluginconfig - */ - public void add(Taskpluginconfig taskpluginconfig) { - if (Objects.isNull(taskpluginconfig.getId())) { - taskpluginconfig.setId(idWorker.nextId() + ""); - } - taskpluginconfigDao.save(taskpluginconfig); - } - - /** - * 修改 - * - * @param taskpluginconfig - */ - public void update(Taskpluginconfig taskpluginconfig) { - taskpluginconfigDao.save(taskpluginconfig); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - taskpluginconfigDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - taskpluginconfigDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 任务编号 - if (searchMap.get("taskid") != null && !"".equals(searchMap.get("taskid"))) { - predicateList.add(cb.equal(root.get("taskid").as(String.class), searchMap.get("taskid"))); - } - // 插件编号 - if (searchMap.get("pluginconfigid") != null && !"".equals(searchMap.get("pluginconfigid"))) { - predicateList.add(cb.equal(root.get("pluginconfigid").as(String.class), searchMap.get("pluginconfigid"))); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据taskid pluginconfigid查询实体 - * - * @param taskid - * @param pluginconfigid - * @return - */ - public Taskpluginconfig findByTaskidAndPluginconfigid(String taskid, String pluginconfigid) { - return taskpluginconfigDao.findByTaskidAndPluginconfigid(taskid, pluginconfigid); - } - - - /** - * 查询全部列表 - * - * @return - */ - public List findAllByTaskid(String taskid) { - return taskpluginconfigDao.findAllByTaskid(taskid); - } - - /** - * 查询全部列表 - * - * @return - */ - public List findPluginconfigidByTaskid(String taskid) { - return taskpluginconfigDao.findPluginconfigidByTaskid(taskid); - } - - /** - * 删除 - * - * @param taskid - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByTaskid(String taskid) { - taskpluginconfigDao.deleteAllByTaskid(taskid); - } - - /** - * 删除 - * - * @param pluginconfigid - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByPluginconfigid(String pluginconfigid) { - taskpluginconfigDao.deleteAllByPluginconfigid(pluginconfigid); - } - - - /** - * 删除 - * - * @param taskid - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByTaskidAndPluginconfigid(String taskid, String pluginconfigid) { - taskpluginconfigDao.deleteAllByTaskidAndPluginconfigid(taskid, pluginconfigid); - } - - - /** - * 批量增加 - * - * @param taskpluginconfigList - */ - public void batchAdd(List taskpluginconfigList) { - taskpluginconfigDao.saveAll(taskpluginconfigList); - } -} diff --git a/center/src/main/java/com/tiji/center/service/TaskportService.java b/center/src/main/java/com/tiji/center/service/TaskportService.java deleted file mode 100755 index aa5ace7..0000000 --- a/center/src/main/java/com/tiji/center/service/TaskportService.java +++ /dev/null @@ -1,251 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.TaskportDao; -import com.tiji.center.pojo.Taskport; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * taskport服务层 - * - * @author 贰拾壹 - */ -@Service -public class TaskportService { - - @Autowired - private TaskportDao taskportDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return taskportDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return taskportDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return taskportDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Taskport findById(String id) { - return taskportDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param taskport - */ - public void add(Taskport taskport) { - if (Objects.isNull(taskport.getId())) { - taskport.setId(idWorker.nextId() + ""); - } - if (Objects.isNull(taskport.getCheckwhitelist())) { - taskport.setCheckwhitelist(false); - } - taskportDao.save(taskport); - } - - /** - * 修改 - * - * @param taskport - */ - public void update(Taskport taskport) { - taskportDao.save(taskport); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - taskportDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - taskportDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 端口编号 - //if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - // predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - //} - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.in(root.get("id")).value(searchMap.get("id"))); - } - - // 资产ip编号 - if (searchMap.get("taskipid") != null && !"".equals(searchMap.get("taskipid"))) { - predicateList.add(cb.like(root.get("taskipid").as(String.class), "%" + searchMap.get("taskipid") + "%")); - } - // 端口 - if (searchMap.get("port") != null && !"".equals(searchMap.get("port"))) { - predicateList.add(cb.like(root.get("port").as(String.class), "%" + searchMap.get("port") + "%")); - } - // 端口协议 - if (searchMap.get("protocol") != null && !"".equals(searchMap.get("protocol"))) { - predicateList.add(cb.like(root.get("protocol").as(String.class), "%" + searchMap.get("protocol") + "%")); - } - // 端口开放状态 - if (searchMap.get("state") != null && !"".equals(searchMap.get("state"))) { - predicateList.add(cb.like(root.get("state").as(String.class), "%" + searchMap.get("state") + "%")); - } - // 端口服务 - if (searchMap.get("service") != null && !"".equals(searchMap.get("service"))) { - predicateList.add(cb.like(root.get("service").as(String.class), "%" + searchMap.get("service") + "%")); - } - // 服务版本 - if (searchMap.get("version") != null && !"".equals(searchMap.get("version"))) { - predicateList.add(cb.like(root.get("version").as(String.class), "%" + searchMap.get("version") + "%")); - } - //安全检测白名单 - if (searchMap.get("checkwhitelist") != null && !"".equals(searchMap.get("checkwhitelist"))) { - predicateList.add(cb.equal(root.get("checkwhitelist").as(Boolean.class), searchMap.get("checkwhitelist"))); - } - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 批量增加 - * - * @param portList - */ - public void batchAdd(List portList) { - taskportDao.saveAll(portList); - } - - /** - * 根据taskIpId查询实体 - * - * @param taskIpId - * @return - */ - public List findByTaskipid(String taskIpId) { - return taskportDao.findByTaskipid(taskIpId); - } - - /** - * 根据 taskipid,port查询端口 - * - * @param taskipid - * @param taskport - * @return Taskport - */ - public Taskport findByTaskipidAndPort(String taskipid, String taskport) { - return taskportDao.findByTaskipidAndPort(taskipid, taskport); - } - - /** - * 根据 taskipid,port查询端口 - * - * @param taskIpId - * @param state - * @return list - */ - public List findByTaskipidAndState(String taskIpId, String state) { - return taskportDao.findByTaskipidAndState(taskIpId, state); - } - - /** - * 查根据service和state查询端口 - * - * @param taskipid - * @param service - * @param state - * @return - */ - - public List findByTaskipidAndServiceAndState(String taskipid, String service, String state) { - return taskportDao.findByTaskipidAndServiceAndState(taskipid, service, state); - } - - /** - * 查根据version和state查询端口 - * - * @param taskipid - * @param version - * @param state - * @return - */ - - public List findByTaskipidAndVersionAndState(String taskipid, String version, String state) { - return taskportDao.findByTaskipidAndVersionAndState(taskipid, version, state); - } - - /** - * 根据taskipid批量删除 - * - * @param taskipid - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByTaskipid(String taskipid) { - taskportDao.deleteAllByTaskipid(taskipid); - } - -} diff --git a/center/src/main/java/com/tiji/center/service/TitlewhitelistService.java b/center/src/main/java/com/tiji/center/service/TitlewhitelistService.java deleted file mode 100755 index fa57a2a..0000000 --- a/center/src/main/java/com/tiji/center/service/TitlewhitelistService.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.TitlewhitelistDao; -import com.tiji.center.pojo.Titlewhitelist; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * titlewhitelist服务层 - * - * @author 贰拾壹 - */ -@Service -public class TitlewhitelistService { - - @Autowired - private TitlewhitelistDao titlewhitelistDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return titlewhitelistDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return titlewhitelistDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return titlewhitelistDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Titlewhitelist findById(String id) { - return titlewhitelistDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param titlewhitelist - */ - public void add(Titlewhitelist titlewhitelist) { - if (Objects.isNull(titlewhitelist.getId())) { - titlewhitelist.setId(idWorker.nextId() + ""); - } - titlewhitelistDao.save(titlewhitelist); - } - - /** - * 修改 - * - * @param titlewhitelist - */ - public void update(Titlewhitelist titlewhitelist) { - titlewhitelistDao.save(titlewhitelist); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - titlewhitelistDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - titlewhitelistDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 参数编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 标题 - if (searchMap.get("title") != null && !"".equals(searchMap.get("title"))) { - predicateList.add(cb.like(root.get("title").as(String.class), "%" + (String) searchMap.get("title") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据title查询实体 - * - * @param title - * @return - */ - public Titlewhitelist findByTitle(String title) { - return titlewhitelistDao.findByTitle(title); - } - - - @Transactional(value = "masterTransactionManager") - public void deleteByTitle(String title) { - titlewhitelistDao.deleteByTitle(title); - } -} diff --git a/center/src/main/java/com/tiji/center/service/UrlService.java b/center/src/main/java/com/tiji/center/service/UrlService.java deleted file mode 100755 index e683eac..0000000 --- a/center/src/main/java/com/tiji/center/service/UrlService.java +++ /dev/null @@ -1,217 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.UrlDao; -import com.tiji.center.pojo.Assetport; -import com.tiji.center.pojo.Url; -import com.tiji.center.pojo.Webinfo; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * url服务层 - * - * @author 贰拾壹 - */ -@Service -public class UrlService { - - @Autowired - private UrlDao urlDao; - - @Autowired - private IdWorker idWorker; - /** - * 根据webinfoids查询所有链接pojo,webinfoid替换成端口 - * - * @param webinfoids - * @return - */ - @Autowired - private WebinfoService webinfoService; - @Autowired - private AssetportService assetportService; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return urlDao.findAll(); - } - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return urlDao.findAll(specification, pageRequest); - } - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return urlDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Url findById(String id) { - return urlDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param url - */ - public void add(Url url) { - if (Objects.isNull(url.getId())) { - url.setId(idWorker.nextId() + ""); - } - urlDao.save(url); - } - - /** - * 修改 - * - * @param url - */ - public void update(Url url) { - urlDao.save(url); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - urlDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - urlDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // url编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // web信息编号 - if (searchMap.get("webinfoid") != null && !"".equals(searchMap.get("webinfoid"))) { - predicateList.add(cb.like(root.get("webinfoid").as(String.class), "%" + searchMap.get("webinfoid") + "%")); - } - // 名称 - if (searchMap.get("name") != null && !"".equals(searchMap.get("name"))) { - predicateList.add(cb.like(root.get("name").as(String.class), "%" + searchMap.get("name") + "%")); - } - // url - if (searchMap.get("url") != null && !"".equals(searchMap.get("url"))) { - predicateList.add(cb.like(root.get("url").as(String.class), "%" + searchMap.get("url") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[0])); - - }; - - } - - /** - * 根据webinfoid批量删除 - * - * @param webinfoid - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByWebinfoid(String webinfoid) { - urlDao.deleteAllByWebinfoid(webinfoid); - } - - /** - * 根据webinfoid查询 - * - * @param webinfoid webinfoid - * @return - */ - public List findAllByWebinfoid(String webinfoid) { - return urlDao.findAllByWebinfoid(webinfoid); - } - - /** - * 根据webinfoids查询所有链接pojo - * - * @param webinfoids - * @return - */ - public List findAllByWebinfoids(String[] webinfoids) { - List urlList = new ArrayList<>(); - for (String webinfoid : webinfoids) { - urlList.addAll(urlDao.findAllByWebinfoid(webinfoid)); - } - return urlList; - } - - public List findAllByWebinfoIds2Port(String[] webinfoids) { - List resultList = new ArrayList<>(); - for (String webinfoid : webinfoids) { - List urlList = urlDao.findAllByWebinfoid(webinfoid); - for (Url url : urlList) { - Webinfo webinfo = webinfoService.findById(webinfoid); - String portid = webinfo.getPortid(); - Assetport assetport = assetportService.findById(portid); - url.setWebinfoid(assetport.getPort()); - resultList.add(url); - } - } - return resultList; - } - - public StringBuilder findLinksByWebinfoId(String webinfoid) { - StringBuilder result = new StringBuilder(); - List urlList = urlDao.findAllByWebinfoid(webinfoid); - urlList.parallelStream().forEach(url -> result.append(url.getName()).append(" ").append(url.getUrl()).append("\n")); - return result; - } -} diff --git a/center/src/main/java/com/tiji/center/service/UserService.java b/center/src/main/java/com/tiji/center/service/UserService.java deleted file mode 100755 index 4f7043a..0000000 --- a/center/src/main/java/com/tiji/center/service/UserService.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.UserDao; -import com.tiji.center.pojo.User; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * user服务层 - * - * @author 贰拾壹 - */ -@Service -public class UserService { - - @Autowired - private UserDao userDao; - - @Autowired - private IdWorker idWorker; - - @Autowired - private BCryptPasswordEncoder bCryptPasswordEncoder; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return userDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return userDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return userDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public User findById(String id) { - return userDao.findById(id).isPresent() ? userDao.findById(id).get() : null; - } - - - /** - * 增加 - * - * @param user - */ - public void add(User user) { - if (Objects.isNull(user.getId())) { - user.setId(idWorker.nextId() + ""); - } - if (Objects.isNull(user.getAdmin())) { - user.setAdmin(false); - } - if (Objects.isNull(user.getActive())) { - user.setActive(false); - } - String encodePassword = bCryptPasswordEncoder.encode(user.getPassword()); - user.setPassword(encodePassword); - userDao.save(user); - } - - /** - * 修改 - * - * @param user - */ - public void update(User user) { - userDao.save(user); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - userDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - userDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 用户编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 用户名 - if (searchMap.get("username") != null && !"".equals(searchMap.get("username"))) { - predicateList.add(cb.like(root.get("username").as(String.class), "%" + searchMap.get("username") + "%")); - } - //// 密码 - //if (searchMap.get("password") != null && !"".equals(searchMap.get("password"))) { - // predicateList.add(cb.like(root.get("password").as(String.class), "%" + searchMap.get("password") + "%")); - //} - // 头像地址 - if (searchMap.get("avatar") != null && !"".equals(searchMap.get("avatar"))) { - predicateList.add(cb.like(root.get("avatar").as(String.class), "%" + searchMap.get("avatar") + "%")); - } - //最后登录时间 - if (searchMap.get("lastdate") != null && !"".equals(searchMap.get("lastdate"))) { - List activetimeList = (List) searchMap.get("lastdate"); - //开始 - predicateList.add(cb.greaterThanOrEqualTo(root.get("lastdate").as(String.class), activetimeList.get(0))); - //结束 - predicateList.add(cb.lessThanOrEqualTo(root.get("lastdate").as(String.class), activetimeList.get(1))); - } - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - - /** - * 登录 - * - * @param user - * @return - */ - public User login(User user) { - User loginUser = userDao.findByUsername(user.getUsername()); - if (loginUser != null && bCryptPasswordEncoder.matches(user.getPassword(), loginUser.getPassword())) { - return loginUser; - } else { - return null; - } - } - - - /** - * 根据username查询 - * - * @return - */ - public User findByUsername(String username) { - return userDao.findByUsername(username); - } - -} diff --git a/center/src/main/java/com/tiji/center/service/UseragentService.java b/center/src/main/java/com/tiji/center/service/UseragentService.java deleted file mode 100755 index 83e58b0..0000000 --- a/center/src/main/java/com/tiji/center/service/UseragentService.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.UseragentDao; -import com.tiji.center.pojo.Useragent; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * useragent服务层 - * - * @author 贰拾壹 - */ -@Service -public class UseragentService { - - @Autowired - private UseragentDao useragentDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return useragentDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return useragentDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return useragentDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Useragent findById(String id) { - return useragentDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param useragent - */ - public void add(Useragent useragent) { - if (Objects.isNull(useragent.getId())) { - useragent.setId(idWorker.nextId() + ""); - } - useragentDao.save(useragent); - } - - /** - * 修改 - * - * @param useragent - */ - public void update(Useragent useragent) { - useragentDao.save(useragent); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - useragentDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - useragentDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // useragent - if (searchMap.get("useragent") != null && !"".equals(searchMap.get("useragent"))) { - predicateList.add(cb.like(root.get("useragent").as(String.class), "%" + searchMap.get("useragent") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 查询全部不重复的agent - * - * @return - */ - public List findAllDistinctUserAgentList() { - return useragentDao.findAllDistinctUserAgentList(); - } - - - /** - * 根据ua查询实体 - * - * @param ua - * @return - */ - public Useragent findByUseragent(String ua) { - return useragentDao.findByUseragent(ua); - } - - /** - * 批量增加 - * - * @param useragentList - */ - public void batchAdd(List useragentList) { - useragentDao.saveAll(useragentList); - } -} diff --git a/center/src/main/java/com/tiji/center/service/VulnService.java b/center/src/main/java/com/tiji/center/service/VulnService.java deleted file mode 100755 index e89e361..0000000 --- a/center/src/main/java/com/tiji/center/service/VulnService.java +++ /dev/null @@ -1,205 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.VulnDao; -import com.tiji.center.pojo.Vuln; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * vuln服务层 - * - * @author 贰拾壹 - */ -@Service -public class VulnService { - - @Autowired - private VulnDao vulnDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return vulnDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return vulnDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return vulnDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Vuln findById(String id) { - return vulnDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param vuln - */ - public void add(Vuln vuln) { - if (Objects.isNull(vuln.getId())) { - vuln.setId(idWorker.nextId() + ""); - } - vulnDao.save(vuln); - } - - /** - * 修改 - * - * @param vuln - */ - public void update(Vuln vuln) { - vulnDao.save(vuln); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - vulnDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - vulnDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 漏洞编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - - // 漏洞二级分类编号 - if (searchMap.get("categorysecondid") != null && !"".equals(searchMap.get("categorysecondid"))) { - predicateList.add(cb.equal(root.get("categorysecondid").as(String.class), searchMap.get("categorysecondid"))); - } - - // 漏洞名称 - if (searchMap.get("name") != null && !"".equals(searchMap.get("name"))) { - predicateList.add(cb.like(root.get("name").as(String.class), "%" + (String) searchMap.get("name") + "%")); - } - // 漏洞描述 - if (searchMap.get("description") != null && !"".equals(searchMap.get("description"))) { - predicateList.add(cb.like(root.get("description").as(String.class), "%" + (String) searchMap.get("description") + "%")); - } - // 漏洞风险级别 - if (searchMap.get("risk") != null && !"".equals(searchMap.get("risk"))) { - predicateList.add(cb.like(root.get("risk").as(String.class), "%" + (String) searchMap.get("risk") + "%")); - } - // 参考 - if (searchMap.get("refer") != null && !"".equals(searchMap.get("refer"))) { - predicateList.add(cb.like(root.get("refer").as(String.class), "%" + (String) searchMap.get("refer") + "%")); - } - // impactscope - if (searchMap.get("impactscope") != null && !"".equals(searchMap.get("impactscope"))) { - predicateList.add(cb.like(root.get("impactscope").as(String.class), "%" + (String) searchMap.get("impactscope") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据name查询实体 - * - * @param name - * @return - */ - public Vuln findByName(String name) { - return vulnDao.findByName(name); - } - - - /** - * 根据id数组查询 - * - * @param ids - * @return - */ - public List findByIds(String[] ids) { - List vulnIdAndVulnNameList = new ArrayList<>(); - for (String id : ids) { - Vuln vuln = findById(id); - if (Objects.isNull(vuln)) { - vulnIdAndVulnNameList.add(id + "-" + null); - } else { - vulnIdAndVulnNameList.add(id + "-" + vuln.getName()); - } - } - return vulnIdAndVulnNameList.isEmpty() ? null : vulnIdAndVulnNameList; - } - - /** - * 根据id数组查询漏洞 - * - * @param vulnids - * @return - */ - public List findByVulnIds(List vulnids) { - return vulnDao.findAllById(vulnids); - } -} diff --git a/center/src/main/java/com/tiji/center/service/VulnkeywordService.java b/center/src/main/java/com/tiji/center/service/VulnkeywordService.java deleted file mode 100755 index 9a39e05..0000000 --- a/center/src/main/java/com/tiji/center/service/VulnkeywordService.java +++ /dev/null @@ -1,196 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.VulnkeywordDao; -import com.tiji.center.pojo.Vulnkeyword; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * vulnkeyword服务层 - * - * @author 贰拾壹 - */ -@Service -public class VulnkeywordService { - - @Autowired - private VulnkeywordDao vulnkeywordDao; - - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return vulnkeywordDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return vulnkeywordDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return vulnkeywordDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Vulnkeyword findById(String id) { - return vulnkeywordDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param vulnkeyword - */ - public void add(Vulnkeyword vulnkeyword) { - if (Objects.isNull(vulnkeyword.getId())) { - vulnkeyword.setId(idWorker.nextId() + ""); - } - vulnkeywordDao.save(vulnkeyword); - } - - /** - * 修改 - * - * @param vulnkeyword - */ - public void update(Vulnkeyword vulnkeyword) { - vulnkeywordDao.save(vulnkeyword); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - vulnkeywordDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - vulnkeywordDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 漏洞关键字编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 插件配置编号 - if (searchMap.get("pluginconfigid") != null && !"".equals(searchMap.get("pluginconfigid"))) { - predicateList.add(cb.like(root.get("pluginconfigid").as(String.class), "%" + searchMap.get("pluginconfigid") + "%")); - } - // 漏洞关键字 - if (searchMap.get("keyword") != null && !"".equals(searchMap.get("keyword"))) { - predicateList.add(cb.like(root.get("keyword").as(String.class), "%" + searchMap.get("keyword") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 批量增加 - * - * @param vulnKeywordList - */ - public void batchAdd(List vulnKeywordList) { - vulnkeywordDao.saveAll(vulnKeywordList); - } - - /** - * 根据pluginConfigI和vulnKeywordName查询实体 - * - * @param pluginConfigId - * @param vulnKeywordName - * @return Vulnkeyword - */ - public Vulnkeyword findByPluginconfigidAndService(String pluginConfigId, String vulnKeywordName) { - return vulnkeywordDao.findByPluginconfigidAndKeyword(pluginConfigId, vulnKeywordName); - } - - /** - * 根据pluginconfigId批量删除 - * - * @param pluginconfigId - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByPluginconfigid(String pluginconfigId) { - vulnkeywordDao.deleteAllByPluginconfigid(pluginconfigId); - } - - /** - * 根据pluginId查询 - * - * @param pluginconfigid pluginconfigid - * @return - */ - public List findAllByPluginId(String pluginconfigid) { - return vulnkeywordDao.findAllByPluginconfigid(pluginconfigid); - } - - /** - * 查询所有并去重 - * - * @return List - */ - public List findAllDistinctVulnKeyword() { - return vulnkeywordDao.findAllDistinctVulnKeyword(); - } -} diff --git a/center/src/main/java/com/tiji/center/service/VulnpluginconfigService.java b/center/src/main/java/com/tiji/center/service/VulnpluginconfigService.java deleted file mode 100755 index 9287a88..0000000 --- a/center/src/main/java/com/tiji/center/service/VulnpluginconfigService.java +++ /dev/null @@ -1,207 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.VulnpluginconfigDao; -import com.tiji.center.pojo.Vuln; -import com.tiji.center.pojo.Vulnpluginconfig; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * vulnpluginconfig服务层 - * - * @author 贰拾壹 - */ -@Service -public class VulnpluginconfigService { - - @Autowired - private VulnpluginconfigDao vulnpluginconfigDao; - @Autowired - private VulnService vulnService; - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return vulnpluginconfigDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return vulnpluginconfigDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return vulnpluginconfigDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Vulnpluginconfig findById(String id) { - return vulnpluginconfigDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param vulnpluginconfig - */ - public void add(Vulnpluginconfig vulnpluginconfig) { - if (Objects.isNull(vulnpluginconfig.getId())) { - vulnpluginconfig.setId(idWorker.nextId() + ""); - } - vulnpluginconfigDao.save(vulnpluginconfig); - } - - /** - * 修改 - * - * @param vulnpluginconfig - */ - public void update(Vulnpluginconfig vulnpluginconfig) { - vulnpluginconfigDao.save(vulnpluginconfig); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - vulnpluginconfigDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - vulnpluginconfigDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // 编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%")); - } - // 漏洞编号 - if (searchMap.get("vulnid") != null && !"".equals(searchMap.get("vulnid"))) { - predicateList.add(cb.like(root.get("vulnid").as(String.class), "%" + (String) searchMap.get("vulnid") + "%")); - } - // 插件配置编号 - if (searchMap.get("pluginconfigid") != null && !"".equals(searchMap.get("pluginconfigid"))) { - predicateList.add(cb.like(root.get("pluginconfigid").as(String.class), "%" + (String) searchMap.get("pluginconfigid") + "%")); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据pluginConfigId查询所有的 - * - * @param pluginConfigId - * @return - */ - public List findAllByPluginConfigId(String pluginConfigId) { - return vulnpluginconfigDao.findAllByPluginconfigid(pluginConfigId); - } - - /** - * 根据pluginconfigId批量删除 - * - * @param pluginconfigId - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByPluginconfigid(String pluginconfigId) { - vulnpluginconfigDao.deleteAllByPluginconfigid(pluginconfigId); - } - - /** - * 根据pluginId查询 - * - * @param pluginId pluginId - * @return - */ - public List findAllByPluginconfigid(String pluginId) { - List vulnidList = new ArrayList<>(); - List vulnpluginconfigList = vulnpluginconfigDao.findAllByPluginconfigid(pluginId); - vulnpluginconfigList.forEach(vulnpluginconfig -> { - String vulnid = vulnpluginconfig.getVulnid(); - vulnidList.add(vulnid); - }); - return vulnService.findByVulnIds(vulnidList); - } - - /** - * 根据vulnid、pluginId查询 - * - * @param vulnid vulnid - * @param pluginconfigid pluginconfigid - * @return - */ - public Vulnpluginconfig findByVulnidAndPluginconfigid(String vulnid, String pluginconfigid) { - return vulnpluginconfigDao.findByVulnidAndPluginconfigid(vulnid, pluginconfigid); - } - - /** - * 根据pluginId vulnId 删除 - * - * @param pluginId - * @param vulnId - */ - @Transactional(value = "masterTransactionManager") - public void deleteByPluginIdVulnId(String pluginId,String vulnId) { - vulnpluginconfigDao.deleteByPluginconfigidAndVulnid(pluginId,vulnId); - } -} diff --git a/center/src/main/java/com/tiji/center/service/WebinfoService.java b/center/src/main/java/com/tiji/center/service/WebinfoService.java deleted file mode 100755 index b3b2bba..0000000 --- a/center/src/main/java/com/tiji/center/service/WebinfoService.java +++ /dev/null @@ -1,244 +0,0 @@ -package com.tiji.center.service; - -import com.tiji.center.dao.WebinfoDao; -import com.tiji.center.pojo.Assetport; -import com.tiji.center.pojo.Webinfo; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; - -import javax.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * webinfo服务层 - * - * @author 贰拾壹 - */ -@Service -public class WebinfoService { - - @Autowired - private WebinfoDao webinfoDao; - @Autowired - private AssetportService assetportService; - @Autowired - private IdWorker idWorker; - - /** - * 查询全部列表 - * - * @return - */ - public List findAll() { - return webinfoDao.findAll(); - } - - - /** - * 条件查询+分页 - * - * @param whereMap - * @param page - * @param size - * @return - */ - public Page findSearch(Map whereMap, int page, int size) { - Specification specification = createSpecification(whereMap); - PageRequest pageRequest = PageRequest.of(page - 1, size); - return webinfoDao.findAll(specification, pageRequest); - } - - - /** - * 条件查询 - * - * @param whereMap - * @return - */ - public List findSearch(Map whereMap) { - Specification specification = createSpecification(whereMap); - return webinfoDao.findAll(specification); - } - - /** - * 根据ID查询实体 - * - * @param id - * @return - */ - public Webinfo findById(String id) { - return webinfoDao.findById(id).orElse(null); - } - - /** - * 增加 - * - * @param webinfo - */ - public void add(Webinfo webinfo) { - if (Objects.isNull(webinfo.getId())) { - webinfo.setId(idWorker.nextId() + ""); - } - webinfoDao.save(webinfo); - } - - /** - * 修改 - * - * @param webinfo - */ - public void update(Webinfo webinfo) { - webinfoDao.save(webinfo); - } - - /** - * 删除 - * - * @param id - */ - public void deleteById(String id) { - webinfoDao.deleteById(id); - } - - /** - * 根据id数组删除 - * - * @param ids - */ - @Transactional(value = "masterTransactionManager") - public void deleteAllByIds(List ids) { - webinfoDao.deleteAllByIds(ids); - } - - /** - * 动态条件构建 - * - * @param searchMap - * @return - */ - private Specification createSpecification(Map searchMap) { - - return (Specification) (root, query, cb) -> { - List predicateList = new ArrayList(); - // web信息编号 - if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) { - predicateList.add(cb.like(root.get("id").as(String.class), "%" + searchMap.get("id") + "%")); - } - // 端口编号 - if (searchMap.get("portid") != null && !"".equals(searchMap.get("portid"))) { - predicateList.add(cb.in(root.get("portid")).value(searchMap.get("portid"))); - } - // 标题白名单编号 - if (searchMap.get("titlewhitelistid") != null && !"".equals(searchMap.get("titlewhitelistid"))) { - predicateList.add(cb.like(root.get("titlewhitelistid").as(String.class), "%" + searchMap.get("titlewhitelistid") + "%")); - } - // 页面标题 - if (searchMap.get("title") != null && !"".equals(searchMap.get("title"))) { - predicateList.add(cb.like(root.get("title").as(String.class), "%" + searchMap.get("title") + "%")); - } - // body子节点文本内容 - if (searchMap.get("bodychildrenstextcontent") != null && !"".equals(searchMap.get("bodychildrenstextcontent"))) { - predicateList.add(cb.like(root.get("bodychildrenstextcontent").as(String.class), "%" + searchMap.get("bodychildrenstextcontent") + "%")); - } - // 响应头中的服务 - if (searchMap.get("server") != null && !"".equals(searchMap.get("server"))) { - predicateList.add(cb.like(root.get("server").as(String.class), "%" + searchMap.get("server") + "%")); - } - // xpoweredby - if (searchMap.get("xpoweredby") != null && !"".equals(searchMap.get("xpoweredby"))) { - predicateList.add(cb.like(root.get("xpoweredby").as(String.class), "%" + searchMap.get("xpoweredby") + "%")); - } - // 设置cookie - if (searchMap.get("setcookie") != null && !"".equals(searchMap.get("setcookie"))) { - predicateList.add(cb.like(root.get("setcookie").as(String.class), "%" + searchMap.get("setcookie") + "%")); - } - // 认证方式 - if (searchMap.get("wwwauthenticate") != null && !"".equals(searchMap.get("wwwauthenticate"))) { - predicateList.add(cb.like(root.get("wwwauthenticate").as(String.class), "%" + searchMap.get("wwwauthenticate") + "%")); - } - // appname - if (searchMap.get("appname") != null && !"".equals(searchMap.get("appname"))) { - predicateList.add(cb.like(root.get("appname").as(String.class), "%" + searchMap.get("appname") + "%")); - } - // 应用版本 - if (searchMap.get("appversion") != null && !"".equals(searchMap.get("appversion"))) { - predicateList.add(cb.like(root.get("appversion").as(String.class), "%" + searchMap.get("appversion") + "%")); - } - // devlanguage - if (searchMap.get("devlanguage") != null && !"".equals(searchMap.get("devlanguage"))) { - predicateList.add(cb.like(root.get("devlanguage").as(String.class), "%" + searchMap.get("devlanguage") + "%")); - } - //页面抓取时间 - if (searchMap.get("crawltime") != null && !"".equals(searchMap.get("crawltime"))) { - List activetimeList = (List) searchMap.get("crawltime"); - //开始 - predicateList.add(cb.greaterThanOrEqualTo(root.get("crawltime").as(String.class), activetimeList.get(0))); - //结束 - predicateList.add(cb.lessThanOrEqualTo(root.get("crawltime").as(String.class), activetimeList.get(1))); - } - - return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); - - }; - - } - - /** - * 根据ID查询实体 - * - * @param portId - * @return - */ - public List findByPortId(String portId) { - return webinfoDao.findByPortid(portId); - } - - - /** - * 根据assetportId批量删除 - * - * @param assetportId - */ - @Transactional(value = "masterTransactionManager") - public List deleteAllByPortid(String assetportId) { - return webinfoDao.deleteAllByPortid(assetportId); - } - - /** - * 根据assetportid查询 - * - * @param assetportid assetportid - * @return - */ - public List findAllByAssetportid(String assetportid) { - return webinfoDao.findAllByPortid(assetportid); - } - - /** - * 根据assetportids查询 - * - * @param assetportids assetportids - * @return - */ - public List findAllByAssetportIds(String[] assetportids) { - List resultList = new ArrayList<>(); - for (String id : assetportids) { - List webinfoList = webinfoDao.findAllByPortid(id); - for (Webinfo webinfo : webinfoList) { - String assetportid = webinfo.getPortid(); - Assetport assetport = assetportService.findById(assetportid); - webinfo.setPortid(assetport.getPort()); - resultList.add(webinfo); - } - } - return resultList; - } -} diff --git a/center/src/main/java/com/tiji/center/thread/DNSResolveThread.java b/center/src/main/java/com/tiji/center/thread/DNSResolveThread.java deleted file mode 100755 index 1675823..0000000 --- a/center/src/main/java/com/tiji/center/thread/DNSResolveThread.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.tiji.center.thread; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.concurrent.BlockingQueue; - -/** - * @author 贰拾壹 - * @create 2019-01-07 14:34 - */ - -public class DNSResolveThread implements Runnable { - private InetAddress inetAddress; - private byte[] addr; - private String rawIP; - private BlockingQueue rawResultQueue; - - public DNSResolveThread() { - } - - public DNSResolveThread(byte[] addr, String rawIp, BlockingQueue rawResultQueue) { - this.addr = addr; - this.rawIP = rawIp; - this.rawResultQueue = rawResultQueue; - } - - @Override - public void run() { - try { - InetAddress add = InetAddress.getByAddress(addr); - set(add); - } catch (UnknownHostException ignored) { - } - } - - private synchronized void set(InetAddress inetAddress) { - this.inetAddress = inetAddress; - if (!this.rawIP.equals(getIPHostName())) { - try { - rawResultQueue.put(this.rawIP + ":" + getIPHostName()); - } catch (InterruptedException e) { - //e.printStackTrace(); - } - } - } - - private synchronized String getIPHostName() { - return this.inetAddress == null ? null : inetAddress.getHostName(); - } -} diff --git a/center/src/main/java/com/tiji/center/util/HostNameUtil.java b/center/src/main/java/com/tiji/center/util/HostNameUtil.java deleted file mode 100755 index 559c163..0000000 --- a/center/src/main/java/com/tiji/center/util/HostNameUtil.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.tiji.center.util; - -import com.tiji.center.pojo.Assetip; -import com.tiji.center.pojo.Assetport; -import com.tiji.center.pojo.Checkresult; -import com.tiji.center.pojo.Host; -import com.tiji.center.service.AssetipService; -import com.tiji.center.service.AssetportService; -import com.tiji.center.service.CheckresultService; -import com.tiji.center.service.HostService; -import com.tiji.center.thread.DNSResolveThread; -import org.springframework.util.DigestUtils; -import util.IdWorker; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * @author 贰拾壹 - * @create 2019-11-22 15:10 - */ -public class HostNameUtil { - - public static void dnsResolver(AssetipService assetipService, HostService hostService, IdWorker idWorker, Date date) throws InterruptedException { - //DNS解析 - BlockingQueue rawResultQueue = new LinkedBlockingQueue<>(); - List allIpaddressv4 = assetipService.findAllDistinctIpaddressv4ListAndPassivetimeIsNull(); - List activeHostList = new ArrayList<>(); - System.setProperty("networkaddress.cache.ttl", "0"); - System.setProperty("networkaddress.cache.negative.ttl", "0"); - for (String ipv4 : allIpaddressv4) { - getDNSResolve(rawResultQueue, ipv4); - } - - for (String rawResult : rawResultQueue) { - boolean addHostFlag = true; - String ip = rawResult.split(":")[0]; - Assetip assetip = assetipService.findByIpaddressv4AndPassivetimeIsNull(ip); - if (assetip != null) { - String assetipId = assetip.getId(); - String hostname = rawResult.split(":")[1]; - String temp = hostname.split("\\.")[0]; - String owner = temp.substring(temp.indexOf("-") + 1); - String md5Base = hostname + owner; - String incomeDigest = DigestUtils.md5DigestAsHex(md5Base.toLowerCase().getBytes()); - List hostList = hostService.findByAssetIpId(assetipId); - if (!hostList.isEmpty()) { - for (Host host : hostList) { - String hostname1 = host.getHostname(); - String owner1 = host.getOwner(); - String dbBase = hostname1 + owner1; - String dbDigest = DigestUtils.md5DigestAsHex(dbBase.toLowerCase().getBytes()); - if (incomeDigest.equals(dbDigest)) { - addHostFlag = false; - } - } - } - if (addHostFlag) { - //TODO 这里可以得到新增的host信息或者发生改变的host信息 - Host host = new Host(idWorker.nextId() + "", assetipId, null, hostname, null, null, null, owner, date, null); - activeHostList.add(host); - } - } - } - hostService.batchAdd(activeHostList); - } - - public static void nseResultParser(AssetportService assetportService, CheckresultService checkresultService, HostService hostService, IdWorker idWorker, Date date) { - List nseActiveHostList = new ArrayList<>(); - //nse插件:根据ntlm信息获取DNS_Computer_Name - //DNS_Computer_Name - //资产端口编号->资产ip编号 - //判断host是否存在 - //不存在,新增 - String[] ntlmNseNameArray = new String[]{"http-ntlm-info", "imap-ntlm-info", "ms-sql-ntlm-info", "nntp-ntlm-info", "pop3-ntlm-info", "rdp-nlm-info", "smtp-ntlm-info", "telnet-ntlm-info"}; - List checkresultList = new ArrayList<>(); - //根据nse获取检测结果 - for (String ntlmNseName : ntlmNseNameArray) { - checkresultList.addAll(checkresultService.findAllByName(ntlmNseName)); - } - //获取资产端口编号 - for (Checkresult checkresult : checkresultList) { - String assetportid = checkresult.getAssetportid(); - String result = checkresult.getResult(); - Pattern pattern = Pattern.compile("(?:^|\\n)DNS_Computer_Name.*"); - Matcher matcher = pattern.matcher(result); - String hostname = null; - if (matcher.find()) { - String dnsComputerName = matcher.group(0); - hostname = dnsComputerName.split(":\\s")[1]; - } - //nse检测结果中hostname不为空 - if (!Objects.isNull(hostname)) { - boolean addHostFlag = true; - Assetport assetport = assetportService.findById(assetportid); - //获取资产ip编号 - String assetipid = assetport.getAssetipid(); - String temp = hostname.split("\\.")[0]; - String owner = temp.substring(temp.indexOf("-") + 1); - //获取host - List hostList = hostService.findByAssetIpId(assetipid); - //当前不存在host - if (hostList.isEmpty()) { - //TODO 这里可以得到新增的host信息 - nseActiveHostList.add(new Host(idWorker.nextId() + "", assetipid, null, hostname, null, null, null, owner, date, "add by " + checkresult.getName())); - } else { - //存在host - String md5Base = hostname + owner; - String incomeDigest = DigestUtils.md5DigestAsHex(md5Base.toLowerCase().getBytes()); - for (Host host : hostList) { - String hostname1 = host.getHostname(); - String owner1 = host.getOwner(); - String dbBase = hostname1 + owner1; - String dbDigest = DigestUtils.md5DigestAsHex(dbBase.toLowerCase().getBytes()); - if (incomeDigest.equals(dbDigest)) { - addHostFlag = false; - } - } - if (addHostFlag) { - //host信息有更改 - nseActiveHostList.add(new Host(idWorker.nextId() + "", assetipid, null, hostname, null, null, null, owner, date, "change by " + checkresult.getName())); - } - } - } - } - hostService.batchAdd(nseActiveHostList); - } - - public static void getDNSResolve(BlockingQueue rawResultQueue, String rawIP) throws InterruptedException { - String[] ip_split = rawIP.split("\\."); - //ip一到四位,String直接转byte会溢出,先转short,再由short强转成byte - byte ip1 = (byte) Short.parseShort(ip_split[0]); - byte ip2 = (byte) Short.parseShort(ip_split[1]); - byte ip3 = (byte) Short.parseShort(ip_split[2]); - byte ip4 = (byte) Short.parseShort(ip_split[3]); - byte[] ip = new byte[]{ip1, ip2, ip3, ip4}; - DNSResolveThread dnsLookupThread = new DNSResolveThread(ip, rawIP, rawResultQueue); - Thread thread = new Thread(dnsLookupThread); - thread.start(); - //设置解析线程存活的时间,超时终止 - thread.join(10); - } -} diff --git a/center/src/main/java/com/tiji/center/util/JwtUtil.java b/center/src/main/java/com/tiji/center/util/JwtUtil.java deleted file mode 100755 index 578901c..0000000 --- a/center/src/main/java/com/tiji/center/util/JwtUtil.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.tiji.center.util; - -import io.jsonwebtoken.Claims; -import io.jsonwebtoken.JwtBuilder; -import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.SignatureAlgorithm; -import org.springframework.boot.context.properties.ConfigurationProperties; - -import java.util.Date; - -@ConfigurationProperties("jwt.config") -public class JwtUtil { - - private String key; - - private long ttl; - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public long getTtl() { - return ttl; - } - - public void setTtl(long ttl) { - this.ttl = ttl; - } - - /** - * 生成JWT - * - * @param id - * @param subject - * @return - */ - public String createJWT(String id, String subject, String roles) { - long nowMillis = System.currentTimeMillis(); - Date now = new Date(nowMillis); - JwtBuilder builder = Jwts.builder().setId(id) - .setSubject(subject) - .setIssuedAt(now) - .signWith(SignatureAlgorithm.HS256, key).claim("roles", roles); - if (ttl > 0) { - builder.setExpiration(new Date(nowMillis + ttl)); - } - return builder.compact(); - } - - /** - * 解析JWT - * - * @param jwtStr - * @return - */ - public Claims parseJWT(String jwtStr) { - return Jwts.parser() - .setSigningKey(key) - .parseClaimsJws(jwtStr) - .getBody(); - } - -} diff --git a/center/src/main/java/com/tiji/center/util/NotifyUtil.java b/center/src/main/java/com/tiji/center/util/NotifyUtil.java deleted file mode 100755 index 1ec56c8..0000000 --- a/center/src/main/java/com/tiji/center/util/NotifyUtil.java +++ /dev/null @@ -1,343 +0,0 @@ -package com.tiji.center.util; - -import com.google.gson.Gson; -import com.tiji.center.pojo.Notifylog; -import com.tiji.center.service.NotifylogService; -import org.apache.commons.codec.binary.Base64; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.mail.javamail.JavaMailSenderImpl; -import org.springframework.mail.javamail.MimeMessageHelper; -import org.springframework.util.StringUtils; -import util.ExcpUtil; -import util.IdWorker; - -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; -import javax.mail.MessagingException; -import javax.mail.internet.MimeMessage; -import java.io.File; -import java.io.IOException; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.util.*; - -/** - * @author 贰拾壹 - * @create 2019-11-05 14:51 - */ -public class NotifyUtil { - static class ImResponse { - private String errcode; - private String errmsg; - - public String getErrcode() { - return errcode; - } - - public String getErrmsg() { - return errmsg; - } - - } - - private final static Logger logger = LoggerFactory.getLogger(NotifyUtil.class); - - public static void sendMail2ProjectOwner(String sendFrom, String sendMailConfigAssetSubject, String sendMailConfigAssetContent, Map> projectInfoAndContactWithFilelistMap, JavaMailSenderImpl mailSender, NotifylogService notifylogService, IdWorker idWorker) { - Set>> entries = projectInfoAndContactWithFilelistMap.entrySet(); - List notifyLogList = new ArrayList<>(); - -// for (Map.Entry> stringListEntry : entries) { - entries.parallelStream().forEach((stringListEntry) -> { - String nameAndEmail = stringListEntry.getKey(); - String name = nameAndEmail.split("-\\+-")[0]; - String emails = nameAndEmail.split("-\\+-")[1]; - - //发邮件 - Map fileMap = new LinkedHashMap<>(); - List fileList = stringListEntry.getValue(); - List fileNameList = new ArrayList<>(); - fileList.forEach(file -> { - String attachmentName = file.getName(); - fileMap.put(attachmentName, file); - fileNameList.add(attachmentName); - //System.out.println(name + " " + email + " " + attachmentName); - }); - String fileListString = fileNameList.toString().replaceAll("[\\[\\]]", ""); - String[] emailArray = emails.split(","); - for (String email : emailArray) { - - //System.out.println("给 " + name + " " + email + " 发邮件成功 " + fileListString); - try { - //NotifyUtil.sendMail(mailSender, sendFrom, email, sendMailConfigAssetSubject, name + " " + sendMailConfigAssetContent + sendFrom, fileMap); - NotifyUtil.sendMailWithAttach(mailSender, sendFrom, email, sendMailConfigAssetSubject, sendMailConfigAssetContent, fileMap); - //记录发送成功 - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "E", name, email, fileListString, true, null, new Date())); - //System.out.println("给" + name + " " + email + " 发邮件成功" + fileListString); - } catch (Exception e) { - //记录发送失败 - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "E", name, email, fileListString, false, e.getMessage(), new Date())); - //System.out.println("给" + name + " " + email + "发邮件失败:" + fileListString + e.getMessage()); - logger.info("send mail 2 owner Exception here: " + e); - } - } - }); - notifylogService.batchAdd(notifyLogList); - } - - - //发送带附件 - public static void sendMailWithAttach(JavaMailSenderImpl mailSender, String sendFrom, String sendTo, String subject, String content, Map fileMap) throws MessagingException { - MimeMessage mimeMailMessage = mailSender.createMimeMessage(); - MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMailMessage, true); - mimeMessageHelper.setFrom(sendFrom); - mimeMessageHelper.setTo(sendTo); - //邮件主题 - mimeMessageHelper.setSubject(subject); - //邮件内容 - mimeMessageHelper.setText(content); - Set> entrySet = fileMap.entrySet(); - for (Map.Entry fileEntry : entrySet) { - String attachmentName = fileEntry.getKey(); - File file = fileEntry.getValue(); - mimeMessageHelper.addAttachment(attachmentName, file); - } - mailSender.send(mimeMailMessage); - } - - public static void sendSimpleMail(JavaMailSenderImpl mailSender, String sendFrom, String sendTo, String subject, String content) throws MessagingException { - MimeMessage mimeMailMessage = mailSender.createMimeMessage(); - MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMailMessage); - mimeMessageHelper.setFrom(sendFrom); - mimeMessageHelper.setTo(sendTo); - //邮件主题 - mimeMessageHelper.setSubject(subject); - //邮件内容 - mimeMessageHelper.setText(content); - mailSender.send(mimeMailMessage); - } - - - //根据titleArrays设置标题 - public static void setSheetHeaderTitle(Sheet sheet, String[] titleArrays) { - Row row = sheet.createRow(0); - for (int i = 0; i < titleArrays.length; i++) { - sheet.setColumnWidth(i, 16 * 256); - Cell cell = row.createCell(i); - cell.setCellValue(titleArrays[i]); - } - } - - - public static void setCellData(Sheet sheet, Row row, int rowNumber, Object cellData) { - String cellDataString = ""; - int cellDataStringLength = 4; - if (!Objects.isNull(cellData)) { - cellDataString = cellData.toString().replaceAll("[\\[\\]]", ""); - cellDataStringLength = Math.min(cellDataString.length(), 10); - } - sheet.setColumnWidth(rowNumber, cellDataStringLength * 512); - Cell cell = row.createCell(rowNumber); - cell.setCellValue(cellDataString); - } - - /** - * 企微群机器人测试消息 - */ - public static void sendWeChet(IdWorker idWorker, NotifylogService notifylogService, String resultWithContact, Map imvulnnotifyMap, Date date) { - List notifyLogList = new ArrayList<>(); - String resultWithContactReplaceAll = resultWithContact.replaceAll("> \\*\\*", "").replaceAll("\\*\\*\\s", " ").replaceAll(">\\s", " "); - try { - String wechatmessageurl = (String) imvulnnotifyMap.get("wechatmessageurl"); - //暂时用不上 - //String[] receiverArray = ((String) imvulnnotifyMap.get("wechatreceiver")).split(","); - String messagetitle = (String) imvulnnotifyMap.get("messagetitle"); - String messageprefix = (String) imvulnnotifyMap.get("messageprefix"); - String messagesuffix = (String) imvulnnotifyMap.get("messagesuffix"); - String messagecharset = (String) imvulnnotifyMap.get("messagecharset"); - - String wechatnotifyall = (String) imvulnnotifyMap.get("wechatnotifyall"); - - if (StringUtils.isEmpty(wechatmessageurl)) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "W", "企微group", "", resultWithContact, false, "webhook地址配置错误", date)); - notifylogService.batchAdd(notifyLogList); - return; - } - - Map contentMap = new HashMap<>(); - if (!StringUtils.isEmpty(messagetitle)) { - messagetitle = "**" + messagetitle + "**" + "\n"; - } else { - messagetitle = ""; - } - if (!StringUtils.isEmpty(messageprefix)) { - messageprefix = messageprefix + "\n"; - } else { - messageprefix = ""; - } - if (!StringUtils.isEmpty(messagesuffix)) { - messagesuffix = messagesuffix + "\n"; - } else { - messagesuffix = ""; - } - - - String massgeType = "markdown"; - //@all不支持markdown格式,转成text - if ("true".equals(wechatnotifyall)) { - massgeType = "text"; - contentMap.put("mentioned_mobile_list", "@all"); - contentMap.put("content", (messagetitle + messageprefix + resultWithContact + "\n" + messagesuffix).replaceAll("[*>]", "")); - } else { - contentMap.put("content", messagetitle + messageprefix + resultWithContact + "\n" + messagesuffix); - } - - Map dataMap = new HashMap<>(); - dataMap.put("msgtype", massgeType); - dataMap.put(massgeType, contentMap); - - String reqStr = new Gson().toJson(dataMap); - - CloseableHttpClient httpClient = HttpClients.createDefault(); - HttpPost httpPost = new HttpPost(wechatmessageurl); - httpPost.addHeader("Content-Type", "application/json"); - httpPost.setEntity(new StringEntity(reqStr, messagecharset)); - ImResponse wcResponse = null; - try (CloseableHttpResponse response = httpClient.execute(httpPost)) { - String resString = EntityUtils.toString(response.getEntity(), messagecharset); - wcResponse = new Gson().fromJson(resString, ImResponse.class); - if ("0".equals(wcResponse.getErrcode()) && wcResponse.getErrmsg().contains("ok")) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "W", "企微group", "", resultWithContactReplaceAll, true, null, date)); - } else { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "W", "企微group", "", resultWithContactReplaceAll, false, resString, date)); - } - logger.info("Ding talk response: " + EntityUtils.toString(response.getEntity(), messagecharset)); - } catch (IOException e) { - if (Objects.isNull(wcResponse)) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "W", "企微group", "", resultWithContactReplaceAll, false, "发送失败,异常消息:\n" + e.getMessage(), date)); - } - } - } catch (Exception e) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "W", "企微group", "", resultWithContactReplaceAll, false, "发送失败,异常消息:\n" + e.getMessage(), date)); - } - notifylogService.batchAdd(notifyLogList); - } - - /** - * 钉钉群机器人测试消息 - */ - public static void sendDingTalk(IdWorker idWorker, NotifylogService notifylogService, String resultWithContact, Map imvulnnotifyMap, Date date) { - List notifyLogList = new ArrayList<>(); - String resultWithContactRepalceAll = resultWithContact.replaceAll("> \\*\\*", "").replaceAll("\\*\\*\\s", " ").replaceAll(">\\s", " "); - try { - String dingtalkmessageurl = (String) imvulnnotifyMap.get("dingtalkmessageurl"); - //暂时用不上 - //String[] receiverArray = ((String) imvulnnotifyMap.get("dingtalkreceiver")).split(","); - - String messagetitle = (String) imvulnnotifyMap.get("messagetitle"); - String messageprefix = (String) imvulnnotifyMap.get("messageprefix"); - String messagesuffix = (String) imvulnnotifyMap.get("messagesuffix"); - String messagecharset = (String) imvulnnotifyMap.get("messagecharset"); - - String secret = (String) imvulnnotifyMap.get("secret"); - if (StringUtils.isEmpty(dingtalkmessageurl) || StringUtils.isEmpty(secret)) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "D", "钉钉group", "", resultWithContactRepalceAll, false, "签名密钥和webhook地址配置错误", date)); - notifylogService.batchAdd(notifyLogList); - return; - } - String dingtalknotifyall = (String) imvulnnotifyMap.get("dingtalknotifyall"); - String contentTitle = messagetitle; - if (StringUtils.isEmpty(messagetitle)) { - messagetitle = "【魔方】提醒"; - } - if (!StringUtils.isEmpty(messageprefix)) { - messageprefix = "\n" + messageprefix + "\n"; - } else { - messageprefix = ""; - } - if (!StringUtils.isEmpty(messagesuffix)) { - messagesuffix = messagesuffix + "\n"; - } else { - messagesuffix = ""; - } - if (!StringUtils.isEmpty(contentTitle)) { - contentTitle = "**" + messagetitle + "**" + "\n"; - } else { - contentTitle = ""; - } - Map contentMap = new HashMap<>(); - contentMap.put("title", messagetitle); - contentMap.put("text", contentTitle + messageprefix + resultWithContact + "\n" + messagesuffix); - //@所有或指定联系人,两者只能生效一个 - Map atMap = new HashMap<>(); - List mobileList = new ArrayList<>(); - //mobileList.add("185xxxxxx"); - if ("true".equals(dingtalknotifyall)) { - atMap.put("isAtAll", true); - } - - - //atMap.put("atMobiles", mobileList); - Map dataMap = new HashMap<>(); - dataMap.put("msgtype", "markdown"); - dataMap.put("markdown", contentMap); - dataMap.put("at", atMap); - - String reqStr = new Gson().toJson(dataMap); - String signUrl = signUrl(secret, dingtalkmessageurl); - - CloseableHttpClient httpClient = HttpClients.createDefault(); - HttpPost httpPost = new HttpPost(signUrl); - httpPost.addHeader("Content-Type", "application/json"); - httpPost.setEntity(new StringEntity(reqStr, messagecharset)); - ImResponse dingResponse = null; - try (CloseableHttpResponse response = httpClient.execute(httpPost)) { - String dResponse = EntityUtils.toString(response.getEntity(), messagecharset); - dingResponse = new Gson().fromJson(dResponse, ImResponse.class); - if ("0".equals(dingResponse.getErrcode()) && "ok".equals(dingResponse.getErrmsg())) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "D", "钉钉group", "", resultWithContactRepalceAll, true, null, date)); - } else { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "D", "钉钉group", "", resultWithContactRepalceAll, false, dResponse, date)); - } - logger.info("Ding talk response: " + EntityUtils.toString(response.getEntity(), messagecharset)); - } catch (IOException e) { - if (Objects.isNull(dingResponse)) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "D", "钉钉group", "", resultWithContactRepalceAll, false, "发送失败,异常消息:\n" + e.getMessage(), date)); - } - } - } catch (Exception e) { - notifyLogList.add(new Notifylog(idWorker.nextId() + "", "D", "钉钉group", "", resultWithContactRepalceAll, false, "发送失败,异常消息:\n" + e.getMessage(), date)); - } - notifylogService.batchAdd(notifyLogList); - } - - /** - * 钉钉消息签名 - * - * @param secret - * @param url - * @return - */ - private static String signUrl(String secret, String url) throws NoSuchAlgorithmException, InvalidKeyException { - Long timestamp = System.currentTimeMillis(); - String stringToSign = timestamp + "\n" + secret; - Mac mac = Mac.getInstance("HmacSHA256"); - mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256")); - byte[] signData = mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8)); - String sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)), StandardCharsets.UTF_8); - //https://oapi.dingtalk.com/robot/send?access_token=XXXXXX×tamp=XXX&sign=XXX - return url + "×tamp=" + timestamp + "&sign=" + sign; - } - -} diff --git a/center/src/main/java/com/tiji/center/util/TijiHelper.java b/center/src/main/java/com/tiji/center/util/TijiHelper.java deleted file mode 100755 index f8df8e0..0000000 --- a/center/src/main/java/com/tiji/center/util/TijiHelper.java +++ /dev/null @@ -1,1275 +0,0 @@ -package com.tiji.center.util; - -import com.tiji.center.pojo.*; -import com.tiji.center.service.*; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.net.util.SubnetUtils; -import org.quartz.CronExpression; -import org.quartz.TriggerUtils; -import org.quartz.impl.triggers.CronTriggerImpl; -import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.messaging.Message; -import org.springframework.util.DigestUtils; -import util.IdWorker; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.LongStream; - -/** - * @author 贰拾壹 - * @create 2018-10-24 16:50 - */ - -public class TijiHelper { - - private static final String RE_DOMAIN = "[\\w-]+\\.(com\\.cn|net\\.cn|gov\\.cn|org\\.nz|org\\.cn|com|net|org|gov|cc|biz|info|cn|co|js)\\b()*"; - private static final Pattern DomainPattern = Pattern.compile(RE_DOMAIN, Pattern.CASE_INSENSITIVE); - - public static boolean agentOnline(AgentService agentService, IdWorker idWorker, RabbitMessagingTemplate rabbitMessagingTemplate) { - List onlineAgentList = agentService.findAllByOnline(true); - // 没有agent在线,发agent心跳包监控 - // 在线则不管,状态由AgentHeartbeatMonitorScheduler刷新 - if (onlineAgentList.isEmpty()) { - Map taskConfig = new HashMap<>(); - taskConfig.put("status", "heartbeat"); - rabbitMessagingTemplate.convertAndSend("tijifanout", "", taskConfig); - // 接收 - Message agentConfigMessage = rabbitMessagingTemplate.receive("agentconfig"); - if (!Objects.isNull(agentConfigMessage)) { - getAgentConfigMessage(agentService, idWorker, agentConfigMessage); - } - } - return !onlineAgentList.isEmpty(); - } - - //TODO 处理agent cpu和内存状态 - public static void getAgentConfigMessage(AgentService agentService, IdWorker idWorker, Message agentConfigMessage) { - if (!Objects.isNull(agentConfigMessage)) { - Map agentConfig = (Map) agentConfigMessage.getPayload(); - String agentName = agentConfig.get("agentName"); - String nmapPath = agentConfig.get("nmapPath"); - String massPath = agentConfig.get("massPath"); - String online = agentConfig.get("online"); - String ipAddress = agentConfig.get("ipAddress"); - String onlineFlag = online + ipAddress; - - if (!Objects.isNull(agentName) && !Objects.isNull(nmapPath) && !Objects.isNull(massPath) && !Objects.isNull(online)) { - Agent dbAgent = agentService.findByNameAndIpaddress(agentName, ipAddress); - //新增一个agent记录 - if (Objects.isNull(dbAgent)) { - agentService.add(new Agent(idWorker.nextId() + "", agentName, nmapPath, massPath, ipAddress, true, "0")); - } - } - // - if (!Objects.isNull(online)) { - List agentList = agentService.findAll(); - for (Agent agent : agentList) { - String name = agent.getName(); - String ipaddress = agent.getIpaddress(); - if (!onlineFlag.equals(name + ipaddress)) { - //agent.setOnline(false); - } else { - agent.setOnline(true); - agent.setTimeouts("0"); - } - agentService.update(agent); - } - } - } - } - - //http parser 结果进数据库 - public static void httppResult2Db(WebinfoService webinfoService, UrlService urlService, IdWorker idWorker, TitlewhitelistService titlewhitelistService, DomainwhitelistService domainwhitelistService, WebrawdataService webrawdataService, Map resultMap, String scanResult) { - Date date = new Date(); - String webInfoId = idWorker.nextId() + ""; - String assetPortId = resultMap.get("assetPortId"); - String title = resultMap.get("title"); - String bodyWholeText = resultMap.get("bodyWholeText"); - String server = resultMap.get("server"); - String x_Powered_By = resultMap.get("x_Powered_By"); - String set_Cookie = resultMap.get("set_Cookie"); - String www_Authenticate = resultMap.get("www_Authenticate"); - - String header = resultMap.get("header"); - String response = resultMap.get("response"); - - - List allTitlewhitelist = titlewhitelistService.findAll(); - List allDomainwhitelist = domainwhitelistService.findAllDistinct(); - - - String titleWhiteListId = null; - //title不在白名单里才记录bodyWholeText - for (Titlewhitelist titlewhitelistItem : allTitlewhitelist) { - String titlewhitelist = titlewhitelistItem.getTitle(); - if (title.contains(titlewhitelist)) { - titleWhiteListId = titlewhitelistItem.getId(); - bodyWholeText = null; - } - } - - boolean addWebInfoFlag = true; - //set_Cookie,sessionId会变,不加到md5中 - String md5Base = title + bodyWholeText + server + x_Powered_By + www_Authenticate; - //计算MD5 - String incomeDigest = DigestUtils.md5DigestAsHex(md5Base.toLowerCase().getBytes()); - - List webinfoList = webinfoService.findByPortId(assetPortId); - if (webinfoList.size() != 0) { - for (Webinfo webinfo : webinfoList) { - String title1 = webinfo.getTitle(); - String bodyWholeText1 = webinfo.getBodychildrenstextcontent(); - String server1 = webinfo.getServer(); - String x_Powered_By1 = webinfo.getXpoweredby(); - String www_Authenticate1 = webinfo.getWwwauthenticate(); - String dbBase = title1 + bodyWholeText1 + server1 + x_Powered_By1 + www_Authenticate1; - String dbDigest = DigestUtils.md5DigestAsHex(dbBase.toLowerCase().getBytes()); - if (incomeDigest.equals(dbDigest)) { - addWebInfoFlag = false; - } - } - } - if (addWebInfoFlag) { - //TODO 这里可以得到新增的web信息和url信息, - // 如果是第一次跑,则全部的都是新增的 - // 如果是第二次+,则web信息有修改 - // 如果页面中包含时间戳..则每次都会新增 - //title为空也直接记录,防止title和body的text都为空时访问的记录丢失 - webinfoService.add(new Webinfo(webInfoId, assetPortId, titleWhiteListId, title, bodyWholeText, - server, x_Powered_By, set_Cookie, www_Authenticate, null, null, null, date)); - webrawdataService.add(new Webrawdata(idWorker.nextId() + "", webInfoId, header, response)); - if (!Objects.isNull(bodyWholeText)) { - //此时scanResult只有urlNameAndLink - if (!Objects.isNull(scanResult) && !scanResult.isEmpty()) { - //去掉最后的<+> - String relUrlNameAndLinks = scanResult.substring(0, scanResult.length() - 3); - String[] urlNameAndLinks = relUrlNameAndLinks.split("<\\+>"); - for (String urlNameAndLink : urlNameAndLinks) { - String urlName = urlNameAndLink.split("<\\|>")[0]; - String urlLink = urlNameAndLink.split("<\\|>")[1]; - Matcher matcher = DomainPattern.matcher(urlLink); - //有域名 - if (matcher.find()) { - //域名不在白名单 - if (!allDomainwhitelist.contains(matcher.group(0))) { - urlService.add(new Url(idWorker.nextId() + "", webInfoId, urlName, urlLink)); - } - } else { - urlService.add(new Url(idWorker.nextId() + "", webInfoId, urlName, urlLink)); - } - } - } - } - } - } - - - //nse扫描结果处理 - public static void nseResultParser(AssetipService assetipService, AssetportService assetportService, IdWorker idWorker, PluginconfigService pluginconfigService, CheckresultService checkresultService, VulnkeywordService vulnkeywordService, CheckresultVulnService checkresultVulnService, VulnpluginconfigService vulnpluginconfigService, ImvulnnotifyService imvulnnotifyService, RedisTemplate redisTemplate, RabbitMessagingTemplate rabbitMessagingTemplate, String scanResult) { - - Date date = new Date(); - //scanResult第一行包含127.0.0.1 -p6379 --script redis-info - String nseCommandTemp = scanResult.split("Starting")[0]; - String ip = nseCommandTemp.split("-p")[0].trim(); - String port = nseCommandTemp.split("-p")[1].split("\\s")[0].trim(); - String nseName = nseCommandTemp.split("--script")[1].trim(); - scanResult = scanResult.split("Starting")[1]; - - //System.out.println(scanResult); - //nse结果不包含|_,证明nse结果为空 - if (!scanResult.contains("|_")) { - //结果为空,判断之前扫描情况 - //如果之前扫描到漏洞,则标记该漏洞修复 - //否则不做处理 - Assetip assetip = assetipService.findByIpaddressv4AndPassivetimeIsNull(ip); - Assetport assetport = assetportService.findByAssetipidAndPortAndDowntimeIsNull(assetip.getId(), port); - String assetPortId = assetport.getId(); - Checkresult checkresult = checkresultService.findByAssetportidAndNameAndPassivetimeIsNull(assetPortId, nseName); - if (!Objects.isNull(checkresult)) { - checkresult.setPassivetime(date); - checkresultService.update(checkresult); - } - } else { - //匹配nse结果 - String mulRegex = "(((?:^|\n)\\|.*){1,101}|((?:^|\n)\\|_.*))"; - Pattern pattern = Pattern.compile(mulRegex); - Matcher matcher = pattern.matcher(scanResult); - //单个nse结果,用if - if (matcher.find()) { - String nseResult = matcher.group(0); - nseResult = nseResult.replaceAll("\\|\\s{2,}|\\|_\\s+", "@@@@@@@@@@@@@@"); - nseResult = nseResult.replaceAll("\\|\\s|\\|_", "!#-#!#-#!#-#!#-#!#-#!#-#!#-#!"); - nseResult = nseResult.split("!#-#!#-#!#-#!#-#!#-#!#-#!#-#!")[1]; - nseResult = nseResult.replaceAll("@", ""); - //去掉结果中的nseName: - String nseResultReplaceNseName = nseResult.replaceAll(nseName + ":\\s*", ""); - pluginScanResult2Db(assetipService, assetportService, idWorker, pluginconfigService, checkresultService, vulnkeywordService, checkresultVulnService, vulnpluginconfigService, imvulnnotifyService, redisTemplate, rabbitMessagingTemplate, ip, port, nseName, nseResultReplaceNseName, "nse"); - } - } - } - - //selfd结果处理 - public static void selfdResultParser(AssetipService assetipService, AssetportService assetportService, IdWorker idWorker, PluginconfigService pluginconfigService, CheckresultService checkresultService, VulnkeywordService vulnkeywordService, CheckresultVulnService checkresultVulnService, VulnpluginconfigService vulnpluginconfigService, ImvulnnotifyService imvulnnotifyService, RedisTemplate redisTemplate, RabbitMessagingTemplate rabbitMessagingTemplate, Map resultMap, String scanResult) { - String ip = resultMap.get("ip"); - String port = resultMap.get("port"); - String selfdName = resultMap.get("pluginName"); - pluginScanResult2Db(assetipService, assetportService, idWorker, pluginconfigService, checkresultService, vulnkeywordService, checkresultVulnService, vulnpluginconfigService, imvulnnotifyService, redisTemplate, rabbitMessagingTemplate, ip, port, selfdName, scanResult, "selfd"); - } - - //插件扫描结果进数据库 - private static void pluginScanResult2Db(AssetipService assetipService, AssetportService assetportService, IdWorker idWorker, PluginconfigService pluginconfigService, CheckresultService checkresultService, VulnkeywordService vulnkeywordService, CheckresultVulnService checkresultVulnService, VulnpluginconfigService vulnpluginconfigService, ImvulnnotifyService imvulnnotifyService, RedisTemplate redisTemplate, RabbitMessagingTemplate rabbitMessagingTemplate, String ip, String port, String pluginName, String pluginScanResult, String pluginConfigType) { - Date date = new Date(); - Pluginconfig pluginconfig = pluginconfigService.findByNameAndType(pluginName, pluginConfigType); - String pluginConfigId = pluginconfig.getId(); - Map searchMap = new HashMap<>(); - searchMap.put("pluginconfigid", pluginConfigId); - List vulnkeywordList = vulnkeywordService.findSearch(searchMap); - - String validateType = pluginconfig.getValidatetype(); - //验证类型为http - //HttpValidateKey_ - if (!Objects.isNull(validateType) && validateType.contains("http")) { - //从redis中取key,设置成漏洞关键词 - String httpValidateKey = redisTemplate.opsForValue().get("HttpValidateKey_"); - vulnkeywordList.add(new Vulnkeyword(null, null, httpValidateKey)); - } - - Assetip assetip = assetipService.findByIpaddressv4AndPassivetimeIsNull(ip); - Assetport assetport = assetportService.findByAssetipidAndPortAndDowntimeIsNull(assetip.getId(), port); - String assetPortId = assetport.getId(); - Checkresult checkresult = checkresultService.findByAssetportidAndNameAndPassivetimeIsNull(assetPortId, pluginName); - //漏洞不存在或者修复后又有了 - if (Objects.isNull(checkresult)) { - for (Vulnkeyword vulnkeyword : vulnkeywordList) { - String keyword = vulnkeyword.getKeyword(); - //如果nseResultReplaceNseName包含漏洞关键字,存在漏洞,新增checkresult - if (pluginScanResult.contains(keyword)) { - //新增 checkresult - String checkResultId = idWorker.nextId() + ""; - String risk = pluginconfig.getRisk(); - checkresultService.add(new Checkresult(checkResultId, assetPortId, pluginName, pluginScanResult, risk, date, null, null)); - //更新检测结果漏洞中间表 - //获取当前pluginConfigId对应的所有插件配置 - List vulnpluginconfigList = vulnpluginconfigService.findAllByPluginConfigId(pluginConfigId); - //如果一个插件对应多个漏洞 - List vulnIdList = new ArrayList<>(); - vulnpluginconfigList.forEach(vulnpluginconfig -> { - String vulnId = vulnpluginconfig.getVulnid(); - vulnIdList.add(vulnId); - checkresultVulnService.add(new CheckresultVuln(idWorker.nextId() + "", checkResultId, vulnId)); - }); - - sendCheckResutl2ImResultQueue(imvulnnotifyService, redisTemplate, rabbitMessagingTemplate, ip, port, pluginName, assetip, assetport, risk, vulnIdList); - //vulnResultList:[Redis未授权访问] 192.168.12.138 6379 redis Redis key-value store RedisInfo 高危 - //漏洞名称 风险 ip 端口 服务 版本 检测插件名称 - //System.out.println("vulnResultList:" + vulnResultList + " " + risk + " " + ip + " " + port + " " + service + " " + version + " " + pluginName); - //TODO 立即发送邮件 - - break; - } - } - } else { - //漏洞存在 - boolean existFlag = true; - for (Vulnkeyword vulnkeyword : vulnkeywordList) { - String keyword = vulnkeyword.getKeyword(); - //如果nseResultReplaceNseName不包含漏洞关键字,不存在漏洞,漏洞已修复 - if (pluginScanResult.contains(keyword)) { - existFlag = false; - break; - } - } - if (existFlag) { - //TODO 已修复漏洞 - checkresult.setPassivetime(date); - checkresultService.update(checkresult); - } - } - } - - private static void sendCheckResutl2ImResultQueue(ImvulnnotifyService imvulnnotifyService, RedisTemplate redisTemplate, RabbitMessagingTemplate rabbitMessagingTemplate, String ip, String port, String pluginName, Assetip assetip, Assetport assetport, String risk, List vulnIdList) { - boolean sendWFlag = false; - boolean sendDFlag = false; - - String wechatnotifyKey = "wechatnotify"; - String dingtalknotifyKey = "dingtalknotify"; - String riskKey = "risk"; - - Boolean wechatnotifyFlagExist = redisTemplate.hasKey(wechatnotifyKey); - if (!Objects.isNull(wechatnotifyFlagExist) && wechatnotifyFlagExist) { - String wechatnotify = redisTemplate.opsForValue().get(wechatnotifyKey); - if (!Objects.isNull(wechatnotify) && "true".equals(wechatnotify)) { - sendWFlag = true; - } - } - - Boolean dingtalknotifyFlagExist = redisTemplate.hasKey(dingtalknotifyKey); - if (!Objects.isNull(dingtalknotifyFlagExist) && dingtalknotifyFlagExist) { - String dingtalknotify = redisTemplate.opsForValue().get(wechatnotifyKey); - if (!Objects.isNull(dingtalknotify) && "true".equals(dingtalknotify)) { - sendDFlag = true; - } - } else { - Imvulnnotify imvulnnotify = imvulnnotifyService.findAll().get(0); - //钉钉 - Boolean dingtalknotify = imvulnnotify.getDingtalknotify(); - if (!Objects.isNull(dingtalknotify) && dingtalknotify) { - sendDFlag = true; - redisTemplate.opsForValue().set(dingtalknotifyKey, "true"); - } - //企微 - Boolean wechatnotify = imvulnnotify.getWechatnotify(); - if (!Objects.isNull(wechatnotify) && wechatnotify) { - sendWFlag = true; - redisTemplate.opsForValue().set(wechatnotifyKey, "true"); - } - } - if (sendDFlag || sendWFlag) { - Boolean riskKeyFlagExist = redisTemplate.hasKey(riskKey); - String notifyRisk; - if (!Objects.isNull(riskKeyFlagExist) && riskKeyFlagExist) { - notifyRisk = redisTemplate.opsForValue().get(riskKey); - } else { - Imvulnnotify imvulnnotify = imvulnnotifyService.findAll().get(0); - notifyRisk = imvulnnotify.getRisk(); - redisTemplate.opsForValue().set(riskKey, notifyRisk); - } - //判断risk - if (!StringUtils.isEmpty(notifyRisk) && notifyRisk.contains(risk)) { - String service = assetport.getService(); - String version = assetport.getVersion(); - Map resultMap = new LinkedHashMap<>(); - resultMap.put("projectinfoid", assetip.getProjectinfoid()); - resultMap.put("vulnIdList", vulnIdList); - resultMap.put("risk", risk); - resultMap.put("ip", ip); - resultMap.put("port", port); - resultMap.put("service", service); - resultMap.put("version", version); - resultMap.put("pluginName", pluginName); - rabbitMessagingTemplate.convertAndSend("imresult", resultMap); - } - } - } - - - //一个端口,且端口相同的IP,分到一组 - public static void iPWithSamePorts2OneGroup(Map> dstMap, Map> srcMap, BlockingQueue massIpQueue) throws InterruptedException { - for (Map.Entry> entry : srcMap.entrySet()) { - //StringUtils将Set中的端口转换成str - String ip = entry.getKey(); - Set portSet = entry.getValue(); - //一个端口,且端口相同,分到一组 - if (portSet.size() == 1) { - String port = portSet.iterator().next(); - removeMultiKeyWithSameValue(dstMap, ip, port); - } else {//端口数大于2 - String ports = StringUtils.join(portSet, ","); - massIpQueue.put(ip + " -p" + ports); - } - } - } - - public static Map> ipAndPortList2Map(List ipAndPortList) { - Map> resultMap = new LinkedHashMap<>(); - //多次扫描,ip可能会重复,此时如果直接put到map中,会造成数据丢失,需要比较 - //将resultList中的结果去重,存入massResultMap - for (String line : ipAndPortList) { - String ip = line.split(",")[0]; - String port = line.split(",")[1]; - removeMultiKeyWithSameValue(resultMap, port, ip); - } - return resultMap; - } - - - //mass扫描结果进数据库 - public static void massScanResult2DB(Map> resultMap, TaskipService taskipService, TaskportService taskportService, IdWorker idWorker, String taskId) { - if (resultMap.size() != 0) { - List taskipList = new LinkedList<>(); - for (Map.Entry> entry : resultMap.entrySet()) { - String ip = entry.getKey(); - Set portInfoSet = entry.getValue(); - List taskPortList = new LinkedList<>(); - Taskip taskip = taskipService.findByTaskidAndIpaddressv4(taskId, ip); - String taskIpId; - //ip在数据库中不存在,直接新增 - if (Objects.isNull(taskip)) { - //TODO 本次任务新增的ip和端口 - taskIpId = idWorker.nextId() + ""; - taskip = new Taskip(taskIpId, taskId, ip, null, false); - //taskipList.add(taskip); - taskipService.add(taskip); - portInfoSet.forEach(portInfoString -> { - //taskPortList.add(new Taskport(idWorker.nextId() + "", taskIpId, portInfoString, null, "open", null, null)); - taskportService.add(new Taskport(idWorker.nextId() + "", taskIpId, portInfoString, "tcp", "open", null, null, false)); - }); - } else { - //当前ip在数据库中存在,判断端口 - taskIpId = taskip.getId(); - portInfoSet.forEach(portInfoString -> { - Taskport taskport = taskportService.findByTaskipidAndPort(taskIpId, portInfoString); - //端口不在数据库中,直接新增 - if (Objects.isNull(taskport)) { - //taskPortList.add(new Taskport(idWorker.nextId() + "", taskIpId, portInfoString, null, "open", null, null)); - taskportService.add(new Taskport(idWorker.nextId() + "", taskIpId, portInfoString, "tcp", "open", null, null, false)); - } - //否则不做处理 - }); - //taskportService.batchAdd(taskPortList); - } - } - //taskipService.batchAdd(taskipList); - } - } - - //nmap扫描结果进数据库 - public static void nmapScanResult2DB(Map, Set> resultMap, TaskipService taskipService, TaskportService taskportService, IdWorker idWorker, String taskId) { - if (!Objects.isNull(resultMap)&&!resultMap.isEmpty()) { - List taskipList = new LinkedList<>(); -// for (Map.Entry> entry : resultMap.entrySet()) { - resultMap.forEach((map, portInfoSet) -> { - List taskPortList = new LinkedList<>(); - String ip = map.get("ip"); - Taskip taskip = taskipService.findByTaskidAndIpaddressv4(taskId, ip); - String taskIpId; - //ip在数据库中不存在,直接新增 - if (Objects.isNull(taskip)) { - //TODO 本次任务新增的ip和端口 - taskIpId = idWorker.nextId() + ""; - taskip = new Taskip(taskIpId, taskId, ip, null, false); - //taskipList.add(taskip); - taskipService.add(taskip); - } else { - //当前ip在数据库中存在,判断端口 - taskIpId = taskip.getId(); - //taskportService.batchAdd(taskPortList); - } - //非ping扫描,有端口信息 - if (!Objects.isNull(portInfoSet)) { - portInfoSet2Db(taskportService, idWorker, portInfoSet, taskIpId); - } - }); - //taskipService.batchAdd(taskipList); - } - } - - private static void portInfoSet2Db(TaskportService taskportService, IdWorker idWorker, Set portInfoSet, String taskIpId) { - portInfoSet.forEach(portInfoString -> { - String[] portInfoStringArrays = portInfoString.split(","); - String portTemp = portInfoStringArrays[0]; - String protocolTemp = portInfoStringArrays[1]; - String stateTemp = portInfoStringArrays[2]; - String serviceTemp = portInfoStringArrays[3]; - String versionTemp = portInfoStringArrays[4]; - Taskport dbTaskport = taskportService.findByTaskipidAndPort(taskIpId, portTemp); - //taskPortList.add(new Taskport(idWorker.nextId() + "", taskIpId, portInfoStringArrays[0], portInfoStringArrays[1], portInfoStringArrays[2], portInfoStringArrays[3], portInfoStringArrays[4])); - if (Objects.isNull(dbTaskport)) { - taskportService.add(new Taskport(idWorker.nextId() + "", taskIpId, portTemp, protocolTemp, stateTemp, serviceTemp, versionTemp, false)); - } else { - boolean flag = false; - //端口在数据库中 - //更新protocol - if (!Objects.isNull(protocolTemp) && (Objects.isNull(dbTaskport.getProtocol()) || "null".equals(dbTaskport.getProtocol()))) { - dbTaskport.setProtocol(protocolTemp); - flag = true; - } - //更新tcp/udp - if (!Objects.isNull(protocolTemp) && !Objects.isNull(dbTaskport.getProtocol()) && !"null".equals(dbTaskport.getProtocol())) { - if (!dbTaskport.getProtocol().contains("/")) { - if (("tcp".equals(protocolTemp) && "udp".equals(dbTaskport.getProtocol())) || "udp".equals(protocolTemp) && "tcp".equals(dbTaskport.getProtocol())) { - dbTaskport.setProtocol("tcp/udp"); - flag = true; - } - } - } - //更新state - if ("open".equals(stateTemp) && (Objects.isNull(dbTaskport.getState()) || !"open".equals(dbTaskport.getState()))) { - dbTaskport.setState(stateTemp); - flag = true; - } - //更新service - if ( - (!Objects.isNull(serviceTemp) && !"tcpwrapped".equals(serviceTemp) && !"unknown".equals(serviceTemp) && !serviceTemp.contains("?")) - && (Objects.isNull(dbTaskport.getService()) || "tcpwrapped".equals(dbTaskport.getService()) || "unknown".equals(dbTaskport.getService()) || dbTaskport.getService().contains("?") || "null".equals(dbTaskport.getService()) || !serviceTemp.equals(dbTaskport.getService())) - ) { - dbTaskport.setService(serviceTemp); - flag = true; - } - //更新version - if ((!Objects.isNull(versionTemp) && !"null".equals(versionTemp)) - && (Objects.isNull(dbTaskport.getVersion()) || "null".equals(dbTaskport.getVersion()) || !versionTemp.equals(dbTaskport.getVersion()))) { - dbTaskport.setVersion(versionTemp); - flag = true; - } - if (flag) { - taskportService.update(dbTaskport); - } - } - }); - } - - //mass扫描结果直接进资产 - public static void massScanResult2AssetDB(AssetipService assetipService, AssetportService assetportService, IdWorker idWorker, RabbitMessagingTemplate rabbitMessagingTemplate, Set riskPortSet, Set riskServiceSet, Set riskVersionSet, Map> massResultMap) { - if (massResultMap.size() != 0) { - Date date = new Date(); - List assetipList = new LinkedList<>(); - massResultMap.forEach((ip, portInfoSet) -> { - //当前ip端口列表,用于批量增加 - List portList = new LinkedList<>(); - String assetIpId; - //查询数据库中passivetime为空且ipaddressv4等于当前ip的ip - Assetip assetip = assetipService.findByIpaddressv4AndPassivetimeIsNull(ip); - //ip在数据库中不存在,直接新增 - if (Objects.isNull(assetip)) { - //如果结果返回空 - //数据库中没有当前ip或者所有的ip都已下线,新增ip及端口 - //TODO mass扫描新增ip和端口 - assetIpId = idWorker.nextId() + ""; - assetip = new Assetip(assetIpId, null, ip, null, false, false, date, null, null); - //assetipList.add(assetip); - assetipService.add(assetip); - portInfoSet.forEach(portInfoString -> { - //portList.add(new Assetport(idWorker.nextId() + "", assetIpId, portInfoString, null, "open", null, null, date, null)); - assetportService.add(new Assetport(idWorker.nextId() + "", assetIpId, portInfoString, "tcp", "open", null, null, false, false, date, null, null)); - //新增高危信息端口发送到IM - sendRiskPort2IM(rabbitMessagingTemplate, riskPortSet, riskServiceSet, riskVersionSet, "**" + ip + "**", portInfoString, "tcp", null, null); - }); - } else { - //当前ip在数据库中存在,更新端口信息 - for (String portInfoString : portInfoSet) { - //mass扫描结果 - Assetport dbPort = assetportService.findByAssetipidAndPortAndDowntimeIsNull(assetip.getId(), portInfoString); - if (Objects.isNull(dbPort)) { - //当前端口不在DB中或者当前端口已下线,新增端口 - //TODO 已存在数据库中ip的新增端口 - //portList.add(new Assetport(idWorker.nextId() + "", assetip.getId(), portInfoString, null, "open", null, null, date, null)); - assetportService.add(new Assetport(idWorker.nextId() + "", assetip.getId(), portInfoString, "tcp", "open", null, null, false, false, date, null, null)); - //新增高危信息端口发送到IM - sendRiskPort2IM(rabbitMessagingTemplate, riskPortSet, riskServiceSet, riskVersionSet, ip, portInfoString, "tcp", null, null); - } else { - //当前端口在DB中,更新端口状态 - boolean flag = false; - if (dbPort.getState() == null || !"open".equals(dbPort.getState())) { - dbPort.setState("open"); - dbPort.setUptime(date); - dbPort.setChangedtime(date); - flag = true; - } - if (flag) { - assetportService.update(dbPort); - } - } - } - } - //assetportService.batchAdd(portList); - }); - //assetipService.batchAdd(assetipList); - } - } - - - //nmap扫描结果直接进资产 - public static void nmapScanResult2AssetDB(AssetipService assetipService, AssetportService assetportService, HostService hostService, IdWorker idWorker, RabbitMessagingTemplate rabbitMessagingTemplate, Set riskPortSet, Set riskServiceSet, Set riskVersionSet, Map, Set> nmapResultMap) { - if (!Objects.isNull(nmapResultMap)&&!nmapResultMap.isEmpty()) { - Date date = new Date(); - List assetipList = new LinkedList<>(); -// for (Map.Entry> entry : nmapResultMap.entrySet()) { - nmapResultMap.forEach((map, portInfoSet) -> { - //当前ip端口列表,用于批量增加 - String ip = map.get("ip"); - List portList = new LinkedList<>(); - String assetIpId; - - //查询数据库中passivetime为空且ipaddressv4等于当前ip的ip - Assetip assetip = assetipService.findByIpaddressv4AndPassivetimeIsNull(ip); - if (Objects.isNull(assetip)) { - //如果结果返回空 - //数据库中没有当前ip或者所有的ip都已下线,新增ip及端口 - //TODO nmap扫描新增ip和端口 - assetIpId = idWorker.nextId() + ""; - assetip = new Assetip(assetIpId, null, ip, null, false, false, date, null, null); - //assetipList.add(assetip); - assetipService.add(assetip); - if (!Objects.isNull(portInfoSet)) { - for (String portInfoString : portInfoSet) { - String[] portInfoStringArrays = portInfoString.split(","); - String portTemp = portInfoStringArrays[0]; - String protocolTemp = portInfoStringArrays[1]; - String stateTemp = portInfoStringArrays[2]; - String serviceTemp = portInfoStringArrays[3]; - String versionTemp = portInfoStringArrays[4]; - //状态为open的端口才进资产库 - if ("open".equals(stateTemp)) { - Assetport dbAssetPort = assetportService.findByAssetipidAndPortAndDowntimeIsNull(assetip.getId(), portTemp); - //批量导入时,如果单个ip端口重复,数据库中端口会重复 - //需要判断端口是否在数据库中才新增 - if (Objects.isNull(dbAssetPort)) { - assetportService.add(new Assetport(idWorker.nextId() + "", assetip.getId(), portTemp, protocolTemp, stateTemp, serviceTemp, versionTemp, false, false, date, null, null)); - //新增高危信息端口发送到IM - sendRiskPort2IM(rabbitMessagingTemplate, riskPortSet, riskServiceSet, riskVersionSet, "**" + ip + "**", portTemp, protocolTemp, serviceTemp, versionTemp); - //portList.add(new Assetport(idWorker.nextId() + "", assetip.getId(), portTemp, protocolTemp, stateTemp, serviceTemp, versionTemp, date, null)); - } else { - //当前端口在DB中,更新端口 - boolean flag = false; - //更新protocol - if (!Objects.isNull(protocolTemp) && (Objects.isNull(dbAssetPort.getProtocol()) || "null".equals(dbAssetPort.getProtocol()))) { - dbAssetPort.setProtocol(protocolTemp); - flag = true; - } - //更新tcp/udp - if (!Objects.isNull(protocolTemp) && !Objects.isNull(dbAssetPort.getProtocol()) && !"null".equals(dbAssetPort.getProtocol())) { - if (!dbAssetPort.getProtocol().contains("/")) { - if (("tcp".equals(protocolTemp) && "udp".equals(dbAssetPort.getProtocol())) || "udp".equals(protocolTemp) && "tcp".equals(dbAssetPort.getProtocol())) { - dbAssetPort.setProtocol("tcp/udp"); - flag = true; - } - } - } - //更新state - if ((Objects.isNull(dbAssetPort.getState()) || !"open".equals(dbAssetPort.getState()))) { - dbAssetPort.setState(stateTemp); - flag = true; - } - //更新service - if ( - (!Objects.isNull(serviceTemp) && !"tcpwrapped".equals(serviceTemp) && !"unknown".equals(serviceTemp) && !serviceTemp.contains("?")) - && (Objects.isNull(dbAssetPort.getService()) || "tcpwrapped".equals(dbAssetPort.getService()) || "unknown".equals(dbAssetPort.getService()) || dbAssetPort.getService().contains("?") || "null".equals(dbAssetPort.getService()) || !serviceTemp.equals(dbAssetPort.getService())) - ) { - dbAssetPort.setService(serviceTemp); - flag = true; - } - //version为空或者null,才更新version - //加新verison - if ((!Objects.isNull(versionTemp) && !"null".equals(versionTemp)) - && (Objects.isNull(dbAssetPort.getVersion()) || "null".equals(dbAssetPort.getVersion()) || !versionTemp.equals(dbAssetPort.getVersion()))) { - dbAssetPort.setVersion(versionTemp); - flag = true; - } - if (flag) { - dbAssetPort.setChangedtime(date); - assetportService.update(dbAssetPort); - } - } - } - } - } - - - } else { - //当前ip在数据库中存在,更新端口信息 - assetIpId = assetip.getId(); - if (!Objects.isNull(portInfoSet)) { - for (String portInfoString : portInfoSet) { - - //nmap扫描结果 - //port,protocol,state,service,version - //3306,tcp,open,mysql,MySQL 5.7.24-log - String[] portInfoStringArrays = portInfoString.split(","); - String portTemp = portInfoStringArrays[0]; - String protocolTemp = portInfoStringArrays[1]; - String stateTemp = portInfoStringArrays[2]; - String serviceTemp = portInfoStringArrays[3]; - String versionTemp = portInfoStringArrays[4]; - - Assetport dbAssetPort = assetportService.findByAssetipidAndPortAndDowntimeIsNull(assetIpId, portTemp); - if (Objects.isNull(dbAssetPort)) { - //当前端口不在DB中或者当前端口已下线,且端口状态是open,新增端口 - //TODO 已在数据库中ip的新增端口 - if ("open".equals(stateTemp)) { - //portList.add(new Assetport(idWorker.nextId() + "", assetip.getId(), portTemp, protocolTemp, stateTemp, serviceTemp, versionTemp, date, null)); - assetportService.add(new Assetport(idWorker.nextId() + "", assetIpId, portTemp, protocolTemp, stateTemp, serviceTemp, versionTemp, false, false, date, null, null)); - //已在数据库中的ip 新增高危信息端口发送到IM - sendRiskPort2IM(rabbitMessagingTemplate, riskPortSet, riskServiceSet, riskVersionSet, ip, portTemp, protocolTemp, serviceTemp, versionTemp); - } - } else { - //当前端口在DB中,更新端口 - boolean flag = false; - boolean sendFlag = false; - //如果扫描到端口已关闭,将端口下线 - if ("closed".equals(stateTemp)) { - dbAssetPort.setState("closed"); - dbAssetPort.setDowntime(date); - flag = true; - } else { - //更新protocol - if (!Objects.isNull(protocolTemp) && (Objects.isNull(dbAssetPort.getProtocol()) || "null".equals(dbAssetPort.getProtocol()))) { - dbAssetPort.setProtocol(protocolTemp); - flag = true; - } - //更新tcp/udp - if (!Objects.isNull(protocolTemp) && !Objects.isNull(dbAssetPort.getProtocol()) && !"null".equals(dbAssetPort.getProtocol())) { - if (!dbAssetPort.getProtocol().contains("/")) { - if (("tcp".equals(protocolTemp) && "udp".equals(dbAssetPort.getProtocol())) || "udp".equals(protocolTemp) && "tcp".equals(dbAssetPort.getProtocol())) { - dbAssetPort.setProtocol("tcp/udp"); - flag = true; - } - } - } - //更新state - if ("open".equals(stateTemp) && (Objects.isNull(dbAssetPort.getState()) || !"open".equals(dbAssetPort.getState()))) { - dbAssetPort.setState(stateTemp); - flag = true; - sendFlag = true; - } - //更新service - if ( - (!Objects.isNull(serviceTemp) && !"tcpwrapped".equals(serviceTemp) && !"unknown".equals(serviceTemp) && !serviceTemp.contains("?")) - && (Objects.isNull(dbAssetPort.getService()) || "tcpwrapped".equals(dbAssetPort.getService()) || "unknown".equals(dbAssetPort.getService()) || dbAssetPort.getService().contains("?") || "null".equals(dbAssetPort.getService()) || !serviceTemp.equals(dbAssetPort.getService())) - ) { - dbAssetPort.setService(serviceTemp); - flag = true; - sendFlag = true; - } - //更新version - if ((!Objects.isNull(versionTemp) && !"null".equals(versionTemp)) - && (Objects.isNull(dbAssetPort.getVersion()) || "null".equals(dbAssetPort.getVersion())) || !versionTemp.equals(dbAssetPort.getVersion())) { - dbAssetPort.setVersion(versionTemp); - flag = true; - sendFlag = true; - } - } - if (flag) { - dbAssetPort.setChangedtime(date); - assetportService.update(dbAssetPort); - } - //已在数据库中的ip,已存在的端口,新增高危信息端口发送到IM - if (sendFlag) { - sendRiskPort2IM(rabbitMessagingTemplate, riskPortSet, riskServiceSet, riskVersionSet, ip, portTemp, protocolTemp, serviceTemp, versionTemp); - } - } - - } - } - } - //assetportService.batchAdd(portList); - //hostname / domain - //域名 - String domain = map.get("domain"); - if (!Objects.isNull(domain)) { - Host hostname = hostService.findByHostname(domain); - if (Objects.isNull(hostname)) { - hostService.add(new Host(idWorker.nextId() + "", assetIpId, map.get("macAddress"), domain, null, null, map.get("type"), null, new Date(), null)); - } - } - String macAddress = map.get("macAddress"); - if (!Objects.isNull(macAddress)) { - Host macaddress = hostService.findByMacaddress(macAddress); - if (Objects.isNull(macaddress)) { - hostService.add(new Host(idWorker.nextId() + "", assetIpId, map.get("macAddress"), map.get("domain"), null, null, map.get("type"), null, new Date(), null)); - } - } - }); - //assetipService.batchAdd(assetipList); - } - } - - private static void sendRiskPort2IM(RabbitMessagingTemplate rabbitMessagingTemplate, Set riskPortSet, Set riskServiceSet, Set riskVersionSet, String ip, String portTemp, String protocolTemp, String serviceTemp, String versionTemp) { - if (!riskPortSet.isEmpty() || !riskServiceSet.isEmpty() || !riskVersionSet.isEmpty()) { - boolean sendFlag = false; - Map imResultMap = new HashMap<>(); - //端口在高危设置中,服务和版本也要一起推送 - if (riskPortSet.contains(portTemp) || riskServiceSet.contains(serviceTemp) || riskVersionSet.contains(versionTemp)) { - if (!StringUtils.isEmpty(portTemp)) { - imResultMap.put("port", portTemp); - sendFlag = true; - } - if (!StringUtils.isEmpty(serviceTemp)) { - imResultMap.put("service", serviceTemp); - sendFlag = true; - }else { - imResultMap.put("service", "null"); - } - if (!StringUtils.isEmpty(versionTemp)) { - imResultMap.put("version", versionTemp); - sendFlag = true; - }else { - imResultMap.put("version", "null"); - } - } - if (sendFlag) { - //新增ip的高危端口信息 - imResultMap.put("ip", ip); - imResultMap.put("protocol", protocolTemp); - rabbitMessagingTemplate.convertAndSend("imresult", imResultMap); - } - } - } - - //批量导入 - public static void batchNmapScanResult2AssetDB(AssetipService assetipService, AssetportService assetportService, HostService hostService, IdWorker idWorker, Map> nmapResultMap) { - if (nmapResultMap.size() != 0) { - Date date = new Date(); - List assetipList = new LinkedList<>(); -// for (Map.Entry> entry : nmapResultMap.entrySet()) { - nmapResultMap.forEach((ip, portInfoSet) -> { - //当前ip端口列表,用于批量增加 - List portList = new LinkedList<>(); - String assetIpId; - - //查询数据库中passivetime为空且ipaddressv4等于当前ip的ip - Assetip assetip = assetipService.findByIpaddressv4AndPassivetimeIsNull(ip); - if (Objects.isNull(assetip)) { - //如果结果返回空 - //数据库中没有当前ip或者所有的ip都已下线,新增ip及端口 - //TODO nmap扫描新增ip和端口 - assetIpId = idWorker.nextId() + ""; - assetip = new Assetip(assetIpId, null, ip, null, false, false, date, null, null); - //assetipList.add(assetip); - assetipService.add(assetip); - if (!Objects.isNull(portInfoSet)) { - for (String portInfoString : portInfoSet) { - String[] portInfoStringArrays = portInfoString.split(","); - String portTemp = portInfoStringArrays[0]; - String protocolTemp = portInfoStringArrays[1]; - String stateTemp = portInfoStringArrays[2]; - String serviceTemp = portInfoStringArrays[3]; - String versionTemp = portInfoStringArrays[4]; - //状态为open的端口才进资产库 - if ("open".equals(stateTemp)) { - Assetport dbAssetPort = assetportService.findByAssetipidAndPortAndDowntimeIsNull(assetip.getId(), portTemp); - //批量导入时,如果单个ip端口重复,数据库中端口会重复 - //需要判断端口是否在数据库中才新增 - if (Objects.isNull(dbAssetPort)) { - assetportService.add(new Assetport(idWorker.nextId() + "", assetip.getId(), portTemp, protocolTemp, stateTemp, serviceTemp, versionTemp, false, false, date, null, null)); - //portList.add(new Assetport(idWorker.nextId() + "", assetip.getId(), portTemp, protocolTemp, stateTemp, serviceTemp, versionTemp, date, null)); - } else { - //当前端口在DB中,更新端口 - boolean flag = false; - //更新protocol - if (!Objects.isNull(protocolTemp) && (Objects.isNull(dbAssetPort.getProtocol()) || "null".equals(dbAssetPort.getProtocol()))) { - dbAssetPort.setProtocol(protocolTemp); - flag = true; - } - //更新tcp/udp - if (!Objects.isNull(protocolTemp) && !Objects.isNull(dbAssetPort.getProtocol()) && !"null".equals(dbAssetPort.getProtocol())) { - if (!dbAssetPort.getProtocol().contains("/")) { - if (("tcp".equals(protocolTemp) && "udp".equals(dbAssetPort.getProtocol())) || "udp".equals(protocolTemp) && "tcp".equals(dbAssetPort.getProtocol())) { - dbAssetPort.setProtocol("tcp/udp"); - flag = true; - } - } - } - //更新state - if ((Objects.isNull(dbAssetPort.getState()) || !"open".equals(dbAssetPort.getState()))) { - dbAssetPort.setState(stateTemp); - flag = true; - } - //更新service - if ( - (!Objects.isNull(serviceTemp) && !"tcpwrapped".equals(serviceTemp) && !"unknown".equals(serviceTemp) && !serviceTemp.contains("?")) - && (Objects.isNull(dbAssetPort.getService()) || "tcpwrapped".equals(dbAssetPort.getService()) || "unknown".equals(dbAssetPort.getService()) || dbAssetPort.getService().contains("?") || "null".equals(dbAssetPort.getService()) || !serviceTemp.equals(dbAssetPort.getService())) - ) { - dbAssetPort.setService(serviceTemp); - flag = true; - } - //version为空或者null,才更新version - //加新verison - if ((!Objects.isNull(versionTemp) && !"null".equals(versionTemp)) - && (Objects.isNull(dbAssetPort.getVersion()) || "null".equals(dbAssetPort.getVersion()) || !versionTemp.equals(dbAssetPort.getVersion()))) { - dbAssetPort.setVersion(versionTemp); - flag = true; - } - if (flag) { - dbAssetPort.setChangedtime(date); - assetportService.update(dbAssetPort); - } - } - } - } - } - } else { - //当前ip在数据库中存在,更新端口信息 - assetIpId = assetip.getId(); - if (!Objects.isNull(portInfoSet)) { - for (String portInfoString : portInfoSet) { - - //nmap扫描结果 - //port,protocol,state,service,version - //3306,tcp,open,mysql,MySQL 5.7.24-log - String[] portInfoStringArrays = portInfoString.split(","); - String portTemp = portInfoStringArrays[0]; - String protocolTemp = portInfoStringArrays[1]; - String stateTemp = portInfoStringArrays[2]; - String serviceTemp = portInfoStringArrays[3]; - String versionTemp = portInfoStringArrays[4]; - - Assetport dbAssetPort = assetportService.findByAssetipidAndPortAndDowntimeIsNull(assetIpId, portTemp); - if (Objects.isNull(dbAssetPort)) { - //当前端口不在DB中或者当前端口已下线,且端口状态是open,新增端口 - //TODO 已在数据库中ip的新增端口 - if ("open".equals(stateTemp)) { - //portList.add(new Assetport(idWorker.nextId() + "", assetip.getId(), portTemp, protocolTemp, stateTemp, serviceTemp, versionTemp, date, null)); - assetportService.add(new Assetport(idWorker.nextId() + "", assetIpId, portTemp, protocolTemp, stateTemp, serviceTemp, versionTemp, false, false, date, null, null)); - } - } else { - //当前端口在DB中,更新端口 - boolean flag = false; - //如果扫描到端口已关闭,将端口下线 - if ("closed".equals(stateTemp)) { - dbAssetPort.setState("closed"); - dbAssetPort.setDowntime(date); - flag = true; - } else { - //更新protocol - if (!Objects.isNull(protocolTemp) && (Objects.isNull(dbAssetPort.getProtocol()) || "null".equals(dbAssetPort.getProtocol()))) { - dbAssetPort.setProtocol(protocolTemp); - flag = true; - } - //更新tcp/udp - if (!Objects.isNull(protocolTemp) && !Objects.isNull(dbAssetPort.getProtocol()) && !"null".equals(dbAssetPort.getProtocol())) { - if (!dbAssetPort.getProtocol().contains("/")) { - if (("tcp".equals(protocolTemp) && "udp".equals(dbAssetPort.getProtocol())) || "udp".equals(protocolTemp) && "tcp".equals(dbAssetPort.getProtocol())) { - dbAssetPort.setProtocol("tcp/udp"); - flag = true; - } - } - } - //更新state - if ("open".equals(stateTemp) && (Objects.isNull(dbAssetPort.getState()) || !"open".equals(dbAssetPort.getState()))) { - dbAssetPort.setState(stateTemp); - flag = true; - } - //更新service - if ( - (!Objects.isNull(serviceTemp) && !"tcpwrapped".equals(serviceTemp) && !"unknown".equals(serviceTemp) && !serviceTemp.contains("?")) - && (Objects.isNull(dbAssetPort.getService()) || "tcpwrapped".equals(dbAssetPort.getService()) || "unknown".equals(dbAssetPort.getService()) || dbAssetPort.getService().contains("?") || "null".equals(dbAssetPort.getService()) || !serviceTemp.equals(dbAssetPort.getService())) - ) { - dbAssetPort.setService(serviceTemp); - flag = true; - } - //更新version - if ((!Objects.isNull(versionTemp) && !"null".equals(versionTemp)) - && (Objects.isNull(dbAssetPort.getVersion()) || "null".equals(dbAssetPort.getVersion())) || !versionTemp.equals(dbAssetPort.getVersion())) { - dbAssetPort.setVersion(versionTemp); - flag = true; - } - } - if (flag) { - dbAssetPort.setChangedtime(date); - assetportService.update(dbAssetPort); - } - } - } - } - } - //assetportService.batchAdd(portList); - }); - //assetipService.batchAdd(assetipList); - } - } - - //合并Map中相同value(单个)的key - //如a:1,b:1,c:1=》1:a,b,c - private static void removeMultiKeyWithSameValue(Map> massRawMap, String value, String key) { - Set set; - if (massRawMap.containsKey(key)) { - set = massRawMap.get(key); - } else { - set = new LinkedHashSet<>(); - } - set.add(value); - massRawMap.put(key, set); - } - - public static Map, Set> nmapResult2Map(String result) { - //portInfo port, state, service, version; - Map, Set> resultMap = new LinkedHashMap<>(); - String regex = "All\\s.*|(?:^|are\\sclosed\n)MAC\\sAddress\\s|(?:^|\n)Nmap\\sscan\\sreport\\s|(?:^|\n)Starting\\sNmap.*|(?:^|\n)Host.*|(?:^|\n)Not shown.*|(?:^|\n)Some\\sclosed .*|(?:^|\n)PORT.*|(?:^|\n)[0-9]?\\sservice.?\\sunrecognized.*|(?:^|\n)SF.*|(?:^|\n)Starting.*|(?:^|\n)Warning.*|(?:^|\n)={14}.*|(?:^|\n)Service\\sdetection.*|(?:^|\n)Nmap done.*"; - result = result.replaceAll(regex, ""); - if (result.length() != 1) { - if ((result.contains("tcp") || result.contains("udp"))) { - //端口扫描 - //正则采用NFA,递归过深会导致Exception in thread "main" java.lang.StackOverflowError - //{1,500}限制单个ip匹配端口数,测试中超过770个就会导致栈溢出 - //匹配IP及对应服务 - //String mulRegex = "for\\s(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})\n?(((?:^|\n)[0-9].*){1,500})"; - String ipRegex = "(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})"; - String[] tempResults = result.split("\\n"); - String singleLine = tempResults[0]; - singleLine = singleLine.replaceAll(ipRegex, ""); - singleLine = singleLine.replaceAll("[()]", ""); - String[] split = singleLine.split("\\s"); - //没有域名 - if (split.length == 1) { - String mulRegex = "for\\s(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})\n?(((?:^|\n)[0-9].*){1,500})"; - Pattern pattern = Pattern.compile(mulRegex); - Matcher matcher = pattern.matcher(result); - while (matcher.find()) { - //singleStatus[0]:PORT,singleStatus[1]:STATE,singleStatus[2]:SERVICE,singleStatus[3]:VERSION - String ip = matcher.group(1); - String status = matcher.group(2); - //单行IP状态,PORT STATE SERVICE VERSION - //用于保存分割后的状态 - //将lineStatus分解成单个数组元素,并保存到singleStatus中 - String[] lineStatus = status.split("\n"); - if (!org.springframework.util.StringUtils.isEmpty(ip)) { - Map map = new HashMap<>(); - map.put("ip", ip); - macAddress2Map(result, resultMap, tempResults, lineStatus, map); - } - } - } else { - String replaceRegex = "Other\\saddresses\\sfor.*|(?:^|\n)rDNS\\srecord\\sfor.*|(?:^|\n)Nmap\\sscan\\sreport\\s|(?:^|\n)Starting\\sNmap.*|(?:^|\n)Host.*|(?:^|\n)Not shown.*|(?:^|\n)Some\\sclosed .*|(?:^|\n)PORT.*|(?:^|\n)[0-9]?\\sservice.?\\sunrecognized.*|(?:^|\n)SF.*|(?:^|\n)Starting.*|(?:^|\n)Warning.*|(?:^|\n)={14}.*|(?:^|\n)Service\\sdetection.*|(?:^|\n)Nmap done.*"; - result = result.replaceAll(replaceRegex, ""); - String mulRegex = "for\\s(.*)\n?(((?:^|\n)[0-9].*){1,500})"; - Pattern pattern = Pattern.compile(mulRegex); - Matcher matcher = pattern.matcher(result); - while (matcher.find()) { - //singleStatus[0]:PORT,singleStatus[1]:STATE,singleStatus[2]:SERVICE,singleStatus[3]:VERSION - String domainAndIp = matcher.group(1); - String domain = domainAndIp.replaceAll("[()]", "").split("\\s")[0]; - String ip = domainAndIp.replaceAll("[()]", "").split("\\s")[1]; - String status = matcher.group(2); - //单行IP状态,PORT STATE SERVICE VERSION - //用于保存分割后的状态 - //将lineStatus分解成单个数组元素,并保存到singleStatus中 - String[] lineStatus = status.split("\n"); - if (!org.springframework.util.StringUtils.isEmpty(ip)) { - Map map = new HashMap<>(); - map.put("ip", ip); - map.put("domain", domain); - macAddress2Map(result, resultMap, tempResults, lineStatus, map); - } - } - } - - - } else if (!result.contains("tcp") && !result.contains("udp")) { //nmap -sn,ping扫描 - result = result.replaceAll("\\)for\\s", "<+>"); - result = result.replaceAll("for\\s", ""); - result = result.replaceAll("\n", ""); - Set resultSet = new HashSet<>(0); - String[] ipAndMacAddr = result.split("<\\+>"); - for (String line : ipAndMacAddr) { - if (!org.springframework.util.StringUtils.isEmpty(line)) { - Map map = new HashMap<>(); - String ip = line; - if (line.contains("MAC Address: ")) { - ip = line.split("MAC Address: ")[0]; - String temp = line.split("MAC Address: ")[1]; - if (temp.contains("(")) { - String macAddr = temp.split("\\s\\(")[0]; - String type = temp.split("\\s\\(")[1]; - map.put("macAddress", macAddr); - map.put("type", type); - } - } - if (!org.springframework.util.StringUtils.isEmpty(ip)) { - map.put("ip", ip); - resultMap.put(map, resultSet); - } - } - } - } - } - return resultMap.isEmpty() ? null : resultMap; - } - - private static void macAddress2Map(String result, Map, Set> resultMap, String[] tempResults, String[] lineStatus, Map map) { - if (result.contains("MAC Address")) { - String macAddrTemp = tempResults[tempResults.length - 1]; - String s = macAddrTemp.split(":\\s")[1]; - String macAddr = s; - if (s.contains("(")) { - String type = s.split("\\s\\(")[1]; - type = type.replace(")", ""); - map.put("type", type); - macAddr = s.split("\\s\\(")[0]; - } - map.put("macAddress", macAddr); - } - resultMap.put(map, lineStatus2Set(lineStatus)); - } - - - private static Set lineStatus2Set(String[] targetLine) { - Set resultSet = new HashSet<>(); - for (String line : targetLine) { - String[] singleStatus = new String[5]; - //去掉第一个空元素 - if (line.length() == 0) { - continue; - } else { - //按空格分割成数组 - String[] statusArray = line.split("\\s+"); - //对PORT、protocol、STATE、SERVICE赋值 - singleStatus[0] = statusArray[0].split("/")[0];//port - singleStatus[1] = statusArray[0].split("/")[1];//protocol - singleStatus[2] = statusArray[1];//STATE - singleStatus[3] = statusArray[2];//VERVICE - - //对VERSION赋值,如果statusArray等于3,则VERSION为null - if (statusArray.length > 3) { - String[] version = Arrays.copyOfRange(statusArray, 3, statusArray.length); - StringBuilder stringBuilder = new StringBuilder(); - //空格分割VERSION中的单词,并去掉末尾的空格 - for (int i = 0; i < version.length; i++) { - if (i != version.length - 1) { - stringBuilder.append(version[i]).append(" "); - } else { - stringBuilder.append(version[i]); - } - } - singleStatus[4] = stringBuilder.toString(); - } else { - singleStatus[4] = null; - } - } - String singleStatusString = Arrays.asList(singleStatus).toString(); - //去掉逗号后面的空格 - singleStatusString = singleStatusString.replaceAll(",\\s", ","); - resultSet.add(singleStatusString.replace("[", "").replace("]", "")); - } - return resultSet; - } - - public static Map> ipAndPortList2Map(String result) { - - //Discovered open port 21/tcp on 192.168.1.1 - String mulRegex = "([1-9][0-9]*)/\\w+\\son\\s(\\d+\\.\\d+\\.\\d+\\.\\d+)"; - Pattern pattern = Pattern.compile(mulRegex); - Matcher matcher = pattern.matcher(result); - Map> resultMap = new LinkedHashMap<>(); - List resultList = new ArrayList<>(); - while (matcher.find()) { - String ports = matcher.group(1); - String ip = matcher.group(2); - resultList.add(ip + "-" + ports); - } - //多次扫描,ip可能会重复,此时如果直接put到map中,会造成数据丢失,需要比较 - //将resultList中的结果去重,存入massResultMap - resultList.forEach(line -> { - String ip = line.split("-")[0]; - String port = line.split("-")[1]; - removeMultiKeyWithSameValue(resultMap, port, ip); - }); - - return resultMap; - } - - public static void targetIPSet2SliceIPSet(String worktype, String targetport, String dstkey, String srckey, RedisTemplate redisTemplate, String ipslicesize, String portslicesize) { - - int sliceSize = 255; - if (!Objects.isNull(ipslicesize) && !"".equals(ipslicesize)) { - sliceSize = Integer.parseInt(ipslicesize); - } - long ipGroupNumber = redisTemplate.opsForSet().size(srckey) / sliceSize; - - BlockingQueue rawIpQueue = new LinkedBlockingQueue<>(redisTemplate.opsForSet().members(srckey)); - for (long i = 0; i <= ipGroupNumber; i++) { - List list = new ArrayList<>(); - rawIpQueue.drainTo(list, sliceSize); - //nmap模式下全端口分组,mass模式不管它 - if ("nmap".equals(worktype) && (Objects.isNull(targetport) || targetport.isEmpty()) && !Objects.isNull(portslicesize) && !portslicesize.isEmpty()) { - //默认1000端口为一组 - int pSliceSize = 1000; - //分组范围1000-10000,其他则按默认1000大小进行分组 - if (Integer.parseInt(portslicesize) >= 1000 && Integer.parseInt(portslicesize) <= 10000) { - pSliceSize = Integer.parseInt(portslicesize); - } - int portGroupNumber = 65535 / pSliceSize; - StringBuilder stringBuilder = new StringBuilder(); - int start, end; - for (int j = 0, k = 1; j <= portGroupNumber; j++) { - start = k; - stringBuilder.append(start).append("-"); - k += pSliceSize; - end = k - 1; - if (end >= 65535) { - end = 65535; - } - stringBuilder.append(end).append(","); - } - - String[] portsArr = stringBuilder.toString().split(","); - for (String ports : portsArr) { - String targetIp = list.toString().replaceAll("[,\\[\\]]", ""); - if (!targetIp.isEmpty()) { - redisTemplate.opsForList().rightPush(dstkey, list.toString().replaceAll("[,\\[\\]]", "") + " -p" + ports); - } - } - - } else { - //分组可能为空 - if (list.size() != 0) { - redisTemplate.opsForList().rightPush(dstkey, list.toString()); - } - } - } - } - - - public static void target2Redis(String targetIp, RedisTemplate redisTemplate, String key) { - if (Objects.isNull(targetIp)) - return; - //单个ip - if (!targetIp.contains(",") && !targetIp.contains("-") && !targetIp.contains("/")) { - redisTemplate.opsForSet().add(key, targetIp); - } - String[] targetIps = targetIp.split(","); - for (String singleIp : targetIps) { - //ip段 - if (singleIp.contains("-")) { - Long start = ip2num(singleIp.split("-")[0]); - Long end = ip2num(singleIp.split("-")[1]); - LongStream.rangeClosed(start, end).forEach(ip -> { - if ((ip & 0xff) == 0) - return; - redisTemplate.opsForSet().add(key, num2ip(ip)); - }); - } else if (singleIp.contains("/")) { - //CIDR表示的地址,将其转换成IP - SubnetUtils subnetUtils = new SubnetUtils(singleIp); - String[] IPs = subnetUtils.getInfo().getAllAddresses(); - for (String ip : IPs) { - redisTemplate.opsForSet().add(key, ip); - } - } else { - //单个ip - redisTemplate.opsForSet().add(key, singleIp); - } - } - - } - - private static Long ip2num(String ip) { - String[] ips = ip.split("\\."); - return Long.parseLong(ips[0]) << 24 | Long.parseLong(ips[1]) << 16 | Long.parseLong(ips[2]) << 8 | Long.parseLong(ips[3]); - } - - private static String num2ip(Long num) { - return ((num >> 24) & 0xff) + "." + ((num >> 16) & 0xff) + "." + ((num >> 8) & 0xff) + "." + (num & 0xff); - } - - public static Map cronParseResult(String cronExpression) throws ParseException { - Map runResultMap = new LinkedHashMap<>(); - Map resultMap = new LinkedHashMap<>(); - if (org.springframework.util.StringUtils.isEmpty(cronExpression) || !CronExpression.isValidExpression(cronExpression)) { - runResultMap.put("解析失败", "Cron表达式错误"); - return runResultMap; - } - CronTriggerImpl cronTriggerImpl = new CronTriggerImpl(); - cronTriggerImpl.setCronExpression(cronExpression); - List dates = TriggerUtils.computeFireTimes(cronTriggerImpl, null, 10); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date dateNow = new Date(); - String now = sdf.format(dateNow); - resultMap.put("当前时间", now); - for (int i = 1; i <= dates.size(); i++) { - if (!Objects.isNull(dates.get(i - 1))) { - resultMap.put("第" + i + "次执行", sdf.format(dates.get(i - 1))); - } - } - runResultMap.put("解析结果", resultMap); - return runResultMap; - } - -} diff --git a/center/src/main/java/com/tiji/center/util/WhitelistUtil.java b/center/src/main/java/com/tiji/center/util/WhitelistUtil.java deleted file mode 100755 index 72782e5..0000000 --- a/center/src/main/java/com/tiji/center/util/WhitelistUtil.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.tiji.center.util; - -import com.tiji.center.pojo.*; -import com.tiji.center.service.*; - -import java.util.*; - -/** - * @author 贰拾壹 - * @create 2019-11-27 17:39 - */ -public class WhitelistUtil { - - /** - * 根据ip、ip端口进行加白,安全检测白名单,提醒白名单 - */ - public static void markIpWhitelist(AssetipService assetipService, AssetportService assetportService, IpwhitelistService ipwhitelistService, IpportwhitelistService ipportwhitelistService) { - List assetipList = new ArrayList<>(); - List assetPortList = new ArrayList<>(); - List ipwhitelistList = ipwhitelistService.findAll(); - ipwhitelistList.forEach(ipwhitelist -> { - String ipwhitelistId = ipwhitelist.getId(); - String ip = ipwhitelist.getIp(); - Boolean ipCheckwhitelist = ipwhitelist.getCheckwhitelist(); - Boolean ipNotifywhitelist = ipwhitelist.getNotifywhitelist(); - Assetip assetip = assetipService.findByIpaddressv4AndPassivetimeIsNull(ip); - //当前ip在数据库中 - if (!Objects.isNull(assetip)) { - String assetIpId = assetip.getId(); - - List whitelistPortList = ipportwhitelistService.findAllPortByIpwhitelistid(ipwhitelistId); - //没有白名单端口,直接更新ip - if (whitelistPortList.isEmpty()) { - assetip.setCheckwhitelist(ipCheckwhitelist); - assetip.setAssetnotifywhitelist(ipNotifywhitelist); - assetipService.update(assetip); - } else { - //有白名单端口,ip白名单置空 - if (ipCheckwhitelist) { - assetip.setCheckwhitelist(false); - assetipList.add(assetip); - } - if (ipNotifywhitelist) { - assetip.setAssetnotifywhitelist(false); - assetipList.add(assetip); - } - - //根据白名单端口,遍历资产库端口,如果白名单端口列表包含数据库端口,则判断白名单 - //根据ip编号获取端口列表 - List assetportList = assetportService.findAllByAssetipidAndDowntimeIsNull(assetIpId); - if (!assetportList.isEmpty()) { -// for (Assetport assetport : assetportList) { - assetportList.forEach(assetport -> { - String dbPort = assetport.getPort(); - //当前端口在白名单whitelistPortList中,加白 - if (whitelistPortList.contains(dbPort)) { - Ipportwhitelist ipportwhitelist = ipportwhitelistService.findByIpwhitelistidAndPort(ipwhitelistId, dbPort); - Boolean portCheckwhitelist = ipportwhitelist.getCheckwhitelist(); - Boolean portNotifywhitelist = ipportwhitelist.getNotifywhitelist(); - assetport.setCheckwhitelist(portCheckwhitelist); - assetport.setAssetnotifywhitelist(portNotifywhitelist); - assetPortList.add(assetport); - } - }); - } - } - } - }); - //批量更新 - if (!assetPortList.isEmpty()) { - assetportService.batchAdd(assetPortList); - } - //批量更新 - if (!assetipList.isEmpty()) { - assetipService.batchAdd(assetipList); - } - } - - /*** - *根据项目、项目和端口进行加白,安全检测白名单,提醒白名单 - */ - public static void markProjectInfoWhitelist(ProjectinfoService projectinfoService, AssetipService assetipService, AssetportService assetportService, ProjectportwhitelistService projectportwhitelistService) { - List assetipList = new ArrayList<>(); - List projectinfoList = projectinfoService.findAll(); - List assetPortList = new ArrayList<>(); - projectinfoList.forEach(projectinfo -> { - String projectinfoid = projectinfo.getId(); - Boolean projectCheckwhitelist = projectinfo.getCheckwhitelist(); - Boolean projectNotifywhitelist = projectinfo.getNotifywhitelist(); - - List whitelistProjectPortList = projectportwhitelistService.findAllPortByProjectinfoid(projectinfoid); - //覆盖ip白名单,且没有白名单端口,直接更新当前项目的所有ip - if (projectinfo.getOverrideipwhitelist() && whitelistProjectPortList.isEmpty()) { - assetipService.updateByProjectinfoidAndCheckwhitelistAndAssetNotifywhitelist(projectinfoid, projectCheckwhitelist, projectNotifywhitelist); - } else { - //有白名单端口 - //查找当前项目的所有ip - Map searchMap = new HashMap<>(); - searchMap.put("projectinfoid", projectinfoid); - //根据项目id获取ip列表 - List searchAssetIpList = assetipService.findSearch(searchMap); - searchAssetIpList.forEach(assetip -> { - String assetIpId = assetip.getId(); - //根据ip编号获取端口列表 - List assetportList = assetportService.findAllByAssetipidAndDowntimeIsNull(assetIpId); - if (!assetportList.isEmpty()) { - assetportList.forEach(assetport -> { - //ip白名单置空 - if (projectCheckwhitelist) { - assetip.setCheckwhitelist(false); - assetipList.add(assetip); - } - if (projectNotifywhitelist) { - assetip.setAssetnotifywhitelist(false); - assetipList.add(assetip); - } - String port = assetport.getPort(); - //当前端口在白名单whitelistProjectPortList中,加白 - if (whitelistProjectPortList.contains(port)) { - Projectportwhitelist projectportwhitelist = projectportwhitelistService.findByProjectinfoidAndPort(projectinfoid, port); - Boolean portCheckwhitelist = projectportwhitelist.getCheckwhitelist(); - Boolean portNotifywhitelist = projectportwhitelist.getNotifywhitelist(); - assetport.setCheckwhitelist(portCheckwhitelist); - assetport.setAssetnotifywhitelist(portNotifywhitelist); - assetPortList.add(assetport); - } - }); - } - }); - } - }); - //批量更新 - if (!assetPortList.isEmpty()) { - assetportService.batchAdd(assetPortList); - } - //批量更新 - if (!assetipList.isEmpty()) { - assetipService.batchAdd(assetipList); - } - } - -} diff --git a/center/src/main/resources/logback-spring.xml b/center/src/main/resources/logback-spring.xml deleted file mode 100755 index bbd2ac2..0000000 --- a/center/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,162 +0,0 @@ - - - - - - - - - - - logback - - - - - - - - - - - - - - - - - debug - - - ${CONSOLE_LOG_PATTERN} - - UTF-8 - - - - - - - - - - ${log.path}/log_debug.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - - ${log.path}/debug/log-debug-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 180 - - - - debug - ACCEPT - DENY - - - - - - - ${log.path}/log_info.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - - ${log.path}/info/log-info-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 180 - - - - info - ACCEPT - DENY - - - - - - - ${log.path}/log_warn.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - ${log.path}/warn/log-warn-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 180 - - - - warn - ACCEPT - DENY - - - - - - - - ${log.path}/log_error.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - ${log.path}/error/log-error-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 180 - - - - ERROR - ACCEPT - DENY - - - - - - - - - - - - - - - - \ No newline at end of file