https://github.com/easy-wi/developer/issues/31
This commit is contained in:
Ulrich Block 2013-08-30 22:01:38 +02:00
parent 58eee53035
commit 68448b878f
11 changed files with 93 additions and 379 deletions

View File

@ -452,15 +452,10 @@ if (!isset($ip) or $_SERVER['SERVER_ADDR']==$ip) {
foreach ($query2->fetchAll(PDO::FETCH_ASSOC) as $row2) {
$rootServer=new masterServer($row2['id'],$aeskey);
$rootServer->collectData();
if (4==$stunde) {
$sshcmd=$rootServer->returnCmds('update','all');
} else {
$sshcmd=$rootServer->returnCmds();
}
$sshcmd=(4==$stunde) ? $rootServer->returnCmds('update','all') : $rootServer->returnCmds();
if ($rootServer->sshcmd!==null) {
echo "Starting updates for ".$rootServer->sship."\r\n";
$update=exec_server($rootServer->sship,$rootServer->sshport,$rootServer->sshuser,$rootServer->sshpass,$rootServer->sshcmd,$sql);
if ($update!="Could not connect to Server" and $update!="The login data does not work") {
if (ssh2_execute('gs',$row2['id'],$rootServer->sshcmd)!==false) {
$rootServer->setUpdating();
echo "Updater started for ".$rootServer->sship."\r\n";
} else {
@ -475,11 +470,7 @@ if (!isset($ip) or $_SERVER['SERVER_ADDR']==$ip) {
print "Check for new news feeds\r\n";
include('stuff/feeds_function.php');
if (isset($template_file)) print $template_file."\r\n";
if (isset($argv[1]) and is_numeric($argv[1])) {
$chunkSize=$argv[1];
} else {
$chunkSize=500;
}
$chunkSize=(isset($argv[1]) and is_numeric($argv[1])) ? $argv[1] : 500;
print "Cleaning Up hourly data. Chunksize is ${chunkSize}\r\n";
$query=$sql->prepare("DELETE FROM `voice_server_stats` WHERE `date` IS NULL OR `date`='0000-00-00 00:00:00'");
$query->execute();

View File

@ -366,8 +366,7 @@ if ($ui->smallletters('w',5,'get')=='check') {
if ($rootServer->sshcmd===null) {
echo 'Nothing to update/sync!';
} else {
$start=exec_server($rootServer->sship,$rootServer->sshport,$rootServer->sshuser,$rootServer->sshpass,$rootServer->sshcmd,$sql);
if ($start=="The login data does not work" or $start=="Could not connect to Server") {
if (ssh2_execute('gs',$ui->id('id',10,'get'),$rootServer->sshcmd)===false) {
echo $sprache->error_root_updatemaster." ( ".implode(", ",$gamelist)." ) ( $start )";
} else {
$rootServer->setUpdating();

View File

@ -454,32 +454,20 @@ if (!function_exists('passwordgenerate')) {
$anticheat=$row['anticheat'];
$shorten=$row['shorten'];
}
if ($anticheat==3) {
$parameter='';
} else if ($anticheat==4) {
$parameter='-2';
} else if ($anticheat==5) {
$parameter='-1';
} else if ($anticheat==6) {
$parameter='-3';
}
if ($shorten=='cstrike' or $shorten=='czero') {
$subfolder='hl1';
} else if ($shorten=='css' or $shorten=='tf') {
$subfolder='hl2';
} else if ($shorten=='cod4') {
$subfolder='cod4';
}
if ($anticheat==3) $parameter='';
else if ($anticheat==4) $parameter='-2';
else if ($anticheat==5) $parameter='-1';
else if ($anticheat==6) $parameter='-3';
if ($shorten=='cstrike' or $shorten=='czero') $subfolder='hl1';
else if ($shorten=='css' or $shorten=='tf') $subfolder='hl2';
else if ($shorten=='cod4') $subfolder='cod4';
$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 ($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('ssh2exec')) include(EASYWIDIR.'/stuff/ssh_exec.php');
ssh2exec($reseller_id,'eac',$aeskey,$ssh2cmd,$sql);
if (!function_exists('ssh2_execute')) include(EASYWIDIR.'/stuff/ssh_exec.php');
if (isset($ssh2cmd)) ssh2_execute('eac',$reseller_id,$ssh2cmd);
}
}
function gsrestart($switchID,$action,$aeskey,$sprache,$reseller_id,$sql) {

View File

@ -484,14 +484,12 @@ if ($ui->st('d','get')=='ad' and is_numeric($licenceDetails['lG']) and $licenceD
$ftppass2=passwordgenerate(10);
$webhostdomain=webhostdomain($reseller_id,$sql);
$gsuser=$cname.'-'.$switchID;
$reply=ssh2exec($serverid,'root',$aeskey,"./control.sh add $gsuser $ftppass $sshuser $ftppass2",$sql);
if ($ui->id('installGames',1,'post')!=3 and $reply!="Could not connect to Server" and $reply!="The login data does not work") {
if ($ui->id('installGames',1,'post')==2) {
$gamestring=array($ui->escaped('primary','post'));
}
$gamestring=count($gamestring).'_'.implode('_',$gamestring);
$reply=shell_server($sship,$sshport,$sshuser,$sshpass,$gsuser,$ftppass,"./control.sh addserver $gsuser $gamestring $gsfolder",$sql);
}
$cmds=array();
$cmds[]="./control.sh add ${gsuser} ${ftppass} ${sshuser} ${ftppass2}";
if ($ui->id('installGames',1,'post')==2) $gamestring=array($ui->escaped('primary','post'));
$gamestring=count($gamestring).'_'.implode('_',$gamestring);
if ($ui->id('installGames',1,'post')!=3) $cmds[]="sudo -u ${gsuser} ./control.sh addserver ${gsuser} ${gamestring} ${gsfolder}";
ssh2_execute('gs',$serverid,$cmds);
} else {
$reply="Could not insert data into database";
}

View File

@ -124,8 +124,8 @@ if ($ui->w('action',4,'post') and !token(true)) {
$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/ssh_exec.php');
$uidb=ssh2exec($serverid,'virtualhost',$aeskey,'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',$sql);
if ($uidb!="" and $uidb!="The login data does not work" and $uidb!="Could not connect to Server") {
$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;

View File

@ -38,311 +38,66 @@ if (!function_exists('ssh2_execute')) {
function ssh2_execute($type,$id,$cmds) {
global $sql,$rSA,$aeskey;
$return='';
if ($type=='vs') {
if ($type=='eac') {
$query=$sql->prepare("SELECT *,AES_DECRYPT(`port`,:aeskey) AS `decryptedport`,AES_DECRYPT(`user`,:aeskey) AS `decrypteduser`,AES_DECRYPT(`pass`,:aeskey) AS `decryptedpass` FROM `eac` WHERE resellerid=:serverID LIMIT 1");
} else if ($type=='gs') {
$query=$sql->prepare("SELECT *,AES_DECRYPT(`port`,:aeskey) AS `decryptedport`,AES_DECRYPT(`user`,:aeskey) AS `decrypteduser`,AES_DECRYPT(`pass`,:aeskey) AS `decryptedpass`,AES_DECRYPT(`steamAccount`,:aeskey) AS `decryptedsteamAccount`,AES_DECRYPT(`steamPassword`,:aeskey) AS `decryptedsteamPassword` FROM `rserverdata` WHERE `id`=:serverID LIMIT 1");
} else if ($type=='vh') {
$query=$sql->prepare("SELECT *,AES_DECRYPT(`port`,:aeskey) AS `decryptedport`,AES_DECRYPT(`user`,:aeskey) AS `decrypteduser`,AES_DECRYPT(`pass`,:aeskey) AS `decryptedpass` FROM `virtualhosts` WHERE `id`=:serverID LIMIT 1");
}
$query->execute(array(':serverID'=>$id,':aeskey'=>$aeskey));
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
$serverID=$row['id'];
$resellerID=$row['resellerid'];
$notified=$row['notified'];
$ssh2IP=$row['ip'];
$ssh2Port=$row['decryptedport'];
$ssh2User=$row['decrypteduser'];
$ssh2Pass=$row['decryptedpass'];
$ssh2Publickey=$row['publickey'];
$pubkey=EASYWIDIR."/keys/${row['keyname']}.pub";
$key=EASYWIDIR."/keys/${row['keyname']}";
$ssh2Socket=($ssh2Publickey=='Y') ? (file_exists($pubkey) and file_exists($key)) ? @ssh2_connect($ssh2IP,$ssh2Port,array('hostkey'=>'ssh-rsa')) : false : @ssh2_connect($ssh2IP,$ssh2Port);
if ($ssh2Socket==true) {
$ssh2Connect=($ssh2Publickey=='Y') ? @ssh2_auth_pubkey_file($ssh2Socket,$ssh2User,$pubkey,$key) : @ssh2_auth_password($ssh2Socket,$ssh2User,$ssh2Pass);
if ($ssh2Connect==true) {
if (!is_array($cmds)) $cmds=array($cmds);
foreach ($cmds as $c) {
if (is_string($c) and $c!='') {
$ssh2Stream=@ssh2_exec($ssh2Socket,$c);
stream_set_blocking($ssh2Stream,true);
if ($ssh2Stream) $error=true;
$return.=stream_get_contents($ssh2Stream);
fclose($ssh2Stream);
if (isset($query)) {
$query->execute(array(':serverID'=>$id,':aeskey'=>$aeskey));
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
$serverID=$row['id'];
$resellerID=$row['resellerid'];
$notified=$row['notified'];
$ssh2IP=$row['ip'];
$ssh2Port=$row['decryptedport'];
$ssh2User=$row['decrypteduser'];
$ssh2Pass=$row['decryptedpass'];
$ssh2Publickey=$row['publickey'];
$pubkey=EASYWIDIR."/keys/${row['keyname']}.pub";
$key=EASYWIDIR."/keys/${row['keyname']}";
$ssh2Socket=($ssh2Publickey=='Y') ? (file_exists($pubkey) and file_exists($key)) ? @ssh2_connect($ssh2IP,$ssh2Port,array('hostkey'=>'ssh-rsa')) : false : @ssh2_connect($ssh2IP,$ssh2Port);
if ($ssh2Socket==true) {
$ssh2Connect=($ssh2Publickey=='Y') ? @ssh2_auth_pubkey_file($ssh2Socket,$ssh2User,$pubkey,$key) : @ssh2_auth_password($ssh2Socket,$ssh2User,$ssh2Pass);
if ($ssh2Connect==true) {
if (!is_array($cmds)) $cmds=array($cmds);
foreach ($cmds as $c) {
if (is_string($c) and $c!='') {
$ssh2Stream=@ssh2_exec($ssh2Socket,$c);
stream_set_blocking($ssh2Stream,true);
if (!$ssh2Stream) $error=true;
$return.=stream_get_contents($ssh2Stream);
fclose($ssh2Stream);
}
}
} else {
$error=true;
}
$ssh2Socket=null;
} else {
$error=true;
}
$ssh2Socket=null;
} else {
$error=true;
print_r($rSA['down_checks']);
if (isset($error)) $notified++;
else $notified=0;
if ($notified==$rSA['down_checks']) {
$query=($resellerID==0) ? $sql->prepare("SELECT `id`,`mail_serverdown` FROM `userdata` WHERE `resellerid`=0 AND `accounttype`='a'") : $sql->prepare("SELECT `id`,`mail_serverdown` FROM `userdata` WHERE (`id`=${resellerID} AND `id`=`resellerid`) OR `resellerid`=0 AND `accounttype`='a'");
$query->execute();
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row2) if ($row2['mail_serverdown']=='Y') sendmail('emaildown',$row2['id'],$ssh2IP,'',$sql);
}
if ($type=='gs') {
$query=$sql->prepare("UPDATE `rserverdata` SET `notified`=? WHERE `id`=? LIMIT 1");
} else if ($type=="eac") {
$query=$sql->prepare("UPDATE `eac` SET `notified`=? WHERE `id`=? LIMIT 1");
} else if ($type=='vh') {
$query=$sql->prepare("UPDATE `virtualhosts` SET `notified`=? WHERE `id`=? LIMIT 1");
}
$query->execute(array($notified,$serverID));
return $return;
}
if (isset($error)) $notified++;
else $notified=0;
if ($notified==$rSA['down_checks']) {
$query=($resellerID==0) ? $sql->prepare("SELECT `id`,`mail_serverdown` FROM `userdata` WHERE `resellerid`='0' AND `accounttype`='a'") : $sql->prepare("SELECT `id`,`mail_serverdown` FROM `userdata` WHERE (`id`=${resellerID} AND `id`=`resellerid`) OR `resellerid`=0 AND `accounttype`='a'");
$query->execute();
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row2) if ($row2['mail_serverdown']=='Y') sendmail('emaildown',$row2['id'],$ssh2IP,'',$sql);
}
if ($type=='gs') {
$query=$sql->prepare("UPDATE `rserverdata` SET `notified`=? WHERE `id`=? LIMIT 1");
} else if ($type=="vs") {
$query=$sql->prepare("UPDATE `virtualhosts` SET `notified`=? WHERE `id`=? LIMIT 1");
} else if ($type=="dh") {
$query=$sql->prepare("UPDATE `dhcpdata` SET `notified`=? WHERE `id`=? LIMIT 1");
} else if ($type=="ea") {
$query=$sql->prepare("UPDATE `eac` SET `notified`=? WHERE `resellerid`=? LIMIT 1");
}
$query->execute(array($notified,$serverID));
return $return;
}
return false;
}
function exec_server($ssh2ip,$ssh2port,$ssh2user,$ssh2pass,$ssh2cmd,$sql) {
if (strpos(strtolower($ssh2cmd), "control.sh") !== false) {
$pselect=$sql->prepare("SELECT `publickey`,`keyname`,`notified`,`resellerid` FROM `virtualhosts` WHERE `ip`=? LIMIT 1");
$pselect->execute(array($ssh2ip));
foreach ($pselect->fetchAll() as $row) {
$publickey=$row['publickey'];
$keyname=$row['keyname'];
$notified=$row['notified'];
$resellerid=$row['resellerid'];
}
} else {
$pselect=$sql->prepare("SELECT `publickey`,`keyname`,`notified`,`resellerid` FROM `rserverdata` WHERE `ip`=? LIMIT 1");
$pselect->execute(array($ssh2ip));
foreach ($pselect->fetchAll() as $row) {
$publickey=$row['publickey'];
$keyname=$row['keyname'];
$notified=$row['notified'];
$resellerid=$row['resellerid'];
}
}
if (!isset($notified)) $notified=0;
if (!isset($resellerid)) $resellerid=0;
$pselect=$sql->prepare("SELECT `down_checks` FROM `settings` WHERE `resellerid`=? LIMIT 1");
$pselect->execute(array($resellerid));
foreach ($pselect->fetchAll() as $row) {
$down_checks=$row['down_checks'];
}
if (isset($publickey) and $publickey=="Y") {
$pubkey="keys/".$keyname.".pub";
$key="keys/".$keyname;
$ssh2= @ssh2_connect($ssh2ip,$ssh2port,array('hostkey'=>'ssh-rsa'));
} else {
$ssh2= @ssh2_connect($ssh2ip,$ssh2port);
}
if ($ssh2==true) {
if (isset($publickey) and $publickey=="Y") {
$connect_ssh2= @ssh2_auth_pubkey_file($ssh2, $ssh2user, $pubkey, $key);
} else {
$connect_ssh2= @ssh2_auth_password($ssh2, $ssh2user, $ssh2pass);
}
if ($connect_ssh2==true) {
$shell = ssh2_exec($ssh2, $ssh2cmd);
stream_set_blocking($shell,true);
$data = '';
while($buffer = fread($shell,4096)){
$data .= $buffer;
}
if (strpos(strtolower($ssh2cmd), "control.sh") !== false and $notified>0) {
$pupdate2=$sql->prepare("UPDATE `virtualhosts` SET `notified`='0' WHERE `ip`=? LIMIT 1");
$pupdate2->execute(array($ssh2ip));
} else if ($notified>0) {
$pupdate2=$sql->prepare("UPDATE `rserverdata` SET `notified`='0' WHERE `ip`=? LIMIT 1");
$pupdate2->execute(array($ssh2ip));
}
ssh2_exec($ssh2,'exit');
$connect_ssh2=null;
return $data;
} else {
$bad="The login data does not work";
}
} else {
$bad="Could not connect to Server";
}
if (isset($bad)) {
$notified++;
if (strpos(strtolower($ssh2cmd), "control.sh") !== false) {
$pupdate2=$sql->prepare("UPDATE `virtualhosts` SET `notified`=? WHERE `ip`=? LIMIT 1");
$pupdate2->execute(array($notified,$ssh2ip));
} else {
$pupdate2=$sql->prepare("UPDATE `rserverdata` SET `notified`=? WHERE `ip`=? LIMIT 1");
$pupdate2->execute(array($notified,$ssh2ip));
}
}
if (isset($bad) and ($bad=="Could not connect to Server" or $bad=="The login data does not work") and $notified==$down_checks) {
if ($resellerid==0) {
$query2=$sql->prepare("SELECT `id`,`mail_serverdown` FROM `userdata` WHERE `resellerid`='0' AND `accounttype`='a'");
$query2->execute();
} else {
$query2=$sql->prepare("SELECT `id`,`mail_serverdown` FROM `userdata` WHERE (`id`=? AND `id`=`resellerid`) OR `resellerid`='0' AND `accounttype`='a'");
$query2->execute(array($resellerid));
}
foreach ($query2->fetchAll() as $row2) {
if ($row2['mail_serverdown']=='Y') {
sendmail('emaildown',$row2['id'],$ssh2ip,'',$sql);
}
}
}
if (isset($bad)) {
return $bad;
}
}
function ssh2exec($serverid,$type,$aeskey,$ssh2cmd,$sql) {
$serverdata=serverdata($type,$serverid,$aeskey,$sql);
$notified=$serverdata['notified'];
$resellerid=$serverdata['resellerid'];
$ssh2ip=$serverdata['ip'];
global $rSA;
if ($serverdata['publickey']=="Y") {
$pubkey=EASYWIDIR."/keys/".$serverdata['keyname'].".pub";
$key=EASYWIDIR."/keys/".$serverdata['keyname'];
if (file_exists($pubkey) and file_exists($key)) $ssh2=@ssh2_connect($ssh2ip,$serverdata['port'],array('hostkey'=>'ssh-rsa'));
} else {
$ssh2=@ssh2_connect($ssh2ip,$serverdata['port']);
}
if (isset($ssh2) and $ssh2==true) {
if ($serverdata['publickey']=="Y") {
$connect_ssh2= @ssh2_auth_pubkey_file($ssh2, $serverdata['user'], $pubkey, $key);
} else {
$connect_ssh2= @ssh2_auth_password($ssh2, $serverdata['user'], $serverdata['pass']);
}
if ($connect_ssh2==true) {
$shell = ssh2_exec($ssh2, $ssh2cmd);
stream_set_blocking($shell, true);
$data = '';
while($buffer = fread($shell,4096)){
$data .= $buffer;
}
fclose($shell);
ssh2_exec($ssh2,'exit');
if ($notified>0) {
if ($type=="root") {
$query=$sql->prepare("UPDATE `rserverdata` SET `notified`='0' WHERE `id`=? LIMIT 1");
} else if ($type=="virtualhost") {
$query=$sql->prepare("UPDATE `virtualhosts` SET `notified`='0' WHERE `id`=? LIMIT 1");
} else if ($type=="dhcp") {
$query=$sql->prepare("UPDATE `dhcpdata` SET `notified`='0' WHERE `id`=? LIMIT 1");
} else if ($type=="eac") {
$query=$sql->prepare("UPDATE `eac` SET `notified`='0' WHERE `resellerid`=? LIMIT 1");
}
$query->execute(array($serverid));
}
return $data;
} else {
$bad="The login data does not work";
}
} else {
$bad="Could not connect to Server";
}
if (isset($bad)) {
$notified++;
if ($type=="root") {
$query=$sql->prepare("UPDATE `rserverdata` SET `notified`=? WHERE `id`=? LIMIT 1");
} else if ($type=="virtualhost") {
$query=$sql->prepare("UPDATE `virtualhosts` SET `notified`=? WHERE `id`=? LIMIT 1");
} else if ($type=="dhcp") {
$query=$sql->prepare("UPDATE `dhcpdata` SET `notified`=? WHERE `id`=? LIMIT 1");
} else if ($type=="eac") {
$query=$sql->prepare("UPDATE `eac` SET `notified`=? WHERE `resellerid`=? LIMIT 1");
}
$query->execute(array($notified,$serverid));
}
if (isset($bad) and ($bad=="Could not connect to Server" or $bad=="The login data does not work") and $notified==$rSA['down_checks']) {
if ($resellerid==0) {
$query=$sql->prepare("SELECT `id`,`mail_serverdown` FROM `userdata` WHERE `resellerid`='0' AND `accounttype`='a'");
$query->execute();
} else {
$query=$sql->prepare("SELECT `id`,`mail_serverdown` FROM `userdata` WHERE (`id`=? AND `id`=`resellerid`) OR (`resellerid`='0' AND `accounttype`='a')");
$query->execute(array($resellerid));
}
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
if ($row['mail_serverdown']=='Y') {
sendmail('emaildown',$row['id'],$ssh2ip,'',$sql);
}
}
}
if (isset($bad)) return $bad;
}
function shell_server($ssh2ip,$ssh2port,$ssh2user,$ssh2pass,$suuser,$supass,$sucmd,$sql) {
$command=array();
$command[]="su -c '".$sucmd."' ".$suuser;
$command[]=$supass;
$command[]='exit';
$pselect=$sql->prepare("SELECT `id`,`publickey`,`keyname`,`notified`,`resellerid` FROM `rserverdata` WHERE `ip`=? LIMIT 1");
$pselect->execute(array($ssh2ip));
foreach ($pselect->fetchAll() as $row) {
$publickey=$row['publickey'];
$keyname=$row['keyname'];
$notified=$row['notified'];
$resellerid=$row['resellerid'];
$rootID=$row['id'];
}
$pselect=$sql->prepare("SELECT `down_checks` FROM `settings` WHERE `resellerid`=? LIMIT 1");
$pselect->execute(array($resellerid));
foreach ($pselect->fetchAll() as $row) {
$down_checks=$row['down_checks'];
}
if ($publickey=="Y") {
$pubkey="keys/".$keyname.".pub";
$key="keys/".$keyname;
$ssh2= @ssh2_connect($ssh2ip,$ssh2port,array('hostkey'=>'ssh-rsa'));
} else {
$ssh2= @ssh2_connect($ssh2ip,$ssh2port);
}
if ($ssh2==true) {
if ($publickey=="Y") {
$connect_ssh2= @ssh2_auth_pubkey_file($ssh2, $ssh2user, $pubkey, $key);
} else {
$connect_ssh2= @ssh2_auth_password($ssh2, $ssh2user, $ssh2pass);
}
if ($connect_ssh2==true) {
$data = '';
$shell = ssh2_shell($ssh2);
for($i=0; $i<count($command); $i++) {
fwrite($shell, $command[$i] . PHP_EOL);
#usleep(500000);
sleep(1);
while($buffer = fgets($shell)) {
flush();
$data .= $buffer;
}
}
#usleep(500000);
sleep(1);
fclose($shell);
if ($notified>0) {
$pupdate2=$sql->prepare("UPDATE `rserverdata` SET `notified`='0' WHERE `ip`=? LIMIT 1");
$pupdate2->execute(array($ssh2ip));
}
return '';
} else {
$bad="The login data does not work";
}
} else {
$bad="Could not connect to Server";
}
if (isset($bad)) {
$notified++;
$pupdate2=$sql->prepare("UPDATE `rserverdata` SET `notified`=? WHERE `id`=? LIMIT 1");
$pupdate2->execute(array($notified,$rootID));
}
if (isset($bad) and ($bad=="Could not connect to Server" or $bad=="The login data does not work") and $down_checks==$notified) {
if ($resellerid==0) {
$query2=$sql->prepare("SELECT `id`,`mail_serverdown` FROM `userdata` WHERE `resellerid`='0' AND `accounttype`='a'");
$query2->execute();
} else {
$query2=$sql->prepare("SELECT `id`,`mail_serverdown` FROM `userdata` WHERE (`id`=? AND `id`=`resellerid`) OR (`resellerid`='0' AND `accounttype`='a')");
$query2->execute(array($resellerid));
}
foreach ($query2->fetchAll() as $row2) {
if ($row2['mail_serverdown']=='Y') {
sendmail('emaildown',$row2['id'],$ssh2ip,'',$sql);
}
}
}
if (isset($bad)) {
return $bad;
}
}
}

View File

@ -112,9 +112,7 @@ if ($ui->id('id',10,'get') and $ui->id('adid',10,'get') and in_array($ui->smalll
$customer=$customer."-p";
}
if ($ui->st('action','get')=='ad' and ($protected=="N" or ($protected=="Y" and $paddon=="Y"))) {
$sshcmd="./control.sh addaddon $type $addon \"$serverfolder\" \"$modfolder\"";
$reply=shell_server($sship,$sshport,$sshuser,$sshpass,$customer,$ftppass,$sshcmd,$sql);
if($reply!="The login data does not work" and $reply!="Could not connect to Server"){
if(ssh2_execute('gs',$rootID,"sudo -u $customer ./control.sh addaddon $type $addon \"$serverfolder\" \"$modfolder\"")!==false){
$query=$sql->prepare("INSERT INTO `addons_installed` (`userid`,`addonid`,`serverid`,`servertemplate`,`paddon`,`resellerid`) VALUES (?,?,?,?,?,?)");
$query->execute(array($user_id,$addonid,$serverid,$servertemplate,$protected,$reseller_id));
$template_file=$sprache->addon_inst;
@ -125,7 +123,8 @@ if ($ui->id('id',10,'get') and $ui->id('adid',10,'get') and in_array($ui->smalll
}
} else if ($ui->st('action','get')=='dl' and $ui->id('rid',19,'get')) {
$installedid=$ui->id('rid',19,'get');
$sshcmd="./control.sh deladdon $type $addon \"$serverfolder\" \"$modfolder\" \"$folder\"";
$cmds=array();
$cmds[]="sudo -u $customer ./control.sh deladdon $type $addon \"$serverfolder\" \"$modfolder\" \"$folder\"";
$delids=$addonid;
while (isset($delids) and isset($installedid)) {
$query=$sql->prepare("SELECT `id`,`folder`,`addon` FROM `addons` WHERE `depending`=? AND `resellerid`=? LIMIT 1");
@ -135,7 +134,7 @@ if ($ui->id('id',10,'get') and $ui->id('adid',10,'get') and in_array($ui->smalll
$query2->execute(array($installedid,$reseller_id));
unset($installedid);
if (isset($deladdon)) {
$sshcmd .=" && ./control.sh deladdon $type $deladdon \"$serverfolder\" \"$modfolder\" \"$delfolder\"";
$cmds[]="sudo -u $customer ./control.sh deladdon $type $deladdon \"$serverfolder\" \"$modfolder\" \"$delfolder\"";
unset($deladdon);
unset($delfolder);
}
@ -147,13 +146,10 @@ if ($ui->id('id',10,'get') and $ui->id('adid',10,'get') and in_array($ui->smalll
$deladdon=$row['addon'];
$query2=$sql->prepare("SELECT `id` FROM `addons_installed` WHERE `addonid`=? AND `serverid`=? AND `servertemplate`=? AND `resellerid`=? LIMIT 1");
$query2->execute(array($delids,$serverid,$servertemplate,$reseller_id));
foreach ($query2->fetchAll(PDO::FETCH_ASSOC) as $row2) {
$installedid=$row2['id'];
}
$installedid=$query2->fetchColumn();
}
}
$reply=shell_server($sship,$sshport,$sshuser,$sshpass,$customer,$ftppass,$sshcmd,$sql);
if($reply!="The login data does not work" and $reply!="Could not connect to Server"){
if(ssh2_execute('gs',$rootID,$cmds)!==false){
$template_file=$sprache->addon_del;
$actionstatus="ok";
} else {

View File

@ -46,7 +46,7 @@ $customer=getusername($user_id,$sql);
$aesfilecvar=getconfigcvars(EASYWIDIR."/stuff/keyphrasefile.php");
$aeskey=$aesfilecvar['aeskey'];
if ($ui->id('id',10,'get') and (!isset($_SESSION['sID']) or in_array($ui->id('id',10,'get'),$substituteAccess['gs']))) {
$id=$ui->id('id',10,'get');
$id=(int)$ui->id('id',10,'get');
$query=$sql->prepare("SELECT g.`serverip`,g.`port`,g.`rootID`,g.`newlayout`,s.`map`,t.`shorten`,AES_DECRYPT(g.`ftppassword`,?) AS `dftppassword`,u.`cname`,AES_DECRYPT(u.`ftpbackup`,?) AS `ftp` FROM `gsswitch` g LEFT JOIN `serverlist` s ON g.`serverid`=s.`id` LEFT JOIN `servertypes` t ON s.`servertype`=t.`id` LEFT JOIN `userdata` u ON g.`userid`=u.`id` WHERE g.`id`=? AND g.`userid`=? AND g.`resellerid`=? LIMIT 1");
$query->execute(array($aeskey,$aeskey,$id,$user_id,$reseller_id));
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
@ -58,9 +58,7 @@ if ($ui->id('id',10,'get') and (!isset($_SESSION['sID']) or in_array($ui->id('id
$rootid=$row['rootID'];
$ftppass=$row['dftppassword'];
$customer=$row['cname'];
if ($row['newlayout']=='Y') {
$customer=$customer.'-'.$id;
}
if ($row['newlayout']=='Y') $customer=$customer.'-'.$id;
$ftpbackup=$row['ftp'];
}
if ($query->rowCount()==0) redirect('userpanel.php');
@ -76,16 +74,11 @@ if ($ui->id('id',10,'get') and (!isset($_SESSION['sID']) or in_array($ui->id('id
$query=$sql->prepare("SELECT DISTINCT(t.`shorten`) FROM `serverlist` s LEFT JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE s.`switchID`=?");
$query->execute(array($id));
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
if (isset($shortens)) {
$shortens .=" ".$row['shorten'];
} else {
$shortens=$row['shorten'];
}
if (isset($shortens)) $shortens .=" ".$row['shorten'];
else $shortens=$row['shorten'];
}
$webhostdomain=webhostdomain($reseller_id,$sql);
$sshcmd="./control.sh backup $gsfolder \"$shortens\" \"$webhostdomain\" \"$ftpbackup\"";
$ssh_reply=shell_server($sship,$sshport,$sshuser,$sshpass,$customer,$ftppass,$sshcmd,$sql);
$template_file=($ssh_reply=="Could not connect to Server" or $ssh_reply=="The login data does not work") ? "Error: ".$ssh_reply: $template_file=$gsprache->backup." ".$sprache->create;
$template_file=(ssh2_execute('gs',$rootid,"sudo -u $customer ./control.sh backup $gsfolder \"$shortens\" \"$webhostdomain\" \"$ftpbackup\"")===false) ? "Error: ".$ssh_reply: $template_file=$gsprache->backup." ".$sprache->create;
} else if ($ui->w('action',3,'post')=='md'){
$template_file="userpanel_gserver_backup_md.tpl";
} else if ($ui->w('action',3,'post')=='md2') {
@ -118,9 +111,7 @@ if ($ui->id('id',10,'get') and (!isset($_SESSION['sID']) or in_array($ui->id('id
$i++;
}
$webhostdomain=(isset($ui->server['HTTPS'])) ? "https://".$ui->server['HTTP_HOST'].$path : $webhostdomain="http://".$ui->server['HTTP_HOST'].$path;
$sshcmd="./control.sh restore $gsfolder \"".$ui->gamestring('template','post')."\" \"$webhostdomain\" \"$ftpbackup\"";
$ssh_reply=shell_server($sship,$sshport,$sshuser,$sshpass,$customer,$ftppass,$sshcmd,$sql);
$template_file=($ssh_reply=="Could not connect to Server" or $ssh_reply=="The login data does not work") ? "Error: ".$ssh_reply: $template_file=$gsprache->backup." ".$sprache->recover;
$template_file=(ssh2_execute('gs',$rootid,"sudo -u $customer ./control.sh restore $gsfolder \"".$ui->gamestring('template','post')."\" \"$webhostdomain\" \"$ftpbackup\"")===false) ? "Error: ".$ssh_reply: $template_file=$gsprache->backup." ".$sprache->recover;
} else {
$template_file='userpanel_404.tpl';
}

View File

@ -93,13 +93,9 @@ if ($ui->st('d','get')=='ud' and $ui->id('id',19,'get') and (!isset($_SESSION['s
$sshport=$rdata['port'];
$sshuser=$rdata['user'];
$sshpass=$rdata['pass'];
if ($row['newlayout']=='Y') {
$customer=$customer.'-'.$serverid;
}
if ($row['newlayout']=='Y') $customer=$customer.'-'.$serverid;
$serverfolder=$serverip."_"."$port/$shorten$servertemplate";
$sshcmd="screen -dmS $port.sync ./control.sh fastdl $customer $serverfolder \"$ftpupload\" $modfolder";
$reply=shell_server($sship,$sshport,$sshuser,$sshpass,$customer,$ftppass,$sshcmd,$sql);
if($reply=="Could not connect to Server" or $reply=="The login data does not work") {
if(ssh2_execute('gs',$rootid,"sudo -u ${customer} screen -dmS $port.sync ./control.sh fastdl $customer $serverfolder \"$ftpupload\" $modfolder")===false) {
$template_file=$spracheResponse->error_server;
$actionstatus="fail";
} else {

View File

@ -101,15 +101,16 @@ if ($ui->w('action',4,'post') and !token(true)) {
$sshport=$rdata['port'];
$sshuser=$rdata['user'];
$sshpass=$rdata['pass'];
$cmds=array();
if ($ui->active('type','post')=='Y') {
ssh2exec($rootID,'root',$aeskey,"./control.sh add ${customer} ${ftppass} ${sshuser} ".passwordgenerate(10),$sql);
$sshcmd="./control.sh reinstserver ${customer} ${gamestring} ${gsfolder} \"".implode(' ',$template).'"';
$cmds[]="./control.sh add ${customer} ${ftppass} ${sshuser} ".passwordgenerate(10);
$cmds[]="sudo -u ${customer} ./control.sh reinstserver ${customer} ${gamestring} ${gsfolder} \"".implode(' ',$template).'"';
$loguseraction="%reinstall% %gserver% ${serverip}:${port}";
} else {
$sshcmd="./control.sh addserver ${customer} ${gamestring} ${gsfolder} \"".implode(' ',$template).'"';
$cmds[]="sudo -u ${customer} ./control.sh addserver ${customer} ${gamestring} ${gsfolder} \"".implode(' ',$template).'"';
$loguseraction="%resync% %gserver% ${serverip}:${port}";
}
shell_server($sship,$sshport,$sshuser,$sshpass,$customer,$ftppass,$sshcmd,$sql);
ssh2_execute('gs',$rootID,$cmds);
$template_file=$sprache->server_installed;
$insertlog->execute();
} else {

View File

@ -214,9 +214,8 @@ if ($ui->w('action',4,'post') and !token(true)) {
$ftpConnect='ftps://';
}
$ftpConnect.=str_replace('//','/',$ftpAddress.':'.$ftpPort.'/'.$ftpPath);
$sshcmd='./control.sh migrateserver "'.$customer.'" "1_'.$shorten.'" "'.$gsfolder.'" "'.$template.'" "'.$ftpUser.'" "'.$ftpPassword.'" "'.$ftpConnect.'" "'.$modFolder.'"';
ssh2_execute('gs',$rootID,"sudo -u ${customer} ./control.sh migrateserver ${customer} 1_${shorten} ${gsfolder} ${template} ${ftpUser} ${ftpPassword} ${ftpConnect} ${modFolder}");
$loguseraction="%import% %gserver% ${address}";
shell_server($sship,$sshport,$sshuser,$sshpass,$customer,$cftppass,$sshcmd,$sql);
$template_file=$sprache->import_start;
$insertlog->execute();
}