index.php 61 KB

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