config.class.inc.php 51 KB

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