release 1.3.22

This commit is contained in:
Newcomer1989
2023-02-01 20:44:58 +01:00
parent b96e32b713
commit f7d7aedc5a
100 changed files with 5710 additions and 1435 deletions

View File

@@ -1,22 +1,22 @@
<?PHP
function update_rs($mysqlcon,$lang,$cfg,$dbname,$phpcommand,$norotate=NULL) {
function update_rs($mysqlcon,$lang,$cfg,$dbname,$norotate=NULL) {
$nowtime = time();
$sqlexec = '';
$norotate = true;
enter_logfile($cfg,4," Start updating the Ranksystem...",$norotate);
enter_logfile($cfg,4," Backup the database due cloning tables...",$norotate);
enter_logfile(4," Start updating the Ranksystem...",$norotate);
enter_logfile(4," Backup the database due cloning tables...",$norotate);
$countbackuperr = 0;
$tables = array('addons_config','cfg_params','groups','job_check','server_usage','stats_server','stats_user','user','user_snapshot');
$tables = array('addon_assign_groups','addons_config','admin_addtime','cfg_params','channel','csrf_token','groups','job_check','server_usage','stats_nations','stats_platforms','stats_server','stats_user','stats_versions','user','user_iphash','user_snapshot');
foreach ($tables as $table) {
try {
if($mysqlcon->query("SELECT 1 FROM `$dbname`.`bak_$table` LIMIT 1") !== false) {
if($mysqlcon->exec("DROP TABLE `$dbname`.`bak_$table`") === false) {
enter_logfile($cfg,1," Error due deleting old backup table bak_".$table.".",$norotate);
enter_logfile(1," Error due deleting old backup table bak_".$table.".",$norotate);
$countbackuperr++;
} else {
enter_logfile($cfg,4," Old backup table bak_".$table." successfully removed.",$norotate);
enter_logfile(4," Old backup table bak_".$table." successfully removed.",$norotate);
}
}
} catch (Exception $e) { }
@@ -24,47 +24,47 @@ function update_rs($mysqlcon,$lang,$cfg,$dbname,$phpcommand,$norotate=NULL) {
foreach ($tables as $table) {
if($mysqlcon->exec("CREATE TABLE `$dbname`.`bak_$table` LIKE `$dbname`.`$table`") === false) {
enter_logfile($cfg,1," Error due creating table bak_".$table.".",$norotate);
enter_logfile(1," Error due creating table bak_".$table.".",$norotate);
$countbackuperr++;
} else {
if($mysqlcon->exec("INSERT `$dbname`.`bak_$table` SELECT * FROM `$dbname`.`$table`") === false) {
enter_logfile($cfg,1," Error due inserting data from table ".$table.".",$norotate);
enter_logfile(1," Error due inserting data from table ".$table.".",$norotate);
$countbackuperr++;
} else {
enter_logfile($cfg,4," Table ".$table." successfully cloned.",$norotate);
enter_logfile(4," Table ".$table." successfully cloned.",$norotate);
}
}
}
if($countbackuperr != 0) {
enter_logfile($cfg,4," Backup failed. Please check your database permissions.",$norotate);
enter_logfile($cfg,4," Update failed. Go on with normal work on old version.",$norotate);
enter_logfile(4," Backup failed. Please check your database permissions.",$norotate);
enter_logfile(4," Update failed. Go on with normal work on old version.",$norotate);
return;
} else {
enter_logfile($cfg,4," Database-tables successfully backuped.",$norotate);
enter_logfile(4," Database-tables successfully backuped.",$norotate);
}
if(!is_file(substr(__DIR__,0,-4).'update/ranksystem_'.$cfg['version_latest_available'].'.zip')) {
enter_logfile($cfg,4," Downloading new update...",$norotate);
if(!is_file(dirname(__DIR__).DIRECTORY_SEPARATOR.'update/ranksystem_'.$cfg['version_latest_available'].'.zip')) {
enter_logfile(4," Downloading new update...",$norotate);
$newUpdate = file_get_contents('https://ts-n.net/downloads/ranksystem_'.$cfg['version_latest_available'].'.zip');
if(!is_dir(substr(__DIR__,0,-4).'update/')) {
mkdir (substr(__DIR__,0,-4).'update/');
if(!is_dir(dirname(__DIR__).DIRECTORY_SEPARATOR.'update/')) {
mkdir (dirname(__DIR__).DIRECTORY_SEPARATOR.'update/');
}
$dlHandler = fopen(substr(__DIR__,0,-4).'update/ranksystem_'.$cfg['version_latest_available'].'.zip', 'w');
$dlHandler = fopen(dirname(__DIR__).DIRECTORY_SEPARATOR.'update/ranksystem_'.$cfg['version_latest_available'].'.zip', 'w');
if(!fwrite($dlHandler,$newUpdate)) {
enter_logfile($cfg,1," Could not save new update. Please check the permissions for folder 'update'.",$norotate);
enter_logfile($cfg,4," Update failed. Go on with normal work on old version.",$norotate);
enter_logfile(1," Could not save new update. Please check the permissions for folder 'update'.",$norotate);
enter_logfile(4," Update failed. Go on with normal work on old version.",$norotate);
return;
}
if(!is_file(substr(__DIR__,0,-4).'update/ranksystem_'.$cfg['version_latest_available'].'.zip')) {
enter_logfile($cfg,4," Something gone wrong with downloading/saving the new update file.",$norotate);
enter_logfile($cfg,4," Update failed. Go on with normal work on old version.",$norotate);
if(!is_file(dirname(__DIR__).DIRECTORY_SEPARATOR.'update/ranksystem_'.$cfg['version_latest_available'].'.zip')) {
enter_logfile(4," Something gone wrong with downloading/saving the new update file.",$norotate);
enter_logfile(4," Update failed. Go on with normal work on old version.",$norotate);
return;
}
fclose($dlHandler);
enter_logfile($cfg,4," New update successfully saved.",$norotate);
enter_logfile(4," New update successfully saved.",$norotate);
} else {
enter_logfile($cfg,5," New update file (update/ranksystem_".$cfg['version_latest_available'].".zip) already here...",$norotate);
enter_logfile(5," New update file (update/ranksystem_".$cfg['version_latest_available'].".zip) already here...",$norotate);
}
$countwrongfiles = 0;
@@ -72,63 +72,63 @@ function update_rs($mysqlcon,$lang,$cfg,$dbname,$phpcommand,$norotate=NULL) {
$zip = new ZipArchive;
if($zip->open(substr(__DIR__,0,-4).'update/ranksystem_'.$cfg['version_latest_available'].'.zip')) {
if($zip->open(dirname(__DIR__).DIRECTORY_SEPARATOR.'update/ranksystem_'.$cfg['version_latest_available'].'.zip')) {
for ($i = 0; $i < $zip->numFiles; $i++) {
$thisFileName = $zip->getNameIndex($i);
$thisFileDir = dirname($thisFileName);
enter_logfile($cfg,6," Parent directory: ".$thisFileDir,$norotate);
enter_logfile($cfg,6," File/Dir: ".$thisFileName,$norotate);
enter_logfile(6," Parent directory: ".$thisFileDir,$norotate);
enter_logfile(6," File/Dir: ".$thisFileName,$norotate);
if(substr($thisFileName,-1,1) == '/' || substr($thisFileName,-1,1) == '\\') {
enter_logfile($cfg,6," Check folder is existing: ".$thisFileName,$norotate);
if(!is_dir(substr(__DIR__,0,-4).substr($thisFileName,0,-1))) {
enter_logfile($cfg,5," Create folder: ".substr(__DIR__,0,-4).substr($thisFileName,0,-1),$norotate);
if(mkdir((substr(__DIR__,0,-4).substr($thisFileName,0,-1)), 0740, true)) {
enter_logfile($cfg,4," Created new folder ".substr(__DIR__,0,-4).substr($thisFileName,0,-1),$norotate);
enter_logfile(6," Check folder is existing: ".$thisFileName,$norotate);
if(!is_dir(dirname(__DIR__).DIRECTORY_SEPARATOR.substr($thisFileName,0,-1))) {
enter_logfile(5," Create folder: ".dirname(__DIR__).DIRECTORY_SEPARATOR.substr($thisFileName,0,-1),$norotate);
if(mkdir((dirname(__DIR__).DIRECTORY_SEPARATOR.substr($thisFileName,0,-1)), 0750, true)) {
enter_logfile(4," Created new folder ".dirname(__DIR__).DIRECTORY_SEPARATOR.substr($thisFileName,0,-1),$norotate);
} else {
enter_logfile($cfg,2," Error by creating folder ".substr(__DIR__,0,-4).substr($thisFileName,0,-1).". Please check the permissions on the folder one level above.",$norotate);
enter_logfile(2," Error by creating folder ".dirname(__DIR__).DIRECTORY_SEPARATOR.substr($thisFileName,0,-1).". Please check the permissions on the folder one level above.",$norotate);
$countwrongfiles++;
}
} else {
enter_logfile($cfg,6," Folder still existing.",$norotate);
enter_logfile(6," Folder still existing.",$norotate);
}
continue;
}
if(!is_dir(substr(__DIR__,0,-4).'/'.$thisFileDir)) {
enter_logfile($cfg,6," Check parent folder is existing: ".$thisFileDir,$norotate);
if(mkdir(substr(__DIR__,0,-4).$thisFileDir, 0740, true)) {
enter_logfile($cfg,4," Created new folder ".$thisFileDir,$norotate);
if(!is_dir(dirname(__DIR__).DIRECTORY_SEPARATOR.$thisFileDir)) {
enter_logfile(6," Check parent folder is existing: ".$thisFileDir,$norotate);
if(mkdir(dirname(__DIR__).DIRECTORY_SEPARATOR.$thisFileDir, 0750, true)) {
enter_logfile(4," Created new folder ".$thisFileDir,$norotate);
} else {
enter_logfile($cfg,2," Error by creating folder ".$thisFileDir.". Please check the permissions on your folder ".substr(__DIR__,0,-4),$norotate);
enter_logfile(2," Error by creating folder ".$thisFileDir.". Please check the permissions on your folder ".dirname(__DIR__),$norotate);
$countwrongfiles++;
}
} else {
enter_logfile($cfg,6," Parent folder still existing.",$norotate);
enter_logfile(6," Parent folder still existing.",$norotate);
}
enter_logfile($cfg,6," Check file: ".substr(__DIR__,0,-4).$thisFileName,$norotate);
if(!is_dir(substr(__DIR__,0,-4).$thisFileName)) {
enter_logfile(6," Check file: ".dirname(__DIR__).DIRECTORY_SEPARATOR.$thisFileName,$norotate);
if(!is_dir(dirname(__DIR__).DIRECTORY_SEPARATOR.$thisFileName)) {
$contents = $zip->getFromName($thisFileName);
$updateThis = '';
if($thisFileName == 'other/dbconfig.php' || $thisFileName == 'install.php' || $thisFileName == 'other/phpcommand.php' || $thisFileName == 'logs/autostart_deactivated') {
enter_logfile($cfg,5," Did not touch ".$thisFileName,$norotate);
enter_logfile(5," Did not touch ".$thisFileName,$norotate);
} else {
if(($updateThis = fopen(substr(__DIR__,0,-4).'/'.$thisFileName, 'w')) === false) {
enter_logfile($cfg,2," Failed to open file ".$thisFileName,$norotate);
if(($updateThis = fopen(dirname(__DIR__).DIRECTORY_SEPARATOR.$thisFileName, 'w')) === false) {
enter_logfile(2," Failed to open file ".$thisFileName,$norotate);
$countwrongfiles++;
} elseif(!fwrite($updateThis, $contents)) {
enter_logfile($cfg,2," Failed to write file ".$thisFileName,$norotate);
enter_logfile(2," Failed to write file ".$thisFileName,$norotate);
$countwrongfiles++;
} else {
enter_logfile($cfg,4," Replaced file ".$thisFileName,$norotate);
enter_logfile(4," Replaced file ".$thisFileName,$norotate);
$countchangedfiles++;
}
fclose($updateThis);
unset($contents);
}
} else {
enter_logfile($cfg,2," Unkown thing happened.. Is the parent directory existing? ".$thisFileDir." # ".$thisFileName,$norotate);
enter_logfile(2," Unknown thing happened.. Is the parent directory existing? ".$thisFileDir." # ".$thisFileName,$norotate);
$countwrongfiles++;
}
}
@@ -137,39 +137,37 @@ function update_rs($mysqlcon,$lang,$cfg,$dbname,$phpcommand,$norotate=NULL) {
unset($zip);
sleep(1);
} else {
enter_logfile($cfg,2," Error with downloaded Zip file happened. Is the file inside the folder 'update' valid and readable?",$norotate);
enter_logfile(2," Error with downloaded Zip file happened. Is the file inside the folder 'update' valid and readable?",$norotate);
$countwrongfiles++;
}
if(!unlink(substr(__DIR__,0,-4).'update/ranksystem_'.$cfg['version_latest_available'].'.zip')) {
enter_logfile($cfg,3," Could not clean update folder. Please remove the unneeded file ".substr(__DIR__,0,-4)."update/ranksystem_".$cfg['version_latest_available'].".zip",$norotate);
if(!unlink(dirname(__DIR__).DIRECTORY_SEPARATOR.'update'.DIRECTORY_SEPARATOR.'ranksystem_'.$cfg['version_latest_available'].'.zip')) {
enter_logfile(3," Could not clean update folder. Please remove the unneeded file ".dirname(__DIR__).DIRECTORY_SEPARATOR."update".DIRECTORY_SEPARATOR."ranksystem_".$cfg['version_latest_available'].".zip",$norotate);
} else {
enter_logfile($cfg,5," Cleaned update folder.",$norotate);
enter_logfile(5," Cleaned update folder.",$norotate);
}
if($countwrongfiles == 0 && $countchangedfiles != 0) {
$sqlexec .= "UPDATE `$dbname`.`cfg_params` SET `value`='{$cfg['version_latest_available']}' WHERE `param`='version_latest_available';\n";
$path = substr(__DIR__, 0, -4);
if (file_exists($cfg['logs_path'].'pid')) {
unlink($cfg['logs_path'].'pid');
if (file_exists($GLOBALS['pidfile'])) {
unlink($GLOBALS['pidfile']);
}
enter_logfile($cfg,4," Files updated successfully.",$norotate);
enter_logfile(4," Files updated successfully.",$norotate);
if (substr(php_uname(), 0, 7) == "Windows") {
pclose(popen("start /B cmd /C ".$phpcommand." ".$path."worker.php start 1500000 >NUL 2>NUL", "r"));
pclose(popen("start /B cmd /C ".$GLOBALS['phpcommand']." ".dirname(__DIR__).DIRECTORY_SEPARATOR."worker.php start 1500000 >NUL 2>NUL", "r"));
} else {
exec($phpcommand." ".$path."worker.php start 2500000 > /dev/null 2>&1 &");
exec($GLOBALS['phpcommand']." ".dirname(__DIR__).DIRECTORY_SEPARATOR."worker.php start 2500000 > /dev/null 2>&1 &");
}
shutdown($mysqlcon,$cfg,4,"Update done. Wait for restart via cron/task.",FALSE);
shutdown($mysqlcon,4,"Update done. Wait for restart via cron/task.",FALSE);
} else {
enter_logfile($cfg,1," Files updated with at least one error. Please check the log!",$norotate);
enter_logfile($cfg,2,"Update of the Ranksystem failed!",$norotate);
enter_logfile($cfg,4,"Continue with normal work on old version.",$norotate);
enter_logfile(1," Files updated with at least one error. Please check the log!",$norotate);
enter_logfile(2,"Update of the Ranksystem failed!",$norotate);
enter_logfile(4,"Continue with normal work on old version.",$norotate);
}
$sqlexec .= "UPDATE `$dbname`.`job_check` SET `timestamp`='$nowtime' WHERE `job_name`='get_version';\n";