config.class.inc.php 49 KB

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