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
}
if ( isset ( $argv )) {
2013-09-29 15:29:58 +02:00
$args = array ();
2013-08-28 22:47:04 +02:00
foreach ( $argv as $a ) {
2013-10-03 12:49:13 +02:00
if ( $a == 'gs' or $a == 'vs' ) $checkTypeOfServer = $a ;
else if ( is_numeric ( $a )) $sleep = $a ;
2013-08-28 22:47:04 +02:00
else {
2013-10-03 12:49:13 +02:00
$e = explode ( ':' , $a );
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__ ));
include ( EASYWIDIR . '/stuff/vorlage.php' );
include ( EASYWIDIR . '/stuff/functions.php' );
include ( EASYWIDIR . '/stuff/class_validator.php' );
include ( EASYWIDIR . '/stuff/settings.php' );
include ( EASYWIDIR . '/stuff/ssh_exec.php' );
include ( EASYWIDIR . '/stuff/class_voice.php' );
include ( EASYWIDIR . '/stuff/queries.php' );
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
if ( ! isset ( $ip ) or $ui -> escaped ( 'SERVER_ADDR' , 'server' ) == $ip or in_array ( $ip , ipstoarray ( $rSA [ 'cronjob_ips' ]))) {
if ( isset ( $checkTypeOfServer )) {
print ( $checkTypeOfServer == 'gs' ) ? 'Checking Gameserver' . " \r \n " : 'Checking Voiceserver' . " \r \n " ;
} else {
$checkTypeOfServer = 'all' ;
print 'Checking Gameserver and Voiceserver' . " \r \n " ;
}
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
# 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` " );
$query2 = $sql -> prepare ( " SELECT `active`,`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 ) {
unset ( $active );
2013-10-03 12:49:13 +02:00
$resellerid = $row [ 'resellerid' ];
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
$active = $row2 [ 'active' ];
$shutdownempty = $row2 [ 'shutdownempty' ];
$shutdownemptytime = $row2 [ 'shutdownemptytime' ];
2013-08-28 22:47:04 +02:00
$firstcheck = '00-00-' . round ( 2 * ( strtotime ( $row2 [ 'lastcheck' ]) - strtotime ( $row2 [ 'oldcheck' ])) / 60 );
$firstchecktime = date ( 'd-G-i' );
}
2013-10-10 08:06:37 +02:00
if ( isset ( $active )) $resellersettings [ $resellerid ] = array ( 'active' => $active , '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
}
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-10-03 12:49:13 +02:00
function statushandle () {
2013-10-13 17:11:32 +02:00
2013-10-03 12:49:13 +02:00
global $userid , $resellersettings , $resellerid , $serverid , $logdate , $aeskey , $address , $gametype , $war , $status , $password , $lendserver , $elapsed , $shutdownemptytime , $numplayers , $maxplayers , $slots , $brandname , $name , $map , $secnotified , $notified , $sql , $ssprache , $lid ;
2013-10-13 17:11:32 +02:00
2013-10-03 12:49:13 +02:00
list ( $serverip , $port ) = explode ( ':' , $address );
2013-10-13 17:11:32 +02:00
2013-09-29 15:29:58 +02:00
$returnCmd = array ();
2013-10-13 17:11:32 +02:00
// Check lendserver specific settings
if ( $lendserver == 'Y' ) {
// Running but no lend information in temp table
if ( $status == 'UP' ) {
$query = $sql -> prepare ( " SELECT 1 FROM `lendedserver` WHERE `id`=? LIMIT 1 " );
$query -> execute ( array ( $lid ));
if ( $query -> rowCount () == 0 ) {
print " Will stop lendserver $address with lendID $lid because not lendet \r \n " ;
$stopserver = true ;
}
if ( ! isset ( $stopserver ) and $lendserver == 'Y' and $resellersettings [ $resellerid ][ 'active' ] == '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 ;
}
}
// Expected to be running but is not, so remove from temp table
if ( isset ( $stopserver ) or $status != 'UP' ) {
if ( ! isset ( $stopserver )) {
print " Will remove lendserver $address with lendID $lid because it is lendet but stopped \r \n " ;
}
$doNotRestart = true ;
$query = $sql -> prepare ( " DELETE FROM `lendedserver` WHERE `id`=? LIMIT 1 " );
$query -> execute ( array ( $lid ));
}
}
2013-10-03 12:49:13 +02:00
if ( $status == 'UP' ) {
2013-10-13 17:11:32 +02:00
$rulebreak = array ();
if ( $war == 'Y' and $password == 'N' ) {
$rulebreak [] = $ssprache -> nopassword ;
2013-10-03 12:49:13 +02:00
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 " ;
2013-10-13 17:11:32 +02:00
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
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-08-28 22:47:04 +02:00
}
}
2013-10-13 17:11:32 +02:00
2013-10-03 12:49:13 +02:00
if ( $maxplayers > $slots ) {
2013-10-13 17:11:32 +02:00
$rulebreak [] = $ssprache -> tohighslots ;
2013-10-03 12:49:13 +02:00
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 " ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
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-10-13 17:11:32 +02:00
2013-10-03 12:49:13 +02:00
if ( $brandname == 'Y' and $resellersettings [ $resellerid ][ 'brandname' ] != '' and strpos ( strtolower ( $name ), strtolower ( $resellersettings [ $resellerid ][ 'brandname' ])) === false ) {
2013-10-13 17:11:32 +02:00
$rulebreak [] = $ssprache -> noservertag ;
2013-10-03 12:49:13 +02:00
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 " ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
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 " ;
2013-08-28 22:47:04 +02:00
}
}
2013-10-13 17:11:32 +02:00
if ( count ( $rulebreak ) == 0 and ! isset ( $stopserver )) {
2013-10-03 12:49:13 +02:00
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 " ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 17:11:32 +02:00
if ( $secnotified == 'N' and count ( $rulebreak ) > 0 ) {
2013-08-28 22:47:04 +02:00
if ( $resellerid == 0 ) {
2013-10-13 17:11:32 +02:00
$query = $sql -> prepare ( " SELECT `id`,`mail_securitybreach` FROM `userdata` WHERE `id`=? OR (`resellerid`=0 AND `accounttype`='a') " );
2013-08-28 22:47:04 +02:00
$query -> execute ( array ( $userid ));
2013-10-13 17:11:32 +02:00
2013-08-28 22:47:04 +02:00
} else {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT `id`,`mail_securitybreach` FROM `userdata` WHERE `id`=? OR (`id`=? AND `accounttype`='r') " );
2013-10-03 12:49:13 +02:00
$query -> execute ( array ( $userid , $resellerid ));
2013-08-28 22:47:04 +02:00
}
2013-10-13 17:11:32 +02:00
2013-08-28 22:47:04 +02:00
foreach ( $query -> fetchall ( PDO :: FETCH_ASSOC ) as $row ) {
2013-10-03 12:49:13 +02:00
if ( $row [ 'mail_securitybreach' ] == 'Y' ) {
2013-10-13 17:15:35 +02:00
sendmail ( 'emailsecuritybreach' , $row [ 'id' ], $address , implode ( '<br>' , $rulebreak ));
2013-08-28 22:47:04 +02:00
}
}
2013-10-13 17:11:32 +02:00
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " UPDATE `gsswitch` SET `secnotified`='Y' WHERE `serverip`=? AND `port`=? LIMIT 1 " );
2013-10-03 12:49:13 +02:00
$query -> execute ( array ( $serverip , $port ));
2013-10-13 17:11:32 +02:00
2013-08-28 22:47:04 +02:00
}
2013-10-13 17:11:32 +02:00
if ( $secnotified == 'Y' and count ( $rulebreak ) == 0 ) {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " UPDATE `gsswitch` SET `secnotified`='N' WHERE `serverip`=? AND `port`=? LIMIT 1 " );
2013-10-03 12:49:13 +02:00
$query -> execute ( array ( $serverip , $port ));
2013-08-28 22:47:04 +02:00
}
2013-10-13 17:11:32 +02:00
2013-08-28 22:47:04 +02:00
if ( isset ( $stopserver )) {
2013-10-13 17:11:32 +02:00
$numplayers = 0 ;
$map = '' ;
2013-10-03 12:49:13 +02:00
$tmp = gsrestart ( $serverid , 'so' , $aeskey , $resellerid );
if ( is_array ( $tmp )) {
foreach ( $tmp as $t ) {
$returnCmd [] = $t ;
}
}
2013-10-13 17:11:32 +02:00
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " DELETE FROM `lendedserver` WHERE `serverid`=? AND `resellerid`=? AND `servertype`='g' LIMIT 1 " );
2013-10-03 12:49:13 +02:00
$query -> execute ( array ( $serverid , $resellerid ));
2013-08-28 22:47:04 +02:00
}
2013-10-13 17:11:32 +02:00
if ( $notified > 0 ) {
$query = $sql -> prepare ( " UPDATE `gsswitch` SET `notified`=0 WHERE `serverip`=? AND `port`=? LIMIT 1 " );
2013-10-03 12:49:13 +02:00
$query -> execute ( array ( $serverip , $port ));
2013-08-28 22:47:04 +02:00
}
2013-10-13 17:11:32 +02:00
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02: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-10-13 17:11:32 +02:00
if ( ! isset ( $doNotRestart )) {
2013-08-28 22:47:04 +02:00
$notified ++ ;
2013-10-13 17:11:32 +02:00
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT `autoRestart` FROM `gsswitch` WHERE `serverip`=? and `port`=? LIMIT 1 " );
2013-10-03 12:49:13 +02:00
$query -> execute ( array ( $serverip , $port ));
2013-10-13 17:11:32 +02:00
if ( $query -> fetchColumn () == 'Y' and $notified >= $resellersettings [ $resellerid ][ 'down_checks' ]) {
2013-08-28 22:47:04 +02:00
print " Restarting: $address\r\n " ;
2013-10-13 17:11:32 +02:00
$tmp = gsrestart ( $serverid , 're' , $aeskey , $resellerid );
2013-10-03 12:49:13 +02:00
if ( is_array ( $tmp )) {
foreach ( $tmp as $t ) {
$returnCmd [] = $t ;
}
}
2013-10-13 17:11:32 +02:00
2013-08-28 22:47:04 +02:00
} else {
print " Not Restarting: $address\r\n " ;
}
2013-10-13 17:11:32 +02:00
2013-10-03 12:49:13 +02:00
if ( $notified == $resellersettings [ $resellerid ][ 'down_checks' ]) {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT `mail_serverdown` FROM `userdata` WHERE `id`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$query -> execute ( array ( $userid ));
foreach ( $query -> fetchall ( PDO :: FETCH_ASSOC ) as $row ) {
2013-10-13 17:11:32 +02:00
if ( $row [ 'mail_serverdown' ] == 'Y' ) {
sendmail ( 'emaildownrestart' , $userid , $address , '' );
}
2013-08-28 22:47:04 +02:00
}
}
}
}
2013-10-13 17:11:32 +02:00
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " UPDATE `gsswitch` SET `queryName`=?,`queryNumplayers`=?,`queryMaxplayers`=?,`queryMap`=?,`queryPassword`=?,`queryUpdatetime`=?,`notified`=? WHERE `serverip`=? and `port`=? LIMIT 1 " );
2013-10-03 12:49:13 +02:00
$query -> execute ( array ( $name , $numplayers , $maxplayers , $map , $password , $logdate , $notified , $serverip , $port ));
2013-10-13 17:11:32 +02:00
2013-08-29 23:37:49 +02:00
return $returnCmd ;
2013-08-28 22:47:04 +02:00
}
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-09-29 15:29:58 +02:00
$other = array ();
$i = 1 ;
$totalcount = 0 ;
$queries = array ();
2013-10-13 17:11:32 +02:00
// Get the list of servers which are active and are not stopped
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT g.`id`,g.`serverid`,g.`serverip`,g.`port`,t.`qstat` 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-03 12:49:13 +02:00
$qstat = $row [ 'qstat' ];
$serverip = $row [ 'serverip' ];
$port = $row [ 'port' ];
$server = $serverip . ':' . $port ;
2013-10-13 17:11:32 +02:00
2013-10-03 12:49:13 +02:00
if ( ! in_array ( $qstat , array ( '' , null , false ))) {
2013-10-13 17:11:32 +02:00
2013-10-06 14:39:54 +02:00
if ( in_array ( $qstat , array ( 'minecraft' , 'tm' , 'gtasamp' , 'teeworlds' , 'mtasa' ))) {
$other [] = array ( 'qstat' => $qstat , 'switchID' => $row [ 'id' ]);
2013-10-03 16:48:54 +02:00
} else {
2013-10-03 12:49:13 +02:00
$queries [] = '-' . $qstat . ' ' . $server ;
2013-08-28 22:47:04 +02:00
$i ++ ;
}
2013-10-13 17:11:32 +02:00
2013-10-03 16:48:54 +02:00
if ( $i == 50 ) {
2013-10-03 12:49:13 +02:00
$querry_array [] = implode ( ' ' , $queries );
2013-09-29 15:29:58 +02:00
$queries = array ();
$i = 1 ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 17:11:32 +02:00
2013-08-28 22:47:04 +02:00
$totalcount ++ ;
}
}
2013-10-13 17:11:32 +02:00
2013-10-03 12:49:13 +02:00
$querry_array [] = implode ( ' ' , $queries );
2013-10-13 17:11:32 +02:00
2013-08-28 22:47:04 +02:00
print " Checking $totalcount server \r \n " ;
2013-09-29 15:29:58 +02:00
$shellCmds = array ();
2013-10-13 17:11:32 +02:00
2013-08-28 22:47:04 +02:00
foreach ( $querry_array as $querystring ) {
2013-10-13 17:11:32 +02:00
2013-09-29 15:29:58 +02:00
$xml = array ();
2013-10-13 17:11:32 +02:00
unset ( $xmlquakestring );
print " The Quakestat Querystring is: " . $querystring . " \r \n " ;
2013-08-28 22:47:04 +02:00
ob_start ();
2013-10-03 12:49:13 +02:00
if ( $querystring != '' ) {
2013-08-28 22:47:04 +02:00
passthru ( escapeshellcmd ( " /usr/bin/quakestat -xml -R -utf8 $querystring -sort i " ));
2013-10-13 17:11:32 +02:00
$xmlquakestring = ob_get_contents ();
2013-08-28 22:47:04 +02:00
}
ob_end_clean ();
2013-10-13 17:11:32 +02:00
2013-08-28 22:47:04 +02:00
if ( isset ( $xmlquakestring )) {
2013-10-13 17:11:32 +02:00
$xml = @ simplexml_load_string ( $xmlquakestring );
2013-08-28 22:47:04 +02:00
}
2013-10-13 17:11:32 +02:00
2013-08-28 22:47:04 +02:00
if ( ! is_array ( $xml ) and ! is_object ( $xml )) {
2013-09-29 15:29:58 +02:00
$xml = array ();
2013-08-28 22:47:04 +02:00
}
2013-10-13 17:11:32 +02:00
2013-08-28 22:47:04 +02:00
unset ( $badstatus );
unset ( $badquery );
unset ( $badxml );
unset ( $badquerystring );
2013-10-13 17:11:32 +02:00
2013-08-28 22:47:04 +02:00
foreach ( $xml as $xml2 ) {
2013-10-03 12:49:13 +02:00
$address = $xml2 [ 'address' ];
list ( $ip , $port ) = explode ( ':' , $address );
2013-10-13 17:11:32 +02:00
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT t.`qstat` FROM `gsswitch` g INNER JOIN `serverlist` s ON g.`serverid`=s.`id` INNER JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE g.`serverip`=? AND g.`port`=? AND g.`active`='Y' LIMIT 1 " );
2013-10-03 12:49:13 +02:00
$query -> execute ( array ( $ip , $port ));
$qstat = $query -> fetchColumn ();
2013-10-13 17:11:32 +02:00
2013-10-03 12:49:13 +02:00
if ( $xml2 [ 'status' ] == 'DOWN' or $xml2 [ 'status' ] == 'TIMEOUT' ) {
2013-08-28 22:47:04 +02:00
if ( isset ( $badquery )) {
2013-10-05 13:39:56 +02:00
$badquery .= ' -' . $qstat . ' ' . $address ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-05 13:39:56 +02:00
$badquery = ' -' . $qstat . ' ' . $address ;
2013-08-28 22:47:04 +02:00
}
}
}
2013-10-13 17:11:32 +02:00
2013-09-29 15:29:58 +02:00
$badstatus = array ();
2013-10-03 12:49:13 +02:00
if ( isset ( $badquery ) and $badquery != '' ) {
2013-08-28 22:47:04 +02:00
print " The recheck Querystring is: $badquery\r\n " ;
ob_start ();
passthru ( escapeshellcmd ( " /usr/bin/quakestat -xml -R -utf8 $badquery -sort i " ));
$badquerystring = ob_get_contents ();
ob_end_clean ();
$badxml = simplexml_load_string ( $badquerystring );
foreach ( $badxml as $badxml2 ) {
2013-10-10 08:06:37 +02:00
if ( isset ( $badxml2 [ 'address' ]) and isip ( $badxml2 [ 'address' ], 'ipx' )) {
2013-10-05 13:39:56 +02:00
$address = $badxml2 [ 'address' ];
$status = $badxml2 [ 'status' ];
$badstatus [ $address ] = array ( 'status' => $status );
if ( $badxml2 [ 'status' ] == 'UP' ) {
if ( $badxml2 [ 'type' ] != 'A2S' ) {
$gametype = $badxml2 -> gametype ;
}
foreach ( $badxml2 -> rules -> rule as $rule ) {
switch (( string ) $rule [ 'name' ]) {
case 'gamename' :
$gametype = $rule ;
break ;
}
2013-08-28 22:47:04 +02:00
}
2013-10-05 13:39:56 +02:00
$name = $badxml2 -> name ;
$numplayers = $badxml2 -> numplayers ;
$maxplayers = $badxml2 -> maxplayers ;
$map = $badxml2 -> map ;
$badstatus [ $address ] = array ( 'gametype' => $gametype , 'name' => $name , 'numplayers' => $numplayers , 'maxplayers' => $maxplayers , 'map' => $map , 'rules' => $badxml2 -> rules -> rule );
2013-08-28 22:47:04 +02:00
}
}
}
}
2013-09-29 15:29:58 +02:00
if ( ! is_array ( $xml ) and ! is_object ( $xml )) $xml = array ();
2013-08-28 22:47:04 +02:00
foreach ( $xml as $xml2 ) {
2013-09-29 15:29:58 +02:00
$lid = 0 ;
2013-08-28 22:47:04 +02:00
unset ( $war );
2013-10-03 12:49:13 +02:00
$address = $xml2 [ 'address' ];
2013-09-29 15:29:58 +02:00
$password = '' ;
2013-10-03 12:49:13 +02:00
$addressarray = explode ( ':' , $address );
$ip = $addressarray [ 0 ];
$port = $addressarray [ 1 ];
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT g.*,t.`shorten`,t.`qstat` FROM `gsswitch` g INNER JOIN `serverlist` s ON g.`serverid`=s.`id` INNER JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE g.`serverip`=? AND g.`port`=? LIMIT 1 " );
2013-10-03 12:49:13 +02:00
$query -> execute ( array ( $ip , $port ));
2013-08-28 22:47:04 +02:00
foreach ( $query -> fetchall ( PDO :: FETCH_ASSOC ) as $row ) {
2013-10-03 12:49:13 +02:00
$serverid = $row [ 'id' ];
$rootID = $row [ 'rootID' ];
$resellerid = $row [ 'resellerid' ];
$lendserver = $row [ 'lendserver' ];
$notified = $row [ 'notified' ];
$secnotified = $row [ 'secnotified' ];
$userid = $row [ 'userid' ];
$qstat = $row [ 'qstat' ];
$shorten = $row [ 'shorten' ];
$brandname = $row [ 'brandname' ];
$slots = $row [ 'slots' ];
$war = $row [ 'war' ];
if ( $row [ 'tvenable' ] == 'Y' ) {
2013-08-28 22:47:04 +02:00
$slots ++ ;
}
2013-10-03 12:49:13 +02:00
if ( $lendserver == 'Y' and $resellersettings [ $resellerid ][ 'active' ] == 'Y' and $resellersettings [ $resellerid ][ 'shutdownempty' ] == 'Y' ) {
$shutdownemptytime = $resellersettings [ $resellerid ][ 'shutdownemptytime' ];
2013-09-29 15:29:58 +02:00
$query2 = $sql -> prepare ( " SELECT `id`,`started` FROM `lendedserver` WHERE `serverid`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$query2 -> execute ( array ( $serverid ));
foreach ( $query2 -> fetchall ( PDO :: FETCH_ASSOC ) as $row2 ) {
2013-10-03 12:49:13 +02:00
$lid = $row2 [ 'id' ];
2013-10-13 17:11:32 +02:00
$elapsed = round (( strtotime ( 'now' ) - strtotime ( $row2 [ 'started' ])) / 60 );
2013-08-28 22:47:04 +02:00
}
}
}
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT `qstatpassparam` FROM `servertypes` WHERE `shorten`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$query -> execute ( array ( $shorten ));
foreach ( $query -> fetchall ( PDO :: FETCH_ASSOC ) as $row ) {
2013-10-03 12:49:13 +02:00
$qstatpassparam = $row [ 'qstatpassparam' ];
$passparams = explode ( ':' , $qstatpassparam );
2013-08-28 22:47:04 +02:00
}
2013-10-03 12:49:13 +02:00
unset ( $password , $rulebreak , $maxplayers , $name );
2013-10-05 13:39:56 +02:00
if (( ! isset ( $xml2 [ 'status' ]) or $xml2 [ 'status' ] == 'DOWN' or $xml2 [ 'status' ] == 'TIMEOUT' ) and ( ! isset ( $badstatus [ $address ][ 'status' ]) or $badstatus [ $address ][ 'status' ] == 'DOWN' or $badstatus [ $address ][ 'status' ] == 'TIMEOUT' )) {
2013-10-03 12:49:13 +02:00
$status = 'DOWN' ;
2013-09-29 15:29:58 +02:00
$name = '' ;
$numplayers = 0 ;
$maxplayers = 0 ;
$map = '' ;
$gametype = '' ;
2013-08-28 22:47:04 +02:00
print " recheck status for $address is still: $status\r\n " ;
2013-10-05 13:39:56 +02:00
} else if (( ! $xml2 [ 'status' ] or $xml2 [ 'status' ] == 'DOWN' or $xml2 [ 'status' ] == 'TIMEOUT' ) and isset ( $badstatus [ $address ][ 'status' ]) and $badstatus [ $address ][ 'status' ] == 'UP' ) {
2013-10-03 12:49:13 +02:00
$status = 'UP' ;
2013-09-08 17:21:34 +02:00
foreach ( $badstatus [ $address ][ 'rules' ] as $rule ) {
2013-08-28 22:47:04 +02:00
switch (( string ) $rule [ 'name' ]) {
2013-09-08 17:21:34 +02:00
case $passparams [ 0 ] :
2013-10-03 12:49:13 +02:00
if ( $rule == $passparams [ 1 ]) $password = 'Y' ;
else $password = 'N' ;
2013-08-28 22:47:04 +02:00
break ;
}
}
2013-10-03 12:49:13 +02:00
$name = $badstatus [ $address ][ 'name' ];
$numplayers = $badstatus [ $address ][ 'numplayers' ];
$maxplayers = $badstatus [ $address ][ 'maxplayers' ];
$map = $badstatus [ $address ][ 'map' ];
$gametype = $badstatus [ $address ][ 'gametype' ];
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
$status = 'UP' ;
$name = $xml2 -> name ;
$numplayers = $xml2 -> numplayers ;
$maxplayers = $xml2 -> maxplayers ;
$map = $xml2 -> map ;
$type = $xml2 [ 'type' ];
if ( $type != 'A2S' ) {
$gametype = $xml2 -> gametype ;
2013-08-28 22:47:04 +02:00
}
foreach ( $xml2 -> rules -> rule as $rule ) {
switch (( string ) $rule [ 'name' ]) {
case 'gamename' :
2013-10-03 12:49:13 +02:00
$gametype = $rule ;
2013-08-28 22:47:04 +02:00
break ;
2013-09-08 17:21:34 +02:00
case $passparams [ 0 ] :
2013-10-03 12:49:13 +02:00
if ( $rule == $passparams [ 1 ]) $password = 'Y' ;
else $password = 'N' ;
2013-08-28 22:47:04 +02:00
break ;
}
}
}
2013-10-03 12:49:13 +02:00
if ( ! isset ( $password ) or $password == '' ) {
$password = 'N' ;
}
if ( ! isset ( $elapsed )) {
$elapsed = 0 ;
}
if ( ! isset ( $shutdownemptytime )) {
$shutdownemptytime = 0 ;
}
2013-08-29 23:37:49 +02:00
if ( isset ( $war )) {
2013-10-03 12:49:13 +02:00
$tmp = statushandle ();
if ( is_array ( $tmp )) {
foreach ( $tmp as $t ) {
$shellCmds [ $rootID ][] = $t ;
}
}
2013-08-29 23:37:49 +02:00
}
2013-08-28 22:47:04 +02:00
}
}
2013-10-03 12:49:13 +02:00
print " Checking Gameserver with Easy-Wi query: \r \n " ;
2013-08-28 22:47:04 +02:00
foreach ( $other as $array ) {
2013-10-03 12:49:13 +02:00
unset ( $userid , $serverid );
2013-09-29 15:29:58 +02:00
$lid = 0 ;
2013-10-03 12:49:13 +02:00
$qstat = $array [ 'qstat' ];
$serverid = $array [ 'switchID' ];
2013-10-06 14:39:54 +02:00
$query = $sql -> prepare ( " SELECT s.`id`,t.`description`,g.`serverip`,g.`port`,g.`port2`,g.`slots`,g.`war`,g.`brandname`,g.`secnotified`,g.`notified`,g.`lendserver`,g.`userid`,g.`resellerid`,g.`rootID` 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-10-13 11:42:31 +02:00
$query2 = $sql -> prepare ( " SELECT `id`,`started` FROM `lendedserver` WHERE `serverid`=? LIMIT 1 " );
2013-10-03 12:49:13 +02:00
$query -> execute ( array ( $serverid ));
2013-08-28 22:47:04 +02:00
foreach ( $query -> fetchall ( PDO :: FETCH_ASSOC ) as $row ) {
2013-10-06 14:39:54 +02:00
$serverip = $row [ 'serverip' ];
$port = $row [ 'port' ];
$address = $row [ 'serverip' ] . ':' . $row [ 'port' ];
2013-10-03 12:49:13 +02:00
$gametype = $row [ 'description' ];
$notified = $row [ 'notified' ];
$secnotified = $row [ 'secnotified' ];
$lendserver = $row [ 'lendserver' ];
$slots = $row [ 'slots' ];
$userid = $row [ 'userid' ];
$resellerid = $row [ 'resellerid' ];
$brandname = $row [ 'brandname' ];
$rootID = $row [ 'rootID' ];
$war = $row [ 'war' ];
if ( $lendserver == 'Y' and $resellersettings [ $resellerid ][ 'active' ] == 'Y' and $resellersettings [ $resellerid ][ 'shutdownempty' ] == 'Y' ) {
$shutdownemptytime = $resellersettings [ $resellerid ][ 'shutdownemptytime' ];
$query2 -> execute ( array ( $row [ 'id' ]));
foreach ( $query2 -> fetchall ( PDO :: FETCH_ASSOC ) as $row2 ) {
$lid = $row2 [ 'id' ];
$elapsed = round (( strtotime ( 'now' ) - strtotime ( $row2 [ 'started' ])) / 60 );
2013-08-28 22:47:04 +02:00
}
}
}
2013-10-06 14:39:54 +02:00
if ( isset ( $userid ) and isset ( $serverid ) and isset ( $port ) and isset ( $qstat ) and isset ( $serverip )) {
2013-10-03 12:49:13 +02:00
$status = 'UP' ;
2013-10-06 14:39:54 +02:00
if ( in_array ( $qstat , array ( 'gtasamp' , 'minecraft' , 'teeworlds' , 'mtasa' ))) {
echo " $qstat\r\n " ;
$query = ( $qstat == 'mtasa' ) ? serverQuery ( $serverip , ( $port + 123 ), $qstat ) : serverQuery ( $serverip , $port , $qstat );
2013-08-28 22:47:04 +02:00
if ( is_array ( $query )) {
2013-10-03 12:49:13 +02:00
$name = $query [ 'hostname' ];
2013-10-03 16:48:54 +02:00
$password = ( $query [ 'password' ] == 1 ) ? 'Y' : 'N' ;
2013-10-03 12:49:13 +02:00
$numplayers = $query [ 'players' ];
$maxplayers = $query [ 'slots' ];
$map = $query [ 'map' ];
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 16:48:54 +02:00
$status = 'DOWN' ;
2013-10-03 12:49:13 +02:00
$name = $gametype . '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-08-28 22:47:04 +02:00
}
} else {
2013-10-03 12:49:13 +02:00
$brandname = 'N' ;
$name = $gametype . 'ONLINE' ;
2013-09-29 15:29:58 +02:00
$numplayers = 0 ;
$maxplayers = 0 ;
$map = '' ;
2013-10-03 12:49:13 +02:00
$password = 'Y' ;
}
if ( ! isset ( $elapsed )) {
$elapsed = 0 ;
}
if ( ! isset ( $shutdownemptytime )) {
$shutdownemptytime = 0 ;
}
$tmp = statushandle ();
if ( is_array ( $tmp )) {
foreach ( $tmp as $t ) {
$shellCmds [ $rootID ][] = $t ;
}
2013-08-28 22:47:04 +02:00
}
}
}
2013-08-29 23:37:49 +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 ) {
2013-10-03 12:49:13 +02:00
$resellerid = $row [ 'resellerid' ];
$tsdnscheck =@ fsockopen ( $row [ 'ssh2ip' ], 41144 , $errno , $errstr , 5 );
if ( ! is_resource ( $tsdnscheck ) and $row [ 'autorestart' ] == 'Y' ) {
2013-08-28 22:47:04 +02:00
sleep ( 1 );
2013-10-03 12:49:13 +02:00
$tsdnscheck =@ fsockopen ( $row [ 'ssh2ip' ], 41144 , $errno , $errstr , 5 );
2013-08-28 22:47:04 +02:00
}
2013-10-03 12:49:13 +02:00
if ( ! is_resource ( $tsdnscheck ) and $row [ 'autorestart' ] == 'Y' ) {
2013-09-29 15:29:58 +02:00
print " TSDNS Error: " . $row [ 'ssh2ip' ] . ' ' . $errno . ' (' . $errstr . " ) \r \n " ;
$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' ]));
2013-10-03 12:49:13 +02:00
$tsdnsDownCheck = $row [ 'notified' ] + 1 ;
if ( $tsdnsDownCheck == $resellersettings [ $resellerid ][ 'down_checks' ]) {
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 ));
}
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-10-03 12:49:13 +02:00
if ( $row [ 'bitversion' ] == '32' ) {
2013-08-28 22:47:04 +02:00
$tsdnsbin = 'tsdnsserver_linux_x86' ;
} else {
$tsdnsbin = 'tsdnsserver_linux_amd64' ;
}
2013-09-29 15:29:58 +02:00
$ssh2_2 = false ;
2013-10-03 12:49:13 +02:00
if ( $row [ 'publickey' ] == 'Y' ) {
2013-09-22 12:00:33 +02:00
# https://github.com/easy-wi/developer/issues/70
2013-10-13 11:42:31 +02:00
$sshkey = removePub ( $row [ 'keyname' ]);
2013-09-22 12:00:33 +02:00
$pubkey = 'keys/' . $sshkey . '.pub' ;
$key = 'keys/' . $sshkey ;
2013-08-28 22:47:04 +02:00
if ( file_exists ( $pubkey ) and file_exists ( $key )) {
2013-10-13 17:11:32 +02:00
$ssh2_2 = @ ssh2_connect ( $row [ 'ssh2ip' ], $row [ 'decryptedssh2port' ], array ( 'hostkey' => 'ssh-rsa' ));
2013-08-28 22:47:04 +02:00
}
} else {
2013-10-13 17:11:32 +02:00
$ssh2_2 = @ ssh2_connect ( $row [ 'ssh2ip' ], $row [ 'decryptedssh2port' ]);
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:42:31 +02:00
if ( $ssh2_2 == true ) {
2013-10-03 12:49:13 +02:00
$connect_ssh2_2 = ( $row [ 'publickey' ] == 'Y' ) ? @ ssh2_auth_pubkey_file ( $ssh2_2 , $row [ 'decryptedssh2user' ], $pubkey , $key ) : @ ssh2_auth_password ( $ssh2_2 , $row [ 'decryptedssh2user' ], $row [ 'decryptedssh2password' ]);
2013-10-13 11:42:31 +02:00
if ( $connect_ssh2_2 == true ) {
2013-10-03 12:49:13 +02:00
$split_config = preg_split ( '/\//' , $row [ 'serverdir' ], - 1 , PREG_SPLIT_NO_EMPTY );
2013-08-28 22:47:04 +02:00
$folderfilecount = count ( $split_config ) - 1 ;
2013-09-29 15:29:58 +02:00
$i = 0 ;
2013-08-28 22:47:04 +02:00
unset ( $folders );
2013-10-03 12:49:13 +02:00
$folders = ( substr ( $row [ 'serverdir' ], 0 , 1 ) == '/' ) ? 'cd /' : 'cd ' ;
2013-09-29 15:29:58 +02:00
$lastFolder = '' ;
2013-10-03 12:49:13 +02:00
while ( $i <= $folderfilecount ) {
2013-10-13 11:42:31 +02:00
$folders = $folders . $split_config [ $i ] . '/' ;
2013-10-03 12:49:13 +02:00
$lastFolder = $split_config [ $i ];
2013-08-28 22:47:04 +02:00
$i ++ ;
}
2013-10-03 12:49:13 +02:00
if ( $folders == 'cd ' ) {
2013-09-29 15:29:58 +02:00
$folders = '' ;
2013-10-03 12:49:13 +02:00
} else if ( $lastFolder != 'tsdns' or substr ( $row [ 'serverdir' ], 0 , 1 ) != '/' ) {
$folders = $folders . 'tsdns/ && ' ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-13 11:42:31 +02:00
$folders = $folders . ' && ' ;
2013-08-28 22:47:04 +02:00
}
2013-10-03 12:49:13 +02:00
$ssh2cmd = $folders . 'function r () { if [ "`ps fx | grep ' . $tsdnsbin . ' | grep -v grep`" == "" ]; then ./' . $tsdnsbin . ' > /dev/null & else ./' . $tsdnsbin . ' --update > /dev/null & fi }; r& ' ;
echo $ssh2cmd . " \r \n " ;
echo ssh2_exec ( $ssh2_2 , $ssh2cmd ) . " \r \n " ;
2013-10-13 11:42:31 +02:00
$ssh2_2 = null ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
print " Error: Bad logindata for external tsdns " . $row [ 'ssh2ip' ] . " \r \n " ;
2013-08-28 22:47:04 +02:00
}
} else {
print " Error: Can not connect to external tsdns server " . $row [ 'ssh2ip' ] . " via ssh2 \r \n " ;
}
} else {
print " TSDNS ${ row['ssh2ip'] } is up and running \r \n " ;
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 */
2013-10-03 12:49:13 +02:00
if (( isset ( $args [ 'tsDebug' ]) and $args [ 'tsDebug' ] == 1 )) print " Checking voice server with debug on \r \n " ;
$vselect = $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' " );
$vselect -> execute ( array ( ':aeskey' => $aeskey ));
2013-08-28 22:47:04 +02:00
foreach ( $vselect -> fetchall ( PDO :: FETCH_ASSOC ) as $vrow ) {
2013-10-03 12:49:13 +02:00
unset ( $connect_ssh2 , $ssh2 , $badLogin );
$ts3masterid = $vrow [ 'id' ];
$ts3masternotified = $vrow [ 'notified' ];
$addedby = $vrow [ 'addedby' ];
$queryport = $vrow [ 'queryport' ];
$querypassword = $vrow [ 'decryptedquerypassword' ];
$resellerid = $vrow [ 'resellerid' ];
$autorestart = $vrow [ 'autorestart' ];
if ( $addedby == '2' ) {
$queryip = $vrow [ 'ssh2ip' ];
} else 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 ));
foreach ( $vselect2 -> fetchall ( PDO :: FETCH_ASSOC ) as $vrow2 ) $queryip = $vrow2 [ 'ip' ];
2013-08-28 22:47:04 +02:00
}
2013-10-03 12:49:13 +02:00
if ( $vrow [ 'type' ] == 'ts3' ) {
2013-09-29 15:29:58 +02:00
$tsdown = false ;
$tsdnsdown = false ;
2013-10-03 12:49:13 +02:00
$defaultwelcome = $vrow [ 'defaultwelcome' ];
2013-10-10 08:06:37 +02: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' ]);
2013-08-28 22:47:04 +02:00
print " Connecting to TS3 server $queryip\r\n " ;
2013-10-03 12:49:13 +02:00
$connection = new TS3 ( $queryip , $queryport , 'serveradmin' , $querypassword ,( isset ( $args [ 'tsDebug' ]) and $args [ 'tsDebug' ] == 1 ) ? true : false );
$errorcode = $connection -> errorcode ;
2013-08-28 22:47:04 +02:00
if ( strpos ( $errorcode , 'error id=0' ) === false ) {
$connection -> CloseConnection ();
unset ( $connection );
sleep ( 1 );
2013-10-03 12:49:13 +02:00
$connection = new TS3 ( $queryip , $queryport , 'serveradmin' , $querypassword );
$errorcode = $connection -> errorcode ;
2013-08-28 22:47:04 +02:00
}
if ( strpos ( $errorcode , 'error id=0' ) === false ) {
$connection -> CloseConnection ();
unset ( $connection );
}
if ( strpos ( $errorcode , 'error id=0' ) === false ) {
2013-10-03 12:49:13 +02:00
print " TS3 Query Error: " . $errorcode . " \r \n " ;
$tsdown = true ;
2013-08-28 22:47:04 +02:00
$restartreturn = " TS3 " ;
}
2013-10-03 12:49:13 +02:00
if ( $vrow [ 'usedns' ] == 'Y' ) {
$tsdnscheck =@ fsockopen ( $queryip , 41144 , $errno , $errstr , 5 );
2013-08-28 22:47:04 +02:00
if ( ! is_resource ( $tsdnscheck )) {
sleep ( 1 );
2013-10-03 12:49:13 +02:00
$tsdnscheck =@ fsockopen ( $queryip , 41144 , $errno , $errstr , 5 );
2013-08-28 22:47:04 +02:00
}
if ( ! is_resource ( $tsdnscheck )) {
print " TSDNS Error: " . $errno . ' (' . $errstr . " ) \r \n " ;
2013-10-03 12:49:13 +02:00
$tsdnsdown = true ;
2013-08-28 22:47:04 +02:00
if ( isset ( $restartreturn )) {
$restartreturn .= " and TSDNS " ;
} else {
$restartreturn = " TSDNS " ;
}
}
}
2013-10-13 11:42:31 +02:00
if ( $tsdown == true or $tsdnsdown == true ) {
2013-08-28 22:47:04 +02:00
$ts3masternotified ++ ;
2013-10-03 12:49:13 +02:00
if ( $ts3masternotified == $resellersettings [ $resellerid ][ 'down_checks' ]) {
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 ));
}
foreach ( $query2 -> fetchall ( PDO :: FETCH_ASSOC ) as $row2 ) {
2013-10-03 12:49:13 +02:00
if ( $row2 [ 'mail_serverdown' ] == 'Y' ) {
sendmail ( 'emaildownrestart' , $row2 [ 'id' ], $queryip . ' (' . $restartreturn . ')' , '' );
}
2013-08-28 22:47:04 +02: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-10-13 11:42:31 +02:00
if (( $autorestart == 'Y' and $ts3masternotified >= $resellersettings [ $resellerid ][ 'down_checks' ]) or ( $tsdown != true and $tsdnsdown == true )) {
2013-10-03 12:49:13 +02:00
if ( $vrow [ 'publickey' ] == 'Y' ) {
2013-09-22 12:00:33 +02:00
# https://github.com/easy-wi/developer/issues/70
$sshkey = removePub ( $vrow [ 'keyname' ]);
2013-10-13 11:42:31 +02:00
$pubkey = EASYWIDIR . '/keys/' . $sshkey . '.pub' ;
$key = EASYWIDIR . '/keys/' . $sshkey ;
2013-09-22 12:00:33 +02:00
2013-10-03 12:49:13 +02:00
$ssh2 = ( file_exists ( $pubkey ) and file_exists ( $key )) ? @ ssh2_connect ( $queryip , $vrow [ 'decryptedssh2port' ], array ( 'hostkey' => 'ssh-rsa' )) : false ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
$ssh2 = @ ssh2_connect ( $queryip , $vrow [ 'decryptedssh2port' ]);
2013-08-28 22:47:04 +02:00
}
if ( $ssh2 ) {
2013-10-03 12:49:13 +02:00
if ( $vrow [ 'publickey' ] == 'Y' ) {
$connect_ssh2 = @ ssh2_auth_pubkey_file ( $ssh2 , $vrow [ 'decryptedssh2user' ], $pubkey , $key );
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
$connect_ssh2 = @ ssh2_auth_password ( $ssh2 , $vrow [ 'decryptedssh2user' ], $vrow [ 'decryptedssh2password' ]);
2013-08-28 22:47:04 +02:00
}
if ( $connect_ssh2 ) {
2013-10-03 12:49:13 +02:00
$split_config = preg_split ( '/\//' , $vrow [ 'serverdir' ], - 1 , PREG_SPLIT_NO_EMPTY );
2013-08-28 22:47:04 +02:00
$folderfilecount = count ( $split_config ) - 1 ;
2013-09-29 15:29:58 +02:00
$i = 0 ;
2013-10-03 12:49:13 +02:00
$folders = ( substr ( $vrow [ 'serverdir' ], 0 , 1 ) == '/' ) ? 'cd /' : 'cd ' ;
while ( $i <= $folderfilecount ) {
2013-10-13 11:42:31 +02:00
$folders = $folders . $split_config [ $i ] . '/' ;
2013-08-28 22:47:04 +02:00
$i ++ ;
}
2013-10-03 12:49:13 +02:00
if ( $folders == 'cd ' ) {
2013-09-29 15:29:58 +02:00
$folders = '' ;
2013-08-28 22:47:04 +02:00
$tsdnsFolders = 'cd tsdns && ' ;
} else {
2013-10-03 12:49:13 +02:00
$tsdnsFolders = $folders . 'tsdns && ' ;
2013-10-13 11:42:31 +02:00
$folders = $folders . ' && ' ;
2013-08-28 22:47:04 +02:00
}
2013-10-03 12:49:13 +02:00
if ( $vrow [ 'bitversion' ] == '32' ) {
2013-08-28 22:47:04 +02:00
$tsbin = 'ts3server_linux_x86' ;
$tsdnsbin = 'tsdnsserver_linux_x86' ;
} else {
$tsbin = 'ts3server_linux_amd64' ;
$tsdnsbin = 'tsdnsserver_linux_amd64' ;
}
2013-10-03 12:49:13 +02:00
$ssh2cmd = $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& ' ;
if ( $vrow [ 'usedns' ] == 'Y' ) {
2013-08-28 22:47:04 +02:00
$tsndsserver = " and TSDNS " ;
2013-10-13 11:42:31 +02:00
$ssh2cmd2 = $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
}
2013-10-13 11:42:31 +02:00
if ( $tsdown == true ) {
2013-10-03 12:49:13 +02:00
echo $ssh2cmd . " \r \n " ;
echo ssh2_exec ( $ssh2 , $ssh2cmd );
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:42:31 +02:00
if ( $tsdnsdown == true ) {
2013-10-03 12:49:13 +02:00
echo $ssh2cmd2 . " \r \n " ;
echo ssh2_exec ( $ssh2 , $ssh2cmd2 );
2013-08-28 22:47:04 +02:00
}
2013-10-03 12:49:13 +02:00
print 'Restarting: ' . $restartreturn . " \r \n " ;
2013-08-28 22:47:04 +02:00
} else {
print " Error: Bad logindata \r \n " ;
}
} else {
print " Error: Can not connect via ssh2 \r \n " ;
}
} else {
print " Down but no Restart triggert \r \n " ;
}
}
2013-10-13 11:42:31 +02:00
if ( $tsdown != true ) {
2013-08-28 22:47:04 +02: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-10-03 12:49:13 +02:00
$serverlist = $connection -> ServerList ();
2013-10-13 17:11:32 +02:00
if ( ! isset ( $serverlist [ 0 ][ 'id' ]) or $serverlist [ 0 ][ 'id' ] == 0 ) {
2013-08-28 22:47:04 +02:00
foreach ( $serverlist as $server ) {
unset ( $modbadserver );
2013-09-29 15:29:58 +02:00
$modbadserver = array ();
2013-10-03 12:49:13 +02:00
$virtualserver_id = $server [ 'virtualserver_id' ];
$vs = $server [ 'virtualserver_status' ];
2013-08-28 22:47:04 +02:00
$uptime = ( isset ( $server [ 'virtualserver_uptime' ])) ? $server [ 'virtualserver_uptime' ] : 0 ;
2013-10-03 12:49:13 +02:00
$newnotified = 'N' ;
unset ( $newtrafficdata , $newtraffic , $ts3id );
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' ];
$maxtraffic = $maxtrafficmb * 1024 ;
2013-10-03 16:48:54 +02:00
$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-10-03 12:49:13 +02:00
if ( isset ( $ts3id ) and $vs == 'online' and $active == 'N' ) {
2013-08-28 22:47:04 +02:00
print " Inactive TS3 server $address running. Stopping it. \r \n " ;
$connection -> StopServer ( $virtualserver_id );
2013-10-03 12:49:13 +02:00
} else if ( isset ( $ts3id ) and $vs == 'online' and $active == 'Y' ) {
$queryName = $server [ 'virtualserver_name' ];
2013-08-28 22:47:04 +02:00
$usedslots = ( isset ( $server [ 'virtualserver_clientsonline' ])) ? $server [ 'virtualserver_clientsonline' ] : 0 - ( isset ( $server [ 'virtualserver_queryclientsonline' ])) ? $server [ 'virtualserver_queryclientsonline' ] : 0 ;
2013-10-03 12:49:13 +02:00
$sd = $connection -> ServerDetails ( $virtualserver_id );
unset ( $rulebreak , $changeSlots );
2013-08-28 22:47:04 +02:00
$newtrafficdata = round (( $sd [ 'connection_filetransfer_bytes_sent_total' ] + $sd [ 'connection_filetransfer_bytes_received_total' ]) / 1024 );
2013-09-29 15:29:58 +02:00
if ( $resellersettings [ $resellerid ][ 'firstchecktime' ] < $resellersettings [ $resellerid ][ 'firstcheck' ]) $filetraffic = 0 ;
$newtraffic = 0 ;
2013-08-28 22:47:04 +02:00
if ( $newtrafficdata > $lastfiletraffic ) {
2013-10-03 12:49:13 +02:00
$addedtraffic = $newtrafficdata - $lastfiletraffic ;
$newtraffic = $filetraffic + $addedtraffic ;
} else if ( $newtrafficdata == $lastfiletraffic ) {
$newtraffic = $filetraffic ;
2013-08-28 22:47:04 +02:00
} else if ( $newtrafficdata < $lastfiletraffic ) {
2013-10-03 12:49:13 +02:00
$addedtraffic = $newtrafficdata ;
$newtraffic = $filetraffic + $addedtraffic ;
2013-08-28 22:47:04 +02: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-10-03 12:49:13 +02: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 ;
2013-09-29 15:29:58 +02:00
if ( isset ( $changeSlots ) and $flexSlotsCurrent != 2 and $changeSlots < 2 ) $changeSlots = 2 ;
2013-08-28 22:47:04 +02:00
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 ) {
2013-09-29 15:29:58 +02:00
$virtualserver_max_download_total_bandwidth = 1 ;
$virtualserver_max_upload_total_bandwidth = 1 ;
2013-10-03 12:49:13 +02:00
$traffictext = " and has now reached the traffic limit " . $newtrafficmb . '/' . $maxtrafficmb . " MB " ;
2013-08-28 22:47:04 +02:00
if ( isset ( $rulebreak )) {
2013-10-03 12:49:13 +02:00
$rulebreak .= " <br />Traffic Limit " . $newtrafficmb . '/' . $maxtrafficmb . " MB " ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
$rulebreak = " <br />Traffic Limit " . $newtrafficmb . '/' . $maxtrafficmb . " MB " ;
2013-08-28 22:47:04 +02: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 ;
2013-10-03 12:49:13 +02:00
$traffictext = " and has still reached the traffic limit " . $newtrafficmb . '/' . $maxtrafficmb . " MB " ;
2013-08-28 22:47:04 +02:00
} else if ( $maxtraffic > 0 ) {
2013-10-03 12:49:13 +02:00
$traffictext = " and has not reached traffic limit " . $newtrafficmb . '/' . $maxtrafficmb . " MB " ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
$traffictext = " and has traffic limit " . $newtrafficmb . '/' . $maxtrafficmb . " MB " ;
2013-08-28 22:47:04 +02: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
}
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 ) {
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 )) {
$rulebreak .= " <br /> " . $ssprache -> noservertag ;
} else {
2013-10-13 11:42:31 +02:00
$rulebreak = $ssprache -> noservertag ;
2013-08-28 22:47:04 +02: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
}
2013-10-03 12:49:13 +02:00
if ( isset ( $ts3id ) and $forcebanner == 'Y' ) {
2013-08-28 22:47:04 +02: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 ]) {
$modbadserver [ $param ] = $default [ $param ];
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 )) {
2013-09-28 13:23:15 +02: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
}
}
}
}
2013-10-03 12:49:13 +02:00
if ( isset ( $ts3id ) and $forcebutton == 'Y' ) {
2013-08-28 22:47:04 +02: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 ];
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 )) {
2013-09-28 13:23:15 +02: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
}
}
}
}
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' ];
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 )) {
2013-09-28 13:23:15 +02:00
$rulebreak .= " <br />virtualserver_welcomemessage " . $vosprache -> isnot . ' ' . $default [ 'defaultwelcome' ];
2013-08-28 22:47:04 +02:00
} else {
2013-09-28 13:23:15 +02:00
$rulebreak = " virtualserver_welcomemessage " . $vosprache -> isnot . ' ' . $default [ 'defaultwelcome' ];
2013-08-28 22:47:04 +02:00
}
}
2013-10-03 12:49:13 +02:00
if ( isset ( $ts3id , $lendserver ) and $lendserver == 'N' and $slots < $server [ 'virtualserver_maxclients' ]) {
print $vrow [ 'type' ] . " server $address virtualserver_maxclients ${ sd['virtualserver_maxclients'] } != " . $slots . " . 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 )) {
2013-09-28 13:23:15 +02:00
$rulebreak .= " <br />virtualserver_maxclients " . $vosprache -> isnot . ' ' . $slots ;
2013-08-28 22:47:04 +02:00
} else {
2013-09-28 13:23:15 +02:00
$rulebreak = " virtualserver_maxclients " . $vosprache -> isnot . ' ' . $slots ;
2013-08-28 22:47:04 +02: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 ;
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 " ;
}
}
2013-10-03 12:49:13 +02:00
if ( isset ( $ts3id ) and $lendserver == 'N' and ! isset ( $rulebreak )) {
2013-08-28 22:47:04 +02:00
if ( isset ( $changeSlots )) {
2013-10-03 12:49:13 +02: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 " ;
$connection -> ImportModServer ( $virtualserver_id , $changeSlots , $vrow2 [ 'ip' ], $vrow2 [ 'port' ], array ());
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 ));
2013-08-28 22:47:04 +02: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 ));
}
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 " ;
2013-10-13 17:11:32 +02:00
} else if ( isset ( $ts3id ) and $notified == 0 and isset ( $rulebreak )) {
2013-10-03 12:49:13 +02:00
$connection -> ImportModServer ( $virtualserver_id , $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
}
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-10-05 13:39:56 +02:00
$elapsed = round (( strtotime ( 'now' ) - strtotime ( $erow [ 'started' ])) / 60 );
2013-10-13 17:11:32 +02:00
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-08-28 22:47:04 +02:00
} else if ( $elapsed >= $runtime ) {
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-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 );
}
}
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " INSERT INTO `voice_server_stats` (`sid`,`mid`,`installed`,`used`,`date`,`uid`,`resellerid`) VALUES (?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE `used`=(`used`*(`count`/(`count`+1))+(VALUES(`used`)*(1/(`count`+1)))),`installed`=(`installed`*(`count`/(`count`+1))+(VALUES(`installed`)*(1/(`count`+1)))),`count`=`count`+1 " );
2013-10-03 12:49:13 +02:00
$query -> execute ( array ( $ts3id , $ts3masterid , $server [ 'virtualserver_maxclients' ], $usedslots , $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-10-03 12:49:13 +02:00
if ( $lendserver == 'Y' and $resellersettings [ $resellerid ][ 'active' ] == 'Y' ) {
$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' ])) {
2013-10-03 12:49:13 +02:00
$nano = time_nanosleep ( 0 , $args [ 'coolDown' ]);
2013-10-12 08:40:09 +02:00
if ( $nano === true ) {
2013-10-03 12:49:13 +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 " ;
echo 'Time remaining: ' . $nano [ 'seconds' ] . ' seconds, ' . $nano [ 'nanoseconds' ] . ' nanoseconds' . " \r \n " ;
2013-08-28 22:47:04 +02:00
}
}
}
2013-10-03 12:49:13 +02:00
} else print " Error: " . $serverlist [ 0 ][ 'msg' ] . " \r \n " ;
2013-08-28 22:47:04 +02:00
}
if ( isset ( $connection )) {
$connection -> CloseConnection ();
sleep ( 1 );
}
}
}
}
flush ();
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " UPDATE `settings` SET `lastCronStatus`=UNIX_TIMESTAMP() WHERE `resellerid`=0 LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$query -> execute ();
} else {
header ( 'Location: login.php' );
die ( 'Statuscheck can only be run via console or a cronjob' );
}