From 2f05360d696f5751daf0f6e7073f462ac167a165 Mon Sep 17 00:00:00 2001 From: Developer Date: Thu, 18 Dec 2025 15:46:56 +0200 Subject: [PATCH] Fix: Initialize logs table on startup - Add init_logs_table() function to create logs table schema - Call init_logs_table() on application startup - Fixes 'no such table: logs' error when accessing dashboard - Tables now created automatically before routes are accessed --- server.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/server.py b/server.py index 5dacb31..311fbd1 100644 --- a/server.py +++ b/server.py @@ -57,6 +57,24 @@ def init_users_table(): conn.commit() print("Default admin user created - username: admin, password: admin123") + +def init_logs_table(): + """Initialize the logs table if it doesn't exist""" + with sqlite3.connect(DATABASE) as conn: + cursor = conn.cursor() + cursor.execute(''' + CREATE TABLE IF NOT EXISTS logs ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + hostname TEXT NOT NULL, + device_ip TEXT NOT NULL, + nume_masa TEXT NOT NULL, + timestamp TEXT NOT NULL, + event_description TEXT NOT NULL + ) + ''') + conn.commit() + print("Logs table initialized") + # Login route @app.route('/login', methods=['GET', 'POST']) def login(): @@ -559,4 +577,5 @@ def database_stats(): if __name__ == '__main__': init_users_table() + init_logs_table() app.run(host='0.0.0.0', port=80) \ No newline at end of file