config.class.inc.php 32 KB

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