Issues (1061)

Sources/Admin.php (1 issue)

1
<?php
2
3
/**
4
 * This file, unpredictable as this might be, handles basic administration.
5
 *
6
 * Simple Machines Forum (SMF)
7
 *
8
 * @package SMF
9
 * @author Simple Machines https://www.simplemachines.org
10
 * @copyright 2020 Simple Machines and individual contributors
11
 * @license https://www.simplemachines.org/about/smf/license.php BSD
12
 *
13
 * @version 2.1 RC2
14
 */
15
16
if (!defined('SMF'))
17
	die('No direct access...');
18
19
/**
20
 * The main admin handling function.<br>
21
 * It initialises all the basic context required for the admin center.<br>
22
 * It passes execution onto the relevant admin section.<br>
23
 * If the passed section is not found it shows the admin home page.
24
 */
25
function AdminMain()
26
{
27
	global $txt, $context, $scripturl, $modSettings, $settings;
28
	global $smcFunc, $sourcedir, $options, $boarddir;
29
30
	// Load the language and templates....
31
	loadLanguage('Admin');
32
	loadTemplate('Admin');
33
	loadJavaScriptFile('admin.js', array('minimize' => true), 'smf_admin');
34
	loadCSSFile('admin.css', array(), 'smf_admin');
35
36
	// No indexing evil stuff.
37
	$context['robot_no_index'] = true;
38
39
	require_once($sourcedir . '/Subs-Menu.php');
40
41
	// Some preferences.
42
	$context['admin_preferences'] = !empty($options['admin_preferences']) ? $smcFunc['json_decode']($options['admin_preferences'], true) : array();
43
44
	/** @var array $admin_areas Defines the menu structure for the admin center. See {@link Subs-Menu.php Subs-Menu.php} for details! */
45
	$admin_areas = array(
46
		'forum' => array(
47
			'title' => $txt['admin_main'],
48
			'permission' => array('admin_forum', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_boards', 'manage_smileys', 'manage_attachments'),
49
			'areas' => array(
50
				'index' => array(
51
					'label' => $txt['admin_center'],
52
					'function' => 'AdminHome',
53
					'icon' => 'administration',
54
				),
55
				'credits' => array(
56
					'label' => $txt['support_credits_title'],
57
					'function' => 'AdminHome',
58
					'icon' => 'support',
59
				),
60
				'news' => array(
61
					'label' => $txt['news_title'],
62
					'file' => 'ManageNews.php',
63
					'function' => 'ManageNews',
64
					'icon' => 'news',
65
					'permission' => array('edit_news', 'send_mail', 'admin_forum'),
66
					'subsections' => array(
67
						'editnews' => array($txt['admin_edit_news'], 'edit_news'),
68
						'mailingmembers' => array($txt['admin_newsletters'], 'send_mail'),
69
						'settings' => array($txt['settings'], 'admin_forum'),
70
					),
71
				),
72
				'packages' => array(
73
					'label' => $txt['package'],
74
					'file' => 'Packages.php',
75
					'function' => 'Packages',
76
					'permission' => array('admin_forum'),
77
					'icon' => 'packages',
78
					'subsections' => array(
79
						'browse' => array($txt['browse_packages']),
80
						'packageget' => array($txt['download_packages'], 'url' => $scripturl . '?action=admin;area=packages;sa=packageget;get'),
81
						'perms' => array($txt['package_file_perms']),
82
						'options' => array($txt['package_settings']),
83
					),
84
				),
85
				'search' => array(
86
					'function' => 'AdminSearch',
87
					'permission' => array('admin_forum'),
88
					'select' => 'index'
89
				),
90
				'adminlogoff' => array(
91
					'label' => $txt['admin_logoff'],
92
					'function' => 'AdminEndSession',
93
					'enabled' => empty($modSettings['securityDisable']),
94
					'icon' => 'exit',
95
				),
96
97
			),
98
		),
99
		'config' => array(
100
			'title' => $txt['admin_config'],
101
			'permission' => array('admin_forum'),
102
			'areas' => array(
103
				'featuresettings' => array(
104
					'label' => $txt['modSettings_title'],
105
					'file' => 'ManageSettings.php',
106
					'function' => 'ModifyFeatureSettings',
107
					'icon' => 'features',
108
					'subsections' => array(
109
						'basic' => array($txt['mods_cat_features']),
110
						'bbc' => array($txt['manageposts_bbc_settings']),
111
						'layout' => array($txt['mods_cat_layout']),
112
						'sig' => array($txt['signature_settings_short']),
113
						'profile' => array($txt['custom_profile_shorttitle']),
114
						'likes' => array($txt['likes']),
115
						'mentions' => array($txt['mentions']),
116
						'alerts' => array($txt['notifications']),
117
					),
118
				),
119
				'antispam' => array(
120
					'label' => $txt['antispam_title'],
121
					'file' => 'ManageSettings.php',
122
					'function' => 'ModifyAntispamSettings',
123
					'icon' => 'security',
124
				),
125
				'languages' => array(
126
					'label' => $txt['language_configuration'],
127
					'file' => 'ManageLanguages.php',
128
					'function' => 'ManageLanguages',
129
					'icon' => 'languages',
130
					'subsections' => array(
131
						'edit' => array($txt['language_edit']),
132
						'add' => array($txt['language_add']),
133
						'settings' => array($txt['language_settings']),
134
					),
135
				),
136
				'current_theme' => array(
137
					'label' => $txt['theme_current_settings'],
138
					'file' => 'Themes.php',
139
					'function' => 'ThemesMain',
140
					'custom_url' => $scripturl . '?action=admin;area=theme;sa=list;th=' . $settings['theme_id'],
141
					'icon' => 'current_theme',
142
				),
143
				'theme' => array(
144
					'label' => $txt['theme_admin'],
145
					'file' => 'Themes.php',
146
					'function' => 'ThemesMain',
147
					'custom_url' => $scripturl . '?action=admin;area=theme',
148
					'icon' => 'themes',
149
					'subsections' => array(
150
						'admin' => array($txt['themeadmin_admin_title']),
151
						'list' => array($txt['themeadmin_list_title']),
152
						'reset' => array($txt['themeadmin_reset_title']),
153
						'edit' => array($txt['themeadmin_edit_title']),
154
					),
155
				),
156
				'modsettings' => array(
157
					'label' => $txt['admin_modifications'],
158
					'file' => 'ManageSettings.php',
159
					'function' => 'ModifyModSettings',
160
					'icon' => 'modifications',
161
					'subsections' => array(
162
						'general' => array($txt['mods_cat_modifications_misc']),
163
						// Mod Authors for a "ADD AFTER" on this line. Ensure you end your change with a comma. For example:
164
						// 'shout' => array($txt['shout']),
165
						// Note the comma!! The setting with automatically appear with the first mod to be added.
166
					),
167
				),
168
			),
169
		),
170
		'layout' => array(
171
			'title' => $txt['layout_controls'],
172
			'permission' => array('manage_boards', 'admin_forum', 'manage_smileys', 'manage_attachments', 'moderate_forum'),
173
			'areas' => array(
174
				'manageboards' => array(
175
					'label' => $txt['admin_boards'],
176
					'file' => 'ManageBoards.php',
177
					'function' => 'ManageBoards',
178
					'icon' => 'boards',
179
					'permission' => array('manage_boards'),
180
					'subsections' => array(
181
						'main' => array($txt['boards_edit']),
182
						'newcat' => array($txt['mboards_new_cat']),
183
						'settings' => array($txt['settings'], 'admin_forum'),
184
					),
185
				),
186
				'postsettings' => array(
187
					'label' => $txt['manageposts'],
188
					'file' => 'ManagePosts.php',
189
					'function' => 'ManagePostSettings',
190
					'permission' => array('admin_forum'),
191
					'icon' => 'posts',
192
					'subsections' => array(
193
						'posts' => array($txt['manageposts_settings']),
194
						'censor' => array($txt['admin_censored_words']),
195
						'topics' => array($txt['manageposts_topic_settings']),
196
						'drafts' => array($txt['manage_drafts']),
197
					),
198
				),
199
				'managecalendar' => array(
200
					'label' => $txt['manage_calendar'],
201
					'file' => 'ManageCalendar.php',
202
					'function' => 'ManageCalendar',
203
					'icon' => 'calendar',
204
					'permission' => array('admin_forum'),
205
					'inactive' => empty($modSettings['cal_enabled']),
206
					'subsections' => empty($modSettings['cal_enabled']) ? array() : array(
207
						'holidays' => array($txt['manage_holidays'], 'admin_forum'),
208
						'settings' => array($txt['calendar_settings'], 'admin_forum'),
209
					),
210
				),
211
				'managesearch' => array(
212
					'label' => $txt['manage_search'],
213
					'file' => 'ManageSearch.php',
214
					'function' => 'ManageSearch',
215
					'icon' => 'search',
216
					'permission' => array('admin_forum'),
217
					'subsections' => array(
218
						'weights' => array($txt['search_weights']),
219
						'method' => array($txt['search_method']),
220
						'settings' => array($txt['settings']),
221
					),
222
				),
223
				'smileys' => array(
224
					'label' => $txt['smileys_manage'],
225
					'file' => 'ManageSmileys.php',
226
					'function' => 'ManageSmileys',
227
					'icon' => 'smiley',
228
					'permission' => array('manage_smileys'),
229
					'subsections' => array(
230
						'editsets' => array($txt['smiley_sets']),
231
						'addsmiley' => array($txt['smileys_add'], 'enabled' => !empty($modSettings['smiley_enable'])),
232
						'editsmileys' => array($txt['smileys_edit'], 'enabled' => !empty($modSettings['smiley_enable'])),
233
						'setorder' => array($txt['smileys_set_order'], 'enabled' => !empty($modSettings['smiley_enable'])),
234
						'editicons' => array($txt['icons_edit_message_icons'], 'enabled' => !empty($modSettings['messageIcons_enable'])),
235
						'settings' => array($txt['settings']),
236
					),
237
				),
238
				'manageattachments' => array(
239
					'label' => $txt['attachments_avatars'],
240
					'file' => 'ManageAttachments.php',
241
					'function' => 'ManageAttachments',
242
					'icon' => 'attachment',
243
					'permission' => array('manage_attachments'),
244
					'subsections' => array(
245
						'browse' => array($txt['attachment_manager_browse']),
246
						'attachments' => array($txt['attachment_manager_settings']),
247
						'avatars' => array($txt['attachment_manager_avatar_settings']),
248
						'attachpaths' => array($txt['attach_directories']),
249
						'maintenance' => array($txt['attachment_manager_maintenance']),
250
					),
251
				),
252
				'sengines' => array(
253
					'label' => $txt['search_engines'],
254
					'inactive' => empty($modSettings['spider_mode']),
255
					'file' => 'ManageSearchEngines.php',
256
					'icon' => 'engines',
257
					'function' => 'SearchEngines',
258
					'permission' => 'admin_forum',
259
					'subsections' => empty($modSettings['spider_mode']) ? array() : array(
260
						'stats' => array($txt['spider_stats']),
261
						'logs' => array($txt['spider_logs']),
262
						'spiders' => array($txt['spiders']),
263
						'settings' => array($txt['settings']),
264
					),
265
				),
266
			),
267
		),
268
		'members' => array(
269
			'title' => $txt['admin_manage_members'],
270
			'permission' => array('moderate_forum', 'manage_membergroups', 'manage_bans', 'manage_permissions', 'admin_forum'),
271
			'areas' => array(
272
				'viewmembers' => array(
273
					'label' => $txt['admin_users'],
274
					'file' => 'ManageMembers.php',
275
					'function' => 'ViewMembers',
276
					'icon' => 'members',
277
					'permission' => array('moderate_forum'),
278
					'subsections' => array(
279
						'all' => array($txt['view_all_members']),
280
						'search' => array($txt['mlist_search']),
281
					),
282
				),
283
				'membergroups' => array(
284
					'label' => $txt['admin_groups'],
285
					'file' => 'ManageMembergroups.php',
286
					'function' => 'ModifyMembergroups',
287
					'icon' => 'membergroups',
288
					'permission' => array('manage_membergroups'),
289
					'subsections' => array(
290
						'index' => array($txt['membergroups_edit_groups'], 'manage_membergroups'),
291
						'add' => array($txt['membergroups_new_group'], 'manage_membergroups'),
292
						'settings' => array($txt['settings'], 'admin_forum'),
293
					),
294
				),
295
				'permissions' => array(
296
					'label' => $txt['edit_permissions'],
297
					'file' => 'ManagePermissions.php',
298
					'function' => 'ModifyPermissions',
299
					'icon' => 'permissions',
300
					'permission' => array('manage_permissions'),
301
					'subsections' => array(
302
						'index' => array($txt['permissions_groups'], 'manage_permissions'),
303
						'board' => array($txt['permissions_boards'], 'manage_permissions'),
304
						'profiles' => array($txt['permissions_profiles'], 'manage_permissions'),
305
						'postmod' => array($txt['permissions_post_moderation'], 'manage_permissions'),
306
						'settings' => array($txt['settings'], 'admin_forum'),
307
					),
308
				),
309
				'regcenter' => array(
310
					'label' => $txt['registration_center'],
311
					'file' => 'ManageRegistration.php',
312
					'function' => 'RegCenter',
313
					'icon' => 'regcenter',
314
					'permission' => array('admin_forum', 'moderate_forum'),
315
					'subsections' => array(
316
						'register' => array($txt['admin_browse_register_new'], 'moderate_forum'),
317
						'agreement' => array($txt['registration_agreement'], 'admin_forum'),
318
						'reservednames' => array($txt['admin_reserved_set'], 'admin_forum'),
319
						'settings' => array($txt['settings'], 'admin_forum'),
320
					),
321
				),
322
				'warnings' => array(
323
					'label' => $txt['warnings'],
324
					'file' => 'ManageSettings.php',
325
					'function' => 'ModifyWarningSettings',
326
					'icon' => 'warning',
327
					'inactive' => $modSettings['warning_settings'][0] == 0,
328
					'permission' => array('admin_forum'),
329
				),
330
				'ban' => array(
331
					'label' => $txt['ban_title'],
332
					'file' => 'ManageBans.php',
333
					'function' => 'Ban',
334
					'icon' => 'ban',
335
					'permission' => 'manage_bans',
336
					'subsections' => array(
337
						'list' => array($txt['ban_edit_list']),
338
						'add' => array($txt['ban_add_new']),
339
						'browse' => array($txt['ban_trigger_browse']),
340
						'log' => array($txt['ban_log']),
341
					),
342
				),
343
				'paidsubscribe' => array(
344
					'label' => $txt['paid_subscriptions'],
345
					'inactive' => empty($modSettings['paid_enabled']),
346
					'file' => 'ManagePaid.php',
347
					'icon' => 'paid',
348
					'function' => 'ManagePaidSubscriptions',
349
					'permission' => 'admin_forum',
350
					'subsections' => empty($modSettings['paid_enabled']) ? array() : array(
351
						'view' => array($txt['paid_subs_view']),
352
						'settings' => array($txt['settings']),
353
					),
354
				),
355
			),
356
		),
357
		'maintenance' => array(
358
			'title' => $txt['admin_maintenance'],
359
			'permission' => array('admin_forum'),
360
			'areas' => array(
361
				'serversettings' => array(
362
					'label' => $txt['admin_server_settings'],
363
					'file' => 'ManageServer.php',
364
					'function' => 'ModifySettings',
365
					'icon' => 'server',
366
					'subsections' => array(
367
						'general' => array($txt['general_settings']),
368
						'database' => array($txt['database_settings']),
369
						'cookie' => array($txt['cookies_sessions_settings']),
370
						'security' => array($txt['security_settings']),
371
						'cache' => array($txt['caching_settings']),
372
						'export' => array($txt['export_settings']),
373
						'loads' => array($txt['load_balancing_settings']),
374
						'phpinfo' => array($txt['phpinfo_settings']),
375
					),
376
				),
377
				'maintain' => array(
378
					'label' => $txt['maintain_title'],
379
					'file' => 'ManageMaintenance.php',
380
					'icon' => 'maintain',
381
					'function' => 'ManageMaintenance',
382
					'subsections' => array(
383
						'routine' => array($txt['maintain_sub_routine'], 'admin_forum'),
384
						'database' => array($txt['maintain_sub_database'], 'admin_forum'),
385
						'members' => array($txt['maintain_sub_members'], 'admin_forum'),
386
						'topics' => array($txt['maintain_sub_topics'], 'admin_forum'),
387
						'hooks' => array($txt['hooks_title_list'], 'admin_forum'),
388
					),
389
				),
390
				'scheduledtasks' => array(
391
					'label' => $txt['maintain_tasks'],
392
					'file' => 'ManageScheduledTasks.php',
393
					'icon' => 'scheduled',
394
					'function' => 'ManageScheduledTasks',
395
					'subsections' => array(
396
						'tasks' => array($txt['maintain_tasks'], 'admin_forum'),
397
						'tasklog' => array($txt['scheduled_log'], 'admin_forum'),
398
						'settings' => array($txt['scheduled_tasks_settings'], 'admin_forum'),
399
					),
400
				),
401
				'mailqueue' => array(
402
					'label' => $txt['mailqueue_title'],
403
					'file' => 'ManageMail.php',
404
					'function' => 'ManageMail',
405
					'icon' => 'mail',
406
					'subsections' => array(
407
						'browse' => array($txt['mailqueue_browse'], 'admin_forum'),
408
						'settings' => array($txt['mailqueue_settings'], 'admin_forum'),
409
						'test' => array($txt['mailqueue_test'], 'admin_forum'),
410
					),
411
				),
412
				'reports' => array(
413
					'label' => $txt['generate_reports'],
414
					'file' => 'Reports.php',
415
					'function' => 'ReportsMain',
416
					'icon' => 'reports',
417
				),
418
				'logs' => array(
419
					'label' => $txt['logs'],
420
					'function' => 'AdminLogs',
421
					'icon' => 'logs',
422
					'subsections' => array(
423
						'errorlog' => array($txt['errorlog'], 'admin_forum', 'enabled' => !empty($modSettings['enableErrorLogging']), 'url' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc'),
424
						'adminlog' => array($txt['admin_log'], 'admin_forum', 'enabled' => !empty($modSettings['adminlog_enabled'])),
425
						'modlog' => array($txt['moderation_log'], 'admin_forum', 'enabled' => !empty($modSettings['modlog_enabled'])),
426
						'banlog' => array($txt['ban_log'], 'manage_bans'),
427
						'spiderlog' => array($txt['spider_logs'], 'admin_forum', 'enabled' => !empty($modSettings['spider_mode'])),
428
						'tasklog' => array($txt['scheduled_log'], 'admin_forum'),
429
						'settings' => array($txt['log_settings'], 'admin_forum'),
430
					),
431
				),
432
				'repairboards' => array(
433
					'label' => $txt['admin_repair'],
434
					'file' => 'RepairBoards.php',
435
					'function' => 'RepairBoards',
436
					'select' => 'maintain',
437
					'hidden' => true,
438
				),
439
			),
440
		),
441
	);
442
443
	// Any files to include for administration?
444
	if (!empty($modSettings['integrate_admin_include']))
445
	{
446
		$admin_includes = explode(',', $modSettings['integrate_admin_include']);
447
		foreach ($admin_includes as $include)
448
		{
449
			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
450
			if (file_exists($include))
451
				require_once($include);
452
		}
453
	}
454
455
	// Make sure the administrator has a valid session...
456
	validateSession();
457
458
	// Actually create the menu!
459
	$admin_include_data = createMenu($admin_areas, array('do_big_icons' => true));
460
	unset($admin_areas);
461
462
	// Nothing valid?
463
	if ($admin_include_data == false)
464
		fatal_lang_error('no_access', false);
465
466
	// Build the link tree.
467
	$context['linktree'][] = array(
468
		'url' => $scripturl . '?action=admin',
469
		'name' => $txt['admin_center'],
470
	);
471
	if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index')
472
		$context['linktree'][] = array(
473
			'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'],
474
			'name' => $admin_include_data['label'],
475
		);
476
	if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label'])
477
		$context['linktree'][] = array(
478
			'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'],
479
			'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0],
480
		);
481
482
	// Make a note of the Unique ID for this menu.
483
	$context['admin_menu_id'] = $context['max_menu_id'];
484
	$context['admin_menu_name'] = 'menu_data_' . $context['admin_menu_id'];
485
486
	// Where in the admin are we?
487
	$context['admin_area'] = $admin_include_data['current_area'];
488
489
	// Now - finally - call the right place!
490
	if (isset($admin_include_data['file']))
491
		require_once($sourcedir . '/' . $admin_include_data['file']);
492
493
	// Get the right callable.
494
	$call = call_helper($admin_include_data['function'], true);
495
496
	// Is it valid?
497
	if (!empty($call))
498
		call_user_func($call);
499
}
500
501
/**
502
 * The main administration section.
503
 * It prepares all the data necessary for the administration front page.
504
 * It uses the Admin template along with the admin sub template.
505
 * It requires the moderate_forum, manage_membergroups, manage_bans,
506
 *  admin_forum, manage_permissions, manage_attachments, manage_smileys,
507
 *  manage_boards, edit_news, or send_mail permission.
508
 *  It uses the index administrative area.
509
 *  It can be found by going to ?action=admin.
510
 */
