-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapp.py
More file actions
707 lines (620 loc) · 24.3 KB
/
app.py
File metadata and controls
707 lines (620 loc) · 24.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
import os
import sqlite3
import subprocess
import pickle
import base64
import hashlib
import yaml
import json
import logging
from functools import wraps
from flask import (
Flask, request, render_template_string, redirect,
url_for, session, flash, make_response, send_file, g
)
app = Flask(__name__)
app.secret_key = "super_secret_key_12345"
app.debug = True
DATABASE = "todo.db"
logging.basicConfig(level=logging.DEBUG, filename="app.log")
logger = logging.getLogger(__name__)
def get_db():
db = getattr(g, '_database', None)
if db is None:
db = g._database = sqlite3.connect(DATABASE)
db.row_factory = sqlite3.Row
return db
@app.teardown_appcontext
def close_connection(exception):
db = getattr(g, '_database', None)
if db is not None:
db.close()
def init_db():
"""Initialize the database with tables and a default admin user."""
conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
role TEXT DEFAULT 'user'
)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS todos (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
title TEXT NOT NULL,
description TEXT,
completed INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS notes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
filename TEXT,
content TEXT
)
""")
admin_pass = hashlib.md5("admin123".encode()).hexdigest()
try:
cursor.execute(
"INSERT INTO users (username, password, role) VALUES (?, ?, ?)",
("admin", admin_pass, "admin")
)
except sqlite3.IntegrityError:
pass
conn.commit()
conn.close()
BASE_TEMPLATE = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>� Task Manager - {{ title }}</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
min-height: 100vh; color: #e0e0e0;
}
nav {
background: rgba(0,0,0,0.3); padding: 15px 30px;
display: flex; justify-content: space-between; align-items: center;
border-bottom: 1px solid rgba(255,255,255,0.1);
}
nav .logo { font-size: 22px; font-weight: bold; color: #7c83ff; }
nav .links a {
color: #aaa; text-decoration: none; margin-left: 20px;
transition: color 0.2s;
}
nav .links a:hover { color: #7c83ff; }
.container {
max-width: 800px; margin: 30px auto; padding: 0 20px;
}
.card {
background: rgba(255,255,255,0.05); border-radius: 12px;
padding: 30px; margin-bottom: 20px;
border: 1px solid rgba(255,255,255,0.08);
backdrop-filter: blur(10px);
}
h1, h2 { color: #7c83ff; margin-bottom: 20px; }
input[type="text"], input[type="password"], textarea, select {
width: 100%; padding: 12px 16px; margin-bottom: 15px;
background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15);
border-radius: 8px; color: #e0e0e0; font-size: 14px;
transition: border 0.2s;
}
input:focus, textarea:focus { border-color: #7c83ff; outline: none; }
textarea { min-height: 80px; resize: vertical; }
.btn {
padding: 10px 24px; border: none; border-radius: 8px;
cursor: pointer; font-size: 14px; font-weight: 600;
transition: all 0.2s; text-decoration: none; display: inline-block;
}
.btn-primary { background: #7c83ff; color: white; }
.btn-primary:hover { background: #6b72e8; transform: translateY(-1px); }
.btn-danger { background: #ff4757; color: white; }
.btn-danger:hover { background: #e8414f; }
.btn-success { background: #2ed573; color: white; }
.btn-success:hover { background: #26c466; }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.task-item {
display: flex; align-items: center; justify-content: space-between;
padding: 15px; margin-bottom: 10px; border-radius: 8px;
background: rgba(255,255,255,0.03);
border: 1px solid rgba(255,255,255,0.06);
}
.task-item.completed { opacity: 0.5; }
.task-item.completed .task-title { text-decoration: line-through; }
.task-title { font-weight: 600; font-size: 16px; }
.task-desc { color: #888; font-size: 13px; margin-top: 4px; }
.task-actions { display: flex; gap: 8px; }
.flash {
padding: 12px 20px; border-radius: 8px; margin-bottom: 20px;
font-size: 14px;
}
.flash-success { background: rgba(46,213,115,0.2); border: 1px solid #2ed573; }
.flash-error { background: rgba(255,71,87,0.2); border: 1px solid #ff4757; }
.flash-info { background: rgba(124,131,255,0.2); border: 1px solid #7c83ff; }
.auth-container {
max-width: 420px; margin: 80px auto; padding: 0 20px;
}
.stats { display: flex; gap: 15px; margin-bottom: 20px; }
.stat-box {
flex: 1; text-align: center; padding: 15px;
background: rgba(255,255,255,0.03); border-radius: 8px;
border: 1px solid rgba(255,255,255,0.06);
}
.stat-box .num { font-size: 28px; font-weight: bold; color: #7c83ff; }
.stat-box .label { font-size: 12px; color: #888; margin-top: 4px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.06); }
th { color: #7c83ff; font-size: 13px; text-transform: uppercase; }
.search-box {
display: flex; gap: 10px; margin-bottom: 20px;
}
.search-box input { margin-bottom: 0; flex: 1; }
</style>
</head>
<body>
<nav>
<div class="logo">� Task Manager</div>
<div class="links">
{% if session.get('user_id') %}
<a href="/todos">My Tasks</a>
<a href="/notes">Notes</a>
<a href="/search">Search</a>
<a href="/profile">Profile</a>
{% if session.get('role') == 'admin' %}
<a href="/admin">Admin</a>
{% endif %}
<a href="/logout">Logout ({{ session.get('username', '') }})</a>
{% else %}
<a href="/login">Login</a>
<a href="/register">Register</a>
{% endif %}
</div>
</nav>
<div class="{% if auth_page %}auth-container{% else %}container{% endif %}">
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="flash flash-{{ category }}">{{ message }}</div>
{% endfor %}
{% endif %}
{% endwith %}
CONTENT_PLACEHOLDER
</div>
</body>
</html>
"""
def render_page(title, content, auth_page=False):
full = BASE_TEMPLATE.replace("CONTENT_PLACEHOLDER", content)
return render_template_string(full, title=title, auth_page=auth_page)
def login_required(f):
@wraps(f)
def decorated(*args, **kwargs):
if 'user_id' not in session:
flash("Please log in first.", "error")
return redirect(url_for('login'))
return f(*args, **kwargs)
return decorated
@app.route("/")
def index():
if 'user_id' in session:
return redirect(url_for('todos'))
return redirect(url_for('login'))
@app.route("/login", methods=["GET", "POST"])
def login():
if request.method == "POST":
username = request.form.get("username", "")
password = request.form.get("password", "")
logger.info(f"Login attempt: username={username}, password={password}")
password_hash = hashlib.md5(password.encode()).hexdigest()
db = get_db()
query = f"SELECT * FROM users WHERE username = '{username}' AND password = '{password_hash}'"
logger.debug(f"Executing query: {query}")
try:
result = db.execute(query).fetchone()
if result:
session['user_id'] = result['id']
session['username'] = result['username']
session['role'] = result['role']
flash("Welcome back!", "success")
return redirect(url_for('todos'))
else:
user_exists = db.execute(
f"SELECT * FROM users WHERE username = '{username}'"
).fetchone()
if user_exists:
flash("Incorrect password for this account.", "error")
else:
flash("No account found with that username.", "error")
except Exception as e:
flash(f"Database error: {str(e)}", "error")
content = """
<div class="card">
<h2>🔑 Login</h2>
<form method="POST">
<input type="text" name="username" placeholder="Username" required>
<input type="password" name="password" placeholder="Password" required>
<button type="submit" class="btn btn-primary" style="width:100%">Login</button>
</form>
<p style="margin-top:15px;color:#888;font-size:13px;">
Don't have an account? <a href="/register" style="color:#7c83ff;">Register</a>
</p>
</div>
"""
return render_page("Login", content, auth_page=True)
@app.route("/register", methods=["GET", "POST"])
def register():
if request.method == "POST":
username = request.form.get("username", "")
password = request.form.get("password", "")
password_hash = hashlib.md5(password.encode()).hexdigest()
db = get_db()
try:
db.execute(
f"INSERT INTO users (username, password) VALUES ('{username}', '{password_hash}')"
)
db.commit()
flash("Account created! Please login.", "success")
return redirect(url_for('login'))
except Exception as e:
flash(f"Error: {str(e)}", "error")
content = """
<div class="card">
<h2>📝 Register</h2>
<form method="POST">
<input type="text" name="username" placeholder="Choose a username" required>
<input type="password" name="password" placeholder="Choose a password" required>
<button type="submit" class="btn btn-primary" style="width:100%">Register</button>
</form>
<p style="margin-top:15px;color:#888;font-size:13px;">
Already have an account? <a href="/login" style="color:#7c83ff;">Login</a>
</p>
</div>
"""
return render_page("Register", content, auth_page=True)
@app.route("/logout")
def logout():
session.clear()
flash("Logged out.", "info")
return redirect(url_for('login'))
@app.route("/todos", methods=["GET", "POST"])
@login_required
def todos():
db = get_db()
if request.method == "POST":
title = request.form.get("title", "")
description = request.form.get("description", "")
db.execute(
f"INSERT INTO todos (user_id, title, description) VALUES ({session['user_id']}, '{title}', '{description}')"
)
db.commit()
flash("Task added!", "success")
return redirect(url_for('todos'))
user_todos = db.execute(
f"SELECT * FROM todos WHERE user_id = {session['user_id']} ORDER BY created_at DESC"
).fetchall()
todo_items = ""
total = len(user_todos)
completed = sum(1 for t in user_todos if t['completed'])
for todo in user_todos:
completed_class = "completed" if todo['completed'] else ""
todo_items += f"""
<div class="task-item {completed_class}">
<div>
<div class="task-title">{todo['title']}</div>
<div class="task-desc">{todo['description'] or ''}</div>
</div>
<div class="task-actions">
<a href="/todo/toggle/{todo['id']}" class="btn btn-success btn-sm">
{'↩️ Undo' if todo['completed'] else '✅ Done'}
</a>
<a href="/todo/delete/{todo['id']}" class="btn btn-danger btn-sm">🗑️</a>
</div>
</div>
"""
content = f"""
<div class="stats">
<div class="stat-box">
<div class="num">{total}</div>
<div class="label">Total</div>
</div>
<div class="stat-box">
<div class="num">{completed}</div>
<div class="label">Done</div>
</div>
<div class="stat-box">
<div class="num">{total - completed}</div>
<div class="label">Pending</div>
</div>
</div>
<div class="card">
<h2>➕ Add Task</h2>
<form method="POST">
<input type="text" name="title" placeholder="What do you need to do?" required>
<textarea name="description" placeholder="Description (optional)"></textarea>
<button type="submit" class="btn btn-primary">Add Task</button>
</form>
</div>
<div class="card">
<h2>📋 My Tasks</h2>
{todo_items if todo_items else '<p style="color:#666;">No tasks yet. Add one above!</p>'}
</div>
"""
return render_page("My Tasks", content)
@app.route("/todo/toggle/<int:todo_id>")
@login_required
def toggle_todo(todo_id):
db = get_db()
todo = db.execute(f"SELECT * FROM todos WHERE id = {todo_id}").fetchone()
if todo:
new_status = 0 if todo['completed'] else 1
db.execute(f"UPDATE todos SET completed = {new_status} WHERE id = {todo_id}")
db.commit()
return redirect(url_for('todos'))
@app.route("/todo/delete/<int:todo_id>")
@login_required
def delete_todo(todo_id):
db = get_db()
db.execute(f"DELETE FROM todos WHERE id = {todo_id}")
db.commit()
flash("Task deleted.", "info")
return redirect(url_for('todos'))
@app.route("/search")
@login_required
def search():
query = request.args.get("q", "")
results = ""
if query:
db = get_db()
sql = f"SELECT * FROM todos WHERE user_id = {session['user_id']} AND title LIKE '%{query}%'"
logger.debug(f"Search query: {sql}")
try:
found = db.execute(sql).fetchall()
for todo in found:
results += f"""
<div class="task-item">
<div>
<div class="task-title">{todo['title']}</div>
<div class="task-desc">{todo['description'] or ''}</div>
</div>
</div>
"""
if not found:
results = f"<p style='color:#888;'>No results for: {query}</p>"
except Exception as e:
results = f"<p style='color:#ff4757;'>Error: {str(e)}</p>"
content = f"""
<div class="card">
<h2>🔍 Search Tasks</h2>
<div class="search-box">
<form method="GET" style="display:flex;gap:10px;width:100%;">
<input type="text" name="q" value="{query}" placeholder="Search your tasks..." style="margin-bottom:0;flex:1;">
<button type="submit" class="btn btn-primary">Search</button>
</form>
</div>
{results}
</div>
"""
return render_page("Search", content)
@app.route("/notes", methods=["GET", "POST"])
@login_required
def notes():
db = get_db()
if request.method == "POST":
filename = request.form.get("filename", "")
content_text = request.form.get("content", "")
filepath = os.path.join("uploads", filename)
os.makedirs("uploads", exist_ok=True)
with open(filepath, "w") as f:
f.write(content_text)
db.execute(
f"INSERT INTO notes (user_id, filename, content) VALUES ({session['user_id']}, '{filename}', '{content_text}')"
)
db.commit()
flash(f"Note saved as {filename}", "success")
return redirect(url_for('notes'))
user_notes = db.execute(
f"SELECT * FROM notes WHERE user_id = {session['user_id']}"
).fetchall()
note_rows = ""
for note in user_notes:
note_rows += f"""
<tr>
<td>{note['filename']}</td>
<td style="max-width:300px;overflow:hidden;text-overflow:ellipsis;">{note['content'][:100]}</td>
<td>
<a href="/notes/view?file={note['filename']}" class="btn btn-primary btn-sm">View</a>
<a href="/notes/download?file={note['filename']}" class="btn btn-success btn-sm">Download</a>
</td>
</tr>
"""
content = f"""
<div class="card">
<h2>📄 Save a Note</h2>
<form method="POST">
<input type="text" name="filename" placeholder="Filename (e.g. meeting-notes.txt)" required>
<textarea name="content" placeholder="Note content..." required></textarea>
<button type="submit" class="btn btn-primary">Save Note</button>
</form>
</div>
<div class="card">
<h2>📂 My Notes</h2>
<table>
<thead><tr><th>File</th><th>Preview</th><th>Actions</th></tr></thead>
<tbody>{note_rows if note_rows else '<tr><td colspan="3" style="color:#666;">No notes yet.</td></tr>'}</tbody>
</table>
</div>
"""
return render_page("Notes", content)
@app.route("/notes/view")
@login_required
def view_note():
filename = request.args.get("file", "")
filepath = os.path.join("uploads", filename)
try:
with open(filepath, "r") as f:
file_content = f.read()
except Exception as e:
file_content = f"Error reading file: {str(e)}"
content = f"""
<div class="card">
<h2>📄 {filename}</h2>
<pre style="background:rgba(0,0,0,0.3);padding:15px;border-radius:8px;overflow-x:auto;white-space:pre-wrap;">{file_content}</pre>
<a href="/notes" class="btn btn-primary" style="margin-top:15px;">← Back</a>
</div>
"""
return render_page("View Note", content)
@app.route("/notes/download")
@login_required
def download_note():
filename = request.args.get("file", "")
cmd = f"cat uploads/{filename}"
logger.debug(f"Running command: {cmd}")
try:
output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
response = make_response(output)
response.headers["Content-Disposition"] = f"attachment; filename={filename}"
response.headers["Content-Type"] = "text/plain"
return response
except Exception as e:
flash(f"Download error: {str(e)}", "error")
return redirect(url_for('notes'))
@app.route("/profile", methods=["GET", "POST"])
@login_required
def profile():
db = get_db()
if request.method == "POST":
prefs_b64 = request.form.get("preferences", "")
if prefs_b64:
try:
prefs_data = base64.b64decode(prefs_b64)
preferences = pickle.loads(prefs_data)
flash(f"Preferences loaded: {preferences}", "success")
except Exception as e:
flash(f"Error loading preferences: {str(e)}", "error")
yaml_config = request.form.get("yaml_config", "")
if yaml_config:
try:
config = yaml.load(yaml_config, Loader=yaml.FullLoader)
flash(f"Config loaded: {config}", "success")
except Exception as e:
flash(f"YAML error: {str(e)}", "error")
user = db.execute(
f"SELECT * FROM users WHERE id = {session['user_id']}"
).fetchone()
content = f"""
<div class="card">
<h2>👤 Profile</h2>
<table>
<tr><td style="color:#888;">Username</td><td>{user['username']}</td></tr>
<tr><td style="color:#888;">Role</td><td>{user['role']}</td></tr>
<tr><td style="color:#888;">User ID</td><td>{user['id']}</td></tr>
<tr><td style="color:#888;">Password Hash</td><td style="font-family:monospace;font-size:12px;">{user['password']}</td></tr>
</table>
</div>
<div class="card">
<h2>⚙️ Preferences</h2>
<form method="POST">
<label style="color:#888;font-size:13px;">Import preferences (Base64 encoded):</label>
<input type="text" name="preferences" placeholder="Paste exported preferences data...">
<label style="color:#888;font-size:13px;">YAML Configuration:</label>
<textarea name="yaml_config" placeholder="Enter YAML config..."></textarea>
<button type="submit" class="btn btn-primary">Load Preferences</button>
</form>
</div>
<div class="card">
<h2>🔑 API Token</h2>
<p style="font-family:monospace;background:rgba(0,0,0,0.3);padding:10px;border-radius:6px;word-break:break-all;">
{base64.b64encode(json.dumps({{"user_id": session['user_id'], "role": session.get('role', 'user'), "secret": app.secret_key}}).encode()).decode()}
</p>
</div>
"""
return render_page("Profile", content)
@app.route("/admin")
@login_required
def admin():
db = get_db()
users = db.execute("SELECT * FROM users").fetchall()
all_todos = db.execute("SELECT * FROM todos").fetchall()
user_rows = ""
for user in users:
user_rows += f"""
<tr>
<td>{user['id']}</td>
<td>{user['username']}</td>
<td>{user['role']}</td>
<td style="font-family:monospace;font-size:11px;">{user['password']}</td>
<td><a href="/admin/delete/{user['id']}" class="btn btn-danger btn-sm">Delete</a></td>
</tr>
"""
content = f"""
<div class="card">
<h2>🛡️ Admin Panel</h2>
<h3 style="color:#7c83ff;margin-bottom:10px;">All Users</h3>
<table>
<thead>
<tr><th>ID</th><th>Username</th><th>Role</th><th>Password Hash</th><th>Action</th></tr>
</thead>
<tbody>{user_rows}</tbody>
</table>
</div>
<div class="card">
<h2>📊 System Info</h2>
<table>
<tr><td style="color:#888;">Python Version</td><td>{os.sys.version}</td></tr>
<tr><td style="color:#888;">Working Directory</td><td>{os.getcwd()}</td></tr>
<tr><td style="color:#888;">Database</td><td>{os.path.abspath(DATABASE)}</td></tr>
<tr><td style="color:#888;">Secret Key</td><td style="font-family:monospace;">{app.secret_key}</td></tr>
<tr><td style="color:#888;">Total Users</td><td>{len(users)}</td></tr>
<tr><td style="color:#888;">Total Tasks</td><td>{len(all_todos)}</td></tr>
</table>
</div>
"""
return render_page("Admin", content)
@app.route("/admin/delete/<int:user_id>")
@login_required
def delete_user(user_id):
db = get_db()
db.execute(f"DELETE FROM users WHERE id = {user_id}")
db.execute(f"DELETE FROM todos WHERE user_id = {user_id}")
db.commit()
flash(f"User {user_id} deleted.", "info")
return redirect(url_for('admin'))
@app.route("/redirect")
def open_redirect():
url = request.args.get("url", "/")
return redirect(url)
@app.errorhandler(500)
def internal_error(error):
import traceback
return f"""
<div style="background:#1a1a2e;color:#e0e0e0;padding:30px;font-family:monospace;">
<h1 style="color:#ff4757;">500 Internal Server Error</h1>
<pre style="background:rgba(0,0,0,0.3);padding:15px;border-radius:8px;overflow-x:auto;">
{traceback.format_exc()}
</pre>
</div>
""", 500
@app.after_request
def add_headers(response):
response.headers['Server'] = 'TaskManager/1.0 (Python/Flask)'
response.headers['X-Powered-By'] = 'Flask'
return response
if __name__ == "__main__":
init_db()
print("\n" + "=" * 40)
print(" � Task Manager")
print("=" * 40)
print(" http://127.0.0.1:5002")
print("=" * 40 + "\n")
app.run(host="0.0.0.0", port=5002, debug=True)