index.php 44 KB

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