forked from s9y/Serendipity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serendipity_admin.php
262 lines (211 loc) · 9.17 KB
/
serendipity_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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
# Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
# All rights reserved. See LICENSE file for licensing details
define('IN_installer', true);
define('IN_upgrader', true);
define('IN_serendipity', true);
define('IN_serendipity_admin', true);
include('serendipity_config.inc.php');
header('Content-Type: text/html; charset=' . LANG_CHARSET);
if (IS_installed === false) {
require_once(S9Y_INCLUDE_PATH . 'include/functions.inc.php');
} else {
if (defined('IS_up2date') && IS_up2date === true) {
serendipity_plugin_api::hook_event('backend_configure', $serendipity);
}
}
if (isset($serendipity['GET']['adminModule']) && $serendipity['GET']['adminModule'] == 'logout') {
serendipity_logout();
header("Location: ".$serendipity['baseURL']);
} else {
if (IS_installed === true) {
/* Check author token to insure session not hijacked */
if (!isset($_SESSION['author_token']) || !isset($serendipity['COOKIE']['author_token']) ||
($_SESSION['author_token'] !== $serendipity['COOKIE']['author_token'])) {
$_SESSION['serendipityAuthedUser'] = false;
serendipity_session_destroy();
}
if (!serendipity_userLoggedIn()) {
// Try again to log in, this time with enabled external authentication event hook
serendipity_login(true);
if (serendipity_userLoggedIn()) {
// login with external authentication - reload page to set language settings correct for user
include_once S9Y_INCLUDE_PATH . 'include/functions_routing.inc.php';
gotoAdmin();
return true;
}
}
}
}
// If we are inside an iframe, halt the script
if (serendipity_is_iframe() !== false) {
include_once S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php';
// An iframe may NOT contain <html> and </html> tags, that's why we emit different headers here than on serendipity_admin.php
// We need to restore GET/POST variables to that depending plugins inside the iframe
// can still fetch all that variables; and we also tighten security by not allowing
// to pass any different GET/POST variables to our iframe.
$iframe_mode = $serendipity['GET']['iframe_mode'];
$serendipity['POST'] = &$_SESSION['save_entry_POST'];
$serendipity['GET'] = &$_SESSION['save_entry_POST']; // GET-Vars are the same as POST to ensure compatibility.
$serendipity['hidefooter'] = true;
ignore_user_abort(true);
echo serendipity_iframe($_SESSION['save_entry'], $iframe_mode);
return true;
}
if (isset($serendipity['GET']['no_smarty']) || isset($serendipity['no_smarty'])) {
$_SESSION['no_smarty'] = true;
}
if (defined('IS_up2date') && IS_up2date === true && IS_installed === true) {
$admin_installed = true;
} else {
$admin_installed = false;
}
$is_logged_in = serendipity_userLoggedIn();
if ($is_logged_in) {
$self_info = sprintf(USER_SELF_INFO, serendipity_specialchars($serendipity['serendipityUser']), $serendipity['permissionLevels'][$serendipity['serendipityUserlevel']]);
} else {
$self_info = '';
}
$serendipity['ajax'] = $ajax = (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
$no_banner = (isset($serendipity['GET']['noBanner']) || isset($serendipity['POST']['noBanner']));
$no_sidebar = (isset($serendipity['GET']['noSidebar']) || isset($serendipity['POST']['noSidebar']));
$no_footer = (isset($serendipity['GET']['noFooter']) || isset($serendipity['POST']['noFooter']));
$use_installer = (!isset($serendipity['serendipityPath']) || IS_installed === false || IS_up2date === false );
$post_action = $serendipity['POST']['action'] ?? null;
$main_content = '';
if (!$use_installer && $is_logged_in) {
if (!isset($serendipity['GET']['adminModule'])) {
$serendipity['GET']['adminModule'] = (isset($serendipity['POST']['adminModule']) ? $serendipity['POST']['adminModule'] : '');
}
ob_start();
serendipity_checkXSRF();
switch($serendipity['GET']['adminModule']) {
case 'installer':
case 'configuration':
if (!serendipity_checkPermission('siteConfiguration') && !serendipity_checkPermission('blogConfiguration')) {
break;
}
include S9Y_INCLUDE_PATH . 'include/admin/configuration.inc.php';
$admin_section = CONFIGURATION;
break;
case 'media':
case 'images':
if (!serendipity_checkPermission('adminImages')) {
break;
}
include S9Y_INCLUDE_PATH . 'include/admin/images.inc.php';
$admin_section = MEDIA;
break;
case 'templates':
if (!serendipity_checkPermission('adminTemplates')) {
break;
}
include S9Y_INCLUDE_PATH . 'include/admin/templates.inc.php';
$admin_section = MENU_TEMPLATES;
break;
case 'plugins':
if (!serendipity_checkPermission('adminPlugins')) {
break;
}
include S9Y_INCLUDE_PATH . 'include/admin/plugins.inc.php';
$admin_section = MENU_PLUGINS;
break;
case 'users':
if (!serendipity_checkPermission('adminUsers')) {
break;
}
include S9Y_INCLUDE_PATH . 'include/admin/users.inc.php';
$admin_section = MANAGE_USERS;
break;
case 'groups':
if (!serendipity_checkPermission('adminUsersGroups')) {
break;
}
include S9Y_INCLUDE_PATH . 'include/admin/groups.inc.php';
$admin_section = MANAGE_GROUPS;
break;
case 'personal':
if (!serendipity_checkPermission('personalConfiguration')) {
break;
}
include S9Y_INCLUDE_PATH . 'include/admin/personal.inc.php';
$admin_section = PERSONAL_SETTINGS;
break;
case 'import':
if (!serendipity_checkPermission('adminImport')) {
break;
}
include S9Y_INCLUDE_PATH . 'include/admin/import.inc.php';
$admin_section = IMPORT_ENTRIES;
break;
case 'entries':
if (!serendipity_checkPermission('adminEntries')) {
break;
}
include S9Y_INCLUDE_PATH . 'include/admin/entries.inc.php';
$admin_section = ADMIN_ENTRIES;
break;
case 'comments':
// perms are checked by author
include S9Y_INCLUDE_PATH . 'include/admin/comments.inc.php';
$admin_section = COMMENTS;
break;
case 'category':
case 'categories':
if (!serendipity_checkPermission('adminCategories')) {
break;
}
include S9Y_INCLUDE_PATH . 'include/admin/category.inc.php';
$admin_section = CATEGORIES;
break;
case 'logout':
echo LOGGEDOUT;
break;
case 'event_display':
if (($serendipity['no_create'] ?? false) !== true) {
serendipity_plugin_api::hook_event('backend_sidebar_entries_event_display_' . $serendipity['GET']['adminAction'], $serendipity);
}
break;
case 'maintenance':
include S9Y_INCLUDE_PATH . 'include/admin/maintenance.inc.php';
$admin_section = MENU_MAINTENANCE;
break;
default:
include S9Y_INCLUDE_PATH . 'include/admin/overview.inc.php';
$admin_section = ADMIN_FRONTPAGE;
break;
}
$main_content = ob_get_contents();
ob_end_clean();
}
if ($ajax) {
// if that is an ajax request we can stop here, since we by convention don't want to wrap the content in the usual backend code
echo $main_content;
} elseif (!$use_installer) {
$poll_admin_vars = array('main_content', 'no_banner', 'no_sidebar', 'no_footer', 'post_action', 'is_logged_in', 'admin_installed', 'self_info', 'use_installer', 'title');
$admin_vars = array();
foreach($poll_admin_vars AS $poll_admin_var) {
$admin_vars[$poll_admin_var] =& $$poll_admin_var;
}
$admin_vars['out'] = array();
$admin_vars['no_create'] = $serendipity['no_create'] ?? null;
$admin_vars['title'] = $admin_section ?? '';
$admin_vars['backendBlogtitleFirst'] = $serendipity['backendBlogtitleFirst'];
if ($serendipity['expose_s9y']) {
$admin_vars['version_info'] = sprintf(ADMIN_FOOTER_POWERED_BY, $serendipity['versionInstalled'], phpversion());
} else {
$admin_vars['version_info'] = sprintf(ADMIN_FOOTER_POWERED_BY, '', '');
}
if (!is_object($serendipity['smarty'] ?? null)) {
serendipity_smarty_init();
}
$serendipity['smarty']->assignByRef('admin_vars', $admin_vars);
$serendipity['smarty']->display(serendipity_getTemplateFile('admin/index.tpl', 'serendipityPath'));
} else {
if (IS_installed === false) {
$file = 'include/admin/installer.inc.php';
} elseif ( IS_up2date === false ) {
$file = 'include/admin/upgrader.inc.php';
}
require(S9Y_INCLUDE_PATH . $file);
}