index.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  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. /**
  17. * Wizard to configure and initialize the iTop application
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. require_once('../application/utils.inc.php');
  25. require_once('../core/config.class.inc.php');
  26. require_once('../core/log.class.inc.php');
  27. require_once('../core/cmdbsource.class.inc.php');
  28. require_once('./setuppage.class.inc.php');
  29. define('TMP_CONFIG_FILE', '../tmp-config-itop.php');
  30. define('FINAL_CONFIG_FILE', '../config-itop.php');
  31. define('PHP_MIN_VERSION', '5.2.0');
  32. define('MYSQL_MIN_VERSION', '5.0.0');
  33. define('MIN_MEMORY_LIMIT', 32*1024*1024);
  34. $sOperation = Utils::ReadParam('operation', 'step0');
  35. $oP = new SetupWebPage('iTop configuration wizard');
  36. ///////////////////////////////////////////////////////////////////////////////////////////////////
  37. // Various helper function
  38. ///////////////////////////////////////////////////////////////////////////////////////////////////
  39. /**
  40. * Get a nicely formatted version string
  41. */
  42. function GetITopVersion($bShort = true)
  43. {
  44. $sVersionString = '';
  45. if ($bShort)
  46. {
  47. $sVersionString = "iTop Version ".ITOP_VERSION;
  48. }
  49. else
  50. {
  51. if (ITOP_REVISION == '$WCREV$')
  52. {
  53. // This is NOT a version built using the buil system, just display the main version
  54. $sVersionString = "iTop Version ".ITOP_VERSION;
  55. }
  56. else
  57. {
  58. // This is a build made from SVN, let display the full information
  59. $sVersionString = "iTop Version ".ITOP_VERSION." revision ".ITOP_REVISION.", built on: ".ITOP_BUILD_DATE;
  60. }
  61. }
  62. return $sVersionString;
  63. }
  64. /**
  65. * Helper function to retrieve the system's temporary directory
  66. * Emulates sys_get_temp_dir if neeed (PHP < 5.2.1)
  67. * @return string Path to the system's temp directory
  68. */
  69. function GetTmpDir()
  70. {
  71. // try to figure out what is the temporary directory
  72. // prior to PHP 5.2.1 the function sys_get_temp_dir
  73. // did not exist
  74. if ( !function_exists('sys_get_temp_dir'))
  75. {
  76. if( $temp=getenv('TMP') ) return realpath($temp);
  77. if( $temp=getenv('TEMP') ) return realpath($temp);
  78. if( $temp=getenv('TMPDIR') ) return realpath($temp);
  79. $temp=tempnam(__FILE__,'');
  80. if (file_exists($temp))
  81. {
  82. unlink($temp);
  83. return realpath(dirname($temp));
  84. }
  85. return null;
  86. }
  87. else
  88. {
  89. return realpath(sys_get_temp_dir());
  90. }
  91. }
  92. /**
  93. * Check the value of the PHP setting 'memory_limit'
  94. * against the minimum recommended value
  95. * @param SetpWebPage $oP The current web page
  96. * @param integer $iMinMemoryRequired The minimum memory for the test to pass
  97. * @return boolean Whether or not it's Ok to continue
  98. */
  99. function CheckMemoryLimit(SetupWebPage $oP, $iMinMemoryRequired)
  100. {
  101. $sMemoryLimit = trim(ini_get('memory_limit'));
  102. $bResult = true;
  103. if (empty($sMemoryLimit))
  104. {
  105. // On some PHP installations, memory_limit does not exist as a PHP setting!
  106. // (encountered on a 5.2.0 under Windows)
  107. // In that case, ini_set will not work, let's keep track of this and proceed anyway
  108. $oP->warning("No memory limit has been defined in this instance of PHP");
  109. }
  110. else
  111. {
  112. // Check that the limit will allow us to load the data
  113. //
  114. $iMemoryLimit = utils::ConvertToBytes($sMemoryLimit);
  115. if ($iMemoryLimit < $iMinMemoryRequired)
  116. {
  117. $oP->error("memory_limit ($iMemoryLimit) is too small, the minimum value to run iTop is $iMinMemoryRequired.");
  118. $bResult = false;
  119. }
  120. else
  121. {
  122. $oP->log_info("memory_limit is $iMemoryLimit, ok.");
  123. }
  124. }
  125. return $bResult;
  126. }
  127. /**
  128. * Helper function to retrieve the directory where files are to be uploaded
  129. * @return string Path to the temp directory used for uploading files
  130. */
  131. function GetUploadTmpDir()
  132. {
  133. $sPath = ini_get('upload_tmp_dir');
  134. if (empty($sPath))
  135. {
  136. $sPath = GetTmpDir();
  137. }
  138. return $sPath;
  139. }
  140. /**
  141. * Helper function to check if the current version of PHP
  142. * is compatible with the application
  143. * @return boolean true if this is Ok, false otherwise
  144. */
  145. function CheckPHPVersion(SetupWebPage $oP)
  146. {
  147. $bResult = true;
  148. $oP->log('Info - CheckPHPVersion');
  149. if (version_compare(phpversion(), PHP_MIN_VERSION, '>='))
  150. {
  151. $oP->ok("The current PHP Version (".phpversion().") is greater than the minimum required version (".PHP_MIN_VERSION.")");
  152. }
  153. else
  154. {
  155. $oP->error("Error: The current PHP Version (".phpversion().") is lower than the minimum required version (".PHP_MIN_VERSION.")");
  156. return false;
  157. }
  158. $aMandatoryExtensions = array('mysql', 'iconv', 'simplexml', 'soap');
  159. asort($aMandatoryExtensions); // Sort the list to look clean !
  160. $aExtensionsOk = array();
  161. $aMissingExtensions = array();
  162. $aMissingExtensionsLinks = array();
  163. foreach($aMandatoryExtensions as $sExtension)
  164. {
  165. if (extension_loaded($sExtension))
  166. {
  167. $aExtensionsOk[] = $sExtension;
  168. }
  169. else
  170. {
  171. $aMissingExtensions[] = $sExtension;
  172. $aMissingExtensionsLinks[] = "<a href=\"http://www.php.net/manual/en/book.$sExtension.php\">$sExtension</a>";
  173. }
  174. }
  175. if (count($aExtensionsOk) > 0)
  176. {
  177. $oP->ok("Required PHP extension(s): ".implode(', ', $aExtensionsOk).".");
  178. }
  179. if (count($aMissingExtensions) > 0)
  180. {
  181. $oP->error("Missing PHP extension(s): ".implode(', ', $aMissingExtensionsLinks).".");
  182. $bResult = false;
  183. }
  184. // Check some ini settings here
  185. if (function_exists('php_ini_loaded_file')) // PHP >= 5.2.4
  186. {
  187. $sPhpIniFile = php_ini_loaded_file();
  188. // Other included/scanned files
  189. if ($sFileList = php_ini_scanned_files())
  190. {
  191. if (strlen($sFileList) > 0)
  192. {
  193. $aFiles = explode(',', $sFileList);
  194. foreach ($aFiles as $sFile)
  195. {
  196. $sPhpIniFile .= ', '.trim($sFile);
  197. }
  198. }
  199. }
  200. $oP->log("Info - php.ini file(s): '$sPhpIniFile'");
  201. }
  202. else
  203. {
  204. $sPhpIniFile = 'php.ini';
  205. }
  206. if (!ini_get('file_uploads'))
  207. {
  208. $oP->error("Files upload is not allowed on this server (file_uploads = ".ini_get('file_uploads').").");
  209. $bResult = false;
  210. }
  211. $sUploadTmpDir = GetUploadTmpDir();
  212. if (empty($sUploadTmpDir))
  213. {
  214. $sUploadTmpDir = '/tmp';
  215. $oP->warning("Temporary directory for files upload is not defined (upload_tmp_dir), assuming that $sUploadTmpDir is used.");
  216. }
  217. // check that the upload directory is indeed writable from PHP
  218. if (!empty($sUploadTmpDir))
  219. {
  220. if (!file_exists($sUploadTmpDir))
  221. {
  222. $oP->error("Temporary directory for files upload ($sUploadTmpDir) does not exist or cannot be read by PHP.");
  223. $bResult = false;
  224. }
  225. else if (!is_writable($sUploadTmpDir))
  226. {
  227. $oP->error("Temporary directory for files upload ($sUploadTmpDir) is not writable.");
  228. $bResult = false;
  229. }
  230. else
  231. {
  232. $oP->log("Info - Temporary directory for files upload ($sUploadTmpDir) is writable.");
  233. }
  234. }
  235. if (!ini_get('upload_max_filesize'))
  236. {
  237. $oP->error("File upload is not allowed on this server (file_uploads = ".ini_get('file_uploads').").");
  238. }
  239. $iMaxFileUploads = ini_get('max_file_uploads');
  240. if (!empty($iMaxFileUploads) && ($iMaxFileUploads < 1))
  241. {
  242. $oP->error("File upload is not allowed on this server (max_file_uploads = ".ini_get('max_file_uploads').").");
  243. $bResult = false;
  244. }
  245. $oP->log("Info - upload_max_filesize: ".ini_get('upload_max_filesize'));
  246. $oP->log("Info - max_file_uploads: ".ini_get('max_file_uploads'));
  247. // Check some more ini settings here, needed for file upload
  248. if (get_magic_quotes_gpc())
  249. {
  250. $oP->error("'magic_quotes_gpc' is set to On. Please turn it Off before continuing. You may want to check the PHP configuration file(s): '$sPhpIniFile'. Be aware that this setting can also be overridden in the apache configuration.");
  251. $bResult = false;
  252. }
  253. $bResult = $bResult & CheckMemoryLimit($oP, MIN_MEMORY_LIMIT);
  254. return $bResult;
  255. }
  256. /**
  257. * Helper function check the connection to the database and (if connected) to enumerate
  258. * the existing databases
  259. * @return Array The list of databases found in the server
  260. */
  261. function CheckServerConnection(SetupWebPage $oP, $sDBServer, $sDBUser, $sDBPwd)
  262. {
  263. $aResult = array();
  264. $oP->log('Info - CheckServerConnection');
  265. try
  266. {
  267. $oDBSource = new CMDBSource;
  268. $oDBSource->Init($sDBServer, $sDBUser, $sDBPwd);
  269. $oP->ok("Connection to '$sDBServer' as '$sDBUser' successful.");
  270. $oP->log("Info - User privileges: ".($oDBSource->GetRawPrivileges()));
  271. $sDBVersion = $oDBSource->GetDBVersion();
  272. if (version_compare($sDBVersion, MYSQL_MIN_VERSION, '>='))
  273. {
  274. $oP->ok("Current MySQL version ($sDBVersion), greater than minimum required version (".MYSQL_MIN_VERSION.")");
  275. // Check some server variables
  276. $iMaxAllowedPacket = $oDBSource->GetServerVariable('max_allowed_packet');
  277. $iMaxUploadSize = utils::ConvertToBytes(ini_get('upload_max_filesize'));
  278. if ($iMaxAllowedPacket >= (500 + $iMaxUploadSize)) // Allow some space for the query + the file to upload
  279. {
  280. $oP->ok("MySQL server's max_allowed_packet is big enough.");
  281. }
  282. else if($iMaxAllowedPacket < $iMaxUploadSize)
  283. {
  284. $oP->warning("MySQL server's max_allowed_packet ($iMaxAllowedPacket) is not big enough. Please, consider setting it to at least ".(500 + $iMaxUploadSize).".");
  285. }
  286. $oP->log("Info - MySQL max_allowed_packet: $iMaxAllowedPacket");
  287. $iMaxConnections = $oDBSource->GetServerVariable('max_connections');
  288. if ($iMaxConnections < 5)
  289. {
  290. $oP->warning("MySQL server's max_connections ($iMaxConnections) is not enough. Please, consider setting it to at least 5.");
  291. }
  292. $oP->log("Info - MySQL max_connections: ".($oDBSource->GetServerVariable('max_connections')));
  293. }
  294. else
  295. {
  296. $oP->error("Error: Current MySQL version is ($sDBVersion), minimum required version (".MYSQL_MIN_VERSION.")");
  297. return false;
  298. }
  299. try
  300. {
  301. $aResult = $oDBSource->ListDB();
  302. }
  303. catch(Exception $e)
  304. {
  305. $oP->warning("Warning: unable to enumerate the current databases.");
  306. $aResult = true; // Not an array to differentiate with an empty array
  307. }
  308. }
  309. catch(Exception $e)
  310. {
  311. $oP->error("Error: Connection to '$sDBServer' as '$sDBUser' failed.");
  312. $oP->p($e->GetHtmlDesc());
  313. $aResult = false;
  314. }
  315. return $aResult;
  316. }
  317. /**
  318. * Helper function to initialize the ORM and load the data model
  319. * from the given file
  320. * @param $sConfigFileName string The name of the configuration file to load
  321. * @param $bModelOnly boolean Whether or not to allow loading a data model with no corresponding DB
  322. * @return none
  323. */
  324. function InitDataModel(SetupWebPage $oP, $sConfigFileName, $bModelOnly = true)
  325. {
  326. require_once('../core/log.class.inc.php');
  327. require_once('../core/coreexception.class.inc.php');
  328. require_once('../core/dict.class.inc.php');
  329. require_once('../core/attributedef.class.inc.php');
  330. require_once('../core/filterdef.class.inc.php');
  331. require_once('../core/stimulus.class.inc.php');
  332. require_once('../core/MyHelpers.class.inc.php');
  333. require_once('../core/expression.class.inc.php');
  334. require_once('../core/cmdbsource.class.inc.php');
  335. require_once('../core/sqlquery.class.inc.php');
  336. require_once('../core/dbobject.class.php');
  337. require_once('../core/dbobjectsearch.class.php');
  338. require_once('../core/dbobjectset.class.php');
  339. require_once('../application/cmdbabstract.class.inc.php');
  340. require_once('../core/userrights.class.inc.php');
  341. $oP->log("Info - MetaModel::Startup from file '$sConfigFileName' (ModelOnly = $bModelOnly)");
  342. MetaModel::Startup($sConfigFileName, $bModelOnly);
  343. }
  344. /**
  345. * Helper function to create the database structure
  346. * @return boolean true on success, false otherwise
  347. */
  348. function CreateDatabaseStructure(SetupWebPage $oP, Config $oConfig, $sDBName, $sDBPrefix)
  349. {
  350. InitDataModel($oP, TMP_CONFIG_FILE, true); // Allow the DB to NOT exist since we're about to create it !
  351. $oP->log('Info - CreateDatabaseStructure');
  352. if (strlen($sDBPrefix) > 0)
  353. {
  354. $oP->info("Creating the structure in '$sDBName' (table names prefixed by '$sDBPrefix').");
  355. }
  356. else
  357. {
  358. $oP->info("Creating the structure in '$sDBName'.");
  359. }
  360. //MetaModel::CheckDefinitions();
  361. if (!MetaModel::DBExists(/* bMustBeComplete */ false))
  362. {
  363. MetaModel::DBCreate();
  364. $oP->ok("Database structure successfully created.");
  365. }
  366. else
  367. {
  368. if (strlen($sDBPrefix) > 0)
  369. {
  370. $oP->error("Error: found iTop tables into the database '$sDBName' (prefix: '$sDBPrefix'). Please, try selecting another database instance or specify another prefix to prevent conflicting table names.");
  371. }
  372. else
  373. {
  374. $oP->error("Error: found iTop tables into the database '$sDBName'. Please, try selecting another database instance or specify a prefix to prevent conflicting table names.");
  375. }
  376. return false;
  377. }
  378. return true;
  379. }
  380. /**
  381. * Helper function to create and administrator account for iTop
  382. * @return boolean true on success, false otherwise
  383. */
  384. function CreateAdminAccount(SetupWebPage $oP, Config $oConfig, $sAdminUser, $sAdminPwd, $sLanguage)
  385. {
  386. $oP->log('Info - CreateAdminAccount');
  387. InitDataModel($oP, TMP_CONFIG_FILE, false); // load data model and connect to the database
  388. if (!UserRights::Setup())
  389. {
  390. return false;
  391. }
  392. if (UserRights::CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage))
  393. {
  394. $oP->ok("Administrator account '$sAdminUser' created.");
  395. return true;
  396. }
  397. else
  398. {
  399. $oP->error("Failed to create the administrator account '$sAdminUser'.");
  400. return false;
  401. }
  402. }
  403. function ListModuleFiles($sDirectory, SetupWebPage $oP)
  404. {
  405. //echo "<p>$sDirectory</p>\n";
  406. if ($hDir = opendir($sDirectory))
  407. {
  408. // This is the correct way to loop over the directory. (according to the documentation)
  409. while (($sFile = readdir($hDir)) !== false)
  410. {
  411. $aMatches = array();
  412. if (is_dir($sDirectory.'/'.$sFile))
  413. {
  414. if (($sFile != '.') && ($sFile != '..') && ($sFile != '.svn'))
  415. {
  416. ListModuleFiles($sDirectory.'/'.$sFile, $oP);
  417. }
  418. }
  419. else if (preg_match('/^module\.(.*).php$/i', $sFile, $aMatches))
  420. {
  421. try
  422. {
  423. //echo "<p>Loading: $sDirectory/$sFile...</p>\n";
  424. require_once($sDirectory.'/'.$sFile);
  425. //echo "<p>Done.</p>\n";
  426. }
  427. catch(Exception $e)
  428. {
  429. // Continue...
  430. }
  431. }
  432. }
  433. closedir($hDir);
  434. }
  435. else
  436. {
  437. $oP->error("Data directory (".$sDirectory.") not found or not readable.");
  438. }
  439. }
  440. /**
  441. * Scans the ./data directory for XML files and output them as a Javascript array
  442. */
  443. function PopulateDataFilesList(SetupWebPage $oP, $aParamValues)
  444. {
  445. $oP->add("<script type=\"text/javascript\">\n");
  446. $oP->add("function PopulateDataFilesList()\n");
  447. $oP->add("{\n");
  448. $oP->add("if (aFilesToLoad.length > 0) return;"); // Populate the list only once...
  449. $aAvailableModules = GetAvailableModules($oP);
  450. $aStructureDataFiles = array();
  451. $aSampleDataFiles = array();
  452. foreach($aParamValues['module'] as $sModuleId)
  453. {
  454. $aModuleStruct = $aAvailableModules[$sModuleId]['data.struct'];
  455. $aModuleSamples = $aAvailableModules[$sModuleId]['data.sample'];
  456. $aStructureDataFiles = array_merge($aStructureDataFiles, $aModuleStruct);
  457. $aSampleDataFiles = array_merge($aSampleDataFiles, $aModuleSamples);
  458. }
  459. // Structure data
  460. //
  461. foreach($aStructureDataFiles as $sFile)
  462. {
  463. // Under Windows, it is a must to escape backslashes (not an issue until a folder name starts with t or n, etc...)
  464. $sFile = str_replace('\\', '\\\\', $sFile);
  465. $oP->add("aFilesToLoad[aFilesToLoad.length] = '$sFile';\n");
  466. }
  467. // Sample data - loaded IIF wished by the user
  468. //
  469. $oP->add("if (($(\"#sample_data:checked\").length == 1))");
  470. $oP->add("{");
  471. foreach($aSampleDataFiles as $sFile)
  472. {
  473. // Under Windows, it is a must to escape backslashes (not an issue until a folder name starts with t or n, etc...)
  474. $sFile = str_replace('\\', '\\\\', $sFile);
  475. $oP->add("aFilesToLoad[aFilesToLoad.length] = '$sFile';\n");
  476. }
  477. $oP->add("}\n");
  478. $oP->add("}\n");
  479. $oP->add("</script>\n");
  480. }
  481. /**
  482. * Add some parameters as hidden inputs into a form
  483. * @param SetupWebpage $oP The page to insert the form elements into
  484. * @param Hash $aParamValues The pairs name/value to be stored in the form
  485. * @param Array $aExcludeParams A list of parameters to exclude from the previous hash
  486. */
  487. function AddParamsToForm(SetupWebpage $oP, $aParamValues, $aExcludeParams = array())
  488. {
  489. foreach($aParamValues as $sName => $value)
  490. {
  491. if(!in_array($sName, $aExcludeParams))
  492. {
  493. if (is_array($value))
  494. {
  495. foreach($value as $sKey => $sItem)
  496. {
  497. $oP->add('<input type="hidden" name="'.$sName.'['.$sKey.']'.'" value="'.$sItem.'">');
  498. }
  499. }
  500. else
  501. {
  502. $oP->add('<input type="hidden" name="'.$sName.'" value="'.$value.'">');
  503. }
  504. }
  505. }
  506. }
  507. /**
  508. * Search (on the disk) for all defined iTop modules, load them and returns the list (as an array)
  509. * of the possible iTop modules to install
  510. * @param none
  511. * @return Hash A big array moduleID => ModuleData
  512. */
  513. function GetAvailableModules(SetupWebpage $oP)
  514. {
  515. clearstatcache();
  516. ListModuleFiles('../modules/', $oP);
  517. return $oP->GetModules();
  518. }
  519. /**
  520. * Build the config file from the parameters (especially the selected modules)
  521. */
  522. function BuildConfig(SetupWebpage $oP, Config &$oConfig, $aParamValues)
  523. {
  524. $aAvailableModules = GetAvailableModules($oP);
  525. // Initialize the arrays below with default values for the application...
  526. $aAddOns = $oConfig->GetAddOns();
  527. $aAppModules = $oConfig->GetAppModules();
  528. $aDataModels = $oConfig->GetDataModels();
  529. $sDictionaries = $oConfig->GetDictionaries();
  530. // Merge the values with the ones provided by the modules
  531. // Make sure when don't load the same file twice...
  532. foreach($aParamValues['module'] as $sModuleId)
  533. {
  534. $oP->log('Installed iTop module: '. $sModuleId);
  535. $aDataModels = array_unique(array_merge($aDataModels, $aAvailableModules[$sModuleId]['datamodel']));
  536. $sDictionaries = array_unique(array_merge($sDictionaries, $aAvailableModules[$sModuleId]['dictionary']));
  537. foreach($aAvailableModules[$sModuleId]['settings'] as $sProperty => $value)
  538. {
  539. $oConfig->SetModuleSetting($sModuleId, $sProperty, $value);
  540. }
  541. }
  542. $oConfig->SetAddOns($aAddOns);
  543. $oConfig->SetAppModules($aAppModules);
  544. $oConfig->SetDataModels($aDataModels);
  545. $oConfig->SetDictionaries($sDictionaries);
  546. }
  547. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  548. // Handling of the different steps of the setup wizard
  549. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  550. /**
  551. * Displays the welcome screen and check some basic prerequisites
  552. */
  553. function WelcomeAndCheckPrerequisites(SetupWebPage $oP, $aParamValues, $iCurrentStep)
  554. {
  555. $sNextOperation = 'step'.($iCurrentStep+1);
  556. $oP->add("<h1>iTop configuration wizard</h1>\n");
  557. $sVersionStringShort = GetITopVersion(true);
  558. $sVersionStringLong = GetITopVersion(false);
  559. $oP->set_title('Welcome to '.$sVersionStringShort);
  560. $oP->log($sVersionStringLong);
  561. $oP->add("<h2>Checking prerequisites</h2>\n");
  562. if (CheckPHPVersion($oP))
  563. {
  564. $oP->add("<h2 class=\"next\">Next: Licence agreement</h2>\n");
  565. $oP->add("<form id=\"theForm\" method=\"post\" onSubmit=\"return DoSubmit('', 0)\">\n");
  566. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  567. AddParamsToForm($oP, $aParamValues);
  568. $oP->add("<table style=\"width:100%\"><tr>\n");
  569. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\" type=\"submit\">Next >></button></td>\n");
  570. $oP->add("</tr></table>\n");
  571. $oP->add("</form>\n");
  572. }
  573. }
  574. function LicenceAcknowledgement($oP, $aParamValues, $iCurrentStep)
  575. {
  576. $sNextOperation = 'step'.($iCurrentStep+1);
  577. $oP->set_title('License Agreement');
  578. $oP->add('<h2>iTop is released by <a href="http://www.combodo.com">Combodo SARL</a> under the terms of the GPL V3 license. In order to use iTop you must accept the terms of this license.</h2>');
  579. $oP->add("<iframe style=\"width: 100%; height: 350px; overflow-y:auto; font-size:0.8em;\" src=\"./licence.html\">Next: Database server selection</iframe>\n");
  580. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  581. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  582. AddParamsToForm($oP, $aParamValues, array('licence_ok'));
  583. $sChecked = $aParamValues['licence_ok'] == 1 ? 'checked' : '';
  584. $oP->add("<h2><input id=\"licence_ok\" type=\"checkbox\" name=\"licence_ok\" value=\"1\" $sChecked><label for=\"licence_ok\">I accept the terms of this licence agreement</label></h2>\n");
  585. $oP->add("<h2 class=\"next\">Next: Database server selection</h2>\n");
  586. $oP->add("<table style=\"width:100%\"><tr>\n");
  587. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button></td>\n");
  588. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\" onClick=\"return DoSubmit('', $iCurrentStep)\">Next >></button></td>\n");
  589. $oP->add("</tr></table>\n");
  590. $oP->add("</form>\n");
  591. }
  592. /**
  593. * Display the form for the first step of the configuration wizard
  594. * which consists in the database server selection
  595. */
  596. function DatabaseServerSelection(SetupWebPage $oP, $aParamValues, $iCurrentStep)
  597. {
  598. $sNextOperation = 'step'.($iCurrentStep+1);
  599. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  600. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  601. AddParamsToForm($oP, $aParamValues, array('db_server', 'db_user', 'db_pwd'));
  602. if ($aParamValues['licence_ok'] == 1)
  603. {
  604. $sRedStar = '<span class="hilite">*</span>';
  605. $oP->set_title("Configuration of the database connection\n");
  606. $oP->add("<h2>Please enter the name of the MySQL database server you want to use for iTop and supply valid credentials to connect to it</h2>\n");
  607. // Form goes here
  608. $oP->add("<fieldset><legend>Database connection</legend>\n");
  609. $aForm = array();
  610. $aForm[] = array('label' => "Server name$sRedStar:", 'input' => "<input id=\"db_server\" type=\"text\" name=\"db_server\" value=\"{$aParamValues['db_server']}\">",
  611. 'help' => 'E.g. "localhost", "dbserver.mycompany.com" or "192.142.10.23"');
  612. $aForm[] = array('label' => "User name$sRedStar:", 'input' => "<input id=\"db_user\" type=\"text\" name=\"db_user\" value=\"{$aParamValues['db_user']}\">",
  613. 'help' => 'The account must have the following privileges: SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER');
  614. $aForm[] = array('label' => 'Password:', 'input' => "<input id=\"db_pwd\" type=\"password\" name=\"db_pwd\" value=\"{$aParamValues['db_pwd']}\">");
  615. $oP->form($aForm);
  616. $oP->add("</fieldset>\n");
  617. $oP->add("<h2 class=\"next\">Next: Database Instance Selection</h2>\n");
  618. $oP->add("<table style=\"width:100%\"><tr>\n");
  619. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button></td>\n");
  620. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\" onClick=\"return DoSubmit('Connecting to the database...', $iCurrentStep);\">Next >></button></td>\n");
  621. $oP->add("</tr></table>\n");
  622. }
  623. else
  624. {
  625. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iCurrentStep);\"><< Back</button>\n");
  626. }
  627. $oP->add("</form>\n");
  628. }
  629. /**
  630. * Display the form for the second step of the configuration wizard
  631. * which consists in
  632. * 1) Validating the parameters by connecting to the database server
  633. * 2) Prompting to select an existing database or to create a new one
  634. */
  635. function DatabaseInstanceSelection(SetupWebPage $oP, $aParamValues, $iCurrentStep, $oConfig)
  636. {
  637. $sNextOperation = 'step'.($iCurrentStep+1);
  638. $oP->set_title("Database Instance Selection\n");
  639. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  640. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  641. AddParamsToForm($oP, $aParamValues, array('db_name', 'db_prefix', 'new_db_name'));
  642. $sDBServer = $aParamValues['db_server'];
  643. $sDBUser = $aParamValues['db_user'];
  644. $sDBPwd = $aParamValues['db_pwd'];
  645. $aDatabases = CheckServerConnection($oP, $sDBServer, $sDBUser, $sDBPwd);
  646. if ($aDatabases === false)
  647. {
  648. // Connection failed, invalid credentials ? Go back
  649. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iCurrentStep);\"><< Back</button>\n");
  650. }
  651. else
  652. {
  653. // Connection is Ok, save it and continue the setup wizard
  654. $oConfig->SetDBHost($sDBServer);
  655. $oConfig->SetDBUser($sDBUser);
  656. $oConfig->SetDBPwd($sDBPwd);
  657. $oConfig->WriteToFile();
  658. $oP->add("<fieldset><legend>Select the database instance to use for iTop<span class=\"hilite\">*</span></legend>\n");
  659. $aForm = array();
  660. $bExistingChecked = false;
  661. if (is_array($aDatabases))
  662. {
  663. foreach($aDatabases as $sDBName)
  664. {
  665. $sChecked = '';
  666. if ($aParamValues['db_name'] == $sDBName)
  667. {
  668. $sChecked = 'checked';
  669. $bExistingChecked = true;
  670. }
  671. $aForm[] = array('label' => "<input id=\"db_$sDBName\" type=\"radio\" name=\"db_name\" value=\"$sDBName\" $sChecked/><label for=\"db_$sDBName\"> $sDBName</label>");
  672. }
  673. }
  674. else
  675. {
  676. $aForm[] = array('label' => "<input id=\"current_db\" type=\"radio\" name=\"db_name\" value=\"-1\" /><label for=\"current_db\"> Use the existing database:</label> <input type=\"text\" id=\"current_db_name\" name=\"current_db_name\" value=\"\" maxlength=\"32\"/>");
  677. $oP->add_ready_script("$('#current_db_name').click( function() { $('#current_db').attr('checked', true); });");
  678. }
  679. $sChecked = '';
  680. $sDBName = '';
  681. // If the 'Create Database' option was checked... and the database still does not exist
  682. if (!$bExistingChecked && !empty($aParamValues['new_db_name']))
  683. {
  684. $sChecked = 'checked';
  685. $sDBName = $aParamValues['new_db_name'];
  686. }
  687. $aForm[] = array('label' => "<input id=\"new_db\" type=\"radio\" name=\"db_name\" value=\"\" $sChecked/><label for=\"new_db\"> Create a new database:</label> <input type=\"text\" id=\"new_db_name\" name=\"new_db_name\" value=\"$sDBName\" maxlength=\"32\"/>");
  688. $oP->form($aForm);
  689. $oP->add_ready_script("$('#new_db_name').click( function() { $('#new_db').attr('checked', true); })");
  690. $oP->add("</fieldset>\n");
  691. $aForm = array();
  692. $aForm[] = array('label' => "Add a prefix to all the tables: <input id=\"db_prefix\" type=\"text\" name=\"db_prefix\" value=\"{$aParamValues['db_prefix']}\" maxlength=\"32\"/>");
  693. $oP->form($aForm);
  694. $oP->add("<h2 class=\"next\">Next: iTop Modules Selection</h2>\n");
  695. $oP->add("<table style=\"width:100%\"><tr>\n");
  696. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button></td>\n");
  697. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\" onClick=\"return DoSubmit('', $iCurrentStep);\">Next >></button></td>\n");
  698. $oP->add("</tr></table>\n");
  699. }
  700. $oP->add("</form>\n");
  701. }
  702. /**
  703. * Display the form to select the iTop modules to be installed
  704. */
  705. function ModulesSelection(SetupWebPage $oP, $aParamValues, $iCurrentStep, $oConfig)
  706. {
  707. $sNextOperation = 'step'.($iCurrentStep+1);
  708. $sPrevOperation = 'step'.($iCurrentStep-1);
  709. $sDBName = $aParamValues['db_name'];
  710. if ($sDBName == '')
  711. {
  712. $sDBName = $aParamValues['new_db_name'];
  713. }
  714. $sDBPrefix = $aParamValues['db_prefix'];
  715. $oConfig->SetDBName($sDBName);
  716. $oConfig->SetDBSubname($sDBPrefix);
  717. $oConfig->WriteToFile(TMP_CONFIG_FILE);
  718. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  719. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  720. AddParamsToForm($oP, $aParamValues, array('module'));
  721. $sRedStar = '<span class="hilite">*</span>';
  722. $oP->set_title("Selection of the iTop Modules\n");
  723. $oP->add("<h2>Customize your iTop installation to fit your needs</h2>\n");
  724. $aAvailableModules = GetAvailableModules($oP);
  725. // Form goes here
  726. $oP->add("<fieldset><legend>Select the iTop modules you want to install:</legend>\n");
  727. $oP->add("<div style=\"border: 0;width:100%; height: 350px; overflow-y:auto;\">");
  728. $sRedStar = '<span class="hilite">*</span>';
  729. $index = 0;
  730. $aSelectedModules = $aParamValues['module'];
  731. if ($aSelectedModules == '')
  732. {
  733. // Make sure it gets initialized as an array, default value: all modules selected !
  734. $aSelectedModules = array();
  735. foreach($aAvailableModules as $sModuleId => $aModule)
  736. {
  737. $aSelectedModules[] = $sModuleId;
  738. }
  739. }
  740. foreach($aAvailableModules as $sModuleId => $aModule)
  741. {
  742. $sModuleLabel = $aModule['label'];
  743. $sModuleHelp = $aModule['doc.more_information'];
  744. $sClass = ($aModule['mandatory']) ? 'class="read-only"' : '';
  745. $sChecked = ($aModule['mandatory'] || in_array($sModuleId, $aSelectedModules) ) ? 'checked' : '';
  746. $sMoreInfo = (!empty($aModule['doc.more_information'])) ? "<a href=\"{$aModule['doc.more_information']}\" target=\"_blank\">more info</a>": '';
  747. if ($aModule['category'] == 'authentication')
  748. {
  749. // For now authentication modules are always on and hidden
  750. $oP->add("<input type=\"hidden\" id=\"module[$index]\" name=\"module[$index]\" value=\"$sModuleId\">\n");
  751. $index++;
  752. }
  753. elseif ($aModule['visible'])
  754. {
  755. $oP->add("<p><input type=\"checkbox\" $sClass $sChecked id=\"module[$index]\" name=\"module[$index]\" value=\"$sModuleId\"><label $sClass for=\"module[$index]\"> {$aModule['label']}</label> $sMoreInfo</p>\n");
  756. $index++;
  757. }
  758. else
  759. {
  760. // For now hidden modules are always on !
  761. $oP->add("<input type=\"hidden\" id=\"module[$index]\" name=\"module[$index]\" value=\"$sModuleId\">\n");
  762. $index++;
  763. }
  764. }
  765. $oP->add("</div>");
  766. $oP->add("</fieldset>\n");
  767. $oP->add("<h2 class=\"next\">Next: Administrator Account Creation</h2>\n");
  768. $oP->add("<table style=\"width:100%\"><tr>\n");
  769. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button></td>\n");
  770. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\" onClick=\"return DoSubmit('Creating the database structure...', $iCurrentStep);\">Next >></button></td>\n");
  771. $oP->add("</tr></table>\n");
  772. $oP->add("</form>\n");
  773. $oP->add_ready_script("$('.read-only').click( function() { $(this).attr('checked','checked'); } );");
  774. }
  775. /**
  776. * Display the form for the third step of the configuration wizard
  777. * which consists in
  778. * 1) Validating the parameters by connecting to the database server & selecting the database
  779. * 2) Creating the database structure
  780. * 3) Prompting for the admin account to be created
  781. */
  782. function AdminAccountDefinition(SetupWebPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  783. {
  784. $sNextOperation = 'step'.($iCurrentStep+1);
  785. $oP->set_title("Configuration of the admin account");
  786. $oP->add("<h2>Creation of the database structure</h2>");
  787. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  788. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  789. AddParamsToForm($oP, $aParamValues, array('auth_user', 'auth_pwd', 'language'));
  790. $sDBName = $aParamValues['db_name'];
  791. if ($sDBName == '')
  792. {
  793. $sDBName = $aParamValues['new_db_name'];
  794. }
  795. $sDBPrefix = $aParamValues['db_prefix'];
  796. $oConfig->SetDBName($sDBName);
  797. $oConfig->SetDBSubname($sDBPrefix);
  798. BuildConfig($oP, $oConfig, $aParamValues); // Load all the includes based on the modules selected
  799. $oConfig->WriteToFile(TMP_CONFIG_FILE);
  800. if (CreateDatabaseStructure($oP, $oConfig, $sDBName, $sDBPrefix))
  801. {
  802. $sRedStar = "<span class=\"hilite\">*</span>";
  803. $oP->add("<h2>Default language for the application:</h2>\n");
  804. // Possible languages (depends on the dictionaries loaded in the config)
  805. $aForm = array();
  806. $aAvailableLanguages = Dict::GetLanguages();
  807. $sLanguages = '';
  808. $sDefaultCode = $oConfig->GetDefaultLanguage();
  809. foreach($aAvailableLanguages as $sLangCode => $aInfo)
  810. {
  811. $sSelected = ($sLangCode == $sDefaultCode ) ? 'selected ' : '';
  812. $sLanguages.="<option value=\"{$sLangCode}\">{$aInfo['description']} ({$aInfo['localized_description']})</option>";
  813. }
  814. $aForm[] = array('label' => "Default Language$sRedStar:", 'input' => "<select id=\"language\" name=\"language\">$sLanguages</option>");
  815. $oP->form($aForm);
  816. $oP->add("<h2>Definition of the administrator account</h2>\n");
  817. // Database created, continue with admin creation
  818. $oP->add("<fieldset><legend>Administrator account</legend>\n");
  819. $aForm = array();
  820. $aForm[] = array('label' => "Login$sRedStar:", 'input' => "<input id=\"auth_user\" type=\"text\" name=\"auth_user\" value=\"{$aParamValues['auth_user']}\">");
  821. $aForm[] = array('label' => "Password$sRedStar:", 'input' => "<input id=\"auth_pwd\" type=\"password\" name=\"auth_pwd\" value=\"{$aParamValues['auth_pwd']}\">");
  822. $aForm[] = array('label' => "Retype password$sRedStar:", 'input' => "<input id=\"auth_pwd2\" type=\"password\" name=\"auth_pwd2\" value=\"{$aParamValues['auth_pwd']}\">");
  823. $oP->form($aForm);
  824. $oP->add("</fieldset>\n");
  825. $oP->add("<h2 class=\"next\">Next: Administrator Account Creation</h2>\n");
  826. $oP->add("<table style=\"width:100%\"><tr>\n");
  827. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button></td>\n");
  828. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\" onClick=\"return DoSubmit('Creating the admin account and profiles...', $iCurrentStep);\">Next >></button></td>\n");
  829. $oP->add("</tr></table>\n");
  830. }
  831. else
  832. {
  833. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button>\n");
  834. }
  835. // Form goes here
  836. $oP->add("</form>\n");
  837. }
  838. /**
  839. * Display the form for the fourth step of the configuration wizard
  840. * which consists in
  841. * 1) Creating the admin user account
  842. * 2) Prompting to load some sample data
  843. */
  844. function SampleDataSelection(SetupWebPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  845. {
  846. $sNextOperation = 'step'.($iCurrentStep+1);
  847. $oP->set_title("Application Initialization");
  848. $sAdminUser = $aParamValues['auth_user'];
  849. $sAdminPwd = $aParamValues['auth_pwd'];
  850. $sLanguage = $aParamValues['language'];
  851. $oConfig->SetDefaultLanguage($aParamValues['language']);
  852. $oConfig->WriteToFile(TMP_CONFIG_FILE);
  853. $oP->add("<form id=\"theForm\" method=\"post\"\">\n");
  854. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  855. AddParamsToForm($oP, $aParamValues, array('sample_data'));
  856. if (CreateAdminAccount($oP, $oConfig, $sAdminUser, $sAdminPwd, $sLanguage))
  857. {
  858. $oP->add("<h2>Loading of sample data</h2>\n");
  859. $oP->p("<fieldset><legend> Do you want to load sample data into the database ? </legend>\n");
  860. $oP->p("<input type=\"radio\" id=\"sample_data\" name=\"sample_data\" id=\"sample_data_no\" checked value=\"yes\"><label for=\"sample_data_yes\"> Yes, for testing purposes, populate the database with sample data.</label>\n");
  861. $oP->p("<input type=\"radio\" name=\"sample_data\" unchecked id=\"sample_data_no\" value=\"no\"><label for=\"sample_data_no\"> No, this is a production system, load only the data required by the application.</label>\n");
  862. $oP->p("</fieldset>\n");
  863. $oP->add("<h2 class=\"next\">Next: Application Initialization</h2>\n");
  864. $oP->add("<table style=\"width:100%\"><tr>\n");
  865. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button></td>\n");
  866. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\" onClick=\"return DoSubmit('Finalizing configuration and loading data...', $iCurrentStep)\">Next >></button></td>\n");
  867. $oP->add("</tr></table>\n");
  868. }
  869. else
  870. {
  871. // Creation failed
  872. $oP->error("Internal error: Failed to create the admin account or to setup the user rights");
  873. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button>\n");
  874. }
  875. // End of visible form
  876. $oP->add("</form>\n");
  877. // Hidden form submitted when moving on to the next page, once all the data files
  878. // have been processed
  879. $oP->add("<form id=\"GoToNextStep\" method=\"post\">\n");
  880. AddParamsToForm($oP, $aParamValues, array('sample_data'));
  881. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  882. $oP->add("</form>\n");
  883. $oP->add("<div id=\"log\" style=\"color:#F00;\"></div>\n");
  884. $oP->add_linked_script('./jquery.progression.js');
  885. PopulateDataFilesList($oP, $aParamValues);
  886. }
  887. /**
  888. * Display the form for the fifth (and final) step of the configuration wizard
  889. * which consists in
  890. * 1) Creating the final configuration file
  891. * 2) Prompting the user to make the file read-only
  892. */
  893. function SetupFinished(SetupWebPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  894. {
  895. $sAuthUser = $aParamValues['auth_user'];
  896. $sAuthPwd = $aParamValues['auth_pwd'];
  897. try
  898. {
  899. session_start();
  900. // Write the final configuration file
  901. $oConfig->WriteToFile(FINAL_CONFIG_FILE);
  902. // Start the application
  903. InitDataModel($oP, FINAL_CONFIG_FILE, false); // Load model and startup DB
  904. if (UserRights::CheckCredentials($sAuthUser, $sAuthPwd))
  905. {
  906. UserRights::Login($sAuthUser);
  907. $_SESSION['auth_user'] = $sAuthUser;
  908. $_SESSION['login_mode'] = 'form'; // Will enable the "log-off button"
  909. // remove the tmp config file
  910. @unlink(TMP_CONFIG_FILE);
  911. // try to make the final config file read-only
  912. @chmod(FINAL_CONFIG_FILE, 0440); // Read-only for owner and group, nothing for others
  913. $oP->set_title("Configuration completed");
  914. $oP->add("<form id=\"theForm\" method=\"get\" action=\"../index.php\">\n");
  915. // Check if there are some manual steps required:
  916. $aAvailableModules = GetAvailableModules($oP);
  917. $aManualSteps = array();
  918. foreach($aParamValues['module'] as $sModuleId)
  919. {
  920. if (!empty($aAvailableModules[$sModuleId]['doc.manual_setup']))
  921. {
  922. $aManualSteps[$aAvailableModules[$sModuleId]['label']] = $aAvailableModules[$sModuleId]['doc.manual_setup'];
  923. }
  924. }
  925. if (count($aManualSteps) > 0)
  926. {
  927. $oP->add("<h2>Manual operations required</h2>");
  928. $oP->p("In order to complete the installation, the following manual operations are required:");
  929. foreach($aManualSteps as $sModuleLabel => $sUrl)
  930. {
  931. $oP->p("<a href=\"$sUrl\" target=\"_blank\">Manual instructions for $sModuleLabel</a>");
  932. }
  933. }
  934. else
  935. {
  936. $oP->add("<h2>Congratulations for installing iTop</h2>");
  937. $oP->ok("The initialization completed successfully.");
  938. }
  939. // Form goes here.. No back button since the job is done !
  940. $oP->add("<h1>Let us know what you think about iTop</h1>");
  941. $oP->add('<table style="width:100%;border:0;padding:0;"><tr><td style="width:100px;vertical-align:middle;background:#f6f6f1;text-align:center">');
  942. $oP->add('<a href="http://www.combodo.com" style="padding:0;background:transparent;margin:0;"><img style="border:0" src="../images/logo-combodo.png"></a></td>');
  943. $oP->add('<td style="padding-left: 10px;font-size:10pt">');
  944. $oP->add("Combodo built iTop because Combodo believes that modern ITIL tools should be at the center of any IT department.");
  945. $oP->p("Combodo invested a lot of time and effort in iTop, but you can help us improve it even further by providing your feedbacks</p>");
  946. $oP->p("<a href=\"http://www.combodo.com/register?product=iTop&version=".urlencode(ITOP_VERSION." revision ".ITOP_REVISION)."\" target=\"_blank\">Register online</a> to get informed about all iTop related events (new versions, webinars, etc...)");
  947. $oP->p("Check out the <a href=\"http://www.combodo.com/itopsupport\">support options</a> available for iTop.");
  948. $oP->add('</td></tr></table>');
  949. $oP->add("<p style=\"text-align:center;width:100%\"><button type=\"submit\">Enter iTop</button></p>\n");
  950. $oP->add("</form>\n");
  951. }
  952. else
  953. {
  954. $oP->add("<h1>iTop configuration wizard</h1>\n");
  955. $oP->add("<h2>Step 5: Configuration completed</h2>\n");
  956. @unlink(FINAL_CONFIG_FILE); // remove the aborted config
  957. $oP->error("Error: Failed to login for user: '$sAuthUser'\n");
  958. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  959. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iCurrentStep);\"><< Back</button>\n");
  960. AddParamsToForm($oP, $aParamValues);
  961. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"step0\">\n");
  962. $oP->add("</form>\n");
  963. }
  964. }
  965. catch(Exception $e)
  966. {
  967. $oP->error("Error: unable to create the configuration file.");
  968. $oP->p($e->getHtmlDesc());
  969. $oP->p("Did you forget to remove the previous (read-only) configuration file ?");
  970. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  971. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"step0\">\n");
  972. AddParamsToForm($oP, $aParamValues);
  973. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iCurrentStep);\"><< Back</button>\n");
  974. $oP->add("</form>\n");
  975. }
  976. }
  977. ///////////////////////////////////////////////////////////////////////////////////////////////////
  978. // Main program
  979. ///////////////////////////////////////////////////////////////////////////////////////////////////
  980. clearstatcache(); // Make sure we know what we are doing !
  981. if (file_exists(FINAL_CONFIG_FILE))
  982. {
  983. // The configuration file already exists
  984. if (is_writable(FINAL_CONFIG_FILE))
  985. {
  986. $oP->warning("<b>Warning:</b> a configuration file '".FINAL_CONFIG_FILE."' already exists, and will be overwritten.");
  987. }
  988. else
  989. {
  990. $oP->add("<h1>iTop configuration wizard</h1>\n");
  991. $oP->add("<h2>Fatal error</h2>\n");
  992. $oP->error("<b>Error:</b> the configuration file '".FINAL_CONFIG_FILE."' already exists and cannot be overwritten.");
  993. $oP->p("The wizard cannot create the configuration file for you. Please remove the file '<b>".realpath(FINAL_CONFIG_FILE)."</b>' or change its access-rights/read-only flag before continuing.");
  994. $oP->output();
  995. exit;
  996. }
  997. }
  998. else
  999. {
  1000. // No configuration file yet
  1001. // Check that the wizard can write into the root dir to create the configuration file
  1002. if (!is_writable(dirname(FINAL_CONFIG_FILE)))
  1003. {
  1004. $oP->add("<h1>iTop configuration wizard</h1>\n");
  1005. $oP->add("<h2>Fatal error</h2>\n");
  1006. $oP->error("<b>Error:</b> the directory where to store the configuration file is not writable.");
  1007. $oP->p("The wizard cannot create the configuration file for you. Please make sure that the directory '<b>".realpath(dirname(FINAL_CONFIG_FILE))."</b>' is writable for the web server.");
  1008. $oP->output();
  1009. exit;
  1010. }
  1011. }
  1012. try
  1013. {
  1014. $oConfig = new Config(TMP_CONFIG_FILE);
  1015. }
  1016. catch(Exception $e)
  1017. {
  1018. // We'll end here when the tmp config file does not exist. It's normal
  1019. $oConfig = new Config(TMP_CONFIG_FILE, false /* Don't try to load it */);
  1020. }
  1021. try
  1022. {
  1023. $aParams = array('licence_ok', 'db_server', 'db_user', 'db_pwd','db_name', 'new_db_name', 'db_prefix', 'module', 'sample_data', 'auth_user', 'auth_pwd', 'language');
  1024. foreach($aParams as $sName)
  1025. {
  1026. $aParamValues[$sName] = utils::ReadParam($sName, '');
  1027. }
  1028. switch($sOperation)
  1029. {
  1030. case 'step0':
  1031. $oP->no_cache();
  1032. $oP->log("Info - ========= Wizard step 0 ========");
  1033. WelcomeAndCheckPrerequisites($oP, $aParamValues, 0);
  1034. break;
  1035. case 'step1':
  1036. $oP->no_cache();
  1037. $oP->log("Info - ========= Wizard step 1 ========");
  1038. LicenceAcknowledgement($oP, $aParamValues, 1);
  1039. break;
  1040. case 'step2':
  1041. $oP->log("Info - ========= Wizard step 2 ========");
  1042. DatabaseServerSelection($oP, $aParamValues, 2);
  1043. break;
  1044. case 'step3':
  1045. $oP->no_cache();
  1046. $oP->log("Info - ========= Wizard step 3 ========");
  1047. DatabaseInstanceSelection($oP, $aParamValues, 3, $oConfig);
  1048. break;
  1049. case 'step4':
  1050. $oP->no_cache();
  1051. $oP->log("Info - ========= Wizard step 4 ========");
  1052. ModulesSelection($oP, $aParamValues, 4, $oConfig);
  1053. break;
  1054. case 'step5':
  1055. $oP->no_cache();
  1056. $oP->log("Info - ========= Wizard step 5 ========");
  1057. AdminAccountDefinition($oP, $aParamValues, 5, $oConfig);
  1058. break;
  1059. case 'step6':
  1060. $oP->no_cache();
  1061. $oP->log("Info - ========= Wizard step 6 ========");
  1062. SampleDataSelection($oP, $aParamValues, 6, $oConfig);
  1063. break;
  1064. case 'step7':
  1065. $oP->no_cache();
  1066. $oP->log("Info - ========= Wizard step 7 ========");
  1067. SetupFinished($oP, $aParamValues, 7, $oConfig);
  1068. break;
  1069. default:
  1070. $oP->error("Error: unsupported operation '$sOperation'");
  1071. }
  1072. }
  1073. catch(Exception $e)
  1074. {
  1075. $oP->error("Error: '".$e->getMessage()."'");
  1076. $oP->add("<button type=\"button\" onClick=\"window.history.back();\"><< Back</button>\n");
  1077. }
  1078. catch(CoreException $e)
  1079. {
  1080. $oP->error("Error: '".$e->getHtmlDesc()."'");
  1081. $oP->add("<button type=\"button\" onClick=\"window.history.back();\"><< Back</button>\n");
  1082. }
  1083. $oP->output();
  1084. ?>