2013-08-28 22:47:04 +02:00
< ? php
2013-10-03 12:49:13 +02:00
2013-08-28 22:47:04 +02:00
/**
* File : statuscheck . php .
* Author : Ulrich Block
* Date : 03.10 . 12
* Time : 17 : 09
* Contact : < ulrich . block @ easy - wi . com >
*
* This file is part of Easy - WI .
*
* Easy - WI is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* Easy - WI is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with Easy - WI . If not , see < http :// www . gnu . org / licenses />.
*
* Diese Datei ist Teil von Easy - WI .
*
* Easy - WI ist Freie Software : Sie koennen es unter den Bedingungen
* der GNU General Public License , wie von der Free Software Foundation ,
* Version 3 der Lizenz oder ( nach Ihrer Wahl ) jeder spaeteren
* veroeffentlichten Version , weiterverbreiten und / oder modifizieren .
*
* Easy - WI wird in der Hoffnung , dass es nuetzlich sein wird , aber
* OHNE JEDE GEWAEHELEISTUNG , bereitgestellt ; sogar ohne die implizite
* Gewaehrleistung der MARKTFAEHIGKEIT oder EIGNUNG FUER EINEN BESTIMMTEN ZWECK .
* Siehe die GNU General Public License fuer weitere Details .
*
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
* Programm erhalten haben . Wenn nicht , siehe < http :// www . gnu . org / licenses />.
*/
if ( isset ( $_SERVER [ 'REMOTE_ADDR' ])) {
2013-10-20 12:02:02 +02:00
$ip = $_SERVER [ 'REMOTE_ADDR' ];
$timelimit = ( isset ( $_GET [ 'timeout' ]) and is_numeric ( $_GET [ 'timeout' ])) ? $_GET [ 'timeout' ] : ini_get ( 'max_execution_time' ) - 10 ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-20 12:02:02 +02:00
$timelimit = 600 ;
2013-08-28 22:47:04 +02:00
}
2014-01-01 13:59:37 +01:00
2013-08-28 22:47:04 +02:00
if ( isset ( $argv )) {
2014-01-01 13:59:37 +01:00
2013-09-29 15:29:58 +02:00
$args = array ();
2014-01-01 13:59:37 +01:00
2013-08-28 22:47:04 +02:00
foreach ( $argv as $a ) {
2014-05-01 19:20:28 +02:00
if ( $a == 'gs' or $a == 'vs' or $a == 'vh' or $a == 'my' or $a == 'st' ) {
2014-01-01 13:59:37 +01:00
$checkTypeOfServer = $a ;
} else if ( is_numeric ( $a )) {
$sleep = $a ;
} else {
2013-10-03 12:49:13 +02:00
$e = explode ( ':' , $a );
2014-01-01 13:59:37 +01:00
if ( isset ( $e [ 1 ])) {
$args [ $e [ 0 ]] = $e [ 1 ];
}
2013-08-28 22:47:04 +02:00
}
}
}
2013-10-20 12:02:02 +02:00
define ( 'EASYWIDIR' , dirname ( __FILE__ ));
2014-02-23 13:13:48 +01:00
include ( EASYWIDIR . '/stuff/methods/vorlage.php' );
include ( EASYWIDIR . '/stuff/methods/functions.php' );
include ( EASYWIDIR . '/stuff/methods/class_validator.php' );
2013-10-20 12:02:02 +02:00
include ( EASYWIDIR . '/stuff/settings.php' );
2014-02-23 13:13:48 +01:00
include ( EASYWIDIR . '/stuff/methods/functions_gs.php' );
include ( EASYWIDIR . '/stuff/methods/functions_ssh_exec.php' );
include ( EASYWIDIR . '/stuff/methods/class_ts3.php' );
2013-11-27 20:26:19 +01:00
include ( EASYWIDIR . '/third_party/gameq/GameQ.php' );
2014-03-30 12:54:42 +02:00
include ( EASYWIDIR . '/stuff/methods/class_mysql.php' );
2014-04-12 15:40:14 +02:00
include ( EASYWIDIR . '/stuff/methods/class_httpd.php' );
2013-10-20 12:02:02 +02:00
include ( EASYWIDIR . '/stuff/keyphrasefile.php' );
2013-08-28 22:47:04 +02:00
set_time_limit ( $timelimit );
2013-10-20 12:02:02 +02:00
2014-03-30 12:54:42 +02:00
$query = $sql -> prepare ( " UPDATE `settings` SET `lastCronStatus`=UNIX_TIMESTAMP() " );
$query -> execute ();
2013-10-20 12:02:02 +02:00
if ( ! isset ( $ip ) or $ui -> escaped ( 'SERVER_ADDR' , 'server' ) == $ip or in_array ( $ip , ipstoarray ( $rSA [ 'cronjob_ips' ]))) {
if ( isset ( $checkTypeOfServer )) {
2014-03-30 12:54:42 +02:00
if ( $checkTypeOfServer == 'gs' ) {
print 'Checking Gameserver' . " \r \n " ;
2014-04-12 15:40:14 +02:00
} else if ( $checkTypeOfServer == 'vh' ) {
print 'Checking Web Quotas' . " \r \n " ;
2014-03-30 12:54:42 +02:00
} else if ( $checkTypeOfServer == 'vs' ) {
print 'Checking Voiceserver' . " \r \n " ;
2014-05-01 19:20:28 +02:00
} else if ( $checkTypeOfServer == 'st' ) {
print 'Checking Usage Statistics' . " \r \n " ;
2014-03-30 12:54:42 +02:00
} else {
print 'Getting MySQL DB sizes' . " \r \n " ;
}
2013-10-20 12:02:02 +02:00
} else {
$checkTypeOfServer = 'all' ;
2014-04-12 15:40:14 +02:00
print 'Checking Gameserver, Voiceserver MySQL DB sizes and Web Quotas' . " \r \n " ;
2013-10-20 12:02:02 +02:00
}
2013-08-28 22:47:04 +02:00
$dayAndHour = date ( 'Y-m-d H:' ) . '00:00' ;
$dayAndZeroHour = date ( 'Y-m-d' ) . ' 00:00:00' ;
2013-09-29 15:29:58 +02:00
$ssprache = getlanguagefile ( 'settings' , 'uk' , 0 );
$vosprache = getlanguagefile ( 'voice' , 'uk' , 0 );
$sprache = getlanguagefile ( 'gserver' , 'uk' , 0 );
2013-08-28 22:47:04 +02:00
2013-11-27 20:26:19 +01:00
// lendmodul active ?
$query = $sql -> prepare ( " SELECT `active` FROM `modules` WHERE `id`=5 LIMIT 1 " );
$query -> execute ();
$lendActive = $query -> fetchColumn ();
2013-12-27 14:42:39 +01:00
$lendActive = ( active_check ( $lendActive )) ? $lendActive : 'Y' ;
2013-11-27 20:26:19 +01:00
2013-08-28 22:47:04 +02:00
# Pick up Reseller and Lend Settings
2013-09-29 15:29:58 +02:00
$resellersettings = array ();
$query = $sql -> prepare ( " SELECT `brandname`,`noservertag`,`nopassword`,`tohighslots`,`down_checks`,`resellerid` FROM `settings` " );
2013-11-27 20:26:19 +01:00
$query2 = $sql -> prepare ( " SELECT `shutdownempty`,`shutdownemptytime`,`lastcheck`,`oldcheck` FROM `lendsettings` WHERE `resellerid`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$query -> execute ();
foreach ( $query -> fetchall ( PDO :: FETCH_ASSOC ) as $row ) {
2014-02-02 09:37:31 +01:00
2013-11-27 20:26:19 +01:00
unset ( $shutdownempty );
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
$resellerid = $row [ 'resellerid' ];
2014-02-02 09:37:31 +01:00
2013-08-28 22:47:04 +02:00
$query2 -> execute ( array ( $resellerid ));
foreach ( $query2 -> fetchall ( PDO :: FETCH_ASSOC ) as $row2 ) {
2013-10-03 12:49:13 +02:00
$shutdownempty = $row2 [ 'shutdownempty' ];
$shutdownemptytime = $row2 [ 'shutdownemptytime' ];
2014-01-10 22:16:51 +01:00
$firstcheck = '00-00-' . round ( 2 * ( strtotime ( $row2 [ 'lastcheck' ]) - strtotime ( $row2 [ 'oldcheck' ])) / 60 );
$firstchecktime = date ( 'd-G-i' );
2013-08-28 22:47:04 +02:00
}
2014-02-02 09:37:31 +01:00
2013-11-27 20:26:19 +01:00
if ( isset ( $shutdownempty )) {
$resellersettings [ $resellerid ] = array ( 'shutdownempty' => $shutdownempty , 'shutdownemptytime' => $shutdownemptytime , 'firstchecktime' => $firstchecktime , 'firstcheck' => $firstcheck , 'brandname' => $row [ 'brandname' ], 'noservertag' => $row [ 'noservertag' ], 'nopassword' => $row [ 'nopassword' ], 'tohighslots' => $row [ 'tohighslots' ], 'down_checks' => $row [ 'down_checks' ]);
}
2013-08-28 22:47:04 +02:00
}
2014-02-02 09:37:31 +01:00
2013-10-13 11:42:31 +02:00
$query = $sql -> prepare ( " UPDATE `lendsettings` SET `oldcheck`=`lastcheck`,`lastcheck`=NOW() " );
2013-08-28 22:47:04 +02:00
$query -> execute ();
# Game Server
2013-10-03 12:49:13 +02:00
if ( $checkTypeOfServer == 'all' or $checkTypeOfServer == 'gs' ) {
2013-10-13 17:11:32 +02:00
2013-11-27 20:26:19 +01:00
// Lend server stopping.
2013-10-13 17:11:32 +02:00
// We want only one socket per root server. Collect the to be stopped lendservers in an array and sort by root ID
$rtmp = array ();
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT `id`,`serverid`,`started`,`lendtime`,`resellerid` FROM `lendedserver` WHERE `servertype`='g' " );
2013-10-13 17:11:32 +02:00
$query2 = $sql -> prepare ( " SELECT g.`rootID`,g.`id` FROM `serverlist` s INNER JOIN `gsswitch` g ON s.`switchID`=g.`id` WHERE s.`id`=? LIMIT 1 " );
$query3 = $sql -> prepare ( " DELETE FROM `lendedserver` WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$query -> execute ();
foreach ( $query -> fetchall ( PDO :: FETCH_ASSOC ) as $row ) {
2013-10-03 12:49:13 +02:00
$id = $row [ 'id' ];
$lendtime = $row [ 'lendtime' ];
2013-10-13 17:11:32 +02:00
$serverid = $row [ 'serverid' ];
2013-10-03 12:49:13 +02:00
$resellerid = $row [ 'resellerid' ];
$timeleft = round ( $row [ 'lendtime' ] - ( strtotime ( 'now' ) - strtotime ( $row [ 'started' ])) / 60 );
2013-10-13 17:11:32 +02:00
2013-10-03 12:49:13 +02:00
if ( $timeleft <= 0 ) {
2013-10-13 17:11:32 +02:00
$query3 -> execute ( array ( $id , $resellerid ));
$query2 -> execute ( array ( $row [ 'serverid' ]));
foreach ( $query2 -> fetchAll ( PDO :: FETCH_ASSOC ) as $row2 ) {
$tmp = gsrestart ( $row2 [ 'id' ], 'so' , $aeskey , $resellerid );
if ( is_array ( $tmp )) {
foreach ( $tmp as $t ) {
$rtmp [ $row2 [ 'rootID' ]][] = $t ;
}
}
}
2013-08-28 22:47:04 +02:00
print " Time is up, stopping lendserver: $id\r\n " ;
2013-10-13 17:11:32 +02:00
2013-08-28 22:47:04 +02:00
} else {
print " Lendserver $serverid has $timeleft minutes left \r \n " ;
}
}
2013-10-13 17:11:32 +02:00
// Send stop commands to rootserver
foreach ( $rtmp as $k => $v ) {
if ( count ( $v ) > 0 ) {
ssh2_execute ( 'gs' , $k , $v );
}
}
2013-11-27 20:26:19 +01:00
// Define basic variables for GS status checks
2013-09-29 15:29:58 +02:00
$other = array ();
$i = 1 ;
2013-11-27 20:26:19 +01:00
$totalCount = 0 ;
$serverBatchArray = array ();
$allServersArray = array ();
$shellCmds = array ();
2013-10-13 17:11:32 +02:00
2013-11-27 20:26:19 +01:00
// Get the list of servers which are active and are not stopped. The array to be created will support batch mode.
$query = $sql -> prepare ( " SELECT g.`id`,g.`rootID`,g.`serverid`,g.`serverip`,g.`port`,g.`port2`,t.`gameq` FROM `gsswitch` g INNER JOIN `serverlist` s ON g.`serverid`=s.`id` INNER JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE g.`stopped`='N' AND g.`active`='Y' " );
2013-08-28 22:47:04 +02:00
$query -> execute ();
foreach ( $query -> fetchAll ( PDO :: FETCH_ASSOC ) as $row ) {
2013-10-13 17:11:32 +02:00
2013-11-27 20:26:19 +01:00
// without the gameq value we cannot query. So this results need to be sorted out.
if ( ! in_array ( $row [ 'gameq' ], array ( '' , null , false ))) {
2013-10-13 17:11:32 +02:00
2014-03-30 11:59:03 +02:00
if ( in_array ( $row [ 'gameq' ], array ( 'cube2' , 'ut' , 'ut2004' , 'ut3' , 'mta' ))) {
2014-01-26 11:15:39 +01:00
$checkAtIPPort = $row [ 'serverip' ] . ':' . $row [ 'port2' ];
} else {
$checkAtIPPort = $row [ 'serverip' ] . ':' . $row [ 'port' ];
}
$serverBatchArray [] = array ( 'id' => $row [ 'id' ], 'type' => $row [ 'gameq' ], 'host' => $checkAtIPPort );
2013-11-27 20:26:19 +01:00
$i ++ ;
2013-10-13 17:11:32 +02:00
2013-10-03 16:48:54 +02:00
if ( $i == 50 ) {
2013-11-27 20:26:19 +01:00
$allServersArray [] = $serverBatchArray ;
$serverBatchArray = array ();
2013-09-29 15:29:58 +02:00
$i = 1 ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 17:11:32 +02:00
2013-11-27 20:26:19 +01:00
$totalCount ++ ;
2013-08-28 22:47:04 +02:00
}
}
2013-10-13 17:11:32 +02:00
2013-11-27 20:26:19 +01:00
$allServersArray [] = $serverBatchArray ;
2013-10-13 17:11:32 +02:00
2013-11-27 20:26:19 +01:00
print " Checking $totalCount server(s) with GameQ query \r \n " ;
2013-10-13 17:11:32 +02:00
2013-11-27 20:26:19 +01:00
foreach ( $allServersArray as $servers ) {
2014-02-02 09:37:31 +01:00
2013-11-27 20:26:19 +01:00
$gq = new GameQ ();
$gq -> setOption ( 'timeout' , 3 );
2013-10-13 17:11:32 +02:00
2013-11-27 20:26:19 +01:00
if ( isset ( $dbConnect [ 'debug' ]) and $dbConnect [ 'debug' ] == 1 ) {
$gq -> setOption ( 'debug' , true );
2013-08-28 22:47:04 +02:00
}
2013-10-13 17:11:32 +02:00
2013-11-27 20:26:19 +01:00
$gq -> setFilter ( 'normalise' );
$gq -> addServers ( $servers );
2013-10-13 17:11:32 +02:00
2013-11-27 20:26:19 +01:00
foreach ( $gq -> requestData () as $switchID => $v ) {
2013-10-13 17:11:32 +02:00
2014-05-01 19:20:28 +02:00
unset ( $userid , $lendserver , $stopserver , $doNotRestart );
2014-02-02 09:37:31 +01:00
2013-09-29 15:29:58 +02:00
$lid = 0 ;
2013-11-27 20:26:19 +01:00
$elapsed = 0 ;
$shutdownemptytime = 0 ;
2013-12-01 15:57:23 +01:00
$notified = 0 ;
2013-11-27 20:26:19 +01:00
2014-01-01 17:44:57 +01:00
$query = $sql -> prepare ( " SELECT s.`id` AS `serverID`,t.`description`,t.`gamebinary`,g.* FROM `gsswitch` g INNER JOIN `serverlist` s ON g.`serverid`=s.`id` INNER JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE g.`id`=? LIMIT 1 " );
2013-11-27 20:26:19 +01:00
$query2 = $sql -> prepare ( " SELECT `id`,`started` FROM `lendedserver` WHERE `serverid`=? LIMIT 1 " );
$query -> execute ( array ( $switchID ));
2013-08-28 22:47:04 +02:00
foreach ( $query -> fetchall ( PDO :: FETCH_ASSOC ) as $row ) {
2014-02-02 09:37:31 +01:00
2013-11-27 20:26:19 +01:00
$serverip = $row [ 'serverip' ];
2014-01-01 14:19:37 +01:00
$autoRestart = $row [ 'autoRestart' ];
2013-11-27 20:26:19 +01:00
$port = $row [ 'port' ];
$address = $row [ 'serverip' ] . ':' . $row [ 'port' ];
$gametype = $row [ 'description' ];
2013-10-03 12:49:13 +02:00
$notified = $row [ 'notified' ];
$secnotified = $row [ 'secnotified' ];
2013-11-27 20:26:19 +01:00
$lendserver = $row [ 'lendserver' ];
2013-10-03 12:49:13 +02:00
$userid = $row [ 'userid' ];
2013-11-27 20:26:19 +01:00
$resellerid = $row [ 'resellerid' ];
2013-10-03 12:49:13 +02:00
$brandname = $row [ 'brandname' ];
2013-11-27 20:26:19 +01:00
$rootID = $row [ 'rootID' ];
2013-10-03 12:49:13 +02:00
$war = $row [ 'war' ];
2014-01-01 17:44:57 +01:00
$slots = $row [ 'slots' ];
if (( $row [ 'gamebinary' ] == 'hlds_run' or $row [ 'gamebinary' ] == 'srcds_run' ) and $row [ 'tvenable' ] == 'Y' ) {
$slots ++ ;
}
2013-11-27 20:26:19 +01:00
2014-05-01 19:20:28 +02:00
if ( $lendserver == 'Y' and $lendActive == 'Y' ) {
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
$shutdownemptytime = $resellersettings [ $resellerid ][ 'shutdownemptytime' ];
2014-02-02 09:37:31 +01:00
2014-01-01 17:44:57 +01:00
$query2 -> execute ( array ( $row [ 'serverID' ]));
2013-08-28 22:47:04 +02:00
foreach ( $query2 -> fetchall ( PDO :: FETCH_ASSOC ) as $row2 ) {
2013-10-03 12:49:13 +02:00
$lid = $row2 [ 'id' ];
2013-11-27 20:26:19 +01:00
$elapsed = round (( strtotime ( 'now' ) - strtotime ( $row2 [ 'started' ])) / 60 );
2013-08-28 22:47:04 +02:00
}
}
}
2013-11-27 20:26:19 +01:00
if ( $v [ 'gq_online' ] == 1 ) {
2014-01-30 19:03:02 +01:00
$name = normalizeName ( $v [ 'gq_hostname' ]);
2013-11-27 20:26:19 +01:00
$numplayers = $v [ 'gq_numplayers' ];
$maxplayers = $v [ 'gq_maxplayers' ];
$map = $v [ 'gq_mapname' ];
$password = ( $v [ 'gq_password' ] == 1 ) ? 'Y' : 'N' ;
} else {
$name = 'OFFLINE' ;
2013-09-29 15:29:58 +02:00
$numplayers = 0 ;
$maxplayers = 0 ;
$map = '' ;
2013-11-27 20:26:19 +01:00
$password = 'Y' ;
}
$returnCmd = array ();
// Check lendserver specific settings
2014-05-01 19:20:28 +02:00
if ( isset ( $userid ) and isset ( $lendserver ) and $lendserver == 'Y' ) {
2013-11-27 20:26:19 +01:00
// Running but no lend information in temp table
if ( $v [ 'gq_online' ] == 1 ) {
$query = $sql -> prepare ( " SELECT 1 FROM `lendedserver` WHERE `id`=? LIMIT 1 " );
$query -> execute ( array ( $lid ));
if ( $query -> rowCount () == 0 ) {
2013-12-01 15:57:23 +01:00
print " Will stop lendserver $address because not lendet \r \n " ;
2013-11-27 20:26:19 +01:00
$stopserver = true ;
}
if ( ! isset ( $stopserver ) and $lendserver == 'Y' and $lendActive == 'Y' and $resellersettings [ $resellerid ][ 'shutdownempty' ] == 'Y' and $elapsed > $shutdownemptytime and $numplayers == 0 and $maxplayers != 0 and $slots != 0 ) {
print " Will stop server $address after $elapsed minutes, because it is empty and threshold is $shutdownemptytime minutes \r \n " ;
$stopserver = true ;
2013-08-28 22:47:04 +02:00
}
}
2013-11-27 20:26:19 +01:00
// Expected to be running but is not, so remove from temp table
if ( isset ( $stopserver ) or $v [ 'gq_online' ] != 1 ) {
if ( ! isset ( $stopserver )) {
print " Will remove lendserver $address with lendID $lid because it is lendet but stopped \r \n " ;
2013-08-28 22:47:04 +02:00
}
2013-11-27 20:26:19 +01:00
$doNotRestart = true ;
$query = $sql -> prepare ( " DELETE FROM `lendedserver` WHERE `id`=? LIMIT 1 " );
$query -> execute ( array ( $lid ));
2013-08-28 22:47:04 +02:00
}
}
2013-11-27 20:26:19 +01:00
if ( isset ( $userid ) and $v [ 'gq_online' ] == 1 ) {
$rulebreak = array ();
if ( $war == 'Y' and $password == 'N' ) {
$rulebreak [] = $ssprache -> nopassword ;
if ( $resellersettings [ $resellerid ][ 'nopassword' ] == 1 ) {
$stopserver = true ;
print " Will stop server $address because running without password. The name converted to ISO-8859-1 is " . iconv ( 'UTF-8' , 'ISO-8859-1//TRANSLIT' , $name ) . " . \r \n " ;
} else {
print " Server with address $address is running as $gametype and illegal without password. The name converted to ISO-8859-1 is " . iconv ( 'UTF-8' , 'ISO-8859-1//TRANSLIT' , $name ) . " . \r \n " ;
2013-10-03 12:49:13 +02:00
}
}
2013-11-27 20:26:19 +01:00
if ( $maxplayers > $slots ) {
$rulebreak [] = $ssprache -> tohighslots ;
if ( $resellersettings [ $resellerid ][ 'tohighslots' ] == 1 ) {
$stopserver = true ;
print " Will stop server $address because running with to much slots. The name converted to ISO-8859-1 is " . iconv ( 'UTF-8' , 'ISO-8859-1//TRANSLIT' , $name ) . " . \r \n " ;
} else {
print " Server $address is running as $gametype and with illegal slotamount. The name converted to ISO-8859-1 is " . iconv ( 'UTF-8' , 'ISO-8859-1//TRANSLIT' , $name ) . " . \r \n " ;
}
2013-08-28 22:47:04 +02:00
}
2013-11-27 20:26:19 +01:00
if ( $brandname == 'Y' and $resellersettings [ $resellerid ][ 'brandname' ] != '' and strpos ( strtolower ( $name ), strtolower ( $resellersettings [ $resellerid ][ 'brandname' ])) === false ) {
$rulebreak [] = $ssprache -> noservertag ;
if ( $resellersettings [ $resellerid ][ 'noservertag' ] == 1 ) {
$stopserver = true ;
print " Will stop server $address because running without servertag. The name converted to ISO-8859-1 is " . iconv ( 'UTF-8' , 'ISO-8859-1//TRANSLIT' , $name ) . " . \r \n " ;
} else {
print " Server $address is running as $gametype and illegal without servertag. The name converted to ISO-8859-1 is " . iconv ( 'UTF-8' , 'ISO-8859-1//TRANSLIT' , $name ) . " . \r \n " ;
}
}
if ( count ( $rulebreak ) == 0 and ! isset ( $stopserver )) {
print " Server $address is running as $gametype . The name converted to ISO-8859-1 is " . iconv ( 'UTF-8' , 'ISO-8859-1//TRANSLIT' , $name ) . " . \r \n " ;
}
if ( $secnotified == 'N' and count ( $rulebreak ) > 0 ) {
if ( $resellerid == 0 ) {
$query = $sql -> prepare ( " SELECT `id`,`mail_securitybreach` FROM `userdata` WHERE `id`=? OR (`resellerid`=0 AND `accounttype`='a') " );
$query -> execute ( array ( $userid ));
} else {
$query = $sql -> prepare ( " SELECT `id`,`mail_securitybreach` FROM `userdata` WHERE `id`=? OR (`id`=? AND `accounttype`='r') " );
$query -> execute ( array ( $userid , $resellerid ));
}
foreach ( $query -> fetchall ( PDO :: FETCH_ASSOC ) as $row ) {
if ( $row [ 'mail_securitybreach' ] == 'Y' ) {
sendmail ( 'emailsecuritybreach' , $row [ 'id' ], $address , implode ( '<br>' , $rulebreak ));
}
}
$query = $sql -> prepare ( " UPDATE `gsswitch` SET `secnotified`='Y' WHERE `id`=? LIMIT 1 " );
$query -> execute ( array ( $switchID ));
}
if ( $secnotified == 'Y' and count ( $rulebreak ) == 0 ) {
$query = $sql -> prepare ( " UPDATE `gsswitch` SET `secnotified`='N' WHERE `id`=? LIMIT 1 " );
$query -> execute ( array ( $switchID ));
}
2013-12-31 19:42:43 +01:00
if ( isset ( $stopserver ) and $stopserver === true ) {
2013-11-27 20:26:19 +01:00
2013-09-29 15:29:58 +02:00
$numplayers = 0 ;
$map = '' ;
2013-11-27 20:26:19 +01:00
$tmp = gsrestart ( $switchID , 'so' , $aeskey , $resellerid );
if ( is_array ( $tmp )) {
foreach ( $tmp as $t ) {
$returnCmd [] = $t ;
}
}
$query = $sql -> prepare ( " DELETE FROM `lendedserver` WHERE `serverid`=? AND `resellerid`=? AND `servertype`='g' LIMIT 1 " );
$query -> execute ( array ( $switchID , $resellerid ));
2013-08-28 22:47:04 +02:00
}
2013-11-27 20:26:19 +01:00
if ( $notified > 0 ) {
$query = $sql -> prepare ( " UPDATE `gsswitch` SET `notified`=0 WHERE `id`=? LIMIT 1 " );
$query -> execute ( array ( $switchID ));
}
2014-01-01 14:19:37 +01:00
} else if ( isset ( $userid ) and isset ( $autoRestart )) {
2013-11-27 20:26:19 +01:00
$name = 'OFFLINE' ;
2013-09-29 15:29:58 +02:00
$numplayers = 0 ;
$maxplayers = 0 ;
$map = '' ;
2013-10-03 12:49:13 +02:00
$password = 'Y' ;
2013-11-27 20:26:19 +01:00
if ( ! isset ( $doNotRestart )) {
$notified ++ ;
2014-01-01 14:19:37 +01:00
if ( isset ( $dbConnect [ 'debug' ]) and $dbConnect [ 'debug' ] == 1 ) {
print_r ( $v );
}
2013-11-27 20:26:19 +01:00
2014-01-01 14:19:37 +01:00
if ( $autoRestart == 'Y' and $notified >= $resellersettings [ $resellerid ][ 'down_checks' ]) {
2013-11-27 20:26:19 +01:00
print " Restarting: $address\r\n " ;
$tmp = gsrestart ( $switchID , 're' , $aeskey , $resellerid );
if ( is_array ( $tmp )) {
foreach ( $tmp as $t ) {
$returnCmd [] = $t ;
}
}
} else {
print " Not Restarting: $address\r\n " ;
}
if ( $notified == $resellersettings [ $resellerid ][ 'down_checks' ]) {
$query = $sql -> prepare ( " SELECT `mail_serverdown` FROM `userdata` WHERE `id`=? LIMIT 1 " );
$query -> execute ( array ( $userid ));
foreach ( $query -> fetchall ( PDO :: FETCH_ASSOC ) as $row ) {
if ( $row [ 'mail_serverdown' ] == 'Y' ) {
sendmail ( 'emaildownrestart' , $userid , $address , '' );
}
}
}
2014-01-01 14:19:37 +01:00
} else {
print " Not Stopping as database leftover: $address\r\n " ;
2013-10-03 12:49:13 +02:00
}
2013-08-28 22:47:04 +02:00
}
2013-11-27 20:26:19 +01:00
$query = $sql -> prepare ( " UPDATE `gsswitch` SET `queryName`=?,`queryNumplayers`=?,`queryMaxplayers`=?,`queryMap`=?,`queryPassword`=?,`queryUpdatetime`=?,`notified`=? WHERE `id`=? LIMIT 1 " );
$query -> execute ( array ( $name , $numplayers , $maxplayers , $map , $password , $logdate , $notified , $switchID ));
foreach ( $returnCmd as $t ) {
$shellCmds [ $rootID ][] = $t ;
}
2013-08-28 22:47:04 +02:00
}
}
2013-11-27 20:26:19 +01:00
unset ( $gq );
2014-01-01 14:19:37 +01:00
if ( isset ( $dbConnect [ 'debug' ]) and $dbConnect [ 'debug' ] == 1 ) {
print_r ( $shellCmds );
}
2013-10-26 11:59:03 +02:00
foreach ( $shellCmds as $k => $v ) {
2013-10-03 12:49:13 +02:00
ssh2_execute ( 'gs' , $k , $v );
2013-08-29 23:37:49 +02:00
}
2013-08-28 22:47:04 +02:00
}
# Voice Server
2013-10-03 12:49:13 +02:00
if ( $checkTypeOfServer == 'all' or $checkTypeOfServer == 'vs' ) {
2013-08-28 22:47:04 +02:00
#voice_tsdns
2013-10-03 12:49:13 +02:00
print 'Checking TSDNS' . " \r \n " ;
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT *,AES_DECRYPT(`ssh2port`,:aeskey) AS `decryptedssh2port`,AES_DECRYPT(`ssh2user`,:aeskey) AS `decryptedssh2user`,AES_DECRYPT(`ssh2password`,:aeskey) AS `decryptedssh2password` FROM `voice_tsdns` WHERE `active`='Y' " );
2013-10-03 12:49:13 +02:00
$query -> execute ( array ( ':aeskey' => $aeskey ));
2013-08-28 22:47:04 +02:00
foreach ( $query -> fetchAll ( PDO :: FETCH_ASSOC ) as $row ) {
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
$resellerid = $row [ 'resellerid' ];
2014-02-02 09:37:31 +01:00
$tsdnscheck = @ fsockopen ( $row [ 'ssh2ip' ], 41144 , $errno , $errstr , 5 );
2013-10-03 12:49:13 +02:00
if ( ! is_resource ( $tsdnscheck ) and $row [ 'autorestart' ] == 'Y' ) {
2013-08-28 22:47:04 +02:00
sleep ( 1 );
2014-02-02 09:37:31 +01:00
$tsdnscheck = @ fsockopen ( $row [ 'ssh2ip' ], 41144 , $errno , $errstr , 5 );
2013-08-28 22:47:04 +02:00
}
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
if ( ! is_resource ( $tsdnscheck ) and $row [ 'autorestart' ] == 'Y' ) {
2014-02-02 09:37:31 +01:00
2013-09-29 15:29:58 +02:00
print " TSDNS Error: " . $row [ 'ssh2ip' ] . ' ' . $errno . ' (' . $errstr . " ) \r \n " ;
2014-02-02 09:37:31 +01:00
2013-09-29 15:29:58 +02:00
$query3 = $sql -> prepare ( " UPDATE `voice_tsdns` SET `notified`=`notified`+1 WHERE `id`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$query3 -> execute ( array ( $row [ 'id' ]));
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
$tsdnsDownCheck = $row [ 'notified' ] + 1 ;
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
if ( $tsdnsDownCheck == $resellersettings [ $resellerid ][ 'down_checks' ]) {
2014-02-02 09:37:31 +01:00
2013-08-28 22:47:04 +02:00
if ( $resellerid == 0 ) {
2013-09-29 15:29:58 +02:00
$query3 = $sql -> prepare ( " SELECT `id`,`mail_serverdown` FROM `userdata` WHERE `accounttype`='a' AND `resellerid`=0 " );
2013-08-28 22:47:04 +02:00
$query3 -> execute ();
} else {
2013-09-29 15:29:58 +02:00
$query3 = $sql -> prepare ( " SELECT `id`,`mail_serverdown` FROM `userdata` WHERE `id`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$query3 -> execute ( array ( $resellerid ));
}
2014-02-02 09:37:31 +01:00
2013-08-28 22:47:04 +02:00
foreach ( $query3 -> fetchAll ( PDO :: FETCH_ASSOC ) as $row3 ) {
2013-10-03 12:49:13 +02:00
if ( $row3 [ 'mail_serverdown' ] == 'Y' ) {
sendmail ( 'emaildownrestart' , $row3 [ 'id' ], $row [ 'ssh2ip' ] . ' (External TSDNS)' , '' );
2013-08-28 22:47:04 +02:00
}
}
}
2013-09-22 12:00:33 +02:00
2014-01-05 13:00:36 +01:00
unset ( $folders );
2014-02-02 09:37:31 +01:00
$i = 0 ;
2014-01-05 13:00:36 +01:00
$lastFolder = '' ;
2014-02-02 09:37:31 +01:00
$tsdnsbin = ( $row [ 'bitversion' ] == '32' ) ? 'tsdnsserver_linux_x86' : 'tsdnsserver_linux_amd64' ;
$split_config = preg_split ( '/\//' , $row [ 'serverdir' ], - 1 , PREG_SPLIT_NO_EMPTY );
$folderfilecount = count ( $split_config ) - 1 ;
$folders = ( substr ( $row [ 'serverdir' ], 0 , 1 ) == '/' ) ? 'cd /' : 'cd ' ;
2014-01-05 13:00:36 +01:00
while ( $i <= $folderfilecount ) {
$folders = $folders . $split_config [ $i ] . '/' ;
$lastFolder = $split_config [ $i ];
$i ++ ;
}
2014-02-02 09:37:31 +01:00
2014-01-05 13:00:36 +01:00
if ( $folders == 'cd ' ) {
$folders = '' ;
2014-02-02 09:37:31 +01:00
} else if ( $lastFolder != 'tsdns' or substr ( $row [ 'serverdir' ], 0 , 1 ) != '/' ) {
$folders = $folders . 'tsdns/ && ' ;
2013-08-28 22:47:04 +02:00
} else {
2014-01-05 13:00:36 +01:00
$folders = $folders . ' && ' ;
2013-08-28 22:47:04 +02:00
}
2014-02-02 09:37:31 +01:00
$ssh2cmd = $folders . 'function r () { if [ "`ps fx | grep ' . $tsdnsbin . ' | grep -v grep`" == "" ]; then ./' . $tsdnsbin . ' > /dev/null & else ./' . $tsdnsbin . ' --update > /dev/null & fi }; r& ' ;
2014-01-05 13:00:36 +01:00
if ( ssh2_execute ( 'vd' , $row [ 'id' ], $ssh2cmd )) {
print " Restarting TSDNS: { $row [ 'ssh2ip' ] } \r \n " ;
2013-08-28 22:47:04 +02:00
} else {
2014-01-05 13:00:36 +01:00
print " Failed restarting TSDNS: { $row [ 'ssh2ip' ] } \r \n " ;
}
if ( isset ( $dbConnect [ 'debug' ]) and $dbConnect [ 'debug' ] == 1 ) {
echo $ssh2cmd . " \r \n " ;
2013-08-28 22:47:04 +02:00
}
2014-01-05 13:00:36 +01:00
2013-08-28 22:47:04 +02:00
} else {
2014-02-02 09:37:31 +01:00
2013-08-28 22:47:04 +02:00
print " TSDNS ${ row['ssh2ip'] } is up and running \r \n " ;
2014-02-02 09:37:31 +01:00
2013-09-29 15:29:58 +02:00
$query3 = $sql -> prepare ( " UPDATE `voice_tsdns` SET `notified`=0 WHERE `id`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$query3 -> execute ( array ( $row [ 'id' ]));
}
}
/* Voice Server */
2014-01-05 13:00:36 +01:00
if (( isset ( $args [ 'tsDebug' ]) and $args [ 'tsDebug' ] == 1 )) {
print " Checking voice server with debug on \r \n " ;
}
2014-02-02 09:37:31 +01:00
$query = $sql -> prepare ( " SELECT *,AES_DECRYPT(`querypassword`,:aeskey) AS `decryptedquerypassword`,AES_DECRYPT(`ssh2port`,:aeskey) AS `decryptedssh2port`,AES_DECRYPT(`ssh2user`,:aeskey) AS `decryptedssh2user`,AES_DECRYPT(`ssh2password`,:aeskey) AS `decryptedssh2password` FROM `voice_masterserver` WHERE `active`='Y' " );
$query -> execute ( array ( ':aeskey' => $aeskey ));
foreach ( $query -> fetchAll ( PDO :: FETCH_ASSOC ) as $vrow ) {
2013-10-03 12:49:13 +02:00
unset ( $connect_ssh2 , $ssh2 , $badLogin );
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
$ts3masterid = $vrow [ 'id' ];
$ts3masternotified = $vrow [ 'notified' ];
$addedby = $vrow [ 'addedby' ];
$queryport = $vrow [ 'queryport' ];
$querypassword = $vrow [ 'decryptedquerypassword' ];
$resellerid = $vrow [ 'resellerid' ];
$autorestart = $vrow [ 'autorestart' ];
2013-11-02 09:55:59 +01:00
2014-02-02 09:37:31 +01:00
if ( $addedby == 1 ) {
2013-10-13 11:42:31 +02:00
$vselect2 = $sql -> prepare ( " SELECT `ip` FROM `rserverdata` WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
2013-10-03 12:49:13 +02:00
$vselect2 -> execute ( array ( $vrow [ 'rootid' ], $resellerid ));
2013-11-02 09:55:59 +01:00
$queryip = $vselect2 -> fetchColumn ();
2014-02-02 09:37:31 +01:00
} else {
$queryip = $vrow [ 'ssh2ip' ];
2013-08-28 22:47:04 +02:00
}
2013-11-02 09:55:59 +01:00
2013-10-03 12:49:13 +02:00
if ( $vrow [ 'type' ] == 'ts3' ) {
2014-02-02 09:37:31 +01:00
print " Connecting to TS3 server $queryip\r\n " ;
2013-09-29 15:29:58 +02:00
$tsdown = false ;
$tsdnsdown = false ;
2013-10-03 12:49:13 +02:00
$defaultwelcome = $vrow [ 'defaultwelcome' ];
2013-11-02 09:55:59 +01:00
$default = array ( 'virtualserver_hostbanner_url' => $vrow [ 'defaulthostbanner_url' ], 'virtualserver_hostbanner_gfx_url' => $vrow [ 'defaulthostbanner_gfx_url' ], 'virtualserver_hostbutton_tooltip' => $vrow [ 'defaulthostbutton_tooltip' ], 'virtualserver_hostbutton_url' => $vrow [ 'defaulthostbutton_url' ], 'virtualserver_hostbutton_gfx_url' => $vrow [ 'defaulthostbutton_gfx_url' ], 'defaultwelcome' => $vrow [ 'defaultwelcome' ]);
2014-02-02 09:37:31 +01:00
$connection = new TS3 ( $queryip , $queryport , 'serveradmin' , $querypassword , ( isset ( $args [ 'tsDebug' ]) and $args [ 'tsDebug' ] == 1 ) ? true : false );
2013-10-03 12:49:13 +02:00
$errorcode = $connection -> errorcode ;
2014-02-02 09:37:31 +01:00
2013-08-28 22:47:04 +02:00
if ( strpos ( $errorcode , 'error id=0' ) === false ) {
2014-02-02 09:37:31 +01:00
2013-08-28 22:47:04 +02:00
$connection -> CloseConnection ();
unset ( $connection );
2014-02-02 09:37:31 +01:00
2013-08-28 22:47:04 +02:00
sleep ( 1 );
2014-02-02 09:37:31 +01:00
$connection = new TS3 ( $queryip , $queryport , 'serveradmin' , $querypassword );
2013-10-03 12:49:13 +02:00
$errorcode = $connection -> errorcode ;
2013-08-28 22:47:04 +02:00
}
2014-02-02 09:37:31 +01:00
if ( strpos ( $errorcode , 'error id=0' ) === false ) {
2013-08-28 22:47:04 +02:00
$connection -> CloseConnection ();
unset ( $connection );
}
2014-02-02 09:37:31 +01:00
if ( strpos ( $errorcode , 'error id=0' ) === false ) {
print " TS3 Query Error: " . $errorcode . " \r \n " ;
2013-10-03 12:49:13 +02:00
$tsdown = true ;
2014-02-02 09:37:31 +01:00
$restartreturn = " TS3 " ;
2013-08-28 22:47:04 +02:00
}
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
if ( $vrow [ 'usedns' ] == 'Y' ) {
2014-02-02 09:37:31 +01:00
$tsdnscheck = @ fsockopen ( $queryip , 41144 , $errno , $errstr , 5 );
2013-08-28 22:47:04 +02:00
if ( ! is_resource ( $tsdnscheck )) {
sleep ( 1 );
2014-02-02 09:37:31 +01:00
$tsdnscheck = @ fsockopen ( $queryip , 41144 , $errno , $errstr , 5 );
2013-08-28 22:47:04 +02:00
}
if ( ! is_resource ( $tsdnscheck )) {
2014-02-02 09:37:31 +01:00
2013-08-28 22:47:04 +02:00
print " TSDNS Error: " . $errno . ' (' . $errstr . " ) \r \n " ;
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
$tsdnsdown = true ;
2014-02-02 09:37:31 +01:00
2013-08-28 22:47:04 +02:00
if ( isset ( $restartreturn )) {
2014-02-02 09:37:31 +01:00
$restartreturn .= " and TSDNS " ;
2013-08-28 22:47:04 +02:00
} else {
2014-02-02 09:37:31 +01:00
$restartreturn = " TSDNS " ;
2013-08-28 22:47:04 +02:00
}
}
}
2014-02-02 09:37:31 +01:00
2013-10-13 11:42:31 +02:00
if ( $tsdown == true or $tsdnsdown == true ) {
2014-02-02 09:37:31 +01:00
2013-08-28 22:47:04 +02:00
$ts3masternotified ++ ;
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
if ( $ts3masternotified == $resellersettings [ $resellerid ][ 'down_checks' ]) {
2014-02-02 09:37:31 +01:00
2013-10-13 17:11:32 +02:00
if ( $resellerid == 0 ) {
$query2 = $sql -> prepare ( " SELECT `id`,`mail_serverdown` FROM `userdata` WHERE `accounttype`='a' AND `resellerid`=0 " );
2013-08-28 22:47:04 +02:00
$query2 -> execute ();
} else {
2013-09-29 15:29:58 +02:00
$query2 = $sql -> prepare ( " SELECT `id`,`mail_serverdown` FROM `userdata` WHERE `id`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$query2 -> execute ( array ( $resellerid ));
}
2014-02-02 09:37:31 +01:00
2013-08-28 22:47:04 +02:00
foreach ( $query2 -> fetchall ( PDO :: FETCH_ASSOC ) as $row2 ) {
2013-10-03 12:49:13 +02:00
if ( $row2 [ 'mail_serverdown' ] == 'Y' ) {
2014-02-02 09:37:31 +01:00
sendmail ( 'emaildownrestart' , $row2 [ 'id' ], $queryip . ' (' . $restartreturn . ')' , '' );
2013-10-03 12:49:13 +02:00
}
2013-08-28 22:47:04 +02:00
}
}
2014-02-02 09:37:31 +01:00
2013-10-13 17:11:32 +02:00
$query2 = $sql -> prepare ( " UPDATE `voice_server` SET `uptime`=0 WHERE `masterserver`=? " );
2013-10-03 12:49:13 +02:00
$query2 -> execute ( array ( $ts3masterid ));
2013-10-13 11:42:31 +02:00
$query2 = $sql -> prepare ( " UPDATE `voice_masterserver` SET `notified`=? WHERE `id`=? LIMIT 1 " );
2013-10-03 12:49:13 +02:00
$query2 -> execute ( array ( $ts3masternotified , $ts3masterid ));
2013-09-22 12:00:33 +02:00
2014-01-05 13:00:36 +01:00
if (( $autorestart == 'Y' and $ts3masternotified >= $resellersettings [ $resellerid ][ 'down_checks' ])) {
$cmds = array ();
$i = 0 ;
2014-02-02 09:37:31 +01:00
$split_config = preg_split ( '/\//' , $vrow [ 'serverdir' ], - 1 , PREG_SPLIT_NO_EMPTY );
$folderfilecount = count ( $split_config ) - 1 ;
2014-01-05 13:00:36 +01:00
$folders = ( substr ( $vrow [ 'serverdir' ], 0 , 1 ) == '/' ) ? 'cd /' : 'cd ' ;
2014-02-02 09:37:31 +01:00
2014-01-05 13:00:36 +01:00
while ( $i <= $folderfilecount ) {
2014-02-02 09:37:31 +01:00
$folders = $folders . $split_config [ $i ] . '/' ;
2014-01-05 13:00:36 +01:00
$i ++ ;
}
if ( $folders == 'cd ' ) {
$folders = '' ;
2014-02-02 09:37:31 +01:00
$tsdnsFolders = 'cd tsdns && ' ;
2014-01-05 13:00:36 +01:00
} else {
$tsdnsFolders = $folders . 'tsdns && ' ;
$folders = $folders . ' && ' ;
}
2013-09-22 12:00:33 +02:00
2014-01-05 13:00:36 +01:00
if ( $vrow [ 'bitversion' ] == '32' ) {
2014-02-02 09:37:31 +01:00
$tsbin = 'ts3server_linux_x86' ;
$tsdnsbin = 'tsdnsserver_linux_x86' ;
2013-08-28 22:47:04 +02:00
} else {
2014-02-02 09:37:31 +01:00
$tsbin = 'ts3server_linux_amd64' ;
$tsdnsbin = 'tsdnsserver_linux_amd64' ;
2014-01-05 13:00:36 +01:00
}
if ( $tsdown == true ) {
2014-02-02 09:37:31 +01:00
$cmds [] = $folders . 'function r () { if [ "`ps fx | grep ' . $tsbin . ' | grep -v grep`" == "" ]; then ./ts3server_startscript.sh start > /dev/null & else ./ts3server_startscript.sh restart > /dev/null & fi }; r& ' ;
2014-01-05 13:00:36 +01:00
}
if ( $vrow [ 'usedns' ] == 'Y' and $tsdnsdown == true ) {
2014-02-02 09:37:31 +01:00
$cmds [] = $tsdnsFolders . 'function r () { if [ "`ps fx | grep ' . $tsdnsbin . ' | grep -v grep`" == "" ]; then ./' . $tsdnsbin . ' > /dev/null & else ./' . $tsdnsbin . ' --update > /dev/null & fi }; r& ' ;
2013-08-28 22:47:04 +02:00
}
2014-01-05 13:00:36 +01:00
if ( count ( $cmds ) > 0 ) {
if ( ssh2_execute ( 'vm' , $ts3masterid , $cmds )) {
print " Restarting: $restartreturn $queryip\r\n " ;
2013-08-28 22:47:04 +02:00
} else {
2014-01-05 13:00:36 +01:00
print " Failed restarting: $restartreturn $queryip\r\n " ;
2013-08-28 22:47:04 +02:00
}
2014-01-05 13:00:36 +01:00
if ( isset ( $dbConnect [ 'debug' ]) and $dbConnect [ 'debug' ] == 1 ) {
print_r ( $cmds );
2013-08-28 22:47:04 +02:00
}
}
} else {
2014-01-05 13:00:36 +01:00
print " $restartreturn $queryip down but no Restart triggert \r \n " ;
2013-08-28 22:47:04 +02:00
}
}
2014-01-05 13:00:36 +01:00
2013-10-13 11:42:31 +02:00
if ( $tsdown != true ) {
2014-02-02 09:37:31 +01:00
if ( $ts3masternotified > 0 ) {
2013-10-13 17:11:32 +02:00
$pupdate = $sql -> prepare ( " UPDATE `voice_masterserver` SET `notified`=0 WHERE `id`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$pupdate -> execute ( array ( $ts3masterid ));
}
2013-12-18 22:46:48 +01:00
2013-10-03 12:49:13 +02:00
$serverlist = $connection -> ServerList ();
2013-12-18 22:46:48 +01:00
2013-10-13 17:11:32 +02:00
if ( ! isset ( $serverlist [ 0 ][ 'id' ]) or $serverlist [ 0 ][ 'id' ] == 0 ) {
2013-12-18 22:46:48 +01:00
2013-08-28 22:47:04 +02:00
foreach ( $serverlist as $server ) {
2014-02-02 09:37:31 +01:00
unset ( $newtrafficdata , $newtraffic , $ts3id );
2013-09-29 15:29:58 +02:00
$modbadserver = array ();
2014-02-02 09:37:31 +01:00
$newnotified = 'N' ;
2013-10-03 12:49:13 +02:00
$virtualserver_id = $server [ 'virtualserver_id' ];
$vs = $server [ 'virtualserver_status' ];
2014-02-02 09:37:31 +01:00
$uptime = ( isset ( $server [ 'virtualserver_uptime' ])) ? $server [ 'virtualserver_uptime' ] : 0 ;
2013-10-13 11:42:31 +02:00
$vselect2 = $sql -> prepare ( " SELECT * FROM `voice_server` WHERE `localserverid`=? AND `masterserver`=? AND `resellerid`=? AND `autoRestart`='Y' LIMIT 1 " );
2013-10-03 12:49:13 +02:00
$vselect2 -> execute ( array ( $virtualserver_id , $vrow [ 'id' ], $resellerid ));
2013-08-28 22:47:04 +02:00
foreach ( $vselect2 -> fetchall ( PDO :: FETCH_ASSOC ) as $vrow2 ) {
2013-10-03 12:49:13 +02:00
$queryName = $vrow2 [ 'queryName' ];
$lendserver = $vrow2 [ 'lendserver' ];
$ts3id = $vrow2 [ 'id' ];
$userid = $vrow2 [ 'userid' ];
$slots = $vrow2 [ 'slots' ];
$password = $vrow2 [ 'password' ];
$forcebanner = $vrow2 [ 'forcebanner' ];
$forcebutton = $vrow2 [ 'forcebutton' ];
$forceservertag = $vrow2 [ 'forceservertag' ];
$forcewelcome = $vrow2 [ 'forcewelcome' ];
$flexSlots = $vrow2 [ 'flexSlots' ];
$flexSlotsFree = $vrow2 [ 'flexSlotsFree' ];
$flexSlotsPercent = $vrow2 [ 'flexSlotsPercent' ];
$flexSlotsCurrent = $vrow2 [ 'flexSlotsCurrent' ];
$max_download_total_bandwidth = $vrow2 [ 'max_download_total_bandwidth' ];
$max_upload_total_bandwidth = $vrow2 [ 'max_upload_total_bandwidth' ];
$address = $vrow2 [ 'ip' ] . ':' . $vrow2 [ 'port' ];
$active = $vrow2 [ 'active' ];
$notified = $vrow2 [ 'notified' ];
$olduptime = $vrow2 [ 'uptime' ];
$initialpassword = $vrow2 [ 'initialpassword' ];
$maxtrafficmb = $vrow2 [ 'maxtraffic' ];
2014-02-02 09:37:31 +01:00
$maxtraffic = $maxtrafficmb * 1024 ;
$filetraffic = ( $vrow2 [ 'filetraffic' ] == null ) ? 0 : $vrow2 [ 'filetraffic' ];
$lastfiletraffic = ( $vrow2 [ 'lastfiletraffic' ] == null ) ? 0 : $vrow2 [ 'lastfiletraffic' ];
2013-10-03 12:49:13 +02:00
$newtrafficdata = $lastfiletraffic ;
$newtraffic = $filetraffic ;
2013-08-28 22:47:04 +02:00
}
2013-11-02 09:55:59 +01:00
2013-10-03 12:49:13 +02:00
if ( isset ( $ts3id ) and $vs == 'online' and $active == 'N' ) {
2014-02-02 09:37:31 +01:00
2013-08-28 22:47:04 +02:00
print " Inactive TS3 server $address running. Stopping it. \r \n " ;
$connection -> StopServer ( $virtualserver_id );
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
} else if ( isset ( $ts3id ) and $vs == 'online' and $active == 'Y' ) {
2014-02-02 09:37:31 +01:00
2013-11-02 09:55:59 +01:00
unset ( $rulebreak , $changeSlots );
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
$queryName = $server [ 'virtualserver_name' ];
2013-11-02 09:55:59 +01:00
$usedslots = ( isset ( $server [ 'virtualserver_clientsonline' ])) ? $server [ 'virtualserver_clientsonline' ] : 0 ;
2014-02-02 09:37:31 +01:00
if ( $lendserver == 'Y' ) {
$vselect2 = $sql -> prepare ( " SELECT `slots` FROM `lendedserver` WHERE `servertype`='v' AND `serverid`=? AND `resellerid`=? LIMIT 1 " );
$vselect2 -> execute ( array ( $ts3id , $resellerid ));
$lendslots = $vselect2 -> fetchColumn ();
} else {
$lendslots = 0 ;
}
2013-10-03 12:49:13 +02:00
$sd = $connection -> ServerDetails ( $virtualserver_id );
2014-02-02 09:37:31 +01:00
$newtrafficdata = round (( $sd [ 'connection_filetransfer_bytes_sent_total' ] + $sd [ 'connection_filetransfer_bytes_received_total' ]) / 1024 );
2013-11-02 09:55:59 +01:00
2014-01-10 22:16:51 +01:00
if ( isset ( $resellersettings [ $resellerid ][ 'firstchecktime' ]) and isset ( $resellersettings [ $resellerid ][ 'firstcheck' ]) and $resellersettings [ $resellerid ][ 'firstchecktime' ] < $resellersettings [ $resellerid ][ 'firstcheck' ]) {
2013-11-02 09:55:59 +01:00
$filetraffic = 0 ;
}
2013-09-29 15:29:58 +02:00
$newtraffic = 0 ;
2014-02-15 19:30:19 +01:00
$addedtraffic = 0 ;
2013-11-02 09:55:59 +01:00
if ( $newtrafficdata > $lastfiletraffic ) {
$addedtraffic = $newtrafficdata - $lastfiletraffic ;
$newtraffic = $filetraffic + $addedtraffic ;
2013-10-03 12:49:13 +02:00
} else if ( $newtrafficdata == $lastfiletraffic ) {
$newtraffic = $filetraffic ;
2013-11-02 09:55:59 +01:00
} else if ( $newtrafficdata < $lastfiletraffic ) {
2013-10-03 12:49:13 +02:00
$addedtraffic = $newtrafficdata ;
2014-02-15 19:30:19 +01:00
$newtraffic = $filetraffic + $addedtraffic ;
2013-08-28 22:47:04 +02:00
}
2013-11-02 09:55:59 +01:00
$newtrafficmb = round ( $newtraffic / 1024 );
2013-09-29 15:29:58 +02:00
$traffictext = '' ;
2013-10-13 11:42:31 +02:00
$virtualserver_max_download_total_bandwidth = $max_download_total_bandwidth ;
$virtualserver_max_upload_total_bandwidth = $max_upload_total_bandwidth ;
2013-11-02 09:55:59 +01:00
if ( isset ( $ts3id ) and $flexSlots == 'Y' and $usedslots == 0 and ( $usedslots + $flexSlotsFree ) != $flexSlotsCurrent ) {
$changeSlots = $flexSlotsFree ;
} else if ( isset ( $ts3id ) and $flexSlots == 'Y' and ( $usedslots + $flexSlotsFree ) != $flexSlotsCurrent and ( $usedslots + $flexSlotsFree ) <= $slots and ( abs (( $usedslots + $flexSlotsFree ) - $flexSlotsCurrent ) / ( $flexSlotsFree / 100 )) >= $flexSlotsPercent ) {
$changeSlots = $usedslots + $flexSlotsFree ;
} else if ( isset ( $ts3id ) and $flexSlots == 'Y' and $flexSlotsCurrent != $slots and ( $usedslots + $flexSlotsFree ) > $slots and ( abs (( $usedslots + $flexSlotsFree ) - $flexSlotsCurrent ) / ( $flexSlotsFree / 100 )) >= $flexSlotsPercent ) {
$changeSlots = $slots ;
}
if ( isset ( $changeSlots ) and $flexSlotsCurrent != 2 and $changeSlots < 2 ) {
$changeSlots = 2 ;
} else if ( isset ( $changeSlots ) and $flexSlotsCurrent == 2 and $changeSlots < 2 ) {
unset ( $changeSlots );
}
if ( $maxtraffic > 0 and $newtraffic > $maxtraffic and $sd [ 'virtualserver_max_download_total_bandwidth' ] > 1 and $sd [ 'virtualserver_max_upload_total_bandwidth' ] > 1 ) {
2014-02-02 09:37:31 +01:00
2013-09-29 15:29:58 +02:00
$virtualserver_max_download_total_bandwidth = 1 ;
$virtualserver_max_upload_total_bandwidth = 1 ;
2014-02-02 09:37:31 +01:00
$traffictext = 'and has now reached the traffic limit ' . $newtrafficmb . '/' . $maxtrafficmb . " MB " ;
2013-08-28 22:47:04 +02:00
if ( isset ( $rulebreak )) {
2014-02-02 09:37:31 +01:00
$rulebreak .= '<br />Traffic Limit' . $newtrafficmb . '/' . $maxtrafficmb . " MB " ;
2013-08-28 22:47:04 +02:00
} else {
2014-02-02 09:37:31 +01:00
$rulebreak = '<br />Traffic Limit' . $newtrafficmb . '/' . $maxtrafficmb . " MB " ;
2013-08-28 22:47:04 +02:00
}
2014-02-02 09:37:31 +01:00
} else if ( $maxtraffic > 0 and $newtraffic > $maxtraffic and $sd [ 'virtualserver_max_download_total_bandwidth' ] < 2 and $sd [ 'virtualserver_max_upload_total_bandwidth' ] < 2 ) {
2013-09-29 15:29:58 +02:00
$virtualserver_max_download_total_bandwidth = 1 ;
$virtualserver_max_upload_total_bandwidth = 1 ;
2014-02-02 09:37:31 +01:00
$traffictext = 'and has still reached the traffic limit ' . $newtrafficmb . '/' . $maxtrafficmb . " MB " ;
} else if ( $maxtraffic > 0 ) {
$traffictext = 'and has not reached traffic limit ' . $newtrafficmb . '/' . $maxtrafficmb . " MB " ;
2013-08-28 22:47:04 +02:00
} else {
2014-02-02 09:37:31 +01:00
$traffictext = 'and has traffic limit ' . $newtrafficmb . '/' . $maxtrafficmb . " MB " ;
2013-08-28 22:47:04 +02:00
}
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
if ( $sd [ 'virtualserver_max_download_total_bandwidth' ] != $virtualserver_max_download_total_bandwidth or $sd [ 'virtualserver_max_upload_total_bandwidth' ] != $virtualserver_max_download_total_bandwidth ) {
$modbadserver [ 'virtualserver_max_download_total_bandwidth' ] = $virtualserver_max_download_total_bandwidth ;
$modbadserver [ 'virtualserver_max_upload_total_bandwidth' ] = $virtualserver_max_download_total_bandwidth ;
2013-08-28 22:47:04 +02:00
}
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
if ( $forceservertag == 'Y' and $resellersettings [ $resellerid ][ 'brandname' ] != '' and strpos ( strtolower ( $server [ 'virtualserver_name' ]), strtolower ( $resellersettings [ $resellerid ][ 'brandname' ])) === false ) {
2014-02-02 09:37:31 +01:00
print $vrow [ 'type' ] . ' server $address illegal without servertag. The name converted to ISO-8859-1 is ' . iconv ( 'UTF-8' , 'ISO-8859-1//TRANSLIT' , $server [ 'virtualserver_name' ]) . " \r \n " ;
2013-08-28 22:47:04 +02:00
if ( isset ( $rulebreak )) {
2014-02-02 09:37:31 +01:00
$rulebreak .= '<br />' . $ssprache -> noservertag ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-13 11:42:31 +02:00
$rulebreak = $ssprache -> noservertag ;
2013-08-28 22:47:04 +02:00
}
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
$modbadserver [ 'virtualserver_name' ] = $server [ 'virtualserver_name' ] . ' ' . $resellersettings [ $resellerid ][ 'brandname' ];
2013-08-28 22:47:04 +02:00
}
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
if ( isset ( $ts3id ) and $forcebanner == 'Y' ) {
2014-02-02 09:37:31 +01:00
foreach ( array ( 'virtualserver_hostbanner_url' , 'virtualserver_hostbanner_gfx_url' ) as $param ) {
2013-10-03 12:49:13 +02:00
if ( $default [ $param ] != '' and $sd [ $param ] != $default [ $param ]) {
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
$modbadserver [ $param ] = $default [ $param ];
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
print $vrow [ 'type' ] . " server $address $param != " . $default [ $param ] . " . The name converted to ISO-8859-1 is " . iconv ( 'UTF-8' , 'ISO-8859-1//TRANSLIT' , $server [ 'virtualserver_name' ]) . " \r \n " ;
2014-02-02 09:37:31 +01:00
2013-08-28 22:47:04 +02:00
if ( isset ( $rulebreak )) {
2014-02-02 09:37:31 +01:00
$rulebreak .= '<br />' . $param . ' ' . $vosprache -> isnot . ' ' . $default [ $param ];
2013-08-28 22:47:04 +02:00
} else {
2013-10-13 11:42:31 +02:00
$rulebreak = $param . ' ' . $vosprache -> isnot . ' ' . $default [ $param ];
2013-08-28 22:47:04 +02:00
}
}
}
}
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
if ( isset ( $ts3id ) and $forcebutton == 'Y' ) {
2014-02-02 09:37:31 +01:00
foreach ( array ( 'virtualserver_hostbutton_tooltip' , 'virtualserver_hostbutton_url' , 'virtualserver_hostbutton_gfx_url' ) as $param ) {
2013-10-03 12:49:13 +02:00
if ( $default [ $param ] != '' and $sd [ $param ] != $default [ $param ]) {
$modbadserver [ $param ] = $default [ $param ];
2014-02-02 09:37:31 +01:00
print $vrow [ 'type' ] . " server $address $param != " . $default [ $param ] . " . The name converted to ISO-8859-1 is " . iconv ( 'UTF-8' , 'ISO-8859-1//TRANSLIT' , $server [ 'virtualserver_name' ]) . " \r \n " ;
2013-08-28 22:47:04 +02:00
if ( isset ( $rulebreak )) {
2014-02-02 09:37:31 +01:00
$rulebreak .= '<br />' . $param . ' ' . $vosprache -> isnot . ' ' . $default [ $param ];
2013-08-28 22:47:04 +02:00
} else {
2013-10-13 11:42:31 +02:00
$rulebreak = $param . ' ' . $vosprache -> isnot . ' ' . $default [ $param ];
2013-08-28 22:47:04 +02:00
}
}
}
}
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
if ( isset ( $ts3id ) and $forcewelcome == 'Y' and $default [ 'defaultwelcome' ] != '' and $sd [ 'virtualserver_welcomemessage' ] != $default [ 'defaultwelcome' ]) {
$modbadserver [ 'virtualserver_welcomemessage' ] = $default [ 'defaultwelcome' ];
2014-02-02 09:37:31 +01:00
print $vrow [ 'type' ] . " server $address $param != " . $default [ 'defaultwelcome' ] . '. The name converted to ISO-8859-1 is ' . iconv ( 'UTF-8' , 'ISO-8859-1//TRANSLIT' , $server [ 'virtualserver_name' ]) . " \r \n " ;
2013-08-28 22:47:04 +02:00
if ( isset ( $rulebreak )) {
2014-02-02 09:37:31 +01:00
$rulebreak .= '<br />virtualserver_welcomemessage ' . $vosprache -> isnot . ' ' . $default [ 'defaultwelcome' ];
2013-08-28 22:47:04 +02:00
} else {
2014-02-02 09:37:31 +01:00
$rulebreak = 'virtualserver_welcomemessage ' . $vosprache -> isnot . ' ' . $default [ 'defaultwelcome' ];
2013-08-28 22:47:04 +02:00
}
}
2014-02-02 09:37:31 +01:00
if ( isset ( $ts3id , $lendserver ) and (( $lendserver == 'N' and $slots < $server [ 'virtualserver_maxclients' ]) or ( $lendserver == 'Y' and $lendslots < $server [ 'virtualserver_maxclients' ]))) {
$showSlots = ( $lendserver == 'Y' ) ? $lendslots : $slots ;
print $vrow [ 'type' ] . " server $address virtualserver_maxclients ${ sd['virtualserver_maxclients'] } != " . $showSlots . " . The name converted to ISO-8859-1 is " . iconv ( 'UTF-8' , 'ISO-8859-1//TRANSLIT' , $server [ 'virtualserver_name' ]) . " \r \n " ;
2013-08-28 22:47:04 +02:00
if ( isset ( $rulebreak )) {
2014-02-02 09:37:31 +01:00
$rulebreak .= '<br />virtualserver_maxclients ' . $vosprache -> isnot . ' ' . $showSlots ;
2013-08-28 22:47:04 +02:00
} else {
2014-02-02 09:37:31 +01:00
$rulebreak = 'virtualserver_maxclients ' . $vosprache -> isnot . ' ' . $showSlots ;
2013-08-28 22:47:04 +02:00
}
}
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
if ( isset ( $ts3id ) and $password == 'Y' and $sd [ 'virtualserver_flag_password' ] != '1' ) {
$modbadserver [ 'virtualserver_password' ] = $initialpassword ;
2014-02-02 09:37:31 +01:00
print $vrow [ 'type' ] . " server $address virtualserver_flag_password != 1. The name converted to ISO-8859-1 is " . iconv ( 'UTF-8' , 'ISO-8859-1//TRANSLIT' , $server [ 'virtualserver_name' ]) . " \r \n " ;
2013-08-28 22:47:04 +02:00
if ( isset ( $rulebreak )) {
$rulebreak .= " <br />virtualserver_flag_password " . $vosprache -> isnot . " 1 " ;
} else {
$rulebreak = " virtualserver_flag_password " . $vosprache -> isnot . " 1 " ;
}
}
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
if ( isset ( $ts3id ) and $lendserver == 'N' and ! isset ( $rulebreak )) {
2014-02-02 09:37:31 +01:00
2013-08-28 22:47:04 +02:00
if ( isset ( $changeSlots )) {
2014-02-02 09:37:31 +01:00
print $vrow [ 'type' ] . " server $address Changing Flex Slots to ${ changeSlots } . The name converted to ISO-8859-1 is " . iconv ( 'UTF-8' , 'ISO-8859-1//TRANSLIT' , $server [ 'virtualserver_name' ]) . " \r \n " ;
2013-10-03 12:49:13 +02:00
$connection -> ImportModServer ( $virtualserver_id , $changeSlots , $vrow2 [ 'ip' ], $vrow2 [ 'port' ], array ());
2014-02-02 09:37:31 +01:00
2013-10-13 17:11:32 +02:00
$pupdate2 = $sql -> prepare ( " UPDATE `voice_server` SET `notified`=0,`flexSlotsCurrent`=? WHERE `id`=? LIMIT 1 " );
2013-10-03 12:49:13 +02:00
$pupdate2 -> execute ( array ( $changeSlots , $ts3id ));
2014-02-02 09:37:31 +01:00
} else if ( $notified > 0 ) {
2013-10-13 17:11:32 +02:00
$pupdate2 = $sql -> prepare ( " UPDATE `voice_server` SET `notified`=0 WHERE `id`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$pupdate2 -> execute ( array ( $ts3id ));
}
2014-02-02 09:37:31 +01:00
2013-10-03 12:49:13 +02:00
print $vrow [ 'type' ] . " server $address is running $traffictext . The name converted to ISO-8859-1 is " . iconv ( 'UTF-8' , 'ISO-8859-1//TRANSLIT' , $server [ 'virtualserver_name' ]) . " \r \n " ;
2014-02-02 09:37:31 +01:00
2013-10-13 17:11:32 +02:00
} else if ( isset ( $ts3id ) and $notified == 0 and isset ( $rulebreak )) {
2014-02-02 09:37:31 +01:00
$connection -> ImportModServer ( $virtualserver_id ,( $lendserver == 'Y' ) ? $lendslots : $slots , $vrow2 [ 'ip' ], $vrow2 [ 'port' ], $modbadserver );
2013-08-28 22:47:04 +02:00
if ( $resellerid == 0 ) {
2013-10-13 17:11:32 +02:00
$query2 = $sql -> prepare ( " SELECT `id`,`mail_securitybreach` FROM `userdata` WHERE `id`=? OR (`resellerid`=0 AND `accounttype`='a') " );
2013-08-28 22:47:04 +02:00
$query2 -> execute ( array ( $userid ));
} else {
2013-09-29 15:29:58 +02:00
$query2 = $sql -> prepare ( " SELECT `id`,`mail_securitybreach` FROM `userdata` WHERE `id`=? OR (`id`=? AND `accounttype`='r') " );
2013-10-03 12:49:13 +02:00
$query2 -> execute ( array ( $userid , $resellerid ));
2013-08-28 22:47:04 +02:00
}
2014-02-02 09:37:31 +01:00
2013-08-28 22:47:04 +02:00
foreach ( $query2 -> fetchall ( PDO :: FETCH_ASSOC ) as $row2 ) {
2013-10-03 12:49:13 +02:00
if ( $row2 [ 'mail_securitybreach' ] == 'Y' or $row2 [ 'id' ] == $userid ) {
sendmail ( 'emailsecuritybreach' , $row2 [ 'id' ], $address , $rulebreak );
2013-08-28 22:47:04 +02:00
}
}
2013-10-13 11:42:31 +02:00
$pupdate2 = $sql -> prepare ( " UPDATE `voice_server` SET `notified`='1' WHERE `id`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$pupdate2 -> execute ( array ( $ts3id ));
}
2013-10-03 12:49:13 +02:00
if ( isset ( $ts3id ) and $lendserver == 'Y' and $resellersettings [ $resellerid ][ 'shutdownempty' ] == 'Y' ) {
2013-09-29 15:29:58 +02:00
$stop = false ;
2013-10-03 12:49:13 +02:00
$dataloss = true ;
$shutdownemptytime = $resellersettings [ $resellerid ][ 'shutdownemptytime' ];
$elapsedtime = $sql -> prepare ( " SELECT `id`,`started`,`lendtime` FROM `lendedserver` WHERE `serverid`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$elapsedtime -> execute ( array ( $ts3id ));
foreach ( $elapsedtime -> fetchall ( PDO :: FETCH_ASSOC ) as $erow ) {
2013-09-29 15:29:58 +02:00
$dataloss = false ;
2013-10-03 12:49:13 +02:00
$lid = $erow [ 'id' ];
$runtime = $erow [ 'lendtime' ];
2013-11-02 09:55:59 +01:00
$elapsed = round (( strtotime ( 'now' ) - strtotime ( $erow [ 'started' ])) / 60 );
if ( $elapsed > $shutdownemptytime and $usedslots == 0 ) {
2013-08-28 22:47:04 +02:00
print " Will stop server $address before time is up, because it is empty \r \n " ;
2013-10-03 12:49:13 +02:00
$stop = true ;
2013-11-02 09:55:59 +01:00
} else if ( $elapsed >= $runtime ) {
2013-08-28 22:47:04 +02:00
print " Will stop server $address because time is up \r \n " ;
2013-10-03 12:49:13 +02:00
$stop = true ;
2013-08-28 22:47:04 +02:00
}
2013-11-02 09:55:59 +01:00
2013-10-13 11:42:31 +02:00
if ( $stop == true ) {
2013-10-03 12:49:13 +02:00
$rmvoicelend = $sql -> prepare ( " DELETE FROM `lendedserver` WHERE `id`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$rmvoicelend -> execute ( array ( $lid ));
}
}
2013-10-13 11:42:31 +02:00
if ( $dataloss == true ) {
2013-08-28 22:47:04 +02:00
print " Will stop server $address because it is a lendserver and should not be running \r \n " ;
2013-10-03 12:49:13 +02:00
$stop = true ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:42:31 +02:00
if ( $stop == true ) {
2013-08-28 22:47:04 +02:00
$connection -> StopServer ( $virtualserver_id );
}
}
2014-02-15 19:30:19 +01:00
$query = $sql -> prepare ( " INSERT INTO `voice_server_stats` (`sid`,`mid`,`installed`,`used`,`traffic`,`date`,`uid`,`resellerid`) VALUES (?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE `traffic`=`traffic`+VALUES(`traffic`),`used`=(`used`*(`count`/(`count`+1))+(VALUES(`used`)*(1/(`count`+1)))),`installed`=(`installed`*(`count`/(`count`+1))+(VALUES(`installed`)*(1/(`count`+1)))),`count`=`count`+1 " );
$query -> execute ( array ( $ts3id , $ts3masterid , $server [ 'virtualserver_maxclients' ], $usedslots , $addedtraffic , $dayAndZeroHour , $userid , $resellerid ));
2013-08-28 22:47:04 +02:00
} else if ( isset ( $ts3id )) {
2013-09-29 15:29:58 +02:00
$uptime = 1 ;
$usedslots = 0 ;
2013-12-27 14:41:24 +01:00
if ( $lendserver == 'Y' and $lendActive == 'Y' ) {
2013-10-03 12:49:13 +02:00
$removedeadvoiceserver = $sql -> prepare ( " DELETE FROM `lendedserver` WHERE `serverid`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$removedeadvoiceserver -> execute ( array ( $ts3id ));
2013-10-03 12:49:13 +02:00
} else if ( $active == 'Y' and $vs != 'online' and $olduptime > 1 and $olduptime != null ) {
2013-08-28 22:47:04 +02:00
$notified ++ ;
2013-10-13 13:11:38 +02:00
if ( $notified >= $ts3masternotified == $resellersettings [ $resellerid ][ 'down_checks' ]){
2013-08-28 22:47:04 +02:00
print " TS3 server $address not running. Starting it. \r \n " ;
$connection -> StartServer ( $virtualserver_id );
}
2013-10-03 12:49:13 +02:00
if ( $notified == $resellersettings [ $resellerid ][ 'down_checks' ]) {
2013-09-29 15:29:58 +02:00
$query2 = $sql -> prepare ( " SELECT `mail_serverdown` FROM `userdata` WHERE `id`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$query2 -> execute ( array ( $userid ));
foreach ( $query2 -> fetchall ( PDO :: FETCH_ASSOC ) as $row2 ) {
2013-10-03 12:49:13 +02:00
if ( $row2 [ 'mail_serverdown' ] == 'Y' ) sendmail ( 'emaildownrestart' , $userid , $address , '' );
2013-08-28 22:47:04 +02:00
}
2013-10-03 12:49:13 +02:00
$newnotified = $notified ;
2013-08-28 22:47:04 +02:00
}
}
}
if ( isset ( $ts3id )) {
2013-10-03 12:49:13 +02:00
$flagPassword = 'N' ;
2013-10-13 13:11:38 +02:00
if ( isset ( $sd [ 'virtualserver_flag_password' ]) and $sd [ 'virtualserver_flag_password' ] == 1 ) {
2013-10-03 12:49:13 +02:00
$flagPassword = 'Y' ;
}
$query2 = $sql -> prepare ( " UPDATE `voice_server` SET `usedslots`=?,`uptime`=?,`notified`=?,`filetraffic`=?,`lastfiletraffic`=?,`queryName`=?,`queryNumplayers`=?,`queryMaxplayers`=?,`queryPassword`=?,`queryUpdatetime`=NOW() WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
$query2 -> execute ( array ( $usedslots , $uptime , $newnotified , $newtraffic , $newtrafficdata , $queryName ,(( isset ( $server [ 'virtualserver_clientsonline' ])) ? $server [ 'virtualserver_clientsonline' ] : 0 - 1 ),( isset ( $server [ 'virtualserver_maxclients' ])) ? $server [ 'virtualserver_maxclients' ] : 0 , $flagPassword , $ts3id , $resellerid ));
2013-08-28 22:47:04 +02:00
}
if ( isset ( $args [ 'coolDown' ])) {
2014-03-30 12:54:42 +02:00
2013-10-03 12:49:13 +02:00
$nano = time_nanosleep ( 0 , $args [ 'coolDown' ]);
2014-03-30 12:54:42 +02:00
2013-10-12 08:40:09 +02:00
if ( $nano === true ) {
2014-03-30 12:54:42 +02:00
echo 'Slept for ' . $args [ 'coolDown' ] . ' microseconds' . " \r \n " ;
2013-10-12 08:40:09 +02:00
} elseif ( $nano === false ) {
2013-10-03 12:49:13 +02:00
echo 'Sleeping failed' . " \r \n " ;
} elseif ( is_array ( $nano )) {
echo 'Interrupted by a signal' . " \r \n " ;
2014-03-30 12:54:42 +02:00
echo 'Time remaining: ' . $nano [ 'seconds' ] . ' seconds, ' . $nano [ 'nanoseconds' ] . ' nanoseconds' . " \r \n " ;
2013-08-28 22:47:04 +02:00
}
}
}
2014-03-30 12:54:42 +02:00
} else {
print " Error: " . $serverlist [ 0 ][ 'msg' ] . " \r \n " ;
}
2013-08-28 22:47:04 +02:00
}
2014-03-30 12:54:42 +02:00
2013-08-28 22:47:04 +02:00
if ( isset ( $connection )) {
$connection -> CloseConnection ();
sleep ( 1 );
}
}
}
}
2014-03-30 12:54:42 +02:00
2013-08-28 22:47:04 +02:00
flush ();
2014-03-30 12:54:42 +02:00
# MySQL table sizes
if ( $checkTypeOfServer == 'all' or $checkTypeOfServer == 'my' ) {
$query = $sql -> prepare ( " SELECT `id`,`ip`,`port`,`user`,AES_DECRYPT(`password`,?) AS `decryptedpassword` FROM `mysql_external_servers` WHERE `active`='Y' " );
$query2 = $sql -> prepare ( " SELECT `id` FROM `mysql_external_dbs` WHERE `sid`=? AND `dbname`=? LIMIT 1 " );
$query3 = $sql -> prepare ( " UPDATE `mysql_external_dbs` SET `dbSize`=? WHERE `id`=? LIMIT 1 " );
$query -> execute ( array ( $aeskey ));
foreach ( $query -> fetchAll ( PDO :: FETCH_ASSOC ) as $row ) {
$remotesql = new ExternalSQL ( $row [ 'ip' ], $row [ 'port' ], $row [ 'user' ], $row [ 'decryptedpassword' ]);
if ( $remotesql -> error == 'ok' ) {
$list = $remotesql -> getDBSizeList ();
if ( is_array ( $list )) {
foreach ( $list as $db ) {
$query2 -> execute ( array ( $row [ 'id' ], $db [ 'dbName' ]));
$dbID = $query2 -> fetchColumn ();
if ( isid ( $dbID , 10 )) {
echo 'Found DB ' . $db [ 'dbName' ] . ' with size ' . $db [ 'dbSize' ] . " \r \n " ;
$query3 -> execute ( array ( round ( $db [ 'dbSize' ]), $dbID ));
} else {
echo 'Cannot find DB ' . $db [ 'dbName' ] . ' with size ' . $db [ 'dbSize' ] . " \r \n " ;
}
}
} else {
echo 'Error getting DB list for DB Server ' . $row [ 'ip' ] . ':' . $row [ 'port' ] . ': ' . $list . " \r \n " ;
}
} else {
echo 'Error connecting to DB Server ' . $row [ 'ip' ] . ':' . $row [ 'port' ] . ': ' . $remotesql -> error . " \r \n " ;
}
}
}
2014-04-12 15:40:14 +02:00
flush ();
# Web Quotas
if ( $checkTypeOfServer == 'all' or $checkTypeOfServer == 'vh' ) {
2014-04-18 13:49:04 +02:00
echo " Checking Quota usage \r \n " ;
$query = $sql -> prepare ( " SELECT `webMasterID`,`ip`,`resellerID` FROM `webMaster` WHERE `active`='Y' " );
2014-04-12 15:40:14 +02:00
$query -> execute ();
foreach ( $query -> fetchAll ( PDO :: FETCH_ASSOC ) as $row ) {
2014-04-18 13:49:04 +02:00
echo 'Checking webMaster ' . $row [ 'ip' ] . ' with webMasterID ' . $row [ 'webMasterID' ] . " \r \n " ;
2014-04-12 15:40:14 +02:00
$httpd = new HttpdManagement ( $row [ 'webMasterID' ], $row [ 'resellerID' ]);
$httpd -> ssh2Connect ();
$httpd -> checkQuotaUsage ();
}
}
2014-05-01 19:20:28 +02:00
flush ();
# Gather statistics
if ( $checkTypeOfServer == 'all' or $checkTypeOfServer == 'st' ) {
$query = $sql -> prepare ( " SELECT u.`id`,u.`cname`,u.`resellerid`,u.`accounttype`,s.`brandname` FROM `userdata` AS u LEFT JOIN `settings` AS s ON u.`resellerid`=s.`resellerid` WHERE u.`active`='Y' " );
$query3 = $sql -> prepare ( " INSERT INTO `easywi_statistics` (`gameMasterInstalled`,`gameMasterActive`,`gameMasterSlotsAvailable`,`gameserverInstalled`,`gameserverActive`,`gameserverSlotsInstalled`,`gameserverSlotsActive`,`gameserverSlotsUsed`,`gameserverNoPassword`,`gameserverNoTag`,`gameserverNotRunning`,`ticketsCompleted`,`ticketsInProcess`,`ticketsNew`,`userAmount`,`userAmountActive`,`virtualMasterInstalled`,`virtualMasterActive`,`virtualMasterVserverAvailable`,`virtualInstalled`,`virtualActive`,`voiceMasterInstalled`,`voiceMasterActive`,`voiceMasterSlotsAvailable`,`voiceserverInstalled`,`voiceserverActive`,`voiceserverSlotsInstalled`,`voiceserverSlotsActive`,`voiceserverSlotsUsed`,`voiceserverTrafficAllowed`,`voiceserverTrafficUsed`,`webMasterInstalled`,`webMasterActive`,`webMasterSlotsAvailable`,`webspaceInstalled`,`webspaceActive`,`webspaceSpaceGiven`,`webspaceSpaceUsed`,`userID`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) " );
$query4 = $sql -> prepare ( " UPDATE `easywi_statistics_current` SET `gameMasterInstalled`=?,`gameMasterActive`=?,`gameMasterSlotsAvailable`=?,`gameserverInstalled`=?,`gameserverActive`=?,`gameserverSlotsInstalled`=?,`gameserverSlotsActive`=?,`gameserverSlotsUsed`=?,`gameserverNoPassword`=?,`gameserverNoTag`=?,`gameserverNotRunning`=?,`ticketsCompleted`=?,`ticketsInProcess`=?,`ticketsNew`=?,`userAmount`=?,`userAmountActive`=?,`virtualMasterInstalled`=?,`virtualMasterActive`=?,`virtualMasterVserverAvailable`=?,`virtualInstalled`=?,`virtualActive`=?,`voiceMasterInstalled`=?,`voiceMasterActive`=?,`voiceMasterSlotsAvailable`=?,`voiceserverInstalled`=?,`voiceserverActive`=?,`voiceserverSlotsInstalled`=?,`voiceserverSlotsActive`=?,`voiceserverSlotsUsed`=?,`voiceserverTrafficAllowed`=?,`voiceserverTrafficUsed`=?,`webMasterInstalled`=?,`webMasterActive`=?,`webMasterSlotsAvailable`=?,`webspaceInstalled`=?,`webspaceActive`=?,`webspaceSpaceGiven`=?,`webspaceSpaceUsed`=? WHERE `userID`=? LIMIT 1 " );
$query -> execute ();
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
if (( $row [ 'accounttype' ] == 'a' and ! isset ( $adminStatsCollected )) or $row [ 'accounttype' ] != 'a' ) {
echo " Gathering statistics for user " . $row [ 'cname' ] . " with ID " . $row [ 'id' ] . " \r \n " ;
$statsArray = array (
'gameMasterInstalled' => 0 ,
'gameMasterActive' => 0 ,
'gameMasterSlotsAvailable' => 0 ,
'gameMasterServerAvailable' => 0 ,
'gameMasterCrashed' => 0 ,
'gameserverInstalled' => 0 ,
'gameserverActive' => 0 ,
'gameserverSlotsInstalled' => 0 ,
'gameserverSlotsActive' => 0 ,
'gameserverSlotsUsed' => 0 ,
'gameserverNoPassword' => 0 ,
'gameserverNoTag' => 0 ,
'gameserverNotRunning' => 0 ,
'mysqlMasterInstalled' => 0 ,
'mysqlMasterActive' => 0 ,
'mysqlMasterDBAvailable' => 0 ,
'mysqlMasterCrashed' => 0 ,
'mysqlDBInstalled' => 0 ,
'mysqlDBActive' => 0 ,
'mysqlDBSpaceUsed' => 0 ,
'ticketsCompleted' => 0 ,
'ticketsInProcess' => 0 ,
'ticketsNew' => 0 ,
'userAmount' => 0 ,
'userAmountActive' => 0 ,
'virtualMasterInstalled' => 0 ,
'virtualMasterActive' => 0 ,
'virtualMasterVserverAvailable' => 0 ,
'virtualInstalled' => 0 ,
'virtualActive' => 0 ,
'voiceMasterInstalled' => 0 ,
'voiceMasterActive' => 0 ,
'voiceMasterServerAvailable' => 0 ,
'voiceMasterSlotsAvailable' => 0 ,
'voiceMasterCrashed' => 0 ,
'voiceserverInstalled' => 0 ,
'voiceserverActive' => 0 ,
'voiceserverSlotsInstalled' => 0 ,
'voiceserverSlotsActive' => 0 ,
'voiceserverSlotsUsed' => 0 ,
'voiceserverCrashed' => 0 ,
'voiceserverTrafficAllowed' => 0 ,
'voiceserverTrafficUsed' => 0 ,
'webMasterInstalled' => 0 ,
'webMasterActive' => 0 ,
'webMasterSpaceAvailable' => 0 ,
'webMasterVhostAvailable' => 0 ,
'webspaceInstalled' => 0 ,
'webspaceActive' => 0 ,
'webspaceSpaceGiven' => 0 ,
'webspaceSpaceGivenActive' => 0 ,
'webspaceSpaceUsed' => 0 ,
);
if ( $row [ 'accounttype' ] == 'a' ) {
$insertID = 0 ;
$adminStatsCollected = true ;
} else {
$insertID = $row [ 'id' ];
}
if ( $row [ 'accounttype' ] == 'a' ) {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `userdata` WHERE `resellerid`=? OR `id`=`resellerid` " );
} else if ( $row [ 'accounttype' ] == 'r' ) {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `userdata` WHERE `resellerid`=? " );
}
if ( $row [ 'accounttype' ] != 'u' ) {
$query2 -> execute ( array ( $insertID ));
$statsArray [ 'userAmount' ] = ( int ) $query2 -> fetchColumn ();
}
if ( $row [ 'accounttype' ] == 'a' ) {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `userdata` WHERE (`resellerid`=? OR `id`=`resellerid`) AND `active`='Y' " );
} else if ( $row [ 'accounttype' ] == 'r' ) {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `userdata` WHERE `resellerid`=? AND `active`='Y' " );
}
if ( $row [ 'accounttype' ] != 'u' ) {
$query2 -> execute ( array ( $insertID ));
$statsArray [ 'userAmountActive' ] = ( int ) $query2 -> fetchColumn ();
}
if ( $row [ 'accounttype' ] != 'u' ) {
2014-05-01 20:26:50 +02:00
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `rserverdata` WHERE `resellerid`=? " );
2014-05-01 19:20:28 +02:00
$query2 -> execute ( array ( $insertID ));
$statsArray [ 'gameMasterInstalled' ] = ( int ) $query2 -> fetchColumn ();
2014-05-01 20:26:50 +02:00
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount`,SUM(`maxslots`) AS `maxSlotsTotal`,SUM(`maxserver`) AS `maxServerTotal` FROM `rserverdata` WHERE `resellerid`=? AND `active`='Y' " );
2014-05-01 19:20:28 +02:00
$query2 -> execute ( array ( $insertID ));
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
$statsArray [ 'gameMasterActive' ] = ( int ) $row2 [ 'amount' ];
$statsArray [ 'gameMasterSlotsAvailable' ] = ( int ) $row2 [ 'maxSlotsTotal' ];
$statsArray [ 'gameMasterServerAvailable' ] = ( int ) $row2 [ 'maxServerTotal' ];
}
if ( $row [ 'accounttype' ] == 'a' ) {
2014-05-01 20:26:50 +02:00
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `voice_masterserver` WHERE `managedForID` IS NULL OR `resellerid`=? " );
2014-05-01 19:20:28 +02:00
$query2 -> execute ( array ( $insertID ));
2014-05-01 20:26:50 +02:00
} else {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `voice_masterserver` WHERE `managedForID`=? OR `resellerid`=? " );
$query2 -> execute ( array ( $insertID , $insertID ));
2014-05-01 19:20:28 +02:00
}
$statsArray [ 'voiceMasterInstalled' ] = ( int ) $query2 -> fetchColumn ();
if ( $row [ 'accounttype' ] == 'a' ) {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount`,SUM(`maxslots`) AS `maxSlotsTotal`,SUM(`maxserver`) AS `maxServerTotal` FROM `voice_masterserver` WHERE `managedForID` IS NULL AND `active`='Y' " );
$query2 -> execute ();
} else {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount`,SUM(`maxslots`) AS `maxSlotsTotal`,SUM(`maxserver`) AS `maxServerTotal` FROM `voice_masterserver` WHERE `managedForID`=? AND `active`='Y' " );
$query2 -> execute ( array ( $insertID ));
}
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
$statsArray [ 'voiceMasterActive' ] = ( int ) $row2 [ 'amount' ];
$statsArray [ 'voiceMasterSlotsAvailable' ] = ( int ) $row2 [ 'maxSlotsTotal' ];
$statsArray [ 'voiceMasterServerAvailable' ] = ( int ) $row2 [ 'maxServerTotal' ];
}
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `webMaster` WHERE `resellerID`=? " );
$query2 -> execute ( array ( $insertID ));
$statsArray [ 'webMasterInstalled' ] = ( int ) $query2 -> fetchColumn ();
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount`,SUM(`maxHDD`) AS `maxHDDTotal`,SUM(`maxVhost`) AS `maxVhostTotal` FROM `webMaster` WHERE `resellerID`=? AND `active`='Y' " );
$query2 -> execute ( array ( $insertID ));
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
$statsArray [ 'webMasterActive' ] = ( int ) $row2 [ 'amount' ];
$statsArray [ 'webMasterVhostAvailable' ] = ( int ) $row2 [ 'maxVhostTotal' ];
$statsArray [ 'webMasterSpaceAvailable' ] = ( int ) $row2 [ 'maxHDDTotal' ];
}
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `mysql_external_servers` WHERE `resellerid`=? " );
$query2 -> execute ( array ( $insertID ));
$statsArray [ 'mysqlMasterInstalled' ] = ( int ) $query2 -> fetchColumn ();
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount`,SUM(`max_databases`) AS `maxDBsTotal` FROM `mysql_external_servers` WHERE `resellerid`=? AND `active`='Y' " );
$query2 -> execute ( array ( $insertID ));
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
$statsArray [ 'mysqlMasterActive' ] = ( int ) $row2 [ 'amount' ];
$statsArray [ 'mysqlMasterDBAvailable' ] = ( int ) $row2 [ 'maxDBsTotal' ];
}
}
if ( $row [ 'accounttype' ] == 'u' ) {
$query2 = $sql -> prepare ( " SELECT `active`,`slots`,`stopped`,`war`,`brandname`,`queryName`,`queryPassword`,`queryNumplayers` FROM `gsswitch` AS g WHERE `userid`=? " );
} else {
$query2 = $sql -> prepare ( " SELECT `active`,`slots`,`stopped`,`war`,`brandname`,`queryName`,`queryPassword`,`queryNumplayers` FROM `gsswitch` AS g WHERE `resellerid`=? " );
}
$query2 -> execute ( array ( $insertID ));
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
$statsArray [ 'gameserverInstalled' ] ++ ;
$statsArray [ 'gameserverSlotsInstalled' ] += ( int ) $row2 [ 'slots' ];
if ( $row2 [ 'active' ] == 'Y' ) {
$statsArray [ 'gameserverActive' ] ++ ;
$statsArray [ 'gameserverSlotsActive' ] += ( int ) $row2 [ 'slots' ];
$statsArray [ 'gameserverSlotsUsed' ] += ( int ) $row2 [ 'queryNumplayers' ];
}
2014-05-01 20:00:46 +02:00
if ( $row2 [ 'queryName' ] != 'OFFLINE' and $row2 [ 'stopped' ] != 'Y' and $row2 [ 'war' ] == 'Y' and $row2 [ 'queryPassword' ] == 'N' ) {
2014-05-01 19:20:28 +02:00
$statsArray [ 'gameserverNoPassword' ] ++ ;
} else if ( $row2 [ 'queryName' ] == 'OFFLINE' and $row2 [ 'stopped' ] != 'Y' ) {
$statsArray [ 'gameserverNotRunning' ] ++ ;
}
if ( $row2 [ 'queryName' ] != '' and $row2 [ 'stopped' ] == 'N' and $row2 [ 'queryName' ] != 'OFFLINE' and $row2 [ 'brandname' ] == 'Y' and $row [ 'brandname' ] != '' and strpos ( strtolower ( $row2 [ 'queryName' ]), strtolower ( $row [ 'brandname' ])) === false ) {
$statsArray [ 'gameserverNoTag' ] ++ ;
}
}
if ( $row [ 'accounttype' ] == 'u' ) {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `tickets` WHERE `userid`=? AND `state` = 'C' " );
} else {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `tickets` WHERE `resellerid`=? AND `state` = 'C' " );
}
$query2 -> execute ( array ( $insertID ));
$statsArray [ 'ticketsCompleted' ] = ( int ) $query2 -> fetchColumn ();
if ( $row [ 'accounttype' ] == 'u' ) {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `tickets` WHERE `userid`=? AND `state` NOT IN ('C','D') " );
} else {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `tickets` WHERE `resellerid`=? AND `state` NOT IN ('C','D') " );
}
$query2 -> execute ( array ( $insertID ));
$statsArray [ 'ticketsInProcess' ] = ( int ) $query2 -> fetchColumn ();
if ( $row [ 'accounttype' ] == 'u' ) {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `tickets` WHERE `userid`=? AND `state` = 'N' " );
} else {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `tickets` WHERE `resellerid`=? AND `state` = 'N' " );
}
$query2 -> execute ( array ( $insertID ));
$statsArray [ 'ticketsNew' ] = ( int ) $query2 -> fetchColumn ();
if ( $row [ 'accounttype' ] == 'u' ) {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount`,SUM(`slots`) AS `slotsInstalled` FROM `voice_server` WHERE `userid`=? GROUP BY `userid` " );
} else {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount`,SUM(`slots`) AS `slotsInstalled` FROM `voice_server` WHERE `resellerid`=? GROUP BY `resellerid` " );
}
$query2 -> execute ( array ( $insertID ));
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
$statsArray [ 'voiceserverInstalled' ] = ( int ) $row2 [ 'amount' ];
$statsArray [ 'voiceserverSlotsInstalled' ] = ( int ) $row2 [ 'slotsInstalled' ];
}
if ( $row [ 'accounttype' ] == 'u' ) {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount`,SUM(`slots`) AS `slotsInstalled`,SUM(`queryNumplayers`) AS `slotsUsed`,SUM(`maxtraffic`) AS `trafficAllowed`,SUM(`filetraffic`) AS `trafficUsed` FROM `voice_server` WHERE `active`='Y' AND `userid`=? GROUP BY `userid` " );
} else {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount`,SUM(`slots`) AS `slotsInstalled`,SUM(`queryNumplayers`) AS `slotsUsed`,SUM(`maxtraffic`) AS `trafficAllowed`,SUM(`filetraffic`) AS `trafficUsed` FROM `voice_server` WHERE `active`='Y' AND `resellerid`=? GROUP BY `resellerid` " );
}
$query2 -> execute ( array ( $insertID ));
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
$statsArray [ 'voiceserverActive' ] = ( int ) $row2 [ 'amount' ];
$statsArray [ 'voiceserverSlotsActive' ] = ( int ) $row2 [ 'slotsInstalled' ];
$statsArray [ 'voiceserverSlotsUsed' ] = ( int ) $row2 [ 'slotsUsed' ];
$statsArray [ 'voiceserverTrafficAllowed' ] = ( int ) $row2 [ 'trafficAllowed' ];
$statsArray [ 'voiceserverTrafficUsed' ] = round (( int ) $row2 [ 'trafficUsed' ] / 1024 );
}
if ( $row [ 'accounttype' ] == 'u' ) {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `voice_server` WHERE `active`='Y' AND `uptime`='0' AND `userid`=? GROUP BY `userid` " );
} else {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `voice_server` WHERE `active`='Y' AND `uptime`='0' AND `resellerid`=? GROUP BY `resellerid` " );
}
$query2 -> execute ( array ( $insertID ));
$statsArray [ 'voiceserverCrashed' ] = ( int ) $query2 -> fetchColumn ();
if ( $row [ 'accounttype' ] == 'u' ) {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount`,SUM(`hdd`) AS `spaceInstalled` FROM `webVhost` WHERE `userID`=? GROUP BY `userID` " );
} else {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount`,SUM(`hdd`) AS `spaceInstalled` FROM `webVhost` WHERE `resellerID`=? GROUP BY `resellerID` " );
}
$query2 -> execute ( array ( $insertID ));
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
$statsArray [ 'webspaceInstalled' ] = ( int ) $row2 [ 'amount' ];
$statsArray [ 'webspaceSpaceGivenActive' ] = ( int ) $row2 [ 'spaceInstalled' ];
}
if ( $row [ 'accounttype' ] == 'u' ) {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount`,SUM(`hdd`) AS `spaceInstalled`,SUM(`hddUsage`) AS `spaceUsed` FROM `webVhost` WHERE `active`='Y' AND `userID`=? GROUP BY `userID` " );
} else {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount`,SUM(`hdd`) AS `spaceInstalled`,SUM(`hddUsage`) AS `spaceUsed` FROM `webVhost` WHERE `active`='Y' AND `resellerID`=? GROUP BY `resellerID` " );
}
$query2 -> execute ( array ( $insertID ));
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
$statsArray [ 'webspaceActive' ] = ( int ) $row2 [ 'amount' ];
$statsArray [ 'webspaceSpaceGiven' ] = ( int ) $row2 [ 'spaceInstalled' ];
$statsArray [ 'webspaceSpaceUsed' ] = ( int ) $row2 [ 'spaceUsed' ];
}
if ( $row [ 'accounttype' ] == 'u' ) {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `mysql_external_dbs` WHERE `uid`=? GROUP BY `uid` " );
} else {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `mysql_external_dbs` WHERE `resellerid`=? GROUP BY `resellerid` " );
}
$query2 -> execute ( array ( $insertID ));
$statsArray [ 'mysqlDBInstalled' ] = ( int ) $query2 -> fetchColumn ();
if ( $row [ 'accounttype' ] == 'u' ) {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount`,SUM(`dbSize`) AS `spaceUsed` FROM `mysql_external_dbs` WHERE `active`='Y' AND `uid`=? GROUP BY `uid` " );
} else {
$query2 = $sql -> prepare ( " SELECT COUNT(1) AS `amount`,SUM(`dbSize`) AS `spaceUsed` FROM `mysql_external_dbs` WHERE `active`='Y' AND `resellerid`=? GROUP BY `resellerid` " );
}
$query2 -> execute ( array ( $insertID ));
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
$statsArray [ 'mysqlDBActive' ] = ( int ) $row2 [ 'amount' ];
$statsArray [ 'mysqlDBSpaceUsed' ] = ( int ) $row2 [ 'spaceUsed' ];
}
unset ( $updateString , $insertString , $duplicateString );
foreach ( $statsArray as $k => $v ) {
if ( isset ( $updateString )) {
$updateString .= ',`' . $k . '`=' . $v ;
$insertColumns .= ',`' . $k . '`' ;
$duplicateString .= ',`' . $k . '`=(`' . $k . '`*(`countUpdates`/(`countUpdates`+1))+(VALUES(`' . $k . '`)*(1/(`countUpdates`+1))))' ;
} else {
$updateString = '`' . $k . '`=' . $v ;
$insertColumns = '`' . $k . '`' ;
$duplicateString = '`' . $k . '`=(`' . $k . '`*(`countUpdates`/(`countUpdates`+1))+(VALUES(`' . $k . '`)*(1/(`countUpdates`+1))))' ;
}
}
if ( isset ( $updateString )) {
$query2 = $sql -> prepare ( " UPDATE `easywi_statistics_current` SET " . $updateString . " WHERE `userID`= " . $insertID . " LIMIT 1 " );
$query2 -> execute ();
$query2 = $sql -> prepare ( " INSERT INTO `easywi_statistics` ( " . $insertColumns . " ,`userID`,`statDate`,`countUpdates`) VALUES ( " . implode ( ',' , $statsArray ) . " , " . $insertID . " ,' " . date ( 'Y-m-d H:00:00' ) . " ',1) ON DUPLICATE KEY UPDATE " . $duplicateString . " ,`countUpdates`=`countUpdates`+1 " );
$query2 -> execute ();
}
}
}
}
2014-01-10 22:16:51 +01:00
$query = $sql -> prepare ( " UPDATE `settings` SET `lastCronStatus`=UNIX_TIMESTAMP() " );
2013-08-28 22:47:04 +02:00
$query -> execute ();
2014-03-30 12:54:42 +02:00
2014-05-01 19:20:28 +02:00
2013-08-28 22:47:04 +02:00
} else {
header ( 'Location: login.php' );
die ( 'Statuscheck can only be run via console or a cronjob' );
}