forked from TFcis/SkyOnlinejudge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
60 lines (52 loc) · 1.41 KB
/
admin.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
<?php namespace SKYOJ\Admin;
if (!defined('IN_SKYOJSYSTEM')) {
exit('Access denied');
}
require_once 'function/admin/admin.lib.php';
function AdminHandle()
{
global $_E,$_G,$SkyOJ;
if (!\userControl::isAdmin($_G['uid'])) {
http_response_code(403);
header('Location: index.php');
exit(0);
}
$param = $SkyOJ->UriParam(1)??'index';
switch( $param )
{
//api
case 'api':
break;
//all left should check token!
case 'index':
checkToken();
break;
//Sub Page
case 'log':
case 'plugins':
checkToken();
break;
default:
\Render::render('nonedefined');
exit(0);
}
$funcpath = $_E['ROOT']."/function/admin/admin_$param.php";
$func = __NAMESPACE__ ."\\{$param}Handle";
require_once($funcpath);
$func();
}
function checkToken(bool $json = false)
{
global $_E;
$token = \SKYOJ\safe_post('token')??\SKYOJ\safe_get('token');
if ( \userControl::CheckToken('ADMIN_CSRF',$token)) {
assert( \userControl::getSavedToken('ADMIN_CSRF') === $token );
$_E['template']['ADMIN_CSRF'] = $token;
} else {
if( $json )
\SKYOJ\throwjson('error', 'Token 無效,請重新載入');
else
\Render::ShowMessage('Token 無效,請重新載入');
exit(0);
}
}