index.php 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  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('../application/cmdbabstract.class.inc.php');
  342. require_once('../core/userrights.class.inc.php');
  343. $oP->log("Info - MetaModel::Startup from file '$sConfigFileName' (ModelOnly = $bModelOnly)");
  344. MetaModel::Startup($sConfigFileName, $bModelOnly);
  345. }
  346. /**
  347. * Helper function to create the database structure
  348. * @return boolean true on success, false otherwise
  349. */
  350. function CreateDatabaseStructure(SetupWebPage $oP, Config $oConfig, $sDBName, $sDBPrefix)
  351. {
  352. InitDataModel($oP, TMP_CONFIG_FILE, true); // Allow the DB to NOT exist since we're about to create it !
  353. $oP->log('Info - CreateDatabaseStructure');
  354. if (strlen($sDBPrefix) > 0)
  355. {
  356. $oP->info("Creating the structure in '$sDBName' (table names prefixed by '$sDBPrefix').");
  357. }
  358. else
  359. {
  360. $oP->info("Creating the structure in '$sDBName'.");
  361. }
  362. //MetaModel::CheckDefinitions();
  363. if (!MetaModel::DBExists(/* bMustBeComplete */ false))
  364. {
  365. MetaModel::DBCreate();
  366. $oP->ok("Database structure successfully created.");
  367. }
  368. else
  369. {
  370. if (strlen($sDBPrefix) > 0)
  371. {
  372. $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.");
  373. }
  374. else
  375. {
  376. $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.");
  377. }
  378. return false;
  379. }
  380. return true;
  381. }
  382. /**
  383. * Helper function to create and administrator account for iTop
  384. * @return boolean true on success, false otherwise
  385. */
  386. function CreateAdminAccount(SetupWebPage $oP, Config $oConfig, $sAdminUser, $sAdminPwd, $sLanguage)
  387. {
  388. $oP->log('Info - CreateAdminAccount');
  389. InitDataModel($oP, TMP_CONFIG_FILE, false); // load data model and connect to the database
  390. if (UserRights::CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage))
  391. {
  392. $oP->ok("Administrator account '$sAdminUser' created.");
  393. return true;
  394. }
  395. else
  396. {
  397. $oP->error("Failed to create the administrator account '$sAdminUser'.");
  398. return false;
  399. }
  400. }
  401. function ListModuleFiles($sDirectory, SetupWebPage $oP)
  402. {
  403. //echo "<p>$sDirectory</p>\n";
  404. if ($hDir = opendir($sDirectory))
  405. {
  406. // This is the correct way to loop over the directory. (according to the documentation)
  407. while (($sFile = readdir($hDir)) !== false)
  408. {
  409. $aMatches = array();
  410. if (is_dir($sDirectory.'/'.$sFile))
  411. {
  412. if (($sFile != '.') && ($sFile != '..') && ($sFile != '.svn'))
  413. {
  414. ListModuleFiles($sDirectory.'/'.$sFile, $oP);
  415. }
  416. }
  417. else if (preg_match('/^module\.(.*).php$/i', $sFile, $aMatches))
  418. {
  419. try
  420. {
  421. //echo "<p>Loading: $sDirectory/$sFile...</p>\n";
  422. require_once($sDirectory.'/'.$sFile);
  423. //echo "<p>Done.</p>\n";
  424. }
  425. catch(Exception $e)
  426. {
  427. // Continue...
  428. }
  429. }
  430. }
  431. closedir($hDir);
  432. }
  433. else
  434. {
  435. $oP->error("Data directory (".$sDirectory.") not found or not readable.");
  436. }
  437. }
  438. /**
  439. * Scans the ./data directory for XML files and output them as a Javascript array
  440. */
  441. function PopulateDataFilesList(SetupWebPage $oP, $aParamValues)
  442. {
  443. $oP->add("<script type=\"text/javascript\">\n");
  444. $oP->add("function PopulateDataFilesList()\n");
  445. $oP->add("{\n");
  446. $oP->add("if (aFilesToLoad.length > 0) return;"); // Populate the list only once...
  447. $aAvailableModules = GetAvailableModules($oP);
  448. $aStructureDataFiles = array();
  449. $aSampleDataFiles = array();
  450. foreach($aParamValues['module'] as $sModuleId)
  451. {
  452. $aModuleStruct = $aAvailableModules[$sModuleId]['data.struct'];
  453. $aModuleSamples = $aAvailableModules[$sModuleId]['data.sample'];
  454. $aStructureDataFiles = array_merge($aStructureDataFiles, $aModuleStruct);
  455. $aSampleDataFiles = array_merge($aSampleDataFiles, $aModuleSamples);
  456. }
  457. // Structure data
  458. //
  459. foreach($aStructureDataFiles as $sFile)
  460. {
  461. // Under Windows, it is a must to escape backslashes (not an issue until a folder name starts with t or n, etc...)
  462. $sFile = str_replace('\\', '\\\\', $sFile);
  463. $oP->add("aFilesToLoad[aFilesToLoad.length] = '$sFile';\n");
  464. }
  465. // Sample data - loaded IIF wished by the user
  466. //
  467. $oP->add("if (($(\"#sample_data:checked\").length == 1))");
  468. $oP->add("{");
  469. foreach($aSampleDataFiles as $sFile)
  470. {
  471. // Under Windows, it is a must to escape backslashes (not an issue until a folder name starts with t or n, etc...)
  472. $sFile = str_replace('\\', '\\\\', $sFile);
  473. $oP->add("aFilesToLoad[aFilesToLoad.length] = '$sFile';\n");
  474. }
  475. $oP->add("}\n");
  476. $oP->add("}\n");
  477. $oP->add("</script>\n");
  478. }
  479. /**
  480. * Add some parameters as hidden inputs into a form
  481. * @param SetupWebpage $oP The page to insert the form elements into
  482. * @param Hash $aParamValues The pairs name/value to be stored in the form
  483. * @param Array $aExcludeParams A list of parameters to exclude from the previous hash
  484. */
  485. function AddParamsToForm(SetupWebpage $oP, $aParamValues, $aExcludeParams = array())
  486. {
  487. foreach($aParamValues as $sName => $value)
  488. {
  489. if(!in_array($sName, $aExcludeParams))
  490. {
  491. if (is_array($value))
  492. {
  493. foreach($value as $sKey => $sItem)
  494. {
  495. $oP->add('<input type="hidden" name="'.$sName.'['.$sKey.']'.'" value="'.$sItem.'">');
  496. }
  497. }
  498. else
  499. {
  500. $oP->add('<input type="hidden" name="'.$sName.'" value="'.$value.'">');
  501. }
  502. }
  503. }
  504. }
  505. /**
  506. * Search (on the disk) for all defined iTop modules, load them and returns the list (as an array)
  507. * of the possible iTop modules to install
  508. * @param none
  509. * @return Hash A big array moduleID => ModuleData
  510. */
  511. function GetAvailableModules(SetupWebpage $oP)
  512. {
  513. clearstatcache();
  514. ListModuleFiles('../modules/', $oP);
  515. return $oP->GetModules();
  516. }
  517. /**
  518. * Build the config file from the parameters (especially the selected modules)
  519. */
  520. function BuildConfig(SetupWebpage $oP, Config &$oConfig, $aParamValues)
  521. {
  522. $aAvailableModules = GetAvailableModules($oP);
  523. // Initialize the arrays below with default values for the application...
  524. $aAddOns = $oConfig->GetAddOns();
  525. $aAppModules = $oConfig->GetAppModules();
  526. $aDataModels = $oConfig->GetDataModels();
  527. $sDictionaries = $oConfig->GetDictionaries();
  528. // Merge the values with the ones provided by the modules
  529. // Make sure when don't load the same file twice...
  530. foreach($aParamValues['module'] as $sModuleId)
  531. {
  532. $oP->log('Installed iTop module: '. $sModuleId);
  533. $aDataModels = array_unique(array_merge($aDataModels, $aAvailableModules[$sModuleId]['datamodel']));
  534. $sDictionaries = array_unique(array_merge($sDictionaries, $aAvailableModules[$sModuleId]['dictionary']));
  535. }
  536. $oConfig->SetAddOns($aAddOns);
  537. $oConfig->SetAppModules($aAppModules);
  538. $oConfig->SetDataModels($aDataModels);
  539. $oConfig->SetDictionaries($sDictionaries);
  540. }
  541. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  542. // Handling of the different steps of the setup wizard
  543. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  544. /**
  545. * Displays the welcome screen and check some basic prerequisites
  546. */
  547. function WelcomeAndCheckPrerequisites(SetupWebPage $oP, $aParamValues, $iCurrentStep)
  548. {
  549. $sNextOperation = 'step'.($iCurrentStep+1);
  550. $oP->add("<h1>iTop configuration wizard</h1>\n");
  551. $sVersionStringShort = GetITopVersion(true);
  552. $sVersionStringLong = GetITopVersion(false);
  553. $oP->set_title('Welcome to '.$sVersionStringShort);
  554. $oP->log($sVersionStringLong);
  555. $oP->add("<h2>Checking prerequisites</h2>\n");
  556. if (CheckPHPVersion($oP))
  557. {
  558. $oP->add("<h2 class=\"next\">Next: Licence agreement</h2>\n");
  559. $oP->add("<form id=\"theForm\" method=\"post\" onSubmit=\"return DoSubmit('', 0)\">\n");
  560. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  561. AddParamsToForm($oP, $aParamValues);
  562. $oP->add("<table style=\"width:100%\"><tr>\n");
  563. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\" type=\"submit\">Next >></button></td>\n");
  564. $oP->add("</tr></table>\n");
  565. $oP->add("</form>\n");
  566. }
  567. }
  568. function LicenceAcknowledgement($oP, $aParamValues, $iCurrentStep)
  569. {
  570. $sNextOperation = 'step'.($iCurrentStep+1);
  571. $oP->set_title('License Agreement');
  572. $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>');
  573. $oP->add("<iframe style=\"width: 100%; height: 350px; overflow-y:auto; font-size:0.8em;\" src=\"./licence.html\">Next: Database server selection</iframe>\n");
  574. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  575. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  576. AddParamsToForm($oP, $aParamValues, array('licence_ok'));
  577. $sChecked = $aParamValues['licence_ok'] == 1 ? 'checked' : '';
  578. $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");
  579. $oP->add("<h2 class=\"next\">Next: Database server selection</h2>\n");
  580. $oP->add("<table style=\"width:100%\"><tr>\n");
  581. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button></td>\n");
  582. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\" onClick=\"return DoSubmit('', $iCurrentStep)\">Next >></button></td>\n");
  583. $oP->add("</tr></table>\n");
  584. $oP->add("</form>\n");
  585. }
  586. /**
  587. * Display the form for the first step of the configuration wizard
  588. * which consists in the database server selection
  589. */
  590. function DatabaseServerSelection(SetupWebPage $oP, $aParamValues, $iCurrentStep)
  591. {
  592. $sNextOperation = 'step'.($iCurrentStep+1);
  593. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  594. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  595. AddParamsToForm($oP, $aParamValues, array('db_server', 'db_user', 'db_pwd'));
  596. if ($aParamValues['licence_ok'] == 1)
  597. {
  598. $sRedStar = '<span class="hilite">*</span>';
  599. $oP->set_title("Configuration of the database connection\n");
  600. $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");
  601. // Form goes here
  602. $oP->add("<fieldset><legend>Database connection</legend>\n");
  603. $aForm = array();
  604. $aForm[] = array('label' => "Server name$sRedStar:", 'input' => "<input id=\"db_server\" type=\"text\" name=\"db_server\" value=\"{$aParamValues['db_server']}\">",
  605. 'help' => 'E.g. "localhost", "dbserver.mycompany.com" or "192.142.10.23"');
  606. $aForm[] = array('label' => "User name$sRedStar:", 'input' => "<input id=\"db_user\" type=\"text\" name=\"db_user\" value=\"{$aParamValues['db_user']}\">",
  607. 'help' => 'The account must have the following privileges: SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER');
  608. $aForm[] = array('label' => 'Password:', 'input' => "<input id=\"db_pwd\" type=\"password\" name=\"db_pwd\" value=\"{$aParamValues['db_pwd']}\">");
  609. $oP->form($aForm);
  610. $oP->add("</fieldset>\n");
  611. $oP->add("<h2 class=\"next\">Next: Database Instance Selection</h2>\n");
  612. $oP->add("<table style=\"width:100%\"><tr>\n");
  613. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button></td>\n");
  614. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\" onClick=\"return DoSubmit('Connecting to the database...', $iCurrentStep);\">Next >></button></td>\n");
  615. $oP->add("</tr></table>\n");
  616. }
  617. else
  618. {
  619. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iCurrentStep);\"><< Back</button>\n");
  620. }
  621. $oP->add("</form>\n");
  622. }
  623. /**
  624. * Display the form for the second step of the configuration wizard
  625. * which consists in
  626. * 1) Validating the parameters by connecting to the database server
  627. * 2) Prompting to select an existing database or to create a new one
  628. */
  629. function DatabaseInstanceSelection(SetupWebPage $oP, $aParamValues, $iCurrentStep, $oConfig)
  630. {
  631. $sNextOperation = 'step'.($iCurrentStep+1);
  632. $oP->set_title("Database Instance Selection\n");
  633. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  634. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  635. AddParamsToForm($oP, $aParamValues, array('db_name', 'db_prefix', 'new_db_name'));
  636. $sDBServer = $aParamValues['db_server'];
  637. $sDBUser = $aParamValues['db_user'];
  638. $sDBPwd = $aParamValues['db_pwd'];
  639. $aDatabases = CheckServerConnection($oP, $sDBServer, $sDBUser, $sDBPwd);
  640. if ($aDatabases === false)
  641. {
  642. // Connection failed, invalid credentials ? Go back
  643. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iCurrentStep);\"><< Back</button>\n");
  644. }
  645. else
  646. {
  647. // Connection is Ok, save it and continue the setup wizard
  648. $oConfig->SetDBHost($sDBServer);
  649. $oConfig->SetDBUser($sDBUser);
  650. $oConfig->SetDBPwd($sDBPwd);
  651. $oConfig->WriteToFile();
  652. $oP->add("<fieldset><legend>Select the database instance to use for iTop<span class=\"hilite\">*</span></legend>\n");
  653. $aForm = array();
  654. $bExistingChecked = false;
  655. if (is_array($aDatabases))
  656. {
  657. foreach($aDatabases as $sDBName)
  658. {
  659. $sChecked = '';
  660. if ($aParamValues['db_name'] == $sDBName)
  661. {
  662. $sChecked = 'checked';
  663. $bExistingChecked = true;
  664. }
  665. $aForm[] = array('label' => "<input id=\"db_$sDBName\" type=\"radio\" name=\"db_name\" value=\"$sDBName\" $sChecked/><label for=\"db_$sDBName\"> $sDBName</label>");
  666. }
  667. }
  668. else
  669. {
  670. $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\"/>");
  671. $oP->add_ready_script("$('#current_db_name').click( function() { $('#current_db').attr('checked', true); });");
  672. }
  673. $sChecked = '';
  674. $sDBName = '';
  675. // If the 'Create Database' option was checked... and the database still does not exist
  676. if (!$bExistingChecked && !empty($aParamValues['new_db_name']))
  677. {
  678. $sChecked = 'checked';
  679. $sDBName = $aParamValues['new_db_name'];
  680. }
  681. $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\"/>");
  682. $oP->form($aForm);
  683. $oP->add_ready_script("$('#new_db_name').click( function() { $('#new_db').attr('checked', true); })");
  684. $oP->add("</fieldset>\n");
  685. $aForm = array();
  686. $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\"/>");
  687. $oP->form($aForm);
  688. $oP->add("<h2 class=\"next\">Next: iTop Modules Selection</h2>\n");
  689. $oP->add("<table style=\"width:100%\"><tr>\n");
  690. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button></td>\n");
  691. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\" onClick=\"return DoSubmit('', $iCurrentStep);\">Next >></button></td>\n");
  692. $oP->add("</tr></table>\n");
  693. }
  694. $oP->add("</form>\n");
  695. }
  696. /**
  697. * Display the form to select the iTop modules to be installed
  698. */
  699. function ModulesSelection(SetupWebPage $oP, $aParamValues, $iCurrentStep, $oConfig)
  700. {
  701. $sNextOperation = 'step'.($iCurrentStep+1);
  702. $sPrevOperation = 'step'.($iCurrentStep-1);
  703. $sDBName = $aParamValues['db_name'];
  704. if ($sDBName == '')
  705. {
  706. $sDBName = $aParamValues['new_db_name'];
  707. }
  708. $sDBPrefix = $aParamValues['db_prefix'];
  709. $oConfig->SetDBName($sDBName);
  710. $oConfig->SetDBSubname($sDBPrefix);
  711. $oConfig->WriteToFile(TMP_CONFIG_FILE);
  712. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  713. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  714. AddParamsToForm($oP, $aParamValues, array('module'));
  715. $sRedStar = '<span class="hilite">*</span>';
  716. $oP->set_title("Selection of the iTop Modules\n");
  717. $oP->add("<h2>Customize your iTop installation to fit your needs</h2>\n");
  718. $aAvailableModules = GetAvailableModules($oP);
  719. // Form goes here
  720. $oP->add("<fieldset><legend>Select the iTop modules you want to install:</legend>\n");
  721. $oP->add("<div style=\"border: 0;width:100%; height: 350px; overflow-y:auto;\">");
  722. $sRedStar = '<span class="hilite">*</span>';
  723. $index = 0;
  724. $aSelectedModules = $aParamValues['module'];
  725. if ($aSelectedModules == '')
  726. {
  727. // Make sure it gets initialized as an array, default value: all modules selected !
  728. $aSelectedModules = array();
  729. foreach($aAvailableModules as $sModuleId => $aModule)
  730. {
  731. $aSelectedModules[] = $sModuleId;
  732. }
  733. }
  734. foreach($aAvailableModules as $sModuleId => $aModule)
  735. {
  736. $sModuleLabel = $aModule['label'];
  737. $sModuleHelp = $aModule['doc.more_information'];
  738. $sClass = ($aModule['mandatory']) ? 'class="read-only"' : '';
  739. $sChecked = ($aModule['mandatory'] || in_array($sModuleId, $aSelectedModules) ) ? 'checked' : '';
  740. $sMoreInfo = (!empty($aModule['doc.more_information'])) ? "<a href=\"{$aModule['doc.more_information']}\" target=\"_blank\">more info</a>": '';
  741. if ($aModule['visible'])
  742. {
  743. $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");
  744. $index++;
  745. }
  746. else
  747. {
  748. // For now hidden modules are always on !
  749. $oP->add("<input type=\"hidden\" id=\"module[$index]\" name=\"module[$index]\" value=\"$sModuleId\">\n");
  750. }
  751. }
  752. $oP->add("</div>");
  753. $oP->add("</fieldset>\n");
  754. $oP->add("<h2 class=\"next\">Next: Administrator Account Creation</h2>\n");
  755. $oP->add("<table style=\"width:100%\"><tr>\n");
  756. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button></td>\n");
  757. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\" onClick=\"return DoSubmit('Creating the database structure...', $iCurrentStep);\">Next >></button></td>\n");
  758. $oP->add("</tr></table>\n");
  759. $oP->add("</form>\n");
  760. $oP->add_ready_script("$('.read-only').click( function() { $(this).attr('checked','checked'); } );");
  761. }
  762. /**
  763. * Display the form for the third step of the configuration wizard
  764. * which consists in
  765. * 1) Validating the parameters by connecting to the database server & selecting the database
  766. * 2) Creating the database structure
  767. * 3) Prompting for the admin account to be created
  768. */
  769. function AdminAccountDefinition(SetupWebPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  770. {
  771. $sNextOperation = 'step'.($iCurrentStep+1);
  772. $oP->set_title("Configuration of the admin account");
  773. $oP->add("<h2>Creation of the database structure</h2>");
  774. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  775. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  776. AddParamsToForm($oP, $aParamValues, array('auth_user', 'auth_pwd', 'language'));
  777. $sDBName = $aParamValues['db_name'];
  778. if ($sDBName == '')
  779. {
  780. $sDBName = $aParamValues['new_db_name'];
  781. }
  782. $sDBPrefix = $aParamValues['db_prefix'];
  783. $oConfig->SetDBName($sDBName);
  784. $oConfig->SetDBSubname($sDBPrefix);
  785. BuildConfig($oP, $oConfig, $aParamValues); // Load all the includes based on the modules selected
  786. $oConfig->WriteToFile(TMP_CONFIG_FILE);
  787. if (CreateDatabaseStructure($oP, $oConfig, $sDBName, $sDBPrefix))
  788. {
  789. $sRedStar = "<span class=\"hilite\">*</span>";
  790. $oP->add("<h2>Default language for the application:</h2>\n");
  791. // Possible languages (depends on the dictionaries loaded in the config)
  792. $aForm = array();
  793. $aAvailableLanguages = Dict::GetLanguages();
  794. $sLanguages = '';
  795. $sDefaultCode = $oConfig->GetDefaultLanguage();
  796. foreach($aAvailableLanguages as $sLangCode => $aInfo)
  797. {
  798. $sSelected = ($sLangCode == $sDefaultCode ) ? 'selected ' : '';
  799. $sLanguages.="<option value=\"{$sLangCode}\">{$aInfo['description']} ({$aInfo['localized_description']})</option>";
  800. }
  801. $aForm[] = array('label' => "Default Language$sRedStar:", 'input' => "<select id=\"language\" name=\"language\">$sLanguages</option>");
  802. $oP->form($aForm);
  803. $oP->add("<h2>Definition of the administrator account</h2>\n");
  804. // Database created, continue with admin creation
  805. $oP->add("<fieldset><legend>Administrator account</legend>\n");
  806. $aForm = array();
  807. $aForm[] = array('label' => "Login$sRedStar:", 'input' => "<input id=\"auth_user\" type=\"text\" name=\"auth_user\" value=\"{$aParamValues['auth_user']}\">");
  808. $aForm[] = array('label' => "Password$sRedStar:", 'input' => "<input id=\"auth_pwd\" type=\"password\" name=\"auth_pwd\" value=\"{$aParamValues['auth_pwd']}\">");
  809. $aForm[] = array('label' => "Retype password$sRedStar:", 'input' => "<input id=\"auth_pwd2\" type=\"password\" name=\"auth_pwd2\" value=\"{$aParamValues['auth_pwd']}\">");
  810. $oP->form($aForm);
  811. $oP->add("</fieldset>\n");
  812. $oP->add("<h2 class=\"next\">Next: Administrator Account Creation</h2>\n");
  813. $oP->add("<table style=\"width:100%\"><tr>\n");
  814. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button></td>\n");
  815. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\" onClick=\"return DoSubmit('Creating the admin account and profiles...', $iCurrentStep);\">Next >></button></td>\n");
  816. $oP->add("</tr></table>\n");
  817. }
  818. else
  819. {
  820. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button>\n");
  821. }
  822. // Form goes here
  823. $oP->add("</form>\n");
  824. }
  825. /**
  826. * Display the form for the fourth step of the configuration wizard
  827. * which consists in
  828. * 1) Creating the admin user account
  829. * 2) Prompting to load some sample data
  830. */
  831. function SampleDataSelection(SetupWebPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  832. {
  833. $sNextOperation = 'step'.($iCurrentStep+1);
  834. $oP->set_title("Application Initialization");
  835. $sAdminUser = $aParamValues['auth_user'];
  836. $sAdminPwd = $aParamValues['auth_pwd'];
  837. $sLanguage = $aParamValues['language'];
  838. $oConfig->SetDefaultLanguage($aParamValues['language']);
  839. $oConfig->WriteToFile(TMP_CONFIG_FILE);
  840. $oP->add("<form id=\"theForm\" method=\"post\"\">\n");
  841. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  842. AddParamsToForm($oP, $aParamValues, array('sample_data'));
  843. if (CreateAdminAccount($oP, $oConfig, $sAdminUser, $sAdminPwd, $sLanguage) && UserRights::Setup())
  844. {
  845. $oP->add("<h2>Loading of sample data</h2>\n");
  846. $oP->p("<fieldset><legend> Do you want to load sample data into the database ? </legend>\n");
  847. $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");
  848. $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");
  849. $oP->p("</fieldset>\n");
  850. $oP->add("<h2 class=\"next\">Next: Application Initialization</h2>\n");
  851. $oP->add("<table style=\"width:100%\"><tr>\n");
  852. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button></td>\n");
  853. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\" onClick=\"return DoSubmit('Finalizing configuration and loading data...', $iCurrentStep)\">Next >></button></td>\n");
  854. $oP->add("</tr></table>\n");
  855. }
  856. else
  857. {
  858. // Creation failed
  859. $oP->error("Internal error: Failed to create the admin account or to setup the user rights");
  860. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iCurrentStep)\"><< Back</button>\n");
  861. }
  862. // End of visible form
  863. $oP->add("</form>\n");
  864. // Hidden form submitted when moving on to the next page, once all the data files
  865. // have been processed
  866. $oP->add("<form id=\"GoToNextStep\" method=\"post\">\n");
  867. AddParamsToForm($oP, $aParamValues, array('sample_data'));
  868. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  869. $oP->add("</form>\n");
  870. $oP->add("<div id=\"log\" style=\"color:#F00;\"></div>\n");
  871. $oP->add_linked_script('./jquery.progression.js');
  872. PopulateDataFilesList($oP, $aParamValues);
  873. }
  874. /**
  875. * Display the form for the fifth (and final) step of the configuration wizard
  876. * which consists in
  877. * 1) Creating the final configuration file
  878. * 2) Prompting the user to make the file read-only
  879. */
  880. function SetupFinished(SetupWebPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  881. {
  882. $sAuthUser = $aParamValues['auth_user'];
  883. $sAuthPwd = $aParamValues['auth_pwd'];
  884. try
  885. {
  886. session_start();
  887. // Write the final configuration file
  888. $oConfig->WriteToFile(FINAL_CONFIG_FILE);
  889. // Start the application
  890. InitDataModel($oP, FINAL_CONFIG_FILE, false); // Load model and startup DB
  891. if (UserRights::Login($sAuthUser, $sAuthPwd))
  892. {
  893. $_SESSION['auth_user'] = $sAuthUser;
  894. $_SESSION['auth_pwd'] = $sAuthPwd;
  895. // remove the tmp config file
  896. @unlink(TMP_CONFIG_FILE);
  897. // try to make the final config file read-only
  898. @chmod(FINAL_CONFIG_FILE, 0440); // Read-only for owner and group, nothing for others
  899. $oP->set_title("Configuration completed");
  900. $oP->add("<form id=\"theForm\" method=\"get\" action=\"../index.php\">\n");
  901. // Check if there are some manual steps required:
  902. $aAvailableModules = GetAvailableModules($oP);
  903. $aManualSteps = array();
  904. foreach($aParamValues['module'] as $sModuleId)
  905. {
  906. if (!empty($aAvailableModules[$sModuleId]['doc.manual_setup']))
  907. {
  908. $aManualSteps[$aAvailableModules[$sModuleId]['label']] = $aAvailableModules[$sModuleId]['doc.manual_setup'];
  909. }
  910. }
  911. if (count($aManualSteps) > 0)
  912. {
  913. $oP->add("<h2>Manual operations required</h2>");
  914. $oP->p("In order to complete the installation, the following manual operations are required:");
  915. foreach($aManualSteps as $sModuleLabel => $sUrl)
  916. {
  917. $oP->p("<a href=\"$sUrl\" target=\"_blank\">Manual instructions for $sModuleLabel</a>");
  918. }
  919. }
  920. else
  921. {
  922. $oP->add("<h2>Congratulations for installing iTop</h2>");
  923. $oP->ok("The initialization completed successfully.");
  924. }
  925. // Form goes here.. No back button since the job is done !
  926. $oP->add("<h1>Let us know what you think about iTop</h1>");
  927. $oP->add('<table style="width:100%;border:0;padding:0;"><tr><td style="width:100px;vertical-align:middle;background:#f6f6f1;text-align:center">');
  928. $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>');
  929. $oP->add('<td style="padding-left: 10px;font-size:10pt">');
  930. $oP->add("Combodo built iTop because Combodo believes that modern ITIL tools should be at the center of any IT department.");
  931. $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>");
  932. $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...)");
  933. $oP->p("Check out the <a href=\"http://www.combodo.com/itopsupport\">support options</a> available for iTop.");
  934. $oP->add('</td></tr></table>');
  935. $oP->add("<p style=\"text-align:center;width:100%\"><button type=\"submit\">Enter iTop</button></p>\n");
  936. $oP->add("</form>\n");
  937. }
  938. else
  939. {
  940. $oP->add("<h1>iTop configuration wizard</h1>\n");
  941. $oP->add("<h2>Step 5: Configuration completed</h2>\n");
  942. @unlink(FINAL_CONFIG_FILE); // remove the aborted config
  943. $oP->error("Error: Failed to login for user: '$sAuthUser'\n");
  944. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  945. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iCurrentStep);\"><< Back</button>\n");
  946. AddParamsToForm($oP, $aParamValues);
  947. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"step0\">\n");
  948. $oP->add("</form>\n");
  949. }
  950. }
  951. catch(Exception $e)
  952. {
  953. $oP->error("Error: unable to create the configuration file.");
  954. $oP->p($e->getHtmlDesc());
  955. $oP->p("Did you forget to remove the previous (read-only) configuration file ?");
  956. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  957. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"step0\">\n");
  958. AddParamsToForm($oP, $aParamValues);
  959. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iCurrentStep);\"><< Back</button>\n");
  960. $oP->add("</form>\n");
  961. }
  962. }
  963. ///////////////////////////////////////////////////////////////////////////////////////////////////
  964. // Main program
  965. ///////////////////////////////////////////////////////////////////////////////////////////////////
  966. clearstatcache(); // Make sure we know what we are doing !
  967. if (file_exists(FINAL_CONFIG_FILE))
  968. {
  969. // The configuration file already exists
  970. if (is_writable(FINAL_CONFIG_FILE))
  971. {
  972. $oP->warning("<b>Warning:</b> a configuration file '".FINAL_CONFIG_FILE."' already exists, and will be overwritten.");
  973. }
  974. else
  975. {
  976. $oP->add("<h1>iTop configuration wizard</h1>\n");
  977. $oP->add("<h2>Fatal error</h2>\n");
  978. $oP->error("<b>Error:</b> the configuration file '".FINAL_CONFIG_FILE."' already exists and cannot be overwritten.");
  979. $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.");
  980. $oP->output();
  981. exit;
  982. }
  983. }
  984. else
  985. {
  986. // No configuration file yet
  987. // Check that the wizard can write into the root dir to create the configuration file
  988. if (!is_writable(dirname(FINAL_CONFIG_FILE)))
  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 directory where to store the configuration file is not writable.");
  993. $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.");
  994. $oP->output();
  995. exit;
  996. }
  997. }
  998. try
  999. {
  1000. $oConfig = new Config(TMP_CONFIG_FILE);
  1001. }
  1002. catch(Exception $e)
  1003. {
  1004. // We'll end here when the tmp config file does not exist. It's normal
  1005. $oConfig = new Config(TMP_CONFIG_FILE, false /* Don't try to load it */);
  1006. }
  1007. try
  1008. {
  1009. $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');
  1010. foreach($aParams as $sName)
  1011. {
  1012. $aParamValues[$sName] = utils::ReadParam($sName, '');
  1013. }
  1014. switch($sOperation)
  1015. {
  1016. case 'step0':
  1017. $oP->no_cache();
  1018. $oP->log("Info - ========= Wizard step 0 ========");
  1019. WelcomeAndCheckPrerequisites($oP, $aParamValues, 0);
  1020. break;
  1021. case 'step1':
  1022. $oP->no_cache();
  1023. $oP->log("Info - ========= Wizard step 1 ========");
  1024. LicenceAcknowledgement($oP, $aParamValues, 1);
  1025. break;
  1026. case 'step2':
  1027. $oP->log("Info - ========= Wizard step 2 ========");
  1028. DatabaseServerSelection($oP, $aParamValues, 2);
  1029. break;
  1030. case 'step3':
  1031. $oP->no_cache();
  1032. $oP->log("Info - ========= Wizard step 3 ========");
  1033. DatabaseInstanceSelection($oP, $aParamValues, 3, $oConfig);
  1034. break;
  1035. case 'step4':
  1036. $oP->no_cache();
  1037. $oP->log("Info - ========= Wizard step 4 ========");
  1038. ModulesSelection($oP, $aParamValues, 4, $oConfig);
  1039. break;
  1040. case 'step5':
  1041. $oP->no_cache();
  1042. $oP->log("Info - ========= Wizard step 5 ========");
  1043. AdminAccountDefinition($oP, $aParamValues, 5, $oConfig);
  1044. break;
  1045. case 'step6':
  1046. $oP->no_cache();
  1047. $oP->log("Info - ========= Wizard step 6 ========");
  1048. SampleDataSelection($oP, $aParamValues, 6, $oConfig);
  1049. break;
  1050. case 'step7':
  1051. $oP->no_cache();
  1052. $oP->log("Info - ========= Wizard step 7 ========");
  1053. SetupFinished($oP, $aParamValues, 7, $oConfig);
  1054. break;
  1055. default:
  1056. $oP->error("Error: unsupported operation '$sOperation'");
  1057. }
  1058. }
  1059. catch(Exception $e)
  1060. {
  1061. $oP->error("Error: '".$e->getMessage()."'");
  1062. $oP->add("<button type=\"button\" onClick=\"window.history.back();\"><< Back</button>\n");
  1063. }
  1064. catch(CoreException $e)
  1065. {
  1066. $oP->error("Error: '".$e->getHtmlDesc()."'");
  1067. $oP->add("<button type=\"button\" onClick=\"window.history.back();\"><< Back</button>\n");
  1068. }
  1069. $oP->output();
  1070. ?>