diff options
| author | user <user@node5.net> | 2024-03-23 22:26:19 +0100 |
|---|---|---|
| committer | user <user@node5.net> | 2024-03-23 22:26:19 +0100 |
| commit | 6e4ef29252eea8ee0d72539b48088a1913eb1b83 (patch) | |
| tree | c8a4f8f14aeb20b2d590511bf2711cc5cfc486dd | |
| parent | b70a9b7ed2f5ebea9d35d9bdf4a666b8cfdce29b (diff) | |
chart stacked grouped by ip address
| -rw-r--r-- | src/ssh_node5_net.py | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/src/ssh_node5_net.py b/src/ssh_node5_net.py index 1247603..54e5721 100644 --- a/src/ssh_node5_net.py +++ b/src/ssh_node5_net.py @@ -1,3 +1,4 @@ +import json import logging import datetime @@ -39,9 +40,7 @@ logger.root.addHandler(stream_handler) app = flask.Flask(__name__, template_folder='templates', static_folder='static', static_url_path='') -@app.route("/password_of_the_month") -@app.route("/password of the month") -@app.route("/passwd") +@app.route("/potm") def password_of_the_month(): password = db_handler.get_password_of_the_month() return password @@ -50,18 +49,42 @@ def password_of_the_month(): def format_time(input: datetime.datetime) -> str: return input.strftime('%e %b %Y %H:%M') + +''' + histogram = db_handler.get_histogram() + histogram_data = [a['total_count'] for a in histogram] + histogram_labels = [format_time(a['date']) for a in histogram] +''' + + @app.route("/") def index(): latest_loging_attempts = db_handler.get_latest_login_attempts() top_usernames = db_handler.get_top('username') top_passwords = db_handler.get_top('password') - histogram = db_handler.get_histogram() - histogram_data = [a['total_count'] for a in histogram] - histogram_labels = [format_time(a['date']) for a in histogram] + + histogram = db_handler.get_histogram_detailed() + all_dates = list({d['date'] for d in histogram}) + by_ip = {} + for d in histogram: + if d['ip'] not in by_ip: + by_ip[d['ip']] = [] + for date in all_dates: + by_ip[d['ip']].append(d['total_count'] if date == d['date'] else 0) + + histogram_chartjs = json.dumps([{ + 'label': str(ip), + 'data': data, + 'backgroundColor': f'hsl({index / len(all_dates) * 360}, 50%, 50%)', + 'fill': 'start' + } for index, (ip, data) in enumerate(by_ip.items())]) + + histogram_labels = [str(a) for a in all_dates] + return flask.render_template( 'index.html', latest_login_attempts=latest_loging_attempts, top_usernames=top_usernames, top_passwords=top_passwords, - histogram_data=histogram_data, + histogram_data=histogram_chartjs, histogram_labels=histogram_labels) |
