Automatic WordPress security: local firewall, malware and file-integrity scanning, vulnerability protection, quarantine, scheduled backups, an optional page cache, and automatic global threat intelligence. See README.md for installation, update, and uninstall instructions.
45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
class Argus_GeoIP {
|
|
|
|
const LOCAL = 'Local / Private Network';
|
|
const UNKNOWN = 'Unknown';
|
|
|
|
public static function classify( $ip ) {
|
|
if ( ! filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) {
|
|
return array( 'label' => self::LOCAL, 'code' => null );
|
|
}
|
|
|
|
$result = apply_filters( 'argus_wpd_resolve_country', null, $ip );
|
|
|
|
if ( is_array( $result ) && ! empty( $result['label'] ) ) {
|
|
return array( 'label' => $result['label'], 'code' => $result['code'] ?? null );
|
|
}
|
|
if ( is_string( $result ) && '' !== $result ) {
|
|
return array( 'label' => $result, 'code' => null );
|
|
}
|
|
return array( 'label' => self::UNKNOWN, 'code' => null );
|
|
}
|
|
|
|
public static function label( $ip ) {
|
|
return self::classify( $ip )['label'];
|
|
}
|
|
|
|
public static function icon( $ip ) {
|
|
$c = self::classify( $ip );
|
|
if ( $c['code'] && preg_match( '/^[a-zA-Z]{2}$/', $c['code'] ) ) {
|
|
$code = strtoupper( $c['code'] );
|
|
return mb_chr( 0x1F1E6 + ( ord( $code[0] ) - 65 ) ) . mb_chr( 0x1F1E6 + ( ord( $code[1] ) - 65 ) );
|
|
}
|
|
if ( self::LOCAL === $c['label'] ) {
|
|
return '🏠';
|
|
}
|
|
return '🌐';
|
|
}
|
|
|
|
}
|