index.php 58 KB

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