Skip to content

Commit 7d1445b

Browse files
committed
Add simple script to force admin and judgehost passwords.
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.
1 parent 6a70893 commit 7d1445b

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

misc-tools/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/dj_make_chroot_docker
66
/dj_run_chroot
77
/dj_judgehost_cleanup
8+
/force-passwords

misc-tools/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include $(TOPDIR)/Makefile.global
99
TARGETS =
1010
OBJECTS =
1111

12-
SUBST_DOMSERVER = fix_permissions configure-domjudge import-contest
12+
SUBST_DOMSERVER = fix_permissions configure-domjudge import-contest force-passwords
1313

1414
SUBST_JUDGEHOST = dj_make_chroot dj_run_chroot dj_make_chroot_docker \
1515
dj_judgehost_cleanup

misc-tools/force-passwords.in

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/python3
2+
3+
import subprocess
4+
5+
webappdir = '@domserver_webappdir@'
6+
etcdir = '@domserver_etcdir@'
7+
8+
with open(f'{etcdir}/restapi.secret', 'r') as f:
9+
while True:
10+
line = f.readline()
11+
if line.startswith('#'):
12+
continue
13+
tokens = line.split()
14+
if len(tokens) == 4 and tokens[0] == 'default':
15+
user = tokens[2]
16+
password = tokens[3]
17+
subprocess.run([webappdir + '/bin/console', 'domjudge:reset-user-password', user, password])
18+
break
19+
20+
with open(f'{etcdir}/initial_admin_password.secret', 'r') as f:
21+
password = f.readline().strip()
22+
subprocess.run([webappdir + '/bin/console', 'domjudge:reset-user-password', 'admin', password])

0 commit comments

Comments
 (0)