index.php 59 KB

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