update_server.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2017 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. require_once("includes/lib_remote.php");
  25. require_once("modules/config_games/server_config_parser.php");
  26. function exec_ogp_module() {
  27. global $db;
  28. global $view;
  29. $home_id = isset($_REQUEST['home_id']) ? $_REQUEST['home_id'] : "";
  30. $mod_id = isset($_REQUEST['mod_id']) ? $_REQUEST['mod_id'] : "";
  31. $isAdmin = $db->isAdmin( $_SESSION['user_id'] );
  32. if($isAdmin)
  33. $home_info = $db->getGameHome($home_id);
  34. else
  35. $home_info = $db->getUserGameHome($_SESSION['user_id'],$home_id);
  36. if ( $home_info === FALSE || preg_match("/u/",$home_info['access_rights']) != 1 )
  37. {
  38. print_failure( get_lang("no_rights") );
  39. echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id=".$home_info['home_id']."'><< ". back ."</a></td></tr></table>";
  40. return;
  41. }
  42. $home_id = $home_info['home_id'];
  43. $game_type = $home_info['game_key'];
  44. echo "<h2>Updating game server <em>".htmlentities($home_info['home_name'])."</em></h2>";
  45. $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
  46. if ( $server_xml->installer != "steamcmd" )
  47. {
  48. print_failure( get_lang("xml_steam_error") );
  49. return;
  50. }
  51. $remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'], $home_info['timeout']);
  52. $host_stat = $remote->status_chk();
  53. if( $host_stat === 0 )
  54. {
  55. print_failure( get_lang("agent_offline") );
  56. $view->refresh("?m=gamemanager&amp;p=update&amp;update=".$_GET['update']."&amp;home_id=$home_id&amp;mod_id=$mod_id",5);
  57. return;
  58. }
  59. else
  60. {
  61. if ( $remote->is_screen_running(OGP_SCREEN_TYPE_HOME,$home_id) == 1 )
  62. {
  63. print_failure( get_lang("server_running_cant_update") );
  64. return;
  65. }
  66. $log_txt = '';
  67. $update_active = $remote->get_log(OGP_SCREEN_TYPE_UPDATE,
  68. // Note exec location should not be added here as the log is in root where steam is executed.
  69. $home_id,clean_path($home_info['home_path']),
  70. $log_txt);
  71. $modkey = $home_info['mods'][$mod_id]['mod_key'];
  72. $mod_xml = xml_get_mod($server_xml, $modkey);
  73. if (!$mod_xml)
  74. {
  75. print_failure(get_lang_f('mod_key_not_found_from_xml',$modkey));
  76. return;
  77. }
  78. // Start update.
  79. else if ($_GET['update'] == 'update' && $update_active != 1)
  80. {
  81. $installer_name = $modkey;
  82. if ( isset( $mod_xml->installer_name ) )
  83. {
  84. $installer_name = $mod_xml->installer_name;
  85. }
  86. $precmd = $home_info['mods'][$mod_id]['precmd'] == "" ?
  87. ( $home_info['mods'][$mod_id]['def_precmd'] == "" ? $server_xml->pre_install :
  88. $home_info['mods'][$mod_id]['def_precmd'] ) : $home_info['mods'][$mod_id]['precmd'];
  89. $postcmd = $home_info['mods'][$mod_id]['postcmd'] == "" ?
  90. ( $home_info['mods'][$mod_id]['def_postcmd'] == "" ? $server_xml->post_install :
  91. $home_info['mods'][$mod_id]['def_precmd'] ) : $home_info['mods'][$mod_id]['postcmd'];
  92. $exec_folder_path = clean_path($home_info['home_path'] . "/" . $server_xml->exe_location );
  93. $exec_path = clean_path($exec_folder_path . "/" . $server_xml->server_exec_name );
  94. if( isset( $_REQUEST['master_server_home_id'] ) )
  95. {
  96. $ms_home_id = $_REQUEST['master_server_home_id'];
  97. if ($db->getMasterServer($home_info['remote_server_id'], $home_info['home_cfg_id']) == $ms_home_id) {
  98. if ($ms_home_id !== $home_id) {
  99. $ms_info = $db->getGameHome($ms_home_id);
  100. $steam_out = $remote->masterServerUpdate( $home_id,$home_info['home_path'],$ms_home_id,$ms_info['home_path'],$exec_folder_path,$exec_path,$precmd,$postcmd );
  101. } else {
  102. print_failure(get_lang('cannot_update_from_own_self'));
  103. $view->refresh('?m=gamemanager&p=game_monitor', 2);
  104. return;
  105. }
  106. } else {
  107. $db->logger(get_lang_f('update_attempt_from_nonmaster_server', $_SESSION['users_login'], $home_id, $ms_home_id));
  108. print_failure(get_lang('attempting_nonmaster_update'));
  109. $view->refresh('?m=gamemanager&p=game_monitor', 2);
  110. return;
  111. }
  112. }
  113. else
  114. {
  115. if( preg_match("/win32/", $server_xml->game_key) OR preg_match("/win64/", $server_xml->game_key) )
  116. $cfg_os = "windows";
  117. elseif( preg_match("/linux/", $server_xml->game_key) )
  118. $cfg_os = "linux";
  119. $settings = $db->getSettings();
  120. // Some games like L4D2 require anonymous login
  121. if($mod_xml->installer_login){
  122. $login = $mod_xml->installer_login;
  123. $pass = '';
  124. }else{
  125. $login = $settings['steam_user'];
  126. $pass = $settings['steam_pass'];
  127. }
  128. $modname = ( $installer_name == '90' ) ? $modkey : '';
  129. $betaname = isset($mod_xml->betaname) ? $mod_xml->betaname : '';
  130. $betapwd = isset($mod_xml->betapwd) ? $mod_xml->betapwd : '';
  131. // Additional files to lock
  132. if(isset($server_xml->lock_files) && !empty($server_xml->lock_files)){
  133. $lockFiles = trim($server_xml->lock_files);
  134. }else{
  135. $lockFiles = "";
  136. }
  137. $steam_out = $remote->steam_cmd( $home_id,$home_info['home_path'],$installer_name,$modname,
  138. $betaname,$betapwd,$login,$pass,$settings['steam_guard'],
  139. $exec_folder_path,$exec_path,$precmd,$postcmd,$cfg_os,$lockFiles);
  140. }
  141. if( $steam_out === 0 )
  142. {
  143. print_failure( get_lang("failed_to_start_steam_update") );
  144. return;
  145. }
  146. else if ( $steam_out === 1 )
  147. {
  148. print_success( get_lang("update_started") );
  149. }
  150. }
  151. // Refresh update page.
  152. else
  153. {
  154. if ( isset( $_POST['stop_update_x'] ) )
  155. {
  156. $remote->stop_update($home_id);
  157. print_success("Update stopped.");
  158. $view->refresh("?m=gamemanager&amp;p=update&amp;update=refresh&amp;home_id=$home_id&amp;mod_id=$mod_id", 2);
  159. return;
  160. }
  161. $update_complete = false;
  162. if ( $update_active == 1 )
  163. {
  164. echo "<p class='note'>". update_in_progress ."</p>\n";
  165. echo "<form method=POST><input type='image' name='stop_update' onsubmit='submit-form();' src='modules/administration/images/remove.gif'>". stop_update ."</input></form>";
  166. }
  167. else
  168. {
  169. $view->refresh("{CURRENT_PAGE}", 60);
  170. print_success( get_lang("update_completed") );
  171. echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id=".$home_info['home_id']."'><< ". back ."</a></td></tr></table>";
  172. $update_complete = true;
  173. }
  174. if (empty($log_txt))
  175. $log_txt = not_available;
  176. echo "<pre>".$log_txt."</pre>\n";
  177. if ( $update_complete )
  178. return;
  179. }
  180. echo "<p><a href=\"?m=gamemanager&amp;p=update&amp;update=refresh&amp;home_id=$home_id&amp;mod_id=$mod_id\">";
  181. echo refresh_steam_status ."</a></p>";
  182. $view->refresh("?m=gamemanager&amp;p=update&amp;update=refresh&amp;home_id=$home_id&amp;mod_id=$mod_id",5);
  183. return;
  184. }
  185. }
  186. ?>