typo
This commit is contained in:
parent
c980f32726
commit
573551bd32
1 changed files with 46 additions and 30 deletions
|
@ -1,39 +1,55 @@
|
||||||
import sqlite3
|
#!/usr/bin/python3
|
||||||
import http.cookies
|
|
||||||
import os
|
|
||||||
|
|
||||||
# Ensure the session_id is properly parsed
|
import sqlite3
|
||||||
cookie = http.cookies.SimpleCookie(os.environ.get('HTTP_COOKIE', ''))
|
import http.cookies
|
||||||
session_id = cookie.get('session_id')
|
import os
|
||||||
|
import time # Ensure we import time for the timestamp check
|
||||||
|
|
||||||
if session_id:
|
print("Content-Type: text/html")
|
||||||
|
print()
|
||||||
|
|
||||||
|
# Ensure the session_id is properly parsed
|
||||||
|
cookie = http.cookies.SimpleCookie(os.environ.get('HTTP_COOKIE', ''))
|
||||||
|
session_id = cookie.get('session_id')
|
||||||
|
|
||||||
|
# Log the session ID for debugging
|
||||||
|
with open("/tmp/user_panel_session.log", "a") as f:
|
||||||
|
f.write(f"Parsed session ID: {session_id.value if session_id else 'None'}\n")
|
||||||
|
|
||||||
|
if session_id:
|
||||||
session_id = session_id.value
|
session_id = session_id.value
|
||||||
else:
|
|
||||||
session_id = None
|
|
||||||
|
|
||||||
# Log the session ID for debugging
|
|
||||||
with open("/tmp/user_panel_session.log", "a") as f:
|
|
||||||
f.write(f"Parsed session ID: {session_id}\n")
|
|
||||||
|
|
||||||
if session_id:
|
|
||||||
session_id = session_id.value
|
|
||||||
# Connect to SQLite and check the session
|
# Connect to SQLite and check the session
|
||||||
db = sqlite3.connect('/var/lib/monotreme/data/monotreme.db')
|
db = sqlite3.connect('/var/lib/monotreme/data/monotreme.db')
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
|
|
||||||
|
# Log the current timestamp for debugging
|
||||||
|
current_time = int(time.time())
|
||||||
|
with open("/tmp/user_panel_session.log", "a") as f:
|
||||||
|
f.write(f"Current time (UNIX timestamp): {current_time}\n")
|
||||||
|
|
||||||
# Check if the session exists and is still valid
|
# Check if the session exists and is still valid
|
||||||
cursor.execute("SELECT username FROM sessions WHERE session_id=? AND expires_at > ?", (session_id, int(time.time())))
|
cursor.execute("SELECT username, expires_at FROM sessions WHERE session_id=? AND expires_at > ?", (session_id, current_time))
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
username = result[0]
|
username, expires_at = result
|
||||||
|
|
||||||
|
# Log the session expiration time for debugging
|
||||||
|
with open("/tmp/user_panel_session.log", "a") as f:
|
||||||
|
f.write(f"Session found for user: {username}\n")
|
||||||
|
f.write(f"Session expires at: {expires_at}, Current time: {current_time}\n")
|
||||||
|
|
||||||
|
# Print the user panel
|
||||||
print(f"<h1>Welcome, {username}!</h1>")
|
print(f"<h1>Welcome, {username}!</h1>")
|
||||||
print("<p>This is your user panel.</p>")
|
print("<p>This is your user panel.</p>")
|
||||||
print("<p>Here, for now, you can only log out.</p>")
|
print("<p>This panel contains nothing but the ability to logout.</p>")
|
||||||
print("<a href='/cgi-bin/logout.cgi'>Log out</a>")
|
print('<a href="/cgi-bin/logout.cgi">Logout</a>')
|
||||||
else:
|
else:
|
||||||
|
with open("/tmp/user_panel_session.log", "a") as f:
|
||||||
|
f.write("Session expired or invalid.\n")
|
||||||
print("<h1>Session expired or invalid!</h1>")
|
print("<h1>Session expired or invalid!</h1>")
|
||||||
print("<a href='/login/'>Login again</a>")
|
print("<a href='/login/'>Login again</a>")
|
||||||
else:
|
else:
|
||||||
print("<h1>No session found!</h1>")
|
print("<h1>No session found!</h1>")
|
||||||
print("<a href='/login/'>Login again</a>")
|
print("<a href='/login/'>Login again</a>")
|
Loading…
Reference in a new issue