config.class.inc.php 43 KB

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