| Server IP : 39.106.62.82 / Your IP : 216.73.216.110 Web Server : nginx/1.14.1 System : Linux iz2ze1m0zmp2dk5c3j5ap5z 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /webdata/gohomesh.com/wp-content/plugins/wp-statistics/includes/ |
Upload File : |
<?php
namespace WP_STATISTICS;
use IPTools\Range;
class IP
{
/**
* Default User IP
*
* @var string
*/
public static $default_ip = '127.0.0.1';
/**
* Default Private SubNets
*
* @var array
*/
public static $private_SubNets = array('10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16', '127.0.0.1/24', 'fc00::/7');
/**
* List Of Common $_SERVER for get Users IP
*
* @var array
*/
public static $ip_methods_server = array('REMOTE_ADDR', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'HTTP_X_REAL_IP', 'HTTP_X_CLUSTER_CLIENT_IP');
/**
* Default $_SERVER for Get User Real IP
*
* @var string
*/
public static $default_ip_method = 'REMOTE_ADDR';
/**
* Hash IP Prefix
*
* @var string
*/
public static $hash_ip_prefix = '#hash#';
/**
* Returns the current IP address of the remote client.
*
* @return bool|string
*/
public static function getIP()
{
// Set Default
$ip = false;
// Get User IP Methods
$ip_method = self::getIPMethod();
// Check isset $_SERVER
if (isset($_SERVER[$ip_method])) {
$ip = sanitize_text_field($_SERVER[$ip_method]);
}
/**
* This Filter Used For Custom $_SERVER String
* @see https://wp-statistics.com/sanitize-user-ip/
*/
$ip = apply_filters('wp_statistics_sanitize_user_ip', $ip);
// Sanitize For HTTP_X_FORWARDED
foreach (explode(',', $ip) as $user_ip) {
$user_ip = trim($user_ip);
if (self::isIP($user_ip) != false) {
$ip = $user_ip;
}
}
// If no valid ip address has been found, use default ip.
if (false === $ip) {
$ip = self::$default_ip;
}
return apply_filters('wp_statistics_user_ip', sanitize_text_field($ip));
}
/**
* Generate hash string
*
* @param bool $ip
* @return bool
*/
public static function getHashIP($ip = false)
{
// Check Enabled Options
if (Option::get('hash_ips') == true) {
return apply_filters('wp_statistics_hash_ip', self::$hash_ip_prefix . sha1(($ip === false ? self::getIP() : $ip) . (UserAgent::getHttpUserAgent() == '' ? 'Unknown' : UserAgent::getHttpUserAgent())));
}
return false;
}
/**
* Check IP is Hashed
*
* @param $ip
* @return bool
*/
public static function IsHashIP($ip)
{
return (substr($ip, 0, strlen(self::$hash_ip_prefix)) == self::$hash_ip_prefix);
}
/**
* Store User IP To Database
*/
public static function getStoreIP()
{
//Get User ip
$user_ip = self::getIP();
// use 127.0.0.1 If no valid ip address has been found.
if (false === $user_ip) {
return self::$default_ip;
}
/**
* If the anonymize IP is enabled because of the data privacy & GDPR.
* @example 888.888.888.888 -> 888.888.888.000
*/
if (Option::get('anonymize_ips') == true) {
$user_ip = substr($user_ip, 0, strrpos($user_ip, '.')) . '.0';
}
/**
* If the hash IP is enabled because of the data privacy & GDPR.
* @example 888.888.888.888 -> #hash#e7b398f96b14993b571215e36b41850c65f39b1a
*/
if (self::getHashIP()) {
$user_ip = self::getHashIP($user_ip);
}
return sanitize_text_field($user_ip);
}
/**
* Check IP Has The Custom IP Range List
*
* @param $ip
* @param array $range
* @return bool
* @throws \Exception
*/
public static function CheckIPRange($range = array(), $ip = false)
{
// Get User IP
$ip = ($ip === false ? IP::getIP() : $ip);
// Get Range OF This IP
try {
$ip = new \IPTools\IP($ip);
} catch (\Exception $e) {
\WP_Statistics::log($e->getMessage());
$ip = new \IPTools\IP(self::$default_ip);
}
// Check List
foreach ($range as $list) {
try {
$contains_ip = Range::parse($list)->contains($ip);
} catch (\Exception $e) {
\WP_Statistics::log($e->getMessage());
$contains_ip = false;
}
if ($contains_ip) {
return true;
}
}
return false;
}
/**
* Check Validation IP
*
* @param $ip
* @return bool
*/
public static function isIP($ip)
{
return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
}
/**
* what is Method $_SERVER for get User Real IP
*/
public static function getIPMethod()
{
$ip_method = Option::get('ip_method');
return ($ip_method != false ? $ip_method : self::$default_ip_method);
}
/**
* Check IP contain Special Character
*
* @param $ip
* @return bool
*/
public static function check_sanitize_ip($ip)
{
$preg = preg_replace('/[^0-9- .:]/', '', $ip);
return $preg == $ip;
}
/**
* Update All Hash String For Hash IP
*/
public static function Update_HashIP_Visitor()
{
global $wpdb;
// Get the rows from the Visitors table.
$result = $wpdb->get_results("SELECT DISTINCT ip FROM " . DB::table('visitor'));
foreach ($result as $row) {
if (IP::IsHashIP($row->ip)) {
$wpdb->update(
DB::table('visitor'),
array('ip' => IP::$hash_ip_prefix . sha1($row->ip . Helper::random_string()),),
array('ip' => $row->ip)
);
}
}
}
}