Example #1
0
def mimetype_filter_scan_request(scan_request_dict):
    try:
        with session_transaction() as session:
            available_probelist = probe_ctrl.get_list(session)
            scan_request = IrmaScanRequest(scan_request_dict)
            for filehash in scan_request.filehashes():
                filtered_probelist = []
                mimetype = scan_request.get_mimetype(filehash)
                mimetype_probelist = probe_ctrl.mimetype_probelist(mimetype,
                                                                   session)
                probe_list = scan_request.get_probelist(filehash)
                log.debug("filehash: %s probe_list: %s",
                          filehash, "-".join(probe_list))
                # first check probe_list for unknown probe
                for probe in probe_list:
                    # check if probe exists
                    if probe not in available_probelist:
                        log.warning("probe %s not available", probe)
                    if probe in mimetype_probelist:
                        # probe is asked and supported by mimetype
                        log.debug("filehash %s probe %s asked" +
                                  " and supported for %s append to request",
                                  filehash, probe, mimetype)
                        filtered_probelist.append(probe)
                # update probe list in scan request
                scan_request.set_probelist(filehash, filtered_probelist)
            return IrmaTaskReturn.success(scan_request.to_dict())
    except Exception as e:
        log.exception(e)
        return IrmaTaskReturn.error("Brain error")
Example #2
0
def scan_cancel(frontend_scanid):
    try:
        log.info("scanid %s", frontend_scanid)
        rmqvhost = config.get_frontend_rmqvhost()
        user_id = user_ctrl.get_userid(rmqvhost)
        scan_id = scan_ctrl.get_scan_id(frontend_scanid, user_id)
        (status, progress_details) = scan_ctrl.progress(scan_id)
        scan_ctrl.cancelling(scan_id)
        pending_jobs = scan_ctrl.get_pending_jobs(scan_id)
        cancel_details = None
        if len(pending_jobs) != 0:
            celery_probe.job_cancel(pending_jobs)
            cancel_details = {}
            cancel_details['total'] = progress_details['total']
            cancel_details['finished'] = progress_details['finished']
            cancel_details['cancelled'] = len(pending_jobs)
        scan_ctrl.cancelled(scan_id)
        scan_flush(frontend_scanid)
        res = {}
        res['status'] = status
        res['cancel_details'] = cancel_details
        return IrmaTaskReturn.success(res)
    except:
        log.info("exception", exc_info=True)
        return IrmaTaskReturn.error("cancel error on brain")
Example #3
0
def mimetype_filter_scan_request(scan_request_dict):
    try:
        with session_transaction() as session:
            available_probelist = probe_ctrl.get_list(session)
            scan_request = IrmaScanRequest(scan_request_dict)
            for filehash in scan_request.filehashes():
                filtered_probelist = []
                mimetype = scan_request.get_mimetype(filehash)
                mimetype_probelist = probe_ctrl.mimetype_probelist(mimetype,
                                                                   session)
                probe_list = scan_request.get_probelist(filehash)
                log.debug("filehash: %s probe_list: %s",
                          filehash, "-".join(probe_list))
                # first check probe_list for unknown probe
                for probe in probe_list:
                    # check if probe exists
                    if probe not in available_probelist:
                        msg = "Unknown probe {0}".format(probe)
                        log.error(msg)
                        return IrmaTaskReturn.error(msg)
                    if probe in mimetype_probelist:
                        # probe is asked but not supported by mimetype
                        log.debug("filehash %s probe %s asked but" +
                                  " not supported for %s",
                                  filehash, probe, mimetype)
                        filtered_probelist.append(probe)
                # update probe list in scan request
                scan_request.set_probelist(filehash, filtered_probelist)
            return IrmaTaskReturn.success(scan_request.to_dict())
    except Exception as e:
        log.exception(e)
        raise
Example #4
0
def probe_list():
    try:
        with session_transaction() as session:
            probe_list = probe_ctrl.get_list(session)
            return IrmaTaskReturn.success(probe_list)
    except Exception as e:
        log.exception(e)
        return IrmaTaskReturn.error("Error getting probelist")
