config.class.inc.php 33 KB

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