forked from kohler/hotcrp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
92 lines (86 loc) · 3.02 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
<?php
// index.php -- HotCRP home page
// Copyright (c) 2006-2022 Eddie Kohler; see LICENSE.
require_once("lib/navigation.php");
/** @param Contact $user
* @param Qrequest $qreq
* @param string $group
* @param ComponentSet $pc */
function handle_request_components($user, $qreq, $group, $pc) {
$pc->add_xt_checker([$qreq, "xt_allow"]);
$reqgj = [];
$not_allowed = false;
foreach ($pc->members($group, "request_function") as $gj) {
if ($pc->allowed($gj->allow_request_if ?? null, $gj)) {
$reqgj[] = $gj;
} else {
$not_allowed = true;
}
}
if ($not_allowed && $qreq->is_post() && !$qreq->valid_token()) {
$user->conf->error_msg($user->conf->_i("badpost"));
}
foreach ($reqgj as $gj) {
if ($pc->call_function($gj, $gj->request_function, $gj) === false) {
break;
}
}
}
/** @param NavigationState $nav */
function handle_request($nav) {
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);
$pagej = $pc->get($nav->page);
if (!$pagej || str_starts_with($pagej->name, "__")) {
Multiconference::fail(404, "Page not found.");
} else if ($user->is_disabled() && !($pagej->allow_disabled ?? false)) {
Multiconference::fail(403, "Your account is disabled.");
} else {
$pc->set_root($pagej->group)->set_context_args([$user, $qreq, $pc]);
handle_request_components($user, $qreq, $pagej->group, $pc);
$pc->print_group($pagej->group, true);
}
} catch (Redirection $redir) {
Conf::$main->redirect($redir->url);
} catch (JsonCompletion $jc) {
$jc->result->emit();
} catch (PageCompletion $unused) {
}
}
$nav = Navigation::get();
// handle `/u/USERINDEX/`
if ($nav->page === "u") {
$unum = $nav->path_component(0);
if ($unum !== false && 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 === "iacrcopyright") {
include("iacrcopyright/index.php");
} 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);
}