2024-09-23 06:21:45 +01:00
|
|
|
#!/usr/bin/python3
|
2024-09-22 22:37:04 +01:00
|
|
|
|
|
|
|
import os
|
2024-09-23 06:21:45 +01:00
|
|
|
import sqlite3
|
2024-09-22 22:37:04 +01:00
|
|
|
import http.cookies
|
|
|
|
|
2024-09-23 06:21:45 +01:00
|
|
|
# Set HTTP headers
|
2024-09-22 22:37:04 +01:00
|
|
|
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')
|
|
|
|
|
2024-09-23 06:21:45 +01:00
|
|
|
# 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")
|
|
|
|
|
2024-09-22 22:37:04 +01:00
|
|
|
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()
|
|
|
|
|
2024-09-23 06:21:45 +01:00
|
|
|
# Output the HTML for the logout page
|
|
|
|
print("<html><head><title>Logout</title></head>")
|
|
|
|
print("<body><h1>You have been logged out!</h1>")
|
2024-09-22 22:37:04 +01:00
|
|
|
print("<a href='/login/'>Login again</a>")
|
2024-09-23 06:21:45 +01:00
|
|
|
print("</body></html>")
|
2024-09-23 07:00:19 +01:00
|
|
|
|