Ejemplo n.º 1
0
def reset(datatype, db):
    '''
    Returns whether a reset code has been sent in the last 30 seconds for the
    specified type of data. 
    '''
    if db.query(Reset).filter(Reset.datatype == datatype)\
                      .filter(Reset.timestamp > int(time.time()) - 30)\
                      .count() > 0:
        return jsonify(1)
    return jsonify(0)
Ejemplo n.º 2
0
def get_pvs_data(limit, db):
    '''
    Returns the top 5 vulnerable hosts as detected from the PVS sensor.
    '''
    resp = requests.post('https://%s:8835/login' % setting('pvs_host').value,
        data={
            'login': setting('pvs_user').value,
            'password': setting('pvs_password').value,
            'nocookie': 1, 'json': 1
    }, verify=False)
    pvs_key = resp.json()['reply']['contents']['token']
    data = requests.post('https://%s:8835/report2/hosts/sort' % setting('pvs_host').value, data={
        'report': 0, 'json': 1, 'token': pvs_key}, verify=False)
    hosts = data.json()['reply']['contents']['hostlist']['host']
    shosts = sorted(hosts, key=lambda k: k['severity_index'], reverse=True)
    rethosts = []
    max_vulns = 0
    for item in shosts[:limit]:
        d = {'host': item['hostname']}
        sevs = {0: 'info', 1: 'low', 2: 'medium', 3: 'high', 4: 'critical'}
        for severity in item['severitycount']['item']:
            d[sevs[severity['severitylevel']]] = severity['count']
        if item['severity'] > max_vulns:
            max_vulns = item['severity']
        rethosts.append(d)
    requests.post('https://%s:8835/logout' % setting('pvs_host').value, data={
        'seq': 1802, 'json': 1, 'token': pvs_key}, verify=False)
    return jsonify({'vuln_max': max_vulns, 'hosts': rethosts})
Ejemplo n.º 3
0
def accounts(oid, db):
    '''
    Returns any accounts that are newer than the oid specified.
    '''
    if oid is not '0':
        items = db.query(Account).filter(Account.id > oid).all()
    else:
        items = db.query(Account).limit(setting('web_image_max').intvalue).all()
    return jsonify([i.dump() for i in items])
Ejemplo n.º 4
0
def recent_images(ts, db):
    '''
    Returns up to the last 200 images that were captured since the timestamp
    referenced.
    '''
    if ts == 0:
        skippr = db.query(Image).count() - 200
        if skippr < 0:
            skippr = 0
    else:
        skippr = 0
    images = db.query(Image).filter(Image.timestamp >= ts)\
               .order_by(desc(Image.timestamp)).limit(200).all()
    return jsonify([i.dump() for i in reversed(images)])
Ejemplo n.º 5
0
def recent_images(ts, db):
    '''
    Returns up to the last 200 images that were captured since the timestamp
    referenced.
    '''
    if ts == 0:
        skippr = db.query(Image).count() - 200
        if skippr < 0:
            skippr = 0
    else:
        skippr = 0
    return jsonify([i.dump() for i in db.query(Image)\
                                        .filter(Image.timestamp > ts)\
                                        .offset(skippr).all()])
Ejemplo n.º 6
0
Archivo: post.py Proyecto: xme/DoFler
def services(db):
    '''
    Returns the running status of the services on the dofler sensor. 
    '''
    if auth(request) and request.method == 'POST':
        parser = request.forms.get('parser') or None
        action = request.forms.get('action') or None
        if action == 'Stop':
            monitor.stop(parser)
        if action == 'Start':
            monitor.start(parser)
        if action == 'Restart':
            monitor.stop(parser)
            monitor.start(parser)
    return jsonify(monitor.parser_status())
Ejemplo n.º 7
0
def services(db):
    '''
    Returns the running status of the services on the dofler sensor. 
    '''
    if auth(request) and request.method == 'POST':
        parser = request.forms.get('parser') or None
        action = request.forms.get('action') or None
        if action == 'Stop':
            monitor.stop(parser)
        if action == 'Start':
            monitor.start(parser)
        if action == 'Restart':
            monitor.stop(parser)
            monitor.start(parser)
    return jsonify(monitor.parser_status())
Ejemplo n.º 8
0
def stats(limit, db):
    '''
    Returns the aggregate protocol stats. 
    '''
    data = []
    protos = db.query(Stat.proto, func.sum(Stat.count))\
                .group_by(Stat.proto)\
                .order_by(desc(func.sum(Stat.count)))\
                .limit(limit).all()
    for proto in protos:
        data.append({
            'label': proto[0],
            'data': [[a[0] * 1000, a[1]] for a in db.query(Stat.timestamp, func.sum(Stat.count))\
                                            .filter(Stat.proto == proto[0])\
                                            .group_by(Stat.timestamp)\
                                            .order_by(desc(Stat.timestamp))\
                                            .limit(180)\
                                            .all()]
        })
    return jsonify(data)
Ejemplo n.º 9
0
def stats(limit, db):
    '''
    Returns the aggregate protocol stats. 
    '''
    data = []
    protos = db.query(Stat.proto, func.sum(Stat.count))\
                .group_by(Stat.proto)\
                .order_by(desc(func.sum(Stat.count)))\
                .limit(limit).all()
    for proto in protos:
        data.append({
            'label': proto[0],
            'data': [[int(a[0] * 1000), int(a[1])] for a in db.query(Stat.timestamp, func.sum(Stat.count))\
                                            .filter(Stat.proto == proto[0])\
                                            .filter(Stat.timestamp >= int(time.time() - 10800))\
                                            .group_by(Stat.timestamp)\
                                            .order_by(desc(Stat.timestamp))\
                                            .limit(180)\
                                            .all()]
        })
    return jsonify(data)
Ejemplo n.º 10
0
def account_total(db):
    '''
    Returns the total number of accounts stored.
    '''
    return jsonify(db.query(Account).count())