config.class.inc.php 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849
  1. <?php
  2. // Copyright (C) 2010-2017 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-2016 Combodo SARL
  30. * @license http://opensource.org/licenses/AGPL-3.0
  31. */
  32. require_once('coreexception.class.inc.php');
  33. require_once('attributedef.class.inc.php'); // For the defines
  34. class ConfigException extends CoreException
  35. {
  36. }
  37. define ('DEFAULT_CHARACTER_SET', 'utf8');
  38. define ('DEFAULT_COLLATION', 'utf8_unicode_ci');
  39. define ('DEFAULT_LOG_GLOBAL', true);
  40. define ('DEFAULT_LOG_NOTIFICATION', true);
  41. define ('DEFAULT_LOG_ISSUE', true);
  42. define ('DEFAULT_LOG_WEB_SERVICE', true);
  43. define ('DEFAULT_QUERY_CACHE_ENABLED', true);
  44. define ('DEFAULT_MIN_DISPLAY_LIMIT', 10);
  45. define ('DEFAULT_MAX_DISPLAY_LIMIT', 15);
  46. define ('DEFAULT_STANDARD_RELOAD_INTERVAL', 5*60);
  47. define ('DEFAULT_FAST_RELOAD_INTERVAL', 1*60);
  48. define ('DEFAULT_SECURE_CONNECTION_REQUIRED', false);
  49. define ('DEFAULT_ALLOWED_LOGIN_TYPES', 'form|basic|external');
  50. define ('DEFAULT_EXT_AUTH_VARIABLE', '$_SERVER[\'REMOTE_USER\']');
  51. define ('DEFAULT_ENCRYPTION_KEY', '@iT0pEncr1pti0n!'); // We'll use a random value, later...
  52. /**
  53. * Config
  54. * configuration data (this class cannot not be localized, because it is responsible for loading the dictionaries)
  55. *
  56. * @package iTopORM
  57. */
  58. class Config
  59. {
  60. //protected $m_bIsLoaded = false;
  61. protected $m_sFile = '';
  62. protected $m_aAppModules;
  63. protected $m_aDataModels;
  64. protected $m_aWebServiceCategories;
  65. protected $m_aAddons;
  66. protected $m_aModuleSettings;
  67. // New way to store the settings !
  68. //
  69. protected $m_aSettings = array(
  70. 'app_env_label' => array(
  71. 'type' => 'string',
  72. 'description' => 'Label displayed to describe the current application environnment, defaults to the environment name (e.g. "production")',
  73. 'default' => '',
  74. 'value' => '',
  75. 'source_of_value' => '',
  76. 'show_in_conf_sample' => false,
  77. ),
  78. 'app_root_url' => array(
  79. 'type' => 'string',
  80. '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)',
  81. 'default' => '',
  82. 'value' => '',
  83. 'source_of_value' => '',
  84. 'show_in_conf_sample' => true,
  85. ),
  86. 'app_icon_url' => array(
  87. 'type' => 'string',
  88. 'description' => 'Hyperlink to redirect the user when clicking on the application icon (in the main window, or login/logoff pages)',
  89. 'default' => 'http://www.combodo.com/itop',
  90. 'value' => '',
  91. 'source_of_value' => '',
  92. 'show_in_conf_sample' => false,
  93. ),
  94. 'skip_check_to_write' => array(
  95. 'type' => 'bool',
  96. 'description' => 'Disable data format and integrity checks to boost up data load (insert or update)',
  97. 'default' => false,
  98. 'value' => false,
  99. 'source_of_value' => '',
  100. 'show_in_conf_sample' => false,
  101. ),
  102. 'skip_check_ext_keys' => array(
  103. 'type' => 'bool',
  104. 'description' => 'Disable external key check when checking the value of attributes',
  105. 'default' => false,
  106. 'value' => false,
  107. 'source_of_value' => '',
  108. 'show_in_conf_sample' => false,
  109. ),
  110. 'skip_strong_security' => array(
  111. 'type' => 'bool',
  112. 'description' => 'Disable strong security - TEMPORY: this flag should be removed when we are more confident in the recent change in security',
  113. 'default' => true,
  114. 'value' => true,
  115. 'source_of_value' => '',
  116. 'show_in_conf_sample' => false,
  117. ),
  118. 'query_optimization_enabled' => array(
  119. 'type' => 'bool',
  120. 'description' => 'The queries are optimized based on the assumption that the DB integrity has been preserved. By disabling the optimization one can ensure that the fetched data is clean... but this can be really slower or not usable at all (some queries will exceed the allowed number of joins in MySQL: 61!)',
  121. 'default' => true,
  122. 'value' => true,
  123. 'source_of_value' => '',
  124. 'show_in_conf_sample' => false,
  125. ),
  126. 'query_indentation_enabled' => array(
  127. 'type' => 'bool',
  128. 'description' => 'For developpers: format the SQL queries for human analysis',
  129. 'default' => false,
  130. 'value' => false,
  131. 'source_of_value' => '',
  132. 'show_in_conf_sample' => false,
  133. ),
  134. 'disable_mandatory_ext_keys' => array(
  135. 'type' => 'bool',
  136. 'description' => 'For developpers: allow every external keys to be undefined',
  137. 'default' => false,
  138. 'value' => false,
  139. 'source_of_value' => '',
  140. 'show_in_conf_sample' => false,
  141. ),
  142. 'graphviz_path' => array(
  143. 'type' => 'string',
  144. 'description' => 'Path to the Graphviz "dot" executable for graphing objects lifecycle',
  145. 'default' => '/usr/bin/dot',
  146. 'value' => '',
  147. 'source_of_value' => '',
  148. 'show_in_conf_sample' => true,
  149. ),
  150. 'php_path' => array(
  151. 'type' => 'string',
  152. 'description' => 'Path to the php executable in CLI mode',
  153. 'default' => 'php',
  154. 'value' => 'php',
  155. 'source_of_value' => '',
  156. 'show_in_conf_sample' => true,
  157. ),
  158. 'session_name' => array(
  159. 'type' => 'string',
  160. 'description' => 'The name of the cookie used to store the PHP session id',
  161. 'default' => 'iTop',
  162. 'value' => '',
  163. 'source_of_value' => '',
  164. 'show_in_conf_sample' => true,
  165. ),
  166. 'max_combo_length' => array(
  167. 'type' => 'integer',
  168. 'description' => 'The maximum number of elements in a drop-down list. If more then an autocomplete will be used',
  169. 'default' => 50,
  170. 'value' => 50,
  171. 'source_of_value' => '',
  172. 'show_in_conf_sample' => false,
  173. ),
  174. 'min_autocomplete_chars' => array(
  175. 'type' => 'integer',
  176. 'description' => 'The minimum number of characters to type in order to trigger the "autocomplete" behavior',
  177. 'default' => 3,
  178. 'value' => 3,
  179. 'source_of_value' => '',
  180. 'show_in_conf_sample' => false,
  181. ),
  182. 'allow_target_creation' => array(
  183. 'type' => 'bool',
  184. 'description' => 'Displays the + button on external keys to create target objects',
  185. 'default' => true,
  186. 'value' => true,
  187. 'source_of_value' => '',
  188. 'show_in_conf_sample' => false,
  189. ),
  190. // Levels that trigger a confirmation in the CSV import/synchro wizard
  191. 'csv_import_min_object_confirmation' => array(
  192. 'type' => 'integer',
  193. 'description' => 'Minimum number of objects to check for the confirmation percentages',
  194. 'default' => 3,
  195. 'value' => 3,
  196. 'source_of_value' => '',
  197. 'show_in_conf_sample' => false,
  198. ),
  199. 'csv_import_errors_percentage' => array(
  200. 'type' => 'integer',
  201. 'description' => 'Percentage of errors that trigger a confirmation in the CSV import',
  202. 'default' => 50,
  203. 'value' => 50,
  204. 'source_of_value' => '',
  205. 'show_in_conf_sample' => false,
  206. ),
  207. 'csv_import_modifications_percentage' => array(
  208. 'type' => 'integer',
  209. 'description' => 'Percentage of modifications that trigger a confirmation in the CSV import',
  210. 'default' => 50,
  211. 'value' => 50,
  212. 'source_of_value' => '',
  213. 'show_in_conf_sample' => false,
  214. ),
  215. 'csv_import_creations_percentage' => array(
  216. 'type' => 'integer',
  217. 'description' => 'Percentage of creations that trigger a confirmation in the CSV import',
  218. 'default' => 50,
  219. 'value' => 50,
  220. 'source_of_value' => '',
  221. 'show_in_conf_sample' => false,
  222. ),
  223. 'csv_import_history_display' => array(
  224. 'type' => 'bool',
  225. 'description' => 'Display the history tab in the import wizard',
  226. 'default' => false,
  227. 'value' => false,
  228. 'source_of_value' => '',
  229. 'show_in_conf_sample' => true,
  230. ),
  231. 'access_mode' => array(
  232. 'type' => 'integer',
  233. 'description' => 'Access mode: ACCESS_READONLY = 0, ACCESS_ADMIN_WRITE = 2, ACCESS_FULL = 3',
  234. 'default' => ACCESS_FULL,
  235. 'value' => ACCESS_FULL,
  236. 'source_of_value' => '',
  237. 'show_in_conf_sample' => true,
  238. ),
  239. 'access_message' => array(
  240. 'type' => 'string',
  241. 'description' => 'Message displayed to the users when there is any access restriction',
  242. 'default' => 'iTop is temporarily frozen, please wait... (the admin team)',
  243. 'value' => '',
  244. 'source_of_value' => '',
  245. 'show_in_conf_sample' => true,
  246. ),
  247. 'online_help' => array(
  248. 'type' => 'string',
  249. 'description' => 'Hyperlink to the online-help web page',
  250. 'default' => 'http://www.combodo.com/itop-help',
  251. 'value' => '',
  252. 'source_of_value' => '',
  253. 'show_in_conf_sample' => true,
  254. ),
  255. 'log_usage' => array(
  256. 'type' => 'bool',
  257. 'description' => 'Log the usage of the application (i.e. the date/time and the user name of each login)',
  258. 'default' => false,
  259. 'value' => false,
  260. 'source_of_value' => '',
  261. 'show_in_conf_sample' => false,
  262. ),
  263. 'log_rest_service' => array(
  264. 'type' => 'bool',
  265. 'description' => 'Log the usage of the REST/JSON service',
  266. 'default' => false,
  267. 'value' => false,
  268. 'source_of_value' => '',
  269. 'show_in_conf_sample' => false,
  270. ),
  271. 'synchro_trace' => array(
  272. 'type' => 'string',
  273. 'description' => 'Synchronization details: none, display, save (includes \'display\')',
  274. 'default' => 'none',
  275. 'value' => 'none',
  276. 'source_of_value' => '',
  277. 'show_in_conf_sample' => true,
  278. ),
  279. 'link_set_item_separator' => array(
  280. 'type' => 'string',
  281. 'description' => 'Link set from string: line separator',
  282. 'default' => '|',
  283. 'value' => '|',
  284. 'source_of_value' => '',
  285. 'show_in_conf_sample' => true,
  286. ),
  287. 'link_set_attribute_separator' => array(
  288. 'type' => 'string',
  289. 'description' => 'Link set from string: attribute separator',
  290. 'default' => ';',
  291. 'value' => ';',
  292. 'source_of_value' => '',
  293. 'show_in_conf_sample' => true,
  294. ),
  295. 'link_set_value_separator' => array(
  296. 'type' => 'string',
  297. 'description' => 'Link set from string: value separator (between the attcode and the value itself',
  298. 'default' => ':',
  299. 'value' => ':',
  300. 'source_of_value' => '',
  301. 'show_in_conf_sample' => true,
  302. ),
  303. 'link_set_attribute_qualifier' => array(
  304. 'type' => 'string',
  305. 'description' => 'Link set from string: attribute qualifier (encloses both the attcode and the value)',
  306. 'default' => "'",
  307. 'value' => "'",
  308. 'source_of_value' => '',
  309. 'show_in_conf_sample' => true,
  310. ),
  311. 'cron_max_execution_time' => array(
  312. 'type' => 'integer',
  313. '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',
  314. 'default' => 600,
  315. 'value' => 600,
  316. 'source_of_value' => '',
  317. 'show_in_conf_sample' => true,
  318. ),
  319. 'cron_sleep' => array(
  320. 'type' => 'integer',
  321. 'description' => 'Duration (seconds) before cron.php checks again if something must be done',
  322. 'default' => 2,
  323. 'value' => 2,
  324. 'source_of_value' => '',
  325. 'show_in_conf_sample' => false,
  326. ),
  327. 'async_task_retries' => array(
  328. 'type' => 'array',
  329. 'description' => 'Automatic retries of asynchronous tasks in case of failure (per class)',
  330. 'default' => array('AsyncSendEmail' => array('max_retries' => 0, 'retry_delay' => 600)),
  331. 'value' => false,
  332. 'source_of_value' => '',
  333. 'show_in_conf_sample' => false,
  334. ),
  335. 'email_asynchronous' => array(
  336. 'type' => 'bool',
  337. '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',
  338. 'default' => false,
  339. 'value' => false,
  340. 'source_of_value' => '',
  341. 'show_in_conf_sample' => true,
  342. ),
  343. 'email_transport' => array(
  344. 'type' => 'string',
  345. 'description' => 'Mean to send emails: PHPMail (uses the function mail()) or SMTP (implements the client protocole)',
  346. 'default' => "PHPMail",
  347. 'value' => "PHPMail",
  348. 'source_of_value' => '',
  349. 'show_in_conf_sample' => true,
  350. ),
  351. 'email_transport_smtp.host' => array(
  352. 'type' => 'string',
  353. 'description' => 'host name or IP address (optional)',
  354. 'default' => "localhost",
  355. 'value' => "localhost",
  356. 'source_of_value' => '',
  357. 'show_in_conf_sample' => false,
  358. ),
  359. 'email_transport_smtp.port' => array(
  360. 'type' => 'integer',
  361. 'description' => 'port number (optional)',
  362. 'default' => 25,
  363. 'value' => 25,
  364. 'source_of_value' => '',
  365. 'show_in_conf_sample' => false,
  366. ),
  367. 'email_transport_smtp.encryption' => array(
  368. 'type' => 'string',
  369. 'description' => 'tls or ssl (optional)',
  370. 'default' => "",
  371. 'value' => "",
  372. 'source_of_value' => '',
  373. 'show_in_conf_sample' => false,
  374. ),
  375. 'email_transport_smtp.username' => array(
  376. 'type' => 'string',
  377. 'description' => 'Authentication user (optional)',
  378. 'default' => "",
  379. 'value' => "",
  380. 'source_of_value' => '',
  381. 'show_in_conf_sample' => false,
  382. ),
  383. 'email_transport_smtp.password' => array(
  384. 'type' => 'string',
  385. 'description' => 'Authentication password (optional)',
  386. 'default' => "",
  387. 'value' => "",
  388. 'source_of_value' => '',
  389. 'show_in_conf_sample' => false,
  390. ),
  391. 'email_css' => array(
  392. 'type' => 'string',
  393. 'description' => 'CSS that will override the standard stylesheet used for the notifications',
  394. 'default' => "",
  395. 'value' => "",
  396. 'source_of_value' => '',
  397. 'show_in_conf_sample' => false,
  398. ),
  399. 'apc_cache.enabled' => array(
  400. 'type' => 'bool',
  401. 'description' => 'If set, the APC cache is allowed (the PHP extension must also be active)',
  402. 'default' => true,
  403. 'value' => true,
  404. 'source_of_value' => '',
  405. 'show_in_conf_sample' => true,
  406. ),
  407. 'apc_cache.query_ttl' => array(
  408. 'type' => 'integer',
  409. 'description' => 'Time to live set in APC for the prepared queries (seconds - 0 means no timeout)',
  410. 'default' => 3600,
  411. 'value' => 3600,
  412. 'source_of_value' => '',
  413. 'show_in_conf_sample' => true,
  414. ),
  415. 'timezone' => array(
  416. 'type' => 'string',
  417. 'description' => 'Timezone (reference: http://php.net/manual/en/timezones.php). If empty, it will be left unchanged and MUST be explicitely configured in PHP',
  418. // examples... not used (nor 'description')
  419. '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'),
  420. 'default' => 'Europe/Paris',
  421. 'value' => 'Europe/Paris',
  422. 'source_of_value' => '',
  423. 'show_in_conf_sample' => true,
  424. ),
  425. 'cas_include_path' => array(
  426. 'type' => 'string',
  427. 'description' => 'The path where to find the phpCAS library',
  428. // examples... not used (nor 'description')
  429. 'default' => '/usr/share/php',
  430. 'value' => '/usr/share/php',
  431. 'source_of_value' => '',
  432. 'show_in_conf_sample' => true,
  433. ),
  434. 'cas_version' => array(
  435. 'type' => 'string',
  436. 'description' => 'The CAS protocol version to use: "1.0" (CAS v1), "2.0" (CAS v2) or "S1" (SAML V1) )',
  437. // examples... not used (nor 'description')
  438. 'default' => '2.0',
  439. 'value' => '',
  440. 'source_of_value' => '',
  441. 'show_in_conf_sample' => false,
  442. ),
  443. 'cas_host' => array(
  444. 'type' => 'string',
  445. 'description' => 'The name of the CAS host',
  446. // examples... not used (nor 'description')
  447. 'default' => '',
  448. 'value' => '',
  449. 'source_of_value' => '',
  450. 'show_in_conf_sample' => false,
  451. ),
  452. 'cas_port' => array(
  453. 'type' => 'integer',
  454. 'description' => 'The port used by the CAS server',
  455. // examples... not used (nor 'description')
  456. 'default' => 443,
  457. 'value' => 443,
  458. 'source_of_value' => '',
  459. 'show_in_conf_sample' => false,
  460. ),
  461. 'cas_context' => array(
  462. 'type' => 'string',
  463. 'description' => 'The CAS context',
  464. // examples... not used (nor 'description')
  465. 'default' => '',
  466. 'value' => '',
  467. 'source_of_value' => '',
  468. 'show_in_conf_sample' => false,
  469. ),
  470. 'cas_server_ca_cert_path' => array(
  471. 'type' => 'string',
  472. 'description' => 'The path where to find the certificate of the CA for validating the certificate of the CAS server',
  473. // examples... not used (nor 'description')
  474. 'default' => '',
  475. 'value' => '',
  476. 'source_of_value' => '',
  477. 'show_in_conf_sample' => false,
  478. ),
  479. 'cas_logout_redirect_service' => array(
  480. 'type' => 'string',
  481. 'description' => 'The redirect service (URL) to use when logging-out with CAS',
  482. // examples... not used (nor 'description')
  483. 'default' => '',
  484. 'value' => '',
  485. 'source_of_value' => '',
  486. 'show_in_conf_sample' => false,
  487. ),
  488. 'cas_memberof' => array(
  489. 'type' => 'string',
  490. 'description' => 'A semicolon separated list of group names that the user must be member of (works only with SAML - e.g. cas_version=> "S1")',
  491. // examples... not used (nor 'description')
  492. 'default' => '',
  493. 'value' => '',
  494. 'source_of_value' => '',
  495. 'show_in_conf_sample' => false,
  496. ),
  497. 'cas_user_synchro' => array(
  498. 'type' => 'bool',
  499. 'description' => 'Whether or not to synchronize users with CAS/LDAP',
  500. // examples... not used (nor 'description')
  501. 'default' => 0,
  502. 'value' => 0,
  503. 'source_of_value' => '',
  504. 'show_in_conf_sample' => false,
  505. ),
  506. 'cas_update_profiles' => array(
  507. 'type' => 'bool',
  508. 'description' => 'Whether or not to update the profiles of an existing user from the CAS information',
  509. // examples... not used (nor 'description')
  510. 'default' => 0,
  511. 'value' => 0,
  512. 'source_of_value' => '',
  513. 'show_in_conf_sample' => false,
  514. ),
  515. 'cas_profile_pattern' => array(
  516. 'type' => 'string',
  517. 'description' => 'A regular expression pattern to extract the name of the iTop profile from the name of an LDAP/CAS group',
  518. // examples... not used (nor 'description')
  519. 'default' => '/^cn=([^,]+),/',
  520. 'value' => '/^cn=([^,]+),/',
  521. 'source_of_value' => '',
  522. 'show_in_conf_sample' => false,
  523. ),
  524. 'cas_default_profiles' => array(
  525. 'type' => 'string',
  526. 'description' => 'A semi-colon separated list of iTop Profiles to use when creating a new user if no profile is retrieved from CAS',
  527. // examples... not used (nor 'description')
  528. 'default' => 'Portal user',
  529. 'value' => 'Portal user',
  530. 'source_of_value' => '',
  531. 'show_in_conf_sample' => false,
  532. ),
  533. 'cas_debug' => array(
  534. 'type' => 'bool',
  535. 'description' => 'Activate the CAS debug',
  536. // examples... not used (nor 'description')
  537. 'default' => false,
  538. 'value' => false,
  539. 'source_of_value' => '',
  540. 'show_in_conf_sample' => false,
  541. ),
  542. 'forgot_password' => array(
  543. 'type' => 'bool',
  544. 'description' => 'Enable the "Forgot password" feature',
  545. // examples... not used (nor 'description')
  546. 'default' => true,
  547. 'value' => true,
  548. 'source_of_value' => '',
  549. 'show_in_conf_sample' => false,
  550. ),
  551. 'forgot_password_from' => array(
  552. 'type' => 'string',
  553. 'description' => 'Sender email address for the "forgot password" feature. If empty, defaults to the recipient\'s email address.',
  554. // examples... not used (nor 'description')
  555. 'default' => '',
  556. 'value' => '',
  557. 'source_of_value' => '',
  558. 'show_in_conf_sample' => false,
  559. ),
  560. 'deadline_format' => array(
  561. 'type' => 'string',
  562. 'description' => 'The format used for displaying "deadline" attributes: any string with the following placeholders: $date$, $difference$',
  563. // examples... $date$ ($deadline$)
  564. 'default' => '$difference$',
  565. 'value' => '$difference$',
  566. 'source_of_value' => '',
  567. 'show_in_conf_sample' => true,
  568. ),
  569. 'buttons_position' => array(
  570. 'type' => 'string',
  571. 'description' => 'Position of the forms buttons: bottom | top | both',
  572. // examples... not used
  573. 'default' => 'both',
  574. 'value' => 'both',
  575. 'source_of_value' => '',
  576. 'show_in_conf_sample' => true,
  577. ),
  578. 'shortcut_actions' => array(
  579. 'type' => 'string',
  580. 'description' => 'Actions that are available as direct buttons next to the "Actions" menu',
  581. // examples... not used
  582. 'default' => 'UI:Menu:Modify,UI:Menu:New',
  583. 'value' => 'UI:Menu:Modify',
  584. 'source_of_value' => '',
  585. 'show_in_conf_sample' => true,
  586. ),
  587. 'complex_actions_limit' => array(
  588. 'type' => 'integer',
  589. '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)',
  590. // examples... not used
  591. 'default' => 50,
  592. 'value' => 50,
  593. 'source_of_value' => '',
  594. 'show_in_conf_sample' => false,
  595. ),
  596. 'synchro_prevent_delete_all' => array(
  597. 'type' => 'bool',
  598. 'description' => 'Stop the synchro if all the replicas of a data source become obsolete at the same time.',
  599. // examples... not used
  600. 'default' => true,
  601. 'value' => true,
  602. 'source_of_value' => '',
  603. 'show_in_conf_sample' => false,
  604. ),
  605. 'source_dir' => array(
  606. 'type' => 'string',
  607. 'description' => 'Source directory for the datamodel files. (which gets compiled to env-production).',
  608. // examples... not used
  609. 'default' => '',
  610. 'value' => '',
  611. 'source_of_value' => '',
  612. 'show_in_conf_sample' => true,
  613. ),
  614. 'csv_file_default_charset' => array(
  615. 'type' => 'string',
  616. 'description' => 'Character set used by default for downloading and uploading data as a CSV file. Warning: it is case sensitive (uppercase is preferable).',
  617. // examples... not used
  618. 'default' => 'ISO-8859-1',
  619. 'value' => '',
  620. 'source_of_value' => '',
  621. 'show_in_conf_sample' => true,
  622. ),
  623. 'debug_report_spurious_chars' => array(
  624. 'type' => 'bool',
  625. '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',
  626. // examples... not used
  627. 'default' => false,
  628. 'value' => '',
  629. 'source_of_value' => '',
  630. 'show_in_conf_sample' => false,
  631. ),
  632. 'impact_analysis_first_tab' => array(
  633. 'type' => 'string',
  634. 'description' => 'Which tab to display first in the impact analysis view: list or graphics. Graphics are nicer but slower to display when there are many objects',
  635. // examples... not used
  636. 'default' => 'graphics',
  637. 'value' => '',
  638. 'source_of_value' => '',
  639. 'show_in_conf_sample' => false,
  640. ),
  641. 'url_validation_pattern' => array(
  642. 'type' => 'string',
  643. 'description' => 'Regular expression to validate/detect the format of an URL (URL attributes and Wiki formatting for Text attributes)',
  644. 'default' => '(https?|ftp)\://([a-zA-Z0-9+!*(),;?&=\$_.-]+(\:[a-zA-Z0-9+!*(),;?&=\$_.-]+)?@)?([a-zA-Z0-9-.]{3,})(\:[0-9]{2,5})?(/([a-zA-Z0-9%+\$_-]\.?)+)*/?(\?[a-zA-Z+&\$_.-][a-zA-Z0-9;:[\]@&%=+/\$_.-]*)?(#[a-zA-Z_.-][a-zA-Z0-9+\$_.-]*)?',
  645. // SHEME.......... USER....................... PASSWORD.......................... HOST/IP........... PORT.......... PATH........................ GET............................................ ANCHOR............................
  646. // Example: http://User:passWord@127.0.0.1:8888/patH/Page.php?arrayArgument[2]=something:blah20#myAnchor
  647. // Origin of this regexp: http://www.php.net/manual/fr/function.preg-match.php#93824
  648. 'value' => '',
  649. 'source_of_value' => '',
  650. 'show_in_conf_sample' => true,
  651. ),
  652. 'email_validation_pattern' => array(
  653. 'type' => 'string',
  654. 'description' => 'Regular expression to validate/detect the format of an eMail address',
  655. 'default' => "[a-zA-Z0-9._&'-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]{2,}",
  656. 'value' => '',
  657. 'source_of_value' => '',
  658. 'show_in_conf_sample' => true,
  659. ),
  660. 'log_kpi_duration' => array(
  661. 'type' => 'integer',
  662. 'description' => 'Level of logging for troubleshooting performance issues (1 to enable, 2 +blame callers)',
  663. // examples... not used
  664. 'default' => 0,
  665. 'value' => 0,
  666. 'source_of_value' => '',
  667. 'show_in_conf_sample' => false,
  668. ),
  669. 'log_kpi_memory' => array(
  670. 'type' => 'integer',
  671. 'description' => 'Level of logging for troubleshooting memory limit issues',
  672. // examples... not used
  673. 'default' => 0,
  674. 'value' => 0,
  675. 'source_of_value' => '',
  676. 'show_in_conf_sample' => false,
  677. ),
  678. 'log_kpi_user_id' => array(
  679. 'type' => 'string',
  680. 'description' => 'Limit the scope of users to the given user id (* means no limit)',
  681. // examples... not used
  682. 'default' => '*',
  683. 'value' => '*',
  684. 'source_of_value' => '',
  685. 'show_in_conf_sample' => false,
  686. ),
  687. 'max_linkset_output' => array(
  688. 'type' => 'integer',
  689. 'description' => 'Maximum number of items shown when getting a list of related items in an email, using the form $this->some_list$. 0 means no limit.',
  690. 'default' => 100,
  691. 'value' => 100,
  692. 'source_of_value' => '',
  693. 'show_in_conf_sample' => true,
  694. ),
  695. 'demo_mode' => array(
  696. 'type' => 'bool',
  697. 'description' => 'Set to true to prevent users from changing passwords/languages',
  698. 'default' => false,
  699. 'value' => '',
  700. 'source_of_value' => '',
  701. 'show_in_conf_sample' => false,
  702. ),
  703. 'portal_tickets' => array(
  704. 'type' => 'string',
  705. 'description' => 'CSV list of classes supported in the portal',
  706. // examples... not used
  707. 'default' => 'UserRequest',
  708. 'value' => 'UserRequest',
  709. 'source_of_value' => '',
  710. 'show_in_conf_sample' => true,
  711. ),
  712. 'portal_dispatch_urls' => array(
  713. 'type' => 'array',
  714. 'description' => 'Associative array of sPortalId => Home page URL (relatively to the application root)',
  715. // examples... not used
  716. 'default' => array(),
  717. 'value' => false,
  718. 'source_of_value' => '',
  719. 'show_in_conf_sample' => false,
  720. ),
  721. 'max_execution_time_per_loop' => array(
  722. 'type' => 'integer',
  723. 'description' => 'Maximum execution time requested, per loop, during bulk operations. Zero means no limit.',
  724. // examples... not used
  725. 'default' => 30,
  726. 'value' => 30,
  727. 'source_of_value' => '',
  728. 'show_in_conf_sample' => false,
  729. ),
  730. 'max_history_length' => array(
  731. 'type' => 'integer',
  732. 'description' => 'Maximum length of the history table (in the "History" tab on each object) before it gets truncated. Latest modifications are displayed first.',
  733. // examples... not used
  734. 'default' => 50,
  735. 'value' => 50,
  736. 'source_of_value' => '',
  737. 'show_in_conf_sample' => false,
  738. ),
  739. 'max_history_case_log_entry_length' => array(
  740. 'type' => 'integer',
  741. 'description' => 'The length (in number of characters) at which to truncate the (expandable) display (in the history) of a case log entry. If zero, the display in the history is not truncated.',
  742. // examples... not used
  743. 'default' => 60,
  744. 'value' => 60,
  745. 'source_of_value' => '',
  746. 'show_in_conf_sample' => false,
  747. ),
  748. 'full_text_chunk_duration' => array(
  749. 'type' => 'integer',
  750. 'description' => 'Delay after which the results are displayed.',
  751. // examples... not used
  752. 'default' => 2,
  753. 'value' => 2,
  754. 'source_of_value' => '',
  755. 'show_in_conf_sample' => false,
  756. ),
  757. 'full_text_accelerators' => array(
  758. 'type' => 'array',
  759. 'description' => 'Specifies classes to be searched at first (and the subset of data) when running the full text search.',
  760. 'default' => array(),
  761. 'value' => false,
  762. 'source_of_value' => '',
  763. 'show_in_conf_sample' => false,
  764. ),
  765. 'full_text_needle_min' => array(
  766. 'type' => 'integer',
  767. 'description' => 'Minimum size of the full text needle.',
  768. 'default' => 3,
  769. 'value' => 3,
  770. 'source_of_value' => '',
  771. 'show_in_conf_sample' => false,
  772. ),
  773. 'tracking_level_linked_set_default' => array(
  774. 'type' => 'integer',
  775. 'description' => 'Default tracking level if not explicitely set at the attribute level, for AttributeLinkedSet (defaults to NONE in case of a fresh install, LIST otherwise - this to preserve backward compatibility while upgrading from a version older than 2.0.3 - see TRAC #936)',
  776. 'default' => LINKSET_TRACKING_LIST,
  777. 'value' => LINKSET_TRACKING_LIST,
  778. 'source_of_value' => '',
  779. 'show_in_conf_sample' => false,
  780. ),
  781. 'tracking_level_linked_set_indirect_default' => array(
  782. 'type' => 'integer',
  783. 'description' => 'Default tracking level if not explicitely set at the attribute level, for AttributeLinkedSetIndirect',
  784. 'default' => LINKSET_TRACKING_ALL,
  785. 'value' => LINKSET_TRACKING_ALL,
  786. 'source_of_value' => '',
  787. 'show_in_conf_sample' => false,
  788. ),
  789. 'user_rights_legacy' => array(
  790. 'type' => 'bool',
  791. 'description' => 'Set to true to restore the buggy algorithm for the computation of user rights (within the same profile, ALLOW on the class itself has precedence on DENY of a parent class)',
  792. 'default' => false,
  793. 'value' => '',
  794. 'source_of_value' => '',
  795. 'show_in_conf_sample' => false,
  796. ),
  797. 'xlsx_exporter_memory_limit' => array(
  798. 'type' => 'string',
  799. 'description' => 'Memory limit to use when (interactively) exporting data to Excel',
  800. 'default' => '2048M', // Huuuuuuge 2GB!
  801. 'value' => '',
  802. 'source_of_value' => '',
  803. 'show_in_conf_sample' => false,
  804. ),
  805. 'min_reload_interval' => array(
  806. 'type' => 'integer',
  807. 'description' => 'Minimum refresh interval (seconds) for dashboards, shortcuts, etc. Even if the interval is set programmatically, it is forced to that minimum',
  808. 'default' => 5, // In iTop 2.0.3, this was the hardcoded value
  809. 'value' => '',
  810. 'source_of_value' => '',
  811. 'show_in_conf_sample' => false,
  812. ),
  813. 'relations_max_depth' => array(
  814. 'type' => 'integer',
  815. 'description' => 'Maximum number of successive levels (depth) to explore when displaying the impact/depends on relations.',
  816. 'default' => 20, // In iTop 2.0.3, this was the hardcoded value
  817. 'value' => '',
  818. 'source_of_value' => '',
  819. 'show_in_conf_sample' => false,
  820. ),
  821. 'transaction_storage' => array(
  822. 'type' => 'string',
  823. 'description' => 'The type of mechanism to use for storing the unique identifiers for transactions (Session|File).',
  824. 'default' => 'Session',
  825. 'value' => '',
  826. 'source_of_value' => '',
  827. 'show_in_conf_sample' => false,
  828. ),
  829. 'transactions_enabled' => array(
  830. 'type' => 'bool',
  831. 'description' => 'Whether or not the whole mechanism to prevent multiple submissions of a page is enabled.',
  832. 'default' => true,
  833. 'value' => '',
  834. 'source_of_value' => '',
  835. 'show_in_conf_sample' => false,
  836. ),
  837. 'log_transactions' => array(
  838. 'type' => 'bool',
  839. 'description' => 'Whether or not to enable the debug log for the transactions.',
  840. 'default' => false,
  841. 'value' => '',
  842. 'source_of_value' => '',
  843. 'show_in_conf_sample' => false,
  844. ),
  845. 'concurrent_lock_enabled' => array(
  846. 'type' => 'bool',
  847. 'description' => 'Whether or not to activate the locking mechanism in order to prevent concurrent edition of the same object.',
  848. 'default' => false,
  849. 'value' => '',
  850. 'source_of_value' => '',
  851. 'show_in_conf_sample' => false,
  852. ),
  853. 'concurrent_lock_expiration_delay' => array(
  854. 'type' => 'integer',
  855. 'description' => 'Delay (in seconds) for a concurrent lock to expire',
  856. 'default' => 120,
  857. 'value' => '',
  858. 'source_of_value' => '',
  859. 'show_in_conf_sample' => false,
  860. ),
  861. 'concurrent_lock_override_profiles' => array(
  862. 'type' => 'array',
  863. 'description' => 'The list of profiles allowed to "kill" a lock',
  864. 'default' => array('Administrator'),
  865. 'value' => '',
  866. 'source_of_value' => '',
  867. 'show_in_conf_sample' => false,
  868. ),
  869. 'html_sanitizer' => array(
  870. 'type' => 'string',
  871. 'description' => 'The class to use for HTML sanitization: HTMLDOMSanitizer, HTMLPurifierSanitizer or HTMLNullSanitizer',
  872. 'default' => 'HTMLDOMSanitizer',
  873. 'value' => '',
  874. 'source_of_value' => '',
  875. 'show_in_conf_sample' => false,
  876. ),
  877. 'inline_image_max_display_width' => array(
  878. 'type' => 'integer',
  879. 'description' => 'The maximum width (in pixels) when displaying images inside an HTML formatted attribute. Images will be displayed using this this maximum width.',
  880. 'default' => '250',
  881. 'value' => '',
  882. 'source_of_value' => '',
  883. 'show_in_conf_sample' => true,
  884. ),
  885. 'inline_image_max_storage_width' => array(
  886. 'type' => 'integer',
  887. 'description' => 'The maximum width (in pixels) when uploading images to be used inside an HTML formatted attribute. Images larger than the given size will be downsampled before storing them in the database.',
  888. 'default' => '1600',
  889. 'value' => '',
  890. 'source_of_value' => '',
  891. 'show_in_conf_sample' => true,
  892. ),
  893. 'date_and_time_format' => array(
  894. 'type' => 'array',
  895. 'description' => 'Format for date and time display (per language)',
  896. 'default' => array('default' => array('date' => 'Y-m-d', 'time' => 'H:i:s', 'date_time' => '$date $time')),
  897. 'value' => false,
  898. 'source_of_value' => '',
  899. 'show_in_conf_sample' => true,
  900. ),
  901. 'breadcrumb.max_count' => array(
  902. 'type' => 'integer',
  903. 'description' => 'Maximum number of items kept in the history breadcrumb. Set it to 0 to entirely disable the breadcrumb.',
  904. 'default' => 8,
  905. 'value' => 8,
  906. 'source_of_value' => '',
  907. 'show_in_conf_sample' => false,
  908. ),
  909. 'legacy_search_drawer_open' => array(
  910. 'type' => 'bool',
  911. 'description' => 'Whether or not to display the "search drawer" open by default as in previous versions of iTop.',
  912. 'default' => false,
  913. 'value' => '',
  914. 'source_of_value' => '',
  915. 'show_in_conf_sample' => false,
  916. ),
  917. );
  918. public function IsProperty($sPropCode)
  919. {
  920. return (array_key_exists($sPropCode, $this->m_aSettings));
  921. }
  922. public function GetDescription($sPropCode)
  923. {
  924. return $this->m_aSettings[$sPropCode];
  925. }
  926. public function Set($sPropCode, $value, $sSourceDesc = 'unknown')
  927. {
  928. $sType = $this->m_aSettings[$sPropCode]['type'];
  929. switch($sType)
  930. {
  931. case 'bool':
  932. $value = (bool) $value;
  933. break;
  934. case 'string':
  935. $value = (string) $value;
  936. break;
  937. case 'integer':
  938. $value = (integer) $value;
  939. break;
  940. case 'float':
  941. $value = (float) $value;
  942. break;
  943. case 'array':
  944. break;
  945. default:
  946. throw new CoreException('Unknown type for setting', array('property' => $sPropCode, 'type' => $sType));
  947. }
  948. $this->m_aSettings[$sPropCode]['value'] = $value;
  949. $this->m_aSettings[$sPropCode]['source_of_value'] = $sSourceDesc;
  950. }
  951. public function Get($sPropCode)
  952. {
  953. return $this->m_aSettings[$sPropCode]['value'];
  954. }
  955. // Those variables will be deprecated later, when the transition to ...Get('my_setting') will be done
  956. protected $m_sDBHost;
  957. protected $m_sDBUser;
  958. protected $m_sDBPwd;
  959. protected $m_sDBName;
  960. protected $m_sDBSubname;
  961. protected $m_sDBCharacterSet;
  962. protected $m_sDBCollation;
  963. /**
  964. * Event log options (see LOG_... definition)
  965. */
  966. // Those variables will be deprecated later, when the transition to ...Get('my_setting') will be done
  967. protected $m_bLogGlobal;
  968. protected $m_bLogNotification;
  969. protected $m_bLogIssue;
  970. protected $m_bLogWebService;
  971. protected $m_bQueryCacheEnabled; // private setting
  972. /**
  973. * @var integer Number of elements to be displayed when there are more than m_iMaxDisplayLimit elements
  974. */
  975. protected $m_iMinDisplayLimit;
  976. /**
  977. * @var integer Max number of elements before truncating the display
  978. */
  979. protected $m_iMaxDisplayLimit;
  980. /**
  981. * @var integer Number of seconds between two reloads of the display (standard)
  982. */
  983. protected $m_iStandardReloadInterval;
  984. /**
  985. * @var integer Number of seconds between two reloads of the display (fast)
  986. */
  987. protected $m_iFastReloadInterval;
  988. /**
  989. * @var boolean Whether or not a secure connection is required for using the application.
  990. * If set, any attempt to connect to an iTop page with http:// will be redirected
  991. * to https://
  992. */
  993. protected $m_bSecureConnectionRequired;
  994. /**
  995. * @var string Langage code, default if the user language is undefined
  996. */
  997. protected $m_sDefaultLanguage;
  998. /**
  999. * @var string Type of login process allowed: form|basic|url|external
  1000. */
  1001. protected $m_sAllowedLoginTypes;
  1002. /**
  1003. * @var string Name of the PHP variable in which external authentication information is passed by the web server
  1004. */
  1005. protected $m_sExtAuthVariable;
  1006. /**
  1007. * @var string Encryption key used for all attributes of type "encrypted string". Can be set to a random value
  1008. * unless you want to import a database from another iTop instance, in which case you must use
  1009. * the same encryption key in order to properly decode the encrypted fields
  1010. */
  1011. protected $m_sEncryptionKey;
  1012. /**
  1013. * @var array Additional character sets to be supported by the interactive CSV import
  1014. * 'iconv_code' => 'display name'
  1015. */
  1016. protected $m_aCharsets;
  1017. public function __construct($sConfigFile = null, $bLoadConfig = true)
  1018. {
  1019. $this->m_sFile = $sConfigFile;
  1020. if (is_null($sConfigFile))
  1021. {
  1022. $bLoadConfig = false;
  1023. }
  1024. $this->m_aAddons = array(
  1025. // Default AddOn, always present can be moved to an official iTop Module later if needed
  1026. 'user rights' => 'addons/userrights/userrightsprofile.class.inc.php',
  1027. );
  1028. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  1029. {
  1030. $this->m_aSettings[$sPropCode]['value'] = $aSettingInfo['default'];
  1031. }
  1032. $this->m_sDBHost = '';
  1033. $this->m_sDBUser = '';
  1034. $this->m_sDBPwd = '';
  1035. $this->m_sDBName = '';
  1036. $this->m_sDBSubname = '';
  1037. $this->m_sDBCharacterSet = DEFAULT_CHARACTER_SET;
  1038. $this->m_sDBCollation = DEFAULT_COLLATION;
  1039. $this->m_bLogGlobal = DEFAULT_LOG_GLOBAL;
  1040. $this->m_bLogNotification = DEFAULT_LOG_NOTIFICATION;
  1041. $this->m_bLogIssue = DEFAULT_LOG_ISSUE;
  1042. $this->m_bLogWebService = DEFAULT_LOG_WEB_SERVICE;
  1043. $this->m_iMinDisplayLimit = DEFAULT_MIN_DISPLAY_LIMIT;
  1044. $this->m_iMaxDisplayLimit = DEFAULT_MAX_DISPLAY_LIMIT;
  1045. $this->m_iStandardReloadInterval = DEFAULT_STANDARD_RELOAD_INTERVAL;
  1046. $this->m_iFastReloadInterval = DEFAULT_FAST_RELOAD_INTERVAL;
  1047. $this->m_bSecureConnectionRequired = DEFAULT_SECURE_CONNECTION_REQUIRED;
  1048. $this->m_sDefaultLanguage = 'EN US';
  1049. $this->m_sAllowedLoginTypes = DEFAULT_ALLOWED_LOGIN_TYPES;
  1050. $this->m_sExtAuthVariable = DEFAULT_EXT_AUTH_VARIABLE;
  1051. $this->m_sEncryptionKey = DEFAULT_ENCRYPTION_KEY;
  1052. $this->m_aCharsets = array();
  1053. $this->m_bQueryCacheEnabled = DEFAULT_QUERY_CACHE_ENABLED;
  1054. $this->m_aModuleSettings = array();
  1055. if ($bLoadConfig)
  1056. {
  1057. $this->Load($sConfigFile);
  1058. $this->Verify();
  1059. }
  1060. // Application root url: set a default value, then normalize it
  1061. /*
  1062. * Does not work in CLI/unattended mode
  1063. $sAppRootUrl = trim($this->Get('app_root_url'));
  1064. if (strlen($sAppRootUrl) == 0)
  1065. {
  1066. $sAppRootUrl = utils::GetDefaultUrlAppRoot();
  1067. }
  1068. if (substr($sAppRootUrl, -1, 1) != '/')
  1069. {
  1070. $sAppRootUrl .= '/';
  1071. }
  1072. $this->Set('app_root_url', $sAppRootUrl);
  1073. */
  1074. }
  1075. protected function CheckFile($sPurpose, $sFileName)
  1076. {
  1077. if (!file_exists($sFileName))
  1078. {
  1079. throw new ConfigException("Could not find $sPurpose file", array('file' => $sFileName));
  1080. }
  1081. if (!is_readable($sFileName))
  1082. {
  1083. 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));
  1084. }
  1085. }
  1086. protected function Load($sConfigFile)
  1087. {
  1088. $this->CheckFile('configuration', $sConfigFile);
  1089. $sConfigCode = trim(file_get_contents($sConfigFile));
  1090. // This does not work on several lines
  1091. // preg_match('/^<\\?php(.*)\\?'.'>$/', $sConfigCode, $aMatches)...
  1092. // So, I've implemented a solution suggested in the PHP doc (search for phpWrapper)
  1093. try
  1094. {
  1095. ob_start();
  1096. eval('?'.'>'.trim($sConfigCode));
  1097. $sNoise = trim(ob_get_contents());
  1098. ob_end_clean();
  1099. }
  1100. catch (Exception $e)
  1101. {
  1102. // well, never reach in case of parsing error :-(
  1103. // will be improved in PHP 6 ?
  1104. throw new ConfigException('Error in configuration file', array('file' => $sConfigFile, 'error' => $e->getMessage()));
  1105. }
  1106. if (strlen($sNoise) > 0)
  1107. {
  1108. // Note: sNoise is an html output, but so far it was ok for me (e.g. showing the entire call stack)
  1109. throw new ConfigException('Syntax error in configuration file', array('file' => $sConfigFile, 'error' => '<tt>'.htmlentities($sNoise, ENT_QUOTES, 'UTF-8').'</tt>'));
  1110. }
  1111. if (!isset($MySettings) || !is_array($MySettings))
  1112. {
  1113. throw new ConfigException('Missing array in configuration file', array('file' => $sConfigFile, 'expected' => '$MySettings'));
  1114. }
  1115. if (!array_key_exists('addons', $MyModules))
  1116. {
  1117. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'addons\']'));
  1118. }
  1119. if (!array_key_exists('user rights', $MyModules['addons']))
  1120. {
  1121. // Add one, by default
  1122. $MyModules['addons']['user rights'] = '/addons/userrights/userrightsnull.class.inc.php';
  1123. }
  1124. $this->m_aAddons = $MyModules['addons'];
  1125. foreach($MySettings as $sPropCode => $rawvalue)
  1126. {
  1127. if ($this->IsProperty($sPropCode))
  1128. {
  1129. if (is_string($rawvalue))
  1130. {
  1131. $value = trim($rawvalue);
  1132. }
  1133. else
  1134. {
  1135. $value = $rawvalue;
  1136. }
  1137. $this->Set($sPropCode, $value, $sConfigFile);
  1138. }
  1139. }
  1140. $this->m_sDBHost = trim($MySettings['db_host']);
  1141. $this->m_sDBUser = trim($MySettings['db_user']);
  1142. $this->m_sDBPwd = trim($MySettings['db_pwd']);
  1143. $this->m_sDBName = trim($MySettings['db_name']);
  1144. $this->m_sDBSubname = trim($MySettings['db_subname']);
  1145. $this->m_sDBCharacterSet = isset($MySettings['db_character_set']) ? trim($MySettings['db_character_set']) : DEFAULT_CHARACTER_SET;
  1146. $this->m_sDBCollation = isset($MySettings['db_collation']) ? trim($MySettings['db_collation']) : DEFAULT_COLLATION;
  1147. $this->m_bLogGlobal = isset($MySettings['log_global']) ? (bool) trim($MySettings['log_global']) : DEFAULT_LOG_GLOBAL;
  1148. $this->m_bLogNotification = isset($MySettings['log_notification']) ? (bool) trim($MySettings['log_notification']) : DEFAULT_LOG_NOTIFICATION;
  1149. $this->m_bLogIssue = isset($MySettings['log_issue']) ? (bool) trim($MySettings['log_issue']) : DEFAULT_LOG_ISSUE;
  1150. $this->m_bLogWebService = isset($MySettings['log_web_service']) ? (bool) trim($MySettings['log_web_service']) : DEFAULT_LOG_WEB_SERVICE;
  1151. $this->m_bQueryCacheEnabled = isset($MySettings['query_cache_enabled']) ? (bool) trim($MySettings['query_cache_enabled']) : DEFAULT_QUERY_CACHE_ENABLED;
  1152. $this->m_iMinDisplayLimit = isset($MySettings['min_display_limit']) ? trim($MySettings['min_display_limit']) : DEFAULT_MIN_DISPLAY_LIMIT;
  1153. $this->m_iMaxDisplayLimit = isset($MySettings['max_display_limit']) ? trim($MySettings['max_display_limit']) : DEFAULT_MAX_DISPLAY_LIMIT;
  1154. $this->m_iStandardReloadInterval = isset($MySettings['standard_reload_interval']) ? trim($MySettings['standard_reload_interval']) : DEFAULT_STANDARD_RELOAD_INTERVAL;
  1155. $this->m_iFastReloadInterval = isset($MySettings['fast_reload_interval']) ? trim($MySettings['fast_reload_interval']) : DEFAULT_FAST_RELOAD_INTERVAL;
  1156. $this->m_bSecureConnectionRequired = isset($MySettings['secure_connection_required']) ? (bool) trim($MySettings['secure_connection_required']) : DEFAULT_SECURE_CONNECTION_REQUIRED;
  1157. $this->m_aModuleSettings = isset($MyModuleSettings) ? $MyModuleSettings : array();
  1158. $this->m_sDefaultLanguage = isset($MySettings['default_language']) ? trim($MySettings['default_language']) : 'EN US';
  1159. $this->m_sAllowedLoginTypes = isset($MySettings['allowed_login_types']) ? trim($MySettings['allowed_login_types']) : DEFAULT_ALLOWED_LOGIN_TYPES;
  1160. $this->m_sExtAuthVariable = isset($MySettings['ext_auth_variable']) ? trim($MySettings['ext_auth_variable']) : DEFAULT_EXT_AUTH_VARIABLE;
  1161. $this->m_sEncryptionKey = isset($MySettings['encryption_key']) ? trim($MySettings['encryption_key']) : DEFAULT_ENCRYPTION_KEY;
  1162. $this->m_aCharsets = isset($MySettings['csv_import_charsets']) ? $MySettings['csv_import_charsets'] : array();
  1163. }
  1164. protected function Verify()
  1165. {
  1166. // Files are verified later on, just before using them -see MetaModel::Plugin()
  1167. // (we have their final path at that point)
  1168. }
  1169. public function GetModuleSetting($sModule, $sProperty, $defaultvalue = null)
  1170. {
  1171. if (isset($this->m_aModuleSettings[$sModule][$sProperty]))
  1172. {
  1173. return $this->m_aModuleSettings[$sModule][$sProperty];
  1174. }
  1175. // Fall back to the predefined XML parameter, if any
  1176. return $this->GetModuleParameter($sModule, $sProperty, $defaultvalue);
  1177. }
  1178. public function GetModuleParameter($sModule, $sProperty, $defaultvalue = null)
  1179. {
  1180. $ret = $defaultvalue;
  1181. if (class_exists('ModulesXMLParameters'))
  1182. {
  1183. $aAllParams = ModulesXMLParameters::GetData($sModule);
  1184. if(array_key_exists($sProperty, $aAllParams))
  1185. {
  1186. $ret = $aAllParams[$sProperty];
  1187. }
  1188. }
  1189. return $ret;
  1190. }
  1191. public function SetModuleSetting($sModule, $sProperty, $value)
  1192. {
  1193. $this->m_aModuleSettings[$sModule][$sProperty] = $value;
  1194. }
  1195. public function GetAddons()
  1196. {
  1197. return $this->m_aAddons;
  1198. }
  1199. public function SetAddons($aAddons)
  1200. {
  1201. $this->m_aAddons = $aAddons;
  1202. }
  1203. public function GetDBHost()
  1204. {
  1205. return $this->m_sDBHost;
  1206. }
  1207. public function GetDBName()
  1208. {
  1209. return $this->m_sDBName;
  1210. }
  1211. public function GetDBSubname()
  1212. {
  1213. return $this->m_sDBSubname;
  1214. }
  1215. public function GetDBCharacterSet()
  1216. {
  1217. return $this->m_sDBCharacterSet;
  1218. }
  1219. public function GetDBCollation()
  1220. {
  1221. return $this->m_sDBCollation;
  1222. }
  1223. public function GetDBUser()
  1224. {
  1225. return $this->m_sDBUser;
  1226. }
  1227. public function GetDBPwd()
  1228. {
  1229. return $this->m_sDBPwd;
  1230. }
  1231. public function GetLogGlobal()
  1232. {
  1233. return $this->m_bLogGlobal;
  1234. }
  1235. public function GetLogNotification()
  1236. {
  1237. return $this->m_bLogNotification;
  1238. }
  1239. public function GetLogIssue()
  1240. {
  1241. return $this->m_bLogIssue;
  1242. }
  1243. public function GetLogWebService()
  1244. {
  1245. return $this->m_bLogWebService;
  1246. }
  1247. public function GetLogQueries()
  1248. {
  1249. return false;
  1250. }
  1251. public function GetQueryCacheEnabled()
  1252. {
  1253. return $this->m_bQueryCacheEnabled;
  1254. }
  1255. public function GetMinDisplayLimit()
  1256. {
  1257. return $this->m_iMinDisplayLimit;
  1258. }
  1259. public function GetMaxDisplayLimit()
  1260. {
  1261. return $this->m_iMaxDisplayLimit;
  1262. }
  1263. public function GetStandardReloadInterval()
  1264. {
  1265. return $this->m_iStandardReloadInterval;
  1266. }
  1267. public function GetFastReloadInterval()
  1268. {
  1269. return $this->m_iFastReloadInterval;
  1270. }
  1271. public function GetSecureConnectionRequired()
  1272. {
  1273. return $this->m_bSecureConnectionRequired;
  1274. }
  1275. public function GetDefaultLanguage()
  1276. {
  1277. return $this->m_sDefaultLanguage;
  1278. }
  1279. public function GetEncryptionKey()
  1280. {
  1281. return $this->m_sEncryptionKey;
  1282. }
  1283. public function GetAllowedLoginTypes()
  1284. {
  1285. return explode('|', $this->m_sAllowedLoginTypes);
  1286. }
  1287. public function GetExternalAuthenticationVariable()
  1288. {
  1289. return $this->m_sExtAuthVariable;
  1290. }
  1291. public function GetCSVImportCharsets()
  1292. {
  1293. return $this->m_aCharsets;
  1294. }
  1295. public function SetDBHost($sDBHost)
  1296. {
  1297. $this->m_sDBHost = $sDBHost;
  1298. }
  1299. public function SetDBName($sDBName)
  1300. {
  1301. $this->m_sDBName = $sDBName;
  1302. }
  1303. public function SetDBSubname($sDBSubName)
  1304. {
  1305. $this->m_sDBSubname = $sDBSubName;
  1306. }
  1307. public function SetDBCharacterSet($sDBCharacterSet)
  1308. {
  1309. $this->m_sDBCharacterSet = $sDBCharacterSet;
  1310. }
  1311. public function SetDBCollation($sDBCollation)
  1312. {
  1313. $this->m_sDBCollation = $sDBCollation;
  1314. }
  1315. public function SetDBUser($sUser)
  1316. {
  1317. $this->m_sDBUser = $sUser;
  1318. }
  1319. public function SetDBPwd($sPwd)
  1320. {
  1321. $this->m_sDBPwd = $sPwd;
  1322. }
  1323. public function SetLogGlobal($iLogGlobal)
  1324. {
  1325. $this->m_iLogGlobal = $iLogGlobal;
  1326. }
  1327. public function SetLogNotification($iLogNotification)
  1328. {
  1329. $this->m_iLogNotification = $iLogNotification;
  1330. }
  1331. public function SetLogIssue($iLogIssue)
  1332. {
  1333. $this->m_iLogIssue = $iLogIssue;
  1334. }
  1335. public function SetLogWebService($iLogWebService)
  1336. {
  1337. $this->m_iLogWebService = $iLogWebService;
  1338. }
  1339. public function SetMinDisplayLimit($iMinDisplayLimit)
  1340. {
  1341. $this->m_iMinDisplayLimit = $iMinDisplayLimit;
  1342. }
  1343. public function SetMaxDisplayLimit($iMaxDisplayLimit)
  1344. {
  1345. $this->m_iMaxDisplayLimit = $iMaxDisplayLimit;
  1346. }
  1347. public function SetStandardReloadInterval($iStandardReloadInterval)
  1348. {
  1349. $this->m_iStandardReloadInterval = $iStandardReloadInterval;
  1350. }
  1351. public function SetFastReloadInterval($iFastReloadInterval)
  1352. {
  1353. $this->m_iFastReloadInterval = $iFastReloadInterval;
  1354. }
  1355. public function SetSecureConnectionRequired($bSecureConnectionRequired)
  1356. {
  1357. $this->m_bSecureConnectionRequired = $bSecureConnectionRequired;
  1358. }
  1359. public function SetDefaultLanguage($sLanguageCode)
  1360. {
  1361. $this->m_sDefaultLanguage = $sLanguageCode;
  1362. }
  1363. public function SetAllowedLoginTypes($aAllowedLoginTypes)
  1364. {
  1365. $this->m_sAllowedLoginTypes = implode('|', $aAllowedLoginTypes);
  1366. }
  1367. public function SetExternalAuthenticationVariable($sExtAuthVariable)
  1368. {
  1369. $this->m_sExtAuthVariable = $sExtAuthVariable;
  1370. }
  1371. public function SetEncryptionKey($sKey)
  1372. {
  1373. $this->m_sEncryptionKey = $sKey;
  1374. }
  1375. public function SetCSVImportCharsets($aCharsets)
  1376. {
  1377. $this->m_aCharsets = $aCharsets;
  1378. }
  1379. public function AddCSVImportCharset($sIconvCode, $sDisplayName)
  1380. {
  1381. $this->m_aCharsets[$sIconvCode] = $sDisplayName;
  1382. }
  1383. public function GetLoadedFile()
  1384. {
  1385. if (is_null($this->m_sFile))
  1386. {
  1387. return '';
  1388. }
  1389. else
  1390. {
  1391. return $this->m_sFile;
  1392. }
  1393. }
  1394. /**
  1395. * Render the configuration as an associative array
  1396. * @return boolean True otherwise throws an Exception
  1397. */
  1398. public function ToArray()
  1399. {
  1400. $aSettings = array();
  1401. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  1402. {
  1403. $aSettings[$sPropCode] = $aSettingInfo['value'];
  1404. }
  1405. $aSettings['db_host'] = $this->m_sDBHost;
  1406. $aSettings['db_user'] = $this->m_sDBUser;
  1407. $aSettings['db_pwd'] = $this->m_sDBPwd;
  1408. $aSettings['db_name'] = $this->m_sDBName;
  1409. $aSettings['db_subname'] = $this->m_sDBSubname;
  1410. $aSettings['db_character_set'] = $this->m_sDBCharacterSet;
  1411. $aSettings['db_collation'] = $this->m_sDBCollation;
  1412. $aSettings['log_global'] = $this->m_bLogGlobal;
  1413. $aSettings['log_notification'] = $this->m_bLogNotification;
  1414. $aSettings['log_issue'] = $this->m_bLogIssue;
  1415. $aSettings['log_web_service'] = $this->m_bLogWebService;
  1416. $aSettings['query_cache_enabled'] = $this->m_bQueryCacheEnabled;
  1417. $aSettings['min_display_limit'] = $this->m_iMinDisplayLimit;
  1418. $aSettings['max_display_limit'] = $this->m_iMaxDisplayLimit;
  1419. $aSettings['standard_reload_interval'] = $this->m_iStandardReloadInterval;
  1420. $aSettings['fast_reload_interval'] = $this->m_iFastReloadInterval;
  1421. $aSettings['secure_connection_required'] = $this->m_bSecureConnectionRequired;
  1422. $aSettings['default_language'] = $this->m_sDefaultLanguage;
  1423. $aSettings['allowed_login_types'] = $this->m_sAllowedLoginTypes;
  1424. $aSettings['ext_auth_variable'] = $this->m_sExtAuthVariable;
  1425. $aSettings['encryption_key'] = $this->m_sEncryptionKey;
  1426. $aSettings['csv_import_charsets'] = $this->m_aCharsets;
  1427. foreach ($this->m_aModuleSettings as $sModule => $aProperties)
  1428. {
  1429. foreach ($aProperties as $sProperty => $value)
  1430. {
  1431. $aSettings['module_settings'][$sModule][$sProperty] = $value;
  1432. }
  1433. }
  1434. foreach($this->m_aAddons as $sKey => $sFile)
  1435. {
  1436. $aSettings['addon_list'][] = $sFile;
  1437. }
  1438. return $aSettings;
  1439. }
  1440. /**
  1441. * Write the configuration to a file (php format) that can be reloaded later
  1442. * By default write to the same file that was specified when constructing the object
  1443. * @param $sFileName string Name of the file to write to (emtpy to write to the same file)
  1444. * @return boolean True otherwise throws an Exception
  1445. */
  1446. public function WriteToFile($sFileName = '')
  1447. {
  1448. if (empty($sFileName))
  1449. {
  1450. $sFileName = $this->m_sFile;
  1451. }
  1452. $hFile = @fopen($sFileName, 'w');
  1453. if ($hFile !== false)
  1454. {
  1455. fwrite($hFile, "<?php\n");
  1456. fwrite($hFile, "\n/**\n");
  1457. fwrite($hFile, " *\n");
  1458. fwrite($hFile, " * Configuration file, generated by the ".ITOP_APPLICATION." configuration wizard\n");
  1459. fwrite($hFile, " *\n");
  1460. fwrite($hFile, " * The file is used in MetaModel::LoadConfig() which does all the necessary initialization job\n");
  1461. fwrite($hFile, " *\n");
  1462. fwrite($hFile, " */\n");
  1463. $aConfigSettings = $this->m_aSettings;
  1464. // Old fashioned boolean settings
  1465. $aBoolValues = array(
  1466. 'log_global' => $this->m_bLogGlobal,
  1467. 'log_notification' => $this->m_bLogNotification,
  1468. 'log_issue' => $this->m_bLogIssue,
  1469. 'log_web_service' => $this->m_bLogWebService,
  1470. 'query_cache_enabled' => $this->m_bQueryCacheEnabled,
  1471. 'secure_connection_required' => $this->m_bSecureConnectionRequired,
  1472. );
  1473. foreach($aBoolValues as $sKey => $bValue)
  1474. {
  1475. $aConfigSettings[$sKey] = array(
  1476. 'show_in_conf_sample' => true,
  1477. 'type' => 'bool',
  1478. 'value' => $bValue,
  1479. );
  1480. }
  1481. // Old fashioned integer settings
  1482. $aIntValues = array(
  1483. 'fast_reload_interval' => $this->m_iFastReloadInterval,
  1484. 'max_display_limit' => $this->m_iMaxDisplayLimit,
  1485. 'min_display_limit' => $this->m_iMinDisplayLimit,
  1486. 'standard_reload_interval' => $this->m_iStandardReloadInterval,
  1487. );
  1488. foreach($aIntValues as $sKey => $iValue)
  1489. {
  1490. $aConfigSettings[$sKey] = array(
  1491. 'show_in_conf_sample' => true,
  1492. 'type' => 'integer',
  1493. 'value' => $iValue,
  1494. );
  1495. }
  1496. // Old fashioned remaining values
  1497. $aOtherValues = array(
  1498. 'db_host' => $this->m_sDBHost,
  1499. 'db_user' => $this->m_sDBUser,
  1500. 'db_pwd' => $this->m_sDBPwd,
  1501. 'db_name' => $this->m_sDBName,
  1502. 'db_subname' => $this->m_sDBSubname,
  1503. 'db_character_set' => $this->m_sDBCharacterSet,
  1504. 'db_collation' => $this->m_sDBCollation,
  1505. 'default_language' => $this->m_sDefaultLanguage,
  1506. 'allowed_login_types' => $this->m_sAllowedLoginTypes,
  1507. 'ext_auth_variable' => $this->m_sExtAuthVariable,
  1508. 'encryption_key' => $this->m_sEncryptionKey,
  1509. 'csv_import_charsets' => $this->m_aCharsets,
  1510. );
  1511. foreach($aOtherValues as $sKey => $value)
  1512. {
  1513. $aConfigSettings[$sKey] = array(
  1514. 'show_in_conf_sample' => true,
  1515. 'type' => is_string($value) ? 'string' : 'mixed',
  1516. 'value' => $value,
  1517. );
  1518. }
  1519. ksort($aConfigSettings);
  1520. fwrite($hFile, "\$MySettings = array(\n");
  1521. foreach($aConfigSettings as $sPropCode => $aSettingInfo)
  1522. {
  1523. // Write all values that are either always visible or present in the cloned config file
  1524. if ($aSettingInfo['show_in_conf_sample'] || (!empty($aSettingInfo['source_of_value']) && ($aSettingInfo['source_of_value'] != 'unknown')) )
  1525. {
  1526. $sType = $aSettingInfo['type'];
  1527. switch($sType)
  1528. {
  1529. case 'bool':
  1530. $sSeenAs = $aSettingInfo['value'] ? 'true' : 'false';
  1531. break;
  1532. default:
  1533. $sSeenAs = self::PrettyVarExport($aSettingInfo['value'], "\t");
  1534. }
  1535. fwrite($hFile, "\n");
  1536. if (isset($aSettingInfo['description']))
  1537. {
  1538. fwrite($hFile, "\t// $sPropCode: {$aSettingInfo['description']}\n");
  1539. }
  1540. if (isset($aSettingInfo['default']))
  1541. {
  1542. $default = $aSettingInfo['default'];
  1543. if ($aSettingInfo['type'] == 'bool')
  1544. {
  1545. $default = $default ? 'true' : 'false';
  1546. }
  1547. fwrite($hFile, "\t//\tdefault: ".self::PrettyVarExport($aSettingInfo['default'],"\t//\t\t", true)."\n");
  1548. }
  1549. fwrite($hFile, "\t'$sPropCode' => $sSeenAs,\n");
  1550. }
  1551. }
  1552. fwrite($hFile, ");\n");
  1553. fwrite($hFile, "\n");
  1554. fwrite($hFile, "/**\n *\n * Modules specific settings\n *\n */\n");
  1555. fwrite($hFile, "\$MyModuleSettings = array(\n");
  1556. foreach ($this->m_aModuleSettings as $sModule => $aProperties)
  1557. {
  1558. fwrite($hFile, "\t'$sModule' => array (\n");
  1559. foreach ($aProperties as $sProperty => $value)
  1560. {
  1561. $sNiceExport = self::PrettyVarExport($value, "\t\t");
  1562. fwrite($hFile, "\t\t'$sProperty' => $sNiceExport,\n");
  1563. }
  1564. fwrite($hFile, "\t),\n");
  1565. }
  1566. fwrite($hFile, ");\n");
  1567. fwrite($hFile, "\n/**\n");
  1568. fwrite($hFile, " *\n");
  1569. fwrite($hFile, " * Data model modules to be loaded. Names are specified as relative paths\n");
  1570. fwrite($hFile, " *\n");
  1571. fwrite($hFile, " */\n");
  1572. fwrite($hFile, "\$MyModules = array(\n");
  1573. fwrite($hFile, "\t'addons' => array (\n");
  1574. foreach($this->m_aAddons as $sKey => $sFile)
  1575. {
  1576. fwrite($hFile, "\t\t'$sKey' => '$sFile',\n");
  1577. }
  1578. fwrite($hFile, "\t),\n");
  1579. fwrite($hFile, ");\n");
  1580. fwrite($hFile, '?'.'>'); // Avoid perturbing the syntax highlighting !
  1581. return fclose($hFile);
  1582. }
  1583. else
  1584. {
  1585. throw new ConfigException("Could not write to configuration file", array('file' => $sFileName));
  1586. }
  1587. }
  1588. /**
  1589. * Helper function to initialize a configuration from the page arguments
  1590. */
  1591. public function UpdateFromParams($aParamValues, $sModulesDir = null, $bPreserveModuleSettings = false)
  1592. {
  1593. if (isset($aParamValues['application_path']))
  1594. {
  1595. $this->Set('app_root_url', $aParamValues['application_path']);
  1596. }
  1597. if (isset($aParamValues['graphviz_path']))
  1598. {
  1599. $this->Set('graphviz_path', $aParamValues['graphviz_path']);
  1600. }
  1601. if (isset($aParamValues['mode']) && isset($aParamValues['language']))
  1602. {
  1603. if (($aParamValues['mode'] == 'install') || $this->GetDefaultLanguage() == '')
  1604. {
  1605. $this->SetDefaultLanguage($aParamValues['language']);
  1606. }
  1607. }
  1608. if (isset($aParamValues['db_server']))
  1609. {
  1610. $this->SetDBHost($aParamValues['db_server']);
  1611. $this->SetDBUser($aParamValues['db_user']);
  1612. $this->SetDBPwd($aParamValues['db_pwd']);
  1613. $sDBName = $aParamValues['db_name'];
  1614. if ($sDBName == '')
  1615. {
  1616. // Todo - obsolete after the transition to the new setup (2.0) is complete (WARNING: used by the designer)
  1617. $sDBName = $aParamValues['new_db_name'];
  1618. }
  1619. $this->SetDBName($sDBName);
  1620. $this->SetDBSubname($aParamValues['db_prefix']);
  1621. }
  1622. if (isset($aParamValues['selected_modules']))
  1623. {
  1624. $aSelectedModules = explode(',', $aParamValues['selected_modules']);
  1625. }
  1626. else
  1627. {
  1628. $aSelectedModules = null;
  1629. }
  1630. $this->UpdateIncludes($sModulesDir, $aSelectedModules);
  1631. }
  1632. /**
  1633. * Helper function to rebuild the default configuration and the list of includes from a directory and a list of selected modules
  1634. * @param string $sModulesDir The relative path to the directory to scan for modules (typically the 'env-xxx' directory resulting from the compilation)
  1635. * @param array $aSelectedModules An array of selected modules' identifiers. If null all modules found will be considered as installed
  1636. * @throws Exception
  1637. */
  1638. public function UpdateIncludes($sModulesDir, $aSelectedModules = null)
  1639. {
  1640. if (!is_null($sModulesDir))
  1641. {
  1642. // Initialize the arrays below with default values for the application...
  1643. $oEmptyConfig = new Config('dummy_file', false); // Do NOT load any config file, just set the default values
  1644. $aAddOns = $oEmptyConfig->GetAddOns();
  1645. $aModules = ModuleDiscovery::GetAvailableModules(array(APPROOT.$sModulesDir));
  1646. foreach ($aModules as $sModuleId => $aModuleInfo)
  1647. {
  1648. list ($sModuleName, $sModuleVersion) = ModuleDiscovery::GetModuleName($sModuleId);
  1649. if (is_null($aSelectedModules) || in_array($sModuleName, $aSelectedModules))
  1650. {
  1651. if (isset($aModuleInfo['settings']))
  1652. {
  1653. list ($sName, $sVersion) = ModuleDiscovery::GetModuleName($sModuleId);
  1654. foreach ($aModuleInfo['settings'] as $sProperty => $value)
  1655. {
  1656. if (isset($this->m_aModuleSettings[$sName][$sProperty]))
  1657. {
  1658. // Do nothing keep the original value
  1659. }
  1660. else
  1661. {
  1662. $this->SetModuleSetting($sName, $sProperty, $value);
  1663. }
  1664. }
  1665. }
  1666. if (isset($aModuleInfo['installer']))
  1667. {
  1668. $sModuleInstallerClass = $aModuleInfo['installer'];
  1669. if (!class_exists($sModuleInstallerClass))
  1670. {
  1671. throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not a PHP class - Module: ".$aModuleInfo['label']);
  1672. }
  1673. if (!is_subclass_of($sModuleInstallerClass, 'ModuleInstallerAPI'))
  1674. {
  1675. throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not derived from 'ModuleInstallerAPI' - Module: ".$aModuleInfo['label']);
  1676. }
  1677. $aCallSpec = array($sModuleInstallerClass,'BeforeWritingConfig');
  1678. call_user_func_array($aCallSpec, array($this));
  1679. }
  1680. }
  1681. }
  1682. $this->SetAddOns($aAddOns);
  1683. }
  1684. }
  1685. /**
  1686. * Helper: for an array of string, change the prefix when found
  1687. */
  1688. protected static function ChangePrefix(&$aStrings, $sSearchPrefix, $sNewPrefix)
  1689. {
  1690. foreach ($aStrings as &$sFile)
  1691. {
  1692. if (substr($sFile, 0, strlen($sSearchPrefix)) == $sSearchPrefix)
  1693. {
  1694. $sFile = $sNewPrefix.substr($sFile, strlen($sSearchPrefix));
  1695. }
  1696. }
  1697. }
  1698. /**
  1699. * Obsolete: kept only for backward compatibility of the Toolkit
  1700. * Quick and dirty way to clone a config file into another environment
  1701. */
  1702. public function ChangeModulesPath($sSourceEnv, $sTargetEnv)
  1703. {
  1704. // Now does nothing since the includes are built into the environment itself
  1705. }
  1706. /**
  1707. * Pretty format a var_export'ed value so that (if possible) the identation is preserved on every line
  1708. * @param mixed $value The value to export
  1709. * @param string $sIndentation The string to use to indent the text
  1710. * @param bool $bForceIndentation Forces the identation (enven if it breaks/changes an eval, for example to ouput a value inside a comment)
  1711. * @return string The indented export string
  1712. */
  1713. protected static function PrettyVarExport($value, $sIndentation, $bForceIndentation = false)
  1714. {
  1715. $sExport = var_export($value, true);
  1716. $sNiceExport = str_replace(array("\r\n", "\n", "\r"), "\n".$sIndentation, trim($sExport));
  1717. if (!$bForceIndentation)
  1718. {
  1719. eval('$aImported='.$sNiceExport.';');
  1720. // Check if adding the identations at the beginning of each line
  1721. // did not modify the values (in case of a string containing a line break)
  1722. if($aImported != $value)
  1723. {
  1724. $sNiceExport = $sExport;
  1725. }
  1726. }
  1727. return $sNiceExport;
  1728. }
  1729. }
  1730. ?>