config.class.inc.php 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. define('ITOP_APPLICATION', 'iTop');
  19. define('ITOP_VERSION', '$ITOP_VERSION$');
  20. define('ITOP_REVISION', '$WCREV$');
  21. define('ITOP_BUILD_DATE', '$WCNOW$');
  22. define('ACCESS_USER_WRITE', 1);
  23. define('ACCESS_ADMIN_WRITE', 2);
  24. define('ACCESS_FULL', ACCESS_USER_WRITE | ACCESS_ADMIN_WRITE);
  25. define('ACCESS_READONLY', 0);
  26. /**
  27. * Configuration read/write
  28. *
  29. * @copyright Copyright (C) 2010-2012 Combodo SARL
  30. * @license http://opensource.org/licenses/AGPL-3.0
  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_env_label' => array(
  74. 'type' => 'string',
  75. 'description' => 'Label displayed to describe the current application environnment, defaults to the environment name (e.g. "production")',
  76. 'default' => '',
  77. 'value' => '',
  78. 'source_of_value' => '',
  79. 'show_in_conf_sample' => true,
  80. ),
  81. 'app_root_url' => array(
  82. 'type' => 'string',
  83. '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)',
  84. 'default' => '',
  85. 'value' => '',
  86. 'source_of_value' => '',
  87. 'show_in_conf_sample' => true,
  88. ),
  89. 'app_icon_url' => array(
  90. 'type' => 'string',
  91. 'description' => 'Hyperlink to redirect the user when clicking on the application icon (in the main window, or login/logoff pages)',
  92. 'default' => 'http://www.combodo.com/itop',
  93. 'value' => '',
  94. 'source_of_value' => '',
  95. 'show_in_conf_sample' => false,
  96. ),
  97. 'skip_check_to_write' => array(
  98. 'type' => 'bool',
  99. 'description' => 'Disable data format and integrity checks to boost up data load (insert or update)',
  100. 'default' => false,
  101. 'value' => false,
  102. 'source_of_value' => '',
  103. 'show_in_conf_sample' => false,
  104. ),
  105. 'skip_check_ext_keys' => array(
  106. 'type' => 'bool',
  107. 'description' => 'Disable external key check when checking the value of attributes',
  108. 'default' => false,
  109. 'value' => false,
  110. 'source_of_value' => '',
  111. 'show_in_conf_sample' => false,
  112. ),
  113. 'skip_strong_security' => array(
  114. 'type' => 'bool',
  115. 'description' => 'Disable strong security - TEMPORY: this flag should be removed when we are more confident in the recent change in security',
  116. 'default' => true,
  117. 'value' => true,
  118. 'source_of_value' => '',
  119. 'show_in_conf_sample' => false,
  120. ),
  121. 'graphviz_path' => array(
  122. 'type' => 'string',
  123. 'description' => 'Path to the Graphviz "dot" executable for graphing objects lifecycle',
  124. 'default' => '/usr/bin/dot',
  125. 'value' => '',
  126. 'source_of_value' => '',
  127. 'show_in_conf_sample' => false,
  128. ),
  129. 'php_path' => array(
  130. 'type' => 'string',
  131. 'description' => 'Path to the php executable in CLI mode',
  132. 'default' => 'php',
  133. 'value' => 'php',
  134. 'source_of_value' => '',
  135. 'show_in_conf_sample' => true,
  136. ),
  137. 'session_name' => array(
  138. 'type' => 'string',
  139. 'description' => 'The name of the cookie used to store the PHP session id',
  140. 'default' => 'iTop',
  141. 'value' => '',
  142. 'source_of_value' => '',
  143. 'show_in_conf_sample' => true,
  144. ),
  145. 'max_combo_length' => array(
  146. 'type' => 'integer',
  147. 'description' => 'The maximum number of elements in a drop-down list. If more then an autocomplete will be used',
  148. 'default' => 50,
  149. 'value' => 50,
  150. 'source_of_value' => '',
  151. 'show_in_conf_sample' => false,
  152. ),
  153. 'min_autocomplete_chars' => array(
  154. 'type' => 'integer',
  155. 'description' => 'The minimum number of characters to type in order to trigger the "autocomplete" behavior',
  156. 'default' => 3,
  157. 'value' => 3,
  158. 'source_of_value' => '',
  159. 'show_in_conf_sample' => false,
  160. ),
  161. 'allow_target_creation' => array(
  162. 'type' => 'bool',
  163. 'description' => 'Displays the + button on external keys to create target objects',
  164. 'default' => true,
  165. 'value' => true,
  166. 'source_of_value' => '',
  167. 'show_in_conf_sample' => false,
  168. ),
  169. // Levels that trigger a confirmation in the CSV import/synchro wizard
  170. 'csv_import_min_object_confirmation' => array(
  171. 'type' => 'integer',
  172. 'description' => 'Minimum number of objects to check for the confirmation percentages',
  173. 'default' => 3,
  174. 'value' => 3,
  175. 'source_of_value' => '',
  176. 'show_in_conf_sample' => false,
  177. ),
  178. 'csv_import_errors_percentage' => array(
  179. 'type' => 'integer',
  180. 'description' => 'Percentage of errors 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. 'csv_import_modifications_percentage' => array(
  187. 'type' => 'integer',
  188. 'description' => 'Percentage of modifications that trigger a confirmation in the CSV import',
  189. 'default' => 50,
  190. 'value' => 50,
  191. 'source_of_value' => '',
  192. 'show_in_conf_sample' => false,
  193. ),
  194. 'csv_import_creations_percentage' => array(
  195. 'type' => 'integer',
  196. 'description' => 'Percentage of creations that trigger a confirmation in the CSV import',
  197. 'default' => 50,
  198. 'value' => 50,
  199. 'source_of_value' => '',
  200. 'show_in_conf_sample' => false,
  201. ),
  202. 'csv_import_history_display' => array(
  203. 'type' => 'bool',
  204. 'description' => 'Display the history tab in the import wizard',
  205. 'default' => true,
  206. 'value' => true,
  207. 'source_of_value' => '',
  208. 'show_in_conf_sample' => true,
  209. ),
  210. 'access_mode' => array(
  211. 'type' => 'integer',
  212. 'description' => 'Combination of flags (ACCESS_USER_WRITE | ACCESS_ADMIN_WRITE, or ACCESS_FULL)',
  213. 'default' => ACCESS_FULL,
  214. 'value' => ACCESS_FULL,
  215. 'source_of_value' => '',
  216. 'show_in_conf_sample' => true,
  217. ),
  218. 'access_message' => array(
  219. 'type' => 'string',
  220. 'description' => 'Message displayed to the users when there is any access restriction',
  221. 'default' => 'iTop is temporarily frozen, please wait... (the admin team)',
  222. 'value' => '',
  223. 'source_of_value' => '',
  224. 'show_in_conf_sample' => true,
  225. ),
  226. 'online_help' => array(
  227. 'type' => 'string',
  228. 'description' => 'Hyperlink to the online-help web page',
  229. 'default' => 'http://www.combodo.com/itop-help',
  230. 'value' => '',
  231. 'source_of_value' => '',
  232. 'show_in_conf_sample' => true,
  233. ),
  234. 'log_usage' => array(
  235. 'type' => 'bool',
  236. 'description' => 'Log the usage of the application (i.e. the date/time and the user name of each login)',
  237. 'default' => false,
  238. 'value' => false,
  239. 'source_of_value' => '',
  240. 'show_in_conf_sample' => false,
  241. ),
  242. 'synchro_trace' => array(
  243. 'type' => 'string',
  244. 'description' => 'Synchronization details: none, display, save (includes \'display\')',
  245. 'default' => 'none',
  246. 'value' => 'none',
  247. 'source_of_value' => '',
  248. 'show_in_conf_sample' => true,
  249. ),
  250. 'link_set_item_separator' => array(
  251. 'type' => 'string',
  252. 'description' => 'Link set from string: line separator',
  253. 'default' => '|',
  254. 'value' => '|',
  255. 'source_of_value' => '',
  256. 'show_in_conf_sample' => true,
  257. ),
  258. 'link_set_attribute_separator' => array(
  259. 'type' => 'string',
  260. 'description' => 'Link set from string: attribute separator',
  261. 'default' => ';',
  262. 'value' => ';',
  263. 'source_of_value' => '',
  264. 'show_in_conf_sample' => true,
  265. ),
  266. 'link_set_value_separator' => array(
  267. 'type' => 'string',
  268. 'description' => 'Link set from string: value separator (between the attcode and the value itself',
  269. 'default' => ':',
  270. 'value' => ':',
  271. 'source_of_value' => '',
  272. 'show_in_conf_sample' => true,
  273. ),
  274. 'link_set_attribute_qualifier' => array(
  275. 'type' => 'string',
  276. 'description' => 'Link set from string: attribute qualifier (encloses both the attcode and the value)',
  277. 'default' => "'",
  278. 'value' => "'",
  279. 'source_of_value' => '',
  280. 'show_in_conf_sample' => true,
  281. ),
  282. 'cron_max_execution_time' => array(
  283. 'type' => 'integer',
  284. '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',
  285. 'default' => 600,
  286. 'value' => 600,
  287. 'source_of_value' => '',
  288. 'show_in_conf_sample' => true,
  289. ),
  290. 'cron_sleep' => array(
  291. 'type' => 'integer',
  292. 'description' => 'Duration (seconds) before cron.php checks again if something must be done',
  293. 'default' => 2,
  294. 'value' => 2,
  295. 'source_of_value' => '',
  296. 'show_in_conf_sample' => false,
  297. ),
  298. 'email_asynchronous' => array(
  299. 'type' => 'bool',
  300. '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',
  301. 'default' => false,
  302. 'value' => false,
  303. 'source_of_value' => '',
  304. 'show_in_conf_sample' => true,
  305. ),
  306. 'email_transport' => array(
  307. 'type' => 'string',
  308. 'description' => 'Mean to send emails: PHPMail (uses the function mail()) or SMTP (implements the client protocole)',
  309. 'default' => "PHPMail",
  310. 'value' => "PHPMail",
  311. 'source_of_value' => '',
  312. 'show_in_conf_sample' => true,
  313. ),
  314. 'email_transport_smtp.host' => array(
  315. 'type' => 'string',
  316. 'description' => 'host name or IP address (optional)',
  317. 'default' => "localhost",
  318. 'value' => "localhost",
  319. 'source_of_value' => '',
  320. 'show_in_conf_sample' => false,
  321. ),
  322. 'email_transport_smtp.port' => array(
  323. 'type' => 'integer',
  324. 'description' => 'port number (optional)',
  325. 'default' => 25,
  326. 'value' => 25,
  327. 'source_of_value' => '',
  328. 'show_in_conf_sample' => false,
  329. ),
  330. 'email_transport_smtp.encryption' => array(
  331. 'type' => 'string',
  332. 'description' => 'tls or ssl (optional)',
  333. 'default' => "",
  334. 'value' => "",
  335. 'source_of_value' => '',
  336. 'show_in_conf_sample' => false,
  337. ),
  338. 'email_transport_smtp.username' => array(
  339. 'type' => 'string',
  340. 'description' => 'Authentication user (optional)',
  341. 'default' => "",
  342. 'value' => "",
  343. 'source_of_value' => '',
  344. 'show_in_conf_sample' => false,
  345. ),
  346. 'email_transport_smtp.password' => array(
  347. 'type' => 'string',
  348. 'description' => 'Authentication password (optional)',
  349. 'default' => "",
  350. 'value' => "",
  351. 'source_of_value' => '',
  352. 'show_in_conf_sample' => false,
  353. ),
  354. 'apc_cache.enabled' => array(
  355. 'type' => 'bool',
  356. 'description' => 'If set, the APC cache is allowed (the PHP extension must also be active)',
  357. 'default' => true,
  358. 'value' => true,
  359. 'source_of_value' => '',
  360. 'show_in_conf_sample' => true,
  361. ),
  362. 'apc_cache.query_ttl' => array(
  363. 'type' => 'integer',
  364. 'description' => 'Time to live set in APC for the prepared queries (seconds - 0 means no timeout)',
  365. 'default' => 3600,
  366. 'value' => 3600,
  367. 'source_of_value' => '',
  368. 'show_in_conf_sample' => true,
  369. ),
  370. 'timezone' => array(
  371. 'type' => 'string',
  372. 'description' => 'Timezone (reference: http://php.net/manual/en/timezones.php). If empty, it will be left unchanged and MUST be explicitely configured in PHP',
  373. // examples... not used (nor 'description')
  374. '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'),
  375. 'default' => 'Europe/Paris',
  376. 'value' => 'Europe/Paris',
  377. 'source_of_value' => '',
  378. 'show_in_conf_sample' => true,
  379. ),
  380. 'cas_include_path' => array(
  381. 'type' => 'string',
  382. 'description' => 'The path where to find the phpCAS library',
  383. // examples... not used (nor 'description')
  384. 'default' => '/usr/share/php',
  385. 'value' => '/usr/share/php',
  386. 'source_of_value' => '',
  387. 'show_in_conf_sample' => true,
  388. ),
  389. 'cas_version' => array(
  390. 'type' => 'string',
  391. 'description' => 'The CAS protocol version to use: "1.0" (CAS v1), "2.0" (CAS v2) or "S1" (SAML V1) )',
  392. // examples... not used (nor 'description')
  393. 'default' => '2.0',
  394. 'value' => '',
  395. 'source_of_value' => '',
  396. 'show_in_conf_sample' => true,
  397. ),
  398. 'cas_host' => array(
  399. 'type' => 'string',
  400. 'description' => 'The name of the CAS host',
  401. // examples... not used (nor 'description')
  402. 'default' => '',
  403. 'value' => '',
  404. 'source_of_value' => '',
  405. 'show_in_conf_sample' => true,
  406. ),
  407. 'cas_port' => array(
  408. 'type' => 'integer',
  409. 'description' => 'The port used by the CAS server',
  410. // examples... not used (nor 'description')
  411. 'default' => 443,
  412. 'value' => 443,
  413. 'source_of_value' => '',
  414. 'show_in_conf_sample' => true,
  415. ),
  416. 'cas_context' => array(
  417. 'type' => 'string',
  418. 'description' => 'The CAS context',
  419. // examples... not used (nor 'description')
  420. 'default' => '',
  421. 'value' => '',
  422. 'source_of_value' => '',
  423. 'show_in_conf_sample' => true,
  424. ),
  425. 'cas_server_ca_cert_path' => array(
  426. 'type' => 'string',
  427. 'description' => 'The path where to find the certificate of the CA for validating the certificate of the CAS server',
  428. // examples... not used (nor 'description')
  429. 'default' => '',
  430. 'value' => '',
  431. 'source_of_value' => '',
  432. 'show_in_conf_sample' => true,
  433. ),
  434. 'cas_logout_redirect_service' => array(
  435. 'type' => 'string',
  436. 'description' => 'The redirect service (URL) to use when logging-out with CAS',
  437. // examples... not used (nor 'description')
  438. 'default' => '',
  439. 'value' => '',
  440. 'source_of_value' => '',
  441. 'show_in_conf_sample' => true,
  442. ),
  443. 'cas_memberof' => array(
  444. 'type' => 'string',
  445. 'description' => 'A semicolon separated list of group names that the user must be member of (works only with SAML - e.g. cas_version=> "S1")',
  446. // examples... not used (nor 'description')
  447. 'default' => '',
  448. 'value' => '',
  449. 'source_of_value' => '',
  450. 'show_in_conf_sample' => true,
  451. ),
  452. 'cas_user_synchro' => array(
  453. 'type' => 'bool',
  454. 'description' => 'Whether or not to synchronize users with CAS/LDAP',
  455. // examples... not used (nor 'description')
  456. 'default' => 0,
  457. 'value' => 0,
  458. 'source_of_value' => '',
  459. 'show_in_conf_sample' => true,
  460. ),
  461. 'cas_update_profiles' => array(
  462. 'type' => 'bool',
  463. 'description' => 'Whether or not to update the profiles of an existing user from the CAS information',
  464. // examples... not used (nor 'description')
  465. 'default' => 0,
  466. 'value' => 0,
  467. 'source_of_value' => '',
  468. 'show_in_conf_sample' => true,
  469. ),
  470. 'cas_profile_pattern' => array(
  471. 'type' => 'string',
  472. 'description' => 'A regular expression pattern to extract the name of the iTop profile from the name of an LDAP/CAS group',
  473. // examples... not used (nor 'description')
  474. 'default' => '/^cn=([^,]+),/',
  475. 'value' => '/^cn=([^,]+),/',
  476. 'source_of_value' => '',
  477. 'show_in_conf_sample' => true,
  478. ),
  479. 'cas_default_profiles' => array(
  480. 'type' => 'string',
  481. 'description' => 'A semi-colon separated list of iTop Profiles to use when creating a new user if no profile is retrieved from CAS',
  482. // examples... not used (nor 'description')
  483. 'default' => 'Portal user',
  484. 'value' => 'Portal user',
  485. 'source_of_value' => '',
  486. 'show_in_conf_sample' => true,
  487. ),
  488. 'cas_debug' => array(
  489. 'type' => 'bool',
  490. 'description' => 'Activate the CAS debug',
  491. // examples... not used (nor 'description')
  492. 'default' => false,
  493. 'value' => false,
  494. 'source_of_value' => '',
  495. 'show_in_conf_sample' => true,
  496. ),
  497. 'deadline_format' => array(
  498. 'type' => 'string',
  499. 'description' => 'The format used for displaying "deadline" attributes: any string with the following placeholders: $date$, $difference$',
  500. // examples... $date$ ($deadline$)
  501. 'default' => '$difference$',
  502. 'value' => '$difference$',
  503. 'source_of_value' => '',
  504. 'show_in_conf_sample' => true,
  505. ),
  506. 'buttons_position' => array(
  507. 'type' => 'string',
  508. 'description' => 'Position of the forms buttons: bottom | top | both',
  509. // examples... not used
  510. 'default' => 'both',
  511. 'value' => 'both',
  512. 'source_of_value' => '',
  513. 'show_in_conf_sample' => true,
  514. ),
  515. 'shortcut_actions' => array(
  516. 'type' => 'string',
  517. 'description' => 'Actions that are available as direct buttons next to the "Actions" menu',
  518. // examples... not used
  519. 'default' => 'UI:Menu:Modify,UI:Menu:New',
  520. 'value' => 'UI:Menu:Modify',
  521. 'source_of_value' => '',
  522. 'show_in_conf_sample' => true,
  523. ),
  524. 'complex_actions_limit' => array(
  525. 'type' => 'integer',
  526. 'description' => 'Display the "actions" menu items that require long computation only if the list of objects is contains less objects than this number (0 means no limit)',
  527. // examples... not used
  528. 'default' => 50,
  529. 'value' => 50,
  530. 'source_of_value' => '',
  531. 'show_in_conf_sample' => false,
  532. ),
  533. 'synchro_prevent_delete_all' => array(
  534. 'type' => 'bool',
  535. 'description' => 'Stop the synchro if all the replicas of a data source become obsolete at the same time.',
  536. // examples... not used
  537. 'default' => true,
  538. 'value' => true,
  539. 'source_of_value' => '',
  540. 'show_in_conf_sample' => false,
  541. ),
  542. 'source_dir' => array(
  543. 'type' => 'string',
  544. 'description' => 'Source directory for the datamodel files. (which gets compiled to env-production).',
  545. // examples... not used
  546. 'default' => '',
  547. 'value' => '',
  548. 'source_of_value' => '',
  549. 'show_in_conf_sample' => true,
  550. ),
  551. 'csv_file_default_charset' => array(
  552. 'type' => 'string',
  553. 'description' => 'Character set used by default for downloading and uploading data as a CSV file. Warning: it is case sensitive (uppercase is preferable).',
  554. // examples... not used
  555. 'default' => 'ISO-8859-1',
  556. 'value' => '',
  557. 'source_of_value' => '',
  558. 'show_in_conf_sample' => true,
  559. ),
  560. 'debug_report_spurious_chars' => array(
  561. 'type' => 'bool',
  562. 'description' => 'Report, in the error log, the characters found in the output buffer, echoed by mistake in the loaded modules, and potentially corrupting the output',
  563. // examples... not used
  564. 'default' => false,
  565. 'value' => '',
  566. 'source_of_value' => '',
  567. 'show_in_conf_sample' => false,
  568. ),
  569. );
  570. public function IsProperty($sPropCode)
  571. {
  572. return (array_key_exists($sPropCode, $this->m_aSettings));
  573. }
  574. public function GetDescription($sPropCode)
  575. {
  576. return $this->m_aSettings[$sPropCode];
  577. }
  578. public function Set($sPropCode, $value, $sSourceDesc = 'unknown')
  579. {
  580. $sType = $this->m_aSettings[$sPropCode]['type'];
  581. switch($sType)
  582. {
  583. case 'bool':
  584. $value = (bool) $value;
  585. break;
  586. case 'string':
  587. $value = (string) $value;
  588. break;
  589. case 'integer':
  590. $value = (integer) $value;
  591. break;
  592. case 'float':
  593. $value = (float) $value;
  594. break;
  595. default:
  596. throw new CoreException('Unknown type for setting', array('property' => $sPropCode, 'type' => $sType));
  597. }
  598. $this->m_aSettings[$sPropCode]['value'] = $value;
  599. $this->m_aSettings[$sPropCode]['source_of_value'] = $sSourceDesc;
  600. }
  601. public function Get($sPropCode)
  602. {
  603. return $this->m_aSettings[$sPropCode]['value'];
  604. }
  605. // Those variables will be deprecated later, when the transition to ...Get('my_setting') will be done
  606. protected $m_sDBHost;
  607. protected $m_sDBUser;
  608. protected $m_sDBPwd;
  609. protected $m_sDBName;
  610. protected $m_sDBSubname;
  611. protected $m_sDBCharacterSet;
  612. protected $m_sDBCollation;
  613. /**
  614. * Event log options (see LOG_... definition)
  615. */
  616. // Those variables will be deprecated later, when the transition to ...Get('my_setting') will be done
  617. protected $m_bLogGlobal;
  618. protected $m_bLogNotification;
  619. protected $m_bLogIssue;
  620. protected $m_bLogWebService;
  621. protected $m_bLogKPIDuration; // private setting
  622. protected $m_bLogKPIMemory; // private setting
  623. protected $m_bDebugQueries; // private setting
  624. protected $m_bQueryCacheEnabled; // private setting
  625. /**
  626. * @var integer Number of elements to be displayed when there are more than m_iMaxDisplayLimit elements
  627. */
  628. protected $m_iMinDisplayLimit;
  629. /**
  630. * @var integer Max number of elements before truncating the display
  631. */
  632. protected $m_iMaxDisplayLimit;
  633. /**
  634. * @var integer Number of seconds between two reloads of the display (standard)
  635. */
  636. protected $m_iStandardReloadInterval;
  637. /**
  638. * @var integer Number of seconds between two reloads of the display (fast)
  639. */
  640. protected $m_iFastReloadInterval;
  641. /**
  642. * @var boolean Whether or not a secure connection is required for using the application.
  643. * If set, any attempt to connect to an iTop page with http:// will be redirected
  644. * to https://
  645. */
  646. protected $m_bSecureConnectionRequired;
  647. /**
  648. * @var string Langage code, default if the user language is undefined
  649. */
  650. protected $m_sDefaultLanguage;
  651. /**
  652. * @var string Type of login process allowed: form|basic|url|external
  653. */
  654. protected $m_sAllowedLoginTypes;
  655. /**
  656. * @var string Name of the PHP variable in which external authentication information is passed by the web server
  657. */
  658. protected $m_sExtAuthVariable;
  659. /**
  660. * @var string Encryption key used for all attributes of type "encrypted string". Can be set to a random value
  661. * unless you want to import a database from another iTop instance, in which case you must use
  662. * the same encryption key in order to properly decode the encrypted fields
  663. */
  664. protected $m_sEncryptionKey;
  665. /**
  666. * @var array Additional character sets to be supported by the interactive CSV import
  667. * 'iconv_code' => 'display name'
  668. */
  669. protected $m_aCharsets;
  670. public function __construct($sConfigFile = null, $bLoadConfig = true)
  671. {
  672. $this->m_sFile = $sConfigFile;
  673. if (is_null($sConfigFile))
  674. {
  675. $bLoadConfig = false;
  676. }
  677. $this->m_aAppModules = array(
  678. // Some default modules, always present can be move to an official iTop Module later if needed
  679. 'application/transaction.class.inc.php',
  680. 'application/menunode.class.inc.php',
  681. 'application/user.preferences.class.inc.php',
  682. 'application/user.dashboard.class.inc.php',
  683. 'application/audit.rule.class.inc.php',
  684. 'application/query.class.inc.php',
  685. // Romain - That's dirty, because those classes are in fact part of the core
  686. // but I needed those classes to be derived from cmdbAbstractObject
  687. // (to be managed via the GUI) and this class in not really known from
  688. // the core, PLUS I needed the includes to be there also for the setup
  689. // to create the tables.
  690. 'core/event.class.inc.php',
  691. 'core/action.class.inc.php',
  692. 'core/trigger.class.inc.php',
  693. 'synchro/synchrodatasource.class.inc.php',
  694. );
  695. $this->m_aDataModels = array();
  696. $this->m_aWebServiceCategories = array(
  697. 'webservices/webservices.basic.php',
  698. );
  699. $this->m_aAddons = array(
  700. // Default AddOn, always present can be moved to an official iTop Module later if needed
  701. 'user rights' => 'addons/userrights/userrightsprofile.class.inc.php',
  702. );
  703. $this->m_aDictionaries = self::ScanDictionariesDir();
  704. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  705. {
  706. $this->m_aSettings[$sPropCode]['value'] = $aSettingInfo['default'];
  707. }
  708. $this->m_sDBHost = '';
  709. $this->m_sDBUser = '';
  710. $this->m_sDBPwd = '';
  711. $this->m_sDBName = '';
  712. $this->m_sDBSubname = '';
  713. $this->m_sDBCharacterSet = DEFAULT_CHARACTER_SET;
  714. $this->m_sDBCollation = DEFAULT_COLLATION;
  715. $this->m_bLogGlobal = DEFAULT_LOG_GLOBAL;
  716. $this->m_bLogNotification = DEFAULT_LOG_NOTIFICATION;
  717. $this->m_bLogIssue = DEFAULT_LOG_ISSUE;
  718. $this->m_bLogWebService = DEFAULT_LOG_WEB_SERVICE;
  719. $this->m_bLogKPIDuration = DEFAULT_LOG_KPI_DURATION;
  720. $this->m_bLogKPIDuration = DEFAULT_LOG_KPI_DURATION;
  721. $this->m_iMinDisplayLimit = DEFAULT_MIN_DISPLAY_LIMIT;
  722. $this->m_iMaxDisplayLimit = DEFAULT_MAX_DISPLAY_LIMIT;
  723. $this->m_iStandardReloadInterval = DEFAULT_STANDARD_RELOAD_INTERVAL;
  724. $this->m_iFastReloadInterval = DEFAULT_FAST_RELOAD_INTERVAL;
  725. $this->m_bSecureConnectionRequired = DEFAULT_SECURE_CONNECTION_REQUIRED;
  726. $this->m_sDefaultLanguage = 'EN US';
  727. $this->m_sAllowedLoginTypes = DEFAULT_ALLOWED_LOGIN_TYPES;
  728. $this->m_sExtAuthVariable = DEFAULT_EXT_AUTH_VARIABLE;
  729. $this->m_sEncryptionKey = DEFAULT_ENCRYPTION_KEY;
  730. $this->m_aCharsets = array();
  731. $this->m_aModuleSettings = array();
  732. if ($bLoadConfig)
  733. {
  734. $this->Load($sConfigFile);
  735. $this->Verify();
  736. }
  737. // Application root url: set a default value, then normalize it
  738. /*
  739. * Does not work in CLI/unattended mode
  740. $sAppRootUrl = trim($this->Get('app_root_url'));
  741. if (strlen($sAppRootUrl) == 0)
  742. {
  743. $sAppRootUrl = utils::GetDefaultUrlAppRoot();
  744. }
  745. if (substr($sAppRootUrl, -1, 1) != '/')
  746. {
  747. $sAppRootUrl .= '/';
  748. }
  749. $this->Set('app_root_url', $sAppRootUrl);
  750. */
  751. }
  752. protected function CheckFile($sPurpose, $sFileName)
  753. {
  754. if (!file_exists($sFileName))
  755. {
  756. throw new ConfigException("Could not find $sPurpose file", array('file' => $sFileName));
  757. }
  758. if (!is_readable($sFileName))
  759. {
  760. 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));
  761. }
  762. }
  763. protected function Load($sConfigFile)
  764. {
  765. $this->CheckFile('configuration', $sConfigFile);
  766. $sConfigCode = trim(file_get_contents($sConfigFile));
  767. // This does not work on several lines
  768. // preg_match('/^<\\?php(.*)\\?'.'>$/', $sConfigCode, $aMatches)...
  769. // So, I've implemented a solution suggested in the PHP doc (search for phpWrapper)
  770. try
  771. {
  772. ob_start();
  773. eval('?'.'>'.trim($sConfigCode));
  774. $sNoise = trim(ob_get_contents());
  775. ob_end_clean();
  776. }
  777. catch (Exception $e)
  778. {
  779. // well, never reach in case of parsing error :-(
  780. // will be improved in PHP 6 ?
  781. throw new ConfigException('Error in configuration file', array('file' => $sConfigFile, 'error' => $e->getMessage()));
  782. }
  783. if (strlen($sNoise) > 0)
  784. {
  785. // Note: sNoise is an html output, but so far it was ok for me (e.g. showing the entire call stack)
  786. throw new ConfigException('Syntax error in configuration file', array('file' => $sConfigFile, 'error' => '<tt>'.htmlentities($sNoise, ENT_QUOTES, 'UTF-8').'</tt>'));
  787. }
  788. if (!isset($MySettings) || !is_array($MySettings))
  789. {
  790. throw new ConfigException('Missing array in configuration file', array('file' => $sConfigFile, 'expected' => '$MySettings'));
  791. }
  792. if (!isset($MyModules) || !is_array($MyModules))
  793. {
  794. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules'));
  795. }
  796. if (!array_key_exists('application', $MyModules))
  797. {
  798. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'application\']'));
  799. }
  800. if (!array_key_exists('business', $MyModules))
  801. {
  802. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'business\']'));
  803. }
  804. if (!array_key_exists('addons', $MyModules))
  805. {
  806. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'addons\']'));
  807. }
  808. if (!array_key_exists('user rights', $MyModules['addons']))
  809. {
  810. // Add one, by default
  811. $MyModules['addons']['user rights'] = '/addons/userrights/userrightsnull.class.inc.php';
  812. }
  813. if (!array_key_exists('dictionaries', $MyModules))
  814. {
  815. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'dictionaries\']'));
  816. }
  817. $this->m_aAppModules = $MyModules['application'];
  818. $this->m_aDataModels = $MyModules['business'];
  819. if (isset($MyModules['webservices']))
  820. {
  821. $this->m_aWebServiceCategories = $MyModules['webservices'];
  822. }
  823. $this->m_aAddons = $MyModules['addons'];
  824. $this->m_aDictionaries = $MyModules['dictionaries'];
  825. foreach($MySettings as $sPropCode => $rawvalue)
  826. {
  827. if ($this->IsProperty($sPropCode))
  828. {
  829. $value = trim($rawvalue);
  830. $this->Set($sPropCode, $value, $sConfigFile);
  831. }
  832. }
  833. $this->m_sDBHost = trim($MySettings['db_host']);
  834. $this->m_sDBUser = trim($MySettings['db_user']);
  835. $this->m_sDBPwd = trim($MySettings['db_pwd']);
  836. $this->m_sDBName = trim($MySettings['db_name']);
  837. $this->m_sDBSubname = trim($MySettings['db_subname']);
  838. $this->m_sDBCharacterSet = isset($MySettings['db_character_set']) ? trim($MySettings['db_character_set']) : DEFAULT_CHARACTER_SET;
  839. $this->m_sDBCollation = isset($MySettings['db_collation']) ? trim($MySettings['db_collation']) : DEFAULT_COLLATION;
  840. $this->m_bLogGlobal = isset($MySettings['log_global']) ? (bool) trim($MySettings['log_global']) : DEFAULT_LOG_GLOBAL;
  841. $this->m_bLogNotification = isset($MySettings['log_notification']) ? (bool) trim($MySettings['log_notification']) : DEFAULT_LOG_NOTIFICATION;
  842. $this->m_bLogIssue = isset($MySettings['log_issue']) ? (bool) trim($MySettings['log_issue']) : DEFAULT_LOG_ISSUE;
  843. $this->m_bLogWebService = isset($MySettings['log_web_service']) ? (bool) trim($MySettings['log_web_service']) : DEFAULT_LOG_WEB_SERVICE;
  844. $this->m_bLogKPIDuration = isset($MySettings['log_kpi_duration']) ? (bool) trim($MySettings['log_kpi_duration']) : DEFAULT_LOG_KPI_DURATION;
  845. $this->m_bLogKPIMemory = isset($MySettings['log_kpi_memory']) ? (bool) trim($MySettings['log_kpi_memory']) : DEFAULT_LOG_KPI_MEMORY;
  846. $this->m_bDebugQueries = isset($MySettings['debug_queries']) ? (bool) trim($MySettings['debug_queries']) : DEFAULT_DEBUG_QUERIES;
  847. $this->m_bQueryCacheEnabled = isset($MySettings['query_cache_enabled']) ? (bool) trim($MySettings['query_cache_enabled']) : DEFAULT_QUERY_CACHE_ENABLED;
  848. $this->m_iMinDisplayLimit = isset($MySettings['min_display_limit']) ? trim($MySettings['min_display_limit']) : DEFAULT_MIN_DISPLAY_LIMIT;
  849. $this->m_iMaxDisplayLimit = isset($MySettings['max_display_limit']) ? trim($MySettings['max_display_limit']) : DEFAULT_MAX_DISPLAY_LIMIT;
  850. $this->m_iStandardReloadInterval = isset($MySettings['standard_reload_interval']) ? trim($MySettings['standard_reload_interval']) : DEFAULT_STANDARD_RELOAD_INTERVAL;
  851. $this->m_iFastReloadInterval = isset($MySettings['fast_reload_interval']) ? trim($MySettings['fast_reload_interval']) : DEFAULT_FAST_RELOAD_INTERVAL;
  852. $this->m_bSecureConnectionRequired = isset($MySettings['secure_connection_required']) ? (bool) trim($MySettings['secure_connection_required']) : DEFAULT_SECURE_CONNECTION_REQUIRED;
  853. $this->m_aModuleSettings = isset($MyModuleSettings) ? $MyModuleSettings : array();
  854. $this->m_sDefaultLanguage = isset($MySettings['default_language']) ? trim($MySettings['default_language']) : 'EN US';
  855. $this->m_sAllowedLoginTypes = isset($MySettings['allowed_login_types']) ? trim($MySettings['allowed_login_types']) : DEFAULT_ALLOWED_LOGIN_TYPES;
  856. $this->m_sExtAuthVariable = isset($MySettings['ext_auth_variable']) ? trim($MySettings['ext_auth_variable']) : DEFAULT_EXT_AUTH_VARIABLE;
  857. $this->m_sEncryptionKey = isset($MySettings['encryption_key']) ? trim($MySettings['encryption_key']) : DEFAULT_ENCRYPTION_KEY;
  858. $this->m_aCharsets = isset($MySettings['csv_import_charsets']) ? $MySettings['csv_import_charsets'] : array();
  859. }
  860. protected function Verify()
  861. {
  862. // Files are verified later on, just before using them -see MetaModel::Plugin()
  863. // (we have their final path at that point)
  864. }
  865. public function GetModuleSetting($sModule, $sProperty, $defaultvalue = null)
  866. {
  867. if (isset($this->m_aModuleSettings[$sModule][$sProperty]))
  868. {
  869. return $this->m_aModuleSettings[$sModule][$sProperty];
  870. }
  871. return $defaultvalue;
  872. }
  873. public function SetModuleSetting($sModule, $sProperty, $value)
  874. {
  875. $this->m_aModuleSettings[$sModule][$sProperty] = $value;
  876. }
  877. public function GetAppModules()
  878. {
  879. return $this->m_aAppModules;
  880. }
  881. public function SetAppModules($aAppModules)
  882. {
  883. $this->m_aAppModules = $aAppModules;
  884. }
  885. public function GetDataModels()
  886. {
  887. return $this->m_aDataModels;
  888. }
  889. public function SetDataModels($aDataModels)
  890. {
  891. $this->m_aDataModels = $aDataModels;
  892. }
  893. public function GetWebServiceCategories()
  894. {
  895. return $this->m_aWebServiceCategories;
  896. }
  897. public function SetWebServiceCategories($aWebServiceCategories)
  898. {
  899. $this->m_aWebServiceCategories = $aWebServiceCategories;
  900. }
  901. public function GetAddons()
  902. {
  903. return $this->m_aAddons;
  904. }
  905. public function SetAddons($aAddons)
  906. {
  907. $this->m_aAddons = $aAddons;
  908. }
  909. public function GetDictionaries()
  910. {
  911. return $this->m_aDictionaries;
  912. }
  913. public function SetDictionaries($aDictionaries)
  914. {
  915. $this->m_aDictionaries = $aDictionaries;
  916. }
  917. public function GetDBHost()
  918. {
  919. return $this->m_sDBHost;
  920. }
  921. public function GetDBName()
  922. {
  923. return $this->m_sDBName;
  924. }
  925. public function GetDBSubname()
  926. {
  927. return $this->m_sDBSubname;
  928. }
  929. public function GetDBCharacterSet()
  930. {
  931. return $this->m_sDBCharacterSet;
  932. }
  933. public function GetDBCollation()
  934. {
  935. return $this->m_sDBCollation;
  936. }
  937. public function GetDBUser()
  938. {
  939. return $this->m_sDBUser;
  940. }
  941. public function GetDBPwd()
  942. {
  943. return $this->m_sDBPwd;
  944. }
  945. public function GetLogGlobal()
  946. {
  947. return $this->m_bLogGlobal;
  948. }
  949. public function GetLogNotification()
  950. {
  951. return $this->m_bLogNotification;
  952. }
  953. public function GetLogIssue()
  954. {
  955. return $this->m_bLogIssue;
  956. }
  957. public function GetLogWebService()
  958. {
  959. return $this->m_bLogWebService;
  960. }
  961. public function GetLogKPIDuration()
  962. {
  963. return $this->m_bLogKPIDuration;
  964. }
  965. public function GetLogKPIMemory()
  966. {
  967. return $this->m_bLogKPIMemory;
  968. }
  969. public function GetDebugQueries()
  970. {
  971. return $this->m_bDebugQueries;
  972. }
  973. public function GetQueryCacheEnabled()
  974. {
  975. return $this->m_bQueryCacheEnabled;
  976. }
  977. public function GetMinDisplayLimit()
  978. {
  979. return $this->m_iMinDisplayLimit;
  980. }
  981. public function GetMaxDisplayLimit()
  982. {
  983. return $this->m_iMaxDisplayLimit;
  984. }
  985. public function GetStandardReloadInterval()
  986. {
  987. return $this->m_iStandardReloadInterval;
  988. }
  989. public function GetFastReloadInterval()
  990. {
  991. return $this->m_iFastReloadInterval;
  992. }
  993. public function GetSecureConnectionRequired()
  994. {
  995. return $this->m_bSecureConnectionRequired;
  996. }
  997. public function GetDefaultLanguage()
  998. {
  999. return $this->m_sDefaultLanguage;
  1000. }
  1001. public function GetEncryptionKey()
  1002. {
  1003. return $this->m_sEncryptionKey;
  1004. }
  1005. public function GetAllowedLoginTypes()
  1006. {
  1007. return explode('|', $this->m_sAllowedLoginTypes);
  1008. }
  1009. public function GetExternalAuthenticationVariable()
  1010. {
  1011. return $this->m_sExtAuthVariable;
  1012. }
  1013. public function GetCSVImportCharsets()
  1014. {
  1015. return $this->m_aCharsets;
  1016. }
  1017. public function SetDBHost($sDBHost)
  1018. {
  1019. $this->m_sDBHost = $sDBHost;
  1020. }
  1021. public function SetDBName($sDBName)
  1022. {
  1023. $this->m_sDBName = $sDBName;
  1024. }
  1025. public function SetDBSubname($sDBSubName)
  1026. {
  1027. $this->m_sDBSubname = $sDBSubName;
  1028. }
  1029. public function SetDBCharacterSet($sDBCharacterSet)
  1030. {
  1031. $this->m_sDBCharacterSet = $sDBCharacterSet;
  1032. }
  1033. public function SetDBCollation($sDBCollation)
  1034. {
  1035. $this->m_sDBCollation = $sDBCollation;
  1036. }
  1037. public function SetDBUser($sUser)
  1038. {
  1039. $this->m_sDBUser = $sUser;
  1040. }
  1041. public function SetDBPwd($sPwd)
  1042. {
  1043. $this->m_sDBPwd = $sPwd;
  1044. }
  1045. public function SetLogGlobal($iLogGlobal)
  1046. {
  1047. $this->m_iLogGlobal = $iLogGlobal;
  1048. }
  1049. public function SetLogNotification($iLogNotification)
  1050. {
  1051. $this->m_iLogNotification = $iLogNotification;
  1052. }
  1053. public function SetLogIssue($iLogIssue)
  1054. {
  1055. $this->m_iLogIssue = $iLogIssue;
  1056. }
  1057. public function SetLogWebService($iLogWebService)
  1058. {
  1059. $this->m_iLogWebService = $iLogWebService;
  1060. }
  1061. public function SetMinDisplayLimit($iMinDisplayLimit)
  1062. {
  1063. $this->m_iMinDisplayLimit = $iMinDisplayLimit;
  1064. }
  1065. public function SetMaxDisplayLimit($iMaxDisplayLimit)
  1066. {
  1067. $this->m_iMaxDisplayLimit = $iMaxDisplayLimit;
  1068. }
  1069. public function SetStandardReloadInterval($iStandardReloadInterval)
  1070. {
  1071. $this->m_iStandardReloadInterval = $iStandardReloadInterval;
  1072. }
  1073. public function SetFastReloadInterval($iFastReloadInterval)
  1074. {
  1075. $this->m_iFastReloadInterval = $iFastReloadInterval;
  1076. }
  1077. public function SetSecureConnectionRequired($bSecureConnectionRequired)
  1078. {
  1079. $this->m_bSecureConnectionRequired = $bSecureConnectionRequired;
  1080. }
  1081. public function SetDefaultLanguage($sLanguageCode)
  1082. {
  1083. $this->m_sDefaultLanguage = $sLanguageCode;
  1084. }
  1085. public function SetAllowedLoginTypes($aAllowedLoginTypes)
  1086. {
  1087. $this->m_sAllowedLoginTypes = implode('|', $aAllowedLoginTypes);
  1088. }
  1089. public function SetExternalAuthenticationVariable($sExtAuthVariable)
  1090. {
  1091. $this->m_sExtAuthVariable = $sExtAuthVariable;
  1092. }
  1093. public function SetEncryptionKey($sKey)
  1094. {
  1095. $this->m_sEncryptionKey = $sKey;
  1096. }
  1097. public function SetCSVImportCharsets($aCharsets)
  1098. {
  1099. $this->m_aCharsets = $aCharsets;
  1100. }
  1101. public function AddCSVImportCharset($sIconvCode, $sDisplayName)
  1102. {
  1103. $this->m_aCharsets[$sIconvCode] = $sDisplayName;
  1104. }
  1105. public function GetLoadedFile()
  1106. {
  1107. if (is_null($this->m_sFile))
  1108. {
  1109. return '';
  1110. }
  1111. else
  1112. {
  1113. return $this->m_sFile;
  1114. }
  1115. }
  1116. /**
  1117. * Render the configuration as an associative array
  1118. * @return boolean True otherwise throws an Exception
  1119. */
  1120. public function ToArray()
  1121. {
  1122. $aSettings = array();
  1123. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  1124. {
  1125. $aSettings[$sPropCode] = $aSettingInfo['value'];
  1126. }
  1127. $aSettings['db_host'] = $this->m_sDBHost;
  1128. $aSettings['db_user'] = $this->m_sDBUser;
  1129. $aSettings['db_pwd'] = $this->m_sDBPwd;
  1130. $aSettings['db_name'] = $this->m_sDBName;
  1131. $aSettings['db_subname'] = $this->m_sDBSubname;
  1132. $aSettings['db_character_set'] = $this->m_sDBCharacterSet;
  1133. $aSettings['db_collation'] = $this->m_sDBCollation;
  1134. $aSettings['log_global'] = $this->m_bLogGlobal;
  1135. $aSettings['log_notification'] = $this->m_bLogNotification;
  1136. $aSettings['log_issue'] = $this->m_bLogIssue;
  1137. $aSettings['log_web_service'] = $this->m_bLogWebService;
  1138. $aSettings['min_display_limit'] = $this->m_iMinDisplayLimit;
  1139. $aSettings['max_display_limit'] = $this->m_iMaxDisplayLimit;
  1140. $aSettings['standard_reload_interval'] = $this->m_iStandardReloadInterval;
  1141. $aSettings['fast_reload_interval'] = $this->m_iFastReloadInterval;
  1142. $aSettings['secure_connection_required'] = $this->m_bSecureConnectionRequired;
  1143. $aSettings['default_language'] = $this->m_sDefaultLanguage;
  1144. $aSettings['allowed_login_types'] = $this->m_sAllowedLoginTypes;
  1145. $aSettings['encryption_key'] = $this->m_sEncryptionKey;
  1146. $aSettings['csv_import_charsets'] = $this->m_aCharsets;
  1147. foreach ($this->m_aModuleSettings as $sModule => $aProperties)
  1148. {
  1149. foreach ($aProperties as $sProperty => $value)
  1150. {
  1151. $aSettings['module_settings'][$sModule][$sProperty] = $value;
  1152. }
  1153. }
  1154. foreach($this->m_aAppModules as $sFile)
  1155. {
  1156. $aSettings['application_list'][] = $sFile;
  1157. }
  1158. foreach($this->m_aDataModels as $sFile)
  1159. {
  1160. $aSettings['datamodel_list'][] = $sFile;
  1161. }
  1162. foreach($this->m_aWebServiceCategories as $sFile)
  1163. {
  1164. $aSettings['webservice_list'][] = $sFile;
  1165. }
  1166. foreach($this->m_aAddons as $sKey => $sFile)
  1167. {
  1168. $aSettings['addon_list'][] = $sFile;
  1169. }
  1170. foreach($this->m_aDictionaries as $sFile)
  1171. {
  1172. $aSettings['dictionary_list'][] = $sFile;
  1173. }
  1174. return $aSettings;
  1175. }
  1176. /**
  1177. * Write the configuration to a file (php format) that can be reloaded later
  1178. * By default write to the same file that was specified when constructing the object
  1179. * @param $sFileName string Name of the file to write to (emtpy to write to the same file)
  1180. * @return boolean True otherwise throws an Exception
  1181. */
  1182. public function WriteToFile($sFileName = '')
  1183. {
  1184. if (empty($sFileName))
  1185. {
  1186. $sFileName = $this->m_sFile;
  1187. }
  1188. $hFile = @fopen($sFileName, 'w');
  1189. if ($hFile !== false)
  1190. {
  1191. fwrite($hFile, "<?php\n");
  1192. fwrite($hFile, "\n/**\n");
  1193. fwrite($hFile, " *\n");
  1194. fwrite($hFile, " * Configuration file, generated by the ".ITOP_APPLICATION." configuration wizard\n");
  1195. fwrite($hFile, " *\n");
  1196. fwrite($hFile, " * The file is used in MetaModel::LoadConfig() which does all the necessary initialization job\n");
  1197. fwrite($hFile, " *\n");
  1198. fwrite($hFile, " */\n");
  1199. $aConfigSettings = $this->m_aSettings;
  1200. // Old fashioned boolean settings
  1201. $aBoolValues = array(
  1202. 'log_global' => $this->m_bLogGlobal,
  1203. 'log_notification' => $this->m_bLogNotification,
  1204. 'log_issue' => $this->m_bLogIssue,
  1205. 'log_web_service' => $this->m_bLogWebService,
  1206. 'secure_connection_required' => $this->m_bSecureConnectionRequired,
  1207. );
  1208. foreach($aBoolValues as $sKey => $bValue)
  1209. {
  1210. $aConfigSettings[$sKey] = array(
  1211. 'show_in_conf_sample' => true,
  1212. 'type' => 'bool',
  1213. 'value' => $bValue,
  1214. );
  1215. }
  1216. // Old fashioned integer settings
  1217. $aIntValues = array(
  1218. 'fast_reload_interval' => $this->m_iFastReloadInterval,
  1219. 'max_display_limit' => $this->m_iMaxDisplayLimit,
  1220. 'min_display_limit' => $this->m_iMinDisplayLimit,
  1221. 'standard_reload_interval' => $this->m_iStandardReloadInterval,
  1222. );
  1223. foreach($aIntValues as $sKey => $iValue)
  1224. {
  1225. $aConfigSettings[$sKey] = array(
  1226. 'show_in_conf_sample' => true,
  1227. 'type' => 'integer',
  1228. 'value' => $iValue,
  1229. );
  1230. }
  1231. // Old fashioned remaining values
  1232. $aOtherValues = array(
  1233. 'db_host' => $this->m_sDBHost,
  1234. 'db_user' => $this->m_sDBUser,
  1235. 'db_pwd' => $this->m_sDBPwd,
  1236. 'db_name' => $this->m_sDBName,
  1237. 'db_subname' => $this->m_sDBSubname,
  1238. 'db_character_set' => $this->m_sDBCharacterSet,
  1239. 'db_collation' => $this->m_sDBCollation,
  1240. 'default_language' => $this->m_sDefaultLanguage,
  1241. 'allowed_login_types' => $this->m_sAllowedLoginTypes,
  1242. 'encryption_key' => $this->m_sEncryptionKey,
  1243. 'csv_import_charsets' => $this->m_aCharsets,
  1244. );
  1245. foreach($aOtherValues as $sKey => $value)
  1246. {
  1247. $aConfigSettings[$sKey] = array(
  1248. 'show_in_conf_sample' => true,
  1249. 'type' => is_string($value) ? 'string' : 'mixed',
  1250. 'value' => $value,
  1251. );
  1252. }
  1253. ksort($aConfigSettings);
  1254. fwrite($hFile, "\$MySettings = array(\n");
  1255. foreach($aConfigSettings as $sPropCode => $aSettingInfo)
  1256. {
  1257. // Write all values that are either always visible or present in the cloned config file
  1258. if ($aSettingInfo['show_in_conf_sample'] || ($aSettingInfo['source_of_value'] != 'unknown') )
  1259. {
  1260. $sType = $aSettingInfo['type'];
  1261. switch($sType)
  1262. {
  1263. case 'bool':
  1264. $sSeenAs = $aSettingInfo['value'] ? 'true' : 'false';
  1265. break;
  1266. default:
  1267. $sSeenAs = self::PrettyVarExport($aSettingInfo['value'], "\t");
  1268. }
  1269. fwrite($hFile, "\n");
  1270. if (isset($aSettingInfo['description']))
  1271. {
  1272. fwrite($hFile, "\t// $sPropCode: {$aSettingInfo['description']}\n");
  1273. }
  1274. if (isset($aSettingInfo['default']))
  1275. {
  1276. $default = $aSettingInfo['default'];
  1277. if ($aSettingInfo['type'] == 'bool')
  1278. {
  1279. $default = $default ? 'true' : 'false';
  1280. }
  1281. fwrite($hFile, "\t//\tdefault: ".self::PrettyVarExport($aSettingInfo['default'],"\t//\t\t", true)."\n");
  1282. }
  1283. fwrite($hFile, "\t'$sPropCode' => $sSeenAs,\n");
  1284. }
  1285. }
  1286. fwrite($hFile, ");\n");
  1287. fwrite($hFile, "\n");
  1288. fwrite($hFile, "/**\n *\n * Modules specific settings\n *\n */\n");
  1289. fwrite($hFile, "\$MyModuleSettings = array(\n");
  1290. foreach ($this->m_aModuleSettings as $sModule => $aProperties)
  1291. {
  1292. fwrite($hFile, "\t'$sModule' => array (\n");
  1293. foreach ($aProperties as $sProperty => $value)
  1294. {
  1295. $sNiceExport = self::PrettyVarExport($value, "\t\t");
  1296. fwrite($hFile, "\t\t'$sProperty' => $sNiceExport,\n");
  1297. }
  1298. fwrite($hFile, "\t),\n");
  1299. }
  1300. fwrite($hFile, ");\n");
  1301. fwrite($hFile, "\n/**\n");
  1302. fwrite($hFile, " *\n");
  1303. fwrite($hFile, " * Data model modules to be loaded. Names are specified as relative paths\n");
  1304. fwrite($hFile, " *\n");
  1305. fwrite($hFile, " */\n");
  1306. fwrite($hFile, "\$MyModules = array(\n");
  1307. fwrite($hFile, "\t'application' => array (\n");
  1308. foreach($this->m_aAppModules as $sFile)
  1309. {
  1310. fwrite($hFile, "\t\t'$sFile',\n");
  1311. }
  1312. fwrite($hFile, "\t),\n");
  1313. fwrite($hFile, "\t'business' => array (\n");
  1314. foreach($this->m_aDataModels as $sFile)
  1315. {
  1316. fwrite($hFile, "\t\t'$sFile',\n");
  1317. }
  1318. fwrite($hFile, "\t),\n");
  1319. fwrite($hFile, "\t'webservices' => array (\n");
  1320. foreach($this->m_aWebServiceCategories as $sFile)
  1321. {
  1322. fwrite($hFile, "\t\t'$sFile',\n");
  1323. }
  1324. fwrite($hFile, "\t),\n");
  1325. fwrite($hFile, "\t'addons' => array (\n");
  1326. foreach($this->m_aAddons as $sKey => $sFile)
  1327. {
  1328. fwrite($hFile, "\t\t'$sKey' => '$sFile',\n");
  1329. }
  1330. fwrite($hFile, "\t),\n");
  1331. fwrite($hFile, "\t'dictionaries' => array (\n");
  1332. foreach($this->m_aDictionaries as $sFile)
  1333. {
  1334. fwrite($hFile, "\t\t'$sFile',\n");
  1335. }
  1336. fwrite($hFile, "\t),\n");
  1337. fwrite($hFile, ");\n");
  1338. fwrite($hFile, '?'.'>'); // Avoid perturbing the syntax highlighting !
  1339. return fclose($hFile);
  1340. }
  1341. else
  1342. {
  1343. throw new ConfigException("Could not write to configuration file", array('file' => $sFileName));
  1344. }
  1345. }
  1346. protected static function ScanDictionariesDir()
  1347. {
  1348. $aResult = array();
  1349. // Populate automatically the list of dictionary files
  1350. $sDir = APPROOT.'/dictionaries';
  1351. if ($hDir = @opendir($sDir))
  1352. {
  1353. while (($sFile = readdir($hDir)) !== false)
  1354. {
  1355. $aMatches = array();
  1356. if (preg_match("/^([^\.]+\.)?dictionary\.itop\.(ui|core)\.php$/i", $sFile, $aMatches)) // Dictionary files named like [<Lang>.]dictionary.[core|ui].php are loaded automatically
  1357. {
  1358. $aResult[] = 'dictionaries/'.$sFile;
  1359. }
  1360. }
  1361. closedir($hDir);
  1362. }
  1363. return $aResult;
  1364. }
  1365. /**
  1366. * Helper function to initialize a configuration from the page arguments
  1367. */
  1368. public function UpdateFromParams($aParamValues, $sModulesDir = null, $bPreserveModuleSettings = false)
  1369. {
  1370. if (isset($aParamValues['application_path']))
  1371. {
  1372. $this->Set('app_root_url', $aParamValues['application_path']);
  1373. }
  1374. if (isset($aParamValues['mode']) && isset($aParamValues['language']))
  1375. {
  1376. if (($aParamValues['mode'] == 'install') || $this->GetDefaultLanguage() == '')
  1377. {
  1378. $this->SetDefaultLanguage($aParamValues['language']);
  1379. }
  1380. }
  1381. if (isset($aParamValues['db_server']))
  1382. {
  1383. $this->SetDBHost($aParamValues['db_server']);
  1384. $this->SetDBUser($aParamValues['db_user']);
  1385. $this->SetDBPwd($aParamValues['db_pwd']);
  1386. $sDBName = $aParamValues['db_name'];
  1387. if ($sDBName == '')
  1388. {
  1389. // Todo - obsolete after the transition to the new setup (2.0) is complete (WARNING: used by the designer)
  1390. $sDBName = $aParamValues['new_db_name'];
  1391. }
  1392. $this->SetDBName($sDBName);
  1393. $this->SetDBSubname($aParamValues['db_prefix']);
  1394. }
  1395. if (!is_null($sModulesDir))
  1396. {
  1397. if (isset($aParamValues['selected_modules']))
  1398. {
  1399. $aSelectedModules = explode(',', $aParamValues['selected_modules']);
  1400. }
  1401. else
  1402. {
  1403. $aSelectedModules = null;
  1404. }
  1405. // Initialize the arrays below with default values for the application...
  1406. $oEmptyConfig = new Config('dummy_file', false); // Do NOT load any config file, just set the default values
  1407. $aAddOns = $oEmptyConfig->GetAddOns();
  1408. $aAppModules = $oEmptyConfig->GetAppModules();
  1409. $aDataModels = $oEmptyConfig->GetDataModels();
  1410. $aWebServiceCategories = $oEmptyConfig->GetWebServiceCategories();
  1411. $aDictionaries = $oEmptyConfig->GetDictionaries();
  1412. // Merge the values with the ones provided by the modules
  1413. // Make sure when don't load the same file twice...
  1414. $aModules = ModuleDiscovery::GetAvailableModules(array(APPROOT.$sModulesDir));
  1415. foreach($aModules as $sModuleId => $aModuleInfo)
  1416. {
  1417. list($sModuleName, $sModuleVersion) = ModuleDiscovery::GetModuleName($sModuleId);
  1418. if (is_null($aSelectedModules) || in_array($sModuleName, $aSelectedModules))
  1419. {
  1420. if (isset($aModuleInfo['datamodel']))
  1421. {
  1422. $aDataModels = array_unique(array_merge($aDataModels, $aModuleInfo['datamodel']));
  1423. }
  1424. if (isset($aModuleInfo['webservice']))
  1425. {
  1426. $aWebServiceCategories = array_unique(array_merge($aWebServiceCategories, $aModuleInfo['webservice']));
  1427. }
  1428. if (isset($aModuleInfo['dictionary']))
  1429. {
  1430. $aDictionaries = array_unique(array_merge($aDictionaries, $aModuleInfo['dictionary']));
  1431. }
  1432. if (isset($aModuleInfo['settings']))
  1433. {
  1434. list($sName, $sVersion) = ModuleDiscovery::GetModuleName($sModuleId);
  1435. foreach($aModuleInfo['settings'] as $sProperty => $value)
  1436. {
  1437. if ($bPreserveModuleSettings && isset($this->m_aModuleSettings[$sName][$sProperty]))
  1438. {
  1439. // Do nothing keep the original value
  1440. }
  1441. else
  1442. {
  1443. $this->SetModuleSetting($sName, $sProperty, $value);
  1444. }
  1445. }
  1446. }
  1447. if (isset($aModuleInfo['installer']))
  1448. {
  1449. $sModuleInstallerClass = $aModuleInfo['installer'];
  1450. if (!class_exists($sModuleInstallerClass))
  1451. {
  1452. throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not a PHP class - Module: ".$aModuleInfo['label']);
  1453. }
  1454. if (!is_subclass_of($sModuleInstallerClass, 'ModuleInstallerAPI'))
  1455. {
  1456. throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not derived from 'ModuleInstallerAPI' - Module: ".$aModuleInfo['label']);
  1457. }
  1458. $aCallSpec = array($sModuleInstallerClass, 'BeforeWritingConfig');
  1459. call_user_func_array($aCallSpec, array($this));
  1460. }
  1461. }
  1462. }
  1463. $this->SetAddOns($aAddOns);
  1464. $this->SetAppModules($aAppModules);
  1465. $this->SetDataModels($aDataModels);
  1466. $this->SetWebServiceCategories($aWebServiceCategories);
  1467. $this->SetDictionaries($aDictionaries);
  1468. }
  1469. }
  1470. /**
  1471. * Helper: for an array of string, change the prefix when found
  1472. */
  1473. protected static function ChangePrefix(&$aStrings, $sSearchPrefix, $sNewPrefix)
  1474. {
  1475. foreach ($aStrings as &$sFile)
  1476. {
  1477. if (substr($sFile, 0, strlen($sSearchPrefix)) == $sSearchPrefix)
  1478. {
  1479. $sFile = $sNewPrefix.substr($sFile, strlen($sSearchPrefix));
  1480. }
  1481. }
  1482. }
  1483. /**
  1484. * Quick an dirty way to clone a config file into another environment
  1485. */
  1486. public function ChangeModulesPath($sSourceEnv, $sTargetEnv)
  1487. {
  1488. $sSearchPrefix = 'env-'.$sSourceEnv.'/';
  1489. $sNewPrefix = 'env-'.$sTargetEnv.'/';
  1490. self::ChangePrefix($this->m_aDataModels, $sSearchPrefix, $sNewPrefix);
  1491. self::ChangePrefix($this->m_aWebServiceCategories, $sSearchPrefix, $sNewPrefix);
  1492. self::ChangePrefix($this->m_aDictionaries, $sSearchPrefix, $sNewPrefix);
  1493. }
  1494. /**
  1495. * Pretty format a var_export'ed value so that (if possible) the identation is preserved on every line
  1496. * @param mixed $value The value to export
  1497. * @param string $sIdentation The string to use to indent the text
  1498. * @param bool $bForceIndentation Forces the identation (enven if it breaks/changes an eval, for example to ouput a value inside a comment)
  1499. * @return string The indented export string
  1500. */
  1501. protected static function PrettyVarExport($value, $sIdentation, $bForceIndentation = false)
  1502. {
  1503. $sExport = var_export($value, true);
  1504. $sNiceExport = trim(preg_replace("/^/m", "\t\t\t", $sExport));
  1505. if (!$bForceIndentation)
  1506. {
  1507. eval('$aImported='.$sNiceExport.';');
  1508. // Check if adding the identations at the beginning of each line
  1509. // did not modify the values (in case of a string containing a line break)
  1510. if($aImported != $value)
  1511. {
  1512. $sNiceExport = $sExport;
  1513. }
  1514. }
  1515. return $sNiceExport;
  1516. }
  1517. }
  1518. ?>