forked from kohler/hotcrp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
93 lines (86 loc) · 3.13 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
// index.php -- HotCRP home page
// Copyright (c) 2006-2024 Eddie Kohler; see LICENSE.
require_once("lib/navigation.php");
/** @param Contact $user
* @param Qrequest $qreq
* @param object $pagej
* @param ComponentSet $pc */
function handle_request_components($user, $qreq, $pagej, $pc) {
if (isset($pagej->request_function)
&& $pc->call_function($pagej, $pagej->request_function, $pagej) === false) {
return;
}
foreach ($pc->members($pagej->group, "request_function") as $gj) {
if (isset($gj->allow_request_if)) { /* XXX backward compat */
error_log("Warning: allow_request_if is deprecated");
if (!$pc->allowed($gj->allow_request_if, $gj))
continue;
}
if ($pc->call_function($gj, $gj->request_function, $gj) === false) {
break;
}
}
}
/** @param NavigationState $nav */
function handle_request($nav) {
$qreq = null;
try {
$conf = initialize_conf();
if ($nav->page === "api") {
API_Page::go_nav($nav, $conf);
return;
}
list($user, $qreq) = initialize_request();
$pc = $user->conf->page_components($user, $qreq);
$pagej = $pc->get($nav->page);
if (!$pagej || str_starts_with($pagej->name, "__")) {
Multiconference::fail($qreq, 404, ["link" => true], "<0>Page not found");
} else if ($user->is_disabled() && !($pagej->allow_disabled ?? false)) {
Multiconference::fail($qreq, 403, ["link" => true], $user->conf->_i("account_disabled"));
} else {
$pc->set_root($pagej->group);
handle_request_components($user, $qreq, $pagej, $pc);
$pc->print_body_members($pagej->group);
}
} catch (Redirection $redir) {
Conf::$main->redirect($redir->url);
} catch (JsonCompletion $jc) {
$jc->result->emit($qreq);
} catch (PageCompletion $unused) {
}
}
$nav = Navigation::get();
// handle OPTIONS requests, including CORS preflight
if ($_SERVER["REQUEST_METHOD"] === "OPTIONS") {
include("src/pages/p_api.php");
API_Page::go_options($nav);
}
// handle `/u/USERINDEX/`
if ($nav->page === "u") {
$unum = $nav->path_component(0);
if ($unum !== null && ctype_digit($unum)) {
if (!$nav->shift_path_components(2)) {
// redirect `/u/USERINDEX` => `/u/USERINDEX/`
Navigation::redirect_absolute("{$nav->server}{$nav->base_path}u/{$unum}/{$nav->query}");
}
} else {
// redirect `/u/XXXX` => `/`
Navigation::redirect_absolute("{$nav->server}{$nav->base_path}{$nav->query}");
}
}
// handle pages
if ($nav->page === "images" || $nav->page === "scripts" || $nav->page === "stylesheets") {
$_GET["file"] = $nav->page . $nav->path;
include("src/pages/p_cacheable.php");
Cacheable_Page::go_nav($nav);
} else if ($nav->page === "cacheable") {
include("src/pages/p_cacheable.php");
Cacheable_Page::go_nav($nav);
} else if ($nav->page === "scorechart") {
include("src/pages/p_scorechart.php");
Scorechart_Page::go_param($_GET);
} else {
require_once("src/init.php");
handle_request($nav);
}