summaryrefslogtreecommitdiff
path: root/src/ssh_node5_net.py
diff options
context:
space:
mode:
authoruser <user@node5.net>2024-03-24 00:11:00 +0100
committeruser <user@node5.net>2024-03-24 00:11:00 +0100
commitf8c85565396ee7d027fd3096c598e200037b3733 (patch)
tree0f315a00803021e2e1cfb6ac8f58730b80a5eb12 /src/ssh_node5_net.py
parent5995864720f7c6b1e53196b500e6727011b99a7c (diff)
dedicated /chart page
Diffstat (limited to 'src/ssh_node5_net.py')
-rw-r--r--src/ssh_node5_net.py34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/ssh_node5_net.py b/src/ssh_node5_net.py
index 0b1d37a..0615147 100644
--- a/src/ssh_node5_net.py
+++ b/src/ssh_node5_net.py
@@ -58,14 +58,7 @@ def format_time(input: datetime.datetime) -> str:
'''
-@app.route("/")
-def index():
- latest_loging_attempts = db_handler.get_latest_login_attempts()
- for login_attempt in latest_loging_attempts[0]:
- login_attempt['timestamp'] = format_time(login_attempt['timestamp'])
- top_usernames = db_handler.get_top('username')
- top_passwords = db_handler.get_top('password')
-
+def get_chart():
histogram = db_handler.get_histogram_detailed()
all_dates = sorted(list({d['date'] for d in histogram}))
by_ip = {}
@@ -77,11 +70,34 @@ def index():
histogram_chartjs = json.dumps([{
'label': str(ip),
'data': data,
- 'backgroundColor': f'hsl({random.randrange(0,360)}, 50%, 50%)',
+ 'backgroundColor': f'hsl({random.randrange(0, 360)}, 50%, 50%)',
'fill': 'start'
} for index, (ip, data) in enumerate(by_ip.items())])
histogram_labels = [str(a) for a in all_dates]
+ return histogram_chartjs, histogram_labels
+
+
+@app.route('/chart')
+def chart_page():
+ histogram_chartjs, histogram_labels = get_chart()
+ return flask.render_template(
+ 'chart_page.html',
+ histogram_data=histogram_chartjs,
+ histogram_labels=histogram_labels
+ )
+
+
+@app.route("/")
+def index():
+ latest_loging_attempts = db_handler.get_latest_login_attempts()
+ for login_attempt in latest_loging_attempts[0]:
+ login_attempt['timestamp'] = format_time(login_attempt['timestamp'])
+
+ top_usernames = db_handler.get_top('username')
+ top_passwords = db_handler.get_top('password')
+
+ histogram_chartjs, histogram_labels = get_chart()
return flask.render_template(
'index.html',