config.class.inc.php 35 KB

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