config.class.inc.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  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_APPLICATION', 'iTop');
  17. define('ITOP_VERSION', '$ITOP_VERSION$');
  18. define('ITOP_REVISION', '$WCREV$');
  19. define('ITOP_BUILD_DATE', '$WCNOW$');
  20. define('ACCESS_USER_WRITE', 1);
  21. define('ACCESS_ADMIN_WRITE', 2);
  22. define('ACCESS_FULL', ACCESS_USER_WRITE | ACCESS_ADMIN_WRITE);
  23. define('ACCESS_READONLY', 0);
  24. /**
  25. * Configuration read/write
  26. *
  27. * @author Erwan Taloc <erwan.taloc@combodo.com>
  28. * @author Romain Quetiez <romain.quetiez@combodo.com>
  29. * @author Denis Flaven <denis.flaven@combodo.com>
  30. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  31. */
  32. require_once('coreexception.class.inc.php');
  33. class ConfigException extends CoreException
  34. {
  35. }
  36. define ('DEFAULT_CHARACTER_SET', 'utf8');
  37. define ('DEFAULT_COLLATION', 'utf8_unicode_ci');
  38. define ('DEFAULT_LOG_GLOBAL', true);
  39. define ('DEFAULT_LOG_NOTIFICATION', true);
  40. define ('DEFAULT_LOG_ISSUE', true);
  41. define ('DEFAULT_LOG_WEB_SERVICE', true);
  42. define ('DEFAULT_LOG_KPI_DURATION', false);
  43. define ('DEFAULT_LOG_KPI_MEMORY', false);
  44. define ('DEFAULT_DEBUG_QUERIES', false);
  45. define ('DEFAULT_QUERY_CACHE_ENABLED', true);
  46. define ('DEFAULT_MIN_DISPLAY_LIMIT', 10);
  47. define ('DEFAULT_MAX_DISPLAY_LIMIT', 15);
  48. define ('DEFAULT_STANDARD_RELOAD_INTERVAL', 5*60);
  49. define ('DEFAULT_FAST_RELOAD_INTERVAL', 1*60);
  50. define ('DEFAULT_SECURE_CONNECTION_REQUIRED', 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. 'app_root_url' => array(
  74. 'type' => 'string',
  75. 'description' => 'Root URL used for navigating within the application, or from an email to the application (you can put $SERVER_NAME$ as a placeholder for the server\'s name)',
  76. 'default' => '',
  77. 'value' => '',
  78. 'source_of_value' => '',
  79. 'show_in_conf_sample' => true,
  80. ),
  81. 'skip_check_to_write' => array(
  82. 'type' => 'bool',
  83. 'description' => 'Disable data format and integrity checks to boost up data load (insert or update)',
  84. 'default' => false,
  85. 'value' => false,
  86. 'source_of_value' => '',
  87. 'show_in_conf_sample' => false,
  88. ),
  89. 'skip_check_ext_keys' => array(
  90. 'type' => 'bool',
  91. 'description' => 'Disable external key check when checking the value of attributes',
  92. 'default' => false,
  93. 'value' => false,
  94. 'source_of_value' => '',
  95. 'show_in_conf_sample' => false,
  96. ),
  97. 'skip_strong_security' => array(
  98. 'type' => 'bool',
  99. 'description' => 'Disable strong security - TEMPORY: this flag should be removed when we are more confident in the recent change in security',
  100. 'default' => true,
  101. 'value' => true,
  102. 'source_of_value' => '',
  103. 'show_in_conf_sample' => false,
  104. ),
  105. 'graphviz_path' => array(
  106. 'type' => 'string',
  107. 'description' => 'Path to the Graphviz "dot" executable for graphing objects lifecycle',
  108. 'default' => '/usr/bin/dot',
  109. 'value' => '',
  110. 'source_of_value' => '',
  111. 'show_in_conf_sample' => false,
  112. ),
  113. 'session_name' => array(
  114. 'type' => 'string',
  115. 'description' => 'The name of the cookie used to store the PHP session id',
  116. 'default' => 'iTop',
  117. 'value' => '',
  118. 'source_of_value' => '',
  119. 'show_in_conf_sample' => true,
  120. ),
  121. 'max_combo_length' => array(
  122. 'type' => 'integer',
  123. 'description' => 'The maximum number of elements in a drop-down list. If more then an autocomplete will be used',
  124. 'default' => 50,
  125. 'value' => 50,
  126. 'source_of_value' => '',
  127. 'show_in_conf_sample' => false,
  128. ),
  129. 'min_autocomplete_chars' => array(
  130. 'type' => 'integer',
  131. 'description' => 'The minimum number of characters to type in order to trigger the "autocomplete" behavior',
  132. 'default' => 3,
  133. 'value' => 3,
  134. 'source_of_value' => '',
  135. 'show_in_conf_sample' => false,
  136. ),
  137. 'allow_target_creation' => array(
  138. 'type' => 'bool',
  139. 'description' => 'Displays the + button on external keys to create target objects',
  140. 'default' => true,
  141. 'value' => true,
  142. 'source_of_value' => '',
  143. 'show_in_conf_sample' => false,
  144. ),
  145. // Levels that trigger a confirmation in the CSV import/synchro wizard
  146. 'csv_import_min_object_confirmation' => array(
  147. 'type' => 'integer',
  148. 'description' => 'Minimum number of objects to check for the confirmation percentages',
  149. 'default' => 3,
  150. 'value' => 3,
  151. 'source_of_value' => '',
  152. 'show_in_conf_sample' => false,
  153. ),
  154. 'csv_import_errors_percentage' => array(
  155. 'type' => 'integer',
  156. 'description' => 'Percentage of errors 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_modifications_percentage' => array(
  163. 'type' => 'integer',
  164. 'description' => 'Percentage of modifications 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. 'csv_import_creations_percentage' => array(
  171. 'type' => 'integer',
  172. 'description' => 'Percentage of creations that trigger a confirmation in the CSV import',
  173. 'default' => 50,
  174. 'value' => 50,
  175. 'source_of_value' => '',
  176. 'show_in_conf_sample' => false,
  177. ),
  178. 'access_mode' => array(
  179. 'type' => 'integer',
  180. 'description' => 'Combination of flags (ACCESS_USER_WRITE | ACCESS_ADMIN_WRITE, or ACCESS_FULL)',
  181. 'default' => ACCESS_FULL,
  182. 'value' => ACCESS_FULL,
  183. 'source_of_value' => '',
  184. 'show_in_conf_sample' => true,
  185. ),
  186. 'access_message' => array(
  187. 'type' => 'string',
  188. 'description' => 'Message displayed to the users when there is any access restriction',
  189. 'default' => 'iTop is temporarily frozen, please wait... (the admin team)',
  190. 'value' => '',
  191. 'source_of_value' => '',
  192. 'show_in_conf_sample' => true,
  193. ),
  194. 'online_help' => array(
  195. 'type' => 'string',
  196. 'description' => 'Hyperlink to the online-help web page',
  197. 'default' => 'http://www.combodo.com/itop-help',
  198. 'value' => '',
  199. 'source_of_value' => '',
  200. 'show_in_conf_sample' => true,
  201. ),
  202. 'log_usage' => array(
  203. 'type' => 'bool',
  204. 'description' => 'Log the usage of the application (i.e. the date/time and the user name of each login)',
  205. 'default' => false,
  206. 'value' => false,
  207. 'source_of_value' => '',
  208. 'show_in_conf_sample' => false,
  209. ),
  210. 'synchro_trace' => array(
  211. 'type' => 'string',
  212. 'description' => 'Synchronization details: none, display, save (includes \'display\')',
  213. 'default' => 'none',
  214. 'value' => 'none',
  215. 'source_of_value' => '',
  216. 'show_in_conf_sample' => true,
  217. ),
  218. 'link_set_item_separator' => array(
  219. 'type' => 'string',
  220. 'description' => 'Link set from string: line separator',
  221. 'default' => '|',
  222. 'value' => '|',
  223. 'source_of_value' => '',
  224. 'show_in_conf_sample' => true,
  225. ),
  226. 'link_set_attribute_separator' => array(
  227. 'type' => 'string',
  228. 'description' => 'Link set from string: attribute separator',
  229. 'default' => ';',
  230. 'value' => ';',
  231. 'source_of_value' => '',
  232. 'show_in_conf_sample' => true,
  233. ),
  234. 'link_set_value_separator' => array(
  235. 'type' => 'string',
  236. 'description' => 'Link set from string: value separator (between the attcode and the value itself',
  237. 'default' => ':',
  238. 'value' => ':',
  239. 'source_of_value' => '',
  240. 'show_in_conf_sample' => true,
  241. ),
  242. 'link_set_attribute_qualifier' => array(
  243. 'type' => 'string',
  244. 'description' => 'Link set from string: attribute qualifier (encloses both the attcode and the value)',
  245. 'default' => "'",
  246. 'value' => "'",
  247. 'source_of_value' => '',
  248. 'show_in_conf_sample' => true,
  249. ),
  250. 'cron_max_execution_time' => array(
  251. 'type' => 'integer',
  252. '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',
  253. 'default' => 600,
  254. 'value' => 600,
  255. 'source_of_value' => '',
  256. 'show_in_conf_sample' => true,
  257. ),
  258. 'cron_sleep' => array(
  259. 'type' => 'integer',
  260. 'description' => 'Duration (seconds) before cron.php checks again if something must be done',
  261. 'default' => 2,
  262. 'value' => 2,
  263. 'source_of_value' => '',
  264. 'show_in_conf_sample' => false,
  265. ),
  266. 'email_asynchronous' => array(
  267. 'type' => 'bool',
  268. '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',
  269. 'default' => false,
  270. 'value' => false,
  271. 'source_of_value' => '',
  272. 'show_in_conf_sample' => true,
  273. ),
  274. 'apc_cache.enabled' => array(
  275. 'type' => 'bool',
  276. 'description' => 'If set, the APC cache is allowed (the PHP extension must also be active)',
  277. 'default' => true,
  278. 'value' => true,
  279. 'source_of_value' => '',
  280. 'show_in_conf_sample' => true,
  281. ),
  282. 'apc_cache.query_ttl' => array(
  283. 'type' => 'integer',
  284. 'description' => 'Time to live set in APC for the prepared queries (seconds - 0 means no timeout)',
  285. 'default' => 3600,
  286. 'value' => 3600,
  287. 'source_of_value' => '',
  288. 'show_in_conf_sample' => true,
  289. ),
  290. 'timezone' => array(
  291. 'type' => 'string',
  292. 'description' => 'Timezone (reference: http://php.net/manual/en/timezones.php). If empty, it will be left unchanged and MUST be explicitely configured in PHP',
  293. // examples... not used (nor 'description')
  294. 'examples' => array('America/Sao_Paulo', 'America/New_York (standing for EDT)', 'America/Los_Angeles (standing for PDT)', 'Asia/Istanbul', 'Asia/Singapore', 'Africa/Casablanca', 'Australia/Sydney'),
  295. 'default' => 'Europe/Paris',
  296. 'value' => 'Europe/Paris',
  297. 'source_of_value' => '',
  298. 'show_in_conf_sample' => true,
  299. ),
  300. 'cas_include_path' => array(
  301. 'type' => 'string',
  302. 'description' => 'The path where to find the phpCAS library',
  303. // examples... not used (nor 'description')
  304. 'default' => '/usr/share/php',
  305. 'value' => '/usr/share/php',
  306. 'source_of_value' => '',
  307. 'show_in_conf_sample' => true,
  308. ),
  309. 'cas_version' => array(
  310. 'type' => 'string',
  311. 'description' => 'The CAS protocol version to use: "1.0" (CAS v1), "2.0" (CAS v2) or "S1" (SAML V1) )',
  312. // examples... not used (nor 'description')
  313. 'default' => '2.0',
  314. 'value' => '',
  315. 'source_of_value' => '',
  316. 'show_in_conf_sample' => true,
  317. ),
  318. 'cas_host' => array(
  319. 'type' => 'string',
  320. 'description' => 'The name of the CAS host',
  321. // examples... not used (nor 'description')
  322. 'default' => '',
  323. 'value' => '',
  324. 'source_of_value' => '',
  325. 'show_in_conf_sample' => true,
  326. ),
  327. 'cas_port' => array(
  328. 'type' => 'integer',
  329. 'description' => 'The port used by the CAS server',
  330. // examples... not used (nor 'description')
  331. 'default' => 443,
  332. 'value' => 443,
  333. 'source_of_value' => '',
  334. 'show_in_conf_sample' => true,
  335. ),
  336. 'cas_context' => array(
  337. 'type' => 'string',
  338. 'description' => 'The CAS context',
  339. // examples... not used (nor 'description')
  340. 'default' => '',
  341. 'value' => '',
  342. 'source_of_value' => '',
  343. 'show_in_conf_sample' => true,
  344. ),
  345. 'cas_server_ca_cert_path' => array(
  346. 'type' => 'string',
  347. 'description' => 'The path where to find the certificate of the CA for validating the certificate of the CAS server',
  348. // examples... not used (nor 'description')
  349. 'default' => '',
  350. 'value' => '',
  351. 'source_of_value' => '',
  352. 'show_in_conf_sample' => true,
  353. ),
  354. 'cas_logout_redirect_service' => array(
  355. 'type' => 'string',
  356. 'description' => 'The redirect service (URL) to use when logging-out with CAS',
  357. // examples... not used (nor 'description')
  358. 'default' => '',
  359. 'value' => '',
  360. 'source_of_value' => '',
  361. 'show_in_conf_sample' => true,
  362. ),
  363. 'cas_memberof' => array(
  364. 'type' => 'string',
  365. 'description' => 'A semicolon separated list of group names that the user must be member of (works only with SAML - e.g. cas_version=> "S1")',
  366. // examples... not used (nor 'description')
  367. 'default' => '',
  368. 'value' => '',
  369. 'source_of_value' => '',
  370. 'show_in_conf_sample' => true,
  371. ),
  372. 'cas_debug' => array(
  373. 'type' => 'bool',
  374. 'description' => 'Activate the CAS debug',
  375. // examples... not used (nor 'description')
  376. 'default' => false,
  377. 'value' => false,
  378. 'source_of_value' => '',
  379. 'show_in_conf_sample' => true,
  380. ),
  381. 'deadline_format' => array(
  382. 'type' => 'string',
  383. 'description' => 'The format used for displaying "deadline" attributes: any string with the following placeholders: $date$, $difference$',
  384. // examples... $date$ ($deadline$)
  385. 'default' => '$difference$',
  386. 'value' => '$difference$',
  387. 'source_of_value' => '',
  388. 'show_in_conf_sample' => true,
  389. ),
  390. 'buttons_position' => array(
  391. 'type' => 'string',
  392. 'description' => 'Position of the forms buttons: bottom | top | both',
  393. // examples... not used
  394. 'default' => 'both',
  395. 'value' => 'both',
  396. 'source_of_value' => '',
  397. 'show_in_conf_sample' => true,
  398. ),
  399. 'shortcut_actions' => array(
  400. 'type' => 'string',
  401. 'description' => 'Actions that are available as direct buttons next to the "Actions" menu',
  402. // examples... not used
  403. 'default' => 'UI:Menu:Modify,UI:Menu:New',
  404. 'value' => 'UI:Menu:Modify',
  405. 'source_of_value' => '',
  406. 'show_in_conf_sample' => true,
  407. ),
  408. );
  409. public function IsProperty($sPropCode)
  410. {
  411. return (array_key_exists($sPropCode, $this->m_aSettings));
  412. }
  413. public function GetDescription($sPropCode)
  414. {
  415. return $this->m_aSettings[$sPropCode];
  416. }
  417. public function Set($sPropCode, $value, $sSourceDesc = 'unknown')
  418. {
  419. $sType = $this->m_aSettings[$sPropCode]['type'];
  420. switch($sType)
  421. {
  422. case 'bool':
  423. $value = (bool) $value;
  424. break;
  425. case 'string':
  426. $value = (string) $value;
  427. break;
  428. case 'integer':
  429. $value = (integer) $value;
  430. break;
  431. case 'float':
  432. $value = (float) $value;
  433. break;
  434. default:
  435. throw new CoreException('Unknown type for setting', array('property' => $sPropCode, 'type' => $sType));
  436. }
  437. $this->m_aSettings[$sPropCode]['value'] = $value;
  438. $this->m_aSettings[$sPropCode]['source_of_value'] = $sSourceDesc;
  439. }
  440. public function Get($sPropCode)
  441. {
  442. return $this->m_aSettings[$sPropCode]['value'];
  443. }
  444. // Those variables will be deprecated later, when the transition to ...Get('my_setting') will be done
  445. protected $m_sDBHost;
  446. protected $m_sDBUser;
  447. protected $m_sDBPwd;
  448. protected $m_sDBName;
  449. protected $m_sDBSubname;
  450. protected $m_sDBCharacterSet;
  451. protected $m_sDBCollation;
  452. /**
  453. * Event log options (see LOG_... definition)
  454. */
  455. // Those variables will be deprecated later, when the transition to ...Get('my_setting') will be done
  456. protected $m_bLogGlobal;
  457. protected $m_bLogNotification;
  458. protected $m_bLogIssue;
  459. protected $m_bLogWebService;
  460. protected $m_bLogKpiDuration; // private setting
  461. protected $m_bLogKpiMemory; // private setting
  462. protected $m_bDebugQueries; // private setting
  463. protected $m_bQueryCacheEnabled; // private setting
  464. /**
  465. * @var integer Number of elements to be displayed when there are more than m_iMaxDisplayLimit elements
  466. */
  467. protected $m_iMinDisplayLimit;
  468. /**
  469. * @var integer Max number of elements before truncating the display
  470. */
  471. protected $m_iMaxDisplayLimit;
  472. /**
  473. * @var integer Number of seconds between two reloads of the display (standard)
  474. */
  475. protected $m_iStandardReloadInterval;
  476. /**
  477. * @var integer Number of seconds between two reloads of the display (fast)
  478. */
  479. protected $m_iFastReloadInterval;
  480. /**
  481. * @var boolean Whether or not a secure connection is required for using the application.
  482. * If set, any attempt to connect to an iTop page with http:// will be redirected
  483. * to https://
  484. */
  485. protected $m_bSecureConnectionRequired;
  486. /**
  487. * @var string Langage code, default if the user language is undefined
  488. */
  489. protected $m_sDefaultLanguage;
  490. /**
  491. * @var string Type of login process allowed: form|basic|url|external
  492. */
  493. protected $m_sAllowedLoginTypes;
  494. /**
  495. * @var string Name of the PHP variable in which external authentication information is passed by the web server
  496. */
  497. protected $m_sExtAuthVariable;
  498. /**
  499. * @var string Encryption key used for all attributes of type "encrypted string". Can be set to a random value
  500. * unless you want to import a database from another iTop instance, in which case you must use
  501. * the same encryption key in order to properly decode the encrypted fields
  502. */
  503. protected $m_sEncryptionKey;
  504. /**
  505. * @var array Additional character sets to be supported by the interactive CSV import
  506. * 'iconv_code' => 'display name'
  507. */
  508. protected $m_aCharsets;
  509. public function __construct($sConfigFile, $bLoadConfig = true)
  510. {
  511. $this->m_sFile = $sConfigFile;
  512. $this->m_aAppModules = array(
  513. // Some default modules, always present can be move to an official iTop Module later if needed
  514. 'application/transaction.class.inc.php',
  515. 'application/menunode.class.inc.php',
  516. 'application/user.preferences.class.inc.php',
  517. 'application/audit.rule.class.inc.php',
  518. // Romain - That's dirty, because those classes are in fact part of the core
  519. // but I needed those classes to be derived from cmdbAbstractObject
  520. // (to be managed via the GUI) and this class in not really known from
  521. // the core, PLUS I needed the includes to be there also for the setup
  522. // to create the tables.
  523. 'core/event.class.inc.php',
  524. 'core/action.class.inc.php',
  525. 'core/trigger.class.inc.php',
  526. 'synchro/synchrodatasource.class.inc.php',
  527. );
  528. $this->m_aDataModels = array();
  529. $this->m_aWebServiceCategories = array(
  530. 'webservices/webservices.basic.php',
  531. );
  532. $this->m_aAddons = array(
  533. // Default AddOn, always present can be moved to an official iTop Module later if needed
  534. 'user rights' => 'addons/userrights/userrightsprofile.class.inc.php',
  535. );
  536. $this->m_aDictionaries = self::ScanDictionariesDir();
  537. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  538. {
  539. $this->m_aSettings[$sPropCode]['value'] = $aSettingInfo['default'];
  540. }
  541. $this->m_sDBHost = '';
  542. $this->m_sDBUser = '';
  543. $this->m_sDBPwd = '';
  544. $this->m_sDBName = '';
  545. $this->m_sDBSubname = '';
  546. $this->m_sDBCharacterSet = DEFAULT_CHARACTER_SET;
  547. $this->m_sDBCollation = DEFAULT_COLLATION;
  548. $this->m_bLogGlobal = DEFAULT_LOG_GLOBAL;
  549. $this->m_bLogNotification = DEFAULT_LOG_NOTIFICATION;
  550. $this->m_bLogIssue = DEFAULT_LOG_ISSUE;
  551. $this->m_bLogWebService = DEFAULT_LOG_WEB_SERVICE;
  552. $this->m_bLogKPIDuration = DEFAULT_LOG_KPI_DURATION;
  553. $this->m_bLogKPIDuration = DEFAULT_LOG_KPI_DURATION;
  554. $this->m_iMinDisplayLimit = DEFAULT_MIN_DISPLAY_LIMIT;
  555. $this->m_iMaxDisplayLimit = DEFAULT_MAX_DISPLAY_LIMIT;
  556. $this->m_iStandardReloadInterval = DEFAULT_STANDARD_RELOAD_INTERVAL;
  557. $this->m_iFastReloadInterval = DEFAULT_FAST_RELOAD_INTERVAL;
  558. $this->m_bSecureConnectionRequired = DEFAULT_SECURE_CONNECTION_REQUIRED;
  559. $this->m_sDefaultLanguage = 'EN US';
  560. $this->m_sAllowedLoginTypes = DEFAULT_ALLOWED_LOGIN_TYPES;
  561. $this->m_sExtAuthVariable = DEFAULT_EXT_AUTH_VARIABLE;
  562. $this->m_sEncryptionKey = DEFAULT_ENCRYPTION_KEY;
  563. $this->m_aCharsets = array();
  564. $this->m_aModuleSettings = array();
  565. if ($bLoadConfig)
  566. {
  567. $this->Load($sConfigFile);
  568. $this->Verify();
  569. }
  570. // Application root url: set a default value, then normalize it
  571. $sAppRootUrl = trim($this->Get('app_root_url'));
  572. if (strlen($sAppRootUrl) == 0)
  573. {
  574. $sAppRootUrl = utils::GetDefaultUrlAppRoot();
  575. }
  576. if (substr($sAppRootUrl, -1, 1) != '/')
  577. {
  578. $sAppRootUrl .= '/';
  579. }
  580. $this->Set('app_root_url', $sAppRootUrl);
  581. }
  582. protected function CheckFile($sPurpose, $sFileName)
  583. {
  584. if (!file_exists($sFileName))
  585. {
  586. throw new ConfigException("Could not find $sPurpose file", array('file' => $sFileName));
  587. }
  588. if (!is_readable($sFileName))
  589. {
  590. throw new ConfigException("Could not read $sPurpose file (the file exists but cannot be read). Do you have the rights to access this file?", array('file' => $sFileName));
  591. }
  592. }
  593. protected function Load($sConfigFile)
  594. {
  595. $this->CheckFile('configuration', $sConfigFile);
  596. $sConfigCode = trim(file_get_contents($sConfigFile));
  597. // This does not work on several lines
  598. // preg_match('/^<\\?php(.*)\\?'.'>$/', $sConfigCode, $aMatches)...
  599. // So, I've implemented a solution suggested in the PHP doc (search for phpWrapper)
  600. try
  601. {
  602. ob_start();
  603. eval('?'.'>'.trim($sConfigCode));
  604. $sNoise = trim(ob_get_contents());
  605. ob_end_clean();
  606. }
  607. catch (Exception $e)
  608. {
  609. // well, never reach in case of parsing error :-(
  610. // will be improved in PHP 6 ?
  611. throw new ConfigException('Error in configuration file', array('file' => $sConfigFile, 'error' => $e->getMessage()));
  612. }
  613. if (strlen($sNoise) > 0)
  614. {
  615. // Note: sNoise is an html output, but so far it was ok for me (e.g. showing the entire call stack)
  616. throw new ConfigException('Syntax error in configuration file', array('file' => $sConfigFile, 'error' => '<tt>'.htmlentities($sNoise, ENT_QUOTES, 'UTF-8').'</tt>'));
  617. }
  618. if (!isset($MySettings) || !is_array($MySettings))
  619. {
  620. throw new ConfigException('Missing array in configuration file', array('file' => $sConfigFile, 'expected' => '$MySettings'));
  621. }
  622. if (!isset($MyModules) || !is_array($MyModules))
  623. {
  624. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules'));
  625. }
  626. if (!array_key_exists('application', $MyModules))
  627. {
  628. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'application\']'));
  629. }
  630. if (!array_key_exists('business', $MyModules))
  631. {
  632. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'business\']'));
  633. }
  634. if (!array_key_exists('addons', $MyModules))
  635. {
  636. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'addons\']'));
  637. }
  638. if (!array_key_exists('user rights', $MyModules['addons']))
  639. {
  640. // Add one, by default
  641. $MyModules['addons']['user rights'] = '/addons/userrights/userrightsnull.class.inc.php';
  642. }
  643. if (!array_key_exists('dictionaries', $MyModules))
  644. {
  645. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'dictionaries\']'));
  646. }
  647. $this->m_aAppModules = $MyModules['application'];
  648. $this->m_aDataModels = $MyModules['business'];
  649. if (isset($MyModules['webservices']))
  650. {
  651. $this->m_aWebServiceCategories = $MyModules['webservices'];
  652. }
  653. $this->m_aAddons = $MyModules['addons'];
  654. $this->m_aDictionaries = $MyModules['dictionaries'];
  655. foreach($MySettings as $sPropCode => $rawvalue)
  656. {
  657. if ($this->IsProperty($sPropCode))
  658. {
  659. $value = trim($rawvalue);
  660. $this->Set($sPropCode, $value, $sConfigFile);
  661. }
  662. }
  663. $this->m_sDBHost = trim($MySettings['db_host']);
  664. $this->m_sDBUser = trim($MySettings['db_user']);
  665. $this->m_sDBPwd = trim($MySettings['db_pwd']);
  666. $this->m_sDBName = trim($MySettings['db_name']);
  667. $this->m_sDBSubname = trim($MySettings['db_subname']);
  668. $this->m_sDBCharacterSet = isset($MySettings['db_character_set']) ? trim($MySettings['db_character_set']) : DEFAULT_CHARACTER_SET;
  669. $this->m_sDBCollation = isset($MySettings['db_collation']) ? trim($MySettings['db_collation']) : DEFAULT_COLLATION;
  670. $this->m_bLogGlobal = isset($MySettings['log_global']) ? (bool) trim($MySettings['log_global']) : DEFAULT_LOG_GLOBAL;
  671. $this->m_bLogNotification = isset($MySettings['log_notification']) ? (bool) trim($MySettings['log_notification']) : DEFAULT_LOG_NOTIFICATION;
  672. $this->m_bLogIssue = isset($MySettings['log_issue']) ? (bool) trim($MySettings['log_issue']) : DEFAULT_LOG_ISSUE;
  673. $this->m_bLogWebService = isset($MySettings['log_web_service']) ? (bool) trim($MySettings['log_web_service']) : DEFAULT_LOG_WEB_SERVICE;
  674. $this->m_bLogKPIDuration = isset($MySettings['log_kpi_duration']) ? (bool) trim($MySettings['log_kpi_duration']) : DEFAULT_LOG_KPI_DURATION;
  675. $this->m_bLogKPIMemory = isset($MySettings['log_kpi_memory']) ? (bool) trim($MySettings['log_kpi_memory']) : DEFAULT_LOG_KPI_MEMORY;
  676. $this->m_bDebugQueries = isset($MySettings['debug_queries']) ? (bool) trim($MySettings['debug_queries']) : DEFAULT_DEBUG_QUERIES;
  677. $this->m_bQueryCacheEnabled = isset($MySettings['query_cache_enabled']) ? (bool) trim($MySettings['query_cache_enabled']) : DEFAULT_QUERY_CACHE_ENABLED;
  678. $this->m_iMinDisplayLimit = isset($MySettings['min_display_limit']) ? trim($MySettings['min_display_limit']) : DEFAULT_MIN_DISPLAY_LIMIT;
  679. $this->m_iMaxDisplayLimit = isset($MySettings['max_display_limit']) ? trim($MySettings['max_display_limit']) : DEFAULT_MAX_DISPLAY_LIMIT;
  680. $this->m_iStandardReloadInterval = isset($MySettings['standard_reload_interval']) ? trim($MySettings['standard_reload_interval']) : DEFAULT_STANDARD_RELOAD_INTERVAL;
  681. $this->m_iFastReloadInterval = isset($MySettings['fast_reload_interval']) ? trim($MySettings['fast_reload_interval']) : DEFAULT_FAST_RELOAD_INTERVAL;
  682. $this->m_bSecureConnectionRequired = isset($MySettings['secure_connection_required']) ? (bool) trim($MySettings['secure_connection_required']) : DEFAULT_SECURE_CONNECTION_REQUIRED;
  683. $this->m_aModuleSettings = isset($MyModuleSettings) ? $MyModuleSettings : array();
  684. $this->m_sDefaultLanguage = isset($MySettings['default_language']) ? trim($MySettings['default_language']) : 'EN US';
  685. $this->m_sAllowedLoginTypes = isset($MySettings['allowed_login_types']) ? trim($MySettings['allowed_login_types']) : DEFAULT_ALLOWED_LOGIN_TYPES;
  686. $this->m_sExtAuthVariable = isset($MySettings['ext_auth_variable']) ? trim($MySettings['ext_auth_variable']) : DEFAULT_EXT_AUTH_VARIABLE;
  687. $this->m_sEncryptionKey = isset($MySettings['encryption_key']) ? trim($MySettings['encryption_key']) : DEFAULT_ENCRYPTION_KEY;
  688. $this->m_aCharsets = isset($MySettings['csv_import_charsets']) ? $MySettings['csv_import_charsets'] : array();
  689. }
  690. protected function Verify()
  691. {
  692. // Files are verified later on, just before using them -see MetaModel::Plugin()
  693. // (we have their final path at that point)
  694. }
  695. public function GetModuleSetting($sModule, $sProperty, $defaultvalue = null)
  696. {
  697. if (isset($this->m_aModuleSettings[$sModule][$sProperty]))
  698. {
  699. return $this->m_aModuleSettings[$sModule][$sProperty];
  700. }
  701. return $defaultvalue;
  702. }
  703. public function SetModuleSetting($sModule, $sProperty, $value)
  704. {
  705. $this->m_aModuleSettings[$sModule][$sProperty] = $value;
  706. }
  707. public function GetAppModules()
  708. {
  709. return $this->m_aAppModules;
  710. }
  711. public function SetAppModules($aAppModules)
  712. {
  713. $this->m_aAppModules = $aAppModules;
  714. }
  715. public function GetDataModels()
  716. {
  717. return $this->m_aDataModels;
  718. }
  719. public function SetDataModels($aDataModels)
  720. {
  721. $this->m_aDataModels = $aDataModels;
  722. }
  723. public function GetWebServiceCategories()
  724. {
  725. return $this->m_aWebServiceCategories;
  726. }
  727. public function SetWebServiceCategories($aWebServiceCategories)
  728. {
  729. $this->m_aWebServiceCategories = $aWebServiceCategories;
  730. }
  731. public function GetAddons()
  732. {
  733. return $this->m_aAddons;
  734. }
  735. public function SetAddons($aAddons)
  736. {
  737. $this->m_aAddons = $aAddons;
  738. }
  739. public function GetDictionaries()
  740. {
  741. return $this->m_aDictionaries;
  742. }
  743. public function SetDictionaries($aDictionaries)
  744. {
  745. $this->m_aDictionaries = $aDictionaries;
  746. }
  747. public function GetDBHost()
  748. {
  749. return $this->m_sDBHost;
  750. }
  751. public function GetDBName()
  752. {
  753. return $this->m_sDBName;
  754. }
  755. public function GetDBSubname()
  756. {
  757. return $this->m_sDBSubname;
  758. }
  759. public function GetDBCharacterSet()
  760. {
  761. return $this->m_sDBCharacterSet;
  762. }
  763. public function GetDBCollation()
  764. {
  765. return $this->m_sDBCollation;
  766. }
  767. public function GetDBUser()
  768. {
  769. return $this->m_sDBUser;
  770. }
  771. public function GetDBPwd()
  772. {
  773. return $this->m_sDBPwd;
  774. }
  775. public function GetLogGlobal()
  776. {
  777. return $this->m_bLogGlobal;
  778. }
  779. public function GetLogNotification()
  780. {
  781. return $this->m_bLogNotification;
  782. }
  783. public function GetLogIssue()
  784. {
  785. return $this->m_bLogIssue;
  786. }
  787. public function GetLogWebService()
  788. {
  789. return $this->m_bLogWebService;
  790. }
  791. public function GetLogKPIDuration()
  792. {
  793. return $this->m_bLogKPIDuration;
  794. }
  795. public function GetLogKPIMemory()
  796. {
  797. return $this->m_bLogKPIMemory;
  798. }
  799. public function GetDebugQueries()
  800. {
  801. return $this->m_bDebugQueries;
  802. }
  803. public function GetQueryCacheEnabled()
  804. {
  805. return $this->m_bQueryCacheEnabled;
  806. }
  807. public function GetMinDisplayLimit()
  808. {
  809. return $this->m_iMinDisplayLimit;
  810. }
  811. public function GetMaxDisplayLimit()
  812. {
  813. return $this->m_iMaxDisplayLimit;
  814. }
  815. public function GetStandardReloadInterval()
  816. {
  817. return $this->m_iStandardReloadInterval;
  818. }
  819. public function GetFastReloadInterval()
  820. {
  821. return $this->m_iFastReloadInterval;
  822. }
  823. public function GetSecureConnectionRequired()
  824. {
  825. return $this->m_bSecureConnectionRequired;
  826. }
  827. public function GetDefaultLanguage()
  828. {
  829. return $this->m_sDefaultLanguage;
  830. }
  831. public function GetEncryptionKey()
  832. {
  833. return $this->m_sEncryptionKey;
  834. }
  835. public function GetAllowedLoginTypes()
  836. {
  837. return explode('|', $this->m_sAllowedLoginTypes);
  838. }
  839. public function GetExternalAuthenticationVariable()
  840. {
  841. return $this->m_sExtAuthVariable;
  842. }
  843. public function GetCSVImportCharsets()
  844. {
  845. return $this->m_aCharsets;
  846. }
  847. public function SetDBHost($sDBHost)
  848. {
  849. $this->m_sDBHost = $sDBHost;
  850. }
  851. public function SetDBName($sDBName)
  852. {
  853. $this->m_sDBName = $sDBName;
  854. }
  855. public function SetDBSubname($sDBSubName)
  856. {
  857. $this->m_sDBSubname = $sDBSubName;
  858. }
  859. public function SetDBCharacterSet($sDBCharacterSet)
  860. {
  861. $this->m_sDBCharacterSet = $sDBCharacterSet;
  862. }
  863. public function SetDBCollation($sDBCollation)
  864. {
  865. $this->m_sDBCollation = $sDBCollation;
  866. }
  867. public function SetDBUser($sUser)
  868. {
  869. $this->m_sDBUser = $sUser;
  870. }
  871. public function SetDBPwd($sPwd)
  872. {
  873. $this->m_sDBPwd = $sPwd;
  874. }
  875. public function SetLogGlobal($iLogGlobal)
  876. {
  877. $this->m_iLogGlobal = $iLogGlobal;
  878. }
  879. public function SetLogNotification($iLogNotification)
  880. {
  881. $this->m_iLogNotification = $iLogNotification;
  882. }
  883. public function SetLogIssue($iLogIssue)
  884. {
  885. $this->m_iLogIssue = $iLogIssue;
  886. }
  887. public function SetLogWebService($iLogWebService)
  888. {
  889. $this->m_iLogWebService = $iLogWebService;
  890. }
  891. public function SetMinDisplayLimit($iMinDisplayLimit)
  892. {
  893. $this->m_iMinDisplayLimit = $iMinDisplayLimit;
  894. }
  895. public function SetMaxDisplayLimit($iMaxDisplayLimit)
  896. {
  897. $this->m_iMaxDisplayLimit = $iMaxDisplayLimit;
  898. }
  899. public function SetStandardReloadInterval($iStandardReloadInterval)
  900. {
  901. $this->m_iStandardReloadInterval = $iStandardReloadInterval;
  902. }
  903. public function SetFastReloadInterval($iFastReloadInterval)
  904. {
  905. $this->m_iFastReloadInterval = $iFastReloadInterval;
  906. }
  907. public function SetSecureConnectionRequired($bSecureConnectionRequired)
  908. {
  909. $this->m_bSecureConnectionRequired = $bSecureConnectionRequired;
  910. }
  911. public function SetDefaultLanguage($sLanguageCode)
  912. {
  913. $this->m_sDefaultLanguage = $sLanguageCode;
  914. }
  915. public function SetAllowedLoginTypes($aAllowedLoginTypes)
  916. {
  917. $this->m_sAllowedLoginTypes = implode('|', $aAllowedLoginTypes);
  918. }
  919. public function SetExternalAuthenticationVariable($sExtAuthVariable)
  920. {
  921. $this->m_sExtAuthVariable = $sExtAuthVariable;
  922. }
  923. public function SetEncryptionKey($sKey)
  924. {
  925. $this->m_sEncryptionKey = $sKey;
  926. }
  927. public function SetCSVImportCharsets($aCharsets)
  928. {
  929. $this->m_aCharsets = $aCharsets;
  930. }
  931. public function AddCSVImportCharset($sIconvCode, $sDisplayName)
  932. {
  933. $this->m_aCharsets[$sIconvCode] = $sDisplayName;
  934. }
  935. public function FileIsWritable()
  936. {
  937. return is_writable($this->m_sFile);
  938. }
  939. public function GetLoadedFile()
  940. {
  941. return $this->m_sFile;
  942. }
  943. /**
  944. * Render the configuration as an associative array
  945. * @return boolean True otherwise throws an Exception
  946. */
  947. public function ToArray()
  948. {
  949. $aSettings = array();
  950. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  951. {
  952. $aSettings[$sPropCode] = $aSettingInfo['value'];
  953. }
  954. $aSettings['db_host'] = $this->m_sDBHost;
  955. $aSettings['db_user'] = $this->m_sDBUser;
  956. $aSettings['db_pwd'] = $this->m_sDBPwd;
  957. $aSettings['db_name'] = $this->m_sDBName;
  958. $aSettings['db_subname'] = $this->m_sDBSubname;
  959. $aSettings['db_character_set'] = $this->m_sDBCharacterSet;
  960. $aSettings['db_collation'] = $this->m_sDBCollation;
  961. $aSettings['log_global'] = $this->m_bLogGlobal;
  962. $aSettings['log_notification'] = $this->m_bLogNotification;
  963. $aSettings['log_issue'] = $this->m_bLogIssue;
  964. $aSettings['log_web_service'] = $this->m_bLogWebService;
  965. $aSettings['min_display_limit'] = $this->m_iMinDisplayLimit;
  966. $aSettings['max_display_limit'] = $this->m_iMaxDisplayLimit;
  967. $aSettings['standard_reload_interval'] = $this->m_iStandardReloadInterval;
  968. $aSettings['fast_reload_interval'] = $this->m_iFastReloadInterval;
  969. $aSettings['secure_connection_required'] = $this->m_bSecureConnectionRequired;
  970. $aSettings['default_language'] = $this->m_sDefaultLanguage;
  971. $aSettings['allowed_login_types'] = $this->m_sAllowedLoginTypes;
  972. $aSettings['encryption_key'] = $this->m_sEncryptionKey;
  973. $aSettings['csv_import_charsets'] = $this->m_aCharsets;
  974. foreach ($this->m_aModuleSettings as $sModule => $aProperties)
  975. {
  976. foreach ($aProperties as $sProperty => $value)
  977. {
  978. $aSettings['module_settings'][$sModule][$sProperty] = $value;
  979. }
  980. }
  981. foreach($this->m_aAppModules as $sFile)
  982. {
  983. $aSettings['application_list'][] = $sFile;
  984. }
  985. foreach($this->m_aDataModels as $sFile)
  986. {
  987. $aSettings['datamodel_list'][] = $sFile;
  988. }
  989. foreach($this->m_aWebServiceCategories as $sFile)
  990. {
  991. $aSettings['webservice_list'][] = $sFile;
  992. }
  993. foreach($this->m_aAddons as $sKey => $sFile)
  994. {
  995. $aSettings['addon_list'][] = $sFile;
  996. }
  997. foreach($this->m_aDictionaries as $sFile)
  998. {
  999. $aSettings['dictionary_list'][] = $sFile;
  1000. }
  1001. return $aSettings;
  1002. }
  1003. /**
  1004. * Write the configuration to a file (php format) that can be reloaded later
  1005. * By default write to the same file that was specified when constructing the object
  1006. * @param $sFileName string Name of the file to write to (emtpy to write to the same file)
  1007. * @return boolean True otherwise throws an Exception
  1008. */
  1009. public function WriteToFile($sFileName = '')
  1010. {
  1011. if (empty($sFileName))
  1012. {
  1013. $sFileName = $this->m_sFile;
  1014. }
  1015. $hFile = @fopen($sFileName, 'w');
  1016. if ($hFile !== false)
  1017. {
  1018. fwrite($hFile, "<?php\n");
  1019. fwrite($hFile, "\n/**\n");
  1020. fwrite($hFile, " *\n");
  1021. fwrite($hFile, " * phpMyORM configuration file, generated by the iTop configuration wizard\n");
  1022. fwrite($hFile, " *\n");
  1023. fwrite($hFile, " * The file is used in MetaModel::LoadConfig() which does all the necessary initialization job\n");
  1024. fwrite($hFile, " *\n");
  1025. fwrite($hFile, " */\n");
  1026. fwrite($hFile, "\n");
  1027. fwrite($hFile, "\$MySettings = array(\n");
  1028. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  1029. {
  1030. if ($aSettingInfo['show_in_conf_sample'])
  1031. {
  1032. $sType = $this->m_aSettings[$sPropCode]['type'];
  1033. switch($sType)
  1034. {
  1035. case 'bool':
  1036. $sSeenAs = $aSettingInfo['value'] ? '1' : '0';
  1037. break;
  1038. default:
  1039. $sSeenAs = "'".addslashes($aSettingInfo['value'])."'";
  1040. }
  1041. fwrite($hFile, "\t'$sPropCode' => $sSeenAs,\n");
  1042. }
  1043. }
  1044. fwrite($hFile, "\t'db_host' => '{$this->m_sDBHost}',\n");
  1045. fwrite($hFile, "\t'db_user' => '{$this->m_sDBUser}',\n");
  1046. fwrite($hFile, "\t'db_pwd' => '".addslashes($this->m_sDBPwd)."',\n");
  1047. fwrite($hFile, "\t'db_name' => '{$this->m_sDBName}',\n");
  1048. fwrite($hFile, "\t'db_subname' => '{$this->m_sDBSubname}',\n");
  1049. fwrite($hFile, "\t'db_character_set' => '{$this->m_sDBCharacterSet}',\n");
  1050. fwrite($hFile, "\t'db_collation' => '{$this->m_sDBCollation}',\n");
  1051. fwrite($hFile, "\n");
  1052. fwrite($hFile, "\t'log_global' => {$this->m_bLogGlobal},\n");
  1053. fwrite($hFile, "\t'log_notification' => {$this->m_bLogNotification},\n");
  1054. fwrite($hFile, "\t'log_issue' => {$this->m_bLogIssue},\n");
  1055. fwrite($hFile, "\t'log_web_service' => {$this->m_bLogWebService},\n");
  1056. fwrite($hFile, "\t'min_display_limit' => {$this->m_iMinDisplayLimit},\n");
  1057. fwrite($hFile, "\t'max_display_limit' => {$this->m_iMaxDisplayLimit},\n");
  1058. fwrite($hFile, "\t'standard_reload_interval' => {$this->m_iStandardReloadInterval},\n");
  1059. fwrite($hFile, "\t'fast_reload_interval' => {$this->m_iFastReloadInterval},\n");
  1060. fwrite($hFile, "\t'secure_connection_required' => ".($this->m_bSecureConnectionRequired ? 'true' : 'false').",\n");
  1061. fwrite($hFile, "\t'default_language' => '{$this->m_sDefaultLanguage}',\n");
  1062. fwrite($hFile, "\t'allowed_login_types' => '{$this->m_sAllowedLoginTypes}',\n");
  1063. fwrite($hFile, "\t'encryption_key' => '{$this->m_sEncryptionKey}',\n");
  1064. $sExport = var_export($this->m_aCharsets, true);
  1065. fwrite($hFile, "\t'csv_import_charsets' => $sExport,\n");
  1066. fwrite($hFile, ");\n");
  1067. fwrite($hFile, "\n");
  1068. fwrite($hFile, "\$MyModuleSettings = array(\n");
  1069. foreach ($this->m_aModuleSettings as $sModule => $aProperties)
  1070. {
  1071. fwrite($hFile, "\t'$sModule' => array (\n");
  1072. foreach ($aProperties as $sProperty => $value)
  1073. {
  1074. $sExport = var_export($value, true);
  1075. fwrite($hFile, "\t\t'$sProperty' => $sExport,\n");
  1076. }
  1077. fwrite($hFile, "\t),\n");
  1078. }
  1079. fwrite($hFile, ");\n");
  1080. fwrite($hFile, "\n/**\n");
  1081. fwrite($hFile, " *\n");
  1082. fwrite($hFile, " * Data model modules to be loaded. Names are specified as relative paths\n");
  1083. fwrite($hFile, " *\n");
  1084. fwrite($hFile, " */\n");
  1085. fwrite($hFile, "\$MyModules = array(\n");
  1086. fwrite($hFile, "\t'application' => array (\n");
  1087. foreach($this->m_aAppModules as $sFile)
  1088. {
  1089. fwrite($hFile, "\t\t'$sFile',\n");
  1090. }
  1091. fwrite($hFile, "\t),\n");
  1092. fwrite($hFile, "\t'business' => array (\n");
  1093. foreach($this->m_aDataModels as $sFile)
  1094. {
  1095. fwrite($hFile, "\t\t'$sFile',\n");
  1096. }
  1097. fwrite($hFile, "\t),\n");
  1098. fwrite($hFile, "\t'webservices' => array (\n");
  1099. foreach($this->m_aWebServiceCategories as $sFile)
  1100. {
  1101. fwrite($hFile, "\t\t'$sFile',\n");
  1102. }
  1103. fwrite($hFile, "\t),\n");
  1104. fwrite($hFile, "\t'addons' => array (\n");
  1105. foreach($this->m_aAddons as $sKey => $sFile)
  1106. {
  1107. fwrite($hFile, "\t\t'$sKey' => '$sFile',\n");
  1108. }
  1109. fwrite($hFile, "\t),\n");
  1110. fwrite($hFile, "\t'dictionaries' => array (\n");
  1111. foreach($this->m_aDictionaries as $sFile)
  1112. {
  1113. fwrite($hFile, "\t\t'$sFile',\n");
  1114. }
  1115. fwrite($hFile, "\t),\n");
  1116. fwrite($hFile, ");\n");
  1117. fwrite($hFile, '?'.'>'); // Avoid perturbing the syntax highlighting !
  1118. return fclose($hFile);
  1119. }
  1120. else
  1121. {
  1122. throw new ConfigException("Could not write to configuration file", array('file' => $sFileName));
  1123. }
  1124. }
  1125. protected static function ScanDictionariesDir()
  1126. {
  1127. $aResult = array();
  1128. // Populate automatically the list of dictionary files
  1129. $sDir = APPROOT.'/dictionaries';
  1130. if ($hDir = @opendir($sDir))
  1131. {
  1132. while (($sFile = readdir($hDir)) !== false)
  1133. {
  1134. $aMatches = array();
  1135. if (preg_match("/^([^\.]+\.)?dictionary\.itop\.(ui|core)\.php$/i", $sFile, $aMatches)) // Dictionary files named like [<Lang>.]dictionary.[core|ui].php are loaded automatically
  1136. {
  1137. $aResult[] = 'dictionaries/'.$sFile;
  1138. }
  1139. }
  1140. closedir($hDir);
  1141. }
  1142. return $aResult;
  1143. }
  1144. }
  1145. ?>