|
@@ -5,19 +5,23 @@ 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.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.http.server.reactive.ServerHttpResponse;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.io.*;
|
|
|
import java.sql.Timestamp;
|
|
import java.sql.Timestamp;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
@@ -34,6 +38,8 @@ public class HandleReportController {
|
|
|
private String REPORT_JSON_UPLOAD_PATH;
|
|
private String REPORT_JSON_UPLOAD_PATH;
|
|
|
@Value("${order.autoReport.upload.path}")
|
|
@Value("${order.autoReport.upload.path}")
|
|
|
private String REPORT_UPLOAD_PATH;
|
|
private String REPORT_UPLOAD_PATH;
|
|
|
|
|
+ @Value("${host.ip}")
|
|
|
|
|
+ private String HOST_IP;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private AutoReportProductService autoReportProductService;
|
|
private AutoReportProductService autoReportProductService;
|
|
@@ -41,7 +47,7 @@ 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)
|
|
@RequestMapping(value = "/generate/report/{orderId}/{ownerId}", method = RequestMethod.GET)
|
|
|
- public void generateReport(@PathVariable(value = "orderId") Long orderId, @PathVariable(value = "ownerId") Long ownerId){
|
|
|
|
|
|
|
+ public String generateReport(@PathVariable(value = "orderId") Long orderId, @PathVariable(value = "ownerId") Long ownerId){
|
|
|
List<String> menus = new ArrayList<>();
|
|
List<String> menus = new ArrayList<>();
|
|
|
menus.add("APK扫描");
|
|
menus.add("APK扫描");
|
|
|
ProjectInfoVO projectInfoVO = new ProjectInfoVO();
|
|
ProjectInfoVO projectInfoVO = new ProjectInfoVO();
|
|
@@ -59,6 +65,7 @@ public class HandleReportController {
|
|
|
vulReportDataVO.setVulStatistics(vulStatisticsVO);
|
|
vulReportDataVO.setVulStatistics(vulStatisticsVO);
|
|
|
System.out.println(vulReportDataVO.toString());
|
|
System.out.println(vulReportDataVO.toString());
|
|
|
handleReport(orderId, ownerId, vulReportDataVO);
|
|
handleReport(orderId, ownerId, vulReportDataVO);
|
|
|
|
|
+ return "http://"+HOST_IP+"/reportFile/"+ownerId+"/"+orderId+"/vulReport/dist/vulResults.html";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -75,15 +82,52 @@ public class HandleReportController {
|
|
|
|
|
|
|
|
private void reportTransferToPath(Long orderId, Long ownerId, String path) {
|
|
private void reportTransferToPath(Long orderId, Long ownerId, String path) {
|
|
|
String autoReportPath = REPORT_UPLOAD_PATH + ownerId + "/" + orderId + "/vulReport";
|
|
String autoReportPath = REPORT_UPLOAD_PATH + ownerId + "/" + orderId + "/vulReport";
|
|
|
|
|
+ String downloadPath = autoReportPath+"/report.zip";
|
|
|
File uploadFile = new File(autoReportPath);
|
|
File uploadFile = new File(autoReportPath);
|
|
|
|
|
+ File downloadFile = new File(downloadPath);
|
|
|
boolean sign = uploadFile.mkdirs();
|
|
boolean sign = uploadFile.mkdirs();
|
|
|
log.info("------------mkdirs------------", sign);
|
|
log.info("------------mkdirs------------", sign);
|
|
|
try {
|
|
try {
|
|
|
log.info("开始拷贝文件");
|
|
log.info("开始拷贝文件");
|
|
|
FileUtils.copyDirectoryToDirectory(new File(path + "dist"), new File(autoReportPath));
|
|
FileUtils.copyDirectoryToDirectory(new File(path + "dist"), new File(autoReportPath));
|
|
|
|
|
+ net.lingala.zip4j.core.ZipFile zipFile = new net.lingala.zip4j.core.ZipFile(downloadFile);
|
|
|
|
|
+ ZipParameters parameters = new ZipParameters();
|
|
|
|
|
+ parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
|
|
|
|
|
+ parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
|
|
|
|
|
+ zipFile.addFolder(new File(autoReportPath+ "/dist"),parameters);
|
|
|
log.info("----------------拷贝结束-------------------");
|
|
log.info("----------------拷贝结束-------------------");
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
|
log.info("----------copy error{}---------", e);
|
|
log.info("----------copy error{}---------", e);
|
|
|
|
|
+ }catch (ZipException e){
|
|
|
|
|
+ log.info("----------copy error{}---------", e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// @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();
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
}
|
|
}
|