release 1.1.1

This commit is contained in:
Newcomer1989
2016-10-08 15:26:17 +02:00
parent e20f08f8b3
commit ab76128c42
80 changed files with 4085 additions and 3002 deletions

View File

@@ -1,5 +1,7 @@
#!/usr/bin/php
<?PHP
if(isset($_SERVER['HTTP_HOST'])) exit;
if(isset($_SERVER['REMOTE_ADDR'])) exit;
set_time_limit(0);
ini_set('default_charset', 'UTF-8');
setlocale(LC_ALL, 'UTF-8');
@@ -22,6 +24,7 @@ function enter_logfile($logpath,$timezone,$loglevel,$logtext) {
$input = DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u ").$loglevel.$logtext."\n";
$loghandle = fopen($file, 'a');
fwrite($loghandle, $input);
fclose($loghandle);
if (filesize($file) > 5242880) {
fwrite($loghandle, DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u ")." NOTICE Logfile filesie of 5 MiB reached.. Rotate logfile.\n");
fwrite($loghandle, DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u ")." NOTICE Restart Bot to continue with new log file...\n");
@@ -59,15 +62,6 @@ require_once(substr(__DIR__,0,-4).'jobs/calc_userstats.php');
require_once(substr(__DIR__,0,-4).'jobs/clean.php');
require_once(substr(__DIR__,0,-4).'jobs/check_db.php');
function log_mysql($jobname,$mysqlcon,$timezone,$dbname) {
$timestamp = time();
if($mysqlcon->exec("INSERT INTO $dbname.job_log (timestamp,job_name,status) VALUES ('$timestamp','$jobname','9')") === false) {
enter_logfile($logpath,$timezone,2,print_r($mysqlcon->errorInfo()));
} else {
return $jobid = $mysqlcon->lastInsertId();
}
}
function check_shutdown($timezone,$logpath) {
if(!is_file(substr(__DIR__,0,-4).'logs/pid')) {
enter_logfile($logpath,$timezone,5,"Received signal to stop. Shutting down!\n\n");
@@ -81,7 +75,7 @@ enter_logfile($logpath,$timezone,5," Ranksystem Version: ".$currvers);
enter_logfile($logpath,$timezone,5,"Connect to TS3 Server (Address: \"".$ts['host']."\" Voice-Port: \"".$ts['voice']."\" Query-Port: \"".$ts['query']."\").");
try {
$ts3 = TeamSpeak3::factory("serverquery://" . $ts['user'] . ":" . $ts['pass'] . "@" . $ts['host'] . ":" . $ts['query'] . "/?server_port=" . $ts['voice'] . "&blocking=0");
enter_logfile($logpath,$timezone,5," Conenction to TS3 Server established.");
enter_logfile($logpath,$timezone,5," Connection to TS3 Server established.");
try {
usleep($slowmode);
@@ -112,14 +106,16 @@ try {
}
}
} else {
enter_logfile($logpath,$timezone,4," No channel defined where the Ranksystem should be entered.");
enter_logfile($logpath,$timezone,4," No channel defined where the Ranksystem Bot should be entered.");
}
enter_logfile($logpath,$timezone,5,"Bot starts now his work!");
$looptime = 1;
usleep(5000000);
while(1) {
if($looptime<1) {
$loopsleep = 1 - $looptime;
$loopsleep = (1 - $looptime) * 1000000;
//enter_logfile($logpath,$timezone,6," Sleep for ".(1 - $looptime)." seconds till next loop starts.");
check_shutdown($timezone,$logpath); usleep($loopsleep);
}
$starttime = microtime(true);
@@ -132,23 +128,17 @@ try {
if($defchid != 0) {
try { usleep($slowmode); $ts3->clientMove($whoami['client_id'],$defchid); } catch (Exception $e) {}
}
$jobid = log_mysql('calc_user',$mysqlcon,$timezone,$dbname);
calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$update,$grouptime,$boostarr,$resetbydbchange,$msgtouser,$uniqueid,$updateinfotime,$currvers,$substridle,$exceptuuid,$exceptgroup,$allclients,$logpath,$rankupmsg,$ignoreidle,$exceptcid);
calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$update,$grouptime,$boostarr,$resetbydbchange,$msgtouser,$uniqueid,$updateinfotime,$currvers,$substridle,$exceptuuid,$exceptgroup,$allclients,$logpath,$rankupmsg,$ignoreidle,$exceptcid);
check_shutdown($timezone,$logpath); usleep($slowmode);
$jobid = log_mysql('get_avatars',$mysqlcon,$timezone,$dbname);
get_avatars($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$logpath);
get_avatars($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$logpath);
check_shutdown($timezone,$logpath); usleep($slowmode);
$jobid = log_mysql('update_groups',$mysqlcon,$timezone,$dbname);
update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$serverinfo,$logpath);
update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serverinfo,$logpath);
check_shutdown($timezone,$logpath); usleep($slowmode);
$jobid = log_mysql('calc_serverstats',$mysqlcon,$timezone,$dbname);
calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$serverinfo,$substridle,$grouptime,$logpath);
calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serverinfo,$substridle,$grouptime,$logpath);
check_shutdown($timezone,$logpath); usleep($slowmode);
$jobid = log_mysql('calc_userstats',$mysqlcon,$timezone,$dbname);
calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$logpath);
calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$logpath);
check_shutdown($timezone,$logpath); usleep($slowmode);
$jobid = log_mysql('clean',$mysqlcon,$timezone,$dbname);
clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$cleanclients,$cleanperiod,$logpath);
clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$cleanclients,$cleanperiod,$logpath);
$looptime = microtime(true) - $starttime;
}
}
@@ -158,11 +148,7 @@ catch (Exception $e) {
if(in_array($e->getCode(), $offline_status)) {
if($mysqlcon->exec("UPDATE $dbname.stats_server SET server_status='0'") === false) {
enter_logfile($logpath,$timezone,2,$lang['error'].print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
$sqlmsg .= $e->getCode() . ': ' . $e->getMessage();
$sqlerr++;
}
?>
?>

View File

@@ -1,9 +1,6 @@
<?PHP
function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$serverinfo,$substridle,$grouptime,$logpath) {
$starttime = microtime(true);
function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serverinfo,$substridle,$grouptime,$logpath) {
$nowtime = time();
$sqlmsg = '';
$sqlerr = 0;
$total_user = 0;
$total_online_time = 0;
@@ -15,8 +12,6 @@ function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezon
$server_channel_amount = 0;
if(($uuids = $mysqlcon->query("SELECT uuid,count,idle,platform,nation FROM $dbname.user")) === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 1:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$uuids = $uuids->fetchAll();
foreach($uuids as $uuid) {
@@ -39,8 +34,6 @@ function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezon
// Duplicate users Table in snapshot Table
if(($max_entry_usersnap = $mysqlcon->query("SELECT MAX(DISTINCT(timestamp)) AS timestamp FROM $dbname.user_snapshot")) === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 2:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$max_entry_usersnap = $max_entry_usersnap->fetch(PDO::FETCH_ASSOC);
$diff_max_usersnap = $nowtime - $max_entry_usersnap['timestamp'];
@@ -54,8 +47,6 @@ function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezon
if ($allinsertsnap != '') {
if($mysqlcon->exec("INSERT INTO $dbname.user_snapshot (timestamp, uuid, count, idle) VALUES $allinsertsnap") === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 3:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
}
@@ -63,8 +54,6 @@ function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezon
$deletiontime = $nowtime - 2678400;
if($mysqlcon->exec("DELETE FROM $dbname.user_snapshot WHERE timestamp=$deletiontime") === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 4:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
@@ -81,16 +70,12 @@ function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezon
// Calc Values for server stats
if(($entry_snapshot_count = $mysqlcon->query("SELECT count(DISTINCT(timestamp)) AS timestamp FROM $dbname.user_snapshot")) === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 5:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$entry_snapshot_count = $entry_snapshot_count->fetch(PDO::FETCH_ASSOC);
if ($entry_snapshot_count['timestamp'] > 27) {
// Calc total_online_week
if(($snapshot_count_week = $mysqlcon->query("SELECT (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)) - (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp) AND uuid IN (SELECT uuid FROM $dbname.user)) AS count")) === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 6:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$snapshot_count_week = $snapshot_count_week->fetch(PDO::FETCH_ASSOC);
$total_online_week = $snapshot_count_week['count'];
@@ -101,8 +86,6 @@ function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezon
// Calc total_online_month
if(($snapshot_count_month = $mysqlcon->query("SELECT (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)) - (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp) AND uuid IN (SELECT uuid FROM $dbname.user)) AS count")) === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 7:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$snapshot_count_month = $snapshot_count_month->fetch(PDO::FETCH_ASSOC);
$total_online_month = $snapshot_count_month['count'];
@@ -221,8 +204,6 @@ function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezon
if($mysqlcon->exec("UPDATE $dbname.stats_server SET total_user='$total_user', total_online_time='$total_online_time', total_online_month='$total_online_month', total_online_week='$total_online_week', total_active_time='$total_active_time', total_inactive_time='$total_inactive_time', country_nation_name_1='$country_nation_name_1', country_nation_name_2='$country_nation_name_2', country_nation_name_3='$country_nation_name_3', country_nation_name_4='$country_nation_name_4', country_nation_name_5='$country_nation_name_5', country_nation_1='$country_nation_1', country_nation_2='$country_nation_2', country_nation_3='$country_nation_3', country_nation_4='$country_nation_4', country_nation_5='$country_nation_5', country_nation_other='$country_nation_other', platform_1='$platform_1', platform_2='$platform_2', platform_3='$platform_3', platform_4='$platform_4', platform_5='$platform_5', platform_other='$platform_other', version_name_1='$version_name_1', version_name_2='$version_name_2', version_name_3='$version_name_3', version_name_4='$version_name_4', version_name_5='$version_name_5', version_1='$version_1', version_2='$version_2', version_3='$version_3', version_4='$version_4', version_5='$version_5', version_other='$version_other', version_name_1='$version_name_1', server_status='$server_status', server_free_slots='$server_free_slots', server_used_slots='$server_used_slots', server_channel_amount='$server_channel_amount', server_ping='$server_ping', server_packet_loss='$server_packet_loss', server_bytes_down='$server_bytes_down', server_bytes_up='$server_bytes_up', server_uptime='$server_uptime', server_id='$server_id', server_name=$server_name, server_pass='$server_pass', server_creation_date='$server_creation_date', server_platform='$server_platform', server_weblist='$server_weblist', server_version='$server_version'") === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 8:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
// Stats for Server Usage
@@ -235,8 +216,6 @@ function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezon
if ($max_entry_serverusage['timestamp'] == 0 || $diff_max_serverusage > 898) { // every 15 mins
if($mysqlcon->exec("INSERT INTO $dbname.server_usage (timestamp, clients, channel) VALUES ($nowtime,$server_used_slots,$server_channel_amount)") === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 10:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
@@ -244,8 +223,6 @@ function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezon
$upnextuptime = $nowtime - 86400;
if(($uuidsoff = $mysqlcon->query("SELECT uuid,idle,count FROM $dbname.user WHERE online<>1 AND lastseen>$upnextuptime")) === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 11:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
if ($uuidsoff->rowCount() != 0) {
$uuidsoff = $uuidsoff->fetchAll(PDO::FETCH_ASSOC);
@@ -285,41 +262,20 @@ function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezon
$allupdateuuid = substr($allupdateuuid, 0, -1);
if ($mysqlcon->exec("UPDATE $dbname.user set nextup = CASE uuid $allupdatenextup END WHERE uuid IN ($allupdateuuid)") === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 12:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
//Calc Rank
if($mysqlcon->exec("SET @a:=0") === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 13:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
if ($substridle == 1) {
if($mysqlcon->exec("UPDATE $dbname.user u INNER JOIN (SELECT @a:=@a+1 nr,uuid FROM $dbname.user WHERE except!=1 ORDER BY (count - idle) DESC) s USING (uuid) SET u.rank=s.nr") === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 14:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
} else {
if($mysqlcon->exec("UPDATE $dbname.user u INNER JOIN (SELECT @a:=@a+1 nr,uuid FROM $dbname.user WHERE except!=1 ORDER BY count DESC) s USING (uuid) SET u.rank=s.nr") === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 14:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
$buildtime = microtime(true) - $starttime;
if ($buildtime < 0) { $buildtime = 0; }
if ($sqlerr == 0) {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='0', runtime='$buildtime' WHERE id='$jobid'") === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 15:".print_r($mysqlcon->errorInfo()));
}
} else {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='1', err_msg='$sqlmsg', runtime='$buildtime' WHERE id='$jobid'") === false) {
enter_logfile($logpath,$timezone,2,"calc_serverstats 16:".print_r($mysqlcon->errorInfo()));
}
}
}

View File

@@ -1,15 +1,9 @@
<?PHP
function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$update,$grouptime,$boostarr,$resetbydbchange,$msgtouser,$uniqueid,$updateinfotime,$currvers,$substridle,$exceptuuid,$exceptgroup,$allclients,$logpath,$rankupmsg,$ignoreidle,$exceptcid) {
$starttime = microtime(true);
function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$update,$grouptime,$boostarr,$resetbydbchange,$msgtouser,$uniqueid,$updateinfotime,$currvers,$substridle,$exceptuuid,$exceptgroup,$allclients,$logpath,$rankupmsg,$ignoreidle,$exceptcid) {
$nowtime = time();
$sqlmsg = '';
$sqlerr = 0;
if(($getversion = $mysqlcon->query("SELECT * FROM $dbname.job_check WHERE job_name='get_version'")) === false) {
enter_logfile($logpath,$timezone,2,"calc_user -3:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
} else {
$getversion = $getversion->fetchAll();
$updatetime = $nowtime - 43200;
@@ -19,13 +13,9 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$upda
restore_error_handler();
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='get_version'") === false) {
enter_logfile($logpath,$timezone,2,"calc_user -2:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
if($mysqlcon->exec("UPDATE $dbname.config SET newversion='$newversion'") === false) {
enter_logfile($logpath,$timezone,2,"calc_user -1:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
}
@@ -34,18 +24,14 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$upda
$updatetime = $nowtime - $updateinfotime;
if(($lastupdate = $mysqlcon->query("SELECT * FROM $dbname.job_check WHERE job_name='check_update'")) === false) {
enter_logfile($logpath,$timezone,2,"calc_user 0:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$lastupdate = $lastupdate->fetchAll();
if ($lastupdate[0]['timestamp'] < $updatetime) {
if(($getversion = $mysqlcon->query("SELECT newversion FROM $dbname.config")) === false) {
enter_logfile($logpath,$timezone,2,"calc_user 1:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$getversion = $getversion->fetchAll();
$newversion = $getversion[0];
$getversion = $getversion->fetch(PDO::FETCH_ASSOC);
$newversion = $getversion['newversion'];
if(version_compare(substr($newversion, 0, 5), substr($currvers, 0, 5), '>') && $newversion != '') {
enter_logfile($logpath,$timezone,4,$lang['upinf']);
foreach ($uniqueid as $clientid) {
@@ -56,15 +42,11 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$upda
}
catch (Exception $e) {
enter_logfile($logpath,$timezone,4," ".sprintf($lang['upusrerr'], $clientid));
$sqlmsg .= $e->getCode() . ': ' . $e->getMessage();
$sqlerr++;
}
}
}
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp=$nowtime WHERE job_name='check_update'") === false) {
enter_logfile($logpath,$timezone,2,"calc_user 3:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
}
@@ -85,15 +67,11 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$upda
if ($dbdata->rowCount() != 0) {
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='calc_user_lastscan'") === false) {
enter_logfile($logpath,$timezone,2,"calc_user 5:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
if(($dbuserdata = $mysqlcon->query("SELECT uuid,cldbid,count,grpid,nextup,idle,boosttime FROM $dbname.user")) === false) {
enter_logfile($logpath,$timezone,2,"calc_user 6:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$uuids = $dbuserdata->fetchAll();
$uuids = $dbuserdata->fetchAll(PDO::FETCH_ASSOC);
foreach($uuids as $uuid) {
$sqlhis[$uuid['uuid']] = array(
"uuid" => $uuid['uuid'],
@@ -122,18 +100,22 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$upda
foreach ($allclients as $client) {
$sumentries++;
$cldbid = $client['client_database_id'];
$ip = ip2long($client['connection_client_ip']);
$name = str_replace('\\', '\\\\', htmlspecialchars($client['client_nickname'], ENT_QUOTES));
$uid = htmlspecialchars($client['client_unique_identifier'], ENT_QUOTES);
$cldbid = $client['client_database_id'];
$name = $mysqlcon->quote($client['client_nickname'], ENT_QUOTES);
$uid = htmlspecialchars($client['client_unique_identifier'], ENT_QUOTES);
$cldgroup = $client['client_servergroups'];
$sgroups = explode(",", $cldgroup);
$platform=$client['client_platform'];
$nation=$client['client_country'];
$version=$client['client_version'];
$firstconnect=$client['client_created'];
$channel=$client['cid'];
$sgroups = explode(",", $cldgroup);
$platform = $client['client_platform'];
$nation = $client['client_country'];
$version = $client['client_version'];
$firstconnect = $client['client_created'];
$channel = $client['cid'];
if (!in_array($uid, $yetonline) && $client['client_version'] != "ServerQuery") {
if(strstr($client['connection_client_ip'], '[')) {
$ip = $mysqlcon->quote(inet_pton(str_replace(array('[',']'),'',$client['connection_client_ip'])), ENT_QUOTES);
} else {
$ip = $mysqlcon->quote(inet_pton($client['connection_client_ip']), ENT_QUOTES);
}
$clientidle = floor($client['client_idle_time'] / 1000);
if(isset($ignoreidle) && $clientidle < $ignoreidle) {
$clientidle = 0;
@@ -171,8 +153,6 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$upda
}
catch (Exception $e) {
enter_logfile($logpath,$timezone,2,"calc_user 8:".sprintf($lang['sgrprerr'], $name, $uid, $cldbid));
$sqlmsg .= $e->getCode() . ': ' . $e->getMessage();
$sqlerr++;
}
}
}
@@ -220,8 +200,6 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$upda
}
catch (Exception $e) {
enter_logfile($logpath,$timezone,2,"calc_user 9:".sprintf($lang['sgrprerr'], $name, $uid, $cldbid));
$sqlmsg .= $e->getCode() . ': ' . $e->getMessage();
$sqlerr++;
}
}
if (!in_array($groupid, $sgroups)) {
@@ -232,8 +210,6 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$upda
}
catch (Exception $e) {
enter_logfile($logpath,$timezone,2,"calc_user 10:".sprintf($lang['sgrprerr'], $name, $uid, $cldbid));
$sqlmsg .= $e->getCode() . ': ' . $e->getMessage();
$sqlerr++;
}
}
$grpid = $groupid;
@@ -247,8 +223,6 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$upda
$ts3->clientGetByUid($uid)->message(sprintf($rankupmsg, $days, $hours, $mins, $secs));
} catch (Exception $e) {
enter_logfile($logpath,$timezone,2,"calc_user 12:".sprintf($lang['sgrprerr'], $name, $uid, $cldbid));
$sqlmsg .= $e->getCode() . ': ' . $e->getMessage();
$sqlerr++;
}
}
}
@@ -261,7 +235,7 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$upda
}
}
$updatedata[] = array(
"uuid" => $uid,
"uuid" => $mysqlcon->quote($client['client_unique_identifier'], ENT_QUOTES),
"cldbid" => $cldbid,
"count" => $count,
"ip" => $ip,
@@ -286,7 +260,7 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$upda
}
}
$insertdata[] = array(
"uuid" => $uid,
"uuid" => $mysqlcon->quote($client['client_unique_identifier'], ENT_QUOTES),
"cldbid" => $cldbid,
"ip" => $ip,
"name" => $name,
@@ -308,21 +282,17 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$upda
if($mysqlcon->exec("UPDATE $dbname.user SET online='0'") === false) {
enter_logfile($logpath,$timezone,2,"calc_user 13:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
if ($insertdata != '') {
$allinsertdata = '';
foreach ($insertdata as $insertarr) {
$allinsertdata = $allinsertdata . "('" . $insertarr['uuid'] . "', '" . $insertarr['cldbid'] . "', '1', '" . $insertarr['ip'] . "', '" . $insertarr['name'] . "', '" . $insertarr['lastseen'] . "', '" . $insertarr['grpid'] . "', '" . $insertarr['nextup'] . "', '" . $insertarr['cldgroup'] . "', '" . $insertarr['platform'] . "', '" . $insertarr['nation'] . "', '" . $insertarr['version'] . "', '" . $insertarr['firstcon'] . "', '" . $insertarr['except'] . "','1'),";
$allinsertdata = $allinsertdata . "(" . $insertarr['uuid'] . ", '" . $insertarr['cldbid'] . "', '1', " . $insertarr['ip'] . ", " . $insertarr['name'] . ", '" . $insertarr['lastseen'] . "', '" . $insertarr['grpid'] . "', '" . $insertarr['nextup'] . "', '" . $insertarr['cldgroup'] . "', '" . $insertarr['platform'] . "', '" . $insertarr['nation'] . "', '" . $insertarr['version'] . "', '" . $insertarr['firstcon'] . "', '" . $insertarr['except'] . "','1'),";
}
$allinsertdata = substr($allinsertdata, 0, -1);
if ($allinsertdata != '') {
if($mysqlcon->exec("INSERT INTO $dbname.user (uuid, cldbid, count, ip, name, lastseen, grpid, nextup, cldgroup, platform, nation, version, firstcon, except, online) VALUES $allinsertdata") === false) {
enter_logfile($logpath,$timezone,2,"calc_user 14:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
}
@@ -346,40 +316,25 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$upda
$allupdateversion = '';
$allupdateexcept = '';
foreach ($updatedata as $updatearr) {
$allupdateuuid = $allupdateuuid . "'" . $updatearr['uuid'] . "',";
$allupdatecldbid = $allupdatecldbid . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['cldbid'] . "' ";
$allupdatecount = $allupdatecount . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['count'] . "' ";
$allupdateip = $allupdateip . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['ip'] . "' ";
$allupdatename = $allupdatename . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['name'] . "' ";
$allupdatelastseen = $allupdatelastseen . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['lastseen'] . "' ";
$allupdategrpid = $allupdategrpid . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['grpid'] . "' ";
$allupdatenextup = $allupdatenextup . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['nextup'] . "' ";
$allupdateidle = $allupdateidle . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['idle'] . "' ";
$allupdatecldgroup = $allupdatecldgroup . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['cldgroup'] . "' ";
$allupdateboosttime = $allupdateboosttime . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['boosttime'] . "' ";
$allupdateplatform = $allupdateplatform . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['platform'] . "' ";
$allupdatenation = $allupdatenation . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['nation'] . "' ";
$allupdateversion = $allupdateversion . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['version'] . "' ";
$allupdateexcept = $allupdateexcept . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['except'] . "' ";
$allupdateuuid = $allupdateuuid . $updatearr['uuid'] . ",";
$allupdatecldbid = $allupdatecldbid . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['cldbid'] . "' ";
$allupdatecount = $allupdatecount . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['count'] . "' ";
$allupdateip = $allupdateip . "WHEN " . $updatearr['uuid'] . " THEN " . $updatearr['ip'] . " ";
$allupdatename = $allupdatename . "WHEN " . $updatearr['uuid'] . " THEN " . $updatearr['name'] . " ";
$allupdatelastseen = $allupdatelastseen . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['lastseen'] . "' ";
$allupdategrpid = $allupdategrpid . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['grpid'] . "' ";
$allupdatenextup = $allupdatenextup . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['nextup'] . "' ";
$allupdateidle = $allupdateidle . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['idle'] . "' ";
$allupdatecldgroup = $allupdatecldgroup . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['cldgroup'] . "' ";
$allupdateboosttime = $allupdateboosttime . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['boosttime'] . "' ";
$allupdateplatform = $allupdateplatform . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['platform'] . "' ";
$allupdatenation = $allupdatenation . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['nation'] . "' ";
$allupdateversion = $allupdateversion . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['version'] . "' ";
$allupdateexcept = $allupdateexcept . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['except'] . "' ";
}
$allupdateuuid = substr($allupdateuuid, 0, -1);
if($mysqlcon->exec("UPDATE $dbname.user set cldbid = CASE uuid $allupdatecldbid END, count = CASE uuid $allupdatecount END, ip = CASE uuid $allupdateip END, name = CASE uuid $allupdatename END, lastseen = CASE uuid $allupdatelastseen END, grpid = CASE uuid $allupdategrpid END, nextup = CASE uuid $allupdatenextup END, idle = CASE uuid $allupdateidle END, cldgroup = CASE uuid $allupdatecldgroup END, boosttime = CASE uuid $allupdateboosttime END, platform = CASE uuid $allupdateplatform END, nation = CASE uuid $allupdatenation END, version = CASE uuid $allupdateversion END, except = CASE uuid $allupdateexcept END, online = 1 WHERE uuid IN ($allupdateuuid)") === false) {
enter_logfile($logpath,$timezone,2,"calc_user 15:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
$buildtime = microtime(true) - $starttime;
if ($buildtime < 0) { $buildtime = 0; }
if ($sqlerr == 0) {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='0', runtime='$buildtime' WHERE id='$jobid'") === false) {
enter_logfile($logpath,$timezone,2,"calc_user 16:".print_r($mysqlcon->errorInfo()));
}
} else {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='1', err_msg='$sqlmsg', runtime='$buildtime' WHERE id='$jobid'") === false) {
enter_logfile($logpath,$timezone,2,"calc_user 17:".print_r($mysqlcon->errorInfo()));
}
}
}

View File

@@ -1,21 +1,14 @@
<?PHP
function calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$logpath) {
$starttime = microtime(true);
$sqlmsg = '';
$sqlerr = 0;
function calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$logpath) {
if(($count_user = $mysqlcon->query("SELECT count(*) as count FROM ((SELECT u.uuid FROM $dbname.user AS u INNER JOIN $dbname.stats_user As s On u.uuid=s.uuid) UNION (SELECT u.uuid FROM $dbname.user AS u LEFT JOIN $dbname.stats_user As s On u.uuid=s.uuid WHERE s.uuid IS NULL)) x")) === false) {
enter_logfile($logpath,$timezone,2,"calc_userstats 1:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$count_user = $count_user->fetchAll(PDO::FETCH_ASSOC);
$total_user = $count_user[0]['count'];
if(($job_begin = $mysqlcon->query("SELECT timestamp FROM $dbname.job_check WHERE job_name='calc_user_limit'")) === false) {
enter_logfile($logpath,$timezone,2,"calc_userstats 2:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$job_begin = $job_begin->fetchAll();
$job_begin = $job_begin[0]['timestamp'];
@@ -29,8 +22,6 @@ function calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,
if(($uuids = $mysqlcon->query("(SELECT u.uuid,u.rank,u.cldbid FROM $dbname.user AS u INNER JOIN $dbname.stats_user As s On u.uuid=s.uuid) UNION (SELECT u.uuid,u.rank,u.cldbid FROM $dbname.user AS u LEFT JOIN $dbname.stats_user As s On u.uuid=s.uuid WHERE s.uuid IS NULL) ORDER BY cldbid ASC LIMIT $job_begin, 10")) === false) {
enter_logfile($logpath,$timezone,2,"calc_userstats 3:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$uuids = $uuids->fetchAll();
foreach($uuids as $uuid) {
@@ -44,14 +35,10 @@ function calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,
// Calc Client Stats
if ($mysqlcon->exec("UPDATE $dbname.stats_user AS t LEFT JOIN $dbname.user AS u ON t.uuid=u.uuid SET t.removed='1' WHERE u.uuid IS NULL") === false) {
enter_logfile($logpath,$timezone,2,"calc_userstats 4:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
if(($statsuserhis = $mysqlcon->query("SELECT uuid, removed FROM $dbname.stats_user")) === false) {
enter_logfile($logpath,$timezone,2,"calc_userstats 5:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$statsuserhis = $statsuserhis->fetchAll();
foreach($statsuserhis as $userhis) {
@@ -60,29 +47,21 @@ function calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,
unset($statsuserhis);
if(isset($sqlhis)) {
//enter_logfile($logpath,$timezone,2,"Update User Stats between ".$job_begin." and ".$job_end.":");
//enter_logfile($logpath,$timezone,6,"Update User Stats between ".$job_begin." and ".$job_end.":");
if(($userdataweekbegin = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")) === false) {
enter_logfile($logpath,$timezone,2,"calc_userstats 6:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$userdataweekbegin = $userdataweekbegin->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
if(($userdataweekend = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")) === false) {
enter_logfile($logpath,$timezone,2,"calc_userstats 7:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$userdataweekend = $userdataweekend->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
if(($userdatamonthbegin = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")) === false) {
enter_logfile($logpath,$timezone,2,"calc_userstats 8:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$userdatamonthbegin = $userdatamonthbegin->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
if(($userdatamonthend = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")) === false) {
enter_logfile($logpath,$timezone,2,"calc_userstats 9:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$userdatamonthend = $userdatamonthend->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
@@ -100,6 +79,7 @@ function calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,
$allinsertuserstats = '';
foreach ($sqlhis as $userstats) {
check_shutdown($timezone,$logpath); usleep($slowmode);
try {
$clientinfo = $ts3->clientInfoDb($userstats['cldbid']);
@@ -134,22 +114,18 @@ function calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,
$allinsertuserstats = $allinsertuserstats . "('" . $userstats['uuid'] . "', '" .$userstats['rank'] . "', '" . $count_week . "', '" . $count_month . "', '" . $idle_week . "', '" . $idle_month . "', '" . $clientinfo['client_totalconnections'] . "', '" . $clientinfo['client_base64HashClientUID'] . "', '" . $clientinfo['client_total_bytes_uploaded'] . "', '" . $clientinfo['client_total_bytes_downloaded'] . "', " . $clientdesc . "),";
}
} catch (Exception $e) {
//error would be, when client is missing in ts db
//enter_logfile($logpath,$timezone,6,$e->getCode() . ': ' . $e->getMessage()."; Client (uuid: ".$userstats['cldbid']." cldbid: ".$userstats['cldbid'].") was missing in TS database, perhaps its already deleted".);
}
}
if ($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp=$job_end WHERE job_name='calc_user_limit'") === false) {
enter_logfile($logpath,$timezone,2,"calc_userstats 11:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
if ($allupdateuuid != '') {
$allupdateuuid = substr($allupdateuuid, 0, -1);
if ($mysqlcon->exec("UPDATE $dbname.stats_user set rank = CASE uuid $allupdaterank END, count_week = CASE uuid $allupdatecountw END, count_month = CASE uuid $allupdatecountm END, idle_week = CASE uuid $allupdateidlew END, idle_month = CASE uuid $allupdateidlem END, total_connections = CASE uuid $allupdatetotac END, base64hash = CASE uuid $allupdatebase64 END, client_total_up = CASE uuid $allupdatecldtup END, client_total_down = CASE uuid $allupdatecldtdo END, client_description = CASE uuid $allupdateclddes END WHERE uuid IN ($allupdateuuid)") === false) {
enter_logfile($logpath,$timezone,2,"calc_userstats 12:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
@@ -157,23 +133,8 @@ function calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,
$allinsertuserstats = substr($allinsertuserstats, 0, -1);
if ($mysqlcon->exec("INSERT INTO $dbname.stats_user (uuid,rank,count_week,count_month,idle_week,idle_month,total_connections,base64hash,client_total_up,client_total_down,client_description) VALUES $allinsertuserstats") === false) {
enter_logfile($logpath,$timezone,2,"calc_userstats 13:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
}
$buildtime = microtime(true) - $starttime;
if ($buildtime < 0) { $buildtime = 0; }
if ($sqlerr == 0) {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='0', runtime='$buildtime' WHERE id='$jobid'") === false) {
enter_logfile($logpath,$timezone,2,"calc_userstats 14:".print_r($mysqlcon->errorInfo()));
}
} else {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='1', err_msg='$sqlmsg', runtime='$buildtime' WHERE id='$jobid'") === false) {
enter_logfile($logpath,$timezone,2,"calc_userstats 15:".print_r($mysqlcon->errorInfo()));
}
}
}
?>

View File

@@ -1,6 +1,6 @@
<?PHP
function check_db($mysqlcon,$lang,$dbname,$timezone,$currvers,$logpath) {
$newversion = '1.1.0';
$newversion = '1.1.1';
enter_logfile($logpath,$timezone,5,"Check Ranksystem database for updates.");
function set_new_version($mysqlcon,$dbname,$timezone,$newversion,$logpath) {
@@ -27,7 +27,7 @@ function check_db($mysqlcon,$lang,$dbname,$timezone,$currvers,$logpath) {
}
}
function old_files($timezone) {
function old_files($timezone,$logpath) {
if(is_file(substr(__DIR__,0,-4).'install.php')) {
if(!unlink('install.php')) {
enter_logfile($logpath,$timezone,4,"Unnecessary file, please delete it from your webserver: install.php");
@@ -113,11 +113,16 @@ function check_db($mysqlcon,$lang,$dbname,$timezone,$currvers,$logpath) {
enter_logfile($logpath,$timezone,4,"Unnecessary file, please delete it from your webserver: bootstrap/js/_bootstrap.js");
}
}
if(is_file(substr(__DIR__,0,-4).'server-news')) {
if(!unlink(substr(__DIR__,0,-4).'server-news')) {
enter_logfile($logpath,$timezone,4,"Unnecessary file, please delete it from your webserver: server-news");
}
}
}
if($currvers==$newversion) {
enter_logfile($logpath,$timezone,5," No newer version detected; Database check finished.");
old_files($timezone);
old_files($timezone,$logpath);
check_chmod($timezone);
} elseif($currvers=="0.13-beta") {
enter_logfile($logpath,$timezone,4," Update the Ranksystem Database to version 1.0.1");
@@ -246,7 +251,7 @@ function check_db($mysqlcon,$lang,$dbname,$timezone,$currvers,$logpath) {
if ($errcount == 1) {
$currvers = set_new_version($mysqlcon,$dbname,$timezone,$newversion,$logpath);
old_files($timezone);
old_files($timezone,$logpath);
check_chmod($timezone);
} else {
enter_logfile($logpath,$timezone,1,"An error happens due updating the Ranksystem Database!");
@@ -254,29 +259,66 @@ function check_db($mysqlcon,$lang,$dbname,$timezone,$currvers,$logpath) {
exit;
}
} else {
enter_logfile($logpath,$timezone,4," Update the Ranksystem Database to new version...");
if($mysqlcon->exec("CREATE INDEX serverusage_timestamp ON $dbname.server_usage (timestamp)") === false) { }
if($mysqlcon->exec("ALTER TABLE $dbname.config ADD (advancemode int(1) NOT NULL default '0', count_access int(2) NOT NULL default '0', last_access bigint(11) NOT NULL default '0', ignoreidle bigint(11) NOT NULL default '0', exceptcid text CHARACTER SET utf8 COLLATE utf8_unicode_ci, rankupmsg text CHARACTER SET utf8 COLLATE utf8_unicode_ci, boost_mode int(1) NOT NULL default '0', newversion varchar(25) CHARACTER SET utf8 COLLATE utf8_unicode_ci)") === false) { } else {
enter_logfile($logpath,$timezone,4," Adjusted table config successfully.");
enter_logfile($logpath,$timezone,4," [1.1.0] Adjusted table config successfully.");
}
if($mysqlcon->exec("UPDATE $dbname.config set ignoreidle='600', rankupmsg='\\nHey, you got a rank up, cause you reached an activity of %s days, %s hours, %s minutes and %s seconds.', newversion='1.1.0'") === false) { } else {
enter_logfile($logpath,$timezone,4," Set default values to new fields in table config.");
if(version_compare($currvers, '1.1.0', '<')) {
if($mysqlcon->exec("UPDATE $dbname.config set ignoreidle='600', rankupmsg='\\nHey, you got a rank up, cause you reached an activity of %s days, %s hours, %s minutes and %s seconds.', newversion='1.1.0'") === false) { } else {
enter_logfile($logpath,$timezone,4," [1.1.0] Set default values to new fields in table config.");
}
}
if($mysqlcon->exec("INSERT INTO $dbname.job_check (job_name) VALUES ('get_version')") === false) { } else {
enter_logfile($logpath,$timezone,4," Set new values to table job_check.");
enter_logfile($logpath,$timezone,4," [1.1.0] Set new values to table job_check.");
}
if(($password = $mysqlcon->query("SELECT webpass FROM $dbname.config")) === false) { }
$password = $password->fetchAll();
if(strlen($password[0]['webpass']) != 60) {
$newwebpass = password_hash($password[0]['webpass'], PASSWORD_DEFAULT);
if($mysqlcon->exec("UPDATE $dbname.config set webpass='$newwebpass'") === false) { } else {
enter_logfile($logpath,$timezone,4," Encrypted password for the webinterface and wrote hash to database.");
enter_logfile($logpath,$timezone,4," [1.1.0] Encrypted password for the webinterface and wrote hash to database.");
}
}
if($mysqlcon->exec("ALTER TABLE $dbname.config DROP COLUMN showexgrp, DROP COLUMN showgen, DROP COLUMN bgcolor, DROP COLUMN hdcolor, DROP COLUMN txcolor, DROP COLUMN hvcolor, DROP COLUMN ifcolor, DROP COLUMN wncolor, DROP COLUMN sccolor") === false) { } else {
enter_logfile($logpath,$timezone,4," Delete old configs, which are no more needed.");
enter_logfile($logpath,$timezone,4," [1.1.0] Delete old configs, which are no more needed.");
}
if(version_compare($currvers, '1.1.0', '<=')) {
if($mysqlcon->exec("ALTER TABLE $dbname.user CHANGE ip clientip bigint(11) NOT NULL default '0'") === false) { }
if($mysqlcon->exec("ALTER TABLE $dbname.user ADD ip VARBINARY(16) DEFAULT NULL") === false) { } else {
enter_logfile($logpath,$timezone,4," [1.1.1] Adjusted table user successfully.");
}
if(($dbuserdata = $mysqlcon->query("SELECT uuid,clientip FROM $dbname.user")) === false) { }
$uuids = $dbuserdata->fetchAll();
foreach($uuids as $uuid) {
$sqlhis[$uuid['uuid']] = array(
"uuid" => $uuid['uuid'],
"ip" => $mysqlcon->quote(inet_pton(long2ip($uuid['clientip'])), ENT_QUOTES)
);
}
foreach ($sqlhis as $updatearr) {
$allupdateuuid = $allupdateuuid . "'" . $updatearr['uuid'] . "',";
$allupdateip = $allupdateip . "WHEN '" . $updatearr['uuid'] . "' THEN " . $updatearr['ip'] . " ";
}
$allupdateuuid = substr($allupdateuuid, 0, -1);
if($mysqlcon->exec("UPDATE $dbname.user set ip = CASE uuid $allupdateip END WHERE uuid IN ($allupdateuuid)") === false) { } else {
enter_logfile($logpath,$timezone,4," [1.1.1] Converted client IP successfully for IPv6 support.");
}
if($mysqlcon->exec("ALTER TABLE $dbname.user DROP COLUMN clientip") === false) { } else {
enter_logfile($logpath,$timezone,4," [1.1.1] Delete unconverted IP(v4), which are no more needed.");
}
if($mysqlcon->exec("ALTER TABLE $dbname.config ADD (servernews text CHARACTER SET utf8 COLLATE utf8_unicode_ci)") === false) { } else {
$servernews = $mysqlcon->quote(file_get_contents('../server-news'));
if($mysqlcon->exec("INSERT INTO $dbname.config (servernews) VALUES ($servernews)") === false) { } else {
enter_logfile($logpath,$timezone,4," [1.1.1] Adjusted table config successfully.");
}
}
if($mysqlcon->exec("DROP TABLE $dbname.job_log") === false) { } else {
enter_logfile($logpath,$timezone,4," [1.1.1] Drop table job_log, which is no more needed.");
}
}
$currvers = set_new_version($mysqlcon,$dbname,$timezone,$newversion,$logpath);
old_files($timezone);
old_files($timezone,$logpath);
check_chmod($timezone);
}
return $currvers;

View File

@@ -1,23 +1,16 @@
<?PHP
function clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$cleanclients,$cleanperiod,$logpath) {
$starttime = microtime(true);
$sqlmsg = '';
$sqlerr = 0;
function clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$cleanclients,$cleanperiod,$logpath) {
$count_tsuser['count'] = 0;
$nowtime = time();
// clean old logs
if($mysqlcon->query("DELETE a FROM $dbname.job_log AS a CROSS JOIN(SELECT id FROM $dbname.job_log ORDER BY id DESC LIMIT 1 OFFSET 1000) AS b WHERE b.id>a.id") === false) {
enter_logfile($logpath,$timezone,2,"clean 1:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
// clean usersnaps older then 1 month
if($mysqlcon->query("DELETE a FROM $dbname.user_snapshot AS a CROSS JOIN(SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 1000 OFFSET 121) AS b WHERE a.timestamp=b.timestamp") === false) {
enter_logfile($logpath,$timezone,2,"clean 2:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
enter_logfile($logpath,$timezone,2,"clean 2.1:".print_r($mysqlcon->errorInfo()));
}
// clean old server usage - older then a year
if($mysqlcon->query("DELETE FROM $dbname.server_usage WHERE timestamp < (UNIX_TIMESTAMP() - 31536000)") === false) {
enter_logfile($logpath,$timezone,2,"clean 2.2:".print_r($mysqlcon->errorInfo()));
}
// clean old clients out of the database
@@ -25,18 +18,14 @@ function clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$cleancli
$cleantime = $nowtime - $cleanperiod;
if(($lastclean = $mysqlcon->query("SELECT * FROM $dbname.job_check WHERE job_name='check_clean'")) === false) {
enter_logfile($logpath,$timezone,2,"clean 3:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$lastclean = $lastclean->fetchAll();
if(($dbuserdata = $mysqlcon->query("SELECT uuid FROM $dbname.user")) === false) {
enter_logfile($logpath,$timezone,2,"clean 4:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$countrs = $dbuserdata->rowCount();
$uuids = $dbuserdata->fetchAll();
if ($lastclean[0]['timestamp'] < $cleantime) {
if(($dbuserdata = $mysqlcon->query("SELECT uuid FROM $dbname.user")) === false) {
enter_logfile($logpath,$timezone,2,"clean 4:".print_r($mysqlcon->errorInfo()));
}
$countrs = $dbuserdata->rowCount();
$uuids = $dbuserdata->fetchAll();
enter_logfile($logpath,$timezone,4,$lang['clean']);
$start=0;
$break=200;
@@ -81,14 +70,10 @@ function clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$cleancli
if ($alldeldata != '') {
if($mysqlcon->exec("DELETE FROM $dbname.user WHERE uuid IN $alldeldata") === false) {
enter_logfile($logpath,$timezone,2,"clean 5:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
} else {
enter_logfile($logpath,$timezone,4," ".sprintf($lang['cleandel'], $countdel));
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='check_clean'") === false) {
enter_logfile($logpath,$timezone,2,"clean 6:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
}
@@ -96,24 +81,9 @@ function clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$cleancli
enter_logfile($logpath,$timezone,4," ".$lang['cleanno']);
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='check_clean'") === false) {
enter_logfile($logpath,$timezone,2,"clean 7:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
}
}
$buildtime = microtime(true) - $starttime;
if ($buildtime < 0) { $buildtime = 0; }
if ($sqlerr == 0) {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='0', runtime='$buildtime' WHERE id='$jobid'") === false) {
enter_logfile($logpath,$timezone,2,"clean 8:".print_r($mysqlcon->errorInfo()));
}
} else {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='1', err_msg='$sqlmsg', runtime='$buildtime' WHERE id='$jobid'") === false) {
enter_logfile($logpath,$timezone,2,"clean 9:".print_r($mysqlcon->errorInfo()));
}
}
}
?>

View File

@@ -1,8 +1,5 @@
<?PHP
function get_avatars($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$logpath) {
$starttime = microtime(true);
$sqlmsg = '';
$sqlerr = 0;
function get_avatars($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$logpath) {
$count = 0;
try {
@@ -11,8 +8,6 @@ function get_avatars($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$lo
} catch (Exception $e) {
if ($e->getCode() != 1281) {
enter_logfile($logpath,$timezone,2,"get_avatars 1:".$e->getCode().': '."Error while getting avatarlist: ".$e->getMessage());
$sqlmsg .= $e->getCode() . ': ' . "Error while getting avatarlist: " . $e->getMessage();
$sqlerr++;
}
}
$fsfilelist = opendir(substr(__DIR__,0,-4).'avatars/');
@@ -42,25 +37,10 @@ function get_avatars($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$lo
}
catch (Exception $e) {
enter_logfile($logpath,$timezone,2,"get_avatars 2:".$e->getCode().': '."Error while downloading avatar: ".$e->getMessage());
$sqlmsg .= $e->getCode() . ': ' . "Error while downloading avatar: " . $e->getMessage();
$sqlerr++;
}
}
}
}
}
$buildtime = microtime(true) - $starttime;
if ($buildtime < 0) { $buildtime = 0; }
if ($sqlerr == 0) {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='0', runtime='$buildtime' WHERE id='$jobid'") === false) {
enter_logfile($logpath,$timezone,2,"get_avatars 3:".print_r($mysqlcon->errorInfo()));
}
} else {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='1', err_msg='$sqlmsg', runtime='$buildtime' WHERE id='$jobid'") === false) {
enter_logfile($logpath,$timezone,2,"get_avatars 4:".print_r($mysqlcon->errorInfo()));
}
}
}
?>

View File

@@ -1,17 +1,12 @@
<?PHP
function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$serverinfo,$logpath) {
$starttime = microtime(true);
$sqlmsg = '';
$sqlerr = 0;
function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serverinfo,$logpath) {
try {
check_shutdown($timezone,$logpath); usleep($slowmode);
$iconlist = $ts3->channelFileList($cid="0", $cpw="", $path="/icons/");
} catch (Exception $e) {
if ($e->getCode() != 1281) {
enter_logfile($logpath,$timezone,2,"update_groups 1:".$e->getCode().': '."Error while getting servergrouplist: ".$e->getMessage());
$sqlmsg .= $e->getCode() . ': ' . "Error by getting servergrouplist: " . $e->getMessage();
$sqlerr++;
}
}
@@ -26,14 +21,10 @@ function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$
$ts3groups = $ts3->serverGroupList();
} catch (Exception $e) {
enter_logfile($logpath,$timezone,2,"update_groups 2:".$e->getCode().': '."Error while getting servergrouplist: ".$e->getMessage());
$sqlmsg .= $e->getCode() . ': ' . "Error by getting servergrouplist: " . $e->getMessage();
$sqlerr++;
}
if(($dbgroups = $mysqlcon->query("SELECT * FROM $dbname.groups")) === false) {
enter_logfile($logpath,$timezone,2,"update_groups 3:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
if ($dbgroups->rowCount() == 0) {
$sqlhisgroup = "empty";
@@ -64,8 +55,6 @@ function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$
}
} catch (Exception $e) {
enter_logfile($logpath,$timezone,2,"update_groups 4:".$e->getCode().': '."Error while downloading servericon: ".$e->getMessage());
$sqlmsg .= $e->getCode() . ': ' . "Error while downloading servericon: " . $e->getMessage();
$sqlerr++;
}
}
if (!isset($sqlhisgroup['0'])) {
@@ -99,18 +88,24 @@ function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$
if($iconid > 600) {
if (!isset($sqlhisgroup[$sgid]) || $sqlhisgroup[$sgid]['iconid'] != $iconid || $iconarr["i".$iconid] > $sqlhisgroup[$sgid]['icondate']) {
try {
check_shutdown($timezone,$logpath); usleep($slowmode);
enter_logfile($logpath,$timezone,5,"Download new ServerGroupIcon for group ".$sgname." with ID: ".$sgid);
$iconfile = $servergroup->iconDownload();
try {
$iconfile = $servergroup->iconDownload();
} catch (Exception $e) {
enter_logfile($logpath,$timezone,2,"update_groups 5:".$e->getCode().': '."Error while downloading servericon: ".$e->getMessage());
}
if(file_put_contents(substr(dirname(__FILE__),0,-4) . "icons/" . $sgid . ".png", $iconfile) === false) {
enter_logfile($logpath,$timezone,2,"Error while writing out the servergroup icon. Please check the permission for the folder 'icons'");
}
} catch (Exception $e) {
enter_logfile($logpath,$timezone,2,"update_groups 5:".$e->getCode().': '."Error while downloading servergroup icon: ".$e->getMessage());
$sqlmsg .= $e->getCode() . ': ' . "Error while downloading servergroup icon: " . $e->getMessage();
$sqlerr++;
enter_logfile($logpath,$timezone,2,"update_groups 6:".$e->getCode().': '."Error while downloading servergroup icon: ".$e->getMessage());
}
}
}
if(!isset($iconarr["i".$iconid])) {
$iconarr["i".$iconid] = 0;
}
if ($sqlhisgroup != "empty") {
foreach ($sqlhisgroup as $groups) {
if ($groups['sgid'] == $sgid) {
@@ -120,7 +115,7 @@ function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$
"sgidname" => $sgname,
"iconid" => $iconid,
"icon" => $iconfile,
"icondate" => $iconarr["i".$iconid]
"icondate" => $groups['icondate']
);
break;
}
@@ -148,7 +143,7 @@ function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$
if (isset($insertgroups)) {
$allinsertdata = '';
foreach ($insertgroups as $insertarr) {
if( $insertarr['iconid'] == 0) {
if( $insertarr['iconid'] == 0 || $insertarr['icondate'] == null || $insertarr['icondate'] == 0) {
//enter_logfile($logpath,$timezone,6,"IconID is 0 for (servergroup) ".$insertarr['sgidname']." (".$insertarr['sgid'].")");
continue;
}
@@ -157,9 +152,7 @@ function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$
$allinsertdata = substr($allinsertdata, 0, -1);
if ($allinsertdata != '') {
if($mysqlcon->exec("INSERT INTO $dbname.groups (sgid, sgidname, iconid, icondate) VALUES $allinsertdata") === false) {
enter_logfile($logpath,$timezone,2,"update_groups 6:".$allinsertdata.print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
enter_logfile($logpath,$timezone,2,"update_groups 7:".$allinsertdata.print_r($mysqlcon->errorInfo()));
}
}
}
@@ -177,9 +170,7 @@ function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$
}
$allsgids = substr($allsgids, 0, -1);
if($mysqlcon->exec("UPDATE $dbname.groups set sgidname = CASE sgid $allupdatesgid END, iconid = CASE sgid $allupdateiconid END, icondate = CASE sgid $allupdatedate END WHERE sgid IN ($allsgids)") === false) {
enter_logfile($logpath,$timezone,2,"update_groups 7:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
enter_logfile($logpath,$timezone,2,"update_groups 8:".print_r($mysqlcon->errorInfo()));
}
}
@@ -193,24 +184,9 @@ function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$
if(isset($delsgroupids)) {
$delsgroupids = substr($delsgroupids, 0, -1);
if($mysqlcon->exec("DELETE FROM groups WHERE sgid IN ($delsgroupids)") === false) {
enter_logfile($logpath,$timezone,2,"update_groups 8:".print_r($mysqlcon->errorInfo()));
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
$buildtime = microtime(true) - $starttime;
if ($buildtime < 0) { $buildtime = 0; }
if ($sqlerr == 0) {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='0', runtime='$buildtime' WHERE id='$jobid'") === false) {
if($mysqlcon->exec("DELETE FROM $dbname.groups WHERE sgid IN ($delsgroupids)") === false) {
enter_logfile($logpath,$timezone,2,"update_groups 9:".print_r($mysqlcon->errorInfo()));
}
} else {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='1', err_msg='$sqlmsg', runtime='$buildtime' WHERE id='$jobid'") === false) {
enter_logfile($logpath,$timezone,2,"update_groups 10:".print_r($mysqlcon->errorInfo()));
}
}
}
?>