index.php 44 KB

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