Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/CleantalkSP/Security/Firewall.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public function loadFwModule(FirewallModule $module)
$module->ipAppendAdditional($this->ip_array);
$this->fw_modules[$module->module_name] = $module;
$module->setIpArray($this->ip_array);
// Store real IP for test page display
if ( isset($this->ip_array['real']) && property_exists($module, 'real_ip') ) {
$module->real_ip = $this->ip_array['real'];
}
}
}

Expand Down Expand Up @@ -166,7 +170,7 @@ public function run()
$this->fw_modules[$result->module]->actionsForPassed($result);
//if this is a test, run block anyway
if (!empty($this->test_block) && !empty($this->test_block->module) ) {
$this->fw_modules[ $this->test_block->module ]->_die($result);
$this->fw_modules[ $this->test_block->module ]->_die($this->test_block);
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion lib/CleantalkSP/Security/Firewall/FirewallModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ class FirewallModule extends FirewallModuleAbstract
protected $ip_array = array();

/**
* @var bool
* @var string|null
* @psalm-suppress PossiblyUnusedProperty
*/
public $test_ip;

/**
* Real IP address (user's actual IP, not test IP)
* @var string|null
* @psalm-suppress PossiblyUnusedProperty
*/
public $real_ip;

protected $die_page__file;

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/CleantalkSP/SpbctWP/Firewall/FW.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FW extends FirewallModule
/**
* @psalm-suppress PossiblyUnusedProperty
*/
protected $real_ip;
public $real_ip;

/**
* @psalm-suppress PossiblyUnusedProperty
Expand All @@ -46,7 +46,7 @@ public function ipAppendAdditional(&$ips)
$test_ip = Get::getString('spbct_test_ip');
if ( IP::validate($test_ip) && Get::getString('spbct_test') === md5($this->api_key) ) {
$ips['test'] = $test_ip;
$this->test_ip = (bool) $test_ip;
$this->test_ip = $test_ip;
$this->test = true;
}
}
Expand Down
16 changes: 15 additions & 1 deletion lib/CleantalkSP/SpbctWP/Firewall/FirewallModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
class FirewallModule extends \CleantalkSP\Security\Firewall\FirewallModule
{
public $result;

/**
* Real IP address (user's actual IP, not test IP)
* @var string|null
*/
public $real_ip;

/**
* FireWall_module constructor.
* Use this method to prepare any data for the module working.
Expand Down Expand Up @@ -139,6 +146,10 @@ public function _die(Result $result) // phpcs:ignore PSR2.Methods.MethodDeclarat
)
);

// Check if this is test mode
$is_test_mode = (bool) Get::getString('spbct_test');
$test_ip = Get::getString('spbct_test_ip');

// Translation
$replaces = array(
'{TITLE}' => __('Blocked: ' . $spbc->data["wl_brandname"], 'security-malware-firewall'),
Expand All @@ -149,14 +160,17 @@ public function _die(Result $result) // phpcs:ignore PSR2.Methods.MethodDeclarat
'{TEST_TITLE}' => Get::getString('spbct_test')
? __('This is the testing page for Security FireWall', 'security-malware-firewall')
: '',
'{TEST_INFO_DISPLAY}' => $is_test_mode ? 'block' : 'none',
'{REAL_IP}' => $this->real_ip ?: __('Unknown', 'security-malware-firewall'),
'{TEST_IP}' => $test_ip ?: __('Not specified', 'security-malware-firewall'),
'{REASON}' => $reason,
'{GENERATED_TIMESTAMP}' => time(),
'{FALSE_POSITIVE_WARNING}' => __(
'Maybe you\'ve been blocked by a mistake. Please refresh the page (press CTRL + F5) or try again later.',
'security-malware-firewall'
),

'{REMOTE_ADDRESS}' => $result->ip,
'{REMOTE_ADDRESS}' => $is_test_mode && $test_ip ? $test_ip : $result->ip,
'{SERVICE_ID}' => isset($this->state->data['service_id']) ? $this->state->data['service_id'] : '',
'{HOST}' => Server::getString('HTTP_HOST'),
'{GENERATED}' => sprintf(
Expand Down
4 changes: 4 additions & 0 deletions lib/CleantalkSP/SpbctWP/Firewall/die_page_fw.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@
<h1 class="main">Security FireWall has been activated for your IP&nbsp;<a href="https://cleantalk.org/blacklists/{REMOTE_ADDRESS}" target="_blank">{REMOTE_ADDRESS}</a></h1>
<div>{CUSTOM_MESSAGE}</div>
<h2>{TEST_TITLE}</h2>
<div class="test-info" style="display: {TEST_INFO_DISPLAY}; margin: 15px 0;">
<p><strong style="color: #666;">Your Real IP:</strong> <a href="https://cleantalk.org/blacklists/{REAL_IP}" target="_blank">{REAL_IP}</a></p>
<p><strong style="color: #666;">Test IP being checked:</strong> <a href="https://cleantalk.org/blacklists/{TEST_IP}" target="_blank">{TEST_IP}</a></p>
</div>
<h2 class="second">{REASON}</h2>
<h2 class="second false_positive_warning" style="display: none;">{FALSE_POSITIVE_WARNING}</h2>
{GENERATED}
Expand Down