settings.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 exec_ogp_module()
  25. {
  26. require_once('includes/form_table_class.php');
  27. global $db,$view;
  28. if ( isset($_REQUEST['update_settings']) )
  29. {
  30. $ssl = (isset($_POST['smtp_secure']) and $_POST['smtp_secure'] == 'ssl') ? 1 : 0;
  31. $tls = (isset($_POST['smtp_secure']) and $_POST['smtp_secure'] == 'tls') ? 1 : 0;
  32. $oldSettings = $db->getSettings();
  33. $settings = array("panel_name" => $_REQUEST['panel_name'],
  34. "header_code" => $_REQUEST['header_code'],
  35. "maintenance_mode" => $_REQUEST['maintenance_mode'],
  36. "maintenance_title" => $_REQUEST['maintenance_title'],
  37. "maintenance_message" => $_REQUEST['maintenance_message'],
  38. "panel_language" => $_REQUEST['panel_language'],
  39. "time_zone" => $_REQUEST['time_zone'],
  40. "page_auto_refresh" => $_REQUEST['page_auto_refresh'],
  41. "smtp_server" => $_REQUEST['smtp_server'],
  42. "smtp_port" => $_REQUEST['smtp_port'],
  43. "smtp_login" => $_REQUEST['smtp_login'],
  44. "smtp_passw" => $_REQUEST['smtp_passw'],
  45. "smtp_ssl" => $ssl,
  46. "smtp_tls" => $tls,
  47. "panel_email_address" => $_REQUEST['panel_email_address'],
  48. "remote_query" => $_REQUEST['remote_query'],
  49. "feed_enable" => $_REQUEST['feed_enable'],
  50. "feed_url" => $_REQUEST['feed_url'],
  51. "query_cache_life" => $_REQUEST['query_cache_life'],
  52. "query_num_servers_stop" => $_REQUEST['query_num_servers_stop'],
  53. "steam_user" => $_REQUEST['steam_user'],
  54. "steam_pass" => $_REQUEST['steam_pass'],
  55. "steam_guard" => $_REQUEST['steam_guard'],
  56. "editable_email" => $_REQUEST['editable_email'],
  57. "old_dashboard_behavior" => $_REQUEST['old_dashboard_behavior'],
  58. "rsync_available" => $_REQUEST['rsync_available'],
  59. "support_widget_title" => $_REQUEST['support_widget_title'],
  60. "support_widget_content" => $_REQUEST['support_widget_content'],
  61. "support_widget_link" => $_REQUEST['support_widget_link'],
  62. "check_expiry_by" => $_REQUEST['check_expiry_by'],
  63. "recaptcha_site_key" => $_REQUEST['recaptcha_site_key'],
  64. "recaptcha_secret_key" => $_REQUEST['recaptcha_secret_key'],
  65. "recaptcha_use_login" => $_REQUEST['recaptcha_use_login'],
  66. "login_attempts_before_banned" => $_REQUEST['login_attempts_before_banned'],
  67. "custom_github_update_username" => $_REQUEST['custom_github_update_username'],
  68. "custom_github_update_branch_name" => $_REQUEST['custom_github_update_branch_name'],
  69. "show_server_id_game_monitor" => $_REQUEST['show_server_id_game_monitor'],
  70. "default_game_server_home_path_prefix" => $_REQUEST['default_game_server_home_path_prefix'],
  71. "use_authorized_hosts" => $_REQUEST['use_authorized_hosts'],
  72. "allow_setting_cpu_affinity" => $_REQUEST['allow_setting_cpu_affinity'],
  73. "regex_invalid_file_name_chars" => addslashes($_REQUEST['regex_invalid_file_name_chars']),
  74. "login_ban_time" => $_REQUEST['login_ban_time']
  75. );
  76. $db->setSettings($settings);
  77. if(array_key_exists("reset_game_server_order", $_REQUEST) && $_REQUEST["reset_game_server_order"] == 1){
  78. $db->resetGameServerOrder();
  79. }
  80. if($oldSettings["custom_github_update_branch_name"] != $settings["custom_github_update_branch_name"] || $oldSettings["custom_github_update_usernam"] != $settings["custom_github_update_usernam"]){
  81. // Delete any old atom files for extras module
  82. $extrasPathData = realpath('modules/extras/') . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR;
  83. array_map('unlink', glob($extrasPathData . "*.atom"));
  84. // Delete any branch atom for update module
  85. $updatesPath = realpath('modules/update/');
  86. array_map('unlink', glob($updatesPath . "*.atom"));
  87. }
  88. echo "<h2>".get_lang('settings')."</h2>";
  89. print_success(get_lang('settings_updated'));
  90. $view->refresh("?m=settings");
  91. return;
  92. }
  93. function formatOffset($offset) {
  94. $hours = $offset / 3600;
  95. $remainder = $offset % 3600;
  96. $sign = $hours > 0 ? '+' : '-';
  97. $hour = (int) abs($hours);
  98. $minutes = (int) abs($remainder / 60);
  99. if ($hour == 0 AND $minutes == 0) {
  100. $sign = ' ';
  101. }
  102. return $sign . str_pad($hour, 2, '0', STR_PAD_LEFT) .':'. str_pad($minutes,2, '0');
  103. }
  104. $utc = new DateTimeZone('UTC');
  105. $dt = new DateTime('now', $utc);
  106. foreach(DateTimeZone::listIdentifiers() as $tz) {
  107. $current_tz = new DateTimeZone($tz);
  108. $offset = $current_tz->getOffset($dt);
  109. $transition = $current_tz->getTransitions($dt->getTimestamp(), $dt->getTimestamp());
  110. $abbr = $transition[0]['abbr'];
  111. $zones["$tz"] = $tz . '[' . $abbr . ' ' . formatOffset($offset) . ']';
  112. }
  113. $rsync_options = array("1" => get_lang('all_available_servers'), "2" => get_lang('only_remote_servers'), "3" => get_lang('only_local_servers'));
  114. $row = $db->getSettings();
  115. echo "<h2>".get_lang('settings')."</h2>";
  116. if(@$row['use_authorized_hosts']){
  117. echo "<h4><a href='?m=settings&p=api_hosts'>".get_lang('setup_api_authorized_hosts')."</a></h4>";
  118. }
  119. $ft = new FormTable();
  120. $ft->start_form("?m=settings", "post", "autocomplete=\"off\"");
  121. $ft->start_table();
  122. $ft->add_field('string','panel_name',@$row['panel_name']);
  123. $locale_files = makefilelist("lang/", ".|..|.svn", true, "folders");
  124. $locale_files = array('' => "-") + $locale_files;
  125. $ft->add_custom_field('panel_language',
  126. create_drop_box_from_array($locale_files,"panel_language",@$row['panel_language']));
  127. $zones = array('' => "-") + $zones;
  128. $ft->add_custom_field('time_zone',
  129. create_drop_box_from_array($zones,"time_zone",@$row['time_zone'],false));
  130. $ft->add_field('text','header_code',@$row['header_code'], 38);
  131. $ft->add_field('on_off','maintenance_mode',@$row['maintenance_mode']);
  132. $ft->add_field('string','maintenance_title',@$row['maintenance_title']);
  133. $ft->add_field('text','maintenance_message',@$row['maintenance_message'], 38);
  134. $ft->add_field('on_off','page_auto_refresh',@$row['page_auto_refresh']);
  135. $ft->add_field('string','panel_email_address',@$row['panel_email_address']);
  136. $ft->add_field('string','smtp_server',@$row['smtp_server']);
  137. $ft->add_field('string','smtp_port',@$row['smtp_port']);
  138. $ssl = (isset($row['smtp_ssl']) and $row['smtp_ssl'] == 1) ? "checked='checked'" : "";
  139. $tls = (isset($row['smtp_tls']) and $row['smtp_tls'] == 1) ? "checked='checked'" : "";
  140. $no = (!isset($row['smtp_ssl']) or $row['smtp_ssl'] == 0 AND !isset($row['smtp_tls']) or ( isset($row['smtp_tls']) and $row['smtp_tls'] == 0)) ? "checked='checked'" : "";
  141. $ft->add_custom_field('smtp_secure','<input type=radio name=smtp_secure value=0 '.$no.
  142. '>'.get_lang('no').'&nbsp;&nbsp;<input type=radio name=smtp_secure value=ssl '.$ssl.
  143. '>SSL&nbsp;&nbsp;<input type=radio name=smtp_secure value=tls '.$tls.'>TLS');
  144. $ft->add_field('string','smtp_login',@$row['smtp_login']);
  145. $ft->add_field('password','smtp_passw',@$row['smtp_passw']);
  146. $ft->add_field('on_off','remote_query',@$row['remote_query']);
  147. $ft->add_field('on_off','feed_enable',@$row['feed_enable']);
  148. $ft->add_field('string','feed_url',@$row['feed_url']);
  149. $query_cache_life = (isset($row['query_cache_life']) and $row['query_cache_life'] != "" )? $row['query_cache_life'] : "30";
  150. $ft->add_field('string','query_cache_life',$query_cache_life);
  151. $query_num_servers_stop = (isset($row['query_num_servers_stop']) and $row['query_num_servers_stop'] != "" )? $row['query_num_servers_stop'] : "15";
  152. $ft->add_field('string','query_num_servers_stop',$query_num_servers_stop);
  153. $ft->add_field('string','steam_user',@$row['steam_user']);
  154. $ft->add_field('password','steam_pass',@$row['steam_pass']);
  155. $ft->add_field('password','steam_guard',@$row['steam_guard']);
  156. $mail_setting = isset($row['editable_email']) ? $row['editable_email'] : "1";
  157. $ft->add_field('on_off','editable_email',$mail_setting);
  158. $ft->add_field('on_off','old_dashboard_behavior',@$row['old_dashboard_behavior']);
  159. $ft->add_custom_field('rsync_available',
  160. create_drop_box_from_array($rsync_options,"rsync_available",@$row['rsync_available'],false));
  161. $ft->add_field('string','support_widget_title',@$row['support_widget_title']);
  162. $ft->add_field('text','support_widget_content',@$row['support_widget_content'], 38);
  163. $ft->add_field('string','support_widget_link',@$row['support_widget_link']);
  164. $ft->add_custom_field('check_expiry_by',
  165. create_drop_box_from_array(array('once_logged_in' => get_lang('once_logged_in'), 'cron_job' => get_lang('cron_job')),"check_expiry_by",@$row['check_expiry_by'],false));
  166. $ft->add_field('string','recaptcha_site_key',@$row['recaptcha_site_key']);
  167. $ft->add_field('string','recaptcha_secret_key',@$row['recaptcha_secret_key']);
  168. $ft->add_field('on_off','recaptcha_use_login',@$row['recaptcha_use_login']);
  169. $login_attempts_before_banned = (isset($row['login_attempts_before_banned']) and $row['login_attempts_before_banned'] != "" and is_numeric($row['login_attempts_before_banned']))? $row['login_attempts_before_banned'] : "6";
  170. $ft->add_field('string','login_attempts_before_banned',$login_attempts_before_banned);
  171. $ft->add_field('string','login_ban_time', array_key_exists("login_ban_time", $row) && !empty($row["login_ban_time"]) && is_numeric($row["login_ban_time"]) ? $row["login_ban_time"] : '');
  172. $ft->add_field('string','custom_github_update_username',@$row['custom_github_update_username']);
  173. $ft->add_field('string','custom_github_update_branch_name',@$row['custom_github_update_branch_name']);
  174. $ft->add_field('on_off','show_server_id_game_monitor',@$row['show_server_id_game_monitor']);
  175. $ft->add_field('string','default_game_server_home_path_prefix',@$row['default_game_server_home_path_prefix']);
  176. // Use authorized hosts for API - this should be disabled by default since using the KEY alone should be secure enough
  177. $ft->add_field('on_off','use_authorized_hosts',@$row['use_authorized_hosts']);
  178. // Allow setting the cpu affinity for game servers
  179. $ft->add_field('on_off','allow_setting_cpu_affinity',@$row['allow_setting_cpu_affinity']);
  180. // Add regex setting for file manager
  181. $ft->add_field('string','regex_invalid_file_name_chars',(@empty($row['regex_invalid_file_name_chars']) ? htmlentities('/[\^\$\*\+\?\(\)\[\{\\\\\\|\]!@#%&=~`,\\\'<>"}\s]/i', ENT_COMPAT | ENT_HTML401 | ENT_QUOTES) : htmlentities(@$row['regex_invalid_file_name_chars'], ENT_COMPAT | ENT_HTML401 | ENT_QUOTES)));
  182. // Add option to reset game server order to default
  183. $ft->add_field('checkbox','reset_game_server_order','0');
  184. $ft->end_table();
  185. $ft->add_button("submit","update_settings",get_lang('update_settings'));
  186. $ft->end_form();
  187. }
  188. ?>