diff options
Diffstat (limited to 'src/ssh_node5_net.py')
| -rw-r--r-- | src/ssh_node5_net.py | 34 |
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', |
