1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Contains all the functionality required to be able to edit the core server settings. |
5
|
|
|
* This includes anything from which an error may result in the forum destroying |
6
|
|
|
* itself in a firey fury. |
7
|
|
|
* |
8
|
|
|
* @package ElkArte Forum |
9
|
|
|
* @copyright ElkArte Forum contributors |
10
|
|
|
* @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file) |
11
|
|
|
* |
12
|
|
|
* This file contains code covered by: |
13
|
|
|
* copyright: 2011 Simple Machines (http://www.simplemachines.org) |
14
|
|
|
* |
15
|
|
|
* @version 2.0 dev |
16
|
|
|
* |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace ElkArte\AdminController; |
20
|
|
|
|
21
|
|
|
use ElkArte\AbstractController; |
22
|
|
|
use ElkArte\Action; |
23
|
|
|
use ElkArte\Cache\CacheMethod\AbstractCacheMethod; |
24
|
|
|
use ElkArte\Exceptions\Exception; |
25
|
|
|
use ElkArte\SettingsForm\SettingsForm; |
26
|
|
|
use ElkArte\Languages\Txt; |
27
|
|
|
use ElkArte\User; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* ManageServer administration pages controller. |
31
|
|
|
* |
32
|
|
|
* This handles several screens, with low-level essential settings such as |
33
|
|
|
* database settings, cache, general forum settings, and others. |
34
|
|
|
* It sends the data for display, and it allows the admin to change it. |
35
|
|
|
*/ |
36
|
|
|
class ManageServer extends AbstractController |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects |
40
|
|
|
* the appropriate one based on the sub-action. |
41
|
|
|
* |
42
|
|
|
* What it does: |
43
|
|
|
* |
44
|
|
|
* - Requires the admin_forum permission. |
45
|
|
|
* - Redirects to the appropriate function based on the sub-action. |
46
|
|
|
* |
47
|
|
|
* @event integrate_sa_server_settings |
48
|
|
|
* @uses edit_settings adminIndex. |
49
|
|
|
* @see AbstractController::action_index() |
50
|
|
|
*/ |
51
|
|
|
public function action_index() |
52
|
|
|
{ |
53
|
|
|
global $context, $txt; |
54
|
|
|
|
55
|
|
|
// The settings are in here, I swear! |
56
|
|
|
Txt::load('ManageSettings'); |
57
|
|
|
|
58
|
|
|
// This is just to keep the database password more secure. |
59
|
|
|
isAllowedTo('admin_forum'); |
60
|
|
|
checkSession('request'); |
61
|
|
|
|
62
|
|
|
$subActions = array( |
63
|
|
|
'general' => array($this, 'action_generalSettings_display', 'permission' => 'admin_forum'), |
64
|
|
|
'database' => array($this, 'action_databaseSettings_display', 'permission' => 'admin_forum'), |
65
|
|
|
'cookie' => array($this, 'action_cookieSettings_display', 'permission' => 'admin_forum'), |
66
|
|
|
'cache' => array($this, 'action_cacheSettings_display', 'permission' => 'admin_forum'), |
67
|
|
|
'loads' => array($this, 'action_loadavgSettings_display', 'permission' => 'admin_forum'), |
68
|
|
|
'phpinfo' => array($this, 'action_phpinfo', 'permission' => 'admin_forum'), |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$action = new Action('server_settings'); |
72
|
|
|
|
73
|
|
|
// By default we're editing the core settings, call integrate_sa_server_settings |
74
|
|
|
$subAction = $action->initialize($subActions, 'general'); |
75
|
|
|
|
76
|
|
|
// Last things for the template |
77
|
|
|
$context['sub_action'] = $subAction; |
78
|
|
|
$context['page_title'] = $txt['admin_server_settings']; |
79
|
|
|
$context['sub_template'] = 'show_settings'; |
80
|
|
|
|
81
|
|
|
// Load up all the tabs... |
82
|
|
|
$context[$context['admin_menu_name']]['object']->prepareTabData([ |
83
|
|
|
'title' => 'admin_server_settings', |
84
|
|
|
'help' => 'serversettings', |
85
|
|
|
'description' => 'admin_basic_settings', |
86
|
|
|
]); |
87
|
|
|
|
88
|
|
|
// Any messages to speak of? |
89
|
|
|
$context['settings_message'] = (isset($this->_req->query->msg, $txt[$this->_req->query->msg])) ? $txt[$this->_req->query->msg] : ''; |
90
|
|
|
|
91
|
|
|
// Warn the user if there's any relevant information regarding Settings.php. |
92
|
|
|
$settings_not_writable = !is_writable(BOARDDIR . '/Settings.php'); |
93
|
|
|
|
94
|
|
|
// Warn the user if the backup of Settings.php failed. |
95
|
|
|
$settings_backup_fail = !@is_writable(BOARDDIR . '/Settings_bak.php') || !@copy(BOARDDIR . '/Settings.php', BOARDDIR . '/Settings_bak.php'); |
96
|
|
|
|
97
|
|
|
if ($settings_not_writable) |
98
|
|
|
{ |
99
|
|
|
$context['settings_message'] = $txt['settings_not_writable']; |
100
|
|
|
$context['error_type'] = 'notice'; |
101
|
|
|
} |
102
|
|
|
elseif ($settings_backup_fail) |
103
|
|
|
{ |
104
|
|
|
$context['settings_message'] = $txt['admin_backup_fail']; |
105
|
|
|
$context['error_type'] = 'notice'; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$context['settings_not_writable'] = $settings_not_writable; |
109
|
|
|
|
110
|
|
|
// Call the right function for this sub-action. |
111
|
|
|
$action->dispatch($subAction); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* General forum settings - forum name, maintenance mode, etc. |
116
|
|
|
* |
117
|
|
|
* Practically, this shows an interface for the settings in Settings.php to |
118
|
|
|
* be changed. The method handles the display, allows to edit, and saves |
119
|
|
|
* the result for generalSettings form. |
120
|
|
|
* |
121
|
|
|
* What it does: |
122
|
|
|
* |
123
|
|
|
* - Requires the admin_forum permission. |
124
|
|
|
* - Uses the edit_settings administration area. |
125
|
|
|
* - Contains the actual array of settings to show from Settings.php. |
126
|
|
|
* - Accessed from ?action=admin;area=serversettings;sa=general. |
127
|
|
|
* |
128
|
|
|
* @event integrate_save_general_settings |
129
|
|
|
*/ |
130
|
|
|
public function action_generalSettings_display() |
131
|
|
|
{ |
132
|
|
|
global $context, $txt; |
133
|
|
|
|
134
|
|
|
// Initialize the form |
135
|
|
|
$settingsForm = new SettingsForm(SettingsForm::FILE_ADAPTER); |
136
|
|
|
|
137
|
|
|
// Initialize it with our settings |
138
|
|
|
$settingsForm->setConfigVars($this->_generalSettings()); |
139
|
|
|
|
140
|
|
|
// Setup the template stuff. |
141
|
|
|
$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'serversettings', 'sa' => 'general', 'save']); |
142
|
|
|
$context['settings_title'] = $txt['general_settings']; |
143
|
|
|
|
144
|
|
|
// Saving settings? |
145
|
|
|
if (isset($this->_req->query->save)) |
146
|
|
|
{ |
147
|
|
|
call_integration_hook('integrate_save_general_settings'); |
148
|
|
|
|
149
|
|
|
// Reset this in the event the server has changed, it will get set again if needed. |
150
|
|
|
updateSettings(['host_to_dis' => 0]); |
151
|
|
|
|
152
|
|
|
$settingsForm->setConfigValues((array) $this->_req->post); |
153
|
|
|
$settingsForm->save(); |
154
|
|
|
redirectexit('action=admin;area=serversettings;sa=general;' . $context['session_var'] . '=' . $context['session_id'] . ';msg=' . (empty($context['settings_message']) ? 'core_settings_saved' : $context['settings_message'])); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
// Fill the config array for the template and all that. |
158
|
|
|
$settingsForm->prepare(); |
159
|
|
|
} |
160
|
|
|
|
161
|
2 |
|
/** |
162
|
|
|
* This function returns all general settings. |
163
|
2 |
|
* |
164
|
|
|
* @event integrate_modify_general_settings |
165
|
|
|
*/ |
166
|
|
|
private function _generalSettings() |
167
|
2 |
|
{ |
168
|
2 |
|
global $txt; |
169
|
2 |
|
|
170
|
2 |
|
// initialize configuration |
171
|
2 |
|
$config_vars = array( |
172
|
2 |
|
array('mbname', $txt['admin_title'], 'file', 'text', 30), |
173
|
2 |
|
'', |
174
|
2 |
|
array('maintenance', $txt['admin_maintain'], 'file', 'check'), |
175
|
2 |
|
array('mtitle', $txt['maintenance_subject'], 'file', 'text', 36), |
176
|
2 |
|
array('mmessage', $txt['maintenance_message'], 'file', 'large_text', 6), |
177
|
2 |
|
'', |
178
|
|
|
array('webmaster_email', $txt['admin_webmaster_email'], 'file', 'text', 30), |
179
|
|
|
'', |
180
|
|
|
array('enableCompressedOutput', $txt['enableCompressedOutput'], 'db', 'check', null, 'enableCompressedOutput'), |
181
|
2 |
|
array('disableHostnameLookup', $txt['disableHostnameLookup'], 'db', 'check', null, 'disableHostnameLookup'), |
182
|
|
|
array('url_format', $txt['url_format'], 'file', 'select', array('standard' => $txt['url_format_standard'], 'semantic' => $txt['url_format_semantic'], 'queryless' => $txt['url_format_queryless'])), |
183
|
2 |
|
); |
184
|
|
|
|
185
|
|
|
// Notify the integration |
186
|
|
|
call_integration_hook('integrate_modify_general_settings', array(&$config_vars)); |
187
|
|
|
|
188
|
|
|
return $config_vars; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Basic database and paths settings - database name, host, etc. |
193
|
|
|
* |
194
|
|
|
* This method handles the display, allows to edit, and saves the results |
195
|
|
|
* for _databaseSettings. |
196
|
|
|
* |
197
|
|
|
* What it does: |
198
|
|
|
* |
199
|
|
|
* - It shows an interface for the settings in Settings.php to be changed. |
200
|
|
|
* - It contains the actual array of settings to show from Settings.php. |
201
|
|
|
* - Requires the admin_forum permission. |
202
|
|
|
* - Uses the edit_settings administration area. |
203
|
|
|
* - Accessed from ?action=admin;area=serversettings;sa=database. |
204
|
|
|
* |
205
|
|
|
* @event integrate_save_database_settings |
206
|
|
|
*/ |
207
|
|
|
public function action_databaseSettings_display() |
208
|
|
|
{ |
209
|
|
|
global $context, $txt; |
210
|
|
|
|
211
|
|
|
// Initialize the form |
212
|
|
|
$settingsForm = new SettingsForm(SettingsForm::FILE_ADAPTER); |
213
|
|
|
|
214
|
|
|
// Initialize it with our settings |
215
|
|
|
$settingsForm->setConfigVars($this->_databaseSettings()); |
216
|
|
|
|
217
|
|
|
// Setup the template stuff. |
218
|
|
|
$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'serversettings', 'sa' => 'database', 'save']); |
219
|
|
|
$context['settings_title'] = $txt['database_paths_settings']; |
220
|
|
|
$context['save_disabled'] = $context['settings_not_writable']; |
221
|
|
|
|
222
|
|
|
// Saving settings? |
223
|
|
|
if (isset($this->_req->query->save)) |
224
|
|
|
{ |
225
|
|
|
call_integration_hook('integrate_save_database_settings'); |
226
|
|
|
|
227
|
|
|
$settingsForm->setConfigValues((array) $this->_req->post); |
228
|
|
|
$settingsForm->save(); |
229
|
|
|
redirectexit('action=admin;area=serversettings;sa=database;' . $context['session_var'] . '=' . $context['session_id'] . ';msg=' . (empty($context['settings_message']) ? 'core_settings_saved' : $context['settings_message'])); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
// Fill the config array for the template. |
233
|
|
|
$settingsForm->prepare(); |
234
|
|
|
} |
235
|
|
|
|
236
|
2 |
|
/** |
237
|
|
|
* This function returns database settings. |
238
|
2 |
|
* |
239
|
|
|
* @event integrate_modify_database_settings |
240
|
|
|
*/ |
241
|
|
|
private function _databaseSettings() |
242
|
2 |
|
{ |
243
|
2 |
|
global $txt; |
244
|
2 |
|
|
245
|
2 |
|
// initialize settings |
246
|
2 |
|
$config_vars = array( |
247
|
2 |
|
array('db_server', $txt['database_server'], 'file', 'text'), |
248
|
2 |
|
array('db_user', $txt['database_user'], 'file', 'text'), |
249
|
2 |
|
array('db_passwd', $txt['database_password'], 'file', 'password'), |
250
|
2 |
|
array('db_name', $txt['database_name'], 'file', 'text'), |
251
|
2 |
|
array('db_prefix', $txt['database_prefix'], 'file', 'text'), |
252
|
2 |
|
array('db_persist', $txt['db_persist'], 'file', 'check', null, 'db_persist'), |
253
|
2 |
|
array('db_error_send', $txt['db_error_send'], 'file', 'check'), |
254
|
2 |
|
array('ssi_db_user', $txt['ssi_db_user'], 'file', 'text', null, 'ssi_db_user'), |
255
|
2 |
|
array('ssi_db_passwd', $txt['ssi_db_passwd'], 'file', 'password'), |
256
|
2 |
|
'', |
257
|
2 |
|
array('autoFixDatabase', $txt['autoFixDatabase'], 'db', 'check', false, 'autoFixDatabase'), |
258
|
2 |
|
array('autoOptMaxOnline', $txt['autoOptMaxOnline'], 'subtext' => $txt['zero_for_no_limit'], 'db', 'int'), |
259
|
|
|
'', |
260
|
|
|
array('boardurl', $txt['admin_url'], 'file', 'text', 36), |
261
|
|
|
array('boarddir', $txt['boarddir'], 'file', 'text', 36), |
262
|
2 |
|
array('sourcedir', $txt['sourcesdir'], 'file', 'text', 36), |
263
|
|
|
array('cachedir', $txt['cachedir'], 'file', 'text', 36), |
264
|
2 |
|
); |
265
|
|
|
|
266
|
|
|
// Notify the integration |
267
|
|
|
call_integration_hook('integrate_modify_database_settings', array(&$config_vars)); |
268
|
|
|
|
269
|
|
|
return $config_vars; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Modify cookies settings. |
274
|
|
|
* |
275
|
|
|
* This method handles the display, allows to edit, and saves the result |
276
|
|
|
* for the _cookieSettings form. |
277
|
|
|
* |
278
|
|
|
* @event integrate_save_cookie_settings |
279
|
|
|
*/ |
280
|
|
|
public function action_cookieSettings_display() |
281
|
|
|
{ |
282
|
|
|
global $context, $txt, $modSettings, $cookiename, $boardurl; |
283
|
|
|
|
284
|
|
|
// Initialize the form |
285
|
|
|
$settingsForm = new SettingsForm(SettingsForm::FILE_ADAPTER); |
286
|
|
|
|
287
|
|
|
// Initialize it with our settings |
288
|
|
|
$settingsForm->setConfigVars($this->_cookieSettings()); |
289
|
|
|
|
290
|
|
|
$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'serversettings', 'sa' => 'cookie', 'save']); |
291
|
|
|
$context['settings_title'] = $txt['cookies_sessions_settings']; |
292
|
|
|
|
293
|
|
|
// Saving settings? |
294
|
|
|
if (isset($this->_req->query->save)) |
295
|
|
|
{ |
296
|
|
|
call_integration_hook('integrate_save_cookie_settings'); |
297
|
|
|
|
298
|
|
|
// Its either local or global cookies |
299
|
|
|
if (!empty($this->_req->post->localCookies) && !empty($this->_req->post->globalCookies)) |
300
|
|
|
{ |
301
|
|
|
unset($this->_req->post->globalCookies); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
if (!empty($this->_req->post->globalCookiesDomain) && strpos($boardurl, (string) $this->_req->post->globalCookiesDomain) === false) |
305
|
|
|
{ |
306
|
|
|
throw new Exception('invalid_cookie_domain', false); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
if ($this->_req->getPost('cookiename', 'trim', '') === '') |
310
|
|
|
{ |
311
|
|
|
$this->_req->post->cookiename = $cookiename; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
$settingsForm->setConfigValues((array) $this->_req->post); |
315
|
|
|
$settingsForm->save(); |
316
|
|
|
|
317
|
|
|
// If the cookie name was changed, reset the cookie. |
318
|
|
|
if ($cookiename !== $this->_req->post->cookiename) |
319
|
|
|
{ |
320
|
|
|
require_once(SUBSDIR . '/Auth.subs.php'); |
321
|
|
|
|
322
|
|
|
$original_session_id = $context['session_id']; |
323
|
|
|
|
324
|
|
|
// Remove the old cookie, nom nom nom |
325
|
|
|
setLoginCookie(-3600, 0); |
326
|
|
|
|
327
|
|
|
// Set the new one. |
328
|
|
|
$cookiename = $this->_req->post->cookiename; |
329
|
|
|
setLoginCookie(60 * $modSettings['cookieTime'], (int) User::$settings['id_member'], hash('sha256', User::$settings['passwd'] . User::$settings['password_salt'])); |
330
|
|
|
|
331
|
|
|
redirectexit('action=admin;area=serversettings;sa=cookie;' . $context['session_var'] . '=' . $original_session_id); |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
redirectexit('action=admin;area=serversettings;sa=cookie;' . $context['session_var'] . '=' . $context['session_id'] . ';msg=' . (empty($context['settings_message']) ? 'core_settings_saved' : $context['settings_message'])); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
theme()->addInlineJavascript(' |
338
|
|
|
// Initial state |
339
|
|
|
hideGlobalCookies(); |
340
|
|
|
|
341
|
|
|
// Update when clicked |
342
|
|
|
document.querySelectorAll("#localCookies, #globalCookies").forEach(function(element) { |
343
|
|
|
element.addEventListener("click", function() { |
344
|
|
|
hideGlobalCookies(); |
345
|
2 |
|
}); |
346
|
|
|
});', true); |
347
|
2 |
|
|
348
|
|
|
// Fill the config array. |
349
|
|
|
$settingsForm->prepare(); |
350
|
|
|
} |
351
|
|
|
|
352
|
2 |
|
/** |
353
|
2 |
|
* This little function returns all cookie settings. |
354
|
2 |
|
* |
355
|
2 |
|
* @event integrate_modify_cookie_settings |
356
|
2 |
|
*/ |
357
|
2 |
|
private function _cookieSettings() |
358
|
2 |
|
{ |
359
|
2 |
|
global $txt; |
360
|
|
|
|
361
|
2 |
|
// Define the variables we want to edit or show in the cookie form. |
362
|
2 |
|
$config_vars = array( |
363
|
2 |
|
// Cookies... |
364
|
|
|
array('cookiename', $txt['cookie_name'], 'file', 'text', 20), |
365
|
|
|
array('cookieTime', $txt['cookieTime'], 'db', 'int', 'postinput' => $txt['minutes']), |
366
|
|
|
array('localCookies', $txt['localCookies'], 'subtext' => $txt['localCookies_note'], 'db', 'check', false, 'localCookies'), |
367
|
2 |
|
array('globalCookies', $txt['globalCookies'], 'subtext' => $txt['globalCookies_note'], 'db', 'check', false, 'globalCookies'), |
368
|
|
|
array('globalCookiesDomain', $txt['globalCookiesDomain'], 'subtext' => $txt['globalCookiesDomain_note'], 'db', 'text', false, 'globalCookiesDomain'), |
369
|
|
|
array('secureCookies', $txt['secureCookies'], 'subtext' => $txt['secureCookies_note'], 'db', 'check', false, 'secureCookies', 'disabled' => !isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) !== 'on' && strtolower($_SERVER['HTTPS']) != '1'), |
370
|
2 |
|
array('httponlyCookies', $txt['httponlyCookies'], 'subtext' => $txt['httponlyCookies_note'], 'db', 'check', false, 'httponlyCookies'), |
371
|
|
|
'', |
372
|
|
|
// Sessions |
373
|
|
|
array('databaseSession_enable', $txt['databaseSession_enable'], 'db', 'check', false, 'databaseSession_enable'), |
374
|
|
|
array('databaseSession_loose', $txt['databaseSession_loose'], 'db', 'check', false, 'databaseSession_loose'), |
375
|
|
|
array('databaseSession_lifetime', $txt['databaseSession_lifetime'], 'db', 'int', false, 'databaseSession_lifetime', 'postinput' => $txt['seconds']), |
376
|
|
|
); |
377
|
|
|
|
378
|
|
|
// Notify the integration |
379
|
|
|
call_integration_hook('integrate_modify_cookie_settings', array(&$config_vars)); |
380
|
|
|
|
381
|
|
|
// Set them vars for our settings form |
382
|
|
|
return $config_vars; |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* Cache settings editing and submission. |
387
|
|
|
* |
388
|
|
|
* This method handles the display, allows to edit, and saves the result |
389
|
|
|
* for _cacheSettings form. |
390
|
|
|
* |
391
|
|
|
* @event integrate_save_cache_settings |
392
|
|
|
*/ |
393
|
|
|
public function action_cacheSettings_display() |
394
|
|
|
{ |
395
|
|
|
global $context, $txt; |
396
|
|
|
|
397
|
|
|
// Initialize the form |
398
|
|
|
$settingsForm = new SettingsForm(SettingsForm::FILE_ADAPTER); |
399
|
|
|
|
400
|
|
|
// Initialize it with our settings |
401
|
|
|
$settingsForm->setConfigVars($this->_cacheSettings()); |
402
|
|
|
|
403
|
|
|
// Saving again? |
404
|
|
|
if (isset($this->_req->query->save)) |
405
|
|
|
{ |
406
|
|
|
call_integration_hook('integrate_save_cache_settings'); |
407
|
|
|
|
408
|
|
|
// Move accelerator servers to the cache_servers value |
409
|
|
|
$var = 'cache_servers_' . $this->_req->post->cache_accelerator; |
410
|
|
|
if (isset($this->_req->post->$var)) |
411
|
|
|
{ |
412
|
|
|
$this->_req->post->cache_servers = $this->_req->post->$var; |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
$settingsForm->setConfigValues((array) $this->_req->post); |
416
|
|
|
$settingsForm->save(); |
417
|
|
|
|
418
|
|
|
// we need to save the $cache_enable to $modSettings as well |
419
|
|
|
updateSettings(['cache_enable' => (int) $this->_req->post->cache_enable]); |
420
|
|
|
|
421
|
|
|
// exit so we reload our new settings on the page |
422
|
|
|
redirectexit('action=admin;area=serversettings;sa=cache;' . $context['session_var'] . '=' . $context['session_id']); |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
Txt::load('Maintenance'); |
426
|
|
|
createToken('admin-maint'); |
427
|
|
|
theme()->getLayers()->add('clean_cache_button'); |
428
|
|
|
|
429
|
|
|
// Some javascript to enable / disable certain settings if the option is not selected |
430
|
|
|
theme()->addInlineJavascript(' |
431
|
|
|
let cache_type = document.getElementById(\'cache_accelerator\'); |
432
|
|
|
|
433
|
|
|
cache_type.addEventListener("change", showCache); |
434
|
2 |
|
cache_type.addEventListener("change", toggleCache); |
435
|
|
|
|
436
|
2 |
|
let event = new Event("change"); |
437
|
|
|
cache_type.dispatchEvent(event); |
438
|
|
|
', true); |
439
|
2 |
|
|
440
|
2 |
|
$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'serversettings', 'sa' => 'cache', 'save']); |
441
|
2 |
|
$context['settings_title'] = $txt['caching_settings']; |
442
|
2 |
|
$context['settings_message'] = $txt['caching_information'] . '<br /><br />' . $txt['cache_settings_message']; |
443
|
|
|
|
444
|
2 |
|
// Prepare the template. |
445
|
|
|
createToken('admin-ssc'); |
446
|
2 |
|
|
447
|
|
|
// Prepare settings for display in the template. |
448
|
2 |
|
$settingsForm->prepare(); |
449
|
|
|
} |
450
|
2 |
|
|
451
|
|
|
/** |
452
|
|
|
* This little function returns all cache settings. |
453
|
|
|
* |
454
|
2 |
|
* @event integrate_modify_cache_settings |
455
|
|
|
*/ |
456
|
|
|
private function _cacheSettings() |
457
|
2 |
|
{ |
458
|
2 |
|
global $txt, $cache_accelerator, $context; |
459
|
|
|
|
460
|
|
|
// Detect all available cache engines |
461
|
|
|
require_once(SUBSDIR . '/Cache.subs.php'); |
462
|
|
|
$detected = loadCacheEngines(false); |
463
|
2 |
|
$detected_names = []; |
464
|
2 |
|
$detected_supported = []; |
465
|
|
|
|
466
|
|
|
/** @var $value AbstractCacheMethod */ |
467
|
|
|
foreach ($detected as $key => $value) |
468
|
2 |
|
{ |
469
|
|
|
$detected_names[] = $value->title(); |
470
|
2 |
|
|
471
|
|
|
if (!empty($value->isAvailable())) |
472
|
2 |
|
{ |
473
|
|
|
$detected_supported[$key] = $value->title(); |
474
|
|
|
if ($key === $cache_accelerator) |
475
|
|
|
{ |
476
|
|
|
$context['cache_accelerator_stats'] = $value->getStats(); |
477
|
2 |
|
} |
478
|
|
|
} |
479
|
2 |
|
} |
480
|
|
|
|
481
|
|
|
$txt['caching_information'] = str_replace('{supported_accelerators}', '<i>' . implode(', ', $detected_names) . '</i><br />', $txt['caching_information']); |
482
|
|
|
|
483
|
|
|
// Set our values to show what, if anything, we found |
484
|
|
|
$txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected_supported)); |
485
|
|
|
$cache_level = [$txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']]; |
486
|
|
|
|
487
|
|
|
// Define the variables we want to edit. |
488
|
|
|
$config_vars = [ |
489
|
|
|
// Only a few settings, but they are important |
490
|
|
|
['cache_enable', $txt['cache_enable'], 'file', 'select', $cache_level, 'cache_enable'], |
491
|
|
|
['cache_accelerator', $txt['cache_accelerator'], 'file', 'select', $detected_supported], |
492
|
|
|
]; |
493
|
|
|
|
494
|
|
|
// If the cache engine has any specific settings, add them in |
495
|
|
|
foreach ($detected as $engine) |
496
|
|
|
{ |
497
|
|
|
/** @var $engine AbstractCacheMethod */ |
498
|
|
|
if ($engine->isAvailable()) |
499
|
|
|
{ |
500
|
|
|
$engine->settings($config_vars); |
501
|
|
|
} |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
// Notify the integration that we're preparing to mess with cache settings... |
505
|
|
|
call_integration_hook('integrate_modify_cache_settings', [&$config_vars]); |
506
|
|
|
|
507
|
|
|
return $config_vars; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
/** |
511
|
|
|
* Allows to edit load management settings. |
512
|
|
|
* |
513
|
|
|
* This method handles the display, allows to edit, and saves the result |
514
|
|
|
* for the _loadavgSettings form. |
515
|
|
|
* |
516
|
|
|
* @event integrate_loadavg_settings |
517
|
|
|
* @event integrate_save_loadavg_settings |
518
|
|
|
*/ |
519
|
|
|
public function action_loadavgSettings_display() |
520
|
|
|
{ |
521
|
|
|
global $txt, $context; |
522
|
|
|
|
523
|
|
|
// Initialize the form |
524
|
|
|
$settingsForm = new SettingsForm(SettingsForm::DB_ADAPTER); |
525
|
|
|
|
526
|
|
|
// Initialize it with our settings |
527
|
|
|
$settingsForm->setConfigVars($this->_loadavgSettings()); |
528
|
|
|
|
529
|
|
|
call_integration_hook('integrate_loadavg_settings'); |
530
|
|
|
|
531
|
|
|
$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'serversettings', 'sa' => 'loads', 'save']); |
532
|
|
|
$context['settings_title'] = $txt['loadavg_settings']; |
533
|
|
|
|
534
|
|
|
// Saving? |
535
|
|
|
if (isset($this->_req->query->save)) |
536
|
|
|
{ |
537
|
|
|
// Stupidity is not allowed. |
538
|
|
|
foreach ($this->_req->post as $key => $value) |
539
|
|
|
{ |
540
|
|
|
if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable') |
541
|
|
|
{ |
542
|
|
|
continue; |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
if ($key === 'loadavg_auto_opt' && $value <= 1) |
546
|
|
|
{ |
547
|
|
|
$this->_req->post->loadavg_auto_opt = '1.0'; |
548
|
2 |
|
} |
549
|
|
|
elseif ($key === 'loadavg_forum' && $value < 10) |
550
|
2 |
|
{ |
551
|
|
|
$this->_req->post->loadavg_forum = '10.0'; |
552
|
|
|
} |
553
|
2 |
|
elseif ($value < 2) |
554
|
2 |
|
{ |
555
|
|
|
$this->_req->{$key} = '2.0'; |
556
|
|
|
} |
557
|
2 |
|
} |
558
|
|
|
|
559
|
|
|
call_integration_hook('integrate_save_loadavg_settings'); |
560
|
|
|
|
561
|
|
|
$settingsForm->setConfigValues((array) $this->_req->post); |
562
|
|
|
$settingsForm->save(); |
563
|
2 |
|
redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']); |
564
|
2 |
|
} |
565
|
|
|
|
566
|
2 |
|
createToken('admin-ssc'); |
567
|
|
|
createToken('admin-dbsc'); |
568
|
2 |
|
$settingsForm->prepare(); |
569
|
2 |
|
} |
570
|
|
|
|
571
|
|
|
/** |
572
|
|
|
* This little function returns load management settings. |
573
|
|
|
* |
574
|
|
|
* @event integrate_modify_loadavg_settings |
575
|
2 |
|
*/ |
576
|
|
|
private function _loadavgSettings() |
577
|
|
|
{ |
578
|
|
|
global $txt, $modSettings, $context; |
579
|
|
|
|
580
|
2 |
|
// Initialize settings for the form to show, disabled by default. |
581
|
|
|
$disabled = true; |
582
|
|
|
$context['settings_message'] = $txt['loadavg_disabled_conf']; |
583
|
|
|
|
584
|
|
|
// Don't say you're using that win-thing, no cookies for you :P |
585
|
|
|
if (strpos(PHP_OS_FAMILY, 'Win') === 0) |
586
|
|
|
{ |
587
|
|
|
$context['settings_message'] = $txt['loadavg_disabled_windows']; |
588
|
|
|
} |
589
|
|
|
else |
590
|
|
|
{ |
591
|
2 |
|
require_once(SUBSDIR . '/Server.subs.php'); |
592
|
|
|
$modSettings['load_average'] = detectServerLoad(); |
593
|
|
|
|
594
|
2 |
|
if ($modSettings['load_average'] !== false) |
595
|
2 |
|
{ |
596
|
|
|
$disabled = false; |
597
|
|
|
$context['settings_message'] = sprintf($txt['loadavg_warning'], $modSettings['load_average']); |
598
|
|
|
} |
599
|
2 |
|
} |
600
|
|
|
|
601
|
2 |
|
// Start with a simple checkbox. |
602
|
|
|
$config_vars = array( |
603
|
|
|
array('check', 'loadavg_enable', 'disabled' => $disabled), |
604
|
|
|
); |
605
|
|
|
|
606
|
|
|
// Set the default values for each option. |
607
|
|
|
$default_values = array( |
608
|
|
|
'loadavg_auto_opt' => '1.0', |
609
|
|
|
'loadavg_search' => '2.5', |
610
|
|
|
'loadavg_allunread' => '2.0', |
611
|
|
|
'loadavg_unreadreplies' => '3.5', |
612
|
|
|
'loadavg_show_posts' => '2.0', |
613
|
|
|
'loadavg_userstats' => '10.0', |
614
|
|
|
'loadavg_bbc' => '30.0', |
615
|
|
|
'loadavg_forum' => '40.0', |
616
|
|
|
); |
617
|
|
|
|
618
|
|
|
// Loop through the settings. |
619
|
|
|
foreach ($default_values as $name => $value) |
620
|
|
|
{ |
621
|
|
|
// Use the default value if the setting isn't set yet. |
622
|
|
|
$value = $modSettings[$name] ?? $value; |
623
|
|
|
$config_vars[] = array('text', $name, 'value' => $value, 'disabled' => $disabled); |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
// Notify the integration that we're preparing to mess with load management settings... |
627
|
|
|
call_integration_hook('integrate_modify_loadavg_settings', array(&$config_vars)); |
628
|
|
|
|
629
|
|
|
return $config_vars; |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
/** |
633
|
|
|
* Allows us to see the servers php settings |
634
|
|
|
* |
635
|
|
|
* What it does: |
636
|
|
|
* |
637
|
|
|
* - loads the settings into an array for display in a template |
638
|
|
|
* - drops cookie values just in case |
639
|
|
|
* |
640
|
|
|
* @uses sub-template php_info |
641
|
|
|
*/ |
642
|
|
|
public function action_phpinfo() |
643
|
|
|
{ |
644
|
|
|
global $context, $txt; |
645
|
|
|
|
646
|
|
|
$category = $txt['phpinfo_settings']; |
647
|
|
|
$pinfo = array(); |
648
|
|
|
|
649
|
|
|
// Get the data |
650
|
|
|
ob_start(); |
651
|
|
|
phpinfo(); |
652
|
|
|
|
653
|
|
|
// We only want it for its body, pigs that we are |
654
|
|
|
$info_lines = preg_replace('~^.*<body>(.*)</body>.*$~', '$1', ob_get_contents()); |
655
|
|
|
$info_lines = explode("\n", strip_tags($info_lines, '<tr><td><h2>')); |
656
|
|
|
@ob_end_clean(); |
|
|
|
|
657
|
|
|
|
658
|
|
|
// Remove things that could be considered sensitive |
659
|
|
|
$remove = '_COOKIE|Cookie|_GET|_REQUEST|REQUEST_URI|QUERY_STRING|REQUEST_URL|HTTP_REFERER'; |
660
|
|
|
|
661
|
|
|
// Put all of it into an array |
662
|
|
|
foreach ($info_lines as $line) |
663
|
|
|
{ |
664
|
|
|
if (preg_match('~(' . $remove . ')~', $line)) |
665
|
|
|
{ |
666
|
|
|
continue; |
667
|
2 |
|
} |
668
|
|
|
|
669
|
2 |
|
// New category? |
670
|
|
|
if (strpos($line, '<h2>') !== false) |
671
|
|
|
{ |
672
|
|
|
$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $title[1] : $category; |
673
|
|
|
} |
674
|
|
|
|
675
|
2 |
|
// Load it as setting => value or the old setting local master |
676
|
|
|
if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) |
677
|
2 |
|
{ |
678
|
|
|
$pinfo[$category][$val[1]] = $val[2]; |
679
|
|
|
} |
680
|
|
|
elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) |
681
|
|
|
{ |
682
|
|
|
$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]); |
683
|
2 |
|
} |
684
|
|
|
} |
685
|
2 |
|
|
686
|
|
|
// Load it in to context and display it |
687
|
|
|
$context['pinfo'] = $pinfo; |
688
|
|
|
$context['page_title'] = $txt['admin_server_settings']; |
689
|
|
|
$context['sub_template'] = 'php_info'; |
690
|
|
|
} |
691
|
2 |
|
|
692
|
|
|
/** |
693
|
2 |
|
* Return the search settings for use in admin search |
694
|
|
|
*/ |
695
|
|
|
public function generalSettings_search() |
696
|
|
|
{ |
697
|
|
|
return $this->_generalSettings(); |
698
|
|
|
} |
699
|
2 |
|
|
700
|
|
|
/** |
701
|
2 |
|
* Return the search settings for use in admin search |
702
|
|
|
*/ |
703
|
|
|
public function databaseSettings_search() |
704
|
|
|
{ |
705
|
|
|
return $this->_databaseSettings(); |
706
|
|
|
} |
707
|
|
|
|
708
|
|
|
/** |
709
|
|
|
* Return the search settings for use in admin search |
710
|
|
|
*/ |
711
|
|
|
public function cookieSettings_search() |
712
|
|
|
{ |
713
|
|
|
return $this->_cookieSettings(); |
714
|
|
|
} |
715
|
|
|
|
716
|
|
|
/** |
717
|
|
|
* Return the search settings for use in admin search |
718
|
|
|
*/ |
719
|
|
|
public function cacheSettings_search() |
720
|
|
|
{ |
721
|
|
|
return $this->_cacheSettings(); |
722
|
|
|
} |
723
|
|
|
|
724
|
|
|
/** |
725
|
|
|
* Return the search settings for use in admin search |
726
|
|
|
*/ |
727
|
|
|
public function balancingSettings_search() |
728
|
|
|
{ |
729
|
|
|
return $this->_loadavgSettings(); |
730
|
|
|
} |
731
|
|
|
} |
732
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: