update_server_manual.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. function do_progress($kbytes,$totalsize)
  25. {
  26. $mbytes = round($kbytes / 1024, 2);
  27. if($kbytes > 0)
  28. {
  29. $pct = round(( $kbytes / $totalsize ) * 100, 2);
  30. }
  31. else
  32. {
  33. $pct = unavailable;
  34. }
  35. #echo "Percent is $pct";
  36. return "$totalsize;$mbytes;$pct";
  37. }
  38. require_once("includes/lib_remote.php");
  39. require_once("modules/config_games/server_config_parser.php");
  40. function exec_ogp_module() {
  41. global $db, $view;
  42. $home_id = isset($_REQUEST['home_id']) ? $_REQUEST['home_id'] : "";
  43. $mod_id = isset($_REQUEST['mod_id']) ? $_REQUEST['mod_id'] : "";
  44. $isAdmin = $db->isAdmin( $_SESSION['user_id'] );
  45. if($isAdmin)
  46. $home_info = $db->getGameHome($home_id);
  47. else
  48. $home_info = $db->getUserGameHome($_SESSION['user_id'],$home_id);
  49. if ( $home_info === FALSE || preg_match("/u/",$home_info['access_rights']) != 1 )
  50. {
  51. print_failure( get_lang("no_rights") );
  52. echo create_back_button("gamemanager","gamemanager");
  53. return;
  54. }
  55. $home_id = $home_info['home_id'];
  56. $state = isset($_REQUEST['state']) ? $_REQUEST['state'] : "";
  57. $pid = isset($_REQUEST['pid']) ? $_REQUEST['pid'] : -1;
  58. $filename = isset($_REQUEST['filename']) ? $_REQUEST['filename'] : "";
  59. echo "<h2>". get_lang("install_update_manual") ." " . $home_info['home_name'] . "</h2>";
  60. if ( !empty($state) )
  61. {
  62. $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
  63. $remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'],$home_info['timeout']);
  64. if ( $state == "start" )
  65. {
  66. $postinstall = $server_xml->post_install ? $server_xml->post_install : "";
  67. $pid = $remote->start_file_download($_REQUEST['url'],$home_info['home_path'],
  68. $filename,"uncompress",$postinstall);
  69. if ( $pid < 0 )
  70. {
  71. print_failure( get_lang("failed_to_start_file_download") );
  72. return;
  73. }
  74. }
  75. $url = $_REQUEST['url'];
  76. $headers = get_headers($url, 1);
  77. $download_available = !$headers ? FALSE : TRUE;
  78. // Check if any error occured
  79. if($download_available)
  80. {
  81. $bytes = is_array($headers['Content-Length']) ? $headers['Content-Length'][1] : $headers['Content-Length'];
  82. // Display the File Size
  83. $totalsize = $bytes / 1024;
  84. clearstatcache();
  85. }
  86. $kbytes = $remote->rsync_progress($home_info['home_path']."/".$filename);
  87. list($totalsize,$mbytes,$pct) = explode(";",do_progress($kbytes,$totalsize));
  88. $totalmbytes = round($totalsize / 1024, 2);
  89. $pct = $pct > 100 ? 100 : $pct;
  90. echo '<div class="dragbox bloc rounded" style="background-color:#dce9f2;" >
  91. <h4>'. get_lang("update_in_progress") ." ${mbytes}MB/${totalmbytes}MB</h4>
  92. <div style='background-color:#dce9f2;' >
  93. ";
  94. $bar = '';
  95. for( $i = 1; $i <= $pct; $i++ )
  96. {
  97. $bar .= '<img style="width:0.92%;vertical-align:middle;" src="images/progressBar.png">';
  98. }
  99. echo "<center>$bar <b style='vertical-align:top;display:inline;font-size:1.2em;color:red;' >$pct%</b></center>
  100. </div>
  101. </div>";
  102. if ( $remote->is_file_download_in_progress($pid) == 0 )
  103. {
  104. // Lock the executable when done
  105. $remote->secure_path("chattr+i", $home_info['home_path'] . "/" . ($server_xml->exe_location ? $server_xml->exe_location . "/" : "") . $server_xml->server_exec_name);
  106. print_success( get_lang("finished_manual_update") );
  107. }
  108. else
  109. {
  110. echo "<p><a href=\"?m=gamemanager&amp;p=update_manual&amp;state=refresh&amp;home_id=".
  111. $home_id."&amp;mod_id=$mod_id&amp;pid=$pid&amp;url=$url&amp;filename=$filename\">Refresh</a></p>";
  112. $view->refresh("?m=gamemanager&amp;p=update_manual&amp;state=refresh&amp;home_id=".
  113. $home_id."&amp;mod_id=$mod_id&amp;pid=$pid&amp;url=$url&amp;filename=$filename",5);
  114. }
  115. echo create_back_button($_GET['m'],"game_monitor&amp;home_id=".$home_id);
  116. }
  117. else
  118. {
  119. echo "<form action='?m=gamemanager&amp;p=update_manual' method='post'>
  120. <table class='center'>
  121. <input type='hidden' name='home_id' value='$home_id' />
  122. <input type='hidden' name='mod_id' value='$mod_id' />
  123. <input type='hidden' name='state' value='start' />
  124. <tr><td align='right'>". get_lang("game_name") .":</td><td align='left'>" . $home_info['game_name'] . "</td></tr>
  125. <tr><td align='right'>". get_lang("dest_dir") .":</td><td align='left'>" . $home_info['home_path'] . "</td></tr>
  126. <tr><td align='right'>". get_lang("remote_server") .":</td>
  127. <td align='left'>" . $home_info['remote_server_name'] . " (" . $home_info['agent_ip'] . ":" . $home_info['agent_port'] . ")</td></tr>
  128. <tr><td align='right'>". get_lang("file_url") .":</td>
  129. <td align='left'><input type='text' id='url' name='url' value='' onChange='setFilename(this.value)' size='50' /></td></tr>
  130. <tr><td colspan='2' class='info'>". get_lang("file_url_info") ."</td></tr>
  131. <tr><td align='right'>". get_lang("dest_filename") .":</td>
  132. <td align='left'><input type='text' id='filename' name='filename' value='' size='50'/></td></tr>
  133. <tr><td colspan='2' class='info'>". get_lang("dest_filename_info") ."</td></tr>
  134. </table>
  135. <p><input type='submit' name='update' value='". get_lang("update_server") ."' /></p>
  136. </form>";
  137. ?>
  138. <script type="text/javascript">
  139. function setFilename(url)
  140. {
  141. filename = url.substring(url.lastIndexOf('/')+1);
  142. document.getElementById('filename').setAttribute('value', filename);
  143. }
  144. </script>
  145. <?php
  146. }
  147. return;
  148. }
  149. ?>