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
This commit is contained in:
Developer
2025-12-18 15:46:56 +02:00
parent cb52e67afa
commit 2f05360d69

View File

@@ -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)