Fix Storry Level 5

This commit is contained in:
Tim
2026-01-08 23:32:57 +01:00
parent fae6ae68a5
commit d4411d45a4
6 changed files with 11 additions and 12 deletions

40
Level/Level5/Microsoft.py Normal file
View File

@@ -0,0 +1,40 @@
import os
import time
import pwd
STATE_FILE = "/home/level5/.timer/timer_state.txt"
END_STATE = "/home/level5/.timer/end_state.txt"
def drop_privileges(user):
pw = pwd.getpwnam(user)
os.setgid(pw.pw_gid)
os.setuid(pw.pw_uid)
def countdown(seconds):
if os.path.exists(END_STATE):
os.remove(END_STATE)
for remaining in range(seconds, 0, -1):
with open(STATE_FILE, "w") as f:
f.write(str(remaining))
mins, secs = divmod(remaining, 60)
with open("/home/level5/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__":
drop_privileges("level5")
countdown(600)