config_servers.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. require_once("server_config_parser.php");
  25. function exec_ogp_module() {
  26. global $db,$view;
  27. $game_cfgs = $db->getGameCfgs();
  28. echo "<h2>".get_lang('game_config_setup')."</h2>\n
  29. <p>".get_lang_f("modify_configs_info",SERVER_CONFIG_LOCATION)."</p>\n
  30. <form action='?m=config_games' method='post'>\n
  31. <p><input id='reset_old_configs' type='checkbox' name='clear_old' value='yes' /><label for='reset_old_configs'>".get_lang('reset_old_configs')."</label></p>\n
  32. <p class='note'>".get_lang('note').": ".get_lang('config_reset_warning')."</p>\n
  33. <p><input type='submit' name='reconfig' value='".get_lang('update_configs')."' /></p>\n
  34. </form>\n";
  35. if ( isset($_REQUEST['reconfig']) )
  36. {
  37. // Remove any old config files that may have been renamed or removed by developers
  38. // Function is defined in helpers.php (add entries to array there)
  39. removeOldGameConfigs();
  40. $files = glob(SERVER_CONFIG_LOCATION."*.xml");
  41. if ( empty($files) )
  42. {
  43. print_failure(get_lang_f("no_configs_found",SERVER_CONFIG_LOCATION));
  44. return;
  45. }
  46. /// \todo remove the clear_old hack when the update on duplicate is completed to database.
  47. $clear_old = FALSE;
  48. if ( isset( $_REQUEST['clear_old']) && $_REQUEST['clear_old'] === 'yes' )
  49. {
  50. echo "<p class='info'>".get_lang('resetting_configs').":</p>";
  51. $clear_old = TRUE;
  52. }
  53. else
  54. {
  55. echo "<p class='info'>".get_lang('updating_configs').":</p>";
  56. }
  57. $oldStructure = $db->getCurrentHomeConfigMods();
  58. $db->clearGameCfgs($clear_old);
  59. foreach ( $files as $config_file )
  60. {
  61. $config = read_server_config($config_file);
  62. if ( empty($config) )
  63. {
  64. print_failure(get_lang_f("error_when_handling_file",$config_file));
  65. continue;
  66. }
  67. echo "<p class='info'>".get_lang_f("updating_config_from_file",$config_file)."</p>";
  68. if ( !$db->addGameCfg($config) )
  69. {
  70. print_failure(get_lang_f("error_while_adding_cfg_to_db",$config_file));
  71. continue;
  72. }
  73. }
  74. // Update and remove invalid old game mod ids
  75. if($clear_old){
  76. $db->updateOGPGameModsWithNewIDs($oldStructure);
  77. }
  78. print_success(get_lang('configs_updated_ok'));
  79. }
  80. $game_cfgs = $db->getGameCfgs();
  81. echo "<table class='center'>\n
  82. <form action='' method='GET'>\n
  83. <input type='hidden' name='m' value='config_games'/>
  84. <tr>\n
  85. <td class='left'>\n
  86. <select name='home_cfg_id' onchange=".'"this.form.submit()"'.">\n
  87. <option style='background:black;color:white;' value=''>".get_lang('select_game')."</option>\n";
  88. foreach ( $game_cfgs as $row )
  89. {
  90. if ( preg_match( "/_win/", $row['game_key'] ) )
  91. $os = "(Windows)";
  92. if (preg_match( "/_linux/", $row['game_key'] ) )
  93. $os = "(Linux)";
  94. if (preg_match( "/64/", $row['game_key'] ) )
  95. $arch = "(64bit)";
  96. else
  97. $arch = "";
  98. if ( isset($_GET['home_cfg_id']) AND $row['home_cfg_id'] == $_GET['home_cfg_id'])
  99. $selected = "selected='selected'";
  100. else
  101. $selected = "";
  102. echo "<option value='".$row['home_cfg_id']."' $selected >".$row['game_name']." $os $arch</option>\n";
  103. unset ($os,$arch);
  104. }
  105. echo "</select>\n
  106. </td>\n
  107. </tr>\n
  108. </form>\n
  109. </table>\n";
  110. if ( isset($_GET['home_cfg_id']) )
  111. {
  112. $home_cfg_id = trim($_GET['home_cfg_id']);
  113. $cfg_info = $db->getGameCfg($home_cfg_id);
  114. if($cfg_info !== FALSE)
  115. {
  116. $config_file = SERVER_CONFIG_LOCATION.$cfg_info['home_cfg_file'];
  117. if ( preg_match( "/_win/", $cfg_info['game_key'] ) )
  118. $os = "(Windows)";
  119. if (preg_match( "/_linux/", $cfg_info['game_key'] ) )
  120. $os = "(Linux)";
  121. if (preg_match( "/64/", $cfg_info['game_key'] ) )
  122. $arch = "(64bit)";
  123. else
  124. $arch = "";
  125. if( isset($_GET['delete']) )
  126. {
  127. if( $db->delGameCfgAndMods($home_cfg_id) === FALSE )
  128. {
  129. print_failure(get_lang_f('failed_to_delete_config_from_db',$cfg_info['game_name']));
  130. $view->refresh('?m=config_games&home_cfg_id='.$home_cfg_id,3);
  131. }
  132. elseif( unlink($config_file) === FALSE )
  133. {
  134. print_failure(get_lang_f('failed_removing_file',$config_file));
  135. $view->refresh('?m=config_games&home_cfg_id='.$home_cfg_id,3);
  136. }
  137. else
  138. {
  139. print_success(get_lang_f('removed_game_cfg_from_disk_and_datbase',$cfg_info['game_name']." $os $arch"));
  140. $view->refresh('?m=config_games',3);
  141. }
  142. }
  143. else
  144. {
  145. echo "<a href='?m=config_games&home_cfg_id=".$home_cfg_id."&delete'>".get_lang_f('delete_game_config_for',$cfg_info['game_name']." $os $arch")."</a><br>";
  146. $configs = read_server_config($config_file);
  147. echo "<table>\n";
  148. foreach( $configs as $key => $value )
  149. {
  150. echo "<tr><td><b>$key<b></td><td colspan=25 >$value</td></tr>\n";
  151. foreach($value as $subkey => $subvalue )
  152. {
  153. echo "<tr><td><b>$subkey<b></td><td>$subvalue</td>\n";
  154. list($attributes,$attrvalue)=array(key($subvalue), current($subvalue));
  155. foreach($attrvalue as $attrkey => $attrval)
  156. {
  157. echo "<td><b>$attrkey<b></td><td>$attrval</td>\n";
  158. }
  159. echo "</td>";
  160. foreach($subvalue as $option => $options )
  161. {
  162. echo "<td><b>$option<b></td><td>$options</td>\n";
  163. }
  164. }
  165. echo "</tr>\n";
  166. }
  167. echo "</table>\n";
  168. }
  169. }
  170. }
  171. if(isset($_GET['xml_config_creator']))
  172. {
  173. echo "<iframe style='width:100%;height:600px;' frameBorder='0' src='home.php?m=config_games&p=xml_config_creator&type=cleared' ></iframe>";
  174. }
  175. else
  176. {
  177. echo "<br><form action='' method='GET'><input type='hidden' name='m' value='config_games' /><input type='submit' name='xml_config_creator' value='".get_lang('create_xml_configs')."'/></form>";
  178. }
  179. }
  180. ?>