-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserendipity_admin.php
309 lines (257 loc) · 12.3 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?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') {
if ((serendipity_checkPermission('adminUsers') && (!isset($serendipity['maintenance']) || !serendipity_db_bool($serendipity['maintenance']))) || !serendipity_checkPermission('adminUsers')) {
serendipity_logout();
header("Location: ".$serendipity['baseURL']);
} else {
$offmesg = sprintf(PLUGIN_MODEMAINTAIN_WARNLOGOFF, 'serendipity_admin.php?serendipity[adminModule]=maintenance');
$logwarn = sprintf('<span class="msg_error"><span class="icon-attention-circled"></span> %s</span>', $offmesg);
$logoffdenied = true;
}
} 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);
}
}
}
// Check private variable to force back to light mode
if (isset($serendipity['forceLightMode']) && $serendipity['forceLightMode'] === true) {
$serendipity['smarty']->assign('forceLightMode', true);
}
// avoid posting general configuration when in maintenance mode (!)
if (isset($serendipity['POST']['adminModule']) && $serendipity['POST']['adminModule'] == 'installer' && isset($serendipity['maintenance']) && serendipity_db_bool($serendipity['maintenance'])) {
$offmesg = sprintf(PLUGIN_MODEMAINTAIN_WARNGLOBALCONFIGFORM, 'serendipity_admin.php?serendipity[adminModule]=maintenance');
$warning = sprintf('<span class="msg_error"><span class="icon-attention-circled"></span> %s</span>', $offmesg);
unset($serendipity['POST']);
unset($_POST);
$_POST['installAction'] = 'temporary_denied';
}
// 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'] ?? ''; // see ($$) poll_admin_vars
$admin_section = LOGIN;
$main_content = '';
if (!$use_installer && $is_logged_in) {
if (!isset($serendipity['GET']['adminModule'])) {
$serendipity['GET']['adminModule'] = $serendipity['POST']['adminModule'] ?? '';
}
// check for index sidebar whether any cookie stored pinned entries are set
$pinids = '';
foreach ($serendipity['COOKIE'] AS $cokey => $coval) {
if (preg_match('/^entrylist_pin_entry_(\d+)$/', $cokey, $m)) {
$pinids .= $m[1].',';
if (!isset($serendipity['matched_entry_pin'])) $serendipity['matched_entry_pin'] = $m[1]; // keep the first, for later Cookie check
} else unset($serendipity['matched_entry_pin']);
}
if (is_object($serendipity['smarty'])) {
$serendipity['smarty']->assign('pin_entries', $pinids);
}
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;
}
// temporary dev variable for non-used WebP support
if (empty($serendipity['useWebPFormat'])) {
$serendipity['useWebPFormat'] = false;
}
// temporary dev variable for non-used AVIF support
if (empty($serendipity['useAvifFormat'])) {
$serendipity['useAvifFormat'] = false;
}
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';
// check for special case plugin_to conf - do we have more of this kind?
$admin_section = (!isset($serendipity['GET']['plugin_to_conf']) || FALSE === strpos($serendipity['GET']['plugin_to_conf'], 'serendipity_event_spamblock')) ? MENU_PLUGINS : 'Spamblock Plugin Config';
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 inside
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 $logoffdenied ? $logwarn : LOGGEDOUT;
break;
case 'event_display':
if ($serendipity['no_create'] !== true) {
serendipity_plugin_api::hook_event('backend_sidebar_entries_event_display_' . $serendipity['GET']['adminAction'], $serendipity);
}
// check for special cases
$plugintabname = (!empty($serendipity['GET']['adminAction']) ? $serendipity['GET']['adminAction'] : '');
$plugintabname = ($serendipity['GET']['adminAction'] == 'managetags' ? 'freetags' : $plugintabname);
$admin_section = (!empty($plugintabname) ? ucfirst($plugintabname) . ' Plugin' : MENU_PLUGINS);
break;
case 'maintenance':
include S9Y_INCLUDE_PATH . 'include/admin/maintenance.inc.php';
$admin_section = MENU_MAINTENANCE;
break;
default:
if (isset($warning)) {
echo $warning;
break;
}
include S9Y_INCLUDE_PATH . 'include/admin/overview.inc.php';
$admin_section = ADMIN_FRONTPAGE;
break;
}
$main_content = trim(ob_get_contents()); // strip starting and ending whitespace indents brought into by ob_***() or by hooks
ob_end_clean();
}
if ($ajax) {
// if that is an ajax request we can stop here, since by convention we 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['darkmode'] = $serendipity['dark_mode'] ?? false;
$admin_vars['no_create'] = $serendipity['no_create'];
$admin_vars['title'] = $admin_section;
// The Styx default page title of backend pages is "section | SERENDIPITY_ADMIN_SUITE | blog title"
// If set to true (in serendipity_config_local.inc.php), the pages (tab) title will be
// "blog title | section | SERENDIPITY_ADMIN_SUITE" instead
$admin_vars['backendBlogtitleFirst'] = empty($serendipity['backendBlogtitleFirst']) ? false : true;
$admin_vars['right_publish'] = $serendipity['right_publish'] ?? false;
if ($serendipity['expose_s9y']) {
$admin_vars['version_info'] = sprintf(ADMIN_FOOTER_POWERED_BY, $serendipity['versionInstalled'], PHP_VERSION);
} else {
$admin_vars['version_info'] = sprintf(ADMIN_FOOTER_POWERED_BY, '', '');
}
if (!is_object($serendipity['smarty'])) {
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);
}