menu();
SE_Layout::dol();
}
private function menu() {
$serversList = $this->fetchActiveLicences();
?>
menu($args['licence_id']);// TODO: GO BACK BTN
try {
$appLicenceInfo = $this->getAppLicenceInfo($args['licence_id']);
} catch (Exception $e) {
$this->_endWithException($e);
}
//$this->generateApp($args['licence_id']);
//DBG::_(true, true, "appLicenceInfo", $appLicenceInfo, __CLASS__, __FUNCTION__, __LINE__);
?>
Generowanie aplikacji dla licencji ID; ?>
Licencja dla domen: domains); ?>
Katalog z zakodowanymi plikami: installFolderName; ?>
installFolderGitExists) : ?>
';
echo '' . "Generowanie..." . '
';
echo '';
try {
$this->generateApp($appLicenceInfo);
} catch (Exception $e) {
echo '
';// .container/ scroll
$this->_endWithException($e);
}
echo '';// .container
?>
Gotowe Aplikacja znajduje się w katalogu installFolderName; ?>
menu($args['licence_id']);// TODO: GO BACK BTN
try {
$appLicenceInfo = $this->getAppLicenceInfo($args['licence_id']);
$this->_gitResetHard($appLicenceInfo);
} catch (Exception $e) {
$this->_endWithException($e);
}
SE_Layout::dol();
}
public function _gitResetHard($appLicenceInfo) {
if (empty($appLicenceInfo->ID)) throw new Exception("Nie wybrano serwera/licencji.");
if (empty($appLicenceInfo->domains)) throw new Exception("Domains not found");
$installPath = $appLicenceInfo->installPath;
if (empty($installPath)) throw new Exception("Install path not found");
$cmds = array();
$cmds[] = "cd {$installPath} && git reset --hard";
$cmds[] = "cd {$installPath} && git pull";
$cmds[] = "cd {$installPath} && echo `git show-ref --head|head -1|head -c 8` > SE/VERSION ";
foreach ($cmds as $cmd) {
$out = ''; $ret = '';
exec($cmd, $out, $ret);
echo'cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'
';
}
}
public function encodeSourceAction() {
session_write_close();
$args = array();
$args['licence_id'] = V::get('licence_id', 0, $_REQUEST, 'int');
SE_Layout::gora();
SE_Layout::menu();
//$this->menu($args['licence_id']);// TODO: GO BACK BTN
try {
$appLicenceInfo = $this->getAppLicenceInfo($args['licence_id']);
$this->_encodeSource($appLicenceInfo);
} catch (Exception $e) {
$this->_endWithException($e);
}
SE_Layout::dol();
}
public function _encodeSource($appLicenceInfo) {
if (empty($appLicenceInfo->ID)) throw new Exception("Nie wybrano serwera/licencji.");
if (empty($appLicenceInfo->domains)) throw new Exception("Domains not found");
$installPath = $appLicenceInfo->installPath;
if (empty($installPath)) throw new Exception("Install path not found");
$phpVersion = '5.5';
if ('1' == V::get('DBG_ENCODER_HELP', '', $_REQUEST)) {// encoder help
$cmd = "cd {$installPath}/SE && /Applications/SourceGuardian.app/Contents/MacOS/sgencoder --help ";
$out = ''; $ret = '';
exec($cmd, $out, $ret);
echo'cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'
';
exit;
}
if (0) {//'1' == V::get('DBG_ENCODER_TEST_IP', '', $_REQUEST)) {
$phpFiles = array();
$phpFiles[] = 't.php';
$cmd = "cd {$installPath}/SE && echo ' t.php ; echo 'echo \"test\\n\";' >> t.php ";
//$cmd = "cd {$installPath}/SE && rm t.php ";
V::exec($cmd, $out, $ret);
DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
$cmd = "cd {$installPath}/SE && /Applications/SourceGuardian.app/Contents/MacOS/sgencoder --phpversion {$phpVersion} -b- ";
//$mac = '38:c9:86:31:80:77';
//$cmd .= " --mac {$mac}";
foreach ($appLicenceInfo->domains as $domain) {
$cmd .= " --domain {$domain} ";
}
$cmd .= " " . implode(" ", $phpFiles);
V::exec($cmd, $out, $ret);
DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
if (0 !== $ret) throw new Exception("Error at encode files");
if (empty($out)) throw new Exception("No output for encode files command");
exit;
}
{
$phpFiles = array();
$skipPhpFiles = array();
$skipPhpFiles[] = 'bash_sync_perms.php';
$skipPhpFiles[] = '.config.php';
$skipPhpFiles[] = 'se-lib/V.php';
$skipPhpFiles[] = 'se-lib/Lib.php';
$skipPhpFiles[] = 'se-lib/DB.php';
$skipPhpFiles[] = 'se-lib/User.php';
$skipPhpFiles[] = 'se-lib/UserProfile.php';
$skipPhpFiles[] = 'se-lib/Config.php';
$skipPhpFiles[] = 'se-lib/Config/INI.php';
$skipPhpFiles[] = 'se-lib/FoldersConfig.php';
$skipPhpFiles[] = 'se-lib/FileUploader.php';
$skipPhpFiles[] = 'se-lib/Route/Budget.php';
$skipPhpFiles[] = 'se-lib/Route/FixCrmProcesInitIdx.php';
$skipPhpFiles[] = 'se-lib/Route/FixProjectPath.php';
$skipPhpFiles[] = 'se-lib/Route/FixZasobPath.php';
//$skipPhpFiles[] = 'se-lib/Route/Install.php';
$skipPhpFiles[] = 'se-lib/Route/Msgs.php';
$skipPhpFiles[] = 'superedit-DB_PROCEDURES_CREATE.php';
//$skipPhpFiles[] = '';
$skipPhpFiles[] = 'se-lib/DataSourceException.php';
$skipPhpFiles[] = 'se-lib/Core/Pdo.php';
$skipPhpFiles[] = 'se-lib/Cron.php';
$skipPhpFiles[] = 'se-lib/Router.php';
$skipPhpFiles[] = 'se-lib/RouteBase.php';
$skipPhpFiles[] = 'se-lib/HttpException.php';
$skipPhpFiles[] = 'se-lib/DebugExecutionTime.php';
$cmd = "cd {$installPath}/SE && find . -name '*.php' ";
$out = ''; $ret = '';
exec($cmd, $out, $ret);
echo'cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'
';
if (0 !== $ret) throw new Exception("Error at find php files");
if (empty($out)) throw new Exception("No php files found");
foreach ($out as $phpFilePath) {
$phpFilePath = ('./' == substr($phpFilePath, 0, 2))? substr($phpFilePath, 2) : $phpFilePath;
if (in_array($phpFilePath, $skipPhpFiles)) continue;
if ('schema/' == substr($phpFilePath, 0, 7)) continue;
$phpFiles[] = $phpFilePath;
}
DBG::_(true, true, 'phpFiles', $phpFiles, __CLASS__, __FUNCTION__, __LINE__);
if (empty($phpFiles)) throw new Exception("No php files to encode");
}
{
$cmd = "cd {$installPath}/SE && /Applications/SourceGuardian.app/Contents/MacOS/sgencoder --phpversion {$phpVersion} -b- ";
foreach ($appLicenceInfo->domains as $domain) {
$cmd .= " --domain {$domain} ";
}
$cmd .= " " . implode(" ", $phpFiles);
$out = ''; $ret = '';
exec($cmd, $out, $ret);
echo'cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'
';
if (0 !== $ret) throw new Exception("Error at encode files");
if (empty($out)) throw new Exception("No output for encode files command");
}
}
public function getAppLicenceInfo($idLicence) {
$idLicence = intval($idLicence);
if (empty($idLicence)) throw new Exception("Nie wybrano serwera/licencji.");
//DBG::_(true, true, 'idLicence', $idLicence, __CLASS__, __FUNCTION__, __LINE__);
$appLicenceInfo = (object)$this->fetchAppLicenceInfo($idLicence);
$appLicenceInfo->domains = $this->fetchDomainsByLicenceId($idLicence);
$installRootPath = '/Library/Server/Web/Data/Sites/Default/PLIKI/SES_PROCESY5_A';
$appLicenceInfo->installFolderName = "{$idLicence}_upgrade_SE_source_encrypted";
$appLicenceInfo->installPath = "{$installRootPath}/{$appLicenceInfo->installFolderName}";
//DBG::_(true, true, 'appLicenceInfo', $appLicenceInfo, __CLASS__, __FUNCTION__, __LINE__);
if (empty($appLicenceInfo->domains)) throw new Exception("Domains not found.");
$appLicenceInfo->installFolderExists = file_exists("{$appLicenceInfo->installPath}/SE");
$appLicenceInfo->installFolderGitExists = file_exists("{$appLicenceInfo->installPath}/.git");
return $appLicenceInfo;
}
public function generateApp($appLicenceInfo) {
if (empty($appLicenceInfo->ID)) throw new Exception("Nie wybrano serwera/licencji.");
if (empty($appLicenceInfo->domains)) throw new Exception("Domains not found");
$installPath = $appLicenceInfo->installPath;
if (empty($installPath)) throw new Exception("Install path not found");
$cmds = array();
$cmds[] = "if [ -d {$installPath} ] ; then rm -rf '{$installPath}'; fi";
$cmds[] = "mkdir {$installPath}";
$cmds[] = "cd {$installPath} && git clone ssh://git@biuro.biall-net.pl:2222/plabudda/se.git .";
$cmds[] = "cd {$installPath} && echo `git show-ref --head|head -1|head -c 8` > SE/VERSION ";
//echo'cmds: ';print_r($cmds);echo'
';
foreach ($cmds as $cmd) {
$out = ''; $ret = '';
exec($cmd, $out, $ret);
echo'cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'
';
}
$this->_encodeSource($appLicenceInfo);
// 1763: $exec='cd '.$installer_dir.' && /Applications/SourceGuardian.app/Contents/MacOS/sgencoder -b-
// '.INSTALL_SES_PROCESY_A::get_same_domains_for_install($h->SERVER_ADDRESS_SHORT).'
// -r *.php
// -x superedit-DB_PROCEDURES_CREATE.php
// -x INI.php
// -x .config_base_structure.php
// ';
//
// INSTALL_SES_PROCESY_A::get_same_domains_for_install($h->SERVER_ADDRESS_SHORT):
// $res2=DB::query("select SERVER_ADDRESS_SHORT from SES_PROCESY5_A where SERVER_ADDRESS_IP='".$h->SERVER_ADDRESS_IP."'");
// while($h2=DB::fetch($res2)) {
// $domain[]=' --domain '.$h2->SERVER_ADDRESS_SHORT;
// ssh server@biuro.galeriaprzymorze.eu: PHP 5.5.20
// ssh server@biuro.biall-net.pl
// cd /Users/plabudda/procesy5-install-galeriaprzymorze.eu/
// sudo chown -R server:admin SE/
// /Applications/SourceGuardian.app/Contents/MacOS/sgencoder --phpversion 5.5 -b- --domain galeriaprzymorze.eu -r SE/*.php SE/se-lib/*.php SE/se-lib/*/*.php SE/se-lib/*/*/*.php SE/procesy/*.php SE/odt2xhtml/*.php -x superedit-DB_PROCEDURES_CREATE.php -x INI.php -x .config_base_structure.php
}
public function fetchActiveLicences() {
$activeLic = array();
$db = DB::getDB();
$sql = "select l.`ID`
, l.`SERVER_ADDRESS`
, l.`SERVER_ADDRESS_SHORT` as domain -- domain for sgencoder
, l.`SERVER_ADDRESS_IP`
from `SES_PROCESY5_A` l
where 1=1
-- TODO: and l.`A_STATUS` in('NORMAL','WAITING')
order by l.`ID` DESC
";
$res = $db->query($sql);
while ($r = $db->fetch($res)) {
$activeLic[$r->ID] = $r;
}
return $activeLic;
}
public function fetchDomainsByLicenceId($licenceId) {
$domains = array();
$db = DB::getDB();
$sql = "select g.`SERVER_ADDRESS_SHORT`, g.`SERVER_ADDRESS`
from `SES_PROCESY5_A` g
where g.`SERVER_ADDRESS_IP`=(select l.`SERVER_ADDRESS_IP`
from `SES_PROCESY5_A` l
where l.`ID`='{$licenceId}'
-- TODO: and l.`A_STATUS` in('NORMAL','WAITING')
)
-- TODO: and g.`A_STATUS` in('NORMAL','WAITING')
";
$res = $db->query($sql);
while ($r = $db->fetch($res)) {
$domains[] = $r->SERVER_ADDRESS_SHORT;
if ($r->SERVER_ADDRESS != $r->SERVER_ADDRESS_SHORT) {
$domains[] = $r->SERVER_ADDRESS;
}
}
return $domains;
}
public function fetchMainServerByLicenceId($licenceId) {
$mainServer = null;
$db = DB::getDB();
$sql = "select g.`SERVER_ADDRESS`
from `SES_PROCESY5_A` g
where g.`ID`='{$licenceId}'
-- TODO: and g.`A_STATUS` in('NORMAL','WAITING')
";
$res = $db->query($sql);
while ($r = $db->fetch($res)) {
$mainServer = $r->SERVER_ADDRESS;
}
return $mainServer;
}
public function fetchAppLicenceInfo($licenceId) {
$licenceInfo = null;
$sth = DB::getPDO()->prepare("
select g.ID
, g.SERVER_ADDRESS as mainServer
, g.ADMIN_USERNAME as rootLogin
, g.ADMIN_USERNAME_PASSWD as rootPassword
, g.SSH_PORT as sshPort
from SES_PROCESY5_A g
where g.`ID`=:id_licence
-- TODO: and g.A_STATUS in('NORMAL','WAITING')
");
$sth->bindValue('id_licence', $licenceId, PDO::PARAM_INT);
$sth->execute();
$all = $sth->fetchAll();
if (empty($all)) throw new Exception("Brak licencji o nr '{$licenceId}'");
$licenceInfo = reset($all);
if (!$licenceInfo['sshPort']) $licenceInfo['sshPort'] = 22;
return $licenceInfo;
}
public function _endWithException($e) {
?>
#getLine(); ?>: getMessage(); ?>
Wróć do menu
menu($args['licence_id']);// TODO: GO BACK BTN
try {
$appLicenceInfo = $this->getAppLicenceInfo($args['licence_id']);
$this->_sendToRemoteTestDir($appLicenceInfo);
?>
Test online: https://mainServer; ?>/se.encrypted.upgrade/
_endWithException($e);
}
SE_Layout::dol();
}
public function _fetchRemoteHomeDir($appLicenceInfo) {
$this->_assertRsaKeyExists($appLicenceInfo);
$sshHostUsr = "{$appLicenceInfo->rootLogin}@{$appLicenceInfo->mainServer}";
$sshArgs = (22 != $appLicenceInfo->sshPort)? "-p {$appLicenceInfo->sshPort}" : '';
$rsyncSshPort = (22 != $appLicenceInfo->sshPort)? "-e 'ssh -p {$appLicenceInfo->sshPort}'" : '';
if (V::get('DBG_REMOTE', '', $_GET)) {// DBG
$cmd = "echo ~";
V::exec("ssh {$sshArgs} {$sshHostUsr} '{$cmd}'", $out, $ret);
DBG::_(true, true, "exec(ssh ... 'cmd'): {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
V::execRemote($appLicenceInfo->mainServer, $appLicenceInfo->rootLogin, $appLicenceInfo->rootPassword, $cmd, $out, $ret, $appLicenceInfo->sshPort);
DBG::_(true, true, "execRemote(cmd): {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
V::execRootRemote($appLicenceInfo->mainServer, $appLicenceInfo->rootLogin, $appLicenceInfo->rootPassword, $cmd, $out, $ret, $appLicenceInfo->sshPort);
DBG::_(true, true, "execRootRemote(cmd): {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
}
$cmd = "echo ~";
V::exec("ssh {$sshArgs} {$sshHostUsr} '{$cmd}'", $out, $ret);
DBG::_(true, true, "exec(ssh ... '{$cmd}') (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
if (empty($out) || empty($out[0])) throw new Exception("Cannot fetch remote home dir");
return $out[0];
}
public function _sendToRemoteTestDir($appLicenceInfo) {
$cmd = ''; $out = ''; $ret = '';
$this->_assertRsaKeyExists($appLicenceInfo);
$sshHostUsr = "{$appLicenceInfo->rootLogin}@{$appLicenceInfo->mainServer}";
$sshArgs = (22 != $appLicenceInfo->sshPort)? "-p {$appLicenceInfo->sshPort}" : '';
$rsyncSshPort = (22 != $appLicenceInfo->sshPort)? "-e 'ssh -p {$appLicenceInfo->sshPort}'" : '';
// $appLicenceInfo->sshPort
/* rsync options:
-a, --archive archive mode; same as -rlptgoD (no -H)
-u, --update skip files that are newer on the receiver
-t, --times preserve times
--delete delete extraneous files from dest dirs
*/
DBG::_(true, true, "remote home dir:", $this->_fetchRemoteHomeDir($appLicenceInfo), __CLASS__, __FUNCTION__, __LINE__);
$cmd = "
ssh {$sshArgs} {$sshHostUsr} '[ ! -d ~/se.encrypted.upgrade ] && mkdir ~/se.encrypted.upgrade || echo 1';
ssh {$sshArgs} {$sshHostUsr} 'rm -rf ~/se.encrypted.upgrade/SE';
ssh {$sshArgs} {$sshHostUsr} 'cp -r /Library/Server/Web/Data/Sites/Default/SE ~/se.encrypted.upgrade/SE';
ssh {$sshArgs} {$sshHostUsr} 'rm -rf ~/se.encrypted.upgrade/SE/config';
rsync --archive --times --delete --compress --one-file-system --omit-dir-times --no-g --no-perms \
--verbose {$rsyncSshPort} \
--exclude='stuff/qgis__kyngchaos.com' \
--exclude='stuff/qgis__kyngchaos.com/QGIS-2.14.3-1.dmg' \
'{$appLicenceInfo->installPath}/SE/' {$sshHostUsr}:~/se.encrypted.upgrade/SE/;
ssh {$sshArgs} {$sshHostUsr} 'cp -r /Library/Server/Web/Data/Sites/Default/SE/config ~/se.encrypted.upgrade/SE/';
ssh {$sshArgs} {$sshHostUsr} 'rm /Library/Server/Web/Data/Sites/Default/se.encrypted.upgrade'
ssh {$sshArgs} {$sshHostUsr} 'ln -s ~/se.encrypted.upgrade/SE /Library/Server/Web/Data/Sites/Default/se.encrypted.upgrade'
";
// --dry-run \
V::exec($cmd, $out, $ret);
DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
if (0 !== $ret) throw new Exception("Cannot run remote command using rsa key! #{$ret}");
}
public function upgradeRemoteFromTestDirAction() {
session_write_close();
$args = array();
$args['licence_id'] = V::get('licence_id', 0, $_REQUEST, 'int');
SE_Layout::gora();
//SE_Layout::menu();
//$this->menu($args['licence_id']);// TODO: GO BACK BTN
try {
$appLicenceInfo = $this->getAppLicenceInfo($args['licence_id']);
$this->_upgradeRemoteFromTestDir($appLicenceInfo);
?>
Test online: https://mainServer; ?>/SE/
_endWithException($e);
}
SE_Layout::dol();
}
public function _upgradeRemoteFromTestDir($appLicenceInfo) {
$cmd = ''; $out = ''; $ret = '';
$this->_assertRsaKeyExists($appLicenceInfo);
$dateStr = date("Y-m-d_H-i-s");
// $remoteHomeDir = "/Users/{$appLicenceInfo->rootLogin}";// BUG: alias like in ams - login = prezes is alias for arkadiuszbinder
$remoteHomeDir = $this->_fetchRemoteHomeDir($appLicenceInfo);
$cmd = "
rm -rf /Library/Server/Web/Data/Sites/Default/SE.test 2>&1
cp -r {$remoteHomeDir}/se.encrypted.upgrade/SE /Library/Server/Web/Data/Sites/Default/SE.test 2>&1
[ ! -d {$remoteHomeDir}/bup.se.upgrade ] && mkdir {$remoteHomeDir}/bup.se.upgrade || echo 1
[ ! -d {$remoteHomeDir}/bup.se.upgrade ] && exit 1
[ ! -d {$remoteHomeDir}/bup.se.upgrade-testttttt ] && exit 1
[ ! -f /Library/Server/Web/Data/Sites/Default/SE.test/VERSION ] && echo \"Error: plik VERSION nie istnieje\" || echo \"check VERSION OK\"
[ ! -f /Library/Server/Web/Data/Sites/Default/SE.test/VERSION ] && exit 1
[ ! -f /Library/Server/Web/Data/Sites/Default/SE.test/index.php ] && echo \"Error: plik index.php nie istnieje\" || echo \"check index.php OK\"
[ ! -f /Library/Server/Web/Data/Sites/Default/SE.test/index.php ] && exit 1
[ ! -d /Library/Server/Web/Data/Sites/Default/SE.test/se-lib ] && echo \"Error: plik se-lib nie istnieje\" || echo \"check se-lib OK\"
[ ! -d /Library/Server/Web/Data/Sites/Default/SE.test/se-lib ] && exit 1
exit 0
";
V::execRootRemote($appLicenceInfo->mainServer, $appLicenceInfo->rootLogin, $appLicenceInfo->rootPassword, $cmd, $out, $ret, $appLicenceInfo->sshPort);
$cmd = "
mv /Library/Server/Web/Data/Sites/Default/SE {$remoteHomeDir}/bup.se.upgrade/bup.{$dateStr} 2>&1
mv /Library/Server/Web/Data/Sites/Default/SE.test /Library/Server/Web/Data/Sites/Default/SE 2>&1
exit 0
";
V::execRootRemote($appLicenceInfo->mainServer, $appLicenceInfo->rootLogin, $appLicenceInfo->rootPassword, $cmd, $out, $ret, $appLicenceInfo->sshPort);
DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
if (0 !== $ret) throw new Exception("Cannot run remote command as root! #{$ret}");
}
public function _assertRsaKeyExists($appLicenceInfo) {
$cmd = ''; $out = ''; $ret = '';
$cmd = "echo ~ && pwd";// /Library/WebServer
$cmd = "ls -1 ~/.ssh/";
//$cmd = "rm /tmp/id_rsa";
//$cmd = "rm /tmp/id_rsa.pub";
//$cmd = "ssh-keygen -t rsa -N '' -C '_www@biuro.biall-net.pl' -f /tmp/id_rsa";
//$cmd = "ssh-keygen -t rsa -N '' -C '_www@biuro.biall-net.pl' -f /tmp/id_rsa";
V::exec($cmd, $out, $ret);
DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
if (0 !== $ret) {// no ~/.ssh directory
$rsaKeyPath = "~/.ssh";
$cmds = array();
$cmds[] = "mkdir {$rsaKeyPath}";
$cmds[] = "ssh-keygen -t rsa -N '' -C '_www@biuro.biall-net.pl' -f {$rsaKeyPath}/id_rsa 2>&1";
$cmds[] = "ls -1 $rsaKeyPath";
foreach ($cmds as $cmd) {
V::exec($cmd, $out, $ret);
DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
if (0 !== $ret) throw new Exception("Error '{$ret}' cmd({$cmd}): " . implode("\n", $out));
}
}
$cmd = "cat ~/.ssh/id_rsa.pub";
V::exec($cmd, $out, $ret);
DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
if (0 !== $ret || empty($out) || empty($out[0])) throw new Exception("Cannot read rsa public key");
$rsaPubKey = $out[0];
$cmd = 'ls -1a';
$cmd = "
[ ! -d ~/.ssh ] && mkdir ~/.ssh;
[ ! -d ~/.ssh ] && echo 'ERROR ~/.ssh not exists and cannot be created';
[ ! -f ~/.ssh/authorized_keys ] && echo '{$rsaPubKey}' > ~/.ssh/authorized_keys;
[ ! -f ~/.ssh/authorized_keys ] && echo 'ERROR ~/.ssh/authorized_keys not exists and cannot be created';
cat ~/.ssh/authorized_keys| grep '{$rsaPubKey}' && echo 'OK' || echo '{$rsaPubKey}' >> ~/.ssh/authorized_keys;
chmod 600 ~/.ssh/authorized_keys;
";
V::execRemote($appLicenceInfo->mainServer, $appLicenceInfo->rootLogin, $appLicenceInfo->rootPassword, $cmd, $out, $ret, $appLicenceInfo->sshPort);
DBG::_(true, true, "remote cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
//$cmd = "ssh server@{$appLicenceInfo->mainServer} 'ls -1 .ssh/'";
//$cmd = "ssh -i ~/.ssh/id_rsa server@{$appLicenceInfo->mainServer} 'ls -1'";
$sshPort = (22 != $appLicenceInfo->sshPort)? "-p {$appLicenceInfo->sshPort}" : '';
$cmd = "ssh {$sshPort} {$appLicenceInfo->rootLogin}@{$appLicenceInfo->mainServer} 'ls -1'";
V::exec($cmd, $out, $ret);
DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
if (0 !== $ret) throw new Exception("Cannot run remote command using rsa key! #{$ret}");
}
}