Example #1
0
def get_reports_history():
    history = []
    user_email = request.args.get('user')
    if user_email is not None:
        user = users.find_one({'email': user_email})
        if user is None:
            return jsonify(success=False, reason='no-such-user')
        for s in scans.find({'configuration.target': {'$in': _find_sites_for_user(user_email)}}).sort("created", -1).limit(100):
            history.append(summarize_scan(sanitize_scan(s)))
    else:
        for s in scans.find({}).sort("created", -1).limit(100):
            history.append(summarize_scan(sanitize_scan(s)))
    return jsonify(success=True, report=history)
Example #2
0
def get_reports_history():
    history = []
    user_email = request.args.get('user')
    scans = []
    if user_email is not None:
        user = User.get_user(user_email)
        if user is None:
            return jsonify(success=False, reason='no-such-user')

        
        # Get Sites
        for site in user.sites():
            for scan in Site.get_site_by_url(site).scans:
                scans.append(scan)

        scans.sort(key=lambda x : x.created, reverse = True)
        # Get Scans for Sites
    else:
        for site in Site.query.all():
            for scan in site.scans:
                scans.append(scan)

    for s in scans[:100]:
            history.append(summarize_scan(s))
    return jsonify(success=True, report=history)
Example #3
0
def get_reports_sites():
    result = []
    group_name = request.args.get('group_name')
    user_email = request.args.get('user')
    if user_email is not None:
        # User specified, so return recent scans for each site/plan that the user can see
        user = users.find_one({'email': user_email})
        if user is None:
            return jsonify(success=False, reason='no-such-user')
        if group_name:
            site_list = _find_sites_for_user_by_group_name(user_email, group_name)
        else:
            site_list = _find_sites_for_user(user_email)
        for site_url in sorted(site_list):
            site = sites.find_one({'url': site_url})
            if site is not None:
                for plan_name in site['plans']:
                    schedule = scanschedules.find_one({'site':site_url, 'plan':plan_name})
                    crontab = None
                    scheduleEnabled = False
                    if schedule is not None:
                        crontab = schedule['crontab']
                        scheduleEnabled = schedule['enabled']

                    l = list(scans.find({'configuration.target':site['url'], 'plan.name': plan_name}).sort("created", -1).limit(1))
                    if len(l) == 1:
                        scan = summarize_scan(sanitize_scan(l[0]))
                        s = {v: scan.get(v) for v in ('id', 'created', 'state', 'issues')}
                        result.append({'target': site_url, 'plan': plan_name, 'scan': scan, 'crontab': crontab, 'scheduleEnabled': scheduleEnabled})
                    else:
                        result.append({'target': site_url, 'plan': plan_name, 'scan': None, 'crontab': crontab, 'scheduleEnabled': scheduleEnabled})
    return jsonify(success=True, report=result)
Example #4
0
def get_reports_sites():
    result = []
    group_name = request.args.get('group_name')
    user_email = request.args.get('user')

    if user_email is not None:
        # User specified, so return recent scans for each site/plan that the user can see
        user = User.get_user(user_email)
        if user is None:
            return jsonify(success=False, reason='no-such-user')
        if group_name:
            group = Group.get_group(group_name)
            if group is None:
                return jsonify(success=False, reason='no-such-group')

            site_list = map(lambda x: x.url, group.sites)
        else:
            site_list = user.sites()
        for site_url in sorted(site_list):
            site = Site.get_site_by_url(site_url)
            if site is not None:
                for plan in site.plans:
                    plan_name = plan.name
                    schedule = ScanSchedule.get_schedule(site.site_uuid, plan.plan_uuid)

                    crontab = None
                    scheduleEnabled = False
                    if schedule is not None:
                        crontab = schedule['crontab']
                        scheduleEnabled = schedule['enabled']

                    scans = []
                    for scan in site.scans:
                        if scan.plan is not None:
                            p = json.loads(scan.plan)
                            if p['name'] == plan_name:
                                scans.append(scan)                    

                    scan_for_site = []
                    for scan in scans:
                        config = json.loads(scan.configuration)
                        
                        if config.get('target', None) == site_url:
                            scan_for_site.append(scan)


                    o = list(sorted(scan_for_site, cmp= lambda x, y: cmp(x.created, y, created)))
                    if len(o):
                     l = [o[0]]
                    else:
                     l = []         
                    
                    if len(l) == 1:
                        scan = summarize_scan(l[0])
                        s = {v: scan.get(v) for v in ('id', 'created', 'state', 'issues')}
                        result.append({'target': site_url, 'plan': plan_name, 'scan': scan, 'crontab': crontab, 'scheduleEnabled': scheduleEnabled})
                    else:
                        result.append({'target': site_url, 'plan': plan_name, 'scan': None, 'crontab': crontab, 'scheduleEnabled': scheduleEnabled})
    return jsonify(success=True, report=result)
