config.class.inc.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. define('ITOP_VERSION', '$ITOP_VERSION$');
  17. define('ITOP_REVISION', '$WCREV$');
  18. define('ITOP_BUILD_DATE', '$WCNOW$');
  19. /**
  20. * Configuration read/write
  21. *
  22. * @author Erwan Taloc <erwan.taloc@combodo.com>
  23. * @author Romain Quetiez <romain.quetiez@combodo.com>
  24. * @author Denis Flaven <denis.flaven@combodo.com>
  25. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  26. */
  27. require_once('coreexception.class.inc.php');
  28. class ConfigException extends CoreException
  29. {
  30. }
  31. define ('DEFAULT_LOG_GLOBAL', true);
  32. define ('DEFAULT_LOG_NOTIFICATION', true);
  33. define ('DEFAULT_LOG_ISSUE', true);
  34. define ('DEFAULT_LOG_WEB_SERVICE', true);
  35. define ('DEFAULT_LOG_DURATION', false);
  36. define ('DEFAULT_MIN_DISPLAY_LIMIT', 10);
  37. define ('DEFAULT_MAX_DISPLAY_LIMIT', 15);
  38. define ('DEFAULT_STANDARD_RELOAD_INTERVAL', 5*60);
  39. define ('DEFAULT_FAST_RELOAD_INTERVAL', 1*60);
  40. define ('DEFAULT_SECURE_CONNECTION_REQUIRED', false);
  41. define ('DEFAULT_HTTPS_HYPERLINKS', false);
  42. define ('DEFAULT_ALLOWED_LOGIN_TYPES', 'form|basic|external');
  43. define ('DEFAULT_EXT_AUTH_VARIABLE', '$_SERVER[\'REMOTE_USER\']');
  44. define ('DEFAULT_ENCRYPTION_KEY', '@iT0pEncr1pti0n!'); // We'll use a random value, later...
  45. /**
  46. * Config
  47. * configuration data (this class cannot not be localized, because it is responsible for loading the dictionaries)
  48. *
  49. * @package iTopORM
  50. */
  51. class Config
  52. {
  53. //protected $m_bIsLoaded = false;
  54. protected $m_sFile = '';
  55. protected $m_aAppModules;
  56. protected $m_aDataModels;
  57. protected $m_aAddons;
  58. protected $m_aDictionaries;
  59. protected $m_aModuleSettings;
  60. protected $m_sDBHost;
  61. protected $m_sDBUser;
  62. protected $m_sDBPwd;
  63. protected $m_sDBName;
  64. protected $m_sDBSubname;
  65. /**
  66. * @var integer Event log options (see LOG_... definition)
  67. */
  68. protected $m_bLogGlobal;
  69. protected $m_bLogNotification;
  70. protected $m_bLogIssue;
  71. protected $m_bLogWebService;
  72. protected $m_bLogDuration; // private setting
  73. /**
  74. * @var integer Number of elements to be displayed when there are more than m_iMaxDisplayLimit elements
  75. */
  76. protected $m_iMinDisplayLimit;
  77. /**
  78. * @var integer Max number of elements before truncating the display
  79. */
  80. protected $m_iMaxDisplayLimit;
  81. /**
  82. * @var integer Number of seconds between two reloads of the display (standard)
  83. */
  84. protected $m_iStandardReloadInterval;
  85. /**
  86. * @var integer Number of seconds between two reloads of the display (fast)
  87. */
  88. protected $m_iFastReloadInterval;
  89. /**
  90. * @var boolean Whether or not a secure connection is required for using the application.
  91. * If set, any attempt to connect to an iTop page with http:// will be redirected
  92. * to https://
  93. */
  94. protected $m_bSecureConnectionRequired;
  95. /**
  96. * @var boolean Forces iTop to output hyperlinks starting with https:// even
  97. * if the current page is not using https. This can be useful when
  98. * the application runs behind a SSL gateway
  99. */
  100. protected $m_bHttpsHyperlinks;
  101. /**
  102. * @var string Langage code, default if the user language is undefined
  103. */
  104. protected $m_sDefaultLanguage;
  105. /**
  106. * @var string Type of login process allowed: form|basic|url|external
  107. */
  108. protected $m_sAllowedLoginTypes;
  109. /**
  110. * @var string Name of the PHP variable in which external authentication information is passed by the web server
  111. */
  112. protected $m_sExtAuthVariable;
  113. /**
  114. * @var string Encryption key used for all attributes of type "encrypted string". Can be set to a random value
  115. * unless you want to import a database from another iTop instance, in which case you must use
  116. * the same encryption key in order to properly decode the encrypted fields
  117. */
  118. protected $m_sEncryptionKey;
  119. public function __construct($sConfigFile, $bLoadConfig = true)
  120. {
  121. $this->m_sFile = $sConfigFile;
  122. $this->m_aAppModules = array(
  123. // Some default modules, always present can be move to an official iTop Module later if needed
  124. '../application/transaction.class.inc.php',
  125. '../application/menunode.class.inc.php',
  126. '../application/user.preferences.class.inc.php',
  127. '../application/audit.rule.class.inc.php',
  128. // Romain - That's dirty, because those 3 classes are in fact part of the core
  129. // but I needed those classes to be derived from cmdbAbstractObject
  130. // (to be managed via the GUI) and this class in not really known from
  131. // the core, PLUS I needed the includes to be there also for the setup
  132. // to create the tables.
  133. '../core/event.class.inc.php',
  134. '../core/action.class.inc.php',
  135. '../core/trigger.class.inc.php',
  136. );
  137. $this->m_aDataModels = array();
  138. $this->m_aAddons = array(
  139. // Default AddOn, always present can be moved to an official iTop Module later if needed
  140. 'user rights' => '../addons/userrights/userrightsprofile.class.inc.php',
  141. );
  142. $this->m_aDictionaries = array(
  143. // Default dictionaries, always present can be moved to an official iTop Module later if needed
  144. '../dictionaries/dictionary.itop.core.php',
  145. '../dictionaries/dictionary.itop.ui.php', // Support for English
  146. '../dictionaries/fr.dictionary.itop.ui.php', // Support for French
  147. '../dictionaries/fr.dictionary.itop.core.php', // Support for French
  148. '../dictionaries/es_cr.dictionary.itop.ui.php', // Support for Spanish (from Costa Rica)
  149. '../dictionaries/es_cr.dictionary.itop.core.php', // Support for Spanish (from Costa Rica)
  150. );
  151. $this->m_sDBHost = '';
  152. $this->m_sDBUser = '';
  153. $this->m_sDBPwd = '';
  154. $this->m_sDBName = '';
  155. $this->m_sDBSubname = '';
  156. $this->m_bLogGlobal = DEFAULT_LOG_GLOBAL;
  157. $this->m_bLogNotification = DEFAULT_LOG_NOTIFICATION;
  158. $this->m_bLogIssue = DEFAULT_LOG_ISSUE;
  159. $this->m_bLogWebService = DEFAULT_LOG_WEB_SERVICE;
  160. $this->m_bLogDuration = DEFAULT_LOG_DURATION;
  161. $this->m_iMinDisplayLimit = DEFAULT_MIN_DISPLAY_LIMIT;
  162. $this->m_iMaxDisplayLimit = DEFAULT_MAX_DISPLAY_LIMIT;
  163. $this->m_iStandardReloadInterval = DEFAULT_STANDARD_RELOAD_INTERVAL;
  164. $this->m_iFastReloadInterval = DEFAULT_FAST_RELOAD_INTERVAL;
  165. $this->m_bSecureConnectionRequired = DEFAULT_SECURE_CONNECTION_REQUIRED;
  166. $this->m_bHttpsHyperlinks = DEFAULT_HTTPS_HYPERLINKS;
  167. $this->m_sDefaultLanguage = 'EN US';
  168. $this->m_sAllowedLoginTypes = DEFAULT_ALLOWED_LOGIN_TYPES;
  169. $this->m_sExtAuthVariable = DEFAULT_EXT_AUTH_VARIABLE;
  170. $this->m_sEncryptionKey = DEFAULT_ENCRYPTION_KEY;
  171. $this->m_aModuleSettings = array();
  172. if ($bLoadConfig)
  173. {
  174. $this->Load($sConfigFile);
  175. $this->Verify();
  176. }
  177. }
  178. protected function CheckFile($sPurpose, $sFileName)
  179. {
  180. if (!file_exists($sFileName))
  181. {
  182. throw new ConfigException("Could not find $sPurpose file", array('file' => $sFileName));
  183. }
  184. }
  185. protected function Load($sConfigFile)
  186. {
  187. $this->CheckFile('configuration', $sConfigFile);
  188. $sConfigCode = trim(file_get_contents($sConfigFile));
  189. // This does not work on several lines
  190. // preg_match('/^<\\?php(.*)\\?'.'>$/', $sConfigCode, $aMatches)...
  191. // So, I've implemented a solution suggested in the PHP doc (search for phpWrapper)
  192. try
  193. {
  194. ob_start();
  195. eval('?'.'>'.trim($sConfigCode));
  196. $sNoise = trim(ob_get_contents());
  197. ob_end_clean();
  198. }
  199. catch (Exception $e)
  200. {
  201. // well, never reach in case of parsing error :-(
  202. // will be improved in PHP 6 ?
  203. throw new ConfigException('Error in configuration file', array('file' => $sConfigFile, 'error' => $e->getMessage()));
  204. }
  205. if (strlen($sNoise) > 0)
  206. {
  207. // Note: sNoise is an html output, but so far it was ok for me (e.g. showing the entire call stack)
  208. throw new ConfigException('Syntax error in configuration file', array('file' => $sConfigFile, 'error' => '<tt>'.htmlentities($sNoise).'</tt>'));
  209. }
  210. if (!isset($MySettings) || !is_array($MySettings))
  211. {
  212. throw new ConfigException('Missing array in configuration file', array('file' => $sConfigFile, 'expected' => '$MySettings'));
  213. }
  214. if (!isset($MyModules) || !is_array($MyModules))
  215. {
  216. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules'));
  217. }
  218. if (!array_key_exists('application', $MyModules))
  219. {
  220. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'application\']'));
  221. }
  222. if (!array_key_exists('business', $MyModules))
  223. {
  224. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'business\']'));
  225. }
  226. if (!array_key_exists('addons', $MyModules))
  227. {
  228. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'addons\']'));
  229. }
  230. if (!array_key_exists('user rights', $MyModules['addons']))
  231. {
  232. $MyModules['addons']['user rights'] = '../addons/userrights/userrightsnull.class.inc.php';
  233. }
  234. if (!array_key_exists('dictionaries', $MyModules))
  235. {
  236. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'dictionaries\']'));
  237. }
  238. $this->m_aAppModules = $MyModules['application'];
  239. $this->m_aDataModels = $MyModules['business'];
  240. $this->m_aAddons = $MyModules['addons'];
  241. $this->m_aDictionaries = $MyModules['dictionaries'];
  242. $this->m_sDBHost = trim($MySettings['db_host']);
  243. $this->m_sDBUser = trim($MySettings['db_user']);
  244. $this->m_sDBPwd = trim($MySettings['db_pwd']);
  245. $this->m_sDBName = trim($MySettings['db_name']);
  246. $this->m_sDBSubname = trim($MySettings['db_subname']);
  247. $this->m_bLogGlobal = isset($MySettings['log_global']) ? (bool) trim($MySettings['log_global']) : DEFAULT_LOG_GLOBAL;
  248. $this->m_bLogNotification = isset($MySettings['log_notification']) ? (bool) trim($MySettings['log_notification']) : DEFAULT_LOG_NOTIFICATION;
  249. $this->m_bLogIssue = isset($MySettings['log_issue']) ? (bool) trim($MySettings['log_issue']) : DEFAULT_LOG_ISSUE;
  250. $this->m_bLogWebService = isset($MySettings['log_web_service']) ? (bool) trim($MySettings['log_web_service']) : DEFAULT_LOG_WEB_SERVICE;
  251. $this->m_bLogDuration = isset($MySettings['log_duration']) ? (bool) trim($MySettings['log_duration']) : DEFAULT_LOG_DURATION;
  252. $this->m_iMinDisplayLimit = isset($MySettings['min_display_limit']) ? trim($MySettings['min_display_limit']) : DEFAULT_MIN_DISPLAY_LIMIT;
  253. $this->m_iMaxDisplayLimit = isset($MySettings['max_display_limit']) ? trim($MySettings['max_display_limit']) : DEFAULT_MAX_DISPLAY_LIMIT;
  254. $this->m_iStandardReloadInterval = isset($MySettings['standard_reload_interval']) ? trim($MySettings['standard_reload_interval']) : DEFAULT_STANDARD_RELOAD_INTERVAL;
  255. $this->m_iFastReloadInterval = isset($MySettings['fast_reload_interval']) ? trim($MySettings['fast_reload_interval']) : DEFAULT_FAST_RELOAD_INTERVAL;
  256. $this->m_bSecureConnectionRequired = isset($MySettings['secure_connection_required']) ? (bool) trim($MySettings['secure_connection_required']) : DEFAULT_SECURE_CONNECTION_REQUIRED;
  257. $this->m_bHttpsHyperlinks = isset($MySettings['https_hyperlinks']) ? (bool) trim($MySettings['https_hyperlinks']) : DEFAULT_HTTPS_HYPERLINKS;
  258. $this->m_aModuleSettings = isset($MyModuleSettings) ? $MyModuleSettings : array();
  259. $this->m_sDefaultLanguage = isset($MySettings['default_language']) ? trim($MySettings['default_language']) : 'EN US';
  260. $this->m_sAllowedLoginTypes = isset($MySettings['allowed_login_types']) ? trim($MySettings['allowed_login_types']) : DEFAULT_ALLOWED_LOGIN_TYPES;
  261. $this->m_sExtAuthVariable = isset($MySettings['ext_auth_variable']) ? trim($MySettings['ext_auth_variable']) : DEFAULT_EXT_AUTH_VARIABLE;
  262. $this->m_sEncryptionKey = isset($MySettings['encryption_key']) ? trim($MySettings['encryption_key']) : DEFAULT_ENCRYPTION_KEY;
  263. }
  264. protected function Verify()
  265. {
  266. foreach ($this->m_aAppModules as $sModule => $sToInclude)
  267. {
  268. $this->CheckFile('application module', $sToInclude);
  269. }
  270. foreach ($this->m_aDataModels as $sModule => $sToInclude)
  271. {
  272. $this->CheckFile('business model', $sToInclude);
  273. }
  274. foreach ($this->m_aAddons as $sModule => $sToInclude)
  275. {
  276. $this->CheckFile('addon module', $sToInclude);
  277. }
  278. foreach ($this->m_aDictionaries as $sModule => $sToInclude)
  279. {
  280. $this->CheckFile('dictionary', $sToInclude);
  281. }
  282. }
  283. public function GetModuleSetting($sModule, $sProperty, $defaultvalue = null)
  284. {
  285. if (isset($this->m_aModuleSettings[$sModule][$sProperty]))
  286. {
  287. return $this->m_aModuleSettings[$sModule][$sProperty];
  288. }
  289. return $defaultvalue;
  290. }
  291. public function SetModuleSetting($sModule, $sProperty, $value)
  292. {
  293. $this->m_aModuleSettings[$sModule][$sProperty] = $value;
  294. }
  295. public function GetAppModules()
  296. {
  297. return $this->m_aAppModules;
  298. }
  299. public function SetAppModules($aAppModules)
  300. {
  301. $this->m_aAppModules = $aAppModules;
  302. }
  303. public function GetDataModels()
  304. {
  305. return $this->m_aDataModels;
  306. }
  307. public function SetDataModels($aDataModels)
  308. {
  309. $this->m_aDataModels = $aDataModels;
  310. }
  311. public function GetAddons()
  312. {
  313. return $this->m_aAddons;
  314. }
  315. public function SetAddons($aAddons)
  316. {
  317. $this->m_aAddons = $aAddons;
  318. }
  319. public function GetDictionaries()
  320. {
  321. return $this->m_aDictionaries;
  322. }
  323. public function SetDictionaries($aDictionaries)
  324. {
  325. $this->m_aDictionaries = $aDictionaries;
  326. }
  327. public function GetDBHost()
  328. {
  329. return $this->m_sDBHost;
  330. }
  331. public function GetDBName()
  332. {
  333. return $this->m_sDBName;
  334. }
  335. public function GetDBSubname()
  336. {
  337. return $this->m_sDBSubname;
  338. }
  339. public function GetDBUser()
  340. {
  341. return $this->m_sDBUser;
  342. }
  343. public function GetDBPwd()
  344. {
  345. return $this->m_sDBPwd;
  346. }
  347. public function GetLogGlobal()
  348. {
  349. return $this->m_bLogGlobal;
  350. }
  351. public function GetLogNotification()
  352. {
  353. return $this->m_bLogNotification;
  354. }
  355. public function GetLogIssue()
  356. {
  357. return $this->m_bLogIssue;
  358. }
  359. public function GetLogWebService()
  360. {
  361. return $this->m_bLogWebService;
  362. }
  363. public function GetLogDuration()
  364. {
  365. return $this->m_bLogDuration;
  366. }
  367. public function GetMinDisplayLimit()
  368. {
  369. return $this->m_iMinDisplayLimit;
  370. }
  371. public function GetMaxDisplayLimit()
  372. {
  373. return $this->m_iMaxDisplayLimit;
  374. }
  375. public function GetStandardReloadInterval()
  376. {
  377. return $this->m_iStandardReloadInterval;
  378. }
  379. public function GetFastReloadInterval()
  380. {
  381. return $this->m_iFastReloadInterval;
  382. }
  383. public function GetSecureConnectionRequired()
  384. {
  385. return $this->m_bSecureConnectionRequired;
  386. }
  387. public function GetHttpsHyperlinks()
  388. {
  389. return $this->m_bHttpsHyperlinks;
  390. }
  391. public function GetDefaultLanguage()
  392. {
  393. return $this->m_sDefaultLanguage;
  394. }
  395. public function GetEncryptionKey()
  396. {
  397. return $this->m_sEncryptionKey;
  398. }
  399. public function GetAllowedLoginTypes()
  400. {
  401. return explode('|', $this->m_sAllowedLoginTypes);
  402. }
  403. public function GetExternalAuthenticationVariable()
  404. {
  405. return $this->m_sExtAuthVariable;
  406. }
  407. public function SetDBHost($sDBHost)
  408. {
  409. $this->m_sDBHost = $sDBHost;
  410. }
  411. public function SetDBName($sDBName)
  412. {
  413. $this->m_sDBName = $sDBName;
  414. }
  415. public function SetDBSubname($sDBSubName)
  416. {
  417. $this->m_sDBSubname = $sDBSubName;
  418. }
  419. public function SetDBUser($sUser)
  420. {
  421. $this->m_sDBUser = $sUser;
  422. }
  423. public function SetDBPwd($sPwd)
  424. {
  425. $this->m_sDBPwd = $sPwd;
  426. }
  427. public function SetLogGlobal($iLogGlobal)
  428. {
  429. $this->m_iLogGlobal = $iLogGlobal;
  430. }
  431. public function SetLogNotification($iLogNotification)
  432. {
  433. $this->m_iLogNotification = $iLogNotification;
  434. }
  435. public function SetLogIssue($iLogIssue)
  436. {
  437. $this->m_iLogIssue = $iLogIssue;
  438. }
  439. public function SetLogWebService($iLogWebService)
  440. {
  441. $this->m_iLogWebService = $iLogWebService;
  442. }
  443. public function SetMinDisplayLimit($iMinDisplayLimit)
  444. {
  445. $this->m_iMinDisplayLimit = $iMinDisplayLimit;
  446. }
  447. public function SetMaxDisplayLimit($iMaxDisplayLimit)
  448. {
  449. $this->m_iMaxDisplayLimit = $iMaxDisplayLimit;
  450. }
  451. public function SetStandardReloadInterval($iStandardReloadInterval)
  452. {
  453. $this->m_iStandardReloadInterval = $iStandardReloadInterval;
  454. }
  455. public function SetFastReloadInterval($iFastReloadInterval)
  456. {
  457. $this->m_iFastReloadInterval = $iFastReloadInterval;
  458. }
  459. public function SetSecureConnectionRequired($bSecureConnectionRequired)
  460. {
  461. $this->m_bSecureConnectionRequired = $bSecureConnectionRequired;
  462. }
  463. public function SetHttpsHyperlinks($bHttpsHyperlinks)
  464. {
  465. $this->m_bHttpsHyperlinks = $bHttpsHyperlinks;
  466. }
  467. public function SetDefaultLanguage($sLanguageCode)
  468. {
  469. $this->m_sDefaultLanguage = $sLanguageCode;
  470. }
  471. public function SetAllowedLoginTypes($aAllowedLoginTypes)
  472. {
  473. $this->m_sAllowedLoginTypes = implode('|', $aAllowedLoginTypes);
  474. }
  475. public function SetExternalAuthenticationVariable($sExtAuthVariable)
  476. {
  477. $this->m_sExtAuthVariable = $sExtAuthVariable;
  478. }
  479. public function SetEncryptionKey($sKey)
  480. {
  481. $this->m_sEncryptionKey = $sKey;
  482. }
  483. public function FileIsWritable()
  484. {
  485. return is_writable($this->m_sFile);
  486. }
  487. /**
  488. * Write the configuration to a file (php format) that can be reloaded later
  489. * By default write to the same file that was specified when constructing the object
  490. * @param $sFileName string Name of the file to write to (emtpy to write to the same file)
  491. * @return boolean True otherwise throws an Exception
  492. */
  493. public function WriteToFile($sFileName = '')
  494. {
  495. if (empty($sFileName))
  496. {
  497. $sFileName = $this->m_sFile;
  498. }
  499. $hFile = @fopen($sFileName, 'w');
  500. if ($hFile !== false)
  501. {
  502. fwrite($hFile, "<?php\n");
  503. fwrite($hFile, "\n/**\n");
  504. fwrite($hFile, " *\n");
  505. fwrite($hFile, " * phpMyORM configuration file, generated by the iTop configuration wizard\n");
  506. fwrite($hFile, " *\n");
  507. fwrite($hFile, " * The file is used in MetaModel::LoadConfig() which does all the necessary initialization job\n");
  508. fwrite($hFile, " *\n");
  509. fwrite($hFile, " */\n");
  510. fwrite($hFile, "\n");
  511. fwrite($hFile, "\$MySettings = array(\n");
  512. fwrite($hFile, "\t'db_host' => '{$this->m_sDBHost}',\n");
  513. fwrite($hFile, "\t'db_user' => '{$this->m_sDBUser}',\n");
  514. fwrite($hFile, "\t'db_pwd' => '".addslashes($this->m_sDBPwd)."',\n");
  515. fwrite($hFile, "\t'db_name' => '{$this->m_sDBName}',\n");
  516. fwrite($hFile, "\t'db_subname' => '{$this->m_sDBSubname}',\n");
  517. fwrite($hFile, "\n");
  518. fwrite($hFile, "\t'log_global' => {$this->m_bLogGlobal},\n");
  519. fwrite($hFile, "\t'log_notification' => {$this->m_bLogNotification},\n");
  520. fwrite($hFile, "\t'log_issue' => {$this->m_bLogIssue},\n");
  521. fwrite($hFile, "\t'log_web_service' => {$this->m_bLogWebService},\n");
  522. fwrite($hFile, "\t'min_display_limit' => {$this->m_iMinDisplayLimit},\n");
  523. fwrite($hFile, "\t'max_display_limit' => {$this->m_iMaxDisplayLimit},\n");
  524. fwrite($hFile, "\t'standard_reload_interval' => {$this->m_iStandardReloadInterval},\n");
  525. fwrite($hFile, "\t'fast_reload_interval' => {$this->m_iFastReloadInterval},\n");
  526. fwrite($hFile, "\t'secure_connection_required' => ".($this->m_bSecureConnectionRequired ? 'true' : 'false').",\n");
  527. fwrite($hFile, "\t'https_hyperlinks' => ".($this->m_bHttpsHyperlinks ? 'true' : 'false').",\n");
  528. fwrite($hFile, "\t'default_language' => '{$this->m_sDefaultLanguage}',\n");
  529. fwrite($hFile, "\t'allowed_login_types' => '{$this->m_sAllowedLoginTypes}',\n");
  530. fwrite($hFile, "\t'encryption_key' => '{$this->m_sEncryptionKey}',\n");
  531. fwrite($hFile, ");\n");
  532. fwrite($hFile, "\n");
  533. fwrite($hFile, "\$MyModuleSettings = array(\n");
  534. foreach ($this->m_aModuleSettings as $sModule => $aProperties)
  535. {
  536. fwrite($hFile, "\t'$sModule' => array (\n");
  537. foreach ($aProperties as $sProperty => $value)
  538. {
  539. $sExport = var_export($value, true);
  540. fwrite($hFile, "\t\t'$sProperty' => $sExport,\n");
  541. }
  542. fwrite($hFile, "\t),\n");
  543. }
  544. fwrite($hFile, ");\n");
  545. fwrite($hFile, "\n/**\n");
  546. fwrite($hFile, " *\n");
  547. fwrite($hFile, " * Data model modules to be loaded. Names should be specified as absolute paths\n");
  548. fwrite($hFile, " *\n");
  549. fwrite($hFile, " */\n");
  550. fwrite($hFile, "\$MyModules = array(\n");
  551. fwrite($hFile, "\t'application' => array (\n");
  552. foreach($this->m_aAppModules as $sFile)
  553. {
  554. fwrite($hFile, "\t\t'$sFile',\n");
  555. }
  556. fwrite($hFile, "\t),\n");
  557. fwrite($hFile, "\t'business' => array (\n");
  558. foreach($this->m_aDataModels as $sFile)
  559. {
  560. fwrite($hFile, "\t\t'$sFile',\n");
  561. }
  562. fwrite($hFile, "\t),\n");
  563. fwrite($hFile, "\t'addons' => array (\n");
  564. foreach($this->m_aAddons as $sKey => $sFile)
  565. {
  566. fwrite($hFile, "\t\t'$sKey' => '$sFile',\n");
  567. }
  568. fwrite($hFile, "\t),\n");
  569. fwrite($hFile, "\t'dictionaries' => array (\n");
  570. foreach($this->m_aDictionaries as $sFile)
  571. {
  572. fwrite($hFile, "\t\t'$sFile',\n");
  573. }
  574. fwrite($hFile, "\t),\n");
  575. fwrite($hFile, ");\n");
  576. fwrite($hFile, '?'.'>'); // Avoid perturbing the syntax highlighting !
  577. return fclose($hFile);
  578. }
  579. else
  580. {
  581. throw new ConfigException("Could not write to configuration file", array('file' => $sFileName));
  582. }
  583. }
  584. }
  585. ?>