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:
19
server.py
19
server.py
@@ -57,6 +57,24 @@ def init_users_table():
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
print("Default admin user created - username: admin, password: admin123")
|
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
|
# Login route
|
||||||
@app.route('/login', methods=['GET', 'POST'])
|
@app.route('/login', methods=['GET', 'POST'])
|
||||||
def login():
|
def login():
|
||||||
@@ -559,4 +577,5 @@ def database_stats():
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
init_users_table()
|
init_users_table()
|
||||||
|
init_logs_table()
|
||||||
app.run(host='0.0.0.0', port=80)
|
app.run(host='0.0.0.0', port=80)
|
||||||
Reference in New Issue
Block a user