config.class.inc.php 52 KB

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