Skip to content

Commit

Permalink
Add simple script to force admin and judgehost passwords.
Browse files Browse the repository at this point in the history
This will read from restapi.secret and initial_admin_password.secret and
reset the DB state to match these passwords.

This can be especially useful if you are importing a database from a
previous contest and do not want to do update passwords manually.
  • Loading branch information
meisterT committed Nov 22, 2024
1 parent 6a70893 commit 7d1445b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions misc-tools/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/dj_make_chroot_docker
/dj_run_chroot
/dj_judgehost_cleanup
/force-passwords
2 changes: 1 addition & 1 deletion misc-tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include $(TOPDIR)/Makefile.global
TARGETS =
OBJECTS =

SUBST_DOMSERVER = fix_permissions configure-domjudge import-contest
SUBST_DOMSERVER = fix_permissions configure-domjudge import-contest force-passwords

SUBST_JUDGEHOST = dj_make_chroot dj_run_chroot dj_make_chroot_docker \
dj_judgehost_cleanup
Expand Down
22 changes: 22 additions & 0 deletions misc-tools/force-passwords.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/python3

import subprocess

webappdir = '@domserver_webappdir@'
etcdir = '@domserver_etcdir@'

with open(f'{etcdir}/restapi.secret', 'r') as f:
while True:
line = f.readline()
if line.startswith('#'):
continue
tokens = line.split()
if len(tokens) == 4 and tokens[0] == 'default':
user = tokens[2]
password = tokens[3]
subprocess.run([webappdir + '/bin/console', 'domjudge:reset-user-password', user, password])
break

with open(f'{etcdir}/initial_admin_password.secret', 'r') as f:
password = f.readline().strip()
subprocess.run([webappdir + '/bin/console', 'domjudge:reset-user-password', 'admin', password])

0 comments on commit 7d1445b

Please sign in to comment.