function tsbackup($action, $sshuser, $path, $ts3MasterID, $virtualserver_id, $backupid, $move = array()) { $split_config = preg_split('/\\//', $path, -1, PREG_SPLIT_NO_EMPTY); $folderfilecount = count($split_config) - 1; $i = 0; $folders = substr($path, 0, 1) == '/' ? '/' : '/home/' . $sshuser . '/'; while ($i <= $folderfilecount) { $folders .= $split_config[$i] . '/'; $i++; } if ($folders == '') { $folders = '.'; } if (substr($folders, -1) != '/') { $folders = $folders . '/'; } $filefolder = $folders . 'files/virtualserver_' . $virtualserver_id . '/'; $backupfolder = $folders . 'backups/virtualserver_' . $virtualserver_id . '/'; if ($action == 'create') { $function = 'function backup () { mkdir -p ' . $backupfolder . ' && nice -n +19 tar cfj ' . $backupfolder . $backupid . '.tar.bz2 ' . $filefolder . '; }'; } else { if ($action == 'delete') { $function = 'function backup () { nice -n +19 rm -f ' . $backupfolder . $backupid . '.tar.bz2; }'; } else { if ($action == 'deploy') { $function = 'function backup () { nice -n +19 rm -rf ' . $filefolder . '* && nice -n +19 tar xfj ' . $backupfolder . $backupid . '.tar.bz2 -C /'; if (count($move) > 0) { foreach ($move as $o => $n) { $function .= ' && mv ' . $o . ' ' . $n; } } $function .= '; }'; } } } if (isset($function)) { $ssh2cmd = 'cd ' . $folders . ' && ' . $function . '; backup& '; if (ssh2_execute('vm', $ts3MasterID, $ssh2cmd) !== false) { return 'ok'; } else { return 'The login data does not work'; } } return 'Incorrect action'; }
$snapshot = gzcompress($rawsnapshot, 9); $query4 = $sql->prepare("INSERT INTO `voice_server_backup` (`sid`,`uid`,`name`,`snapshot`,`date`,`resellerid`) VALUES(?,?,?,?,NOW(),?)"); $query4->execute(array($ts3id, $ts3userid, $name, $snapshot, $resellerid)); $query4 = $sql->prepare("SELECT `id` FROM `voice_server_backup` WHERE `sid`=? AND `uid`=? AND `resellerid`=? ORDER BY `id` DESC LIMIT 1"); $query4->execute(array($ts3id, $ts3userid, $resellerid)); while ($row4 = $query4->fetch(PDO::FETCH_ASSOC)) { $filefolder = 'files/virtualserver_' . $localserverid . '/'; $backupfolder = 'backups/virtualserver_' . $localserverid . '/'; $cmds[] = 'cd ' . $folders . ' && function backup () { mkdir -p ' . $backupfolder . ' && nice -n +19 tar cfj ' . $backupfolder . $row4['id'] . '.tar.bz2 ' . $filefolder . '; }; backup& '; print "Creating backup for ts3 server: " . $row3['ip'] . ':' . $row3['port'] . "\r\n"; } } } } if (count($cmds) > 0) { if (ssh2_execute('vm', $ts3masterid, $cmds)) { print "Restarting: {$restartreturn}\r\n"; } else { print "Failed restarting: {$restartreturn}\r\n"; } if (isset($dbConnect['debug']) and $dbConnect['debug'] == 1) { print_r($cmds); } } if (isset($connection) and is_object($connection)) { $connection->CloseConnection(); } usleep(500000); } } $currenttime = strtolower(date('D', strtotime("{$resellerstimezone} hour"))) . '_' . date('G', strtotime("{$resellerstimezone} hour"));
function eacchange($what, $serverid, $rcon, $reseller_id) { global $sql; global $dbConnect; $subfolder = ''; $parameter = ''; $query = $sql->prepare("SELECT `active`,`cfgdir`,`type`,`mysql_server`,`mysql_port`,`mysql_db`,`mysql_table`,`mysql_user`,`mysql_password` FROM `eac` WHERE `resellerid`=? LIMIT 1"); $query->execute(array($reseller_id)); while ($row = $query->fetch(PDO::FETCH_ASSOC)) { $cfgdir = $row['cfgdir']; $active = $row['active']; $type = $row['type']; $mysql_server = $row['mysql_server']; $mysql_port = $row['mysql_port']; $mysql_db = $row['mysql_db']; $mysql_table = $row['mysql_table']; $mysql_user = $row['mysql_user']; $mysql_password = $row['mysql_password']; $query2 = $sql->prepare("SELECT g.`serverip`,g.`port`,s.`anticheat`,t.`shorten` FROM `gsswitch` g LEFT JOIN `serverlist` s ON g.`serverid`=s.`id` LEFT JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE g.`id`=? AND g.`resellerid`=? LIMIT 1"); $query2->execute(array($serverid, $reseller_id)); while ($row2 = $query2->fetch(PDO::FETCH_ASSOC)) { $gsip = $row2['serverip']; $gsport = $row2['port']; $sqlParameter = 0; if ($row2['anticheat'] == 3) { $parameter = ''; } else { if ($row2['anticheat'] == 4) { $parameter = '-2'; $sqlParameter = 2; } else { if ($row2['anticheat'] == 5) { $parameter = '-1'; $sqlParameter = 1; } else { if ($row2['anticheat'] == 6) { $parameter = '-3'; $sqlParameter = 3; } } } } $gameID = 0; if ($row2['shorten'] == 'cstrike' or $row2['shorten'] == 'czero') { $subfolder = 'hl1'; $gameID = 1; } else { if ($row2['shorten'] == 'css' or $row2['shorten'] == 'tf') { $subfolder = 'hl2'; $gameID = 2; } else { if ($row2['shorten'] == 'csgo') { $subfolder = 'csgo'; $gameID = 4; } } } if ($type == 'M') { $mysql_port = port($mysql_port) ? $mysql_port : 3306; $eacSql = new PDO("mysql:host={$mysql_server};dbname={$mysql_db};port={$mysql_port}", $mysql_user, $mysql_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); if ($dbConnect['debug'] == 1) { $eacSql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } $query3 = $eacSql->prepare("SELECT 1 FROM `" . $mysql_table . "` WHERE `IP`=? LIMIT 1"); $query3->execute(array($gsip . ':' . $gsport)); $entryExists = $query3->rowCount(); if ($entryExists > 0 and $what == 'change') { $query3 = $eacSql->prepare("UPDATE `" . $mysql_table . "` SET `GAME`=?,`RCONPWD`=?,`FLAGS`=?,`EAC_ENABLED`=1 WHERE `IP`=? LIMIT 1"); $query3->execute(array($gameID, $rcon, $sqlParameter, $gsip . ':' . $gsport)); } else { if ($entryExists == 0 and $what == 'change') { $query3 = $eacSql->prepare("INSERT INTO `" . $mysql_table . "` (`GAME`,`IP`,`RCONPWD`,`FLAGS`,`EAC_ENABLED`) VALUES (?,?,?,?,1)"); $query3->execute(array($gameID, $gsip . ':' . $gsport, $rcon, $sqlParameter)); } else { if ($entryExists > 0 and $what == 'remove') { $query3 = $eacSql->prepare("DELETE FROM `" . $mysql_table . "` WHERE `IP`=?"); $query3->execute(array($gsip . ':' . $gsport)); } } } } else { $file = $cfgdir . '/' . $subfolder . '/' . $gsip . '-' . $gsport; $file = preg_replace('/\\/\\//', '/', $file); if ($what == 'change') { $ssh2cmd = 'echo "' . $gsip . ':' . $gsport . '-' . $rcon . $parameter . '" > ' . $file; } else { if ($what == 'remove') { $ssh2cmd = 'rm -f ' . $file; } } if (isset($ssh2cmd) and $active == 'Y') { if (!function_exists('ssh2_execute')) { include EASYWIDIR . '/stuff/methods/functions_ssh_exec.php'; } if (isset($ssh2cmd)) { ssh2_execute('eac', $reseller_id, $ssh2cmd); } } } } } }
} if ($active == 'N') { $ssh2cmd = "ps fx | grep '{$tsbin}' | grep -v 'grep' | awk '{print \$1}' | while read pid; do kill " . '$pid' . "; done"; $ssh2cmd2 = "ps fx | grep '{$tsdnsbin}' | grep -v 'grep' | awk '{print \$1}' | while read pid; do kill " . '$pid' . "; done"; } else { if ($active == 'Y') { $ssh2cmd = $commandFolders . 'function restart1 () { if [ "`ps fx | grep ' . $tsbin . ' | grep -v grep`" == "" ]; then ./ts3server_startscript.sh start > /dev/null & else ./ts3server_startscript.sh restart > /dev/null & fi }; restart1& '; $ssh2cmd2 = $commandFolders . ' cd tsdns && function restart2 () { if [ "`ps fx | grep ' . $tsdnsbin . ' | grep -v grep`" == "" ]; then ./' . $tsdnsbin . ' > /dev/null & else ./' . $tsdnsbin . ' --update > /dev/null & fi }; restart2& '; } } if ($usedns == 'Y') { $cmds = array($ssh2cmd, $ssh2cmd2); } else { $cmds = array($ssh2cmd); } ssh2_execute('vm', $id, $cmds); } // https://github.com/easy-wi/developer/issues/36 managedServer,managedForID added $query = $sql->prepare("UPDATE `voice_masterserver` SET `active`=:active,`connect_ip_only`=:connect_ip_only,`description`=:description,`managedServer`=:managedServer,`managedForID`=:managedForID,`externalID`=:externalID,`defaultname`=:defaultname,`bitversion`=:bit,`queryport`=:queryport,`querypassword`=AES_ENCRYPT(:querypassword,:aeskey),`filetransferport`=:filetransferport,`maxserver`=:maxserver,`maxslots`=:maxslots,`usedns`=:usedns,`defaultdns`=:defaultdns,`defaultwelcome`=:defaultwelcome,`defaulthostbanner_url`=:defaulthostbanner_url,`defaulthostbanner_gfx_url`=:defaulthostbanner_gfx_url,`defaulthostbutton_tooltip`=:defaulthostbutton_tooltip,`defaulthostbutton_url`=:defaulthostbutton_url,`defaulthostbutton_gfx_url`=:defaulthostbutton_gfx_url,`defaultFlexSlotsFree`=:defaultFlexSlotsFree,`defaultFlexSlotsPercent`=:defaultFlexSlotsPercent,`publickey`=:publickey,`ssh2ip`=:ssh2ip,`ssh2port`=AES_ENCRYPT(:ssh2port,:aeskey),`ssh2user`=AES_ENCRYPT(:ssh2user,:aeskey),`ssh2password`=AES_ENCRYPT(:ssh2password,:aeskey),`ips`=:ips,`serverdir`=:serverdir,`keyname`=:keyname,`autorestart`=:autorestart,`tsdnsServerID`=:tsdnsServerID,`externalDefaultDNS`=:externalDefaultDNS WHERE `id`=:id AND `resellerid`=:reseller_id LIMIT 1"); $query->execute(array(':aeskey' => $aeskey, ':active' => $active, ':connect_ip_only' => $connectIpOnly, ':description' => $description, ':managedServer' => $managedServer, ':managedForID' => $resellerToBeWritten, ':externalID' => $externalID, ':defaultname' => $defaultname, ':bit' => $bit, ':queryport' => $queryport, ':querypassword' => $querypassword, ':filetransferport' => $filetransferport, ':maxserver' => $maxserver, ':maxslots' => $maxslots, ':usedns' => $usedns, ':defaultdns' => $defaultdns, ':defaultwelcome' => $defaultwelcome, ':defaulthostbanner_url' => $defaulthostbanner_url, ':defaulthostbanner_gfx_url' => $defaulthostbanner_gfx_url, ':defaulthostbutton_tooltip' => $defaulthostbutton_tooltip, ':defaulthostbutton_url' => $defaulthostbutton_url, ':defaulthostbutton_gfx_url' => $defaulthostbutton_gfx_url, ':defaultFlexSlotsFree' => $defaultFlexSlotsFree, ':defaultFlexSlotsPercent' => $defaultFlexSlotsPercent, ':publickey' => $publickey, ':ssh2ip' => $ip, ':ssh2port' => $port, ':ssh2user' => $user, ':ssh2password' => $pass, ':ips' => $ips, ':serverdir' => $serverdir, ':keyname' => $keyname, ':autorestart' => $autorestart, ':tsdnsServerID' => $tsdnsServerID, ':externalDefaultDNS' => $externalDefaultDNS, ':id' => $id, ':reseller_id' => $reseller_id)); $rowCount = $query->rowCount(); $template_file = $spracheResponse->table_add; $loguseraction = '%mod% %voserver% %master% ' . $ip; } } } else { if ($ui->w('action', 3, 'post') == 'ad2' and $ui->id('id', 10, 'get')) { # get masterserver data to be able to import existing voice servers $masterid = $ui->id('id', 10, 'get'); # Suhoshin has a POST Limit. So we need to limit as well. $prefix = $rSA['prefix2'];
printText('JSON Response does not contain expected values'); $left = 0; } else { if (strpos(strtolower($rawResponse), 'file not found') === false) { printText('No Json Response. Will retry.'); } else { $left = 0; printText('404: File not found'); } } } } } // Start the migration of newly imported gameservers foreach ($gameRootCmds as $k => $v) { ssh2_execute('gs', $k, $v); } // Set to null instead of unset() because PHP garbage collector does not work very efficient $gameRootCmds = null; $gameRootIPs = null; // TS3 Master server array $ts3MasterIPs = array(); $query2 = $sql->prepare("SELECT `id`,`ssh2ip`,`ips`,`sourceSystemID`,`externalID` FROM `voice_masterserver` WHERE `resellerid`=?"); $query2->execute(array($resellerID)); while ($row2 = $query2->fetch(PDO::FETCH_ASSOC)) { $ts3MasterIPs[$row2['ssh2ip']] = array('id' => $row2['id'], 'sourceSystemID' => $row2['sourceSystemID'], 'externalID' => $row2['externalID']); foreach (ipstoarray($row2['ips']) as $ip) { $ts3MasterIPs[$ip] = array('id' => $row2['id'], 'sourceSystemID' => $row2['sourceSystemID'], 'externalID' => $row2['externalID']); } } // TS3 Masterserver
$maxserver = isid($ui->post['maxserver'], "3"); $port = $ui->post['port']; $user = $ui->post['user']; $esxi = $ui->post['esxi']; $pass = password_check($ui->post['pass'], 255); $os = "linux"; $description = $ui->description('description', 'post'); $cores = isid($ui->post['cores'], "5"); $cpu = $ui->description('cpu', 'post'); $mhz = isid($ui->post['mhz'], "5"); $ram = isinteger($ui->post['ram']); $pinsert = $sql->prepare("INSERT INTO `virtualhosts` (`active`,`esxi`,`ip`,`port`,`user`,`pass`,`os`,`description`,`publickey`,`keyname`,`cpu`,`cores`,`mhz`,`ram`,`maxserver`,`thin`,`thinquota`,`resellerid`) VALUES (:active, :esxi, :ip, AES_ENCRYPT(:port, :aeskey),AES_ENCRYPT(:user, :aeskey),AES_ENCRYPT(:pass, :aeskey),:os, :description, :publickey, :keyname, :cpu, :cores, :mhz, :ram, :maxserver, :thin, :thinquota, :reseller)"); $pinsert->execute(array(':active' => $active, ':esxi' => $esxi, ':ip' => $ip, ':port' => $port, ':aeskey' => $aeskey, ':user' => $user, ':pass' => $pass, ':os' => $os, ':description' => $description, ':publickey' => $publickey, ':keyname' => $keyname, ':cpu' => $cpu, ':cores' => $cores, ':mhz' => $mhz, ':ram' => $ram, ':maxserver' => $maxserver, ':thin' => $thin, ':thinquota' => $thinquota, ':reseller' => $reseller)); $serverid = $sql->lastInsertId(); include EASYWIDIR . '/stuff/methods/functions_ssh_exec.php'; $uidb = ssh2_execute('vh', $serverid, 'cd /vmfs/volumes; S=""; for U in `ls -la | grep "drwxr-xr-t" | awk \'{print $9}\'`; do C=`vmkfstools -Ph $U 2> /dev/null | grep "Capacity" | awk \'{print $2$3}\'`; S="$S$U:$C;"; done; for U in `ls -la | grep "drwxrwxrwx" | awk \'{print $9}\'`; do C=`vmkfstools -Ph $U 2> /dev/null | grep "Capacity" | awk \'{print $2$3}\'`; S="$S$U:$C;"; done; echo $S'); if ($uidb != '' and $uidb !== false) { $uiddata = explode(";", $uidb); $i = 0; $count = count($uiddata) - 1; while ($i < $count) { list($uid, $space) = explode(":", $uiddata[$i]); if (strpos(strtolower($space), strtolower('TB')) === false) { $hddamount = str_replace('GB,', '', $space); } else { $hddamount = str_replace('TB,', '', $space) * 1000; } if (isset($hdd)) { $hdd .= "\r\n" . $uid . ' ' . $hddamount; } else { $hdd = $uid . ' ' . $hddamount;