PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.1
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
← All changes | includes/Core/Util/IpTool.php +131 -120 2.03.3.1 View file →
@@ -5,9 +5,10 @@
5 5 */
6 6
7 7 namespace BitCode\BitForm\Core\Util;
8 8
9 -final class IpTool {
9 +final class IpTool
10 +{
10 11 /**
11 12 * Check ip address
12 13 *
13 14 * @return string IP address of current visitor
@@ -16,9 +17,10 @@
16 17 /**
17 18 *
18 19 ipaddress converted to number digit
19 20 */
20 - private static function ip2Number($ipAdr) {
21 + private static function ip2Number($ipAdr)
22 + {
21 23 $ipTobytes = @inet_pton($ipAdr);
22 24
23 25 if (!$ipTobytes) {
24 26 return false;
@@ -31,9 +33,10 @@
31 33
32 34 return base_convert(ltrim($number, '0'), 2, 10);
33 35 }
34 36
35 - private static function validateIpAddress($ip) {
37 + private static function validateIpAddress($ip)
38 + {
36 39 $ipv4Pattern = '/(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}/';
37 40 $ipv6Pattern = '/([A-Fa-f0-9]{1,4})\:([A-Fa-f0-9]{1,4})\:([A-Fa-f0-9]{1,4})\:([A-Fa-f0-9]{1,4})\:([A-Fa-f0-9]{1,4})\:([A-Fa-f0-9]{1,4})\:([A-Fa-f0-9]{1,4})\:([A-Fa-f0-9]{1,4})/';
38 41
39 42 if (preg_match($ipv4Pattern, $ip, $patternMatchIp)) {
@@ -44,9 +47,10 @@
44 47
45 48 return $ip;
46 49 }
47 50
48 - private static function _checkIP() {
51 + private static function _checkIP()
52 + {
49 53 if (getenv('HTTP_CLIENT_IP')) {
50 54 $ip = getenv('HTTP_CLIENT_IP');
51 55 } elseif (getenv('HTTP_X_FORWARDED_FOR')) {
52 56 $ip = getenv('HTTP_X_FORWARDED_FOR');
@@ -56,9 +60,9 @@
56 60 $ip = getenv('HTTP_FORWARDED_FOR');
57 61 } elseif (getenv('HTTP_FORWARDED')) {
58 62 $ip = getenv('HTTP_FORWARDED');
59 63 } else {
60 - $ip = $_SERVER['REMOTE_ADDR'];
64 + $ip = isset($_SERVER['REMOTE_ADDR']) ? sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])) : '';
61 65 }
62 66 return IpTool::validateIpAddress($ip);
63 67 }
64 68
@@ -66,11 +70,12 @@
66 70 * Check device info
67 71 *
68 72 * @return void
69 73 */
70 - private static function _checkDevice() {
74 + private static function _checkDevice()
75 + {
71 76 if (isset($_SERVER, $_SERVER['HTTP_USER_AGENT'])) {
72 - $user_agent = $_SERVER['HTTP_USER_AGENT'];
77 + $user_agent = sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT']));
73 78 } else {
74 79 $user_agent = '';
75 80 }
76 81 return IpTool::_getBrowserName($user_agent) . '|' . IpTool::_getOS($user_agent);
@@ -84,15 +89,16 @@
84 89 * @param string $user_agent $_SERVER['HTTP_USER_AGENT']
85 90 *
86 91 * @return void
87 92 */
88 - private static function _getBrowserName($user_agent) {
93 + private static function _getBrowserName($user_agent)
94 + {
89 95 // Make case insensitive.
90 96 $t = strtolower($user_agent);
91 97
92 98 // If the string *starts* with the string, strpos returns 0 (i.e., FALSE). Do a ghetto hack and start with a space.
93 99 // "[strpos()] may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE."
94 - // http://php.net/manual/en/function.strpos.php
100 + // http://php.net/manual/en/function.strpos.php
95 101 $t = ' ' . $t;
96 102
97 103 // Humans / Regular Users
98 104 if (strpos($t, 'opera') || strpos($t, 'opr/')) {
@@ -162,132 +168,134 @@
162 168 * @link https://stackoverflow.com/questions/18070154/get-operating-system-info
163 169 *
164 170 * @return void
165 171 */
166 - private static function _getOS($user_agent) {
167 - $ros[] = ['Windows XP', 'Windows XP'];
168 - $ros[] = ['Windows NT 5.1|Windows NT5.1', 'Windows XP'];
169 - $ros[] = ['Windows 2000', 'Windows 2000'];
170 - $ros[] = ['Windows NT 5.0', 'Windows 2000'];
171 - $ros[] = ['Windows NT 4.0|WinNT4.0', 'Windows NT'];
172 - $ros[] = ['Windows NT 5.2', 'Windows Server 2003'];
173 - $ros[] = ['Windows NT 6.0', 'Windows Vista'];
174 - $ros[] = ['Windows NT 7.0', 'Windows 7'];
175 - $ros[] = ['Windows CE', 'Windows CE'];
176 - $ros[] = [
177 - '(media center pc).([0-9]{1,2}\.[0-9]{1,2})',
178 - 'Windows Media Center',
179 - ];
180 - $ros[] = ['(win)([0-9]{1,2}\.[0-9x]{1,2})', 'Windows'];
181 - $ros[] = ['(win)([0-9]{2})', 'Windows'];
182 - $ros[] = ['(windows)([0-9x]{2})', 'Windows'];
172 + private static function _getOS($user_agent)
173 + {
174 + $ros[] = ['Windows XP', 'Windows XP', false];
175 + $ros[] = ['Windows NT 5.1|Windows NT5.1', 'Windows XP', true];
176 + $ros[] = ['Windows 2000', 'Windows 2000', false];
177 + $ros[] = ['Windows NT 5.0', 'Windows 2000', false];
178 + $ros[] = ['Windows NT 4.0|WinNT4.0', 'Windows NT', true];
179 + $ros[] = ['Windows NT 5.2', 'Windows Server 2003', false];
180 + $ros[] = ['Windows NT 6.0', 'Windows Vista', false];
181 + $ros[] = ['Windows NT 7.0', 'Windows 7', false];
182 + $ros[] = ['Windows CE', 'Windows CE', false];
183 + $ros[] = ['(media center pc).([0-9]{1,2}\.[0-9]{1,2})', 'Windows Media Center', true];
184 + $ros[] = ['(win)([0-9]{1,2}\.[0-9x]{1,2})', 'Windows', true];
185 + $ros[] = ['(win)([0-9]{2})', 'Windows', true];
186 + $ros[] = ['(windows)([0-9x]{2})', 'Windows', true];
183 187 // Doesn't seem like these are necessary...not totally sure though..
184 188 //$ros[] = array('(winnt)([0-9]{1,2}\.[0-9]{1,2}){0,1}', 'Windows NT');
185 189 //$ros[] = array('(windows nt)(([0-9]{1,2}\.[0-9]{1,2}){0,1})', 'Windows NT'); // fix by bg
186 - $ros[] = ['Windows ME', 'Windows ME'];
187 - $ros[] = ['Win 9x 4.90', 'Windows ME'];
188 - $ros[] = ['Windows 98|Win98', 'Windows 98'];
189 - $ros[] = ['Windows 95', 'Windows 95'];
190 - $ros[] = ['(windows)([0-9]{1,2}\.[0-9]{1,2})', 'Windows'];
191 - $ros[] = ['win32', 'Windows'];
192 - $ros[] = ['(java)([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2})', 'Java'];
193 - $ros[] = ['(Solaris)([0-9]{1,2}\.[0-9x]{1,2}){0,1}', 'Solaris'];
194 - $ros[] = ['dos x86', 'DOS'];
195 - $ros[] = ['unix', 'Unix'];
190 + $ros[] = ['Windows ME', 'Windows ME', false];
191 + $ros[] = ['Win 9x 4.90', 'Windows ME', false];
192 + $ros[] = ['Windows 98|Win98', 'Windows 98', true];
193 + $ros[] = ['Windows 95', 'Windows 95', false];
194 + $ros[] = ['(windows)([0-9]{1,2}\.[0-9]{1,2})', 'Windows', true];
195 + $ros[] = ['win32', 'Windows', false];
196 + $ros[] = ['(java)([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2})', 'Java', true];
197 + $ros[] = ['(Solaris)([0-9]{1,2}\.[0-9x]{1,2}){0,1}', 'Solaris', true];
198 + $ros[] = ['dos x86', 'DOS', false];
199 + $ros[] = ['unix', 'Unix', false];
196 200 //Android
197 - $ros[] = ['SM', 'Samsung'];
198 - $ros[] = ['HTC', 'HTC'];
199 - $ros[] = ['LG', 'LG'];
200 - $ros[] = ['Microsoft', 'Microsoft'];
201 - $ros[] = ['Pixel', 'Pixel'];
202 - $ros[] = ['MI', 'Xiaomi'];
203 - $ros[] = ['Xiaomi', 'Xiaomi'];
204 - $ros[] = ['Android', 'Android'];
205 - $ros[] = ['android', 'Android'];
201 + $ros[] = ['SM', 'Samsung', false];
202 + $ros[] = ['HTC', 'HTC', false];
203 + $ros[] = ['LG', 'LG', false];
204 + $ros[] = ['Microsoft', 'Microsoft', false];
205 + $ros[] = ['Pixel', 'Pixel', false];
206 + $ros[] = ['MI', 'Xiaomi', false];
207 + $ros[] = ['Xiaomi', 'Xiaomi', false];
208 + $ros[] = ['Android', 'Android', false];
209 + $ros[] = ['android', 'Android', false];
206 210
207 211 //iPhone
208 - $ros[] = ['iPhone', 'iPhone'];
212 + $ros[] = ['iPhone', 'iPhone', false];
209 213
210 - $ros[] = ['Mac OS X', 'Mac OS X'];
211 - $ros[] = ['Mac OS X Puma', 'Mac OS X 10.1[^0-9]'];
212 - $ros[] = ['Mac_PowerPC', 'Macintosh PowerPC'];
213 - $ros[] = ['(mac|Macintosh)', 'Mac OS'];
214 - $ros[] = ['(sunos)([0-9]{1,2}\.[0-9]{1,2}){0,1}', 'SunOS'];
215 - $ros[] = ['(beos)([0-9]{1,2}\.[0-9]{1,2}){0,1}', 'BeOS'];
216 - $ros[] = ['(risc os)([0-9]{1,2}\.[0-9]{1,2})', 'RISC OS'];
217 - $ros[] = ['os\/2', 'OS/2'];
218 - $ros[] = ['freebsd', 'FreeBSD'];
219 - $ros[] = ['openbsd', 'OpenBSD'];
220 - $ros[] = ['netbsd', 'NetBSD'];
221 - $ros[] = ['irix', 'IRIX'];
222 - $ros[] = ['plan9', 'Plan9'];
223 - $ros[] = ['osf', 'OSF'];
224 - $ros[] = ['aix', 'AIX'];
225 - $ros[] = ['GNU Hurd', 'GNU Hurd'];
226 - $ros[] = ['(fedora)', 'Linux - Fedora'];
227 - $ros[] = ['(kubuntu)', 'Linux - Kubuntu'];
228 - $ros[] = ['(ubuntu)', 'Linux - Ubuntu'];
229 - $ros[] = ['(debian)', 'Linux - Debian'];
230 - $ros[] = ['(CentOS)', 'Linux - CentOS'];
231 - $ros[] = [
232 - '(Mandriva).([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?)',
233 - 'Linux - Mandriva',
234 - ];
235 - $ros[] = [
236 - '(SUSE).([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?)',
237 - 'Linux - SUSE',
238 - ];
239 - $ros[] = ['(Dropline)', 'Linux - Slackware (Dropline GNOME)'];
240 - $ros[] = ['(ASPLinux)', 'Linux - ASPLinux'];
241 - $ros[] = ['(Red Hat)', 'Linux - Red Hat'];
214 + $ros[] = ['Mac OS X', 'Mac OS X', false];
215 + $ros[] = ['Mac OS X Puma', 'Mac OS X 10.1[^0-9]', true];
216 + $ros[] = ['Mac_PowerPC', 'Macintosh PowerPC', false];
217 + $ros[] = ['(mac|Macintosh)', 'Mac OS', true];
218 + $ros[] = ['(sunos)([0-9]{1,2}\.[0-9]{1,2}){0,1}', 'SunOS', true];
219 + $ros[] = ['(beos)([0-9]{1,2}\.[0-9]{1,2}){0,1}', 'BeOS', true];
220 + $ros[] = ['(risc os)([0-9]{1,2}\.[0-9]{1,2})', 'RISC OS', true];
221 + $ros[] = ['os\/2', 'OS/2', true];
222 + $ros[] = ['freebsd', 'FreeBSD', false];
223 + $ros[] = ['openbsd', 'OpenBSD', false];
224 + $ros[] = ['netbsd', 'NetBSD', false];
225 + $ros[] = ['irix', 'IRIX', false];
226 + $ros[] = ['plan9', 'Plan9', false];
227 + $ros[] = ['osf', 'OSF', false];
228 + $ros[] = ['aix', 'AIX', false];
229 + $ros[] = ['GNU Hurd', 'GNU Hurd', false];
230 + $ros[] = ['(fedora)', 'Linux - Fedora', true];
231 + $ros[] = ['(kubuntu)', 'Linux - Kubuntu', true];
232 + $ros[] = ['(ubuntu)', 'Linux - Ubuntu', true];
233 + $ros[] = ['(debian)', 'Linux - Debian', true];
234 + $ros[] = ['(CentOS)', 'Linux - CentOS', true];
235 + $ros[] = ['(Mandriva).([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?)', 'Linux - Mandriva', true];
236 + $ros[] = ['(SUSE).([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?)', 'Linux - SUSE', true];
237 + $ros[] = ['(Dropline)', 'Linux - Slackware (Dropline GNOME)', true];
238 + $ros[] = ['(ASPLinux)', 'Linux - ASPLinux', true];
239 + $ros[] = ['(Red Hat)', 'Linux - Red Hat', true];
242 240 // Loads of Linux machines will be detected as unix.
243 241 // Actually, all of the linux machines I've checked have the 'X11' in the User Agent.
244 242 //$ros[] = array('X11', 'Unix');
245 - $ros[] = ['(linux)', 'Linux'];
246 - $ros[] = ['(amigaos)([0-9]{1,2}\.[0-9]{1,2})', 'AmigaOS'];
247 - $ros[] = ['amiga-aweb', 'AmigaOS'];
248 - $ros[] = ['amiga', 'Amiga'];
249 - $ros[] = ['AvantGo', 'PalmOS'];
243 + $ros[] = ['(linux)', 'Linux', true];
244 + $ros[] = ['(amigaos)([0-9]{1,2}\.[0-9]{1,2})', 'AmigaOS', true];
245 + $ros[] = ['amiga-aweb', 'AmigaOS', false];
246 + $ros[] = ['amiga', 'Amiga', false];
247 + $ros[] = ['AvantGo', 'PalmOS', false];
250 248 //$ros[] = array('(Linux)([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3}(rel\.[0-9]{1,2}){0,1}-([0-9]{1,2}) i([0-9]{1})86){1}', 'Linux');
251 249 //$ros[] = array('(Linux)([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3}(rel\.[0-9]{1,2}){0,1} i([0-9]{1}86)){1}', 'Linux');
252 250 //$ros[] = array('(Linux)([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3}(rel\.[0-9]{1,2}){0,1})', 'Linux');
253 - $ros[] = ['[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3})', 'Linux'];
254 - $ros[] = ['(webtv)/([0-9]{1,2}\.[0-9]{1,2})', 'WebTV'];
255 - $ros[] = ['Dreamcast', 'Dreamcast OS'];
256 - $ros[] = ['GetRight', 'Windows'];
257 - $ros[] = ['go!zilla', 'Windows'];
258 - $ros[] = ['gozilla', 'Windows'];
259 - $ros[] = ['gulliver', 'Windows'];
260 - $ros[] = ['ia archiver', 'Windows'];
261 - $ros[] = ['NetPositive', 'Windows'];
262 - $ros[] = ['mass downloader', 'Windows'];
263 - $ros[] = ['microsoft', 'Windows'];
264 - $ros[] = ['offline explorer', 'Windows'];
265 - $ros[] = ['teleport', 'Windows'];
266 - $ros[] = ['web downloader', 'Windows'];
267 - $ros[] = ['webcapture', 'Windows'];
268 - $ros[] = ['webcollage', 'Windows'];
269 - $ros[] = ['webcopier', 'Windows'];
270 - $ros[] = ['webstripper', 'Windows'];
271 - $ros[] = ['webzip', 'Windows'];
272 - $ros[] = ['wget', 'Windows'];
273 - $ros[] = ['Java', 'Unknown'];
274 - $ros[] = ['flashget', 'Windows'];
251 + $ros[] = ['[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3}', 'Linux', true];
252 + $ros[] = ['(webtv)/([0-9]{1,2}\.[0-9]{1,2})', 'WebTV', true];
253 + $ros[] = ['Dreamcast', 'Dreamcast OS', false];
254 + $ros[] = ['GetRight', 'Windows', false];
255 + $ros[] = ['go!zilla', 'Windows', false];
256 + $ros[] = ['gozilla', 'Windows', false];
257 + $ros[] = ['gulliver', 'Windows', false];
258 + $ros[] = ['ia archiver', 'Windows', false];
259 + $ros[] = ['NetPositive', 'Windows', false];
260 + $ros[] = ['mass downloader', 'Windows', false];
261 + $ros[] = ['microsoft', 'Windows', false];
262 + $ros[] = ['offline explorer', 'Windows', false];
263 + $ros[] = ['teleport', 'Windows', false];
264 + $ros[] = ['web downloader', 'Windows', false];
265 + $ros[] = ['webcapture', 'Windows', false];
266 + $ros[] = ['webcollage', 'Windows', false];
267 + $ros[] = ['webcopier', 'Windows', false];
268 + $ros[] = ['webstripper', 'Windows', false];
269 + $ros[] = ['webzip', 'Windows', false];
270 + $ros[] = ['wget', 'Windows', false];
271 + $ros[] = ['Java', 'Unknown', false];
272 + $ros[] = ['flashget', 'Windows', false];
275 273 // delete next line if the script show not the right OS
276 274 //$ros[] = array('(PHP)/([0-9]{1,2}.[0-9]{1,2})', 'PHP');
277 - $ros[] = ['MS FrontPage', 'Windows'];
278 - $ros[] = ['(msproxy)/([0-9]{1,2}.[0-9]{1,2})', 'Windows'];
279 - $ros[] = ['(msie)([0-9]{1,2}.[0-9]{1,2})', 'Windows'];
280 - $ros[] = ['libwww-perl', 'Unix'];
281 - $ros[] = ['UP.Browser', 'Windows CE'];
282 - $ros[] = ['NetAnts', 'Windows'];
283 - $ros[] = ['Android', 'Android'];
275 + $ros[] = ['MS FrontPage', 'Windows', false];
276 + $ros[] = ['(msproxy)/([0-9]{1,2}\.[0-9]{1,2})', 'Windows', true];
277 + $ros[] = ['(msie)([0-9]{1,2}\.[0-9]{1,2})', 'Windows', true];
278 + $ros[] = ['libwww-perl', 'Unix', false];
279 + $ros[] = ['UP.Browser', 'Windows CE', false];
280 + $ros[] = ['NetAnts', 'Windows', false];
281 + $ros[] = ['Android', 'Android', false];
284 282 $file = count($ros);
285 283 $os = '';
286 284 for ($n = 0; $n < $file; $n++) {
287 - if (@preg_match('/' . $ros[$n][0] . '/i', $user_agent)) {
288 - $os = @$ros[$n][1];
289 - break;
285 + $isRegex = isset($ros[$n][2]) && true === $ros[$n][2];
286 + $pattern = $ros[$n][0];
287 +
288 + if ($isRegex) {
289 + if (@preg_match('/' . $pattern . '/i', $user_agent)) {
290 + $os = $ros[$n][1];
291 + break;
292 + }
293 + } else {
294 + if (false !== stripos($user_agent, $pattern)) {
295 + $os = $ros[$n][1];
296 + break;
297 + }
290 298 }
291 299 }
292 300 return trim($os);
293 301 }
@@ -294,11 +302,12 @@
294 302
295 303 /**
296 304 * Set user details ip,cdevice, user_id, user's visited page, current mysql formatted time
297 305 *
298 - * @return Array of user details
306 + * @return array of user details
299 307 */
300 - private static function _setUserDetail() {
308 + private static function _setUserDetail()
309 + {
301 310 $referer = wp_get_referer();
302 311 $user_details['ip'] = IpTool::ip2Number(IpTool::_checkIP());
303 312 $user_details['device'] = IpTool::_checkDevice();
304 313 $user_details['id'] = get_current_user_id();
@@ -310,11 +319,12 @@
310 319
311 320 /**
312 321 * Provide user details
313 322 *
314 - * @return _setUserDetail user details array
323 + * @return array user details array
315 324 */
316 - public static function getUserDetail() {
325 + public static function getUserDetail()
326 + {
317 327 return IpTool::_setUserDetail();
318 328 }
319 329
320 330 /**
@@ -321,8 +331,9 @@
321 331 * Provide user IP address
322 332 *
323 333 * @return ip
324 334 */
325 - public static function getIP() {
335 + public static function getIP()
336 + {
326 337 return IpTool::_checkIP();
327 338 }
328 339 }