forked from Phorum/Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
137 lines (114 loc) · 5.66 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
////////////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2011 Phorum Development Team //
// http://www.phorum.org //
// //
// This program is free software. You can redistribute it and/or modify //
// it under the terms of either the current Phorum License (viewable at //
// phorum.org) or the Phorum License that was distributed with this file //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY, without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
// //
// You should have received a copy of the Phorum License //
// along with this program. //
// //
////////////////////////////////////////////////////////////////////////////////
// Phorum 5 Admin
define("PHORUM_ADMIN", 1);
// set a sane error level for our admin.
// this will make the coding time faster and
// the code run faster.
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR );
require_once './common.php';
require_once PHORUM_PATH.'/include/admin/functions.php';
require_once PHORUM_PATH.'/include/api/buffer.php';
require_once PHORUM_PATH.'/include/api/sign.php';
require_once PHORUM_PATH.'/include/api/lang.php';
// initialized as empty
$PHORUM['admin_token']="";
if(!empty($_GET['phorum_admin_token'])) {
$PHORUM['admin_token']=$_GET['phorum_admin_token'];
} elseif(!empty($_POST['phorum_admin_token'])) {
$PHORUM['admin_token']=$_POST['phorum_admin_token'];
}
// determine absolute URI for the admin
$PHORUM["admin_http_path"] = phorum_get_current_url(false);
// determine http_path (at install time; after that it's in the settings)
if(!isset($PHORUM["http_path"])){
$PHORUM["http_path"] = dirname($_SERVER["PHP_SELF"]);
}
// A variable that can be filled for showing a notification in the
// admin header.php.
$notification = NULL;
// if we are installing or upgrading, we don't need to check for a session
// 2005081000 was the internal version that introduced the installed flag
if(!isset($PHORUM['internal_version']) || (!isset($PHORUM['installed']) && $PHORUM['internal_version']>='2005081000')) {
// this is an install
$module="install";
} elseif ( (isset($_REQUEST["module"]) && $_REQUEST["module"]=="upgrade") ||
$PHORUM['internal_version'] < PHORUM_SCHEMA_VERSION ||
!isset($PHORUM['internal_patchlevel']) ||
$PHORUM['internal_patchlevel'] < PHORUM_SCHEMA_PATCHLEVEL ) {
// this is an upgrade
$module="upgrade";
} else {
// Try to restore an admin session.
phorum_api_user_session_restore(PHORUM_ADMIN_SESSION);
if(!isset($PHORUM["user"]) || !$PHORUM["user"]["admin"]){
// if not an admin
unset($PHORUM["user"]);
$module="login";
} else {
// load the default module if none is specified
if(!empty($_REQUEST["module"]) && is_string($_REQUEST["module"])){
$module = @basename($_REQUEST["module"]);
} else {
$module = "default";
}
// Check if there are updated module information files.
// If yes, the load the information and store the data.
require_once './include/api/modules.php';
$updates = phorum_api_modules_check_updated_info();
if (!empty($updates)) {
phorum_api_modules_save();
$notification =
"Updated module info for module".(count($updates)==1?"":"s") .
(count($updates)>10 ? "" : ":" . implode(", ", $updates));
}
// Check if there are modules that require a database layer upgrade.
// If this is the case, then we will run the upgrade code in
// module upgrading mode.
$modupgrades = phorum_api_modules_check_updated_dblayer();
if (!empty($modupgrades)) {
define('MODULE_DATABASE_UPGRADE', 1);
$module = "upgrade";
}
// check the admin token
if(!empty($GLOBALS["PHORUM"]["user"]['settings_data']['admin_token']) &&
$PHORUM['admin_token'] != $GLOBALS["PHORUM"]["user"]['settings_data']['admin_token'] ||
$GLOBALS["PHORUM"]["user"]['settings_data']['admin_token_time'] <= (time()-PHORUM_ADMIN_TOKEN_TIMEOUT)) {
// 900 = timeout after 15 minutes of inactivity
// echo "invalid token or timeout ...";
// var_dump($PHORUM['admin_token'],$GLOBALS["PHORUM"]["user"]['settings_data']['admin_token'],$GLOBALS["PHORUM"]["user"]['settings_data']['admin_token_time'],(time()-PHORUM_ADMIN_TOKEN_TIMEOUT));
$PHORUM['admin_token']="";
}
if(empty($PHORUM['admin_token'])) {
$module = "tokenmissing";
} else {
// update the token time
phorum_api_user_save_settings(array(
'admin_token_time' => time()
));
}
}
}
$module = phorum_api_hook("admin_pre", $module);
phorum_api_buffer_start();
if ($module!="help") require_once './include/admin/header.php';
require_once "./include/admin/$module.php";
if ($module!="help") require_once './include/admin/footer.php';
phorum_api_buffer_flush();
?>