PageRenderTime 63ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/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
  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 = 'users'
  1322. AND module_class = 'acp'
  1323. AND module_mode = 'overview'";
  1324. $result = $db->sql_query($sql);
  1325. $row = $db->sql_fetchrow($result);
  1326. $db->sql_freeresult($result);
  1327. $_module->move_module_by($row, 'move_up', 5);
  1328. }
  1329. if ($module_class == 'ucp')
  1330. {
  1331. // Move attachment module 4 down...
  1332. $sql = 'SELECT *
  1333. FROM ' . MODULES_TABLE . "
  1334. WHERE module_basename = 'attachments'
  1335. AND module_class = 'ucp'
  1336. AND module_mode = 'attachments'";
  1337. $result = $db->sql_query($sql);
  1338. $row = $db->sql_fetchrow($result);
  1339. $db->sql_freeresult($result);
  1340. $_module->move_module_by($row, 'move_down', 4);
  1341. }
  1342. // And now for the special ones
  1343. // (these are modules which appear in multiple categories and thus get added manually to some for more control)
  1344. if (isset($this->module_extras[$module_class]))
  1345. {
  1346. foreach ($this->module_extras[$module_class] as $cat_name => $mods)
  1347. {
  1348. $sql = 'SELECT module_id, left_id, right_id
  1349. FROM ' . MODULES_TABLE . "
  1350. WHERE module_langname = '" . $db->sql_escape($cat_name) . "'
  1351. AND module_class = '" . $db->sql_escape($module_class) . "'";
  1352. $result = $db->sql_query_limit($sql, 1);
  1353. $row2 = $db->sql_fetchrow($result);
  1354. $db->sql_freeresult($result);
  1355. foreach ($mods as $mod_name)
  1356. {
  1357. $sql = 'SELECT *
  1358. FROM ' . MODULES_TABLE . "
  1359. WHERE module_langname = '" . $db->sql_escape($mod_name) . "'
  1360. AND module_class = '" . $db->sql_escape($module_class) . "'
  1361. AND module_basename <> ''";
  1362. $result = $db->sql_query_limit($sql, 1);
  1363. $row = $db->sql_fetchrow($result);
  1364. $db->sql_freeresult($result);
  1365. $module_data = array(
  1366. 'module_basename' => $row['module_basename'],
  1367. 'module_enabled' => (int) $row['module_enabled'],
  1368. 'module_display' => (int) $row['module_display'],
  1369. 'parent_id' => (int) $row2['module_id'],
  1370. 'module_class' => $row['module_class'],
  1371. 'module_langname' => $row['module_langname'],
  1372. 'module_mode' => $row['module_mode'],
  1373. 'module_auth' => $row['module_auth'],
  1374. );
  1375. $_module->update_module_data($module_data, true);
  1376. // Check for last sql error happened
  1377. if ($db->sql_error_triggered)
  1378. {
  1379. $error = $db->sql_error($db->sql_error_sql);
  1380. $this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
  1381. }
  1382. }
  1383. }
  1384. }
  1385. $_module->remove_cache_file();
  1386. }
  1387. }
  1388. /**
  1389. * Populate the language tables
  1390. */
  1391. function add_language($mode, $sub)
  1392. {
  1393. global $db, $lang, $phpbb_root_path, $phpEx;
  1394. $dir = @opendir($phpbb_root_path . 'language');
  1395. if (!$dir)
  1396. {
  1397. $this->error('Unable to access the language directory', __LINE__, __FILE__);
  1398. }
  1399. while (($file = readdir($dir)) !== false)
  1400. {
  1401. $path = $phpbb_root_path . 'language/' . $file;
  1402. if ($file == '.' || $file == '..' || is_link($path) || is_file($path) || $file == 'CVS')
  1403. {
  1404. continue;
  1405. }
  1406. if (is_dir($path) && file_exists($path . '/iso.txt'))
  1407. {
  1408. $lang_file = file("$path/iso.txt");
  1409. $lang_pack = array(
  1410. 'lang_iso' => basename($path),
  1411. 'lang_dir' => basename($path),
  1412. 'lang_english_name' => trim(htmlspecialchars($lang_file[0])),
  1413. 'lang_local_name' => trim(htmlspecialchars($lang_file[1], ENT_COMPAT, 'UTF-8')),
  1414. 'lang_author' => trim(htmlspecialchars($lang_file[2], ENT_COMPAT, 'UTF-8')),
  1415. );
  1416. $db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $lang_pack));
  1417. if ($db->sql_error_triggered)
  1418. {
  1419. $error = $db->sql_error($db->sql_error_sql);
  1420. $this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
  1421. }
  1422. $valid_localized = array(
  1423. 'icon_back_top', 'icon_contact_aim', 'icon_contact_email', 'icon_contact_icq', 'icon_contact_jabber', 'icon_contact_msnm', 'icon_contact_pm', 'icon_contact_yahoo', 'icon_contact_www', 'icon_post_delete', 'icon_post_edit', 'icon_post_info', 'icon_post_quote', 'icon_post_report', 'icon_user_online', 'icon_user_offline', 'icon_user_profile', 'icon_user_search', 'icon_user_warn', 'button_pm_forward', 'button_pm_new', 'button_pm_reply', 'button_topic_locked', 'button_topic_new', 'button_topic_reply',
  1424. );
  1425. $sql_ary = array();
  1426. $sql = 'SELECT *
  1427. FROM ' . STYLES_IMAGESET_TABLE;
  1428. $result = $db->sql_query($sql);
  1429. while ($imageset_row = $db->sql_fetchrow($result))
  1430. {
  1431. if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['lang_iso']}/imageset.cfg"))
  1432. {
  1433. $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['lang_iso']}/imageset.cfg");
  1434. foreach ($cfg_data_imageset_data as $image_name => $value)
  1435. {
  1436. if (strpos($value, '*') !== false)
  1437. {
  1438. if (substr($value, -1, 1) === '*')
  1439. {
  1440. list($image_filename, $image_height) = explode('*', $value);
  1441. $image_width = 0;
  1442. }
  1443. else
  1444. {
  1445. list($image_filename, $image_height, $image_width) = explode('*', $value);
  1446. }
  1447. }
  1448. else
  1449. {
  1450. $image_filename = $value;
  1451. $image_height = $image_width = 0;
  1452. }
  1453. if (strpos($image_name, 'img_') === 0 && $image_filename)
  1454. {
  1455. $image_name = substr($image_name, 4);
  1456. if (in_array($image_name, $valid_localized))
  1457. {
  1458. $sql_ary[] = array(
  1459. 'image_name' => (string) $image_name,
  1460. 'image_filename' => (string) $image_filename,
  1461. 'image_height' => (int) $image_height,
  1462. 'image_width' => (int) $image_width,
  1463. 'imageset_id' => (int) $imageset_row['imageset_id'],
  1464. 'image_lang' => (string) $lang_pack['lang_iso'],
  1465. );
  1466. }
  1467. }
  1468. }
  1469. }
  1470. }
  1471. $db->sql_freeresult($result);
  1472. if (sizeof($sql_ary))
  1473. {
  1474. $db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);
  1475. if ($db->sql_error_triggered)
  1476. {
  1477. $error = $db->sql_error($db->sql_error_sql);
  1478. $this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
  1479. }
  1480. }
  1481. }
  1482. }
  1483. closedir($dir);
  1484. }
  1485. /**
  1486. * Add search robots to the database
  1487. */
  1488. function add_bots($mode, $sub)
  1489. {
  1490. global $db, $lang, $phpbb_root_path, $phpEx, $config;
  1491. // Obtain any submitted data
  1492. $data = $this->get_submitted_data();
  1493. // Fill the config array - it is needed by those functions we call
  1494. $sql = 'SELECT *
  1495. FROM ' . CONFIG_TABLE;
  1496. $result = $db->sql_query($sql);
  1497. $config = array();
  1498. while ($row = $db->sql_fetchrow($result))
  1499. {
  1500. $config[$row['config_name']] = $row['config_value'];
  1501. }
  1502. $db->sql_freeresult($result);
  1503. $sql = 'SELECT group_id
  1504. FROM ' . GROUPS_TABLE . "
  1505. WHERE group_name = 'BOTS'";
  1506. $result = $db->sql_query($sql);
  1507. $group_id = (int) $db->sql_fetchfield('group_id');
  1508. $db->sql_freeresult($result);
  1509. if (!$group_id)
  1510. {
  1511. // If we reach this point then something has gone very wrong
  1512. $this->p_master->error($lang['NO_GROUP'], __LINE__, __FILE__);
  1513. }
  1514. if (!function_exists('user_add'))
  1515. {
  1516. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  1517. }
  1518. foreach ($this->bot_list as $bot_name => $bot_ary)
  1519. {
  1520. $user_row = array(
  1521. 'user_type' => USER_IGNORE,
  1522. 'group_id' => $group_id,
  1523. 'username' => $bot_name,
  1524. 'user_regdate' => time(),
  1525. 'user_password' => '',
  1526. 'user_colour' => '9E8DA7',
  1527. 'user_email' => '',
  1528. 'user_lang' => $data['default_lang'],
  1529. 'user_style' => 1,
  1530. 'user_timezone' => 0,
  1531. 'user_dateformat' => $lang['default_dateformat'],
  1532. 'user_allow_massemail' => 0,
  1533. );
  1534. $user_id = user_add($user_row);
  1535. if (!$user_id)
  1536. {
  1537. // If we can't insert this user then continue to the next one to avoid inconsistent data
  1538. $this->p_master->db_error('Unable to insert bot into users table', $db->sql_error_sql, __LINE__, __FILE__, true);
  1539. continue;
  1540. }
  1541. $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
  1542. 'bot_active' => 1,
  1543. 'bot_name' => (string) $bot_name,
  1544. 'user_id' => (int) $user_id,
  1545. 'bot_agent' => (string) $bot_ary[0],
  1546. 'bot_ip' => (string) $bot_ary[1],
  1547. ));
  1548. $result = $db->sql_query($sql);
  1549. }
  1550. }
  1551. /**
  1552. * Sends an email to the board administrator with their password and some useful links
  1553. */
  1554. function email_admin($mode, $sub)
  1555. {
  1556. global $auth, $config, $db, $lang, $template, $user, $phpbb_root_path, $phpEx;
  1557. $this->page_title = $lang['STAGE_FINAL'];
  1558. // Obtain any submitted data
  1559. $data = $this->get_submitted_data();
  1560. $sql = 'SELECT *
  1561. FROM ' . CONFIG_TABLE;
  1562. $result = $db->sql_query($sql);
  1563. $config = array();
  1564. while ($row = $db->sql_fetchrow($result))
  1565. {
  1566. $config[$row['config_name']] = $row['config_value'];
  1567. }
  1568. $db->sql_freeresult($result);
  1569. $user->session_begin();
  1570. $auth->login($data['admin_name'], $data['admin_pass1'], false, true, true);
  1571. // OK, Now that we've reached this point we can be confident that everything
  1572. // is installed and working......I hope :)
  1573. // So it's time to send an email to the administrator confirming the details
  1574. // they entered
  1575. if ($config['email_enable'])
  1576. {
  1577. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  1578. $messenger = new messenger(false);
  1579. $messenger->template('installed', $data['language']);
  1580. $messenger->to($data['board_email1'], $data['admin_name']);
  1581. $messenger->anti_abuse_headers($config, $user);
  1582. $messenger->assign_vars(array(
  1583. 'USERNAME' => htmlspecialchars_decode($data['admin_name']),
  1584. 'PASSWORD' => htmlspecialchars_decode($data['admin_pass1']))
  1585. );
  1586. $messenger->send(NOTIFY_EMAIL);
  1587. }
  1588. // And finally, add a note to the log
  1589. add_log('admin', 'LOG_INSTALL_INSTALLED', $config['version']);
  1590. $template->assign_vars(array(
  1591. 'TITLE' => $lang['INSTALL_CONGRATS'],
  1592. 'BODY' => sprintf($lang['INSTALL_CONGRATS_EXPLAIN'], $config['version'], append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=convert&amp;language=' . $data['language']), '../docs/README.html'),
  1593. 'L_SUBMIT' => $lang['INSTALL_LOGIN'],
  1594. 'U_ACTION' => append_sid($phpbb_root_path . 'adm/index.' . $phpEx, 'i=send_statistics&amp;mode=send_statistics'),
  1595. ));
  1596. }
  1597. /**
  1598. * Check if the avatar directory is writable and disable avatars
  1599. * if it isn't writable.
  1600. */
  1601. function disable_avatars_if_unwritable()
  1602. {
  1603. global $phpbb_root_path;
  1604. if (!phpbb_is_writable($phpbb_root_path . 'images/avatars/upload/'))
  1605. {
  1606. set_config('allow_avatar', 0);
  1607. set_config('allow_avatar_upload', 0);
  1608. }
  1609. }
  1610. /**
  1611. * Generate a list of available mail server authentication methods
  1612. */
  1613. function mail_auth_select($selected_method)
  1614. {
  1615. global $lang;
  1616. $auth_methods = array('PLAIN', 'LOGIN', 'CRAM-MD5', 'DIGEST-MD5', 'POP-BEFORE-SMTP');
  1617. $s_smtp_auth_options = '';
  1618. foreach ($auth_methods as $method)
  1619. {
  1620. $s_smtp_auth_options .= '<option value="' . $method . '"' . (($selected_method == $method) ? ' selected="selected"' : '') . '>' . $lang['SMTP_' . str_replace('-', '_', $method)] . '</option>';
  1621. }
  1622. return $s_smtp_auth_options;
  1623. }
  1624. /**
  1625. * Get submitted data
  1626. */
  1627. function get_submitted_data()
  1628. {
  1629. return array(
  1630. 'language' => basename(request_var('language', '')),
  1631. 'dbms' => request_var('dbms', ''),
  1632. 'dbhost' => request_var('dbhost', ''),
  1633. 'dbport' => request_var('dbport', ''),
  1634. 'dbuser' => request_var('dbuser', ''),
  1635. 'dbpasswd' => request_var('dbpasswd', '', true),
  1636. 'dbname' => request_var('dbname', ''),
  1637. 'table_prefix' => request_var('table_prefix', ''),
  1638. 'default_lang' => basename(request_var('default_lang', '')),
  1639. 'admin_name' => utf8_normalize_nfc(request_var('admin_name', '', true)),
  1640. 'admin_pass1' => request_var('admin_pass1', '', true),
  1641. 'admin_pass2' => request_var('admin_pass2', '', true),
  1642. 'board_email1' => strtolower(request_var('board_email1', '')),
  1643. 'board_email2' => strtolower(request_var('board_email2', '')),
  1644. 'img_imagick' => request_var('img_imagick', ''),
  1645. 'ftp_path' => request_var('ftp_path', ''),
  1646. 'ftp_user' => request_var('ftp_user', ''),
  1647. 'ftp_pass' => request_var('ftp_pass', ''),
  1648. 'email_enable' => request_var('email_enable', ''),
  1649. 'smtp_delivery' => request_var('smtp_delivery', ''),
  1650. 'smtp_host' => request_var('smtp_host', ''),
  1651. 'smtp_auth' => request_var('smtp_auth', ''),
  1652. 'smtp_user' => request_var('smtp_user', ''),
  1653. 'smtp_pass' => request_var('smtp_pass', ''),
  1654. 'cookie_secure' => request_var('cookie_secure', ''),
  1655. 'force_server_vars' => request_var('force_server_vars', ''),
  1656. 'server_protocol' => request_var('server_protocol', ''),
  1657. 'server_name' => request_var('server_name', ''),
  1658. 'server_port' => request_var('server_port', ''),
  1659. 'script_path' => request_var('script_path', ''),
  1660. );
  1661. }
  1662. /**
  1663. * The information below will be used to build the input fields presented to the user
  1664. */
  1665. var $db_config_options = array(
  1666. 'legend1' => 'DB_CONFIG',
  1667. 'dbms' => array('lang' => 'DBMS', 'type' => 'select', 'options' => 'dbms_select(\'{VALUE}\')', 'explain' => false),
  1668. 'dbhost' => array('lang' => 'DB_HOST', 'type' => 'text:25:100', 'explain' => true),
  1669. 'dbport' => array('lang' => 'DB_PORT', 'type' => 'text:25:100', 'explain' => true),
  1670. 'dbname' => array('lang' => 'DB_NAME', 'type' => 'text:25:100', 'explain' => false),
  1671. 'dbuser' => array('lang' => 'DB_USERNAME', 'type' => 'text:25:100', 'explain' => false),
  1672. 'dbpasswd' => array('lang' => 'DB_PASSWORD', 'type' => 'password:25:100', 'explain' => false),
  1673. 'table_prefix' => array('lang' => 'TABLE_PREFIX', 'type' => 'text:25:100', 'explain' => true),
  1674. );
  1675. var $admin_config_options = array(
  1676. 'legend1' => 'ADMIN_CONFIG',
  1677. 'default_lang' => array('lang' => 'DEFAULT_LANG', 'type' => 'select', 'options' => '$this->module->inst_language_select(\'{VALUE}\')', 'explain' => false),
  1678. 'admin_name' => array('lang' => 'ADMIN_USERNAME', 'type' => 'text:25:100', 'explain' => true),
  1679. 'admin_pass1' => array('lang' => 'ADMIN_PASSWORD', 'type' => 'password:25:100', 'explain' => true),
  1680. 'admin_pass2' => array('lang' => 'ADMIN_PASSWORD_CONFIRM', 'type' => 'password:25:100', 'explain' => false),
  1681. 'board_email1' => array('lang' => 'CONTACT_EMAIL', 'type' => 'text:25:100', 'explain' => false),
  1682. 'board_email2' => array('lang' => 'CONTACT_EMAIL_CONFIRM', 'type' => 'text:25:100', 'explain' => false),
  1683. );
  1684. var $advanced_config_options = array(
  1685. 'legend1' => 'ACP_EMAIL_SETTINGS',
  1686. 'email_enable' => array('lang' => 'ENABLE_EMAIL', 'type' => 'radio:enabled_disabled', 'explain' => true),
  1687. 'smtp_delivery' => array('lang' => 'USE_SMTP', 'type' => 'radio:yes_no', 'explain' => true),
  1688. 'smtp_host' => array('lang' => 'SMTP_SERVER', 'type' => 'text:25:50', 'explain' => false),
  1689. 'smtp_auth' => array('lang' => 'SMTP_AUTH_METHOD', 'type' => 'select', 'options' => '$this->module->mail_auth_select(\'{VALUE}\')', 'explain' => true),
  1690. 'smtp_user' => array('lang' => 'SMTP_USERNAME', 'type' => 'text:25:255', 'explain' => true),
  1691. 'smtp_pass' => array('lang' => 'SMTP_PASSWORD', 'type' => 'password:25:255', 'explain' => true),
  1692. 'legend2' => 'SERVER_URL_SETTINGS',
  1693. 'cookie_secure' => array('lang' => 'COOKIE_SECURE', 'type' => 'radio:enabled_disabled', 'explain' => true),
  1694. 'force_server_vars' => array('lang' => 'FORCE_SERVER_VARS', 'type' => 'radio:yes_no', 'explain' => true),
  1695. 'server_protocol' => array('lang' => 'SERVER_PROTOCOL', 'type' => 'text:10:10', 'explain' => true),
  1696. 'server_name' => array('lang' => 'SERVER_NAME', 'type' => 'text:40:255', 'explain' => true),
  1697. 'server_port' => array('lang' => 'SERVER_PORT', 'type' => 'text:5:5', 'explain' => true),
  1698. 'script_path' => array('lang' => 'SCRIPT_PATH', 'type' => 'text::255', 'explain' => true),
  1699. );
  1700. /**
  1701. * Specific PHP modules we may require for certain optional or extended features
  1702. */
  1703. var $php_dlls_other = array('zlib', 'ftp', 'gd', 'xml');
  1704. /**
  1705. * A list of the web-crawlers/bots we recognise by default
  1706. *
  1707. * Candidates but not included:
  1708. * 'Accoona [Bot]' 'Accoona-AI-Agent/'
  1709. * 'ASPseek [Crawler]' 'ASPseek/'
  1710. * 'Boitho [Crawler]' 'boitho.com-dc/'
  1711. * 'Bunnybot [Bot]' 'powered by www.buncat.de'
  1712. * 'Cosmix [Bot]' 'cfetch/'
  1713. * 'Crawler Search [Crawler]' '.Crawler-Search.de'
  1714. * 'Findexa [Crawler]' 'Findexa Crawler ('
  1715. * 'GBSpider [Spider]' 'GBSpider v'
  1716. * 'genie [Bot]' 'genieBot ('
  1717. * 'Hogsearch [Bot]' 'oegp v. 1.3.0'
  1718. * 'Insuranco [Bot]' 'InsurancoBot'
  1719. * 'IRLbot [Bot]' 'http://irl.cs.tamu.edu/crawler'
  1720. * 'ISC Systems [Bot]' 'ISC Systems iRc Search'
  1721. * 'Jyxobot [Bot]' 'Jyxobot/'
  1722. * 'Kraehe [Metasuche]' '-DIE-KRAEHE- META-SEARCH-ENGINE/'
  1723. * 'LinkWalker' 'LinkWalker'
  1724. * 'MMSBot [Bot]' 'http://www.mmsweb.at/bot.html'
  1725. * 'Naver [Bot]' 'nhnbot@naver.com)'
  1726. * 'NetResearchServer' 'NetResearchServer/'
  1727. * 'Nimble [Crawler]' 'NimbleCrawler'
  1728. * 'Ocelli [Bot]' 'Ocelli/'
  1729. * 'Onsearch [Bot]' 'onCHECK-Robot'
  1730. * 'Orange [Spider]' 'OrangeSpider'
  1731. * 'Sproose [Bot]' 'http://www.sproose.com/bot'
  1732. * 'Susie [Sync]' '!Susie (http://www.sync2it.com/susie)'
  1733. * 'Tbot [Bot]' 'Tbot/'
  1734. * 'Thumbshots [Capture]' 'thumbshots-de-Bot'
  1735. * 'Vagabondo [Crawler]' 'http://webagent.wise-guys.nl/'
  1736. * 'Walhello [Bot]' 'appie 1.1 (www.walhello.com)'
  1737. * 'WissenOnline [Bot]' 'WissenOnline-Bot'
  1738. * 'WWWeasel [Bot]' 'WWWeasel Robot v'
  1739. * 'Xaldon [Spider]' 'Xaldon WebSpider'
  1740. */
  1741. var $bot_list = array(
  1742. 'AdsBot [Google]' => array('AdsBot-Google', ''),
  1743. 'Alexa [Bot]' => array('ia_archiver', ''),
  1744. 'Alta Vista [Bot]' => array('Scooter/', ''),
  1745. 'Ask Jeeves [Bot]' => array('Ask Jeeves', ''),
  1746. 'Baidu [Spider]' => array('Baiduspider+(', ''),
  1747. 'Bing [Bot]' => array('bingbot/', ''),
  1748. 'Exabot [Bot]' => array('Exabot/', ''),
  1749. 'FAST Enterprise [Crawler]' => array('FAST Enterprise Crawler', ''),
  1750. 'FAST WebCrawler [Crawler]' => array('FAST-WebCrawler/', ''),
  1751. 'Francis [Bot]' => array('http://www.neomo.de/', ''),
  1752. 'Gigabot [Bot]' => array('Gigabot/', ''),
  1753. 'Google Adsense [Bot]' => array('Mediapartners-Google', ''),
  1754. 'Google Desktop' => array('Google Desktop', ''),
  1755. 'Google Feedfetcher' => array('Feedfetcher-Google', ''),
  1756. 'Google [Bot]' => array('Googlebot', ''),
  1757. 'Heise IT-Markt [Crawler]' => array('heise-IT-Markt-Crawler', ''),
  1758. 'Heritrix [Crawler]' => array('heritrix/1.', ''),
  1759. 'IBM Research [Bot]' => array('ibm.com/cs/crawler', ''),
  1760. 'ICCrawler - ICjobs' => array('ICCrawler - ICjobs', ''),
  1761. 'ichiro [Crawler]' => array('ichiro/', ''),
  1762. 'Majestic-12 [Bot]' => array('MJ12bot/', ''),
  1763. 'Metager [Bot]' => array('MetagerBot/', ''),
  1764. 'MSN NewsBlogs' => array('msnbot-NewsBlogs/', ''),
  1765. 'MSN [Bot]' => array('msnbot/', ''),
  1766. 'MSNbot Media' => array('msnbot-media/', ''),
  1767. 'NG-Search [Bot]' => array('NG-Search/', ''),
  1768. 'Nutch [Bot]' => array('http://lucene.apache.org/nutch/', ''),
  1769. 'Nutch/CVS [Bot]' => array('NutchCVS/', ''),
  1770. 'OmniExplorer [Bot]' => array('OmniExplorer_Bot/', ''),
  1771. 'Online link [Validator]' => array('online link validator', ''),
  1772. 'psbot [Picsearch]' => array('psbot/0', ''),
  1773. 'Seekport [Bot]' => array('Seekbot/', ''),
  1774. 'Sensis [Crawler]' => array('Sensis Web Crawler', ''),
  1775. 'SEO Crawler' => array('SEO search Crawler/', ''),
  1776. 'Seoma [Crawler]' => array('Seoma [SEO Crawler]', ''),
  1777. 'SEOSearch [Crawler]' => array('SEOsearch/', ''),
  1778. 'Snappy [Bot]' => array('Snappy/1.1 ( http://www.urltrends.com/ )', ''),
  1779. 'Steeler [Crawler]' => array('http://www.tkl.iis.u-tokyo.ac.jp/~crawler/', ''),
  1780. 'Synoo [Bot]' => array('SynooBot/', ''),
  1781. 'Telekom [Bot]' => array('crawleradmin.t-info@telekom.de', ''),
  1782. 'TurnitinBot [Bot]' => array('TurnitinBot/', ''),
  1783. 'Voyager [Bot]' => array('voyager/1.0', ''),
  1784. 'W3 [Sitesearch]' => array('W3 SiteSearch Crawler', ''),
  1785. 'W3C [Linkcheck]' => array('W3C-checklink/', ''),
  1786. 'W3C [Validator]' => array('W3C_*Validator', ''),
  1787. 'WiseNut [Bot]' => array('http://www.WISEnutbot.com', ''),
  1788. 'YaCy [Bot]' => array('yacybot', ''),
  1789. 'Yahoo MMCrawler [Bot]' => array('Yahoo-MMCrawler/', ''),
  1790. 'Yahoo Slurp [Bot]' => array('Yahoo! DE Slurp', ''),
  1791. 'Yahoo [Bot]' => array('Yahoo! Slurp', ''),
  1792. 'YahooSeeker [Bot]' => array('YahooSeeker/', ''),
  1793. );
  1794. /**
  1795. * Define the module structure so that we can populate the database without
  1796. * needing to hard-code module_id values
  1797. */
  1798. var $module_categories = array(
  1799. 'acp' => array(
  1800. 'ACP_CAT_GENERAL' => array(
  1801. 'ACP_QUICK_ACCESS',
  1802. 'ACP_BOARD_CONFIGURATION',
  1803. 'ACP_CLIENT_COMMUNICATION',
  1804. 'ACP_SERVER_CONFIGURATION',
  1805. ),
  1806. 'ACP_CAT_FORUMS' => array(
  1807. 'ACP_MANAGE_FORUMS',
  1808. 'ACP_FORUM_BASED_PERMISSIONS',
  1809. ),
  1810. 'ACP_CAT_POSTING' => array(
  1811. 'ACP_MESSAGES',
  1812. 'ACP_ATTACHMENTS',
  1813. ),
  1814. 'ACP_CAT_USERGROUP' => array(
  1815. 'ACP_CAT_USERS',
  1816. 'ACP_GROUPS',
  1817. 'ACP_USER_SECURITY',
  1818. ),
  1819. 'ACP_CAT_PERMISSIONS' => array(
  1820. 'ACP_GLOBAL_PERMISSIONS',
  1821. 'ACP_FORUM_BASED_PERMISSIONS',
  1822. 'ACP_PERMISSION_ROLES',
  1823. 'ACP_PERMISSION_MASKS',
  1824. ),
  1825. 'ACP_CAT_STYLES' => array(
  1826. 'ACP_STYLE_MANAGEMENT',
  1827. 'ACP_STYLE_COMPONENTS',
  1828. ),
  1829. 'ACP_CAT_MAINTENANCE' => array(
  1830. 'ACP_FORUM_LOGS',
  1831. 'ACP_CAT_DATABASE',
  1832. ),
  1833. 'ACP_CAT_SYSTEM' => array(
  1834. 'ACP_AUTOMATION',
  1835. 'ACP_GENERAL_TASKS',
  1836. 'ACP_MODULE_MANAGEMENT',
  1837. ),
  1838. 'ACP_CAT_DOT_MODS' => null,
  1839. ),
  1840. 'mcp' => array(
  1841. 'MCP_MAIN' => null,
  1842. 'MCP_QUEUE' => null,
  1843. 'MCP_REPORTS' => null,
  1844. 'MCP_NOTES' => null,
  1845. 'MCP_WARN' => null,
  1846. 'MCP_LOGS' => null,
  1847. 'MCP_BAN' => null,
  1848. ),
  1849. 'ucp' => array(
  1850. 'UCP_MAIN' => null,
  1851. 'UCP_PROFILE' => null,
  1852. 'UCP_PREFS' => null,
  1853. 'UCP_PM' => null,
  1854. 'UCP_USERGROUPS' => null,
  1855. 'UCP_ZEBRA' => null,
  1856. ),
  1857. );
  1858. var $module_extras = array(
  1859. 'acp' => array(
  1860. 'ACP_QUICK_ACCESS' => array(
  1861. 'ACP_MANAGE_USERS',
  1862. 'ACP_GROUPS_MANAGE',
  1863. 'ACP_MANAGE_FORUMS',
  1864. 'ACP_MOD_LOGS',
  1865. 'ACP_BOTS',
  1866. 'ACP_PHP_INFO',
  1867. ),
  1868. 'ACP_FORUM_BASED_PERMISSIONS' => array(
  1869. 'ACP_FORUM_PERMISSIONS',
  1870. 'ACP_FORUM_PERMISSIONS_COPY',
  1871. 'ACP_FORUM_MODERATORS',
  1872. 'ACP_USERS_FORUM_PERMISSIONS',
  1873. 'ACP_GROUPS_FORUM_PERMISSIONS',
  1874. ),
  1875. ),
  1876. );
  1877. }
  1878. ?>