| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- <?php
- Lib::loadClass('RouteBase');
- class Route_Install extends RouteBase {
- public function handleAuth() {
- if (!User::logged()) {
- throw new HttpException('Unauthorized', 401);
- }
- if (!User::isAdmin()) {
- throw new HttpException('Unauthorized - only for administrators', 401);
- }
- }
- public function defaultAction() {
- SE_Layout::gora();
- SE_Layout::menu();
- $this->menu();
- SE_Layout::dol();
- }
- private function menu() {
- $serversList = $this->fetchActiveLicences();
- ?>
- <div class="jumbotron">
- <div class="container">
- <form class="form-inline" method="GET">
- <input type="hidden" name="_route" value="Install" />
- <input type="hidden" name="_task" value="createApp" />
- <label>Przygotuj kod źródłowy do aktualizacji na serwerze klienta:</label>
- <select class="form-control" name="licence_id">
- <?php foreach ($serversList as $srv) : ?>
- <option value="<?php echo $srv->ID; ?>">[<?php echo $srv->ID; ?>] <?php echo $srv->domain; ?></option>
- <?php endforeach; ?>
- </select>
- <button type="submit" id="fldSbmtBtn" class="btn btn-primary" autocomplete="off">
- Generuj
- </button>
- </form>
- </div>
- </div>
- <script type="text/javascript">
- jQuery(document).ready(function () {
- jQuery('#fldSbmtBtn').on('click', function () {
- jQuery(this).text(jQuery(this).text() + '...').attr('disabled', 'disabled');
- jQuery(this).parent().submit();
- })
- });
- </script>
- <?php
- }
- public function createAppAction() {
- $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']);
- } catch (Exception $e) {
- $this->_endWithException($e);
- }
- //$this->generateApp($args['licence_id']);
- //DBG::_(true, true, "appLicenceInfo", $appLicenceInfo, __CLASS__, __FUNCTION__, __LINE__);
- ?>
- <div class="jumbotron">
- <div class="container">
- <h3>Generowanie aplikacji dla licencji <?php echo $appLicenceInfo->ID; ?></h3>
- <p>Licencja dla domen: <?php echo implode(', ', $appLicenceInfo->domains); ?></p>
- <p>Katalog z zakodowanymi plikami: <?php echo $appLicenceInfo->installFolderName; ?></p>
- <form class="form-inline" method="POST">
- <input type="hidden" name="_task" value="createApp" />
- <input type="hidden" name="licence_id" value="<?php echo $appLicenceInfo->ID; ?>" />
- <input type="hidden" name="_generateEncryptedSource" value="1" />
- <button type="submit" id="fldSbmtBtn" class="btn btn-primary" autocomplete="off">
- Generuj
- </button>
- </form>
- <?php if ($appLicenceInfo->installFolderGitExists) : ?>
- <br>
- <div class="alert alert-info">
- Katalog istnieje i zawiera już repozytorium git:
- <br> - <a href="index.php?_route=Install&_task=gitResetHard&licence_id=<?php echo $appLicenceInfo->ID; ?>"
- target="_blank"
- class="btn btn-xs btn-default">aktualizuj werjsę</a> (git reset --hard, git pull, set SE/VERSION - tak samo co 'rm -rf; git clone', ale szybciej)
- <br> - <a href="index.php?_route=Install&_task=encodeSource&licence_id=<?php echo $appLicenceInfo->ID; ?>"
- target="_blank"
- class="btn btn-xs btn-default">encode files</a>
- <br> - <a href="index.php?_route=Install&_task=sendToRemoteTestDir&licence_id=<?php echo $appLicenceInfo->ID; ?>"
- target="_blank"
- class="btn btn-xs btn-default">send encoded files to remote server test folder (generates ssh key if not set)</a>
- <p style="margin-top:30px">
- Test online: <a target="_blank" href="https://<?php echo $appLicenceInfo->mainServer; ?>/se.encrypted.upgrade/">https://<?php echo $appLicenceInfo->mainServer; ?>/se.encrypted.upgrade/</a>
- </p>
- <br> - <a href="index.php?_route=Install&_task=upgradeRemoteFromTestDir&licence_id=<?php echo $appLicenceInfo->ID; ?>"
- target="_blank"
- class="btn btn-xs btn-warning">UPGRADE Production folder from uploaded dir: ~/se.encrypted.upgrade/</a>
- </div>
- <?php endif; ?>
- </div>
- </div>
- <script type="text/javascript">
- jQuery(document).ready(function () {
- jQuery('#fldSbmtBtn').on('click', function () {
- jQuery(this).text(jQuery(this).text() + '...').attr('disabled', 'disabled');
- jQuery(this).parent().submit();
- })
- });
- </script>
- <?php
- $generateEncryptedSource = (1 == V::get('_generateEncryptedSource', 0, $_REQUEST, 'int'));
- if ($generateEncryptedSource) {
- echo '<div class="container">';
- echo '<h4>' . "Generowanie..." . '</h4>';
- echo '<div style="border:1px solid silver; max-height:400px; overflow-y:scroll">';
- try {
- $this->generateApp($appLicenceInfo);
- } catch (Exception $e) {
- echo '</div></div>';// .container/ scroll
- $this->_endWithException($e);
- }
- echo '</div>';// .container
- ?>
- <div class="alert alert-success">
- <strong>Gotowe</strong> Aplikacja znajduje się w katalogu <?php echo $appLicenceInfo->installFolderName; ?>
- </div>
- <?php
- }
- SE_Layout::dol();
- }
- public function gitResetHardAction() {
- $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->_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'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
- }
- }
- public function encodeSourceAction() {
- $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'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
- 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/Router.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'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
- 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);
- 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'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
- 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 git@biuro.biall-net.pl:plabudda/se.git .";
- $cmds[] = "cd {$installPath} && echo `git show-ref --head|head -1|head -c 8` > SE/VERSION ";
- //echo'<pre>cmds: ';print_r($cmds);echo'</pre>';
- foreach ($cmds as $cmd) {
- $out = ''; $ret = '';
- exec($cmd, $out, $ret);
- echo'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
- }
- $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;
- $pdo = DB::getPDO();
- $sth = $pdo->prepare("
- select g.ID
- , g.SERVER_ADDRESS as mainServer
- , g.ADMIN_USERNAME as rootLogin
- , g.ADMIN_USERNAME_PASSWD as rootPassword
- 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);
- return $licenceInfo;
- }
- public function _endWithException($e) {
- ?>
- <div class="container">
- <div class="alert alert-danger">
- #<?php echo $e->getLine(); ?>: <?php echo $e->getMessage(); ?>
- </div>
- <p>Wróć do <a href="index.php?_route=Install">menu</a></p>
- </div>
- <?php
- SE_Layout::dol();
- exit;
- }
- public function sendToRemoteTestDirAction() {
- $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->_sendToRemoteTestDir($appLicenceInfo);
- ?>
- Test online: <a target="_blank" href="https://<?php echo $appLicenceInfo->mainServer; ?>/se.encrypted.upgrade/">https://<?php echo $appLicenceInfo->mainServer; ?>/se.encrypted.upgrade/</a>
- <?php
- } catch (Exception $e) {
- $this->_endWithException($e);
- }
- SE_Layout::dol();
- }
- public function _sendToRemoteTestDir($appLicenceInfo) {
- $cmd = ''; $out = ''; $ret = '';
- $this->_assertRsaKeyExists($appLicenceInfo);
- $sshHostUsr = "{$appLicenceInfo->rootLogin}@{$appLicenceInfo->mainServer}";
- $cmd = "
- ssh {$sshHostUsr} '[ ! -d ~/se.encrypted.upgrade ] && mkdir ~/se.encrypted.upgrade || echo 1';
- ssh {$sshHostUsr} 'rm -rf ~/se.encrypted.upgrade/SE';
- rsync --archive --verbose --update --times --compress --one-file-system --omit-dir-times --no-g --no-perms \
- '{$appLicenceInfo->installPath}/SE/' {$sshHostUsr}:~/se.encrypted.upgrade/SE/;
- ssh {$sshHostUsr} 'cp -r /Library/Server/Web/Data/Sites/Default/SE/config ~/se.encrypted.upgrade/SE/';
- ssh {$sshHostUsr} 'rm /Library/Server/Web/Data/Sites/Default/se.encrypted.upgrade'
- ssh {$sshHostUsr} 'ln -s ~/se.encrypted.upgrade/SE /Library/Server/Web/Data/Sites/Default/se.encrypted.upgrade'
- ";
- 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() {
- $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: <a target="_blank" href="https://<?php echo $appLicenceInfo->mainServer; ?>/SE/">https://<?php echo $appLicenceInfo->mainServer; ?>/SE/</a>
- <?php
- } catch (Exception $e) {
- $this->_endWithException($e);
- }
- SE_Layout::dol();
- }
- public function _upgradeRemoteFromTestDir($appLicenceInfo) {
- $cmd = ''; $out = ''; $ret = '';
- $this->_assertRsaKeyExists($appLicenceInfo);
- $sshHostUsr = "{$appLicenceInfo->rootLogin}@{$appLicenceInfo->mainServer}";
- $dateStr = date("Y-m-d_H-i-s");
- $cmd = "
- ssh {$sshHostUsr} 'rm -rf /Library/Server/Web/Data/Sites/Default/SE.test';
- ssh {$sshHostUsr} 'cp -r ~/se.encrypted.upgrade/SE /Library/Server/Web/Data/Sites/Default/SE.test';
- ssh {$sshHostUsr} '[ ! -d ~/bup.se.upgrade ] && mkdir ~/bup.se.upgrade || echo 1';
- ssh {$sshHostUsr} '[ ! -f /Library/Server/Web/Data/Sites/Default/SE.test/VERSION ] && echo \"Error: plik VERSION nie istnieje\" || echo \"check VERSION OK\"';
- ssh {$sshHostUsr} '[ ! -f /Library/Server/Web/Data/Sites/Default/SE.test/index.php ] && echo \"Error: plik index.php nie istnieje\" || echo \"check index.php OK\"';
- ssh {$sshHostUsr} '[ ! -d /Library/Server/Web/Data/Sites/Default/SE.test/se-lib ] && echo \"Error: plik se-lib nie istnieje\" || echo \"check se-lib OK\"';
- ssh {$sshHostUsr} 'mv /Library/Server/Web/Data/Sites/Default/SE ~/bup.se.upgrade/bup.{$dateStr}';
- ssh {$sshHostUsr} 'mv /Library/Server/Web/Data/Sites/Default/SE.test /Library/Server/Web/Data/Sites/Default/SE';
- ";
- 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 _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 || echo 'OK ~/.ssh exists';
- 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);
- 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'";
- $cmd = "ssh server@{$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}");
- }
- }
|