#508 Replace control.sh with PHP class

replaced old function usage with class usage at:
Lend server
statuscheck
planned restarts

Removed not function gsrestart
This commit is contained in:
Ulrich Block 2014-11-23 12:53:36 +01:00
parent ed5a540000
commit 736eb7ecf7
6 changed files with 136 additions and 774 deletions

View File

@ -64,6 +64,7 @@ include(EASYWIDIR . '/stuff/keyphrasefile.php');
include(EASYWIDIR . '/stuff/methods/functions_gs.php');
include(EASYWIDIR . '/stuff/methods/functions_ssh_exec.php');
include(EASYWIDIR . '/stuff/methods/class_ts3.php');
include(EASYWIDIR . '/stuff/methods/class_app.php');
$validacces = false;
@ -311,8 +312,10 @@ if (isset($servertype)) {
$query1->execute(array($serverid, $reseller_id));
foreach($query1->fetchAll(PDO::FETCH_ASSOC) as $row1) {
$cmds = gsrestart($row1['switchID'], 'so', $aeskey, $reseller_id);
ssh2_execute('gs', $row1['rootID'], $cmds);
$appServer = new AppServer($row1['rootID']);
$appServer->getAppServerDetails($row1['switchID']);
$appServer->stopApp();
$appServer->execute();
}
} else if ($servertype == 'v') {
@ -881,8 +884,10 @@ if (!isset($template_file) and ((!isset($servertype) and isset($page_include) an
$query = $insert = $sql->prepare("UPDATE `gsswitch` SET `serverid`=? WHERE `id`=? AND `resellerid`=? LIMIT 1");
$query->execute(array($serverid, $updateID, $reseller_id));
$cmds = gsrestart($updateID, 're', $aeskey, $reseller_id);
ssh2_execute('gs', $rootID, $cmds);
$appServer = new AppServer($rootID);
$appServer->getAppServerDetails($updateID);
$appServer->startApp();
$appServer->execute();
if (!isset($page_include) and $ui->id('xml', 1, 'post') == 1) {

View File

@ -53,6 +53,7 @@ include(EASYWIDIR . '/stuff/methods/functions.php');
include(EASYWIDIR . '/stuff/settings.php');
include(EASYWIDIR . '/stuff/methods/functions_gs.php');
include(EASYWIDIR . '/stuff/methods/functions_ssh_exec.php');
include(EASYWIDIR . '/stuff/methods/class_app.php');
include(EASYWIDIR . '/stuff/methods/class_masterserver.php');
include(EASYWIDIR . '/stuff/methods/class_ts3.php');
include(EASYWIDIR . '/stuff/methods/queries_updates.php');
@ -77,7 +78,7 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
$query = $sql->prepare("SELECT t.`shorten` FROM `servertypes` t LEFT JOIN `rservermasterg` r ON t.`id`=r.`servertypeid` WHERE r.`id` IS NOT NULL AND t.`gameq`='minecraft' GROUP BY t.`shorten` ORDER BY t.`shorten`");
$query2 = $sql->prepare("UPDATE `servertypes` SET `steamVersion`=?,`downloadPath`=? WHERE `shorten`=?");
$query->execute();
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
echo 'Retrieving Version for ' . $row['shorten'] . "\r\n";
$reply = ($row['shorten'] == 'bukkit') ? getCraftBukkitVersion () : getMinecraftVersion();
@ -96,7 +97,7 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
$query2 = $sql->prepare("UPDATE `servertypes` SET `steamVersion`=? WHERE `appID`=?");
$query->execute();
$steamVersion = array();
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
if (!in_array($row['appID'], array(null,'', false))) {
@ -120,9 +121,10 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
$webhostdomain = webhostdomain(0);
$query = $sql->prepare("SELECT `timezone`,`voice_autobackup`,`voice_autobackup_intervall`,`voice_maxbackup`,`down_checks`,`resellerid` FROM `settings`");
$query->execute();
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$resellerstimezone = $row['timezone'];
$resellerid = $row['resellerid'];
$resellerLockupID = $row['resellerid'];
$voice_autobackup = $row['voice_autobackup'];
$voice_autobackup_intervall = $row['voice_autobackup_intervall'];
$voice_maxbackup = $row['voice_maxbackup'];
@ -372,7 +374,6 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
}
}
if (count($cmds) > 0) {
if (ssh2_execute('vm', $ts3masterid, $cmds)) {
@ -396,179 +397,77 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
}
$currenttime = strtolower(date('D', strtotime("$resellerstimezone hour"))) . '_' . date('G',strtotime("$resellerstimezone hour"));
$query = $sql->prepare("SELECT `id` FROM `rserverdata` WHERE `active`='Y'");
$query2 = $sql->prepare("SELECT *,AES_DECRYPT(`ftppassword`,?) AS `decryptedftppass`,AES_DECRYPT(`ppassword`,?) AS `decryptedppassword` FROM `gsswitch` WHERE `rootID`=? AND `resellerid`=? AND `active`='Y' AND `lendserver`='N' AND `stopped`='N' ORDER BY `userid`,`serverid`");
$query2 = $sql->prepare("SELECT g.`id`,CONCAT(g.`serverip`,':',g.`port`) AS `server`,g.`protected`,AES_DECRYPT(`ftpbackup`,?) AS `backup` FROM `gsswitch` AS g INNER JOIN `userdata` AS u ON u.`id`=g.`userid` WHERE g.`rootID`=? AND g.`active`='Y' AND g.`lendserver`='N' AND g.`stopped`='N' AND u.`active`='Y'");
$query3 = $sql->prepare("SELECT r.*,s.`id` AS `server_id` FROM `gserver_restarts` AS r INNER JOIN `servertypes` AS t ON t.`shorten`=r.`gsswitch` AND t.`resellerid`=r.`resellerid` INNER JOIN `serverlist` AS s ON s.`servertype`=t.`id` AND s.`switchID`=r.`switchID` WHERE r.`switchID`=? AND r.`restarttime`=? LIMIT 1");
$query4 = $sql->prepare("UPDATE `gsswitch` SET `serverid`=? WHERE `id`=? AND `resellerid`=? LIMIT 1");
$query5 = $sql->prepare("UPDATE `serverlist` SET `anticheat`=?,`map`=?,`mapGroup`=?,`servertemplate`=? WHERE `id`=? AND `resellerid`=? LIMIT 1");
$query6 = $sql->prepare("UPDATE `gsswitch` SET `ppassword`=AES_ENCRYPT(?,?) WHERE `id`=? LIMIT 1");
$query = $sql->prepare("SELECT `id`,`resellerid` FROM `rserverdata` WHERE `active`='Y'");
$query->execute();
foreach($query->fetchAll(PDO::FETCH_ASSOC) as $row1) {
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
$cmds = array();
$rootID = $row1['id'];
$resellerLockupID = $row['resellerid'];
$query2->execute(array($aeskey, $aeskey, $rootID, $resellerid));
foreach ($query2->fetchAll(PDO::FETCH_ASSOC) as $row2) {
$appServer = new AppServer($row['id']);
unset($restart);
$query2->execute(array($aeskey, $row['id']));
while($row2 = $query2->fetch(PDO::FETCH_ASSOC)) {
$serverip = $row2['serverip'];
$gsport = $row2['port'];
$gsswitchID = $row2['id'];
$useridID = $row2['userid'];
$newlayout = $row2['newlayout'];
$gsfolder = $serverip . '_' . $gsport;
$ftppass = $row2['decryptedftppass'];
$decryptedftppass = $row2['decryptedppassword'];
$protected_old = $row2['protected'];
$query3->execute(array($row2['id'], $currenttime));
while($row3 = $query3->fetch(PDO::FETCH_ASSOC)) {
if ($row2['serverid'] == null) {
$query3 = $sql->prepare("SELECT `id` FROM `serverlist` WHERE `switchID`=? LIMIT 1");
$query3->execute(array($gsswitchID));
$runID_old = $query3->fetchColumn();
$query3 = $sql->prepare("UPDATE `gsswitch` SET `serverid`=? WHERE `id`=? LIMIT 1");
$query3->execute(array($runID_old, $gsswitchID));
} else {
$runID_old = $row2['serverid'];
$query4->execute(array($row3['server_id'], $row3['switchID'], $resellerLockupID));
$query5->execute(array($row3['anticheat'], $row3['map'], $row3['mapGroup'], $row3['template'], $row3['server_id'], $resellerLockupID));
$appServer->getAppServerDetails($row3['switchID']);
if ($row3['restart'] == 'N' and $row3['worldsafe'] == 'Y') {
$appServer->mcWorldSave();
echo 'MC worldsave: ' . $row2['server'] . "\r\n";
}
$server = $row2['serverip'] . ':' . $row2['port'];
if ($row3['restart'] == 'N' and $row3['upload'] == 'Y') {
$query3 = $sql->prepare("SELECT * FROM `gserver_restarts` WHERE `switchID`=? AND `restarttime`=? LIMIT 1");
$query3->execute(array($gsswitchID, $currenttime));
foreach ($query3->fetchAll(PDO::FETCH_ASSOC) as $row3) {
$template = $row3['template'];
$anticheat = $row3['anticheat'];
$shorten = $row3['gsswitch'];
$map = $row3['map'];
$mapGroup = $row3['mapGroup'];
$protected = $row3['protected'];
$restart = $row3['restart'];
$backup = $row3['backup'];
$worldsafe = $row3['worldsafe'];
$upload = $row3['upload'];
$appServer->demoUpload();
echo 'Demo upload for: ' . $row2['server'] . "\r\n";
}
$query3 = $sql->prepare("SELECT `active`,`cname` FROM `userdata` WHERE `id`=? AND `resellerid`=? LIMIT 1");
$query3->execute(array($row2['userid'], $resellerid));
foreach ($query3->fetchAll(PDO::FETCH_ASSOC) as $row3) {
$user_active = $row3['active'];
$SSH2customer = $row3['cname'];
if ($row3['restart'] == 'Y') {
if ($row3['protected'] == 'Y' and $row2['protected'] == 'N') {
$appServer->stopAppHard();
$query6->execute(array(passwordgenerate(20), $aeskey, $row3['switchID']));
$appServer->getAppServerDetails($row3['switchID']);
$appServer->removeApp($row3['template']);
$appServer->addApp($row3['template']);
}
if ($newlayout == 'Y') {
$SSH2customer .= '-' . $gsswitchID;
$appServer->startApp();
echo 'Restarting server: ' . $row2['server'] . "\r\n";
}
if (isset($restart) and $user_active == 'Y') {
if ($row3['backup'] == 'Y') {
$query3 = $sql->prepare("SELECT s.`id`,s.`upload`,s.`map`,s.`servertemplate`,s.`mapGroup`,t.`gameq`,t.`gamebinary` FROM `serverlist` s LEFT JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE t.`shorten`=? AND s.`switchID`=? LIMIT 1");
$query3->execute(array($shorten, $gsswitchID));
foreach ($query3->fetchAll(PDO::FETCH_ASSOC) as $row3) {
$runID = $row3['id'];
$appServer->backupCreate($row2['backup']);
$query3 = $sql->prepare("UPDATE `gsswitch` SET `serverid`=? WHERE `id`=? AND `resellerid`=? LIMIT 1");
$query3->execute(array($runID, $gsswitchID, $resellerid));
$query3 = $sql->prepare("UPDATE `serverlist` SET `anticheat`=?,`map`=?,`mapGroup`=?,`servertemplate`=? WHERE `id`=? AND `resellerid`=? LIMIT 1");
$query3->execute(array($anticheat, $map, $mapGroup, $template, $runID, $resellerid));
$shortens = '';
if ($restart == 'Y') {
unset($newProtected);
if ($protected== 'Y' and $protected_old== 'N') {
$tmp = gsrestart($gsswitchID,'so', $aeskey, $resellerid);
if (is_array($tmp)) {
foreach($tmp as $t) {
$cmds[] = $t;
}
}
echo "Stopping unprotected server: $server\r\n";
$gamestring = '1_' . $shorten;
$randompass = passwordgenerate(20);
$query3 = $sql->prepare("UPDATE `gsswitch` SET `ppassword`=AES_ENCRYPT(?,?) WHERE `id`=? LIMIT 1");
$query3->execute(array($randompass, $aeskey, $gsswitchID));
$cmds[] = './control.sh mod '.$SSH2customer . ' ' . $ftppass . ' ' . $randompass;
$SSH2customer .= '-p';
$cmds[]="sudo -u ${SSH2customer} ./control.sh reinstserver ${SSH2customer} ${gamestring} ${gsfolder} protected";
echo 'Reinstall protected server: '.$server."\r\n";
$newProtected = true;
}
$query3 = $sql->prepare("UPDATE `gsswitch` SET `serverid`=?,`stopped`='N',`protected`=? WHERE `id`=? AND `resellerid`=? LIMIT 1");
$query3->execute(array($runID, $protected, $gsswitchID, $resellerid));
if (!isset($newProtected)) {
echo 'Restarting server: '.$server."\r\n";
$tmp = gsrestart($gsswitchID,'re', $aeskey, $resellerid);
if (is_array($tmp)) {
foreach($tmp as $t) {
$cmds[] = $t;
echo 'Backup server: ' . $row2['server'] . "\r\n";
}
}
}
} else if ($restart == 'N' and $row3['gameq'] == 'minecraft' and $worldsafe == 'Y') {
$cmds[]="sudo -u ${SSH2customer} ./control.sh mc_ws $gsfolder";
echo "Minecraft worlsafe: $server\r\n";
} else if ($restart == 'N' and $row3['gamebinary'] == 'srcds_run' and ($uploadtype == 2 or $uploadtype == '3') and $upload== 'Y') {
$tmp = gsrestart($gsswitchID,'du', $aeskey, $resellerid);
if (is_array($tmp)) {
foreach($tmp as $t) {
$cmds[] = $t;
}
}
}
if ($backup == 'Y') {
$shortens = array();
$query3 = $sql->prepare("SELECT AES_DECRYPT(`ftpbackup`,?) AS `backup` FROM `userdata` WHERE `id`=? LIMIT 1");
$query3->execute(array($aeskey, $useridID));
$ftpbackup = $query3->fetchColumn();
$query3 = $sql->prepare("SELECT DISTINCT(t.`shorten`) FROM `serverlist` s LEFT JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE s.`switchID`=?");
$query3->execute(array($gsswitchID));
foreach ($query3->fetchAll(PDO::FETCH_ASSOC) as $row3) {
$shortens[] = $row3['shorten'];
}
$cmds[]="sudo -u ${SSH2customer} ./control.sh backup ${gsfolder} \"".implode(' ', $shortens)."\" \"${webhostdomain}\" \"${ftpbackup}\"";
echo "Backup for $server\r\n";
}
}
} else {
echo "$currenttime Not the restart time for $server\r\n";
}
}
if (count($cmds)>0) {
if (ssh2_execute('gs', $rootID, $cmds)) {
echo "Commands executed for server $server\r\n";
} else {
echo "Executing commands for server $server failed \r\n";
}
$appServer->execute();
if (isset($dbConnect['debug']) and $dbConnect['debug'] == 1) {
print_r($cmds);
}
print implode("\r\n", $appServer->debug()) . "\r\n";
}
}
}

View File

@ -72,6 +72,7 @@ include(EASYWIDIR . '/stuff/methods/class_validator.php');
include(EASYWIDIR . '/stuff/settings.php');
include(EASYWIDIR . '/stuff/methods/functions_gs.php');
include(EASYWIDIR . '/stuff/methods/functions_ssh_exec.php');
include(EASYWIDIR . '/stuff/methods/class_app.php');
include(EASYWIDIR . '/stuff/methods/class_ts3.php');
include(EASYWIDIR . '/third_party/gameq/GameQ.php');
include(EASYWIDIR . '/stuff/methods/class_mysql.php');
@ -149,6 +150,8 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
# Game Server
if ($checkTypeOfServer == 'all' or $checkTypeOfServer == 'gs') {
$startStopList = array();
// Lend server stopping.
// We want only one socket per root server. Collect the to be stopped lendservers in an array and sort by root ID
$rtmp = array();
@ -157,7 +160,7 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
$query2 = $sql->prepare("SELECT g.`rootID`,g.`id`,g.`userid`,g.`serverip`,g.`port` 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");
$query->execute();
foreach ($query->fetchall(PDO::FETCH_ASSOC) as $row) {
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$id = $row['id'];
$lendtime = $row['lendtime'];
$serverid = $row['serverid'];
@ -168,23 +171,15 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
$query3->execute(array($id, $resellerid));
$query2->execute(array($row['serverid']));
foreach ($query2->fetchAll(PDO::FETCH_ASSOC) as $row2) {
while ($row2 = $query2->fetch(PDO::FETCH_ASSOC)) {
$loguserid = $row2['userid'];
$reseller_id = $row['resellerid'];
$loguseraction = "%stop% %gserver% {$row2['serverip']}:{$row2['port']} (Lend stop)";
$insertlog->execute();
$tmp = gsrestart($row2['id'], 'so', $aeskey, $resellerid);
if (is_array($tmp)) {
foreach($tmp as $t) {
$rtmp[$row2['rootID']][] = $t;
$startStopList[$row['resellerid']][$row2['rootID']]['stop'][] = $id;
}
}
}
print "Time is up, stopping lendserver: $id\r\n";
@ -193,14 +188,6 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
}
}
// Send stop commands to rootserver
foreach ($rtmp as $k => $v) {
if (count($v) > 0) {
ssh2_execute('gs', $k, $v);
}
}
// Define basic variables for GS status checks
$other = array();
$i = 1;
@ -208,7 +195,6 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
$rootID = 0;
$serverBatchArray = array();
$allServersArray = array();
$shellCmds = array();
$query2 = $sql->prepare("SELECT g.`id`,g.`serverid`,g.`serverip`,g.`port`,g.`port2`,g.`port3`,g.`port4`,g.`port5`,t.`gameq`,t.`shorten`,t.`useQueryPort` FROM `gsswitch` g INNER JOIN `serverlist` s ON g.`serverid`=s.`id` INNER JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE g.`rootID`=? AND g.`stopped`='N' AND g.`active`='Y'");
$query = $sql->prepare("SELECT DISTINCT(`rootID`) AS `root_id` FROM `gsswitch` WHERE `active`='Y'");
@ -264,11 +250,8 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
$rootID = $row['root_id'];
}
$allServersArray[] = $serverBatchArray;
print "Checking $totalCount server(s) with GameQ query\r\n";
foreach ($allServersArray as $servers) {
@ -292,10 +275,9 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
$shutdownemptytime = 0;
$notified = 0;
$query = $sql->prepare("SELECT s.`id` AS `serverID`,t.`description`,t.`gamebinary`,g.* FROM `gsswitch` g INNER JOIN `serverlist` s ON g.`serverid`=s.`id` INNER JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE g.`id`=? LIMIT 1");
$query2 = $sql->prepare("SELECT `id`,`started` FROM `lendedserver` WHERE `serverid`=? LIMIT 1");
$query = $sql->prepare("SELECT s.`id` AS `serverID`,t.`description`,t.`gamebinary`,l.`id` AS `lend_id`,l.`started` AS `lend_started`,g.* FROM `gsswitch` g INNER JOIN `serverlist` s ON g.`serverid`=s.`id` INNER JOIN `servertypes` t ON s.`servertype`=t.`id` LEFT JOIN `lendedserver` AS l ON l.`serverid`=s.`id` WHERE g.`id`=? LIMIT 1");
$query->execute(array($switchID));
foreach ($query->fetchall(PDO::FETCH_ASSOC) as $row) {
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$serverip = $row['serverip'];
$autoRestart = $row['autoRestart'];
@ -317,14 +299,9 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
}
if ($lendserver == 'Y' and $lendActive == 'Y') {
$lid = $row['lend_id'];
$shutdownemptytime = $resellersettings[$resellerid]['shutdownemptytime'];
$query2->execute(array($row['serverID']));
foreach ($query2->fetchall(PDO::FETCH_ASSOC) as $row2) {
$lid = $row2['id'];
$elapsed = round((strtotime('now') - strtotime($row2['started'])) / 60);
}
$elapsed = round((strtotime('now') - strtotime($row['lend_started'])) / 60);
}
}
@ -342,7 +319,6 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
$password = 'Y';
}
$returnCmd = array();
$lendStop = array();
// Check lendserver specific settings
@ -470,12 +446,7 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
$loguseraction .= (count($lendStop) > 0 && count($rulebreak) == 0) ? " " . implode(', ', $lendStop) : "";
$insertlog->execute();
$tmp = gsrestart($switchID, 'so', $aeskey, $resellerid);
if (is_array($tmp)) {
foreach($tmp as $t) {
$returnCmd[] = $t;
}
}
$startStopList[$resellerid][$rootID]['stop'][] = $switchID;
$query = $sql->prepare("DELETE FROM `lendedserver` WHERE `serverid`=? AND `resellerid`=? AND `servertype`='g' LIMIT 1");
$query->execute(array($switchID, $resellerid));
@ -511,12 +482,7 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
$loguseraction = "%start% %gserver% {$address} (Found offline since {$notified} checks)";
$insertlog->execute();
$tmp = gsrestart($switchID, 're', $aeskey, $resellerid);
if (is_array($tmp)) {
foreach($tmp as $t) {
$returnCmd[] = $t;
}
}
$startStopList[$resellerid][$rootID]['start'][] = $switchID;
} else {
print "Not Restarting: $address\r\n";
@ -538,21 +504,37 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
$query = $sql->prepare("UPDATE `gsswitch` SET `queryName`=?,`queryNumplayers`=?,`queryMaxplayers`=?,`queryMap`=?,`queryPassword`=?,`queryUpdatetime`=?,`notified`=? WHERE `id`=? LIMIT 1");
$query->execute(array($name, $numplayers, $maxplayers, $map, $password, $logdate, $notified, $switchID));
foreach($returnCmd as $t) {
$shellCmds[$rootID][] = $t;
}
}
}
unset($gq);
if (isset($dbConnect['debug']) and $dbConnect['debug'] == 1) {
print_r($shellCmds);
foreach ($startStopList as $resellerLockupID => $rootServer) {
foreach ($rootServer as $rootID => $actionList) {
$appServer = new AppServer($rootID);
foreach ($actionList as $action => $switchIDs) {
foreach ($switchIDs as $switchID) {
$appServer->getAppServerDetails($switchID);
if ($action == 'start') {
$appServer->startApp();
} else {
$appServer->stopApp();
}
}
}
foreach($shellCmds as $k => $v) {
ssh2_execute('gs', $k, $v);
$appServer->execute();
if (isset($dbConnect['debug']) and $dbConnect['debug'] == 1) {
print implode("\r\n", $appServer->debug()) . "\r\n";
}
}
}
}

View File

@ -44,6 +44,7 @@ include(EASYWIDIR . '/stuff/keyphrasefile.php');
include(EASYWIDIR . '/stuff/methods/functions_gs.php');
include(EASYWIDIR . '/stuff/methods/functions_ssh_exec.php');
include(EASYWIDIR . '/stuff/methods/class_ts3.php');
include(EASYWIDIR . '/stuff/methods/class_app.php');
$sprache = getlanguagefile('lendserver', $user_language, $reseller_id);
$gssprache = getlanguagefile('gserver', $user_language, $reseller_id);
@ -140,7 +141,7 @@ if ($ui->w('action', 4, 'post') and !token(true)) {
} else if ($pa['lendserver']) {
if ($ui->id('id',19, 'post')) {
if ($ui->id('id', 19, 'post')) {
$query = $sql->prepare("SELECT `serverid`,`servertype` FROM `lendedserver` WHERE `id`=? AND `resellerid`=? LIMIT 1");
$query->execute(array($ui->id('id',19, 'post'), $reseller_id));
@ -153,9 +154,11 @@ if ($ui->w('action', 4, 'post') and !token(true)) {
$query = $sql->prepare("SELECT s.`switchID`,g.`rootID` FROM `serverlist` s INNER JOIN `gsswitch` g ON s.`switchID`=g.`id` WHERE s.`id`=? AND s.`resellerid`=? LIMIT 1");
$query->execute(array($id, $reseller_id));
foreach($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
$cmds = gsrestart($row['switchID'], 'so', $aeskey, $reseller_id);
ssh2_execute('gs', $row['rootID'], $cmds);
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$appServer = new AppServer($row['rootID']);
$appServer->getAppServerDetails($row['switchID']);
$appServer->stopApp();
$appServer->execute();
}
} else if (isset($servertype) and $servertype == 'v') {
@ -211,7 +214,7 @@ if ($ui->w('action', 4, 'post') and !token(true)) {
$deleteQuery = $sql->prepare("DELETE FROM `lendedserver` WHERE `id`=? LIMIT 1");
$query = $sql->prepare("SELECT `id`,`queryMap`,`queryNumplayers`,`queryName`,`serverip`,`port`,`slots`,`serverid` FROM `gsswitch` WHERE `lendserver`='Y' AND `active`='Y' AND `resellerid`=0");
$query = $sql->prepare("SELECT `id`,`queryMap`,`queryNumplayers`,`queryName`,`serverip`,`port`,`slots`,`serverid`,`rootID` FROM `gsswitch` WHERE `lendserver`='Y' AND `active`='Y' AND `resellerid`=0");
$query2 = $sql->prepare("SELECT s.`id`,t.`shorten`,t.`description` FROM `serverlist` s INNER JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE s.`switchID`=? AND s.`resellerid`=0");
$query3 = $sql->prepare("SELECT `id`,`slots`,`started`,`lendtime`,`password`,`rcon`,CURRENT_TIMESTAMP AS `now` FROM `lendedserver` WHERE `serverid`=? AND `servertype`='g' LIMIT 1");
@ -248,8 +251,10 @@ if ($ui->w('action', 4, 'post') and !token(true)) {
if ($time == 0 or ($shutDownEmpty == 'Y' and ($row3['lendtime'] - $timeleft) > $shutDownEmptyTime and $row['queryNumplayers'] < 1)) {
$cmds = gsrestart($row['id'], 'so', $aeskey, $reseller_id);
ssh2_execute('gs', $row['id'], $cmds);
$appServer = new AppServer($row['rootID']);
$appServer->getAppServerDetails($row['id']);
$appServer->stopApp();
$appServer->execute();
$deleteQuery->execute(array($row3['id']));

View File

@ -542,7 +542,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";
@ -575,7 +575,7 @@ class AppServer {
if ($standalone and isset($scriptName)) {
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
} else {
$script = '';
}
@ -640,7 +640,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) {
@ -674,7 +674,7 @@ class AppServer {
if ($standalone === true) {
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
} else {
$script = '';
@ -701,7 +701,7 @@ class AppServer {
}
public function mcWorldSave () {
if ($this->appServerDetails and $this->appServerDetails['template']['gameq'] == 'minecraft') {
if ($this->appServerDetails and $this->getGameType() == 'mc') {
if ($this->appMasterServerDetails['os'] == 'L') {
} else if ($this->appMasterServerDetails['os'] == 'W') {
}
@ -717,7 +717,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 = '';
@ -786,7 +786,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";
@ -1213,7 +1213,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);
@ -1317,7 +1317,7 @@ class AppServer {
if ($standalone == true) {
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
} else {
$script = '';
}
@ -1361,7 +1361,7 @@ class AppServer {
} else if (in_array($this->appServerDetails['app']['upload'], array(4, 5))) {
$script .= 'DEMOPATH=`find -mindepth 1 -maxdepth 3 -type d -name "' . $this->appServerDetails['template']['modfolder'] . '" | head -n1`' . "\n";
$script .= 'SCREENLOG="`find /home/user12882-317/server/37.187.20.198_27025/css/ -name "screenlog.0" | head -n1`"' . "\n";
$script .= 'SCREENLOG="`find ' . $this->appServerDetails['absolutePath'] . ' -name "screenlog.0" | head -n1`"' . "\n";
$script .= 'if [ "$SCREENLOG" != "" ]; then' . "\n";
$script .= 'cd `dirname $SCREENLOG`' . "\n";
$script .= 'tail -f screenlog.0 | while read LINE; do' . "\n";
@ -1391,7 +1391,7 @@ class AppServer {
$screenScriptName = $this->removeSlashes('/home/' . $this->appMasterServerDetails['ssh2User'] . '/temp/demo-start-' . $this->appServerDetails['userNameExecute'] . '-' . $this->appServerDetails['serverIP'] . '-' . $this->appServerDetails['port'] . '.sh');
$script = $this->shellScriptHeader;
$script .= '#rm ' . $screenScriptName . "\n";
$script .= 'rm ' . $screenScriptName . "\n";
// Kill any screen that is running with the same name
$script .= 'ps fx | grep \'SCREEN\' | grep \'demo_' . $this->appServerDetails['serverIP'] . '_' . $this->appServerDetails['port'] . '\' | grep -v grep | awk \'{print $1}\' | while read PID; do' . "\n";
@ -1496,7 +1496,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) {
@ -1621,7 +1621,7 @@ class AppServer {
$scriptName = $this->removeSlashes('/home/' . $this->appMasterServerDetails['ssh2User'] . '/temp/addons-del-' . $this->appServerDetails['userNameExecute'] . '-' . $this->appServerDetails['serverIP'] . '-' . $this->appServerDetails['port'] . '.sh');
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
$script .= 'USER=`id -un`' . "\n";
foreach ($ids as $id) {
@ -1679,7 +1679,7 @@ class AppServer {
$scriptName = $this->removeSlashes('/home/' . $this->appMasterServerDetails['ssh2User'] . '/temp/migrate-' . $this->appServerDetails['userName'] . '-' . $this->appServerDetails['serverIP'] . '-' . $this->appServerDetails['port'] . '.sh');
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
$script .= 'if [ -d "' . $serverDir . '" ]; then ${IONICE}rm -rf "' . $serverDir . '"; fi' . "\n";
$script .= $this->linuxAddApp(array($targetTemplate), false);
@ -1714,7 +1714,6 @@ class AppServer {
}
}
//TODO: Fast DL Sync
private function linuxFastDLSync ($fdlConnectString) {
$gameType = $this->getGameType();
@ -1726,7 +1725,7 @@ class AppServer {
$scriptName = $this->removeSlashes('/home/' . $this->appMasterServerDetails['ssh2User'] . '/temp/fdl-sync-' . $this->appServerDetails['userName'] . '-' . $this->appServerDetails['serverIP'] . '-' . $this->appServerDetails['port'] . '.sh');
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
$script .= 'USERNAME=`id -un`' . "\n";
$script .= 'if [ -f "' . $fdlFileList . '" ]; then' . "\n";
@ -1853,7 +1852,7 @@ class AppServer {
$scriptName = $this->removeSlashes('/home/' . $this->appMasterServerDetails['ssh2User'] . '/temp/backup-create-' . $this->appServerDetails['userName'] . '-' . $this->appServerDetails['serverIP'] . '-' . $this->appServerDetails['port'] . '.sh');
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
$script .= 'if [ ! -d "' . $backupDir . '" ]; then mkdir -p "' . $backupDir . '"; fi' . "\n";
$script .= 'find "' . $backupDir . '" -maxdepth 1 -type f -name "*.tar.bz2" -delete' . "\n";
@ -1890,7 +1889,7 @@ class AppServer {
$scriptName = $this->removeSlashes('/home/' . $this->appMasterServerDetails['ssh2User'] . '/temp/backup-deploy-' . $this->appServerDetails['userName'] . '-' . $this->appServerDetails['serverIP'] . '-' . $this->appServerDetails['port'] . '.sh');
$script = $this->shellScriptHeader;
$script .= '#rm ' . $scriptName . "\n";
$script .= 'rm ' . $scriptName . "\n";
if (strlen($ftpDownloadString) > 0) {
$script .= 'if [ ! -d "' . $backupDir . '" ]; then mkdir -p "' . $backupDir . '"; fi' . "\n";

View File

@ -42,535 +42,7 @@ if (!defined('EASYWIDIR')) {
define('EASYWIDIR', '');
}
if (!function_exists('gsrestart')) {
function gsrestart($switchID, $action, $aeskey, $reseller_id) {
if (!class_exists('EasyWiFTP')) {
include(EASYWIDIR . '/stuff/methods/class_ftp.php');
}
global $sql;
$tempCmds = array();
$stopped = 'Y';
$query = $sql->prepare("SELECT g.*,g.`id` AS `switchID`,g.`pallowed` AS `gsPallowed`,g.`protected` AS `gsProtected`,AES_DECRYPT(g.`ppassword`,:aeskey) AS `decryptedppass`,AES_DECRYPT(g.`ftppassword`,:aeskey) AS `decryptedftppass`,s.*,s.`cmd` AS `localCmd`,s.`workShop` AS `sWorkShop`,AES_DECRYPT(s.`uploaddir`,:aeskey) AS `decypteduploaddir`,AES_DECRYPT(s.`webapiAuthkey`,:aeskey) AS `dwebapiAuthkey`,t.`configedit`,t.`modcmds`,t.`modfolder`,t.`gamebinary`,t.`binarydir`,t.`shorten`,t.`appID`,t.`cmd` AS `globalCmd`,t.`workShop` AS `tWorkShop`,t.`protected` AS `tProtected`,u.`cname` FROM `gsswitch` g INNER JOIN `serverlist` s ON g.`serverid`=s.`id` INNER JOIN `servertypes` t ON s.`servertype`=t.`id` INNER JOIN `userdata` u ON u.`id`=g.`userid` WHERE g.`id`=:serverid AND g.`resellerid`=:reseller_id AND t.`resellerid`=:reseller_id LIMIT 1");
$query->execute(array(':aeskey' => $aeskey, ':serverid' => $switchID, ':reseller_id' => $reseller_id));
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
$serverid = $row['serverid'];
$anticheat = $row['anticheat'];
$servertemplate = $row['servertemplate'];
$upload = $row['upload'];
$uploaddir = $row['decypteduploaddir'];
$shorten = $row['shorten'];
$tvenable = $row['tvenable'];
$gsip = $row['serverip'];
$port = $row['port'];
$port2 = $row['port2'];
$port3 = $row['port3'];
$port4 = $row['port4'];
$port5 = $row['port5'];
$minram = ($row['minram'] > 0) ? $row['minram'] : 512;
$maxram = ($row['maxram'] > 0) ? $row['maxram'] : 1024;
$binarydir = $row['binarydir'];
$eacallowed = $row['eacallowed'];
$fps = $row['fps'];
$slots = $row['slots'];
$map = $row['map'];
$mapGroup = $row['mapGroup'];
$tic = $row['tic'];
$pallowed = $row['gsPallowed'];
$protected = ($row['gsPallowed'] == 'N' or $row['tProtected'] == 'N') ? 'N' : $row['gsProtected'];
$modfolder = $row['modfolder'];
$ftppass = $row['decryptedftppass'];
$decryptedftppass = $row['decryptedppass'];
$cmd = ($row['owncmd'] == 'Y') ? $row['localCmd'] : $row['globalCmd'];
$modcmd = $row['modcmd'];
$user_id = $row['userid'];
$customer = $row['cname'];
$workShop = ($row['sWorkShop'] == 'Y' AND $row['tWorkShop'] == 'Y') ? 'Y' : 'N';
if ($row['newlayout'] == 'Y') {
$customer .= '-' . $row['switchID'];
}
$rdata = serverdata('root', $row['rootID'], $aeskey);
$sship = $rdata['ip'];
$ftpport = $rdata['ftpport'];
$rootOS = $rdata['os'];
$iniVars = parse_ini_string($rdata['install_paths'], true);
$homeDir = ($iniVars and isset($iniVars[$row['homeLabel']]['path'])) ? $iniVars[$row['homeLabel']]['path'] : '/home';
//install_paths
if ($rootOS == 'W') {
if (substr($cmd, 0, 2) == './') {
$cmd = substr($cmd, 3);
}
$gamebinary = $row['gamebinaryWin'];
} else {
$gamebinary = $row['gamebinary'];
}
$cores = ($row['taskset'] == 'Y') ? $row['cores'] : 'none';
$maxcores = count(preg_split("/\,/", $cores, -1, PREG_SPLIT_NO_EMPTY));
if ($maxcores == 0) {
$maxcores = 1;
}
$folder = ($servertemplate > 1 and $protected == 'N') ? $shorten . '-' . $servertemplate : $shorten;
if ($protected == 'Y') {
$pserver = '';
$absolutepath = $homeDir . '/' . $customer . '/pserver/' . $gsip . '_' . $port . '/' . $folder;
} else {
$pserver = 'server/';
$absolutepath = $homeDir . '/' . $customer . '/server/' . $gsip . '_' . $port . '/' . $folder;
}
$bindir = $absolutepath. '/' . $binarydir;
$cvarprotect = array();
if ($gamebinary == 'hlds_run' and $tvenable == 'Y') {
$slots++;
}
$modsCmds = array();
$cvars = array('%binary%', '%tickrate%', '%tic%', '%ip%', '%port%', '%tvport%', '%port2%', '%port3%', '%port4%', '%port5%', '%slots%', '%map%', '%mapgroup%', '%fps%', '%minram%', '%maxram%', '%maxcores%', '%folder%', '%user%', '%absolutepath%');
foreach (explode("\r\n", $row['configedit']) as $line) {
if (preg_match('/^(\[[\w\/\.\-\_]{1,}\]|\[[\w\/\.\-\_]{1,}\] (xml|ini|cfg|lua|json))$/', $line)) {
$ex = preg_split("/\s+/", $line, -1,PREG_SPLIT_NO_EMPTY);
$cvartype = (isset($ex[1])) ? $ex[1] : 'cfg';
$config = substr($ex[0], 1, strlen($ex[0]) - 2);
$cvarprotect[$config]['type'] = $cvartype;
} else if (isset($config)) {
unset($splitline);
if ($cvarprotect[$config]['type'] == 'cfg') {
$splitline = preg_split("/\s+/", $line, -1, PREG_SPLIT_NO_EMPTY);
} else if ($cvarprotect[$config]['type'] == 'ini') {
$splitline = preg_split("/\=/", $line, -1, PREG_SPLIT_NO_EMPTY);
} else if ($cvarprotect[$config]['type'] == 'lua') {
$splitline = preg_split("/\=/", $line, -1, PREG_SPLIT_NO_EMPTY);
} else if ($cvarprotect[$config]['type'] == 'json') {
$splitline = preg_split("/:/", $line, -1, PREG_SPLIT_NO_EMPTY);
} else if ($cvarprotect[$config]['type'] == 'xml') {
$ex1 = explode('>', $line);
if (isset($ex1[1])) {
$c = str_replace('<', '', $ex1[0]);
list($v) = explode('<', $ex1[1]);
$splitline= array($c, $v);
}
}
if (isset($splitline[1])) {
$replace = array($gamebinary, $tic, $tic, $gsip, $port, $port2, $port2, $port3, $port4, $port5, $slots, $map, $mapGroup, $fps, $minram, $maxram, $maxcores, $folder, $customer, $absolutepath);
$cvar = str_replace($cvars, $replace, $splitline[1]);
foreach (customColumns('G', $switchID) as $cu) {
$cvar = str_replace("%${cu['name']}%", $cu['value'], $cvar);
}
$cvarprotect[$config]['cvars'][$splitline[0]] = $cvar;
}
}
}
foreach (explode("\r\n", $row['modcmds']) as $line) {
if (preg_match('/^(\[[\w\/\.\-\_\= ]{1,}\])$/', $line)) {
$name = trim($line,'[]');
$ex = preg_split("/\=/", $name, -1,PREG_SPLIT_NO_EMPTY);
$name = trim($ex[0]);
if (isset($ex[1]) and trim($ex[1]) == 'default' and ($modcmd === null or $modcmd == '')) {
$modcmd = trim($ex[0]);
}
if (!isset($modsCmds[$name])) {
$modsCmds[$name] = array();
}
} else if (isset($name) and isset ($modsCmds[$name]) and $line!='') {
$modsCmds[$name][] = $line;
}
}
// https://github.com/easy-wi/developer/issues/205
// In case Workshop is on we need to remove workgroup
if ($workShop == 'Y') {
$cmd = str_replace(array('%mapgroup%', ' +mapgroup'), '', $cmd);
}
if ($gamebinary == 'srcds_run' and $tvenable == 'N') {
$cmd .= ' -nohltv -tvdisable';
}
if (($protected == 'N' and ($gamebinary == 'hlds_run' or $gamebinary == 'srcds_run') and ($anticheat == 2 or $anticheat == 3 or $anticheat == 4 or $anticheat == 5 or $anticheat == 6)) or (($protected == 'Y' and ($anticheat == 3 or $anticheat == 4 or $anticheat == 5 or $anticheat == 6)) and ($gamebinary == 'srcds_run' or $gamebinary == 'hlds_run') and $eacallowed == 'Y')) {
$cmd .= ' -insecure';
}
$installedaddons = array();
$installedMaps = array();
$rmarray = array();
$query2 = ($protected == 'Y') ? $sql->prepare("SELECT `addonid` FROM `addons_installed` WHERE `userid`=? AND `serverid`=? AND `paddon`='Y' AND `resellerid`=?") : $sql->prepare("SELECT `addonid` FROM `addons_installed` WHERE `userid`=? AND `serverid`=? AND `paddon`='N' AND `resellerid`=?");
$query3 = $sql->prepare("SELECT `cmd`,`rmcmd`,`addon`,`type` FROM `addons` WHERE `id`=? AND `resellerid`=? AND `active`='Y' LIMIT 1");
$query2->execute(array($user_id, $serverid, $reseller_id));
foreach ($query2->fetchAll(PDO::FETCH_ASSOC) as $row2) {
$query3->execute(array($row2['addonid'], $reseller_id));
foreach ($query3->fetchAll(PDO::FETCH_ASSOC) as $row3) {
if ($row3['type'] == 'tool') {
$installedaddons[] = $row3['addon'];
} else {
$installedMaps[] = $row3['addon'];
}
if ($row3['cmd'] != null) {
$cmd .= (substr($row3['cmd'], 0, 12) == '[no_padding]') ? trim(substr($row3['cmd'], 12)) : ' ' . $row3['cmd'];
}
if ($row3['rmcmd'] != null) {
foreach (preg_split("/\r\n/", $row3['rmcmd'], -1, PREG_SPLIT_NO_EMPTY) as $rm) {
$rmarray[] = $rm;
}
}
}
}
foreach ($rmarray as $rm) {
$cmd = str_replace($rm, '', $cmd);
}
$query2 = $sql->prepare("SELECT `rcon`,`password`,`slots`,AES_DECRYPT(`ftpuploadpath`,?) AS `decyptedftpuploadpath` FROM `lendedserver` WHERE `serverid`=? AND `servertype`='g' AND `resellerid`=? LIMIT 1");
$query2->execute(array($aeskey, $serverid, $reseller_id));
foreach ($query2->fetchAll(PDO::FETCH_ASSOC) as $row2) {
$slots = $row2['slots'];
if ($row2['decyptedftpuploadpath'] != null and $row2['decyptedftpuploadpath'] != '' and $row2['decyptedftpuploadpath'] != 'ftp://username:password@1.1.1.1/demos') {
$ftpupload = $row2['decyptedftpuploadpath'];
}
if ($gamebinary == 'srcds_run') {
$cmd .= ' +rcon_password ' .$row2['rcon'] . ' +sv_password ' . $row2['password']. ' +tv_enable 1 +tv_autorecord 1';
} else if ($gamebinary == 'hlds_run') {
$cmd .= ' +rcon_password ' . $row2['rcon'] . ' +sv_password ' . $row2['password'];
} else if ($gamebinary == 'cod4_lnxded') {
$cmd .= ' +set rcon_password ' . $row2['rcon'] . ' +set g_password ' . $row2['password'];
}
}
if (isset($modcmd) and isset($modsCmds[$modcmd]) and is_array($modsCmds[$modcmd])) {
foreach ($modsCmds[$modcmd] as $singleModADD) {
$cmd .= ' ' . $singleModADD;
}
}
if ($workShop == 'Y' and isid($row['workshopCollection'], 10) and wpreg_check($row['dwebapiAuthkey'], 32) and strlen($row['dwebapiAuthkey']) > 0 and $row['workshopCollection'] > 0) {
if ($shorten == 'gmod' or $shorten == 'garrysmod') {
$cmd .= ' -nodefaultmap +host_workshop_collection ' . $row['workshopCollection'] . ' -authkey ' . $row['dwebapiAuthkey'];
} else {
$cmd .= ' -nodefaultmap +host_workshop_collection ' . $row['workshopCollection'] . ' +workshop_start_map ' . $map . ' -authkey ' . $row['dwebapiAuthkey'];
$cmd = preg_replace('/[\s\s+]{1,}\+map[\s\s+]{1,}[\w-_!%]{1,}/', '', $cmd);
}
}
$serverFolder = $gsip . '_' . $port . '/' . $folder;
$binaryFolder = $serverFolder . '/' . $binarydir;
$replace = array($gamebinary, $tic, $tic, $gsip, $port, $port2, $port2, $port3, $port4, $port5, $slots, $map, $mapGroup, $fps, $minram, $maxram, $maxcores, $folder, $customer, $absolutepath);
$startline = str_replace($cvars, $replace, $cmd);
foreach (customColumns('G', $switchID) as $cu) {
$startline = str_replace("%${cu['name']}%", $cu['value'], $startline);
}
if ($protected == 'Y' and $pallowed == 'Y') {
$customerUnprotected = $customer;
$customer .= '-p';
$ftppass = $decryptedftppass;
} else if ($protected == 'N' and $pallowed == 'Y') {
$customerProtected = $customer . '-p';
}
if ($action != 'du' and $eacallowed == 'Y' and in_array($anticheat, array(3, 4, 5, 6)) and ($gamebinary == 'srcds_run' or $gamebinary == 'hlds_run')) {
if ($action == 'so' or $action == 'sp') {
$rcon = '';
eacchange('remove', $serverid, $rcon, $reseller_id);
} else if ($action == 're') {
if ($gamebinary == 'srcds_run') {
$config = $modfolder . '/cfg/server.cfg';
} else if ($gamebinary == 'hlds_run') {
$config = $modfolder . '/server.cfg';
} else {
$config = 'main/server.cfg';
}
$ftpObect = new EasyWiFTP($sship, $ftpport, $customer, $ftppass);
if ($ftpObect->loggedIn === true) {
$ftpObect->downloadToTemp($pserver . $serverFolder . '/' . $config);
$configfile = $ftpObect->getTempFileContent();
$configfile = str_replace(array("\0","\b","\r","\Z"), '', $configfile);
$lines = explode("\n", $configfile);
$lines = preg_replace('/\s+/', ' ', $lines);
foreach ($lines as $singeline) {
if (preg_match("/\w/", substr($singeline, 0, 1))) {
if (preg_match("/\"/", $singeline)) {
$split = explode('"', $singeline);
$cvar = str_replace(' ', '', $split[0]);
$value = $split[1];
if ($cvar == 'rcon_password') {
$rcon = $value;
}
} else {
$split = explode(' ', $singeline);
if (isset($split[0])) {
$cvar = $split[0];
$value=(isset($split[1])) ? $split[1] : '';
if ($cvar == 'rcon_password') {
$rcon = $value;
}
}
}
}
}
if (isset($rcon)) {
eacchange('change', $serverid, $rcon, $reseller_id);
}
}
}
} else if ($action!='du' and $eacallowed == 'Y' and ($gamebinary == 'srcds_run' or $gamebinary == 'hlds_run') and ($anticheat == 1 or $anticheat == 2)) {
$rcon = '';
eacchange('remove', $serverid, $rcon, $reseller_id);
}
$protectedString = ($protected == 'N') ? 'unprotected' : 'protected';
if ($action == 'so' or $action == 'sp') {
$stopped = 'Y';
if ($action == 'so') {
$tempCmds[] = "sudo -u ${customer} ./control.sh gstop {$customer} \"{$binaryFolder}\" {$gamebinary} {$protectedString} {$homeDir}";
if ((isset($ftpupload) and $gamebinary == 'srcds_run')) {
$tempCmds[] = "sudo -u ${customer} ./control.sh demoupload \"{$bindir}\" \"{$ftpupload}\" \"{$modfolder}\"";
}
} else {
$tempCmds[] = "sudo -u ${customer} ./control.sh stopall";
}
} else if ($action == 're') {
$stopped = 'N';
if ($protected == 'N' and count($installedaddons) > 0) {
$tempCmds[] = "sudo -u ${customer} ./control.sh addonmatch {$customer} \"{$binaryFolder}\" \"" . implode(' ', $installedaddons) . "\" {$homeDir}";
}
if (count($installedMaps) > 0) {
$tempCmds[] = "sudo -u ${customer} ./control.sh mapmatch {$customer} \"{$binaryFolder}\" \"" . implode(' ', $installedMaps) . "\" {$homeDir}";
}
$restartCmd = "sudo -u ${customer} ./control.sh grestart {$customer} \"{$binaryFolder}\" \"{$startline}\" {$protectedString} {$gamebinary} \"{$cores}\" {$homeDir}";
}
if (!isset($ftpupload) and $gamebinary == 'srcds_run' and isurl($uploaddir)) {
if ($upload==2) {
$uploadcmd = "./control.sh demoupload \"{$bindir}\" \"{$uploaddir}\" \"{$modfolder}\" manual remove";
} else if ($upload==3) {
$uploadcmd = "./control.sh demoupload \"{$bindir}\" \"{$uploaddir}\" \"{$modfolder}\" manual keep";
} else if ($upload==4) {
$uploadcmd = "./control.sh demoupload \"{$bindir}\" \"{$uploaddir}\" \"{$modfolder}\" auto remove";
} else if ($upload==5) {
$uploadcmd = "./control.sh demoupload \"{$bindir}\" \"{$uploaddir}\" \"{$modfolder}\" auto keep";
}
if (($action == 'du' or ($action != 'so' and $action!='sp')) and isset($uploadcmd)) {
$tempCmds[]="sudo -u ${customer} $uploadcmd";
}
if ($action == 'du' and isset($uploadcmd)) {
$stopped = 'N';
}
}
foreach ($cvarprotect as $config => $values) {
if (!isset($values['cvars']) or count($values['cvars']) == 0) {
unset($cvarprotect[$config]);
}
}
if (count($cvarprotect) > 0 and $action != 'du') {
if (!isset($ftpObect)) {
$ftpObect = new EasyWiFTP($sship, $ftpport, $customer, $ftppass);
}
if ($ftpObect->loggedIn === true) {
foreach ($cvarprotect as $config => $values) {
$cfgtype = $values['type'];
if ($gamebinary == 'srcds_run' or $gamebinary == 'hlds_run') {
$config = $modfolder . '/' . $config;
}
$split_config = preg_split('/\//', $config, -1,PREG_SPLIT_NO_EMPTY);
$folderfilecount = count($split_config)-1;
$i = 0;
$folders = '/' . $pserver . $serverFolder;
while ($i<$folderfilecount) {
$folders .= '/' . $split_config[$i];
$i++;
}
$uploadfile = $split_config[$i];
$ftpObect->downloadToTemp($folders . '/' . $uploadfile);
$configfile = $ftpObect->getTempFileContent();
$ftpObect->tempHandle = null;
$configfile = str_replace(array("\0","\b","\r","\Z"),"", $configfile);
$lines = explode("\n", $configfile);
$linecount = count($lines) - 1;
$i = 0;
foreach ($lines as $singeline) {
$edited = false;
$lline = strtolower($singeline);
foreach ($values['cvars'] as $cvar => $value) {
if ($cfgtype == 'cfg' and preg_match("/^(.*)" . strtolower($cvar) . "\s+(.*)$/", $lline)) {
$edited = true;
$splitline = preg_split("/$cvar/", $singeline, -1,PREG_SPLIT_NO_EMPTY);
$ftpObect->writeContentToTemp((isset($splitline[1])) ? $splitline[0] . $cvar . ' ' . $value : $cvar . ' ' . $value);
} else if ($cfgtype == 'ini' and preg_match("/^(.*)" . strtolower($cvar) . "[\s+]{0,}\=[\s+]{0,}(.*)$/", $lline)) {
$edited = true;
$ftpObect->writeContentToTemp($cvar . '=' . $value);
} else if ($cfgtype == 'lua' and preg_match("/^(.*)" . strtolower($cvar) . "[\s+]{0,}\=[\s+]{0,}(.*)[\,]$/", $lline)) {
$edited = true;
$splitline = preg_split("/$cvar/", $singeline, -1,PREG_SPLIT_NO_EMPTY);
$ftpObect->writeContentToTemp((isset($splitline[1])) ? $splitline[0] . $cvar. ' = ' .$value : $cvar . '=' . $value);
} else if ($cfgtype == 'json' and preg_match("/^(.*)" . strtolower($cvar) . "[\s+]{0,}:[\s+]{0,}(.*)[\,]{0,1}$/", $lline)) {
$edited = true;
$splitline = preg_split("/$cvar/", $singeline, -1,PREG_SPLIT_NO_EMPTY);
$ftpObect->writeContentToTemp((isset($splitline[1])) ? $splitline[0] . $cvar. ' : ' .$value : $cvar . ':' . $value);
} else if ($cfgtype == 'xml' and preg_match("/^(.*)<" . strtolower($cvar) . ">(.*)<\/" . strtolower($cvar) . ">(.*)$/", $lline)) {
$edited = true;
$splitline = preg_split("/\<$cvar/", $singeline, -1,PREG_SPLIT_NO_EMPTY);
$ftpObect->writeContentToTemp((isset($splitline[1])) ? $splitline[0] . '<' .$cvar . '>' . $value . '</' . $cvar . '>' : '<' . $cvar . '> ' . $value . '</' . $cvar . '>');
}
}
if ($edited == false) {
$ftpObect->writeContentToTemp($singeline);
}
if ($i < $linecount) {
$ftpObect->writeContentToTemp("\r\n");
}
$i++;
}
$ftpObect->uploadFileFromTemp($folders, $uploadfile, false);
}
}
}
if (isset($ftpObect)) {
$ftpObect->logOut();
}
$query = $sql->prepare("UPDATE `gsswitch` SET `stopped`=? WHERE `id`=? AND `resellerid`=? LIMIT 1");
$query->execute(array($stopped, $switchID, $reseller_id));
$cmds = array();
if ($pallowed == 'Y' and $protected == 'Y') {
$cmds[]="sudo -u ${customerUnprotected} ./control.sh stopall";
} else if ($pallowed == 'Y' and $protected == 'N') {
$cmds[]="sudo -u ${customerProtected} ./control.sh stopall";
}
$cmds[] = 'sudo -u ' . $customer . ' ./control.sh addserver ' . $customer . ' 1_' . $shorten . ' ' . $gsip . '_' . $port . ' ' . $servertemplate . ' ' . $homeDir;
if (isset($restartCmd)) {
$cmds[] = $restartCmd;
}
foreach ($tempCmds as $c) {
$cmds[] = $c;
}
return $cmds;
}
return false;
}
if (!function_exists('eacchange')) {
function eacchange($what, $serverid, $rcon, $reseller_id) {