Exemplo n.º 1
0
def submit_archive(group):
    """
    Allows for authenticated users to submit archives
    """
    user = '******' % api_request_user()
    try:
        if group not in groups():
            raise ValueError('Invalid group specified')

        if 'cves' not in request.args:
            raise ValueError('CVE(s) required')

        cves = [cve.strip() for cve in request.args['cves'].split(',')]

        meta = {}
        for field in current_app.config['SUBMISSION_GROUPS'].get(group):
            if field in request.args:
                value = request.args.get(field)
                if len(value) > 0:
                    meta[field] = value

        files = upload(group, request.files.get('archive', None), meta)

        for (ondisk, filename, suffix) in files:
            submit(user, ondisk, group, filename, suffix, cves, meta)

        return success()
    except ValueError as ve:
        current_app.logger.info('Invalid submission by %s: %s' %
                                (user, ve.message))
        return error(ve.message)
    except Exception as e:
        current_app.logger.info(e.message)
        return error()
Exemplo n.º 2
0
def submit_archive(group):
    """
    Allows for authenticated users to submit archives
    """
    user = '******' % api_request_user()
    try:
        if group not in groups():
            raise ValueError('Invalid group specified')

        if 'cves' not in request.args:
            raise ValueError('CVE(s) required')

        cves = [cve.strip() for cve in request.args['cves'].split(',')]

        coordinates = CoordinateDict({
            coord: request.args.get(coord).strip()
            for coord in SUBMISSION_GROUPS.get(group)
            if coord in request.args
        })
        files = upload(group, request.files.get('archive', None), coordinates)

        for (ondisk, filename, suffix) in files:
            submit(
                user, ondisk, group, filename, suffix, cves,
                coordinates=coordinates
            )

        return success()
    except ValueError as ve:
        current_app.logger.info('Invalid submission by %s: %s' %
                                (user, ve.message))
        return error(ve.message)
    except Exception as e:
        current_app.logger.info(e.message)
        return error()
Exemplo n.º 3
0
def submit_hash(group):
    """
    Allows for authenticated users to submit hashes via json.
    """
    user = '******' % api_request_user()
    try:
        if group not in groups():
            raise ValueError('Invalid group specified')
        json_data = request.get_json()
        if 'cves' not in json_data:
            raise ValueError('No CVE provided')
        entry = Hash()
        entry.mongify(json_data)
        entry.submitter = user
        submit(
            user, 'json-api-hash', group, suffix='Hash', entry=entry,
            approval='PENDING_APPROVAL')
        return success()
    except ValueError as ve:
        return error(ve.message)
    except Exception as e:
        current_app.logger.info('Invalid submission by %s' % (user))
        current_app.logger.debug(e)
        return error()