monotreme.org/scripts/logout.cgi

26 lines
706 B
Text
Raw Normal View History

2024-09-22 22:37:04 +01:00
# logout.cgi
import sqlite3
import os
import http.cookies
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')
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()
print("<h1>You have been logged out!</h1>")
print("<a href='/login/'>Login again</a>")