use of com.xebia.vulnmanager.models.openvas.objects.OpenvasReport in project vulnmanager by xebia-research.
the class OpenvasController method getResult.
/**
* Get a certain result from a report.
*
* @param id The index id in the OpenvasReport.
* @return A response with correct http header
* @throws IOException Exception when example log isn't found or couldn't be opened
*/
@RequestMapping(value = "/result/{id}", method = RequestMethod.GET)
@ResponseBody
ResponseEntity<?> getResult(@PathVariable("id") int id, @ModelAttribute("isAuthenticated") boolean isAuthenticated) throws IOException {
if (!isAuthenticated) {
return new ResponseEntity(new ErrorMsg("Auth not correct!"), HttpStatus.BAD_REQUEST);
}
Object parsedDocument = ReportUtil.parseDocument(ReportUtil.getDocumentFromFile(new File("example_logs/openvas.xml")));
OpenvasReport report = getOpenvasReportFromObject(parsedDocument);
if (report == null) {
return new ResponseEntity<>(new ErrorMsg("The file requested is not of the right type"), HttpStatus.BAD_REQUEST);
} else if (id >= report.getResults().size() || id < 0) {
return new ResponseEntity<>(new ErrorMsg("Result not found"), HttpStatus.NOT_FOUND);
} else {
return new ResponseEntity<>(report.getResults().get(id), HttpStatus.OK);
}
}
use of com.xebia.vulnmanager.models.openvas.objects.OpenvasReport in project vulnmanager by xebia-research.
the class OpenvasController method getReport.
/**
* Get a parsed test report of openvas
*
* @return A response with correct http header
* @throws IOException An exception if the example log isn't found
*/
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody
ResponseEntity<?> getReport(@ModelAttribute("isAuthenticated") boolean isAuthenticated) throws IOException {
if (!isAuthenticated) {
return new ResponseEntity(new ErrorMsg("Auth not correct!"), HttpStatus.BAD_REQUEST);
}
Object parsedDocument = ReportUtil.parseDocument(ReportUtil.getDocumentFromFile(new File("example_logs/openvas.xml")));
OpenvasReport report = getOpenvasReportFromObject(parsedDocument);
if (report == null) {
return new ResponseEntity(new ErrorMsg("The file requested is not of the right type"), HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<>(report, HttpStatus.OK);
}
use of com.xebia.vulnmanager.models.openvas.objects.OpenvasReport in project vulnmanager by xebia-research.
the class OpenvasParser method getOpenvasReport.
/**
* Parse a openvas xml report
*
* @param openvasDoc Document of openvas report
*/
public OpenvasReport getOpenvasReport(Document openvasDoc) {
OpenvasReport retReport = new OpenvasReport();
Element mainElement = openvasDoc.getDocumentElement();
retReport.setTimeDone(mainElement.getElementsByTagName("creation_time").item(0).getTextContent());
retReport.setId(mainElement.getAttribute("id"));
NodeList reportList = mainElement.getElementsByTagName("report");
Element reports = (Element) reportList.item(0);
NodeList resultList = reports.getElementsByTagName("results").item(0).getChildNodes();
for (int i = 0; i < resultList.getLength(); i++) {
if (resultList.item(i).getNodeType() == Node.ELEMENT_NODE) {
Element result = (Element) resultList.item(i);
retReport = handleResult(retReport, result);
}
}
// System.out.println(retReport.toString());
return retReport;
}
Aggregations