From 2f74406f64052ceb697c08ed45b1d9c36bb2e912 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Tue, 14 Nov 2017 17:03:46 +0100 Subject: [PATCH] Draft MISP-Users --- server.py | 39 +++++++++ templates/users.html | 187 +++++++++++++++++++++++++++++++++++++++++++ zmq_subscriber.py | 14 +++- 3 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 templates/users.html diff --git a/server.py b/server.py index 2cd581d..9999d37 100755 --- a/server.py +++ b/server.py @@ -198,6 +198,45 @@ def users(): return render_template('users.html', ) + +@app.route("/_getUserLogins") +def getUserLogins(): + try: + date = datetime.datetime.fromtimestamp(float(request.args.get('date'))) + except: + date = datetime.datetime.now() + + keyname = "USER_LOGIN:{}" + prev_days = 6 + week = {} + for curDate in util.getXPrevDaysSpan(date, prev_days): + timestamps = serv_redis_db.smembers(keyname.format(util.getDateStrFormat(curDate))) + timestamps = [int(timestamp.decode('utf8')) for timestamp in timestamps] + day = {} + for timestamp in timestamps: + date = datetime.datetime.fromtimestamp(float(timestamp)) + if date.hour not in day: + day[date.hour] = 0 + day[date.hour] += 1 + week[curDate.weekday()] = day + + # Format data + data = [] + for d in range(7): + try: + to_append = [] + for h in range(24): + try: + to_append.append(week[d][h]) + except KeyError: + to_append.append(0) + # swap 24 and 1. (punchcard starts at 1h) + temp = to_append[1:]+[to_append[0]] + data.append(temp) + except KeyError: + data.append([0 for x in range(24)]) + return jsonify(data) + ''' INDEX ''' @app.route("/_logs") diff --git a/templates/users.html b/templates/users.html new file mode 100644 index 0000000..7779528 --- /dev/null +++ b/templates/users.html @@ -0,0 +1,187 @@ + + + + + + + + + + + MISP live dashboard + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+
+
+
+ +
+
+
+ Punch card - login +
+
+
+
+
+
+ +
+
+
+ Contribution after login (API vs non-API) +
+
+
+
+
+
+ +
+
+ +
+ +
+ + + + + + + + + + + + + diff --git a/zmq_subscriber.py b/zmq_subscriber.py index 48bb3c3..263a977 100755 --- a/zmq_subscriber.py +++ b/zmq_subscriber.py @@ -187,6 +187,18 @@ def handler_keepalive(zmq_name, jsonevent): to_push = [ jsonevent['uptime'] ] publish_log(zmq_name, 'Keepalive', to_push) +def handler_user(zmq_name, jsondata): + json_user = jsondata['User'] + userID = json_user['id'] + try: #only consider user login + timestamp = json_user['current_login'] + except KeyError: + return + now = datetime.datetime.now() + today_str = util.getDateStrFormat(now) + keyname = "{}:{}".format('USER_LOGIN', today_str) + serv_redis_db.sadd(keyname, timestamp) + def handler_conversation(zmq_name, jsonevent): try: #only consider POST, not THREAD jsonpost = jsonevent['Post'] @@ -323,7 +335,7 @@ dico_action = { "misp_json_object": handler_object, "misp_json_sighting": handler_sighting, "misp_json_organisation": handler_log, - "misp_json_user": handler_log, + "misp_json_user": handler_user, "misp_json_conversation": handler_conversation }