config.class.inc.php 28 KB

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