config.class.inc.php 62 KB

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