Ticket 70 cut ".pub" in case user added it

https://github.com/easy-wi/developer/issues/70
This commit is contained in:
Ulrich Block 2013-09-22 12:00:33 +02:00
parent cd55e416b9
commit 56388ce517
8 changed files with 69 additions and 32 deletions

View File

@ -129,9 +129,14 @@ if (!isset($ip) or $_SERVER['SERVER_ADDR']==$ip) {
$tsdnsExternalActive=true;
}
}
$ssh2=false;
if ($row2['publickey']=='Y') {
$pubkey="keys/".$row2['keyname'].".pub";
$key="keys/".$row2['keyname'];
# https://github.com/easy-wi/developer/issues/70
$sshkey=removePub($row2['keyname']);
$pubkey=EASYWIDIR.'/keys/'.$sshkey.'.pub';
$key=EASYWIDIR.'/keys/'.$sshkey;
if (file_exists($pubkey) and file_exists($key)) {
$ssh2= @ssh2_connect($queryip,$row2['decryptedssh2port'],array('hostkey'=>'ssh-rsa'));
}
@ -139,20 +144,12 @@ if (!isset($ip) or $_SERVER['SERVER_ADDR']==$ip) {
$ssh2= @ssh2_connect($queryip,$row2['decryptedssh2port']);
}
if ($ssh2) {
if ($row2['publickey']=='Y') {
$connect_ssh2= @ssh2_auth_pubkey_file($ssh2,$row2['decryptedssh2user'],$pubkey,$key);
} else {
$connect_ssh2= @ssh2_auth_password($ssh2,$row2['decryptedssh2user'],$row2['decryptedssh2password']);
}
$connect_ssh2=($row2['publickey']=='Y') ? @ssh2_auth_pubkey_file($ssh2,$row2['decryptedssh2user'],$pubkey,$key) : @ssh2_auth_password($ssh2,$row2['decryptedssh2user'],$row2['decryptedssh2password']);
if ($connect_ssh2) {
$split_config=preg_split('/\//',$row2['serverdir'], -1, PREG_SPLIT_NO_EMPTY);
$folderfilecount=count($split_config)-1;
$i=0;
if (substr($row2['serverdir'],0,1)=='/') {
$folders='cd /';
} else {
$folders='cd ';
}
$folders= (substr($row2['serverdir'],0,1)=='/') ? 'cd /' : 'cd ';
while ($i<=$folderfilecount) {
$folders=$folders.$split_config[$i]."/";
$i++;
@ -170,7 +167,7 @@ if (!isset($ip) or $_SERVER['SERVER_ADDR']==$ip) {
$badLogin=true;
print "Error: Can not connect via ssh2\r\n";
}
if (!isset($badLogin) and $connect_ssh2) {
if (!isset($badLogin) and isset($connect_ssh2) and $connect_ssh2) {
$tsdown=false;
$tsdnsdown=false;
$connection=new TS3($queryip,$queryport,'serveradmin',$querypassword);

View File

@ -568,13 +568,16 @@ if (!isset($ip) or $_SERVER['SERVER_ADDR']==$ip) {
} else {
$tsdnsbin='tsdnsserver_linux_amd64';
}
$ssh2_2=false;
if ($row['publickey']=='Y') {
$pubkey="keys/".$row['keyname'].".pub";
$key="keys/".$row['keyname'];
# https://github.com/easy-wi/developer/issues/70
$sshkey=removePub($row['keyname']);
$pubkey='keys/'.$sshkey.'.pub';
$key='keys/'.$sshkey;
if (file_exists($pubkey) and file_exists($key)) {
$ssh2_2= ssh2_connect($row['ssh2ip'],$row['decryptedssh2port'],array('hostkey'=>'ssh-rsa'));
} else {
$ssh2_2=false;
}
} else {
$ssh2_2=ssh2_connect($row['ssh2ip'],$row['decryptedssh2port']);
@ -697,8 +700,12 @@ if (!isset($ip) or $_SERVER['SERVER_ADDR']==$ip) {
$pupdate->execute(array($ts3masternotified,$ts3masterid));
if (($autorestart=='Y' and $ts3masternotified>=$resellersettings[$resellerid]['down_checks']) or ($tsdown!=true and $tsdnsdown==true)) {
if ($vrow['publickey']=="Y") {
$pubkey="keys/".$vrow['keyname'].".pub";
$key="keys/".$vrow['keyname'];
# https://github.com/easy-wi/developer/issues/70
$sshkey=removePub($vrow['keyname']);
$pubkey=EASYWIDIR.'/keys/'.$sshkey.'.pub';
$key=EASYWIDIR.'/keys/'.$sshkey;
$ssh2=(file_exists($pubkey) and file_exists($key)) ? @ssh2_connect($queryip,$vrow['decryptedssh2port'],array('hostkey'=>'ssh-rsa')) : false;
} else {
$ssh2= @ssh2_connect($queryip,$vrow['decryptedssh2port']);

View File

@ -256,8 +256,12 @@ class rootServer {
$i=0;
unset($tempBad);
if ($v['publickey']=="Y") {
$pubkey=EASYWIDIR."/keys/".$v['keyname'].".pub";
$key=EASYWIDIR."/keys/".$v['keyname'];
# https://github.com/easy-wi/developer/issues/70
$sshkey=removePub($v['keyname']);
$pubkey=EASYWIDIR.'/keys/'.$sshkey.'.pub';
$key=EASYWIDIR.'/keys/'.$sshkey;
$ssh2=(file_exists($pubkey) and file_exists($key)) ? @ssh2_connect($v['ip'],$v['port'],array('hostkey'=>'ssh-rsa')) : false;
} else {
$ssh2= @ssh2_connect($v['ip'],$v['port']);
@ -314,8 +318,12 @@ class rootServer {
public function PXEFiles() {
foreach($this->PXEData as $k=>$v) {
if ($v['publickey']=="Y") {
$pubkey=EASYWIDIR."/keys/".$v['keyname'].".pub";
$key=EASYWIDIR."/keys/".$v['keyname'];
# https://github.com/easy-wi/developer/issues/70
$sshkey=removePub($v['keyname']);
$pubkey=EASYWIDIR.'/keys/'.$sshkey.'.pub';
$key=EASYWIDIR.'/keys/'.$sshkey;
$ssh2=(file_exists($pubkey) and file_exists($key)) ? @ssh2_connect($v['ip'],$v['port'],array('hostkey'=>'ssh-rsa')) : false;
} else {
$ssh2= @ssh2_connect($v['ip'],$v['port']);
@ -444,8 +452,12 @@ class rootServer {
public function VMWare(){
foreach ($this->vmwareHosts as $hID =>$h) {
if ($this->vmwareHosts[$hID]['vmIDs']['publickey']=='Y') {
$pubkey=EASYWIDIR."/keys/".$this->vmwareHosts[$hID['hostID']]['vmIDs']['keyname'].".pub";
$key=EASYWIDIR."/keys/".$this->vmwareHosts[$hID['hostID']]['vmIDs']['keyname'];
# https://github.com/easy-wi/developer/issues/70
$sshkey=removePub($this->vmwareHosts[$hID['hostID']]['vmIDs']['keyname']);
$pubkey=EASYWIDIR.'/keys/'.$sshkey.'.pub';
$key=EASYWIDIR.'/keys/'.$sshkey;
$ssh2=(file_exists($pubkey) and file_exists($key)) ? @ssh2_connect($this->vmwareHosts[$hID]['vmIDs']['ip'],$this->vmwareHosts[$hID]['vmIDs']['dport'],array('hostkey'=>'ssh-rsa')) : false;
} else {
$ssh2=@ssh2_connect($this->vmwareHosts[$hID]['vmIDs']['ip'],$this->vmwareHosts[$hID]['vmIDs']['dport']);

View File

@ -587,8 +587,11 @@ class TS3 {
function tsbackup ($action,$sship,$sshport,$sshuser,$keyuse,$sshkey,$sshpw,$notified,$path,$virtualserver_id,$backupid,$reseller_id,$sql,$move=array()) {
if ($keyuse=="Y") {
$pubkey=EASYWIDIR."/keys/".$sshkey.".pub";
$key=EASYWIDIR."/keys/".$sshkey;
# https://github.com/easy-wi/developer/issues/70
$sshkey=removePub($sshkey);
$pubkey=EASYWIDIR.'/keys/'.$sshkey.'.pub';
$key=EASYWIDIR.'/keys/'.$sshkey;
if (file_exists($pubkey) and file_exists($key)) {
$ssh2= @ssh2_connect($sship,$sshport,array('hostkey'=>'ssh-rsa'));
} else {

View File

@ -1335,4 +1335,12 @@ function workAroundForValveChaos ($appID,$shorten,$toApi=true) {
}
}
return $appID;
}
# https://github.com/easy-wi/developer/issues/70
function removePub ($string) {
if (substr(strtolower($string), -4) == '.pub') {
return substr($string, 0, -4);
}
return $string;
}

View File

@ -56,8 +56,12 @@ if (!function_exists('ssh2_execute')) {
$ssh2User=$row['decrypteduser'];
$ssh2Pass=$row['decryptedpass'];
$ssh2Publickey=$row['publickey'];
$pubkey=EASYWIDIR."/keys/${row['keyname']}.pub";
$key=EASYWIDIR."/keys/${row['keyname']}";
# https://github.com/easy-wi/developer/issues/70
$sshkey=removePub($row['keyname']);
$pubkey=EASYWIDIR.'/keys/'.$sshkey.'.pub';
$key=EASYWIDIR.'/keys/'.$sshkey;
$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);

View File

@ -78,7 +78,9 @@ if ($ui->w('action',4,'post') and !token(true)) {
if ($row['newlayout']=='Y') $customer=$customer.'-'.$row['id'];
}
$template=array();
foreach($ui->id('template',10,'post') as $id => $tpl) {
# https://github.com/easy-wi/developer/issues/69
$templates = (array) $ui->id('template',10,'post');
foreach($templates as $id => $tpl) {
if ($tpl>0) {
$template[]=$tpl;
if ($ui->active('type','post')=='Y') {

View File

@ -449,8 +449,12 @@ if ($ui->w('action',4,'post') and !token(true)) {
}
if (($oldactive=='Y' and $active=='N') or ($oldactive=='N' and $active=='Y')) {
if ($row['publickey']=="Y") {
$pubkey=EASYWIDIR."/keys/".$row['keyname'].".pub";
$key=EASYWIDIR."/keys/".$row['keyname'];
# https://github.com/easy-wi/developer/issues/70
$sshkey=removePub($row['keyname']);
$pubkey=EASYWIDIR.'/keys/'.$sshkey.'.pub';
$key=EASYWIDIR.'/keys/'.$sshkey;
if (file_exists($pubkey) and file_exists($key)) {
$ssh2= @ssh2_connect($queryip,$row['decryptedssh2port'],array('hostkey'=>'ssh-rsa'));
} else {