Skip to content

Commit

Permalink
Upd. Settings. Additional headers IP getting option updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
Glomberg committed Nov 15, 2023
1 parent e310ffa commit 696c8bd
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions inc/spbc-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
),
),
Expand Down Expand Up @@ -5027,6 +5014,44 @@ function spbc_settings_field__action_shuffle_salts()
<?php
}

function spbc_settings_field__secfw__get_ip__get_description()
{
$ip = IP::get();

return sprintf('Detected IP is: %s',
'<a href="https://cleantalk.org/my-ip/'.$ip.'" target="_blank">'.$ip.'</a>'
);
}

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
*/
Expand Down

0 comments on commit 696c8bd

Please sign in to comment.