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..4dae864d6 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,31 @@ 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; + } + + // 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); + } + /** * Format status * @param array $row @@ -144,6 +172,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;