ManageServer.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  1. <?php
  2. /**
  3. * Contains all the functionality required to be able to edit the core server
  4. * settings. This includes anything from which an error may result in the forum
  5. * destroying itself in a firey fury.
  6. *
  7. * Adding options to one of the setting screens isn't hard. Call prepareDBSettingsContext;
  8. * The basic format for a checkbox is:
  9. * array('check', 'nameInModSettingsAndSQL'),
  10. * And for a text box:
  11. * array('text', 'nameInModSettingsAndSQL')
  12. * (NOTE: You have to add an entry for this at the bottom!)
  13. *
  14. * In these cases, it will look for $txt['nameInModSettingsAndSQL'] as the description,
  15. * and $helptxt['nameInModSettingsAndSQL'] as the help popup description.
  16. *
  17. * Here's a quick explanation of how to add a new item:
  18. *
  19. * - A text input box. For textual values.
  20. * array('text', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth'),
  21. * - A text input box. For numerical values.
  22. * array('int', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth'),
  23. * - A text input box. For floating point values.
  24. * array('float', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth'),
  25. * - A large text input box. Used for textual values spanning multiple lines.
  26. * array('large_text', 'nameInModSettingsAndSQL', 'OptionalNumberOfRows'),
  27. * - A check box. Either one or zero. (boolean)
  28. * array('check', 'nameInModSettingsAndSQL'),
  29. * - A selection box. Used for the selection of something from a list.
  30. * array('select', 'nameInModSettingsAndSQL', array('valueForSQL' => $txt['displayedValue'])),
  31. * Note that just saying array('first', 'second') will put 0 in the SQL for 'first'.
  32. * - A password input box. Used for passwords, no less!
  33. * array('password', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth'),
  34. * - A permission - for picking groups who have a permission.
  35. * array('permissions', 'manage_groups'),
  36. * - A BBC selection box.
  37. * array('bbc', 'sig_bbc'),
  38. * - A list of boards to choose from
  39. * array('boards', 'likes_boards'),
  40. * Note that the storage in the database is as 1,2,3,4
  41. *
  42. * For each option:
  43. * - type (see above), variable name, size/possible values.
  44. * OR make type '' for an empty string for a horizontal rule.
  45. * - SET preinput - to put some HTML prior to the input box.
  46. * - SET postinput - to put some HTML following the input box.
  47. * - SET invalid - to mark the data as invalid.
  48. * - PLUS you can override label and help parameters by forcing their keys in the array, for example:
  49. * array('text', 'invalidlabel', 3, 'label' => 'Actual Label')
  50. *
  51. * Simple Machines Forum (SMF)
  52. *
  53. * @package SMF
  54. * @author Simple Machines http://www.simplemachines.org
  55. * @copyright 2013 Simple Machines and individual contributors
  56. * @license http://www.simplemachines.org/about/smf/license.php BSD
  57. *
  58. * @version 2.1 Alpha 1
  59. */
  60. if (!defined('SMF'))
  61. die('No direct access...');
  62. /**
  63. * This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects
  64. * the appropriate one based on the sub-action.
  65. *
  66. * Requires the admin_forum permission.
  67. * Redirects to the appropriate function based on the sub-action.
  68. *
  69. * @uses edit_settings adminIndex.
  70. */
  71. function ModifySettings()
  72. {
  73. global $context, $txt, $scripturl, $boarddir;
  74. // This is just to keep the database password more secure.
  75. isAllowedTo('admin_forum');
  76. // Load up all the tabs...
  77. $context[$context['admin_menu_name']]['tab_data'] = array(
  78. 'title' => $txt['admin_server_settings'],
  79. 'help' => 'serversettings',
  80. 'description' => $txt['admin_basic_settings'],
  81. );
  82. checkSession('request');
  83. // The settings are in here, I swear!
  84. loadLanguage('ManageSettings');
  85. $context['page_title'] = $txt['admin_server_settings'];
  86. $context['sub_template'] = 'show_settings';
  87. $subActions = array(
  88. 'general' => 'ModifyGeneralSettings',
  89. 'database' => 'ModifyDatabaseSettings',
  90. 'cookie' => 'ModifyCookieSettings',
  91. 'security' => 'ModifyGeneralSecuritySettings',
  92. 'cache' => 'ModifyCacheSettings',
  93. 'loads' => 'ModifyLoadBalancingSettings',
  94. 'phpinfo' => 'ShowPHPinfoSettings',
  95. );
  96. call_integration_hook('integrate_server_settings', array(&$subActions));
  97. // By default we're editing the core settings
  98. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'general';
  99. $context['sub_action'] = $_REQUEST['sa'];
  100. // Any messages to speak of?
  101. $context['settings_message'] = (isset($_REQUEST['msg']) && isset($txt[$_REQUEST['msg']])) ? $txt[$_REQUEST['msg']] : '';
  102. // Warn the user if there's any relevant information regarding Settings.php.
  103. if ($_REQUEST['sa'] != 'cache')
  104. {
  105. // Warn the user if the backup of Settings.php failed.
  106. $settings_not_writable = !is_writable($boarddir . '/Settings.php');
  107. $settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
  108. if ($settings_not_writable)
  109. $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br />';
  110. elseif ($settings_backup_fail)
  111. $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br />';
  112. $context['settings_not_writable'] = $settings_not_writable;
  113. }
  114. // Call the right function for this sub-action.
  115. $subActions[$_REQUEST['sa']]();
  116. }
  117. /**
  118. * General forum settings - forum name, maintenance mode, etc.
  119. * Practically, this shows an interface for the settings in Settings.php to be changed.
  120. *
  121. * - It uses the rawdata sub template (not theme-able.)
  122. * - Requires the admin_forum permission.
  123. * - Uses the edit_settings administration area.
  124. * - Contains the actual array of settings to show from Settings.php.
  125. * - Accessed from ?action=admin;area=serversettings;sa=general.
  126. *
  127. * @param $return_config
  128. */
  129. function ModifyGeneralSettings($return_config = false)
  130. {
  131. global $scripturl, $context, $txt;
  132. /* If you're writing a mod, it's a bad idea to add things here....
  133. For each option:
  134. variable name, description, type (constant), size/possible values, helptext.
  135. OR an empty string for a horizontal rule.
  136. OR a string for a titled section. */
  137. $config_vars = array(
  138. array('mbname', $txt['admin_title'], 'file', 'text', 30),
  139. '',
  140. array('maintenance', $txt['admin_maintain'], 'file', 'check'),
  141. array('mtitle', $txt['maintenance_subject'], 'file', 'text', 36),
  142. array('mmessage', $txt['maintenance_message'], 'file', 'text', 36),
  143. '',
  144. array('webmaster_email', $txt['admin_webmaster_email'], 'file', 'text', 30),
  145. '',
  146. array('enableCompressedOutput', $txt['enableCompressedOutput'], 'db', 'check', null, 'enableCompressedOutput'),
  147. array('disableTemplateEval', $txt['disableTemplateEval'], 'db', 'check', null, 'disableTemplateEval'),
  148. array('disableHostnameLookup', $txt['disableHostnameLookup'], 'db', 'check', null, 'disableHostnameLookup'),
  149. );
  150. call_integration_hook('integrate_general_settings', array(&$config_vars));
  151. if ($return_config)
  152. return $config_vars;
  153. // Setup the template stuff.
  154. $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=general;save';
  155. $context['settings_title'] = $txt['general_settings'];
  156. // Saving settings?
  157. if (isset($_REQUEST['save']))
  158. {
  159. call_integration_hook('integrate_save_general_settings');
  160. saveSettings($config_vars);
  161. redirectexit('action=admin;area=serversettings;sa=general;' . $context['session_var'] . '=' . $context['session_id']. ';msg=' . (!empty($context['settings_message']) ? $context['settings_message'] : 'core_settings_saved'));
  162. }
  163. // Fill the config array.
  164. prepareServerSettingsContext($config_vars);
  165. }
  166. /**
  167. * Basic database and paths settings - database name, host, etc.
  168. *
  169. * - It shows an interface for the settings in Settings.php to be changed.
  170. * - It contains the actual array of settings to show from Settings.php.
  171. * - It uses the rawdata sub template (not theme-able.)
  172. * - Requires the admin_forum permission.
  173. * - Uses the edit_settings administration area.
  174. * - Accessed from ?action=admin;area=serversettings;sa=database.
  175. *
  176. * @param $return_config
  177. */
  178. function ModifyDatabaseSettings($return_config = false)
  179. {
  180. global $scripturl, $context, $settings, $txt, $boarddir;
  181. /* If you're writing a mod, it's a bad idea to add things here....
  182. For each option:
  183. variable name, description, type (constant), size/possible values, helptext.
  184. OR an empty string for a horizontal rule.
  185. OR a string for a titled section. */
  186. $config_vars = array(
  187. array('db_persist', $txt['db_persist'], 'file', 'check', null, 'db_persist'),
  188. array('db_error_send', $txt['db_error_send'], 'file', 'check'),
  189. array('ssi_db_user', $txt['ssi_db_user'], 'file', 'text', null, 'ssi_db_user'),
  190. array('ssi_db_passwd', $txt['ssi_db_passwd'], 'file', 'password'),
  191. '',
  192. array('autoFixDatabase', $txt['autoFixDatabase'], 'db', 'check', false, 'autoFixDatabase'),
  193. array('autoOptMaxOnline', $txt['autoOptMaxOnline'], 'subtext' => $txt['zero_for_no_limit'], 'db', 'int'),
  194. '',
  195. array('cachedir', $txt['cachedir'], 'file', 'text', 36),
  196. );
  197. call_integration_hook('integrate_database_settings', array(&$config_vars));
  198. if ($return_config)
  199. return $config_vars;
  200. // Setup the template stuff.
  201. $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save';
  202. $context['settings_title'] = $txt['database_paths_settings'];
  203. $context['save_disabled'] = $context['settings_not_writable'];
  204. // Saving settings?
  205. if (isset($_REQUEST['save']))
  206. {
  207. call_integration_hook('integrate_save_database_settings');
  208. saveSettings($config_vars);
  209. redirectexit('action=admin;area=serversettings;sa=database;' . $context['session_var'] . '=' . $context['session_id'] . ';msg=' . (!empty($context['settings_message']) ? $context['settings_message'] : 'core_settings_saved'));
  210. }
  211. // Fill the config array.
  212. prepareServerSettingsContext($config_vars);
  213. }
  214. /**
  215. * This function handles cookies settings modifications.
  216. *
  217. * @param bool $return_config = false
  218. */
  219. function ModifyCookieSettings($return_config = false)
  220. {
  221. global $context, $scripturl, $txt, $sourcedir, $modSettings, $cookiename, $user_settings, $boardurl;
  222. // Define the variables we want to edit.
  223. $config_vars = array(
  224. // Cookies...
  225. array('cookiename', $txt['cookie_name'], 'file', 'text', 20),
  226. array('cookieTime', $txt['cookieTime'], 'db', 'int', 'postinput' => $txt['minutes']),
  227. array('localCookies', $txt['localCookies'], 'db', 'check', false, 'localCookies'),
  228. array('globalCookies', $txt['globalCookies'], 'db', 'check', false, 'globalCookies'),
  229. array('globalCookiesDomain', $txt['globalCookiesDomain'], 'db', 'text', false, 'globalCookiesDomain'),
  230. array('secureCookies', $txt['secureCookies'], 'db', 'check', false, 'secureCookies', 'disabled' => !isset($_SERVER['HTTPS']) || !(strtolower($_SERVER['HTTPS']) == 'on' || strtolower($_SERVER['HTTPS']) == '1')),
  231. array('httponlyCookies', $txt['httponlyCookies'], 'db', 'check', false, 'httponlyCookies'),
  232. '',
  233. // Sessions
  234. array('databaseSession_enable', $txt['databaseSession_enable'], 'db', 'check', false, 'databaseSession_enable'),
  235. array('databaseSession_loose', $txt['databaseSession_loose'], 'db', 'check', false, 'databaseSession_loose'),
  236. array('databaseSession_lifetime', $txt['databaseSession_lifetime'], 'db', 'int', false, 'databaseSession_lifetime', 'postinput' => $txt['seconds']),
  237. );
  238. addInlineJavascript('
  239. function hideGlobalCookies()
  240. {
  241. var usingLocal = $("#localCookies").prop("checked");
  242. $("#setting_globalCookies").closest("dt").toggle(!usingLocal);
  243. $("#globalCookies").closest("dd").toggle(!usingLocal);
  244. var usingGlobal = !usingLocal && $("#globalCookies").prop("checked");
  245. $("#setting_globalCookiesDomain").closest("dt").toggle(usingGlobal);
  246. $("#globalCookiesDomain").closest("dd").toggle(usingGlobal);
  247. };
  248. hideGlobalCookies();
  249. $("#localCookies, #globalCookies").click(function() {
  250. hideGlobalCookies();
  251. });', true);
  252. call_integration_hook('integrate_cookie_settings', array(&$config_vars));
  253. if ($return_config)
  254. return $config_vars;
  255. $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save';
  256. $context['settings_title'] = $txt['cookies_sessions_settings'];
  257. // Saving settings?
  258. if (isset($_REQUEST['save']))
  259. {
  260. call_integration_hook('integrate_save_cookie_settings');
  261. // Local and global do not play nicely together.
  262. if (!empty($_POST['localCookies']) && empty($_POST['globalCookies']))
  263. unset ($_POST['globalCookies']);
  264. if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false)
  265. fatal_lang_error('invalid_cookie_domain', false);
  266. saveSettings($config_vars);
  267. // If the cookie name was changed, reset the cookie.
  268. if ($cookiename != $_POST['cookiename'])
  269. {
  270. $original_session_id = $context['session_id'];
  271. include_once($sourcedir . '/Subs-Auth.php');
  272. // Remove the old cookie.
  273. setLoginCookie(-3600, 0);
  274. // Set the new one.
  275. $cookiename = $_POST['cookiename'];
  276. setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], sha1($user_settings['passwd'] . $user_settings['password_salt']));
  277. redirectexit('action=admin;area=serversettings;sa=cookie;' . $context['session_var'] . '=' . $original_session_id, $context['server']['needs_login_fix']);
  278. }
  279. redirectexit('action=admin;area=serversettings;sa=cookie;' . $context['session_var'] . '=' . $context['session_id']. ';msg=' . (!empty($context['settings_message']) ? $context['settings_message'] : 'core_settings_saved'));
  280. }
  281. // Fill the config array.
  282. prepareServerSettingsContext($config_vars);
  283. }
  284. /**
  285. * Settings really associated with general security aspects.
  286. *
  287. * @param $return_config
  288. */
  289. function ModifyGeneralSecuritySettings($return_config = false)
  290. {
  291. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  292. $config_vars = array(
  293. array('int', 'failed_login_threshold'),
  294. array('int', 'loginHistoryDays'),
  295. '',
  296. array('check', 'securityDisable'),
  297. array('check', 'securityDisable_moderate'),
  298. '',
  299. // Reactive on email, and approve on delete
  300. array('check', 'send_validation_onChange'),
  301. array('check', 'approveAccountDeletion'),
  302. '',
  303. // Password strength.
  304. array('select', 'password_strength', array($txt['setting_password_strength_low'], $txt['setting_password_strength_medium'], $txt['setting_password_strength_high'])),
  305. array('check', 'enable_password_conversion'),
  306. '',
  307. // Reporting of personal messages?
  308. array('check', 'enableReportPM'),
  309. '',
  310. array('select', 'frame_security', array('SAMEORIGIN' => $txt['setting_frame_security_SAMEORIGIN'], 'DENY' => $txt['setting_frame_security_DENY'], 'DISABLE' => $txt['setting_frame_security_DISABLE'])),
  311. );
  312. call_integration_hook('integrate_general_security_settings', array(&$config_vars));
  313. if ($return_config)
  314. return $config_vars;
  315. // Saving?
  316. if (isset($_GET['save']))
  317. {
  318. saveDBSettings($config_vars);
  319. $_SESSION['adm-save'] = true;
  320. call_integration_hook('integrate_save_general_security_settings');
  321. writeLog();
  322. redirectexit('action=admin;area=serversettings;sa=security;' . $context['session_var'] . '=' . $context['session_id']);
  323. }
  324. $context['post_url'] = $scripturl . '?action=admin;area=serversettings;save;sa=security';
  325. $context['settings_title'] = $txt['security_settings'];
  326. prepareDBSettingContext($config_vars);
  327. }
  328. /**
  329. * Simply modifying cache functions
  330. *
  331. * @param bool $return_config = false
  332. */
  333. function ModifyCacheSettings($return_config = false)
  334. {
  335. global $context, $scripturl, $txt, $helptxt, $cache_enable;
  336. // Detect all available optimizers
  337. $detected = array();
  338. if (function_exists('eaccelerator_put'))
  339. $detected['eaccelerator'] = $txt['eAccelerator_cache'];
  340. if (function_exists('mmcache_put'))
  341. $detected['mmcache'] = $txt['mmcache_cache'];
  342. if (function_exists('apc_store'))
  343. $detected['apc'] = $txt['apc_cache'];
  344. if (function_exists('output_cache_put') || function_exists('zend_shm_cache_store'))
  345. $detected['zend'] = $txt['zend_cache'];
  346. if (function_exists('memcache_set') || function_exists('memcached_set'))
  347. $detected['memcached'] = $txt['memcached_cache'];
  348. if (function_exists('xcache_set'))
  349. $detected['xcache'] = $txt['xcache_cache'];
  350. if (function_exists('file_put_contents'))
  351. $detected['smf'] = $txt['default_cache'];
  352. // set our values to show what, if anything, we found
  353. if (empty($detected))
  354. {
  355. $txt['cache_settings_message'] = $txt['detected_no_caching'];
  356. $cache_level = array($txt['cache_off']);
  357. $detected['none'] = $txt['cache_off'];
  358. }
  359. else
  360. {
  361. $txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected));
  362. $cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']);
  363. }
  364. // Define the variables we want to edit.
  365. $config_vars = array(
  366. // Only a few settings, but they are important
  367. array('', $txt['cache_settings_message'], '', 'desc'),
  368. array('cache_enable', $txt['cache_enable'], 'file', 'select', $cache_level, 'cache_enable'),
  369. array('cache_accelerator', $txt['cache_accelerator'], 'file', 'select', $detected),
  370. array('cache_memcached', $txt['cache_memcached'], 'file', 'text', $txt['cache_memcached'], 'cache_memcached'),
  371. array('cachedir', $txt['cachedir'], 'file', 'text', 36, 'cache_cachedir'),
  372. );
  373. // some javascript to enable / disable certain settings if the option is not selected
  374. $context['settings_post_javascript'] = '
  375. var cache_type = document.getElementById(\'cache_accelerator\');
  376. createEventListener(cache_type);
  377. cache_type.addEventListener("change", toggleCache);
  378. toggleCache();';
  379. call_integration_hook('integrate_modify_cache_settings', array(&$config_vars));
  380. if ($return_config)
  381. return $config_vars;
  382. // Saving again?
  383. if (isset($_GET['save']))
  384. {
  385. call_integration_hook('integrate_save_cache_settings');
  386. saveSettings($config_vars);
  387. // we need to save the $cache_enable to $modSettings as well
  388. updatesettings(array('cache_enable' => (int) $_POST['cache_enable']));
  389. // exit so we reload our new settings on the page
  390. redirectexit('action=admin;area=serversettings;sa=cache;' . $context['session_var'] . '=' . $context['session_id']);
  391. }
  392. loadLanguage('ManageMaintenance');
  393. createToken('admin-maint');
  394. $context['template_layers'][] = 'clean_cache_button';
  395. $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cache;save';
  396. $context['settings_title'] = $txt['caching_settings'];
  397. $context['settings_message'] = $txt['caching_information'];
  398. // Prepare the template.
  399. createToken('admin-ssc');
  400. prepareServerSettingsContext($config_vars);
  401. }
  402. /**
  403. * Allows to edit load balancing settings.
  404. *
  405. * @param bool $return_config = false
  406. */
  407. function ModifyLoadBalancingSettings($return_config = false)
  408. {
  409. global $txt, $scripturl, $context, $settings, $modSettings;
  410. // Setup a warning message, but disabled by default.
  411. $disabled = true;
  412. $context['settings_message'] = $txt['loadavg_disabled_conf'];
  413. if (stripos(PHP_OS, 'win') === 0)
  414. {
  415. $context['settings_message'] = $txt['loadavg_disabled_windows'];
  416. if (isset($_GET['save']))
  417. $_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
  418. }
  419. else
  420. {
  421. $modSettings['load_average'] = @file_get_contents('/proc/loadavg');
  422. if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0)
  423. $modSettings['load_average'] = (float) $matches[1];
  424. elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0)
  425. $modSettings['load_average'] = (float) $matches[1];
  426. else
  427. unset($modSettings['load_average']);
  428. if (!empty($modSettings['load_average']))
  429. {
  430. $context['settings_message'] = sprintf($txt['loadavg_warning'], $modSettings['load_average']);
  431. $disabled = false;
  432. }
  433. }
  434. // Start with a simple checkbox.
  435. $config_vars = array(
  436. array('check', 'loadavg_enable', 'disabled' => $disabled),
  437. );
  438. // Set the default values for each option.
  439. $default_values = array(
  440. 'loadavg_auto_opt' => '1.0',
  441. 'loadavg_search' => '2.5',
  442. 'loadavg_allunread' => '2.0',
  443. 'loadavg_unreadreplies' => '3.5',
  444. 'loadavg_show_posts' => '2.0',
  445. 'loadavg_userstats' => '10.0',
  446. 'loadavg_bbc' => '30.0',
  447. 'loadavg_forum' => '40.0',
  448. );
  449. // Loop through the settings.
  450. foreach ($default_values as $name => $value)
  451. {
  452. // Use the default value if the setting isn't set yet.
  453. $value = !isset($modSettings[$name]) ? $value : $modSettings[$name];
  454. $config_vars[] = array('text', $name, 'value' => $value, 'disabled' => $disabled);
  455. }
  456. call_integration_hook('integrate_loadavg_settings', array(&$config_vars));
  457. if ($return_config)
  458. return $config_vars;
  459. $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save';
  460. $context['settings_title'] = $txt['load_balancing_settings'];
  461. // Saving?
  462. if (isset($_GET['save']))
  463. {
  464. // Stupidity is not allowed.
  465. foreach ($_POST as $key => $value)
  466. {
  467. if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable')
  468. continue;
  469. elseif ($key == 'loadavg_auto_opt' && $value <= 1)
  470. $_POST['loadavg_auto_opt'] = '1.0';
  471. elseif ($key == 'loadavg_forum' && $value < 10)
  472. $_POST['loadavg_forum'] = '10.0';
  473. elseif ($value < 2)
  474. $_POST[$key] = '2.0';
  475. }
  476. call_integration_hook('integrate_save_loadavg_settings');
  477. saveDBSettings($config_vars);
  478. if (!isset($_SESSION['adm-save']))
  479. $_SESSION['adm-save'] = true;
  480. redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']);
  481. }
  482. createToken('admin-ssc');
  483. createToken('admin-dbsc');
  484. prepareDBSettingContext($config_vars);
  485. }
  486. /**
  487. * Helper function, it sets up the context for the manage server settings.
  488. * - The basic usage of the six numbered key fields are
  489. * - array (0 ,1, 2, 3, 4, 5
  490. * 0 variable name - the name of the saved variable
  491. * 1 label - the text to show on the settings page
  492. * 2 saveto - file or db, where to save the variable name - value pair
  493. * 3 type - type of data to save, int, float, text, check
  494. * 4 size - false or field size
  495. * 5 help - '' or helptxt variable name
  496. * )
  497. *
  498. * the following named keys are also permitted
  499. * 'disabled' => 'postinput' => 'preinput' =>
  500. *
  501. * @param array $config_vars
  502. */
  503. function prepareServerSettingsContext(&$config_vars)
  504. {
  505. global $context, $modSettings, $smcFunc;
  506. if (isset($_SESSION['adm-save']))
  507. {
  508. if ($_SESSION['adm-save'] === true)
  509. $context['saved_successful'] = true;
  510. else
  511. $context['saved_failed'] = $_SESSION['adm-save'];
  512. unset($_SESSION['adm-save']);
  513. }
  514. $context['config_vars'] = array();
  515. foreach ($config_vars as $identifier => $config_var)
  516. {
  517. if (!is_array($config_var) || !isset($config_var[1]))
  518. $context['config_vars'][] = $config_var;
  519. else
  520. {
  521. $varname = $config_var[0];
  522. global $$varname;
  523. // Set the subtext in case it's part of the label.
  524. // @todo Temporary. Preventing divs inside label tags.
  525. $divPos = strpos($config_var[1], '<div');
  526. $subtext = '';
  527. if ($divPos !== false)
  528. {
  529. $subtext = preg_replace('~</?div[^>]*>~', '', substr($config_var[1], $divPos));
  530. $config_var[1] = substr($config_var[1], 0, $divPos);
  531. }
  532. $context['config_vars'][$config_var[0]] = array(
  533. 'label' => $config_var[1],
  534. 'help' => isset($config_var[5]) ? $config_var[5] : '',
  535. 'type' => $config_var[3],
  536. 'size' => empty($config_var[4]) ? 0 : $config_var[4],
  537. 'data' => isset($config_var[4]) && is_array($config_var[4]) && $config_var[3] != 'select' ? $config_var[4] : array(),
  538. 'name' => $config_var[0],
  539. 'value' => $config_var[2] == 'file' ? $smcFunc['htmlspecialchars']($$varname) : (isset($modSettings[$config_var[0]]) ? $smcFunc['htmlspecialchars']($modSettings[$config_var[0]]) : (in_array($config_var[3], array('int', 'float')) ? 0 : '')),
  540. 'disabled' => !empty($context['settings_not_writable']) || !empty($config_var['disabled']),
  541. 'invalid' => false,
  542. 'subtext' => !empty($config_var['subtext']) ? $config_var['subtext'] : $subtext,
  543. 'javascript' => '',
  544. 'preinput' => !empty($config_var['preinput']) ? $config_var['preinput'] : '',
  545. 'postinput' => !empty($config_var['postinput']) ? $config_var['postinput'] : '',
  546. );
  547. // If this is a select box handle any data.
  548. if (!empty($config_var[4]) && is_array($config_var[4]))
  549. {
  550. // If it's associative
  551. $config_values = array_values($config_var[4]);
  552. if (isset($config_values[0]) && is_array($config_values[0]))
  553. $context['config_vars'][$config_var[0]]['data'] = $config_var[4];
  554. else
  555. {
  556. foreach ($config_var[4] as $key => $item)
  557. $context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
  558. }
  559. }
  560. }
  561. }
  562. // Two tokens because saving these settings requires both saveSettings and saveDBSettings
  563. createToken('admin-ssc');
  564. createToken('admin-dbsc');
  565. }
  566. /**
  567. * Helper function, it sets up the context for database settings.
  568. * @todo see rev. 10406 from 2.1-requests
  569. *
  570. * @param array $config_vars
  571. */
  572. function prepareDBSettingContext(&$config_vars)
  573. {
  574. global $txt, $helptxt, $context, $modSettings, $sourcedir, $smcFunc;
  575. loadLanguage('Help');
  576. if (isset($_SESSION['adm-save']))
  577. {
  578. if ($_SESSION['adm-save'] === true)
  579. $context['saved_successful'] = true;
  580. else
  581. $context['saved_failed'] = $_SESSION['adm-save'];
  582. unset($_SESSION['adm-save']);
  583. }
  584. $context['config_vars'] = array();
  585. $inlinePermissions = array();
  586. $bbcChoice = array();
  587. $board_list = false;
  588. foreach ($config_vars as $config_var)
  589. {
  590. // HR?
  591. if (!is_array($config_var))
  592. $context['config_vars'][] = $config_var;
  593. else
  594. {
  595. // If it has no name it doesn't have any purpose!
  596. if (empty($config_var[1]))
  597. continue;
  598. // Special case for inline permissions
  599. if ($config_var[0] == 'permissions' && allowedTo('manage_permissions'))
  600. $inlinePermissions[] = $config_var[1];
  601. elseif ($config_var[0] == 'permissions')
  602. continue;
  603. if ($config_var[0] == 'boards')
  604. $board_list = true;
  605. // Are we showing the BBC selection box?
  606. if ($config_var[0] == 'bbc')
  607. $bbcChoice[] = $config_var[1];
  608. // We need to do some parsing of the value before we pass it in.
  609. if (isset($modSettings[$config_var[1]]))
  610. {
  611. switch ($config_var[0])
  612. {
  613. case 'select':
  614. $value = $modSettings[$config_var[1]];
  615. break;
  616. case 'boards':
  617. $value = explode(',', $modSettings[$config_var[1]]);
  618. break;
  619. default:
  620. $value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]);
  621. }
  622. }
  623. else
  624. {
  625. // Darn, it's empty. What type is expected?
  626. switch ($config_var[0])
  627. {
  628. case 'int':
  629. case 'float':
  630. $value = 0;
  631. break;
  632. case 'select':
  633. $value = !empty($config_var['multiple']) ? serialize(array()) : '';
  634. break;
  635. case 'boards':
  636. $value = array();
  637. break;
  638. default:
  639. $value = '';
  640. }
  641. }
  642. $context['config_vars'][$config_var[1]] = array(
  643. 'label' => isset($config_var['text_label']) ? $config_var['text_label'] : (isset($txt[$config_var[1]]) ? $txt[$config_var[1]] : (isset($config_var[3]) && !is_array($config_var[3]) ? $config_var[3] : '')),
  644. 'help' => isset($helptxt[$config_var[1]]) ? $config_var[1] : '',
  645. 'type' => $config_var[0],
  646. 'size' => !empty($config_var[2]) && !is_array($config_var[2]) ? $config_var[2] : (in_array($config_var[0], array('int', 'float')) ? 6 : 0),
  647. 'data' => array(),
  648. 'name' => $config_var[1],
  649. 'value' => $value,
  650. 'disabled' => false,
  651. 'invalid' => !empty($config_var['invalid']),
  652. 'javascript' => '',
  653. 'var_message' => !empty($config_var['message']) && isset($txt[$config_var['message']]) ? $txt[$config_var['message']] : '',
  654. 'preinput' => isset($config_var['preinput']) ? $config_var['preinput'] : '',
  655. 'postinput' => isset($config_var['postinput']) ? $config_var['postinput'] : '',
  656. );
  657. // If this is a select box handle any data.
  658. if (!empty($config_var[2]) && is_array($config_var[2]))
  659. {
  660. // If we allow multiple selections, we need to adjust a few things.
  661. if ($config_var[0] == 'select' && !empty($config_var['multiple']))
  662. {
  663. $context['config_vars'][$config_var[1]]['name'] .= '[]';
  664. $context['config_vars'][$config_var[1]]['value'] = unserialize($context['config_vars'][$config_var[1]]['value']);
  665. }
  666. // If it's associative
  667. if (isset($config_var[2][0]) && is_array($config_var[2][0]))
  668. $context['config_vars'][$config_var[1]]['data'] = $config_var[2];
  669. else
  670. {
  671. foreach ($config_var[2] as $key => $item)
  672. $context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
  673. }
  674. }
  675. // Finally allow overrides - and some final cleanups.
  676. foreach ($config_var as $k => $v)
  677. {
  678. if (!is_numeric($k))
  679. {
  680. if (substr($k, 0, 2) == 'on')
  681. $context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
  682. else
  683. $context['config_vars'][$config_var[1]][$k] = $v;
  684. }
  685. // See if there are any other labels that might fit?
  686. if (isset($txt['setting_' . $config_var[1]]))
  687. $context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
  688. elseif (isset($txt['groups_' . $config_var[1]]))
  689. $context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
  690. }
  691. // Set the subtext in case it's part of the label.
  692. // @todo Temporary. Preventing divs inside label tags.
  693. $divPos = strpos($context['config_vars'][$config_var[1]]['label'], '<div');
  694. if ($divPos !== false)
  695. {
  696. $context['config_vars'][$config_var[1]]['subtext'] = preg_replace('~</?div[^>]*>~', '', substr($context['config_vars'][$config_var[1]]['label'], $divPos));
  697. $context['config_vars'][$config_var[1]]['label'] = substr($context['config_vars'][$config_var[1]]['label'], 0, $divPos);
  698. }
  699. }
  700. }
  701. // If we have inline permissions we need to prep them.
  702. if (!empty($inlinePermissions) && allowedTo('manage_permissions'))
  703. {
  704. require_once($sourcedir . '/ManagePermissions.php');
  705. init_inline_permissions($inlinePermissions, isset($context['permissions_excluded']) ? $context['permissions_excluded'] : array());
  706. }
  707. if ($board_list)
  708. {
  709. require_once($sourcedir . '/Subs-MessageIndex.php');
  710. $context['board_list'] = getBoardList();
  711. }
  712. // What about any BBC selection boxes?
  713. if (!empty($bbcChoice))
  714. {
  715. // What are the options, eh?
  716. $temp = parse_bbc(false);
  717. $bbcTags = array();
  718. foreach ($temp as $tag)
  719. $bbcTags[] = $tag['tag'];
  720. $bbcTags = array_unique($bbcTags);
  721. $totalTags = count($bbcTags);
  722. // The number of columns we want to show the BBC tags in.
  723. $numColumns = isset($context['num_bbc_columns']) ? $context['num_bbc_columns'] : 3;
  724. // Start working out the context stuff.
  725. $context['bbc_columns'] = array();
  726. $tagsPerColumn = ceil($totalTags / $numColumns);
  727. $col = 0; $i = 0;
  728. foreach ($bbcTags as $tag)
  729. {
  730. if ($i % $tagsPerColumn == 0 && $i != 0)
  731. $col++;
  732. $context['bbc_columns'][$col][] = array(
  733. 'tag' => $tag,
  734. // @todo 'tag_' . ?
  735. 'show_help' => isset($helptxt[$tag]),
  736. );
  737. $i++;
  738. }
  739. // Now put whatever BBC options we may have into context too!
  740. $context['bbc_sections'] = array();
  741. foreach ($bbcChoice as $bbc)
  742. {
  743. $context['bbc_sections'][$bbc] = array(
  744. 'title' => isset($txt['bbc_title_' . $bbc]) ? $txt['bbc_title_' . $bbc] : $txt['bbcTagsToUse_select'],
  745. 'disabled' => empty($modSettings['bbc_disabled_' . $bbc]) ? array() : $modSettings['bbc_disabled_' . $bbc],
  746. 'all_selected' => empty($modSettings['bbc_disabled_' . $bbc]),
  747. );
  748. }
  749. }
  750. call_integration_hook('integrate_prepare_db_settings', array(&$config_vars));
  751. createToken('admin-dbsc');
  752. }
  753. /**
  754. * Helper function. Saves settings by putting them in Settings.php or saving them in the settings table.
  755. *
  756. * - Saves those settings set from ?action=admin;area=serversettings.
  757. * - Requires the admin_forum permission.
  758. * - Contains arrays of the types of data to save into Settings.php.
  759. *
  760. * @param $config_vars
  761. */
  762. function saveSettings(&$config_vars)
  763. {
  764. global $boarddir, $sc, $cookiename, $modSettings, $user_settings;
  765. global $sourcedir, $context, $cachedir;
  766. validateToken('admin-ssc');
  767. // Fix the darn stupid cookiename! (more may not be allowed, but these for sure!)
  768. if (isset($_POST['cookiename']))
  769. $_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
  770. // Fix the forum's URL if necessary.
  771. if (isset($_POST['boardurl']))
  772. {
  773. if (substr($_POST['boardurl'], -10) == '/index.php')
  774. $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
  775. elseif (substr($_POST['boardurl'], -1) == '/')
  776. $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
  777. if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
  778. $_POST['boardurl'] = 'http://' . $_POST['boardurl'];
  779. }
  780. // Any passwords?
  781. $config_passwords = array(
  782. 'db_passwd',
  783. 'ssi_db_passwd',
  784. );
  785. // All the strings to write.
  786. $config_strs = array(
  787. 'mtitle', 'mmessage',
  788. 'language', 'mbname', 'boardurl',
  789. 'cookiename',
  790. 'webmaster_email',
  791. 'db_name', 'db_user', 'db_server', 'db_prefix', 'ssi_db_user',
  792. 'boarddir', 'sourcedir',
  793. 'cachedir', 'cache_accelerator', 'cache_memcached',
  794. );
  795. // All the numeric variables.
  796. $config_ints = array(
  797. 'cache_enable',
  798. );
  799. // All the checkboxes.
  800. $config_bools = array(
  801. 'db_persist', 'db_error_send',
  802. 'maintenance',
  803. );
  804. // Now sort everything into a big array, and figure out arrays and etc.
  805. $new_settings = array();
  806. foreach ($config_passwords as $config_var)
  807. {
  808. if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1])
  809. $new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
  810. }
  811. foreach ($config_strs as $config_var)
  812. {
  813. if (isset($_POST[$config_var]))
  814. $new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var], '\'\\') . '\'';
  815. }
  816. foreach ($config_ints as $config_var)
  817. {
  818. if (isset($_POST[$config_var]))
  819. $new_settings[$config_var] = (int) $_POST[$config_var];
  820. }
  821. foreach ($config_bools as $key)
  822. {
  823. if (!empty($_POST[$key]))
  824. $new_settings[$key] = '1';
  825. else
  826. $new_settings[$key] = '0';
  827. }
  828. // Save the relevant settings in the Settings.php file.
  829. require_once($sourcedir . '/Subs-Admin.php');
  830. updateSettingsFile($new_settings);
  831. // Now loop through the remaining (database-based) settings.
  832. $new_settings = array();
  833. foreach ($config_vars as $config_var)
  834. {
  835. // We just saved the file-based settings, so skip their definitions.
  836. if (!is_array($config_var) || $config_var[2] == 'file')
  837. continue;
  838. // Rewrite the definition a bit.
  839. $new_settings[] = array($config_var[3], $config_var[0]);
  840. }
  841. // Save the new database-based settings, if any.
  842. if (!empty($new_settings))
  843. saveDBSettings($new_settings);
  844. }
  845. /**
  846. * Helper function for saving database settings.
  847. * @todo see rev. 10406 from 2.1-requests
  848. *
  849. * @param array $config_vars
  850. */
  851. function saveDBSettings(&$config_vars)
  852. {
  853. global $sourcedir, $context, $smcFunc;
  854. static $board_list = null;
  855. validateToken('admin-dbsc');
  856. $inlinePermissions = array();
  857. foreach ($config_vars as $var)
  858. {
  859. if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags']))))
  860. continue;
  861. // Checkboxes!
  862. elseif ($var[0] == 'check')
  863. $setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
  864. // Select boxes!
  865. elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2])))
  866. $setArray[$var[1]] = $_POST[$var[1]];
  867. elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
  868. {
  869. // For security purposes we validate this line by line.
  870. $options = array();
  871. foreach ($_POST[$var[1]] as $invar)
  872. if (in_array($invar, array_keys($var[2])))
  873. $options[] = $invar;
  874. $setArray[$var[1]] = serialize($options);
  875. }
  876. // List of boards!
  877. elseif ($var[0] == 'boards')
  878. {
  879. // We just need a simple list of valid boards, nothing more.
  880. if ($board_list === null)
  881. {
  882. $board_list = array();
  883. $request = $smcFunc['db_query']('', '
  884. SELECT id_board
  885. FROM {db_prefix}boards');
  886. while ($row = $smcFunc['db_fetch_row']($request))
  887. $board_list[$row[0]] = true;
  888. $smcFunc['db_free_result']($request);
  889. }
  890. $options = array();
  891. foreach ($_POST[$var[1]] as $invar => $dummy)
  892. if (isset($board_list[$invar]))
  893. $options[] = $invar;
  894. $setArray[$var[1]] = implode(',', $options);
  895. }
  896. // Integers!
  897. elseif ($var[0] == 'int')
  898. $setArray[$var[1]] = (int) $_POST[$var[1]];
  899. // Floating point!
  900. elseif ($var[0] == 'float')
  901. $setArray[$var[1]] = (float) $_POST[$var[1]];
  902. // Text!
  903. elseif ($var[0] == 'text' || $var[0] == 'large_text')
  904. $setArray[$var[1]] = $_POST[$var[1]];
  905. // Passwords!
  906. elseif ($var[0] == 'password')
  907. {
  908. if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1])
  909. $setArray[$var[1]] = $_POST[$var[1]][0];
  910. }
  911. // BBC.
  912. elseif ($var[0] == 'bbc')
  913. {
  914. $bbcTags = array();
  915. foreach (parse_bbc(false) as $tag)
  916. $bbcTags[] = $tag['tag'];
  917. if (!isset($_POST[$var[1] . '_enabledTags']))
  918. $_POST[$var[1] . '_enabledTags'] = array();
  919. elseif (!is_array($_POST[$var[1] . '_enabledTags']))
  920. $_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
  921. $setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags']));
  922. }
  923. // Permissions?
  924. elseif ($var[0] == 'permissions')
  925. $inlinePermissions[] = $var[1];
  926. }
  927. if (!empty($setArray))
  928. updateSettings($setArray);
  929. // If we have inline permissions we need to save them.
  930. if (!empty($inlinePermissions) && allowedTo('manage_permissions'))
  931. {
  932. require_once($sourcedir . '/ManagePermissions.php');
  933. save_inline_permissions($inlinePermissions);
  934. }
  935. }
  936. /**
  937. * Allows us to see the servers php settings
  938. *
  939. * - loads the settings into an array for display in a template
  940. * - drops cookie values just in case
  941. */
  942. function ShowPHPinfoSettings()
  943. {
  944. global $context, $txt;
  945. $info_lines = array();
  946. $category = $txt['phpinfo_settings'];
  947. // get the data
  948. ob_start();
  949. phpinfo();
  950. // We only want it for its body, pigs that we are
  951. $info_lines = preg_replace('~^.*<body>(.*)</body>.*$~', '$1', ob_get_contents());
  952. $info_lines = explode("\n", strip_tags($info_lines, "<tr><td><h2>"));
  953. ob_end_clean();
  954. // remove things that could be considered sensitive
  955. $remove = '_COOKIE|Cookie|_GET|_REQUEST|REQUEST_URI|QUERY_STRING|REQUEST_URL|HTTP_REFERER';
  956. // put all of it into an array
  957. foreach ($info_lines as $line)
  958. {
  959. if (preg_match('~(' . $remove . ')~', $line))
  960. continue;
  961. // new category?
  962. if (strpos($line, '<h2>') !== false)
  963. $category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
  964. // load it as setting => value or the old setting local master
  965. if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
  966. $pinfo[$category][$val[1]] = $val[2];
  967. elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
  968. $pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
  969. }
  970. // load it in to context and display it
  971. $context['pinfo'] = $pinfo;
  972. $context['page_title'] = $txt['admin_server_settings'];
  973. $context['sub_template'] = 'php_info';
  974. return;
  975. }
  976. ?>