OS : Linux
PHP Version : 7.4.33
Software : Apache/2.4.6 (CentOS) PHP/7.4.33
Information System : Linux apprendre2 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 $screen_id ) ) ) {
return;
}
$option = 'cerber-' . $screen_id;
register_setting( 'cerberus-' . $screen_id, $option );
global $tmp;
foreach ( $sections as $section_id => $section_config ) {
$desc = crb_array_get( $section_config, 'desc' );
if ( $links = crb_array_get( $section_config, 'seclinks' ) ) {
foreach ( $links as $link ) {
$desc .= '[ ' . $link[0] . ' ]';
}
}
if ( $doclink = crb_array_get( $section_config, 'doclink' ) ) {
$desc .= '[ ' . __( 'Know more', 'wp-cerber' ) . ' ]';
}
$tmp[ $section_id ] = '' . $desc . '';
add_settings_section( $section_id, crb_array_get( $section_config, 'name', '' ), function ( $sec ) {
global $tmp;
if ( $tmp[ $sec['id'] ] ) {
echo $tmp[ $sec['id'] ];
}
}, $option );
foreach ( $section_config['fields'] as $field => $config ) {
if ( ( $req_wp = $config['requires_wp'] ?? false )
&& ! crb_wp_version_compare( (string) $req_wp ) ) {
continue;
}
if ( ( $cb = $config['requires_true'] ?? false )
&& is_callable( $cb )
&& ! $cb() ) {
continue;
}
if ( in_array( $field, CRB_PRO_SETTINGS ) && ! lab_lab() ) {
continue;
}
$config['setting'] = $field;
$config['group'] = $screen_id;
$config['type'] = $config['type'] ?? 'text';
// Setting row (tr) class, to specify the input class use 'input_class'
$config['class'] = '';
if ( $config['type'] == 'hidden' ) {
$config['class'] .= ' crb-display-none';
}
if ( isset( $config['enabler'] ) ) {
$config['class'] .= crb_check_enabler( $config, crb_get_settings( $config['enabler'][0] ) );
}
add_settings_field( $field, crb_array_get( $config, 'title', '' ), 'cerber_field_show', $option, $section_id, $config );
}
}
}
function cerber_get_setting_id( $tab = null ) {
$id = ( ! $tab ) ? cerber_get_get( 'tab', CRB_SANITIZE_ID ) : $tab;
if ( ! $id ) {
$id = cerber_get_wp_option_id();
}
if ( ! $id ) {
$id = crb_admin_get_page();
}
// Mapping: some tab names (or page id) doesn't match WP setting names
// tab => settings id
$map = array(
'scan_settings' => 'scanner', // define('CERBER_OPT_S','cerber-scanner');
'scan_schedule' => 'schedule', // define('CERBER_OPT_E','cerber-schedule');
'scan_policy' => 'policies',
'ti_settings' => 'traffic',
'captcha' => 'recaptcha',
'cerber-recaptcha' => 'antispam',
'global_policies' => 'users',
'cerber-shield' => 'user_shield',
'cerber-nexus' => 'nexus-slave',
'nexus_slave' => 'nexus-slave',
);
crb_addon_settings_mapper( $map );
if ( isset( $map[ $id ] ) ) {
return $map[ $id ];
}
return $id;
}
/**
* Works when updating WP options
*
* @return bool|string
*/
function cerber_get_wp_option_id( $option_page = null ) {
if ( ! $option_page ) {
$option_page = crb_array_get( $_POST, 'option_page' );
}
if ( $option_page && ( 0 === strpos( $option_page, 'cerberus-' ) ) ) {
return substr( $option_page, 9 ); // 8 = length of 'cerberus-'
}
return false;
}
/*
* Display a settings form on an admin page
*
*/
function cerber_show_settings_form( $group = null ) {
$action = '';
if ( is_multisite() ) {
$action = ''; // Settings API doesn't work in multisite. Post data will be handled in the cerber_ms_update()
}
else {
if ( nexus_is_valid_request() ) {
//$action = cerber_admin_link();
}
else {
$action = 'options.php'; // Standard way
}
}
?>
' . $hint . '
'; if ( $echo ) { echo $echo; } return $html; } /* Sanitizing users input for Main Settings */ add_filter( 'pre_update_option_'.CERBER_OPT, function ($new, $old, $option) { $ret = cerber_set_boot_mode( $new['boot-mode'], $old['boot-mode'] ); if ( crb_is_wp_error( $ret ) ) { cerber_admin_notice( __( 'ERROR:', 'wp-cerber' ) . ' ' . $ret->get_error_message() ); cerber_admin_notice( __( 'Plugin initialization mode has not been changed', 'wp-cerber' ) ); $new['boot-mode'] = $old['boot-mode']; } $new['attempts'] = absint( $new['attempts'] ); $new['period'] = absint( $new['period'] ); $new['lockout'] = absint( $new['lockout'] ); $new['agperiod'] = absint( $new['agperiod'] ); $new['aglocks'] = absint( $new['aglocks'] ); $new['aglast'] = absint( $new['aglast'] ); if ( cerber_is_permalink_enabled() ) { $new['loginpath'] = urlencode( str_replace( '/', '', $new['loginpath'] ) ); $new['loginpath'] = sanitize_text_field( $new['loginpath'] ); if ( $new['loginpath'] ) { if ( $new['loginpath'] == 'wp-admin' || preg_match( '/[#|\.\!\?\:\s]/', $new['loginpath'] ) ) { cerber_admin_notice( __( 'ERROR:', 'wp-cerber' ) . ' You may not set this value for Custom login URL. Please specify another one.' ); $new['loginpath'] = $old['loginpath']; } elseif ( $new['loginpath'] != $old['loginpath'] ) { $href = cerber_get_home_url() . '/' . $new['loginpath'] . '/'; $url = urldecode( $href ); $msg = array(); $msg_e = array(); $msg[] = __( 'Attention! You have changed the login URL! The new login URL is', 'wp-cerber' ) . ': ' . $url . ''; $msg_e[] = __( 'Attention! You have changed the login URL! The new login URL is', 'wp-cerber' ) . ': ' . $url; $msg[] = __( 'If you use a caching plugin, you have to add your new login URL to the list of pages not to cache.', 'wp-cerber' ); $msg_e[] = __( 'If you use a caching plugin, you have to add your new login URL to the list of pages not to cache.', 'wp-cerber' ); cerber_admin_notice( $msg ); cerber_send_notification( 'newlurl', array( 'text' => $msg_e ) ); } } } else { $new['loginpath'] = ''; $new['loginnowp'] = 0; } if ( $new['loginnowp'] && empty( $new['loginpath'] ) && ! class_exists( 'WooCommerce' ) ) { cerber_admin_notice( array( '' . __( 'Heads up!' ) . '', __( 'You have disabled the default login page. Ensure that you have configured an alternative login page. Otherwise, you will not be able to log in.', 'wp-cerber' ) ) ); } $new['ciduration'] = absint( $new['ciduration'] ); $new['cilimit'] = absint( $new['cilimit'] ); $new['cilimit'] = $new['cilimit'] == 0 ? '' : $new['cilimit']; $new['ciperiod'] = absint( $new['ciperiod'] ); $new['ciperiod'] = $new['ciperiod'] == 0 ? '' : $new['ciperiod']; if ( ! $new['cilimit'] ) { $new['ciperiod'] = ''; } if ( ! $new['ciperiod'] ) { $new['cilimit'] = ''; } $new['keeplog'] = absint( $new['keeplog'] ); if ( $new['keeplog'] == 0 ) { $new['keeplog'] = 1; } if ( $new['cookiepref'] != $old['cookiepref'] ) { crb_update_cookie_dependent(); } return $new; }, 10, 3 ); /* Sanitizing/checking user input for anti-spam tab settings */ add_filter( 'pre_update_option_' . CERBER_OPT_A, function ( $new, $old, $option ) { if ( empty( $new['botsany'] ) && empty( $new['botscomm'] ) && empty( $new['botsreg'] ) ) { update_site_option( 'cerber-antibot', '' ); } $warn = false; if ( ! empty( $new['botsany'] ) && crb_array_get( $new, 'botsany' ) != crb_array_get( $old, 'botsany' ) ) { $warn = true; } if ( ! empty( $new['botscomm'] ) && crb_array_get( $new, 'botscomm' ) != crb_array_get( $old, 'botscomm' ) ) { $warn = true; } if ( ! empty( $new['customcomm'] ) ) { if ( ! crb_get_compiled( 'custom_comm_slug' ) ) { crb_update_compiled( 'custom_comm_slug', crb_random_string( 20, 30 ) ); crb_update_compiled( 'custom_comm_mark', crb_random_string( 20, 30 ) ); $warn = true; } } else { if ( crb_get_compiled( 'custom_comm_slug' ) ) { crb_update_compiled( 'custom_comm_slug', '' ); $warn = true; } } if ( $warn ) { cerber_admin_notice( array( '' . __( 'Important note if you have a caching plugin in place', 'wp-cerber' ) . '', __( 'To avoid false positives and get better anti-spam performance, please clear the plugin cache.', 'wp-cerber' ) ) ); } return $new; }, 10, 3 ); /* Sanitizing/checking user input for reCAPTCHA tab settings */ add_filter( 'pre_update_option_'.CERBER_OPT_C, function ($new, $old, $option) { // Check ability to make external HTTP requests if ( ! empty( $new['sitekey'] ) && ! empty( $new['secretkey'] ) ) { if ( ( ! $goo = get_wp_cerber()->reCaptchaRequest( '1' ) ) || ! isset( $goo['success'] ) ) { cerber_admin_notice( __( 'ERROR:', 'wp-cerber' ) . ' ' . cerber_get_labels( 'status', 534 ) ); } } $new['recaptcha-period'] = absint( $new['recaptcha-period'] ); $new['recaptcha-number'] = absint( $new['recaptcha-number'] ); $new['recaptcha-within'] = absint( $new['recaptcha-within'] ); return $new; }, 10, 3 ); /* Sanitizing/checking user input for Notifications tab settings */ add_filter( 'pre_update_option_'.CERBER_OPT_N, function ($new, $old, $option) { $emails = cerber_text2array( $new['email'], ',' ); $new['email'] = array(); foreach ( $emails as $item ) { if ( is_email( $item ) ) { $new['email'][] = $item; } else { cerber_admin_notice( __( 'ERROR: please enter a valid email address.' ) ); } } $emails = cerber_text2array( $new['email-report'], ',' ); $new['email-report'] = array(); foreach ( $emails as $item ) { if ( is_email( $item ) ) { $new['email-report'][] = $item; } else { cerber_admin_notice( __( 'ERROR: please enter a valid email address.' ) ); } } $new['emailrate'] = absint( $new['emailrate'] ); // When we install a new token, we set proper default value for the device setting if ( $new['pbtoken'] != $old['pbtoken'] ) { if ( ! $new['pbtoken'] ) { $new['pbdevice'] = ''; } else { $list = cerber_pb_get_devices( $new['pbtoken'] ); if ( is_array( $list ) && ! empty( $list ) ) { $new['pbdevice'] = 'all'; } else { $new['pbdevice'] = ''; } } } return $new; }, 10, 3 ); /* Sanitizing/checking user input for Hardening tab settings */ add_filter( 'pre_update_option_'.CERBER_OPT_H, function ($new, $old, $option) { $new['restwhite'] = cerber_text2array( $new['restwhite'], "\n", function ( $v ) { $v = preg_replace( '/[^a-z_\-\d\/]/i', '', $v ); return trim( $v, '/' ); } ); $result = cerber_htaccess_sync( 'main', $new ); if ( crb_is_wp_error( $result ) ) { $new['adminphp'] = $old['adminphp']; cerber_admin_notice( $result->get_error_message() ); } $result = cerber_htaccess_sync( 'media', $new ); if ( crb_is_wp_error( $result ) ) { $new['phpnoupl'] = $old['phpnoupl']; cerber_admin_notice( $result->get_error_message() ); } return $new; }, 10, 3 ); /* Sanitizing/checking user input for Traffic Inspector tab settings */ add_filter( 'pre_update_option_'.CERBER_OPT_T, function ($new, $old, $option) { $new['tiwhite'] = cerber_text2array( $new['tiwhite'], "\n" ); foreach ( $new['tiwhite'] as $item ) { if ( strrpos( $item, '?' ) ) { cerber_admin_notice( 'You may not specify the query string with a question mark: ' . htmlspecialchars( $item, ENT_SUBSTITUTE ) ); } if ( strrpos( $item, '://' ) ) { cerber_admin_notice( 'You may not specify the full URL: ' . htmlspecialchars( $item, ENT_SUBSTITUTE ) ); } } if ( $new['tithreshold'] ) { $new['tithreshold'] = absint( $new['tithreshold'] ); } $new['tikeeprec'] = absint( $new['tikeeprec'] ); if ( $new['tikeeprec'] == 0 ) { $new['tikeeprec'] = 1; cerber_admin_notice( 'You may not set Keep records for to 0 days. To completely disable logging set Logging mode to Logging disabled.' ); } return $new; }, 10, 3 ); add_filter( 'pre_update_option_' . CERBER_OPT_US, function ( $new, $old, $option ) { if ( ! empty( $new['ds_4acc'] ) ) { CRB_DS::enable_shadowing( 1 ); } else { CRB_DS::disable_shadowing( 1 ); } if ( ! empty( $new['ds_4roles'] ) ) { CRB_DS::enable_shadowing( 2 ); } else { CRB_DS::disable_shadowing( 2 ); } return $new; }, 10, 3 ); add_filter( 'pre_update_option_' . CERBER_OPT_OS, function ( $new, $old, $option ) { if ( ! empty( $new['ds_4opts'] ) ) { CRB_DS::enable_shadowing( 3 ); } else { CRB_DS::disable_shadowing( 3 ); } return $new; }, 10, 3 ); /* Sanitizing/checking user input for Security Scanner settings */ add_filter( 'pre_update_option_' . CERBER_OPT_S, function ( $new, $old, $option ) { $new['scan_exclude'] = cerber_normal_dirs( $new['scan_exclude'] ); return $new; }, 10, 3 ); /* Sanitizing/checking user input for Scanner Schedule settings */ add_filter( 'pre_update_option_' . CERBER_OPT_E, function ( $new, $old, $option ) { $new['scan_aquick'] = absint( $new['scan_aquick'] ); $new['scan_afull-enabled'] = ( empty( $new['scan_afull-enabled'] ) ) ? 0 : 1; $sec = cerber_sec_from_time( $new['scan_afull'] ); if ( ! $sec || ! ( $sec >= 0 && $sec <= 86400 ) ) { $new['scan_afull'] = '01:00'; } $emails = cerber_text2array( $new['email-scan'], ',' ); $new['email-scan'] = array(); foreach ( $emails as $item ) { if ( is_email( $item ) ) { $new['email-scan'][] = $item; } else { cerber_admin_notice( __( 'ERROR: please enter a valid email address.' ) ); } } if ( lab_lab() ) { if ( cerber_cloud_sync( $new ) ) { cerber_admin_message( __( 'The schedule has been updated', 'wp-cerber' ) ); } else { cerber_admin_message( __( 'Unable to update the schedule', 'wp-cerber' ) ); } } return $new; }, 10, 3 ); add_filter( 'pre_update_option_' . CERBER_OPT_P, function ( $new, $old, $option ) { $new['scan_delexdir'] = cerber_normal_dirs($new['scan_delexdir']); return $new; }, 10, 3 ); /** * Let's sanitize and normalize them all * @since 4.1 * */ add_filter( 'pre_update_option', 'cerber_o_o_sanitizer', 10, 3 ); function cerber_o_o_sanitizer( $value, $option, $old_value ) { if ( ! in_array( $option, cerber_get_setting_list() ) ) { return $value; } $pre_sanitize = $value; $defs = crb_get_settings_def(); // TODO: Is there any case when $value is not array??? if ( is_array( $value ) ) { // Parsing settings, applying formatting, etc. foreach ( $value as $setting => &$setting_val ) { if ( ! $conf = crb_array_get( $defs, $setting ) ) { continue; } if ( $enabler = $conf['enabler'] ?? '' ) { if ( crb_check_enabler( $conf, $value[ $enabler[0] ] ) ) { continue; } } $callback = crb_array_get( $conf, 'apply' ); $regex = crb_array_get( $conf, 'regex_filter' ); // Filtering out not allowed chars $validate = crb_array_get( $conf, 'validate' ); if ( isset( $conf['list'] ) ) { // Process the values $setting_val = cerber_text2array( $setting_val, $conf['delimiter'], $callback, $regex ); // Remove not allowed values global $_deny; if ( $_deny = crb_array_get( $conf, 'deny_filter' ) ) { $setting_val = array_filter( $setting_val, function ( $e ) { global $_deny; return ! in_array( $e, $_deny ); } ); } } else { // Process the value if ( $callback && is_callable( $callback ) ) { $setting_val = call_user_func( $callback, $setting_val ); } if ( $regex ) { $setting_val = mb_ereg_replace( $regex, '', $setting_val ); } // Validating the value if ( $validate ) { $field_name = $conf['title'] ?? $conf['label'] ?? 'Unknown field'; $error_msg = ''; if ( ! empty( $validate['required'] ) && ! $setting_val ) { $error_msg = sprintf( __( 'Field %s may not be empty', 'wp-cerber' ), '' . $field_name . '' ); } elseif ( $setting_val && ( $sat = $validate['satisfy'] ?? false ) && is_callable( $sat ) && ! call_user_func( $sat, $setting_val ) ) { $error_msg = sprintf( __( 'Field %s contains an invalid value', 'wp-cerber' ), '' . $field_name . '' ); } if ( $error_msg ) { cerber_admin_notice( '' . __( 'ERROR:' ) . ' ' . $error_msg ); } } } } } if ( is_array( $value ) ) { array_walk_recursive( $value, function ( &$element, $key ) { if ( ! is_array( $element ) ) { $element = sanitize_text_field( (string) $element ); } } ); } else { $value = sanitize_text_field( (string) $value ); } $value = cerber_normalize( $value, $option ); // Warn the user if we have altered some values the user has entered $changed = array(); foreach ( $pre_sanitize as $setting => $pre_val ) { if ( empty( $pre_val ) ) { continue; } if ( is_array( $pre_val ) ) { // Usually checkboxes if ( json_encode( $pre_val ) !== json_encode( $value[ $setting ] ) ) { $changed[] = $setting; } } elseif ( is_array( $value[ $setting ] ) ) { $pre_val = preg_replace( '/\s+/', '', $pre_val ); $san_val = preg_replace( '/\s+/', '', crb_format_field_value( $value[ $setting ], crb_array_get( $defs, $setting ) ) ); if ( $pre_val != $san_val ) { $changed[] = $setting; } } elseif ( $pre_val != $value[ $setting ] ) { $changed[] = $setting; } } if ( $changed ) { $list = array_intersect_key( $defs, array_flip( $changed ) ); $msg = '' . implode( '
', array_column( $list, 'title' ) ) . '