config.class.inc.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  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. 'link_set_item_separator' => array(
  211. 'type' => 'string',
  212. 'description' => 'Link set from string: line separator',
  213. 'default' => '|',
  214. 'value' => '|',
  215. 'source_of_value' => '',
  216. 'show_in_conf_sample' => true,
  217. ),
  218. 'link_set_attribute_separator' => array(
  219. 'type' => 'string',
  220. 'description' => 'Link set from string: attribute separator',
  221. 'default' => ';',
  222. 'value' => ';',
  223. 'source_of_value' => '',
  224. 'show_in_conf_sample' => true,
  225. ),
  226. 'link_set_value_separator' => array(
  227. 'type' => 'string',
  228. 'description' => 'Link set from string: value separator (between the attcode and the value itself',
  229. 'default' => ':',
  230. 'value' => ':',
  231. 'source_of_value' => '',
  232. 'show_in_conf_sample' => true,
  233. ),
  234. 'link_set_attribute_qualifier' => array(
  235. 'type' => 'string',
  236. 'description' => 'Link set from string: attribute qualifier (encloses both the attcode and the value)',
  237. 'default' => "'",
  238. 'value' => "'",
  239. 'source_of_value' => '',
  240. 'show_in_conf_sample' => true,
  241. ),
  242. 'cron_max_execution_time' => array(
  243. 'type' => 'integer',
  244. 'description' => 'Duration (seconds) of the page cron.php, must be shorter than php setting max_execution_time and shorter than the web server response timeout',
  245. 'default' => 60,
  246. 'value' => 60,
  247. 'source_of_value' => '',
  248. 'show_in_conf_sample' => true,
  249. ),
  250. 'cron_sleep' => array(
  251. 'type' => 'integer',
  252. 'description' => 'Duration (seconds) before cron.php checks again if something must be done',
  253. 'default' => 2,
  254. 'value' => 2,
  255. 'source_of_value' => '',
  256. 'show_in_conf_sample' => false,
  257. ),
  258. 'email_asynchronous' => array(
  259. 'type' => 'bool',
  260. 'description' => 'If set, the emails are sent off line, which requires cron.php to be activated. Exception: some features like the email test utility will force the serialized mode',
  261. 'default' => false,
  262. 'value' => false,
  263. 'source_of_value' => '',
  264. 'show_in_conf_sample' => true,
  265. ),
  266. );
  267. public function IsProperty($sPropCode)
  268. {
  269. return (array_key_exists($sPropCode, $this->m_aSettings));
  270. }
  271. public function Set($sPropCode, $value, $sSourceDesc = 'unknown')
  272. {
  273. $sType = $this->m_aSettings[$sPropCode]['type'];
  274. switch($sType)
  275. {
  276. case 'bool':
  277. $value = (bool) $value;
  278. break;
  279. case 'string':
  280. $value = (string) $value;
  281. break;
  282. case 'integer':
  283. $value = (integer) $value;
  284. break;
  285. case 'float':
  286. $value = (float) $value;
  287. break;
  288. default:
  289. throw new CoreException('Unknown type for setting', array('property' => $sPropCode, 'type' => $sType));
  290. }
  291. $this->m_aSettings[$sPropCode]['value'] = $value;
  292. $this->m_aSettings[$sPropCode]['source_of_value'] = $sSourceDesc;
  293. }
  294. public function Get($sPropCode)
  295. {
  296. return $this->m_aSettings[$sPropCode]['value'];
  297. }
  298. // Those variables will be deprecated later, when the transition to ...Get('my_setting') will be done
  299. protected $m_sDBHost;
  300. protected $m_sDBUser;
  301. protected $m_sDBPwd;
  302. protected $m_sDBName;
  303. protected $m_sDBSubname;
  304. protected $m_sDBCharacterSet;
  305. protected $m_sDBCollation;
  306. /**
  307. * Event log options (see LOG_... definition)
  308. */
  309. // Those variables will be deprecated later, when the transition to ...Get('my_setting') will be done
  310. protected $m_bLogGlobal;
  311. protected $m_bLogNotification;
  312. protected $m_bLogIssue;
  313. protected $m_bLogWebService;
  314. protected $m_bLogKpiDuration; // private setting
  315. protected $m_bLogKpiMemory; // private setting
  316. protected $m_bDebugQueries; // private setting
  317. protected $m_bQueryCacheEnabled; // private setting
  318. /**
  319. * @var integer Number of elements to be displayed when there are more than m_iMaxDisplayLimit elements
  320. */
  321. protected $m_iMinDisplayLimit;
  322. /**
  323. * @var integer Max number of elements before truncating the display
  324. */
  325. protected $m_iMaxDisplayLimit;
  326. /**
  327. * @var integer Number of seconds between two reloads of the display (standard)
  328. */
  329. protected $m_iStandardReloadInterval;
  330. /**
  331. * @var integer Number of seconds between two reloads of the display (fast)
  332. */
  333. protected $m_iFastReloadInterval;
  334. /**
  335. * @var boolean Whether or not a secure connection is required for using the application.
  336. * If set, any attempt to connect to an iTop page with http:// will be redirected
  337. * to https://
  338. */
  339. protected $m_bSecureConnectionRequired;
  340. /**
  341. * @var boolean Forces iTop to output hyperlinks starting with https:// even
  342. * if the current page is not using https. This can be useful when
  343. * the application runs behind a SSL gateway
  344. */
  345. protected $m_bHttpsHyperlinks;
  346. /**
  347. * @var string Langage code, default if the user language is undefined
  348. */
  349. protected $m_sDefaultLanguage;
  350. /**
  351. * @var string Type of login process allowed: form|basic|url|external
  352. */
  353. protected $m_sAllowedLoginTypes;
  354. /**
  355. * @var string Name of the PHP variable in which external authentication information is passed by the web server
  356. */
  357. protected $m_sExtAuthVariable;
  358. /**
  359. * @var string Encryption key used for all attributes of type "encrypted string". Can be set to a random value
  360. * unless you want to import a database from another iTop instance, in which case you must use
  361. * the same encryption key in order to properly decode the encrypted fields
  362. */
  363. protected $m_sEncryptionKey;
  364. /**
  365. * @var array Additional character sets to be supported by the interactive CSV import
  366. * 'iconv_code' => 'display name'
  367. */
  368. protected $m_aCharsets;
  369. public function __construct($sConfigFile, $bLoadConfig = true)
  370. {
  371. $this->m_sFile = $sConfigFile;
  372. $this->m_aAppModules = array(
  373. // Some default modules, always present can be move to an official iTop Module later if needed
  374. 'application/transaction.class.inc.php',
  375. 'application/menunode.class.inc.php',
  376. 'application/user.preferences.class.inc.php',
  377. 'application/audit.rule.class.inc.php',
  378. // Romain - That's dirty, because those classes are in fact part of the core
  379. // but I needed those classes to be derived from cmdbAbstractObject
  380. // (to be managed via the GUI) and this class in not really known from
  381. // the core, PLUS I needed the includes to be there also for the setup
  382. // to create the tables.
  383. 'core/event.class.inc.php',
  384. 'core/action.class.inc.php',
  385. 'core/trigger.class.inc.php',
  386. 'synchro/synchrodatasource.class.inc.php',
  387. );
  388. $this->m_aDataModels = array();
  389. $this->m_aWebServiceCategories = array(
  390. 'webservices/webservices.basic.php',
  391. );
  392. $this->m_aAddons = array(
  393. // Default AddOn, always present can be moved to an official iTop Module later if needed
  394. 'user rights' => 'addons/userrights/userrightsprofile.class.inc.php',
  395. );
  396. $this->m_aDictionaries = array(
  397. // Default dictionaries, always present can be moved to an official iTop Module later if needed
  398. 'dictionaries/dictionary.itop.core.php',
  399. 'dictionaries/dictionary.itop.ui.php', // Support for English
  400. 'dictionaries/fr.dictionary.itop.ui.php', // Support for French
  401. 'dictionaries/fr.dictionary.itop.core.php', // Support for French
  402. 'dictionaries/es_cr.dictionary.itop.ui.php', // Support for Spanish (from Costa Rica)
  403. 'dictionaries/es_cr.dictionary.itop.core.php', // Support for Spanish (from Costa Rica)
  404. 'dictionaries/de.dictionary.itop.ui.php', // Support for German
  405. 'dictionaries/de.dictionary.itop.core.php', // Support for German
  406. 'dictionaries/pt_br.dictionary.itop.ui.php', // Support for Brazilian Portuguese
  407. 'dictionaries/pt_br.dictionary.itop.core.php', // Support for Brazilian Portuguese
  408. 'dictionaries/ru.dictionary.itop.ui.php', // Support for Russian
  409. 'dictionaries/ru.dictionary.itop.core.php', // Support for Russian
  410. 'dictionaries/tr.dictionary.itop.ui.php', // Support for Turkish
  411. 'dictionaries/tr.dictionary.itop.core.php', // Support for Turkish
  412. 'dictionaries/zh.dictionary.itop.ui.php', // Support for Chinese
  413. 'dictionaries/zh.dictionary.itop.core.php', // Support for Chinese
  414. );
  415. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  416. {
  417. $this->m_aSettings[$sPropCode]['value'] = $aSettingInfo['default'];
  418. }
  419. $this->m_sDBHost = '';
  420. $this->m_sDBUser = '';
  421. $this->m_sDBPwd = '';
  422. $this->m_sDBName = '';
  423. $this->m_sDBSubname = '';
  424. $this->m_sDBCharacterSet = DEFAULT_CHARACTER_SET;
  425. $this->m_sDBCollation = DEFAULT_COLLATION;
  426. $this->m_bLogGlobal = DEFAULT_LOG_GLOBAL;
  427. $this->m_bLogNotification = DEFAULT_LOG_NOTIFICATION;
  428. $this->m_bLogIssue = DEFAULT_LOG_ISSUE;
  429. $this->m_bLogWebService = DEFAULT_LOG_WEB_SERVICE;
  430. $this->m_bLogKPIDuration = DEFAULT_LOG_KPI_DURATION;
  431. $this->m_bLogKPIDuration = DEFAULT_LOG_KPI_DURATION;
  432. $this->m_iMinDisplayLimit = DEFAULT_MIN_DISPLAY_LIMIT;
  433. $this->m_iMaxDisplayLimit = DEFAULT_MAX_DISPLAY_LIMIT;
  434. $this->m_iStandardReloadInterval = DEFAULT_STANDARD_RELOAD_INTERVAL;
  435. $this->m_iFastReloadInterval = DEFAULT_FAST_RELOAD_INTERVAL;
  436. $this->m_bSecureConnectionRequired = DEFAULT_SECURE_CONNECTION_REQUIRED;
  437. $this->m_bHttpsHyperlinks = DEFAULT_HTTPS_HYPERLINKS;
  438. $this->m_sDefaultLanguage = 'EN US';
  439. $this->m_sAllowedLoginTypes = DEFAULT_ALLOWED_LOGIN_TYPES;
  440. $this->m_sExtAuthVariable = DEFAULT_EXT_AUTH_VARIABLE;
  441. $this->m_sEncryptionKey = DEFAULT_ENCRYPTION_KEY;
  442. $this->m_aCharsets = array();
  443. $this->m_aModuleSettings = array();
  444. if ($bLoadConfig)
  445. {
  446. $this->Load($sConfigFile);
  447. $this->Verify();
  448. }
  449. }
  450. protected function CheckFile($sPurpose, $sFileName)
  451. {
  452. if (!file_exists($sFileName))
  453. {
  454. throw new ConfigException("Could not find $sPurpose file", array('file' => $sFileName));
  455. }
  456. }
  457. protected function Load($sConfigFile)
  458. {
  459. $this->CheckFile('configuration', $sConfigFile);
  460. $sConfigCode = trim(file_get_contents($sConfigFile));
  461. // This does not work on several lines
  462. // preg_match('/^<\\?php(.*)\\?'.'>$/', $sConfigCode, $aMatches)...
  463. // So, I've implemented a solution suggested in the PHP doc (search for phpWrapper)
  464. try
  465. {
  466. ob_start();
  467. eval('?'.'>'.trim($sConfigCode));
  468. $sNoise = trim(ob_get_contents());
  469. ob_end_clean();
  470. }
  471. catch (Exception $e)
  472. {
  473. // well, never reach in case of parsing error :-(
  474. // will be improved in PHP 6 ?
  475. throw new ConfigException('Error in configuration file', array('file' => $sConfigFile, 'error' => $e->getMessage()));
  476. }
  477. if (strlen($sNoise) > 0)
  478. {
  479. // Note: sNoise is an html output, but so far it was ok for me (e.g. showing the entire call stack)
  480. throw new ConfigException('Syntax error in configuration file', array('file' => $sConfigFile, 'error' => '<tt>'.htmlentities($sNoise, ENT_QUOTES, 'UTF-8').'</tt>'));
  481. }
  482. if (!isset($MySettings) || !is_array($MySettings))
  483. {
  484. throw new ConfigException('Missing array in configuration file', array('file' => $sConfigFile, 'expected' => '$MySettings'));
  485. }
  486. if (!isset($MyModules) || !is_array($MyModules))
  487. {
  488. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules'));
  489. }
  490. if (!array_key_exists('application', $MyModules))
  491. {
  492. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'application\']'));
  493. }
  494. if (!array_key_exists('business', $MyModules))
  495. {
  496. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'business\']'));
  497. }
  498. if (!array_key_exists('addons', $MyModules))
  499. {
  500. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'addons\']'));
  501. }
  502. if (!array_key_exists('user rights', $MyModules['addons']))
  503. {
  504. // Add one, by default
  505. $MyModules['addons']['user rights'] = '/addons/userrights/userrightsnull.class.inc.php';
  506. }
  507. if (!array_key_exists('dictionaries', $MyModules))
  508. {
  509. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'dictionaries\']'));
  510. }
  511. $this->m_aAppModules = $MyModules['application'];
  512. $this->m_aDataModels = $MyModules['business'];
  513. if (isset($MyModules['webservices']))
  514. {
  515. $this->m_aWebServiceCategories = $MyModules['webservices'];
  516. }
  517. $this->m_aAddons = $MyModules['addons'];
  518. $this->m_aDictionaries = $MyModules['dictionaries'];
  519. foreach($MySettings as $sPropCode => $rawvalue)
  520. {
  521. if ($this->IsProperty($sPropCode))
  522. {
  523. $value = trim($rawvalue);
  524. $this->Set($sPropCode, $value, $sConfigFile);
  525. }
  526. }
  527. $this->m_sDBHost = trim($MySettings['db_host']);
  528. $this->m_sDBUser = trim($MySettings['db_user']);
  529. $this->m_sDBPwd = trim($MySettings['db_pwd']);
  530. $this->m_sDBName = trim($MySettings['db_name']);
  531. $this->m_sDBSubname = trim($MySettings['db_subname']);
  532. $this->m_sDBCharacterSet = isset($MySettings['db_character_set']) ? trim($MySettings['db_character_set']) : DEFAULT_CHARACTER_SET;
  533. $this->m_sDBCollation = isset($MySettings['db_collation']) ? trim($MySettings['db_collation']) : DEFAULT_COLLATION;
  534. $this->m_bLogGlobal = isset($MySettings['log_global']) ? (bool) trim($MySettings['log_global']) : DEFAULT_LOG_GLOBAL;
  535. $this->m_bLogNotification = isset($MySettings['log_notification']) ? (bool) trim($MySettings['log_notification']) : DEFAULT_LOG_NOTIFICATION;
  536. $this->m_bLogIssue = isset($MySettings['log_issue']) ? (bool) trim($MySettings['log_issue']) : DEFAULT_LOG_ISSUE;
  537. $this->m_bLogWebService = isset($MySettings['log_web_service']) ? (bool) trim($MySettings['log_web_service']) : DEFAULT_LOG_WEB_SERVICE;
  538. $this->m_bLogKPIDuration = isset($MySettings['log_kpi_duration']) ? (bool) trim($MySettings['log_kpi_duration']) : DEFAULT_LOG_KPI_DURATION;
  539. $this->m_bLogKPIMemory = isset($MySettings['log_kpi_memory']) ? (bool) trim($MySettings['log_kpi_memory']) : DEFAULT_LOG_KPI_MEMORY;
  540. $this->m_bDebugQueries = isset($MySettings['debug_queries']) ? (bool) trim($MySettings['debug_queries']) : DEFAULT_DEBUG_QUERIES;
  541. $this->m_bQueryCacheEnabled = isset($MySettings['query_cache_enabled']) ? (bool) trim($MySettings['query_cache_enabled']) : DEFAULT_QUERY_CACHE_ENABLED;
  542. $this->m_iMinDisplayLimit = isset($MySettings['min_display_limit']) ? trim($MySettings['min_display_limit']) : DEFAULT_MIN_DISPLAY_LIMIT;
  543. $this->m_iMaxDisplayLimit = isset($MySettings['max_display_limit']) ? trim($MySettings['max_display_limit']) : DEFAULT_MAX_DISPLAY_LIMIT;
  544. $this->m_iStandardReloadInterval = isset($MySettings['standard_reload_interval']) ? trim($MySettings['standard_reload_interval']) : DEFAULT_STANDARD_RELOAD_INTERVAL;
  545. $this->m_iFastReloadInterval = isset($MySettings['fast_reload_interval']) ? trim($MySettings['fast_reload_interval']) : DEFAULT_FAST_RELOAD_INTERVAL;
  546. $this->m_bSecureConnectionRequired = isset($MySettings['secure_connection_required']) ? (bool) trim($MySettings['secure_connection_required']) : DEFAULT_SECURE_CONNECTION_REQUIRED;
  547. $this->m_bHttpsHyperlinks = isset($MySettings['https_hyperlinks']) ? (bool) trim($MySettings['https_hyperlinks']) : DEFAULT_HTTPS_HYPERLINKS;
  548. $this->m_aModuleSettings = isset($MyModuleSettings) ? $MyModuleSettings : array();
  549. $this->m_sDefaultLanguage = isset($MySettings['default_language']) ? trim($MySettings['default_language']) : 'EN US';
  550. $this->m_sAllowedLoginTypes = isset($MySettings['allowed_login_types']) ? trim($MySettings['allowed_login_types']) : DEFAULT_ALLOWED_LOGIN_TYPES;
  551. $this->m_sExtAuthVariable = isset($MySettings['ext_auth_variable']) ? trim($MySettings['ext_auth_variable']) : DEFAULT_EXT_AUTH_VARIABLE;
  552. $this->m_sEncryptionKey = isset($MySettings['encryption_key']) ? trim($MySettings['encryption_key']) : DEFAULT_ENCRYPTION_KEY;
  553. $this->m_aCharsets = isset($MySettings['csv_import_charsets']) ? $MySettings['csv_import_charsets'] : array();
  554. }
  555. protected function Verify()
  556. {
  557. // Files are verified later on, just before using them -see MetaModel::Plugin()
  558. // (we have their final path at that point)
  559. }
  560. public function GetModuleSetting($sModule, $sProperty, $defaultvalue = null)
  561. {
  562. if (isset($this->m_aModuleSettings[$sModule][$sProperty]))
  563. {
  564. return $this->m_aModuleSettings[$sModule][$sProperty];
  565. }
  566. return $defaultvalue;
  567. }
  568. public function SetModuleSetting($sModule, $sProperty, $value)
  569. {
  570. $this->m_aModuleSettings[$sModule][$sProperty] = $value;
  571. }
  572. public function GetAppModules()
  573. {
  574. return $this->m_aAppModules;
  575. }
  576. public function SetAppModules($aAppModules)
  577. {
  578. $this->m_aAppModules = $aAppModules;
  579. }
  580. public function GetDataModels()
  581. {
  582. return $this->m_aDataModels;
  583. }
  584. public function SetDataModels($aDataModels)
  585. {
  586. $this->m_aDataModels = $aDataModels;
  587. }
  588. public function GetWebServiceCategories()
  589. {
  590. return $this->m_aWebServiceCategories;
  591. }
  592. public function SetWebServiceCategories($aWebServiceCategories)
  593. {
  594. $this->m_aWebServiceCategories = $aWebServiceCategories;
  595. }
  596. public function GetAddons()
  597. {
  598. return $this->m_aAddons;
  599. }
  600. public function SetAddons($aAddons)
  601. {
  602. $this->m_aAddons = $aAddons;
  603. }
  604. public function GetDictionaries()
  605. {
  606. return $this->m_aDictionaries;
  607. }
  608. public function SetDictionaries($aDictionaries)
  609. {
  610. $this->m_aDictionaries = $aDictionaries;
  611. }
  612. public function GetDBHost()
  613. {
  614. return $this->m_sDBHost;
  615. }
  616. public function GetDBName()
  617. {
  618. return $this->m_sDBName;
  619. }
  620. public function GetDBSubname()
  621. {
  622. return $this->m_sDBSubname;
  623. }
  624. public function GetDBCharacterSet()
  625. {
  626. return $this->m_sDBCharacterSet;
  627. }
  628. public function GetDBCollation()
  629. {
  630. return $this->m_sDBCollation;
  631. }
  632. public function GetDBUser()
  633. {
  634. return $this->m_sDBUser;
  635. }
  636. public function GetDBPwd()
  637. {
  638. return $this->m_sDBPwd;
  639. }
  640. public function GetLogGlobal()
  641. {
  642. return $this->m_bLogGlobal;
  643. }
  644. public function GetLogNotification()
  645. {
  646. return $this->m_bLogNotification;
  647. }
  648. public function GetLogIssue()
  649. {
  650. return $this->m_bLogIssue;
  651. }
  652. public function GetLogWebService()
  653. {
  654. return $this->m_bLogWebService;
  655. }
  656. public function GetLogKPIDuration()
  657. {
  658. return $this->m_bLogKPIDuration;
  659. }
  660. public function GetLogKPIMemory()
  661. {
  662. return $this->m_bLogKPIMemory;
  663. }
  664. public function GetDebugQueries()
  665. {
  666. return $this->m_bDebugQueries;
  667. }
  668. public function GetQueryCacheEnabled()
  669. {
  670. return $this->m_bQueryCacheEnabled;
  671. }
  672. public function GetMinDisplayLimit()
  673. {
  674. return $this->m_iMinDisplayLimit;
  675. }
  676. public function GetMaxDisplayLimit()
  677. {
  678. return $this->m_iMaxDisplayLimit;
  679. }
  680. public function GetStandardReloadInterval()
  681. {
  682. return $this->m_iStandardReloadInterval;
  683. }
  684. public function GetFastReloadInterval()
  685. {
  686. return $this->m_iFastReloadInterval;
  687. }
  688. public function GetSecureConnectionRequired()
  689. {
  690. return $this->m_bSecureConnectionRequired;
  691. }
  692. public function GetHttpsHyperlinks()
  693. {
  694. return $this->m_bHttpsHyperlinks;
  695. }
  696. public function GetDefaultLanguage()
  697. {
  698. return $this->m_sDefaultLanguage;
  699. }
  700. public function GetEncryptionKey()
  701. {
  702. return $this->m_sEncryptionKey;
  703. }
  704. public function GetAllowedLoginTypes()
  705. {
  706. return explode('|', $this->m_sAllowedLoginTypes);
  707. }
  708. public function GetExternalAuthenticationVariable()
  709. {
  710. return $this->m_sExtAuthVariable;
  711. }
  712. public function GetCSVImportCharsets()
  713. {
  714. return $this->m_aCharsets;
  715. }
  716. public function SetDBHost($sDBHost)
  717. {
  718. $this->m_sDBHost = $sDBHost;
  719. }
  720. public function SetDBName($sDBName)
  721. {
  722. $this->m_sDBName = $sDBName;
  723. }
  724. public function SetDBSubname($sDBSubName)
  725. {
  726. $this->m_sDBSubname = $sDBSubName;
  727. }
  728. public function SetDBCharacterSet($sDBCharacterSet)
  729. {
  730. $this->m_sDBCharacterSet = $sDBCharacterSet;
  731. }
  732. public function SetDBCollation($sDBCollation)
  733. {
  734. $this->m_sDBCollation = $sDBCollation;
  735. }
  736. public function SetDBUser($sUser)
  737. {
  738. $this->m_sDBUser = $sUser;
  739. }
  740. public function SetDBPwd($sPwd)
  741. {
  742. $this->m_sDBPwd = $sPwd;
  743. }
  744. public function SetLogGlobal($iLogGlobal)
  745. {
  746. $this->m_iLogGlobal = $iLogGlobal;
  747. }
  748. public function SetLogNotification($iLogNotification)
  749. {
  750. $this->m_iLogNotification = $iLogNotification;
  751. }
  752. public function SetLogIssue($iLogIssue)
  753. {
  754. $this->m_iLogIssue = $iLogIssue;
  755. }
  756. public function SetLogWebService($iLogWebService)
  757. {
  758. $this->m_iLogWebService = $iLogWebService;
  759. }
  760. public function SetMinDisplayLimit($iMinDisplayLimit)
  761. {
  762. $this->m_iMinDisplayLimit = $iMinDisplayLimit;
  763. }
  764. public function SetMaxDisplayLimit($iMaxDisplayLimit)
  765. {
  766. $this->m_iMaxDisplayLimit = $iMaxDisplayLimit;
  767. }
  768. public function SetStandardReloadInterval($iStandardReloadInterval)
  769. {
  770. $this->m_iStandardReloadInterval = $iStandardReloadInterval;
  771. }
  772. public function SetFastReloadInterval($iFastReloadInterval)
  773. {
  774. $this->m_iFastReloadInterval = $iFastReloadInterval;
  775. }
  776. public function SetSecureConnectionRequired($bSecureConnectionRequired)
  777. {
  778. $this->m_bSecureConnectionRequired = $bSecureConnectionRequired;
  779. }
  780. public function SetHttpsHyperlinks($bHttpsHyperlinks)
  781. {
  782. $this->m_bHttpsHyperlinks = $bHttpsHyperlinks;
  783. }
  784. public function SetDefaultLanguage($sLanguageCode)
  785. {
  786. $this->m_sDefaultLanguage = $sLanguageCode;
  787. }
  788. public function SetAllowedLoginTypes($aAllowedLoginTypes)
  789. {
  790. $this->m_sAllowedLoginTypes = implode('|', $aAllowedLoginTypes);
  791. }
  792. public function SetExternalAuthenticationVariable($sExtAuthVariable)
  793. {
  794. $this->m_sExtAuthVariable = $sExtAuthVariable;
  795. }
  796. public function SetEncryptionKey($sKey)
  797. {
  798. $this->m_sEncryptionKey = $sKey;
  799. }
  800. public function SetCSVImportCharsets($aCharsets)
  801. {
  802. $this->m_aCharsets = $aCharsets;
  803. }
  804. public function AddCSVImportCharset($sIconvCode, $sDisplayName)
  805. {
  806. $this->m_aCharsets[$sIconvCode] = $sDisplayName;
  807. }
  808. public function FileIsWritable()
  809. {
  810. return is_writable($this->m_sFile);
  811. }
  812. public function GetLoadedFile()
  813. {
  814. return $this->m_sFile;
  815. }
  816. /**
  817. * Render the configuration as an associative array
  818. * @return boolean True otherwise throws an Exception
  819. */
  820. public function ToArray()
  821. {
  822. $aSettings = array();
  823. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  824. {
  825. $aSettings[$sPropCode] = $aSettingInfo['value'];
  826. }
  827. $aSettings['db_host'] = $this->m_sDBHost;
  828. $aSettings['db_user'] = $this->m_sDBUser;
  829. $aSettings['db_pwd'] = $this->m_sDBPwd;
  830. $aSettings['db_name'] = $this->m_sDBName;
  831. $aSettings['db_subname'] = $this->m_sDBSubname;
  832. $aSettings['db_character_set'] = $this->m_sDBCharacterSet;
  833. $aSettings['db_collation'] = $this->m_sDBCollation;
  834. $aSettings['log_global'] = $this->m_bLogGlobal;
  835. $aSettings['log_notification'] = $this->m_bLogNotification;
  836. $aSettings['log_issue'] = $this->m_bLogIssue;
  837. $aSettings['log_web_service'] = $this->m_bLogWebService;
  838. $aSettings['min_display_limit'] = $this->m_iMinDisplayLimit;
  839. $aSettings['max_display_limit'] = $this->m_iMaxDisplayLimit;
  840. $aSettings['standard_reload_interval'] = $this->m_iStandardReloadInterval;
  841. $aSettings['fast_reload_interval'] = $this->m_iFastReloadInterval;
  842. $aSettings['secure_connection_required'] = $this->m_bSecureConnectionRequired;
  843. $aSettings['https_hyperlinks'] = $this->m_bHttpsHyperlinks;
  844. $aSettings['default_language'] = $this->m_sDefaultLanguage;
  845. $aSettings['allowed_login_types'] = $this->m_sAllowedLoginTypes;
  846. $aSettings['encryption_key'] = $this->m_sEncryptionKey;
  847. $aSettings['csv_import_charsets'] = $this->m_aCharsets;
  848. foreach ($this->m_aModuleSettings as $sModule => $aProperties)
  849. {
  850. foreach ($aProperties as $sProperty => $value)
  851. {
  852. $aSettings['module_settings'][$sModule][$sProperty] = $value;
  853. }
  854. }
  855. foreach($this->m_aAppModules as $sFile)
  856. {
  857. $aSettings['application_list'][] = $sFile;
  858. }
  859. foreach($this->m_aDataModels as $sFile)
  860. {
  861. $aSettings['datamodel_list'][] = $sFile;
  862. }
  863. foreach($this->m_aWebServiceCategories as $sFile)
  864. {
  865. $aSettings['webservice_list'][] = $sFile;
  866. }
  867. foreach($this->m_aAddons as $sKey => $sFile)
  868. {
  869. $aSettings['addon_list'][] = $sFile;
  870. }
  871. foreach($this->m_aDictionaries as $sFile)
  872. {
  873. $aSettings['dictionary_list'][] = $sFile;
  874. }
  875. return $aSettings;
  876. }
  877. /**
  878. * Write the configuration to a file (php format) that can be reloaded later
  879. * By default write to the same file that was specified when constructing the object
  880. * @param $sFileName string Name of the file to write to (emtpy to write to the same file)
  881. * @return boolean True otherwise throws an Exception
  882. */
  883. public function WriteToFile($sFileName = '')
  884. {
  885. if (empty($sFileName))
  886. {
  887. $sFileName = $this->m_sFile;
  888. }
  889. $hFile = @fopen($sFileName, 'w');
  890. if ($hFile !== false)
  891. {
  892. fwrite($hFile, "<?php\n");
  893. fwrite($hFile, "\n/**\n");
  894. fwrite($hFile, " *\n");
  895. fwrite($hFile, " * phpMyORM configuration file, generated by the iTop configuration wizard\n");
  896. fwrite($hFile, " *\n");
  897. fwrite($hFile, " * The file is used in MetaModel::LoadConfig() which does all the necessary initialization job\n");
  898. fwrite($hFile, " *\n");
  899. fwrite($hFile, " */\n");
  900. fwrite($hFile, "\n");
  901. fwrite($hFile, "\$MySettings = array(\n");
  902. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  903. {
  904. if ($aSettingInfo['show_in_conf_sample'])
  905. {
  906. $sType = $this->m_aSettings[$sPropCode]['type'];
  907. switch($sType)
  908. {
  909. case 'bool':
  910. $sSeenAs = $aSettingInfo['value'] ? '1' : '0';
  911. break;
  912. default:
  913. $sSeenAs = "'".addslashes($aSettingInfo['value'])."'";
  914. }
  915. fwrite($hFile, "\t'$sPropCode' => $sSeenAs,\n");
  916. }
  917. }
  918. fwrite($hFile, "\t'db_host' => '{$this->m_sDBHost}',\n");
  919. fwrite($hFile, "\t'db_user' => '{$this->m_sDBUser}',\n");
  920. fwrite($hFile, "\t'db_pwd' => '".addslashes($this->m_sDBPwd)."',\n");
  921. fwrite($hFile, "\t'db_name' => '{$this->m_sDBName}',\n");
  922. fwrite($hFile, "\t'db_subname' => '{$this->m_sDBSubname}',\n");
  923. fwrite($hFile, "\t'db_character_set' => '{$this->m_sDBCharacterSet}',\n");
  924. fwrite($hFile, "\t'db_collation' => '{$this->m_sDBCollation}',\n");
  925. fwrite($hFile, "\n");
  926. fwrite($hFile, "\t'log_global' => {$this->m_bLogGlobal},\n");
  927. fwrite($hFile, "\t'log_notification' => {$this->m_bLogNotification},\n");
  928. fwrite($hFile, "\t'log_issue' => {$this->m_bLogIssue},\n");
  929. fwrite($hFile, "\t'log_web_service' => {$this->m_bLogWebService},\n");
  930. fwrite($hFile, "\t'min_display_limit' => {$this->m_iMinDisplayLimit},\n");
  931. fwrite($hFile, "\t'max_display_limit' => {$this->m_iMaxDisplayLimit},\n");
  932. fwrite($hFile, "\t'standard_reload_interval' => {$this->m_iStandardReloadInterval},\n");
  933. fwrite($hFile, "\t'fast_reload_interval' => {$this->m_iFastReloadInterval},\n");
  934. fwrite($hFile, "\t'secure_connection_required' => ".($this->m_bSecureConnectionRequired ? 'true' : 'false').",\n");
  935. fwrite($hFile, "\t'https_hyperlinks' => ".($this->m_bHttpsHyperlinks ? 'true' : 'false').",\n");
  936. fwrite($hFile, "\t'default_language' => '{$this->m_sDefaultLanguage}',\n");
  937. fwrite($hFile, "\t'allowed_login_types' => '{$this->m_sAllowedLoginTypes}',\n");
  938. fwrite($hFile, "\t'encryption_key' => '{$this->m_sEncryptionKey}',\n");
  939. $sExport = var_export($this->m_aCharsets, true);
  940. fwrite($hFile, "\t'csv_import_charsets' => $sExport,\n");
  941. fwrite($hFile, ");\n");
  942. fwrite($hFile, "\n");
  943. fwrite($hFile, "\$MyModuleSettings = array(\n");
  944. foreach ($this->m_aModuleSettings as $sModule => $aProperties)
  945. {
  946. fwrite($hFile, "\t'$sModule' => array (\n");
  947. foreach ($aProperties as $sProperty => $value)
  948. {
  949. $sExport = var_export($value, true);
  950. fwrite($hFile, "\t\t'$sProperty' => $sExport,\n");
  951. }
  952. fwrite($hFile, "\t),\n");
  953. }
  954. fwrite($hFile, ");\n");
  955. fwrite($hFile, "\n/**\n");
  956. fwrite($hFile, " *\n");
  957. fwrite($hFile, " * Data model modules to be loaded. Names should be specified as absolute paths\n");
  958. fwrite($hFile, " *\n");
  959. fwrite($hFile, " */\n");
  960. fwrite($hFile, "\$MyModules = array(\n");
  961. fwrite($hFile, "\t'application' => array (\n");
  962. foreach($this->m_aAppModules as $sFile)
  963. {
  964. fwrite($hFile, "\t\t'$sFile',\n");
  965. }
  966. fwrite($hFile, "\t),\n");
  967. fwrite($hFile, "\t'business' => array (\n");
  968. foreach($this->m_aDataModels as $sFile)
  969. {
  970. fwrite($hFile, "\t\t'$sFile',\n");
  971. }
  972. fwrite($hFile, "\t),\n");
  973. fwrite($hFile, "\t'webservices' => array (\n");
  974. foreach($this->m_aWebServiceCategories as $sFile)
  975. {
  976. fwrite($hFile, "\t\t'$sFile',\n");
  977. }
  978. fwrite($hFile, "\t),\n");
  979. fwrite($hFile, "\t'addons' => array (\n");
  980. foreach($this->m_aAddons as $sKey => $sFile)
  981. {
  982. fwrite($hFile, "\t\t'$sKey' => '$sFile',\n");
  983. }
  984. fwrite($hFile, "\t),\n");
  985. fwrite($hFile, "\t'dictionaries' => array (\n");
  986. foreach($this->m_aDictionaries as $sFile)
  987. {
  988. fwrite($hFile, "\t\t'$sFile',\n");
  989. }
  990. fwrite($hFile, "\t),\n");
  991. fwrite($hFile, ");\n");
  992. fwrite($hFile, '?'.'>'); // Avoid perturbing the syntax highlighting !
  993. return fclose($hFile);
  994. }
  995. else
  996. {
  997. throw new ConfigException("Could not write to configuration file", array('file' => $sFileName));
  998. }
  999. }
  1000. }
  1001. ?>