PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / component / config / class-config-adapter.php

class-config-adapter.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at src/component/config/class-config-adapter.php

540 lines 25.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Responsible for upgrading and managing configuration data.
4 *
5 * @package WP_Defender\Component\Config
6 */
7
8 namespace WP_Defender\Component\Config;
9
10 use WP_Defender\Component;
11 use WP_Defender\Model\Notification;
12 use WP_Defender\Model\Setting\Two_Fa;
13 use WP_Defender\Model\Setting\Security_Headers;
14 use WP_Defender\Model\Setting\Login_Lockout as Model_Login_Lockout;
15 use WP_Defender\Model\Setting\User_Agent_Lockout as Model_Ua_Lockout;
16 use WP_Defender\Model\Setting\Notfound_Lockout as Model_Notfound_Lockout;
17 use WP_Defender\Model\Setting\Blacklist_Lockout as Model_Blacklist_Lockout;
18
19 /**
20 * Handles the configuration data adapter.
21 *
22 * @since 2.4.0
23 */
24 class Config_Adapter extends Component {
25
26 /**
27 * Status of notification receiver.
28 *
29 * @var string
30 */
31 public $status_recipient;
32
33 /**
34 * Upgrade the structure of config data from older versions.
35 *
36 * @param array $old_data The configuration data from the older version.
37 *
38 * @return array
39 */
40 public function upgrade( array $old_data ): array {
41 $this->status_recipient = Notification::USER_SUBSCRIBED;
42
43 return array(
44 'security_tweaks' => $this->update_security_tweaks( $old_data['security_tweaks'] ),
45 'scan' => ! isset( $old_data['scan'] ) || ! is_array( $old_data['scan'] ) ? array() : $this->update_scan( $old_data['scan'] ),
46 'iplockout' => ! isset( $old_data['iplockout'] ) || ! is_array( $old_data['iplockout'] )
47 ? array()
48 : $this->update_ip_lockout( $old_data['iplockout'] ),
49 'two_factor' => ! isset( $old_data['two_factor'] ) || ! is_array( $old_data['two_factor'] )
50 ? array()
51 : $this->update_two_factor( $old_data['two_factor'] ),
52 // Checks for empty values Mask Login and Security Headers inside methods.
53 'mask_login' => $this->update_mask_login( $old_data['mask_login'] ),
54 'security_headers' => $this->update_security_headers( $old_data['security_headers'] ),
55 'settings' => ! isset( $old_data['settings'] ) || ! is_array( $old_data['settings'] ) ? array() : $old_data['settings'],
56 'blocklist_monitor' => ! isset( $old_data['blocklist_monitor'] ) || ! is_array( $old_data['blocklist_monitor'] ) ? array() : $old_data['blocklist_monitor'],
57 'pwned_passwords' => ! isset( $old_data['pwned_passwords'] ) || ! is_array( $old_data['pwned_passwords'] ) ? array() : $old_data['pwned_passwords'],
58 );
59 }
60
61 /**
62 * Convert key type from frequency to text.
63 * Attention: it's NOT translation lines.
64 *
65 * @param int $freq The frequency as a number.
66 *
67 * @return string
68 */
69 private function number_frequency_to_text( int $freq ): string {
70 switch ( $freq ) {
71 case 1:
72 $text = 'daily';
73 break;
74 case 7:
75 $text = 'weekly';
76 break;
77 case 30:
78 default:
79 $text = 'monthly';
80 break;
81 }
82
83 return $text;
84 }
85
86 /**
87 * Determines the frequency type based on the input, which can be either numeric or textual.
88 *
89 * @param string|int $frequency_type The frequency type which can be a number or a string.
90 *
91 * @return string
92 */
93 private function frequency_type( $frequency_type ) {
94
95 return is_numeric( $frequency_type )
96 ? $this->number_frequency_to_text( (int) $frequency_type )
97 : $frequency_type;
98 }
99
100 /**
101 * Report instance uses the 'day' property if a frequency type is daily and 'day_n' if a frequency type is monthly.
102 *
103 * @param string|int $frequency_type The frequency type.
104 * @param string $report_day The day of the week or month.
105 *
106 * @return array
107 */
108 private function frequency_day( $frequency_type, $report_day ): array {
109 $days = array(
110 'day_n' => 1,
111 'day' => 'sunday',
112 );
113 if (
114 ( ( is_numeric( $frequency_type ) && 30 === (int) $frequency_type ) )
115 || 'monthly' === $frequency_type
116 ) {
117 if ( '' === $report_day ) {
118 return $days;
119 }
120 if ( is_numeric( $report_day ) ) {
121 $days['day_n'] = $report_day;
122
123 return $days;
124 }
125 // Otherwise, get a number of the first day of the month by the day of the week.
126 $format = sprintf( 'first %s of next month', $report_day );
127 $days['day_n'] = (int) wp_date( 'j', strtotime( $format ) );
128
129 return $days;
130 }
131 // Otherwise, we get report day for daily or weekly.
132 $days['day'] = $report_day;
133
134 return $days;
135 }
136
137 /**
138 * Extracts subscriber information from the provided data array.
139 *
140 * @param array $data Data containing subscriber information.
141 *
142 * @return array
143 */
144 private function get_subscribers( array $data ): array {
145 $subscribers = array();
146 if ( is_array( $data ) && array() !== $data ) {
147 foreach ( $data as $receipt ) {
148 $subscribers['out_house_recipients'][] = array(
149 'name' => $receipt['first_name'],
150 'email' => $receipt['email'],
151 'status' => $this->status_recipient,
152 'avatar' => get_avatar_url( $receipt['email'] ),
153 );
154 }
155 }
156
157 return $subscribers;
158 }
159
160 /**
161 * Updates the security tweaks configuration from the old format to the new format.
162 *
163 * @param array $old_tweaks The old security tweaks configuration.
164 *
165 * @return array
166 */
167 public function update_security_tweaks( $old_tweaks ): array {
168 $security_tweaks = array(
169 'issues' => $old_tweaks['issues'] ?? array(),
170 'fixed' => $old_tweaks['fixed'] ?? array(),
171 'ignore' => $old_tweaks['ignore'] ?? array(),
172 'automate' => isset( $old_tweaks['automate'] )
173 // Sometimes string value from old version.
174 ? ( is_bool( $old_tweaks['automate'] ) ? $old_tweaks['automate'] : (bool) $old_tweaks['automate'] )
175 : true,
176 'notification' => isset( $old_tweaks['notification'] )
177 ? ( $old_tweaks['notification'] ? 'enabled' : 'disabled' )
178 : 'disabled',
179 // Prepare from 'notification_repeat' to configs['reminder'] with default value 'weekly'.
180 'notification_repeat' => ! isset( $old_tweaks['notification_repeat'] ) || '' === $old_tweaks['notification_repeat']
181 ? 'weekly'
182 : ( $old_tweaks['notification_repeat'] ? 'daily' : 'weekly' ),
183 'data' => $old_tweaks['data'] ?? array(),
184 );
185 if ( isset( $old_tweaks['last_sent'] ) ) {
186 $security_tweaks['last_sent'] = $old_tweaks['last_sent'];
187 }
188
189 $security_tweaks['subscribers'] = isset( $old_tweaks['receipts'] )
190 ? $this->get_subscribers( $old_tweaks['receipts'] )
191 : array();
192
193 return $security_tweaks;
194 }
195
196 /**
197 * Updates the scan configuration from the old format to the new format.
198 *
199 * @param array $old_data The old scan configuration.
200 *
201 * @return array
202 */
203 public function update_scan( array $old_data ): array {
204 $scan = array(
205 'integrity_check' => ! isset( $old_data['scan_core'] ) || ! is_bool( $old_data['scan_core'] ) ? true : $old_data['scan_core'],
206 'check_core' => ! isset( $old_data['check_core'] ) || ! is_bool( $old_data['check_core'] ) ? true : $old_data['check_core'],
207 'check_plugins' => ! isset( $old_data['check_plugins'] ) || ! is_bool( $old_data['check_plugins'] ) ? false : $old_data['check_plugins'],
208 'check_known_vuln' => ! isset( $old_data['scan_vuln'] ) || ! is_bool( $old_data['scan_vuln'] ) ? true : $old_data['scan_vuln'],
209 'scan_malware' => ! isset( $old_data['scan_content'] ) || ! is_bool( $old_data['scan_content'] ) ? false : $old_data['scan_content'],
210 'filesize' => ! isset( $old_data['max_filesize'] ) || ! is_int( $old_data['max_filesize'] ) ? 3 : $old_data['max_filesize'],
211 // Should get bool value.
212 'report' => isset( $old_data['report'] ) && $old_data['report'] ? 'enabled' : 'disabled',
213 'always_send' => ! isset( $old_data['always_send'] ) || ! is_bool( $old_data['always_send'] ) ? false : $old_data['always_send'],
214 'time' => ! isset( $old_data['time'] ) || ! is_string( $old_data['time'] ) || '' === $old_data['time'] ? '4:00' : $old_data['time'],
215 'frequency' => ! isset( $old_data['frequency'] ) || ! is_string( $old_data['frequency'] ) || '' === $old_data['frequency']
216 ? 'weekly'
217 : $this->frequency_type( $old_data['frequency'] ),
218 // Should get bool value.
219 'notification' => isset( $old_data['notification'] ) && $old_data['notification']
220 ? 'enabled'
221 : 'disabled',
222 'always_send_notification' => ! isset( $old_data['always_send_notification'] ) || ! is_bool( $old_data['always_send_notification'] )
223 ? false
224 : $old_data['always_send_notification'],
225 'error_send' => ! isset( $old_data['error_send'] ) || ! is_bool( $old_data['error_send'] ) ? false : $old_data['error_send'],
226 'email_subject_issue_found' => $old_data['email_subject_issue'] ?? '',
227 'email_subject_issue_not_found' => $old_data['email_subject'] ?? '',
228 'email_subject_error' => $old_data['email_subject_error'] ?? '',
229 'email_content_issue_found' => $old_data['email_has_issue'] ?? '',
230 'email_content_issue_not_found' => $old_data['email_all_ok'] ?? '',
231 'email_content_error' => $old_data['email_content_error'] ?? '',
232 // Since 5.9.0.
233 'check_abandoned_plugin' => true,
234 );
235
236 $scan['report_subscribers'] = ! isset( $old_data['recipients'] ) || ! is_array( $old_data['recipients'] ) || array() === $old_data['recipients']
237 ? array()
238 : $this->get_subscribers( $old_data['recipients'] );
239 $scan['notification_subscribers'] = ! isset( $old_data['recipients_notification'] ) || ! is_array( $old_data['recipients_notification'] ) || array() === $old_data['recipients_notification']
240 ? array()
241 : $this->get_subscribers( $old_data['recipients_notification'] );
242 // Todo: need the key 'last_report_sent'? It's no always in the unixtime format.
243 if ( ! isset( $old_data['frequency'] ) || '' === $old_data['frequency'] ) {
244 $scan['day'] = 'sunday';
245 $scan['day_n'] = 1;
246
247 return $scan;
248 } else {
249 return array_merge( $scan, $this->frequency_day( $old_data['frequency'], $old_data['day'] ) );
250 }
251 }
252
253 /**
254 * Updates the IP lockout configuration from the old format to the new format.
255 *
256 * @param array $old_data The old IP lockout configuration.
257 *
258 * @return array
259 */
260 public function update_ip_lockout( array $old_data ): array {
261 $merged_bl_file_data = $old_data['detect_404_blacklist'] ?? '';
262 // Merge blacklist file & filetype data.
263 if ( isset( $old_data['detect_404_filetypes_blacklist'] ) && '' !== trim( $old_data['detect_404_filetypes_blacklist'] ) ) {
264 $merged_bl_file_data .= PHP_EOL . $old_data['detect_404_filetypes_blacklist'];
265 }
266 $merged_wl_file_data = $old_data['detect_404_whitelist'] ?? '';
267 // Merge whitelist file & filetype data.
268 if ( isset( $old_data['detect_404_whitelist'] ) && '' !== trim( $old_data['detect_404_ignored_filetypes'] ) ) {
269 $merged_wl_file_data .= PHP_EOL . $old_data['detect_404_ignored_filetypes'];
270 }
271
272 $default_login_lockout_values = ( new Model_Login_Lockout() )->get_default_values();
273 $default_404_lockout_values = ( new Model_Notfound_Lockout() )->get_default_values();
274 $default_ip_lockout_values = ( new Model_Blacklist_Lockout() )->get_default_values();
275 $default_ua_lockout_values = ( new Model_Ua_Lockout() )->get_default_values();
276
277 $iplockout = array(
278 'login_protection' => ! isset( $old_data['login_protection'] ) || ! is_bool( $old_data['login_protection'] )
279 ? true : $old_data['login_protection'],
280 'login_protection_login_attempt' => ! isset( $old_data['login_protection_login_attempt'] ) || ! is_numeric( $old_data['login_protection_login_attempt'] )
281 ? '5' : $old_data['login_protection_login_attempt'],
282 'login_protection_lockout_timeframe' => ! isset( $old_data['login_protection_lockout_timeframe'] ) || ! is_numeric( $old_data['login_protection_lockout_timeframe'] )
283 ? '300' : $old_data['login_protection_lockout_timeframe'],
284 'login_protection_lockout_ban' => ! isset( $old_data['login_protection_lockout_ban'] ) || ! is_bool( $old_data['login_protection_lockout_ban'] )
285 ? false : $old_data['login_protection_lockout_ban'],
286 'login_protection_lockout_duration' => ! isset( $old_data['login_protection_lockout_duration'] ) || ! is_numeric( $old_data['login_protection_lockout_duration'] )
287 ? '4' : $old_data['login_protection_lockout_duration'],
288 'login_protection_lockout_duration_unit' => ! isset( $old_data['login_protection_lockout_duration_unit'] ) || ! is_string( $old_data['login_protection_lockout_duration_unit'] )
289 ? 'hours' : $old_data['login_protection_lockout_duration_unit'],
290 'login_protection_lockout_message' => ! isset( $old_data['login_protection_lockout_message'] ) || '' === $old_data['login_protection_lockout_message']
291 ? $default_login_lockout_values['message']
292 : $old_data['login_protection_lockout_message'],
293 'username_blacklist' => ! isset( $old_data['username_blacklist'] ) || ! is_string( $old_data['username_blacklist'] )
294 ? '' : $old_data['username_blacklist'],
295 'detect_404' => ! isset( $old_data['detect_404'] ) || ! is_bool( $old_data['detect_404'] )
296 ? true : $old_data['detect_404'],
297 'detect_404_threshold' => ! isset( $old_data['detect_404_threshold'] ) || ! is_numeric( $old_data['detect_404_threshold'] )
298 ? '20' : $old_data['detect_404_threshold'],
299 'detect_404_timeframe' => ! isset( $old_data['detect_404_timeframe'] ) || ! is_numeric( $old_data['detect_404_timeframe'] )
300 ? '300' : $old_data['detect_404_timeframe'],
301 'detect_404_lockout_ban' => ! isset( $old_data['detect_404_lockout_ban'] ) || ! is_bool( $old_data['detect_404_lockout_ban'] )
302 ? false : $old_data['detect_404_lockout_ban'],
303 'detect_404_lockout_duration' => ! isset( $old_data['detect_404_lockout_duration'] ) || ! is_numeric( $old_data['detect_404_lockout_duration'] )
304 ? '4' : $old_data['detect_404_lockout_duration'],
305 'detect_404_lockout_duration_unit' => ! isset( $old_data['detect_404_lockout_duration_unit'] ) || ! is_string( $old_data['detect_404_lockout_duration_unit'] )
306 ? 'hours' : $old_data['detect_404_lockout_duration_unit'],
307 'detect_404_lockout_message' => ! isset( $old_data['detect_404_lockout_message'] ) || '' === $old_data['detect_404_lockout_message']
308 ? $default_404_lockout_values['message']
309 : $old_data['detect_404_lockout_message'],
310 'detect_404_blacklist' => $merged_bl_file_data,
311 'detect_404_whitelist' => $merged_wl_file_data,
312 'detect_404_logged' => ! isset( $old_data['detect_404_logged'] ) || ! is_bool( $old_data['detect_404_logged'] )
313 ? true : $old_data['detect_404_logged'],
314 'ip_blacklist' => ! isset( $old_data['ip_blacklist'] ) || ! is_string( $old_data['ip_blacklist'] )
315 ? '' : $old_data['ip_blacklist'],
316 'ip_whitelist' => ! isset( $old_data['ip_whitelist'] ) || ! is_string( $old_data['ip_whitelist'] )
317 ? '' : $old_data['ip_whitelist'],
318 'country_blacklist' => ! isset( $old_data['country_blacklist'] ) || ! is_string( $old_data['country_blacklist'] )
319 ? '' : $old_data['country_blacklist'],
320 'country_whitelist' => ! isset( $old_data['country_whitelist'] ) || ! is_string( $old_data['country_whitelist'] )
321 ? '' : $old_data['country_whitelist'],
322 'ip_lockout_message' => ! isset( $old_data['ip_lockout_message'] ) || '' === $old_data['ip_lockout_message']
323 ? $default_ip_lockout_values['message']
324 : $old_data['ip_lockout_message'],
325 'login_lockout_notification' => ! isset( $old_data['login_lockout_notification'] ) || ! is_bool( $old_data['login_lockout_notification'] )
326 ? true : $old_data['login_lockout_notification'],
327 'ip_lockout_notification' => ! isset( $old_data['ip_lockout_notification'] ) || ! is_bool( $old_data['ip_lockout_notification'] )
328 ? true : $old_data['ip_lockout_notification'],
329 'notification' => 'enabled',
330 'cooldown_enabled' => ! isset( $old_data['cooldown_enabled'] ) || ! is_bool( $old_data['cooldown_enabled'] )
331 ? false : $old_data['cooldown_enabled'],
332 'cooldown_number_lockout' => ! isset( $old_data['cooldown_number_lockout'] ) || ! is_numeric( $old_data['cooldown_number_lockout'] )
333 ? '3' : $old_data['cooldown_number_lockout'],
334 'cooldown_period' => ! isset( $old_data['cooldown_period'] ) || ! is_numeric( $old_data['cooldown_period'] )
335 ? '24' : $old_data['cooldown_period'],
336 'report' => isset( $old_data['report'] ) && $old_data['report'] ? 'enabled' : 'disabled',
337 'report_frequency' => ! isset( $old_data['report_frequency'] ) || '' === $old_data['report_frequency']
338 ? 'weekly'
339 : $this->frequency_type( $old_data['report_frequency'] ),
340 // Data for 'day' below.
341 'report_time' => ! isset( $old_data['report_time'] ) || '' === $old_data['report_time']
342 ? '4:00' : $old_data['report_time'],
343 'storage_days' => ! isset( $old_data['storage_days'] ) || '' === $old_data['storage_days']
344 ? '180' : $old_data['storage_days'],
345 'geoIP_db' => $old_data['geoIP_db'] ?? '',
346 'ip_blocklist_cleanup_interval' => ! isset( $old_data['ip_blocklist_cleanup_interval'] ) || '' === $old_data['ip_blocklist_cleanup_interval']
347 ? 'never' : $old_data['ip_blocklist_cleanup_interval'],
348 // For UA Banning.
349 'ua_banning_enabled' => $old_data['ua_banning_enabled'] ?? false,
350 'ua_banning_message' => $old_data['ua_banning_message'] ?? $default_ua_lockout_values['message'],
351 'ua_banning_blacklist' => $old_data['ua_banning_blacklist'] ?? $default_ua_lockout_values['blacklist'],
352 'ua_banning_whitelist' => $old_data['ua_banning_whitelist'] ?? $default_ua_lockout_values['whitelist'],
353 'ua_banning_empty_headers' => $old_data['ua_banning_empty_headers'] ?? false,
354 'maxmind_license_key' => $old_data['maxmind_license_key'] ?? '',
355 // Global IP list.
356 'global_ip_list' => $old_data['global_ip_list'] ?? false,
357 'global_ip_list_blocklist_autosync' => $old_data['global_ip_list_blocklist_autosync'] ?? false,
358 );
359 if ( isset( $old_data['lastReportSent'] ) && '' !== $old_data['lastReportSent'] ) {
360 $iplockout['last_sent'] = $old_data['lastReportSent'];
361 }
362
363 $iplockout['report_subscribers'] = ! isset( $old_data['report_receipts'] ) || ! is_array( $old_data['report_receipts'] ) || array() === $old_data['report_receipts']
364 ? array()
365 : $this->get_subscribers( $old_data['report_receipts'] );
366 $iplockout['notification_subscribers'] = ! isset( $old_data['receipts'] ) || ! is_array( $old_data['receipts'] ) || array() === $old_data['receipts']
367 ? array()
368 : $this->get_subscribers( $old_data['receipts'] );
369
370 if ( ! isset( $old_data['report_frequency'] ) || '' === $old_data['report_frequency'] ) {
371 $iplockout['day'] = 'sunday';
372 $iplockout['day_n'] = 1;
373
374 return $iplockout;
375 } else {
376 return array_merge(
377 $iplockout,
378 $this->frequency_day( $old_data['report_frequency'], $old_data['report_day'] )
379 );
380 }
381 }
382
383 /**
384 * Updates the audit configuration from the old format to the new format.
385 *
386 * @param array $old_data The old audit configuration.
387 *
388 * @return array
389 */
390 public function update_audit( array $old_data ): array {
391 $audit = array(
392 'enabled' => is_bool( $old_data['enabled'] )
393 ? $old_data['enabled']
394 : (bool) $old_data['enabled'],
395 'report' => isset( $old_data['notification'] ) && $old_data['notification'] ? 'enabled' : 'disabled',
396 'frequency' => ! isset( $old_data['frequency'] ) || '' === $old_data['frequency']
397 ? 'weekly'
398 : $this->frequency_type( $old_data['frequency'] ),
399 'time' => ! isset( $old_data['time'] ) || '' === $old_data['time']
400 ? '4:00'
401 : $old_data['time'],
402 'storage_days' => ! isset( $old_data['storage_days'] ) || '' === $old_data['storage_days']
403 ? '6 months'
404 : $old_data['storage_days'],
405 );
406 if ( isset( $old_data['lastReportSent'] ) && '' !== $old_data['lastReportSent'] ) {
407 $audit['last_sent'] = $old_data['lastReportSent'];
408 }
409
410 $audit['subscribers'] = ! isset( $old_data['receipts'] ) || ! is_array( $old_data['receipts'] ) || array() === $old_data['receipts']
411 ? array()
412 : $this->get_subscribers( $old_data['receipts'] );
413
414 if ( ! isset( $old_data['frequency'] ) || '' === $old_data['frequency'] ) {
415 $audit['day'] = 'sunday';
416 $audit['day_n'] = 1;
417
418 return $audit;
419 } else {
420 return array_merge( $audit, $this->frequency_day( $old_data['frequency'], $old_data['day'] ) );
421 }
422 }
423
424 /**
425 * Updates the two-factor authentication configuration from the old format to the new format.
426 *
427 * @param array $old_data The old two-factor authentication configuration.
428 *
429 * @return array
430 */
431 public function update_two_factor( array $old_data ): array {
432 $user_roles = $old_data['user_roles'] ?? array();
433 $force_auth_roles = $old_data['force_auth_roles'] ?? array();
434 $force_auth_roles = array_values( array_intersect( $force_auth_roles, $user_roles ) );
435
436 return array(
437 'enabled' => $old_data['enabled'] ?? false,
438 'lost_phone' => $old_data['lost_phone'] ?? true,
439 'force_auth' => $old_data['force_auth'] ?? false,
440 'force_auth_mess' => $old_data['force_auth_mess'] ?? '',
441 'user_roles' => $user_roles,
442 'force_auth_roles' => $force_auth_roles,
443 'custom_graphic' => $old_data['custom_graphic'] ?? false,
444 'custom_graphic_type' => $old_data['custom_graphic_type'] ?? Two_Fa::CUSTOM_GRAPHIC_TYPE_UPLOAD,
445 'custom_graphic_url' => $old_data['custom_graphic_url'] ?? '',
446 'custom_graphic_link' => $old_data['custom_graphic_link'] ?? '',
447 'email_subject' => $old_data['email_subject'] ?? '',
448 'email_sender' => $old_data['email_sender'] ?? '',
449 'email_body' => $old_data['email_body'] ?? '',
450 'app_title' => $old_data['app_title'] ?? '',
451 'detect_woo' => $old_data['detect_woo'] ?? false,
452 );
453 }
454
455 /**
456 * Updates the mask login configuration from the old format to the new format.
457 *
458 * @param array $old_data The old mask login configuration.
459 *
460 * @return array
461 */
462 public function update_mask_login( array $old_data ): array {
463 if ( array() === $old_data ) {
464 // Sometimes migrated data is empty.
465 return array(
466 'mask_url' => '',
467 'redirect_traffic' => 'off',
468 'redirect_traffic_url' => '',
469 'enabled' => false,
470 'redirect_traffic_page_id' => 0,
471 );
472 } else {
473 return array(
474 'enabled' => $old_data['enabled'],
475 'mask_url' => $old_data['mask_url'] ?? '',
476 'redirect_traffic' => $old_data['redirect_traffic'] ? 'custom_url' : 'off',
477 'redirect_traffic_url' => $old_data['redirect_traffic_url'] ?? '',
478 'redirect_traffic_page_id' => 0,
479 );
480 }
481 }
482
483 /**
484 * Updates the security headers configuration from the old format to the new format.
485 *
486 * @param array $old_data The old security headers configuration.
487 *
488 * @return array
489 * @since 2.5.0 Remove 'ALLOW-FROM' directive and move to 'sameorigin' by default.
490 * Leave 'sh_xframe_urls' for config migration.
491 */
492 public function update_security_headers( array $old_data ): array {
493 if ( array() === $old_data ) {
494 // Sometimes migrated data is empty.
495 $model_sec_headers = new Security_Headers();
496
497 return array(
498 'sh_xframe' => $model_sec_headers->sh_xframe,
499 'sh_xframe_mode' => $model_sec_headers->sh_xframe_mode,
500 // Leave for migration to 2.5.1.
501 'sh_xframe_urls' => '',
502 'sh_xss_protection' => $model_sec_headers->sh_xss_protection,
503 'sh_xss_protection_mode' => $model_sec_headers->sh_xss_protection_mode,
504 'sh_content_type_options' => $model_sec_headers->sh_content_type_options,
505 'sh_content_type_options_mode' => $model_sec_headers->sh_content_type_options_mode,
506 'sh_strict_transport' => $model_sec_headers->sh_strict_transport,
507 'hsts_preload' => $model_sec_headers->hsts_preload,
508 'include_subdomain' => $model_sec_headers->include_subdomain,
509 'hsts_cache_duration' => $model_sec_headers->hsts_cache_duration,
510 'sh_referrer_policy' => $model_sec_headers->sh_referrer_policy,
511 'sh_referrer_policy_mode' => $model_sec_headers->sh_referrer_policy_mode,
512 'sh_feature_policy' => $model_sec_headers->sh_feature_policy,
513 'sh_feature_policy_mode' => $model_sec_headers->sh_feature_policy_mode,
514 'sh_feature_policy_urls' => $model_sec_headers->sh_feature_policy_urls,
515 );
516 } else {
517
518 return array(
519 'sh_xframe' => (bool) $old_data['sh_xframe'],
520 'sh_xframe_mode' => $old_data['sh_xframe_mode'],
521 // Leave for migration to 2.5.1.
522 'sh_xframe_urls' => $old_data['sh_xframe_urls'] ?? '',
523 'sh_xss_protection' => (bool) $old_data['sh_xss_protection'],
524 'sh_xss_protection_mode' => $old_data['sh_xss_protection_mode'],
525 'sh_content_type_options' => (bool) $old_data['sh_content_type_options'],
526 'sh_content_type_options_mode' => $old_data['sh_content_type_options_mode'],
527 'sh_strict_transport' => (bool) $old_data['sh_strict_transport'],
528 'hsts_preload' => $old_data['hsts_preload'],
529 'include_subdomain' => $old_data['include_subdomain'],
530 'hsts_cache_duration' => $old_data['hsts_cache_duration'],
531 'sh_referrer_policy' => (bool) $old_data['sh_referrer_policy'],
532 'sh_referrer_policy_mode' => $old_data['sh_referrer_policy_mode'],
533 'sh_feature_policy' => (bool) $old_data['sh_feature_policy'],
534 'sh_feature_policy_mode' => $old_data['sh_feature_policy_mode'],
535 'sh_feature_policy_urls' => $old_data['sh_feature_policy_urls'],
536 );
537 }
538 }
539 }
540