config.class.inc.php 52 KB

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