index.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <?php
  2. /**
  3. * Wizard to configure and initialize the iTop application
  4. */
  5. require_once('../application/utils.inc.php');
  6. require_once('../core/config.class.inc.php');
  7. require_once('../core/cmdbsource.class.inc.php');
  8. require_once('./setuppage.class.inc.php');
  9. define('TMP_CONFIG_FILE', '../tmp-config-itop.php');
  10. define('FINAL_CONFIG_FILE', '../config-itop.php');
  11. define('SETUP_STRUCTURE_DATA_DIR', './data/structure');
  12. define('SETUP_SAMPLE_DATA_DIR', './data');
  13. define('PHP_MIN_VERSION', '5.2.0');
  14. define('MYSQL_MIN_VERSION', '5.0.0');
  15. $sOperation = Utils::ReadParam('operation', 'step1');
  16. $oP = new setup_web_page('iTop configuration wizard');
  17. /**
  18. * Helper function to check if the current version of PHP
  19. * is compatible with the application
  20. * @return boolean true if this is Ok, false otherwise
  21. */
  22. function CheckPHPVersion(setup_web_page $oP)
  23. {
  24. $oP->log('Info - CheckPHPVersion');
  25. if (version_compare(phpversion(), PHP_MIN_VERSION, '>='))
  26. {
  27. $oP->ok("The current PHP Version (".phpversion().") is greater than the minimum required version (".PHP_MIN_VERSION.")");
  28. }
  29. else
  30. {
  31. $oP->error("Error: The current PHP Version (".phpversion().") is lower than the minimum required version (".PHP_MIN_VERSION.")");
  32. return false;
  33. }
  34. $aMandatoryExtensions = array('mysql', 'iconv', 'simplexml');
  35. asort($aMandatoryExtensions); // Sort the list to look clean !
  36. $aExtensionsOk = array();
  37. $aMissingExtensions = array();
  38. $aMissingExtensionsLinks = array();
  39. foreach($aMandatoryExtensions as $sExtension)
  40. {
  41. if (extension_loaded($sExtension))
  42. {
  43. $aExtensionsOk[] = $sExtension;
  44. }
  45. else
  46. {
  47. $aMissingExtensions[] = $sExtension;
  48. $aMissingExtensionsLinks[] = "<a href=\"http://www.php.net/manual/en/book.$sExtension.php\">$sExtension</a>";
  49. }
  50. }
  51. if (count($aExtensionsOk) > 0)
  52. {
  53. $oP->ok("Required PHP extension(s): ".implode(', ', $aExtensionsOk).".");
  54. }
  55. if (count($aMissingExtensions) > 0)
  56. {
  57. $oP->error("Missing PHP extension(s): ".implode(', ', $aMissingExtensionsLinks).".");
  58. return false;
  59. }
  60. return true;
  61. }
  62. /**
  63. * Helper function check the connection to the database and (if connected) to enumerate
  64. * the existing databases
  65. * @return Array The list of databases found in the server
  66. */
  67. function CheckServerConnection(setup_web_page $oP, $sDBServer, $sDBUser, $sDBPwd)
  68. {
  69. $aResult = array();
  70. $oP->log('Info - CheckServerConnection');
  71. try
  72. {
  73. $oDBSource = new CMDBSource;
  74. $oDBSource->Init($sDBServer, $sDBUser, $sDBPwd);
  75. $oP->ok("Connection to '$sDBServer' as '$sDBUser' successful.");
  76. $sDBVersion = $oDBSource->GetDBVersion();
  77. if (version_compare($sDBVersion, MYSQL_MIN_VERSION, '>='))
  78. {
  79. $oP->ok("Current MySQL version ($sDBVersion), greater than minimum required version (".MYSQL_MIN_VERSION.")");
  80. }
  81. else
  82. {
  83. $oP->error("Error: Current MySQL version is ($sDBVersion), minimum required version (".MYSQL_MIN_VERSION.")");
  84. return false;
  85. }
  86. try
  87. {
  88. $aResult = $oDBSource->ListDB();
  89. }
  90. catch(Exception $e)
  91. {
  92. $oP->warning("Warning: unable to enumerate the current databases.");
  93. $aResult = true; // Not an array to differentiate with an empty array
  94. }
  95. }
  96. catch(Exception $e)
  97. {
  98. $oP->error("Error: Connection to '$sDBServer' as '$sDBUser' failed.");
  99. $oP->p($e->GetHtmlDesc());
  100. $aResult = false;
  101. }
  102. return $aResult;
  103. }
  104. /**
  105. * Helper function to initialize the ORM and load the data model
  106. * from the given file
  107. * @param $sConfigFileName string The name of the configuration file to load
  108. * @param $bAllowMissingDatabase boolean Whether or not to allow loading a data model with no corresponding DB
  109. * @return none
  110. */
  111. function InitDataModel(setup_web_page $oP, $sConfigFileName, $bAllowMissingDatabase = true)
  112. {
  113. require_once('../core/coreexception.class.inc.php');
  114. require_once('../core/attributedef.class.inc.php');
  115. require_once('../core/filterdef.class.inc.php');
  116. require_once('../core/stimulus.class.inc.php');
  117. require_once('../core/MyHelpers.class.inc.php');
  118. require_once('../core/expression.class.inc.php');
  119. require_once('../core/cmdbsource.class.inc.php');
  120. require_once('../core/sqlquery.class.inc.php');
  121. require_once('../core/dbobject.class.php');
  122. require_once('../core/dbobjectsearch.class.php');
  123. require_once('../core/dbobjectset.class.php');
  124. require_once('../core/userrights.class.inc.php');
  125. $oP->log("Info - MetaModel::Startup from file '$sConfigFileName' (AllowMissingDB = $bAllowMissingDatabase)");
  126. MetaModel::Startup($sConfigFileName, $bAllowMissingDatabase);
  127. }
  128. /**
  129. * Helper function to create the database structure
  130. * @return boolean true on success, false otherwise
  131. */
  132. function CreateDatabaseStructure(setup_web_page $oP, Config $oConfig, $sDBName, $sDBPrefix)
  133. {
  134. InitDataModel($oP, TMP_CONFIG_FILE, true); // Allow the DB to NOT exist since we're about to create it !
  135. $oP->log('Info - CreateDatabaseStructure');
  136. $oP->info("Creating the structure in '$sDBName' (prefix = '$sDBPrefix').");
  137. //MetaModel::CheckDefinitions();
  138. if (!MetaModel::DBExists())
  139. {
  140. MetaModel::DBCreate();
  141. $oP->ok("Database structure created in '$sDBName' (prefix = '$sDBPrefix').");
  142. }
  143. else
  144. {
  145. $oP->error("Error: database '$sDBName' (prefix = '$sDBPrefix') already exists.");
  146. $oP->p("Tables with conflicting names already exist in the database.
  147. Try selecting another database instance or specifiy a prefix to prevent conflicting table names.");
  148. return false;
  149. }
  150. return true;
  151. }
  152. /**
  153. * Helper function to create and administrator account for iTop
  154. * @return boolean true on success, false otherwise
  155. */
  156. function CreateAdminAccount(setup_web_page $oP, Config $oConfig, $sAdminUser, $sAdminPwd)
  157. {
  158. $oP->log('Info - CreateAdminAccount');
  159. InitDataModel($oP, TMP_CONFIG_FILE, true); // allow missing DB
  160. if (UserRights::CreateAdministrator($sAdminUser, $sAdminPwd))
  161. {
  162. $oP->ok("Administrator account '$sAdminUser' created.");
  163. return true;
  164. }
  165. else
  166. {
  167. $oP->error("Failed to create the administrator account '$sAdminUser'.");
  168. return false;
  169. }
  170. }
  171. //aFilesToLoad[aFilesToLoad.length] = './menus.xml'; // First load the menus
  172. function ListDataFiles($sDirectory, setup_web_page $oP)
  173. {
  174. $aFilesToLoad = array();
  175. if ($hDir = @opendir($sDirectory))
  176. {
  177. // This is the correct way to loop over the directory. (according to the documentation)
  178. while (($sFile = readdir($hDir)) !== false)
  179. {
  180. $sExtension = pathinfo($sFile, PATHINFO_EXTENSION );
  181. if (strcasecmp($sExtension, 'xml') == 0)
  182. {
  183. $aFilesToLoad[] = $sDirectory.'/'.$sFile;
  184. }
  185. }
  186. closedir($hDir);
  187. // Load order is important we expect the files to be ordered
  188. // like numbered 1.Organizations.xml 2.Locations.xml , etc.
  189. asort($aFilesToLoad);
  190. }
  191. else
  192. {
  193. $oP->error("Data directory (".$sDirectory.") not found or not readable.");
  194. }
  195. return $aFilesToLoad;
  196. }
  197. /**
  198. * Scans the ./data directory for XML files and output them as a Javascript array
  199. */
  200. function PopulateDataFilesList(setup_web_page $oP)
  201. {
  202. $oP->add("<script type=\"text/javascript\">\n");
  203. $oP->add("function PopulateDataFilesList()\n");
  204. $oP->add("{\n");
  205. // Structure data
  206. //
  207. $aStructureDataFiles = ListDataFiles(SETUP_STRUCTURE_DATA_DIR, $oP);
  208. foreach($aStructureDataFiles as $sFile)
  209. {
  210. $oP->add("aFilesToLoad[aFilesToLoad.length] = '$sFile';\n");
  211. }
  212. // Sample data - loaded IIF wished by the user
  213. //
  214. $oP->add("if (($(\"#sample_data:checked\").length == 1))");
  215. $oP->add("{");
  216. $aSampleDataFiles = ListDataFiles(SETUP_SAMPLE_DATA_DIR, $oP);
  217. foreach($aSampleDataFiles as $sFile)
  218. {
  219. $oP->add("aFilesToLoad[aFilesToLoad.length] = '$sFile';\n");
  220. }
  221. $oP->add("}\n");
  222. $oP->add("}\n");
  223. $oP->add("</script>\n");
  224. }
  225. /**
  226. * Display the form for the first step of the configuration wizard
  227. * which consists in the database server selection
  228. */
  229. function DisplayStep1(setup_web_page $oP)
  230. {
  231. $sNextOperation = 'step2';
  232. $oP->add("<h1>iTop configuration wizard</h1>\n");
  233. $oP->add("<h2>Checking prerequisites</h2>\n");
  234. if (CheckPHPVersion($oP))
  235. {
  236. $sRedStar = '<span class="hilite">*</span>';
  237. $oP->add("<h2>Step 1: Configuration of the database connection</h2>\n");
  238. $oP->add("<form method=\"post\" onSubmit=\"return DoSubmit('Connection to the database...', 1)\">\n");
  239. // Form goes here
  240. $oP->add("<fieldset><legend>Database connection</legend>\n");
  241. $aForm = array();
  242. $aForm[] = array('label' => "Server name$sRedStar:", 'input' => "<input id=\"db_server\" type=\"text\" name=\"db_server\" value=\"\">",
  243. 'help' => 'E.g. "localhost", "dbserver.mycompany.com" or "192.142.10.23".');
  244. $aForm[] = array('label' => "User name$sRedStar:", 'input' => "<input id=\"db_user\" type=\"text\" name=\"db_user\" value=\"\">");
  245. $aForm[] = array('label' => 'Password:', 'input' => "<input id=\"db_pwd\" type=\"password\" name=\"db_pwd\" value=\"\">");
  246. $oP->form($aForm);
  247. $oP->add("</fieldset>\n");
  248. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  249. $oP->add("<button type=\"submit\">Next >></button>\n");
  250. $oP->add("</form>\n");
  251. }
  252. }
  253. /**
  254. * Display the form for the second step of the configuration wizard
  255. * which consists in
  256. * 1) Validating the parameters by connecting to the database server
  257. * 2) Prompting to select an existing database or to create a new one
  258. */
  259. function DisplayStep2(setup_web_page $oP, Config $oConfig, $sDBServer, $sDBUser, $sDBPwd)
  260. {
  261. $sNextOperation = 'step3';
  262. $oP->add("<h1>iTop configuration wizard</h1>\n");
  263. $oP->add("<h2>Step 2: Database selection</h2>\n");
  264. $oP->add("<form method=\"post\" onSubmit=\"return DoSubmit('Creating database structure...', 2);\">\n");
  265. $aDatabases = CheckServerConnection($oP, $sDBServer, $sDBUser, $sDBPwd);
  266. if ($aDatabases === false)
  267. {
  268. // Connection failed, invalid credentials ? Go back
  269. $oP->add("<button onClick=\"window.history.back();\"><< Back</button>\n");
  270. }
  271. else
  272. {
  273. // Connection is Ok, save it and continue the setup wizard
  274. $oConfig->SetDBHost($sDBServer);
  275. $oConfig->SetDBUser($sDBUser);
  276. $oConfig->SetDBPwd($sDBPwd);
  277. $oConfig->WriteToFile();
  278. $oP->add("<fieldset><legend>Specify a database<span class=\"hilite\">*</span></legend>\n");
  279. $aForm = array();
  280. if (is_array($aDatabases))
  281. {
  282. foreach($aDatabases as $sDBName)
  283. {
  284. $aForm[] = array('label' => "<input id=\"db_$sDBName\" type=\"radio\" name=\"db_name\" value=\"$sDBName\" /><label for=\"db_$sDBName\"> $sDBName</label>");
  285. }
  286. }
  287. else
  288. {
  289. $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\"/>");
  290. $oP->add_ready_script("$('#current_db_name').click( function() { $('#current_db').attr('checked', true); });");
  291. }
  292. $aForm[] = array('label' => "<input id=\"new_db\" type=\"radio\" name=\"db_name\" value=\"\" /><label for=\"new_db\"> Create a new database:</label> <input type=\"text\" id=\"new_db_name\" name=\"new_db_name\" value=\"\" maxlength=\"32\"/>");
  293. $oP->form($aForm);
  294. $oP->add_ready_script("$('#new_db_name').click( function() { $('#new_db').attr('checked', true); })");
  295. $oP->add("</fieldset>\n");
  296. $aForm = array();
  297. $aForm[] = array('label' => "Add a prefix to all the tables: <input id=\"db_prefix\" type=\"text\" name=\"db_prefix\" value=\"\" maxlength=\"32\"/>");
  298. $oP->form($aForm);
  299. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  300. $oP->add("<button onClick=\"window.history.back();\"><< Back</button>\n");
  301. $oP->add("&nbsp;&nbsp;&nbsp;&nbsp;\n");
  302. $oP->add("<button type=\"submit\">Next >></button>\n");
  303. }
  304. $oP->add("</form>\n");
  305. }
  306. /**
  307. * Display the form for the third step of the configuration wizard
  308. * which consists in
  309. * 1) Validating the parameters by connecting to the database server & selecting the database
  310. * 2) Creating the database structure
  311. * 3) Prompting for the admin account to be created
  312. */
  313. function DisplayStep3(setup_web_page $oP, Config $oConfig, $sDBName, $sDBPrefix)
  314. {
  315. $sNextOperation = 'step4';
  316. $oP->add("<h1>iTop configuration wizard</h1>\n");
  317. $oP->add("<h2>Creation of the database structure</h2>\n");
  318. $oP->add("<form method=\"post\" onSubmit=\"return DoSubmit('Creating user and profiles...', 3);\">\n");
  319. $oConfig->SetDBName($sDBName);
  320. $oConfig->SetDBSubname($sDBPrefix);
  321. $oConfig->WriteToFile(TMP_CONFIG_FILE);
  322. if (CreateDatabaseStructure($oP, $oConfig, $sDBName, $sDBPrefix))
  323. {
  324. $sRedStar = "<span class=\"hilite\">*</span>";
  325. $oP->add("<h2>Step 3: Definition of the administrator account</h2>\n");
  326. // Database created, continue with admin creation
  327. $oP->add("<fieldset><legend>Administrator account</legend>\n");
  328. $aForm = array();
  329. $aForm[] = array('label' => "Login$sRedStar:", 'input' => "<input id=\"auth_user\" type=\"text\" name=\"auth_user\" value=\"\">");
  330. $aForm[] = array('label' => "Password$sRedStar:", 'input' => "<input id=\"auth_pwd\" type=\"password\" name=\"auth_pwd\" value=\"\">");
  331. $aForm[] = array('label' => "Retype password$sRedStar:", 'input' => "<input id=\"auth_pwd2\" type=\"password\" name=\"auth_pwd2\" value=\"\">");
  332. $oP->form($aForm);
  333. $oP->add("</fieldset>\n");
  334. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  335. $oP->add("<button onClick=\"window.history.back();\"><< Back</button>\n");
  336. $oP->add("&nbsp;&nbsp;&nbsp;&nbsp;\n");
  337. $oP->add("<button type=\"submit\">Next >></button>\n");
  338. }
  339. else
  340. {
  341. $oP->add("<button onClick=\"window.history.back();\"><< Back</button>\n");
  342. }
  343. // Form goes here
  344. $oP->add("</form>\n");
  345. }
  346. /**
  347. * Display the form for the fourth step of the configuration wizard
  348. * which consists in
  349. * 1) Creating the admin user account
  350. * 2) Prompting to load some sample data
  351. */
  352. function DisplayStep4(setup_web_page $oP, Config $oConfig, $sAdminUser, $sAdminPwd)
  353. {
  354. $sNextOperation = 'step5';
  355. $oP->add("<h1>iTop configuration wizard</h1>\n");
  356. $oP->add("<h2>Creation of the administrator account</h2>\n");
  357. $oP->add("<form method=\"post\"\">\n");
  358. if (CreateAdminAccount($oP, $oConfig, $sAdminUser, $sAdminPwd) && UserRights::Setup())
  359. {
  360. $oP->add("<h2>Step 4: Loading of sample data</h2>\n");
  361. $oP->p("<fieldset><legend> Do you want to load sample data into the database ? </legend>\n");
  362. $oP->p("<input type=\"radio\" id=\"sample_data\" name=\"sample_data\" checked value=\"yes\"> Yes, for testing purposes, populate the database with sample data.\n");
  363. $oP->p("<input type=\"radio\" name=\"sample_data\" unchecked value=\"no\"> No, this is a production system, I will load real data myself.\n");
  364. $oP->p("</fieldset>\n");
  365. $oP->add("<button onClick=\"window.history.back();\"><< Back</button>\n");
  366. $oP->add("&nbsp;&nbsp;&nbsp;&nbsp;\n");
  367. $oP->add("<button onclick=\"DoSubmit('Finalizing configuration and loading data...', 4);\">Finish</button>\n");
  368. }
  369. else
  370. {
  371. // Creation failed
  372. $oP->add("<button onClick=\"window.history.back();\"><< Back</button>\n");
  373. }
  374. // End of visible form
  375. $oP->add("</form>\n");
  376. // Hidden form
  377. $oP->add("<form id=\"GoToNextStep\" method=\"post\">\n");
  378. $oP->add("<input type=\"hidden\" name=\"auth_user\" value=\"$sAdminUser\">\n"); // To be compatible with login page
  379. $oP->add("<input type=\"hidden\" name=\"auth_pwd\" value=\"$sAdminPwd\">\n"); // To be compatible with login page
  380. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  381. $oP->add("</form>\n");
  382. $oP->add_linked_script('./jquery.progression.js');
  383. PopulateDataFilesList($oP);
  384. }
  385. /**
  386. * Display the form for the fifth (and final) step of the configuration wizard
  387. * which consists in
  388. * 1) Creating the final configuration file
  389. * 2) Prompting the user to make the file read-only
  390. */
  391. function DisplayStep5(setup_web_page $oP, Config $oConfig, $sAuthUser, $sAuthPwd)
  392. {
  393. try
  394. {
  395. session_start();
  396. // Write the final configuration file
  397. $oConfig->WriteToFile(FINAL_CONFIG_FILE);
  398. // Start the application
  399. InitDataModel($oP, FINAL_CONFIG_FILE, false); // DO NOT allow missing DB
  400. if (UserRights::Login($sAuthUser, $sAuthPwd))
  401. {
  402. $_SESSION['auth_user'] = $sAuthUser;
  403. $_SESSION['auth_pwd'] = $sAuthPwd;
  404. // remove the tmp config file
  405. @unlink(TMP_CONFIG_FILE);
  406. // try to make the final config file read-only
  407. @chmod(FINAL_CONFIG_FILE, 0440); // Read-only for owner and group, nothing for others
  408. $oP->add("<h1>iTop configuration wizard</h1>\n");
  409. $oP->add("<h2>Configuration completed</h2>\n");
  410. $oP->add("<form method=\"get\" action=\"../index.php\">\n");
  411. $oP->ok("The initialization completed successfully.");
  412. // Form goes here
  413. $oP->add("<button onClick=\"window.history.back();\"><< Back</button>\n");
  414. $oP->add("&nbsp;&nbsp;&nbsp;&nbsp;\n");
  415. $oP->add("<button type=\"submit\">Enter iTop</button>\n");
  416. $oP->add("</form>\n");
  417. }
  418. else
  419. {
  420. $oP->add("<h1>iTop configuration wizard</h1>\n");
  421. $oP->add("<h2>Step 5: Configuration completed</h2>\n");
  422. @unlink(FINAL_CONFIG_FILE); // remove the aborted config
  423. $oP->error("Error: Failed to login for user: '$sAuthUser'\n");
  424. $oP->add("<form method=\"get\" action=\"../index.php\">\n");
  425. $oP->add("<button onClick=\"window.history.back();\"><< Back</button>\n");
  426. $oP->add("&nbsp;&nbsp;&nbsp;&nbsp;\n");
  427. $oP->add("</form>\n");
  428. }
  429. }
  430. catch(Exception $e)
  431. {
  432. $oP->error("Error: unable to create the configuration file.");
  433. $oP->p($e->getHtmlDesc());
  434. $oP->p("Did you forget to remove the previous (read-only) configuration file ?");
  435. }
  436. }
  437. /**
  438. * Main program
  439. */
  440. clearstatcache(); // Make sure we know what we are doing !
  441. if (file_exists(FINAL_CONFIG_FILE))
  442. {
  443. // The configuration file already exists
  444. if (is_writable(FINAL_CONFIG_FILE))
  445. {
  446. $oP->warning("<b>Warning:</b> a configuration file '".FINAL_CONFIG_FILE."' already exists, and will be overwritten.");
  447. }
  448. else
  449. {
  450. $oP->add("<h1>iTop configuration wizard</h1>\n");
  451. $oP->add("<h2>Fatal error</h2>\n");
  452. $oP->error("<b>Error:</b> the configuration file '".FINAL_CONFIG_FILE."' already exists and cannot be overwritten.");
  453. $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.");
  454. $oP->output();
  455. exit;
  456. }
  457. }
  458. else
  459. {
  460. // No configuration file yet
  461. // Check that the wizard can write into the root dir to create the configuration file
  462. if (!is_writable(dirname(FINAL_CONFIG_FILE)))
  463. {
  464. $oP->add("<h1>iTop configuration wizard</h1>\n");
  465. $oP->add("<h2>Fatal error</h2>\n");
  466. $oP->error("<b>Error:</b> the directory where to store the configuration file is not writable.");
  467. $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.");
  468. $oP->output();
  469. exit;
  470. }
  471. }
  472. try
  473. {
  474. $oConfig = new Config(TMP_CONFIG_FILE);
  475. }
  476. catch(Exception $e)
  477. {
  478. // We'll end here when the tmp config file does not exist. It's normal
  479. $oConfig = new Config(TMP_CONFIG_FILE, false /* Don't try to load it */);
  480. }
  481. try
  482. {
  483. switch($sOperation)
  484. {
  485. case 'step1':
  486. $oP->log("Info - ========= Wizard step 1 ========");
  487. DisplayStep1($oP);
  488. break;
  489. case 'step2':
  490. $oP->no_cache();
  491. $oP->log("Info - ========= Wizard step 2 ========");
  492. $sDBServer = Utils::ReadParam('db_server');
  493. $sDBUser = Utils::ReadParam('db_user');
  494. $sDBPwd = Utils::ReadParam('db_pwd');
  495. DisplayStep2($oP, $oConfig, $sDBServer, $sDBUser, $sDBPwd);
  496. break;
  497. case 'step3':
  498. $oP->no_cache();
  499. $oP->log("Info - ========= Wizard step 3 ========");
  500. $sDBName = Utils::ReadParam('db_name');
  501. if (empty($sDBName))
  502. {
  503. $sDBName = Utils::ReadParam('new_db_name');
  504. }
  505. $sDBPrefix = Utils::ReadParam('db_prefix');
  506. DisplayStep3($oP, $oConfig, $sDBName, $sDBPrefix);
  507. break;
  508. case 'step4':
  509. $oP->no_cache();
  510. $oP->log("Info - ========= Wizard step 4 ========");
  511. $sAdminUser = Utils::ReadParam('auth_user');
  512. $sAdminPwd = Utils::ReadParam('auth_pwd');
  513. DisplayStep4($oP, $oConfig, $sAdminUser, $sAdminPwd);
  514. break;
  515. case 'step5':
  516. $oP->no_cache();
  517. $oP->log("Info - ========= Wizard step 5 ========");
  518. $sAdminUser = Utils::ReadParam('auth_user');
  519. $sAdminPwd = Utils::ReadParam('auth_pwd');
  520. DisplayStep5($oP, $oConfig, $sAdminUser, $sAdminPwd);
  521. break;
  522. default:
  523. $oP->error("Error: unsupported operation '$sOperation'");
  524. }
  525. }
  526. catch(Exception $e)
  527. {
  528. $oP->error("Error: '".$e->getMessage()."'");
  529. }
  530. catch(CoreException $e)
  531. {
  532. $oP->error("Error: '".$e->getHtmlDesc()."'");
  533. }
  534. $oP->output();
  535. ?>