|
@@ -1,33 +1,24 @@
|
|
package cn.iselab.mooctest.site.web.ctrl;
|
|
package cn.iselab.mooctest.site.web.ctrl;
|
|
|
|
|
|
import cn.iselab.mooctest.site.domainObject.ReportTask;
|
|
import cn.iselab.mooctest.site.domainObject.ReportTask;
|
|
|
|
+import cn.iselab.mooctest.site.domainObject.ReportTaskStatus;
|
|
import cn.iselab.mooctest.site.service.AutoReportProductService;
|
|
import cn.iselab.mooctest.site.service.AutoReportProductService;
|
|
import cn.iselab.mooctest.site.web.data.vulData.ProjectInfoVO;
|
|
import cn.iselab.mooctest.site.web.data.vulData.ProjectInfoVO;
|
|
import cn.iselab.mooctest.site.web.data.vulData.VulReportDataVO;
|
|
import cn.iselab.mooctest.site.web.data.vulData.VulReportDataVO;
|
|
import cn.iselab.mooctest.site.web.data.vulData.VulStatisticsVO;
|
|
import cn.iselab.mooctest.site.web.data.vulData.VulStatisticsVO;
|
|
import cn.iselab.mooctest.site.web.data.vulData.VulnerabilityVo;
|
|
import cn.iselab.mooctest.site.web.data.vulData.VulnerabilityVo;
|
|
-import net.lingala.zip4j.exception.ZipException;
|
|
|
|
-import net.lingala.zip4j.model.ZipParameters;
|
|
|
|
-import net.lingala.zip4j.util.Zip4jConstants;
|
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
|
-import org.springframework.scheduling.annotation.AsyncResult;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
-import com.google.gson.Gson;
|
|
|
|
-import java.io.*;
|
|
|
|
import java.sql.Timestamp;
|
|
import java.sql.Timestamp;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
-import java.util.concurrent.Future;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author guochao
|
|
* @author guochao
|
|
* @date 2019-11-14 22:22
|
|
* @date 2019-11-14 22:22
|
|
*/
|
|
*/
|
|
-
|
|
|
|
@RestController
|
|
@RestController
|
|
public class HandleReportController {
|
|
public class HandleReportController {
|
|
|
|
|
|
@@ -43,8 +34,50 @@ public class HandleReportController {
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(Process.class.getName());
|
|
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){
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取报告任务状态
|
|
|
|
+ * @param orderId
|
|
|
|
+ * @param ownerId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @ResponseBody
|
|
|
|
+ @RequestMapping(value = "/api/report/status/order/{orderId}/owner/{ownerId}", method = RequestMethod.GET)
|
|
|
|
+ public Map getReportTaskStatus(@PathVariable(value = "orderId") Long orderId,
|
|
|
|
+ @PathVariable(value = "ownerId") Long ownerId) {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ ReportTask reportTask = autoReportProductService.getReportTask(orderId, ownerId);
|
|
|
|
+ if(reportTask == null) {
|
|
|
|
+ // 报告任务不存在
|
|
|
|
+ map.put("status", ReportTaskStatus.INEXISTENCE);
|
|
|
|
+ map.put("describe", "报告任务不存在");
|
|
|
|
+ }else{
|
|
|
|
+ // 报告任务存在
|
|
|
|
+ if(reportTask.getStatus() == ReportTaskStatus.GENERATING){
|
|
|
|
+ // 报告任务正在执行
|
|
|
|
+ map.put("status", ReportTaskStatus.GENERATING);
|
|
|
|
+ map.put("describe", "报告生成中");
|
|
|
|
+ }else{
|
|
|
|
+ // 报告任务执行结束,返回任务状态和url
|
|
|
|
+ map.put("status", ReportTaskStatus.COMPLETED);
|
|
|
|
+ map.put("describe", "报告生成结束");
|
|
|
|
+ map.put("url",reportTask.getTaskUrl());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成报告
|
|
|
|
+ * @param orderId 任务ID
|
|
|
|
+ * @param ownerId 用户ID
|
|
|
|
+ * @param vulReportDataVO
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @ResponseBody
|
|
|
|
+ @RequestMapping(value = "/api/generate/report/order/{orderId}/owner/{ownerId}", method = RequestMethod.POST)
|
|
|
|
+ public Map handleReport(@PathVariable(value = "orderId") Long orderId,
|
|
|
|
+ @PathVariable(value = "ownerId") Long ownerId, @RequestBody VulReportDataVO vulReportDataVO) {
|
|
// List<String> menus = new ArrayList<>();
|
|
// List<String> menus = new ArrayList<>();
|
|
// menus.add("APK扫描");
|
|
// menus.add("APK扫描");
|
|
// ProjectInfoVO projectInfoVO = new ProjectInfoVO();
|
|
// ProjectInfoVO projectInfoVO = new ProjectInfoVO();
|
|
@@ -60,100 +93,12 @@ public class HandleReportController {
|
|
// vulReportDataVO.setProjectInfo(projectInfoVO);
|
|
// vulReportDataVO.setProjectInfo(projectInfoVO);
|
|
// vulReportDataVO.setVulnerability(vulnerabilityVos);
|
|
// vulReportDataVO.setVulnerability(vulnerabilityVos);
|
|
// vulReportDataVO.setVulStatistics(vulStatisticsVO);
|
|
// 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) {
|
|
|
|
-// 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
|
|
|
|
- */
|
|
|
|
- @ResponseBody
|
|
|
|
- @RequestMapping(value = "/generate/report/order/{orderId}/owner/{ownerId}", method = RequestMethod.POST)
|
|
|
|
- public Map handleReport(@PathVariable(value = "orderId") Long orderId,
|
|
|
|
- @PathVariable(value = "ownerId") Long ownerId) throws Exception {
|
|
|
|
- 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);
|
|
|
|
|
|
|
|
|
|
+ autoReportProductService.generateReport(orderId, ownerId, vulReportDataVO);
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
-
|
|
|
|
- ReportTask reportTask = autoReportProductService.getReportTask(orderId, ownerId);
|
|
|
|
- if(reportTask == null){
|
|
|
|
- // 没有当前报告任务,执行报告生成任务
|
|
|
|
- autoReportProductService.generateReport(orderId, ownerId, vulReportDataVO);
|
|
|
|
- map.put("status", -1);
|
|
|
|
- map.put("describe", "异步生成报告");
|
|
|
|
- }else if(reportTask.getStatus() == 0){
|
|
|
|
- // 报告任务正在执行
|
|
|
|
- map.put("status", 0);
|
|
|
|
- map.put("describe", "报告生成中");
|
|
|
|
- }else{
|
|
|
|
- // 报告任务执行结束,返回任务状态和url
|
|
|
|
- map.put("status", 1);
|
|
|
|
- map.put("describe", "报告生成结束");
|
|
|
|
- map.put("url",reportTask.getTaskUrl());
|
|
|
|
- }
|
|
|
|
|
|
+ map.put("status", ReportTaskStatus.GENERATING);
|
|
|
|
+ map.put("describe", "报告生成中");
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// @RequestMapping(value = "/download/report/{orderId}/{ownerId}", method = RequestMethod.GET)
|
|
|
|
-// public void downloadFile(@PathVariable(value = "orderId") Long orderId, @PathVariable(value = "ownerId") Long ownerId, HttpServletResponse response){
|
|
|
|
-//
|
|
|
|
-// String filePath = REPORT_UPLOAD_PATH + ownerId + "/" + orderId + "/vulReport/";
|
|
|
|
-// String fileName = "report.zip";
|
|
|
|
-// response.setCharacterEncoding("utf-8");
|
|
|
|
-// try {
|
|
|
|
-// File file=new File(filePath,fileName);
|
|
|
|
-// // 以流的形式下载文件。
|
|
|
|
-// BufferedInputStream fis = new BufferedInputStream(new FileInputStream(file.getPath()));
|
|
|
|
-// byte[] buffer = new byte[fis.available()];
|
|
|
|
-// fis.read(buffer);
|
|
|
|
-// fis.close();
|
|
|
|
-// // 清空response
|
|
|
|
-// response.reset();
|
|
|
|
-// OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
|
|
|
|
-// response.setContentType("application/octet-stream");
|
|
|
|
-// response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
|
|
|
-// toClient.write(buffer);
|
|
|
|
-// toClient.flush();
|
|
|
|
-// toClient.close();
|
|
|
|
-// }
|
|
|
|
-// catch (IOException ex) {
|
|
|
|
-// ex.printStackTrace();
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
}
|
|
}
|