config.class.inc.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  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. );
  400. public function IsProperty($sPropCode)
  401. {
  402. return (array_key_exists($sPropCode, $this->m_aSettings));
  403. }
  404. public function GetDescription($sPropCode)
  405. {
  406. return $this->m_aSettings[$sPropCode];
  407. }
  408. public function Set($sPropCode, $value, $sSourceDesc = 'unknown')
  409. {
  410. $sType = $this->m_aSettings[$sPropCode]['type'];
  411. switch($sType)
  412. {
  413. case 'bool':
  414. $value = (bool) $value;
  415. break;
  416. case 'string':
  417. $value = (string) $value;
  418. break;
  419. case 'integer':
  420. $value = (integer) $value;
  421. break;
  422. case 'float':
  423. $value = (float) $value;
  424. break;
  425. default:
  426. throw new CoreException('Unknown type for setting', array('property' => $sPropCode, 'type' => $sType));
  427. }
  428. $this->m_aSettings[$sPropCode]['value'] = $value;
  429. $this->m_aSettings[$sPropCode]['source_of_value'] = $sSourceDesc;
  430. }
  431. public function Get($sPropCode)
  432. {
  433. return $this->m_aSettings[$sPropCode]['value'];
  434. }
  435. // Those variables will be deprecated later, when the transition to ...Get('my_setting') will be done
  436. protected $m_sDBHost;
  437. protected $m_sDBUser;
  438. protected $m_sDBPwd;
  439. protected $m_sDBName;
  440. protected $m_sDBSubname;
  441. protected $m_sDBCharacterSet;
  442. protected $m_sDBCollation;
  443. /**
  444. * Event log options (see LOG_... definition)
  445. */
  446. // Those variables will be deprecated later, when the transition to ...Get('my_setting') will be done
  447. protected $m_bLogGlobal;
  448. protected $m_bLogNotification;
  449. protected $m_bLogIssue;
  450. protected $m_bLogWebService;
  451. protected $m_bLogKpiDuration; // private setting
  452. protected $m_bLogKpiMemory; // private setting
  453. protected $m_bDebugQueries; // private setting
  454. protected $m_bQueryCacheEnabled; // private setting
  455. /**
  456. * @var integer Number of elements to be displayed when there are more than m_iMaxDisplayLimit elements
  457. */
  458. protected $m_iMinDisplayLimit;
  459. /**
  460. * @var integer Max number of elements before truncating the display
  461. */
  462. protected $m_iMaxDisplayLimit;
  463. /**
  464. * @var integer Number of seconds between two reloads of the display (standard)
  465. */
  466. protected $m_iStandardReloadInterval;
  467. /**
  468. * @var integer Number of seconds between two reloads of the display (fast)
  469. */
  470. protected $m_iFastReloadInterval;
  471. /**
  472. * @var boolean Whether or not a secure connection is required for using the application.
  473. * If set, any attempt to connect to an iTop page with http:// will be redirected
  474. * to https://
  475. */
  476. protected $m_bSecureConnectionRequired;
  477. /**
  478. * @var string Langage code, default if the user language is undefined
  479. */
  480. protected $m_sDefaultLanguage;
  481. /**
  482. * @var string Type of login process allowed: form|basic|url|external
  483. */
  484. protected $m_sAllowedLoginTypes;
  485. /**
  486. * @var string Name of the PHP variable in which external authentication information is passed by the web server
  487. */
  488. protected $m_sExtAuthVariable;
  489. /**
  490. * @var string Encryption key used for all attributes of type "encrypted string". Can be set to a random value
  491. * unless you want to import a database from another iTop instance, in which case you must use
  492. * the same encryption key in order to properly decode the encrypted fields
  493. */
  494. protected $m_sEncryptionKey;
  495. /**
  496. * @var array Additional character sets to be supported by the interactive CSV import
  497. * 'iconv_code' => 'display name'
  498. */
  499. protected $m_aCharsets;
  500. public function __construct($sConfigFile, $bLoadConfig = true)
  501. {
  502. $this->m_sFile = $sConfigFile;
  503. $this->m_aAppModules = array(
  504. // Some default modules, always present can be move to an official iTop Module later if needed
  505. 'application/transaction.class.inc.php',
  506. 'application/menunode.class.inc.php',
  507. 'application/user.preferences.class.inc.php',
  508. 'application/audit.rule.class.inc.php',
  509. // Romain - That's dirty, because those classes are in fact part of the core
  510. // but I needed those classes to be derived from cmdbAbstractObject
  511. // (to be managed via the GUI) and this class in not really known from
  512. // the core, PLUS I needed the includes to be there also for the setup
  513. // to create the tables.
  514. 'core/event.class.inc.php',
  515. 'core/action.class.inc.php',
  516. 'core/trigger.class.inc.php',
  517. 'synchro/synchrodatasource.class.inc.php',
  518. );
  519. $this->m_aDataModels = array();
  520. $this->m_aWebServiceCategories = array(
  521. 'webservices/webservices.basic.php',
  522. );
  523. $this->m_aAddons = array(
  524. // Default AddOn, always present can be moved to an official iTop Module later if needed
  525. 'user rights' => 'addons/userrights/userrightsprofile.class.inc.php',
  526. );
  527. $this->m_aDictionaries = array(
  528. // Default dictionaries, always present can be moved to an official iTop Module later if needed
  529. 'dictionaries/dictionary.itop.core.php',
  530. 'dictionaries/dictionary.itop.ui.php', // Support for English
  531. 'dictionaries/fr.dictionary.itop.ui.php', // Support for French
  532. 'dictionaries/fr.dictionary.itop.core.php', // Support for French
  533. 'dictionaries/es_cr.dictionary.itop.ui.php', // Support for Spanish (from Costa Rica)
  534. 'dictionaries/es_cr.dictionary.itop.core.php', // Support for Spanish (from Costa Rica)
  535. 'dictionaries/de.dictionary.itop.ui.php', // Support for German
  536. 'dictionaries/de.dictionary.itop.core.php', // Support for German
  537. 'dictionaries/pt_br.dictionary.itop.ui.php', // Support for Brazilian Portuguese
  538. 'dictionaries/pt_br.dictionary.itop.core.php', // Support for Brazilian Portuguese
  539. 'dictionaries/ru.dictionary.itop.ui.php', // Support for Russian
  540. 'dictionaries/ru.dictionary.itop.core.php', // Support for Russian
  541. 'dictionaries/tr.dictionary.itop.ui.php', // Support for Turkish
  542. 'dictionaries/tr.dictionary.itop.core.php', // Support for Turkish
  543. 'dictionaries/zh.dictionary.itop.ui.php', // Support for Chinese
  544. 'dictionaries/zh.dictionary.itop.core.php', // Support for Chinese
  545. 'dictionaries/it.dictionary.itop.ui.php', // Support for Italian
  546. 'dictionaries/it.dictionary.itop.core.php', // Support for Italian
  547. 'dictionaries/hu.dictionary.itop.ui.php', // Support for Hungarian
  548. 'dictionaries/hu.dictionary.itop.core.php', // Support for Hungarian
  549. );
  550. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  551. {
  552. $this->m_aSettings[$sPropCode]['value'] = $aSettingInfo['default'];
  553. }
  554. $this->m_sDBHost = '';
  555. $this->m_sDBUser = '';
  556. $this->m_sDBPwd = '';
  557. $this->m_sDBName = '';
  558. $this->m_sDBSubname = '';
  559. $this->m_sDBCharacterSet = DEFAULT_CHARACTER_SET;
  560. $this->m_sDBCollation = DEFAULT_COLLATION;
  561. $this->m_bLogGlobal = DEFAULT_LOG_GLOBAL;
  562. $this->m_bLogNotification = DEFAULT_LOG_NOTIFICATION;
  563. $this->m_bLogIssue = DEFAULT_LOG_ISSUE;
  564. $this->m_bLogWebService = DEFAULT_LOG_WEB_SERVICE;
  565. $this->m_bLogKPIDuration = DEFAULT_LOG_KPI_DURATION;
  566. $this->m_bLogKPIDuration = DEFAULT_LOG_KPI_DURATION;
  567. $this->m_iMinDisplayLimit = DEFAULT_MIN_DISPLAY_LIMIT;
  568. $this->m_iMaxDisplayLimit = DEFAULT_MAX_DISPLAY_LIMIT;
  569. $this->m_iStandardReloadInterval = DEFAULT_STANDARD_RELOAD_INTERVAL;
  570. $this->m_iFastReloadInterval = DEFAULT_FAST_RELOAD_INTERVAL;
  571. $this->m_bSecureConnectionRequired = DEFAULT_SECURE_CONNECTION_REQUIRED;
  572. $this->m_sDefaultLanguage = 'EN US';
  573. $this->m_sAllowedLoginTypes = DEFAULT_ALLOWED_LOGIN_TYPES;
  574. $this->m_sExtAuthVariable = DEFAULT_EXT_AUTH_VARIABLE;
  575. $this->m_sEncryptionKey = DEFAULT_ENCRYPTION_KEY;
  576. $this->m_aCharsets = array();
  577. $this->m_aModuleSettings = array();
  578. if ($bLoadConfig)
  579. {
  580. $this->Load($sConfigFile);
  581. $this->Verify();
  582. }
  583. // Application root url: set a default value, then normalize it
  584. $sAppRootUrl = trim($this->Get('app_root_url'));
  585. if (strlen($sAppRootUrl) == 0)
  586. {
  587. $sAppRootUrl = utils::GetDefaultUrlAppRoot();
  588. }
  589. if (substr($sAppRootUrl, -1, 1) != '/')
  590. {
  591. $sAppRootUrl .= '/';
  592. }
  593. $this->Set('app_root_url', $sAppRootUrl);
  594. }
  595. protected function CheckFile($sPurpose, $sFileName)
  596. {
  597. if (!file_exists($sFileName))
  598. {
  599. throw new ConfigException("Could not find $sPurpose file", array('file' => $sFileName));
  600. }
  601. if (!is_readable($sFileName))
  602. {
  603. 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));
  604. }
  605. }
  606. protected function Load($sConfigFile)
  607. {
  608. $this->CheckFile('configuration', $sConfigFile);
  609. $sConfigCode = trim(file_get_contents($sConfigFile));
  610. // This does not work on several lines
  611. // preg_match('/^<\\?php(.*)\\?'.'>$/', $sConfigCode, $aMatches)...
  612. // So, I've implemented a solution suggested in the PHP doc (search for phpWrapper)
  613. try
  614. {
  615. ob_start();
  616. eval('?'.'>'.trim($sConfigCode));
  617. $sNoise = trim(ob_get_contents());
  618. ob_end_clean();
  619. }
  620. catch (Exception $e)
  621. {
  622. // well, never reach in case of parsing error :-(
  623. // will be improved in PHP 6 ?
  624. throw new ConfigException('Error in configuration file', array('file' => $sConfigFile, 'error' => $e->getMessage()));
  625. }
  626. if (strlen($sNoise) > 0)
  627. {
  628. // Note: sNoise is an html output, but so far it was ok for me (e.g. showing the entire call stack)
  629. throw new ConfigException('Syntax error in configuration file', array('file' => $sConfigFile, 'error' => '<tt>'.htmlentities($sNoise, ENT_QUOTES, 'UTF-8').'</tt>'));
  630. }
  631. if (!isset($MySettings) || !is_array($MySettings))
  632. {
  633. throw new ConfigException('Missing array in configuration file', array('file' => $sConfigFile, 'expected' => '$MySettings'));
  634. }
  635. if (!isset($MyModules) || !is_array($MyModules))
  636. {
  637. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules'));
  638. }
  639. if (!array_key_exists('application', $MyModules))
  640. {
  641. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'application\']'));
  642. }
  643. if (!array_key_exists('business', $MyModules))
  644. {
  645. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'business\']'));
  646. }
  647. if (!array_key_exists('addons', $MyModules))
  648. {
  649. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'addons\']'));
  650. }
  651. if (!array_key_exists('user rights', $MyModules['addons']))
  652. {
  653. // Add one, by default
  654. $MyModules['addons']['user rights'] = '/addons/userrights/userrightsnull.class.inc.php';
  655. }
  656. if (!array_key_exists('dictionaries', $MyModules))
  657. {
  658. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'dictionaries\']'));
  659. }
  660. $this->m_aAppModules = $MyModules['application'];
  661. $this->m_aDataModels = $MyModules['business'];
  662. if (isset($MyModules['webservices']))
  663. {
  664. $this->m_aWebServiceCategories = $MyModules['webservices'];
  665. }
  666. $this->m_aAddons = $MyModules['addons'];
  667. $this->m_aDictionaries = $MyModules['dictionaries'];
  668. foreach($MySettings as $sPropCode => $rawvalue)
  669. {
  670. if ($this->IsProperty($sPropCode))
  671. {
  672. $value = trim($rawvalue);
  673. $this->Set($sPropCode, $value, $sConfigFile);
  674. }
  675. }
  676. $this->m_sDBHost = trim($MySettings['db_host']);
  677. $this->m_sDBUser = trim($MySettings['db_user']);
  678. $this->m_sDBPwd = trim($MySettings['db_pwd']);
  679. $this->m_sDBName = trim($MySettings['db_name']);
  680. $this->m_sDBSubname = trim($MySettings['db_subname']);
  681. $this->m_sDBCharacterSet = isset($MySettings['db_character_set']) ? trim($MySettings['db_character_set']) : DEFAULT_CHARACTER_SET;
  682. $this->m_sDBCollation = isset($MySettings['db_collation']) ? trim($MySettings['db_collation']) : DEFAULT_COLLATION;
  683. $this->m_bLogGlobal = isset($MySettings['log_global']) ? (bool) trim($MySettings['log_global']) : DEFAULT_LOG_GLOBAL;
  684. $this->m_bLogNotification = isset($MySettings['log_notification']) ? (bool) trim($MySettings['log_notification']) : DEFAULT_LOG_NOTIFICATION;
  685. $this->m_bLogIssue = isset($MySettings['log_issue']) ? (bool) trim($MySettings['log_issue']) : DEFAULT_LOG_ISSUE;
  686. $this->m_bLogWebService = isset($MySettings['log_web_service']) ? (bool) trim($MySettings['log_web_service']) : DEFAULT_LOG_WEB_SERVICE;
  687. $this->m_bLogKPIDuration = isset($MySettings['log_kpi_duration']) ? (bool) trim($MySettings['log_kpi_duration']) : DEFAULT_LOG_KPI_DURATION;
  688. $this->m_bLogKPIMemory = isset($MySettings['log_kpi_memory']) ? (bool) trim($MySettings['log_kpi_memory']) : DEFAULT_LOG_KPI_MEMORY;
  689. $this->m_bDebugQueries = isset($MySettings['debug_queries']) ? (bool) trim($MySettings['debug_queries']) : DEFAULT_DEBUG_QUERIES;
  690. $this->m_bQueryCacheEnabled = isset($MySettings['query_cache_enabled']) ? (bool) trim($MySettings['query_cache_enabled']) : DEFAULT_QUERY_CACHE_ENABLED;
  691. $this->m_iMinDisplayLimit = isset($MySettings['min_display_limit']) ? trim($MySettings['min_display_limit']) : DEFAULT_MIN_DISPLAY_LIMIT;
  692. $this->m_iMaxDisplayLimit = isset($MySettings['max_display_limit']) ? trim($MySettings['max_display_limit']) : DEFAULT_MAX_DISPLAY_LIMIT;
  693. $this->m_iStandardReloadInterval = isset($MySettings['standard_reload_interval']) ? trim($MySettings['standard_reload_interval']) : DEFAULT_STANDARD_RELOAD_INTERVAL;
  694. $this->m_iFastReloadInterval = isset($MySettings['fast_reload_interval']) ? trim($MySettings['fast_reload_interval']) : DEFAULT_FAST_RELOAD_INTERVAL;
  695. $this->m_bSecureConnectionRequired = isset($MySettings['secure_connection_required']) ? (bool) trim($MySettings['secure_connection_required']) : DEFAULT_SECURE_CONNECTION_REQUIRED;
  696. $this->m_aModuleSettings = isset($MyModuleSettings) ? $MyModuleSettings : array();
  697. $this->m_sDefaultLanguage = isset($MySettings['default_language']) ? trim($MySettings['default_language']) : 'EN US';
  698. $this->m_sAllowedLoginTypes = isset($MySettings['allowed_login_types']) ? trim($MySettings['allowed_login_types']) : DEFAULT_ALLOWED_LOGIN_TYPES;
  699. $this->m_sExtAuthVariable = isset($MySettings['ext_auth_variable']) ? trim($MySettings['ext_auth_variable']) : DEFAULT_EXT_AUTH_VARIABLE;
  700. $this->m_sEncryptionKey = isset($MySettings['encryption_key']) ? trim($MySettings['encryption_key']) : DEFAULT_ENCRYPTION_KEY;
  701. $this->m_aCharsets = isset($MySettings['csv_import_charsets']) ? $MySettings['csv_import_charsets'] : array();
  702. }
  703. protected function Verify()
  704. {
  705. // Files are verified later on, just before using them -see MetaModel::Plugin()
  706. // (we have their final path at that point)
  707. }
  708. public function GetModuleSetting($sModule, $sProperty, $defaultvalue = null)
  709. {
  710. if (isset($this->m_aModuleSettings[$sModule][$sProperty]))
  711. {
  712. return $this->m_aModuleSettings[$sModule][$sProperty];
  713. }
  714. return $defaultvalue;
  715. }
  716. public function SetModuleSetting($sModule, $sProperty, $value)
  717. {
  718. $this->m_aModuleSettings[$sModule][$sProperty] = $value;
  719. }
  720. public function GetAppModules()
  721. {
  722. return $this->m_aAppModules;
  723. }
  724. public function SetAppModules($aAppModules)
  725. {
  726. $this->m_aAppModules = $aAppModules;
  727. }
  728. public function GetDataModels()
  729. {
  730. return $this->m_aDataModels;
  731. }
  732. public function SetDataModels($aDataModels)
  733. {
  734. $this->m_aDataModels = $aDataModels;
  735. }
  736. public function GetWebServiceCategories()
  737. {
  738. return $this->m_aWebServiceCategories;
  739. }
  740. public function SetWebServiceCategories($aWebServiceCategories)
  741. {
  742. $this->m_aWebServiceCategories = $aWebServiceCategories;
  743. }
  744. public function GetAddons()
  745. {
  746. return $this->m_aAddons;
  747. }
  748. public function SetAddons($aAddons)
  749. {
  750. $this->m_aAddons = $aAddons;
  751. }
  752. public function GetDictionaries()
  753. {
  754. return $this->m_aDictionaries;
  755. }
  756. public function SetDictionaries($aDictionaries)
  757. {
  758. $this->m_aDictionaries = $aDictionaries;
  759. }
  760. public function GetDBHost()
  761. {
  762. return $this->m_sDBHost;
  763. }
  764. public function GetDBName()
  765. {
  766. return $this->m_sDBName;
  767. }
  768. public function GetDBSubname()
  769. {
  770. return $this->m_sDBSubname;
  771. }
  772. public function GetDBCharacterSet()
  773. {
  774. return $this->m_sDBCharacterSet;
  775. }
  776. public function GetDBCollation()
  777. {
  778. return $this->m_sDBCollation;
  779. }
  780. public function GetDBUser()
  781. {
  782. return $this->m_sDBUser;
  783. }
  784. public function GetDBPwd()
  785. {
  786. return $this->m_sDBPwd;
  787. }
  788. public function GetLogGlobal()
  789. {
  790. return $this->m_bLogGlobal;
  791. }
  792. public function GetLogNotification()
  793. {
  794. return $this->m_bLogNotification;
  795. }
  796. public function GetLogIssue()
  797. {
  798. return $this->m_bLogIssue;
  799. }
  800. public function GetLogWebService()
  801. {
  802. return $this->m_bLogWebService;
  803. }
  804. public function GetLogKPIDuration()
  805. {
  806. return $this->m_bLogKPIDuration;
  807. }
  808. public function GetLogKPIMemory()
  809. {
  810. return $this->m_bLogKPIMemory;
  811. }
  812. public function GetDebugQueries()
  813. {
  814. return $this->m_bDebugQueries;
  815. }
  816. public function GetQueryCacheEnabled()
  817. {
  818. return $this->m_bQueryCacheEnabled;
  819. }
  820. public function GetMinDisplayLimit()
  821. {
  822. return $this->m_iMinDisplayLimit;
  823. }
  824. public function GetMaxDisplayLimit()
  825. {
  826. return $this->m_iMaxDisplayLimit;
  827. }
  828. public function GetStandardReloadInterval()
  829. {
  830. return $this->m_iStandardReloadInterval;
  831. }
  832. public function GetFastReloadInterval()
  833. {
  834. return $this->m_iFastReloadInterval;
  835. }
  836. public function GetSecureConnectionRequired()
  837. {
  838. return $this->m_bSecureConnectionRequired;
  839. }
  840. public function GetDefaultLanguage()
  841. {
  842. return $this->m_sDefaultLanguage;
  843. }
  844. public function GetEncryptionKey()
  845. {
  846. return $this->m_sEncryptionKey;
  847. }
  848. public function GetAllowedLoginTypes()
  849. {
  850. return explode('|', $this->m_sAllowedLoginTypes);
  851. }
  852. public function GetExternalAuthenticationVariable()
  853. {
  854. return $this->m_sExtAuthVariable;
  855. }
  856. public function GetCSVImportCharsets()
  857. {
  858. return $this->m_aCharsets;
  859. }
  860. public function SetDBHost($sDBHost)
  861. {
  862. $this->m_sDBHost = $sDBHost;
  863. }
  864. public function SetDBName($sDBName)
  865. {
  866. $this->m_sDBName = $sDBName;
  867. }
  868. public function SetDBSubname($sDBSubName)
  869. {
  870. $this->m_sDBSubname = $sDBSubName;
  871. }
  872. public function SetDBCharacterSet($sDBCharacterSet)
  873. {
  874. $this->m_sDBCharacterSet = $sDBCharacterSet;
  875. }
  876. public function SetDBCollation($sDBCollation)
  877. {
  878. $this->m_sDBCollation = $sDBCollation;
  879. }
  880. public function SetDBUser($sUser)
  881. {
  882. $this->m_sDBUser = $sUser;
  883. }
  884. public function SetDBPwd($sPwd)
  885. {
  886. $this->m_sDBPwd = $sPwd;
  887. }
  888. public function SetLogGlobal($iLogGlobal)
  889. {
  890. $this->m_iLogGlobal = $iLogGlobal;
  891. }
  892. public function SetLogNotification($iLogNotification)
  893. {
  894. $this->m_iLogNotification = $iLogNotification;
  895. }
  896. public function SetLogIssue($iLogIssue)
  897. {
  898. $this->m_iLogIssue = $iLogIssue;
  899. }
  900. public function SetLogWebService($iLogWebService)
  901. {
  902. $this->m_iLogWebService = $iLogWebService;
  903. }
  904. public function SetMinDisplayLimit($iMinDisplayLimit)
  905. {
  906. $this->m_iMinDisplayLimit = $iMinDisplayLimit;
  907. }
  908. public function SetMaxDisplayLimit($iMaxDisplayLimit)
  909. {
  910. $this->m_iMaxDisplayLimit = $iMaxDisplayLimit;
  911. }
  912. public function SetStandardReloadInterval($iStandardReloadInterval)
  913. {
  914. $this->m_iStandardReloadInterval = $iStandardReloadInterval;
  915. }
  916. public function SetFastReloadInterval($iFastReloadInterval)
  917. {
  918. $this->m_iFastReloadInterval = $iFastReloadInterval;
  919. }
  920. public function SetSecureConnectionRequired($bSecureConnectionRequired)
  921. {
  922. $this->m_bSecureConnectionRequired = $bSecureConnectionRequired;
  923. }
  924. public function SetDefaultLanguage($sLanguageCode)
  925. {
  926. $this->m_sDefaultLanguage = $sLanguageCode;
  927. }
  928. public function SetAllowedLoginTypes($aAllowedLoginTypes)
  929. {
  930. $this->m_sAllowedLoginTypes = implode('|', $aAllowedLoginTypes);
  931. }
  932. public function SetExternalAuthenticationVariable($sExtAuthVariable)
  933. {
  934. $this->m_sExtAuthVariable = $sExtAuthVariable;
  935. }
  936. public function SetEncryptionKey($sKey)
  937. {
  938. $this->m_sEncryptionKey = $sKey;
  939. }
  940. public function SetCSVImportCharsets($aCharsets)
  941. {
  942. $this->m_aCharsets = $aCharsets;
  943. }
  944. public function AddCSVImportCharset($sIconvCode, $sDisplayName)
  945. {
  946. $this->m_aCharsets[$sIconvCode] = $sDisplayName;
  947. }
  948. public function FileIsWritable()
  949. {
  950. return is_writable($this->m_sFile);
  951. }
  952. public function GetLoadedFile()
  953. {
  954. return $this->m_sFile;
  955. }
  956. /**
  957. * Render the configuration as an associative array
  958. * @return boolean True otherwise throws an Exception
  959. */
  960. public function ToArray()
  961. {
  962. $aSettings = array();
  963. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  964. {
  965. $aSettings[$sPropCode] = $aSettingInfo['value'];
  966. }
  967. $aSettings['db_host'] = $this->m_sDBHost;
  968. $aSettings['db_user'] = $this->m_sDBUser;
  969. $aSettings['db_pwd'] = $this->m_sDBPwd;
  970. $aSettings['db_name'] = $this->m_sDBName;
  971. $aSettings['db_subname'] = $this->m_sDBSubname;
  972. $aSettings['db_character_set'] = $this->m_sDBCharacterSet;
  973. $aSettings['db_collation'] = $this->m_sDBCollation;
  974. $aSettings['log_global'] = $this->m_bLogGlobal;
  975. $aSettings['log_notification'] = $this->m_bLogNotification;
  976. $aSettings['log_issue'] = $this->m_bLogIssue;
  977. $aSettings['log_web_service'] = $this->m_bLogWebService;
  978. $aSettings['min_display_limit'] = $this->m_iMinDisplayLimit;
  979. $aSettings['max_display_limit'] = $this->m_iMaxDisplayLimit;
  980. $aSettings['standard_reload_interval'] = $this->m_iStandardReloadInterval;
  981. $aSettings['fast_reload_interval'] = $this->m_iFastReloadInterval;
  982. $aSettings['secure_connection_required'] = $this->m_bSecureConnectionRequired;
  983. $aSettings['default_language'] = $this->m_sDefaultLanguage;
  984. $aSettings['allowed_login_types'] = $this->m_sAllowedLoginTypes;
  985. $aSettings['encryption_key'] = $this->m_sEncryptionKey;
  986. $aSettings['csv_import_charsets'] = $this->m_aCharsets;
  987. foreach ($this->m_aModuleSettings as $sModule => $aProperties)
  988. {
  989. foreach ($aProperties as $sProperty => $value)
  990. {
  991. $aSettings['module_settings'][$sModule][$sProperty] = $value;
  992. }
  993. }
  994. foreach($this->m_aAppModules as $sFile)
  995. {
  996. $aSettings['application_list'][] = $sFile;
  997. }
  998. foreach($this->m_aDataModels as $sFile)
  999. {
  1000. $aSettings['datamodel_list'][] = $sFile;
  1001. }
  1002. foreach($this->m_aWebServiceCategories as $sFile)
  1003. {
  1004. $aSettings['webservice_list'][] = $sFile;
  1005. }
  1006. foreach($this->m_aAddons as $sKey => $sFile)
  1007. {
  1008. $aSettings['addon_list'][] = $sFile;
  1009. }
  1010. foreach($this->m_aDictionaries as $sFile)
  1011. {
  1012. $aSettings['dictionary_list'][] = $sFile;
  1013. }
  1014. return $aSettings;
  1015. }
  1016. /**
  1017. * Write the configuration to a file (php format) that can be reloaded later
  1018. * By default write to the same file that was specified when constructing the object
  1019. * @param $sFileName string Name of the file to write to (emtpy to write to the same file)
  1020. * @return boolean True otherwise throws an Exception
  1021. */
  1022. public function WriteToFile($sFileName = '')
  1023. {
  1024. if (empty($sFileName))
  1025. {
  1026. $sFileName = $this->m_sFile;
  1027. }
  1028. $hFile = @fopen($sFileName, 'w');
  1029. if ($hFile !== false)
  1030. {
  1031. fwrite($hFile, "<?php\n");
  1032. fwrite($hFile, "\n/**\n");
  1033. fwrite($hFile, " *\n");
  1034. fwrite($hFile, " * phpMyORM configuration file, generated by the iTop configuration wizard\n");
  1035. fwrite($hFile, " *\n");
  1036. fwrite($hFile, " * The file is used in MetaModel::LoadConfig() which does all the necessary initialization job\n");
  1037. fwrite($hFile, " *\n");
  1038. fwrite($hFile, " */\n");
  1039. fwrite($hFile, "\n");
  1040. fwrite($hFile, "\$MySettings = array(\n");
  1041. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  1042. {
  1043. if ($aSettingInfo['show_in_conf_sample'])
  1044. {
  1045. $sType = $this->m_aSettings[$sPropCode]['type'];
  1046. switch($sType)
  1047. {
  1048. case 'bool':
  1049. $sSeenAs = $aSettingInfo['value'] ? '1' : '0';
  1050. break;
  1051. default:
  1052. $sSeenAs = "'".addslashes($aSettingInfo['value'])."'";
  1053. }
  1054. fwrite($hFile, "\t'$sPropCode' => $sSeenAs,\n");
  1055. }
  1056. }
  1057. fwrite($hFile, "\t'db_host' => '{$this->m_sDBHost}',\n");
  1058. fwrite($hFile, "\t'db_user' => '{$this->m_sDBUser}',\n");
  1059. fwrite($hFile, "\t'db_pwd' => '".addslashes($this->m_sDBPwd)."',\n");
  1060. fwrite($hFile, "\t'db_name' => '{$this->m_sDBName}',\n");
  1061. fwrite($hFile, "\t'db_subname' => '{$this->m_sDBSubname}',\n");
  1062. fwrite($hFile, "\t'db_character_set' => '{$this->m_sDBCharacterSet}',\n");
  1063. fwrite($hFile, "\t'db_collation' => '{$this->m_sDBCollation}',\n");
  1064. fwrite($hFile, "\n");
  1065. fwrite($hFile, "\t'log_global' => {$this->m_bLogGlobal},\n");
  1066. fwrite($hFile, "\t'log_notification' => {$this->m_bLogNotification},\n");
  1067. fwrite($hFile, "\t'log_issue' => {$this->m_bLogIssue},\n");
  1068. fwrite($hFile, "\t'log_web_service' => {$this->m_bLogWebService},\n");
  1069. fwrite($hFile, "\t'min_display_limit' => {$this->m_iMinDisplayLimit},\n");
  1070. fwrite($hFile, "\t'max_display_limit' => {$this->m_iMaxDisplayLimit},\n");
  1071. fwrite($hFile, "\t'standard_reload_interval' => {$this->m_iStandardReloadInterval},\n");
  1072. fwrite($hFile, "\t'fast_reload_interval' => {$this->m_iFastReloadInterval},\n");
  1073. fwrite($hFile, "\t'secure_connection_required' => ".($this->m_bSecureConnectionRequired ? 'true' : 'false').",\n");
  1074. fwrite($hFile, "\t'default_language' => '{$this->m_sDefaultLanguage}',\n");
  1075. fwrite($hFile, "\t'allowed_login_types' => '{$this->m_sAllowedLoginTypes}',\n");
  1076. fwrite($hFile, "\t'encryption_key' => '{$this->m_sEncryptionKey}',\n");
  1077. $sExport = var_export($this->m_aCharsets, true);
  1078. fwrite($hFile, "\t'csv_import_charsets' => $sExport,\n");
  1079. fwrite($hFile, ");\n");
  1080. fwrite($hFile, "\n");
  1081. fwrite($hFile, "\$MyModuleSettings = array(\n");
  1082. foreach ($this->m_aModuleSettings as $sModule => $aProperties)
  1083. {
  1084. fwrite($hFile, "\t'$sModule' => array (\n");
  1085. foreach ($aProperties as $sProperty => $value)
  1086. {
  1087. $sExport = var_export($value, true);
  1088. fwrite($hFile, "\t\t'$sProperty' => $sExport,\n");
  1089. }
  1090. fwrite($hFile, "\t),\n");
  1091. }
  1092. fwrite($hFile, ");\n");
  1093. fwrite($hFile, "\n/**\n");
  1094. fwrite($hFile, " *\n");
  1095. fwrite($hFile, " * Data model modules to be loaded. Names are specified as relative paths\n");
  1096. fwrite($hFile, " *\n");
  1097. fwrite($hFile, " */\n");
  1098. fwrite($hFile, "\$MyModules = array(\n");
  1099. fwrite($hFile, "\t'application' => array (\n");
  1100. foreach($this->m_aAppModules as $sFile)
  1101. {
  1102. fwrite($hFile, "\t\t'$sFile',\n");
  1103. }
  1104. fwrite($hFile, "\t),\n");
  1105. fwrite($hFile, "\t'business' => array (\n");
  1106. foreach($this->m_aDataModels as $sFile)
  1107. {
  1108. fwrite($hFile, "\t\t'$sFile',\n");
  1109. }
  1110. fwrite($hFile, "\t),\n");
  1111. fwrite($hFile, "\t'webservices' => array (\n");
  1112. foreach($this->m_aWebServiceCategories as $sFile)
  1113. {
  1114. fwrite($hFile, "\t\t'$sFile',\n");
  1115. }
  1116. fwrite($hFile, "\t),\n");
  1117. fwrite($hFile, "\t'addons' => array (\n");
  1118. foreach($this->m_aAddons as $sKey => $sFile)
  1119. {
  1120. fwrite($hFile, "\t\t'$sKey' => '$sFile',\n");
  1121. }
  1122. fwrite($hFile, "\t),\n");
  1123. fwrite($hFile, "\t'dictionaries' => array (\n");
  1124. foreach($this->m_aDictionaries as $sFile)
  1125. {
  1126. fwrite($hFile, "\t\t'$sFile',\n");
  1127. }
  1128. fwrite($hFile, "\t),\n");
  1129. fwrite($hFile, ");\n");
  1130. fwrite($hFile, '?'.'>'); // Avoid perturbing the syntax highlighting !
  1131. return fclose($hFile);
  1132. }
  1133. else
  1134. {
  1135. throw new ConfigException("Could not write to configuration file", array('file' => $sFileName));
  1136. }
  1137. }
  1138. }
  1139. ?>