Example #5
0
def probe_list():
    try:
        with session_transaction() as session:
            probe_list = probe_ctrl.get_list(session)
            return IrmaTaskReturn.success(probe_list)
    except Exception as e:
        log.exception(e)
        return IrmaTaskReturn.error("Error getting probelist")
Example #6
0
def scan_cancel(frontend_scan_id):
    try:
        with session_transaction() as session:
            user = User.get_by_rmqvhost(session)
            scan = Scan.get_scan(frontend_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")
Example #7
0
def probe_list():
    try:
        probe_list = celery_probe.get_probelist()
        if len(probe_list) > 0:
            return IrmaTaskReturn.success(probe_list)
        else:
            return IrmaTaskReturn.error("no probe available")
    except:
        log.info("exception", exc_info=True)
        raise
Example #8
0
def scan_cancel(frontend_scan_id):
    try:
        with session_transaction() as session:
            user = User.get_by_rmqvhost(session)
            scan = Scan.get_scan(frontend_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")
Example #9
0
def scan_progress(frontend_scanid):
    try:
        log.info("scanid %s", frontend_scanid)
        rmqvhost = config.get_frontend_rmqvhost()
        user_id = user_ctrl.get_userid(rmqvhost)
        scan_id = scan_ctrl.get_scan_id(frontend_scanid, user_id)
        (status, progress_details) = scan_ctrl.progress(scan_id)
        res = {}
        res['status'] = status
        res['progress_details'] = progress_details
        return IrmaTaskReturn.success(res)
    except:
        log.info("exception", exc_info=True)
        return IrmaTaskReturn.error("progress error on brain")
Example #10
0
def scan(frontend_scanid, scan_request):
    try:
        log.info("%s", frontend_scanid)
        # TODO user should be identified by RMQ vhost
        # read vhost from config as workaround
        rmqvhost = config.get_frontend_rmqvhost()
        user_id = user_ctrl.get_userid(rmqvhost)
        ftpuser = user_ctrl.get_ftpuser(user_id)
        # create an initial entry to track future errors
        # tell frontend that frontend_scanid is now known to brain
        # progress available
        scan_id = scan_ctrl.new(frontend_scanid, user_id, len(scan_request))
        # send a scan launched event to frontend
        (remaining, quota) = user_ctrl.get_quota(user_id)
        if remaining is not None:
            log.info("%s quota remaining {0}/{1}",
                     frontend_scanid,
                     remaining,
                     quota)
        else:
            log.info("%s unlimited quota",
                     frontend_scanid)
        if remaining <= 0:
            scan_ctrl.error(scan_id, IrmaScanStatus.error)

        available_probelist = celery_probe.get_probelist()
        for (filename, probe_list) in scan_request.items():
            if probe_list is None:
                scan_ctrl.error(scan_id, IrmaScanStatus.error_probe_missing)
                log.info("%s Empty probe list", frontend_scanid)
                return IrmaTaskReturn.error("empty probe list on brain")
            # first check probe_list
            for p in probe_list:
                # check if probe exists
                if p not in available_probelist:
                    scan_ctrl.error(scan_id,
                                    IrmaScanStatus.error_probe_missing)
                    msg = "Unknown probe {0}".format(p)
                    log.info("%s Unknown probe %s",
                             frontend_scanid,
                             p)
                    return IrmaTaskReturn.error(msg)

            # Now, create one subtask per file to
            # scan per probe according to quota
            for probe in probe_list:
                if remaining is not None:
                    if remaining <= 0:
                        break
                    else:
                        remaining -= 1
                task_id = UUID.generate()
                job_id = job_ctrl.new(scan_id, filename, probe, task_id)
                celery_probe.job_launch(ftpuser,
                                        frontend_scanid,
                                        filename,
                                        probe,
                                        job_id,
                                        task_id)
        scan_ctrl.launched(scan_id)
        celery_frontend.scan_launched(frontend_scanid)
        log.info(
            "%s %d files receives / %d active probe /" +
            " %d probe used / %d jobs launched",
            frontend_scanid,
            len(scan_request),
            len(available_probelist),
            len(probe_list),
            scan_ctrl.get_nbjobs(scan_id))
    except:
        log.info("exception", exc_info=True)
        raise