def get_reports_history():
    history = []
    user_email = request.args.get('user')
    if user_email is not None:
        user = users.find_one({'email': user_email})
        if user is None:
            return jsonify(success=False, reason='no-such-user')
        for s in scans.find({
                'configuration.target': {
                    '$in': _find_sites_for_user(user_email)
                }
        }).sort("created", -1).limit(100):
            history.append(summarize_scan(sanitize_scan(s)))
    else:
        for s in scans.find({}).sort("created", -1).limit(100):
            history.append(summarize_scan(sanitize_scan(s)))
    return jsonify(success=True, report=history)
def get_reports_sites():
    result = []
    group_name = request.args.get('group_name')
    user_email = request.args.get('user')
    if user_email is not None:
        # User specified, so return recent scans for each site/plan that the user can see
        user = users.find_one({'email': user_email})
        if user is None:
            return jsonify(success=False, reason='no-such-user')
        if group_name:
            site_list = _find_sites_for_user_by_group_name(
                user_email, group_name)
        else:
            site_list = _find_sites_for_user(user_email)
        for site_url in sorted(site_list):
            site = sites.find_one({'url': site_url})
            if site is not None:
                for plan_name in site['plans']:
                    schedule = scanschedules.find_one({
                        'site': site_url,
                        'plan': plan_name
                    })
                    crontab = None
                    scheduleEnabled = False
                    if schedule is not None:
                        crontab = schedule['crontab']
                        scheduleEnabled = schedule['enabled']

                    l = list(
                        scans.find({
                            'configuration.target': site['url'],
                            'plan.name': plan_name
                        }).sort("created", -1).limit(1))
                    if len(l) == 1:
                        scan = summarize_scan(sanitize_scan(l[0]))
                        s = {
                            v: scan.get(v)
                            for v in ('id', 'created', 'state', 'issues')
                        }
                        result.append({
                            'target': site_url,
                            'plan': plan_name,
                            'scan': scan,
                            'crontab': crontab,
                            'scheduleEnabled': scheduleEnabled
                        })
                    else:
                        result.append({
                            'target': site_url,
                            'plan': plan_name,
                            'scan': None,
                            'crontab': crontab,
                            'scheduleEnabled': scheduleEnabled
                        })
    return jsonify(success=True, report=result)
Example #7
0
def get_reports_sites():
    result = []
    user_email = request.args.get('user')
    if user_email is not None:
        # User specified, so return recent scans for each site/plan that the user can see
        user = users.find_one({'email': user_email})
        if user is None:
            return jsonify(success=False, reason='no-such-user')
        for site_url in sorted(_find_sites_for_user(user_email)):
            site = sites.find_one({'url': site_url})
            if site is not None:
                for plan_name in site['plans']:
                    l = list(scans.find({'configuration.target':site['url'], 'plan.name': plan_name}).sort("created", -1).limit(1))
                    if len(l) == 1:
                        scan = summarize_scan(sanitize_scan(l[0]))
                        s = {v: scan.get(v) for v in ('id', 'created', 'state', 'issues')}
                        result.append({'target': site_url, 'plan': plan_name, 'scan': scan})
                    else:
                        result.append({'target': site_url, 'plan': plan_name, 'scan': None})
    return jsonify(success=True, report=result)