|
@@ -14,11 +14,8 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.server.reactive.ServerHttpResponse;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import com.google.gson.Gson;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
@@ -46,43 +43,63 @@ public class HandleReportController {
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(Process.class.getName());
|
|
|
|
|
|
- @RequestMapping(value = "/generate/report/{orderId}/{ownerId}", method = RequestMethod.GET)
|
|
|
- public String generateReport(@PathVariable(value = "orderId") Long orderId, @PathVariable(value = "ownerId") Long ownerId){
|
|
|
- List<String> menus = new ArrayList<>();
|
|
|
- menus.add("APK扫描");
|
|
|
- ProjectInfoVO projectInfoVO = new ProjectInfoVO();
|
|
|
- projectInfoVO.setCostTime("2019/11/15");
|
|
|
- projectInfoVO.setProjectName("途牛APP");
|
|
|
- projectInfoVO.setStartTime(new Timestamp(new Date().getTime()));
|
|
|
- projectInfoVO.setUserName("郭超");
|
|
|
- List<VulnerabilityVo> vulnerabilityVos = new ArrayList<>();
|
|
|
- VulStatisticsVO vulStatisticsVO = new VulStatisticsVO();
|
|
|
-
|
|
|
- VulReportDataVO vulReportDataVO = new VulReportDataVO();
|
|
|
- vulReportDataVO.setMenus(menus);
|
|
|
- vulReportDataVO.setProjectInfo(projectInfoVO);
|
|
|
- vulReportDataVO.setVulnerability(vulnerabilityVos);
|
|
|
- vulReportDataVO.setVulStatistics(vulStatisticsVO);
|
|
|
- System.out.println(vulReportDataVO.toString());
|
|
|
- handleReport(orderId, ownerId, vulReportDataVO);
|
|
|
- return "http://"+HOST_IP+"/reportFile/"+ownerId+"/"+orderId+"/vulReport/dist/vulResults.html";
|
|
|
- }
|
|
|
+// @RequestMapping(value = "/generate/report/{orderId}/{ownerId}", method = RequestMethod.GET)
|
|
|
+// public String generateReport(@PathVariable(value = "orderId") Long orderId, @PathVariable(value = "ownerId") Long ownerId){
|
|
|
+// List<String> menus = new ArrayList<>();
|
|
|
+// menus.add("APK扫描");
|
|
|
+// ProjectInfoVO projectInfoVO = new ProjectInfoVO();
|
|
|
+// projectInfoVO.setCostTime("2019/11/15");
|
|
|
+// projectInfoVO.setProjectName("途牛APP");
|
|
|
+// projectInfoVO.setStartTime(new Timestamp(new Date().getTime()));
|
|
|
+// projectInfoVO.setUserName("郭超");
|
|
|
+// List<VulnerabilityVo> vulnerabilityVos = new ArrayList<>();
|
|
|
+// VulStatisticsVO vulStatisticsVO = new VulStatisticsVO();
|
|
|
+//
|
|
|
+// VulReportDataVO vulReportDataVO = new VulReportDataVO();
|
|
|
+// vulReportDataVO.setMenus(menus);
|
|
|
+// vulReportDataVO.setProjectInfo(projectInfoVO);
|
|
|
+// vulReportDataVO.setVulnerability(vulnerabilityVos);
|
|
|
+// vulReportDataVO.setVulStatistics(vulStatisticsVO);
|
|
|
+// System.out.println(vulReportDataVO.toString());
|
|
|
+// handleReport(orderId, ownerId, vulReportDataVO);
|
|
|
+//
|
|
|
+// }
|
|
|
|
|
|
|
|
|
// @RequiresPermissions("task:create")
|
|
|
// @RequestMapping(value = "generate/report", method = RequestMethod.POST)
|
|
|
- private void handleReport(Long orderId, Long ownerId, VulReportDataVO reportData) {
|
|
|
+// private void handleReport(Long orderId, Long ownerId, VulReportDataVO reportData) {
|
|
|
+// String builderPath = autoReportProductService.copyReportBuilderToPath(orderId, "static-scan-report");
|
|
|
+// autoReportProductService.writeDataToJsonFile(new Gson().toJson(reportData), builderPath + REPORT_JSON_UPLOAD_PATH);
|
|
|
+// boolean bale = autoReportProductService.runBuilderToProductReport("npm run build", builderPath + "/static-scan-report/");
|
|
|
+// if (bale) {
|
|
|
+// reportTransferToPath(orderId, ownerId, builderPath + "/static-scan-report/");
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param orderId 任务ID
|
|
|
+ * @param ownerId 用户ID
|
|
|
+ * @param reportData
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/generate/report/order/{orderId}/owner/{ownerId}", method = RequestMethod.POST)
|
|
|
+ private String handleReport(@PathVariable(value = "orderId") Long orderId,
|
|
|
+ @PathVariable(value = "ownerId") Long ownerId,
|
|
|
+ @RequestBody VulReportDataVO reportData) {
|
|
|
String builderPath = autoReportProductService.copyReportBuilderToPath(orderId, "static-scan-report");
|
|
|
autoReportProductService.writeDataToJsonFile(new Gson().toJson(reportData), builderPath + REPORT_JSON_UPLOAD_PATH);
|
|
|
boolean bale = autoReportProductService.runBuilderToProductReport("npm run build", builderPath + "/static-scan-report/");
|
|
|
if (bale) {
|
|
|
reportTransferToPath(orderId, ownerId, builderPath + "/static-scan-report/");
|
|
|
}
|
|
|
+ return "http://" + HOST_IP + "/reportFile/" + ownerId + "/" + orderId + "/vulReport/dist/vulResults.html";
|
|
|
}
|
|
|
|
|
|
private void reportTransferToPath(Long orderId, Long ownerId, String path) {
|
|
|
String autoReportPath = REPORT_UPLOAD_PATH + ownerId + "/" + orderId + "/vulReport";
|
|
|
- String downloadPath = autoReportPath+"/report.zip";
|
|
|
+ String downloadPath = autoReportPath + "/report.zip";
|
|
|
File uploadFile = new File(autoReportPath);
|
|
|
File downloadFile = new File(downloadPath);
|
|
|
boolean sign = uploadFile.mkdirs();
|
|
@@ -94,11 +111,11 @@ public class HandleReportController {
|
|
|
ZipParameters parameters = new ZipParameters();
|
|
|
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
|
|
|
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
|
|
|
- zipFile.addFolder(new File(autoReportPath+ "/dist"),parameters);
|
|
|
+ zipFile.addFolder(new File(autoReportPath + "/dist"), parameters);
|
|
|
log.info("----------------拷贝结束-------------------");
|
|
|
} catch (IOException e) {
|
|
|
log.info("----------copy error{}---------", e);
|
|
|
- }catch (ZipException e){
|
|
|
+ } catch (ZipException e) {
|
|
|
log.info("----------copy error{}---------", e);
|
|
|
}
|
|
|
}
|