Beispiel #1
0
def mimetype_filter_scan_request(scan_request_dict):
    try:
        with session_transaction() as session:
            scan_request = IrmaScanRequest(scan_request_dict)
            for file in scan_request.files():
                filtered_probelist = []
                mimetype = scan_request.get_mimetype(file)
                mimetype_probelist = probe_ctrl.mimetype_probelist(mimetype,
                                                                   session)
                probe_list = scan_request.get_probelist(file)
                log.debug("file: %s probe_list: %s",
                          file, "-".join(probe_list))
                # first check probe_list for unknown probe
                for probe in probe_list:
                    # check if probe exists
                    if probe not in probe_ctrl.available_probes:
                        log.warning("probe %s not available", probe)
                    if probe in mimetype_probelist:
                        # probe is asked and supported by mimetype
                        log.debug("file %s probe %s asked" +
                                  " and supported for %s append to request",
                                  file, probe, mimetype)
                        filtered_probelist.append(probe)
                # update probe list in scan request
                scan_request.set_probelist(file, filtered_probelist)
            return IrmaTaskReturn.success(scan_request.to_dict())
    except Exception as e:
        log.exception(e)
        return IrmaTaskReturn.error("Brain error")
Beispiel #2
0
def mimetype_filter_scan_request(scan_request_dict):
    try:
        with session_transaction() as session:
            scan_request = IrmaScanRequest(scan_request_dict)
            for file in scan_request.files():
                filtered_probelist = []
                mimetype = scan_request.get_mimetype(file)
                mimetype_probelist = probe_ctrl.mimetype_probelist(
                    mimetype, session)
                probe_list = scan_request.get_probelist(file)
                log.debug("file: %s probe_list: %s", file,
                          "-".join(probe_list))
                # first check probe_list for unknown probe
                for probe in probe_list:
                    # check if probe exists
                    if probe not in probe_ctrl.available_probes:
                        log.warning("probe %s not available", probe)
                    if probe in mimetype_probelist:
                        # probe is asked and supported by mimetype
                        log.debug(
                            "file %s probe %s asked" +
                            " and supported for %s append to request", file,
                            probe, mimetype)
                        filtered_probelist.append(probe)
                # update probe list in scan request
                scan_request.set_probelist(file, filtered_probelist)
            return IrmaTaskReturn.success(scan_request.to_dict())
    except Exception as e:
        log.exception(type(e).__name__ + " : " + str(e))
        return IrmaTaskReturn.error("Brain error")
Beispiel #3
0
def scan_cancel(scan_id):
    try:
        log.info("scan %s: cancel", scan_id)
        with session_transaction() as session:
            user = User.get_by_rmqvhost(session)
            scan = Scan.get_scan(scan_id, user.id, session)
            res = scan_ctrl.cancel(scan, session)
            return IrmaTaskReturn.success(res)
    except Exception as e:
        log.exception(e)
        return IrmaTaskReturn.error("cancel error on brain")
Beispiel #4
0
def scan_cancel(scan_id):
    try:
        log.info("scan %s: cancel", scan_id)
        with session_transaction() as session:
            user = User.get_by_rmqvhost(session)
            scan = Scan.get_scan(scan_id, user.id, session)
            res = scan_ctrl.cancel(scan, session)
            return IrmaTaskReturn.success(res)
    except Exception as e:
        log.exception(type(e).__name__ + " : " + str(e))
        return IrmaTaskReturn.error("cancel error on brain")
Beispiel #5
0
 def test_irma_taskreturn_error(self):
     ret = IrmaTaskReturn.error("error")
     self.assertEqual(ret[0], IrmaReturnCode.error)
     self.assertEqual(ret[1], "error")
     self.assertEqual(type(ret), tuple)
     self.assertEqual(type(ret[0]), int)
     self.assertEqual(type(ret[1]), str)
Beispiel #6
0
 def test_irma_taskreturn_warning(self):
     ret = IrmaTaskReturn.warning("warning")
     self.assertEqual(ret[0], IrmaReturnCode.warning)
     self.assertEqual(ret[1], "warning")
     self.assertEqual(type(ret), tuple)
     self.assertEqual(type(ret[0]), int)
     self.assertEqual(type(ret[1]), str)
Beispiel #7
0
 def test_irma_taskreturn_success(self):
     ret = IrmaTaskReturn.success("success")
     self.assertEqual(ret[0], IrmaReturnCode.success)
     self.assertEqual(ret[1], "success")
     self.assertEqual(type(ret), tuple)
     self.assertEqual(type(ret[0]), int)
     self.assertEqual(type(ret[1]), str)
Beispiel #8
0
def probe_list_refresh():
    try:
        with session_transaction() as session:
            probe_ctrl.refresh_probelist(session)
    except Exception as e:
        log.exception(e)
        return IrmaTaskReturn.error("Error getting probelist")
Beispiel #9
0
def probe_list_refresh():
    try:
        with session_transaction() as session:
            probe_ctrl.refresh_probelist(session)
    except Exception as e:
        log.exception(type(e).__name__ + " : " + str(e))
        return IrmaTaskReturn.error("Error getting probelist")
Beispiel #10
0
def probe_list():
    # convert to list because ListProxy is not serializable
    probes = list(probe_ctrl.available_probes)
    return IrmaTaskReturn.success(probes)
Beispiel #11
0
def probe_list():
    # convert to list because ListProxy is not serializable
    probes = list(probe_ctrl.available_probes)
    return IrmaTaskReturn.success(probes)