Install.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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="POST">
  24. <input type="hidden" name="_task" value="createApp" />
  25. <label>Przygotuj kod źródłowy do aktualizacji na serwerze klienta:</label>
  26. <select class="form-control" name="licence_id">
  27. <?php foreach ($serversList as $srv) : ?>
  28. <option value="<?php echo $srv->ID; ?>">[<?php echo $srv->ID; ?>] <?php echo $srv->domain; ?></option>
  29. <?php endforeach; ?>
  30. </select>
  31. <button type="submit" id="fldSbmtBtn" class="btn btn-primary" autocomplete="off">
  32. Generuj
  33. </button>
  34. </form>
  35. </div>
  36. </div>
  37. <script type="text/javascript">
  38. jQuery(document).ready(function () {
  39. jQuery('#fldSbmtBtn').on('click', function () {
  40. jQuery(this).text(jQuery(this).text() + '...').attr('disabled', 'disabled');
  41. jQuery(this).parent().submit();
  42. })
  43. });
  44. </script>
  45. <?php
  46. }
  47. public function createAppAction() {
  48. $args = array();
  49. $args['licence_id'] = V::get('licence_id', 0, $_REQUEST, 'int');
  50. SE_Layout::gora();
  51. SE_Layout::menu();
  52. //$this->menu($args['licence_id']);// TODO: GO BACK BTN
  53. if (empty($args['licence_id'])) {
  54. ?>
  55. <div class="alert alert-warning">
  56. Nie wybrano serwera/licencji.
  57. </div>
  58. <?php
  59. SE_Layout::dol();
  60. exit;
  61. }
  62. $this->generateApp($args['licence_id']);
  63. SE_Layout::dol();
  64. }
  65. public function generateApp() {
  66. $args = array();
  67. $args['licence_id'] = V::get('licence_id', 0, $_REQUEST, 'int');
  68. if (empty($args['licence_id'])) {
  69. $this->menu();
  70. ?>
  71. <div class="alert alert-warning">
  72. Nie wybrano serwera/licencji.
  73. </div>
  74. <?php
  75. SE_Layout::dol();
  76. exit;
  77. }
  78. $domains = $this->fetchDomainsByLicenceId($args['licence_id']);
  79. if (empty($domains)) {
  80. $this->menu($args['licence_id']);
  81. ?>
  82. <div class="alert alert-warning">
  83. Domains not found.
  84. </div>
  85. <?php
  86. SE_Layout::dol();
  87. exit;
  88. }
  89. echo'<pre>Domains with Licence: ';print_r($domains);echo'</pre>';
  90. $installPath = '/Library/Server/Web/Data/Sites/Default/PLIKI/SES_PROCESY5_A';
  91. $installPath .= "/{$args['licence_id']}_upgrade_SE_source_encrypted";
  92. $cmds = array();
  93. $cmds[] = "if [ -d {$installPath} ] ; then rm -rf '{$installPath}'; fi";
  94. $cmds[] = "mkdir {$installPath}";
  95. $cmds[] = "cd {$installPath} && git clone git@biuro.biall-net.pl:plabudda/se.git .";
  96. $cmds[] = "cd {$installPath} && echo `git show-ref --head|head -1|head -c 8` > SE/VERSION ";
  97. $cmds[] = "cd {$installPath} && /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";
  98. //echo'<pre>cmds: ';print_r($cmds);echo'</pre>';
  99. foreach ($cmds as $cmd) {
  100. $out = ''; $ret = '';
  101. exec($cmd, $out, $ret);
  102. echo'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
  103. }
  104. // 1763: $exec='cd '.$installer_dir.' && /Applications/SourceGuardian.app/Contents/MacOS/sgencoder -b-
  105. // '.INSTALL_SES_PROCESY_A::get_same_domains_for_install($h->SERVER_ADDRESS_SHORT).'
  106. // -r *.php
  107. // -x superedit-DB_PROCEDURES_CREATE.php
  108. // -x INI.php
  109. // -x .config_base_structure.php
  110. // ';
  111. //
  112. // INSTALL_SES_PROCESY_A::get_same_domains_for_install($h->SERVER_ADDRESS_SHORT):
  113. // $res2=DB::query("select SERVER_ADDRESS_SHORT from SES_PROCESY5_A where SERVER_ADDRESS_IP='".$h->SERVER_ADDRESS_IP."'");
  114. // while($h2=DB::fetch($res2)) {
  115. // $domain[]=' --domain '.$h2->SERVER_ADDRESS_SHORT;
  116. // ssh server@biuro.galeriaprzymorze.eu: PHP 5.5.20
  117. // ssh server@biuro.biall-net.pl
  118. // cd /Users/plabudda/procesy5-install-galeriaprzymorze.eu/
  119. // sudo chown -R server:admin SE/
  120. // /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
  121. }
  122. public function fetchActiveLicences() {
  123. $activeLic = array();
  124. $db = DB::getDB();
  125. $sql = "select l.`ID`
  126. , l.`SERVER_ADDRESS`
  127. , l.`SERVER_ADDRESS_SHORT` as domain -- domain for sgencoder
  128. , l.`SERVER_ADDRESS_IP`
  129. from `SES_PROCESY5_A` l
  130. where 1=1
  131. -- TODO: and l.`A_STATUS` in('NORMAL','WAITING')
  132. order by l.`ID` DESC
  133. ";
  134. $res = $db->query($sql);
  135. while ($r = $db->fetch($res)) {
  136. $activeLic[$r->ID] = $r;
  137. }
  138. return $activeLic;
  139. }
  140. public function fetchDomainsByLicenceId($licenceId) {
  141. $domains = array();
  142. $db = DB::getDB();
  143. $sql = "select g.`SERVER_ADDRESS_SHORT`, g.`SERVER_ADDRESS`
  144. from `SES_PROCESY5_A` g
  145. where g.`SERVER_ADDRESS_IP`=(select l.`SERVER_ADDRESS_IP`
  146. from `SES_PROCESY5_A` l
  147. where l.`ID`='{$licenceId}'
  148. -- TODO: and l.`A_STATUS` in('NORMAL','WAITING')
  149. )
  150. -- TODO: and g.`A_STATUS` in('NORMAL','WAITING')
  151. ";
  152. $res = $db->query($sql);
  153. while ($r = $db->fetch($res)) {
  154. $domains[] = $r->SERVER_ADDRESS_SHORT;
  155. if ($r->SERVER_ADDRESS != $r->SERVER_ADDRESS_SHORT) {
  156. $domains[] = $r->SERVER_ADDRESS;
  157. }
  158. }
  159. return $domains;
  160. }
  161. }