Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions cgi-bin/link
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/python3
import cgi
import os
import re
import http.cookies

import cgitb
cgitb.enable()

def main():
path_info = os.getenv('PATH_INFO', '')

m = re.match('/(\d+)/(\d+)', path_info)
if not m:
print('\nMalformed request')
return

contest_id = int(m.group(1))
run_id = int(m.group(2))

cookies = os.getenv('HTTP_COOKIE', '')
jar = http.cookies.SimpleCookie()
jar.load(cookies)

scheme = os.getenv('REQUEST_SCHEME', 'https')
host = os.getenv('HTTP_HOST')
location = f'{scheme}://{host}/cgi-bin'

for role, script in (('admin', 'master'), ('judge', 'judge'), ('contestant', 'user')):
key = f'SID_{role}_{contest_id}'
if key in jar:
sid = jar[key].value
print(f'Location: {location}/new-{script}?SID={sid}&action=36&run_id={run_id}\n')
return
print(f'Location: {location}/new-master?contest_id={contest_id}\n')


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions include/ejudge/ej_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef long long ej_time64_t; /* time_t for new file formats */
typedef ruint32_t ej_size_t; /* size_t as stored in files */
typedef ruint32_t ej_ip4_t; /* IP address as stored in files */
typedef unsigned long long ej_cookie_t; /* cookie */
#define PRI_COOKIE "016llx"
typedef unsigned long long ej_tsc_t; /* timestamp counter type */
typedef long long ej_size64_t; /* size for use in config files, parse expressions, etc */

Expand Down
13 changes: 13 additions & 0 deletions lib/new_server_html.c
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,15 @@ ns_submit_button_2(
return buf;
}

static const char*
role_text(int role) {
switch (role) {
case USER_ROLE_ADMIN: return "admin";
case USER_ROLE_JUDGE: return "judge";
default: return "contestant";
}
}

void
ns_refresh_page(
FILE *fout,
Expand All @@ -1199,6 +1208,10 @@ ns_refresh_page(
if (phr->client_key) {
fprintf(fout, "Set-Cookie: EJSID=%016llx; Path=/; SameSite=Lax\n", phr->client_key);
}
if (phr->session_id) {
fprintf(fout, "Set-Cookie: SID_%s_%d=%" PRI_COOKIE "; Secure; SameSite=Lax; Max-Age=864000\n",
role_text(phr->role), phr->contest_id, phr->session_id);
}
fprintf(fout, "Location: %s\n\n", url);
}

Expand Down