#!/usr/bin/python3 import os import sqlite3 import http.cookies # Set HTTP headers print("Content-Type: text/html") print("Set-Cookie: session_id=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT") print() # Get the session ID from the cookie cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) session_id = cookie.get('session_id') # Log the logout process for debugging with open("/tmp/logout_session.log", "a") as f: f.write(f"Session ID: {session_id.value if session_id else 'None'}\n") if session_id: session_id = session_id.value # Connect to SQLite and remove the session db = sqlite3.connect('/var/lib/monotreme/data/monotreme.db') cursor = db.cursor() cursor.execute("DELETE FROM sessions WHERE session_id=?", (session_id,)) db.commit() db.close() # Output the HTML for the logout page print("