Commit 28e1f542 authored by ale's avatar ale

store the timestamp of the last received update

parent ed206fef
# FastCGI receiver component of the offlinescan package.
# (Meant to be run behind authentication).
import json
import time
import redis
from flask import Flask, request, abort, g
from flask.ext.cache import Cache
app = Flask(__name__)
cache = Cache(app)
def get_redis_connection():
return redis.Redis(
# Retrieve all per-user data and cache it somewhere (for a short time,
# since FastCGI runners aren't long-lived anyway).
def get_virus_by_user():
virus_by_user = {}
rdb = get_redis_connection()
for obj in ai.LDAPObj(ai.config.base_uid).search('(&(objectClass=ftpAccount)(status=active))'):
virus_by_user[obj['ftpname']] = rdb.lrange('virus:%s' % obj['ftpname'], 0, -1)
return virus_by_user
def before_request():
g.redis = get_redis_connection()
@app.route('/submit', methods=('GET', 'POST'))
def receive():
if request.method == 'POST':
p = g.redis.pipeline(transaction=False)
#per_user = {}
for user, results in request.json.iteritems():
key = 'virus:%s' % user
#p.ltrim(key, 0, 0)
for r in results:
p.lpush(key, r)
#per_user[user] = len(results)
# Save some incremental stats with per-user infection counts.
#new_ptr = 'virus_stats:%f' % time.time()
#for user, count in per_user.iteritems():
# p.hset(new_ptr, user, count)
#p.set('virus_stats:head', new_ptr)
# Store the time of last update, to monitor freshness.
p.set('virut_stats:stamp', int(time.time()))
return 'ok'
def index():
return render_template('index.html',
def create_app():
# The env variable name is compatible with wsgi-app-installer.
app.config.from_envvar('APP_CONFIG', silent=True)
return app
def main():
from flup.server.fcgi import WSGIServer
if __name__ == '__main__':
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment