2013-08-28 22:47:04 +02:00
< ? php
2013-10-03 16:48:54 +02:00
2013-08-28 22:47:04 +02:00
/**
* File : class_masterserver . php .
* Author : Ulrich Block
* Date : 16.09 . 12
* Time : 11 : 27
* 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 />.
*/
2014-12-31 15:45:05 +01:00
// Include PHPSeclib if not already included
2016-03-20 10:24:41 +01:00
if ( ! class_exists ( 'SSH2' )) {
include ( EASYWIDIR . '/third_party/phpseclib/autoloader.php' );
2014-12-31 15:45:05 +01:00
}
2013-08-28 22:47:04 +02:00
class masterServer {
2014-12-31 15:45:05 +01:00
private $updateIDs = array ();
private $removeLogs = array ();
2015-01-10 17:13:23 +01:00
private $winCmds = array ();
2023-10-04 16:48:42 +02:00
private $imageserver , $resellerID , $webhost , $rootOK , $rootID , $rootNotifiedCount , $steamAccount , $steamPassword , $updates , $os , $aeskey , $shellScript , $uniqueHex , $masterserverDir ;
2013-10-05 13:39:56 +02:00
public $sship , $sshport , $sshuser , $sshpass , $publickey , $keyname ;
2014-12-31 15:45:05 +01:00
public $updateAmount = 0 ;
2013-08-28 22:47:04 +02:00
2013-10-05 13:39:56 +02:00
function __construct ( $rootID , $aeskey ) {
2013-08-28 22:47:04 +02:00
// fetch global PDO object
global $sql ;
2013-10-13 11:42:31 +02:00
$this -> aeskey = $aeskey ;
2013-08-28 22:47:04 +02:00
// store the rootserverID
2013-10-13 11:42:31 +02:00
$this -> rootID = $rootID ;
2013-08-28 22:47:04 +02:00
// fetch rootserverdata
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT *,AES_DECRYPT(`port`,:aeskey) AS `dport`,AES_DECRYPT(`user`,:aeskey) AS `duser`,AES_DECRYPT(`pass`,:aeskey) AS `dpass`,AES_DECRYPT(`steamAccount`,:aeskey) AS `steamAcc`,AES_DECRYPT(`steamPassword`,:aeskey) AS `steamPwd` FROM `rserverdata` WHERE `id`=:id LIMIT 1 " );
2013-10-05 13:39:56 +02:00
$query -> execute ( array ( ':aeskey' => $aeskey , ':id' => $rootID ));
2014-12-31 15:45:05 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-05 13:39:56 +02:00
$active = $row [ 'active' ];
2014-12-31 15:45:05 +01:00
$this -> rootNotifiedCount = $row [ 'notified' ];
2013-10-05 13:39:56 +02:00
$this -> sship = $row [ 'ip' ];
$this -> sshport = $row [ 'dport' ];
$this -> sshuser = $row [ 'duser' ];
$this -> sshpass = $row [ 'dpass' ];
$this -> publickey = $row [ 'publickey' ];
2014-12-31 15:45:05 +01:00
$this -> keyname = EASYWIDIR . '/keys/' . removePub ( $row [ 'keyname' ]);
2013-10-05 13:39:56 +02:00
$this -> steamAccount = $row [ 'steamAcc' ];
$this -> steamPassword = $row [ 'steamPwd' ];
$this -> resellerID = $row [ 'resellerid' ];
2014-12-31 15:45:05 +01:00
$this -> updates = $row [ 'updates' ];
$this -> os = $row [ 'os' ];
$this -> masterserverDir = '/home/' . $row [ 'duser' ] . '/masterserver/' ;
}
2013-08-28 22:47:04 +02:00
2014-12-31 15:45:05 +01:00
// In case the rootserver could be found and it is active return true
if ( isset ( $active ) and $active == 'Y' ) {
2014-03-01 21:21:00 +01:00
2014-12-31 15:45:05 +01:00
$this -> rootOK = true ;
2014-03-01 21:21:00 +01:00
2014-12-31 15:45:05 +01:00
$this -> getWebHost ();
$this -> getImageServer ();
if ( $this -> os == 'L' ) {
$this -> startShellScript ();
}
} else {
$this -> rootOK = false ;
}
}
private function getWebHost () {
global $sql ;
// get the current webhost
$query = $sql -> prepare ( " SELECT `paneldomain` FROM `settings` WHERE `resellerid`=0 LIMIT 1 " );
$query -> execute ();
$this -> webhost = $query -> fetchColumn ();
}
2015-01-10 17:13:23 +01:00
private function checkIfImageServerIsInSameSubnet ( $type , $imageString ) {
// Get the imageserver if possible and use Easy-WI server as fallback
$mainIp = explode ( '.' , $this -> sship );
$mainSubnet = $mainIp [ 0 ] . '.' . $mainIp [ 1 ] . '.' . $mainIp [ 2 ];
if ( $type == 'rsync' ) {
$splitPaths = @ preg_split ( '/\//' , $imageString , - 1 , PREG_SPLIT_NO_EMPTY );
$splitCredentialsAndServer = ( isset ( $split1 [ 1 ])) ? preg_split ( '/\:/' , $splitPaths [ 1 ], - 1 , PREG_SPLIT_NO_EMPTY ) : preg_split ( '/\:/' , $splitPaths [ 0 ], - 1 , PREG_SPLIT_NO_EMPTY );
} else {
$splitPaths = @ preg_split ( '/\//' , $imageString , - 1 , PREG_SPLIT_NO_EMPTY );
$splitCredentialsAndServer = ( isset ( $split1 [ 1 ])) ? preg_split ( '/\@/' , $splitPaths [ 1 ], - 1 , PREG_SPLIT_NO_EMPTY ) : preg_split ( '/\@/' , $splitPaths [ 0 ], - 1 , PREG_SPLIT_NO_EMPTY );
}
foreach ( $splitCredentialsAndServer as $splitIp ) {
if ( $splitIp != $this -> sship && isip ( $splitIp , 'all' )) {
$ipParts = explode ( '.' , $splitIp );
$subnet = $ipParts [ 0 ] . '.' . $ipParts [ 1 ] . '.' . $ipParts [ 2 ];
if ( $mainSubnet == $subnet ) {
return $imageString ;
}
}
}
return false ;
}
private function getPreferdImageServer ( $preferedServer , $allServer ) {
if ( count ( $preferedServer ) > 0 ) {
$allServer = $preferedServer ;
}
2015-06-04 13:16:24 +02:00
$serverAmount = count ( $allServer );
2015-07-05 02:01:02 +02:00
2015-06-04 13:16:24 +02:00
if ( $serverAmount > 0 ) {
$imageserverCount = $serverAmount - 1 ;
2015-01-10 17:13:23 +01:00
$arrayEntry = rand ( 0 , $imageserverCount );
2015-06-04 13:16:24 +02:00
return $allServer [ $arrayEntry ];
2015-01-10 17:13:23 +01:00
}
return false ;
}
2014-12-31 15:45:05 +01:00
private function getImageServer () {
global $sql ;
$query = $sql -> prepare ( " SELECT `imageserver` FROM `settings` WHERE `resellerid`=? LIMIT 1 " );
$query -> execute ( array ( $this -> resellerID ));
$splitImageservers = preg_split ( '/\r\n/' , $query -> fetchColumn (), - 1 , PREG_SPLIT_NO_EMPTY );
2015-01-10 17:13:23 +01:00
$rsyncServers = array ();
$ftpServers = array ();
2014-12-31 15:45:05 +01:00
2015-06-04 13:16:24 +02:00
2014-12-31 15:45:05 +01:00
foreach ( $splitImageservers as $server ) {
2015-01-10 17:13:23 +01:00
if ( isurl ( $server )) {
$ftpServers [] = $server ;
} else if ( isRsync ( $server )) {
$rsyncServers [] = $server ;
}
}
2014-12-31 15:45:05 +01:00
2015-01-10 17:13:23 +01:00
$preferedServer = array ();
2014-12-31 15:45:05 +01:00
2015-01-10 17:13:23 +01:00
if ( $this -> os == 'L' and count ( $rsyncServers ) > 0 ) {
2014-12-31 15:45:05 +01:00
2015-01-10 17:13:23 +01:00
foreach ( $rsyncServers as $server ) {
$imageServer = $this -> checkIfImageServerIsInSameSubnet ( 'rsync' , $server );
if ( $imageServer ) {
$preferedServer [] = $imageServer ;
}
2014-12-31 15:45:05 +01:00
}
2015-01-10 17:13:23 +01:00
$imageServer = $this -> getPreferdImageServer ( $preferedServer , $rsyncServers );
}
2014-12-31 15:45:05 +01:00
2015-01-10 17:13:23 +01:00
if ( ! isset ( $imageServer ) and count ( $ftpServers ) > 0 ) {
2015-06-04 13:16:24 +02:00
2015-01-10 17:13:23 +01:00
foreach ( $ftpServers as $server ) {
2014-12-31 15:45:05 +01:00
2015-01-10 17:13:23 +01:00
$imageServer = $this -> checkIfImageServerIsInSameSubnet ( 'ftp' , $server );
2014-12-31 15:45:05 +01:00
2015-01-10 17:13:23 +01:00
if ( $imageServer ) {
$preferedServer [] = $imageServer ;
2013-08-28 22:47:04 +02:00
}
}
2015-01-10 17:13:23 +01:00
$imageServer = $this -> getPreferdImageServer ( $preferedServer , $ftpServers );
2014-12-31 15:45:05 +01:00
}
2015-10-26 22:06:10 +01:00
if ( ! isset ( $imageServer ) or ! $imageServer or $this -> updates == 2 ) {
2015-01-10 17:13:23 +01:00
$imageServer = 'none' ;
2014-12-31 15:45:05 +01:00
}
2015-01-10 17:13:23 +01:00
$this -> imageserver = $imageServer ;
}
private function imageStringtoWinDeamon () {
if ( isurl ( $this -> imageserver )) {
return ftpStringToData ( $this -> imageserver );
2014-12-31 15:45:05 +01:00
}
2015-01-10 17:13:23 +01:00
return false ;
2014-12-31 15:45:05 +01:00
}
public function getCommands () {
if ( $this -> os == 'L' ) {
return $this -> shellScript ;
}
2015-01-10 17:13:23 +01:00
return implode ( '<br>' , $this -> winCmds );
2014-12-31 15:45:05 +01:00
}
private function startShellScript () {
$this -> uniqueHex = dechex ( mt_rand ());
$this -> shellScript = " #!/bin/bash \n " ;
2015-07-13 16:32:11 +02:00
$this -> shellScript .= 'rm -f /home/' . $this -> sshuser . '/temp/master-' . $this -> uniqueHex . '.sh' . " \n " ;
2014-12-31 15:45:05 +01:00
$this -> shellScript .= " if ionice -c3 true 2>/dev/null; then IONICE='ionice -n 7 '; else IONICE=''; fi \n " ;
$this -> shellScript .= 'UPDATESTATUS=""' . " \n " ;
$this -> shellScript .= 'BOMRM="sed \"\'s/^\xef\xbb\xbf//g\'\""' . " \n " ;
$this -> shellScript .= 'PATTERN="\.log\|\.txt\|\.cfg\|\.vdf\|\.db\|\.dat\|\.ztmp\|\.blib\|log\/\|logs\/\|downloads\/\|DownloadLists\/\|metamod\/\|amxmodx\/\|hl\/\|hl2\/\|cfg\/\|addons\/\|bin\/\|classes/"' . " \n " ;
2015-10-26 22:06:10 +01:00
if ( $this -> imageserver != 'none' ) {
2014-12-31 15:45:05 +01:00
$this -> shellScript .= 'if [ "`which rsync`" != "" -a "`echo ' . $this -> imageserver . ' | grep -E \'^ftp(s|)\:(.*)\'`" == "" ]; then' . " \n " ;
$this -> shellScript .= 'SYNCTOOL="rsync"' . " \n " ;
$this -> shellScript .= 'SYNCCMD="rsync -azuvx ' . $this -> imageserver . '"' . " \n " ;
$this -> shellScript .= 'else' . " \n " ;
$this -> shellScript .= 'SYNCTOOL="wget"' . " \n " ;
$this -> shellScript .= 'SYNCCMD="wget -r -N -l inf -nH --no-check-certificate --cut-dirs=1 ' . $this -> imageserver . '"' . " \n " ;
$this -> shellScript .= 'fi' . " \n " ;
}
$this -> shellScript .= 'if [ ! -d "' . $this -> masterserverDir . 'steamCMD/" ]; then' . " \n " ;
$this -> shellScript .= 'mkdir -p "' . $this -> masterserverDir . 'steamCMD/"' . " \n " ;
$this -> shellScript .= 'cd "' . $this -> masterserverDir . 'steamCMD/"' . " \n " ;
$this -> shellScript .= 'if [ ! -f steamcmd.sh ]; then' . " \n " ;
$this -> shellScript .= 'wget -q --timeout=10 http://media.steampowered.com/client/steamcmd_linux.tar.gz' . " \n " ;
$this -> shellScript .= 'if [ -f steamcmd_linux.tar.gz ]; then' . " \n " ;
$this -> shellScript .= 'tar xfz steamcmd_linux.tar.gz' . " \n " ;
2015-07-13 16:32:11 +02:00
$this -> shellScript .= 'rm -f steamcmd_linux.tar.gz' . " \n " ;
2014-12-31 15:45:05 +01:00
$this -> shellScript .= 'chmod +x steamcmd.sh' . " \n " ;
$this -> shellScript .= './steamcmd.sh +login anonymous +quit' . " \n " ;
$this -> shellScript .= 'fi' . " \n " ;
$this -> shellScript .= 'fi' . " \n " ;
$this -> shellScript .= 'fi' . " \n " ;
$this -> shellScript .= 'cd' . " \n " ;
}
private function serverSync ( $shorten , $updateLog ) {
if ( $this -> os == 'L' ) {
$this -> shellScript .= 'if [ "$SYNCTOOL" == "rsync" ]; then' . " \n " ;
$this -> shellScript .= '$SYNCCMD/masterserver/' . $shorten . ' ' . $this -> masterserverDir . ' > ' . $updateLog . " \n " ;
$this -> shellScript .= 'elif [ "$SYNCTOOL" == "wget" ]; then' . " \n " ;
$this -> shellScript .= '$SYNCCMD/masterserver/' . $shorten . ' > ' . $updateLog . " \n " ;
2023-10-04 16:48:42 +02:00
$this -> shellScript .= '${IONICE}nice -n +19 find ' . $this -> masterserverDir . $shorten . '/ -type f -name "*.listing" -delete' . " \n " ;
2014-12-31 15:45:05 +01:00
$this -> shellScript .= 'fi' . " \n " ;
2015-01-10 17:13:23 +01:00
} else {
$imageServer = $this -> imageStringtoWinDeamon ();
if ( is_array ( $imageServer )) {
$this -> winCmds [] = 'master ' . $shorten . ' ftp:' . $imageServer [ 'server' ] . ':' . $imageServer [ 'port' ] . ':' . $imageServer [ 'user' ] . ':' . $imageServer [ 'pwd' ] . ':/Masterserver ' . $this -> webhost . '/get_password.php?w=ms&shorten=' . $shorten ;
}
2014-12-31 15:45:05 +01:00
}
}
private function houseKeeping ( $absoluteGamePath ) {
// Workaround for another valve chaos. If the files exist, mapgroups will not work properly
2023-10-04 16:48:42 +02:00
$this -> shellScript .= '${IONICE}nice -n +19 find ' . $absoluteGamePath . ' -maxdepth 2 -type f -name "subscribed_file_ids.txt" -o -name "subscribed_collection_ids.txt" -delete' . " \n " ;
2014-12-31 15:45:05 +01:00
// Chmods should be aligned or else the server install for customer will not work
2023-10-04 16:48:42 +02:00
$this -> shellScript .= '${IONICE}nice -n +19 find ' . $absoluteGamePath . ' -type f \( -iname "*.0" -or -iname "*.1" -or -iname "*.2" -or -iname "*.3" -or -iname "*.3ds" -or -iname "*.4" -or -iname "*.5" -or -iname "*.6" -or -iname "*.7" -or -iname "*.8" -or -iname "*.9" -or -iname "*.amx" -or -iname "*.asi" -or -iname "*.asm" -or -iname "*.bin" \) -exec chmod 640 {} \;' . " \n " ;
$this -> shellScript .= '${IONICE}nice -n +19 find ' . $absoluteGamePath . ' -type f \( -iname "*.bmp" -or -iname "*.BMP" -or -iname "*.bsp" -or -iname "*.bz2" -or -iname "*.c" -or -iname "*.cab" -or -iname "*.cache" -or -iname "*.cfg" -or -iname "*.cmake" -or -iname "*.col" -or -iname "*.conf" -or -iname "*.cpp" -or -iname "*.css" -or -iname "*.csv" \) -exec chmod 640 {} \;' . " \n " ;
$this -> shellScript .= '${IONICE}nice -n +19 find ' . $absoluteGamePath . ' -type f \( -iname "*.cur" -or -iname "*.dat" -or -iname "*.db" -or -iname "*.dds" -or -iname "*.def" -or -iname "*.dff" -or -iname "*.dll" -or -iname "*.doc" -or -iname "*.dsp" -or -iname "*.dxf" -or -iname "*.dylib" -or -iname "*.edf" -or -iname "*.ekv" -or -iname "*.example" \) -exec chmod 640 {} \;' . " \n " ;
$this -> shellScript .= '${IONICE}nice -n +19 find ' . $absoluteGamePath . ' -type f \( -iname "*.exe" -or -iname "*.exp" -or -iname "*.fgd" -or -iname "*.flt" -or -iname "*.fx" -or -iname "*.gam" -or -iname "*.Gbx" -or -iname "*.gif" -or -iname "*.h" -or -iname "*.hpp" -or -iname "*.htm" -or -iname "*.html" -or -iname "*.icns" -or -iname "*.ico" \) -exec chmod 640 {} \;' . " \n " ;
$this -> shellScript .= '${IONICE}nice -n +19 find ' . $absoluteGamePath . ' -type f \( -iname "*.image" -or -iname "*.inc" -or -iname "*.inf" -or -iname "*.ini" -or -iname "*.installed" -or -iname "*.jpg" -or -iname "*.js" -or -iname "*.key" -or -iname "*.kv" -or -iname "*.lib" -or -iname "*.lmp" -or -iname "*.lst" -or -iname "*.lua" -or -iname "*.LUA" \) -exec chmod 640 {} \;' . " \n " ;
$this -> shellScript .= '${IONICE}nice -n +19 find ' . $absoluteGamePath . ' -type f \( -iname "*.manifest" -or -iname "*.map" -or -iname "*.mapRACE" -or -iname "*.mdl" -or -iname "*.mix" -or -iname "*.mp3" -or -iname "*.nav" -or -iname "*.nod" -or -iname "*.nut" -or -iname "*.pak" -or -iname "*.pcx" -or -iname "*.pem" -or -iname "*.pl" \) -exec chmod 640 {} \;' . " \n " ;
$this -> shellScript .= '${IONICE}nice -n +19 find ' . $absoluteGamePath . ' -type f \( -iname "*.png" -or -iname "*.properties" -or -iname "*.psd" -or -iname "*.pwn" -or -iname "*.rad" -or -iname "*.raw" -or -iname "*.rc" -or -iname "*.rec" -or -iname "*.res" -or -iname "*.rules" -or -iname "*.sc" -or -iname "*.scr" -or -iname "*.sfk" \) -exec chmod 640 {} \;' . " \n " ;
$this -> shellScript .= '${IONICE}nice -n +19 find ' . $absoluteGamePath . ' -type f \( -iname "*.sln" -or -iname "*.so" -or -iname "*.spr" -or -iname "*.suo" -or -iname "*.swf" -or -iname "*.tar" -or -iname "*.tga" -or -iname "*.ttf" -or -iname "*.txd" -or -iname "*.txt" -or -iname "*.vbf" -or -iname "*.vcproj" -or -iname "*.vcs" -or -iname "*.vdf" \) -exec chmod 640 {} \;' . " \n " ;
$this -> shellScript .= '${IONICE}nice -n +19 find ' . $absoluteGamePath . ' -type f \( -iname "*.vfe" -or -iname "*.vfont" -or -iname "*.vmf" -or -iname "*.vmt" -or -iname "*.vpk" -or -iname "*.vtf" -or -iname "*.wad" -or -iname "*.wav" -or -iname "*.wv" -or -iname "*.xml" -or -iname "*.xsc" -or -iname "*.yml" -or -iname "*.zip" \) -exec chmod 640 {} \;' . " \n " ;
$this -> shellScript .= '${IONICE}nice -n +19 find ' . $absoluteGamePath . ' -type f -name "srcds_*" -o -name "hlds_*" -o -name "*.run" -o -name "*.sh" -o -name "*.jar" -exec chmod 750 {} \;' . " \n " ;
$this -> shellScript .= '${IONICE}nice -n +19 find ' . $absoluteGamePath . ' -type f ! -perm -750 ! -perm -755 -exec chmod 640 {} \;' . " \n " ;
$this -> shellScript .= '${IONICE}nice -n +19 find ' . $absoluteGamePath . ' -type d -exec chmod 750 {} \;' . " \n " ;
2014-12-31 15:45:05 +01:00
// Check for temp files belonging to the steam updater
$this -> shellScript .= 'ls ' . $absoluteGamePath . ' | while read dir; do' . " \n " ;
$this -> shellScript .= 'if [[ `echo $dir| grep \'[a-z0-9]\{40\}\'` ]]; then rm -rf ' . $absoluteGamePath . '/$dir; fi' . " \n " ;
$this -> shellScript .= 'done' . " \n " ;
// Remove wget left overs
$this -> shellScript .= 'find ' . $absoluteGamePath . ' -type f -iname "wget-*" -delete' . " \n " ;
}
private function createFdlList ( $row ) {
$fastDownloadList = '/home/' . $this -> sshuser . '/conf/fdl-' . $row [ 'shorten' ] . '.list' ;
2015-07-13 16:32:11 +02:00
$this -> shellScript .= 'if [ -f ' . $fastDownloadList . ' ]; then rm -f ' . $fastDownloadList . '; fi' . " \n " ;
2014-12-31 15:45:05 +01:00
$this -> shellScript .= 'touch ' . $fastDownloadList . " \n " ;
$this -> shellScript .= 'cd "' . $this -> masterserverDir . '$UPDATE"' . " \n " ;
$this -> shellScript .= 'SEARCH=0' . " \n " ;
$this -> shellScript .= 'if [[ `find -maxdepth 2 -name srcds_run` ]]; then' . " \n " ;
$this -> shellScript .= 'cd `find -mindepth 1 -maxdepth 2 -type d -name "' . $row [ 'modfolder' ] . '" | head -n 1`' . " \n " ;
$this -> shellScript .= 'SEARCHFOLDERS="particles/ maps/ materials/ resource/ models/ sound/"' . " \n " ;
$this -> shellScript .= 'SEARCH=1' . " \n " ;
$this -> shellScript .= 'elif [[ `find -maxdepth 2 -name hlds_run` ]]; then' . " \n " ;
$this -> shellScript .= 'cd `find -mindepth 1 -maxdepth 1 -type d -name "' . $row [ 'modfolder' ] . '" | head -n 1`' . " \n " ;
$this -> shellScript .= 'SEARCHFOLDERS=""' . " \n " ;
$this -> shellScript .= 'SEARCH=1' . " \n " ;
$this -> shellScript .= 'elif [[ `find -maxdepth 2 -name "cod4_lnxded"` ]]; then' . " \n " ;
$this -> shellScript .= 'SEARCHFOLDERS="usermaps/ mods/"' . " \n " ;
$this -> shellScript .= 'SEARCH=1' . " \n " ;
$this -> shellScript .= 'fi' . " \n " ;
$this -> shellScript .= 'if [ "$SEARCH" == "1" ]; then' . " \n " ;
2023-10-04 16:48:42 +02:00
$this -> shellScript .= '${IONICE}nice -n +19 find $SEARCHFOLDERS -type f 2> /dev/null | grep -v "$PATTERN" | sed \'s/\.\///g\' | while read FILTEREDFILES; do' . " \n " ;
2014-12-31 15:45:05 +01:00
$this -> shellScript .= 'echo $FILTEREDFILES >> ' . $fastDownloadList . " \n " ;
$this -> shellScript .= 'done' . " \n " ;
$this -> shellScript .= 'if [ -f ' . $fastDownloadList . ' ]; then chmod 640 ' . $fastDownloadList . '; fi' . " \n " ;
$this -> shellScript .= 'if [ -f /home/' . $this -> sshuser . '/logs/fdl.log ]; then echo "`date`: Updated filelist for the game ' . $row [ 'shorten' ] . '" >> /home/' . $this -> sshuser . '/logs/fdl.log; fi' . " \n " ;
$this -> shellScript .= 'fi' . " \n " ;
}
private function sendUpdateSuccess ( $updateLog , $force , $row , $returnSuccessInAnyCase ) {
if ( strlen ( $this -> webhost ) > 0 ) {
if ( $force === true or $returnSuccessInAnyCase === true ) {
$this -> shellScript .= 'SENDUPDATE="YES"' . " \n " ;
2013-08-28 22:47:04 +02:00
}
2014-12-31 15:45:05 +01:00
// Check if update or install succeeded
$this -> shellScript .= 'if [ -f "' . $updateLog . '" ]; then' . " \n " ;
// Check for sync
2017-11-01 14:34:52 +01:00
$this -> shellScript .= 'if [ "`grep ' . $row [ 'appID' ] . ' \"' . $updateLog . '\" | grep \'Success\' | grep \'fully installed\'`" != "" ]; then' . " \n " ;
2014-12-31 15:45:05 +01:00
$this -> shellScript .= 'SENDUPDATE="YES"' . " \n " ;
$this -> shellScript .= 'fi' . " \n " ;
// Check for steamCMD updater
$this -> shellScript .= 'if [ "`grep \'' . $row [ 'shorten' ] . '/\' \"' . $updateLog . '\" | head -n 1`" != "" ]; then' . " \n " ;
$this -> shellScript .= 'SENDUPDATE="YES"' . " \n " ;
$this -> shellScript .= 'fi' . " \n " ;
$this -> shellScript .= 'fi' . " \n " ;
$this -> shellScript .= 'if [ "$SENDUPDATE" == "YES" ]; then' . " \n " ;
$this -> shellScript .= 'I=0' . " \n " ;
$this -> shellScript .= 'CHECK=`wget -q --timeout=10 --no-check-certificate -O - ' . $this -> webhost . '/get_password.php?w=ms\&shorten=' . $row [ 'shorten' ] . ' | $BOMRM`' . " \n " ;
$this -> shellScript .= 'while [ "$CHECK" != "ok" -a "$I" -le "10" ]; do' . " \n " ;
$this -> shellScript .= 'if [ "$CHECK" == "" ]; then' . " \n " ;
$this -> shellScript .= 'I=11' . " \n " ;
$this -> shellScript .= 'else' . " \n " ;
$this -> shellScript .= 'sleep 30' . " \n " ;
$this -> shellScript .= 'I=$[I+1]' . " \n " ;
$this -> shellScript .= 'CHECK=`wget -q --timeout=10 --no-check-certificate -O - ' . $this -> webhost . '/get_password.php?w=ms\&shorten=' . $row [ 'shorten' ] . ' | $BOMRM`' . " \n " ;
$this -> shellScript .= 'fi' . " \n " ;
$this -> shellScript .= 'done' . " \n " ;
$this -> shellScript .= 'fi' . " \n " ;
}
}
private function linuxCollectData ( $row , $force , $returnSuccessInAnyCase ) {
$absoluteGamePath = $this -> masterserverDir . $row [ 'shorten' ];
$updateLog = '/home/' . $this -> sshuser . '/logs/update-' . $row [ 'shorten' ] . '.log' ;
// Ensure we are in the home folder
$this -> shellScript .= 'cd /home/' . $this -> sshuser . " \n " ;
if ( $row [ 'supdates' ] != 3 and $row [ 'updates' ] != 3 ) {
// Create masterserver folder if it does not exists
$this -> shellScript .= 'if [ ! -d "' . $absoluteGamePath . '" ]; then mkdir -p "' . $absoluteGamePath . '"; fi' . " \n " ;
// If template and app master configs allow sync
if ( in_array ( $row [ 'supdates' ], array ( 1 , 4 )) and in_array ( $row [ 'updates' ], array ( 1 , 4 ))) {
$this -> serverSync ( $row [ 'shorten' ], $updateLog );
2013-08-28 22:47:04 +02:00
}
2014-12-31 15:45:05 +01:00
// If template and app master configs allow vendor update
if ( in_array ( $row [ 'supdates' ], array ( 1 , 2 )) and in_array ( $row [ 'updates' ], array ( 1 , 2 ))) {
//Steam updater
if ( $row [ 'steamgame' ] == 'S' ) {
2021-12-22 13:46:16 +01:00
$this -> shellScript .= 'cd /home/' . $this -> sshuser . '/masterserver/steamCMD/' . " \n " ;
2023-10-04 16:48:42 +02:00
$this -> shellScript .= 'taskset -c 0 ${IONICE}nice -n +19 ./steamcmd.sh +force_install_dir ' . $absoluteGamePath . ' +login ' ;
2021-12-22 13:46:16 +01:00
2014-12-31 16:07:07 +01:00
if ( strlen ( $this -> steamAccount ) > 0 ) {
2023-10-04 16:48:42 +02:00
$this -> shellScript .= $this -> steamAccount . ' ' . $this -> steamPassword . ' ' ;
2014-12-31 16:07:07 +01:00
} else if ( strlen ( $row [ 'steamAcc' ]) > 0 ) {
2023-10-04 16:48:42 +02:00
$this -> shellScript .= $row [ 'steamAcc' ] . ' ' . $row [ 'steamPwd' ] . ' ' ;
2014-12-31 15:45:05 +01:00
} else {
2021-12-22 13:46:16 +01:00
$this -> shellScript .= 'anonymous ' ;
2014-12-31 15:45:05 +01:00
}
2021-12-22 13:46:16 +01:00
2014-12-31 15:45:05 +01:00
$fixedId = workAroundForValveChaos ( $row [ 'appID' ], $row [ 'shorten' ], false );
2021-12-22 13:46:16 +01:00
2023-10-04 16:48:42 +02:00
$this -> shellScript .= ( $fixedId == 90 ) ? ' +app_set_config 90 mod ' . $row [ 'shorten' ] . ' +app_update 90' : '+app_update ' . $fixedId ;
2014-12-31 15:45:05 +01:00
$this -> shellScript .= ' validate +quit > ' . $updateLog . " \n " ;
} else if ( $row [ 'steamgame' ] == 'N' and ( $row [ 'shorten' ] == 'mc' )) {
2015-08-23 13:31:15 +02:00
if ( ! isurl ( $row [ 'downloadPath' ])) {
if ( ! function_exists ( 'getMinecraftVersion' )) {
require_once ( EASYWIDIR . '/stuff/methods/queries_updates.php' );
}
$mcVersion = getMinecraftVersion ();
if ( isset ( $mcVersion [ 'downloadPath' ]) and isurl ( $mcVersion [ 'downloadPath' ])) {
$row [ 'downloadPath' ] = $mcVersion [ 'downloadPath' ];
}
}
if ( isurl ( $row [ 'downloadPath' ])) {
$this -> shellScript .= 'cd ' . $absoluteGamePath . " \n " ;
$this -> shellScript .= 'wget -q ' . $row [ 'downloadPath' ] . ' --output-document ' . $row [ 'gamebinary' ] . '.new' . " \n " ;
$this -> shellScript .= 'if [ `stat -c %s ' . $row [ 'gamebinary' ] . '.new` -gt 0 ]; then' . " \n " ;
$this -> shellScript .= 'mv ' . $row [ 'gamebinary' ] . '.new ' . $row [ 'gamebinary' ] . " \n " ;
$this -> shellScript .= 'else' . " \n " ;
$this -> shellScript .= 'rm -f ' . $row [ 'gamebinary' ] . '.new ' . " \n " ;
$this -> shellScript .= 'fi' . " \n " ;
$this -> shellScript .= 'chmod 750 ' . $row [ 'gamebinary' ] . " \n " ;
}
2014-12-31 15:45:05 +01:00
}
2013-08-28 22:47:04 +02:00
}
2014-12-31 15:45:05 +01:00
// Housekeeping
$this -> houseKeeping ( $absoluteGamePath );
$this -> createFdlList ( $row );
$this -> sendUpdateSuccess ( $updateLog , $force , $row , $returnSuccessInAnyCase );
$this -> removeLogs [] = $updateLog ;
$this -> updateAmount ++ ;
2013-08-28 22:47:04 +02:00
}
2014-12-31 15:45:05 +01:00
}
2013-08-28 22:47:04 +02:00
2015-01-10 17:13:23 +01:00
private function windowsCollectData ( $row ) {
if ( $row [ 'supdates' ] != 3 and $row [ 'updates' ] != 3 ) {
if ( strlen ( $this -> steamAccount ) > 0 ) {
$connectData = $this -> steamAccount ;
if ( strlen ( $this -> steamPassword ) > 0 ) {
$connectData .= ':' . $this -> steamPassword ;
}
} else if ( strlen ( $row [ 'steamAcc' ]) > 0 ) {
$connectData = $row [ 'steamAcc' ];
if ( strlen ( $this -> steamPassword ) > 0 ) {
$connectData .= ':' . $row [ 'steamPwd' ];
}
} else {
$connectData = 'anonymous' ;
}
$callBackUrl = ( strlen ( $this -> webhost ) > 0 ) ? $this -> webhost . '/get_password.php?w=ms&shorten=' . $row [ 'shorten' ] : '' ;
$this -> winCmds [] = 'master ' . $row [ 'shorten' ] . ' steam:' . $connectData . ':' . workAroundForValveChaos ( $row [ 'appID' ], $row [ 'shorten' ], false ) . ' ' . $callBackUrl ;
}
$this -> updateAmount ++ ;
}
2014-12-31 15:45:05 +01:00
private function addonSync ( $serverTypeIDs ) {
if ( count ( $serverTypeIDs ) > 0 ) {
global $sql ;
$query = $sql -> prepare ( " SELECT t.`addon`,t.`type` FROM `addons_allowed` AS a INNER JOIN `addons` t ON a.`addon_id`=t.`id` WHERE a.`servertype_id` IN ( " . implode ( ',' , $serverTypeIDs ) . " ) AND a.`reseller_id`=? GROUP BY t.`type`,t.`addon` " );
$query -> execute ( array ( $this -> resellerID ));
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
if ( $this -> os == 'L' ) {
$addonMasterFolder = ( $row [ 'type' ] == 'tool' ) ? 'masteraddons' : 'mastermaps' ;
$absoluteMasterPath = '/home/' . $this -> sshuser . '/' . $addonMasterFolder ;
$absoluteAddonPath = $absoluteMasterPath . '/' . $row [ 'addon' ];
$this -> shellScript .= 'if [ "$SYNCTOOL" == "rsync" ]; then' . " \n " ;
$this -> shellScript .= '$SYNCCMD/' . $addonMasterFolder . '/' . $row [ 'addon' ] . ' ' . $absoluteMasterPath . '/' . " \n " ;
$this -> shellScript .= 'elif [ "$SYNCTOOL" == "wget" ]; then' . " \n " ;
$this -> shellScript .= '$SYNCCMD/' . $addonMasterFolder . '/' . $row [ 'addon' ] . " \n " ;
$this -> shellScript .= 'find ' . $absoluteAddonPath . ' -name .listing -delete' . " \n " ;
$this -> shellScript .= 'fi' . " \n " ;
2017-11-01 14:34:52 +01:00
$this -> shellScript .= 'if [ -d "' . $absoluteAddonPath . '" ]; then' . " \n " ;
2014-12-31 15:45:05 +01:00
$this -> shellScript .= 'find ' . $absoluteAddonPath . ' -type d -exec chmod 750 {} \;' . " \n " ;
$this -> shellScript .= 'find ' . $absoluteAddonPath . ' -type f -exec chmod 640 {} \;' . " \n " ;
2017-11-01 14:34:52 +01:00
$this -> shellScript .= 'fi' . " \n " ;
2015-01-10 17:13:23 +01:00
} else {
$imageServer = $this -> imageStringtoWinDeamon ();
if ( $row [ 'type' ] == 'tool' ) {
$addonMasterFolder = 'MasterAddons' ;
$addonCmd = 'masteraddon' ;
} else {
$addonMasterFolder = 'MasterMaps' ;
$addonCmd = 'mastermaps' ;
}
if ( is_array ( $imageServer )) {
$this -> winCmds [] = $addonCmd . ' install ' . $imageServer [ 'server' ] . ' ' . $imageServer [ 'port' ] . ' ' . $imageServer [ 'user' ] . ' ' . $imageServer [ 'pwd' ] . ' /' . $addonMasterFolder . ' ' . $row [ 'addon' ];
}
2014-12-31 15:45:05 +01:00
}
}
2013-08-28 22:47:04 +02:00
}
}
// collect data regarding installed games
2014-12-31 15:45:05 +01:00
public function collectData ( $all = true , $force = false , $returnSuccessInAnyCase = true ) {
2013-10-05 13:39:56 +02:00
2013-10-03 16:48:54 +02:00
if ( $this -> rootOK != true ) {
2013-08-28 22:47:04 +02:00
return null ;
}
// fetch global PDO object
global $sql ;
2013-10-05 13:39:56 +02:00
if ( $force == true ) {
2013-09-29 15:29:58 +02:00
$extraSQL = '' ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 16:48:54 +02:00
$extraSQL = 'AND t.`updates`!=3 AND s.`updates`!=3' ;
2013-08-28 22:47:04 +02:00
}
// if an ID is given collect only data for this ID, else collect all game data for this rootserver
2013-10-03 16:48:54 +02:00
if ( $all === true ) {
2016-06-01 20:28:10 +02:00
$query = $sql -> prepare ( " SELECT t.`id` AS `servertype_id`,t.`shorten`,t.`modfolder`,t.`steamgame`,CASE WHEN t.`serverID` IS NULL THEN t.`appID` ELSE t.`serverID` END AS `appID`,t.`steamVersion`,t.`updates`,t.`downloadPath`,t.`gamebinary`,t.`gameq`,AES_DECRYPT(t.`steam_account`,?) AS `steamAcc`,AES_DECRYPT(t.`steam_password`,?) AS `steamPwd`,r.`id` AS `update_id`,r.`localVersion`,s.`updates` AS `supdates`,s.`id` AS `root_id` FROM `rservermasterg` r INNER JOIN `servertypes` t ON r.`servertypeid`=t.`id` INNER JOIN `rserverdata` s ON r.`serverid`=s.`id` WHERE r.`serverid`=? " . $extraSQL );
2014-12-31 15:45:05 +01:00
$query -> execute ( array ( $this -> aeskey , $this -> aeskey , $this -> rootID ));
2013-08-28 22:47:04 +02:00
} else {
2016-06-01 20:28:10 +02:00
$query = $sql -> prepare ( " SELECT t.`id` AS `servertype_id`,t.`shorten`,t.`modfolder`,t.`steamgame`,CASE WHEN t.`serverID` IS NULL THEN t.`appID` ELSE t.`serverID` END AS `appID`,t.`steamVersion`,t.`updates`,t.`downloadPath`,t.`gamebinary`,t.`gameq`,AES_DECRYPT(t.`steam_account`,?) AS `steamAcc`,AES_DECRYPT(t.`steam_password`,?) AS `steamPwd`,r.`id` AS `update_id`,r.`localVersion`,s.`updates` AS `supdates`,s.`id` AS `root_id` FROM `rservermasterg` r INNER JOIN `servertypes` t ON r.`servertypeid`=t.`id` INNER JOIN `rserverdata` s ON r.`serverid`=s.`id` WHERE r.`serverid`=? AND r.`servertypeid`=? " . $extraSQL . " LIMIT 1 " );
2014-12-31 15:45:05 +01:00
$query -> execute ( array ( $this -> aeskey , $this -> aeskey , $this -> rootID , $all ));
2013-08-28 22:47:04 +02:00
}
2013-10-05 13:39:56 +02:00
2014-12-31 15:45:05 +01:00
// Used for addon sync which will be started after the server updates in order to ensure uniqueness of update run
$serverTypeIDs = array ();
// 3 = no Update; 1 = Vendor + Sync; 2 = Vendor; 4 = Sync
// supdates = appmaster setting; updates = template setting
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-05 13:39:56 +02:00
2015-10-11 15:51:51 +02:00
$steamVersion = floatval ( $row [ 'steamVersion' ]);
$localVersion = floatval ( $row [ 'localVersion' ]);
if (( $steamVersion != $localVersion and ( $row [ 'steamgame' ] == 'S' or $row [ 'gameq' ] == 'minecraft' or $row [ 'gameq' ] == 'minequery' )) or $force === true ) {
2013-10-05 13:39:56 +02:00
2014-12-31 15:45:05 +01:00
if ( $this -> os == 'L' ) {
$this -> linuxCollectData ( $row , $force , $returnSuccessInAnyCase );
2015-01-10 17:13:23 +01:00
} else {
$this -> windowsCollectData ( $row , $force , $returnSuccessInAnyCase );
2013-08-28 22:47:04 +02:00
}
2014-12-31 15:45:05 +01:00
// Set masterserver to updating
if ( $row [ 'supdates' ] != 3 and $row [ 'updates' ] != 3 ) {
$this -> updateIDs [ $row [ 'update_id' ]] = $row [ 'update_id' ];
2013-08-28 22:47:04 +02:00
}
2014-12-31 15:45:05 +01:00
// If template and app master configs allow sync
if ( in_array ( $row [ 'supdates' ], array ( 1 , 4 )) and in_array ( $row [ 'updates' ], array ( 1 , 4 ))) {
$serverTypeIDs [] = $row [ 'servertype_id' ];
2013-08-28 22:47:04 +02:00
}
}
}
2014-01-26 11:37:16 +01:00
2014-12-31 15:45:05 +01:00
$this -> addonSync ( $serverTypeIDs );
}
private function removeUpdateLogs () {
if ( count ( $this -> removeLogs ) > 0 ) {
$shellScript = '#!/bin/bash' . " \n " ;
2015-07-13 16:32:11 +02:00
$shellScript .= 'rm -f /home/' . $this -> sshuser . '/temp/remove-update-logs-' . $this -> uniqueHex . '.sh' . " \n " ;
2014-12-31 15:45:05 +01:00
foreach ( $this -> removeLogs as $log ) {
2015-07-13 16:32:11 +02:00
$shellScript .= 'if [ -f "' . $log . '" ]; then rm -f "' . $log . '"; fi' . " \n " ;
2014-12-31 15:45:05 +01:00
}
return $shellScript ;
}
2014-01-26 11:37:16 +01:00
2014-12-31 15:45:05 +01:00
return false ;
2013-08-28 22:47:04 +02:00
}
2014-12-31 15:45:05 +01:00
private function setUpdating () {
2013-08-28 22:47:04 +02:00
2014-12-31 15:45:05 +01:00
if ( count ( $this -> updateIDs ) > 0 ) {
2013-08-28 22:47:04 +02:00
2014-12-31 15:45:05 +01:00
global $sql ;
$query = $sql -> prepare ( " UPDATE `rservermasterg` SET `updating`='Y' WHERE `id` IN ( " . implode ( ',' , $this -> updateIDs ) . " ) " );
$query -> execute ();
2013-08-28 22:47:04 +02:00
}
2014-12-31 15:45:05 +01:00
}
private function handleFailedConnectAttemps () {
global $sql , $resellerLockupID , $rSA ;
$query = $sql -> prepare ( " UPDATE `rserverdata` SET `notified`=`notified`+1 WHERE `id`=? LIMIT 1 " );
$query -> execute ( array ( $this -> rootID ));
// While we keep on counting up, the mail is send only once to prevent spam
if (( $this -> rootNotifiedCount + 1 ) == $rSA [ 'down_checks' ]) {
2023-10-04 16:48:42 +02:00
$query = ( $resellerLockupID == 0 ) ? $sql -> prepare ( " SELECT `id`,`mail_serverdown` FROM `userdata` WHERE `resellerid`=0 AND `accounttype`='a' " ) : $sql -> prepare ( " SELECT `id`,`mail_serverdown` FROM `userdata` WHERE (`id`= ${ $resellerLockupID } AND `id`=`resellerid`) OR `resellerid`=0 AND `accounttype`='a' " );
2014-12-31 15:45:05 +01:00
$query -> execute ();
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
if ( $row [ 'mail_serverdown' ] == 'Y' ) {
sendmail ( 'emaildown' , $row [ 'id' ], $this -> sship , '' );
2013-08-28 22:47:04 +02:00
}
}
}
2014-12-31 15:45:05 +01:00
}
2013-08-28 22:47:04 +02:00
2014-12-31 15:45:05 +01:00
private function getKeyAndOrPassword () {
2013-08-28 22:47:04 +02:00
2014-12-31 15:45:05 +01:00
if ( $this -> publickey != 'N' and file_exists ( $this -> keyname )) {
2013-10-05 13:39:56 +02:00
2016-03-20 10:24:41 +01:00
$ssh2Pass = new phpseclib\Crypt\RSA ();
2013-10-05 13:39:56 +02:00
2014-12-31 15:45:05 +01:00
if ( $this -> publickey == 'B' ) {
$ssh2Pass -> setPassword ( $this -> sshpass );
2013-08-28 22:47:04 +02:00
}
2014-12-31 15:45:05 +01:00
$ssh2Pass -> loadKey ( file_get_contents ( $this -> keyname ));
2013-10-05 13:39:56 +02:00
2014-12-31 15:45:05 +01:00
} else {
$ssh2Pass = $this -> sshpass ;
}
2013-10-05 13:39:56 +02:00
2014-12-31 15:45:05 +01:00
return $ssh2Pass ;
}
2013-10-05 13:39:56 +02:00
2015-01-10 17:13:23 +01:00
private function linuxSshConnectAndExecute ( $updating , $getReturn , $ssh2Pass ) {
2013-10-05 13:39:56 +02:00
2016-03-20 10:24:41 +01:00
$sftpObject = new phpseclib\Net\SFTP ( $this -> sship , $this -> sshport );
2013-10-05 13:39:56 +02:00
2015-01-10 17:13:23 +01:00
$loginReturn = $sftpObject -> login ( $this -> sshuser , $ssh2Pass );
2013-10-05 13:39:56 +02:00
2015-01-10 17:13:23 +01:00
if ( $loginReturn ) {
2013-10-05 13:39:56 +02:00
2015-01-10 17:13:23 +01:00
$sftpObject -> put ( '/home/' . $this -> sshuser . '/temp/master-' . $this -> uniqueHex . '.sh' , $this -> shellScript );
$sftpObject -> chmod ( 0700 , '/home/' . $this -> sshuser . '/temp/master-' . $this -> uniqueHex . '.sh' );
2013-10-05 13:39:56 +02:00
2015-01-10 17:13:23 +01:00
// File has been created, now login with SSH2 and execute the script
2016-03-20 10:24:41 +01:00
$sshObject = new phpseclib\Net\SSH2 ( $this -> sship , $this -> sshport );
2013-10-05 13:39:56 +02:00
2015-01-10 17:13:23 +01:00
if ( $sshObject -> login ( $this -> sshuser , $ssh2Pass )) {
2013-10-05 13:39:56 +02:00
2015-01-10 17:13:23 +01:00
if ( $updating === true ) {
2013-08-28 22:47:04 +02:00
2015-01-10 17:13:23 +01:00
$this -> setUpdating ();
2014-12-31 15:45:05 +01:00
2015-01-10 17:13:23 +01:00
$removeLogs = $this -> removeUpdateLogs ();
2014-12-31 15:45:05 +01:00
2015-01-10 17:13:23 +01:00
if ( $removeLogs !== false ) {
2015-02-19 22:15:53 +01:00
2015-01-10 17:13:23 +01:00
$sftpObject -> put ( '/home/' . $this -> sshuser . '/temp/remove-update-logs-' . $this -> uniqueHex . '.sh' , $removeLogs );
$sftpObject -> chmod ( 0700 , '/home/' . $this -> sshuser . '/temp/remove-update-logs-' . $this -> uniqueHex . '.sh' );
2015-02-19 22:15:53 +01:00
$sshObject -> exec ( '/home/' . $this -> sshuser . '/temp/remove-update-logs-' . $this -> uniqueHex . '.sh & ' );
2015-01-10 17:13:23 +01:00
}
}
2014-12-31 15:45:05 +01:00
2015-01-10 17:13:23 +01:00
if ( $getReturn === false ) {
2014-12-31 15:45:05 +01:00
2015-01-10 17:13:23 +01:00
$sshObject -> exec ( '/home/' . $this -> sshuser . '/temp/master-' . $this -> uniqueHex . '.sh & ' );
2014-12-31 15:45:05 +01:00
2015-01-10 17:13:23 +01:00
return true ;
}
2014-12-31 15:45:05 +01:00
2015-01-10 17:13:23 +01:00
return $sshObject -> exec ( '/home/' . $this -> sshuser . '/temp/master-' . $this -> uniqueHex . '.sh' );
}
}
2014-12-31 15:45:05 +01:00
2015-01-10 17:13:23 +01:00
return false ;
}
private function windowsSshConnectAndExecute ( $updating , $getReturn , $ssh2Pass ) {
2016-03-20 10:24:41 +01:00
$sshObject = new phpseclib\Net\SSH2 ( $this -> sship , $this -> sshport );
2015-01-10 17:13:23 +01:00
if ( $sshObject -> login ( $this -> sshuser , $ssh2Pass )) {
if ( $updating === true ) {
$this -> setUpdating ();
}
if ( $getReturn === false ) {
2013-10-05 13:39:56 +02:00
2015-01-10 17:13:23 +01:00
foreach ( $this -> winCmds as $command ) {
$sshObject -> exec ( $command . " \r \n " );
2013-08-28 22:47:04 +02:00
}
2015-01-10 17:13:23 +01:00
return true ;
2013-08-28 22:47:04 +02:00
}
2015-01-10 17:13:23 +01:00
$return = '' ;
2013-10-05 13:39:56 +02:00
2015-01-10 17:13:23 +01:00
foreach ( $this -> winCmds as $command ) {
2014-12-31 15:45:05 +01:00
2015-01-10 17:13:23 +01:00
$temp = $sshObject -> exec ( $command . " \r \n " );
if ( $temp ) {
$return .= $temp ;
}
}
return $return ;
}
2014-12-31 15:45:05 +01:00
return false ;
2013-08-28 22:47:04 +02:00
}
2013-10-19 16:20:33 +02:00
2015-01-10 17:13:23 +01:00
public function sshConnectAndExecute ( $updating = true , $getReturn = false ) {
$ssh2Pass = $this -> getKeyAndOrPassword ();
$return = ( $this -> os == 'L' ) ? $this -> linuxSshConnectAndExecute ( $updating , $getReturn , $ssh2Pass ) : $this -> windowsSshConnectAndExecute ( $updating , $getReturn , $ssh2Pass );
if ( ! $return ) {
$this -> handleFailedConnectAttemps ();
}
return $return ;
}
2014-12-31 15:45:05 +01:00
private function linuxCheckForUpdate ( $shorten ) {
$updateLog = '/home/' . $this -> sshuser . '/logs/update-' . $shorten . '.log' ;
// When the logfile is missing the update is still running
$this -> shellScript .= 'if [ ! -f ' . $updateLog . ' ]; then' . " \n " ;
2023-10-04 16:48:42 +02:00
$this -> shellScript .= 'UPDATESTATUS="${UPDATESTATUS};' . $shorten . '=1"' . " \n " ;
2014-12-31 15:45:05 +01:00
$this -> shellScript .= 'else' . " \n " ;
// If it exists and the update is not running, the update is finished
$this -> shellScript .= 'if [ "`ps fx | grep \'masterserver/' . $shorten . '\' | grep -v grep | head -n 1`" ]; then' . " \n " ;
2023-10-04 16:48:42 +02:00
$this -> shellScript .= 'UPDATESTATUS="${UPDATESTATUS};' . $shorten . '=1"' . " \n " ;
2014-12-31 15:45:05 +01:00
$this -> shellScript .= 'else' . " \n " ;
2023-10-04 16:48:42 +02:00
$this -> shellScript .= 'UPDATESTATUS="${UPDATESTATUS};' . $shorten . '=0"' . " \n " ;
2014-12-31 15:45:05 +01:00
$this -> shellScript .= 'fi' . " \n " ;
$this -> shellScript .= 'fi' . " \n " ;
}
public function checkForUpdate ( $shorten ) {
if ( $this -> os == 'L' ) {
$this -> linuxCheckForUpdate ( $shorten );
} else {
2013-08-28 22:47:04 +02:00
}
}
2013-10-19 16:20:33 +02:00
2014-12-31 15:45:05 +01:00
public function getUpdateStatus () {
if ( $this -> os == 'L' ) {
$this -> shellScript .= 'echo $UPDATESTATUS' . " \n " ;
} else {
2013-08-28 22:47:04 +02:00
}
2013-10-20 12:02:02 +02:00
2014-12-31 15:45:05 +01:00
return $this -> sshConnectAndExecute ( false , true );
}
2020-07-12 19:44:16 +02:00
// Add Server space data - Nexus633
2020-07-28 15:36:24 +02:00
// Fix Json_decode error
2020-07-12 19:44:16 +02:00
public function getDiskSpace ( $path ){
if ( $this -> os == 'L' ) {
2020-07-28 15:36:24 +02:00
//$this->shellScript .= 'df -h | grep -w "' . $path . '" | awk \'{print "{\n \"mount\":\"' . $path . '\",\n \"filesystem\":\"" $1 "\",\n \"size\":\"" $2 "\",\n \"used\":\"" $3 "\",\n \"avil\":\"" $4 "\",\n \"perc\":\"" $5 "\"\n}"}\'' . "\n";
2020-07-28 21:12:07 +02:00
$this -> shellScript = 'df -h | grep -w "' . $path . '" | awk \'{print $1" "$2" "$3" "$4" "$5}\'' ;
2020-07-12 19:44:16 +02:00
} else {
2020-07-28 15:36:24 +02:00
return false ;
2020-07-12 19:44:16 +02:00
}
2020-07-28 15:36:24 +02:00
$response = $this -> sshConnectAndExecute ( false , true );
if ( isset ( $response ) && strlen ( $response ) > 0 ){
$data = explode ( ' ' , $response );
$space = new stdClass ();
$space -> mount = $path ;
$space -> filesystem = trim ( $data [ 0 ]);
$space -> size = trim ( $data [ 1 ]);
$space -> used = trim ( $data [ 2 ]);
$space -> avil = trim ( $data [ 3 ]);
$space -> perc = trim ( $data [ 4 ]);
2020-07-12 19:44:16 +02:00
2020-07-28 15:36:24 +02:00
return $space ;
}
return false ;
2020-07-12 19:44:16 +02:00
}
2014-12-31 15:45:05 +01:00
private function linuxMasterRemove ( $shorten ) {
$this -> shellScript .= 'if [ -d "' . $this -> masterserverDir . $shorten . '" ]; then rm -rf "' . $this -> masterserverDir . $shorten . '"; fi' . " \n " ;
}
2015-01-10 17:13:23 +01:00
private function WindowsMasterRemove ( $shorten ) {
$this -> winCmds [] = 'delmaster ' . $shorten ;
}
2014-12-31 15:45:05 +01:00
public function masterRemove ( $shorten ) {
2013-10-20 12:02:02 +02:00
2014-12-31 15:45:05 +01:00
if ( $this -> os == 'L' ) {
$this -> linuxMasterRemove ( $shorten );
} else {
2015-01-10 17:13:23 +01:00
$this -> WindowsMasterRemove ( $shorten );
2014-12-31 15:45:05 +01:00
}
2013-08-28 22:47:04 +02:00
}
2013-10-20 12:02:02 +02:00
2013-08-28 22:47:04 +02:00
function __destruct () {
2014-12-31 15:45:05 +01:00
unset ( $this -> imageserver , $this -> resellerID , $this -> webhost , $this -> rootOK , $this -> rootID , $this -> steamAccount , $this -> steamPassword , $this -> updates , $this -> os , $this -> aeskey , $this -> shellScript , $this -> uniqueHex , $this -> sship , $this -> sshport , $this -> sshuser , $this -> sshpass , $this -> publickey , $this -> keyname );
2013-08-28 22:47:04 +02:00
}
2015-07-05 02:01:02 +02:00
}