#508 Replace control.sh with PHP class

Inlcuded class into GS jobs
Implemented needed changes to GS API
Added fallback for function addApp()
Added fallback in case the serverid is not properly set at gsswitch
Added additional checks in class, if data could be properly fetched
Activated autodelete for generated scripts
This commit is contained in:
Ulrich Block 2014-11-09 12:06:25 +01:00
parent 5454a8464e
commit c361f202d6
6 changed files with 218 additions and 257 deletions

View File

@ -86,6 +86,8 @@ include(EASYWIDIR . '/stuff/methods/vorlage.php');
include(EASYWIDIR . '/stuff/methods/functions.php');
include(EASYWIDIR . '/stuff/methods/class_validator.php');
include(EASYWIDIR . '/stuff/methods/class_rootserver.php');
include(EASYWIDIR . '/stuff/methods/class_ftp.php');
include(EASYWIDIR . '/stuff/methods/class_app.php');
include(EASYWIDIR . '/stuff/methods/class_httpd.php');
include(EASYWIDIR . '/stuff/settings.php');
include(EASYWIDIR . '/stuff/methods/functions_gs.php');

View File

@ -65,7 +65,7 @@ if ($reseller_id == 0) {
$id = $ui->id('id', 10, 'get');
// CSFR protection with hidden tokens. If token(true) returns false, we likely have an attack
if ($ui->w('action',4, 'post') and !token(true)) {
if ($ui->w('action', 4, 'post') and !token(true)) {
unset($header, $text);

View File

@ -443,7 +443,7 @@ if ($ui->w('action', 4, 'post') and !token(true)) {
$started[] = $row['serverip'] . ':' . $row['port'];
$appServer->addApp(array($row['shorten']));
$appServer->addApp();
}
}

View File

@ -553,7 +553,6 @@ if (!isset($success['false']) and array_value_exists('action', 'add', $data) and
$port3 = $row['port3'];
$port4 = $row['port4'];
$port5 = $row['port5'];
$active = $row['active'];
$cores = $row['cores'];
$minram = $row['minram'];
$maxram = $row['maxram'];
@ -652,6 +651,8 @@ if (!isset($success['false']) and array_value_exists('action', 'add', $data) and
}
if (isset($data['active']) and active_check($data['active']) and $data['active'] != $row['active']) {
$updateArray[] = $data['active'];
$eventualUpdate .= ',`active`=?';
$active = $data['active'];
}
@ -771,18 +772,15 @@ if (!isset($success['false']) and array_value_exists('action', 'add', $data) and
}
}
$gamesRemoveAmount = count($gamesToBeRemoved);
$gamesRemoveString = ($gamesRemoveAmount > 0) ? $gamesRemoveAmount . '_' . implode('_', $gamesToBeRemoved) : '';
$customID = $localID;
if ($active != $oldActive or $port != $oldPort or $homeDirLabel != $oldHomeDirLabel or $hdd != $oldHdd or $pallowed != $oldProtected or $gamesRemoveAmount > 0) {
if ($active != $oldActive or $port != $oldPort or $homeDirLabel != $oldHomeDirLabel or $hdd != $oldHdd or $pallowed != $oldProtected or count($gamesToBeRemoved) > 0) {
$query = $sql->prepare("UPDATE `jobs` SET `status`='2' WHERE `type`='gs' AND (`status` IS NULL OR `status`='1') AND `action`!='ad' AND `affectedID`=? and `resellerID`=?");
$query->execute(array($localID, $resellerID));
$query = $sql->prepare("INSERT INTO `jobs` (`api`,`type`,`hostID`,`invoicedByID`,`affectedID`,`userID`,`name`,`status`,`date`,`action`,`extraData`,`resellerID`) VALUES ('A','gs',?,?,?,?,?,NULL,NOW(),'md',?,?)");
$query->execute(array($hostID, $resellerID, $localID, $userID, $name, json_encode(array('newActive' => $active, 'newPort' => $port, 'oldProtected' => $oldProtected, 'homeDirChanged' => ($homeDirLabel != $oldHomeDirLabel) ? 1 : 0, 'installGames' => 'N', 'gamesRemoveString' => $gamesRemoveString)), $resellerID));
$query->execute(array($hostID, $resellerID, $localID, $userID, $name, json_encode(array('newPort' => $port, 'oldProtected' => $oldProtected, 'installGames' => 'N', 'gamesRemoveArray' => $gamesToBeRemoved)), $resellerID));
}
}

View File

@ -4,7 +4,6 @@
* File: jobs_gserver.php.
* Author: Ulrich Block
* Date: 05.08.12
* Time: 23:31
* Contact: <ulrich.block@easy-wi.com>
*
* This file is part of Easy-WI.
@ -38,232 +37,160 @@
* Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
*/
$sprache = getlanguagefile('gserver', 'en', 0);
$query = $sql->prepare("SELECT `hostID`,`resellerID` FROM `jobs` WHERE (`status` IS NULL OR `status`='1') AND `type`='gs' GROUP BY `hostID`");
$query2 = $sql->prepare("SELECT * FROM `jobs` WHERE (`status` IS NULL OR `status`='1') AND `type`='gs' AND `hostID`=?");
$query3 = $sql->prepare("SELECT g.*,AES_DECRYPT(g.`ftppassword`,?) AS `ftp`,AES_DECRYPT(g.`ppassword`,?) AS `ppasswordftp`,u.`cname`,r.`install_paths`,r.`quota_active`,r.`quota_cmd`,r.`blocksize`,r.`inode_block_ratio` FROM `gsswitch` AS g INNER JOIN `userdata` AS u ON g.`userid`=u.`id` INNER JOIN `rserverdata` AS r ON r.`id`=g.`rootID` WHERE g.`id`=? LIMIT 1");
$query->execute();
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
$query3 = $sql->prepare("SELECT `serverip`,`port`,`pallowed` FROM `gsswitch` WHERE `id`=? LIMIT 1");
$query4 = $sql->prepare("DELETE FROM `gsswitch` WHERE `id`=? LIMIT 1");
$query5 = $sql->prepare("UPDATE `jobs` SET `status`='3' WHERE `jobID`=? LIMIT 1");
$query6 = $sql->prepare("SELECT t.`shorten` FROM `serverlist` AS s INNER JOIN `servertypes` AS t ON t.`id`=s.`servertype` WHERE s.`switchID`=?");
$query7 = $sql->prepare("UPDATE `gsswitch` SET `serverip`=?,`port`=? WHERE `id`=? LIMIT 1");
$query8 = $sql->prepare("UPDATE `gsswitch` SET `jobPending`='N' WHERE `id`=? LIMIT 1");
$query9 = $sql->prepare("UPDATE `jobs` SET `status`='2' WHERE `jobID`=? LIMIT 1");
$cmds = array();
$query->execute();
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
// at web part set within settings.php; here in the job needs to be set on a root by root case
$resellerLockupID = $row['resellerID'];
$appServer = new AppServer($row['hostID']);
$query2->execute(array($row['hostID']));
$serverData = serverdata('root', $row['hostID'], $aeskey);
$sshuser = $serverData['user'];
while ($row2 = $query2->fetch(PDO::FETCH_ASSOC)) {
foreach ($query2->fetchAll(PDO::FETCH_ASSOC) as $row2) {
unset($customer, $i);
$appServer->getAppServerDetails($row2['affectedID']);
$extraData = @json_decode($row2['extraData']);
$installGames = (is_object($extraData) and property_exists($extraData, 'installGames') and preg_match('/[APN]/', $extraData->installGames)) ? $extraData->installGames : 'N';
$query3->execute(array($aeskey, $aeskey, $row2['affectedID']));
foreach ($query3->fetchAll(PDO::FETCH_ASSOC) as $row3) {
$active = $row3['active'];
$newActive = $row3['active'];
$query3->execute(array($row2['affectedID']));
while ($row3 = $query3->fetch(PDO::FETCH_ASSOC)) {
$gsIP = $row3['serverip'];
$port = $row3['port'];
$newPort = $row3['serverip'];
$newIP = $row3['port'];
$gsfolder = $row3['serverip'] . '_' . $row3['port'];
$ftppass = $row3['ftp'];
$ftppass2 = ($row3['pallowed'] == 'Y') ? $row3['ppasswordftp'] : '';
$protectedAllowed = $row3['pallowed'];
$customer = ($row3['newlayout'] == 'Y') ? $row3['cname'] . '-' . $row3['id'] : $row3['cname'];
$gamestring = '';
$iniVars = parse_ini_string($row3['install_paths'], true);
$homeDir = (isset($iniVars[$row3['homeLabel']]['path'])) ? $iniVars[$row3['homeLabel']]['path'] : '/home';
$quotaCmd = false;
if ($row3['quota_active'] == 'Y' and strlen($row3['quota_cmd']) > 0 and $row3['hdd'] > 0) {
// setquota works with KibiByte and Inodes; Stored is Megabyte
$sizeInKibiByte = $row3['hdd'] * 1024;
$sizeInByte = $row3['hdd'] * 1048576;
$blockAmount = round(($sizeInByte /$row3['blocksize']));
$inodeAmount = round($blockAmount / $row3['inode_block_ratio']);
$mountPoint = (isset($iniVars[$row3['homeLabel']]['mountpoint'])) ? $iniVars[$row3['homeLabel']]['mountpoint'] : $homeDir;
$quotaCmd = 'q() { ' . str_replace('%cmd%', " -u {$customer} {$sizeInKibiByte} {$sizeInKibiByte} {$inodeAmount} {$inodeAmount} {$mountPoint}", $row3['quota_cmd']) . ' > /dev/null 2>&1; }; q&';
}
if ($installGames == 'P') {
$query4 = $sql->prepare("SELECT t.`gamemod`,t.`gamemod2`,t.`shorten` FROM `serverlist` s INNER JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE s.`id`=? LIMIT 1");
$query4->execute(array($row3['serverid']));
foreach ($query4->fetchAll(PDO::FETCH_ASSOC) as $row4) {
$gamestring .= ($row4['gamemod'] == 'Y' and strlen($row4['gamemod']) > 0) ? '_' . $row4['shorten'] . $row4['gamemod2'] : '_' . $row4['shorten'];
}
} else {
$query4 = $sql->prepare("SELECT t.`gamemod`,t.`gamemod2`,t.`shorten` FROM `serverlist` s INNER JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE s.`switchID`=?");
$query4->execute(array($row2['affectedID']));
foreach ($query4->fetchAll(PDO::FETCH_ASSOC) as $row4) {
$gamestring .= ($row4['gamemod'] == 'Y' and strlen($row4['gamemod']) > 0) ? '_' . $row4['shorten'] . $row4['gamemod2'] : '_' . $row4['shorten'];
}
}
$i = (int) $query4->rowCount();
$gamestring = $i . $gamestring;
}
if (isset($i) and $row2['action'] == 'dl' and isset($customer)) {
if ($query3->rowCount() > 0) {
$cmds[] = 'sudo -u ' . $customer . ' ./control.sh stopall ' . $customer;
$cmds[] = 'sudo -u ' . $customer . '-p ./control.sh stopall ' . $customer . '-p';
$cmds[] = './control.sh delCustomer ' . $customer;
if ($row2['action'] == 'dl') {
$query4 = $sql->prepare("DELETE FROM `gsswitch` WHERE `id`=? LIMIT 1");
$query4->execute(array($row2['affectedID']));
$appServer->stopAppHard();
$appServer->userCud('del', 'both');
customColumns('G', $row2['affectedID'], 'del');
$query4->execute(array($row2['affectedID']));
$query4 = $sql->prepare("UPDATE `jobs` SET `status`='3' WHERE `jobID`=? AND `type`='gs' LIMIT 1");
$query4->execute(array($row2['jobID']));
customColumns('G', $row2['affectedID'], 'del');
$command = $gsprache->del . ' gsswitchID: ' . $row2['affectedID'] . ' name:' . $row2['name'] . ' gsswitchID:' . $row2['affectedID'];
$query5->execute(array($row2['jobID']));
} else if (isset($i) and $row2['action'] == 'ad' and isset($customer)) {
$command = $gsprache->del . ' gsswitchID: ' . $row2['affectedID'] . ' name:' . $row2['name'] . ' gsswitchID:' . $row2['affectedID'];
if ($i > 0) {
} else if ($row2['action'] == 'ad' or $row2['action'] == 'md' and is_object($extraData)) {
$addProtectedUser = ($protectedAllowed == 'Y') ? passwordgenerate(10) : '';
$installGames = (is_object($extraData) and property_exists($extraData, 'installGames') and preg_match('/[APN]/', $extraData->installGames)) ? $extraData->installGames : 'N';
$cmds[] = "./control.sh useradd {$customer} {$ftppass} {$homeDir} {$addProtectedUser}";
// userCrud will set the user to inactive
$appServer->userCud('add');
if ($installGames != 'N') {
$appServer->setQuota();
$cmds[] = "sudo -u {$customer} ./control.sh addserver {$customer} {$gamestring} {$gsfolder} \"1\" {$homeDir}";
if ($row2['action'] == 'ad') {
if ($quotaCmd) {
$cmds[] = $quotaCmd;
if ($installGames == 'P') {
$appServer->addApp();
} else if ($installGames == 'A') {
$templates = array();
$query6->execute(array($row2['affectedID']));
while ($row = $query6->fetch(PDO::FETCH_ASSOC)) {
$templates[] = $row['shorten'];
$templates[] = $row['shorten'] . '-2';
$templates[] = $row['shorten'] . '-3';
}
$appServer->addApp($templates);
}
$command = $gsprache->add . ' gsswitchID: ' . $row2['affectedID'] . ' name:' . $row2['name'] . ' gsswitchID:' . $row2['affectedID'];
} else {
$removeGames = (array) $extraData->gamesRemoveArray;
if (count($removeGames) > 0) {
$removeTemplates = array();
foreach ($removeGames as $game) {
$removeTemplates[] = $game;
$removeTemplates[] = $game . '-2';
$removeTemplates[] = $game . '-3';
}
$appServer->removeApp($removeTemplates);
}
// Send delete request for protected user in case it has been removed from server
if ($protectedAllowed == 'N' and isset($extraData->oldProtected) and $extraData->oldProtected == 'Y') {
$appServer->userCud('del');
}
$newPort = (isset($extraData->newPort) and strlen($extraData->newPort) > 0) ? $extraData->newPort : $port;
$newIP = (isset($extraData->newIP) and strlen($extraData->newIP) > 0) ? $extraData->newIP : $gsIP;
if ($port != $newPort or $gsIP != $newIP) {
$query7->execute(array($newIP, $newPort, $row2['affectedID']));
$appServer->moveServerLocal($row3['serverip'], $row3['port']);
}
$command = $gsprache->mod . ' gsswitchID: ' . $row2['affectedID'] . ' name: ' . $row2['name'] . ' gsswitchID:' . $row2['affectedID'];
}
$query4 = $sql->prepare("UPDATE `jobs` SET `status`='3' WHERE `jobID`=? AND `type`='gs' LIMIT 1");
$query4->execute(array($row2['jobID']));
$query8->execute(array($row2['affectedID']));
$command = $gsprache->add . ' gsswitchID: ' . $row2['affectedID'] . ' name:' . $row2['name'] . ' gsswitchID:' . $row2['affectedID'];
$query5->execute(array($row2['jobID']));
} else if ($row2['action'] == 're') {
$appServer->startApp();
$query5->execute(array($row2['jobID']));
$command = '(Re)Start gsswitchID: ' . $row2['affectedID'] . ' name: ' . $row2['name'];
} else if ($row2['action'] == 'st') {
$appServer->stopApp();
$query5->execute(array($row2['jobID']));
$command = 'Stop gsswitchID: ' . $row2['affectedID'] . ' name: ' . $row2['name'];
} else {
$command = 'Error no switchserver found for this gsswitchID: ' . $row2['affectedID'] . ' name:' . $row2['name'] . ' gsswitchID:' . $row2['affectedID'];
$query9->execute(array($row2['jobID']));
$command = 'Error: unknown command';
}
} else if (isset($i) and $row2['action'] == 'md' and isset($customer) and isset($active)) {
// We will run the add user command in nearly any case
// Reasons are that we ensure FTP password correctness and existence of linux user
// Also we will add the protected user with variable 5 if needed
$cmds[] = "./control.sh useradd {$customer} {$ftppass} {$homeDir} {$ftppass2}";
if (is_object($extraData)) {
// Send delete request for protected user in case it has been removed from server
if (isset($protectedAllowed) and $protectedAllowed == 'N' and isset($extraData->oldProtected) and $extraData->oldProtected == 'Y') {
$cmds[] = "./control.sh delSingleUser {$customer}-p";
}
$newActive = (isset($extraData->newActive) and strlen($extraData->newActive) > 0) ? $extraData->newActive : $active;
if ($active != $newActive and $newActive == 'N') {
$ftppass = passwordgenerate(10);
$ftppass2 = (isset($protectedAllowed) and $protectedAllowed == 'Y') ? passwordgenerate(10) : '';
$tmp = gsrestart($row2['affectedID'], 'so', $aeskey, $row['resellerID']);
if (is_array($tmp)) {
foreach($tmp as $cmd) {
if (strpos($cmd, 'addserver') === false) {
$cmds[] = $cmd;
}
}
}
}
if (isset($extraData->gamesRemoveString) and strlen($extraData->gamesRemoveString) > 0) {
$cmds[] = "sudo -u {$customer} ./control.sh delserver {$customer} {$extraData->gamesRemoveString} {$gsIP}_{$port} unprotected {$homeDir}";
}
if ($active != $newActive or (isset($extraData->homeDirChanged) and $extraData->homeDirChanged == 1)) {
$cmds[] = "./control.sh usermod {$customer} {$ftppass} {$homeDir} {$ftppass2}";
}
$newPort = (isset($extraData->newPort) and strlen($extraData->newPort) > 0) ? $extraData->newPort : $port;
$newIP = (isset($extraData->newIP) and strlen($extraData->newIP) > 0) ? $extraData->newIP : $gsIP;
if ($port != $newPort or $gsIP != $newIP) {
$cmds[] = "sudo -u {$customer} ./control.sh ip_port_change {$customer} {$gsfolder} {$newIP}_{$newPort} {$homeDir}";
}
}
if ($quotaCmd) {
$cmds[] = $quotaCmd;
}
$query4 = $sql->prepare("UPDATE `gsswitch` SET `active`=?,`serverip`=?,`port`=?,`jobPending`='N' WHERE `id`=? LIMIT 1");
$query4->execute(array($newActive, $newIP, $newPort, $row2['affectedID']));
$query4 = $sql->prepare("UPDATE `jobs` SET `status`='3' WHERE `jobID`=? AND `type`='gs' LIMIT 1");
$query4->execute(array($row2['jobID']));
$command = $gsprache->mod . ' gsswitchID: ' . $row2['affectedID'] . ' name: ' . $row2['name'] . ' gsswitchID:' . $row2['affectedID'];
} else if (isset($i) and $row2['action'] == 're' and isset($customer)) {
$tmp = gsrestart($row2['affectedID'], 're', $aeskey, $row2['resellerID']);
if (is_array($tmp)) {
foreach($tmp as $t) {
$cmds[] = $t;
}
}
$query4 = $sql->prepare("UPDATE `jobs` SET `status`='3' WHERE `jobID`=? AND `type`='gs' LIMIT 1");
$query4->execute(array($row2['jobID']));
$command = '(Re)Start gsswitchID: ' . $row2['affectedID'] . ' name: ' . $row2['name'];
} else if (isset($i) and $row2['action'] == 'st' and isset($customer)) {
$tmp = gsrestart($row2['affectedID'], 'so', $aeskey, $row2['resellerID']);
if (is_array($tmp)) {
foreach($tmp as $t) {
$cmds[] = $t;
}
}
$query4 = $sql->prepare("UPDATE `jobs` SET `status`='3' WHERE `jobID`=? AND `type`='gs' LIMIT 1");
$query4->execute(array($row2['jobID']));
$command = 'Stop gsswitchID: ' . $row2['affectedID'] . ' name: ' . $row2['name'];
} else if (!isset($i) and !isset($customer)) {
$query4 = $sql->prepare("UPDATE `jobs` SET `status`='2' WHERE `jobID`=? AND `type`='gs' LIMIT 1");
$query4->execute(array($row2['jobID']));
$command = 'Error: can not find gsswitchID';
} else {
$command = 'Error: unknown command';
$query9->execute(array($row2['jobID']));
$command = 'Error: can not find gsswitchID';
}
$theOutput->printGraph($command);
}
if (isset($dbConnect['debug']) and $dbConnect['debug'] == 1) {
print_r($cmds);
}
$appServer->execute();
if (count($cmds)>0) {
ssh2_execute('gs', $row['hostID'], $cmds);
if (isset($dbConnect['debug']) and $dbConnect['debug'] == 1) {
print_r($appServer->debug());
}
}

View File

@ -124,9 +124,21 @@ class AppServer {
// If app details can not be found return false
if (!$this->getAppDetails($row['serverid'], $id)) {
$this->appServerDetails = false;
$query2 = $sql->prepare("SELECT `id` FROM `serverlist` WHERE `switchID`=? LIMIT 1");
$query2->execute(array($id));
$row['serverid'] = $query2->fetchColumn();
return false;
if ($row['serverid'] > 0) {
$query2 = $sql->prepare("UPDATE `gsswitch` SET `serverid`=? WHERE `id`=? LIMIT 1");
$query2->execute(array($row['serverid'], $id));
}
if (!$this->getAppDetails($row['serverid'], $id)) {
$this->appServerDetails = false;
return false;
}
}
$this->appServerDetails['id'] = (int) $row['id'];
@ -338,7 +350,7 @@ class AppServer {
private function linuxAddModUserGenerate ($userName, $password, $protected = false) {
$userNameHome = ($protected == false) ? $userName : $userName . '/pserver';
$userNameHome = ($protected == false) ? $this->appServerDetails['userName'] : $this->appServerDetails['userName'] . '/pserver';
// Check if the user can be found. If not, add it, if yes, edit
$this->shellScripts['user'] .= 'if [ "`id ' . $userName . ' 2>/dev/null`" == "" ]; then' . "\n";
@ -402,7 +414,7 @@ class AppServer {
public function userCud ($action, $type = false) {
if (isset($this->appMasterServerDetails['os'])) {
if ($this->appServerDetails and isset($this->appMasterServerDetails['os'])) {
if ($action == 'del') {
if ($this->appMasterServerDetails['os'] == 'L') {
@ -426,7 +438,7 @@ class AppServer {
// Quotas are a Linux technique to define the diskspace a user is allowed to use.
public function setQuota () {
if ($this->appMasterServerDetails['os'] == 'L' and $this->appMasterServerDetails['quotaActive'] == 'Y' and strlen($this->appMasterServerDetails['quotaCmd']) > 0 and $this->appServerDetails['hdd'] > 0) {
if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'L' and $this->appMasterServerDetails['quotaActive'] == 'Y' and strlen($this->appMasterServerDetails['quotaCmd']) > 0 and $this->appServerDetails['hdd'] > 0) {
// setquota works with KibiByte and Inodes; Stored is Megabyte
$sizeInKibiByte = $this->appServerDetails['hdd'] * 1024;
@ -461,7 +473,7 @@ class AppServer {
$scriptName = $this->removeSlashes('/home/' . $this->appMasterServerDetails['ssh2User'] . '/temp/move-' . $this->appServerDetails['userName'] . '-' . $this->appServerDetails['serverIP'] . '-' . $this->appServerDetails['port'] . '-' . $oldIP . '-' . $oldPort . '.sh');
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
$script .= 'cd ' . $this->removeSlashes($this->appServerDetails['homeDir'] . '/' . $this->appServerDetails['userName'] . '/server') . "\n";
$script .= 'if [ -d "' . $this->appServerDetails['serverIP'] . '_' . $this->appServerDetails['port']. '" ]; then rm -rf "' . $this->appServerDetails['serverIP'] . '_' . $this->appServerDetails['port'] . '"; fi' . "\n";
$script .= 'mv ' . $oldIP . '_' . $oldPort . ' ' . $this->appServerDetails['serverIP'] . '_' . $this->appServerDetails['port'] . "\n";
@ -473,9 +485,9 @@ class AppServer {
public function moveServerLocal ($oldIP, $oldPort) {
if ($this->appMasterServerDetails['os'] == 'L') {
if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'L') {
$this->linuxMoveServerLocal($oldIP, $oldPort);
} else if ($this->appMasterServerDetails['os'] == 'W') {
} else if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'W') {
}
}
@ -490,7 +502,7 @@ class AppServer {
$copyFileExtensions = array('xml', 'vdf', 'cfg', 'con', 'conf', 'config', 'ini', 'gam', 'txt', 'log', 'smx', 'sp', 'db', 'lua', 'props', 'properties', 'json', 'example');
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
$script .= 'PATTERN="valve\|overviews/\|scripts/\|media/\|particles/\|gameinfo.txt\|steam.inf\|/sound/\|steam_appid.txt\|/hl2/\|/overviews/\|/resource/\|/sprites/"' . "\n";
foreach ($templates as $template) {
@ -521,7 +533,12 @@ class AppServer {
}
public function addApp ($templates = array()) {
if (count($templates) > 0) {
if (count($templates) == 0) {
$templates = array($this->appServerDetails['app']['templateChoosen']);
}
if ($this->appServerDetails) {
if ($this->appMasterServerDetails['os'] == 'L') {
$this->linuxAddApp($templates);
} else if ($this->appMasterServerDetails['os'] == 'W') {
@ -535,7 +552,7 @@ class AppServer {
$serverDir = ($this->appServerDetails['protectionModeStarted'] == 'Y') ? 'pserver/' : 'server/';
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
$script .= 'cd ' . $this->removeSlashes($this->appServerDetails['homeDir'] . $this->appServerDetails['userName'] . '/' . $serverDir . $this->appServerDetails['serverIP'] . '_' . $this->appServerDetails['port'] . '/') . "\n";
foreach ($templates as $template) {
@ -548,12 +565,15 @@ class AppServer {
public function removeApp ($templates) {
$this->easyAntiCheatSettings('stop');
if ($this->appServerDetails) {
if (count($templates) > 0) {
if ($this->appMasterServerDetails['os'] == 'L') {
$this->linuxRemoveApp($templates);
} else if ($this->appMasterServerDetails['os'] == 'W') {
$this->easyAntiCheatSettings('stop');
if (count($templates) > 0) {
if ($this->appMasterServerDetails['os'] == 'L') {
$this->linuxRemoveApp($templates);
} else if ($this->appMasterServerDetails['os'] == 'W') {
}
}
}
}
@ -566,7 +586,7 @@ class AppServer {
if ($standalone === true) {
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
} else {
$script = '';
@ -593,7 +613,7 @@ class AppServer {
}
public function mcWorldSave () {
if ($this->appServerDetails['template']['gameq'] == 'minecraft') {
if ($this->appServerDetails and $this->appServerDetails['template']['gameq'] == 'minecraft') {
if ($this->appMasterServerDetails['os'] == 'L') {
} else if ($this->appMasterServerDetails['os'] == 'W') {
}
@ -609,7 +629,7 @@ class AppServer {
$scriptName = $this->removeSlashes('/home/' . $this->appMasterServerDetails['ssh2User'] . '/temp/stop-' . $this->appServerDetails['userNameExecute'] . '-' . $this->appServerDetails['serverIP'] . '-' . $this->appServerDetails['port'] . '.sh');
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
} else {
$script = '';
@ -641,6 +661,11 @@ class AppServer {
$script .= 'kill -9 $PID > /dev/null 2>&1' . "\n";
$script .= 'done' . "\n";
//TODO: inlcude demo upload
/*if ($this->appServerDetails['template']['gameBinary'] == 'srcds_run' and $this->appServerDetails['tvAllowed'] == 'Y') {
$script .= $this->demoUpload();
}*/
if ($standalone === true) {
$this->addLinuxScript($scriptName, $script);
$this->addLogline('app_server.log', 'App ' . $screenName . ' owned by user ' . $this->appServerDetails['userNameExecute'] . ' stopped');
@ -653,15 +678,18 @@ class AppServer {
global $sql;
$this->easyAntiCheatSettings('stop');
if ($this->appServerDetails) {
if ($this->appMasterServerDetails['os'] == 'L') {
$this->linuxStopApp();
} else if ($this->appMasterServerDetails['os'] == 'W') {
$this->easyAntiCheatSettings('stop');
if ($this->appMasterServerDetails['os'] == 'L') {
$this->linuxStopApp();
} else if ($this->appMasterServerDetails['os'] == 'W') {
}
$query = $sql->prepare("UPDATE `gsswitch` SET `stopped`='Y' WHERE `id`=? LIMIT 1");
$query->execute(array($this->appServerDetails['id']));
}
$query = $sql->prepare("UPDATE `gsswitch` SET `stopped`='Y' WHERE `id`=? LIMIT 1");
$query->execute(array($this->appServerDetails['id']));
}
private function linuxHardStop ($userName) {
@ -669,7 +697,7 @@ class AppServer {
$scriptName = $this->removeSlashes('/home/' . $this->appMasterServerDetails['ssh2User'] . '/temp/hardstop-' . $userName . '.sh');
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
$script .= 'crontab -r' . "\n";
$script .= 'screen -wipe > /dev/null 2>&1' . "\n";
@ -680,7 +708,7 @@ class AppServer {
}
public function stopAppHard () {
if ($this->appMasterServerDetails['os'] == 'L') {
if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'L') {
$this->linuxHardStop($this->appServerDetails['userName']);
@ -688,7 +716,7 @@ class AppServer {
$this->linuxHardStop($this->appServerDetails['userNameExecute']);
}
} else if ($this->appMasterServerDetails['os'] == 'W') {
} else if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'W') {
}
}
@ -1092,7 +1120,7 @@ class AppServer {
$serverTemplateDir = $this->removeSlashes($serverDir . '/' . $this->appServerDetails['serverIP'] . '_' . $this->appServerDetails['port'] . '/');
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
$script .= $this->linuxStopApp(false, $scriptName);
@ -1149,6 +1177,9 @@ class AppServer {
$script .= 'if [ -f screenlog.0 ]; then rm screenlog.0; fi' . "\n";
$script .= $this->generateStartCommand() . "\n";
//TODO: inlcude demo upload. In this case check if deamon mode should be active and start loop that tails the screenlog
// Should be improved like: check if file has been removed and added newly (how to check for the creationdate of a file)
$this->addLinuxScript($scriptName, $script);
$this->addLogline('app_server.log', 'App ' . $this->appServerDetails['serverIP'] . '_' . $this->appServerDetails['port'] . ' owned by user ' . $this->appServerDetails['userNameExecute'] . ' started');
}
@ -1157,35 +1188,38 @@ class AppServer {
global $sql;
$this->getAddonDetails();
if ($this->appServerDetails) {
$this->correctProtectedFiles();
$this->getAddonDetails();
$this->easyAntiCheatSettings();
$this->correctProtectedFiles();
if ($this->appMasterServerDetails['os'] == 'L') {
$this->easyAntiCheatSettings();
if ($this->appServerDetails['protectionModeStarted'] == 'Y') {
$this->linuxHardStop($this->appServerDetails['userName']);
} else if ($this->appServerDetails['protectionModeAllowed'] == 'Y' and $this->appServerDetails['protectionModeStarted'] == 'N') {
$this->linuxHardStop($this->appServerDetails['userName'] . '-p');
if ($this->appMasterServerDetails['os'] == 'L') {
if ($this->appServerDetails['protectionModeStarted'] == 'Y') {
$this->linuxHardStop($this->appServerDetails['userName']);
} else if ($this->appServerDetails['protectionModeAllowed'] == 'Y' and $this->appServerDetails['protectionModeStarted'] == 'N') {
$this->linuxHardStop($this->appServerDetails['userName'] . '-p');
}
$this->linuxAddApp(array($this->appServerDetails['app']['templateChoosen']));
$this->linuxAddAddons();
$this->linuxStartApp();
} else if ($this->appMasterServerDetails['os'] == 'W') {
}
$this->linuxAddApp(array($this->appServerDetails['app']['templateChoosen']));
$this->linuxAddAddons();
$this->linuxStartApp();
} else if ($this->appMasterServerDetails['os'] == 'W') {
$query = $sql->prepare("UPDATE `gsswitch` SET `stopped`='N' WHERE `id`=? LIMIT 1");
$query->execute(array($this->appServerDetails['id']));
}
$query = $sql->prepare("UPDATE `gsswitch` SET `stopped`='N' WHERE `id`=? LIMIT 1");
$query->execute(array($this->appServerDetails['id']));
}
public function demoUpload () {
if ($this->appMasterServerDetails['os'] == 'L') {
} else if ($this->appMasterServerDetails['os'] == 'W') {
if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'L') {
} else if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'W') {
}
}
@ -1246,7 +1280,7 @@ class AppServer {
$scriptName = $this->removeSlashes('/home/' . $this->appMasterServerDetails['ssh2User'] . '/temp/addons-add-' . $this->appServerDetails['userNameExecute'] . '-' . $this->appServerDetails['serverIP'] . '-' . $this->appServerDetails['port'] . '.sh');
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
if ($id === false) {
@ -1284,46 +1318,46 @@ class AppServer {
}
if (isset($logLine)) {
if (isset($logLine) and strlen($logLine) > 0) {
$this->addLinuxScript($scriptName, $script);
$this->addLogline('app_server.log', $logLine . ' to app ' . $this->appServerDetails['serverIP'] . '_' . $this->appServerDetails['port'] . ' owned by user ' . $this->appServerDetails['userNameExecute']);
}
}
public function addAddon ($id) {
if ($this->appMasterServerDetails['os'] == 'L') {
if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'L') {
$this->linuxAddAddons($id);
} else if ($this->appMasterServerDetails['os'] == 'W') {
} else if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'W') {
}
}
public function removeAddon () {
if ($this->appMasterServerDetails['os'] == 'L') {
} else if ($this->appMasterServerDetails['os'] == 'W') {
if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'L') {
} else if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'W') {
}
}
public function migrateToEasyWi () {
if ($this->appMasterServerDetails['os'] == 'L') {
} else if ($this->appMasterServerDetails['os'] == 'W') {
if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'L') {
} else if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'W') {
}
}
public function fastDLSync () {
if ($this->appMasterServerDetails['os'] == 'L') {
} else if ($this->appMasterServerDetails['os'] == 'W') {
if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'L') {
} else if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'W') {
}
}
public function backupCreate () {
if ($this->appMasterServerDetails['os'] == 'L') {
} else if ($this->appMasterServerDetails['os'] == 'W') {
if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'L') {
} else if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'W') {
}
}
public function backupDeploy () {
if ($this->appMasterServerDetails['os'] == 'L') {
} else if ($this->appMasterServerDetails['os'] == 'W') {
if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'L') {
} else if ($this->appServerDetails and $this->appMasterServerDetails['os'] == 'W') {
}
}