Install.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. class Route_Install extends RouteBase {
  4. public function handleAuth() {
  5. if (!User::logged()) {
  6. throw new HttpException('Unauthorized', 401);
  7. }
  8. if (!User::isAdmin()) {
  9. throw new HttpException('Unauthorized - only for administrators', 401);
  10. }
  11. }
  12. public function defaultAction() {
  13. SE_Layout::gora();
  14. SE_Layout::menu();
  15. $this->menu();
  16. SE_Layout::dol();
  17. }
  18. private function menu() {
  19. $serversList = $this->fetchActiveLicences();
  20. ?>
  21. <div class="jumbotron">
  22. <div class="container">
  23. <form class="form-inline" method="GET">
  24. <input type="hidden" name="_route" value="Install" />
  25. <input type="hidden" name="_task" value="createApp" />
  26. <label>Przygotuj kod źródłowy do aktualizacji na serwerze klienta:</label>
  27. <select class="form-control" name="licence_id">
  28. <?php foreach ($serversList as $srv) : ?>
  29. <option value="<?php echo $srv->ID; ?>">[<?php echo $srv->ID; ?>] <?php echo $srv->domain; ?></option>
  30. <?php endforeach; ?>
  31. </select>
  32. <button type="submit" id="fldSbmtBtn" class="btn btn-primary" autocomplete="off">
  33. Generuj
  34. </button>
  35. </form>
  36. </div>
  37. </div>
  38. <script type="text/javascript">
  39. jQuery(document).ready(function () {
  40. jQuery('#fldSbmtBtn').on('click', function () {
  41. jQuery(this).text(jQuery(this).text() + '...').attr('disabled', 'disabled');
  42. jQuery(this).parent().submit();
  43. })
  44. });
  45. </script>
  46. <?php
  47. }
  48. public function createAppAction() {
  49. $args = array();
  50. $args['licence_id'] = V::get('licence_id', 0, $_REQUEST, 'int');
  51. SE_Layout::gora();
  52. SE_Layout::menu();
  53. //$this->menu($args['licence_id']);// TODO: GO BACK BTN
  54. try {
  55. $appLicenceInfo = $this->getAppLicenceInfo($args['licence_id']);
  56. } catch (Exception $e) {
  57. $this->_endWithException($e);
  58. }
  59. //$this->generateApp($args['licence_id']);
  60. //DBG::_(true, true, "appLicenceInfo", $appLicenceInfo, __CLASS__, __FUNCTION__, __LINE__);
  61. ?>
  62. <div class="jumbotron">
  63. <div class="container">
  64. <h3>Generowanie aplikacji dla licencji <?php echo $appLicenceInfo->ID; ?></h3>
  65. <p>Licencja dla domen: <?php echo implode(', ', $appLicenceInfo->domains); ?></p>
  66. <p>Katalog z zakodowanymi plikami: <?php echo $appLicenceInfo->installFolderName; ?></p>
  67. <form class="form-inline" method="POST">
  68. <input type="hidden" name="_task" value="createApp" />
  69. <input type="hidden" name="licence_id" value="<?php echo $appLicenceInfo->ID; ?>" />
  70. <input type="hidden" name="_generateEncryptedSource" value="1" />
  71. <button type="submit" id="fldSbmtBtn" class="btn btn-primary" autocomplete="off">
  72. Generuj
  73. </button>
  74. </form>
  75. <?php if ($appLicenceInfo->installFolderGitExists) : ?>
  76. <br>
  77. <div class="alert alert-info">
  78. Katalog istnieje i zawiera już repozytorium git:
  79. <br> - <a href="index.php?_route=Install&_task=gitResetHard&licence_id=<?php echo $appLicenceInfo->ID; ?>"
  80. target="_blank"
  81. 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)
  82. <br> - <a href="index.php?_route=Install&_task=encodeSource&licence_id=<?php echo $appLicenceInfo->ID; ?>"
  83. target="_blank"
  84. class="btn btn-xs btn-default">encode files</a>
  85. <br> - <a href="index.php?_route=Install&_task=sendToRemoteTestDir&licence_id=<?php echo $appLicenceInfo->ID; ?>"
  86. target="_blank"
  87. class="btn btn-xs btn-default">send encoded files to remote server test folder (generates ssh key if not set)</a>
  88. <p style="margin-top:30px">
  89. Test online: <a target="_blank" href="https://<?php echo $appLicenceInfo->mainServer; ?>/se.encrypted.upgrade/">https://<?php echo $appLicenceInfo->mainServer; ?>/se.encrypted.upgrade/</a>
  90. </p>
  91. </div>
  92. <?php endif; ?>
  93. </div>
  94. </div>
  95. <script type="text/javascript">
  96. jQuery(document).ready(function () {
  97. jQuery('#fldSbmtBtn').on('click', function () {
  98. jQuery(this).text(jQuery(this).text() + '...').attr('disabled', 'disabled');
  99. jQuery(this).parent().submit();
  100. })
  101. });
  102. </script>
  103. <?php
  104. $generateEncryptedSource = (1 == V::get('_generateEncryptedSource', 0, $_REQUEST, 'int'));
  105. if ($generateEncryptedSource) {
  106. echo '<div class="container">';
  107. echo '<h4>' . "Generowanie..." . '</h4>';
  108. echo '<div style="border:1px solid silver; max-height:400px; overflow-y:scroll">';
  109. try {
  110. $this->generateApp($appLicenceInfo);
  111. } catch (Exception $e) {
  112. echo '</div></div>';// .container/ scroll
  113. $this->_endWithException($e);
  114. }
  115. echo '</div>';// .container
  116. ?>
  117. <div class="alert alert-success">
  118. <strong>Gotowe</strong> Aplikacja znajduje się w katalogu <?php echo $appLicenceInfo->installFolderName; ?>
  119. </div>
  120. <?php
  121. }
  122. SE_Layout::dol();
  123. }
  124. public function gitResetHardAction() {
  125. $args = array();
  126. $args['licence_id'] = V::get('licence_id', 0, $_REQUEST, 'int');
  127. SE_Layout::gora();
  128. SE_Layout::menu();
  129. //$this->menu($args['licence_id']);// TODO: GO BACK BTN
  130. try {
  131. $appLicenceInfo = $this->getAppLicenceInfo($args['licence_id']);
  132. $this->_gitResetHard($appLicenceInfo);
  133. } catch (Exception $e) {
  134. $this->_endWithException($e);
  135. }
  136. SE_Layout::dol();
  137. }
  138. public function _gitResetHard($appLicenceInfo) {
  139. if (empty($appLicenceInfo->ID)) throw new Exception("Nie wybrano serwera/licencji.");
  140. if (empty($appLicenceInfo->domains)) throw new Exception("Domains not found");
  141. $installPath = $appLicenceInfo->installPath;
  142. if (empty($installPath)) throw new Exception("Install path not found");
  143. $cmds = array();
  144. $cmds[] = "cd {$installPath} && git reset --hard";
  145. $cmds[] = "cd {$installPath} && git pull";
  146. $cmds[] = "cd {$installPath} && echo `git show-ref --head|head -1|head -c 8` > SE/VERSION ";
  147. foreach ($cmds as $cmd) {
  148. $out = ''; $ret = '';
  149. exec($cmd, $out, $ret);
  150. echo'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
  151. }
  152. }
  153. public function encodeSourceAction() {
  154. $args = array();
  155. $args['licence_id'] = V::get('licence_id', 0, $_REQUEST, 'int');
  156. SE_Layout::gora();
  157. SE_Layout::menu();
  158. //$this->menu($args['licence_id']);// TODO: GO BACK BTN
  159. try {
  160. $appLicenceInfo = $this->getAppLicenceInfo($args['licence_id']);
  161. $this->_encodeSource($appLicenceInfo);
  162. } catch (Exception $e) {
  163. $this->_endWithException($e);
  164. }
  165. SE_Layout::dol();
  166. }
  167. public function _encodeSource($appLicenceInfo) {
  168. if (empty($appLicenceInfo->ID)) throw new Exception("Nie wybrano serwera/licencji.");
  169. if (empty($appLicenceInfo->domains)) throw new Exception("Domains not found");
  170. $installPath = $appLicenceInfo->installPath;
  171. if (empty($installPath)) throw new Exception("Install path not found");
  172. $phpVersion = '5.5';
  173. if ('1' == V::get('DBG_ENCODER_HELP', '', $_REQUEST)) {// encoder help
  174. $cmd = "cd {$installPath}/SE && /Applications/SourceGuardian.app/Contents/MacOS/sgencoder --help ";
  175. $out = ''; $ret = '';
  176. exec($cmd, $out, $ret);
  177. echo'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
  178. exit;
  179. }
  180. {
  181. $phpFiles = array();
  182. $skipPhpFiles = array();
  183. $skipPhpFiles[] = 'bash_sync_perms.php';
  184. $skipPhpFiles[] = '.config.php';
  185. $skipPhpFiles[] = 'se-lib/V.php';
  186. $skipPhpFiles[] = 'se-lib/Lib.php';
  187. $skipPhpFiles[] = 'se-lib/DB.php';
  188. $skipPhpFiles[] = 'se-lib/User.php';
  189. $skipPhpFiles[] = 'se-lib/UserProfile.php';
  190. $skipPhpFiles[] = 'se-lib/Config.php';
  191. $skipPhpFiles[] = 'se-lib/Config/INI.php';
  192. $skipPhpFiles[] = 'se-lib/FoldersConfig.php';
  193. $skipPhpFiles[] = 'se-lib/FileUploader.php';
  194. $skipPhpFiles[] = 'se-lib/Route/Budget.php';
  195. $skipPhpFiles[] = 'se-lib/Route/FixCrmProcesInitIdx.php';
  196. $skipPhpFiles[] = 'se-lib/Route/FixProjectPath.php';
  197. $skipPhpFiles[] = 'se-lib/Route/FixZasobPath.php';
  198. //$skipPhpFiles[] = 'se-lib/Route/Install.php';
  199. $skipPhpFiles[] = 'se-lib/Route/Msgs.php';
  200. $skipPhpFiles[] = 'superedit-DB_PROCEDURES_CREATE.php';
  201. //$skipPhpFiles[] = '';
  202. $cmd = "cd {$installPath}/SE && find . -name '*.php' ";
  203. $out = ''; $ret = '';
  204. exec($cmd, $out, $ret);
  205. echo'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
  206. if (0 !== $ret) throw new Exception("Error at find php files");
  207. if (empty($out)) throw new Exception("No php files found");
  208. foreach ($out as $phpFilePath) {
  209. $phpFilePath = ('./' == substr($phpFilePath, 0, 2))? substr($phpFilePath, 2) : $phpFilePath;
  210. if (in_array($phpFilePath, $skipPhpFiles)) continue;
  211. if ('schema/' == substr($phpFilePath, 0, 7)) continue;
  212. $phpFiles[] = $phpFilePath;
  213. }
  214. DBG::_(true, true, 'phpFiles', $phpFiles);
  215. if (empty($phpFiles)) throw new Exception("No php files to encode");
  216. }
  217. {
  218. $cmd = "cd {$installPath}/SE && /Applications/SourceGuardian.app/Contents/MacOS/sgencoder --phpversion {$phpVersion} -b- ";
  219. foreach ($appLicenceInfo->domains as $domain) {
  220. $cmd .= " --domain {$domain} ";
  221. }
  222. $cmd .= " " . implode(" ", $phpFiles);
  223. $out = ''; $ret = '';
  224. exec($cmd, $out, $ret);
  225. echo'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
  226. if (0 !== $ret) throw new Exception("Error at encode files");
  227. if (empty($out)) throw new Exception("No output for encode files command");
  228. }
  229. }
  230. public function getAppLicenceInfo($idLicence) {
  231. $idLicence = intval($idLicence);
  232. if (empty($idLicence)) throw new Exception("Nie wybrano serwera/licencji.");
  233. //DBG::_(true, true, 'idLicence', $idLicence, __CLASS__, __FUNCTION__, __LINE__);
  234. $appLicenceInfo = (object)$this->fetchAppLicenceInfo($idLicence);
  235. $appLicenceInfo->domains = $this->fetchDomainsByLicenceId($idLicence);
  236. $installRootPath = '/Library/Server/Web/Data/Sites/Default/PLIKI/SES_PROCESY5_A';
  237. $appLicenceInfo->installFolderName = "{$idLicence}_upgrade_SE_source_encrypted";
  238. $appLicenceInfo->installPath = "{$installRootPath}/{$appLicenceInfo->installFolderName}";
  239. //DBG::_(true, true, 'appLicenceInfo', $appLicenceInfo, __CLASS__, __FUNCTION__, __LINE__);
  240. if (empty($appLicenceInfo->domains)) throw new Exception("Domains not found.");
  241. $appLicenceInfo->installFolderExists = file_exists("{$appLicenceInfo->installPath}/SE");
  242. $appLicenceInfo->installFolderGitExists = file_exists("{$appLicenceInfo->installPath}/.git");
  243. return $appLicenceInfo;
  244. }
  245. public function generateApp($appLicenceInfo) {
  246. if (empty($appLicenceInfo->ID)) throw new Exception("Nie wybrano serwera/licencji.");
  247. if (empty($appLicenceInfo->domains)) throw new Exception("Domains not found");
  248. $installPath = $appLicenceInfo->installPath;
  249. if (empty($installPath)) throw new Exception("Install path not found");
  250. $cmds = array();
  251. $cmds[] = "if [ -d {$installPath} ] ; then rm -rf '{$installPath}'; fi";
  252. $cmds[] = "mkdir {$installPath}";
  253. $cmds[] = "cd {$installPath} && git clone git@biuro.biall-net.pl:plabudda/se.git .";
  254. $cmds[] = "cd {$installPath} && echo `git show-ref --head|head -1|head -c 8` > SE/VERSION ";
  255. //echo'<pre>cmds: ';print_r($cmds);echo'</pre>';
  256. foreach ($cmds as $cmd) {
  257. $out = ''; $ret = '';
  258. exec($cmd, $out, $ret);
  259. echo'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
  260. }
  261. $this->_encodeSource($appLicenceInfo);
  262. // 1763: $exec='cd '.$installer_dir.' && /Applications/SourceGuardian.app/Contents/MacOS/sgencoder -b-
  263. // '.INSTALL_SES_PROCESY_A::get_same_domains_for_install($h->SERVER_ADDRESS_SHORT).'
  264. // -r *.php
  265. // -x superedit-DB_PROCEDURES_CREATE.php
  266. // -x INI.php
  267. // -x .config_base_structure.php
  268. // ';
  269. //
  270. // INSTALL_SES_PROCESY_A::get_same_domains_for_install($h->SERVER_ADDRESS_SHORT):
  271. // $res2=DB::query("select SERVER_ADDRESS_SHORT from SES_PROCESY5_A where SERVER_ADDRESS_IP='".$h->SERVER_ADDRESS_IP."'");
  272. // while($h2=DB::fetch($res2)) {
  273. // $domain[]=' --domain '.$h2->SERVER_ADDRESS_SHORT;
  274. // ssh server@biuro.galeriaprzymorze.eu: PHP 5.5.20
  275. // ssh server@biuro.biall-net.pl
  276. // cd /Users/plabudda/procesy5-install-galeriaprzymorze.eu/
  277. // sudo chown -R server:admin SE/
  278. // /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
  279. }
  280. public function fetchActiveLicences() {
  281. $activeLic = array();
  282. $db = DB::getDB();
  283. $sql = "select l.`ID`
  284. , l.`SERVER_ADDRESS`
  285. , l.`SERVER_ADDRESS_SHORT` as domain -- domain for sgencoder
  286. , l.`SERVER_ADDRESS_IP`
  287. from `SES_PROCESY5_A` l
  288. where 1=1
  289. -- TODO: and l.`A_STATUS` in('NORMAL','WAITING')
  290. order by l.`ID` DESC
  291. ";
  292. $res = $db->query($sql);
  293. while ($r = $db->fetch($res)) {
  294. $activeLic[$r->ID] = $r;
  295. }
  296. return $activeLic;
  297. }
  298. public function fetchDomainsByLicenceId($licenceId) {
  299. $domains = array();
  300. $db = DB::getDB();
  301. $sql = "select g.`SERVER_ADDRESS_SHORT`, g.`SERVER_ADDRESS`
  302. from `SES_PROCESY5_A` g
  303. where g.`SERVER_ADDRESS_IP`=(select l.`SERVER_ADDRESS_IP`
  304. from `SES_PROCESY5_A` l
  305. where l.`ID`='{$licenceId}'
  306. -- TODO: and l.`A_STATUS` in('NORMAL','WAITING')
  307. )
  308. -- TODO: and g.`A_STATUS` in('NORMAL','WAITING')
  309. ";
  310. $res = $db->query($sql);
  311. while ($r = $db->fetch($res)) {
  312. $domains[] = $r->SERVER_ADDRESS_SHORT;
  313. if ($r->SERVER_ADDRESS != $r->SERVER_ADDRESS_SHORT) {
  314. $domains[] = $r->SERVER_ADDRESS;
  315. }
  316. }
  317. return $domains;
  318. }
  319. public function fetchMainServerByLicenceId($licenceId) {
  320. $mainServer = null;
  321. $db = DB::getDB();
  322. $sql = "select g.`SERVER_ADDRESS`
  323. from `SES_PROCESY5_A` g
  324. where g.`ID`='{$licenceId}'
  325. -- TODO: and g.`A_STATUS` in('NORMAL','WAITING')
  326. ";
  327. $res = $db->query($sql);
  328. while ($r = $db->fetch($res)) {
  329. $mainServer = $r->SERVER_ADDRESS;
  330. }
  331. return $mainServer;
  332. }
  333. public function fetchAppLicenceInfo($licenceId) {
  334. $licenceInfo = null;
  335. $pdo = DB::getPDO();
  336. $sth = $pdo->prepare("
  337. select g.ID
  338. , g.SERVER_ADDRESS as mainServer
  339. , g.ADMIN_USERNAME as rootLogin
  340. , g.ADMIN_USERNAME_PASSWD as rootPassword
  341. from SES_PROCESY5_A g
  342. where g.`ID`=:id_licence
  343. -- TODO: and g.A_STATUS in('NORMAL','WAITING')
  344. ");
  345. $sth->bindValue('id_licence', $licenceId, PDO::PARAM_INT);
  346. $sth->execute();
  347. $all = $sth->fetchAll();
  348. if (empty($all)) throw new Exception("Brak licencji o nr '{$licenceId}'");
  349. $licenceInfo = reset($all);
  350. return $licenceInfo;
  351. }
  352. public function _endWithException($e) {
  353. ?>
  354. <div class="container">
  355. <div class="alert alert-danger">
  356. #<?php echo $e->getLine(); ?>: <?php echo $e->getMessage(); ?>
  357. </div>
  358. <p>Wróć do <a href="index.php?_route=Install">menu</a></p>
  359. </div>
  360. <?php
  361. SE_Layout::dol();
  362. exit;
  363. }
  364. public function sendToRemoteTestDirAction() {
  365. $args = array();
  366. $args['licence_id'] = V::get('licence_id', 0, $_REQUEST, 'int');
  367. SE_Layout::gora();
  368. //SE_Layout::menu();
  369. //$this->menu($args['licence_id']);// TODO: GO BACK BTN
  370. try {
  371. $appLicenceInfo = $this->getAppLicenceInfo($args['licence_id']);
  372. $this->_sendToRemoteTestDir($appLicenceInfo);
  373. ?>
  374. Test online: <a target="_blank" href="https://<?php echo $appLicenceInfo->mainServer; ?>/se.encrypted.upgrade/">https://<?php echo $appLicenceInfo->mainServer; ?>/se.encrypted.upgrade/</a>
  375. <?php
  376. } catch (Exception $e) {
  377. $this->_endWithException($e);
  378. }
  379. SE_Layout::dol();
  380. }
  381. public function _sendToRemoteTestDir($appLicenceInfo) {
  382. $cmd = ''; $out = ''; $ret = '';
  383. $cmd = "echo ~ && pwd";// /Library/WebServer
  384. $cmd = "ls -1 ~/.ssh/";
  385. //$cmd = "rm /tmp/id_rsa";
  386. //$cmd = "rm /tmp/id_rsa.pub";
  387. //$cmd = "ssh-keygen -t rsa -N '' -C '_www@biuro.biall-net.pl' -f /tmp/id_rsa";
  388. //$cmd = "ssh-keygen -t rsa -N '' -C '_www@biuro.biall-net.pl' -f /tmp/id_rsa";
  389. V::exec($cmd, $out, $ret);
  390. DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
  391. if (0 !== $ret) {// no ~/.ssh directory
  392. $rsaKeyPath = "~/.ssh";
  393. $cmds = array();
  394. $cmds[] = "mkdir {$rsaKeyPath}";
  395. $cmds[] = "ssh-keygen -t rsa -N '' -C '_www@biuro.biall-net.pl' -f {$rsaKeyPath}/id_rsa 2>&1";
  396. $cmds[] = "ls -1 $rsaKeyPath";
  397. foreach ($cmds as $cmd) {
  398. V::exec($cmd, $out, $ret);
  399. DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
  400. if (0 !== $ret) throw new Exception("Error '{$ret}' cmd({$cmd}): " . implode("\n", $out));
  401. }
  402. }
  403. $cmd = "cat ~/.ssh/id_rsa.pub";
  404. V::exec($cmd, $out, $ret);
  405. DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
  406. if (0 !== $ret || empty($out) || empty($out[0])) throw new Exception("Cannot read rsa public key");
  407. $rsaPubKey = $out[0];
  408. $cmd = 'ls -1a';
  409. $cmd = "
  410. [ ! -d ~/.sshX ] && mkdir ~/.sshX || echo 'OK ~/.ssh exists';
  411. cat ~/.sshX/authorized_keys| grep '{$rsaPubKey}' && echo 'OK' || echo '{$rsaPubKey}' >> ~/.sshX/authorized_keys;
  412. chmod 600 ~/.sshX/authorized_keys;
  413. ";
  414. V::execRemote($appLicenceInfo->mainServer, $appLicenceInfo->rootLogin, $appLicenceInfo->rootPassword, $cmd, $out, $ret);
  415. DBG::_(true, true, "remote cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
  416. //$cmd = "ssh server@{$appLicenceInfo->mainServer} 'ls -1 .ssh/'";
  417. //$cmd = "ssh -i ~/.ssh/id_rsa server@{$appLicenceInfo->mainServer} 'ls -1'";
  418. $cmd = "ssh server@{$appLicenceInfo->mainServer} 'ls -1'";
  419. V::exec($cmd, $out, $ret);
  420. DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
  421. if (0 !== $ret) throw new Exception("Cannot run remote command using rsa key! #{$ret}");
  422. $sshHostUsr = "{$appLicenceInfo->rootLogin}@{$appLicenceInfo->mainServer}";
  423. $cmd = "
  424. ssh {$sshHostUsr} '[ ! -d ~/se.encrypted.upgrade ] mkdir ~/se.encrypted.upgrade || echo 1';
  425. ssh {$sshHostUsr} 'rm -rf ~/se.encrypted.upgrade/SE';
  426. rsync --archive --verbose --update --times --compress --one-file-system --omit-dir-times --no-g --no-perms \
  427. '{$appLicenceInfo->installPath}/SE/' {$sshHostUsr}:~/se.encrypted.upgrade/SE/;
  428. ssh {$sshHostUsr} 'ln -s /Library/Server/Web/Data/Sites/Default/SE/config ~/se.encrypted.upgrade/SE/config';
  429. ssh {$sshHostUsr} 'rm /Library/Server/Web/Data/Sites/Default/se.encrypted.upgrade'
  430. ssh {$sshHostUsr} 'ln -s ~/se.encrypted.upgrade/SE /Library/Server/Web/Data/Sites/Default/se.encrypted.upgrade'
  431. ";
  432. V::exec($cmd, $out, $ret);
  433. DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
  434. if (0 !== $ret) throw new Exception("Cannot run remote command using rsa key! #{$ret}");
  435. }
  436. }