511
function AdminHome()
512
{
513
	global $sourcedir, $txt, $scripturl, $context, $user_info;
514
515
	// You have to be able to do at least one of the below to see this page.
516
	isAllowedTo(array('admin_forum', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_boards', 'manage_smileys', 'manage_attachments'));
517
518
	// Find all of this forum's administrators...
519
	require_once($sourcedir . '/Subs-Membergroups.php');
520
	if (listMembergroupMembers_Href($context['administrators'], 1, 32) && allowedTo('manage_membergroups'))
521
	{
522
		// Add a 'more'-link if there are more than 32.
523
		$context['more_admins_link'] = '<a href="' . $scripturl . '?action=moderate;area=viewgroups;sa=members;group=1">' . $txt['more'] . '</a>';
524
	}
525
526
	// Load the credits stuff.
527
	require_once($sourcedir . '/Who.php');
528
	Credits(true);
529
530
	// This makes it easier to get the latest news with your time format.
531
	$context['time_format'] = urlencode($user_info['time_format']);
532
	$context['forum_version'] = SMF_FULL_VERSION;
533
534
	// Get a list of current server versions.
535
	require_once($sourcedir . '/Subs-Admin.php');
536
	$checkFor = array(
537
		'gd',
538
		'imagemagick',
539
		'db_server',
540
		'apc',
541
		'apcu',
542
		'memcache',
543
		'memcached',
544
		'xcache',
545
		'php',
546
		'server',
547
	);
548
	$context['current_versions'] = getServerVersions($checkFor);
549
550
	$context['can_admin'] = allowedTo('admin_forum');
551
552
	$context['sub_template'] = $context['admin_area'] == 'credits' ? 'credits' : 'admin';
553
	$context['page_title'] = $context['admin_area'] == 'credits' ? $txt['support_credits_title'] : $txt['admin_center'];
554
	if ($context['admin_area'] != 'credits')
555
		$context[$context['admin_menu_name']]['tab_data'] = array(
556
			'title' => $txt['admin_center'],
557
			'help' => '',
558
			'description' => '<strong>' . $txt['hello_guest'] . ' ' . $context['user']['name'] . '!</strong>
559
				' . sprintf($txt['admin_main_welcome'], $txt['admin_center'], $txt['help'], $txt['help']),
560
		);
561
562
	// Lastly, fill in the blanks in the support resources paragraphs.
563
	$txt['support_resources_p1'] = sprintf($txt['support_resources_p1'],
564
		'https://wiki.simplemachines.org/',
565
		'https://wiki.simplemachines.org/smf/features2',
566
		'https://wiki.simplemachines.org/smf/options2',
567
		'https://wiki.simplemachines.org/smf/themes2',
568
		'https://wiki.simplemachines.org/smf/packages2'
569
	);
570
	$txt['support_resources_p2'] = sprintf($txt['support_resources_p2'],
571
		'https://www.simplemachines.org/community/',
572
		'https://www.simplemachines.org/redirect/english_support',
573
		'https://www.simplemachines.org/redirect/international_support_boards',
574
		'https://www.simplemachines.org/redirect/smf_support',
575
		'https://www.simplemachines.org/redirect/customize_support'
576
	);
577
578
	if ($context['admin_area'] == 'admin')
579
		loadJavaScriptFile('admin.js', array('defer' => false, 'minimize' => true), 'smf_admin');
580
}
581
582
/**
583
 * Get one of the admin information files from Simple Machines.
584
 */
585
function DisplayAdminFile()
586
{
587
	global $context, $modSettings, $smcFunc;
588
589
	setMemoryLimit('32M');
590
591
	if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename']))
592
		fatal_lang_error('no_access', false);
593
594
	// Strip off the forum cache part or we won't find it...
595
	$_REQUEST['filename'] = str_replace($context['browser_cache'], '', $_REQUEST['filename']);
596
597
	$request = $smcFunc['db_query']('', '
598
		SELECT data, filetype
599
		FROM {db_prefix}admin_info_files
600
		WHERE filename = {string:current_filename}
601
		LIMIT 1',
602
		array(
603
			'current_filename' => $_REQUEST['filename'],
604
		)
605
	);
606
607
	if ($smcFunc['db_num_rows']($request) == 0)
608
		fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404);
609
610
	list ($file_data, $filetype) = $smcFunc['db_fetch_row']($request);
611
	$smcFunc['db_free_result']($request);
612
613
	// @todo Temp
614
	// Figure out if sesc is still being used.
615
	if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript')
616
		$file_data = '
617
if (!(\'smfForum_sessionvar\' in window))
618
	window.smfForum_sessionvar = \'sesc\';
619
' . strtr($file_data, array(';sesc=' => ';\' + window.smfForum_sessionvar + \'='));
620
621
	$context['template_layers'] = array();
622
	// Lets make sure we aren't going to output anything nasty.
623
	@ob_end_clean();
624
	if (!empty($modSettings['enableCompressedOutput']))
625
		@ob_start('ob_gzhandler');
626
	else
627
		@ob_start();
628
629
	// Make sure they know what type of file we are.
630
	header('content-type: ' . $filetype);
631
	echo $file_data;
632
	obExit(false);
633
}
634
635
/**
636
 * This function allocates out all the search stuff.
637
 */
638
function AdminSearch()
639
{
640
	global $txt, $context, $smcFunc, $sourcedir;
641
642
	isAllowedTo('admin_forum');
643
644
	// What can we search for?
645
	$subActions = array(
646
		'internal' => 'AdminSearchInternal',
647
		'online' => 'AdminSearchOM',
648
		'member' => 'AdminSearchMember',
649
	);
650
651
	$context['search_type'] = !isset($_REQUEST['search_type']) || !isset($subActions[$_REQUEST['search_type']]) ? 'internal' : $_REQUEST['search_type'];
652
	$context['search_term'] = isset($_REQUEST['search_term']) ? $smcFunc['htmlspecialchars']($_REQUEST['search_term'], ENT_QUOTES) : '';
653
654
	$context['sub_template'] = 'admin_search_results';
655
	$context['page_title'] = $txt['admin_search_results'];
656
657
	// Keep track of what the admin wants.
658
	if (empty($context['admin_preferences']['sb']) || $context['admin_preferences']['sb'] != $context['search_type'])
659
	{
660
		$context['admin_preferences']['sb'] = $context['search_type'];
661
662
		// Update the preferences.
663
		require_once($sourcedir . '/Subs-Admin.php');
664
		updateAdminPreferences();
665
	}
666
667
	if (trim($context['search_term']) == '')
668
		$context['search_results'] = array();
669
	else
670
		call_helper($subActions[$context['search_type']]);
671
}
672
673
/**
674
 * A complicated but relatively quick internal search.
675
 */
676
function AdminSearchInternal()
677
{
678
	global $context, $txt, $helptxt, $scripturl, $sourcedir;
679
680
	// Try to get some more memory.
681
	setMemoryLimit('128M');
682
683
	// Load a lot of language files.
684
	$language_files = array(
685
		'Help', 'ManageMail', 'ManageSettings', 'ManageCalendar', 'ManageBoards', 'ManagePaid', 'ManagePermissions', 'Search',
686
		'Login', 'ManageSmileys', 'Drafts',
687
	);
688
689
	// All the files we need to include.
690
	$include_files = array(
691
		'ManageSettings', 'ManageBoards', 'ManageNews', 'ManageAttachments', 'ManageCalendar', 'ManageMail', 'ManagePaid', 'ManagePermissions',
692
		'ManagePosts', 'ManageRegistration', 'ManageSearch', 'ManageSearchEngines', 'ManageServer', 'ManageSmileys', 'ManageLanguages',
693
	);
694
695
	// This is a special array of functions that contain setting data - we query all these to simply pull all setting bits!
696
	$settings_search = array(
697
		array('ModifyBasicSettings', 'area=featuresettings;sa=basic'),
698
		array('ModifyBBCSettings', 'area=featuresettings;sa=bbc'),
699
		array('ModifyLayoutSettings', 'area=featuresettings;sa=layout'),
700
		array('ModifyLikesSettings', 'area=featuresettings;sa=likes'),
701
		array('ModifyMentionsSettings', 'area=featuresettings;sa=mentions'),
702
		array('ModifySignatureSettings', 'area=featuresettings;sa=sig'),
703
		array('ModifyAntispamSettings', 'area=antispam'),
704
		array('ModifyWarningSettings', 'area=warnings'),
705
		array('ModifyGeneralModSettings', 'area=modsettings;sa=general'),
706
		// Mod authors if you want to be "real freaking good" then add any setting pages for your mod BELOW this line!
707
		array('ManageAttachmentSettings', 'area=manageattachments;sa=attachments'),
708
		array('ManageAvatarSettings', 'area=manageattachments;sa=avatars'),
709
		array('ModifyCalendarSettings', 'area=managecalendar;sa=settings'),
710
		array('EditBoardSettings', 'area=manageboards;sa=settings'),
711
		array('ModifyMailSettings', 'area=mailqueue;sa=settings'),
712
		array('ModifyNewsSettings', 'area=news;sa=settings'),
713
		array('GeneralPermissionSettings', 'area=permissions;sa=settings'),
714
		array('ModifyPostSettings', 'area=postsettings;sa=posts'),
715
		array('ModifyTopicSettings', 'area=postsettings;sa=topics'),
716
		array('ModifyDraftSettings', 'area=postsettings;sa=drafts'),
717
		array('EditSearchSettings', 'area=managesearch;sa=settings'),
718
		array('EditSmileySettings', 'area=smileys;sa=settings'),
719
		array('ModifyGeneralSettings', 'area=serversettings;sa=general'),
720
		array('ModifyDatabaseSettings', 'area=serversettings;sa=database'),
721
		array('ModifyCookieSettings', 'area=serversettings;sa=cookie'),
722
		array('ModifyGeneralSecuritySettings', 'area=serversettings;sa=security'),
723
		array('ModifyCacheSettings', 'area=serversettings;sa=cache'),
724
		array('ModifyLanguageSettings', 'area=languages;sa=settings'),
725
		array('ModifyRegistrationSettings', 'area=regcenter;sa=settings'),
726
		array('ManageSearchEngineSettings', 'area=sengines;sa=settings'),
727
		array('ModifySubscriptionSettings', 'area=paidsubscribe;sa=settings'),
728
		array('ModifyLogSettings', 'area=logs;sa=settings'),
729
	);
730
731
	call_integration_hook('integrate_admin_search', array(&$language_files, &$include_files, &$settings_search));
732
733
	loadLanguage(implode('+', $language_files));
734
735
	foreach ($include_files as $file)
736
		require_once($sourcedir . '/' . $file . '.php');
737
738
	/* This is the huge array that defines everything... it's a huge array of items formatted as follows:
739
		0 = Language index (Can be array of indexes) to search through for this setting.
740
		1 = URL for this indexes page.
741
		2 = Help index for help associated with this item (If different from 0)
742
	*/
743
744
	$search_data = array(
745
		// All the major sections of the forum.
746
		'sections' => array(
747
		),
748
		'settings' => array(
749
			array('COPPA', 'area=regcenter;sa=settings'),
750
			array('CAPTCHA', 'area=antispam'),
751
		),
752
	);
753
754
	// Go through the admin menu structure trying to find suitably named areas!
755
	foreach ($context[$context['admin_menu_name']]['sections'] as $section)
756
	{
757
		foreach ($section['areas'] as $menu_key => $menu_item)
758
		{
759
			$search_data['sections'][] = array($menu_item['label'], 'area=' . $menu_key);
760
			if (!empty($menu_item['subsections']))
761
				foreach ($menu_item['subsections'] as $key => $sublabel)
762
				{
763
					if (isset($sublabel['label']))
764
						$search_data['sections'][] = array($sublabel['label'], 'area=' . $menu_key . ';sa=' . $key);
765
				}
766
		}
767
	}
768
769
	foreach ($settings_search as $setting_area)
770
	{
771
		// Get a list of their variables.
772
		$config_vars = call_user_func($setting_area[0], true);
773
774
		foreach ($config_vars as $var)
775
			if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc')))
776
				$search_data['settings'][] = array($var[(isset($var[2]) && in_array($var[2], array('file', 'db'))) ? 0 : 1], $setting_area[1], 'alttxt' => (isset($var[2]) && in_array($var[2], array('file', 'db'))) || isset($var[3]) ? (in_array($var[2], array('file', 'db')) ? $var[1] : $var[3]) : '');
777
	}
778
779
	$context['page_title'] = $txt['admin_search_results'];
780
	$context['search_results'] = array();
781
782
	$search_term = strtolower(un_htmlspecialchars($context['search_term']));
783
	// Go through all the search data trying to find this text!
784
	foreach ($search_data as $section => $data)
785
	{
786
		foreach ($data as $item)
787
		{
788
			$found = false;
789
			if (!is_array($item[0]))
790
				$item[0] = array($item[0]);
791
			foreach ($item[0] as $term)
792
			{
793
				if (stripos($term, $search_term) !== false || (isset($txt[$term]) && stripos($txt[$term], $search_term) !== false) || (isset($txt['setting_' . $term]) && stripos($txt['setting_' . $term], $search_term) !== false))
794
				{
795
					$found = $term;
796
					break;
797
				}
798
			}
799
800
			if ($found)
801
			{
802
				// Format the name - and remove any descriptions the entry may have.
803
				$name = isset($txt[$found]) ? $txt[$found] : (isset($txt['setting_' . $found]) ? $txt['setting_' . $found] : (!empty($item['alttxt']) ? $item['alttxt'] : $found));
804
				$name = preg_replace('~<(?:div|span)\sclass="smalltext">.+?</(?:div|span)>~', '', $name);
805
806
				$context['search_results'][] = array(
807
					'url' => (substr($item[1], 0, 4) == 'area' ? $scripturl . '?action=admin;' . $item[1] : $item[1]) . ';' . $context['session_var'] . '=' . $context['session_id'] . ((substr($item[1], 0, 4) == 'area' && $section == 'settings' ? '#' . $item[0][0] : '')),
808
					'name' => $name,
809
					'type' => $section,
810
					'help' => shorten_subject(isset($item[2]) ? strip_tags($helptxt[$item[2]]) : (isset($helptxt[$found]) ? strip_tags($helptxt[$found]) : ''), 255),
811
				);
812
			}
813
		}
814
	}
815
}
816
817
/**
818
 * All this does is pass through to manage members.
819
 * {@see ViewMembers()}
820
 */
821
function AdminSearchMember()
822
{
823
	global $context, $sourcedir;
824
825
	require_once($sourcedir . '/ManageMembers.php');
826
	$_REQUEST['sa'] = 'query';
827
828
	$_POST['membername'] = un_htmlspecialchars($context['search_term']);
829
	$_POST['types'] = '';
830
831
	ViewMembers();
832
}
833
834
/**
835
 * This file allows the user to search the SM online manual for a little of help.
836
 */
837
function AdminSearchOM()
838
{
839
	global $context, $sourcedir;
840
841
	$context['doc_apiurl'] = 'https://wiki.simplemachines.org/api.php';
842
	$context['doc_scripturl'] = 'https://wiki.simplemachines.org/smf/';
843
844
	// Set all the parameters search might expect.
845
	$postVars = explode(' ', $context['search_term']);
846
847
	// Encode the search data.
848
	foreach ($postVars as $k => $v)
849
		$postVars[$k] = urlencode($v);
850
851
	// This is what we will send.
852
	$postVars = implode('+', $postVars);
853
854
	// Get the results from the doc site.
855
	// Demo URL:
856
	// https://wiki.simplemachines.org/api.php?action=query&list=search&srprop=timestamp|snippet&format=xml&srwhat=text&srsearch=template+eval
857
	$search_results = fetch_web_data($context['doc_apiurl'] . '?action=query&list=search&srprop=timestamp|snippet&format=xml&srwhat=text&srsearch=' . $postVars);
858
859
	// If we didn't get any xml back we are in trouble - perhaps the doc site is overloaded?
860
	if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api\b[^>]*>.+?</api>)~is', $search_results, $matches) != true)
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('~<' . '\?xml...arch_results, $matches) of type integer to the boolean true. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
861
		fatal_lang_error('cannot_connect_doc_site');
862
863
	$search_results = $matches[1];
864
865
	// Otherwise we simply walk through the XML and stick it in context for display.
866
	$context['search_results'] = array();
867
	require_once($sourcedir . '/Class-Package.php');
868
869
	// Get the results loaded into an array for processing!
870
	$results = new xmlArray($search_results, false);
871
872
	// Move through the api layer.
873
	if (!$results->exists('api'))
874
		fatal_lang_error('cannot_connect_doc_site');
875
876
	// Are there actually some results?
877
	if ($results->exists('api/query/search/p'))
878
	{
879
		$relevance = 0;
880
		foreach ($results->set('api/query/search/p') as $result)
881
		{
882
			$context['search_results'][$result->fetch('@title')] = array(
883
				'title' => $result->fetch('@title'),
884
				'relevance' => $relevance++,
885
				'snippet' => str_replace('class=\'searchmatch\'', 'class="highlight"', un_htmlspecialchars($result->fetch('@snippet'))),
886
			);
887
		}
888
	}
889
}
890
891
/**
892
 * This function decides which log to load.
893
 */
894
function AdminLogs()
895
{
896
	global $sourcedir, $context, $txt, $scripturl, $modSettings;
897
898
	// These are the logs they can load.
899
	$log_functions = array(
900
		'errorlog' => array('ManageErrors.php', 'ViewErrorLog'),
901
		'adminlog' => array('Modlog.php', 'ViewModlog', 'disabled' => empty($modSettings['adminlog_enabled'])),
902
		'modlog' => array('Modlog.php', 'ViewModlog', 'disabled' => empty($modSettings['modlog_enabled'])),
903
		'banlog' => array('ManageBans.php', 'BanLog'),
904
		'spiderlog' => array('ManageSearchEngines.php', 'SpiderLogs'),
905
		'tasklog' => array('ManageScheduledTasks.php', 'TaskLog'),
906
		'settings' => array('ManageSettings.php', 'ModifyLogSettings'),
907
	);
908
909
	// If it's not got a sa set it must have come here for first time, pretend error log should be reversed.
910
	if (!isset($_REQUEST['sa']))
911
		$_REQUEST['desc'] = true;
912
913
	// Setup some tab stuff.
914
	$context[$context['admin_menu_name']]['tab_data'] = array(
915
		'title' => $txt['logs'],
916
		'help' => '',
917
		'description' => $txt['maintain_info'],
918
		'tabs' => array(
919
			'errorlog' => array(
920
				'url' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc',
921
				'description' => sprintf($txt['errorlog_desc'], $txt['remove']),
922
			),
923
			'adminlog' => array(
924
				'description' => $txt['admin_log_desc'],
925
			),
926
			'modlog' => array(
927
				'description' => $txt['moderation_log_desc'],
928
			),
929
			'banlog' => array(
930
				'description' => $txt['ban_log_description'],
931
			),
932
			'spiderlog' => array(
933
				'description' => $txt['spider_log_desc'],
934
			),
935
			'tasklog' => array(
936
				'description' => $txt['scheduled_log_desc'],
937
			),
938
			'settings' => array(
939
				'description' => $txt['log_settings_desc'],
940
			),
941
		),
942
	);
943
944
	call_integration_hook('integrate_manage_logs', array(&$log_functions));
945
946
	$subAction = isset($_REQUEST['sa']) && isset($log_functions[$_REQUEST['sa']]) && empty($log_functions[$_REQUEST['sa']]['disabled']) ? $_REQUEST['sa'] : 'errorlog';
947
948
	require_once($sourcedir . '/' . $log_functions[$subAction][0]);
949
	call_helper($log_functions[$subAction][1]);
950
}
951
952
/**
953
 * This ends a admin session, requiring authentication to access the ACP again.
954
 */
955
function AdminEndSession()
956
{
957
	// This is so easy!
958
	unset($_SESSION['admin_time']);
959
960
	// Clean any admin tokens as well.
961
	foreach ($_SESSION['token'] as $key => $token)
962
		if (strpos($key, '-admin') !== false)
963
			unset($_SESSION['token'][$key]);
964
965
	redirectexit();
966
}
967
968
?>