config.class.inc.php 25 KB

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