diff --git a/foxxey/config.php b/foxxey/config.php index 5daab98..7dc9a47 100644 --- a/foxxey/config.php +++ b/foxxey/config.php @@ -42,9 +42,8 @@ 'debugStartUpSound' => false, 'antiBruteDebug' => false, 'randTextsDebug' => false, - 'debugStartUpSound' => false, - /* AUTHORISATION */ + /* AUTHORISATION Modules */ 'checkHWID' => true, 'geoIPcheck' => true, 'useAntiBrute' => true, diff --git a/foxxey/scripts/functions.class.php b/foxxey/scripts/functions.class.php index 313bdd9..0f4733d 100644 --- a/foxxey/scripts/functions.class.php +++ b/foxxey/scripts/functions.class.php @@ -11,7 +11,7 @@ ----------------------------------------------------- File: functions,class.php ----------------------------------------------------- - Version: 0.1.4.1 Experimental + Version: 0.1.4.2 Experimental ----------------------------------------------------- Usage: A bunch of functions ===================================================== @@ -51,21 +51,6 @@ public function getUserData($login,$data){ } return $answer; } - - public function passwordReHash($pass, $realPass, $realName){ - global $config; - //$db = new db($config['db_user'],$config['db_pass'],$config['db_database']); - if (password_needs_rehash($realPass, PASSWORD_DEFAULT)) { - session_regenerate_id(); - $this->realPass = password_hash($this->pass, PASSWORD_DEFAULT); - $new_pass_hash = 'password='.$this->db->safesql($realPass).', '; - } else { - $new_pass_hash = ''; - } - - $hash = functions::generateLoginHash(); - $this->db->run("UPDATE LOW_PRIORITY dle_users SET ".$new_pass_hash." hash='".$hash."', lastdate='".CURRENT_TIME."' WHERE name='".$realName."'"); - } /* STATIC FUNCTIONS (NO DB NEEDED)*/ @@ -85,30 +70,50 @@ static function generateLoginHash(){ return $hash; } + public static function passwordReHash($pass, $realPass, $realName){ + global $config; + $db = new db($config['db_user'],$config['db_pass'],$config['db_database']); + if (password_needs_rehash($realPass, PASSWORD_DEFAULT)) { + session_regenerate_id(); + $this->realPass = password_hash($this->pass, PASSWORD_DEFAULT); + $new_pass_hash = 'password='.$db->safesql($realPass).', '; + } else { + $new_pass_hash = ''; + } + + $hash = functions::generateLoginHash(); + $db->run("UPDATE LOW_PRIORITY dle_users SET ".$new_pass_hash." hash='".$hash."', lastdate='".CURRENT_TIME."' WHERE name='".$realName."'"); + } + public static function includeModules($dirInclude, $debug = false){ $count = 1; + $IncludingText = ''; $dir = opendir($dirInclude); if($debug === true){ - echo '
Modules to include:
'; + echo '
Modules to include:
'; } while($file = readdir($dir)){ if($file == '.' || $file == '..'){ continue; } else { if(!is_dir($dirInclude.'/'.$file)) { + if(strpos($file, '-')) { + $moduleName = explode ('-', $file); + $IncludingText = ' SubModule of - '.$moduleName[0]; + } if(strpos($file, 'module') !== false) { require ($dirInclude.'/'.$file); if($debug === true){ - echo "".$count." Including ".$file."
"; + echo "".$count."".$IncludingText." Including ".$file."
"; $count ++; } } else { if($debug === true){ - echo "".$count." ".$file." was not included as not the valid
"; + echo "".$count."".$IncludingText.' '.$file." was not included as not the valid
"; } } } @@ -149,6 +154,18 @@ public static function getUserName(){ return $name; } + public static function wrongHWIDmessage(){ + global $config; + if(class_exists('randTexts')) { + $randTexts = new randTexts('wrongHWID', $config['randTextsDebug']); + $name = $randTexts->textOut(); + } else { + echo '{"message": "Module randTexts not found!", "desc": "Can`t say user how wrong he is!"},'; + $name = 'Incorrect HWID'; + } + return $name; + } + public static function checkTime ($timestamp) { if($timestamp) { switch ($timestamp){ @@ -170,7 +187,7 @@ public static function display_error($error ='No errors', $error_num = 100500, $ $error = htmlspecialchars($error, ENT_QUOTES, 'ISO-8859-1'); $trace = debug_backtrace(); - $level = 0; + $level = 1; if ($trace[1]['function'] == "query" ) $level = 1; $trace[$level]['file'] = str_replace(ROOT_DIR, "", $trace[$level]['file']); @@ -220,9 +237,9 @@ public static function display_error($error ='No errors', $error_num = 100500, $
MySQ: Error! '.$config['webserviceName'].'
MySQL error in file: '.$trace[$level]['file'],' at line '.$trace[$level]['line'].'
-
Error Number: '.$error_num.'
-
The Error returned was: '.$error.'
-
SQL query:
'.$query.'
+
Error Number: '.$error_num.'
+
The Error returned was: '.$error.'
+
SQL query: '.$query.'
diff --git a/foxxey/scripts/modules/authoriseModules/Auth-module_geoIP.class.php b/foxxey/scripts/modules/authoriseModules/Auth-module_geoIP.class.php index af58fa8..2ec31c0 100644 --- a/foxxey/scripts/modules/authoriseModules/Auth-module_geoIP.class.php +++ b/foxxey/scripts/modules/authoriseModules/Auth-module_geoIP.class.php @@ -5,15 +5,15 @@ ----------------------------------------------------- https://Foxesworld.ru/ ----------------------------------------------------- - Copyright (c) 2016-2020 FoxesWorld + Copyright (c) 2016-2021 FoxesWorld ----------------------------------------------------- This code is private ----------------------------------------------------- File: geoIP.class.php ----------------------------------------------------- - Version: 0.0.5 Alpha + Version: 0.1.6 Alpha ----------------------------------------------------- - scanning user's ip + Usage: Scanning user's ip ===================================================== */ if(!defined('Authorisation')) { @@ -25,6 +25,7 @@ class geoPlugin extends Authorise { //the geoPlugin server var $host = 'http://www.geoplugin.net/php.gp?ip={IP}&base_currency={CURRENCY}'; + private static $db; var $currency = 'USD'; var $ip = null; @@ -40,13 +41,15 @@ class geoPlugin extends Authorise { var $currencyCode = null; var $currencySymbol = null; var $currencyConverter = null; + + private static $Logger; /** * geoPlugin constructor. * @param null $ip */ function __construct($ip = null) { - global $_SERVER; + global $_SERVER, $config; if (is_null($ip)) { $ip = $_SERVER['REMOTE_ADDR']; @@ -57,6 +60,8 @@ function __construct($ip = null) { $data = array(); $response = $this->fetch($host); $data = unserialize($response); + geoPlugin::$db = new db($config['db_user'],$config['db_pass'],$config['dbname_launcher']); + geoPlugin::$Logger = new Logger('AuthLog'); $this->ip = $ip; $this->city = $data['geoplugin_city']; @@ -126,19 +131,17 @@ private function nearby($radius=10, $limit=null) { private static function getIP($ip,$ipLocation,$ipRegion,$log=false){ global $config; if($ip){ - $db = new db($config['db_user'],$config['db_pass'],$config['dbname_launcher']); if(!isset($_COOKIE['ipAdded']) && !isset($_SESSION['ipAdded'])){ $query = "SELECT * FROM `ipDatabase` WHERE ip = '$ip'"; - $data = $db->getValue($query); + $data = geoPlugin::$db->getValue($query); if (!isset($data) || $data === false) { - //$date="[".date("d m Y H:i")."] "; if(!$ipLocation){ $ipLocation = 'Ниоткудинск'; } if(!$ipRegion){ $ipRegion = 'Страна дураков'; } - $db->run("INSERT INTO `ipDatabase`(`ipLocation`, `ipRegion`, `ip`) VALUES ('$ipLocation','$ipRegion','$ip')"); + geoPlugin::$db->run("INSERT INTO `ipDatabase`(`ipLocation`, `ipRegion`, `ip`) VALUES ('$ipLocation','$ipRegion','$ip')"); geoPlugin::addCityCount($ipRegion); if($log === true){ echo 'Adding '.$ip.' - '.$ipLocation.'('.$ipRegion.') '.'to IP database'; @@ -165,15 +168,16 @@ private static function getIP($ip,$ipLocation,$ipRegion,$log=false){ private static function addCityCount($city){ global $config; - $db = new db($config['db_user'],$config['db_pass'],$config['dbname_launcher']); $query = "SELECT * FROM ipCity WHERE cityName = '$city'"; - $data = $db->getValue($query); + $data = geoPlugin::$db->getValue($query); if(!isset($data) || $data === false){ + static::$Logger->WriteLine('Adding `'.$city.'` Wow new login city!'); $query = "INSERT INTO `ipCity`(`cityName`) VALUES ('$city')"; } else { + static::$Logger->WriteLine('Oh, another one from `'.$city.'`... Well, I know what to do with you..'); $query = "UPDATE `ipCity` SET `cityCount`= cityCount+1 WHERE cityName = '$city'"; } - $db->run($query); + geoPlugin::$db->run($query); } } \ No newline at end of file diff --git a/foxxey/scripts/modules/authoriseModules/geoIP.class.php b/foxxey/scripts/modules/authoriseModules/geoIP.class.php new file mode 100644 index 0000000..af58fa8 --- /dev/null +++ b/foxxey/scripts/modules/authoriseModules/geoIP.class.php @@ -0,0 +1,179 @@ +host ); + $host = str_replace( '{CURRENCY}', $this->currency, $host ); + $data = array(); + $response = $this->fetch($host); + $data = unserialize($response); + + $this->ip = $ip; + $this->city = $data['geoplugin_city']; + $this->region = $data['geoplugin_region']; + $this->areaCode = $data['geoplugin_areaCode']; + $this->dmaCode = $data['geoplugin_dmaCode']; + $this->countryCode = $data['geoplugin_countryCode']; + $this->countryName = $data['geoplugin_countryName']; + $this->continentCode = $data['geoplugin_continentCode']; + $this->latitude = $data['geoplugin_latitude']; + $this->longitude = $data['geoplugin_longitude']; + $this->currencyCode = $data['geoplugin_currencyCode']; + $this->currencySymbol = $data['geoplugin_currencySymbol']; + $this->currencyConverter = $data['geoplugin_currencyConverter']; + geoPlugin::getIP($this->ip,$this->countryName,$this->city,false); + } + + private function fetch($host) { + if (function_exists('curl_init')) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $host); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_USERAGENT, 'geoPlugin PHP Class v1.0'); + $response = curl_exec($ch); + curl_close ($ch); + } elseif(ini_get('allow_url_fopen')) { + $response = file_get_contents($host, 'r'); + } else { + trigger_error ('geoPlugin class Error: Cannot retrieve data. Either compile PHP with cURL support or enable allow_url_fopen in php.ini ', E_USER_ERROR); + return; + } + + return $response; + } + + private function convert($amount, $float=2, $symbol=true) { + if ( !is_numeric($this->currencyConverter) || $this->currencyConverter == 0 ) { + trigger_error('geoPlugin class Notice: currencyConverter has no value.', E_USER_NOTICE); + return $amount; + } + if ( !is_numeric($amount) ) { + trigger_error ('geoPlugin class Warning: The amount passed to geoPlugin::convert is not numeric.', E_USER_WARNING); + return $amount; + } + if ( $symbol === true ) { + return $this->currencySymbol . round( ($amount * $this->currencyConverter), $float ); + } else { + return round( ($amount * $this->currencyConverter), $float ); + } + } + + private function nearby($radius=10, $limit=null) { + + if ( !is_numeric($this->latitude) || !is_numeric($this->longitude) ) { + trigger_error ('geoPlugin class Warning: Incorrect latitude or longitude values.', E_USER_NOTICE); + return array( array() ); + } + $host = "http://www.geoplugin.net/extras/nearby.gp?lat=" . $this->latitude . "&long=" . $this->longitude . "&radius={$radius}"; + + if ( is_numeric($limit) ) + $host .= "&limit={$limit}"; + + return unserialize( $this->fetch($host) ); + } + + /* DBadding */ + private static function getIP($ip,$ipLocation,$ipRegion,$log=false){ + global $config; + if($ip){ + $db = new db($config['db_user'],$config['db_pass'],$config['dbname_launcher']); + if(!isset($_COOKIE['ipAdded']) && !isset($_SESSION['ipAdded'])){ + $query = "SELECT * FROM `ipDatabase` WHERE ip = '$ip'"; + $data = $db->getValue($query); + if (!isset($data) || $data === false) { + //$date="[".date("d m Y H:i")."] "; + if(!$ipLocation){ + $ipLocation = 'Ниоткудинск'; + } + if(!$ipRegion){ + $ipRegion = 'Страна дураков'; + } + $db->run("INSERT INTO `ipDatabase`(`ipLocation`, `ipRegion`, `ip`) VALUES ('$ipLocation','$ipRegion','$ip')"); + geoPlugin::addCityCount($ipRegion); + if($log === true){ + echo 'Adding '.$ip.' - '.$ipLocation.'('.$ipRegion.') '.'to IP database'; + } + setcookie("ipAdded", $ip, time()+36000); + $_SESSION['ipAdded'] = $ip; + } else { + if($log === true){ + echo 'Cookie was not found but Ip - '.$ip.' is already added in the Database, so get another one cookie! + Thanks for helping us to build server statistics :3'; + setcookie("ipAdded", $ip, time()+36000); + $_SESSION['ipAdded'] = $ip; + } + } + } else { + if($log === true){ + echo 'Cookie was set for ip - '.$_COOKIE['ipAdded']; + } + } + } else { + echo "That can't happen!"; + } + } + + private static function addCityCount($city){ + global $config; + $db = new db($config['db_user'],$config['db_pass'],$config['dbname_launcher']); + $query = "SELECT * FROM ipCity WHERE cityName = '$city'"; + $data = $db->getValue($query); + + if(!isset($data) || $data === false){ + $query = "INSERT INTO `ipCity`(`cityName`) VALUES ('$city')"; + } else { + $query = "UPDATE `ipCity` SET `cityCount`= cityCount+1 WHERE cityName = '$city'"; + } + $db->run($query); + } +} \ No newline at end of file diff --git a/foxxey/scripts/modules/module_authorise.class.php b/foxxey/scripts/modules/module_authorise.class.php index 7b3a429..febe29f 100644 --- a/foxxey/scripts/modules/module_authorise.class.php +++ b/foxxey/scripts/modules/module_authorise.class.php @@ -11,7 +11,7 @@ ----------------------------------------------------- File: authorise.class.php ----------------------------------------------------- - Verssion: 0.1.8.7 Experimental + Verssion: 0.1.9.0 Beta ----------------------------------------------------- Usage: Authorising and using HWID ===================================================== @@ -23,11 +23,6 @@ } else { define('Authorisation', true); } - - /* - * TODO - * - Fix bad code with multi calling DB!!! - */ class Authorise { @@ -94,6 +89,7 @@ public function logIn() { if($config['geoIPcheck'] === true) { if(class_exists('geoPlugin')) { $geoplugin = new geoPlugin(); + $Logger->WriteLine($this->realName.' attemping to log from ['.$geoplugin->countryCode.']'.$geoplugin->countryName .' '.$geoplugin->city.'...'); } else { echo '{"message": "Module geoPlugin not found!", "desc": "Can`t get user login location!"},'; } @@ -131,14 +127,15 @@ public function logIn() { $this->HWIDstatus = 'true'; echo '{"message": "Module HWID not found!", "desc": "Can`t check user`s HWID validity!"},'; } + } else { + $this->HWIDstatus = 'true'; + $HWIDuser = $this->login; } //============== if($this->HWIDstatus === 'true'){ //If HWID is correct $Logger->WriteLine('Successful authorisation for '.$HWIDuser.' with the correct HWID'); - /* ISSUE!!! VAR ASSIGNMENT AGAIN! */ - $this->webSiteFunc = new functions($config['db_user'], $config['db_pass'], $config['db_database'], $config['db_host']); - $this->webSiteFunc->passwordReHash($this->pass, $this->realPass, $this->realName); + functions::passwordReHash($this->pass, $this->realPass, $this->realName); //GETTING PERSONAL DATA $this->fullname = json_decode($this->webSiteFunc->getUserData($this->login, 'fullname')) -> fullname ?? functions::getUserName(); @@ -174,7 +171,11 @@ public function logIn() { die('{"login": "'.$this->login.'", "fullName":"'.$this->fullname.'", "regDate": '.$this->regDate.', "userGroup": '.$this->userGroup.', "balance": '.$units.', "hardwareId": '.$this->HWIDstatus.'}'); } else { $Logger->WriteLine('Incorrect HWID for '.$this->login.' IP is - '.REMOTE_IP.' Bruted by '.$HWIDuser); - $hardwareCheck->renewHWID($this->realMail, REMOTE_IP, $this->login, $this->HWID); + if($config['checkHWID'] === true) { + if(class_exists('HWID')) { + $hardwareCheck->renewHWID($this->realMail, REMOTE_IP, $this->login, $this->HWID); + } + } if(class_exists('randTexts')) { $this->randTexts = new randTexts('wrongHWID'); $this->HWIDerrorMessage = $this->randTexts->textOut(); diff --git a/foxxey/scripts/modules/module_logger.class.php b/foxxey/scripts/modules/module_logger.class.php index b785036..777bc9f 100644 --- a/foxxey/scripts/modules/module_logger.class.php +++ b/foxxey/scripts/modules/module_logger.class.php @@ -11,7 +11,7 @@ ----------------------------------------------------- File: module_logger.class.php ----------------------------------------------------- - Verssion: 0.1.0.0 Alpha + Verssion: 0.1.0.1 Alpha ----------------------------------------------------- Usage: Writes a logFile ===================================================== @@ -30,6 +30,10 @@ function __construct($LogType) { $this->file = FILES_DIR.'/logs/AuthLog.log'; break; + case 'Error': + $this->file = FILES_DIR.'/logs/Errors.log'; + break; + default: die('{"message": "Unknown log operation"}'); } @@ -40,7 +44,7 @@ function WriteLine($text) { if($fp) { fwrite($fp,$this->logDate.$text . "\n"); } else { - $this->error = " -"; + $this->error = "Error writing logFile"; } fclose($fp); } @@ -49,7 +53,7 @@ function Read() { if(file_exists($this->file)) { return file_get_contents($this->file); } else { - $this->error = "- "; + $this->error = "LogFile already created"; } } @@ -59,7 +63,7 @@ function Clear() { { ftruncate($fp,0); } else { - $this->error = " -"; + $this->error = "Error reading LogFile"; } fclose($fp); }