index.php 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616
  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. $oP->log_info("Target configuration file: ".$sConfigFile);
  544. // Check for a previous version
  545. if (file_exists($sConfigFile))
  546. {
  547. $oConfig = new Config($sConfigFile);
  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-'.utils::GetCurrentEnvironment());
  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=\"../setup/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. $sConfigFile = utils::GetConfigFilePath();
  615. if (file_exists($sConfigFile))
  616. {
  617. $oP->add("<h2 class=\"next\">Next: Modules selection</h2>\n");
  618. $sNextOperation = 'step4';
  619. }
  620. else
  621. {
  622. $oP->add("<h2 class=\"next\">Next: Database server selection</h2>\n");
  623. }
  624. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  625. $oP->add("<table style=\"width:100%\"><tr>\n");
  626. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  627. $oP->add("<td style=\"text-align:right;\"><input type=\"submit\" onClick=\"return DoSubmit('', $iCurrentStep)\" value=\" Next >> \"/></td>\n");
  628. $oP->add("</tr></table>\n");
  629. $oP->add("</form>\n");
  630. }
  631. /**
  632. * Display the form for the first step of the configuration wizard
  633. * which consists in the database server selection
  634. */
  635. function DatabaseServerSelection(SetupPage $oP, $aParamValues, $iCurrentStep)
  636. {
  637. $sNextOperation = 'step'.($iCurrentStep+1);
  638. $iPrevStep = 1;
  639. $aParamValues['previous_step'] = $iCurrentStep; // Come back here
  640. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  641. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  642. AddParamsToForm($oP, $aParamValues, array('db_server', 'db_user', 'db_pwd'));
  643. if ($aParamValues['licence_ok'] == 1)
  644. {
  645. $sRedStar = '<span class="hilite">*</span>';
  646. $oP->set_title("Database server selection\n");
  647. $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");
  648. // Form goes here
  649. $oP->add("<fieldset><legend>Database connection</legend>\n");
  650. $aForm = array();
  651. $aForm[] = array('label' => "Server name$sRedStar:", 'input' => "<input id=\"db_server\" type=\"text\" name=\"db_server\" value=\"{$aParamValues['db_server']}\">",
  652. 'help' => 'E.g. "localhost", "dbserver.mycompany.com" or "192.142.10.23"');
  653. $aForm[] = array('label' => "User name$sRedStar:", 'input' => "<input id=\"db_user\" type=\"text\" name=\"db_user\" autocomplete=\"off\" value=\"{$aParamValues['db_user']}\">",
  654. 'help' => 'The account must have the following privileges on the database: SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, CREATE VIEW, TRIGGER');
  655. $aForm[] = array('label' => 'Password:', 'input' => "<input id=\"db_pwd\" type=\"password\" name=\"db_pwd\" autocomplete=\"off\" value=\"{$aParamValues['db_pwd']}\">");
  656. $oP->form($aForm);
  657. $oP->add("</fieldset>\n");
  658. $oP->add("<h2 class=\"next\">Next: Database instance Selection</h2>\n");
  659. $oP->add("<table style=\"width:100%\"><tr>\n");
  660. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  661. $oP->add("<td style=\"text-align:right;\"><input type=\"submit\" onClick=\"return DoSubmit('Connecting to the database...', $iCurrentStep);\" value=\" Next >> \"/></td>\n");
  662. $oP->add("</tr></table>\n");
  663. }
  664. else
  665. {
  666. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iPrevStep);\"><< Back</button>\n");
  667. }
  668. $oP->add("</form>\n");
  669. }
  670. /**
  671. * Display the form for the second step of the configuration wizard
  672. * which consists in
  673. * 1) Validating the parameters by connecting to the database server
  674. * 2) Prompting to select an existing database or to create a new one
  675. */
  676. function DatabaseInstanceSelection(SetupPage $oP, $aParamValues, $iCurrentStep, $oConfig)
  677. {
  678. $sNextOperation = 'step'.($iCurrentStep+1);
  679. $iPrevStep = 2;
  680. $aParamValues['previous_step'] = $iCurrentStep; // Come back here
  681. $oP->set_title("Database instance selection\n");
  682. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  683. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  684. AddParamsToForm($oP, $aParamValues, array('db_name', 'db_prefix', 'new_db_name'));
  685. $sDBServer = $aParamValues['db_server'];
  686. $sDBUser = $aParamValues['db_user'];
  687. $sDBPwd = $aParamValues['db_pwd'];
  688. $aDatabases = CheckServerConnection($oP, $sDBServer, $sDBUser, $sDBPwd);
  689. if ($aDatabases === false)
  690. {
  691. // Connection failed, invalid credentials ? Go back
  692. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iPrevStep);\"><< Back</button>\n");
  693. }
  694. else
  695. {
  696. $oP->add("<fieldset><legend>Select the database instance to use for iTop<span class=\"hilite\">*</span></legend>\n");
  697. $aForm = array();
  698. $bExistingChecked = false;
  699. $sChecked = '';
  700. $sDBName = '';
  701. // If the 'Create Database' option was checked... and the database still does not exist
  702. if (!$bExistingChecked && !empty($aParamValues['new_db_name']))
  703. {
  704. $sChecked = 'checked';
  705. $sDBName = $aParamValues['new_db_name'];
  706. }
  707. if ($aParamValues['mode'] == 'install')
  708. {
  709. $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\"/>");
  710. }
  711. if (is_array($aDatabases))
  712. {
  713. foreach($aDatabases as $sDBName)
  714. {
  715. $sChecked = '';
  716. if ($aParamValues['db_name'] == $sDBName)
  717. {
  718. $sChecked = 'checked';
  719. $bExistingChecked = true;
  720. }
  721. $aForm[] = array('label' => "<input id=\"db_$sDBName\" type=\"radio\" name=\"db_name\" value=\"$sDBName\" $sChecked/><label for=\"db_$sDBName\"> $sDBName</label>");
  722. }
  723. }
  724. else
  725. {
  726. $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\"/>");
  727. $oP->add_ready_script("$('#current_db_name').click( function() { $('#current_db').attr('checked', true); });");
  728. }
  729. $oP->add('<div style="height:250px;overflow-y:auto;padding-left:1em;">');
  730. $oP->form($aForm);
  731. $oP->add('</div>');
  732. $oP->add_ready_script("$('#new_db_name').click( function() { $('#new_db').attr('checked', true); })");
  733. $oP->add("</fieldset>\n");
  734. $aForm = array();
  735. if ($aParamValues['mode'] == 'install')
  736. {
  737. $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\"/>");
  738. }
  739. else
  740. {
  741. $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\"/>");
  742. }
  743. $oP->form($aForm);
  744. $oP->add("<h2 class=\"next\">Next: iTop modules selection</h2>\n");
  745. $oP->add("<table style=\"width:100%\"><tr>\n");
  746. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  747. $oP->add("<td style=\"text-align:right;\"><input type=\"submit\" onClick=\"return DoSubmit('', $iCurrentStep);\" value=\" Next >> \"/></td>\n");
  748. $oP->add("</tr></table>\n");
  749. }
  750. $oP->add("</form>\n");
  751. }
  752. /**
  753. * Display the form to select the iTop modules to be installed
  754. */
  755. function ModulesSelection(SetupPage $oP, $aParamValues, $iCurrentStep, $oConfig)
  756. {
  757. $sNextOperation = 'step'.($iCurrentStep+1);
  758. $aParamValues['previous_step'] = $iCurrentStep; // Come back here
  759. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  760. AddParamsToForm($oP, $aParamValues, array('module'));
  761. $sRedStar = '<span class="hilite">*</span>';
  762. $oP->set_title("iTop modules selection");
  763. $aAvailableModules = AnalyzeInstallation($oConfig, $aParamValues['source_dir']);
  764. $sConfigFile = utils::GetConfigFilePath();
  765. // Form goes here
  766. if ($aParamValues['mode'] == 'upgrade')
  767. {
  768. if (file_exists($sConfigFile))
  769. {
  770. $iPrevStep = 1; // depends on where we came from
  771. }
  772. else
  773. {
  774. $iPrevStep = 3;
  775. }
  776. if (empty($aAvailableModules[ROOT_MODULE]['version_db']))
  777. {
  778. $oP->error("Unable to detect the previous installation of iTop. The upgrade cannot continue.\n");
  779. $oP->add("<table style=\"width:100%\"><tr>\n");
  780. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  781. $oP->add("<td style=\"text-align:right;\">&nbsp;</td>\n");
  782. $oP->add("</tr></table>\n");
  783. $oP->add("</form>\n");
  784. return;
  785. }
  786. $oP->ok("iTop version ".$aAvailableModules[ROOT_MODULE]['version_db']." detected.\n");
  787. $oP->add("<h2>Customize your iTop installation to fit your needs</h2>\n");
  788. $oP->add("<fieldset><legend>Select the iTop modules you want to install or upgrade:</legend>\n");
  789. }
  790. else
  791. {
  792. $iPrevStep = 3; // depends on where we came from
  793. if (!empty($aAvailableModules[ROOT_MODULE]['version_db']))
  794. {
  795. $oP->error("A instance of iTop already exists. Please select the \"Upgrade\" mode to upgrade it.\n");
  796. $oP->add("<table style=\"width:100%\"><tr>\n");
  797. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  798. $oP->add("<td style=\"text-align:right;\">&nbsp;</td>\n");
  799. $oP->add("</tr></table>\n");
  800. $oP->add("</form>\n");
  801. return;
  802. }
  803. $oP->add("<h2>Customize your iTop installation to fit your needs</h2>\n");
  804. $oP->add("<fieldset><legend>Select the iTop modules you want to install:</legend>\n");
  805. }
  806. $oP->add("<div style=\"border: 0;width:100%; height: 250px; overflow-y:auto;\">");
  807. $sRedStar = '<span class="hilite">*</span>';
  808. $index = 0;
  809. $aSelectedModules = $aParamValues['module'];
  810. if ($aSelectedModules == '')
  811. {
  812. // Make sure it gets initialized as an array, default value: all modules selected !
  813. $aSelectedModules = array();
  814. foreach($aAvailableModules as $sModuleId => $aModule)
  815. {
  816. $aSelectedModules[] = $sModuleId;
  817. }
  818. }
  819. foreach($aAvailableModules as $sModuleId => $aModule)
  820. {
  821. if ($sModuleId == ROOT_MODULE) continue; // Convention: the version number of the application is stored as a module named ROOT_MODULE
  822. $sModuleLabel = $aModule['label'];
  823. $sModuleHelp = $aModule['doc.more_information'];
  824. //$sClass = ($aModule['mandatory']) ? 'class="read-only"' : '';
  825. try
  826. {
  827. $sDefaultAppPath = utils::GetDefaultUrlAppRoot();
  828. }
  829. catch(Exception $e)
  830. {
  831. $sDefaultAppPath = '..';
  832. }
  833. $sMoreInfo = (!empty($aModule['doc.more_information'])) ? "<a href=\"$sDefaultAppPath{$aModule['doc.more_information']}\" target=\"_blank\">more info</a>": '';
  834. if ($aModule['category'] == 'authentication')
  835. {
  836. // For now authentication modules are always on and hidden
  837. $oP->add("<input type=\"hidden\" id=\"module[$index]\" name=\"module[$index]\" value=\"$sModuleId\">\n");
  838. $index++;
  839. }
  840. elseif ($aModule['visible'])
  841. {
  842. switch($aModule['install']['flag'])
  843. {
  844. case MODULE_ACTION_OPTIONAL:
  845. $sClass = '';
  846. if ($aParamValues['mode'] == 'upgrade')
  847. {
  848. if (!empty($aParamValues['module']))
  849. {
  850. $sChecked = in_array($sModuleId, $aParamValues['module']) ? 'checked' : '';
  851. }
  852. else
  853. {
  854. $sChecked = '';
  855. // Default value: modules previously installed are checked
  856. if (!empty($aModule['version_db']))
  857. {
  858. $sChecked = 'checked'; // Checked if previously installed
  859. // Previously installed, are we allowed to uninstall this module ?
  860. if ($aModule['install']['flag'] == MODULE_ACTION_IMPOSSIBLE)
  861. {
  862. $sClass = 'class="read-only"';
  863. }
  864. }
  865. }
  866. }
  867. else
  868. {
  869. if (!empty($aParamValues['module']))
  870. {
  871. $sChecked = in_array($sModuleId, $aParamValues['module']) ? 'checked' : '';
  872. }
  873. else
  874. {
  875. $sChecked = 'checked';
  876. }
  877. }
  878. $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");
  879. break;
  880. case MODULE_ACTION_MANDATORY:
  881. $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");
  882. break;
  883. case MODULE_ACTION_IMPOSSIBLE:
  884. if ($aParamValues['mode'] == 'upgrade')
  885. {
  886. if (!empty($aModule['version_db']))
  887. {
  888. // Previously installed, are we allowed to uninstall this module ?
  889. if ($aModule['uninstall']['flag'] == MODULE_ACTION_IMPOSSIBLE)
  890. {
  891. $oP->error('Error: impossible to uninstall the module: '.$aModule['label']."({$aModule['uninstall']['message']})");
  892. }
  893. }
  894. }
  895. else
  896. {
  897. $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");
  898. }
  899. break;
  900. }
  901. $index++;
  902. }
  903. else
  904. {
  905. // For now hidden modules are always on !
  906. $oP->add("<input type=\"hidden\" id=\"module[$index]\" name=\"module[$index]\" value=\"$sModuleId\">\n");
  907. $index++;
  908. }
  909. }
  910. $oP->add("</div>");
  911. $oP->add("</fieldset>\n");
  912. if ($aParamValues['mode'] == 'upgrade')
  913. {
  914. $oP->add("<h2 class=\"next\">Next: Application path</h2>\n");
  915. AddHiddenParam($oP, 'operation', 'step6');
  916. }
  917. else
  918. {
  919. $oP->add("<h2 class=\"next\">Next: Administrator account definition</h2>\n");
  920. AddHiddenParam($oP, 'operation', 'step5');
  921. }
  922. $oP->add("<table style=\"width:100%\"><tr>\n");
  923. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  924. $oP->add("<td style=\"text-align:right;\"><input type=\"submit\" onClick=\"return DoSubmit('', 4)\" value=\" Next >> \"/></td>\n");
  925. $oP->add("</tr></table>\n");
  926. $oP->add("</form>\n");
  927. $oP->add_ready_script("$('.read-only').click( function() { $(this).attr('checked','checked'); } );");
  928. }
  929. /**
  930. * Display the form for the third step of the configuration wizard
  931. * which consists in
  932. * 1) Validating the parameters by connecting to the database server & selecting the database
  933. * 2) Creating the database structure
  934. * 3) Prompting for the admin account to be created
  935. */
  936. function AdminAccountDefinition(SetupPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  937. {
  938. $sNextOperation = 'step'.($iCurrentStep+1);
  939. $aParamValues['previous_step'] = $iCurrentStep; // Come back here
  940. $oP->set_title("Administrator account definition");
  941. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  942. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  943. AddParamsToForm($oP, $aParamValues, array('auth_user', 'auth_pwd', 'language'));
  944. $sRedStar = "<span class=\"hilite\">*</span>";
  945. $oP->add("<h2>Default language for the application:</h2>\n");
  946. // Possible languages (depends on the dictionaries loaded in the config)
  947. $aForm = array();
  948. $aAvailableLanguages = GetAvailableLanguages(APPROOT.'dictionaries');
  949. $sLanguages = '';
  950. $sDefaultCode = 'EN US';
  951. foreach($aAvailableLanguages as $sLangCode => $aInfo)
  952. {
  953. $sSelected = ($sLangCode == $sDefaultCode ) ? 'selected' : '';
  954. $sLanguages.="<option $sSelected value=\"{$sLangCode}\">{$aInfo['description']} ({$aInfo['localized_description']})</option>";
  955. }
  956. $aForm[] = array('label' => "Default Language$sRedStar:", 'input' => "<select id=\"language\" name=\"language\">$sLanguages</option>");
  957. $oP->form($aForm);
  958. $oP->add("<h2>Definition of the administrator account</h2>\n");
  959. // Database created, continue with admin creation
  960. $oP->add("<fieldset><legend>Administrator account</legend>\n");
  961. $aForm = array();
  962. $aForm[] = array('label' => "Login$sRedStar:", 'input' => "<input id=\"auth_user\" type=\"text\" name=\"auth_user\" value=\"{$aParamValues['auth_user']}\">");
  963. $aForm[] = array('label' => "Password$sRedStar:", 'input' => "<input id=\"auth_pwd\" type=\"password\" name=\"auth_pwd\" value=\"{$aParamValues['auth_pwd']}\">");
  964. $aForm[] = array('label' => "Retype password$sRedStar:", 'input' => "<input id=\"auth_pwd2\" type=\"password\" name=\"auth_pwd2\" value=\"{$aParamValues['auth_pwd']}\">");
  965. $oP->form($aForm);
  966. $oP->add("</fieldset>\n");
  967. $oP->add("<h2 class=\"next\">Next: Application path</h2>\n");
  968. $oP->add("<table style=\"width:100%\"><tr>\n");
  969. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack(4)\"><< Back</button></td>\n");
  970. $oP->add("<td style=\"text-align:right;\"><input type=\"submit\" onClick=\"return DoSubmit('', 5);\" value=\" Next >> \"/></td>\n");
  971. $oP->add("</tr></table>\n");
  972. // Form goes here
  973. $oP->add("</form>\n");
  974. }
  975. /**
  976. * Display the form for validating/entering the URL (path) to the application
  977. * which consists in
  978. */
  979. function ApplicationPathSelection(SetupPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  980. {
  981. $sNextOperation = 'step7';
  982. if ($aParamValues['mode'] == 'upgrade')
  983. {
  984. $iPrevStep = 4;
  985. }
  986. else
  987. {
  988. $iPrevStep = 5;
  989. }
  990. $oP->set_title("Application Path");
  991. $oP->add("<form id=\"theForm\" method=\"post\"\">\n");
  992. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  993. AddParamsToForm($oP, $aParamValues, array('application_path'));
  994. try
  995. {
  996. $sDefaultAppPath = utils::GetDefaultUrlAppRoot();
  997. }
  998. catch(Exception $e)
  999. {
  1000. $sDefaultAppPath = 'http://<your_host>/itop';
  1001. }
  1002. $sAppPath = empty($aParamValues['application_path']) ? $sDefaultAppPath : $aParamValues['application_path'];
  1003. $oP->add("<h2>Enter the URL that will be used to connect to the application</h2>\n");
  1004. $oP->p("<fieldset><legend> Application URL </legend>\n");
  1005. $oP->p("<input type=\"text\" id=\"application_path\" size=\"60\" name=\"application_path\" value=\"$sAppPath\">\n");
  1006. $oP->p("</fieldset>\n");
  1007. $oP->add("<h2 class=\"next\">Next: Sample data selection</h2>\n");
  1008. $oP->add("<table style=\"width:100%\"><tr>\n");
  1009. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  1010. $oP->add("<td style=\"text-align:right;\"><input type=\"submit\" onClick=\"return DoSubmit('', 6)\" value=\" Next >> \"/></td>\n");
  1011. $oP->add("</tr></table>\n");
  1012. $oP->add("</form>\n");
  1013. }
  1014. /**
  1015. * Display the form for the fourth step of the configuration wizard
  1016. * which consists in
  1017. * 1) Creating the admin user account
  1018. * 2) Prompting to load some sample data
  1019. */
  1020. function SampleDataSelection(SetupPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  1021. {
  1022. $sNextOperation = 'step8';
  1023. $iPrevStep = 6;
  1024. $oP->set_title("Application initialization");
  1025. $oP->add("<form id=\"theForm\" method=\"post\"\">\n");
  1026. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
  1027. AddParamsToForm($oP, $aParamValues, array('sample_data'));
  1028. $oP->add("<h2>Loading of sample data</h2>\n");
  1029. $oP->p("<fieldset><legend> Do you want to load sample data into the database ? </legend>\n");
  1030. $sChecked = ($aParamValues['sample_data'] == 'no') ? '' : 'checked';
  1031. $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");
  1032. $sChecked = ($aParamValues['sample_data'] == 'no') ? 'checked' : '';
  1033. $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");
  1034. $oP->p("</fieldset>\n");
  1035. $oP->add("<h2 class=\"next\">Next: Installation summary</h2>\n");
  1036. $oP->add("<table style=\"width:100%\"><tr>\n");
  1037. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack($iPrevStep)\"><< Back</button></td>\n");
  1038. $oP->add("<td style=\"text-align:right;\"><input type=\"submit\" onClick=\"DoSubmit('', 7)\" value=\" Next >> \"/></td>\n");
  1039. $oP->add("</tr></table>\n");
  1040. $oP->add("</form>\n");
  1041. }
  1042. /**
  1043. * Displays the summary of the actions to be taken
  1044. */
  1045. function DisplaySummary(SetupPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  1046. {
  1047. $sMode = $aParamValues['mode'];
  1048. $aAvailableModules = AnalyzeInstallation($oConfig, $aParamValues['source_dir']);
  1049. $aInstall = array();
  1050. $aUpgrade = array();
  1051. $aUninstall = array();
  1052. $aUnchanged = array();
  1053. switch($sMode)
  1054. {
  1055. case 'install':
  1056. foreach($aAvailableModules as $sModuleId => $aModule)
  1057. {
  1058. if (($sModuleId != ROOT_MODULE) && $aModule['visible'] && ($aModule['category'] != 'authentication'))
  1059. {
  1060. if (in_array($sModuleId, $aParamValues['module']))
  1061. {
  1062. $aInstall[$sModuleId] = $aModule;
  1063. }
  1064. }
  1065. }
  1066. $oP->set_title('Installation Summary');
  1067. $oP->SetRootUrl($aParamValues['application_path']);
  1068. $oP->add("<h3>iTop version ".$aAvailableModules[ROOT_MODULE]['version_code']." will be installed.</h3>");
  1069. $oP->add('<div id="summary_content" style="height:350px;overflow-y:auto;border:1px solid #999;padding-left:1em;">');
  1070. // Database information
  1071. $sPrefix = '';
  1072. if ($oConfig->GetDBSubname() != '')
  1073. {
  1074. $sPrefix = " (prefix: ".$oConfig->GetDBSubname().")";
  1075. }
  1076. $oP->collapsible('db', "Database", array($oConfig->GetDBName()." on server: ".$oConfig->GetDBHost().$sPrefix));
  1077. if (count($aInstall) > 0)
  1078. {
  1079. $iCount = count($aInstall);
  1080. $aItems = array();
  1081. foreach($aInstall as $sModuleId => $aModule)
  1082. {
  1083. $aItems[] = $aModule['label'].' version '.$aModule['version_code'];
  1084. }
  1085. $oP->collapsible('install', "$iCount module(s) will be installed", $aItems, ($iCount < 5));
  1086. }
  1087. // Sample data
  1088. if ($aParamValues['sample_data'] != 'no')
  1089. {
  1090. $sSampleData = 'Sample data will be loaded for the newly installed modules.';
  1091. }
  1092. else
  1093. {
  1094. $sSampleData = 'No sample data will be loaded.';
  1095. }
  1096. $oP->collapsible('sample_data', "Sample Data", array($sSampleData));
  1097. // Application Path
  1098. $oP->collapsible('application_path', "Application path", array('URL:'.htmlentities($aParamValues['application_path'], ENT_QUOTES, 'UTF-8')));
  1099. // Admin account
  1100. $oP->collapsible('admin_account', "Administrator account", array('Login:'.htmlentities($aParamValues['auth_user'], ENT_QUOTES, 'UTF-8')));
  1101. // Default language
  1102. $aAvailableLanguages = GetAvailableLanguages(APPROOT.'dictionaries');
  1103. $oP->collapsible('language', "Default application language", array( $aAvailableLanguages[$aParamValues['language']]['description']." (".$aAvailableLanguages[$aParamValues['language']]['localized_description'].")"));
  1104. $oP->add('</div>');
  1105. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  1106. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"step9\">\n");
  1107. AddParamsToForm($oP, $aParamValues);
  1108. $oP->add("<table style=\"width:100%\"><tr>\n");
  1109. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack(7)\"><< Back</button></td>\n");
  1110. // Note: the Next >> button is NOT a submit, since moving to the next page is triggered asynchronously
  1111. $oP->add("<td style=\"text-align:right;\"><button type=\"button\" onClick=\"DoSubmit('Installing...', 8)\"> Install ! </button></td>\n");
  1112. $oP->add("</tr></table>\n");
  1113. $oP->add("</form>\n");
  1114. break;
  1115. case 'upgrade':
  1116. foreach($aAvailableModules as $sModuleId => $aModule)
  1117. {
  1118. if (($sModuleId != ROOT_MODULE) && $aModule['visible'] && ($aModule['category'] != 'authentication'))
  1119. {
  1120. if (in_array($sModuleId, $aParamValues['module']))
  1121. {
  1122. if (empty($aModule['version_db']))
  1123. {
  1124. $aInstall[$sModuleId] = $aModule;
  1125. }
  1126. else if ($aModule['version_db'] == $aModule['version_code'])
  1127. {
  1128. $aUnchanged[$sModuleId] = $aModule;
  1129. }
  1130. else
  1131. {
  1132. // Consider it's an upgrade... TO DO: handle downgrades ??
  1133. $aUpgrade[$sModuleId] = $aModule;
  1134. }
  1135. }
  1136. else if (!empty($aModule['version_db']))
  1137. {
  1138. $aUninstall[$sModuleId] = $aModule;
  1139. }
  1140. // Else do nothing: the module was not installed and is not selected
  1141. }
  1142. }
  1143. $oP->set_title('Upgrade Summary');
  1144. $oP->add("<h3>The application will be upgraded from version ".$aAvailableModules[ROOT_MODULE]['version_db'].' to version '.$aAvailableModules[ROOT_MODULE]['version_code'].'</h3>');
  1145. $oP->add('<div id="summary_content" style="height:350px;overflow-y:auto;border:1px solid #999;padding-left:1em;">');
  1146. // Database information
  1147. $sPrefix = '';
  1148. if ($oConfig->GetDBSubname() != '')
  1149. {
  1150. $sPrefix = " (prefix: ".$oConfig->GetDBSubname().")";
  1151. }
  1152. $oP->collapsible('db', "Database", array($oConfig->GetDBName()." on server: ".$oConfig->GetDBHost().$sPrefix));
  1153. // Modules summary, per "type" (install, uninstall...)
  1154. if (count($aUpgrade) > 0)
  1155. {
  1156. $iCount = count($aUpgrade);
  1157. $aItems = array();
  1158. foreach($aUpgrade as $sModuleId => $aModule)
  1159. {
  1160. $aItems[] = $aModule['label'].' version '.$aModule['version_db'].' to version '.$aModule['version_code'];
  1161. }
  1162. $oP->collapsible('upgrade', "$iCount module(s) will be upgraded", $aItems, ($iCount < 5));
  1163. }
  1164. if (count($aInstall) > 0)
  1165. {
  1166. $iCount = count($aInstall);
  1167. $aItems = array();
  1168. foreach($aInstall as $sModuleId => $aModule)
  1169. {
  1170. $aItems[] = $aModule['label'].' version '.$aModule['version_code'];
  1171. }
  1172. $oP->collapsible('install', "$iCount module(s) will be installed", $aItems, ($iCount < 5));
  1173. }
  1174. if (count($aUninstall) > 0)
  1175. {
  1176. $iCount = count($aUninstall);
  1177. $aItems = array();
  1178. foreach($aUninstall as $sModuleId => $aModule)
  1179. {
  1180. $aItems[] = $aModule['label'].' version '.$aModule['version_db'];
  1181. }
  1182. $oP->collapsible('uninstall', "$iCount module(s) will be removed", $aItems, true /* always open */);
  1183. }
  1184. if (count($aUnchanged) > 0)
  1185. {
  1186. $iCount = count($aUnchanged);
  1187. $aItems = array();
  1188. foreach($aUnchanged as $sModuleId => $aModule)
  1189. {
  1190. $aItems[] = $aModule['label'].' version '.$aModule['version_db'];
  1191. }
  1192. $oP->collapsible('unchanged', "$iCount module(s) will remain unchanged", $aItems, ($iCount < 5));
  1193. }
  1194. // Sample data
  1195. if ($aParamValues['sample_data'] != 'no')
  1196. {
  1197. $sSampleData = 'Sample data will be loaded for the newly installed modules.';
  1198. }
  1199. else
  1200. {
  1201. $sSampleData = 'No sample data will be loaded.';
  1202. }
  1203. $oP->collapsible('sample_data', "Sample Data", array($sSampleData));
  1204. // Application Path
  1205. $oP->collapsible('application_path', "Application path", array('URL:'.htmlentities($aParamValues['application_path'], ENT_QUOTES, 'UTF-8')));
  1206. $oP->add('</div>');
  1207. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  1208. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"step8\">\n");
  1209. AddParamsToForm($oP, $aParamValues);
  1210. $oP->add("<table style=\"width:100%\"><tr>\n");
  1211. $oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"DoGoBack(6)\"><< Back</button></td>\n");
  1212. // Note: the Next >> button is NOT a submit, since moving to the next page is triggered asynchronously
  1213. $oP->add("<td style=\"text-align:right;\"><button type=\"button\" onClick=\"DoSubmit('', 8)\"> Upgrade ! </button></td>\n");
  1214. $oP->add("</tr></table>\n");
  1215. $oP->add("</form>\n");
  1216. break;
  1217. default:
  1218. $oP->error("Unsupported mode $sMode");
  1219. }
  1220. // Hidden form submitted when moving on to the next page, once all the data files
  1221. // have been processed
  1222. $oP->add("<form id=\"GoToNextStep\" method=\"post\">\n");
  1223. AddParamsToForm($oP, $aParamValues);
  1224. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"step9\">\n");
  1225. $oP->add("</form>\n");
  1226. $oP->add("<div id=\"log\" style=\"color:#F00;\"></div>\n");
  1227. $oP->add_linked_script('../setup/jquery.progression.js');
  1228. PopulateDataFilesList($oP, $aParamValues, $oConfig);
  1229. $oP->add_ready_script(
  1230. <<<EOF
  1231. $('#log').ajaxError(
  1232. function(e, xhr, settings, exception)
  1233. {
  1234. bStopAysncProcess = true;
  1235. alert('Fatal error detected: '+ xhr.responseText);
  1236. $('#log').append(xhr.responseText);
  1237. $('#setup').unblock();
  1238. } );
  1239. EOF
  1240. );
  1241. }
  1242. /** Display the form for the fifth (and final) step of the configuration wizard
  1243. * which consists in
  1244. * 1) Creating the final configuration file
  1245. * 2) Prompting the user to make the file read-only
  1246. */
  1247. function SetupFinished(SetupPage $oP, $aParamValues, $iCurrentStep, Config $oConfig)
  1248. {
  1249. $sAuthUser = $aParamValues['auth_user'];
  1250. $sAuthPwd = $aParamValues['auth_pwd'];
  1251. $iPrevStep = $aParamValues['previous_step'];
  1252. $aParamValues['previous_step'] = $iCurrentStep; // Come back here
  1253. try
  1254. {
  1255. session_name('itop-'.md5(APPROOT));
  1256. session_start();
  1257. if (!isset($_SESSION['itop_env']))
  1258. {
  1259. $_SESSION['itop_env'] = ITOP_DEFAULT_ENV;
  1260. }
  1261. // Migration: force utf8_unicode_ci as the collation to make the global search
  1262. // NON case sensitive
  1263. $oConfig->SetDBCollation('utf8_unicode_ci');
  1264. // Final config update: add the modules
  1265. $oConfig->UpdateFromParams($aParamValues, $aParamValues['target_dir']);
  1266. // Make sure the root configuration directory exists
  1267. if (!file_exists(APPCONF))
  1268. {
  1269. mkdir(APPCONF);
  1270. chmod(APPCONF, 0770); // RWX for owner and group, nothing for others
  1271. $oP->log_info("Created configuration directory: ".APPCONF);
  1272. }
  1273. // Write the final configuration file
  1274. $sConfigFile = utils::GetConfigFilePath();
  1275. $sConfigDir = dirname($sConfigFile);
  1276. @mkdir($sConfigDir);
  1277. @chmod($sConfigDir, 0770); // RWX for owner and group, nothing for others
  1278. $oConfig->WriteToFile($sConfigFile);
  1279. // Start the application
  1280. InitDataModel($oConfig, false, true); // Load model, startup DB and load the cache
  1281. if ($aParamValues['mode'] == 'install')
  1282. {
  1283. if (UserRights::CheckCredentials($sAuthUser, $sAuthPwd))
  1284. {
  1285. UserRights::Login($sAuthUser);
  1286. $_SESSION['auth_user'] = $sAuthUser;
  1287. $_SESSION['login_mode'] = 'form'; // Will enable the "log-off button"
  1288. }
  1289. else
  1290. {
  1291. $oP->add("<h1>iTop configuration wizard</h1>\n");
  1292. $oP->add("<h2>Step 5: Configuration completed</h2>\n");
  1293. @unlink($sConfigFile); // remove the aborted config
  1294. $oP->error("Error: Failed to login for user: '$sAuthUser'\n");
  1295. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  1296. $oP->add("<button type=\"button\" onClick=\"return DoGoBack($iPrevStep);\"><< Back</button>\n");
  1297. AddParamsToForm($oP, $aParamValues);
  1298. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"step0\">\n");
  1299. $oP->add("</form>\n");
  1300. return;
  1301. }
  1302. }
  1303. // try to make the final config file read-only
  1304. @chmod($sConfigFile, 0440); // Read-only for owner and group, nothing for others
  1305. $oP->set_title("Setup complete");
  1306. $oP->add("<form id=\"theForm\" method=\"get\" action=\"../index.php\">\n");
  1307. // Check if there are some manual steps required:
  1308. $aAvailableModules = AnalyzeInstallation($oConfig, $aParamValues['target_dir']);
  1309. $aManualSteps = array();
  1310. $sRootUrl = utils::GetAbsoluteUrlAppRoot();
  1311. foreach($aParamValues['module'] as $sModuleId)
  1312. {
  1313. if (!empty($aAvailableModules[$sModuleId]['doc.manual_setup']))
  1314. {
  1315. $aManualSteps[$aAvailableModules[$sModuleId]['label']] = $sRootUrl.$aAvailableModules[$sModuleId]['doc.manual_setup'];
  1316. }
  1317. }
  1318. if (count($aManualSteps) > 0)
  1319. {
  1320. $oP->add("<h2>Manual operations required</h2>");
  1321. $oP->p("In order to complete the installation, the following manual operations are required:");
  1322. foreach($aManualSteps as $sModuleLabel => $sUrl)
  1323. {
  1324. $oP->p("<a href=\"$sUrl\" target=\"_blank\">Manual instructions for $sModuleLabel</a>");
  1325. }
  1326. $oP->add("<h2>Congratulations for installing iTop</h2>");
  1327. }
  1328. else
  1329. {
  1330. $oP->add("<h2>Congratulations for installing iTop</h2>");
  1331. $oP->ok("The initialization completed successfully.");
  1332. }
  1333. // Form goes here.. No back button since the job is done !
  1334. $oP->add('<table style="width:600px;border:0;padding:0;"><tr>');
  1335. $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>");
  1336. $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>");
  1337. $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>");
  1338. $oP->add('</tr></table>');
  1339. $oP->add("<p style=\"text-align:center;width:100%\"><button type=\"submit\">Enter iTop</button></p>\n");
  1340. $oP->add("</form>\n");
  1341. }
  1342. catch(Exception $e)
  1343. {
  1344. $oP->error("Error: unable to create the configuration file.");
  1345. $oP->p($e->getHtmlDesc());
  1346. $oP->p("Did you forget to remove the previous (read-only) configuration file ?");
  1347. $oP->add("<form id=\"theForm\" method=\"post\">\n");
  1348. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"step7\">\n");
  1349. AddParamsToForm($oP, $aParamValues, array('previous_step'));
  1350. $oP->add("<button type=\"button\" onClick=\"return DoGoBack(7);\"><< Back</button>\n");
  1351. $oP->add("</form>\n");
  1352. }
  1353. }
  1354. ///////////////////////////////////////////////////////////////////////////////////////////////////
  1355. // Main program
  1356. ///////////////////////////////////////////////////////////////////////////////////////////////////
  1357. clearstatcache(); // Make sure we know what we are doing !
  1358. // Set a long (at least 4 minutes) execution time for the setup to avoid timeouts during this phase
  1359. ini_set('max_execution_time', max(240, ini_get('max_execution_time')));
  1360. // While running the setup it is desirable to see any error that may happen
  1361. ini_set('display_errors', true);
  1362. ini_set('display_startup_errors', true);
  1363. $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');
  1364. foreach($aParams as $sName)
  1365. {
  1366. $aParamValues[$sName] = utils::ReadParam($sName, '', false, 'raw_data');
  1367. }
  1368. $sConfigFile = utils::GetConfigFilePath();
  1369. if (file_exists($sConfigFile))
  1370. {
  1371. // The configuration file already exists
  1372. if (!is_writable($sConfigFile))
  1373. {
  1374. $oP->add("<h1>iTop configuration wizard</h1>\n");
  1375. $oP->add("<h2>Fatal error</h2>\n");
  1376. $oP->error("<b>Error:</b> the configuration file '".$sConfigFile."' already exists and cannot be overwritten.");
  1377. $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.");
  1378. $oP->output();
  1379. exit;
  1380. }
  1381. }
  1382. else
  1383. {
  1384. // No configuration file yet
  1385. // Check that the wizard can write into the conf dir to create the configuration file
  1386. if (file_exists(APPCONF))
  1387. {
  1388. $sTestedDir = APPCONF;
  1389. }
  1390. else
  1391. {
  1392. $sTestedDir = APPROOT;
  1393. }
  1394. if (!is_writable($sTestedDir))
  1395. {
  1396. $oP->add("<h1>iTop configuration wizard</h1>\n");
  1397. $oP->add("<h2>Fatal error</h2>\n");
  1398. $oP->error("<b>Error:</b> the directory where to store the configuration file is not writable.");
  1399. $oP->p("The wizard cannot create the configuration file for you. Please make sure that the directory '<b>".realpath($sTestedDir)."</b>' is writable for the web server.");
  1400. $oP->output();
  1401. exit;
  1402. }
  1403. if (!is_writable(APPROOT.'setup'))
  1404. {
  1405. $oP->add("<h1>iTop configuration wizard</h1>\n");
  1406. $oP->add("<h2>Fatal error</h2>\n");
  1407. $oP->error("<b>Error:</b> the directory where to store temporary setup files is not writable.");
  1408. $oP->p("The wizard cannot create operate. Please make sure that the directory '<b>".realpath(APPROOT.'setup')."</b>' is writable for the web server.");
  1409. $oP->output();
  1410. exit;
  1411. }
  1412. }
  1413. $oConfig = new Config();
  1414. $oConfig->UpdateFromParams($aParamValues);
  1415. try
  1416. {
  1417. switch($sOperation)
  1418. {
  1419. case 'step0':
  1420. $oP->no_cache();
  1421. $oP->log("Info - ========= Wizard step 0 ========");
  1422. WelcomeAndCheckPrerequisites($oP, $aParamValues, 0);
  1423. break;
  1424. case 'step1':
  1425. $oP->no_cache();
  1426. $oP->log("Info - ========= Wizard step 1 ========");
  1427. LicenceAcknowledgement($oP, $aParamValues, 1);
  1428. break;
  1429. case 'step2':
  1430. $oP->log("Info - ========= Wizard step 2 ========");
  1431. DatabaseServerSelection($oP, $aParamValues, 2);
  1432. break;
  1433. case 'step3':
  1434. $oP->no_cache();
  1435. $oP->log("Info - ========= Wizard step 3 ========");
  1436. DatabaseInstanceSelection($oP, $aParamValues, 3, $oConfig);
  1437. break;
  1438. case 'step4':
  1439. $oP->no_cache();
  1440. $oP->log("Info - ========= Wizard step 4 ========");
  1441. ModulesSelection($oP, $aParamValues, 4, $oConfig);
  1442. break;
  1443. case 'step5':
  1444. $oP->no_cache();
  1445. $oP->log("Info - ========= Wizard step 5 ========");
  1446. AdminAccountDefinition($oP, $aParamValues, 5, $oConfig);
  1447. break;
  1448. case 'step6':
  1449. $oP->no_cache();
  1450. $oP->log("Info - ========= Wizard step 6 ========");
  1451. ApplicationPathSelection($oP, $aParamValues, 6, $oConfig);
  1452. break;
  1453. case 'step7':
  1454. $oP->no_cache();
  1455. $oP->log("Info - ========= Wizard step 7 ========");
  1456. SampleDataSelection($oP, $aParamValues, 6, $oConfig);
  1457. break;
  1458. case 'step8':
  1459. $oP->no_cache();
  1460. $oP->log("Info - ========= Wizard step 8 ========");
  1461. DisplaySummary($oP, $aParamValues, 7, $oConfig);
  1462. break;
  1463. case 'step9':
  1464. $oP->no_cache();
  1465. $oP->log("Info - ========= Wizard step 9 ========");
  1466. SetupFinished($oP, $aParamValues, 8, $oConfig);
  1467. break;
  1468. default:
  1469. $oP->error("Error: unsupported operation '$sOperation'");
  1470. }
  1471. }
  1472. catch(Exception $e)
  1473. {
  1474. $oP->error("Error: '".$e->getMessage()."'");
  1475. $oP->add("<button type=\"button\" onClick=\"window.history.back();\"><< Back</button>\n");
  1476. }
  1477. catch(CoreException $e)
  1478. {
  1479. $oP->error("Error: '".$e->getHtmlDesc()."'");
  1480. $oP->add("<button type=\"button\" onClick=\"window.history.back();\"><< Back</button>\n");
  1481. }
  1482. $oP->output();
  1483. ?>