index.php 59 KB

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