index.php 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595
  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('../approot.inc.php');
  25. require_once(APPROOT.'/application/utils.inc.php');
  26. require_once(APPROOT.'/core/config.class.inc.php');
  27. require_once(APPROOT.'/core/log.class.inc.php');
  28. require_once(APPROOT.'/core/kpi.class.inc.php');
  29. require_once(APPROOT.'/core/cmdbsource.class.inc.php');
  30. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  31. require_once(APPROOT.'/setup/moduleinstaller.class.inc.php');
  32. define('TMP_CONFIG_FILE', APPROOT.'/tmp-config-itop.php');
  33. define('FINAL_CONFIG_FILE', APPROOT.'/config-itop.php');
  34. define('PHP_MIN_VERSION', '5.2.0');
  35. define('MYSQL_MIN_VERSION', '5.0.0');
  36. define('MIN_MEMORY_LIMIT', 32*1024*1024);
  37. define('SUHOSIN_GET_MAX_VALUE_LENGTH', 2048);
  38. $sOperation = Utils::ReadParam('operation', 'step0');
  39. $oP = new SetupPage('iTop configuration wizard');
  40. ///////////////////////////////////////////////////////////////////////////////////////////////////
  41. // Various helper function
  42. ///////////////////////////////////////////////////////////////////////////////////////////////////
  43. /**
  44. * Get a nicely formatted version string
  45. */
  46. function GetITopVersion($bShort = true)
  47. {
  48. $sVersionString = '';
  49. if ($bShort)
  50. {
  51. $sVersionString = "iTop Version ".ITOP_VERSION;
  52. }
  53. else
  54. {
  55. if (ITOP_REVISION == '$WCREV$')
  56. {
  57. // This is NOT a version built using the buil system, just display the main version
  58. $sVersionString = "iTop Version ".ITOP_VERSION;
  59. }
  60. else
  61. {
  62. // This is a build made from SVN, let display the full information
  63. $sVersionString = "iTop Version ".ITOP_VERSION." revision ".ITOP_REVISION.", built on: ".ITOP_BUILD_DATE;
  64. }
  65. }
  66. return $sVersionString;
  67. }
  68. /**
  69. * Helper function to retrieve the system's temporary directory
  70. * Emulates sys_get_temp_dir if neeed (PHP < 5.2.1)
  71. * @return string Path to the system's temp directory
  72. */
  73. function GetTmpDir()
  74. {
  75. // try to figure out what is the temporary directory
  76. // prior to PHP 5.2.1 the function sys_get_temp_dir
  77. // did not exist
  78. if ( !function_exists('sys_get_temp_dir'))
  79. {
  80. if( $temp=getenv('TMP') ) return realpath($temp);
  81. if( $temp=getenv('TEMP') ) return realpath($temp);
  82. if( $temp=getenv('TMPDIR') ) return realpath($temp);
  83. $temp=tempnam(__FILE__,'');
  84. if (file_exists($temp))
  85. {
  86. unlink($temp);
  87. return realpath(dirname($temp));
  88. }
  89. return null;
  90. }
  91. else
  92. {
  93. return realpath(sys_get_temp_dir());
  94. }
  95. }
  96. /**
  97. * Helper function to retrieve the directory where files are to be uploaded
  98. * @return string Path to the temp directory used for uploading files
  99. */
  100. function GetUploadTmpDir()
  101. {
  102. $sPath = ini_get('upload_tmp_dir');
  103. if (empty($sPath))
  104. {
  105. $sPath = GetTmpDir();
  106. }
  107. return $sPath;
  108. }
  109. /**
  110. * Helper function to check if the current version of PHP
  111. * is compatible with the application
  112. * @return boolean true if this is Ok, false otherwise
  113. */
  114. function CheckPHPVersion(SetupPage $oP)
  115. {
  116. $bResult = true;
  117. $aErrors = array();
  118. $aWarnings = array();
  119. $aOk = array();
  120. $oP->log('Info - CheckPHPVersion');
  121. if (version_compare(phpversion(), PHP_MIN_VERSION, '>='))
  122. {
  123. $aOk [] = "The current PHP Version (".phpversion().") is greater than the minimum required version (".PHP_MIN_VERSION.")";
  124. }
  125. else
  126. {
  127. $aErrors[] = "Error: The current PHP Version (".phpversion().") is lower than the minimum required version (".PHP_MIN_VERSION.")";
  128. $bResult = false;
  129. }
  130. $aMandatoryExtensions = array('mysqli', 'iconv', 'simplexml', 'soap', 'hash', 'json', 'session', 'pcre', 'dom');
  131. $aOptionalExtensions = array('mcrypt' => 'Strong encryption will not be used.',
  132. 'ldap' => 'LDAP authentication will be disabled.');
  133. asort($aMandatoryExtensions); // Sort the list to look clean !
  134. ksort($aOptionalExtensions); // Sort the list to look clean !
  135. $aExtensionsOk = array();
  136. $aMissingExtensions = array();
  137. $aMissingExtensionsLinks = array();
  138. // First check the mandatory extensions
  139. foreach($aMandatoryExtensions as $sExtension)
  140. {
  141. if (extension_loaded($sExtension))
  142. {
  143. $aExtensionsOk[] = $sExtension;
  144. }
  145. else
  146. {
  147. $aMissingExtensions[] = $sExtension;
  148. $aMissingExtensionsLinks[] = "<a href=\"http://www.php.net/manual/en/book.$sExtension.php\" target=\"_blank\">$sExtension</a>";
  149. }
  150. }
  151. if (count($aExtensionsOk) > 0)
  152. {
  153. $aOk[] = "Required PHP extension(s): ".implode(', ', $aExtensionsOk).".";
  154. }
  155. if (count($aMissingExtensions) > 0)
  156. {
  157. $aErrors[] = "Missing PHP extension(s): ".implode(', ', $aMissingExtensionsLinks).".";
  158. $bResult = false;
  159. }
  160. // Next check the optional extensions
  161. $aExtensionsOk = array();
  162. $aMissingExtensions = array();
  163. foreach($aOptionalExtensions as $sExtension => $sMessage)
  164. {
  165. if (extension_loaded($sExtension))
  166. {
  167. $aExtensionsOk[] = $sExtension;
  168. }
  169. else
  170. {
  171. $aMissingExtensions[$sExtension] = $sMessage;
  172. }
  173. }
  174. if (count($aExtensionsOk) > 0)
  175. {
  176. $aOk[] = "Optional PHP extension(s): ".implode(', ', $aExtensionsOk).".";
  177. }
  178. if (count($aMissingExtensions) > 0)
  179. {
  180. foreach($aMissingExtensions as $sExtension => $sMessage)
  181. {
  182. $aWarnings[] = "Missing optional PHP extension: $sExtension. ".$sMessage;
  183. }
  184. }
  185. // Check some ini settings here
  186. if (function_exists('php_ini_loaded_file')) // PHP >= 5.2.4
  187. {
  188. $sPhpIniFile = php_ini_loaded_file();
  189. // Other included/scanned files
  190. if ($sFileList = php_ini_scanned_files())
  191. {
  192. if (strlen($sFileList) > 0)
  193. {
  194. $aFiles = explode(',', $sFileList);
  195. foreach ($aFiles as $sFile)
  196. {
  197. $sPhpIniFile .= ', '.trim($sFile);
  198. }
  199. }
  200. }
  201. $oP->log("Info - php.ini file(s): '$sPhpIniFile'");
  202. }
  203. else
  204. {
  205. $sPhpIniFile = 'php.ini';
  206. }
  207. if (!ini_get('file_uploads'))
  208. {
  209. $aErrors[] = "Files upload is not allowed on this server (file_uploads = ".ini_get('file_uploads').").";
  210. $bResult = false;
  211. }
  212. $sUploadTmpDir = GetUploadTmpDir();
  213. if (empty($sUploadTmpDir))
  214. {
  215. $sUploadTmpDir = '/tmp';
  216. $aErrors[] = "Temporary directory for files upload is not defined (upload_tmp_dir), assuming that $sUploadTmpDir is used.";
  217. }
  218. // check that the upload directory is indeed writable from PHP
  219. if (!empty($sUploadTmpDir))
  220. {
  221. if (!file_exists($sUploadTmpDir))
  222. {
  223. $aErrors[] = "Temporary directory for files upload ($sUploadTmpDir) does not exist or cannot be read by PHP.";
  224. $bResult = false;
  225. }
  226. else if (!is_writable($sUploadTmpDir))
  227. {
  228. $aErrors[] = "Temporary directory for files upload ($sUploadTmpDir) is not writable.";
  229. $bResult = false;
  230. }
  231. else
  232. {
  233. $oP->log("Info - Temporary directory for files upload ($sUploadTmpDir) is writable.");
  234. }
  235. }
  236. if (!ini_get('upload_max_filesize'))
  237. {
  238. $aErrors[] = "File upload is not allowed on this server (upload_max_filesize = ".ini_get('upload_max_filesize').").";
  239. }
  240. $iMaxFileUploads = ini_get('max_file_uploads');
  241. if (!empty($iMaxFileUploads) && ($iMaxFileUploads < 1))
  242. {
  243. $aErrors[] = "File upload is not allowed on this server (max_file_uploads = ".ini_get('max_file_uploads').").";
  244. $bResult = false;
  245. }
  246. $iMaxUploadSize = utils::ConvertToBytes(ini_get('upload_max_filesize'));
  247. $iMaxPostSize = utils::ConvertToBytes(ini_get('post_max_size'));
  248. if ($iMaxPostSize <= $iMaxUploadSize)
  249. {
  250. $aWarnings[] = "post_max_size (".ini_get('post_max_size').") must be bigger than upload_max_filesize (".ini_get('upload_max_filesize')."). You may want to check the PHP configuration file(s): '$sPhpIniFile'. Be aware that this setting can also be overridden in the apache configuration.";
  251. }
  252. $oP->log("Info - upload_max_filesize: ".ini_get('upload_max_filesize'));
  253. $oP->log("Info - post_max_size: ".ini_get('post_max_size'));
  254. $oP->log("Info - max_file_uploads: ".ini_get('max_file_uploads'));
  255. // Check some more ini settings here, needed for file upload
  256. if (function_exists('get_magic_quotes_gpc'))
  257. {
  258. if (@get_magic_quotes_gpc())
  259. {
  260. $aErrors[] = "'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.";
  261. $bResult = false;
  262. }
  263. }
  264. if (function_exists('magic_quotes_runtime'))
  265. {
  266. if (@magic_quotes_runtime())
  267. {
  268. $aErrors[] = "'magic_quotes_runtime' 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.";
  269. $bResult = false;
  270. }
  271. }
  272. $sMemoryLimit = trim(ini_get('memory_limit'));
  273. if (empty($sMemoryLimit))
  274. {
  275. // On some PHP installations, memory_limit does not exist as a PHP setting!
  276. // (encountered on a 5.2.0 under Windows)
  277. // In that case, ini_set will not work, let's keep track of this and proceed anyway
  278. $aWarnings[] = "No memory limit has been defined in this instance of PHP";
  279. }
  280. else
  281. {
  282. // Check that the limit will allow us to load the data
  283. //
  284. $iMemoryLimit = utils::ConvertToBytes($sMemoryLimit);
  285. if ($iMemoryLimit < MIN_MEMORY_LIMIT)
  286. {
  287. $aErrors[] = "memory_limit ($iMemoryLimit) is too small, the minimum value to run iTop is ".MIN_MEMORY_LIMIT.".";
  288. $bResult = false;
  289. }
  290. else
  291. {
  292. $oP->log_info("memory_limit is $iMemoryLimit, ok.");
  293. }
  294. }
  295. // Special case for APC
  296. if (extension_loaded('apc'))
  297. {
  298. $sAPCVersion = phpversion('apc');
  299. $aOk[] = "APC detected (version $sAPCVersion). The APC cache will be used to speed-up iTop.";
  300. }
  301. // Special case Suhosin extension
  302. if (extension_loaded('suhosin'))
  303. {
  304. $sSuhosinVersion = phpversion('suhosin');
  305. $aOk[] = "Suhosin extension detected (version $sSuhosinVersion).";
  306. $iGetMaxValueLength = ini_get('suhosin.get.max_value_length');
  307. if ($iGetMaxValueLength < SUHOSIN_GET_MAX_VALUE_LENGTH)
  308. {
  309. $aErrors[] = "suhosin.get.max_value_length ($iGetMaxValueLength) is too small, the minimum value to run iTop is ".SUHOSIN_GET_MAX_VALUE_LENGTH.". This value is set by the PHP configuration file(s): '$sPhpIniFile'. Be aware that this setting can also be overridden in the apache configuration.";
  310. $bResult = false;
  311. }
  312. else
  313. {
  314. $oP->log_info("suhosin.get.max_value_length = $iGetMaxValueLength, ok.");
  315. }
  316. }
  317. if (!$bResult)
  318. {
  319. $sTitle = 'Checking prerequisites: Failed !';
  320. }
  321. else
  322. {
  323. if (count($aWarnings) > 0)
  324. {
  325. $sTitle = '<img src="../images/messagebox_warning-mid.png" style="vertical-align:middle"> Checking prerequisites: Warning <a href="#" onClick="$(\'#prereq_details\').toggle();">(show details)</a>';
  326. $oP->add_ready_script("$('#prereq_details').hide();\n");
  327. }
  328. else
  329. {
  330. $sTitle = '<img src="../images/clean-mid.png" style="vertical-align:middle"> Checking prerequisites: Ok <a href="#" onClick="$(\'#prereq_details\').toggle();">(show details)</a>';
  331. $oP->add_ready_script("$('#prereq_details').hide();\n");
  332. }
  333. }
  334. $oP->add("<h2>$sTitle</h2>\n");
  335. $oP->add("<div id=\"prereq_details\">\n");
  336. foreach($aErrors as $sError)
  337. {
  338. $oP->error($sError);
  339. //$oP->add_ready_script("$('#prereq_details').show();");
  340. }
  341. foreach($aWarnings as $sWarning)
  342. {
  343. $oP->warning($sWarning);
  344. }
  345. foreach($aOk as $sOk)
  346. {
  347. $oP->ok($sOk);
  348. }
  349. $oP->add("</div>\n");
  350. return $bResult;
  351. }
  352. /**
  353. * Helper function check the connection to the database and (if connected) to enumerate
  354. * the existing databases
  355. * @return Array The list of databases found in the server
  356. */
  357. function CheckServerConnection(SetupPage $oP, $sDBServer, $sDBUser, $sDBPwd)
  358. {
  359. $aResult = array();
  360. $oP->log('Info - CheckServerConnection');
  361. try
  362. {
  363. $oDBSource = new CMDBSource;
  364. $oDBSource->Init($sDBServer, $sDBUser, $sDBPwd);
  365. $oP->ok("Connection to '$sDBServer' as '$sDBUser' successful.");
  366. $oP->log("Info - User privileges: ".($oDBSource->GetRawPrivileges()));
  367. $sDBVersion = $oDBSource->GetDBVersion();
  368. if (version_compare($sDBVersion, MYSQL_MIN_VERSION, '>='))
  369. {
  370. $oP->ok("Current MySQL version ($sDBVersion), greater than minimum required version (".MYSQL_MIN_VERSION.")");
  371. // Check some server variables
  372. $iMaxAllowedPacket = $oDBSource->GetServerVariable('max_allowed_packet');
  373. $iMaxUploadSize = utils::ConvertToBytes(ini_get('upload_max_filesize'));
  374. if ($iMaxAllowedPacket >= (500 + $iMaxUploadSize)) // Allow some space for the query + the file to upload
  375. {
  376. $oP->ok("MySQL server's max_allowed_packet is big enough.");
  377. }
  378. else if($iMaxAllowedPacket < $iMaxUploadSize)
  379. {
  380. $oP->warning("MySQL server's max_allowed_packet ($iMaxAllowedPacket) is not big enough. Please, consider setting it to at least ".(500 + $iMaxUploadSize).".");
  381. }
  382. $oP->log("Info - MySQL max_allowed_packet: $iMaxAllowedPacket");
  383. $iMaxConnections = $oDBSource->GetServerVariable('max_connections');
  384. if ($iMaxConnections < 5)
  385. {
  386. $oP->warning("MySQL server's max_connections ($iMaxConnections) is not enough. Please, consider setting it to at least 5.");
  387. }
  388. $oP->log("Info - MySQL max_connections: ".($oDBSource->GetServerVariable('max_connections')));
  389. }
  390. else
  391. {
  392. $oP->error("Error: Current MySQL version is ($sDBVersion), minimum required version (".MYSQL_MIN_VERSION.")");
  393. return false;
  394. }
  395. try
  396. {
  397. $aResult = $oDBSource->ListDB();
  398. }
  399. catch(Exception $e)
  400. {
  401. $oP->warning("Warning: unable to enumerate the current databases.");
  402. $aResult = true; // Not an array to differentiate with an empty array
  403. }
  404. }
  405. catch(Exception $e)
  406. {
  407. $oP->error("Error: Connection to '$sDBServer' as '$sDBUser' failed.");
  408. $oP->p($e->GetHtmlDesc());
  409. $aResult = false;
  410. }
  411. return $aResult;
  412. }
  413. /**
  414. * Scans the ./data directory for XML files and output them as a Javascript array
  415. */
  416. function PopulateDataFilesList(SetupPage $oP, $aParamValues, $oConfig)
  417. {
  418. $sScript = "function PopulateDataFilesList()\n";
  419. $sScript .= "{\n";
  420. $sScript .= "if (aFilesToLoad.length > 0) return;"; // Populate the list only once...
  421. $aAvailableModules = AnalyzeInstallation($oConfig, $aParamValues['source_dir']);
  422. $sMode = $aParamValues['mode'];
  423. $aStructureDataFiles = array();
  424. $aSampleDataFiles = array();
  425. foreach($aAvailableModules as $sModuleId => $aModule)
  426. {
  427. if (($sModuleId != ROOT_MODULE))
  428. {
  429. if (in_array($sModuleId, $aParamValues['module']))
  430. {
  431. if (empty($aModule['version_db']))
  432. {
  433. // New installation load the data
  434. $aModuleStruct = $aAvailableModules[$sModuleId]['data.struct'];
  435. $aModuleSamples = $aAvailableModules[$sModuleId]['data.sample'];
  436. $aStructureDataFiles = array_merge($aStructureDataFiles, $aModuleStruct);
  437. $aSampleDataFiles = array_merge($aSampleDataFiles, $aModuleSamples);
  438. }
  439. }
  440. }
  441. }
  442. // Structure data
  443. //
  444. foreach($aStructureDataFiles as $sFile)
  445. {
  446. // Under Windows, it is a must to escape backslashes (not an issue until a folder name starts with t or n, etc...)
  447. $sFile = APPROOT.$sFile;
  448. $sFile = str_replace('\\', '\\\\', $sFile);
  449. $sScript .= "aFilesToLoad[aFilesToLoad.length] = '$sFile';\n";
  450. }
  451. // Sample data - loaded IIF wished by the user
  452. //
  453. if ($aParamValues['sample_data'] != 'no')
  454. {
  455. foreach($aSampleDataFiles as $sFile)
  456. {
  457. // Under Windows, it is a must to escape backslashes (not an issue until a folder name starts with t or n, etc...)
  458. $sFile = APPROOT.$sFile;
  459. $sFile = str_replace('\\', '\\\\', $sFile);
  460. $sScript .= "aFilesToLoad[aFilesToLoad.length] = '$sFile';\n";
  461. }
  462. }
  463. $sScript .= "}\n";
  464. $oP->add_script($sScript);
  465. }
  466. /**
  467. * Add some parameters as hidden inputs into a form
  468. * @param SetupPage $oP The page to insert the form elements into
  469. * @param Hash $aParamValues The pairs name/value to be stored in the form
  470. * @param Array $aExcludeParams A list of parameters to exclude from the previous hash
  471. */
  472. function AddParamsToForm(SetupPage $oP, $aParamValues, $aExcludeParams = array())
  473. {
  474. foreach($aParamValues as $sName => $value)
  475. {
  476. if(!in_array($sName, $aExcludeParams))
  477. {
  478. AddHiddenParam($oP, $sName, $value);
  479. }
  480. }
  481. }
  482. /**
  483. * Add a hidden <INPUT> field to store the specified parameter
  484. * @param $sName string Name of the parameter
  485. * @param $value mixed Value of the parameter
  486. */
  487. function AddHiddenParam($oP, $sName, $value)
  488. {
  489. if (is_array($value))
  490. {
  491. foreach($value as $sKey => $sItem)
  492. {
  493. $oP->add('<input type="hidden" name="'.$sName.'['.$sKey.']'.'" value="'.$sItem.'">');
  494. }
  495. }
  496. else
  497. {
  498. $oP->add('<input type="hidden" name="'.$sName.'" value="'.$value.'">');
  499. }
  500. }
  501. /**
  502. * Helper function to get the available languages from the given directory
  503. * @param $sDir Path to the dictionary
  504. * @return an array of language code => description
  505. */
  506. function GetAvailableLanguages($sDir)
  507. {
  508. require_once(APPROOT.'/core/coreexception.class.inc.php');
  509. require_once(APPROOT.'/core/dict.class.inc.php');
  510. $aFiles = scandir($sDir);
  511. foreach($aFiles as $sFile)
  512. {
  513. if ($sFile == '.' || $sFile == '..' || $sFile == '.svn')
  514. {
  515. // Skip
  516. continue;
  517. }
  518. $sFilePath = $sDir.'/'.$sFile;
  519. if (is_file($sFilePath) && preg_match('/^.+\.dict.*\.php$/i', $sFilePath, $aMatches))
  520. {
  521. require_once($sFilePath);
  522. }
  523. }
  524. return Dict::GetLanguages();
  525. }
  526. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  527. // Handling of the different steps of the setup wizard
  528. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  529. /**
  530. * Displays the welcome screen and check some basic prerequisites
  531. */
  532. function WelcomeAndCheckPrerequisites(SetupPage $oP, $aParamValues, $iCurrentStep)
  533. {
  534. $sNextOperation = 'step'.($iCurrentStep+1);
  535. $aParamValues['previous_step'] = 0;
  536. $oP->add("<h1>iTop configuration wizard</h1>\n");
  537. $sVersionStringShort = GetITopVersion(true);
  538. $sVersionStringLong = GetITopVersion(false);
  539. $oP->set_title('Welcome to '.$sVersionStringShort);
  540. $oP->log($sVersionStringLong);
  541. $aPreviousParams = array();
  542. $oP->add("<form id=\"theForm\" method=\"post\" onSubmit=\"return DoSubmit('', 0)\">\n");
  543. $sMode = 'install'; // Fresh install
  544. // Check for a previous version
  545. if (file_exists(FINAL_CONFIG_FILE))
  546. {
  547. $oConfig = new Config(FINAL_CONFIG_FILE);
  548. $aVersion = AnalyzeInstallation($oConfig, $aParamValues['source_dir']);
  549. if (!empty($aVersion[ROOT_MODULE]['version_db']))
  550. {
  551. $aPreviousParams = array('mode', 'db_server', 'db_user', 'db_pwd','db_name', 'new_db_name', 'db_prefix');
  552. $sMode = 'upgrade';
  553. if ($aVersion[ROOT_MODULE]['version_db'] == $aVersion[ROOT_MODULE]['version_code'])
  554. {
  555. $oP->ok("Version ".$aVersion[ROOT_MODULE]['version_db']." of iTop detected.<br/>The <b>same version</b> of the application will be reinstalled.");
  556. }
  557. else
  558. {
  559. $oP->ok("Version ".$aVersion[ROOT_MODULE]['version_db']." of iTop detected.<br/>The application will be upgraded to version ".$aVersion[ROOT_MODULE]['version_code'].".");
  560. }
  561. AddHiddenParam($oP, 'db_server', $oConfig->GetDBHost());
  562. AddHiddenParam($oP, 'db_user', $oConfig->GetDBUser());
  563. AddHiddenParam($oP, 'db_pwd', $oConfig->GetDBPwd());
  564. AddHiddenParam($oP, 'db_name', $oConfig->GetDBName());
  565. AddHiddenParam($oP, 'db_prefix', $oConfig->GetDBSubname());
  566. AddHiddenParam($oP, 'mode', $sMode);
  567. AddHiddenParam($oP, 'source_dir', 'whichsourcedir');
  568. AddHiddenParam($oP, 'target_dir', 'whichtargetdir');
  569. if (CheckPHPVersion($oP))
  570. {
  571. $oP->add("<h2 class=\"next\">Next: Licence agreement</h2>\n");
  572. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  573. AddParamsToForm($oP, $aParamValues, $aPreviousParams);
  574. $oP->add("<table style=\"width:100%\"><tr>\n");
  575. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\" type=\"submit\">Next >></button></td>\n");
  576. $oP->add("</tr></table>\n");
  577. }
  578. return;
  579. }
  580. // else, normal install ??
  581. }
  582. if (CheckPHPVersion($oP))
  583. {
  584. $oP->add("<h2>What do you want to do?</h2>\n");
  585. $sChecked = ($aParamValues['mode'] == 'install') ? 'checked' : '';
  586. $oP->p("<input id=\"choice_install\" type=\"radio\" value=\"install\" $sChecked name=\"mode\"><label for=\"choice_install\">&nbsp;Install a new iTop</label>");
  587. $sChecked = ($aParamValues['mode'] == 'upgrade') ? 'checked' : '';
  588. $oP->p("<input id=\"choice_upgrade\" type=\"radio\" value=\"upgrade\" $sChecked name=\"mode\"><label for=\"choice_upgrade\">&nbsp;Upgrade an existing iTop instance</label>");
  589. $oP->add("<h2 class=\"next\">Next: Licence agreement</h2>\n");
  590. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  591. //AddHiddenParam($oP, 'source_dir', 'datamodel');
  592. AddHiddenParam($oP, 'source_dir', 'modules'); // not ready for the big bang ?
  593. AddHiddenParam($oP, 'target_dir', 'env-production');
  594. $aPreviousParams = array('mode', 'source_dir', 'target_dir');
  595. AddParamsToForm($oP, $aParamValues, $aPreviousParams);
  596. $oP->add("<table style=\"width:100%\"><tr>\n");
  597. $oP->add("<td style=\"text-align:right;\"><button type=\"submit\">Next >></button></td>\n");
  598. $oP->add("</tr></table>\n");
  599. $oP->add("</form>\n");
  600. }
  601. }
  602. function LicenceAcknowledgement($oP, $aParamValues, $iCurrentStep)
  603. {
  604. $sNextOperation = 'step'.($iCurrentStep+1);
  605. $iPrevStep = 0;
  606. $aParamValues['previous_step'] = $iCurrentStep; // Come back here
  607. $oP->set_title('License agreement');
  608. $oP->add('<h2>iTop is released by <a href="http://www.combodo.com" target="_blank">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>');
  609. $oP->add("<iframe style=\"width: 100%; height: 350px; overflow-y:auto; font-size:0.8em;\" src=\"./licence.html\">Next: Database server selection</iframe>\n");
  610. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  611. AddParamsToForm($oP, $aParamValues, array('licence_ok'));
  612. $sChecked = $aParamValues['licence_ok'] == 1 ? 'checked' : '';
  613. $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");
  614. if (file_exists(FINAL_CONFIG_FILE))
  615. {
  616. $oP->add("<h2 class=\"next\">Next: Modules selection</h2>\n");
  617. $sNextOperation = 'step4';
  618. }
  619. else
  620. {
  621. $oP->add("<h2 class=\"next\">Next: Database server selection</h2>\n");
  622. }
  623. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  624. $oP->add("<table style=\"width:100%\"><tr>\n");
  625. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  626. $oP->add("<td style=\"text-align:right;\"><input type=\"submit\" onClick=\"return DoSubmit('', $iCurrentStep)\" value=\" Next >> \"/></td>\n");
  627. $oP->add("</tr></table>\n");
  628. $oP->add("</form>\n");
  629. }
  630. /**
  631. * Display the form for the first step of the configuration wizard
  632. * which consists in the database server selection
  633. */
  634. function DatabaseServerSelection(SetupPage $oP, $aParamValues, $iCurrentStep)
  635. {
  636. $sNextOperation = 'step'.($iCurrentStep+1);
  637. $iPrevStep = 1;
  638. $aParamValues['previous_step'] = $iCurrentStep; // Come back here
  639. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  640. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  641. AddParamsToForm($oP, $aParamValues, array('db_server', 'db_user', 'db_pwd'));
  642. if ($aParamValues['licence_ok'] == 1)
  643. {
  644. $sRedStar = '<span class="hilite">*</span>';
  645. $oP->set_title("Database server selection\n");
  646. $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");
  647. // Form goes here
  648. $oP->add("<fieldset><legend>Database connection</legend>\n");
  649. $aForm = array();
  650. $aForm[] = array('label' => "Server name$sRedStar:", 'input' => "<input id=\"db_server\" type=\"text\" name=\"db_server\" value=\"{$aParamValues['db_server']}\">",
  651. 'help' => 'E.g. "localhost", "dbserver.mycompany.com" or "192.142.10.23"');
  652. $aForm[] = array('label' => "User name$sRedStar:", 'input' => "<input id=\"db_user\" type=\"text\" name=\"db_user\" autocomplete=\"off\" value=\"{$aParamValues['db_user']}\">",
  653. 'help' => 'The account must have the following privileges on the database: SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, CREATE VIEW, TRIGGER');
  654. $aForm[] = array('label' => 'Password:', 'input' => "<input id=\"db_pwd\" type=\"password\" name=\"db_pwd\" autocomplete=\"off\" value=\"{$aParamValues['db_pwd']}\">");
  655. $oP->form($aForm);
  656. $oP->add("</fieldset>\n");
  657. $oP->add("<h2 class=\"next\">Next: Database instance Selection</h2>\n");
  658. $oP->add("<table style=\"width:100%\"><tr>\n");
  659. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  660. $oP->add("<td style=\"text-align:right;\"><input type=\"submit\" onClick=\"return DoSubmit('Connecting to the database...', $iCurrentStep);\" value=\" Next >> \"/></td>\n");
  661. $oP->add("</tr></table>\n");
  662. }
  663. else
  664. {
  665. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iPrevStep);\"><< Back</button>\n");
  666. }
  667. $oP->add("</form>\n");
  668. }
  669. /**
  670. * Display the form for the second step of the configuration wizard
  671. * which consists in
  672. * 1) Validating the parameters by connecting to the database server
  673. * 2) Prompting to select an existing database or to create a new one
  674. */
  675. function DatabaseInstanceSelection(SetupPage $oP, $aParamValues, $iCurrentStep, $oConfig)
  676. {
  677. $sNextOperation = 'step'.($iCurrentStep+1);
  678. $iPrevStep = 2;
  679. $aParamValues['previous_step'] = $iCurrentStep; // Come back here
  680. $oP->set_title("Database instance selection\n");
  681. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  682. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  683. AddParamsToForm($oP, $aParamValues, array('db_name', 'db_prefix', 'new_db_name'));
  684. $sDBServer = $aParamValues['db_server'];
  685. $sDBUser = $aParamValues['db_user'];
  686. $sDBPwd = $aParamValues['db_pwd'];
  687. $aDatabases = CheckServerConnection($oP, $sDBServer, $sDBUser, $sDBPwd);
  688. if ($aDatabases === false)
  689. {
  690. // Connection failed, invalid credentials ? Go back
  691. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iPrevStep);\"><< Back</button>\n");
  692. }
  693. else
  694. {
  695. $oP->add("<fieldset><legend>Select the database instance to use for iTop<span class=\"hilite\">*</span></legend>\n");
  696. $aForm = array();
  697. $bExistingChecked = false;
  698. $sChecked = '';
  699. $sDBName = '';
  700. // If the 'Create Database' option was checked... and the database still does not exist
  701. if (!$bExistingChecked && !empty($aParamValues['new_db_name']))
  702. {
  703. $sChecked = 'checked';
  704. $sDBName = $aParamValues['new_db_name'];
  705. }
  706. if ($aParamValues['mode'] == 'install')
  707. {
  708. $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\"/>");
  709. }
  710. if (is_array($aDatabases))
  711. {
  712. foreach($aDatabases as $sDBName)
  713. {
  714. $sChecked = '';
  715. if ($aParamValues['db_name'] == $sDBName)
  716. {
  717. $sChecked = 'checked';
  718. $bExistingChecked = true;
  719. }
  720. $aForm[] = array('label' => "<input id=\"db_$sDBName\" type=\"radio\" name=\"db_name\" value=\"$sDBName\" $sChecked/><label for=\"db_$sDBName\"> $sDBName</label>");
  721. }
  722. }
  723. else
  724. {
  725. $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\"/>");
  726. $oP->add_ready_script("$('#current_db_name').click( function() { $('#current_db').attr('checked', true); });");
  727. }
  728. $oP->add('<div style="height:250px;overflow-y:auto;padding-left:1em;">');
  729. $oP->form($aForm);
  730. $oP->add('</div>');
  731. $oP->add_ready_script("$('#new_db_name').click( function() { $('#new_db').attr('checked', true); })");
  732. $oP->add("</fieldset>\n");
  733. $aForm = array();
  734. if ($aParamValues['mode'] == 'install')
  735. {
  736. $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\"/>");
  737. }
  738. else
  739. {
  740. $aForm[] = array('label' => "The following prefix is used for the iTop tables: <input id=\"db_prefix\" type=\"text\" name=\"db_prefix\" value=\"{$aParamValues['db_prefix']}\" maxlength=\"32\"/>");
  741. }
  742. $oP->form($aForm);
  743. $oP->add("<h2 class=\"next\">Next: iTop modules selection</h2>\n");
  744. $oP->add("<table style=\"width:100%\"><tr>\n");
  745. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  746. $oP->add("<td style=\"text-align:right;\"><input type=\"submit\" onClick=\"return DoSubmit('', $iCurrentStep);\" value=\" Next >> \"/></td>\n");
  747. $oP->add("</tr></table>\n");
  748. }
  749. $oP->add("</form>\n");
  750. }
  751. /**
  752. * Display the form to select the iTop modules to be installed
  753. */
  754. function ModulesSelection(SetupPage $oP, $aParamValues, $iCurrentStep, $oConfig)
  755. {
  756. $sNextOperation = 'step'.($iCurrentStep+1);
  757. $aParamValues['previous_step'] = $iCurrentStep; // Come back here
  758. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  759. AddParamsToForm($oP, $aParamValues, array('module'));
  760. $sRedStar = '<span class="hilite">*</span>';
  761. $oP->set_title("iTop modules selection");
  762. $aAvailableModules = AnalyzeInstallation($oConfig, $aParamValues['source_dir']);
  763. // Form goes here
  764. if ($aParamValues['mode'] == 'upgrade')
  765. {
  766. if (file_exists(FINAL_CONFIG_FILE))
  767. {
  768. $iPrevStep = 1; // depends on where we came from
  769. }
  770. else
  771. {
  772. $iPrevStep = 3;
  773. }
  774. if (empty($aAvailableModules[ROOT_MODULE]['version_db']))
  775. {
  776. $oP->error("Unable to detect the previous installation of iTop. The upgrade cannot continue.\n");
  777. $oP->add("<table style=\"width:100%\"><tr>\n");
  778. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  779. $oP->add("<td style=\"text-align:right;\">&nbsp;</td>\n");
  780. $oP->add("</tr></table>\n");
  781. $oP->add("</form>\n");
  782. return;
  783. }
  784. $oP->ok("iTop version ".$aAvailableModules[ROOT_MODULE]['version_db']." detected.\n");
  785. $oP->add("<h2>Customize your iTop installation to fit your needs</h2>\n");
  786. $oP->add("<fieldset><legend>Select the iTop modules you want to install or upgrade:</legend>\n");
  787. }
  788. else
  789. {
  790. $iPrevStep = 3; // depends on where we came from
  791. if (!empty($aAvailableModules[ROOT_MODULE]['version_db']))
  792. {
  793. $oP->error("A instance of iTop already exists. Please select the \"Upgrade\" mode to upgrade it.\n");
  794. $oP->add("<table style=\"width:100%\"><tr>\n");
  795. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  796. $oP->add("<td style=\"text-align:right;\">&nbsp;</td>\n");
  797. $oP->add("</tr></table>\n");
  798. $oP->add("</form>\n");
  799. return;
  800. }
  801. $oP->add("<h2>Customize your iTop installation to fit your needs</h2>\n");
  802. $oP->add("<fieldset><legend>Select the iTop modules you want to install:</legend>\n");
  803. }
  804. $oP->add("<div style=\"border: 0;width:100%; height: 250px; overflow-y:auto;\">");
  805. $sRedStar = '<span class="hilite">*</span>';
  806. $index = 0;
  807. $aSelectedModules = $aParamValues['module'];
  808. if ($aSelectedModules == '')
  809. {
  810. // Make sure it gets initialized as an array, default value: all modules selected !
  811. $aSelectedModules = array();
  812. foreach($aAvailableModules as $sModuleId => $aModule)
  813. {
  814. $aSelectedModules[] = $sModuleId;
  815. }
  816. }
  817. foreach($aAvailableModules as $sModuleId => $aModule)
  818. {
  819. if ($sModuleId == ROOT_MODULE) continue; // Convention: the version number of the application is stored as a module named ROOT_MODULE
  820. $sModuleLabel = $aModule['label'];
  821. $sModuleHelp = $aModule['doc.more_information'];
  822. //$sClass = ($aModule['mandatory']) ? 'class="read-only"' : '';
  823. try
  824. {
  825. $sDefaultAppPath = utils::GetDefaultUrlAppRoot();
  826. }
  827. catch(Exception $e)
  828. {
  829. $sDefaultAppPath = '..';
  830. }
  831. $sMoreInfo = (!empty($aModule['doc.more_information'])) ? "<a href=\"$sDefaultAppPath{$aModule['doc.more_information']}\" target=\"_blank\">more info</a>": '';
  832. if ($aModule['category'] == 'authentication')
  833. {
  834. // For now authentication modules are always on and hidden
  835. $oP->add("<input type=\"hidden\" id=\"module[$index]\" name=\"module[$index]\" value=\"$sModuleId\">\n");
  836. $index++;
  837. }
  838. elseif ($aModule['visible'])
  839. {
  840. switch($aModule['install']['flag'])
  841. {
  842. case MODULE_ACTION_OPTIONAL:
  843. $sClass = '';
  844. if ($aParamValues['mode'] == 'upgrade')
  845. {
  846. if (!empty($aParamValues['module']))
  847. {
  848. $sChecked = in_array($sModuleId, $aParamValues['module']) ? 'checked' : '';
  849. }
  850. else
  851. {
  852. $sChecked = '';
  853. // Default value: modules previously installed are checked
  854. if (!empty($aModule['version_db']))
  855. {
  856. $sChecked = 'checked'; // Checked if previously installed
  857. // Previously installed, are we allowed to uninstall this module ?
  858. if ($aModule['install']['flag'] == MODULE_ACTION_IMPOSSIBLE)
  859. {
  860. $sClass = 'class="read-only"';
  861. }
  862. }
  863. }
  864. }
  865. else
  866. {
  867. if (!empty($aParamValues['module']))
  868. {
  869. $sChecked = in_array($sModuleId, $aParamValues['module']) ? 'checked' : '';
  870. }
  871. else
  872. {
  873. $sChecked = 'checked';
  874. }
  875. }
  876. $oP->add("<p><input type=\"checkbox\" $sChecked $sClass id=\"module[$index]\" name=\"module[$index]\" value=\"$sModuleId\"><label $sClass for=\"module[$index]\"> {$aModule['label']}</label> $sMoreInfo</p>\n");
  877. break;
  878. case MODULE_ACTION_MANDATORY:
  879. $oP->add("<p><input type=\"checkbox\" class=\"read-only\" checked id=\"module[$index]\" name=\"module[$index]\" value=\"$sModuleId\"><label class=\"read-only\" for=\"module[$index]\"> {$aModule['label']}</label> $sMoreInfo</p>\n");
  880. break;
  881. case MODULE_ACTION_IMPOSSIBLE:
  882. if ($aParamValues['mode'] == 'upgrade')
  883. {
  884. if (!empty($aModule['version_db']))
  885. {
  886. // Previously installed, are we allowed to uninstall this module ?
  887. if ($aModule['uninstall']['flag'] == MODULE_ACTION_IMPOSSIBLE)
  888. {
  889. $oP->error('Error: impossible to uninstall the module: '.$aModule['label']."({$aModule['uninstall']['message']})");
  890. }
  891. }
  892. }
  893. else
  894. {
  895. $oP->add("<p><input type=\"checkbox\" class=\"read-only\" id=\"module[$index]\" name=\"module[$index]\" value=\"$sModuleId\"><label class=\"read-only\" for=\"module[$index]\"> {$aModule['label']}</label> $sMoreInfo</p>\n");
  896. }
  897. break;
  898. }
  899. $index++;
  900. }
  901. else
  902. {
  903. // For now hidden modules are always on !
  904. $oP->add("<input type=\"hidden\" id=\"module[$index]\" name=\"module[$index]\" value=\"$sModuleId\">\n");
  905. $index++;
  906. }
  907. }
  908. $oP->add("</div>");
  909. $oP->add("</fieldset>\n");
  910. if ($aParamValues['mode'] == 'upgrade')
  911. {
  912. $oP->add("<h2 class=\"next\">Next: Application path</h2>\n");
  913. AddHiddenParam($oP, 'operation', 'step6');
  914. }
  915. else
  916. {
  917. $oP->add("<h2 class=\"next\">Next: Administrator account definition</h2>\n");
  918. AddHiddenParam($oP, 'operation', 'step5');
  919. }
  920. $oP->add("<table style=\"width:100%\"><tr>\n");
  921. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  922. $oP->add("<td style=\"text-align:right;\"><input type=\"submit\" onClick=\"return DoSubmit('', 4)\" value=\" Next >> \"/></td>\n");
  923. $oP->add("</tr></table>\n");
  924. $oP->add("</form>\n");
  925. $oP->add_ready_script("$('.read-only').click( function() { $(this).attr('checked','checked'); } );");
  926. }
  927. /**
  928. * Display the form for the third step of the configuration wizard
  929. * which consists in
  930. * 1) Validating the parameters by connecting to the database server & selecting the database
  931. * 2) Creating the database structure
  932. * 3) Prompting for the admin account to be created
  933. */
  934. function AdminAccountDefinition(SetupPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  935. {
  936. $sNextOperation = 'step'.($iCurrentStep+1);
  937. $aParamValues['previous_step'] = $iCurrentStep; // Come back here
  938. $oP->set_title("Administrator account definition");
  939. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  940. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  941. AddParamsToForm($oP, $aParamValues, array('auth_user', 'auth_pwd', 'language'));
  942. $sRedStar = "<span class=\"hilite\">*</span>";
  943. $oP->add("<h2>Default language for the application:</h2>\n");
  944. // Possible languages (depends on the dictionaries loaded in the config)
  945. $aForm = array();
  946. $aAvailableLanguages = GetAvailableLanguages(APPROOT.'dictionaries');
  947. $sLanguages = '';
  948. $sDefaultCode = $oConfig->GetDefaultLanguage();
  949. foreach($aAvailableLanguages as $sLangCode => $aInfo)
  950. {
  951. $sSelected = ($sLangCode == $sDefaultCode ) ? 'selected' : '';
  952. $sLanguages.="<option $sSelected value=\"{$sLangCode}\">{$aInfo['description']} ({$aInfo['localized_description']})</option>";
  953. }
  954. $aForm[] = array('label' => "Default Language$sRedStar:", 'input' => "<select id=\"language\" name=\"language\">$sLanguages</option>");
  955. $oP->form($aForm);
  956. $oP->add("<h2>Definition of the administrator account</h2>\n");
  957. // Database created, continue with admin creation
  958. $oP->add("<fieldset><legend>Administrator account</legend>\n");
  959. $aForm = array();
  960. $aForm[] = array('label' => "Login$sRedStar:", 'input' => "<input id=\"auth_user\" type=\"text\" name=\"auth_user\" value=\"{$aParamValues['auth_user']}\">");
  961. $aForm[] = array('label' => "Password$sRedStar:", 'input' => "<input id=\"auth_pwd\" type=\"password\" name=\"auth_pwd\" value=\"{$aParamValues['auth_pwd']}\">");
  962. $aForm[] = array('label' => "Retype password$sRedStar:", 'input' => "<input id=\"auth_pwd2\" type=\"password\" name=\"auth_pwd2\" value=\"{$aParamValues['auth_pwd']}\">");
  963. $oP->form($aForm);
  964. $oP->add("</fieldset>\n");
  965. $oP->add("<h2 class=\"next\">Next: Application path</h2>\n");
  966. $oP->add("<table style=\"width:100%\"><tr>\n");
  967. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack(4)\"><< Back</button></td>\n");
  968. $oP->add("<td style=\"text-align:right;\"><input type=\"submit\" onClick=\"return DoSubmit('', 5);\" value=\" Next >> \"/></td>\n");
  969. $oP->add("</tr></table>\n");
  970. // Form goes here
  971. $oP->add("</form>\n");
  972. }
  973. /**
  974. * Display the form for validating/entering the URL (path) to the application
  975. * which consists in
  976. */
  977. function ApplicationPathSelection(SetupPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  978. {
  979. $sNextOperation = 'step7';
  980. if ($aParamValues['mode'] == 'upgrade')
  981. {
  982. $iPrevStep = 4;
  983. }
  984. else
  985. {
  986. $iPrevStep = 5;
  987. }
  988. $oP->set_title("Application Path");
  989. $oP->add("<form id=\"theForm\" method=\"post\"\">\n");
  990. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  991. AddParamsToForm($oP, $aParamValues, array('application_path'));
  992. try
  993. {
  994. $sDefaultAppPath = utils::GetDefaultUrlAppRoot();
  995. }
  996. catch(Exception $e)
  997. {
  998. $sDefaultAppPath = 'http://<your_host>/itop';
  999. }
  1000. $sAppPath = empty($aParamValues['application_path']) ? $sDefaultAppPath : $aParamValues['application_path'];
  1001. $oP->add("<h2>Enter the URL that will be used to connect to the application</h2>\n");
  1002. $oP->p("<fieldset><legend> Application URL </legend>\n");
  1003. $oP->p("<input type=\"text\" id=\"application_path\" size=\"60\" name=\"application_path\" value=\"$sAppPath\">\n");
  1004. $oP->p("</fieldset>\n");
  1005. $oP->add("<h2 class=\"next\">Next: Sample data selection</h2>\n");
  1006. $oP->add("<table style=\"width:100%\"><tr>\n");
  1007. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  1008. $oP->add("<td style=\"text-align:right;\"><input type=\"submit\" onClick=\"return DoSubmit('', 6)\" value=\" Next >> \"/></td>\n");
  1009. $oP->add("</tr></table>\n");
  1010. $oP->add("</form>\n");
  1011. }
  1012. /**
  1013. * Display the form for the fourth step of the configuration wizard
  1014. * which consists in
  1015. * 1) Creating the admin user account
  1016. * 2) Prompting to load some sample data
  1017. */
  1018. function SampleDataSelection(SetupPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  1019. {
  1020. $sNextOperation = 'step8';
  1021. $iPrevStep = 6;
  1022. $oP->set_title("Application initialization");
  1023. $oP->add("<form id=\"theForm\" method=\"post\"\">\n");
  1024. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  1025. AddParamsToForm($oP, $aParamValues, array('sample_data'));
  1026. $oP->add("<h2>Loading of sample data</h2>\n");
  1027. $oP->p("<fieldset><legend> Do you want to load sample data into the database ? </legend>\n");
  1028. $sChecked = ($aParamValues['sample_data'] == 'no') ? '' : 'checked';
  1029. $oP->p("<input type=\"radio\" id=\"sample_data\" name=\"sample_data\" id=\"sample_data_no\" $sChecked value=\"yes\"><label for=\"sample_data_yes\"> Yes, for testing purposes, populate the database with sample data.</label>\n");
  1030. $sChecked = ($aParamValues['sample_data'] == 'no') ? 'checked' : '';
  1031. $oP->p("<input type=\"radio\" name=\"sample_data\" unchecked id=\"sample_data_no\" $sChecked value=\"no\"><label for=\"sample_data_no\"> No, this is a production system, load only the data required by the application.</label>\n");
  1032. $oP->p("</fieldset>\n");
  1033. $oP->add("<h2 class=\"next\">Next: Installation summary</h2>\n");
  1034. $oP->add("<table style=\"width:100%\"><tr>\n");
  1035. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  1036. $oP->add("<td style=\"text-align:right;\"><input type=\"submit\" onClick=\"DoSubmit('', 7)\" value=\" Next >> \"/></td>\n");
  1037. $oP->add("</tr></table>\n");
  1038. $oP->add("</form>\n");
  1039. }
  1040. /**
  1041. * Displays the summary of the actions to be taken
  1042. */
  1043. function DisplaySummary(SetupPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  1044. {
  1045. $sMode = $aParamValues['mode'];
  1046. $aAvailableModules = AnalyzeInstallation($oConfig, $aParamValues['source_dir']);
  1047. $aInstall = array();
  1048. $aUpgrade = array();
  1049. $aUninstall = array();
  1050. $aUnchanged = array();
  1051. switch($sMode)
  1052. {
  1053. case 'install':
  1054. foreach($aAvailableModules as $sModuleId => $aModule)
  1055. {
  1056. if (($sModuleId != ROOT_MODULE) && $aModule['visible'] && ($aModule['category'] != 'authentication'))
  1057. {
  1058. if (in_array($sModuleId, $aParamValues['module']))
  1059. {
  1060. $aInstall[$sModuleId] = $aModule;
  1061. }
  1062. }
  1063. }
  1064. $oP->set_title('Installation Summary');
  1065. $oP->add("<h3>iTop version ".$aAvailableModules[ROOT_MODULE]['version_code']." will be installed.</h3>");
  1066. $oP->add('<div id="summary_content" style="height:350px;overflow-y:auto;border:1px solid #999;padding-left:1em;">');
  1067. // Database information
  1068. $sPrefix = '';
  1069. if ($oConfig->GetDBSubname() != '')
  1070. {
  1071. $sPrefix = " (prefix: ".$oConfig->GetDBSubname().")";
  1072. }
  1073. $oP->collapsible('db', "Database", array($oConfig->GetDBName()." on server: ".$oConfig->GetDBHost().$sPrefix));
  1074. if (count($aInstall) > 0)
  1075. {
  1076. $iCount = count($aInstall);
  1077. $aItems = array();
  1078. foreach($aInstall as $sModuleId => $aModule)
  1079. {
  1080. $aItems[] = $aModule['label'].' version '.$aModule['version_code'];
  1081. }
  1082. $oP->collapsible('install', "$iCount module(s) will be installed", $aItems, ($iCount < 5));
  1083. }
  1084. // Sample data
  1085. if ($aParamValues['sample_data'] != 'no')
  1086. {
  1087. $sSampleData = 'Sample data will be loaded for the newly installed modules.';
  1088. }
  1089. else
  1090. {
  1091. $sSampleData = 'No sample data will be loaded.';
  1092. }
  1093. $oP->collapsible('sample_data', "Sample Data", array($sSampleData));
  1094. // Application Path
  1095. $oP->collapsible('application_path', "Application path", array('URL:'.htmlentities($aParamValues['application_path'], ENT_QUOTES, 'UTF-8')));
  1096. // Admin account
  1097. $oP->collapsible('admin_account', "Administrator account", array('Login:'.htmlentities($aParamValues['auth_user'], ENT_QUOTES, 'UTF-8')));
  1098. // Default language
  1099. $aAvailableLanguages = GetAvailableLanguages(APPROOT.'dictionaries');
  1100. $oP->collapsible('language', "Default application language", array( $aAvailableLanguages[$aParamValues['language']]['description']." (".$aAvailableLanguages[$aParamValues['language']]['localized_description'].")"));
  1101. $oP->add('</div>');
  1102. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  1103. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"step9\">\n");
  1104. AddParamsToForm($oP, $aParamValues);
  1105. $oP->add("<table style=\"width:100%\"><tr>\n");
  1106. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack(7)\"><< Back</button></td>\n");
  1107. // Note: the Next >> button is NOT a submit, since moving to the next page is triggered asynchronously
  1108. $oP->add("<td style=\"text-align:right;\"><button type=\"button\" onClick=\"DoSubmit('Installing...', 8)\"> Install ! </button></td>\n");
  1109. $oP->add("</tr></table>\n");
  1110. $oP->add("</form>\n");
  1111. break;
  1112. case 'upgrade':
  1113. foreach($aAvailableModules as $sModuleId => $aModule)
  1114. {
  1115. if (($sModuleId != ROOT_MODULE) && $aModule['visible'] && ($aModule['category'] != 'authentication'))
  1116. {
  1117. if (in_array($sModuleId, $aParamValues['module']))
  1118. {
  1119. if (empty($aModule['version_db']))
  1120. {
  1121. $aInstall[$sModuleId] = $aModule;
  1122. }
  1123. else if ($aModule['version_db'] == $aModule['version_code'])
  1124. {
  1125. $aUnchanged[$sModuleId] = $aModule;
  1126. }
  1127. else
  1128. {
  1129. // Consider it's an upgrade... TO DO: handle downgrades ??
  1130. $aUpgrade[$sModuleId] = $aModule;
  1131. }
  1132. }
  1133. else if (!empty($aModule['version_db']))
  1134. {
  1135. $aUninstall[$sModuleId] = $aModule;
  1136. }
  1137. // Else do nothing: the module was not installed and is not selected
  1138. }
  1139. }
  1140. $oP->set_title('Upgrade Summary');
  1141. $oP->add("<h3>The application will be upgraded from version ".$aAvailableModules[ROOT_MODULE]['version_db'].' to version '.$aAvailableModules[ROOT_MODULE]['version_code'].'</h3>');
  1142. $oP->add('<div id="summary_content" style="height:350px;overflow-y:auto;border:1px solid #999;padding-left:1em;">');
  1143. // Database information
  1144. $sPrefix = '';
  1145. if ($oConfig->GetDBSubname() != '')
  1146. {
  1147. $sPrefix = " (prefix: ".$oConfig->GetDBSubname().")";
  1148. }
  1149. $oP->collapsible('db', "Database", array($oConfig->GetDBName()." on server: ".$oConfig->GetDBHost().$sPrefix));
  1150. // Modules summary, per "type" (install, uninstall...)
  1151. if (count($aUpgrade) > 0)
  1152. {
  1153. $iCount = count($aUpgrade);
  1154. $aItems = array();
  1155. foreach($aUpgrade as $sModuleId => $aModule)
  1156. {
  1157. $aItems[] = $aModule['label'].' version '.$aModule['version_db'].' to version '.$aModule['version_code'];
  1158. }
  1159. $oP->collapsible('upgrade', "$iCount module(s) will be upgraded", $aItems, ($iCount < 5));
  1160. }
  1161. if (count($aInstall) > 0)
  1162. {
  1163. $iCount = count($aInstall);
  1164. $aItems = array();
  1165. foreach($aInstall as $sModuleId => $aModule)
  1166. {
  1167. $aItems[] = $aModule['label'].' version '.$aModule['version_code'];
  1168. }
  1169. $oP->collapsible('install', "$iCount module(s) will be installed", $aItems, ($iCount < 5));
  1170. }
  1171. if (count($aUninstall) > 0)
  1172. {
  1173. $iCount = count($aUninstall);
  1174. $aItems = array();
  1175. foreach($aUninstall as $sModuleId => $aModule)
  1176. {
  1177. $aItems[] = $aModule['label'].' version '.$aModule['version_db'];
  1178. }
  1179. $oP->collapsible('uninstall', "$iCount module(s) will be removed", $aItems, true /* always open */);
  1180. }
  1181. if (count($aUnchanged) > 0)
  1182. {
  1183. $iCount = count($aUnchanged);
  1184. $aItems = array();
  1185. foreach($aUnchanged as $sModuleId => $aModule)
  1186. {
  1187. $aItems[] = $aModule['label'].' version '.$aModule['version_db'];
  1188. }
  1189. $oP->collapsible('unchanged', "$iCount module(s) will remain unchanged", $aItems, ($iCount < 5));
  1190. }
  1191. // Sample data
  1192. if ($aParamValues['sample_data'] != 'no')
  1193. {
  1194. $sSampleData = 'Sample data will be loaded for the newly installed modules.';
  1195. }
  1196. else
  1197. {
  1198. $sSampleData = 'No sample data will be loaded.';
  1199. }
  1200. $oP->collapsible('sample_data', "Sample Data", array($sSampleData));
  1201. // Application Path
  1202. $oP->collapsible('application_path', "Application path", array('URL:'.htmlentities($aParamValues['application_path'], ENT_QUOTES, 'UTF-8')));
  1203. $oP->add('</div>');
  1204. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  1205. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"step8\">\n");
  1206. AddParamsToForm($oP, $aParamValues);
  1207. $oP->add("<table style=\"width:100%\"><tr>\n");
  1208. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"DoGoBack(6)\"><< Back</button></td>\n");
  1209. // Note: the Next >> button is NOT a submit, since moving to the next page is triggered asynchronously
  1210. $oP->add("<td style=\"text-align:right;\"><button type=\"button\" onClick=\"DoSubmit('', 8)\"> Upgrade ! </button></td>\n");
  1211. $oP->add("</tr></table>\n");
  1212. $oP->add("</form>\n");
  1213. break;
  1214. default:
  1215. $oP->error("Unsupported mode $sMode");
  1216. }
  1217. // Hidden form submitted when moving on to the next page, once all the data files
  1218. // have been processed
  1219. $oP->add("<form id=\"GoToNextStep\" method=\"post\">\n");
  1220. AddParamsToForm($oP, $aParamValues);
  1221. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"step9\">\n");
  1222. $oP->add("</form>\n");
  1223. $oP->add("<div id=\"log\" style=\"color:#F00;\"></div>\n");
  1224. $oP->add_linked_script('./jquery.progression.js');
  1225. PopulateDataFilesList($oP, $aParamValues, $oConfig);
  1226. $oP->add_ready_script(
  1227. <<<EOF
  1228. $('#log').ajaxError(
  1229. function(e, xhr, settings, exception)
  1230. {
  1231. bStopAysncProcess = true;
  1232. alert('Fatal error detected: '+ xhr.responseText);
  1233. $('#log').append(xhr.responseText);
  1234. $('#setup').unblock();
  1235. } );
  1236. EOF
  1237. );
  1238. }
  1239. /** Display the form for the fifth (and final) step of the configuration wizard
  1240. * which consists in
  1241. * 1) Creating the final configuration file
  1242. * 2) Prompting the user to make the file read-only
  1243. */
  1244. function SetupFinished(SetupPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  1245. {
  1246. $sAuthUser = $aParamValues['auth_user'];
  1247. $sAuthPwd = $aParamValues['auth_pwd'];
  1248. $iPrevStep = $aParamValues['previous_step'];
  1249. $aParamValues['previous_step'] = $iCurrentStep; // Come back here
  1250. try
  1251. {
  1252. $sSessionName = $oConfig->Get('session_name');
  1253. if ($sSessionName != '')
  1254. {
  1255. $sSessionName = sprintf('iTop-%x', rand());
  1256. $oConfig->Set('session_name', $sSessionName);
  1257. }
  1258. session_name($sSessionName);
  1259. session_start();
  1260. // Migration: force utf8_unicode_ci as the collation to make the global search
  1261. // NON case sensitive
  1262. $oConfig->SetDBCollation('utf8_unicode_ci');
  1263. // Final config update: add the modules
  1264. UpdateConfigSettings($oConfig, $aParamValues, $aParamValues['target_dir']);
  1265. // Write the final configuration file
  1266. $oConfig->WriteToFile(FINAL_CONFIG_FILE);
  1267. // Start the application
  1268. InitDataModel($oConfig, false, true); // Load model, startup DB and load the cache
  1269. if ($aParamValues['mode'] == 'install')
  1270. {
  1271. if (UserRights::CheckCredentials($sAuthUser, $sAuthPwd))
  1272. {
  1273. UserRights::Login($sAuthUser);
  1274. $_SESSION['auth_user'] = $sAuthUser;
  1275. $_SESSION['login_mode'] = 'form'; // Will enable the "log-off button"
  1276. }
  1277. else
  1278. {
  1279. $oP->add("<h1>iTop configuration wizard</h1>\n");
  1280. $oP->add("<h2>Step 5: Configuration completed</h2>\n");
  1281. @unlink(FINAL_CONFIG_FILE); // remove the aborted config
  1282. $oP->error("Error: Failed to login for user: '$sAuthUser'\n");
  1283. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  1284. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iPrevStep);\"><< Back</button>\n");
  1285. AddParamsToForm($oP, $aParamValues);
  1286. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"step0\">\n");
  1287. $oP->add("</form>\n");
  1288. return;
  1289. }
  1290. }
  1291. // remove the tmp config file
  1292. @unlink(TMP_CONFIG_FILE);
  1293. // try to make the final config file read-only
  1294. @chmod(FINAL_CONFIG_FILE, 0440); // Read-only for owner and group, nothing for others
  1295. $oP->set_title("Setup complete");
  1296. $oP->add("<form id=\"theForm\" method=\"get\" action=\"../index.php\">\n");
  1297. // Check if there are some manual steps required:
  1298. $aAvailableModules = AnalyzeInstallation($oConfig, $aParamValues['target_dir']);
  1299. $aManualSteps = array();
  1300. $sRootUrl = utils::GetAbsoluteUrlAppRoot();
  1301. foreach($aParamValues['module'] as $sModuleId)
  1302. {
  1303. if (!empty($aAvailableModules[$sModuleId]['doc.manual_setup']))
  1304. {
  1305. $aManualSteps[$aAvailableModules[$sModuleId]['label']] = $sRootUrl.$aAvailableModules[$sModuleId]['doc.manual_setup'];
  1306. }
  1307. }
  1308. if (count($aManualSteps) > 0)
  1309. {
  1310. $oP->add("<h2>Manual operations required</h2>");
  1311. $oP->p("In order to complete the installation, the following manual operations are required:");
  1312. foreach($aManualSteps as $sModuleLabel => $sUrl)
  1313. {
  1314. $oP->p("<a href=\"$sUrl\" target=\"_blank\">Manual instructions for $sModuleLabel</a>");
  1315. }
  1316. $oP->add("<h2>Congratulations for installing iTop</h2>");
  1317. }
  1318. else
  1319. {
  1320. $oP->add("<h2>Congratulations for installing iTop</h2>");
  1321. $oP->ok("The initialization completed successfully.");
  1322. }
  1323. // Form goes here.. No back button since the job is done !
  1324. $oP->add('<table style="width:600px;border:0;padding:0;"><tr>');
  1325. $oP->add("<td><a style=\"background:transparent;padding:0;\" title=\"Free: Register your iTop version.\" href=\"http://www.combodo.com/register?product=iTop&version=".urlencode(ITOP_VERSION." revision ".ITOP_REVISION)."\" target=\"_blank\"><img style=\"border:0\" src=\"../images/setup-register.gif\"/></td></a>");
  1326. $oP->add("<td><a style=\"background:transparent;padding:0;\" title=\"Get Professional Support from Combodo\" href=\"http://www.combodo.com/itopsupport\" target=\"_blank\"><img style=\"border:0\" src=\"../images/setup-support.gif\"/></td></a>");
  1327. $oP->add("<td><a style=\"background:transparent;padding:0;\" title=\"Get Professional Training from Combodo\" href=\"http://www.combodo.com/itoptraining\" target=\"_blank\"><img style=\"border:0\" src=\"../images/setup-training.gif\"/></td></a>");
  1328. $oP->add('</tr></table>');
  1329. $oP->add("<p style=\"text-align:center;width:100%\"><button type=\"submit\">Enter iTop</button></p>\n");
  1330. $oP->add("</form>\n");
  1331. }
  1332. catch(Exception $e)
  1333. {
  1334. $oP->error("Error: unable to create the configuration file.");
  1335. $oP->p($e->getHtmlDesc());
  1336. $oP->p("Did you forget to remove the previous (read-only) configuration file ?");
  1337. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  1338. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"step7\">\n");
  1339. AddParamsToForm($oP, $aParamValues, array('previous_step'));
  1340. $oP->add("<button type=\"button\" onClick=\"return DoGoBack(7);\"><< Back</button>\n");
  1341. $oP->add("</form>\n");
  1342. }
  1343. }
  1344. ///////////////////////////////////////////////////////////////////////////////////////////////////
  1345. // Main program
  1346. ///////////////////////////////////////////////////////////////////////////////////////////////////
  1347. clearstatcache(); // Make sure we know what we are doing !
  1348. // Set a long (at least 4 minutes) execution time for the setup to avoid timeouts during this phase
  1349. ini_set('max_execution_time', max(240, ini_get('max_execution_time')));
  1350. // While running the setup it is desirable to see any error that may happen
  1351. ini_set('display_errors', true);
  1352. ini_set('display_startup_errors', true);
  1353. $aParams = array('mode', 'previous_step', 'licence_ok', 'db_server', 'db_user', 'db_pwd','db_name', 'new_db_name', 'db_prefix', 'module', 'sample_data', 'auth_user', 'auth_pwd', 'language', 'application_path', 'source_dir', 'target_dir');
  1354. foreach($aParams as $sName)
  1355. {
  1356. $aParamValues[$sName] = utils::ReadParam($sName, '', false, 'raw_data');
  1357. }
  1358. if (file_exists(FINAL_CONFIG_FILE))
  1359. {
  1360. // The configuration file already exists
  1361. if (!is_writable(FINAL_CONFIG_FILE))
  1362. {
  1363. $oP->add("<h1>iTop configuration wizard</h1>\n");
  1364. $oP->add("<h2>Fatal error</h2>\n");
  1365. $oP->error("<b>Error:</b> the configuration file '".FINAL_CONFIG_FILE."' already exists and cannot be overwritten.");
  1366. $oP->p("The wizard cannot modify the configuration file for you. If you want to upgrade iTop, please make sure that the file '<b>".realpath(FINAL_CONFIG_FILE)."</b>' can be modified by the web server.");
  1367. $oP->output();
  1368. exit;
  1369. }
  1370. }
  1371. else
  1372. {
  1373. // No configuration file yet
  1374. // Check that the wizard can write into the root dir to create the configuration file
  1375. if (!is_writable(dirname(TMP_CONFIG_FILE)))
  1376. {
  1377. $oP->add("<h1>iTop configuration wizard</h1>\n");
  1378. $oP->add("<h2>Fatal error</h2>\n");
  1379. $oP->error("<b>Error:</b> the directory where to store the configuration file is not writable.");
  1380. $oP->p("The wizard cannot create the configuration file for you. Please make sure that the directory '<b>".realpath(dirname(TMP_CONFIG_FILE))."</b>' is writable for the web server.");
  1381. $oP->output();
  1382. exit;
  1383. }
  1384. if (!is_writable(dirname(TMP_CONFIG_FILE).'/setup'))
  1385. {
  1386. $oP->add("<h1>iTop configuration wizard</h1>\n");
  1387. $oP->add("<h2>Fatal error</h2>\n");
  1388. $oP->error("<b>Error:</b> the directory where to store temporary setup files is not writable.");
  1389. $oP->p("The wizard cannot create operate. Please make sure that the directory '<b>".realpath(dirname(TMP_CONFIG_FILE))."/setup</b>' is writable for the web server.");
  1390. $oP->output();
  1391. exit;
  1392. }
  1393. }
  1394. $oConfig = new Config(TMP_CONFIG_FILE, false /* Don't try to load it */);
  1395. UpdateConfigSettings($oConfig, $aParamValues);
  1396. try
  1397. {
  1398. switch($sOperation)
  1399. {
  1400. case 'step0':
  1401. $oP->no_cache();
  1402. $oP->log("Info - ========= Wizard step 0 ========");
  1403. WelcomeAndCheckPrerequisites($oP, $aParamValues, 0);
  1404. break;
  1405. case 'step1':
  1406. $oP->no_cache();
  1407. $oP->log("Info - ========= Wizard step 1 ========");
  1408. LicenceAcknowledgement($oP, $aParamValues, 1);
  1409. break;
  1410. case 'step2':
  1411. $oP->log("Info - ========= Wizard step 2 ========");
  1412. DatabaseServerSelection($oP, $aParamValues, 2);
  1413. break;
  1414. case 'step3':
  1415. $oP->no_cache();
  1416. $oP->log("Info - ========= Wizard step 3 ========");
  1417. DatabaseInstanceSelection($oP, $aParamValues, 3, $oConfig);
  1418. break;
  1419. case 'step4':
  1420. $oP->no_cache();
  1421. $oP->log("Info - ========= Wizard step 4 ========");
  1422. ModulesSelection($oP, $aParamValues, 4, $oConfig);
  1423. break;
  1424. case 'step5':
  1425. $oP->no_cache();
  1426. $oP->log("Info - ========= Wizard step 5 ========");
  1427. AdminAccountDefinition($oP, $aParamValues, 5, $oConfig);
  1428. break;
  1429. case 'step6':
  1430. $oP->no_cache();
  1431. $oP->log("Info - ========= Wizard step 6 ========");
  1432. ApplicationPathSelection($oP, $aParamValues, 6, $oConfig);
  1433. break;
  1434. case 'step7':
  1435. $oP->no_cache();
  1436. $oP->log("Info - ========= Wizard step 7 ========");
  1437. SampleDataSelection($oP, $aParamValues, 6, $oConfig);
  1438. break;
  1439. case 'step8':
  1440. $oP->no_cache();
  1441. $oP->log("Info - ========= Wizard step 8 ========");
  1442. DisplaySummary($oP, $aParamValues, 7, $oConfig);
  1443. break;
  1444. case 'step9':
  1445. $oP->no_cache();
  1446. $oP->log("Info - ========= Wizard step 9 ========");
  1447. SetupFinished($oP, $aParamValues, 8, $oConfig);
  1448. break;
  1449. default:
  1450. $oP->error("Error: unsupported operation '$sOperation'");
  1451. }
  1452. }
  1453. catch(Exception $e)
  1454. {
  1455. $oP->error("Error: '".$e->getMessage()."'");
  1456. $oP->add("<button type=\"button\" onClick=\"window.history.back();\"><< Back</button>\n");
  1457. }
  1458. catch(CoreException $e)
  1459. {
  1460. $oP->error("Error: '".$e->getHtmlDesc()."'");
  1461. $oP->add("<button type=\"button\" onClick=\"window.history.back();\"><< Back</button>\n");
  1462. }
  1463. $oP->output();
  1464. ?>