PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.9.0
Defender Security – Malware Scanner, Login Security & Firewall v5.9.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 5.9.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 // Empty data if Audit module is disabled.
50 'audit' => ! isset( $old_data['audit'] ) || ! is_array( $old_data['audit'] ) ? array() : $this->update_audit( $old_data['audit'] ),
51 'two_factor' => ! isset( $old_data['two_factor'] ) || ! is_array( $old_data['two_factor'] )
52 ? array()
53 : $this->update_two_factor( $old_data['two_factor'] ),
54 // Checks for empty values Mask Login and Security Headers inside methods.
55 'mask_login' => $this->update_mask_login( $old_data['mask_login'] ),
56 'security_headers' => $this->update_security_headers( $old_data['security_headers'] ),
57 'settings' => ! isset( $old_data['settings'] ) || ! is_array( $old_data['settings'] ) ? array() : $old_data['settings'],
58 'blocklist_monitor' => ! isset( $old_data['blocklist_monitor'] ) || ! is_array( $old_data['blocklist_monitor'] ) ? array() : $old_data['blocklist_monitor'],
59 'pwned_passwords' => ! isset( $old_data['pwned_passwords'] ) || ! is_array( $old_data['pwned_passwords'] ) ? array() : $old_data['pwned_passwords'],
60 );
61 }
62
63 /**
64 * Convert key type from frequency to text.
65 * Attention: it's NOT translation lines.
66 *
67 * @param int $freq The frequency as a number.
68 *
69 * @return string
70 */
71 private function number_frequency_to_text( int $freq ): string {
72 switch ( $freq ) {
73 case 1:
74 $text = 'daily';
75 break;
76 case 7:
77 $text = 'weekly';
78 break;
79 case 30:
80 default:
81 $text = 'monthly';
82 break;
83 }
84
85 return $text;
86 }
87
88 /**
89 * Determines the frequency type based on the input, which can be either numeric or textual.
90 *
91 * @param string|int $frequency_type The frequency type which can be a number or a string.
92 *
93 * @return string
94 */
95 private function frequency_type( $frequency_type ) {
96
97 return is_numeric( $frequency_type )
98 ? $this->number_frequency_to_text( (int) $frequency_type )
99 : $frequency_type;
100 }
101
102 /**
103 * Report instance uses the 'day' property if a frequency type is daily and 'day_n' if a frequency type is monthly.
104 *
105 * @param string|int $frequency_type The frequency type.
106 * @param string $report_day The day of the week or month.
107 *
108 * @return array
109 */
110 private function frequency_day( $frequency_type, $report_day ): array {
111 $days = array(
112 'day_n' => 1,
113 'day' => 'sunday',
114 );
115 if (
116 ( ( is_numeric( $frequency_type ) && 30 === (int) $frequency_type ) )
117 || 'monthly' === $frequency_type
118 ) {
119 if ( '' === $report_day ) {
120 return $days;
121 }
122 if ( is_numeric( $report_day ) ) {
123 $days['day_n'] = $report_day;
124
125 return $days;
126 }
127 // Otherwise, get a number of the first day of the month by the day of the week.
128 $format = sprintf( 'first %s of next month', $report_day );
129 $days['day_n'] = (int) wp_date( 'j', strtotime( $format ) );
130
131 return $days;
132 }
133 // Otherwise, we get report day for daily or weekly.
134 $days['day'] = $report_day;
135
136 return $days;
137 }
138
139 /**
140 * Extracts subscriber information from the provided data array.
141 *
142 * @param array $data Data containing subscriber information.
143 *
144 * @return array
145 */
146 private function get_subscribers( array $data ): array {
147 $subscribers = array();
148 if ( is_array( $data ) && array() !== $data ) {
149 foreach ( $data as $receipt ) {
150 $subscribers['out_house_recipients'][] = array(
151 'name' => $receipt['first_name'],
152 'email' => $receipt['email'],
153 'status' => $this->status_recipient,
154 'avatar' => get_avatar_url( $receipt['email'] ),
155 );
156 }
157 }
158
159 return $subscribers;
160 }
161
162 /**
163 * Updates the security tweaks configuration from the old format to the new format.
164 *
165 * @param array $old_tweaks The old security tweaks configuration.
166 *
167 * @return array
168 */
169 public function update_security_tweaks( $old_tweaks ): array {
170 $security_tweaks = array(
171 'issues' => $old_tweaks['issues'] ?? array(),
172 'fixed' => $old_tweaks['fixed'] ?? array(),
173 'ignore' => $old_tweaks['ignore'] ?? array(),
174 'automate' => isset( $old_tweaks['automate'] )
175 // Sometimes string value from old version.
176 ? ( is_bool( $old_tweaks['automate'] ) ? $old_tweaks['automate'] : (bool) $old_tweaks['automate'] )
177 : true,
178 'notification' => isset( $old_tweaks['notification'] )
179 ? ( $old_tweaks['notification'] ? 'enabled' : 'disabled' )
180 : 'disabled',
181 // Prepare from 'notification_repeat' to configs['reminder'] with default value 'weekly'.
182 'notification_repeat' => ! isset( $old_tweaks['notification_repeat'] ) || '' === $old_tweaks['notification_repeat']
183 ? 'weekly'
184 : ( $old_tweaks['notification_repeat'] ? 'daily' : 'weekly' ),
185 'data' => $old_tweaks['data'] ?? array(),
186 );
187 if ( isset( $old_tweaks['last_sent'] ) ) {
188 $security_tweaks['last_sent'] = $old_tweaks['last_sent'];
189 }
190
191 $security_tweaks['subscribers'] = isset( $old_tweaks['receipts'] )
192 ? $this->get_subscribers( $old_tweaks['receipts'] )
193 : array();
194
195 return $security_tweaks;
196 }
197
198 /**
199 * Updates the scan configuration from the old format to the new format.
200 *
201 * @param array $old_data The old scan configuration.
202 *
203 * @return array
204 */
205 public function update_scan( array $old_data ): array {
206 $scan = array(
207 'integrity_check' => ! isset( $old_data['scan_core'] ) || ! is_bool( $old_data['scan_core'] ) ? true : $old_data['scan_core'],
208 'check_core' => ! isset( $old_data['check_core'] ) || ! is_bool( $old_data['check_core'] ) ? true : $old_data['check_core'],
209 'check_plugins' => ! isset( $old_data['check_plugins'] ) || ! is_bool( $old_data['check_plugins'] ) ? false : $old_data['check_plugins'],
210 'check_known_vuln' => ! isset( $old_data['scan_vuln'] ) || ! is_bool( $old_data['scan_vuln'] ) ? true : $old_data['scan_vuln'],
211 'scan_malware' => ! isset( $old_data['scan_content'] ) || ! is_bool( $old_data['scan_content'] ) ? false : $old_data['scan_content'],
212 'filesize' => ! isset( $old_data['max_filesize'] ) || ! is_int( $old_data['max_filesize'] ) ? 3 : $old_data['max_filesize'],
213 // Should get bool value.
214 'report' => isset( $old_data['report'] ) && $old_data['report'] ? 'enabled' : 'disabled',
215 'always_send' => ! isset( $old_data['always_send'] ) || ! is_bool( $old_data['always_send'] ) ? false : $old_data['always_send'],
216 'time' => ! isset( $old_data['time'] ) || ! is_string( $old_data['time'] ) || '' === $old_data['time'] ? '4:00' : $old_data['time'],
217 'frequency' => ! isset( $old_data['frequency'] ) || ! is_string( $old_data['frequency'] ) || '' === $old_data['frequency']
218 ? 'weekly'
219 : $this->frequency_type( $old_data['frequency'] ),
220 // Should get bool value.
221 'notification' => isset( $old_data['notification'] ) && $old_data['notification']
222 ? 'enabled'
223 : 'disabled',
224 'always_send_notification' => ! isset( $old_data['always_send_notification'] ) || ! is_bool( $old_data['always_send_notification'] )
225 ? false
226 : $old_data['always_send_notification'],
227 'error_send' => ! isset( $old_data['error_send'] ) || ! is_bool( $old_data['error_send'] ) ? false : $old_data['error_send'],
228 'email_subject_issue_found' => $old_data['email_subject_issue'] ?? '',
229 'email_subject_issue_not_found' => $old_data['email_subject'] ?? '',
230 'email_subject_error' => $old_data['email_subject_error'] ?? '',
231 'email_content_issue_found' => $old_data['email_has_issue'] ?? '',
232 'email_content_issue_not_found' => $old_data['email_all_ok'] ?? '',
233 'email_content_error' => $old_data['email_content_error'] ?? '',
234 // Since 2.7.0.
235 'scheduled_scanning' => false,
236 // Since 5.9.0.
237 'check_abandoned_plugin' => true,
238 );
239
240 $scan['report_subscribers'] = ! isset( $old_data['recipients'] ) || ! is_array( $old_data['recipients'] ) || array() === $old_data['recipients']
241 ? array()
242 : $this->get_subscribers( $old_data['recipients'] );
243 $scan['notification_subscribers'] = ! isset( $old_data['recipients_notification'] ) || ! is_array( $old_data['recipients_notification'] ) || array() === $old_data['recipients_notification']
244 ? array()
245 : $this->get_subscribers( $old_data['recipients_notification'] );
246 // Todo: need the key 'last_report_sent'? It's no always in the unixtime format.
247 if ( ! isset( $old_data['frequency'] ) || '' === $old_data['frequency'] ) {
248 $scan['day'] = 'sunday';
249 $scan['day_n'] = 1;
250
251 return $scan;
252 } else {
253 return array_merge( $scan, $this->frequency_day( $old_data['frequency'], $old_data['day'] ) );
254 }
255 }
256
257 /**
258 * Updates the IP lockout configuration from the old format to the new format.
259 *
260 * @param array $old_data The old IP lockout configuration.
261 *
262 * @return array
263 */
264 public function update_ip_lockout( array $old_data ): array {
265 $merged_bl_file_data = $old_data['detect_404_blacklist'] ?? '';
266 // Merge blacklist file & filetype data.
267 if ( isset( $old_data['detect_404_filetypes_blacklist'] ) && '' !== trim( $old_data['detect_404_filetypes_blacklist'] ) ) {
268 $merged_bl_file_data .= PHP_EOL . $old_data['detect_404_filetypes_blacklist'];
269 }
270 $merged_wl_file_data = $old_data['detect_404_whitelist'] ?? '';
271 // Merge whitelist file & filetype data.
272 if ( isset( $old_data['detect_404_whitelist'] ) && '' !== trim( $old_data['detect_404_ignored_filetypes'] ) ) {
273 $merged_wl_file_data .= PHP_EOL . $old_data['detect_404_ignored_filetypes'];
274 }
275
276 $default_login_lockout_values = ( new Model_Login_Lockout() )->get_default_values();
277 $default_404_lockout_values = ( new Model_Notfound_Lockout() )->get_default_values();
278 $default_ip_lockout_values = ( new Model_Blacklist_Lockout() )->get_default_values();
279 $default_ua_lockout_values = ( new Model_Ua_Lockout() )->get_default_values();
280
281 $iplockout = array(
282 'login_protection' => ! isset( $old_data['login_protection'] ) || ! is_bool( $old_data['login_protection'] )
283 ? true : $old_data['login_protection'],
284 'login_protection_login_attempt' => ! isset( $old_data['login_protection_login_attempt'] ) || ! is_numeric( $old_data['login_protection_login_attempt'] )
285 ? '5' : $old_data['login_protection_login_attempt'],
286 'login_protection_lockout_timeframe' => ! isset( $old_data['login_protection_lockout_timeframe'] ) || ! is_numeric( $old_data['login_protection_lockout_timeframe'] )
287 ? '300' : $old_data['login_protection_lockout_timeframe'],
288 'login_protection_lockout_ban' => ! isset( $old_data['login_protection_lockout_ban'] ) || ! is_bool( $old_data['login_protection_lockout_ban'] )
289 ? false : $old_data['login_protection_lockout_ban'],
290 'login_protection_lockout_duration' => ! isset( $old_data['login_protection_lockout_duration'] ) || ! is_numeric( $old_data['login_protection_lockout_duration'] )
291 ? '4' : $old_data['login_protection_lockout_duration'],
292 'login_protection_lockout_duration_unit' => ! isset( $old_data['login_protection_lockout_duration_unit'] ) || ! is_string( $old_data['login_protection_lockout_duration_unit'] )
293 ? 'hours' : $old_data['login_protection_lockout_duration_unit'],
294 'login_protection_lockout_message' => ! isset( $old_data['login_protection_lockout_message'] ) || '' === $old_data['login_protection_lockout_message']
295 ? $default_login_lockout_values['message']
296 : $old_data['login_protection_lockout_message'],
297 'username_blacklist' => ! isset( $old_data['username_blacklist'] ) || ! is_string( $old_data['username_blacklist'] )
298 ? '' : $old_data['username_blacklist'],
299 'detect_404' => ! isset( $old_data['detect_404'] ) || ! is_bool( $old_data['detect_404'] )
300 ? true : $old_data['detect_404'],
301 'detect_404_threshold' => ! isset( $old_data['detect_404_threshold'] ) || ! is_numeric( $old_data['detect_404_threshold'] )
302 ? '20' : $old_data['detect_404_threshold'],
303 'detect_404_timeframe' => ! isset( $old_data['detect_404_timeframe'] ) || ! is_numeric( $old_data['detect_404_timeframe'] )
304 ? '300' : $old_data['detect_404_timeframe'],
305 'detect_404_lockout_ban' => ! isset( $old_data['detect_404_lockout_ban'] ) || ! is_bool( $old_data['detect_404_lockout_ban'] )
306 ? false : $old_data['detect_404_lockout_ban'],
307 'detect_404_lockout_duration' => ! isset( $old_data['detect_404_lockout_duration'] ) || ! is_numeric( $old_data['detect_404_lockout_duration'] )
308 ? '4' : $old_data['detect_404_lockout_duration'],
309 'detect_404_lockout_duration_unit' => ! isset( $old_data['detect_404_lockout_duration_unit'] ) || ! is_string( $old_data['detect_404_lockout_duration_unit'] )
310 ? 'hours' : $old_data['detect_404_lockout_duration_unit'],
311 'detect_404_lockout_message' => ! isset( $old_data['detect_404_lockout_message'] ) || '' === $old_data['detect_404_lockout_message']
312 ? $default_404_lockout_values['message']
313 : $old_data['detect_404_lockout_message'],
314 'detect_404_blacklist' => $merged_bl_file_data,
315 'detect_404_whitelist' => $merged_wl_file_data,
316 'detect_404_logged' => ! isset( $old_data['detect_404_logged'] ) || ! is_bool( $old_data['detect_404_logged'] )
317 ? true : $old_data['detect_404_logged'],
318 'ip_blacklist' => ! isset( $old_data['ip_blacklist'] ) || ! is_string( $old_data['ip_blacklist'] )
319 ? '' : $old_data['ip_blacklist'],
320 'ip_whitelist' => ! isset( $old_data['ip_whitelist'] ) || ! is_string( $old_data['ip_whitelist'] )
321 ? '' : $old_data['ip_whitelist'],
322 'country_blacklist' => ! isset( $old_data['country_blacklist'] ) || ! is_string( $old_data['country_blacklist'] )
323 ? '' : $old_data['country_blacklist'],
324 'country_whitelist' => ! isset( $old_data['country_whitelist'] ) || ! is_string( $old_data['country_whitelist'] )
325 ? '' : $old_data['country_whitelist'],
326 'ip_lockout_message' => ! isset( $old_data['ip_lockout_message'] ) || '' === $old_data['ip_lockout_message']
327 ? $default_ip_lockout_values['message']
328 : $old_data['ip_lockout_message'],
329 'login_lockout_notification' => ! isset( $old_data['login_lockout_notification'] ) || ! is_bool( $old_data['login_lockout_notification'] )
330 ? true : $old_data['login_lockout_notification'],
331 'ip_lockout_notification' => ! isset( $old_data['ip_lockout_notification'] ) || ! is_bool( $old_data['ip_lockout_notification'] )
332 ? true : $old_data['ip_lockout_notification'],
333 'notification' => 'enabled',
334 'cooldown_enabled' => ! isset( $old_data['cooldown_enabled'] ) || ! is_bool( $old_data['cooldown_enabled'] )
335 ? false : $old_data['cooldown_enabled'],
336 'cooldown_number_lockout' => ! isset( $old_data['cooldown_number_lockout'] ) || ! is_numeric( $old_data['cooldown_number_lockout'] )
337 ? '3' : $old_data['cooldown_number_lockout'],
338 'cooldown_period' => ! isset( $old_data['cooldown_period'] ) || ! is_numeric( $old_data['cooldown_period'] )
339 ? '24' : $old_data['cooldown_period'],
340 'report' => isset( $old_data['report'] ) && $old_data['report'] ? 'enabled' : 'disabled',
341 'report_frequency' => ! isset( $old_data['report_frequency'] ) || '' === $old_data['report_frequency']
342 ? 'weekly'
343 : $this->frequency_type( $old_data['report_frequency'] ),
344 // Data for 'day' below.
345 'report_time' => ! isset( $old_data['report_time'] ) || '' === $old_data['report_time']
346 ? '4:00' : $old_data['report_time'],
347 'storage_days' => ! isset( $old_data['storage_days'] ) || '' === $old_data['storage_days']
348 ? '180' : $old_data['storage_days'],
349 'geoIP_db' => $old_data['geoIP_db'] ?? '',
350 'ip_blocklist_cleanup_interval' => ! isset( $old_data['ip_blocklist_cleanup_interval'] ) || '' === $old_data['ip_blocklist_cleanup_interval']
351 ? 'never' : $old_data['ip_blocklist_cleanup_interval'],
352 // For UA Banning.
353 'ua_banning_enabled' => $old_data['ua_banning_enabled'] ?? false,
354 'ua_banning_message' => $old_data['ua_banning_message'] ?? $default_ua_lockout_values['message'],
355 'ua_banning_blacklist' => $old_data['ua_banning_blacklist'] ?? $default_ua_lockout_values['blacklist'],
356 'ua_banning_whitelist' => $old_data['ua_banning_whitelist'] ?? $default_ua_lockout_values['whitelist'],
357 'ua_banning_empty_headers' => $old_data['ua_banning_empty_headers'] ?? false,
358 'maxmind_license_key' => $old_data['maxmind_license_key'] ?? '',
359 // Global IP list.
360 'global_ip_list' => $old_data['global_ip_list'] ?? false,
361 'global_ip_list_blocklist_autosync' => $old_data['global_ip_list_blocklist_autosync'] ?? false,
362 );
363 if ( isset( $old_data['lastReportSent'] ) && '' !== $old_data['lastReportSent'] ) {
364 $iplockout['last_sent'] = $old_data['lastReportSent'];
365 }
366
367 $iplockout['report_subscribers'] = ! isset( $old_data['report_receipts'] ) || ! is_array( $old_data['report_receipts'] ) || array() === $old_data['report_receipts']
368 ? array()
369 : $this->get_subscribers( $old_data['report_receipts'] );
370 $iplockout['notification_subscribers'] = ! isset( $old_data['receipts'] ) || ! is_array( $old_data['receipts'] ) || array() === $old_data['receipts']
371 ? array()
372 : $this->get_subscribers( $old_data['receipts'] );
373
374 if ( ! isset( $old_data['report_frequency'] ) || '' === $old_data['report_frequency'] ) {
375 $iplockout['day'] = 'sunday';
376 $iplockout['day_n'] = 1;
377
378 return $iplockout;
379 } else {
380 return array_merge(
381 $iplockout,
382 $this->frequency_day( $old_data['report_frequency'], $old_data['report_day'] )
383 );
384 }
385 }
386
387 /**
388 * Updates the audit configuration from the old format to the new format.
389 *
390 * @param array $old_data The old audit configuration.
391 *
392 * @return array
393 */
394 public function update_audit( array $old_data ): array {
395 $audit = array(
396 'enabled' => is_bool( $old_data['enabled'] )
397 ? $old_data['enabled']
398 : (bool) $old_data['enabled'],
399 'report' => isset( $old_data['notification'] ) && $old_data['notification'] ? 'enabled' : 'disabled',
400 'frequency' => ! isset( $old_data['frequency'] ) || '' === $old_data['frequency']
401 ? 'weekly'
402 : $this->frequency_type( $old_data['frequency'] ),
403 'time' => ! isset( $old_data['time'] ) || '' === $old_data['time']
404 ? '4:00'
405 : $old_data['time'],
406 'storage_days' => ! isset( $old_data['storage_days'] ) || '' === $old_data['storage_days']
407 ? '6 months'
408 : $old_data['storage_days'],
409 );
410 if ( isset( $old_data['lastReportSent'] ) && '' !== $old_data['lastReportSent'] ) {
411 $audit['last_sent'] = $old_data['lastReportSent'];
412 }
413
414 $audit['subscribers'] = ! isset( $old_data['receipts'] ) || ! is_array( $old_data['receipts'] ) || array() === $old_data['receipts']
415 ? array()
416 : $this->get_subscribers( $old_data['receipts'] );
417
418 if ( ! isset( $old_data['frequency'] ) || '' === $old_data['frequency'] ) {
419 $audit['day'] = 'sunday';
420 $audit['day_n'] = 1;
421
422 return $audit;
423 } else {
424 return array_merge( $audit, $this->frequency_day( $old_data['frequency'], $old_data['day'] ) );
425 }
426 }
427
428 /**
429 * Updates the two-factor authentication configuration from the old format to the new format.
430 *
431 * @param array $old_data The old two-factor authentication configuration.
432 *
433 * @return array
434 */
435 public function update_two_factor( array $old_data ): array {
436
437 return array(
438 'enabled' => $old_data['enabled'],
439 'lost_phone' => $old_data['lost_phone'],
440 'force_auth' => $old_data['force_auth'],
441 'force_auth_mess' => $old_data['force_auth_mess'],
442 'user_roles' => $old_data['user_roles'],
443 'force_auth_roles' => $old_data['force_auth_roles'],
444 'custom_graphic' => $old_data['custom_graphic'],
445 'custom_graphic_type' => $old_data['custom_graphic_type'] ?? Two_Fa::CUSTOM_GRAPHIC_TYPE_UPLOAD,
446 'custom_graphic_url' => $old_data['custom_graphic_url'] ?? '',
447 'custom_graphic_link' => $old_data['custom_graphic_link'] ?? '',
448 'email_subject' => $old_data['email_subject'] ?? '',
449 'email_sender' => $old_data['email_sender'] ?? '',
450 'email_body' => $old_data['email_body'] ?? '',
451 'app_title' => '',
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