index.php 59 KB

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