config.class.inc.php 33 KB

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