Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
shrug
Browse files Browse the repository at this point in the history
  • Loading branch information
glacialcascade committed Jun 7, 2024
1 parent 60e0e42 commit 082c1b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions user-1/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,14 @@ def restart():

def time_to_restart():
# format as mm:ss
return str(next_restart - datetime.datetime.now())[2:-7]
return str(next_restart - datetime.datetime.now())[:-7]

def get_conn(db):
if db not in sql_connections:
conn = sqlite3.connect("dbs/" + db + ".db")
c = conn.cursor()
c.execute("PRAGMA foreign_keys = ON")
sql_connections[db] = conn
return conn
return sql_connections[db]

conn = sqlite3.connect("dbs/" + db + ".db")
c = conn.cursor()
c.execute("PRAGMA foreign_keys = ON")
sql_connections[db] = conn
return conn

def init_db(db):
role_table = "roles_" + os.urandom(8).hex()
Expand All @@ -64,6 +61,7 @@ def init_db(db):
c.execute(f"INSERT INTO {role_table} (id, admin) VALUES (0, 1)")
c.execute(f"INSERT INTO {role_table} (id, admin) VALUES (1, 0)")
conn.commit()
conn.close()
return role_table


Expand All @@ -75,6 +73,7 @@ def set_name():
c = conn.cursor()
c.execute(f'UPDATE users SET name="{request.form["username"]}" WHERE id=1')
conn.commit()
conn.close()
except Exception as e:
print(traceback.format_exc())
return redirect(f"/?error={str(e)}")
Expand All @@ -83,6 +82,9 @@ def set_name():

@app.route("/")
def index():
if (datetime.datetime.now() > next_restart):
restart()

print(session.get("db"), session.get("role_table"))
if not session.get("db") or not session.get("role_table") or request.args.get("reset"):
session["db"] = os.urandom(16).hex()
Expand All @@ -97,6 +99,7 @@ def index():
username = c.fetchone()[0]
c.execute(f'SELECT admin FROM {session["role_table"]} WHERE id=1')
admin = c.fetchone()[0]
conn.close()
except Exception as e:
print(traceback.format_exc())
return redirect(f"/?reset=1&error={str(e)}")
Expand Down
4 changes: 2 additions & 2 deletions user-1/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ <h2>Your username is {{ username }}. Care to change it?</h2>



<h2>Note: This challenge will reset periodically for maintenance (for which you may get 500 errors - just reload).
<h2>Note: This challenge will reset periodically for maintenance (for which you may get 500 errors - just wait a bit and reload).
This is not related to the challenge's solution.
</h2>
<h3>Next restart in: {{ time_to_restart }}</h3>
<h3>Next restart in approximately: {{ time_to_restart }}</h3>

{% if error %}
<h3>My code is bad, so you received an error (and your session might have reset):</h3>
Expand Down

0 comments on commit 082c1b3

Please sign in to comment.