config.class.inc.php 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019
  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_VERSION', '$ITOP_VERSION$');
  17. define('ITOP_REVISION', '$WCREV$');
  18. define('ITOP_BUILD_DATE', '$WCNOW$');
  19. define('ACCESS_USER_WRITE', 1);
  20. define('ACCESS_ADMIN_WRITE', 2);
  21. define('ACCESS_FULL', ACCESS_USER_WRITE | ACCESS_ADMIN_WRITE);
  22. define('ACCESS_READONLY', 0);
  23. /**
  24. * Configuration read/write
  25. *
  26. * @author Erwan Taloc <erwan.taloc@combodo.com>
  27. * @author Romain Quetiez <romain.quetiez@combodo.com>
  28. * @author Denis Flaven <denis.flaven@combodo.com>
  29. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  30. */
  31. require_once('coreexception.class.inc.php');
  32. class ConfigException extends CoreException
  33. {
  34. }
  35. define ('DEFAULT_CHARACTER_SET', 'utf8');
  36. define ('DEFAULT_COLLATION', 'utf8_general_ci');
  37. define ('DEFAULT_LOG_GLOBAL', true);
  38. define ('DEFAULT_LOG_NOTIFICATION', true);
  39. define ('DEFAULT_LOG_ISSUE', true);
  40. define ('DEFAULT_LOG_WEB_SERVICE', true);
  41. define ('DEFAULT_LOG_KPI_DURATION', false);
  42. define ('DEFAULT_LOG_KPI_MEMORY', false);
  43. define ('DEFAULT_DEBUG_QUERIES', false);
  44. define ('DEFAULT_QUERY_CACHE_ENABLED', true);
  45. define ('DEFAULT_MIN_DISPLAY_LIMIT', 10);
  46. define ('DEFAULT_MAX_DISPLAY_LIMIT', 15);
  47. define ('DEFAULT_STANDARD_RELOAD_INTERVAL', 5*60);
  48. define ('DEFAULT_FAST_RELOAD_INTERVAL', 1*60);
  49. define ('DEFAULT_SECURE_CONNECTION_REQUIRED', false);
  50. define ('DEFAULT_HTTPS_HYPERLINKS', 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. 'skip_check_to_write' => array(
  74. 'type' => 'bool',
  75. 'description' => 'Disable data format and integrity checks to boost up data load (insert or update)',
  76. 'default' => false,
  77. 'value' => false,
  78. 'source_of_value' => '',
  79. 'show_in_conf_sample' => false,
  80. ),
  81. 'skip_check_ext_keys' => array(
  82. 'type' => 'bool',
  83. 'description' => 'Disable external key check when checking the value of attribtutes',
  84. 'default' => false,
  85. 'value' => false,
  86. 'source_of_value' => '',
  87. 'show_in_conf_sample' => false,
  88. ),
  89. 'skip_strong_security' => array(
  90. 'type' => 'bool',
  91. 'description' => 'Disable strong security - TEMPORY: this flag should be removed when we are more confident in the recent change in security',
  92. 'default' => true,
  93. 'value' => true,
  94. 'source_of_value' => '',
  95. 'show_in_conf_sample' => false,
  96. ),
  97. 'graphviz_path' => array(
  98. 'type' => 'string',
  99. 'description' => 'Path to the Graphviz "dot" executable for graphing objects lifecycle',
  100. 'default' => '/usr/bin/dot',
  101. 'value' => '',
  102. 'source_of_value' => '',
  103. 'show_in_conf_sample' => false,
  104. ),
  105. 'session_name' => array(
  106. 'type' => 'string',
  107. 'description' => 'The name of the cookie used to store the PHP session id',
  108. 'default' => 'iTop',
  109. 'value' => '',
  110. 'source_of_value' => '',
  111. 'show_in_conf_sample' => true,
  112. ),
  113. 'max_combo_length' => array(
  114. 'type' => 'int',
  115. 'description' => 'The maximum number of elements in a drop-down list. If more then an autocomplete will be used',
  116. 'default' => 50,
  117. 'value' => 50,
  118. 'source_of_value' => '',
  119. 'show_in_conf_sample' => false,
  120. ),
  121. 'min_autocomplete_chars' => array(
  122. 'type' => 'int',
  123. 'description' => 'The minimum number of characters to type in order to trigger the "autocomplete" behavior',
  124. 'default' => 3,
  125. 'value' => 3,
  126. 'source_of_value' => '',
  127. 'show_in_conf_sample' => false,
  128. ),
  129. 'allow_target_creation' => array(
  130. 'type' => 'bool',
  131. 'description' => 'Displays the + button on external keys to create target objects',
  132. 'default' => true,
  133. 'value' => true,
  134. 'source_of_value' => '',
  135. 'show_in_conf_sample' => false,
  136. ),
  137. // Levels that trigger a confirmation in the CSV import/synchro wizard
  138. 'csv_import_min_object_confirmation' => array(
  139. 'type' => 'integer',
  140. 'description' => 'Minimum number of objects to check for the confirmation percentages',
  141. 'default' => 3,
  142. 'value' => 3,
  143. 'source_of_value' => '',
  144. 'show_in_conf_sample' => false,
  145. ),
  146. 'csv_import_errors_percentage' => array(
  147. 'type' => 'integer',
  148. 'description' => 'Percentage of errors that trigger a confirmation in the CSV import',
  149. 'default' => 50,
  150. 'value' => 50,
  151. 'source_of_value' => '',
  152. 'show_in_conf_sample' => false,
  153. ),
  154. 'csv_import_modifications_percentage' => array(
  155. 'type' => 'integer',
  156. 'description' => 'Percentage of modifications that trigger a confirmation in the CSV import',
  157. 'default' => 50,
  158. 'value' => 50,
  159. 'source_of_value' => '',
  160. 'show_in_conf_sample' => false,
  161. ),
  162. 'csv_import_creations_percentage' => array(
  163. 'type' => 'integer',
  164. 'description' => 'Percentage of creations that trigger a confirmation in the CSV import',
  165. 'default' => 50,
  166. 'value' => 50,
  167. 'source_of_value' => '',
  168. 'show_in_conf_sample' => false,
  169. ),
  170. 'access_mode' => array(
  171. 'type' => 'integer',
  172. 'description' => 'Combination of flags (ACCESS_USER_WRITE | ACCESS_ADMIN_WRITE, or ACCESS_FULL)',
  173. 'default' => ACCESS_FULL,
  174. 'value' => ACCESS_FULL,
  175. 'source_of_value' => '',
  176. 'show_in_conf_sample' => true,
  177. ),
  178. 'access_message' => array(
  179. 'type' => 'string',
  180. 'description' => 'Message displayed to the users when there is any access restriction',
  181. 'default' => 'iTop is temporarily frozen, please wait... (the admin team)',
  182. 'value' => '',
  183. 'source_of_value' => '',
  184. 'show_in_conf_sample' => true,
  185. ),
  186. );
  187. public function IsProperty($sPropCode)
  188. {
  189. return (array_key_exists($sPropCode, $this->m_aSettings));
  190. }
  191. public function Set($sPropCode, $value, $sSourceDesc = 'unknown')
  192. {
  193. $sType = $this->m_aSettings[$sPropCode]['type'];
  194. switch($sType)
  195. {
  196. case 'bool':
  197. $value = (bool) $value;
  198. break;
  199. case 'string':
  200. $value = (string) $value;
  201. break;
  202. case 'integer':
  203. $value = (integer) $value;
  204. break;
  205. case 'float':
  206. $value = (float) $value;
  207. break;
  208. default:
  209. throw new CoreException('Unknown type for setting', array('property' => $sPropCode, 'type' => $sType));
  210. }
  211. $this->m_aSettings[$sPropCode]['value'] = $value;
  212. $this->m_aSettings[$sPropCode]['source_of_value'] = $sSourceDesc;
  213. }
  214. public function Get($sPropCode)
  215. {
  216. return $this->m_aSettings[$sPropCode]['value'];
  217. }
  218. // Those variables will be deprecated later, when the transition to ...Get('my_setting') will be done
  219. protected $m_sDBHost;
  220. protected $m_sDBUser;
  221. protected $m_sDBPwd;
  222. protected $m_sDBName;
  223. protected $m_sDBSubname;
  224. protected $m_sDBCharacterSet;
  225. protected $m_sDBCollation;
  226. /**
  227. * Event log options (see LOG_... definition)
  228. */
  229. // Those variables will be deprecated later, when the transition to ...Get('my_setting') will be done
  230. protected $m_bLogGlobal;
  231. protected $m_bLogNotification;
  232. protected $m_bLogIssue;
  233. protected $m_bLogWebService;
  234. protected $m_bLogKpiDuration; // private setting
  235. protected $m_bLogKpiMemory; // private setting
  236. protected $m_bDebugQueries; // private setting
  237. protected $m_bQueryCacheEnabled; // private setting
  238. /**
  239. * @var integer Number of elements to be displayed when there are more than m_iMaxDisplayLimit elements
  240. */
  241. protected $m_iMinDisplayLimit;
  242. /**
  243. * @var integer Max number of elements before truncating the display
  244. */
  245. protected $m_iMaxDisplayLimit;
  246. /**
  247. * @var integer Number of seconds between two reloads of the display (standard)
  248. */
  249. protected $m_iStandardReloadInterval;
  250. /**
  251. * @var integer Number of seconds between two reloads of the display (fast)
  252. */
  253. protected $m_iFastReloadInterval;
  254. /**
  255. * @var boolean Whether or not a secure connection is required for using the application.
  256. * If set, any attempt to connect to an iTop page with http:// will be redirected
  257. * to https://
  258. */
  259. protected $m_bSecureConnectionRequired;
  260. /**
  261. * @var boolean Forces iTop to output hyperlinks starting with https:// even
  262. * if the current page is not using https. This can be useful when
  263. * the application runs behind a SSL gateway
  264. */
  265. protected $m_bHttpsHyperlinks;
  266. /**
  267. * @var string Langage code, default if the user language is undefined
  268. */
  269. protected $m_sDefaultLanguage;
  270. /**
  271. * @var string Type of login process allowed: form|basic|url|external
  272. */
  273. protected $m_sAllowedLoginTypes;
  274. /**
  275. * @var string Name of the PHP variable in which external authentication information is passed by the web server
  276. */
  277. protected $m_sExtAuthVariable;
  278. /**
  279. * @var string Encryption key used for all attributes of type "encrypted string". Can be set to a random value
  280. * unless you want to import a database from another iTop instance, in which case you must use
  281. * the same encryption key in order to properly decode the encrypted fields
  282. */
  283. protected $m_sEncryptionKey;
  284. /**
  285. * @var array Additional character sets to be supported by the interactive CSV import
  286. * 'iconv_code' => 'display name'
  287. */
  288. protected $m_aCharsets;
  289. public function __construct($sConfigFile, $bLoadConfig = true)
  290. {
  291. $this->m_sFile = $sConfigFile;
  292. $this->m_aAppModules = array(
  293. // Some default modules, always present can be move to an official iTop Module later if needed
  294. 'application/transaction.class.inc.php',
  295. 'application/menunode.class.inc.php',
  296. 'application/user.preferences.class.inc.php',
  297. 'application/audit.rule.class.inc.php',
  298. // Romain - That's dirty, because those 3 classes are in fact part of the core
  299. // but I needed those classes to be derived from cmdbAbstractObject
  300. // (to be managed via the GUI) and this class in not really known from
  301. // the core, PLUS I needed the includes to be there also for the setup
  302. // to create the tables.
  303. 'core/event.class.inc.php',
  304. 'core/action.class.inc.php',
  305. 'core/trigger.class.inc.php',
  306. );
  307. $this->m_aDataModels = array();
  308. $this->m_aWebServiceCategories = array(
  309. 'webservices/webservices.basic.php',
  310. );
  311. $this->m_aAddons = array(
  312. // Default AddOn, always present can be moved to an official iTop Module later if needed
  313. 'user rights' => 'addons/userrights/userrightsprofile.class.inc.php',
  314. );
  315. $this->m_aDictionaries = array(
  316. // Default dictionaries, always present can be moved to an official iTop Module later if needed
  317. 'dictionaries/dictionary.itop.core.php',
  318. 'dictionaries/dictionary.itop.ui.php', // Support for English
  319. 'dictionaries/fr.dictionary.itop.ui.php', // Support for French
  320. 'dictionaries/fr.dictionary.itop.core.php', // Support for French
  321. 'dictionaries/es_cr.dictionary.itop.ui.php', // Support for Spanish (from Costa Rica)
  322. 'dictionaries/es_cr.dictionary.itop.core.php', // Support for Spanish (from Costa Rica)
  323. 'dictionaries/de.dictionary.itop.ui.php', // Support for German
  324. 'dictionaries/de.dictionary.itop.core.php', // Support for German
  325. 'dictionaries/pt_br.dictionary.itop.ui.php', // Support for Brazilian Portuguese
  326. 'dictionaries/pt_br.dictionary.itop.core.php', // Support for Brazilian Portuguese
  327. );
  328. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  329. {
  330. $this->m_aSettings[$sPropCode]['value'] = $aSettingInfo['default'];
  331. }
  332. $this->m_sDBHost = '';
  333. $this->m_sDBUser = '';
  334. $this->m_sDBPwd = '';
  335. $this->m_sDBName = '';
  336. $this->m_sDBSubname = '';
  337. $this->m_sDBCharacterSet = DEFAULT_CHARACTER_SET;
  338. $this->m_sDBCollation = DEFAULT_COLLATION;
  339. $this->m_bLogGlobal = DEFAULT_LOG_GLOBAL;
  340. $this->m_bLogNotification = DEFAULT_LOG_NOTIFICATION;
  341. $this->m_bLogIssue = DEFAULT_LOG_ISSUE;
  342. $this->m_bLogWebService = DEFAULT_LOG_WEB_SERVICE;
  343. $this->m_bLogKPIDuration = DEFAULT_LOG_KPI_DURATION;
  344. $this->m_bLogKPIDuration = DEFAULT_LOG_KPI_DURATION;
  345. $this->m_iMinDisplayLimit = DEFAULT_MIN_DISPLAY_LIMIT;
  346. $this->m_iMaxDisplayLimit = DEFAULT_MAX_DISPLAY_LIMIT;
  347. $this->m_iStandardReloadInterval = DEFAULT_STANDARD_RELOAD_INTERVAL;
  348. $this->m_iFastReloadInterval = DEFAULT_FAST_RELOAD_INTERVAL;
  349. $this->m_bSecureConnectionRequired = DEFAULT_SECURE_CONNECTION_REQUIRED;
  350. $this->m_bHttpsHyperlinks = DEFAULT_HTTPS_HYPERLINKS;
  351. $this->m_sDefaultLanguage = 'EN US';
  352. $this->m_sAllowedLoginTypes = DEFAULT_ALLOWED_LOGIN_TYPES;
  353. $this->m_sExtAuthVariable = DEFAULT_EXT_AUTH_VARIABLE;
  354. $this->m_sEncryptionKey = DEFAULT_ENCRYPTION_KEY;
  355. $this->m_aCharsets = array();
  356. $this->m_aModuleSettings = array();
  357. if ($bLoadConfig)
  358. {
  359. $this->Load($sConfigFile);
  360. $this->Verify();
  361. }
  362. }
  363. protected function CheckFile($sPurpose, $sFileName)
  364. {
  365. if (!file_exists($sFileName))
  366. {
  367. throw new ConfigException("Could not find $sPurpose file", array('file' => $sFileName));
  368. }
  369. }
  370. protected function Load($sConfigFile)
  371. {
  372. $this->CheckFile('configuration', $sConfigFile);
  373. $sConfigCode = trim(file_get_contents($sConfigFile));
  374. // This does not work on several lines
  375. // preg_match('/^<\\?php(.*)\\?'.'>$/', $sConfigCode, $aMatches)...
  376. // So, I've implemented a solution suggested in the PHP doc (search for phpWrapper)
  377. try
  378. {
  379. ob_start();
  380. eval('?'.'>'.trim($sConfigCode));
  381. $sNoise = trim(ob_get_contents());
  382. ob_end_clean();
  383. }
  384. catch (Exception $e)
  385. {
  386. // well, never reach in case of parsing error :-(
  387. // will be improved in PHP 6 ?
  388. throw new ConfigException('Error in configuration file', array('file' => $sConfigFile, 'error' => $e->getMessage()));
  389. }
  390. if (strlen($sNoise) > 0)
  391. {
  392. // Note: sNoise is an html output, but so far it was ok for me (e.g. showing the entire call stack)
  393. throw new ConfigException('Syntax error in configuration file', array('file' => $sConfigFile, 'error' => '<tt>'.htmlentities($sNoise).'</tt>'));
  394. }
  395. if (!isset($MySettings) || !is_array($MySettings))
  396. {
  397. throw new ConfigException('Missing array in configuration file', array('file' => $sConfigFile, 'expected' => '$MySettings'));
  398. }
  399. if (!isset($MyModules) || !is_array($MyModules))
  400. {
  401. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules'));
  402. }
  403. if (!array_key_exists('application', $MyModules))
  404. {
  405. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'application\']'));
  406. }
  407. if (!array_key_exists('business', $MyModules))
  408. {
  409. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'business\']'));
  410. }
  411. if (!array_key_exists('addons', $MyModules))
  412. {
  413. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'addons\']'));
  414. }
  415. if (!array_key_exists('user rights', $MyModules['addons']))
  416. {
  417. // Add one, by default
  418. $MyModules['addons']['user rights'] = '/addons/userrights/userrightsnull.class.inc.php';
  419. }
  420. if (!array_key_exists('dictionaries', $MyModules))
  421. {
  422. throw new ConfigException('Missing item in configuration file', array('file' => $sConfigFile, 'expected' => '$MyModules[\'dictionaries\']'));
  423. }
  424. $this->m_aAppModules = $MyModules['application'];
  425. $this->m_aDataModels = $MyModules['business'];
  426. if (isset($MyModules['webservices']))
  427. {
  428. $this->m_aWebServiceCategories = $MyModules['webservices'];
  429. }
  430. $this->m_aAddons = $MyModules['addons'];
  431. $this->m_aDictionaries = $MyModules['dictionaries'];
  432. foreach($MySettings as $sPropCode => $rawvalue)
  433. {
  434. if ($this->IsProperty($sPropCode))
  435. {
  436. $value = trim($rawvalue);
  437. $this->Set($sPropCode, $value, $sConfigFile);
  438. }
  439. }
  440. $this->m_sDBHost = trim($MySettings['db_host']);
  441. $this->m_sDBUser = trim($MySettings['db_user']);
  442. $this->m_sDBPwd = trim($MySettings['db_pwd']);
  443. $this->m_sDBName = trim($MySettings['db_name']);
  444. $this->m_sDBSubname = trim($MySettings['db_subname']);
  445. $this->m_sDBCharacterSet = isset($MySettings['db_character_set']) ? trim($MySettings['db_character_set']) : DEFAULT_CHARACTER_SET;
  446. $this->m_sDBCollation = isset($MySettings['db_collation']) ? trim($MySettings['db_collation']) : DEFAULT_COLLATION;
  447. $this->m_bLogGlobal = isset($MySettings['log_global']) ? (bool) trim($MySettings['log_global']) : DEFAULT_LOG_GLOBAL;
  448. $this->m_bLogNotification = isset($MySettings['log_notification']) ? (bool) trim($MySettings['log_notification']) : DEFAULT_LOG_NOTIFICATION;
  449. $this->m_bLogIssue = isset($MySettings['log_issue']) ? (bool) trim($MySettings['log_issue']) : DEFAULT_LOG_ISSUE;
  450. $this->m_bLogWebService = isset($MySettings['log_web_service']) ? (bool) trim($MySettings['log_web_service']) : DEFAULT_LOG_WEB_SERVICE;
  451. $this->m_bLogKPIDuration = isset($MySettings['log_kpi_duration']) ? (bool) trim($MySettings['log_kpi_duration']) : DEFAULT_LOG_KPI_DURATION;
  452. $this->m_bLogKPIMemory = isset($MySettings['log_kpi_memory']) ? (bool) trim($MySettings['log_kpi_memory']) : DEFAULT_LOG_KPI_MEMORY;
  453. $this->m_bDebugQueries = isset($MySettings['debug_queries']) ? (bool) trim($MySettings['debug_queries']) : DEFAULT_DEBUG_QUERIES;
  454. $this->m_bQueryCacheEnabled = isset($MySettings['query_cache_enabled']) ? (bool) trim($MySettings['query_cache_enabled']) : DEFAULT_QUERY_CACHE_ENABLED;
  455. $this->m_iMinDisplayLimit = isset($MySettings['min_display_limit']) ? trim($MySettings['min_display_limit']) : DEFAULT_MIN_DISPLAY_LIMIT;
  456. $this->m_iMaxDisplayLimit = isset($MySettings['max_display_limit']) ? trim($MySettings['max_display_limit']) : DEFAULT_MAX_DISPLAY_LIMIT;
  457. $this->m_iStandardReloadInterval = isset($MySettings['standard_reload_interval']) ? trim($MySettings['standard_reload_interval']) : DEFAULT_STANDARD_RELOAD_INTERVAL;
  458. $this->m_iFastReloadInterval = isset($MySettings['fast_reload_interval']) ? trim($MySettings['fast_reload_interval']) : DEFAULT_FAST_RELOAD_INTERVAL;
  459. $this->m_bSecureConnectionRequired = isset($MySettings['secure_connection_required']) ? (bool) trim($MySettings['secure_connection_required']) : DEFAULT_SECURE_CONNECTION_REQUIRED;
  460. $this->m_bHttpsHyperlinks = isset($MySettings['https_hyperlinks']) ? (bool) trim($MySettings['https_hyperlinks']) : DEFAULT_HTTPS_HYPERLINKS;
  461. $this->m_aModuleSettings = isset($MyModuleSettings) ? $MyModuleSettings : array();
  462. $this->m_sDefaultLanguage = isset($MySettings['default_language']) ? trim($MySettings['default_language']) : 'EN US';
  463. $this->m_sAllowedLoginTypes = isset($MySettings['allowed_login_types']) ? trim($MySettings['allowed_login_types']) : DEFAULT_ALLOWED_LOGIN_TYPES;
  464. $this->m_sExtAuthVariable = isset($MySettings['ext_auth_variable']) ? trim($MySettings['ext_auth_variable']) : DEFAULT_EXT_AUTH_VARIABLE;
  465. $this->m_sEncryptionKey = isset($MySettings['encryption_key']) ? trim($MySettings['encryption_key']) : DEFAULT_ENCRYPTION_KEY;
  466. $this->m_aCharsets = isset($MySettings['csv_import_charsets']) ? $MySettings['csv_import_charsets'] : array();
  467. }
  468. protected function Verify()
  469. {
  470. // Files are verified later on, just before using them -see MetaModel::Plugin()
  471. // (we have their final path at that point)
  472. }
  473. public function GetModuleSetting($sModule, $sProperty, $defaultvalue = null)
  474. {
  475. if (isset($this->m_aModuleSettings[$sModule][$sProperty]))
  476. {
  477. return $this->m_aModuleSettings[$sModule][$sProperty];
  478. }
  479. return $defaultvalue;
  480. }
  481. public function SetModuleSetting($sModule, $sProperty, $value)
  482. {
  483. $this->m_aModuleSettings[$sModule][$sProperty] = $value;
  484. }
  485. public function GetAppModules()
  486. {
  487. return $this->m_aAppModules;
  488. }
  489. public function SetAppModules($aAppModules)
  490. {
  491. $this->m_aAppModules = $aAppModules;
  492. }
  493. public function GetDataModels()
  494. {
  495. return $this->m_aDataModels;
  496. }
  497. public function SetDataModels($aDataModels)
  498. {
  499. $this->m_aDataModels = $aDataModels;
  500. }
  501. public function GetWebServiceCategories()
  502. {
  503. return $this->m_aWebServiceCategories;
  504. }
  505. public function SetWebServiceCategories($aWebServiceCategories)
  506. {
  507. $this->m_aWebServiceCategories = $aWebServiceCategories;
  508. }
  509. public function GetAddons()
  510. {
  511. return $this->m_aAddons;
  512. }
  513. public function SetAddons($aAddons)
  514. {
  515. $this->m_aAddons = $aAddons;
  516. }
  517. public function GetDictionaries()
  518. {
  519. return $this->m_aDictionaries;
  520. }
  521. public function SetDictionaries($aDictionaries)
  522. {
  523. $this->m_aDictionaries = $aDictionaries;
  524. }
  525. public function GetDBHost()
  526. {
  527. return $this->m_sDBHost;
  528. }
  529. public function GetDBName()
  530. {
  531. return $this->m_sDBName;
  532. }
  533. public function GetDBSubname()
  534. {
  535. return $this->m_sDBSubname;
  536. }
  537. public function GetDBCharacterSet()
  538. {
  539. return $this->m_sDBCharacterSet;
  540. }
  541. public function GetDBCollation()
  542. {
  543. return $this->m_sDBCollation;
  544. }
  545. public function GetDBUser()
  546. {
  547. return $this->m_sDBUser;
  548. }
  549. public function GetDBPwd()
  550. {
  551. return $this->m_sDBPwd;
  552. }
  553. public function GetLogGlobal()
  554. {
  555. return $this->m_bLogGlobal;
  556. }
  557. public function GetLogNotification()
  558. {
  559. return $this->m_bLogNotification;
  560. }
  561. public function GetLogIssue()
  562. {
  563. return $this->m_bLogIssue;
  564. }
  565. public function GetLogWebService()
  566. {
  567. return $this->m_bLogWebService;
  568. }
  569. public function GetLogKPIDuration()
  570. {
  571. return $this->m_bLogKPIDuration;
  572. }
  573. public function GetLogKPIMemory()
  574. {
  575. return $this->m_bLogKPIMemory;
  576. }
  577. public function GetDebugQueries()
  578. {
  579. return $this->m_bDebugQueries;
  580. }
  581. public function GetQueryCacheEnabled()
  582. {
  583. return $this->m_bQueryCacheEnabled;
  584. }
  585. public function GetMinDisplayLimit()
  586. {
  587. return $this->m_iMinDisplayLimit;
  588. }
  589. public function GetMaxDisplayLimit()
  590. {
  591. return $this->m_iMaxDisplayLimit;
  592. }
  593. public function GetStandardReloadInterval()
  594. {
  595. return $this->m_iStandardReloadInterval;
  596. }
  597. public function GetFastReloadInterval()
  598. {
  599. return $this->m_iFastReloadInterval;
  600. }
  601. public function GetSecureConnectionRequired()
  602. {
  603. return $this->m_bSecureConnectionRequired;
  604. }
  605. public function GetHttpsHyperlinks()
  606. {
  607. return $this->m_bHttpsHyperlinks;
  608. }
  609. public function GetDefaultLanguage()
  610. {
  611. return $this->m_sDefaultLanguage;
  612. }
  613. public function GetEncryptionKey()
  614. {
  615. return $this->m_sEncryptionKey;
  616. }
  617. public function GetAllowedLoginTypes()
  618. {
  619. return explode('|', $this->m_sAllowedLoginTypes);
  620. }
  621. public function GetExternalAuthenticationVariable()
  622. {
  623. return $this->m_sExtAuthVariable;
  624. }
  625. public function GetCSVImportCharsets()
  626. {
  627. return $this->m_aCharsets;
  628. }
  629. public function SetDBHost($sDBHost)
  630. {
  631. $this->m_sDBHost = $sDBHost;
  632. }
  633. public function SetDBName($sDBName)
  634. {
  635. $this->m_sDBName = $sDBName;
  636. }
  637. public function SetDBSubname($sDBSubName)
  638. {
  639. $this->m_sDBSubname = $sDBSubName;
  640. }
  641. public function SetDBCharacterSet($sDBCharacterSet)
  642. {
  643. $this->m_sDBCharacterSet = $sDBCharacterSet;
  644. }
  645. public function SetDBCollation($sDBCollation)
  646. {
  647. $this->m_sDBCollation = $sDBCollation;
  648. }
  649. public function SetDBUser($sUser)
  650. {
  651. $this->m_sDBUser = $sUser;
  652. }
  653. public function SetDBPwd($sPwd)
  654. {
  655. $this->m_sDBPwd = $sPwd;
  656. }
  657. public function SetLogGlobal($iLogGlobal)
  658. {
  659. $this->m_iLogGlobal = $iLogGlobal;
  660. }
  661. public function SetLogNotification($iLogNotification)
  662. {
  663. $this->m_iLogNotification = $iLogNotification;
  664. }
  665. public function SetLogIssue($iLogIssue)
  666. {
  667. $this->m_iLogIssue = $iLogIssue;
  668. }
  669. public function SetLogWebService($iLogWebService)
  670. {
  671. $this->m_iLogWebService = $iLogWebService;
  672. }
  673. public function SetMinDisplayLimit($iMinDisplayLimit)
  674. {
  675. $this->m_iMinDisplayLimit = $iMinDisplayLimit;
  676. }
  677. public function SetMaxDisplayLimit($iMaxDisplayLimit)
  678. {
  679. $this->m_iMaxDisplayLimit = $iMaxDisplayLimit;
  680. }
  681. public function SetStandardReloadInterval($iStandardReloadInterval)
  682. {
  683. $this->m_iStandardReloadInterval = $iStandardReloadInterval;
  684. }
  685. public function SetFastReloadInterval($iFastReloadInterval)
  686. {
  687. $this->m_iFastReloadInterval = $iFastReloadInterval;
  688. }
  689. public function SetSecureConnectionRequired($bSecureConnectionRequired)
  690. {
  691. $this->m_bSecureConnectionRequired = $bSecureConnectionRequired;
  692. }
  693. public function SetHttpsHyperlinks($bHttpsHyperlinks)
  694. {
  695. $this->m_bHttpsHyperlinks = $bHttpsHyperlinks;
  696. }
  697. public function SetDefaultLanguage($sLanguageCode)
  698. {
  699. $this->m_sDefaultLanguage = $sLanguageCode;
  700. }
  701. public function SetAllowedLoginTypes($aAllowedLoginTypes)
  702. {
  703. $this->m_sAllowedLoginTypes = implode('|', $aAllowedLoginTypes);
  704. }
  705. public function SetExternalAuthenticationVariable($sExtAuthVariable)
  706. {
  707. $this->m_sExtAuthVariable = $sExtAuthVariable;
  708. }
  709. public function SetEncryptionKey($sKey)
  710. {
  711. $this->m_sEncryptionKey = $sKey;
  712. }
  713. public function SetCSVImportCharsets($aCharsets)
  714. {
  715. $this->m_aCharsets = $aCharsets;
  716. }
  717. public function AddCSVImportCharset($sIconvCode, $sDisplayName)
  718. {
  719. $this->m_aCharsets[$sIconvCode] = $sDisplayName;
  720. }
  721. public function FileIsWritable()
  722. {
  723. return is_writable($this->m_sFile);
  724. }
  725. /**
  726. * Render the configuration as an associative array
  727. * @return boolean True otherwise throws an Exception
  728. */
  729. public function ToArray()
  730. {
  731. $aSettings = array();
  732. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  733. {
  734. $aSettings[$sPropCode] = $aSettingInfo['value'];
  735. }
  736. $aSettings['db_host'] = $this->m_sDBHost;
  737. $aSettings['db_user'] = $this->m_sDBUser;
  738. $aSettings['db_pwd'] = $this->m_sDBPwd;
  739. $aSettings['db_name'] = $this->m_sDBName;
  740. $aSettings['db_subname'] = $this->m_sDBSubname;
  741. $aSettings['db_character_set'] = $this->m_sDBCharacterSet;
  742. $aSettings['db_collation'] = $this->m_sDBCollation;
  743. $aSettings['log_global'] = $this->m_bLogGlobal;
  744. $aSettings['log_notification'] = $this->m_bLogNotification;
  745. $aSettings['log_issue'] = $this->m_bLogIssue;
  746. $aSettings['log_web_service'] = $this->m_bLogWebService;
  747. $aSettings['min_display_limit'] = $this->m_iMinDisplayLimit;
  748. $aSettings['max_display_limit'] = $this->m_iMaxDisplayLimit;
  749. $aSettings['standard_reload_interval'] = $this->m_iStandardReloadInterval;
  750. $aSettings['fast_reload_interval'] = $this->m_iFastReloadInterval;
  751. $aSettings['secure_connection_required'] = $this->m_bSecureConnectionRequired;
  752. $aSettings['https_hyperlinks'] = $this->m_bHttpsHyperlinks;
  753. $aSettings['default_language'] = $this->m_sDefaultLanguage;
  754. $aSettings['allowed_login_types'] = $this->m_sAllowedLoginTypes;
  755. $aSettings['encryption_key'] = $this->m_sEncryptionKey;
  756. $aSettings['csv_import_charsets'] = $this->m_aCharsets;
  757. foreach ($this->m_aModuleSettings as $sModule => $aProperties)
  758. {
  759. foreach ($aProperties as $sProperty => $value)
  760. {
  761. $aSettings['module_settings'][$sModule][$sProperty] = $value;
  762. }
  763. }
  764. foreach($this->m_aAppModules as $sFile)
  765. {
  766. $aSettings['application_list'][] = $sFile;
  767. }
  768. foreach($this->m_aDataModels as $sFile)
  769. {
  770. $aSettings['datamodel_list'][] = $sFile;
  771. }
  772. foreach($this->m_aWebServiceCategories as $sFile)
  773. {
  774. $aSettings['webservice_list'][] = $sFile;
  775. }
  776. foreach($this->m_aAddons as $sKey => $sFile)
  777. {
  778. $aSettings['addon_list'][] = $sFile;
  779. }
  780. foreach($this->m_aDictionaries as $sFile)
  781. {
  782. $aSettings['dictionary_list'][] = $sFile;
  783. }
  784. return $aSettings;
  785. }
  786. /**
  787. * Write the configuration to a file (php format) that can be reloaded later
  788. * By default write to the same file that was specified when constructing the object
  789. * @param $sFileName string Name of the file to write to (emtpy to write to the same file)
  790. * @return boolean True otherwise throws an Exception
  791. */
  792. public function WriteToFile($sFileName = '')
  793. {
  794. if (empty($sFileName))
  795. {
  796. $sFileName = $this->m_sFile;
  797. }
  798. $hFile = @fopen($sFileName, 'w');
  799. if ($hFile !== false)
  800. {
  801. fwrite($hFile, "<?php\n");
  802. fwrite($hFile, "\n/**\n");
  803. fwrite($hFile, " *\n");
  804. fwrite($hFile, " * phpMyORM configuration file, generated by the iTop configuration wizard\n");
  805. fwrite($hFile, " *\n");
  806. fwrite($hFile, " * The file is used in MetaModel::LoadConfig() which does all the necessary initialization job\n");
  807. fwrite($hFile, " *\n");
  808. fwrite($hFile, " */\n");
  809. fwrite($hFile, "\n");
  810. fwrite($hFile, "\$MySettings = array(\n");
  811. foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
  812. {
  813. if ($aSettingInfo['show_in_conf_sample'])
  814. {
  815. $sType = $this->m_aSettings[$sPropCode]['type'];
  816. switch($sType)
  817. {
  818. case 'bool':
  819. $sSeenAs = $aSettingInfo['value'] ? '1' : '0';
  820. break;
  821. default:
  822. $sSeenAs = "'".$aSettingInfo['value']."'";
  823. }
  824. fwrite($hFile, "\t'$sPropCode' => $sSeenAs,\n");
  825. }
  826. }
  827. fwrite($hFile, "\t'db_host' => '{$this->m_sDBHost}',\n");
  828. fwrite($hFile, "\t'db_user' => '{$this->m_sDBUser}',\n");
  829. fwrite($hFile, "\t'db_pwd' => '".addslashes($this->m_sDBPwd)."',\n");
  830. fwrite($hFile, "\t'db_name' => '{$this->m_sDBName}',\n");
  831. fwrite($hFile, "\t'db_subname' => '{$this->m_sDBSubname}',\n");
  832. fwrite($hFile, "\t'db_character_set' => '{$this->m_sDBCharacterSet}',\n");
  833. fwrite($hFile, "\t'db_collation' => '{$this->m_sDBCollation}',\n");
  834. fwrite($hFile, "\n");
  835. fwrite($hFile, "\t'log_global' => {$this->m_bLogGlobal},\n");
  836. fwrite($hFile, "\t'log_notification' => {$this->m_bLogNotification},\n");
  837. fwrite($hFile, "\t'log_issue' => {$this->m_bLogIssue},\n");
  838. fwrite($hFile, "\t'log_web_service' => {$this->m_bLogWebService},\n");
  839. fwrite($hFile, "\t'min_display_limit' => {$this->m_iMinDisplayLimit},\n");
  840. fwrite($hFile, "\t'max_display_limit' => {$this->m_iMaxDisplayLimit},\n");
  841. fwrite($hFile, "\t'standard_reload_interval' => {$this->m_iStandardReloadInterval},\n");
  842. fwrite($hFile, "\t'fast_reload_interval' => {$this->m_iFastReloadInterval},\n");
  843. fwrite($hFile, "\t'secure_connection_required' => ".($this->m_bSecureConnectionRequired ? 'true' : 'false').",\n");
  844. fwrite($hFile, "\t'https_hyperlinks' => ".($this->m_bHttpsHyperlinks ? 'true' : 'false').",\n");
  845. fwrite($hFile, "\t'default_language' => '{$this->m_sDefaultLanguage}',\n");
  846. fwrite($hFile, "\t'allowed_login_types' => '{$this->m_sAllowedLoginTypes}',\n");
  847. fwrite($hFile, "\t'encryption_key' => '{$this->m_sEncryptionKey}',\n");
  848. $sExport = var_export($this->m_aCharsets, true);
  849. fwrite($hFile, "\t'csv_import_charsets' => $sExport,\n");
  850. fwrite($hFile, ");\n");
  851. fwrite($hFile, "\n");
  852. fwrite($hFile, "\$MyModuleSettings = array(\n");
  853. foreach ($this->m_aModuleSettings as $sModule => $aProperties)
  854. {
  855. fwrite($hFile, "\t'$sModule' => array (\n");
  856. foreach ($aProperties as $sProperty => $value)
  857. {
  858. $sExport = var_export($value, true);
  859. fwrite($hFile, "\t\t'$sProperty' => $sExport,\n");
  860. }
  861. fwrite($hFile, "\t),\n");
  862. }
  863. fwrite($hFile, ");\n");
  864. fwrite($hFile, "\n/**\n");
  865. fwrite($hFile, " *\n");
  866. fwrite($hFile, " * Data model modules to be loaded. Names should be specified as absolute paths\n");
  867. fwrite($hFile, " *\n");
  868. fwrite($hFile, " */\n");
  869. fwrite($hFile, "\$MyModules = array(\n");
  870. fwrite($hFile, "\t'application' => array (\n");
  871. foreach($this->m_aAppModules as $sFile)
  872. {
  873. fwrite($hFile, "\t\t'$sFile',\n");
  874. }
  875. fwrite($hFile, "\t),\n");
  876. fwrite($hFile, "\t'business' => array (\n");
  877. foreach($this->m_aDataModels as $sFile)
  878. {
  879. fwrite($hFile, "\t\t'$sFile',\n");
  880. }
  881. fwrite($hFile, "\t),\n");
  882. fwrite($hFile, "\t'webservices' => array (\n");
  883. foreach($this->m_aWebServiceCategories as $sFile)
  884. {
  885. fwrite($hFile, "\t\t'$sFile',\n");
  886. }
  887. fwrite($hFile, "\t),\n");
  888. fwrite($hFile, "\t'addons' => array (\n");
  889. foreach($this->m_aAddons as $sKey => $sFile)
  890. {
  891. fwrite($hFile, "\t\t'$sKey' => '$sFile',\n");
  892. }
  893. fwrite($hFile, "\t),\n");
  894. fwrite($hFile, "\t'dictionaries' => array (\n");
  895. foreach($this->m_aDictionaries as $sFile)
  896. {
  897. fwrite($hFile, "\t\t'$sFile',\n");
  898. }
  899. fwrite($hFile, "\t),\n");
  900. fwrite($hFile, ");\n");
  901. fwrite($hFile, '?'.'>'); // Avoid perturbing the syntax highlighting !
  902. return fclose($hFile);
  903. }
  904. else
  905. {
  906. throw new ConfigException("Could not write to configuration file", array('file' => $sFileName));
  907. }
  908. }
  909. }
  910. ?>