share
8 years ago
.htaccess
11 years ago
anti_malware.php
4 years ago
class-coupon.php
6 months ago
class-email-sodium.php
3 weeks ago
class-firewall-log.php
1 week ago
class-helpers.php
7 months ago
class-import-export.php
3 months ago
class-ip.php
4 months ago
class-nfw-database.php
6 months ago
class-nfw-session.php
1 week ago
class-php-session.php
1 year ago
class-plugin-upgrade.php
1 week ago
class_mail.php
3 weeks ago
event_updates.php
9 months ago
firewall.php
4 months ago
fw_centlog.php
1 week ago
fw_fileguard.php
4 months ago
fw_livelog.php
1 year ago
help.php
3 weeks ago
helpers.php
1 week ago
i18n-extra.php
3 weeks ago
i18n.php
1 year ago
index.html
13 years ago
init_update.php
1 year ago
install.php
1 year ago
install_default.php
6 months ago
loader.php
6 months ago
mail_template_firewall.php
1 year ago
mail_template_plugin.php
1 month ago
scheduled_tasks.php
3 years ago
settings_dashboard.php
1 month ago
settings_dashboard_about.php
3 weeks ago
settings_dashboard_statistics.php
1 month ago
settings_event_notifications.php
1 month ago
settings_events.php
1 month ago
settings_firewall_options.php
1 month ago
settings_firewall_policies.php
1 week ago
settings_login_protection.php
1 month ago
settings_logs.php
1 month ago
settings_logs_firewall_log.php
3 weeks ago
settings_logs_live_log.php
1 month ago
settings_monitoring.php
3 weeks ago
settings_monitoring_file_check.php
1 month ago
settings_monitoring_file_guard.php
1 month ago
settings_network.php
1 month ago
settings_security_rules.php
1 month ago
settings_security_rules_editor.php
1 month ago
settings_security_rules_update.php
1 week ago
sign.pub
7 years ago
thickbox.php
4 years ago
widget.php
3 years ago
wpplus.php
3 months ago
class-ip.php
85 lines
| 1 | <?php |
| 2 | /* |
| 3 | +=====================================================================+ |
| 4 | | _ _ _ _ _____ _ _ _ | |
| 5 | | | \ | (_)_ __ (_) __ _| ___(_)_ __ _____ ____ _| | | | |
| 6 | | | \| | | '_ \ | |/ _` | |_ | | '__/ _ \ \ /\ / / _` | | | | |
| 7 | | | |\ | | | | || | (_| | _| | | | | __/\ V V / (_| | | | | |
| 8 | | |_| \_|_|_| |_|/ |\__,_|_| |_|_| \___| \_/\_/ \__,_|_|_| | |
| 9 | | |__/ | |
| 10 | | (c) NinTechNet Limited ~ https://nintechnet.com/ | |
| 11 | +=====================================================================+ |
| 12 | */ |
| 13 | |
| 14 | if ( class_exists('NinjaFirewall_IP') ) { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | class NinjaFirewall_IP { |
| 19 | |
| 20 | /** |
| 21 | * Return an IP address and its type (public/private). |
| 22 | * $nfw_options is only used here for compatibility with the WP+ version. |
| 23 | */ |
| 24 | public static function check_ip( $nfw_options ) { |
| 25 | /** |
| 26 | * It could have been defined by the firewall, if already loaded. |
| 27 | */ |
| 28 | if ( defined('NFW_REMOTE_ADDR') ) { |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Some command line cron jobs may return an 'Undefined array key REMOTE_ADDR' warning. |
| 34 | */ |
| 35 | if (! isset( $_SERVER['REMOTE_ADDR'] ) ) { |
| 36 | $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; |
| 37 | } |
| 38 | |
| 39 | if ( strpos( $_SERVER['REMOTE_ADDR'], ',') !== false ) { |
| 40 | $matches = array_map('trim', @ explode(',', $_SERVER['REMOTE_ADDR'] ) ); |
| 41 | foreach( $matches as $match ) { |
| 42 | if ( filter_var( $match, FILTER_VALIDATE_IP ) ) { |
| 43 | define('NFW_REMOTE_ADDR', $match ); |
| 44 | break; |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | if (! defined('NFW_REMOTE_ADDR') ) { |
| 49 | /** |
| 50 | * Last hope. |
| 51 | */ |
| 52 | define('NFW_REMOTE_ADDR', htmlspecialchars( $_SERVER['REMOTE_ADDR'] ) ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Check if it's a private address. |
| 57 | */ |
| 58 | if (filter_var( NFW_REMOTE_ADDR, FILTER_VALIDATE_IP, |
| 59 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) { |
| 60 | |
| 61 | define('NFW_REMOTE_ADDR_PRIVATE', false ); |
| 62 | } else { |
| 63 | define('NFW_REMOTE_ADDR_PRIVATE', true ); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | |
| 68 | /** |
| 69 | * Anonymize an IP address by hidding it last 3 characters, unless it's a prive IP. |
| 70 | */ |
| 71 | public static function anonymize_ip( $ip, $nfw_options ) { |
| 72 | |
| 73 | if (! empty( $nfw_options['anon_ip'] ) && NFW_REMOTE_ADDR_PRIVATE === false ) { |
| 74 | |
| 75 | return substr( $ip, 0, -3 ) .'xxx'; |
| 76 | } |
| 77 | |
| 78 | return $ip; |
| 79 | } |
| 80 | |
| 81 | } |
| 82 | |
| 83 | // ===================================================================== |
| 84 | // EOF |
| 85 |