Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/CleantalkSP/SpbctWP/DB/SQLSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '',
Expand Down
35 changes: 34 additions & 1 deletion lib/CleantalkSP/SpbctWP/Firewall/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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;
}
Comment thread
alexander-b-clean marked this conversation as resolved.

// 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
Expand Down Expand Up @@ -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;
Expand Down
Loading