Search in sources :

Example 1 with OpenvasReport

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);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ErrorMsg(com.xebia.vulnmanager.models.net.ErrorMsg) OpenvasReport(com.xebia.vulnmanager.models.openvas.objects.OpenvasReport) File(java.io.File)

Example 2 with OpenvasReport

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ErrorMsg(com.xebia.vulnmanager.models.net.ErrorMsg) OpenvasReport(com.xebia.vulnmanager.models.openvas.objects.OpenvasReport) File(java.io.File)

Example 3 with OpenvasReport

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;
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) OpenvasReport(com.xebia.vulnmanager.models.openvas.objects.OpenvasReport)

Aggregations

OpenvasReport (com.xebia.vulnmanager.models.openvas.objects.OpenvasReport)3 ErrorMsg (com.xebia.vulnmanager.models.net.ErrorMsg)2 File (java.io.File)2 ResponseEntity (org.springframework.http.ResponseEntity)2 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1