index.php 58 KB

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