PageRenderTime 70ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/install/install_install.php

https://bitbucket.org/jablonski/yebood
PHP | 2241 lines | 1651 code | 362 blank | 228 comment | 193 complexity | 5db57b8c95e1ac28d41b67ed2112d58a MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. *
  4. * @package install
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. */
  12. if (!defined('IN_INSTALL'))
  13. {
  14. // Someone has tried to access the file direct. This is not a good idea, so exit
  15. exit;
  16. }
  17. if (!empty($setmodules))
  18. {
  19. // If phpBB is already installed we do not include this module
  20. if (@file_exists($phpbb_root_path . 'config.' . $phpEx) && !file_exists($phpbb_root_path . 'cache/install_lock'))
  21. {
  22. include_once($phpbb_root_path . 'config.' . $phpEx);
  23. if (defined('PHPBB_INSTALLED'))
  24. {
  25. return;
  26. }
  27. }
  28. $module[] = array(
  29. 'module_type' => 'install',
  30. 'module_title' => 'INSTALL',
  31. 'module_filename' => substr(basename(__FILE__), 0, -strlen($phpEx)-1),
  32. 'module_order' => 10,
  33. 'module_subs' => '',
  34. 'module_stages' => array('INTRO', 'REQUIREMENTS', 'DATABASE', 'ADMINISTRATOR', 'CONFIG_FILE', 'ADVANCED', 'CREATE_TABLE', 'FINAL'),
  35. 'module_reqs' => ''
  36. );
  37. }
  38. /**
  39. * Installation
  40. * @package install
  41. */
  42. class install_install extends module
  43. {
  44. function install_install(&$p_master)
  45. {
  46. $this->p_master = &$p_master;
  47. }
  48. function main($mode, $sub)
  49. {
  50. global $lang, $template, $language, $phpbb_root_path, $cache;
  51. switch ($sub)
  52. {
  53. case 'intro':
  54. $cache->purge();
  55. $this->page_title = $lang['SUB_INTRO'];
  56. $template->assign_vars(array(
  57. 'TITLE' => $lang['INSTALL_INTRO'],
  58. 'BODY' => $lang['INSTALL_INTRO_BODY'],
  59. 'L_SUBMIT' => $lang['NEXT_STEP'],
  60. 'S_LANG_SELECT' => '<select id="language" name="language">' . $this->p_master->inst_language_select($language) . '</select>',
  61. 'U_ACTION' => $this->p_master->module_url . "?mode=$mode&amp;sub=requirements&amp;language=$language",
  62. ));
  63. break;
  64. case 'requirements':
  65. $this->check_server_requirements($mode, $sub);
  66. break;
  67. case 'database':
  68. $this->obtain_database_settings($mode, $sub);
  69. break;
  70. case 'administrator':
  71. $this->obtain_admin_settings($mode, $sub);
  72. break;
  73. case 'config_file':
  74. $this->create_config_file($mode, $sub);
  75. break;
  76. case 'advanced':
  77. $this->obtain_advanced_settings($mode, $sub);
  78. break;
  79. case 'create_table':
  80. $this->load_schema($mode, $sub);
  81. break;
  82. case 'final':
  83. $this->build_search_index($mode, $sub);
  84. $this->add_modules($mode, $sub);
  85. $this->add_language($mode, $sub);
  86. $this->add_bots($mode, $sub);
  87. $this->email_admin($mode, $sub);
  88. $this->disable_avatars_if_unwritable();
  89. // Remove the lock file
  90. @unlink($phpbb_root_path . 'cache/install_lock');
  91. break;
  92. }
  93. $this->tpl_name = 'install_install';
  94. }
  95. /**
  96. * Checks that the server we are installing on meets the requirements for running phpBB
  97. */
  98. function check_server_requirements($mode, $sub)
  99. {
  100. global $lang, $template, $phpbb_root_path, $phpEx, $language;
  101. $this->page_title = $lang['STAGE_REQUIREMENTS'];
  102. $template->assign_vars(array(
  103. 'TITLE' => $lang['REQUIREMENTS_TITLE'],
  104. 'BODY' => $lang['REQUIREMENTS_EXPLAIN'],
  105. ));
  106. $passed = array('php' => false, 'db' => false, 'files' => false, 'pcre' => false, 'imagesize' => false,);
  107. // Test for basic PHP settings
  108. $template->assign_block_vars('checks', array(
  109. 'S_LEGEND' => true,
  110. 'LEGEND' => $lang['PHP_SETTINGS'],
  111. 'LEGEND_EXPLAIN' => $lang['PHP_SETTINGS_EXPLAIN'],
  112. ));
  113. // Test the minimum PHP version
  114. $php_version = PHP_VERSION;
  115. if (version_compare($php_version, '4.3.3') < 0)
  116. {
  117. $result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
  118. }
  119. else
  120. {
  121. $passed['php'] = true;
  122. // We also give feedback on whether we're running in safe mode
  123. $result = '<strong style="color:green">' . $lang['YES'];
  124. if (@ini_get('safe_mode') == '1' || strtolower(@ini_get('safe_mode')) == 'on')
  125. {
  126. $result .= ', ' . $lang['PHP_SAFE_MODE'];
  127. }
  128. $result .= '</strong>';
  129. }
  130. $template->assign_block_vars('checks', array(
  131. 'TITLE' => $lang['PHP_VERSION_REQD'],
  132. 'RESULT' => $result,
  133. 'S_EXPLAIN' => false,
  134. 'S_LEGEND' => false,
  135. ));
  136. // Don't check for register_globals on 5.4+
  137. if (version_compare($php_version, '5.4.0-dev') < 0)
  138. {
  139. // Check for register_globals being enabled
  140. if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on')
  141. {
  142. $result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
  143. }
  144. else
  145. {
  146. $result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
  147. }
  148. $template->assign_block_vars('checks', array(
  149. 'TITLE' => $lang['PHP_REGISTER_GLOBALS'],
  150. 'TITLE_EXPLAIN' => $lang['PHP_REGISTER_GLOBALS_EXPLAIN'],
  151. 'RESULT' => $result,
  152. 'S_EXPLAIN' => true,
  153. 'S_LEGEND' => false,
  154. ));
  155. }
  156. // Check for url_fopen
  157. if (@ini_get('allow_url_fopen') == '1' || strtolower(@ini_get('allow_url_fopen')) == 'on')
  158. {
  159. $result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
  160. }
  161. else
  162. {
  163. $result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
  164. }
  165. $template->assign_block_vars('checks', array(
  166. 'TITLE' => $lang['PHP_URL_FOPEN_SUPPORT'],
  167. 'TITLE_EXPLAIN' => $lang['PHP_URL_FOPEN_SUPPORT_EXPLAIN'],
  168. 'RESULT' => $result,
  169. 'S_EXPLAIN' => true,
  170. 'S_LEGEND' => false,
  171. ));
  172. // Check for getimagesize
  173. if (@function_exists('getimagesize'))
  174. {
  175. $passed['imagesize'] = true;
  176. $result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
  177. }
  178. else
  179. {
  180. $result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
  181. }
  182. $template->assign_block_vars('checks', array(
  183. 'TITLE' => $lang['PHP_GETIMAGESIZE_SUPPORT'],
  184. 'TITLE_EXPLAIN' => $lang['PHP_GETIMAGESIZE_SUPPORT_EXPLAIN'],
  185. 'RESULT' => $result,
  186. 'S_EXPLAIN' => true,
  187. 'S_LEGEND' => false,
  188. ));
  189. // Check for PCRE UTF-8 support
  190. if (@preg_match('//u', ''))
  191. {
  192. $passed['pcre'] = true;
  193. $result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
  194. }
  195. else
  196. {
  197. $result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
  198. }
  199. $template->assign_block_vars('checks', array(
  200. 'TITLE' => $lang['PCRE_UTF_SUPPORT'],
  201. 'TITLE_EXPLAIN' => $lang['PCRE_UTF_SUPPORT_EXPLAIN'],
  202. 'RESULT' => $result,
  203. 'S_EXPLAIN' => true,
  204. 'S_LEGEND' => false,
  205. ));
  206. /**
  207. * Better not enabling and adding to the loaded extensions due to the specific requirements needed
  208. if (!@extension_loaded('mbstring'))
  209. {
  210. can_load_dll('mbstring');
  211. }
  212. */
  213. $passed['mbstring'] = true;
  214. if (@extension_loaded('mbstring'))
  215. {
  216. // Test for available database modules
  217. $template->assign_block_vars('checks', array(
  218. 'S_LEGEND' => true,
  219. 'LEGEND' => $lang['MBSTRING_CHECK'],
  220. 'LEGEND_EXPLAIN' => $lang['MBSTRING_CHECK_EXPLAIN'],
  221. ));
  222. $checks = array(
  223. array('func_overload', '&', MB_OVERLOAD_MAIL|MB_OVERLOAD_STRING),
  224. array('encoding_translation', '!=', 0),
  225. array('http_input', '!=', 'pass'),
  226. array('http_output', '!=', 'pass')
  227. );
  228. foreach ($checks as $mb_checks)
  229. {
  230. $ini_val = @ini_get('mbstring.' . $mb_checks[0]);
  231. switch ($mb_checks[1])
  232. {
  233. case '&':
  234. if (intval($ini_val) & $mb_checks[2])
  235. {
  236. $result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
  237. $passed['mbstring'] = false;
  238. }
  239. else
  240. {
  241. $result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
  242. }
  243. break;
  244. case '!=':
  245. if ($ini_val != $mb_checks[2])
  246. {
  247. $result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
  248. $passed['mbstring'] = false;
  249. }
  250. else
  251. {
  252. $result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
  253. }
  254. break;
  255. }
  256. $template->assign_block_vars('checks', array(
  257. 'TITLE' => $lang['MBSTRING_' . strtoupper($mb_checks[0])],
  258. 'TITLE_EXPLAIN' => $lang['MBSTRING_' . strtoupper($mb_checks[0]) . '_EXPLAIN'],
  259. 'RESULT' => $result,
  260. 'S_EXPLAIN' => true,
  261. 'S_LEGEND' => false,
  262. ));
  263. }
  264. }
  265. // Test for available database modules
  266. $template->assign_block_vars('checks', array(
  267. 'S_LEGEND' => true,
  268. 'LEGEND' => $lang['PHP_SUPPORTED_DB'],
  269. 'LEGEND_EXPLAIN' => $lang['PHP_SUPPORTED_DB_EXPLAIN'],
  270. ));
  271. $available_dbms = get_available_dbms(false, true);
  272. $passed['db'] = $available_dbms['ANY_DB_SUPPORT'];
  273. unset($available_dbms['ANY_DB_SUPPORT']);
  274. foreach ($available_dbms as $db_name => $db_ary)
  275. {
  276. if (!$db_ary['AVAILABLE'])
  277. {
  278. $template->assign_block_vars('checks', array(
  279. 'TITLE' => $lang['DLL_' . strtoupper($db_name)],
  280. 'RESULT' => '<span style="color:red">' . $lang['UNAVAILABLE'] . '</span>',
  281. 'S_EXPLAIN' => false,
  282. 'S_LEGEND' => false,
  283. ));
  284. }
  285. else
  286. {
  287. $template->assign_block_vars('checks', array(
  288. 'TITLE' => $lang['DLL_' . strtoupper($db_name)],
  289. 'RESULT' => '<strong style="color:green">' . $lang['AVAILABLE'] . '</strong>',
  290. 'S_EXPLAIN' => false,
  291. 'S_LEGEND' => false,
  292. ));
  293. }
  294. }
  295. // Test for other modules
  296. $template->assign_block_vars('checks', array(
  297. 'S_LEGEND' => true,
  298. 'LEGEND' => $lang['PHP_OPTIONAL_MODULE'],
  299. 'LEGEND_EXPLAIN' => $lang['PHP_OPTIONAL_MODULE_EXPLAIN'],
  300. ));
  301. foreach ($this->php_dlls_other as $dll)
  302. {
  303. if (!@extension_loaded($dll))
  304. {
  305. if (!can_load_dll($dll))
  306. {
  307. $template->assign_block_vars('checks', array(
  308. 'TITLE' => $lang['DLL_' . strtoupper($dll)],
  309. 'RESULT' => '<strong style="color:red">' . $lang['UNAVAILABLE'] . '</strong>',
  310. 'S_EXPLAIN' => false,
  311. 'S_LEGEND' => false,
  312. ));
  313. continue;
  314. }
  315. }
  316. $template->assign_block_vars('checks', array(
  317. 'TITLE' => $lang['DLL_' . strtoupper($dll)],
  318. 'RESULT' => '<strong style="color:green">' . $lang['AVAILABLE'] . '</strong>',
  319. 'S_EXPLAIN' => false,
  320. 'S_LEGEND' => false,
  321. ));
  322. }
  323. // Can we find Imagemagick anywhere on the system?
  324. $exe = (DIRECTORY_SEPARATOR == '\\') ? '.exe' : '';
  325. $magic_home = getenv('MAGICK_HOME');
  326. $img_imagick = '';
  327. if (empty($magic_home))
  328. {
  329. $locations = array('C:/WINDOWS/', 'C:/WINNT/', 'C:/WINDOWS/SYSTEM/', 'C:/WINNT/SYSTEM/', 'C:/WINDOWS/SYSTEM32/', 'C:/WINNT/SYSTEM32/', '/usr/bin/', '/usr/sbin/', '/usr/local/bin/', '/usr/local/sbin/', '/opt/', '/usr/imagemagick/', '/usr/bin/imagemagick/');
  330. $path_locations = str_replace('\\', '/', (explode(($exe) ? ';' : ':', getenv('PATH'))));
  331. $locations = array_merge($path_locations, $locations);
  332. foreach ($locations as $location)
  333. {
  334. // The path might not end properly, fudge it
  335. if (substr($location, -1, 1) !== '/')
  336. {
  337. $location .= '/';
  338. }
  339. if (@file_exists($location) && @is_readable($location . 'mogrify' . $exe) && @filesize($location . 'mogrify' . $exe) > 3000)
  340. {
  341. $img_imagick = str_replace('\\', '/', $location);
  342. continue;
  343. }
  344. }
  345. }
  346. else
  347. {
  348. $img_imagick = str_replace('\\', '/', $magic_home);
  349. }
  350. $template->assign_block_vars('checks', array(
  351. 'TITLE' => $lang['APP_MAGICK'],
  352. 'RESULT' => ($img_imagick) ? '<strong style="color:green">' . $lang['AVAILABLE'] . ', ' . $img_imagick . '</strong>' : '<strong style="color:blue">' . $lang['NO_LOCATION'] . '</strong>',
  353. 'S_EXPLAIN' => false,
  354. 'S_LEGEND' => false,
  355. ));
  356. // Check permissions on files/directories we need access to
  357. $template->assign_block_vars('checks', array(
  358. 'S_LEGEND' => true,
  359. 'LEGEND' => $lang['FILES_REQUIRED'],
  360. 'LEGEND_EXPLAIN' => $lang['FILES_REQUIRED_EXPLAIN'],
  361. ));
  362. $directories = array('cache/', 'files/', 'store/');
  363. umask(0);
  364. $passed['files'] = true;
  365. foreach ($directories as $dir)
  366. {
  367. $exists = $write = false;
  368. // Try to create the directory if it does not exist
  369. if (!file_exists($phpbb_root_path . $dir))
  370. {
  371. @mkdir($phpbb_root_path . $dir, 0777);
  372. phpbb_chmod($phpbb_root_path . $dir, CHMOD_READ | CHMOD_WRITE);
  373. }
  374. // Now really check
  375. if (file_exists($phpbb_root_path . $dir) && is_dir($phpbb_root_path . $dir))
  376. {
  377. phpbb_chmod($phpbb_root_path . $dir, CHMOD_READ | CHMOD_WRITE);
  378. $exists = true;
  379. }
  380. // Now check if it is writable by storing a simple file
  381. $fp = @fopen($phpbb_root_path . $dir . 'test_lock', 'wb');
  382. if ($fp !== false)
  383. {
  384. $write = true;
  385. }
  386. @fclose($fp);
  387. @unlink($phpbb_root_path . $dir . 'test_lock');
  388. $passed['files'] = ($exists && $write && $passed['files']) ? true : false;
  389. $exists = ($exists) ? '<strong style="color:green">' . $lang['FOUND'] . '</strong>' : '<strong style="color:red">' . $lang['NOT_FOUND'] . '</strong>';
  390. $write = ($write) ? ', <strong style="color:green">' . $lang['WRITABLE'] . '</strong>' : (($exists) ? ', <strong style="color:red">' . $lang['UNWRITABLE'] . '</strong>' : '');
  391. $template->assign_block_vars('checks', array(
  392. 'TITLE' => $dir,
  393. 'RESULT' => $exists . $write,
  394. 'S_EXPLAIN' => false,
  395. 'S_LEGEND' => false,
  396. ));
  397. }
  398. // Check permissions on files/directories it would be useful access to
  399. $template->assign_block_vars('checks', array(
  400. 'S_LEGEND' => true,
  401. 'LEGEND' => $lang['FILES_OPTIONAL'],
  402. 'LEGEND_EXPLAIN' => $lang['FILES_OPTIONAL_EXPLAIN'],
  403. ));
  404. $directories = array('config.' . $phpEx, 'images/avatars/upload/');
  405. foreach ($directories as $dir)
  406. {
  407. $write = $exists = true;
  408. if (file_exists($phpbb_root_path . $dir))
  409. {
  410. if (!phpbb_is_writable($phpbb_root_path . $dir))
  411. {
  412. $write = false;
  413. }
  414. }
  415. else
  416. {
  417. $write = $exists = false;
  418. }
  419. $exists_str = ($exists) ? '<strong style="color:green">' . $lang['FOUND'] . '</strong>' : '<strong style="color:red">' . $lang['NOT_FOUND'] . '</strong>';
  420. $write_str = ($write) ? ', <strong style="color:green">' . $lang['WRITABLE'] . '</strong>' : (($exists) ? ', <strong style="color:red">' . $lang['UNWRITABLE'] . '</strong>' : '');
  421. $template->assign_block_vars('checks', array(
  422. 'TITLE' => $dir,
  423. 'RESULT' => $exists_str . $write_str,
  424. 'S_EXPLAIN' => false,
  425. 'S_LEGEND' => false,
  426. ));
  427. }
  428. // And finally where do we want to go next (well today is taken isn't it :P)
  429. $s_hidden_fields = ($img_imagick) ? '<input type="hidden" name="img_imagick" value="' . addslashes($img_imagick) . '" />' : '';
  430. $url = (!in_array(false, $passed)) ? $this->p_master->module_url . "?mode=$mode&amp;sub=database&amp;language=$language" : $this->p_master->module_url . "?mode=$mode&amp;sub=requirements&amp;language=$language ";
  431. $submit = (!in_array(false, $passed)) ? $lang['INSTALL_START'] : $lang['INSTALL_TEST'];
  432. $template->assign_vars(array(
  433. 'L_SUBMIT' => $submit,
  434. 'S_HIDDEN' => $s_hidden_fields,
  435. 'U_ACTION' => $url,
  436. ));
  437. }
  438. /**
  439. * Obtain the information required to connect to the database
  440. */
  441. function obtain_database_settings($mode, $sub)
  442. {
  443. global $lang, $template, $phpEx;
  444. $this->page_title = $lang['STAGE_DATABASE'];
  445. // Obtain any submitted data
  446. $data = $this->get_submitted_data();
  447. $connect_test = false;
  448. $error = array();
  449. $available_dbms = get_available_dbms(false, true);
  450. // Has the user opted to test the connection?
  451. if (isset($_POST['testdb']))
  452. {
  453. if (!isset($available_dbms[$data['dbms']]) || !$available_dbms[$data['dbms']]['AVAILABLE'])
  454. {
  455. $error[] = $lang['INST_ERR_NO_DB'];
  456. $connect_test = false;
  457. }
  458. else if (!preg_match(get_preg_expression('table_prefix'), $data['table_prefix']))
  459. {
  460. $error[] = $lang['INST_ERR_DB_INVALID_PREFIX'];
  461. $connect_test = false;
  462. }
  463. else
  464. {
  465. $connect_test = connect_check_db(true, $error, $available_dbms[$data['dbms']], $data['table_prefix'], $data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport']);
  466. }
  467. $template->assign_block_vars('checks', array(
  468. 'S_LEGEND' => true,
  469. 'LEGEND' => $lang['DB_CONNECTION'],
  470. 'LEGEND_EXPLAIN' => false,
  471. ));
  472. if ($connect_test)
  473. {
  474. $template->assign_block_vars('checks', array(
  475. 'TITLE' => $lang['DB_TEST'],
  476. 'RESULT' => '<strong style="color:green">' . $lang['SUCCESSFUL_CONNECT'] . '</strong>',
  477. 'S_EXPLAIN' => false,
  478. 'S_LEGEND' => false,
  479. ));
  480. }
  481. else
  482. {
  483. $template->assign_block_vars('checks', array(
  484. 'TITLE' => $lang['DB_TEST'],
  485. 'RESULT' => '<strong style="color:red">' . implode('<br />', $error) . '</strong>',
  486. 'S_EXPLAIN' => false,
  487. 'S_LEGEND' => false,
  488. ));
  489. }
  490. }
  491. if (!$connect_test)
  492. {
  493. // Update the list of available DBMS modules to only contain those which can be used
  494. $available_dbms_temp = array();
  495. foreach ($available_dbms as $type => $dbms_ary)
  496. {
  497. if (!$dbms_ary['AVAILABLE'])
  498. {
  499. continue;
  500. }
  501. $available_dbms_temp[$type] = $dbms_ary;
  502. }
  503. $available_dbms = &$available_dbms_temp;
  504. // And now for the main part of this page
  505. $data['table_prefix'] = (!empty($data['table_prefix']) ? $data['table_prefix'] : 'phpbb_');
  506. foreach ($this->db_config_options as $config_key => $vars)
  507. {
  508. if (!is_array($vars) && strpos($config_key, 'legend') === false)
  509. {
  510. continue;
  511. }
  512. if (strpos($config_key, 'legend') !== false)
  513. {
  514. $template->assign_block_vars('options', array(
  515. 'S_LEGEND' => true,
  516. 'LEGEND' => $lang[$vars])
  517. );
  518. continue;
  519. }
  520. $options = isset($vars['options']) ? $vars['options'] : '';
  521. $template->assign_block_vars('options', array(
  522. 'KEY' => $config_key,
  523. 'TITLE' => $lang[$vars['lang']],
  524. 'S_EXPLAIN' => $vars['explain'],
  525. 'S_LEGEND' => false,
  526. 'TITLE_EXPLAIN' => ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '',
  527. 'CONTENT' => $this->p_master->input_field($config_key, $vars['type'], $data[$config_key], $options),
  528. )
  529. );
  530. }
  531. }
  532. // And finally where do we want to go next (well today is taken isn't it :P)
  533. $s_hidden_fields = ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : '';
  534. $s_hidden_fields .= '<input type="hidden" name="language" value="' . $data['language'] . '" />';
  535. if ($connect_test)
  536. {
  537. foreach ($this->db_config_options as $config_key => $vars)
  538. {
  539. if (!is_array($vars))
  540. {
  541. continue;
  542. }
  543. $s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
  544. }
  545. }
  546. $url = ($connect_test) ? $this->p_master->module_url . "?mode=$mode&amp;sub=administrator" : $this->p_master->module_url . "?mode=$mode&amp;sub=database";
  547. $s_hidden_fields .= ($connect_test) ? '' : '<input type="hidden" name="testdb" value="true" />';
  548. $submit = $lang['NEXT_STEP'];
  549. $template->assign_vars(array(
  550. 'L_SUBMIT' => $submit,
  551. 'S_HIDDEN' => $s_hidden_fields,
  552. 'U_ACTION' => $url,
  553. ));
  554. }
  555. /**
  556. * Obtain the administrator's name, password and email address
  557. */
  558. function obtain_admin_settings($mode, $sub)
  559. {
  560. global $lang, $template, $phpEx;
  561. $this->page_title = $lang['STAGE_ADMINISTRATOR'];
  562. // Obtain any submitted data
  563. $data = $this->get_submitted_data();
  564. if ($data['dbms'] == '')
  565. {
  566. // Someone's been silly and tried calling this page direct
  567. // So we send them back to the start to do it again properly
  568. $this->p_master->redirect("index.$phpEx?mode=install");
  569. }
  570. $s_hidden_fields = ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : '';
  571. $passed = false;
  572. $data['default_lang'] = ($data['default_lang'] !== '') ? $data['default_lang'] : $data['language'];
  573. if (isset($_POST['check']))
  574. {
  575. $error = array();
  576. // Check the entered email address and password
  577. if ($data['admin_name'] == '' || $data['admin_pass1'] == '' || $data['admin_pass2'] == '' || $data['board_email1'] == '' || $data['board_email2'] == '')
  578. {
  579. $error[] = $lang['INST_ERR_MISSING_DATA'];
  580. }
  581. if ($data['admin_pass1'] != $data['admin_pass2'] && $data['admin_pass1'] != '')
  582. {
  583. $error[] = $lang['INST_ERR_PASSWORD_MISMATCH'];
  584. }
  585. // Test against the default username rules
  586. if ($data['admin_name'] != '' && utf8_strlen($data['admin_name']) < 3)
  587. {
  588. $error[] = $lang['INST_ERR_USER_TOO_SHORT'];
  589. }
  590. if ($data['admin_name'] != '' && utf8_strlen($data['admin_name']) > 20)
  591. {
  592. $error[] = $lang['INST_ERR_USER_TOO_LONG'];
  593. }
  594. // Test against the default password rules
  595. if ($data['admin_pass1'] != '' && utf8_strlen($data['admin_pass1']) < 6)
  596. {
  597. $error[] = $lang['INST_ERR_PASSWORD_TOO_SHORT'];
  598. }
  599. if ($data['admin_pass1'] != '' && utf8_strlen($data['admin_pass1']) > 30)
  600. {
  601. $error[] = $lang['INST_ERR_PASSWORD_TOO_LONG'];
  602. }
  603. if ($data['board_email1'] != $data['board_email2'] && $data['board_email1'] != '')
  604. {
  605. $error[] = $lang['INST_ERR_EMAIL_MISMATCH'];
  606. }
  607. if ($data['board_email1'] != '' && !preg_match('/^' . get_preg_expression('email') . '$/i', $data['board_email1']))
  608. {
  609. $error[] = $lang['INST_ERR_EMAIL_INVALID'];
  610. }
  611. $template->assign_block_vars('checks', array(
  612. 'S_LEGEND' => true,
  613. 'LEGEND' => $lang['STAGE_ADMINISTRATOR'],
  614. 'LEGEND_EXPLAIN' => false,
  615. ));
  616. if (!sizeof($error))
  617. {
  618. $passed = true;
  619. $template->assign_block_vars('checks', array(
  620. 'TITLE' => $lang['ADMIN_TEST'],
  621. 'RESULT' => '<strong style="color:green">' . $lang['TESTS_PASSED'] . '</strong>',
  622. 'S_EXPLAIN' => false,
  623. 'S_LEGEND' => false,
  624. ));
  625. }
  626. else
  627. {
  628. $template->assign_block_vars('checks', array(
  629. 'TITLE' => $lang['ADMIN_TEST'],
  630. 'RESULT' => '<strong style="color:red">' . implode('<br />', $error) . '</strong>',
  631. 'S_EXPLAIN' => false,
  632. 'S_LEGEND' => false,
  633. ));
  634. }
  635. }
  636. if (!$passed)
  637. {
  638. foreach ($this->admin_config_options as $config_key => $vars)
  639. {
  640. if (!is_array($vars) && strpos($config_key, 'legend') === false)
  641. {
  642. continue;
  643. }
  644. if (strpos($config_key, 'legend') !== false)
  645. {
  646. $template->assign_block_vars('options', array(
  647. 'S_LEGEND' => true,
  648. 'LEGEND' => $lang[$vars])
  649. );
  650. continue;
  651. }
  652. $options = isset($vars['options']) ? $vars['options'] : '';
  653. $template->assign_block_vars('options', array(
  654. 'KEY' => $config_key,
  655. 'TITLE' => $lang[$vars['lang']],
  656. 'S_EXPLAIN' => $vars['explain'],
  657. 'S_LEGEND' => false,
  658. 'TITLE_EXPLAIN' => ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '',
  659. 'CONTENT' => $this->p_master->input_field($config_key, $vars['type'], $data[$config_key], $options),
  660. )
  661. );
  662. }
  663. }
  664. else
  665. {
  666. foreach ($this->admin_config_options as $config_key => $vars)
  667. {
  668. if (!is_array($vars))
  669. {
  670. continue;
  671. }
  672. $s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
  673. }
  674. }
  675. $s_hidden_fields .= ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : '';
  676. $s_hidden_fields .= '<input type="hidden" name="language" value="' . $data['language'] . '" />';
  677. foreach ($this->db_config_options as $config_key => $vars)
  678. {
  679. if (!is_array($vars))
  680. {
  681. continue;
  682. }
  683. $s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
  684. }
  685. $submit = $lang['NEXT_STEP'];
  686. $url = ($passed) ? $this->p_master->module_url . "?mode=$mode&amp;sub=config_file" : $this->p_master->module_url . "?mode=$mode&amp;sub=administrator";
  687. $s_hidden_fields .= ($passed) ? '' : '<input type="hidden" name="check" value="true" />';
  688. $template->assign_vars(array(
  689. 'L_SUBMIT' => $submit,
  690. 'S_HIDDEN' => $s_hidden_fields,
  691. 'U_ACTION' => $url,
  692. ));
  693. }
  694. /**
  695. * Writes the config file to disk, or if unable to do so offers alternative methods
  696. */
  697. function create_config_file($mode, $sub)
  698. {
  699. global $lang, $template, $phpbb_root_path, $phpEx;
  700. $this->page_title = $lang['STAGE_CONFIG_FILE'];
  701. // Obtain any submitted data
  702. $data = $this->get_submitted_data();
  703. if ($data['dbms'] == '')
  704. {
  705. // Someone's been silly and tried calling this page direct
  706. // So we send them back to the start to do it again properly
  707. $this->p_master->redirect("index.$phpEx?mode=install");
  708. }
  709. $s_hidden_fields = ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : '';
  710. $s_hidden_fields .= '<input type="hidden" name="language" value="' . $data['language'] . '" />';
  711. $written = false;
  712. // Create a list of any PHP modules we wish to have loaded
  713. $load_extensions = array();
  714. $available_dbms = get_available_dbms($data['dbms']);
  715. $check_exts = array_merge(array($available_dbms[$data['dbms']]['MODULE']), $this->php_dlls_other);
  716. foreach ($check_exts as $dll)
  717. {
  718. if (!@extension_loaded($dll))
  719. {
  720. if (!can_load_dll($dll))
  721. {
  722. continue;
  723. }
  724. $load_extensions[] = $dll . '.' . PHP_SHLIB_SUFFIX;
  725. }
  726. }
  727. // Create a lock file to indicate that there is an install in progress
  728. $fp = @fopen($phpbb_root_path . 'cache/install_lock', 'wb');
  729. if ($fp === false)
  730. {
  731. // We were unable to create the lock file - abort
  732. $this->p_master->error($lang['UNABLE_WRITE_LOCK'], __LINE__, __FILE__);
  733. }
  734. @fclose($fp);
  735. @chmod($phpbb_root_path . 'cache/install_lock', 0777);
  736. // Time to convert the data provided into a config file
  737. $config_data = phpbb_create_config_file_data($data, $available_dbms[$data['dbms']]['DRIVER'], $load_extensions);
  738. // Attempt to write out the config file directly. If it works, this is the easiest way to do it ...
  739. if ((file_exists($phpbb_root_path . 'config.' . $phpEx) && phpbb_is_writable($phpbb_root_path . 'config.' . $phpEx)) || phpbb_is_writable($phpbb_root_path))
  740. {
  741. // Assume it will work ... if nothing goes wrong below
  742. $written = true;
  743. if (!($fp = @fopen($phpbb_root_path . 'config.' . $phpEx, 'w')))
  744. {
  745. // Something went wrong ... so let's try another method
  746. $written = false;
  747. }
  748. if (!(@fwrite($fp, $config_data)))
  749. {
  750. // Something went wrong ... so let's try another method
  751. $written = false;
  752. }
  753. @fclose($fp);
  754. if ($written)
  755. {
  756. // We may revert back to chmod() if we see problems with users not able to change their config.php file directly
  757. phpbb_chmod($phpbb_root_path . 'config.' . $phpEx, CHMOD_READ);
  758. }
  759. }
  760. if (isset($_POST['dldone']))
  761. {
  762. // Do a basic check to make sure that the file has been uploaded
  763. // Note that all we check is that the file has _something_ in it
  764. // We don't compare the contents exactly - if they can't upload
  765. // a single file correctly, it's likely they will have other problems....
  766. if (filesize($phpbb_root_path . 'config.' . $phpEx) > 10)
  767. {
  768. $written = true;
  769. }
  770. }
  771. $config_options = array_merge($this->db_config_options, $this->admin_config_options);
  772. foreach ($config_options as $config_key => $vars)
  773. {
  774. if (!is_array($vars))
  775. {
  776. continue;
  777. }
  778. $s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
  779. }
  780. if (!$written)
  781. {
  782. // OK, so it didn't work let's try the alternatives
  783. if (isset($_POST['dlconfig']))
  784. {
  785. // They want a copy of the file to download, so send the relevant headers and dump out the data
  786. header("Content-Type: text/x-delimtext; name=\"config.$phpEx\"");
  787. header("Content-disposition: attachment; filename=config.$phpEx");
  788. echo $config_data;
  789. exit;
  790. }
  791. // The option to download the config file is always available, so output it here
  792. $template->assign_vars(array(
  793. 'BODY' => $lang['CONFIG_FILE_UNABLE_WRITE'],
  794. 'L_DL_CONFIG' => $lang['DL_CONFIG'],
  795. 'L_DL_CONFIG_EXPLAIN' => $lang['DL_CONFIG_EXPLAIN'],
  796. 'L_DL_DONE' => $lang['DONE'],
  797. 'L_DL_DOWNLOAD' => $lang['DL_DOWNLOAD'],
  798. 'S_HIDDEN' => $s_hidden_fields,
  799. 'S_SHOW_DOWNLOAD' => true,
  800. 'U_ACTION' => $this->p_master->module_url . "?mode=$mode&amp;sub=config_file",
  801. ));
  802. return;
  803. }
  804. else
  805. {
  806. $template->assign_vars(array(
  807. 'BODY' => $lang['CONFIG_FILE_WRITTEN'],
  808. 'L_SUBMIT' => $lang['NEXT_STEP'],
  809. 'S_HIDDEN' => $s_hidden_fields,
  810. 'U_ACTION' => $this->p_master->module_url . "?mode=$mode&amp;sub=advanced",
  811. ));
  812. return;
  813. }
  814. }
  815. /**
  816. * Provide an opportunity to customise some advanced settings during the install
  817. * in case it is necessary for them to be set to access later
  818. */
  819. function obtain_advanced_settings($mode, $sub)
  820. {
  821. global $lang, $template, $phpEx;
  822. $this->page_title = $lang['STAGE_ADVANCED'];
  823. // Obtain any submitted data
  824. $data = $this->get_submitted_data();
  825. if ($data['dbms'] == '')
  826. {
  827. // Someone's been silly and tried calling this page direct
  828. // So we send them back to the start to do it again properly
  829. $this->p_master->redirect("index.$phpEx?mode=install");
  830. }
  831. $s_hidden_fields = ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : '';
  832. $s_hidden_fields .= '<input type="hidden" name="language" value="' . $data['language'] . '" />';
  833. // HTTP_HOST is having the correct browser url in most cases...
  834. $server_name = (!empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
  835. // HTTP HOST can carry a port number...
  836. if (strpos($server_name, ':') !== false)
  837. {
  838. $server_name = substr($server_name, 0, strpos($server_name, ':'));
  839. }
  840. $data['email_enable'] = ($data['email_enable'] !== '') ? $data['email_enable'] : true;
  841. $data['server_name'] = ($data['server_name'] !== '') ? $data['server_name'] : $server_name;
  842. $data['server_port'] = ($data['server_port'] !== '') ? $data['server_port'] : ((!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT'));
  843. $data['server_protocol'] = ($data['server_protocol'] !== '') ? $data['server_protocol'] : ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://');
  844. $data['cookie_secure'] = ($data['cookie_secure'] !== '') ? $data['cookie_secure'] : ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? true : false);
  845. if ($data['script_path'] === '')
  846. {
  847. $name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
  848. if (!$name)
  849. {
  850. $name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
  851. }
  852. // Replace backslashes and doubled slashes (could happen on some proxy setups)
  853. $name = str_replace(array('\\', '//', '/install'), '/', $name);
  854. $data['script_path'] = trim(dirname($name));
  855. }
  856. foreach ($this->advanced_config_options as $config_key => $vars)
  857. {
  858. if (!is_array($vars) && strpos($config_key, 'legend') === false)
  859. {
  860. continue;
  861. }
  862. if (strpos($config_key, 'legend') !== false)
  863. {
  864. $template->assign_block_vars('options', array(
  865. 'S_LEGEND' => true,
  866. 'LEGEND' => $lang[$vars])
  867. );
  868. continue;
  869. }
  870. $options = isset($vars['options']) ? $vars['options'] : '';
  871. $template->assign_block_vars('options', array(
  872. 'KEY' => $config_key,
  873. 'TITLE' => $lang[$vars['lang']],
  874. 'S_EXPLAIN' => $vars['explain'],
  875. 'S_LEGEND' => false,
  876. 'TITLE_EXPLAIN' => ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '',
  877. 'CONTENT' => $this->p_master->input_field($config_key, $vars['type'], $data[$config_key], $options),
  878. )
  879. );
  880. }
  881. $config_options = array_merge($this->db_config_options, $this->admin_config_options);
  882. foreach ($config_options as $config_key => $vars)
  883. {
  884. if (!is_array($vars))
  885. {
  886. continue;
  887. }
  888. $s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
  889. }
  890. $submit = $lang['NEXT_STEP'];
  891. $url = $this->p_master->module_url . "?mode=$mode&amp;sub=create_table";
  892. $template->assign_vars(array(
  893. 'BODY' => $lang['STAGE_ADVANCED_EXPLAIN'],
  894. 'L_SUBMIT' => $submit,
  895. 'S_HIDDEN' => $s_hidden_fields,
  896. 'U_ACTION' => $url,
  897. ));
  898. }
  899. /**
  900. * Load the contents of the schema into the database and then alter it based on what has been input during the installation
  901. */
  902. function load_schema($mode, $sub)
  903. {
  904. global $db, $lang, $template, $phpbb_root_path, $phpEx;
  905. $this->page_title = $lang['STAGE_CREATE_TABLE'];
  906. $s_hidden_fields = '';
  907. // Obtain any submitted data
  908. $data = $this->get_submitted_data();
  909. if ($data['dbms'] == '')
  910. {
  911. // Someone's been silly and tried calling this page direct
  912. // So we send them back to the start to do it again properly
  913. $this->p_master->redirect("index.$phpEx?mode=install");
  914. }
  915. // HTTP_HOST is having the correct browser url in most cases...
  916. $server_name = (!empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
  917. $referer = (!empty($_SERVER['HTTP_REFERER'])) ? strtolower($_SERVER['HTTP_REFERER']) : getenv('HTTP_REFERER');
  918. // HTTP HOST can carry a port number...
  919. if (strpos($server_name, ':') !== false)
  920. {
  921. $server_name = substr($server_name, 0, strpos($server_name, ':'));
  922. }
  923. $cookie_domain = ($data['server_name'] != '') ? $data['server_name'] : $server_name;
  924. // Try to come up with the best solution for cookie domain...
  925. if (strpos($cookie_domain, 'www.') === 0)
  926. {
  927. $cookie_domain = str_replace('www.', '.', $cookie_domain);
  928. }
  929. // If we get here and the extension isn't loaded it should be safe to just go ahead and load it
  930. $available_dbms = get_available_dbms($data['dbms']);
  931. if (!isset($available_dbms[$data['dbms']]))
  932. {
  933. // Someone's been silly and tried providing a non-existant dbms
  934. $this->p_master->redirect("index.$phpEx?mode=install");
  935. }
  936. $dbms = $available_dbms[$data['dbms']]['DRIVER'];
  937. // Load the appropriate database class if not already loaded
  938. include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
  939. // Instantiate the database
  940. $db = new $sql_db();
  941. $db->sql_connect($data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport'], false, false);
  942. // NOTE: trigger_error does not work here.
  943. $db->sql_return_on_error(true);
  944. // If mysql is chosen, we need to adjust the schema filename slightly to reflect the correct version. ;)
  945. if ($data['dbms'] == 'mysql')
  946. {
  947. if (version_compare($db->sql_server_info(true), '4.1.3', '>='))
  948. {
  949. $available_dbms[$data['dbms']]['SCHEMA'] .= '_41';
  950. }
  951. else
  952. {
  953. $available_dbms[$data['dbms']]['SCHEMA'] .= '_40';
  954. }
  955. }
  956. // Ok we have the db info go ahead and read in the relevant schema
  957. // and work on building the table
  958. $dbms_schema = 'schemas/' . $available_dbms[$data['dbms']]['SCHEMA'] . '_schema.sql';
  959. // How should we treat this schema?
  960. $delimiter = $available_dbms[$data['dbms']]['DELIM'];
  961. $sql_query = @file_get_contents($dbms_schema);
  962. $sql_query = preg_replace('#phpbb_#i', $data['table_prefix'], $sql_query);
  963. $sql_query = phpbb_remove_comments($sql_query);
  964. $sql_query = split_sql_file($sql_query, $delimiter);
  965. foreach ($sql_query as $sql)
  966. {
  967. //$sql = trim(str_replace('|', ';', $sql));
  968. if (!$db->sql_query($sql))
  969. {
  970. $error = $db->sql_error();
  971. $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__);
  972. }
  973. }
  974. unset($sql_query);
  975. // Ok tables have been built, let's fill in the basic information
  976. $sql_query = file_get_contents('schemas/schema_data.sql');
  977. // Deal with any special comments
  978. switch ($data['dbms'])
  979. {
  980. case 'mssql':
  981. case 'mssql_odbc':
  982. case 'mssqlnative':
  983. $sql_query = preg_replace('#\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \##s', 'SET IDENTITY_INSERT \1 \2;', $sql_query);
  984. break;
  985. case 'postgres':
  986. $sql_query = preg_replace('#\# POSTGRES (BEGIN|COMMIT) \##s', '\1; ', $sql_query);
  987. break;
  988. }
  989. // Change prefix
  990. $sql_query = preg_replace('# phpbb_([^\s]*) #i', ' ' . $data['table_prefix'] . '\1 ', $sql_query);
  991. // Change language strings...
  992. $sql_query = preg_replace_callback('#\{L_([A-Z0-9\-_]*)\}#s', 'adjust_language_keys_callback', $sql_query);
  993. $sql_query = phpbb_remove_comments($sql_query);
  994. $sql_query = split_sql_file($sql_query, ';');
  995. foreach ($sql_query as $sql)
  996. {
  997. //$sql = trim(str_replace('|', ';', $sql));
  998. if (!$db->sql_query($sql))
  999. {
  1000. $error = $db->sql_error();
  1001. $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__);
  1002. }
  1003. }
  1004. unset($sql_query);
  1005. $current_time = time();
  1006. $user_ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : '';
  1007. $user_ip = (stripos($user_ip, '::ffff:') === 0) ? substr($user_ip, 7) : $user_ip;
  1008. if ($data['script_path'] !== '/')
  1009. {
  1010. // Adjust destination path (no trailing slash)
  1011. if (substr($data['script_path'], -1) == '/')
  1012. {
  1013. $data['script_path'] = substr($data['script_path'], 0, -1);
  1014. }
  1015. $data['script_path'] = str_replace(array('../', './'), '', $data['script_path']);
  1016. if ($data['script_path'][0] != '/')
  1017. {
  1018. $data['script_path'] = '/' . $data['script_path'];
  1019. }
  1020. }
  1021. // Set default config and post data, this applies to all DB's
  1022. $sql_ary = array(
  1023. 'INSERT INTO ' . $data['table_prefix'] . "config (config_name, config_value)
  1024. VALUES ('board_startdate', '$current_time')",
  1025. 'INSERT INTO ' . $data['table_prefix'] . "config (config_name, config_value)
  1026. VALUES ('default_lang', '" . $db->sql_escape($data['default_lang']) . "')",
  1027. 'UPDATE ' . $data['table_prefix'] . "config
  1028. SET config_value = '" . $db->sql_escape($data['img_imagick']) . "'
  1029. WHERE config_name = 'img_imagick'",
  1030. 'UPDATE ' . $data['table_prefix'] . "config
  1031. SET config_value = '" . $db->sql_escape($data['server_name']) . "'
  1032. WHERE config_name = 'server_name'",
  1033. 'UPDATE ' . $data['table_prefix'] . "config
  1034. SET config_value = '" . $db->sql_escape($data['server_port']) . "'
  1035. WHERE config_name = 'server_port'",
  1036. 'UPDATE ' . $data['table_prefix'] . "config
  1037. SET config_value = '" . $db->sql_escape($data['board_email1']) . "'
  1038. WHERE config_name = 'board_email'",
  1039. 'UPDATE ' . $data['table_prefix'] . "config
  1040. SET config_value = '" . $db->sql_escape($data['board_email1']) . "'
  1041. WHERE config_name = 'board_contact'",
  1042. 'UPDATE ' . $data['table_prefix'] . "config
  1043. SET config_value = '" . $db->sql_escape($cookie_domain) . "'
  1044. WHERE config_name = 'cookie_domain'",
  1045. 'UPDATE ' . $data['table_prefix'] . "config
  1046. SET config_value = '" . $db->sql_escape($lang['default_dateformat']) . "'
  1047. WHERE config_name = 'default_dateformat'",
  1048. 'UPDATE ' . $data['table_prefix'] . "config
  1049. SET config_value = '" . $db->sql_escape($data['email_enable']) . "'
  1050. WHERE config_name = 'email_enable'",
  1051. 'UPDATE ' . $data['table_prefix'] . "config
  1052. SET config_value = '" . $db->sql_escape($data['smtp_delivery']) . "'
  1053. WHERE config_name = 'smtp_delivery'",
  1054. 'UPDATE ' . $data['table_prefix'] . "config
  1055. SET config_value = '" . $db->sql_escape($data['smtp_host']) . "'
  1056. WHERE config_name = 'smtp_host'",
  1057. 'UPDATE ' . $data['table_prefix'] . "config
  1058. SET config_value = '" . $db->sql_escape($data['smtp_auth']) . "'
  1059. WHERE config_name = 'smtp_auth_method'",
  1060. 'UPDATE ' . $data['table_prefix'] . "config
  1061. SET config_value = '" . $db->sql_escape($data['smtp_user']) . "'
  1062. WHERE config_name = 'smtp_username'",
  1063. 'UPDATE ' . $data['table_prefix'] . "config
  1064. SET config_value = '" . $db->sql_escape($data['smtp_pass']) . "'
  1065. WHERE config_name = 'smtp_password'",
  1066. 'UPDATE ' . $data['table_prefix'] . "config
  1067. SET config_value = '" . $db->sql_escape($data['cookie_secure']) . "'
  1068. WHERE config_name = 'cookie_secure'",
  1069. 'UPDATE ' . $data['table_prefix'] . "config
  1070. SET config_value = '" . $db->sql_escape($data['force_server_vars']) . "'
  1071. WHERE config_name = 'force_server_vars'",
  1072. 'UPDATE ' . $data['table_prefix'] . "config
  1073. SET config_value = '" . $db->sql_escape($data['script_path']) . "'
  1074. WHERE config_name = 'script_path'",
  1075. 'UPDATE ' . $data['table_prefix'] . "config
  1076. SET config_value = '" . $db->sql_escape($data['server_protocol']) . "'
  1077. WHERE config_name = 'server_protocol'",
  1078. 'UPDATE ' . $data['table_prefix'] . "config
  1079. SET config_value = '" . $db->sql_escape($data['admin_name']) . "'
  1080. WHERE config_name = 'newest_username'",
  1081. 'UPDATE ' . $data['table_prefix'] . "config
  1082. SET config_value = '" . md5(mt_rand()) . "'
  1083. WHERE config_name = 'avatar_salt'",
  1084. 'UPDATE ' . $data['table_prefix'] . "users
  1085. SET username = '" . $db->sql_escape($data['admin_name']) . "', user_password='" . $db->sql_escape(md5($data['admin_pass1'])) . "', user_ip = '" . $db->sql_escape($user_ip) . "', user_lang = '" . $db->sql_escape($data['default_lang']) . "', user_email='" . $db->sql_escape($data['board_email1']) . "', user_dateformat='" . $db->sql_escape($lang['default_dateformat']) . "', user_email_hash = " . $db->sql_escape(phpbb_email_hash($data['board_email1'])) . ", username_clean = '" . $db->sql_escape(utf8_clean_string($data['admin_name'])) . "'
  1086. WHERE username = 'Admin'",
  1087. 'UPDATE ' . $data['table_prefix'] . "moderator_cache
  1088. SET username = '" . $db->sql_escape($data['admin_name']) . "'
  1089. WHERE username = 'Admin'",
  1090. 'UPDATE ' . $data['table_prefix'] . "forums
  1091. SET forum_last_poster_name = '" . $db->sql_escape($data['admin_name']) . "'
  1092. WHERE forum_last_poster_name = 'Admin'",
  1093. 'UPDATE ' . $data['table_prefix'] . "topics
  1094. SET topic_first_poster_name = '" . $db->sql_escape($data['admin_name']) . "', topic_last_poster_name = '" . $db->sql_escape($data['admin_name']) . "'
  1095. WHERE topic_first_poster_name = 'Admin'
  1096. OR topic_last_poster_name = 'Admin'",
  1097. 'UPDATE ' . $data['table_prefix'] . "users
  1098. SET user_regdate = $current_time",
  1099. 'UPDATE ' . $data['table_prefix'] . "posts
  1100. SET post_time = $current_time, poster_ip = '" . $db->sql_escape($user_ip) . "'",
  1101. 'UPDATE ' . $data['table_prefix'] . "topics
  1102. SET topic_time = $current_time, topic_last_post_time = $current_time",
  1103. 'UPDATE ' . $data['table_prefix'] . "forums
  1104. SET forum_last_post_time = $current_time",
  1105. 'UPDATE ' . $data['table_prefix'] . "config
  1106. SET config_value = '" . $db->sql_escape($db->sql_server_info(true)) . "'
  1107. WHERE config_name = 'dbms_version'",
  1108. );
  1109. if (@extension_loaded('gd') || can_load_dll('gd'))
  1110. {
  1111. $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config
  1112. SET config_value = 'phpbb_captcha_gd'
  1113. WHERE config_name = 'captcha_plugin'";
  1114. $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config
  1115. SET config_value = '1'
  1116. WHERE config_name = 'captcha_gd'";
  1117. }
  1118. $ref = substr($referer, strpos($referer, '://') + 3);
  1119. if (!(stripos($ref, $server_name) === 0))
  1120. {
  1121. $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config
  1122. SET config_value = '0'
  1123. WHERE config_name = 'referer_validation'";
  1124. }
  1125. // We set a (semi-)unique cookie name to bypass login issues related to the cookie name.
  1126. $cookie_name = 'phpbb3_';
  1127. $rand_str = md5(mt_rand());
  1128. $rand_str = str_replace('0', 'z', base_convert($rand_str, 16, 35));
  1129. $rand_str = substr($rand_str, 0, 5);
  1130. $cookie_name .= strtolower($rand_str);
  1131. $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config
  1132. SET config_value = '" . $db->sql_escape($cookie_name) . "'
  1133. WHERE config_name = 'cookie_name'";
  1134. foreach ($sql_ary as $sql)
  1135. {
  1136. //$sql = trim(str_replace('|', ';', $sql));
  1137. if (!$db->sql_query($sql))
  1138. {
  1139. $error = $db->sql_error();
  1140. $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__);
  1141. }
  1142. }
  1143. $submit = $lang['NEXT_STEP'];
  1144. $url = $this->p_master->module_url . "?mode=$mode&amp;sub=final";
  1145. $template->assign_vars(array(
  1146. 'BODY' => $lang['STAGE_CREATE_TABLE_EXPLAIN'],
  1147. 'L_SUBMIT' => $submit,
  1148. 'S_HIDDEN' => build_hidden_fields($data),
  1149. 'U_ACTION' => $url,
  1150. ));
  1151. }
  1152. /**
  1153. * Build the search index...
  1154. */
  1155. function build_search_index($mode, $sub)
  1156. {
  1157. global $db, $lang, $phpbb_root_path, $phpEx, $config;
  1158. // Obtain any submitted data
  1159. $data = $this->get_submitted_data();
  1160. $table_prefix = $data['table_prefix'];
  1161. // If we get here and the extension isn't loaded it should be safe to just go ahead and load it
  1162. $available_dbms = get_available_dbms($data['dbms']);
  1163. if (!isset($available_dbms[$data['dbms']]))
  1164. {
  1165. // Someone's been silly and tried providing a non-existant dbms
  1166. $this->p_master->redirect("index.$phpEx?mode=install");
  1167. }
  1168. $dbms = $available_dbms[$data['dbms']]['DRIVER'];
  1169. // Load the appropriate database class if not already loaded
  1170. include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
  1171. // Instantiate the database
  1172. $db = new $sql_db();
  1173. $db->sql_connect($data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport'], false, false);
  1174. // NOTE: trigger_error does not work here.
  1175. $db->sql_return_on_error(true);
  1176. include_once($phpbb_root_path . 'includes/constants.' . $phpEx);
  1177. include_once($phpbb_root_path . 'includes/search/fulltext_native.' . $phpEx);
  1178. // Fill the config array - it is needed by those functions we call
  1179. $sql = 'SELECT *
  1180. FROM ' . CONFIG_TABLE;
  1181. $result = $db->sql_query($sql);
  1182. $config = array();
  1183. while ($row = $db->sql_fetchrow($result))
  1184. {
  1185. $config[$row['config_name']] = $row['config_value'];
  1186. }
  1187. $db->sql_freeresult($result);
  1188. $error = false;
  1189. $search = new fulltext_native($error);
  1190. $sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id
  1191. FROM ' . POSTS_TABLE;
  1192. $result = $db->sql_query($sql);
  1193. while ($row = $db->sql_fetchrow($result))
  1194. {
  1195. $search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']);
  1196. }
  1197. $db->sql_freeresult($result);
  1198. }
  1199. /**
  1200. * Populate the module tables
  1201. */
  1202. function add_modules($mode, $sub)
  1203. {
  1204. global $db, $lang, $phpbb_root_path, $phpEx;
  1205. include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
  1206. $_module = new acp_modules();
  1207. $module_classes = array('acp', 'mcp', 'ucp');
  1208. // Add categories
  1209. foreach ($module_classes as $module_class)
  1210. {
  1211. $categories = array();
  1212. // Set the module class
  1213. $_module->module_class = $module_class;
  1214. foreach ($this->module_categories[$module_class] as $cat_name => $subs)
  1215. {
  1216. $module_data = array(
  1217. 'module_basename' => '',
  1218. 'module_enabled' => 1,
  1219. 'module_display' => 1,
  1220. 'parent_id' => 0,
  1221. 'module_class' => $module_class,
  1222. 'module_langname' => $cat_name,
  1223. 'module_mode' => '',
  1224. 'module_auth' => '',
  1225. );
  1226. // Add category
  1227. $_module->update_module_data($module_data, true);
  1228. // Check for last sql error happened
  1229. if ($db->sql_error_triggered)
  1230. {
  1231. $error = $db->sql_error($db->sql_error_sql);
  1232. $this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
  1233. }
  1234. $categories[$cat_name]['id'] = (int) $module_data['module_id'];
  1235. $categories[$cat_name]['parent_id'] = 0;
  1236. // Create sub-categories...
  1237. if (is_array($subs))
  1238. {
  1239. foreach ($subs as $level2_name)
  1240. {
  1241. $module_data = array(
  1242. 'module_basename' => '',
  1243. 'module_enabled' => 1,
  1244. 'module_display' => 1,
  1245. 'parent_id' => (int) $categories[$cat_name]['id'],
  1246. 'module_class' => $module_class,
  1247. 'module_langname' => $level2_name,
  1248. 'module_mode' => '',
  1249. 'module_auth' => '',
  1250. );
  1251. $_module->update_module_data($module_data, true);
  1252. // Check for last sql error happened
  1253. if ($db->sql_error_triggered)
  1254. {
  1255. $error = $db->sql_error($db->sql_error_sql);
  1256. $this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
  1257. }
  1258. $categories[$level2_name]['id'] = (int) $module_data['module_id'];
  1259. $categories[$level2_name]['parent_id'] = (int) $categories[$cat_name]['id'];
  1260. }
  1261. }
  1262. }
  1263. // Get the modules we want to add... returned sorted by name
  1264. $module_info = $_module->get_module_infos('', $module_class);
  1265. foreach ($module_info as $module_basename => $fileinfo)
  1266. {
  1267. foreach ($fileinfo['modes'] as $module_mode => $row)
  1268. {
  1269. foreach ($row['cat'] as $cat_name)
  1270. {
  1271. if (!isset($categories[$cat_name]))
  1272. {
  1273. continue;
  1274. }
  1275. $module_data = array(
  1276. 'module_basename' => $module_basename,
  1277. 'module_enabled' => 1,
  1278. 'module_display' => (isset($row['display'])) ? (int) $row['display'] : 1,
  1279. 'parent_id' => (int) $categories[$cat_name]['id'],
  1280. 'module_class' => $module_class,
  1281. 'module_langname' => $row['title'],
  1282. 'module_mode' => $module_mode,
  1283. 'module_auth' => $row['auth'],
  1284. );
  1285. $_module->update_module_data($module_data, true);
  1286. // Check for last sql error happened
  1287. if ($db->sql_error_triggered)
  1288. {
  1289. $error = $db->sql_error($db->sql_error_sql);
  1290. $this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
  1291. }
  1292. }
  1293. }
  1294. }
  1295. // Move some of the modules around since the code above will put them in the wrong place
  1296. if ($module_class == 'acp')
  1297. {
  1298. // Move main module 4 up...
  1299. $sql = 'SELECT *
  1300. FROM ' . MODULES_TABLE . "
  1301. WHERE module_basename = 'main'
  1302. AND module_class = 'acp'
  1303. AND module_mode = 'main'";
  1304. $result = $db->sql_query($sql);
  1305. $row = $db->sql_fetchrow($result);
  1306. $db->sql_freeresult($result);
  1307. $_module->move_module_by($row, 'move_up', 4);
  1308. // Move permissions intro screen module 4 up...
  1309. $sql = 'SELECT *
  1310. FROM ' . MODULES_TABLE . "
  1311. WHERE module_basename = 'permissions'
  1312. AND module_class = 'acp'
  1313. AND module_mode = 'intro'";
  1314. $result = $db->sql_query($sql);
  1315. $row = $db->sql_fetchrow($result);
  1316. $db->sql_freeresult($result);
  1317. $_module->move_module_by($row, 'move_up', 4);
  1318. // Move manage users screen module 5 up...
  1319. $sql = 'SELECT *
  1320. FROM ' . MODULES_TABLE . "
  1321. WHERE module_basename =

Large files files are truncated, but you can click here to view the full file