From 696c8bd2bb9e17293039bd7146c65319f740ce6e Mon Sep 17 00:00:00 2001 From: Glomberg Date: Wed, 15 Nov 2023 19:04:09 +0300 Subject: [PATCH] Upd. Settings. Additional headers IP getting option updated. --- inc/spbc-settings.php | 55 +++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/inc/spbc-settings.php b/inc/spbc-settings.php index 5ed68ec8f..c4f27b47c 100644 --- a/inc/spbc-settings.php +++ b/inc/spbc-settings.php @@ -529,22 +529,9 @@ function spbc_settings__register() 'secfw__get_ip' => array( 'type' => 'field', 'input_type' => 'select', - 'options' => array( - array('val' => 1, 'label' => __('Auto', 'security-malware-firewall'),), - array('val' => 2, 'label' => __('Remote Addr', 'security-malware-firewall'),), - array('val' => 3, 'label' => __('X-Forwarder-For', 'security-malware-firewall'),), - array('val' => 4, 'label' => __('X-Real-Ip', 'security-malware-firewall'),), - array('val' => 5, 'label' => __('Incap-Client-Ip', 'security-malware-firewall'),), - array('val' => 6, 'label' => __('Ico-X-Forwarded-For', 'security-malware-firewall'),), - array('val' => 7, 'label' => __('X-Sp-Forwarded-Ip', 'security-malware-firewall'),), - array('val' => 8, 'label' => __('X-Client-Ip', 'security-malware-firewall'),), - array('val' => 9, 'label' => __('X-Sucuri-Clientip', 'security-malware-firewall'),), - array('val' => 10, 'label' => __('X-Middleton-Ip', 'security-malware-firewall'),), - array('val' => 11, 'label' => __('X-Gt-Viewer-Ip', 'security-malware-firewall'),), - array('val' => 12, 'label' => __('Cf-Connecting-Ip', 'security-malware-firewall'),), - array('val' => 13, 'label' => __('Remote-Ip', 'security-malware-firewall'),), - ), + 'options' => spbc_settings_field__secfw__get_ip__get_labels(), 'title' => __('Get visitors IP from additional headers', 'security-malware-firewall'), + 'description' => spbc_settings_field__secfw__get_ip__get_description(), ), ), ), @@ -5027,6 +5014,44 @@ function spbc_settings_field__action_shuffle_salts() '.$ip.'' + ); +} + +function spbc_settings_field__secfw__get_ip__get_labels () { + $available_header = array( + 2 => array('slug' => 'remote_addr', 'name' => 'Remote Addr'), + 3 => array('slug' => 'x_forwarded_for', 'name' => 'X-Forwarder-For'), + 4 => array('slug' => 'x_real_ip', 'name' => 'X-Real-Ip'), + 5 => array('slug' => 'incapsula', 'name' => 'Incap-Client-Ip'), + 6 => array('slug' => 'ico_x_forwarded_for', 'name' => 'Ico-X-Forwarded-For'), + 7 => array('slug' => 'stackpath', 'name' => 'X-Sp-Forwarded-Ip'), + 8 => array('slug' => 'x_forwarded_by', 'name' => 'X-Client-Ip'), + 9 => array('slug' => 'sucury', 'name' => 'X-Sucuri-Clientip'), + 10 => array('slug' => 'ezoic', 'name' => 'X-Middleton-Ip'), + 11 => array('slug' => 'gtranslate', 'name' => 'X-Gt-Viewer-Ip'), + 12 => array('slug' => 'cloud_flare', 'name' => 'Cf-Connecting-Ip'), + 13 => array('slug' => 'ovh', 'name' => 'Remote-Ip'), + ); + $options = array(); + $options[] = array('val' => 1, 'label' => __('Auto', 'security-malware-firewall'),); + + foreach ( $available_header as $key => $header ) { + $ip = IP::get($header['slug'], [], true); + $option_value = $header['name']; + $option_value .= isset(IP::getInstance()->ips_stored[$header['slug']]) + ? ' ('. IP::getInstance()->ips_stored[$header['slug']] .')' + : ' (not provided)'; + $options[] = array('val' => $key, 'label' => $option_value); + } + return $options; +} + /** * @return int|void */