config.class.inc.php 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632
  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. 'synchro_prevent_delete_all' => array(
  525. 'type' => 'bool',
  526. 'description' => 'Stop the synchro if all the replicas of a data source become obsolete at the same time.',
  527. // examples... not used
  528. 'default' => true,
  529. 'value' => true,
  530. 'source_of_value' => '',
  531. 'show_in_conf_sample' => false,
  532. ),
  533. 'source_dir' => array(
  534. 'type' => 'string',
  535. 'description' => 'Source directory for the datamodel files. (which gets compiled to env-production).',
  536. // examples... not used
  537. 'default' => '',
  538. 'value' => '',
  539. 'source_of_value' => '',
  540. 'show_in_conf_sample' => true,
  541. ),
  542. 'csv_file_default_charset' => array(
  543. 'type' => 'string',
  544. 'description' => 'Character set used by default for downloading and uploading data as a CSV file. Warning: it is case sensitive (uppercase is preferable).',
  545. // examples... not used
  546. 'default' => 'ISO-8859-1',
  547. 'value' => '',
  548. 'source_of_value' => '',
  549. 'show_in_conf_sample' => true,
  550. ),
  551. 'debug_report_spurious_chars' => array(
  552. 'type' => 'bool',
  553. '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',
  554. // examples... not used
  555. 'default' => false,
  556. 'value' => '',
  557. 'source_of_value' => '',
  558. 'show_in_conf_sample' => false,
  559. ),
  560. );
  561. public function IsProperty($sPropCode)
  562. {
  563. return (array_key_exists($sPropCode, $this->m_aSettings));
  564. }
  565. public function GetDescription($sPropCode)
  566. {
  567. return $this->m_aSettings[$sPropCode];
  568. }
  569. public function Set($sPropCode, $value, $sSourceDesc = 'unknown')
  570. {
  571. $sType = $this->m_aSettings[$sPropCode]['type'];
  572. switch($sType)
  573. {
  574. case 'bool':
  575. $value = (bool) $value;
  576. break;
  577. case 'string':
  578. $value = (string) $value;
  579. break;
  580. case 'integer':
  581. $value = (integer) $value;
  582. break;
  583. case 'float':
  584. $value = (float) $value;
  585. break;
  586. default:
  587. throw new CoreException('Unknown type for setting', array('property' => $sPropCode, 'type' => $sType));
  588. }
  589. $this->m_aSettings[$sPropCode]['value'] = $value;
  590. $this->m_aSettings[$sPropCode]['source_of_value'] = $sSourceDesc;
  591. }
  592. public function Get($sPropCode)
  593. {
  594. return $this->m_aSettings[$sPropCode]['value'];
  595. }
  596. // Those variables will be deprecated later, when the transition to ...Get('my_setting') will be done
  597. protected $m_sDBHost;
  598. protected $m_sDBUser;
  599. protected $m_sDBPwd;
  600. protected $m_sDBName;
  601. protected $m_sDBSubname;
  602. protected $m_sDBCharacterSet;
  603. protected $m_sDBCollation;
  604. /**
  605. * Event log options (see LOG_... definition)
  606. */
  607. // Those variables will be deprecated later, when the transition to ...Get('my_setting') will be done
  608. protected $m_bLogGlobal;
  609. protected $m_bLogNotification;
  610. protected $m_bLogIssue;
  611. protected $m_bLogWebService;
  612. protected $m_bLogKPIDuration; // private setting
  613. protected $m_bLogKPIMemory; // private setting
  614. protected $m_bDebugQueries; // private setting
  615. protected $m_bQueryCacheEnabled; // private setting
  616. /**
  617. * @var integer Number of elements to be displayed when there are more than m_iMaxDisplayLimit elements
  618. */
  619. protected $m_iMinDisplayLimit;
  620. /**
  621. * @var integer Max number of elements before truncating the display
  622. */
  623. protected $m_iMaxDisplayLimit;
  624. /**
  625. * @var integer Number of seconds between two reloads of the display (standard)
  626. */
  627. protected $m_iStandardReloadInterval;
  628. /**
  629. * @var integer Number of seconds between two reloads of the display (fast)
  630. */
  631. protected $m_iFastReloadInterval;
  632. /**
  633. * @var boolean Whether or not a secure connection is required for using the application.
  634. * If set, any attempt to connect to an iTop page with http:// will be redirected
  635. * to https://
  636. */
  637. protected $m_bSecureConnectionRequired;
  638. /**
  639. * @var string Langage code, default if the user language is undefined
  640. */
  641. protected $m_sDefaultLanguage;
  642. /**
  643. * @var string Type of login process allowed: form|basic|url|external
  644. */
  645. protected $m_sAllowedLoginTypes;
  646. /**
  647. * @var string Name of the PHP variable in which external authentication information is passed by the web server
  648. */
  649. protected $m_sExtAuthVariable;
  650. /**
  651. * @var string Encryption key used for all attributes of type "encrypted string". Can be set to a random value
  652. * unless you want to import a database from another iTop instance, in which case you must use
  653. * the same encryption key in order to properly decode the encrypted fields
  654. */
  655. protected $m_sEncryptionKey;
  656. /**
  657. * @var array Additional character sets to be supported by the interactive CSV import
  658. * 'iconv_code' => 'display name'
  659. */
  660. protected $m_aCharsets;
  661. public function __construct($sConfigFile = null, $bLoadConfig = true)
  662. {
  663. $this->m_sFile = $sConfigFile;
  664. if (is_null($sConfigFile))
  665. {
  666. $bLoadConfig = false;
  667. }
  668. $this->m_aAppModules = array(
  669. // Some default modules, always present can be move to an official iTop Module later if needed
  670. 'application/transaction.class.inc.php',
  671. 'application/menunode.class.inc.php',
  672. 'application/user.preferences.class.inc.php',
  673. 'application/user.dashboard.class.inc.php',
  674. 'application/audit.rule.class.inc.php',
  675. 'application/query.class.inc.php',
  676. // Romain - That's dirty, because those classes are in fact part of the core
  677. // but I needed those classes to be derived from cmdbAbstractObject
  678. // (to be managed via the GUI) and this class in not really known from
  679. // the core, PLUS I needed the includes to be there also for the setup
  680. // to create the tables.
  681. 'core/event.class.inc.php',
  682. 'core/action.class.inc.php',
  683. 'core/trigger.class.inc.php',
  684. 'synchro/synchrodatasource.class.inc.php',
  685. );
  686. $this->m_aDataModels = array();
  687. $this->m_aWebServiceCategories = array(
  688. 'webservices/webservices.basic.php',
  689. );
  690. $this->m_aAddons = array(
  691. // Default AddOn, always present can be moved to an official iTop Module later if needed
  692. 'user rights' => 'addons/userrights/userrightsprofile.class.inc.php',
  693. );
  694. $this->m_aDictionaries = self::ScanDictionariesDir();
  695. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  696. {
  697. $this->m_aSettings[$sPropCode]['value'] = $aSettingInfo['default'];
  698. }
  699. $this->m_sDBHost = '';
  700. $this->m_sDBUser = '';
  701. $this->m_sDBPwd = '';
  702. $this->m_sDBName = '';
  703. $this->m_sDBSubname = '';
  704. $this->m_sDBCharacterSet = DEFAULT_CHARACTER_SET;
  705. $this->m_sDBCollation = DEFAULT_COLLATION;
  706. $this->m_bLogGlobal = DEFAULT_LOG_GLOBAL;
  707. $this->m_bLogNotification = DEFAULT_LOG_NOTIFICATION;
  708. $this->m_bLogIssue = DEFAULT_LOG_ISSUE;
  709. $this->m_bLogWebService = DEFAULT_LOG_WEB_SERVICE;
  710. $this->m_bLogKPIDuration = DEFAULT_LOG_KPI_DURATION;
  711. $this->m_bLogKPIDuration = DEFAULT_LOG_KPI_DURATION;
  712. $this->m_iMinDisplayLimit = DEFAULT_MIN_DISPLAY_LIMIT;
  713. $this->m_iMaxDisplayLimit = DEFAULT_MAX_DISPLAY_LIMIT;
  714. $this->m_iStandardReloadInterval = DEFAULT_STANDARD_RELOAD_INTERVAL;
  715. $this->m_iFastReloadInterval = DEFAULT_FAST_RELOAD_INTERVAL;
  716. $this->m_bSecureConnectionRequired = DEFAULT_SECURE_CONNECTION_REQUIRED;
  717. $this->m_sDefaultLanguage = 'EN US';
  718. $this->m_sAllowedLoginTypes = DEFAULT_ALLOWED_LOGIN_TYPES;
  719. $this->m_sExtAuthVariable = DEFAULT_EXT_AUTH_VARIABLE;
  720. $this->m_sEncryptionKey = DEFAULT_ENCRYPTION_KEY;
  721. $this->m_aCharsets = array();
  722. $this->m_aModuleSettings = array();
  723. if ($bLoadConfig)
  724. {
  725. $this->Load($sConfigFile);
  726. $this->Verify();
  727. }
  728. // Application root url: set a default value, then normalize it
  729. /*
  730. * Does not work in CLI/unattended mode
  731. $sAppRootUrl = trim($this->Get('app_root_url'));
  732. if (strlen($sAppRootUrl) == 0)
  733. {
  734. $sAppRootUrl = utils::GetDefaultUrlAppRoot();
  735. }
  736. if (substr($sAppRootUrl, -1, 1) != '/')
  737. {
  738. $sAppRootUrl .= '/';
  739. }
  740. $this->Set('app_root_url', $sAppRootUrl);
  741. */
  742. }
  743. protected function CheckFile($sPurpose, $sFileName)
  744. {
  745. if (!file_exists($sFileName))
  746. {
  747. throw new ConfigException("Could not find $sPurpose file", array('file' => $sFileName));
  748. }
  749. if (!is_readable($sFileName))
  750. {
  751. 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));
  752. }
  753. }
  754. protected function Load($sConfigFile)
  755. {
  756. $this->CheckFile('configuration', $sConfigFile);
  757. $sConfigCode = trim(file_get_contents($sConfigFile));
  758. // This does not work on several lines
  759. // preg_match('/^<\\?php(.*)\\?'.'>$/', $sConfigCode, $aMatches)...
  760. // So, I've implemented a solution suggested in the PHP doc (search for phpWrapper)
  761. try
  762. {
  763. ob_start();
  764. eval('?'.'>'.trim($sConfigCode));
  765. $sNoise = trim(ob_get_contents());
  766. ob_end_clean();
  767. }
  768. catch (Exception $e)
  769. {
  770. // well, never reach in case of parsing error :-(
  771. // will be improved in PHP 6 ?
  772. throw new ConfigException('Error in configuration file', array('file' => $sConfigFile, 'error' => $e->getMessage()));
  773. }
  774. if (strlen($sNoise) > 0)
  775. {
  776. // Note: sNoise is an html output, but so far it was ok for me (e.g. showing the entire call stack)
  777. throw new ConfigException('Syntax error in configuration file', array('file' => $sConfigFile, 'error' => '<tt>'.htmlentities($sNoise, ENT_QUOTES, 'UTF-8').'</tt>'));
  778. }
  779. if (!isset($MySettings) || !is_array($MySettings))
  780. {
  781. throw new ConfigException('Missing array in configuration file', array('file' => $sConfigFile, 'expected' => '$MySettings'));
  782. }
  783. if (!isset($MyModules) || !is_array($MyModules))
  784. {
  785. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules'));
  786. }
  787. if (!array_key_exists('application', $MyModules))
  788. {
  789. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'application\']'));
  790. }
  791. if (!array_key_exists('business', $MyModules))
  792. {
  793. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'business\']'));
  794. }
  795. if (!array_key_exists('addons', $MyModules))
  796. {
  797. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'addons\']'));
  798. }
  799. if (!array_key_exists('user rights', $MyModules['addons']))
  800. {
  801. // Add one, by default
  802. $MyModules['addons']['user rights'] = '/addons/userrights/userrightsnull.class.inc.php';
  803. }
  804. if (!array_key_exists('dictionaries', $MyModules))
  805. {
  806. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'dictionaries\']'));
  807. }
  808. $this->m_aAppModules = $MyModules['application'];
  809. $this->m_aDataModels = $MyModules['business'];
  810. if (isset($MyModules['webservices']))
  811. {
  812. $this->m_aWebServiceCategories = $MyModules['webservices'];
  813. }
  814. $this->m_aAddons = $MyModules['addons'];
  815. $this->m_aDictionaries = $MyModules['dictionaries'];
  816. foreach($MySettings as $sPropCode => $rawvalue)
  817. {
  818. if ($this->IsProperty($sPropCode))
  819. {
  820. $value = trim($rawvalue);
  821. $this->Set($sPropCode, $value, $sConfigFile);
  822. }
  823. }
  824. $this->m_sDBHost = trim($MySettings['db_host']);
  825. $this->m_sDBUser = trim($MySettings['db_user']);
  826. $this->m_sDBPwd = trim($MySettings['db_pwd']);
  827. $this->m_sDBName = trim($MySettings['db_name']);
  828. $this->m_sDBSubname = trim($MySettings['db_subname']);
  829. $this->m_sDBCharacterSet = isset($MySettings['db_character_set']) ? trim($MySettings['db_character_set']) : DEFAULT_CHARACTER_SET;
  830. $this->m_sDBCollation = isset($MySettings['db_collation']) ? trim($MySettings['db_collation']) : DEFAULT_COLLATION;
  831. $this->m_bLogGlobal = isset($MySettings['log_global']) ? (bool) trim($MySettings['log_global']) : DEFAULT_LOG_GLOBAL;
  832. $this->m_bLogNotification = isset($MySettings['log_notification']) ? (bool) trim($MySettings['log_notification']) : DEFAULT_LOG_NOTIFICATION;
  833. $this->m_bLogIssue = isset($MySettings['log_issue']) ? (bool) trim($MySettings['log_issue']) : DEFAULT_LOG_ISSUE;
  834. $this->m_bLogWebService = isset($MySettings['log_web_service']) ? (bool) trim($MySettings['log_web_service']) : DEFAULT_LOG_WEB_SERVICE;
  835. $this->m_bLogKPIDuration = isset($MySettings['log_kpi_duration']) ? (bool) trim($MySettings['log_kpi_duration']) : DEFAULT_LOG_KPI_DURATION;
  836. $this->m_bLogKPIMemory = isset($MySettings['log_kpi_memory']) ? (bool) trim($MySettings['log_kpi_memory']) : DEFAULT_LOG_KPI_MEMORY;
  837. $this->m_bDebugQueries = isset($MySettings['debug_queries']) ? (bool) trim($MySettings['debug_queries']) : DEFAULT_DEBUG_QUERIES;
  838. $this->m_bQueryCacheEnabled = isset($MySettings['query_cache_enabled']) ? (bool) trim($MySettings['query_cache_enabled']) : DEFAULT_QUERY_CACHE_ENABLED;
  839. $this->m_iMinDisplayLimit = isset($MySettings['min_display_limit']) ? trim($MySettings['min_display_limit']) : DEFAULT_MIN_DISPLAY_LIMIT;
  840. $this->m_iMaxDisplayLimit = isset($MySettings['max_display_limit']) ? trim($MySettings['max_display_limit']) : DEFAULT_MAX_DISPLAY_LIMIT;
  841. $this->m_iStandardReloadInterval = isset($MySettings['standard_reload_interval']) ? trim($MySettings['standard_reload_interval']) : DEFAULT_STANDARD_RELOAD_INTERVAL;
  842. $this->m_iFastReloadInterval = isset($MySettings['fast_reload_interval']) ? trim($MySettings['fast_reload_interval']) : DEFAULT_FAST_RELOAD_INTERVAL;
  843. $this->m_bSecureConnectionRequired = isset($MySettings['secure_connection_required']) ? (bool) trim($MySettings['secure_connection_required']) : DEFAULT_SECURE_CONNECTION_REQUIRED;
  844. $this->m_aModuleSettings = isset($MyModuleSettings) ? $MyModuleSettings : array();
  845. $this->m_sDefaultLanguage = isset($MySettings['default_language']) ? trim($MySettings['default_language']) : 'EN US';
  846. $this->m_sAllowedLoginTypes = isset($MySettings['allowed_login_types']) ? trim($MySettings['allowed_login_types']) : DEFAULT_ALLOWED_LOGIN_TYPES;
  847. $this->m_sExtAuthVariable = isset($MySettings['ext_auth_variable']) ? trim($MySettings['ext_auth_variable']) : DEFAULT_EXT_AUTH_VARIABLE;
  848. $this->m_sEncryptionKey = isset($MySettings['encryption_key']) ? trim($MySettings['encryption_key']) : DEFAULT_ENCRYPTION_KEY;
  849. $this->m_aCharsets = isset($MySettings['csv_import_charsets']) ? $MySettings['csv_import_charsets'] : array();
  850. }
  851. protected function Verify()
  852. {
  853. // Files are verified later on, just before using them -see MetaModel::Plugin()
  854. // (we have their final path at that point)
  855. }
  856. public function GetModuleSetting($sModule, $sProperty, $defaultvalue = null)
  857. {
  858. if (isset($this->m_aModuleSettings[$sModule][$sProperty]))
  859. {
  860. return $this->m_aModuleSettings[$sModule][$sProperty];
  861. }
  862. return $defaultvalue;
  863. }
  864. public function SetModuleSetting($sModule, $sProperty, $value)
  865. {
  866. $this->m_aModuleSettings[$sModule][$sProperty] = $value;
  867. }
  868. public function GetAppModules()
  869. {
  870. return $this->m_aAppModules;
  871. }
  872. public function SetAppModules($aAppModules)
  873. {
  874. $this->m_aAppModules = $aAppModules;
  875. }
  876. public function GetDataModels()
  877. {
  878. return $this->m_aDataModels;
  879. }
  880. public function SetDataModels($aDataModels)
  881. {
  882. $this->m_aDataModels = $aDataModels;
  883. }
  884. public function GetWebServiceCategories()
  885. {
  886. return $this->m_aWebServiceCategories;
  887. }
  888. public function SetWebServiceCategories($aWebServiceCategories)
  889. {
  890. $this->m_aWebServiceCategories = $aWebServiceCategories;
  891. }
  892. public function GetAddons()
  893. {
  894. return $this->m_aAddons;
  895. }
  896. public function SetAddons($aAddons)
  897. {
  898. $this->m_aAddons = $aAddons;
  899. }
  900. public function GetDictionaries()
  901. {
  902. return $this->m_aDictionaries;
  903. }
  904. public function SetDictionaries($aDictionaries)
  905. {
  906. $this->m_aDictionaries = $aDictionaries;
  907. }
  908. public function GetDBHost()
  909. {
  910. return $this->m_sDBHost;
  911. }
  912. public function GetDBName()
  913. {
  914. return $this->m_sDBName;
  915. }
  916. public function GetDBSubname()
  917. {
  918. return $this->m_sDBSubname;
  919. }
  920. public function GetDBCharacterSet()
  921. {
  922. return $this->m_sDBCharacterSet;
  923. }
  924. public function GetDBCollation()
  925. {
  926. return $this->m_sDBCollation;
  927. }
  928. public function GetDBUser()
  929. {
  930. return $this->m_sDBUser;
  931. }
  932. public function GetDBPwd()
  933. {
  934. return $this->m_sDBPwd;
  935. }
  936. public function GetLogGlobal()
  937. {
  938. return $this->m_bLogGlobal;
  939. }
  940. public function GetLogNotification()
  941. {
  942. return $this->m_bLogNotification;
  943. }
  944. public function GetLogIssue()
  945. {
  946. return $this->m_bLogIssue;
  947. }
  948. public function GetLogWebService()
  949. {
  950. return $this->m_bLogWebService;
  951. }
  952. public function GetLogKPIDuration()
  953. {
  954. return $this->m_bLogKPIDuration;
  955. }
  956. public function GetLogKPIMemory()
  957. {
  958. return $this->m_bLogKPIMemory;
  959. }
  960. public function GetDebugQueries()
  961. {
  962. return $this->m_bDebugQueries;
  963. }
  964. public function GetQueryCacheEnabled()
  965. {
  966. return $this->m_bQueryCacheEnabled;
  967. }
  968. public function GetMinDisplayLimit()
  969. {
  970. return $this->m_iMinDisplayLimit;
  971. }
  972. public function GetMaxDisplayLimit()
  973. {
  974. return $this->m_iMaxDisplayLimit;
  975. }
  976. public function GetStandardReloadInterval()
  977. {
  978. return $this->m_iStandardReloadInterval;
  979. }
  980. public function GetFastReloadInterval()
  981. {
  982. return $this->m_iFastReloadInterval;
  983. }
  984. public function GetSecureConnectionRequired()
  985. {
  986. return $this->m_bSecureConnectionRequired;
  987. }
  988. public function GetDefaultLanguage()
  989. {
  990. return $this->m_sDefaultLanguage;
  991. }
  992. public function GetEncryptionKey()
  993. {
  994. return $this->m_sEncryptionKey;
  995. }
  996. public function GetAllowedLoginTypes()
  997. {
  998. return explode('|', $this->m_sAllowedLoginTypes);
  999. }
  1000. public function GetExternalAuthenticationVariable()
  1001. {
  1002. return $this->m_sExtAuthVariable;
  1003. }
  1004. public function GetCSVImportCharsets()
  1005. {
  1006. return $this->m_aCharsets;
  1007. }
  1008. public function SetDBHost($sDBHost)
  1009. {
  1010. $this->m_sDBHost = $sDBHost;
  1011. }
  1012. public function SetDBName($sDBName)
  1013. {
  1014. $this->m_sDBName = $sDBName;
  1015. }
  1016. public function SetDBSubname($sDBSubName)
  1017. {
  1018. $this->m_sDBSubname = $sDBSubName;
  1019. }
  1020. public function SetDBCharacterSet($sDBCharacterSet)
  1021. {
  1022. $this->m_sDBCharacterSet = $sDBCharacterSet;
  1023. }
  1024. public function SetDBCollation($sDBCollation)
  1025. {
  1026. $this->m_sDBCollation = $sDBCollation;
  1027. }
  1028. public function SetDBUser($sUser)
  1029. {
  1030. $this->m_sDBUser = $sUser;
  1031. }
  1032. public function SetDBPwd($sPwd)
  1033. {
  1034. $this->m_sDBPwd = $sPwd;
  1035. }
  1036. public function SetLogGlobal($iLogGlobal)
  1037. {
  1038. $this->m_iLogGlobal = $iLogGlobal;
  1039. }
  1040. public function SetLogNotification($iLogNotification)
  1041. {
  1042. $this->m_iLogNotification = $iLogNotification;
  1043. }
  1044. public function SetLogIssue($iLogIssue)
  1045. {
  1046. $this->m_iLogIssue = $iLogIssue;
  1047. }
  1048. public function SetLogWebService($iLogWebService)
  1049. {
  1050. $this->m_iLogWebService = $iLogWebService;
  1051. }
  1052. public function SetMinDisplayLimit($iMinDisplayLimit)
  1053. {
  1054. $this->m_iMinDisplayLimit = $iMinDisplayLimit;
  1055. }
  1056. public function SetMaxDisplayLimit($iMaxDisplayLimit)
  1057. {
  1058. $this->m_iMaxDisplayLimit = $iMaxDisplayLimit;
  1059. }
  1060. public function SetStandardReloadInterval($iStandardReloadInterval)
  1061. {
  1062. $this->m_iStandardReloadInterval = $iStandardReloadInterval;
  1063. }
  1064. public function SetFastReloadInterval($iFastReloadInterval)
  1065. {
  1066. $this->m_iFastReloadInterval = $iFastReloadInterval;
  1067. }
  1068. public function SetSecureConnectionRequired($bSecureConnectionRequired)
  1069. {
  1070. $this->m_bSecureConnectionRequired = $bSecureConnectionRequired;
  1071. }
  1072. public function SetDefaultLanguage($sLanguageCode)
  1073. {
  1074. $this->m_sDefaultLanguage = $sLanguageCode;
  1075. }
  1076. public function SetAllowedLoginTypes($aAllowedLoginTypes)
  1077. {
  1078. $this->m_sAllowedLoginTypes = implode('|', $aAllowedLoginTypes);
  1079. }
  1080. public function SetExternalAuthenticationVariable($sExtAuthVariable)
  1081. {
  1082. $this->m_sExtAuthVariable = $sExtAuthVariable;
  1083. }
  1084. public function SetEncryptionKey($sKey)
  1085. {
  1086. $this->m_sEncryptionKey = $sKey;
  1087. }
  1088. public function SetCSVImportCharsets($aCharsets)
  1089. {
  1090. $this->m_aCharsets = $aCharsets;
  1091. }
  1092. public function AddCSVImportCharset($sIconvCode, $sDisplayName)
  1093. {
  1094. $this->m_aCharsets[$sIconvCode] = $sDisplayName;
  1095. }
  1096. public function GetLoadedFile()
  1097. {
  1098. if (is_null($this->m_sFile))
  1099. {
  1100. return '';
  1101. }
  1102. else
  1103. {
  1104. return $this->m_sFile;
  1105. }
  1106. }
  1107. /**
  1108. * Render the configuration as an associative array
  1109. * @return boolean True otherwise throws an Exception
  1110. */
  1111. public function ToArray()
  1112. {
  1113. $aSettings = array();
  1114. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  1115. {
  1116. $aSettings[$sPropCode] = $aSettingInfo['value'];
  1117. }
  1118. $aSettings['db_host'] = $this->m_sDBHost;
  1119. $aSettings['db_user'] = $this->m_sDBUser;
  1120. $aSettings['db_pwd'] = $this->m_sDBPwd;
  1121. $aSettings['db_name'] = $this->m_sDBName;
  1122. $aSettings['db_subname'] = $this->m_sDBSubname;
  1123. $aSettings['db_character_set'] = $this->m_sDBCharacterSet;
  1124. $aSettings['db_collation'] = $this->m_sDBCollation;
  1125. $aSettings['log_global'] = $this->m_bLogGlobal;
  1126. $aSettings['log_notification'] = $this->m_bLogNotification;
  1127. $aSettings['log_issue'] = $this->m_bLogIssue;
  1128. $aSettings['log_web_service'] = $this->m_bLogWebService;
  1129. $aSettings['min_display_limit'] = $this->m_iMinDisplayLimit;
  1130. $aSettings['max_display_limit'] = $this->m_iMaxDisplayLimit;
  1131. $aSettings['standard_reload_interval'] = $this->m_iStandardReloadInterval;
  1132. $aSettings['fast_reload_interval'] = $this->m_iFastReloadInterval;
  1133. $aSettings['secure_connection_required'] = $this->m_bSecureConnectionRequired;
  1134. $aSettings['default_language'] = $this->m_sDefaultLanguage;
  1135. $aSettings['allowed_login_types'] = $this->m_sAllowedLoginTypes;
  1136. $aSettings['encryption_key'] = $this->m_sEncryptionKey;
  1137. $aSettings['csv_import_charsets'] = $this->m_aCharsets;
  1138. foreach ($this->m_aModuleSettings as $sModule => $aProperties)
  1139. {
  1140. foreach ($aProperties as $sProperty => $value)
  1141. {
  1142. $aSettings['module_settings'][$sModule][$sProperty] = $value;
  1143. }
  1144. }
  1145. foreach($this->m_aAppModules as $sFile)
  1146. {
  1147. $aSettings['application_list'][] = $sFile;
  1148. }
  1149. foreach($this->m_aDataModels as $sFile)
  1150. {
  1151. $aSettings['datamodel_list'][] = $sFile;
  1152. }
  1153. foreach($this->m_aWebServiceCategories as $sFile)
  1154. {
  1155. $aSettings['webservice_list'][] = $sFile;
  1156. }
  1157. foreach($this->m_aAddons as $sKey => $sFile)
  1158. {
  1159. $aSettings['addon_list'][] = $sFile;
  1160. }
  1161. foreach($this->m_aDictionaries as $sFile)
  1162. {
  1163. $aSettings['dictionary_list'][] = $sFile;
  1164. }
  1165. return $aSettings;
  1166. }
  1167. /**
  1168. * Write the configuration to a file (php format) that can be reloaded later
  1169. * By default write to the same file that was specified when constructing the object
  1170. * @param $sFileName string Name of the file to write to (emtpy to write to the same file)
  1171. * @return boolean True otherwise throws an Exception
  1172. */
  1173. public function WriteToFile($sFileName = '')
  1174. {
  1175. if (empty($sFileName))
  1176. {
  1177. $sFileName = $this->m_sFile;
  1178. }
  1179. $hFile = @fopen($sFileName, 'w');
  1180. if ($hFile !== false)
  1181. {
  1182. fwrite($hFile, "<?php\n");
  1183. fwrite($hFile, "\n/**\n");
  1184. fwrite($hFile, " *\n");
  1185. fwrite($hFile, " * Configuration file, generated by the ".ITOP_APPLICATION." configuration wizard\n");
  1186. fwrite($hFile, " *\n");
  1187. fwrite($hFile, " * The file is used in MetaModel::LoadConfig() which does all the necessary initialization job\n");
  1188. fwrite($hFile, " *\n");
  1189. fwrite($hFile, " */\n");
  1190. $aConfigSettings = $this->m_aSettings;
  1191. // Old fashioned boolean settings
  1192. $aBoolValues = array(
  1193. 'log_global' => $this->m_bLogGlobal,
  1194. 'log_notification' => $this->m_bLogNotification,
  1195. 'log_issue' => $this->m_bLogIssue,
  1196. 'log_web_service' => $this->m_bLogWebService,
  1197. 'secure_connection_required' => $this->m_bSecureConnectionRequired,
  1198. );
  1199. foreach($aBoolValues as $sKey => $bValue)
  1200. {
  1201. $aConfigSettings[$sKey] = array(
  1202. 'show_in_conf_sample' => true,
  1203. 'type' => 'bool',
  1204. 'value' => $bValue,
  1205. );
  1206. }
  1207. // Old fashioned integer settings
  1208. $aIntValues = array(
  1209. 'fast_reload_interval' => $this->m_iFastReloadInterval,
  1210. 'max_display_limit' => $this->m_iMaxDisplayLimit,
  1211. 'min_display_limit' => $this->m_iMinDisplayLimit,
  1212. 'standard_reload_interval' => $this->m_iStandardReloadInterval,
  1213. );
  1214. foreach($aIntValues as $sKey => $iValue)
  1215. {
  1216. $aConfigSettings[$sKey] = array(
  1217. 'show_in_conf_sample' => true,
  1218. 'type' => 'integer',
  1219. 'value' => $iValue,
  1220. );
  1221. }
  1222. // Old fashioned remaining values
  1223. $aOtherValues = array(
  1224. 'db_host' => $this->m_sDBHost,
  1225. 'db_user' => $this->m_sDBUser,
  1226. 'db_pwd' => $this->m_sDBPwd,
  1227. 'db_name' => $this->m_sDBName,
  1228. 'db_subname' => $this->m_sDBSubname,
  1229. 'db_character_set' => $this->m_sDBCharacterSet,
  1230. 'db_collation' => $this->m_sDBCollation,
  1231. 'default_language' => $this->m_sDefaultLanguage,
  1232. 'allowed_login_types' => $this->m_sAllowedLoginTypes,
  1233. 'encryption_key' => $this->m_sEncryptionKey,
  1234. 'csv_import_charsets' => $this->m_aCharsets,
  1235. );
  1236. foreach($aOtherValues as $sKey => $value)
  1237. {
  1238. $aConfigSettings[$sKey] = array(
  1239. 'show_in_conf_sample' => true,
  1240. 'type' => is_string($value) ? 'string' : 'mixed',
  1241. 'value' => $value,
  1242. );
  1243. }
  1244. ksort($aConfigSettings);
  1245. fwrite($hFile, "\$MySettings = array(\n");
  1246. foreach($aConfigSettings as $sPropCode => $aSettingInfo)
  1247. {
  1248. // Write all values that are either always visible or present in the cloned config file
  1249. if ($aSettingInfo['show_in_conf_sample'] || ($aSettingInfo['source_of_value'] != 'unknown') )
  1250. {
  1251. $sType = $aSettingInfo['type'];
  1252. switch($sType)
  1253. {
  1254. case 'bool':
  1255. $sSeenAs = $aSettingInfo['value'] ? 'true' : 'false';
  1256. break;
  1257. default:
  1258. $sSeenAs = self::PrettyVarExport($aSettingInfo['value'], "\t");
  1259. }
  1260. fwrite($hFile, "\n");
  1261. if (isset($aSettingInfo['description']))
  1262. {
  1263. fwrite($hFile, "\t// $sPropCode: {$aSettingInfo['description']}\n");
  1264. }
  1265. if (isset($aSettingInfo['default']))
  1266. {
  1267. $default = $aSettingInfo['default'];
  1268. if ($aSettingInfo['type'] == 'bool')
  1269. {
  1270. $default = $default ? 'true' : 'false';
  1271. }
  1272. fwrite($hFile, "\t//\tdefault: ".self::PrettyVarExport($aSettingInfo['default'],"\t//\t\t", true)."\n");
  1273. }
  1274. fwrite($hFile, "\t'$sPropCode' => $sSeenAs,\n");
  1275. }
  1276. }
  1277. fwrite($hFile, ");\n");
  1278. fwrite($hFile, "\n");
  1279. fwrite($hFile, "/**\n *\n * Modules specific settings\n *\n */\n");
  1280. fwrite($hFile, "\$MyModuleSettings = array(\n");
  1281. foreach ($this->m_aModuleSettings as $sModule => $aProperties)
  1282. {
  1283. fwrite($hFile, "\t'$sModule' => array (\n");
  1284. foreach ($aProperties as $sProperty => $value)
  1285. {
  1286. $sNiceExport = self::PrettyVarExport($value, "\t\t");
  1287. fwrite($hFile, "\t\t'$sProperty' => $sNiceExport,\n");
  1288. }
  1289. fwrite($hFile, "\t),\n");
  1290. }
  1291. fwrite($hFile, ");\n");
  1292. fwrite($hFile, "\n/**\n");
  1293. fwrite($hFile, " *\n");
  1294. fwrite($hFile, " * Data model modules to be loaded. Names are specified as relative paths\n");
  1295. fwrite($hFile, " *\n");
  1296. fwrite($hFile, " */\n");
  1297. fwrite($hFile, "\$MyModules = array(\n");
  1298. fwrite($hFile, "\t'application' => array (\n");
  1299. foreach($this->m_aAppModules as $sFile)
  1300. {
  1301. fwrite($hFile, "\t\t'$sFile',\n");
  1302. }
  1303. fwrite($hFile, "\t),\n");
  1304. fwrite($hFile, "\t'business' => array (\n");
  1305. foreach($this->m_aDataModels as $sFile)
  1306. {
  1307. fwrite($hFile, "\t\t'$sFile',\n");
  1308. }
  1309. fwrite($hFile, "\t),\n");
  1310. fwrite($hFile, "\t'webservices' => array (\n");
  1311. foreach($this->m_aWebServiceCategories as $sFile)
  1312. {
  1313. fwrite($hFile, "\t\t'$sFile',\n");
  1314. }
  1315. fwrite($hFile, "\t),\n");
  1316. fwrite($hFile, "\t'addons' => array (\n");
  1317. foreach($this->m_aAddons as $sKey => $sFile)
  1318. {
  1319. fwrite($hFile, "\t\t'$sKey' => '$sFile',\n");
  1320. }
  1321. fwrite($hFile, "\t),\n");
  1322. fwrite($hFile, "\t'dictionaries' => array (\n");
  1323. foreach($this->m_aDictionaries as $sFile)
  1324. {
  1325. fwrite($hFile, "\t\t'$sFile',\n");
  1326. }
  1327. fwrite($hFile, "\t),\n");
  1328. fwrite($hFile, ");\n");
  1329. fwrite($hFile, '?'.'>'); // Avoid perturbing the syntax highlighting !
  1330. return fclose($hFile);
  1331. }
  1332. else
  1333. {
  1334. throw new ConfigException("Could not write to configuration file", array('file' => $sFileName));
  1335. }
  1336. }
  1337. protected static function ScanDictionariesDir()
  1338. {
  1339. $aResult = array();
  1340. // Populate automatically the list of dictionary files
  1341. $sDir = APPROOT.'/dictionaries';
  1342. if ($hDir = @opendir($sDir))
  1343. {
  1344. while (($sFile = readdir($hDir)) !== false)
  1345. {
  1346. $aMatches = array();
  1347. if (preg_match("/^([^\.]+\.)?dictionary\.itop\.(ui|core)\.php$/i", $sFile, $aMatches)) // Dictionary files named like [<Lang>.]dictionary.[core|ui].php are loaded automatically
  1348. {
  1349. $aResult[] = 'dictionaries/'.$sFile;
  1350. }
  1351. }
  1352. closedir($hDir);
  1353. }
  1354. return $aResult;
  1355. }
  1356. /**
  1357. * Helper function to initialize a configuration from the page arguments
  1358. */
  1359. public function UpdateFromParams($aParamValues, $sModulesDir = null, $bPreserveModuleSettings = false)
  1360. {
  1361. if (isset($aParamValues['application_path']))
  1362. {
  1363. $this->Set('app_root_url', $aParamValues['application_path']);
  1364. }
  1365. if (isset($aParamValues['mode']) && isset($aParamValues['language']))
  1366. {
  1367. if (($aParamValues['mode'] == 'install') || $this->GetDefaultLanguage() == '')
  1368. {
  1369. $this->SetDefaultLanguage($aParamValues['language']);
  1370. }
  1371. }
  1372. if (isset($aParamValues['db_server']))
  1373. {
  1374. $this->SetDBHost($aParamValues['db_server']);
  1375. $this->SetDBUser($aParamValues['db_user']);
  1376. $this->SetDBPwd($aParamValues['db_pwd']);
  1377. $sDBName = $aParamValues['db_name'];
  1378. if ($sDBName == '')
  1379. {
  1380. // Todo - obsolete after the transition to the new setup (2.0) is complete (WARNING: used by the designer)
  1381. $sDBName = $aParamValues['new_db_name'];
  1382. }
  1383. $this->SetDBName($sDBName);
  1384. $this->SetDBSubname($aParamValues['db_prefix']);
  1385. }
  1386. if (!is_null($sModulesDir))
  1387. {
  1388. if (isset($aParamValues['selected_modules']))
  1389. {
  1390. $aSelectedModules = explode(',', $aParamValues['selected_modules']);
  1391. }
  1392. else
  1393. {
  1394. $aSelectedModules = null;
  1395. }
  1396. // Initialize the arrays below with default values for the application...
  1397. $oEmptyConfig = new Config('dummy_file', false); // Do NOT load any config file, just set the default values
  1398. $aAddOns = $oEmptyConfig->GetAddOns();
  1399. $aAppModules = $oEmptyConfig->GetAppModules();
  1400. $aDataModels = $oEmptyConfig->GetDataModels();
  1401. $aWebServiceCategories = $oEmptyConfig->GetWebServiceCategories();
  1402. $aDictionaries = $oEmptyConfig->GetDictionaries();
  1403. // Merge the values with the ones provided by the modules
  1404. // Make sure when don't load the same file twice...
  1405. $aModules = ModuleDiscovery::GetAvailableModules(array(APPROOT.$sModulesDir));
  1406. foreach($aModules as $sModuleId => $aModuleInfo)
  1407. {
  1408. list($sModuleName, $sModuleVersion) = ModuleDiscovery::GetModuleName($sModuleId);
  1409. if (is_null($aSelectedModules) || in_array($sModuleName, $aSelectedModules))
  1410. {
  1411. if (isset($aModuleInfo['datamodel']))
  1412. {
  1413. $aDataModels = array_unique(array_merge($aDataModels, $aModuleInfo['datamodel']));
  1414. }
  1415. if (isset($aModuleInfo['webservice']))
  1416. {
  1417. $aWebServiceCategories = array_unique(array_merge($aWebServiceCategories, $aModuleInfo['webservice']));
  1418. }
  1419. if (isset($aModuleInfo['dictionary']))
  1420. {
  1421. $aDictionaries = array_unique(array_merge($aDictionaries, $aModuleInfo['dictionary']));
  1422. }
  1423. if (isset($aModuleInfo['settings']))
  1424. {
  1425. list($sName, $sVersion) = ModuleDiscovery::GetModuleName($sModuleId);
  1426. foreach($aModuleInfo['settings'] as $sProperty => $value)
  1427. {
  1428. if ($bPreserveModuleSettings && isset($this->m_aModuleSettings[$sName][$sProperty]))
  1429. {
  1430. // Do nothing keep the original value
  1431. }
  1432. else
  1433. {
  1434. $this->SetModuleSetting($sName, $sProperty, $value);
  1435. }
  1436. }
  1437. }
  1438. if (isset($aModuleInfo['installer']))
  1439. {
  1440. $sModuleInstallerClass = $aModuleInfo['installer'];
  1441. if (!class_exists($sModuleInstallerClass))
  1442. {
  1443. throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not a PHP class - Module: ".$aModuleInfo['label']);
  1444. }
  1445. if (!is_subclass_of($sModuleInstallerClass, 'ModuleInstallerAPI'))
  1446. {
  1447. throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not derived from 'ModuleInstallerAPI' - Module: ".$aModuleInfo['label']);
  1448. }
  1449. $aCallSpec = array($sModuleInstallerClass, 'BeforeWritingConfig');
  1450. call_user_func_array($aCallSpec, array($this));
  1451. }
  1452. }
  1453. }
  1454. $this->SetAddOns($aAddOns);
  1455. $this->SetAppModules($aAppModules);
  1456. $this->SetDataModels($aDataModels);
  1457. $this->SetWebServiceCategories($aWebServiceCategories);
  1458. $this->SetDictionaries($aDictionaries);
  1459. }
  1460. }
  1461. /**
  1462. * Helper: for an array of string, change the prefix when found
  1463. */
  1464. protected static function ChangePrefix(&$aStrings, $sSearchPrefix, $sNewPrefix)
  1465. {
  1466. foreach ($aStrings as &$sFile)
  1467. {
  1468. if (substr($sFile, 0, strlen($sSearchPrefix)) == $sSearchPrefix)
  1469. {
  1470. $sFile = $sNewPrefix.substr($sFile, strlen($sSearchPrefix));
  1471. }
  1472. }
  1473. }
  1474. /**
  1475. * Quick an dirty way to clone a config file into another environment
  1476. */
  1477. public function ChangeModulesPath($sSourceEnv, $sTargetEnv)
  1478. {
  1479. $sSearchPrefix = 'env-'.$sSourceEnv.'/';
  1480. $sNewPrefix = 'env-'.$sTargetEnv.'/';
  1481. self::ChangePrefix($this->m_aDataModels, $sSearchPrefix, $sNewPrefix);
  1482. self::ChangePrefix($this->m_aWebServiceCategories, $sSearchPrefix, $sNewPrefix);
  1483. self::ChangePrefix($this->m_aDictionaries, $sSearchPrefix, $sNewPrefix);
  1484. }
  1485. /**
  1486. * Pretty format a var_export'ed value so that (if possible) the identation is preserved on every line
  1487. * @param mixed $value The value to export
  1488. * @param string $sIdentation The string to use to indent the text
  1489. * @param bool $bForceIndentation Forces the identation (enven if it breaks/changes an eval, for example to ouput a value inside a comment)
  1490. * @return string The indented export string
  1491. */
  1492. protected static function PrettyVarExport($value, $sIdentation, $bForceIndentation = false)
  1493. {
  1494. $sExport = var_export($value, true);
  1495. $sNiceExport = trim(preg_replace("/^/m", "\t\t\t", $sExport));
  1496. if (!$bForceIndentation)
  1497. {
  1498. eval('$aImported='.$sNiceExport.';');
  1499. // Check if adding the identations at the beginning of each line
  1500. // did not modify the values (in case of a string containing a line break)
  1501. if($aImported != $value)
  1502. {
  1503. $sNiceExport = $sExport;
  1504. }
  1505. }
  1506. return $sNiceExport;
  1507. }
  1508. }
  1509. ?>