|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Handles the Security and Moderation pages in the admin panel. This includes |
|
5
|
|
|
* anti-spam, security, and moderation settings |
|
6
|
|
|
* |
|
7
|
|
|
* @package ElkArte Forum |
|
8
|
|
|
* @copyright ElkArte Forum contributors |
|
9
|
|
|
* @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file) |
|
10
|
|
|
* |
|
11
|
|
|
* This file contains code covered by: |
|
12
|
|
|
* copyright: 2011 Simple Machines (http://www.simplemachines.org) |
|
13
|
|
|
* |
|
14
|
|
|
* @version 2.0 Beta 1 |
|
15
|
|
|
* |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace ElkArte\AdminController; |
|
19
|
|
|
|
|
20
|
|
|
use ElkArte\AbstractController; |
|
21
|
|
|
use ElkArte\Action; |
|
22
|
|
|
use ElkArte\Cache\Cache; |
|
23
|
|
|
use ElkArte\Languages\Txt; |
|
24
|
|
|
use ElkArte\SettingsForm\SettingsForm; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* ManageSecurity controller handles the Security and Moderation |
|
28
|
|
|
* pages in admin panel. |
|
29
|
|
|
* |
|
30
|
|
|
* @package Security |
|
31
|
|
|
*/ |
|
32
|
|
|
class ManageSecurity extends AbstractController |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* This function passes control through to the relevant security tab. |
|
36
|
|
|
* |
|
37
|
|
|
* @event integrate_sa_modify_security |
|
38
|
|
|
* @see AbstractController::action_index() |
|
39
|
|
|
*/ |
|
40
|
|
|
public function action_index() |
|
41
|
|
|
{ |
|
42
|
|
|
global $context, $txt; |
|
43
|
|
|
|
|
44
|
|
|
Txt::load('Help+ManageSettings'); |
|
45
|
|
|
|
|
46
|
|
|
$subActions = [ |
|
47
|
|
|
'general' => [$this, 'action_securitySettings_display', 'permission' => 'admin_forum'], |
|
48
|
|
|
'spam' => [$this, 'action_spamSettings_display', 'permission' => 'admin_forum'], |
|
49
|
|
|
]; |
|
50
|
|
|
|
|
51
|
|
|
// Action control |
|
52
|
|
|
$action = new Action('modify_security'); |
|
53
|
|
|
|
|
54
|
|
|
// By default, do the basic settings, call integrate_sa_modify_security |
|
55
|
|
|
$subAction = $action->initialize($subActions, 'general'); |
|
56
|
|
|
|
|
57
|
|
|
// Last pieces of the puzzle |
|
58
|
|
|
$context['sub_action'] = $subAction; |
|
59
|
|
|
$context['page_title'] = $txt['admin_security_moderation']; |
|
60
|
|
|
$context['sub_template'] = 'show_settings'; |
|
61
|
|
|
|
|
62
|
|
|
// Load up all the tabs... |
|
63
|
|
|
$context[$context['admin_menu_name']]['object']->prepareTabData([ |
|
64
|
|
|
'title' => 'admin_security_moderation', |
|
65
|
|
|
'help' => 'securitysettings', |
|
66
|
|
|
'description' => 'security_settings_desc', |
|
67
|
|
|
]); |
|
68
|
|
|
|
|
69
|
|
|
// Call the right function for this sub-action. |
|
70
|
|
|
$action->dispatch($subAction); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Handle settings regarding general security of the site. |
|
75
|
|
|
* |
|
76
|
|
|
* - Uses a settings form for security options. |
|
77
|
|
|
* |
|
78
|
|
|
* @event integrate_save_general_security_settings |
|
79
|
|
|
*/ |
|
80
|
|
|
public function action_securitySettings_display(): void |
|
81
|
|
|
{ |
|
82
|
|
|
global $txt, $context; |
|
83
|
|
|
|
|
84
|
|
|
// Initialize the form |
|
85
|
|
|
$settingsForm = new SettingsForm(SettingsForm::DB_ADAPTER); |
|
86
|
|
|
|
|
87
|
|
|
// Initialize it with our settings |
|
88
|
|
|
$settingsForm->setConfigVars($this->_securitySettings()); |
|
89
|
|
|
|
|
90
|
|
|
// Saving? |
|
91
|
|
|
if ($this->_req->hasQuery('save')) |
|
92
|
|
|
{ |
|
93
|
|
|
checkSession(); |
|
94
|
|
|
|
|
95
|
|
|
$settingsForm->setConfigValues((array) $this->_req->post); |
|
96
|
|
|
$settingsForm->save(); |
|
97
|
|
|
|
|
98
|
|
|
call_integration_hook('integrate_save_general_security_settings'); |
|
99
|
|
|
|
|
100
|
|
|
writeLog(); |
|
101
|
|
|
redirectexit('action=admin;area=securitysettings;sa=general'); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'securitysettings', 'save', 'sa' => 'general']); |
|
105
|
|
|
$context['settings_title'] = $txt['mods_cat_security_general']; |
|
106
|
|
|
|
|
107
|
|
|
$settingsForm->prepare(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Security settings. |
|
112
|
|
|
* |
|
113
|
|
|
* @event integrate_general_security_settings add more security settings |
|
114
|
|
|
*/ |
|
115
|
|
|
private function _securitySettings() |
|
116
|
|
|
{ |
|
117
|
|
|
global $txt, $context, $modSettings; |
|
118
|
|
|
|
|
119
|
|
|
// See if they supplied a valid-looking http:BL API Key |
|
120
|
|
|
$context['invalid_badbehavior_httpbl_key'] = (!empty($modSettings['badbehavior_httpbl_key']) && (strlen($modSettings['badbehavior_httpbl_key']) !== 12)); |
|
121
|
|
|
|
|
122
|
|
|
// Set up the config array for use |
|
123
|
|
|
$config_vars = [ |
|
124
|
|
|
['int', 'failed_login_threshold'], |
|
125
|
|
|
['int', 'loginHistoryDays'], |
|
126
|
|
|
'', |
|
127
|
|
|
['int', 'admin_session_lifetime'], |
|
128
|
2 |
|
['check', 'auto_admin_session'], |
|
129
|
|
|
['check', 'securityDisable'], |
|
130
|
2 |
|
['check', 'securityDisable_moderate'], |
|
131
|
|
|
'', |
|
132
|
|
|
['check', 'enableOTP'], |
|
133
|
|
|
'', |
|
134
|
2 |
|
// Reactive on email and approve on delete |
|
135
|
|
|
['check', 'send_validation_onChange'], |
|
136
|
2 |
|
['check', 'approveAccountDeletion'], |
|
137
|
|
|
'', |
|
138
|
|
|
// Password strength. |
|
139
|
2 |
|
['select', 'password_strength', [$txt['setting_password_strength_low'], $txt['setting_password_strength_medium'], $txt['setting_password_strength_high']]], |
|
140
|
|
|
['check', 'enable_password_conversion'], |
|
141
|
|
|
'', |
|
142
|
|
|
['select', 'frame_security', ['SAMEORIGIN' => $txt['setting_frame_security_SAMEORIGIN'], 'DENY' => $txt['setting_frame_security_DENY'], 'DISABLE' => $txt['setting_frame_security_DISABLE']]], |
|
143
|
|
|
// Bad Behavior |
|
144
|
2 |
|
['title', 'badbehavior_title'], |
|
145
|
|
|
['check', 'badbehavior_accept_header'], |
|
146
|
2 |
|
['text', 'badbehavior_httpbl_key', 12, 'invalid' => $context['invalid_badbehavior_httpbl_key']], |
|
147
|
|
|
['int', 'badbehavior_httpbl_threat', 'postinput' => $txt['badbehavior_httpbl_threat_desc']], |
|
148
|
|
|
['int', 'badbehavior_httpbl_maxage', 'postinput' => $txt['badbehavior_httpbl_maxage_desc']], |
|
149
|
|
|
]; |
|
150
|
2 |
|
|
|
151
|
|
|
call_integration_hook('integrate_general_security_settings', [&$config_vars]); |
|
152
|
2 |
|
|
|
153
|
|
|
return $config_vars; |
|
154
|
2 |
|
} |
|
155
|
2 |
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Handles admin security spam settings. |
|
158
|
2 |
|
* |
|
159
|
|
|
* - Displays a page with settings and eventually allows the admin to change them. |
|
160
|
2 |
|
* |
|
161
|
|
|
* @event integrate_save_spam_settings |
|
162
|
|
|
*/ |
|
163
|
|
|
public function action_spamSettings_display(): void |
|
164
|
|
|
{ |
|
165
|
|
|
global $txt, $context, $modSettings; |
|
166
|
|
|
|
|
167
|
|
|
// Initialize the form |
|
168
|
|
|
$settingsForm = new SettingsForm(SettingsForm::DB_ADAPTER); |
|
169
|
|
|
|
|
170
|
|
|
// Initialize it with our settings |
|
171
|
|
|
$config_vars = $this->_spamSettings(); |
|
172
|
|
|
$settingsForm->setConfigVars($config_vars); |
|
173
|
|
|
|
|
174
|
|
|
// Saving? |
|
175
|
|
|
if ($this->_req->hasQuery('save')) |
|
176
|
|
|
{ |
|
177
|
|
|
checkSession(); |
|
178
|
|
|
|
|
179
|
|
|
// Guest requiring verification! |
|
180
|
|
|
if (empty($this->_req->post->posts_require_captcha) && !empty($this->_req->post->guests_require_captcha)) |
|
181
|
|
|
{ |
|
182
|
|
|
$this->_req->post->posts_require_captcha = -1; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
unset($config_vars['guest_verify']); |
|
186
|
|
|
|
|
187
|
|
|
call_integration_hook('integrate_save_spam_settings'); |
|
188
|
|
|
|
|
189
|
|
|
// Now save. |
|
190
|
|
|
$settingsForm->setConfigValues((array) $this->_req->post); |
|
191
|
|
|
$settingsForm->save(); |
|
192
|
|
|
Cache::instance()->remove('verificationQuestionIds'); |
|
193
|
|
|
redirectexit('action=admin;area=securitysettings;sa=spam'); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
// And the same for guests requiring verification. |
|
197
|
|
|
$modSettings['guests_require_captcha'] = !empty($modSettings['posts_require_captcha']); |
|
198
|
|
|
$modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha']; |
|
199
|
|
|
|
|
200
|
|
|
// Some minor JavaScript for the guest post setting. |
|
201
|
|
|
if ($modSettings['posts_require_captcha']) |
|
202
|
|
|
{ |
|
203
|
|
|
theme()->addInlineJavascript("document.getElementById('guests_require_captcha').disabled = true;", true); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'securitysettings', 'save', 'sa' => 'spam']); |
|
207
|
|
|
$context['settings_title'] = $txt['antispam_Settings']; |
|
208
|
|
|
$settingsForm->prepare(); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Spam settings. |
|
213
|
|
|
* |
|
214
|
|
|
* @event integrate_spam_settings mmmm Spam |
|
215
|
|
|
*/ |
|
216
|
|
|
private function _spamSettings() |
|
217
|
|
|
{ |
|
218
|
|
|
global $txt, $modSettings; |
|
219
|
|
|
|
|
220
|
|
|
// Build up our options array |
|
221
|
|
|
$config_vars = [ |
|
222
|
|
|
['check', 'reg_verification'], |
|
223
|
|
|
['check', 'search_enable_captcha'], |
|
224
|
|
|
// This, my friend, is a cheat :p |
|
225
|
|
|
'guest_verify' => ['check', 'guests_require_captcha', 'postinput' => $txt['setting_guests_require_captcha_desc']], |
|
226
|
|
|
['int', 'posts_require_captcha', 'postinput' => $txt['posts_require_captcha_desc'], 'onchange' => "if (this.value > 0){ document.getElementById('guests_require_captcha').checked = true; document.getElementById('guests_require_captcha').disabled = true;} else {document.getElementById('guests_require_captcha').disabled = false;}"], |
|
227
|
|
|
['check', 'guests_report_require_captcha'], |
|
228
|
2 |
|
]; |
|
229
|
|
|
|
|
230
|
2 |
|
// Cannot use moderation if post-moderation is not enabled. |
|
231
|
|
|
if (!$modSettings['postmod_active']) |
|
232
|
|
|
{ |
|
233
|
|
|
unset($config_vars['moderate']); |
|
234
|
2 |
|
} |
|
235
|
2 |
|
|
|
236
|
2 |
|
// @todo: it may be removed, it may stay, the two hooks may have different functions |
|
237
|
2 |
|
call_integration_hook('integrate_spam_settings', [&$config_vars]); |
|
238
|
2 |
|
|
|
239
|
2 |
|
return $config_vars; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
2 |
|
/** |
|
243
|
|
|
* Public method to return security form settings, used in admin search |
|
244
|
2 |
|
*/ |
|
245
|
|
|
public function securitySettings_search() |
|
246
|
|
|
{ |
|
247
|
|
|
return $this->_securitySettings(); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* Public method to return spam settings, used in admin search |
|
252
|
|
|
*/ |
|
253
|
|
|
public function spamSettings_search() |
|
254
|
|
|
{ |
|
255
|
|
|
return $this->_spamSettings(); |
|
256
|
|
|
} |
|
257
|
|
|
} |
|
258
|
|
|
|