1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Contains all the functionality required to be able to edit the core server |
5
|
|
|
* settings. This includes anything from which an error may result in the forum |
6
|
|
|
* destroying itself in a firey fury. |
7
|
|
|
* |
8
|
|
|
* Adding options to one of the setting screens isn't hard. Call prepareDBSettingsContext; |
9
|
|
|
* The basic format for a checkbox is: |
10
|
|
|
* array('check', 'nameInModSettingsAndSQL'), |
11
|
|
|
* And for a text box: |
12
|
|
|
* array('text', 'nameInModSettingsAndSQL') |
13
|
|
|
* (NOTE: You have to add an entry for this at the bottom!) |
14
|
|
|
* |
15
|
|
|
* In these cases, it will look for $txt['nameInModSettingsAndSQL'] as the description, |
16
|
|
|
* and $helptxt['nameInModSettingsAndSQL'] as the help popup description. |
17
|
|
|
* |
18
|
|
|
* Here's a quick explanation of how to add a new item: |
19
|
|
|
* |
20
|
|
|
* - A text input box. For textual values. |
21
|
|
|
* array('text', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth'), |
22
|
|
|
* - A text input box. For numerical values. |
23
|
|
|
* array('int', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth'), |
24
|
|
|
* - A text input box. For floating point values. |
25
|
|
|
* array('float', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth'), |
26
|
|
|
* - A large text input box. Used for textual values spanning multiple lines. |
27
|
|
|
* array('large_text', 'nameInModSettingsAndSQL', 'OptionalNumberOfRows'), |
28
|
|
|
* - A check box. Either one or zero. (boolean) |
29
|
|
|
* array('check', 'nameInModSettingsAndSQL'), |
30
|
|
|
* - A selection box. Used for the selection of something from a list. |
31
|
|
|
* array('select', 'nameInModSettingsAndSQL', array('valueForSQL' => $txt['displayedValue'])), |
32
|
|
|
* Note that just saying array('first', 'second') will put 0 in the SQL for 'first'. |
33
|
|
|
* - A password input box. Used for passwords, no less! |
34
|
|
|
* array('password', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth'), |
35
|
|
|
* - A permission - for picking groups who have a permission. |
36
|
|
|
* array('permissions', 'manage_groups'), |
37
|
|
|
* - A BBC selection box. |
38
|
|
|
* array('bbc', 'sig_bbc'), |
39
|
|
|
* - A list of boards to choose from |
40
|
|
|
* array('boards', 'likes_boards'), |
41
|
|
|
* Note that the storage in the database is as 1,2,3,4 |
42
|
|
|
* |
43
|
|
|
* For each option: |
44
|
|
|
* - type (see above), variable name, size/possible values. |
45
|
|
|
* OR make type '' for an empty string for a horizontal rule. |
46
|
|
|
* - SET preinput - to put some HTML prior to the input box. |
47
|
|
|
* - SET postinput - to put some HTML following the input box. |
48
|
|
|
* - SET invalid - to mark the data as invalid. |
49
|
|
|
* - PLUS you can override label and help parameters by forcing their keys in the array, for example: |
50
|
|
|
* array('text', 'invalidlabel', 3, 'label' => 'Actual Label') |
51
|
|
|
* |
52
|
|
|
* Simple Machines Forum (SMF) |
53
|
|
|
* |
54
|
|
|
* @package SMF |
55
|
|
|
* @author Simple Machines https://www.simplemachines.org |
56
|
|
|
* @copyright 2021 Simple Machines and individual contributors |
57
|
|
|
* @license https://www.simplemachines.org/about/smf/license.php BSD |
58
|
|
|
* |
59
|
|
|
* @version 2.1 RC3 |
60
|
|
|
*/ |
61
|
|
|
|
62
|
|
|
use SMF\Cache\CacheApi; |
63
|
|
|
use SMF\Cache\CacheApiInterface; |
64
|
|
|
|
65
|
|
|
if (!defined('SMF')) |
66
|
|
|
die('No direct access...'); |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects |
70
|
|
|
* the appropriate one based on the sub-action. |
71
|
|
|
* |
72
|
|
|
* Requires the admin_forum permission. |
73
|
|
|
* Redirects to the appropriate function based on the sub-action. |
74
|
|
|
* |
75
|
|
|
* Uses edit_settings adminIndex. |
76
|
|
|
*/ |
77
|
|
|
function ModifySettings() |
78
|
|
|
{ |
79
|
|
|
global $context, $txt, $boarddir; |
80
|
|
|
|
81
|
|
|
// This is just to keep the database password more secure. |
82
|
|
|
isAllowedTo('admin_forum'); |
83
|
|
|
|
84
|
|
|
// Load up all the tabs... |
85
|
|
|
$context[$context['admin_menu_name']]['tab_data'] = array( |
86
|
|
|
'title' => $txt['admin_server_settings'], |
87
|
|
|
'help' => 'serversettings', |
88
|
|
|
'description' => $txt['admin_basic_settings'], |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
checkSession('request'); |
92
|
|
|
|
93
|
|
|
// The settings are in here, I swear! |
94
|
|
|
loadLanguage('ManageSettings'); |
95
|
|
|
|
96
|
|
|
$context['page_title'] = $txt['admin_server_settings']; |
97
|
|
|
$context['sub_template'] = 'show_settings'; |
98
|
|
|
|
99
|
|
|
$subActions = array( |
100
|
|
|
'general' => 'ModifyGeneralSettings', |
101
|
|
|
'database' => 'ModifyDatabaseSettings', |
102
|
|
|
'cookie' => 'ModifyCookieSettings', |
103
|
|
|
'security' => 'ModifyGeneralSecuritySettings', |
104
|
|
|
'cache' => 'ModifyCacheSettings', |
105
|
|
|
'export' => 'ModifyExportSettings', |
106
|
|
|
'loads' => 'ModifyLoadBalancingSettings', |
107
|
|
|
'phpinfo' => 'ShowPHPinfoSettings', |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
// By default we're editing the core settings |
111
|
|
|
$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'general'; |
112
|
|
|
$context['sub_action'] = $_REQUEST['sa']; |
113
|
|
|
|
114
|
|
|
// Warn the user if there's any relevant information regarding Settings.php. |
115
|
|
|
$settings_not_writable = !is_writable($boarddir . '/Settings.php'); |
116
|
|
|
$settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php'); |
117
|
|
|
|
118
|
|
|
if ($settings_not_writable) |
119
|
|
|
$context['settings_message'] = array( |
120
|
|
|
'label' => $txt['settings_not_writable'], |
121
|
|
|
'tag' => 'div', |
122
|
|
|
'class' => 'centertext strong' |
123
|
|
|
); |
124
|
|
|
elseif ($settings_backup_fail) |
125
|
|
|
$context['settings_message'] = array( |
126
|
|
|
'label' => $txt['admin_backup_fail'], |
127
|
|
|
'tag' => 'div', |
128
|
|
|
'class' => 'centertext strong' |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
$context['settings_not_writable'] = $settings_not_writable; |
132
|
|
|
|
133
|
|
|
call_integration_hook('integrate_server_settings', array(&$subActions)); |
134
|
|
|
|
135
|
|
|
// Call the right function for this sub-action. |
136
|
|
|
call_helper($subActions[$_REQUEST['sa']]); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* General forum settings - forum name, maintenance mode, etc. |
141
|
|
|
* Practically, this shows an interface for the settings in Settings.php to be changed. |
142
|
|
|
* |
143
|
|
|
* - Requires the admin_forum permission. |
144
|
|
|
* - Uses the edit_settings administration area. |
145
|
|
|
* - Contains the actual array of settings to show from Settings.php. |
146
|
|
|
* - Accessed from ?action=admin;area=serversettings;sa=general. |
147
|
|
|
* |
148
|
|
|
* @param bool $return_config Whether to return the $config_vars array (for pagination purposes) |
149
|
|
|
* @return void|array Returns nothing or returns the $config_vars array if $return_config is true |
150
|
|
|
*/ |
151
|
|
|
function ModifyGeneralSettings($return_config = false) |
152
|
|
|
{ |
153
|
|
|
global $scripturl, $context, $txt, $modSettings, $boardurl, $sourcedir; |
154
|
|
|
|
155
|
|
|
// If no cert, force_ssl must remain 0 |
156
|
|
|
require_once($sourcedir . '/Subs.php'); |
157
|
|
|
if (!ssl_cert_found($boardurl) && empty($modSettings['force_ssl'])) |
158
|
|
|
$disable_force_ssl = true; |
159
|
|
|
else |
160
|
|
|
$disable_force_ssl = false; |
161
|
|
|
|
162
|
|
|
/* If you're writing a mod, it's a bad idea to add things here.... |
163
|
|
|
For each option: |
164
|
|
|
variable name, description, type (constant), size/possible values, helptext, optional 'min' (minimum value for float/int, defaults to 0), optional 'max' (maximum value for float/int), optional 'step' (amount to increment/decrement value for float/int) |
165
|
|
|
OR an empty string for a horizontal rule. |
166
|
|
|
OR a string for a titled section. */ |
167
|
|
|
$config_vars = array( |
168
|
|
|
array('mbname', $txt['admin_title'], 'file', 'text', 30), |
169
|
|
|
'', |
170
|
|
|
array('maintenance', $txt['admin_maintain'], 'file', 'check'), |
171
|
|
|
array('mtitle', $txt['maintenance_subject'], 'file', 'text', 36), |
172
|
|
|
array('mmessage', $txt['maintenance_message'], 'file', 'text', 36), |
173
|
|
|
'', |
174
|
|
|
array('webmaster_email', $txt['admin_webmaster_email'], 'file', 'text', 30), |
175
|
|
|
'', |
176
|
|
|
array('enableCompressedOutput', $txt['enableCompressedOutput'], 'db', 'check', null, 'enableCompressedOutput'), |
177
|
|
|
array('disableHostnameLookup', $txt['disableHostnameLookup'], 'db', 'check', null, 'disableHostnameLookup'), |
178
|
|
|
'', |
179
|
|
|
array('force_ssl', $txt['force_ssl'], 'db', 'select', array($txt['force_ssl_off'], $txt['force_ssl_complete']), 'force_ssl', 'disabled' => $disable_force_ssl), |
180
|
|
|
array('image_proxy_enabled', $txt['image_proxy_enabled'], 'file', 'check', null, 'image_proxy_enabled'), |
181
|
|
|
array('image_proxy_secret', $txt['image_proxy_secret'], 'file', 'text', 30, 'image_proxy_secret'), |
182
|
|
|
array('image_proxy_maxsize', $txt['image_proxy_maxsize'], 'file', 'int', null, 'image_proxy_maxsize'), |
183
|
|
|
'', |
184
|
|
|
array('enable_sm_stats', $txt['enable_sm_stats'], 'db', 'check', null, 'enable_sm_stats'), |
185
|
|
|
); |
186
|
|
|
|
187
|
|
|
call_integration_hook('integrate_general_settings', array(&$config_vars)); |
188
|
|
|
|
189
|
|
|
if ($return_config) |
190
|
|
|
return $config_vars; |
191
|
|
|
|
192
|
|
|
// Setup the template stuff. |
193
|
|
|
$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=general;save'; |
194
|
|
|
$context['settings_title'] = $txt['general_settings']; |
195
|
|
|
|
196
|
|
|
// Saving settings? |
197
|
|
|
if (isset($_REQUEST['save'])) |
198
|
|
|
{ |
199
|
|
|
call_integration_hook('integrate_save_general_settings'); |
200
|
|
|
|
201
|
|
|
// Are we saving the stat collection? |
202
|
|
|
if (!empty($_POST['enable_sm_stats']) && empty($modSettings['sm_stats_key'])) |
203
|
|
|
{ |
204
|
|
|
$registerSMStats = registerSMStats(); |
205
|
|
|
|
206
|
|
|
// Failed to register, disable it again. |
207
|
|
|
if (empty($registerSMStats)) |
208
|
|
|
$_POST['enable_sm_stats'] = 0; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
// Ensure all URLs are aligned with the new force_ssl setting |
212
|
|
|
// Treat unset like 0 |
213
|
|
|
if (isset($_POST['force_ssl'])) |
214
|
|
|
AlignURLsWithSSLSetting($_POST['force_ssl']); |
215
|
|
|
else |
216
|
|
|
AlignURLsWithSSLSetting(0); |
217
|
|
|
|
218
|
|
|
saveSettings($config_vars); |
219
|
|
|
$_SESSION['adm-save'] = true; |
220
|
|
|
redirectexit('action=admin;area=serversettings;sa=general;' . $context['session_var'] . '=' . $context['session_id']); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
// Fill the config array. |
224
|
|
|
prepareServerSettingsContext($config_vars); |
225
|
|
|
|
226
|
|
|
// Some javascript for SSL |
227
|
|
|
addInlineJavaScript(' |
228
|
|
|
$(function() |
229
|
|
|
{ |
230
|
|
|
$("#force_ssl").change(function() |
231
|
|
|
{ |
232
|
|
|
var mode = $(this).val() == 1 ? false : true; |
233
|
|
|
$("#image_proxy_enabled").prop("disabled", mode); |
234
|
|
|
$("#image_proxy_secret").prop("disabled", mode); |
235
|
|
|
$("#image_proxy_maxsize").prop("disabled", mode); |
236
|
|
|
}).change(); |
237
|
|
|
});', true); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Align URLs with SSL Setting. |
242
|
|
|
* |
243
|
|
|
* If force_ssl has changed, ensure all URLs are aligned with the new setting. |
244
|
|
|
* This includes: |
245
|
|
|
* - $boardurl |
246
|
|
|
* - $modSettings['smileys_url'] |
247
|
|
|
* - $modSettings['avatar_url'] |
248
|
|
|
* - $modSettings['custom_avatar_url'] - if found |
249
|
|
|
* - theme_url - all entries in the themes table |
250
|
|
|
* - images_url - all entries in the themes table |
251
|
|
|
* |
252
|
|
|
* This function will NOT overwrite URLs that are not subfolders of $boardurl. |
253
|
|
|
* The admin must have pointed those somewhere else on purpose, so they must be updated manually. |
254
|
|
|
* |
255
|
|
|
* A word of caution: You can't trust the http/https scheme reflected for these URLs in $globals |
256
|
|
|
* (e.g., $boardurl) or in $modSettings. This is because SMF may change them in memory to comply |
257
|
|
|
* with the force_ssl setting - a soft redirect may be in effect... Thus, conditional updates |
258
|
|
|
* to these values do not work. You gotta just brute force overwrite them based on force_ssl. |
259
|
|
|
* |
260
|
|
|
* @param int $new_force_ssl is the current force_ssl setting. |
261
|
|
|
* @return void Returns nothing, just does its job |
262
|
|
|
*/ |
263
|
|
|
function AlignURLsWithSSLSetting($new_force_ssl = 0) |
264
|
|
|
{ |
265
|
|
|
global $boardurl, $modSettings, $sourcedir, $smcFunc; |
266
|
|
|
require_once($sourcedir . '/Subs-Admin.php'); |
267
|
|
|
|
268
|
|
|
// Check $boardurl |
269
|
|
|
if (!empty($new_force_ssl)) |
270
|
|
|
$newval = strtr($boardurl, array('http://' => 'https://')); |
271
|
|
|
else |
272
|
|
|
$newval = strtr($boardurl, array('https://' => 'http://')); |
273
|
|
|
updateSettingsFile(array('boardurl' => $newval)); |
274
|
|
|
|
275
|
|
|
$new_settings = array(); |
276
|
|
|
|
277
|
|
|
// Check $smileys_url, but only if it points to a subfolder of $boardurl |
278
|
|
|
if (BoardurlMatch($modSettings['smileys_url'])) |
279
|
|
|
{ |
280
|
|
|
if (!empty($new_force_ssl)) |
281
|
|
|
$newval = strtr($modSettings['smileys_url'], array('http://' => 'https://')); |
282
|
|
|
else |
283
|
|
|
$newval = strtr($modSettings['smileys_url'], array('https://' => 'http://')); |
284
|
|
|
$new_settings['smileys_url'] = $newval; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
// Check $avatar_url, but only if it points to a subfolder of $boardurl |
288
|
|
|
if (BoardurlMatch($modSettings['avatar_url'])) |
289
|
|
|
{ |
290
|
|
|
if (!empty($new_force_ssl)) |
291
|
|
|
$newval = strtr($modSettings['avatar_url'], array('http://' => 'https://')); |
292
|
|
|
else |
293
|
|
|
$newval = strtr($modSettings['avatar_url'], array('https://' => 'http://')); |
294
|
|
|
$new_settings['avatar_url'] = $newval; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
// Check $custom_avatar_url, but only if it points to a subfolder of $boardurl |
298
|
|
|
// This one had been optional in the past, make sure it is set first |
299
|
|
|
if (isset($modSettings['custom_avatar_url']) && BoardurlMatch($modSettings['custom_avatar_url'])) |
300
|
|
|
{ |
301
|
|
|
if (!empty($new_force_ssl)) |
302
|
|
|
$newval = strtr($modSettings['custom_avatar_url'], array('http://' => 'https://')); |
303
|
|
|
else |
304
|
|
|
$newval = strtr($modSettings['custom_avatar_url'], array('https://' => 'http://')); |
305
|
|
|
$new_settings['custom_avatar_url'] = $newval; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
// Save updates to the settings table |
309
|
|
|
if (!empty($new_settings)) |
310
|
|
|
updateSettings($new_settings, true); |
311
|
|
|
|
312
|
|
|
// Now we move onto the themes. |
313
|
|
|
// First, get a list of theme URLs... |
314
|
|
|
$request = $smcFunc['db_query']('', ' |
315
|
|
|
SELECT id_theme, variable, value |
316
|
|
|
FROM {db_prefix}themes |
317
|
|
|
WHERE variable in ({string:themeurl}, {string:imagesurl}) |
318
|
|
|
AND id_member = {int:zero}', |
319
|
|
|
array( |
320
|
|
|
'themeurl' => 'theme_url', |
321
|
|
|
'imagesurl' => 'images_url', |
322
|
|
|
'zero' => 0, |
323
|
|
|
) |
324
|
|
|
); |
325
|
|
|
|
326
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
327
|
|
|
{ |
328
|
|
|
// First check to see if it points to a subfolder of $boardurl |
329
|
|
|
if (BoardurlMatch($row['value'])) |
330
|
|
|
{ |
331
|
|
|
if (!empty($new_force_ssl)) |
332
|
|
|
$newval = strtr($row['value'], array('http://' => 'https://')); |
333
|
|
|
else |
334
|
|
|
$newval = strtr($row['value'], array('https://' => 'http://')); |
335
|
|
|
|
336
|
|
|
$smcFunc['db_query']('', ' |
337
|
|
|
UPDATE {db_prefix}themes |
338
|
|
|
SET value = {string:theme_val} |
339
|
|
|
WHERE variable = {string:theme_var} |
340
|
|
|
AND id_theme = {string:theme_id} |
341
|
|
|
AND id_member = {int:zero}', |
342
|
|
|
array( |
343
|
|
|
'theme_val' => $newval, |
344
|
|
|
'theme_var' => $row['variable'], |
345
|
|
|
'theme_id' => $row['id_theme'], |
346
|
|
|
'zero' => 0, |
347
|
|
|
) |
348
|
|
|
); |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
|
$smcFunc['db_free_result']($request); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* $boardurl Match. |
356
|
|
|
* |
357
|
|
|
* Helper function to see if the url being checked is based off of $boardurl. |
358
|
|
|
* If not, it was overridden by the admin to some other value on purpose, and should not |
359
|
|
|
* be stepped on by SMF when aligning URLs with the force_ssl setting. |
360
|
|
|
* The site admin must change URLs that are not aligned with $boardurl manually. |
361
|
|
|
* |
362
|
|
|
* @param string $url is the url to check. |
363
|
|
|
* @return bool Returns true if the url is based off of $boardurl (without the scheme), false if not |
364
|
|
|
*/ |
365
|
|
|
function BoardurlMatch($url = '') |
366
|
|
|
{ |
367
|
|
|
global $boardurl; |
368
|
|
|
|
369
|
|
|
// Strip the schemes |
370
|
|
|
$urlpath = strtr($url, array('http://' => '', 'https://' => '')); |
371
|
|
|
$boardurlpath = strtr($boardurl, array('http://' => '', 'https://' => '')); |
372
|
|
|
|
373
|
|
|
// If leftmost portion of path matches boardurl, return true |
374
|
|
|
$result = strpos($urlpath, $boardurlpath); |
375
|
|
|
if ($result === false || $result != 0) |
376
|
|
|
return false; |
377
|
|
|
else |
378
|
|
|
return true; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* Basic database and paths settings - database name, host, etc. |
383
|
|
|
* |
384
|
|
|
* - It shows an interface for the settings in Settings.php to be changed. |
385
|
|
|
* - It contains the actual array of settings to show from Settings.php. |
386
|
|
|
* - Requires the admin_forum permission. |
387
|
|
|
* - Uses the edit_settings administration area. |
388
|
|
|
* - Accessed from ?action=admin;area=serversettings;sa=database. |
389
|
|
|
* |
390
|
|
|
* @param bool $return_config Whether or not to return the config_vars array (used for admin search) |
391
|
|
|
* @return void|array Returns nothing or returns the $config_vars array if $return_config is true |
392
|
|
|
*/ |
393
|
|
|
function ModifyDatabaseSettings($return_config = false) |
394
|
|
|
{ |
395
|
|
|
global $scripturl, $context, $txt, $smcFunc; |
396
|
|
|
db_extend('extra'); |
397
|
|
|
|
398
|
|
|
/* If you're writing a mod, it's a bad idea to add things here.... |
399
|
|
|
For each option: |
400
|
|
|
variable name, description, type (constant), size/possible values, helptext, optional 'min' (minimum value for float/int, defaults to 0), optional 'max' (maximum value for float/int), optional 'step' (amount to increment/decrement value for float/int) |
401
|
|
|
OR an empty string for a horizontal rule. |
402
|
|
|
OR a string for a titled section. */ |
403
|
|
|
$config_vars = array( |
404
|
|
|
array('db_persist', $txt['db_persist'], 'file', 'check', null, 'db_persist'), |
405
|
|
|
array('db_error_send', $txt['db_error_send'], 'file', 'check'), |
406
|
|
|
array('ssi_db_user', $txt['ssi_db_user'], 'file', 'text', null, 'ssi_db_user'), |
407
|
|
|
array('ssi_db_passwd', $txt['ssi_db_passwd'], 'file', 'password'), |
408
|
|
|
'', |
409
|
|
|
array('autoFixDatabase', $txt['autoFixDatabase'], 'db', 'check', false, 'autoFixDatabase') |
410
|
|
|
); |
411
|
|
|
|
412
|
|
|
// Add PG Stuff |
413
|
|
|
if ($smcFunc['db_title'] === POSTGRE_TITLE) |
414
|
|
|
{ |
415
|
|
|
$request = $smcFunc['db_query']('', 'SELECT cfgname FROM pg_ts_config', array()); |
416
|
|
|
$fts_language = array(); |
417
|
|
|
|
418
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
419
|
|
|
$fts_language[$row['cfgname']] = $row['cfgname']; |
420
|
|
|
|
421
|
|
|
$config_vars = array_merge($config_vars, array( |
422
|
|
|
'', |
423
|
|
|
array('search_language', $txt['search_language'], 'db', 'select', $fts_language, 'pgFulltextSearch') |
424
|
|
|
) |
425
|
|
|
); |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
call_integration_hook('integrate_database_settings', array(&$config_vars)); |
429
|
|
|
|
430
|
|
|
if ($return_config) |
431
|
|
|
return $config_vars; |
432
|
|
|
|
433
|
|
|
// Setup the template stuff. |
434
|
|
|
$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save'; |
435
|
|
|
$context['settings_title'] = $txt['database_settings']; |
436
|
|
|
$context['save_disabled'] = $context['settings_not_writable']; |
437
|
|
|
|
438
|
|
|
if (!$smcFunc['db_allow_persistent']()) |
439
|
|
|
addInlineJavaScript(' |
440
|
|
|
$(function() |
441
|
|
|
{ |
442
|
|
|
$("#db_persist").prop("disabled", true); |
443
|
|
|
});', true); |
444
|
|
|
|
445
|
|
|
// Saving settings? |
446
|
|
|
if (isset($_REQUEST['save'])) |
447
|
|
|
{ |
448
|
|
|
call_integration_hook('integrate_save_database_settings'); |
449
|
|
|
|
450
|
|
|
saveSettings($config_vars); |
451
|
|
|
$_SESSION['adm-save'] = true; |
452
|
|
|
redirectexit('action=admin;area=serversettings;sa=database;' . $context['session_var'] . '=' . $context['session_id']); |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
// Fill the config array. |
456
|
|
|
prepareServerSettingsContext($config_vars); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* This function handles cookies settings modifications. |
461
|
|
|
* |
462
|
|
|
* @param bool $return_config Whether or not to return the config_vars array (used for admin search) |
463
|
|
|
* @return void|array Returns nothing or returns the $config_vars array if $return_config is true |
464
|
|
|
*/ |
465
|
|
|
function ModifyCookieSettings($return_config = false) |
466
|
|
|
{ |
467
|
|
|
global $context, $scripturl, $txt, $sourcedir, $modSettings, $cookiename, $user_settings, $boardurl, $smcFunc; |
468
|
|
|
|
469
|
|
|
// Define the variables we want to edit. |
470
|
|
|
$config_vars = array( |
471
|
|
|
// Cookies... |
472
|
|
|
array('cookiename', $txt['cookie_name'], 'file', 'text', 20), |
473
|
|
|
array('cookieTime', $txt['cookieTime'], 'db', 'select', array( |
474
|
|
|
3153600 => $txt['always_logged_in'], |
475
|
|
|
60 => $txt['one_hour'], |
476
|
|
|
1440 => $txt['one_day'], |
477
|
|
|
10080 => $txt['one_week'], |
478
|
|
|
43200 => $txt['one_month'], |
479
|
|
|
)), |
480
|
|
|
array('localCookies', $txt['localCookies'], 'db', 'check', false, 'localCookies'), |
481
|
|
|
array('globalCookies', $txt['globalCookies'], 'db', 'check', false, 'globalCookies'), |
482
|
|
|
array('globalCookiesDomain', $txt['globalCookiesDomain'], 'db', 'text', false, 'globalCookiesDomain'), |
483
|
|
|
array('secureCookies', $txt['secureCookies'], 'db', 'check', false, 'secureCookies', 'disabled' => !httpsOn()), |
484
|
|
|
array('httponlyCookies', $txt['httponlyCookies'], 'db', 'check', false, 'httponlyCookies'), |
485
|
|
|
'', |
486
|
|
|
// Sessions |
487
|
|
|
array('databaseSession_enable', $txt['databaseSession_enable'], 'db', 'check', false, 'databaseSession_enable'), |
488
|
|
|
array('databaseSession_loose', $txt['databaseSession_loose'], 'db', 'check', false, 'databaseSession_loose'), |
489
|
|
|
array('databaseSession_lifetime', $txt['databaseSession_lifetime'], 'db', 'int', false, 'databaseSession_lifetime', 'postinput' => $txt['seconds']), |
490
|
|
|
'', |
491
|
|
|
// 2FA |
492
|
|
|
array('tfa_mode', $txt['tfa_mode'], 'db', 'select', array( |
493
|
|
|
0 => $txt['tfa_mode_disabled'], |
494
|
|
|
1 => $txt['tfa_mode_enabled'], |
495
|
|
|
) + (empty($user_settings['tfa_secret']) ? array() : array( |
496
|
|
|
2 => $txt['tfa_mode_forced'], |
497
|
|
|
)) + (empty($user_settings['tfa_secret']) ? array() : array( |
498
|
|
|
3 => $txt['tfa_mode_forcedall'], |
499
|
|
|
)), 'subtext' => $txt['tfa_mode_subtext'] . (empty($user_settings['tfa_secret']) ? '<br><strong>' . $txt['tfa_mode_forced_help'] . '</strong>' : ''), 'tfa_mode'), |
500
|
|
|
); |
501
|
|
|
|
502
|
|
|
addInlineJavaScript(' |
503
|
|
|
function hideGlobalCookies() |
504
|
|
|
{ |
505
|
|
|
var usingLocal = $("#localCookies").prop("checked"); |
506
|
|
|
$("#setting_globalCookies").closest("dt").toggle(!usingLocal); |
507
|
|
|
$("#globalCookies").closest("dd").toggle(!usingLocal); |
508
|
|
|
|
509
|
|
|
var usingGlobal = !usingLocal && $("#globalCookies").prop("checked"); |
510
|
|
|
$("#setting_globalCookiesDomain").closest("dt").toggle(usingGlobal); |
511
|
|
|
$("#globalCookiesDomain").closest("dd").toggle(usingGlobal); |
512
|
|
|
}; |
513
|
|
|
hideGlobalCookies(); |
514
|
|
|
|
515
|
|
|
$("#localCookies, #globalCookies").click(function() { |
516
|
|
|
hideGlobalCookies(); |
517
|
|
|
});', true); |
518
|
|
|
|
519
|
|
|
if (empty($user_settings['tfa_secret'])) |
520
|
|
|
addInlineJavaScript(''); |
521
|
|
|
|
522
|
|
|
call_integration_hook('integrate_cookie_settings', array(&$config_vars)); |
523
|
|
|
|
524
|
|
|
if ($return_config) |
525
|
|
|
return $config_vars; |
526
|
|
|
|
527
|
|
|
$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save'; |
528
|
|
|
$context['settings_title'] = $txt['cookies_sessions_settings']; |
529
|
|
|
|
530
|
|
|
// Saving settings? |
531
|
|
|
if (isset($_REQUEST['save'])) |
532
|
|
|
{ |
533
|
|
|
call_integration_hook('integrate_save_cookie_settings'); |
534
|
|
|
|
535
|
|
|
// Local and global do not play nicely together. |
536
|
|
|
if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) |
537
|
|
|
unset ($_POST['globalCookies']); |
538
|
|
|
|
539
|
|
|
if (empty($modSettings['localCookies']) != empty($_POST['localCookies']) || empty($modSettings['globalCookies']) != empty($_POST['globalCookies'])) |
540
|
|
|
$scope_changed = true; |
541
|
|
|
|
542
|
|
|
if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) |
543
|
|
|
fatal_lang_error('invalid_cookie_domain', false); |
544
|
|
|
|
545
|
|
|
saveSettings($config_vars); |
546
|
|
|
|
547
|
|
|
// If the cookie name or scope were changed, reset the cookie. |
548
|
|
|
if ($cookiename != $_POST['cookiename'] || !empty($scope_changed)) |
549
|
|
|
{ |
550
|
|
|
$original_session_id = $context['session_id']; |
551
|
|
|
include_once($sourcedir . '/Subs-Auth.php'); |
552
|
|
|
|
553
|
|
|
// Remove the old cookie. |
554
|
|
|
setLoginCookie(-3600, 0); |
555
|
|
|
|
556
|
|
|
// Set the new one. |
557
|
|
|
$cookiename = !empty($_POST['cookiename']) ? $_POST['cookiename'] : $cookiename; |
558
|
|
|
setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
559
|
|
|
|
560
|
|
|
redirectexit('action=admin;area=serversettings;sa=cookie;' . $context['session_var'] . '=' . $original_session_id, $context['server']['needs_login_fix']); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
//If we disabled 2FA, reset all members and membergroups settings. |
564
|
|
|
if (isset($_POST['tfa_mode']) && empty($_POST['tfa_mode'])) |
565
|
|
|
{ |
566
|
|
|
$smcFunc['db_query']('', ' |
567
|
|
|
UPDATE {db_prefix}membergroups |
568
|
|
|
SET tfa_required = {int:zero}', |
569
|
|
|
array( |
570
|
|
|
'zero' => 0, |
571
|
|
|
) |
572
|
|
|
); |
573
|
|
|
$smcFunc['db_query']('', ' |
574
|
|
|
UPDATE {db_prefix}members |
575
|
|
|
SET tfa_secret = {string:empty}, tfa_backup = {string:empty}', |
576
|
|
|
array( |
577
|
|
|
'empty' => '', |
578
|
|
|
) |
579
|
|
|
); |
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
$_SESSION['adm-save'] = true; |
583
|
|
|
redirectexit('action=admin;area=serversettings;sa=cookie;' . $context['session_var'] . '=' . $context['session_id']); |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
// Fill the config array. |
587
|
|
|
prepareServerSettingsContext($config_vars); |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
/** |
591
|
|
|
* Settings really associated with general security aspects. |
592
|
|
|
* |
593
|
|
|
* @param bool $return_config Whether or not to return the config_vars array (used for admin search) |
594
|
|
|
* @return void|array Returns nothing or returns the $config_vars array if $return_config is true |
595
|
|
|
*/ |
596
|
|
|
function ModifyGeneralSecuritySettings($return_config = false) |
597
|
|
|
{ |
598
|
|
|
global $txt, $scripturl, $context; |
599
|
|
|
|
600
|
|
|
$config_vars = array( |
601
|
|
|
array('int', 'failed_login_threshold'), |
602
|
|
|
array('int', 'loginHistoryDays', 'subtext' => $txt['zero_to_disable']), |
603
|
|
|
'', |
604
|
|
|
|
605
|
|
|
array('check', 'securityDisable'), |
606
|
|
|
array('check', 'securityDisable_moderate'), |
607
|
|
|
'', |
608
|
|
|
|
609
|
|
|
// Reactive on email, and approve on delete |
610
|
|
|
array('check', 'send_validation_onChange'), |
611
|
|
|
array('check', 'approveAccountDeletion'), |
612
|
|
|
'', |
613
|
|
|
|
614
|
|
|
// Password strength. |
615
|
|
|
array( |
616
|
|
|
'select', |
617
|
|
|
'password_strength', |
618
|
|
|
array( |
619
|
|
|
$txt['setting_password_strength_low'], |
620
|
|
|
$txt['setting_password_strength_medium'], |
621
|
|
|
$txt['setting_password_strength_high'] |
622
|
|
|
) |
623
|
|
|
), |
624
|
|
|
array('check', 'enable_password_conversion'), |
625
|
|
|
'', |
626
|
|
|
|
627
|
|
|
// Reporting of personal messages? |
628
|
|
|
array('check', 'enableReportPM'), |
629
|
|
|
'', |
630
|
|
|
|
631
|
|
|
array('check', 'allow_cors'), |
632
|
|
|
array('check', 'allow_cors_credentials'), |
633
|
|
|
array('text', 'cors_domains'), |
634
|
|
|
array('text', 'cors_headers'), |
635
|
|
|
'', |
636
|
|
|
|
637
|
|
|
array( |
638
|
|
|
'select', |
639
|
|
|
'frame_security', |
640
|
|
|
array( |
641
|
|
|
'SAMEORIGIN' => $txt['setting_frame_security_SAMEORIGIN'], |
642
|
|
|
'DENY' => $txt['setting_frame_security_DENY'], |
643
|
|
|
'DISABLE' => $txt['setting_frame_security_DISABLE'] |
644
|
|
|
) |
645
|
|
|
), |
646
|
|
|
'', |
647
|
|
|
|
648
|
|
|
array( |
649
|
|
|
'select', |
650
|
|
|
'proxy_ip_header', |
651
|
|
|
array( |
652
|
|
|
'disabled' => $txt['setting_proxy_ip_header_disabled'], |
653
|
|
|
'autodetect' => $txt['setting_proxy_ip_header_autodetect'], |
654
|
|
|
'HTTP_X_FORWARDED_FOR' => 'HTTP_X_FORWARDED_FOR', |
655
|
|
|
'HTTP_CLIENT_IP' => 'HTTP_CLIENT_IP', |
656
|
|
|
'HTTP_X_REAL_IP' => 'HTTP_X_REAL_IP', |
657
|
|
|
'CF-Connecting-IP' => 'CF-Connecting-IP' |
658
|
|
|
) |
659
|
|
|
), |
660
|
|
|
array('text', 'proxy_ip_servers'), |
661
|
|
|
); |
662
|
|
|
|
663
|
|
|
call_integration_hook('integrate_general_security_settings', array(&$config_vars)); |
664
|
|
|
|
665
|
|
|
if ($return_config) |
666
|
|
|
return $config_vars; |
667
|
|
|
|
668
|
|
|
// Saving? |
669
|
|
|
if (isset($_GET['save'])) |
670
|
|
|
{ |
671
|
|
|
saveDBSettings($config_vars); |
672
|
|
|
$_SESSION['adm-save'] = true; |
673
|
|
|
|
674
|
|
|
call_integration_hook('integrate_save_general_security_settings'); |
675
|
|
|
|
676
|
|
|
writeLog(); |
677
|
|
|
redirectexit('action=admin;area=serversettings;sa=security;' . $context['session_var'] . '=' . $context['session_id']); |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
$context['post_url'] = $scripturl . '?action=admin;area=serversettings;save;sa=security'; |
681
|
|
|
$context['settings_title'] = $txt['security_settings']; |
682
|
|
|
|
683
|
|
|
prepareDBSettingContext($config_vars); |
684
|
|
|
} |
685
|
|
|
|
686
|
|
|
/** |
687
|
|
|
* Simply modifying cache functions |
688
|
|
|
* |
689
|
|
|
* @param bool $return_config Whether or not to return the config_vars array (used for admin search) |
690
|
|
|
* @return void|array Returns nothing or returns the $config_vars array if $return_config is true |
691
|
|
|
*/ |
692
|
|
|
function ModifyCacheSettings($return_config = false) |
693
|
|
|
{ |
694
|
|
|
global $context, $scripturl, $txt; |
695
|
|
|
|
696
|
|
|
// Detect all available optimizers |
697
|
|
|
$detectedCacheApis = loadCacheAPIs(); |
698
|
|
|
$apis_names = array(); |
699
|
|
|
|
700
|
|
|
/* @var CacheApiInterface $cache_api */ |
701
|
|
|
foreach ($detectedCacheApis as $class_name => $cache_api) |
702
|
|
|
{ |
703
|
|
|
$class_name_txt_key = strtolower($cache_api->getImplementationClassKeyName()); |
704
|
|
|
|
705
|
|
|
$apis_names[$class_name] = isset($txt[$class_name_txt_key . '_cache']) ? |
706
|
|
|
$txt[$class_name_txt_key . '_cache'] : $class_name; |
707
|
|
|
} |
708
|
|
|
|
709
|
|
|
// set our values to show what, if anything, we found |
710
|
|
|
if (empty($detectedCacheApis)) |
711
|
|
|
{ |
712
|
|
|
$txt['cache_settings_message'] = '<strong class="alert">' . $txt['detected_no_caching'] . '</strong>'; |
713
|
|
|
$cache_level = array($txt['cache_off']); |
714
|
|
|
$apis_names['none'] = $txt['cache_off']; |
715
|
|
|
} |
716
|
|
|
|
717
|
|
|
else |
718
|
|
|
{ |
719
|
|
|
$txt['cache_settings_message'] = '<strong class="success">' . |
720
|
|
|
sprintf($txt['detected_accelerators'], implode(', ', $apis_names)) . '</strong>'; |
721
|
|
|
|
722
|
|
|
$cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']); |
723
|
|
|
} |
724
|
|
|
|
725
|
|
|
// Define the variables we want to edit. |
726
|
|
|
$config_vars = array( |
727
|
|
|
// Only a few settings, but they are important |
728
|
|
|
array('', $txt['cache_settings_message'], '', 'desc'), |
729
|
|
|
array('cache_enable', $txt['cache_enable'], 'file', 'select', $cache_level, 'cache_enable'), |
730
|
|
|
array('cache_accelerator', $txt['cache_accelerator'], 'file', 'select', $apis_names), |
731
|
|
|
); |
732
|
|
|
|
733
|
|
|
// some javascript to enable / disable certain settings if the option is not selected |
734
|
|
|
$context['settings_post_javascript'] = ' |
735
|
|
|
$(document).ready(function() { |
736
|
|
|
$("#cache_accelerator").change(); |
737
|
|
|
});'; |
738
|
|
|
|
739
|
|
|
call_integration_hook('integrate_modify_cache_settings', array(&$config_vars)); |
740
|
|
|
|
741
|
|
|
// Maybe we have some additional settings from the selected accelerator. |
742
|
|
|
if (!empty($detectedCacheApis)) |
743
|
|
|
/* @var CacheApiInterface $cache_api */ |
744
|
|
|
foreach ($detectedCacheApis as $class_name_txt_key => $cache_api) |
745
|
|
|
if (is_callable(array($cache_api, 'cacheSettings'))) |
746
|
|
|
$cache_api->cacheSettings($config_vars); |
747
|
|
|
|
748
|
|
|
if ($return_config) |
749
|
|
|
return $config_vars; |
750
|
|
|
|
751
|
|
|
// Saving again? |
752
|
|
|
if (isset($_GET['save'])) |
753
|
|
|
{ |
754
|
|
|
call_integration_hook('integrate_save_cache_settings'); |
755
|
|
|
|
756
|
|
|
saveSettings($config_vars); |
757
|
|
|
$_SESSION['adm-save'] = true; |
758
|
|
|
|
759
|
|
|
// We need to save the $cache_enable to $modSettings as well |
760
|
|
|
updatesettings(array('cache_enable' => (int) $_POST['cache_enable'])); |
761
|
|
|
|
762
|
|
|
// exit so we reload our new settings on the page |
763
|
|
|
redirectexit('action=admin;area=serversettings;sa=cache;' . $context['session_var'] . '=' . $context['session_id']); |
764
|
|
|
} |
765
|
|
|
|
766
|
|
|
loadLanguage('ManageMaintenance'); |
767
|
|
|
createToken('admin-maint'); |
768
|
|
|
$context['template_layers'][] = 'clean_cache_button'; |
769
|
|
|
|
770
|
|
|
$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cache;save'; |
771
|
|
|
$context['settings_title'] = $txt['caching_settings']; |
772
|
|
|
|
773
|
|
|
// Changing cache settings won't have any effect if Settings.php is not writable. |
774
|
|
|
$context['save_disabled'] = $context['settings_not_writable']; |
775
|
|
|
|
776
|
|
|
// Decide what message to show. |
777
|
|
|
if (!$context['save_disabled']) |
778
|
|
|
$context['settings_message'] = $txt['caching_information']; |
779
|
|
|
|
780
|
|
|
// Prepare the template. |
781
|
|
|
prepareServerSettingsContext($config_vars); |
782
|
|
|
} |
783
|
|
|
|
784
|
|
|
/** |
785
|
|
|
* Controls settings for data export functionality |
786
|
|
|
* |
787
|
|
|
* @param bool $return_config Whether or not to return the config_vars array (used for admin search) |
788
|
|
|
* @return void|array Returns nothing or returns the $config_vars array if $return_config is true |
789
|
|
|
*/ |
790
|
|
|
function ModifyExportSettings($return_config = false) |
791
|
|
|
{ |
792
|
|
|
global $context, $scripturl, $txt, $modSettings, $boarddir, $sourcedir; |
793
|
|
|
|
794
|
|
|
// Fill in a default value for this if it is missing. |
795
|
|
|
if (empty($modSettings['export_dir'])) |
796
|
|
|
$modSettings['export_dir'] = $boarddir . DIRECTORY_SEPARATOR . 'exports'; |
797
|
|
|
|
798
|
|
|
/* Some paranoid hosts worry that the disk space functions pose a security risk. Usually these |
799
|
|
|
* hosts just disable the functions and move on, which is fine. A rare few, however, are not |
800
|
|
|
* only paranoid, but also think it'd be a "clever" security move to overload the disk space |
801
|
|
|
* functions with custom code that intentionally delivers false information, which is idiotic |
802
|
|
|
* and evil. At any rate, if the functions are unavailable or if they report obviously insane |
803
|
|
|
* values, it's not possible to track disk usage correctly. */ |
804
|
|
|
$diskspace_disabled = (!function_exists('disk_free_space') || !function_exists('disk_total_space') || intval(@disk_total_space(file_exists($modSettings['export_dir']) ? $modSettings['export_dir'] : $boarddir)) < 1440); |
805
|
|
|
|
806
|
|
|
$context['settings_message'] = $txt['export_settings_description']; |
807
|
|
|
|
808
|
|
|
$config_vars = array( |
809
|
|
|
array('text', 'export_dir', 40), |
810
|
|
|
array('int', 'export_expiry', 'subtext' => $txt['zero_to_disable'], 'postinput' => $txt['days_word']), |
811
|
|
|
array('int', 'export_min_diskspace_pct', 'postinput' => '%', 'max' => 80, 'disabled' => $diskspace_disabled), |
812
|
|
|
array('int', 'export_rate', 'min' => 5, 'max' => 500, 'step' => 5, 'subtext' => $txt['export_rate_desc']), |
813
|
|
|
); |
814
|
|
|
|
815
|
|
|
call_integration_hook('integrate_export_settings', array(&$config_vars)); |
816
|
|
|
|
817
|
|
|
if ($return_config) |
818
|
|
|
return $config_vars; |
819
|
|
|
|
820
|
|
|
if (isset($_REQUEST['save'])) |
821
|
|
|
{ |
822
|
|
|
$prev_export_dir = file_exists($modSettings['export_dir']) ? rtrim($modSettings['export_dir'], '/\\') : ''; |
823
|
|
|
|
824
|
|
|
if (!empty($_POST['export_dir'])) |
825
|
|
|
$_POST['export_dir'] = rtrim($_POST['export_dir'], '/\\'); |
826
|
|
|
|
827
|
|
|
if ($diskspace_disabled) |
828
|
|
|
$_POST['export_min_diskspace_pct'] = 0; |
829
|
|
|
|
830
|
|
|
$_POST['export_rate'] = max(5, min($_POST['export_rate'], 500)); |
831
|
|
|
|
832
|
|
|
saveDBSettings($config_vars); |
833
|
|
|
|
834
|
|
|
// Create the new directory, but revert to the previous one if anything goes wrong. |
835
|
|
|
require_once($sourcedir . '/Profile-Export.php'); |
836
|
|
|
create_export_dir($prev_export_dir); |
837
|
|
|
|
838
|
|
|
// Ensure we don't lose track of any existing export files. |
839
|
|
|
if (!empty($prev_export_dir) && $prev_export_dir != $modSettings['export_dir']) |
840
|
|
|
{ |
841
|
|
|
$export_files = glob($prev_export_dir . DIRECTORY_SEPARATOR . '*'); |
842
|
|
|
|
843
|
|
|
foreach ($export_files as $export_file) |
844
|
|
|
{ |
845
|
|
|
if (!in_array(basename($export_file), array('index.php', '.htaccess'))) |
846
|
|
|
{ |
847
|
|
|
rename($export_file, $modSettings['export_dir'] . DIRECTORY_SEPARATOR . basename($export_file)); |
848
|
|
|
} |
849
|
|
|
} |
850
|
|
|
} |
851
|
|
|
|
852
|
|
|
call_integration_hook('integrate_save_export_settings'); |
853
|
|
|
|
854
|
|
|
$_SESSION['adm-save'] = true; |
855
|
|
|
redirectexit('action=admin;area=serversettings;sa=export;' . $context['session_var'] . '=' . $context['session_id']); |
856
|
|
|
} |
857
|
|
|
|
858
|
|
|
$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=export;save'; |
859
|
|
|
$context['settings_title'] = $txt['export_settings']; |
860
|
|
|
|
861
|
|
|
prepareDBSettingContext($config_vars); |
862
|
|
|
} |
863
|
|
|
|
864
|
|
|
/** |
865
|
|
|
* Allows to edit load balancing settings. |
866
|
|
|
* |
867
|
|
|
* @param bool $return_config Whether or not to return the config_vars array |
868
|
|
|
* @return void|array Returns nothing or returns the $config_vars array if $return_config is true |
869
|
|
|
*/ |
870
|
|
|
function ModifyLoadBalancingSettings($return_config = false) |
871
|
|
|
{ |
872
|
|
|
global $txt, $scripturl, $context, $modSettings; |
873
|
|
|
|
874
|
|
|
// Setup a warning message, but disabled by default. |
875
|
|
|
$disabled = true; |
876
|
|
|
$context['settings_message'] = array('label' => $txt['loadavg_disabled_conf'], 'class' => 'error'); |
877
|
|
|
|
878
|
|
|
if (DIRECTORY_SEPARATOR === '\\') |
879
|
|
|
{ |
880
|
|
|
$context['settings_message']['label'] = $txt['loadavg_disabled_windows']; |
881
|
|
|
if (isset($_GET['save'])) |
882
|
|
|
$_SESSION['adm-save'] = $context['settings_message']['label']; |
883
|
|
|
} |
884
|
|
|
elseif (stripos(PHP_OS, 'darwin') === 0) |
885
|
|
|
{ |
886
|
|
|
$context['settings_message']['label'] = $txt['loadavg_disabled_osx']; |
887
|
|
|
if (isset($_GET['save'])) |
888
|
|
|
$_SESSION['adm-save'] = $context['settings_message']['label']; |
889
|
|
|
} |
890
|
|
|
else |
891
|
|
|
{ |
892
|
|
|
$modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
893
|
|
|
if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) |
894
|
|
|
$modSettings['load_average'] = (float) $matches[1]; |
895
|
|
|
elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) |
896
|
|
|
$modSettings['load_average'] = (float) $matches[1]; |
897
|
|
|
else |
898
|
|
|
unset($modSettings['load_average']); |
899
|
|
|
|
900
|
|
|
if (!empty($modSettings['load_average']) || (isset($modSettings['load_average']) && $modSettings['load_average'] === 0.0)) |
901
|
|
|
{ |
902
|
|
|
$context['settings_message']['label'] = sprintf($txt['loadavg_warning'], $modSettings['load_average']); |
903
|
|
|
$disabled = false; |
904
|
|
|
} |
905
|
|
|
} |
906
|
|
|
|
907
|
|
|
// Start with a simple checkbox. |
908
|
|
|
$config_vars = array( |
909
|
|
|
array('check', 'loadavg_enable', 'disabled' => $disabled), |
910
|
|
|
); |
911
|
|
|
|
912
|
|
|
// Set the default values for each option. |
913
|
|
|
$default_values = array( |
914
|
|
|
'loadavg_auto_opt' => 1.0, |
915
|
|
|
'loadavg_search' => 2.5, |
916
|
|
|
'loadavg_allunread' => 2.0, |
917
|
|
|
'loadavg_unreadreplies' => 3.5, |
918
|
|
|
'loadavg_show_posts' => 2.0, |
919
|
|
|
'loadavg_userstats' => 10.0, |
920
|
|
|
'loadavg_bbc' => 30.0, |
921
|
|
|
'loadavg_forum' => 40.0, |
922
|
|
|
); |
923
|
|
|
|
924
|
|
|
// Loop through the settings. |
925
|
|
|
foreach ($default_values as $name => $value) |
926
|
|
|
{ |
927
|
|
|
// Use the default value if the setting isn't set yet. |
928
|
|
|
$value = !isset($modSettings[$name]) ? $value : $modSettings[$name]; |
929
|
|
|
$config_vars[] = array('float', $name, 'value' => $value, 'disabled' => $disabled); |
930
|
|
|
} |
931
|
|
|
|
932
|
|
|
call_integration_hook('integrate_loadavg_settings', array(&$config_vars)); |
933
|
|
|
|
934
|
|
|
if ($return_config) |
935
|
|
|
return $config_vars; |
936
|
|
|
|
937
|
|
|
$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save'; |
938
|
|
|
$context['settings_title'] = $txt['load_balancing_settings']; |
939
|
|
|
|
940
|
|
|
// Saving? |
941
|
|
|
if (isset($_GET['save'])) |
942
|
|
|
{ |
943
|
|
|
// Stupidity is not allowed. |
944
|
|
|
foreach ($_POST as $key => $value) |
945
|
|
|
{ |
946
|
|
|
if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) |
947
|
|
|
continue; |
948
|
|
|
else |
949
|
|
|
$_POST[$key] = (float) $value; |
950
|
|
|
|
951
|
|
|
if ($key == 'loadavg_auto_opt' && $value <= 1) |
952
|
|
|
$_POST['loadavg_auto_opt'] = 1.0; |
953
|
|
|
elseif ($key == 'loadavg_forum' && $value < 10) |
954
|
|
|
$_POST['loadavg_forum'] = 10.0; |
955
|
|
|
elseif ($value < 2) |
956
|
|
|
$_POST[$key] = 2.0; |
957
|
|
|
} |
958
|
|
|
|
959
|
|
|
call_integration_hook('integrate_save_loadavg_settings'); |
960
|
|
|
|
961
|
|
|
saveDBSettings($config_vars); |
962
|
|
|
if (!isset($_SESSION['adm-save'])) |
963
|
|
|
$_SESSION['adm-save'] = true; |
964
|
|
|
redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']); |
965
|
|
|
} |
966
|
|
|
|
967
|
|
|
prepareDBSettingContext($config_vars); |
968
|
|
|
} |
969
|
|
|
|
970
|
|
|
/** |
971
|
|
|
* Helper function, it sets up the context for the manage server settings. |
972
|
|
|
* - The basic usage of the six numbered key fields are |
973
|
|
|
* - array (0 ,1, 2, 3, 4, 5 |
974
|
|
|
* 0 variable name - the name of the saved variable |
975
|
|
|
* 1 label - the text to show on the settings page |
976
|
|
|
* 2 saveto - file or db, where to save the variable name - value pair |
977
|
|
|
* 3 type - type of data to save, int, float, text, check |
978
|
|
|
* 4 size - false or field size |
979
|
|
|
* 5 help - '' or helptxt variable name |
980
|
|
|
* ) |
981
|
|
|
* |
982
|
|
|
* the following named keys are also permitted |
983
|
|
|
* 'disabled' => A string of code that will determine whether or not the setting should be disabled |
984
|
|
|
* 'postinput' => Text to display after the input field |
985
|
|
|
* 'preinput' => Text to display before the input field |
986
|
|
|
* 'subtext' => Additional descriptive text to display under the field's label |
987
|
|
|
* 'min' => minimum allowed value (for int/float). Defaults to 0 if not set. |
988
|
|
|
* 'max' => maximum allowed value (for int/float) |
989
|
|
|
* 'step' => how much to increment/decrement the value by (only for int/float - mostly used for float values). |
990
|
|
|
* |
991
|
|
|
* @param array $config_vars An array of configuration variables |
992
|
|
|
*/ |
993
|
|
|
function prepareServerSettingsContext(&$config_vars) |
994
|
|
|
{ |
995
|
|
|
global $context, $modSettings, $smcFunc; |
996
|
|
|
|
997
|
|
|
if (isset($_SESSION['adm-save'])) |
998
|
|
|
{ |
999
|
|
|
if ($_SESSION['adm-save'] === true) |
1000
|
|
|
$context['saved_successful'] = true; |
1001
|
|
|
else |
1002
|
|
|
$context['saved_failed'] = $_SESSION['adm-save']; |
1003
|
|
|
|
1004
|
|
|
unset($_SESSION['adm-save']); |
1005
|
|
|
} |
1006
|
|
|
|
1007
|
|
|
$context['config_vars'] = array(); |
1008
|
|
|
foreach ($config_vars as $identifier => $config_var) |
1009
|
|
|
{ |
1010
|
|
|
if (!is_array($config_var) || !isset($config_var[1])) |
1011
|
|
|
$context['config_vars'][] = $config_var; |
1012
|
|
|
else |
1013
|
|
|
{ |
1014
|
|
|
$varname = $config_var[0]; |
1015
|
|
|
global $$varname; |
1016
|
|
|
|
1017
|
|
|
// Set the subtext in case it's part of the label. |
1018
|
|
|
// @todo Temporary. Preventing divs inside label tags. |
1019
|
|
|
$divPos = strpos($config_var[1], '<div'); |
1020
|
|
|
$subtext = ''; |
1021
|
|
|
if ($divPos !== false) |
1022
|
|
|
{ |
1023
|
|
|
$subtext = preg_replace('~</?div[^>]*>~', '', substr($config_var[1], $divPos)); |
1024
|
|
|
$config_var[1] = substr($config_var[1], 0, $divPos); |
1025
|
|
|
} |
1026
|
|
|
|
1027
|
|
|
$context['config_vars'][$config_var[0]] = array( |
1028
|
|
|
'label' => $config_var[1], |
1029
|
|
|
'help' => isset($config_var[5]) ? $config_var[5] : '', |
1030
|
|
|
'type' => $config_var[3], |
1031
|
|
|
'size' => !empty($config_var[4]) && !is_array($config_var[4]) ? $config_var[4] : 0, |
1032
|
|
|
'data' => isset($config_var[4]) && is_array($config_var[4]) && $config_var[3] != 'select' ? $config_var[4] : array(), |
1033
|
|
|
'name' => $config_var[0], |
1034
|
|
|
'value' => $config_var[2] == 'file' ? $smcFunc['htmlspecialchars']($$varname) : (isset($modSettings[$config_var[0]]) ? $smcFunc['htmlspecialchars']($modSettings[$config_var[0]]) : (in_array($config_var[3], array('int', 'float')) ? 0 : '')), |
1035
|
|
|
'disabled' => !empty($context['settings_not_writable']) || !empty($config_var['disabled']), |
1036
|
|
|
'invalid' => false, |
1037
|
|
|
'subtext' => !empty($config_var['subtext']) ? $config_var['subtext'] : $subtext, |
1038
|
|
|
'javascript' => '', |
1039
|
|
|
'preinput' => !empty($config_var['preinput']) ? $config_var['preinput'] : '', |
1040
|
|
|
'postinput' => !empty($config_var['postinput']) ? $config_var['postinput'] : '', |
1041
|
|
|
); |
1042
|
|
|
|
1043
|
|
|
// Handle min/max/step if necessary |
1044
|
|
|
if ($config_var[3] == 'int' || $config_var[3] == 'float') |
1045
|
|
|
{ |
1046
|
|
|
// Default to a min of 0 if one isn't set |
1047
|
|
|
if (isset($config_var['min'])) |
1048
|
|
|
$context['config_vars'][$config_var[0]]['min'] = $config_var['min']; |
1049
|
|
|
else |
1050
|
|
|
$context['config_vars'][$config_var[0]]['min'] = 0; |
1051
|
|
|
|
1052
|
|
|
if (isset($config_var['max'])) |
1053
|
|
|
$context['config_vars'][$config_var[0]]['max'] = $config_var['max']; |
1054
|
|
|
|
1055
|
|
|
if (isset($config_var['step'])) |
1056
|
|
|
$context['config_vars'][$config_var[0]]['step'] = $config_var['step']; |
1057
|
|
|
} |
1058
|
|
|
|
1059
|
|
|
// If this is a select box handle any data. |
1060
|
|
|
if (!empty($config_var[4]) && is_array($config_var[4])) |
1061
|
|
|
{ |
1062
|
|
|
// If it's associative |
1063
|
|
|
$config_values = array_values($config_var[4]); |
1064
|
|
|
if (isset($config_values[0]) && is_array($config_values[0])) |
1065
|
|
|
$context['config_vars'][$config_var[0]]['data'] = $config_var[4]; |
1066
|
|
|
else |
1067
|
|
|
{ |
1068
|
|
|
foreach ($config_var[4] as $key => $item) |
1069
|
|
|
$context['config_vars'][$config_var[0]]['data'][] = array($key, $item); |
1070
|
|
|
} |
1071
|
|
|
} |
1072
|
|
|
} |
1073
|
|
|
} |
1074
|
|
|
|
1075
|
|
|
// Two tokens because saving these settings requires both saveSettings and saveDBSettings |
1076
|
|
|
createToken('admin-ssc'); |
1077
|
|
|
createToken('admin-dbsc'); |
1078
|
|
|
} |
1079
|
|
|
|
1080
|
|
|
/** |
1081
|
|
|
* Helper function, it sets up the context for database settings. |
1082
|
|
|
* |
1083
|
|
|
* @todo see rev. 10406 from 2.1-requests |
1084
|
|
|
* |
1085
|
|
|
* @param array $config_vars An array of configuration variables |
1086
|
|
|
*/ |
1087
|
|
|
function prepareDBSettingContext(&$config_vars) |
1088
|
|
|
{ |
1089
|
|
|
global $txt, $helptxt, $context, $modSettings, $sourcedir, $smcFunc; |
1090
|
|
|
|
1091
|
|
|
loadLanguage('Help'); |
1092
|
|
|
|
1093
|
|
|
if (isset($_SESSION['adm-save'])) |
1094
|
|
|
{ |
1095
|
|
|
if ($_SESSION['adm-save'] === true) |
1096
|
|
|
$context['saved_successful'] = true; |
1097
|
|
|
else |
1098
|
|
|
$context['saved_failed'] = $_SESSION['adm-save']; |
1099
|
|
|
|
1100
|
|
|
unset($_SESSION['adm-save']); |
1101
|
|
|
} |
1102
|
|
|
|
1103
|
|
|
$context['config_vars'] = array(); |
1104
|
|
|
$inlinePermissions = array(); |
1105
|
|
|
$bbcChoice = array(); |
1106
|
|
|
$board_list = false; |
1107
|
|
|
foreach ($config_vars as $config_var) |
1108
|
|
|
{ |
1109
|
|
|
// HR? |
1110
|
|
|
if (!is_array($config_var)) |
1111
|
|
|
$context['config_vars'][] = $config_var; |
1112
|
|
|
else |
1113
|
|
|
{ |
1114
|
|
|
// If it has no name it doesn't have any purpose! |
1115
|
|
|
if (empty($config_var[1])) |
1116
|
|
|
continue; |
1117
|
|
|
|
1118
|
|
|
// Special case for inline permissions |
1119
|
|
|
if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) |
1120
|
|
|
$inlinePermissions[] = $config_var[1]; |
1121
|
|
|
|
1122
|
|
|
elseif ($config_var[0] == 'permissions') |
1123
|
|
|
continue; |
1124
|
|
|
|
1125
|
|
|
if ($config_var[0] == 'boards') |
1126
|
|
|
$board_list = true; |
1127
|
|
|
|
1128
|
|
|
// Are we showing the BBC selection box? |
1129
|
|
|
if ($config_var[0] == 'bbc') |
1130
|
|
|
$bbcChoice[] = $config_var[1]; |
1131
|
|
|
|
1132
|
|
|
// We need to do some parsing of the value before we pass it in. |
1133
|
|
|
if (isset($modSettings[$config_var[1]])) |
1134
|
|
|
{ |
1135
|
|
|
switch ($config_var[0]) |
1136
|
|
|
{ |
1137
|
|
|
case 'select': |
1138
|
|
|
$value = $modSettings[$config_var[1]]; |
1139
|
|
|
break; |
1140
|
|
|
case 'json': |
1141
|
|
|
$value = $smcFunc['htmlspecialchars']($smcFunc['json_encode']($modSettings[$config_var[1]])); |
1142
|
|
|
break; |
1143
|
|
|
case 'boards': |
1144
|
|
|
$value = explode(',', $modSettings[$config_var[1]]); |
1145
|
|
|
break; |
1146
|
|
|
default: |
1147
|
|
|
$value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]); |
1148
|
|
|
} |
1149
|
|
|
} |
1150
|
|
|
else |
1151
|
|
|
{ |
1152
|
|
|
// Darn, it's empty. What type is expected? |
1153
|
|
|
switch ($config_var[0]) |
1154
|
|
|
{ |
1155
|
|
|
case 'int': |
1156
|
|
|
case 'float': |
1157
|
|
|
$value = 0; |
1158
|
|
|
break; |
1159
|
|
|
case 'select': |
1160
|
|
|
$value = !empty($config_var['multiple']) ? $smcFunc['json_encode'](array()) : ''; |
1161
|
|
|
break; |
1162
|
|
|
case 'boards': |
1163
|
|
|
$value = array(); |
1164
|
|
|
break; |
1165
|
|
|
default: |
1166
|
|
|
$value = ''; |
1167
|
|
|
} |
1168
|
|
|
} |
1169
|
|
|
|
1170
|
|
|
$context['config_vars'][$config_var[1]] = array( |
1171
|
|
|
'label' => isset($config_var['text_label']) ? $config_var['text_label'] : (isset($txt[$config_var[1]]) ? $txt[$config_var[1]] : (isset($config_var[3]) && !is_array($config_var[3]) ? $config_var[3] : '')), |
1172
|
|
|
'help' => isset($helptxt[$config_var[1]]) ? $config_var[1] : '', |
1173
|
|
|
'type' => $config_var[0], |
1174
|
|
|
'size' => !empty($config_var['size']) ? $config_var['size'] : (!empty($config_var[2]) && !is_array($config_var[2]) ? $config_var[2] : (in_array($config_var[0], array('int', 'float')) ? 6 : 0)), |
1175
|
|
|
'data' => array(), |
1176
|
|
|
'name' => $config_var[1], |
1177
|
|
|
'value' => $value, |
1178
|
|
|
'disabled' => false, |
1179
|
|
|
'invalid' => !empty($config_var['invalid']), |
1180
|
|
|
'javascript' => '', |
1181
|
|
|
'var_message' => !empty($config_var['message']) && isset($txt[$config_var['message']]) ? $txt[$config_var['message']] : '', |
1182
|
|
|
'preinput' => isset($config_var['preinput']) ? $config_var['preinput'] : '', |
1183
|
|
|
'postinput' => isset($config_var['postinput']) ? $config_var['postinput'] : '', |
1184
|
|
|
); |
1185
|
|
|
|
1186
|
|
|
// Handle min/max/step if necessary |
1187
|
|
|
if ($config_var[0] == 'int' || $config_var[0] == 'float') |
1188
|
|
|
{ |
1189
|
|
|
// Default to a min of 0 if one isn't set |
1190
|
|
|
if (isset($config_var['min'])) |
1191
|
|
|
$context['config_vars'][$config_var[1]]['min'] = $config_var['min']; |
1192
|
|
|
|
1193
|
|
|
else |
1194
|
|
|
$context['config_vars'][$config_var[1]]['min'] = 0; |
1195
|
|
|
|
1196
|
|
|
if (isset($config_var['max'])) |
1197
|
|
|
$context['config_vars'][$config_var[1]]['max'] = $config_var['max']; |
1198
|
|
|
|
1199
|
|
|
if (isset($config_var['step'])) |
1200
|
|
|
$context['config_vars'][$config_var[1]]['step'] = $config_var['step']; |
1201
|
|
|
} |
1202
|
|
|
|
1203
|
|
|
// If this is a select box handle any data. |
1204
|
|
|
if (!empty($config_var[2]) && is_array($config_var[2])) |
1205
|
|
|
{ |
1206
|
|
|
// If we allow multiple selections, we need to adjust a few things. |
1207
|
|
|
if ($config_var[0] == 'select' && !empty($config_var['multiple'])) |
1208
|
|
|
{ |
1209
|
|
|
$context['config_vars'][$config_var[1]]['name'] .= '[]'; |
1210
|
|
|
$context['config_vars'][$config_var[1]]['value'] = !empty($context['config_vars'][$config_var[1]]['value']) ? $smcFunc['json_decode']($context['config_vars'][$config_var[1]]['value'], true) : array(); |
1211
|
|
|
} |
1212
|
|
|
|
1213
|
|
|
// If it's associative |
1214
|
|
|
if (isset($config_var[2][0]) && is_array($config_var[2][0])) |
1215
|
|
|
$context['config_vars'][$config_var[1]]['data'] = $config_var[2]; |
1216
|
|
|
|
1217
|
|
|
else |
1218
|
|
|
{ |
1219
|
|
|
foreach ($config_var[2] as $key => $item) |
1220
|
|
|
$context['config_vars'][$config_var[1]]['data'][] = array($key, $item); |
1221
|
|
|
} |
1222
|
|
|
if (empty($config_var['size']) && !empty($config_var['multiple'])) |
1223
|
|
|
$context['config_vars'][$config_var[1]]['size'] = max(4, count($config_var[2])); |
1224
|
|
|
} |
1225
|
|
|
|
1226
|
|
|
// Finally allow overrides - and some final cleanups. |
1227
|
|
|
foreach ($config_var as $k => $v) |
1228
|
|
|
{ |
1229
|
|
|
if (!is_numeric($k)) |
1230
|
|
|
{ |
1231
|
|
|
if (substr($k, 0, 2) == 'on') |
1232
|
|
|
$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"'; |
1233
|
|
|
else |
1234
|
|
|
$context['config_vars'][$config_var[1]][$k] = $v; |
1235
|
|
|
} |
1236
|
|
|
|
1237
|
|
|
// See if there are any other labels that might fit? |
1238
|
|
|
if (isset($txt['setting_' . $config_var[1]])) |
1239
|
|
|
$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]]; |
1240
|
|
|
|
1241
|
|
|
elseif (isset($txt['groups_' . $config_var[1]])) |
1242
|
|
|
$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]]; |
1243
|
|
|
} |
1244
|
|
|
|
1245
|
|
|
// Set the subtext in case it's part of the label. |
1246
|
|
|
// @todo Temporary. Preventing divs inside label tags. |
1247
|
|
|
$divPos = strpos($context['config_vars'][$config_var[1]]['label'], '<div'); |
1248
|
|
|
if ($divPos !== false) |
1249
|
|
|
{ |
1250
|
|
|
$context['config_vars'][$config_var[1]]['subtext'] = preg_replace('~</?div[^>]*>~', '', substr($context['config_vars'][$config_var[1]]['label'], $divPos)); |
1251
|
|
|
$context['config_vars'][$config_var[1]]['label'] = substr($context['config_vars'][$config_var[1]]['label'], 0, $divPos); |
1252
|
|
|
} |
1253
|
|
|
} |
1254
|
|
|
} |
1255
|
|
|
|
1256
|
|
|
// If we have inline permissions we need to prep them. |
1257
|
|
|
if (!empty($inlinePermissions) && allowedTo('manage_permissions')) |
1258
|
|
|
{ |
1259
|
|
|
require_once($sourcedir . '/ManagePermissions.php'); |
1260
|
|
|
init_inline_permissions($inlinePermissions); |
1261
|
|
|
} |
1262
|
|
|
|
1263
|
|
|
if ($board_list) |
1264
|
|
|
{ |
1265
|
|
|
require_once($sourcedir . '/Subs-MessageIndex.php'); |
1266
|
|
|
$context['board_list'] = getBoardList(); |
1267
|
|
|
} |
1268
|
|
|
|
1269
|
|
|
// What about any BBC selection boxes? |
1270
|
|
|
if (!empty($bbcChoice)) |
1271
|
|
|
{ |
1272
|
|
|
// What are the options, eh? |
1273
|
|
|
$temp = parse_bbc(false); |
1274
|
|
|
$bbcTags = array(); |
1275
|
|
|
foreach ($temp as $tag) |
|
|
|
|
1276
|
|
|
if (!isset($tag['require_parents'])) |
1277
|
|
|
$bbcTags[] = $tag['tag']; |
1278
|
|
|
|
1279
|
|
|
$bbcTags = array_unique($bbcTags); |
1280
|
|
|
|
1281
|
|
|
// The number of columns we want to show the BBC tags in. |
1282
|
|
|
$numColumns = isset($context['num_bbc_columns']) ? $context['num_bbc_columns'] : 3; |
1283
|
|
|
|
1284
|
|
|
// Now put whatever BBC options we may have into context too! |
1285
|
|
|
$context['bbc_sections'] = array(); |
1286
|
|
|
foreach ($bbcChoice as $bbcSection) |
1287
|
|
|
{ |
1288
|
|
|
$context['bbc_sections'][$bbcSection] = array( |
1289
|
|
|
'title' => isset($txt['bbc_title_' . $bbcSection]) ? $txt['bbc_title_' . $bbcSection] : $txt['enabled_bbc_select'], |
1290
|
|
|
'disabled' => empty($modSettings['bbc_disabled_' . $bbcSection]) ? array() : $modSettings['bbc_disabled_' . $bbcSection], |
1291
|
|
|
'all_selected' => empty($modSettings['bbc_disabled_' . $bbcSection]), |
1292
|
|
|
'columns' => array(), |
1293
|
|
|
); |
1294
|
|
|
|
1295
|
|
|
if ($bbcSection == 'legacyBBC') |
1296
|
|
|
$sectionTags = array_intersect($context['legacy_bbc'], $bbcTags); |
1297
|
|
|
else |
1298
|
|
|
$sectionTags = array_diff($bbcTags, $context['legacy_bbc']); |
1299
|
|
|
|
1300
|
|
|
$totalTags = count($sectionTags); |
1301
|
|
|
$tagsPerColumn = ceil($totalTags / $numColumns); |
1302
|
|
|
|
1303
|
|
|
$col = 0; |
1304
|
|
|
$i = 0; |
1305
|
|
|
foreach ($sectionTags as $tag) |
1306
|
|
|
{ |
1307
|
|
|
if ($i % $tagsPerColumn == 0 && $i != 0) |
1308
|
|
|
$col++; |
1309
|
|
|
|
1310
|
|
|
$context['bbc_sections'][$bbcSection]['columns'][$col][] = array( |
1311
|
|
|
'tag' => $tag, |
1312
|
|
|
// @todo 'tag_' . ? |
1313
|
|
|
'show_help' => isset($helptxt[$tag]), |
1314
|
|
|
); |
1315
|
|
|
|
1316
|
|
|
$i++; |
1317
|
|
|
} |
1318
|
|
|
} |
1319
|
|
|
} |
1320
|
|
|
|
1321
|
|
|
call_integration_hook('integrate_prepare_db_settings', array(&$config_vars)); |
1322
|
|
|
createToken('admin-dbsc'); |
1323
|
|
|
} |
1324
|
|
|
|
1325
|
|
|
/** |
1326
|
|
|
* Helper function. Saves settings by putting them in Settings.php or saving them in the settings table. |
1327
|
|
|
* |
1328
|
|
|
* - Saves those settings set from ?action=admin;area=serversettings. |
1329
|
|
|
* - Requires the admin_forum permission. |
1330
|
|
|
* - Contains arrays of the types of data to save into Settings.php. |
1331
|
|
|
* |
1332
|
|
|
* @param array $config_vars An array of configuration variables |
1333
|
|
|
*/ |
1334
|
|
|
function saveSettings(&$config_vars) |
1335
|
|
|
{ |
1336
|
|
|
global $sourcedir, $context; |
1337
|
|
|
|
1338
|
|
|
validateToken('admin-ssc'); |
1339
|
|
|
|
1340
|
|
|
// Fix the darn stupid cookiename! (more may not be allowed, but these for sure!) |
1341
|
|
|
if (isset($_POST['cookiename'])) |
1342
|
|
|
$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']); |
1343
|
|
|
|
1344
|
|
|
// Fix the forum's URL if necessary. |
1345
|
|
|
if (isset($_POST['boardurl'])) |
1346
|
|
|
{ |
1347
|
|
|
if (substr($_POST['boardurl'], -10) == '/index.php') |
1348
|
|
|
$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
1349
|
|
|
elseif (substr($_POST['boardurl'], -1) == '/') |
1350
|
|
|
$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
1351
|
|
|
if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') |
1352
|
|
|
$_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
1353
|
|
|
} |
1354
|
|
|
|
1355
|
|
|
// Any passwords? |
1356
|
|
|
$config_passwords = array( |
1357
|
|
|
'db_passwd', |
1358
|
|
|
'ssi_db_passwd', |
1359
|
|
|
); |
1360
|
|
|
|
1361
|
|
|
// All the strings to write. |
1362
|
|
|
$config_strs = array( |
1363
|
|
|
'mtitle', 'mmessage', |
1364
|
|
|
'language', 'mbname', 'boardurl', |
1365
|
|
|
'cookiename', |
1366
|
|
|
'webmaster_email', |
1367
|
|
|
'db_name', 'db_user', 'db_server', 'db_prefix', 'ssi_db_user', |
1368
|
|
|
'boarddir', 'sourcedir', |
1369
|
|
|
'cachedir', 'cachedir_sqlite', 'cache_accelerator', 'cache_memcached', |
1370
|
|
|
'image_proxy_secret', |
1371
|
|
|
); |
1372
|
|
|
|
1373
|
|
|
// All the numeric variables. |
1374
|
|
|
$config_ints = array( |
1375
|
|
|
'db_port', |
1376
|
|
|
'cache_enable', |
1377
|
|
|
'image_proxy_maxsize', |
1378
|
|
|
); |
1379
|
|
|
|
1380
|
|
|
// All the checkboxes |
1381
|
|
|
$config_bools = array('db_persist', 'db_error_send', 'maintenance', 'image_proxy_enabled'); |
1382
|
|
|
|
1383
|
|
|
// Now sort everything into a big array, and figure out arrays and etc. |
1384
|
|
|
$new_settings = array(); |
1385
|
|
|
// Figure out which config vars we're saving here... |
1386
|
|
|
foreach ($config_vars as $var) |
1387
|
|
|
{ |
1388
|
|
|
if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) |
1389
|
|
|
continue; |
1390
|
|
|
|
1391
|
|
|
$config_var = $var[0]; |
1392
|
|
|
|
1393
|
|
|
if (in_array($config_var, $config_passwords)) |
1394
|
|
|
{ |
1395
|
|
|
if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) |
1396
|
|
|
$new_settings[$config_var] = $_POST[$config_var][0]; |
1397
|
|
|
} |
1398
|
|
|
elseif (in_array($config_var, $config_strs)) |
1399
|
|
|
{ |
1400
|
|
|
$new_settings[$config_var] = $_POST[$config_var]; |
1401
|
|
|
} |
1402
|
|
|
elseif (in_array($config_var, $config_ints)) |
1403
|
|
|
{ |
1404
|
|
|
$new_settings[$config_var] = (int) $_POST[$config_var]; |
1405
|
|
|
|
1406
|
|
|
// If no min is specified, assume 0. This is done to avoid having to specify 'min => 0' for all settings where 0 is the min... |
1407
|
|
|
$min = isset($var['min']) ? $var['min'] : 0; |
1408
|
|
|
$new_settings[$config_var] = max($min, $new_settings[$config_var]); |
1409
|
|
|
|
1410
|
|
|
// Is there a max value for this as well? |
1411
|
|
|
if (isset($var['max'])) |
1412
|
|
|
$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]); |
1413
|
|
|
} |
1414
|
|
|
elseif (in_array($config_var, $config_bools)) |
1415
|
|
|
{ |
1416
|
|
|
if (!empty($_POST[$config_var])) |
1417
|
|
|
$new_settings[$config_var] = 1; |
1418
|
|
|
else |
1419
|
|
|
$new_settings[$config_var] = 0; |
1420
|
|
|
} |
1421
|
|
|
else |
1422
|
|
|
{ |
1423
|
|
|
// This shouldn't happen, but it might... |
1424
|
|
|
fatal_error('Unknown config_var \'' . $config_var . '\''); |
1425
|
|
|
} |
1426
|
|
|
} |
1427
|
|
|
|
1428
|
|
|
// Save the relevant settings in the Settings.php file. |
1429
|
|
|
require_once($sourcedir . '/Subs-Admin.php'); |
1430
|
|
|
updateSettingsFile($new_settings); |
1431
|
|
|
|
1432
|
|
|
// Now loop through the remaining (database-based) settings. |
1433
|
|
|
$new_settings = array(); |
1434
|
|
|
foreach ($config_vars as $config_var) |
1435
|
|
|
{ |
1436
|
|
|
// We just saved the file-based settings, so skip their definitions. |
1437
|
|
|
if (!is_array($config_var) || $config_var[2] == 'file') |
1438
|
|
|
continue; |
1439
|
|
|
|
1440
|
|
|
$new_setting = array($config_var[3], $config_var[0]); |
1441
|
|
|
|
1442
|
|
|
// Select options need carried over, too. |
1443
|
|
|
if (isset($config_var[4])) |
1444
|
|
|
$new_setting[] = $config_var[4]; |
1445
|
|
|
|
1446
|
|
|
// Include min and max if necessary |
1447
|
|
|
if (isset($config_var['min'])) |
1448
|
|
|
$new_setting['min'] = $config_var['min']; |
1449
|
|
|
|
1450
|
|
|
if (isset($config_var['max'])) |
1451
|
|
|
$new_setting['max'] = $config_var['max']; |
1452
|
|
|
|
1453
|
|
|
// Rewrite the definition a bit. |
1454
|
|
|
$new_settings[] = $new_setting; |
1455
|
|
|
} |
1456
|
|
|
|
1457
|
|
|
// Save the new database-based settings, if any. |
1458
|
|
|
if (!empty($new_settings)) |
1459
|
|
|
saveDBSettings($new_settings); |
1460
|
|
|
} |
1461
|
|
|
|
1462
|
|
|
/** |
1463
|
|
|
* Helper function for saving database settings. |
1464
|
|
|
* |
1465
|
|
|
* @todo see rev. 10406 from 2.1-requests |
1466
|
|
|
* |
1467
|
|
|
* @param array $config_vars An array of configuration variables |
1468
|
|
|
*/ |
1469
|
|
|
function saveDBSettings(&$config_vars) |
1470
|
|
|
{ |
1471
|
|
|
global $sourcedir, $smcFunc; |
1472
|
|
|
static $board_list = null; |
1473
|
|
|
|
1474
|
|
|
validateToken('admin-dbsc'); |
1475
|
|
|
|
1476
|
|
|
$inlinePermissions = array(); |
1477
|
|
|
foreach ($config_vars as $var) |
1478
|
|
|
{ |
1479
|
|
|
if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) |
1480
|
|
|
continue; |
1481
|
|
|
|
1482
|
|
|
// Checkboxes! |
1483
|
|
|
elseif ($var[0] == 'check') |
1484
|
|
|
$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0'; |
1485
|
|
|
// Select boxes! |
1486
|
|
|
elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) |
1487
|
|
|
$setArray[$var[1]] = $_POST[$var[1]]; |
1488
|
|
|
elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array()) |
1489
|
|
|
{ |
1490
|
|
|
// For security purposes we validate this line by line. |
1491
|
|
|
$lOptions = array(); |
1492
|
|
|
foreach ($_POST[$var[1]] as $invar) |
1493
|
|
|
if (in_array($invar, array_keys($var[2]))) |
1494
|
|
|
$lOptions[] = $invar; |
1495
|
|
|
|
1496
|
|
|
$setArray[$var[1]] = $smcFunc['json_encode']($lOptions); |
1497
|
|
|
} |
1498
|
|
|
// List of boards! |
1499
|
|
|
elseif ($var[0] == 'boards') |
1500
|
|
|
{ |
1501
|
|
|
// We just need a simple list of valid boards, nothing more. |
1502
|
|
|
if ($board_list === null) |
1503
|
|
|
{ |
1504
|
|
|
$board_list = array(); |
1505
|
|
|
$request = $smcFunc['db_query']('', ' |
1506
|
|
|
SELECT id_board |
1507
|
|
|
FROM {db_prefix}boards'); |
1508
|
|
|
|
1509
|
|
|
while ($row = $smcFunc['db_fetch_row']($request)) |
1510
|
|
|
$board_list[$row[0]] = true; |
1511
|
|
|
|
1512
|
|
|
$smcFunc['db_free_result']($request); |
1513
|
|
|
} |
1514
|
|
|
|
1515
|
|
|
$lOptions = array(); |
1516
|
|
|
|
1517
|
|
|
if (!empty($_POST[$var[1]])) |
1518
|
|
|
foreach ($_POST[$var[1]] as $invar => $dummy) |
1519
|
|
|
if (isset($board_list[$invar])) |
1520
|
|
|
$lOptions[] = $invar; |
1521
|
|
|
|
1522
|
|
|
$setArray[$var[1]] = !empty($lOptions) ? implode(',', $lOptions) : ''; |
1523
|
|
|
} |
1524
|
|
|
// Integers! |
1525
|
|
|
elseif ($var[0] == 'int') |
1526
|
|
|
{ |
1527
|
|
|
$setArray[$var[1]] = (int) $_POST[$var[1]]; |
1528
|
|
|
|
1529
|
|
|
// If no min is specified, assume 0. This is done to avoid having to specify 'min => 0' for all settings where 0 is the min... |
1530
|
|
|
$min = isset($var['min']) ? $var['min'] : 0; |
1531
|
|
|
$setArray[$var[1]] = max($min, $setArray[$var[1]]); |
1532
|
|
|
|
1533
|
|
|
// Do we have a max value for this as well? |
1534
|
|
|
if (isset($var['max'])) |
1535
|
|
|
$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
1536
|
|
|
} |
1537
|
|
|
// Floating point! |
1538
|
|
|
elseif ($var[0] == 'float') |
1539
|
|
|
{ |
1540
|
|
|
$setArray[$var[1]] = (float) $_POST[$var[1]]; |
1541
|
|
|
|
1542
|
|
|
// If no min is specified, assume 0. This is done to avoid having to specify 'min => 0' for all settings where 0 is the min... |
1543
|
|
|
$min = isset($var['min']) ? $var['min'] : 0; |
1544
|
|
|
$setArray[$var[1]] = max($min, $setArray[$var[1]]); |
1545
|
|
|
|
1546
|
|
|
// Do we have a max value for this as well? |
1547
|
|
|
if (isset($var['max'])) |
1548
|
|
|
$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
1549
|
|
|
} |
1550
|
|
|
// Text! |
1551
|
|
|
elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) |
1552
|
|
|
$setArray[$var[1]] = $_POST[$var[1]]; |
1553
|
|
|
// Passwords! |
1554
|
|
|
elseif ($var[0] == 'password') |
1555
|
|
|
{ |
1556
|
|
|
if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) |
1557
|
|
|
$setArray[$var[1]] = $_POST[$var[1]][0]; |
1558
|
|
|
} |
1559
|
|
|
// BBC. |
1560
|
|
|
elseif ($var[0] == 'bbc') |
1561
|
|
|
{ |
1562
|
|
|
$bbcTags = array(); |
1563
|
|
|
foreach (parse_bbc(false) as $tag) |
|
|
|
|
1564
|
|
|
$bbcTags[] = $tag['tag']; |
1565
|
|
|
|
1566
|
|
|
if (!isset($_POST[$var[1] . '_enabledTags'])) |
1567
|
|
|
$_POST[$var[1] . '_enabledTags'] = array(); |
1568
|
|
|
elseif (!is_array($_POST[$var[1] . '_enabledTags'])) |
1569
|
|
|
$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']); |
1570
|
|
|
|
1571
|
|
|
$setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags'])); |
1572
|
|
|
} |
1573
|
|
|
// Permissions? |
1574
|
|
|
elseif ($var[0] == 'permissions') |
1575
|
|
|
$inlinePermissions[] = $var[1]; |
1576
|
|
|
} |
1577
|
|
|
|
1578
|
|
|
if (!empty($setArray)) |
1579
|
|
|
updateSettings($setArray); |
1580
|
|
|
|
1581
|
|
|
// If we have inline permissions we need to save them. |
1582
|
|
|
if (!empty($inlinePermissions) && allowedTo('manage_permissions')) |
1583
|
|
|
{ |
1584
|
|
|
require_once($sourcedir . '/ManagePermissions.php'); |
1585
|
|
|
save_inline_permissions($inlinePermissions); |
1586
|
|
|
} |
1587
|
|
|
} |
1588
|
|
|
|
1589
|
|
|
/** |
1590
|
|
|
* Allows us to see the servers php settings |
1591
|
|
|
* |
1592
|
|
|
* - loads the settings into an array for display in a template |
1593
|
|
|
* - drops cookie values just in case |
1594
|
|
|
*/ |
1595
|
|
|
function ShowPHPinfoSettings() |
1596
|
|
|
{ |
1597
|
|
|
global $context, $txt; |
1598
|
|
|
|
1599
|
|
|
$category = $txt['phpinfo_settings']; |
1600
|
|
|
|
1601
|
|
|
// get the data |
1602
|
|
|
ob_start(); |
1603
|
|
|
phpinfo(); |
1604
|
|
|
|
1605
|
|
|
// We only want it for its body, pigs that we are |
1606
|
|
|
$info_lines = preg_replace('~^.*<body>(.*)</body>.*$~', '$1', ob_get_contents()); |
1607
|
|
|
$info_lines = explode("\n", strip_tags($info_lines, "<tr><td><h2>")); |
1608
|
|
|
ob_end_clean(); |
1609
|
|
|
|
1610
|
|
|
// remove things that could be considered sensitive |
1611
|
|
|
$remove = '_COOKIE|Cookie|_GET|_REQUEST|REQUEST_URI|QUERY_STRING|REQUEST_URL|HTTP_REFERER'; |
1612
|
|
|
|
1613
|
|
|
// put all of it into an array |
1614
|
|
|
foreach ($info_lines as $line) |
1615
|
|
|
{ |
1616
|
|
|
if (preg_match('~(' . $remove . ')~', $line)) |
1617
|
|
|
continue; |
1618
|
|
|
|
1619
|
|
|
// new category? |
1620
|
|
|
if (strpos($line, '<h2>') !== false) |
1621
|
|
|
$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category; |
|
|
|
|
1622
|
|
|
|
1623
|
|
|
// load it as setting => value or the old setting local master |
1624
|
|
|
if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) |
1625
|
|
|
$pinfo[$category][$val[1]] = $val[2]; |
1626
|
|
|
elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) |
1627
|
|
|
$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]); |
1628
|
|
|
} |
1629
|
|
|
|
1630
|
|
|
// load it in to context and display it |
1631
|
|
|
$context['pinfo'] = $pinfo; |
|
|
|
|
1632
|
|
|
$context['page_title'] = $txt['admin_server_settings']; |
1633
|
|
|
$context['sub_template'] = 'php_info'; |
1634
|
|
|
return; |
1635
|
|
|
} |
1636
|
|
|
|
1637
|
|
|
/** |
1638
|
|
|
* Get the installed Cache API implementations. |
1639
|
|
|
* |
1640
|
|
|
*/ |
1641
|
|
|
function loadCacheAPIs() |
1642
|
|
|
{ |
1643
|
|
|
global $sourcedir; |
1644
|
|
|
|
1645
|
|
|
$cacheAPIdir = $sourcedir . '/Cache'; |
1646
|
|
|
|
1647
|
|
|
$loadedApis = array(); |
1648
|
|
|
$apis_dir = $cacheAPIdir .'/'. CacheApi::APIS_FOLDER; |
1649
|
|
|
|
1650
|
|
|
$api_classes = new GlobIterator($apis_dir . '/*.php', FilesystemIterator::NEW_CURRENT_AND_KEY); |
1651
|
|
|
|
1652
|
|
|
foreach ($api_classes as $file_path => $file_info) |
1653
|
|
|
{ |
1654
|
|
|
require_once($apis_dir . '/' . $file_path); |
1655
|
|
|
|
1656
|
|
|
$class_name = $file_info->getBasename('.php'); |
1657
|
|
|
$fully_qualified_class_name = CacheApi::APIS_NAMESPACE . $class_name; |
1658
|
|
|
|
1659
|
|
|
/* @var CacheApiInterface $cache_api */ |
1660
|
|
|
$cache_api = new $fully_qualified_class_name(); |
1661
|
|
|
|
1662
|
|
|
// Deal with it! |
1663
|
|
|
if (!($cache_api instanceof CacheApiInterface) || !($cache_api instanceof CacheApi)) |
1664
|
|
|
continue; |
1665
|
|
|
|
1666
|
|
|
// No Support? NEXT! |
1667
|
|
|
if (!$cache_api->isSupported(true)) |
1668
|
|
|
continue; |
1669
|
|
|
|
1670
|
|
|
$loadedApis[$class_name] = $cache_api; |
1671
|
|
|
} |
1672
|
|
|
|
1673
|
|
|
call_integration_hook('integrate_load_cache_apis', array(&$loadedApis)); |
1674
|
|
|
|
1675
|
|
|
return $loadedApis; |
1676
|
|
|
} |
1677
|
|
|
|
1678
|
|
|
/** |
1679
|
|
|
* Registers the site with the Simple Machines Stat collection. This function |
1680
|
|
|
* purposely does not use updateSettings.php as it will be called shortly after |
1681
|
|
|
* this process completes by the saveSettings() function. |
1682
|
|
|
* |
1683
|
|
|
* @see Stats.php SMStats() for more information. |
1684
|
|
|
* @link https://www.simplemachines.org/about/stats.php for more info. |
1685
|
|
|
* |
1686
|
|
|
*/ |
1687
|
|
|
function registerSMStats() |
1688
|
|
|
{ |
1689
|
|
|
global $modSettings, $boardurl, $smcFunc; |
1690
|
|
|
|
1691
|
|
|
// Already have a key? Can't register again. |
1692
|
|
|
if (!empty($modSettings['sm_stats_key'])) |
1693
|
|
|
return true; |
1694
|
|
|
|
1695
|
|
|
$fp = @fsockopen('www.simplemachines.org', 443, $errno, $errstr); |
1696
|
|
|
if (!$fp) |
|
|
|
|
1697
|
|
|
$fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr); |
1698
|
|
|
if ($fp) |
|
|
|
|
1699
|
|
|
{ |
1700
|
|
|
$out = 'GET /smf/stats/register_stats.php?site=' . base64_encode($boardurl) . ' HTTP/1.1' . "\r\n"; |
1701
|
|
|
$out .= 'Host: www.simplemachines.org' . "\r\n"; |
1702
|
|
|
$out .= 'Connection: Close' . "\r\n\r\n"; |
1703
|
|
|
fwrite($fp, $out); |
1704
|
|
|
|
1705
|
|
|
$return_data = ''; |
1706
|
|
|
while (!feof($fp)) |
1707
|
|
|
$return_data .= fgets($fp, 128); |
1708
|
|
|
|
1709
|
|
|
fclose($fp); |
1710
|
|
|
|
1711
|
|
|
// Get the unique site ID. |
1712
|
|
|
preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
1713
|
|
|
|
1714
|
|
|
if (!empty($ID[1])) |
1715
|
|
|
{ |
1716
|
|
|
$smcFunc['db_insert']('replace', |
1717
|
|
|
'{db_prefix}settings', |
1718
|
|
|
array('variable' => 'string', 'value' => 'string'), |
1719
|
|
|
array('sm_stats_key', $ID[1]), |
1720
|
|
|
array('variable') |
1721
|
|
|
); |
1722
|
|
|
return true; |
1723
|
|
|
} |
1724
|
|
|
} |
1725
|
|
|
|
1726
|
|
|
return false; |
1727
|
|
|
} |
1728
|
|
|
|
1729
|
|
|
?> |