From 573551bd323792a57c86bc81a90c1150cbe7d83b Mon Sep 17 00:00:00 2001 From: Tristan Smith Date: Mon, 23 Sep 2024 01:27:02 -0400 Subject: [PATCH] typo --- scripts/user_panel.cgi | 76 +++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/scripts/user_panel.cgi b/scripts/user_panel.cgi index 42abbbd..c6895e7 100644 --- a/scripts/user_panel.cgi +++ b/scripts/user_panel.cgi @@ -1,39 +1,55 @@ - import sqlite3 - import http.cookies - import os +#!/usr/bin/python3 - # Ensure the session_id is properly parsed - cookie = http.cookies.SimpleCookie(os.environ.get('HTTP_COOKIE', '')) - session_id = cookie.get('session_id') +import sqlite3 +import http.cookies +import os +import time # Ensure we import time for the timestamp check - if session_id: - session_id = session_id.value - else: - session_id = None +print("Content-Type: text/html") +print() - # Log the session ID for debugging +# 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 + + # Connect to SQLite and check the session + db = sqlite3.connect('/var/lib/monotreme/data/monotreme.db') + 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"Parsed session ID: {session_id}\n") + f.write(f"Current time (UNIX timestamp): {current_time}\n") - if session_id: - session_id = session_id.value - # Connect to SQLite and check the session - db = sqlite3.connect('/var/lib/monotreme/data/monotreme.db') - cursor = db.cursor() + # Check if the session exists and is still valid + cursor.execute("SELECT username, expires_at FROM sessions WHERE session_id=? AND expires_at > ?", (session_id, current_time)) + result = cursor.fetchone() - # 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()))) - result = cursor.fetchone() + if result: + username, expires_at = result - if result: - username = result[0] - print(f"

Welcome, {username}!

") - print("

This is your user panel.

") - print("

Here, for now, you can only log out.

") - print("Log out") - else: - print("

Session expired or invalid!

") - print("Login again") + # 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"

Welcome, {username}!

") + print("

This is your user panel.

") + print("

This panel contains nothing but the ability to logout.

") + print('Logout') else: - print("

No session found!

") + with open("/tmp/user_panel_session.log", "a") as f: + f.write("Session expired or invalid.\n") + print("

Session expired or invalid!

") print("Login again") +else: + print("

No session found!

") + print("Login again") \ No newline at end of file