From 68a70e191c95c2f0b2fccf5779a34c7ac614dae9 Mon Sep 17 00:00:00 2001 From: datorik Date: Mon, 24 Aug 2026 09:51:00 +0300 Subject: [PATCH 1/2] Udp.Code.Incorrect logs --- lib/CleantalkSP/Security/Firewall.php | 2 ++ lib/CleantalkSP/SpbctWP/DB/SQLSchema.php | 2 +- lib/CleantalkSP/SpbctWP/Firewall/View.php | 33 ++++++++++++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/CleantalkSP/Security/Firewall.php b/lib/CleantalkSP/Security/Firewall.php index f1e117b2a..10e4718f7 100644 --- a/lib/CleantalkSP/Security/Firewall.php +++ b/lib/CleantalkSP/Security/Firewall.php @@ -41,6 +41,7 @@ class Firewall private $statuses_priority = array( 'PASS', + 'PASS_AS_SKIPPED_NETWORK', 'DENY', 'DENY_BY_SEC_FW', 'DENY_BY_SPAM_FW', @@ -238,6 +239,7 @@ private function filterResultsByLists(array $firewall_results) private function calculatePriorityForFirewallResult(Result $firewall_result) { $point_for_status = array_search($firewall_result->status, $this->statuses_priority, true); + $point_for_status = $point_for_status === false ? 0 : $point_for_status; $points_for_trusted_network = $firewall_result->status === 'PASS_BY_TRUSTED_NETWORK' ? 100 : 0; $points_for_mask = $firewall_result->mask; diff --git a/lib/CleantalkSP/SpbctWP/DB/SQLSchema.php b/lib/CleantalkSP/SpbctWP/DB/SQLSchema.php index 2ede25594..57041be0a 100644 --- a/lib/CleantalkSP/SpbctWP/DB/SQLSchema.php +++ b/lib/CleantalkSP/SpbctWP/DB/SQLSchema.php @@ -472,7 +472,7 @@ class SQLSchema extends \CleantalkSP\Common\DB\SQLSchema array('field' => 'ip_entry', 'type' => 'varchar(50)', 'null' => 'yes',), array( 'field' => 'status', - 'type' => "enum('PASS','PASS_BY_TRUSTED_NETWORK','PASS_BY_WHITELIST','DENY','DENY_BY_NETWORK','DENY_BY_DOS','DENY_BY_WAF_BLOCKER','DENY_BY_WAF_XSS','DENY_BY_WAF_SQL','DENY_BY_WAF_FILE','DENY_BY_WAF_EXPLOIT','DENY_BY_SEC_FW','DENY_BY_SPAM_FW','DENY_BY_BFP')", + 'type' => "enum('PASS','PASS_AS_SKIPPED_NETWORK','PASS_BY_TRUSTED_NETWORK','PASS_BY_WHITELIST','DENY','DENY_BY_NETWORK','DENY_BY_DOS','DENY_BY_WAF_BLOCKER','DENY_BY_WAF_XSS','DENY_BY_WAF_SQL','DENY_BY_WAF_FILE','DENY_BY_WAF_EXPLOIT','DENY_BY_SEC_FW','DENY_BY_SPAM_FW','DENY_BY_BFP')", 'null' => 'yes', 'default' => 'NULL', 'extra' => '', diff --git a/lib/CleantalkSP/SpbctWP/Firewall/View.php b/lib/CleantalkSP/SpbctWP/Firewall/View.php index db3d6f979..e0f986661 100644 --- a/lib/CleantalkSP/SpbctWP/Firewall/View.php +++ b/lib/CleantalkSP/SpbctWP/Firewall/View.php @@ -101,7 +101,10 @@ private static function getFirewallRows($limit = SPBC_LAST_ACTIONS_TO_VIEW, $off $data[] = array( 'ip_entry' => $row['ip_entry'], - 'country' => isset($ip_countries[$row['ip_entry']]) ? $ip_countries[$row['ip_entry']] : '', + 'country' => self::preferFirewallCountry( + isset($ip_countries[$row['ip_entry']]) ? $ip_countries[$row['ip_entry']] : '', + $row['country_code'] + ), 'entry_timestamp' => $row['entry_timestamp'], 'status' => $status['status'], 'statusColor' => $status['color'], @@ -117,6 +120,29 @@ private static function getFirewallRows($limit = SPBC_LAST_ACTIONS_TO_VIEW, $off return $data; } + /** + * The firewall resolves the country by the smallest network the IP belongs to and stores it in the log. + * The IP info service may resolve the same address to a bigger network of another country, + * so the stored code wins when the two disagree. + * + * @param array|string $country location received from the IP info service + * @param string|null $country_code country code stored in the log entry + * + * @return array|string + */ + private static function preferFirewallCountry($country, $country_code) + { + if ( empty($country_code) || $country_code === '0' ) { + return $country; + } + + if ( isset($country['country_code']) && $country['country_code'] === $country_code ) { + return $country; + } + + return array('country_code' => $country_code); + } + /** * Format status * @param array $row @@ -144,6 +170,11 @@ private static function formatStatus($row) $status = $passed_text . ' ' . __('Whitelisted.', 'security-malware-firewall'); $color = 'spbcGreen'; break; + case 'PASS_AS_SKIPPED_NETWORK': + $status = $passed_text . ' ' + . __('The country of the network is not blocked.', 'security-malware-firewall'); + $color = 'spbcGreen'; + break; case 'DENY': $status = $blocked_text . ' ' . __('Blacklisted.', 'security-malware-firewall'); break; From e97e7776f7d0ade5d3b4a593b50279388ff16c5b Mon Sep 17 00:00:00 2001 From: datorik Date: Sun, 6 Sep 2026 17:46:00 +0300 Subject: [PATCH 2/2] Udp.Code.Incorrect logs --- lib/CleantalkSP/Security/Firewall.php | 2 -- lib/CleantalkSP/SpbctWP/Firewall/View.php | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/CleantalkSP/Security/Firewall.php b/lib/CleantalkSP/Security/Firewall.php index 10e4718f7..f1e117b2a 100644 --- a/lib/CleantalkSP/Security/Firewall.php +++ b/lib/CleantalkSP/Security/Firewall.php @@ -41,7 +41,6 @@ class Firewall private $statuses_priority = array( 'PASS', - 'PASS_AS_SKIPPED_NETWORK', 'DENY', 'DENY_BY_SEC_FW', 'DENY_BY_SPAM_FW', @@ -239,7 +238,6 @@ private function filterResultsByLists(array $firewall_results) private function calculatePriorityForFirewallResult(Result $firewall_result) { $point_for_status = array_search($firewall_result->status, $this->statuses_priority, true); - $point_for_status = $point_for_status === false ? 0 : $point_for_status; $points_for_trusted_network = $firewall_result->status === 'PASS_BY_TRUSTED_NETWORK' ? 100 : 0; $points_for_mask = $firewall_result->mask; diff --git a/lib/CleantalkSP/SpbctWP/Firewall/View.php b/lib/CleantalkSP/SpbctWP/Firewall/View.php index e0f986661..4dae864d6 100644 --- a/lib/CleantalkSP/SpbctWP/Firewall/View.php +++ b/lib/CleantalkSP/SpbctWP/Firewall/View.php @@ -140,7 +140,9 @@ private static function preferFirewallCountry($country, $country_code) return $country; } - return array('country_code' => $country_code); + // The service name belongs to the other country, so the stored code is used as the label - + // the plugin has no local country code to name map. + return array('country_code' => $country_code, 'country_name' => $country_code); } /**