PluginProbe
The WP Remote WordPress Plugin / 5.16
The WP Remote WordPress Plugin v5.16
6.72 6.69 6.65 6.62 6.48 6.47 4.87 4.97 5.05 5.09 5.16 5.22 5.24 5.25 5.38 5.41 5.42 5.45 5.47 5.53 5.56 5.65 5.68 5.72 5.73 All 53 releases
wpremote / protect / base.php

base.php in The WP Remote WordPress Plugin 5.16, at protect/base.php

114 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (! (defined('ABSPATH') || defined('MCDATAPATH')) ) exit;
3 if (!class_exists('BVProtectBase')) :
4
5 class BVProtectBase {
6 public static function getIP($ipHeader) {
7 $ip = '127.0.0.1';
8 if ($ipHeader && is_array($ipHeader)) {
9 if (array_key_exists($ipHeader['hdr'], $_SERVER)) {
10 $_ips = preg_split("/(,| |\t)/", $_SERVER[$ipHeader['hdr']]);
11 if (array_key_exists(intval($ipHeader['pos']), $_ips)) {
12 $ip = $_ips[intval($ipHeader['pos'])];
13 }
14 }
15 } else if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
16 $ip = $_SERVER['REMOTE_ADDR'];
17 }
18
19 $ip = trim($ip);
20 if (WPRHelper::safePregMatch('/^\[([0-9a-fA-F:]+)\](:[0-9]+)$/', $ip, $matches)) {
21 $ip = $matches[1];
22 } elseif (WPRHelper::safePregMatch('/^([0-9.]+)(:[0-9]+)$/', $ip, $matches)) {
23 $ip = $matches[1];
24 }
25
26 return $ip;
27 }
28
29 public static function isIPv6($ip) {
30 return (false === filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) ? false : true;
31 }
32
33 public static function hasIPv6Support() {
34 return defined('AF_INET6');
35 }
36
37 public static function isValidIP($ip) {
38 return filter_var($ip, FILTER_VALIDATE_IP) !== false;
39 }
40
41 public static function bvInetPton($ip) {
42 $pton = self::isValidIP($ip) ? (self::hasIPv6Support() ? inet_pton($ip) : self::_bvInetPton($ip)) : false;
43 return $pton;
44 }
45
46 public static function _bvInetPton($ip) {
47 if (WPRHelper::safePregMatch('/^(?:\d{1,3}(?:\.|$)){4}/', $ip)) {
48 $octets = explode('.', $ip);
49 $bin = chr($octets[0]) . chr($octets[1]) . chr($octets[2]) . chr($octets[3]);
50 return $bin;
51 }
52
53 if (WPRHelper::safePregMatch('/^((?:[\da-f]{1,4}(?::|)){0,8})(::)?((?:[\da-f]{1,4}(?::|)){0,8})$/i', $ip)) {
54 if ($ip === '::') {
55 return "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
56 }
57 $colon_count = substr_count($ip, ':');
58 $dbl_colon_pos = strpos($ip, '::');
59 if ($dbl_colon_pos !== false) {
60 $ip = str_replace('::', str_repeat(':0000',
61 (($dbl_colon_pos === 0 || $dbl_colon_pos === strlen($ip) - 2) ? 9 : 8) - $colon_count) . ':', $ip);
62 $ip = trim($ip, ':');
63 }
64
65 $ip_groups = explode(':', $ip);
66 $ipv6_bin = '';
67 foreach ($ip_groups as $ip_group) {
68 $ipv6_bin .= pack('H*', str_pad($ip_group, 4, '0', STR_PAD_LEFT));
69 }
70
71 return strlen($ipv6_bin) === 16 ? $ipv6_bin : false;
72 }
73
74 if (WPRHelper::safePregMatch('/^(?:\:(?:\:0{1,4}){0,4}\:|(?:0{1,4}\:){5})ffff\:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/i', $ip, $matches)) {
75 $octets = explode('.', $matches[1]);
76 return chr($octets[0]) . chr($octets[1]) . chr($octets[2]) . chr($octets[3]);
77 }
78
79 return false;
80 }
81
82 public static function isIPInRange($start_ip_range, $end_ip_range, $ip) {
83 $bin_ip = null;
84 if ($ip) {
85 $bin_ip = self::bvInetPton($ip);
86 }
87 if ($bin_ip && $bin_ip >= self::bvInetPton($start_ip_range)
88 && $bin_ip <= self::bvInetPton($end_ip_range)) {
89 return true;
90 }
91 return false;
92 }
93
94 public static function isPrivateIP($ip) {
95 $private_ip_ranges = array(
96 array("10.0.0.0", "10.255.255.255"),
97 array("172.16.0.0", "172.31.255.255"),
98 array("192.168.0.0", "192.168.255.255"),
99 array("127.0.0.1", "127.255.255.255"),
100 array("::1","::1"),
101 array("fc00::","fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
102 );
103
104 $result = false;
105 foreach ($private_ip_ranges as $ip_range) {
106 $result = self::isIPInRange($ip_range[0], $ip_range[1], $ip);
107 if($result) {
108 return $result;
109 }
110 }
111 return $result;
112 }
113 }
114 endif;