PageRenderTime 53ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/install/install.php

https://github.com/Arantor/Elkarte
PHP | 2597 lines | 2029 code | 309 blank | 259 comment | 354 complexity | 335fc139fb3c695b37d92dc462ecc333 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. /**
  3. * @name ElkArte Forum
  4. * @copyright ElkArte Forum contributors
  5. * @license BSD http://opensource.org/licenses/BSD-3-Clause
  6. *
  7. * This software is a derived product, based on:
  8. *
  9. * Simple Machines Forum (SMF)
  10. * copyright: 2011 Simple Machines (http://www.simplemachines.org)
  11. * license: BSD, See included LICENSE.TXT for terms and conditions.
  12. *
  13. * @version 1.0 Alpha
  14. *
  15. */
  16. $GLOBALS['current_version'] = '1.0 Alpha';
  17. $GLOBALS['db_script_version'] = '1-0';
  18. $GLOBALS['required_php_version'] = '5.1.0';
  19. // Don't have PHP support, do you?
  20. // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
  21. // Database info.
  22. $databases = array(
  23. 'mysql' => array(
  24. 'name' => 'MySQL',
  25. 'version' => '4.1.0',
  26. 'version_check' => 'return min(mysql_get_server_info(), mysql_get_client_info());',
  27. 'supported' => function_exists('mysql_connect'),
  28. 'default_user' => 'mysql.default_user',
  29. 'default_password' => 'mysql.default_password',
  30. 'default_host' => 'mysql.default_host',
  31. 'default_port' => 'mysql.default_port',
  32. 'utf8_support' => true,
  33. 'utf8_version' => '4.1.0',
  34. 'utf8_version_check' => 'return mysql_get_server_info();',
  35. 'alter_support' => true,
  36. 'validate_prefix' => create_function('&$value', '
  37. $value = preg_replace(\'~[^A-Za-z0-9_\$]~\', \'\', $value);
  38. return true;
  39. '),
  40. ),
  41. 'postgresql' => array(
  42. 'name' => 'PostgreSQL',
  43. 'version' => '8.0',
  44. 'function_check' => 'pg_connect',
  45. 'version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
  46. 'supported' => function_exists('pg_connect'),
  47. 'always_has_db' => true,
  48. 'utf8_support' => true,
  49. 'utf8_version' => '8.0',
  50. 'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
  51. 'validate_prefix' => create_function('&$value', '
  52. $value = preg_replace(\'~[^A-Za-z0-9_\$]~\', \'\', $value);
  53. // Is it reserved?
  54. if ($value == \'pg_\')
  55. return $txt[\'error_db_prefix_reserved\'];
  56. // Is the prefix numeric?
  57. if (preg_match(\'~^\d~\', $value))
  58. return $txt[\'error_db_prefix_numeric\'];
  59. return true;
  60. '),
  61. ),
  62. 'sqlite' => array(
  63. 'name' => 'SQLite',
  64. 'version' => '1',
  65. 'function_check' => 'sqlite_open',
  66. 'version_check' => 'return 1;',
  67. 'supported' => function_exists('sqlite_open'),
  68. 'always_has_db' => true,
  69. 'utf8_support' => false,
  70. 'validate_prefix' => create_function('&$value', '
  71. global $incontext, $txt;
  72. $value = preg_replace(\'~[^A-Za-z0-9_\$]~\', \'\', $value);
  73. // Is it reserved?
  74. if ($value == \'sqlite_\')
  75. return $txt[\'error_db_prefix_reserved\'];
  76. // Is the prefix numeric?
  77. if (preg_match(\'~^\d~\', $value))
  78. return $txt[\'error_db_prefix_numeric\'];
  79. return true;
  80. '),
  81. ),
  82. );
  83. // Initialize everything and load the language files.
  84. initialize_inputs();
  85. load_lang_file();
  86. // This is what we are.
  87. $installurl = $_SERVER['PHP_SELF'];
  88. // This is where home is.
  89. $oursite = 'http://www.elkarte.net/';
  90. // All the steps in detail.
  91. // Number,Name,Function,Progress Weight.
  92. $incontext['steps'] = array(
  93. 0 => array(1, $txt['install_step_welcome'], 'action_welcome', 0),
  94. 1 => array(2, $txt['install_step_writable'], 'action_checkFilesWritable', 10),
  95. 2 => array(3, $txt['install_step_databaseset'], 'action_databaseSettings', 15),
  96. 3 => array(4, $txt['install_step_forum'], 'action_forumSettings', 40),
  97. 4 => array(5, $txt['install_step_databasechange'], 'action_databasePopulation', 15),
  98. 5 => array(6, $txt['install_step_admin'], 'action_adminAccount', 20),
  99. 6 => array(7, $txt['install_step_delete'], 'action_deleteInstall', 0),
  100. );
  101. // Default title...
  102. $incontext['page_title'] = $txt['installer'];
  103. // What step are we on?
  104. $incontext['current_step'] = isset($_GET['step']) ? (int) $_GET['step'] : 0;
  105. // Loop through all the steps doing each one as required.
  106. $incontext['overall_percent'] = 0;
  107. foreach ($incontext['steps'] as $num => $step)
  108. {
  109. if ($num >= $incontext['current_step'])
  110. {
  111. // The current weight of this step in terms of overall progress.
  112. $incontext['step_weight'] = $step[3];
  113. // Make sure we reset the skip button.
  114. $incontext['skip'] = false;
  115. // Call the step and if it returns false that means pause!
  116. if (function_exists($step[2]) && $step[2]() === false)
  117. break;
  118. elseif (function_exists($step[2]))
  119. $incontext['current_step']++;
  120. // No warnings pass on.
  121. $incontext['warning'] = '';
  122. }
  123. $incontext['overall_percent'] += $step[3];
  124. }
  125. // Actually do the template stuff.
  126. installExit();
  127. /**
  128. * Initialization step. Called at each request.
  129. * It either sets up variables for other steps, or handle a few requests on its own.
  130. */
  131. function initialize_inputs()
  132. {
  133. global $databases, $incontext;
  134. // Just so people using older versions of PHP aren't left in the cold.
  135. if (!isset($_SERVER['PHP_SELF']))
  136. $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
  137. // Turn off magic quotes runtime and enable error reporting.
  138. if (function_exists('set_magic_quotes_runtime'))
  139. @set_magic_quotes_runtime(0);
  140. error_reporting(E_ALL);
  141. // Fun. Low PHP version...
  142. if (!isset($_GET))
  143. {
  144. $GLOBALS['_GET']['step'] = 0;
  145. return;
  146. }
  147. if (!isset($_GET['obgz']))
  148. {
  149. ob_start();
  150. if (ini_get('session.save_handler') == 'user')
  151. @ini_set('session.save_handler', 'files');
  152. if (function_exists('session_start'))
  153. @session_start();
  154. }
  155. else
  156. {
  157. ob_start('ob_gzhandler');
  158. if (ini_get('session.save_handler') == 'user')
  159. @ini_set('session.save_handler', 'files');
  160. session_start();
  161. if (!headers_sent())
  162. echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  163. <html xmlns="http://www.w3.org/1999/xhtml">
  164. <head>
  165. <title>', htmlspecialchars($_GET['pass_string']), '</title>
  166. </head>
  167. <body style="background-color: #d4d4d4; margin-top: 16%; text-align: center; font-size: 16pt;">
  168. <strong>', htmlspecialchars($_GET['pass_string']), '</strong>
  169. </body>
  170. </html>';
  171. exit;
  172. }
  173. // Are we calling the backup css file?
  174. if (isset($_GET['infile_css']))
  175. {
  176. header('Content-Type: text/css');
  177. template_css();
  178. exit;
  179. }
  180. // Add slashes, as long as they aren't already being added.
  181. if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
  182. {
  183. foreach ($_POST as $k => $v)
  184. if (strpos($k, 'password') === false)
  185. $_POST[$k] = addslashes($v);
  186. }
  187. // This is really quite simple; if ?delete is on the URL, delete the installer...
  188. if (isset($_GET['delete']))
  189. action_deleteInstaller();
  190. // PHP 5 might cry if we don't do this now.
  191. if (function_exists('date_default_timezone_set'))
  192. {
  193. $server_offset = @mktime(0, 0, 0, 1, 1, 1970);
  194. date_default_timezone_set('Etc/GMT' . ($server_offset > 0 ? '+' : '') . ($server_offset / 3600));
  195. }
  196. // Force an integer step, defaulting to 0.
  197. $_GET['step'] = isset($_GET['step']) ? (int) $_GET['step'] : 0;
  198. }
  199. /**
  200. * Load the list of language files, and the current language file.
  201. */
  202. function load_lang_file()
  203. {
  204. global $txt, $incontext;
  205. $incontext['detected_languages'] = array();
  206. // Make sure the languages directory actually exists.
  207. if (file_exists(dirname(__FILE__) . '/themes/default/languages'))
  208. {
  209. // Find all the "Install" language files in the directory.
  210. $dir = dir(dirname(__FILE__) . '/themes/default/languages');
  211. while ($entry = $dir->read())
  212. {
  213. if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
  214. $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
  215. }
  216. $dir->close();
  217. }
  218. // Didn't find any, show an error message!
  219. if (empty($incontext['detected_languages']))
  220. {
  221. // Let's not cache this message, eh?
  222. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  223. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  224. header('Cache-Control: no-cache');
  225. echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  226. <html xmlns="http://www.w3.org/1999/xhtml">
  227. <head>
  228. <title>Installer: Error!</title>
  229. </head>
  230. <body style="font-family: sans-serif;">
  231. <div style="width: 600px;">
  232. <h1 style="font-size: 14pt;">A critical error has occurred.</h1>
  233. <p>This installer was unable to find the installer\'s language file or files. They should be found under:</p>
  234. <div style="margin: 1ex; font-family: monospace; font-weight: bold;">', dirname($_SERVER['PHP_SELF']) != '/' ? dirname($_SERVER['PHP_SELF']) : '', '/themes/default/languages</div>
  235. <p>In some cases, FTP clients do not properly upload files with this many folders. Please double check to make sure you <span style="font-weight: 600;">have uploaded all the files in the distribution</span>.</p>
  236. <p>If that doesn\'t help, please make sure this install.php file is in the same place as the themes folder.</p>
  237. <p>If you continue to get this error message, feel free to <a href="http://www.elkarte.net/">look to us for support</a>.</p>
  238. </div>
  239. </body>
  240. </html>';
  241. die;
  242. }
  243. // Override the language file?
  244. if (isset($_GET['lang_file']))
  245. $_SESSION['installer_temp_lang'] = $_GET['lang_file'];
  246. elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
  247. $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
  248. // Make sure it exists, if it doesn't reset it.
  249. if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/themes/default/languages/' . $_SESSION['installer_temp_lang']))
  250. {
  251. // Use the first one...
  252. list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
  253. // If we have english and some other language, use the other language. We Americans hate english :P.
  254. if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
  255. list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
  256. }
  257. // And now include the actual language file itself.
  258. require_once(dirname(__FILE__) . '/themes/default/languages/' . $_SESSION['installer_temp_lang']);
  259. }
  260. /**
  261. * This handy function loads some settings and the like.
  262. */
  263. function load_database()
  264. {
  265. global $db_prefix, $db_connection, $db_character_set, $language;
  266. global $smcFunc, $mbname, $scripturl, $boardurl, $modSettings, $db_type, $db_name, $db_user;
  267. if (!defined('SOURCEDIR'))
  268. define('SOURCEDIR', dirname(__FILE__) . '/sources');
  269. // Need this to check whether we need the database password.
  270. require(dirname(__FILE__) . '/Settings.php');
  271. if (!defined('ELKARTE'))
  272. define('ELKARTE', 1);
  273. if (empty($smcFunc))
  274. $smcFunc = array();
  275. $modSettings['disableQueryCheck'] = true;
  276. // Connect the database.
  277. if (!$db_connection)
  278. {
  279. require_once(SOURCEDIR . '/database/Db-' . $db_type . '.subs.php');
  280. if (!$db_connection)
  281. $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('persist' => $db_persist));
  282. }
  283. }
  284. /**
  285. * This is called upon exiting the installer, for template etc.
  286. * @param bool $fallThrough
  287. */
  288. function installExit($fallThrough = false)
  289. {
  290. global $incontext, $installurl, $txt;
  291. // Send character set.
  292. header('Content-Type: text/html; charset=UTF-8');
  293. // We usually dump our templates out.
  294. if (!$fallThrough)
  295. {
  296. // The top install bit.
  297. template_install_above();
  298. // Call the template.
  299. if (isset($incontext['sub_template']))
  300. {
  301. $incontext['form_url'] = $installurl . '?step=' . $incontext['current_step'];
  302. call_user_func('template_' . $incontext['sub_template']);
  303. }
  304. // @todo REMOVE THIS!!
  305. else
  306. {
  307. if (function_exists('doStep' . $_GET['step']))
  308. call_user_func('doStep' . $_GET['step']);
  309. }
  310. // Show the footer.
  311. template_install_below();
  312. }
  313. // Bang - gone!
  314. die();
  315. }
  316. /**
  317. * Welcome screen.
  318. * It makes a few basic checks for compatibility
  319. * and informs the user if there are problems.
  320. */
  321. function action_welcome()
  322. {
  323. global $incontext, $txt, $databases, $installurl;
  324. $incontext['page_title'] = $txt['install_welcome'];
  325. $incontext['sub_template'] = 'welcome_message';
  326. // Done the submission?
  327. if (isset($_POST['contbutt']))
  328. return true;
  329. // Check the PHP version.
  330. if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>')))
  331. {
  332. $incontext['warning'] = $txt['error_php_too_low'];
  333. }
  334. // See if we think they have already installed it?
  335. if (is_readable(dirname(__FILE__) . '/Settings.php'))
  336. {
  337. $probably_installed = 0;
  338. foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
  339. {
  340. if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
  341. $probably_installed++;
  342. if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/elkarte\';~', $line))
  343. $probably_installed++;
  344. }
  345. if ($probably_installed == 2)
  346. $incontext['warning'] = $txt['error_already_installed'];
  347. }
  348. // Is some database support even compiled in?
  349. $incontext['supported_databases'] = array();
  350. foreach ($databases as $key => $db)
  351. {
  352. if ($db['supported'])
  353. {
  354. if (!file_exists(dirname(__FILE__) . '/install_' . $GLOBALS['db_script_version'] . '_' . $key . '.sql'))
  355. {
  356. $databases[$key]['supported'] = false;
  357. $notFoundSQLFile = true;
  358. $txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $key . '.sql');
  359. }
  360. else
  361. {
  362. $db_type = $key;
  363. $incontext['supported_databases'][] = $db;
  364. }
  365. }
  366. }
  367. if (empty($incontext['supported_databases']))
  368. $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
  369. // How about session support? Some crazy sysadmin remove it?
  370. elseif (!function_exists('session_start'))
  371. $error = 'error_session_missing';
  372. // Make sure they uploaded all the files.
  373. elseif (!file_exists(dirname(__FILE__) . '/index.php'))
  374. $error = 'error_missing_files';
  375. // Very simple check on the session.save_path for Windows.
  376. // @todo Move this down later if they don't use database-driven sessions?
  377. elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
  378. $error = 'error_session_save_path';
  379. // Since each of the three messages would look the same, anyway...
  380. if (isset($error))
  381. $incontext['error'] = $txt[$error];
  382. // Mod_security blocks everything that smells funny. Let us handle security.
  383. if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
  384. $incontext['error'] = $txt['error_mod_security'] . '<br /><br /><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
  385. return false;
  386. }
  387. /**
  388. * Verify and try to make writable the files and folders that need to be.
  389. */
  390. function action_checkFilesWritable()
  391. {
  392. global $txt, $incontext;
  393. $incontext['page_title'] = $txt['ftp_checking_writable'];
  394. $incontext['sub_template'] = 'chmod_files';
  395. $writable_files = array(
  396. 'attachments',
  397. 'avatars',
  398. 'cache',
  399. 'packages',
  400. 'packages/installed.list',
  401. 'smileys',
  402. 'themes',
  403. 'agreement.txt',
  404. 'Settings.php',
  405. 'Settings_bak.php',
  406. 'db_last_error.php'
  407. );
  408. foreach ($incontext['detected_languages'] as $lang => $temp)
  409. $extra_files[] = 'themes/default/languages/' . $lang;
  410. // With mod_security installed, we could attempt to fix it with .htaccess.
  411. if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
  412. $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
  413. $failed_files = array();
  414. // On linux, it's easy - just use is_writable!
  415. if (substr(__FILE__, 1, 2) != ':\\')
  416. {
  417. foreach ($writable_files as $file)
  418. {
  419. if (!is_writable(dirname(__FILE__) . '/' . $file))
  420. {
  421. @chmod(dirname(__FILE__) . '/' . $file, 0755);
  422. // Well, 755 hopefully worked... if not, try 777.
  423. if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
  424. $failed_files[] = $file;
  425. }
  426. }
  427. foreach ($extra_files as $file)
  428. @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
  429. }
  430. // Windows is trickier. Let's try opening for r+...
  431. else
  432. {
  433. foreach ($writable_files as $file)
  434. {
  435. // Folders can't be opened for write... but the index.php in them can ;)
  436. if (is_dir(dirname(__FILE__) . '/' . $file))
  437. $file .= '/index.php';
  438. // Funny enough, chmod actually does do something on windows - it removes the read only attribute.
  439. @chmod(dirname(__FILE__) . '/' . $file, 0777);
  440. $fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
  441. // Hmm, okay, try just for write in that case...
  442. if (!is_resource($fp))
  443. $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
  444. if (!is_resource($fp))
  445. $failed_files[] = $file;
  446. @fclose($fp);
  447. }
  448. foreach ($extra_files as $file)
  449. @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
  450. }
  451. $failure = count($failed_files) >= 1;
  452. if (!isset($_SERVER))
  453. return !$failure;
  454. // Put the list into context.
  455. $incontext['failed_files'] = $failed_files;
  456. // It's not going to be possible to use FTP on windows to solve the problem...
  457. if ($failure && substr(__FILE__, 1, 2) == ':\\')
  458. {
  459. $incontext['error'] = $txt['error_windows_chmod'] . '
  460. <ul style="margin: 2.5ex; font-family: monospace;">
  461. <li>' . implode('</li>
  462. <li>', $failed_files) . '</li>
  463. </ul>';
  464. return false;
  465. }
  466. // We're going to have to use... FTP!
  467. elseif ($failure)
  468. {
  469. // Load any session data we might have...
  470. if (!isset($_POST['ftp_username']) && isset($_SESSION['installer_temp_ftp']))
  471. {
  472. $_POST['ftp_server'] = $_SESSION['installer_temp_ftp']['server'];
  473. $_POST['ftp_port'] = $_SESSION['installer_temp_ftp']['port'];
  474. $_POST['ftp_username'] = $_SESSION['installer_temp_ftp']['username'];
  475. $_POST['ftp_password'] = $_SESSION['installer_temp_ftp']['password'];
  476. $_POST['ftp_path'] = $_SESSION['installer_temp_ftp']['path'];
  477. }
  478. $incontext['ftp_errors'] = array();
  479. if (isset($_POST['ftp_username']))
  480. {
  481. $ftp = new Ftp_Connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']);
  482. if ($ftp->error === false)
  483. {
  484. // Try it without /home/abc just in case they messed up.
  485. if (!$ftp->chdir($_POST['ftp_path']))
  486. {
  487. $incontext['ftp_errors'][] = $ftp->last_message;
  488. $ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $_POST['ftp_path']));
  489. }
  490. }
  491. }
  492. if (!isset($ftp) || $ftp->error !== false)
  493. {
  494. if (!isset($ftp))
  495. $ftp = new Ftp_Connection(null);
  496. // Save the error so we can mess with listing...
  497. elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
  498. $incontext['ftp_errors'][] = $ftp->last_message;
  499. list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
  500. if (empty($_POST['ftp_path']) && $found_path)
  501. $_POST['ftp_path'] = $detect_path;
  502. if (!isset($_POST['ftp_username']))
  503. $_POST['ftp_username'] = $username;
  504. // Set the username etc, into context.
  505. $incontext['ftp'] = array(
  506. 'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : 'localhost',
  507. 'port' => isset($_POST['ftp_port']) ? $_POST['ftp_port'] : '21',
  508. 'username' => isset($_POST['ftp_username']) ? $_POST['ftp_username'] : '',
  509. 'path' => isset($_POST['ftp_path']) ? $_POST['ftp_path'] : '/',
  510. 'path_msg' => !empty($found_path) ? $txt['ftp_path_found_info'] : $txt['ftp_path_info'],
  511. );
  512. return false;
  513. }
  514. else
  515. {
  516. $_SESSION['installer_temp_ftp'] = array(
  517. 'server' => $_POST['ftp_server'],
  518. 'port' => $_POST['ftp_port'],
  519. 'username' => $_POST['ftp_username'],
  520. 'password' => $_POST['ftp_password'],
  521. 'path' => $_POST['ftp_path']
  522. );
  523. $failed_files_updated = array();
  524. foreach ($failed_files as $file)
  525. {
  526. if (!is_writable(dirname(__FILE__) . '/' . $file))
  527. $ftp->chmod($file, 0755);
  528. if (!is_writable(dirname(__FILE__) . '/' . $file))
  529. $ftp->chmod($file, 0777);
  530. if (!is_writable(dirname(__FILE__) . '/' . $file))
  531. {
  532. $failed_files_updated[] = $file;
  533. $incontext['ftp_errors'][] = rtrim($ftp->last_message) . ' -> ' . $file . "\n";
  534. }
  535. }
  536. $ftp->close();
  537. // Are there any errors left?
  538. if (count($failed_files_updated) >= 1)
  539. {
  540. // Guess there are...
  541. $incontext['failed_files'] = $failed_files_updated;
  542. // Set the username etc, into context.
  543. $incontext['ftp'] = $_SESSION['installer_temp_ftp'] += array(
  544. 'path_msg' => $txt['ftp_path_info'],
  545. );
  546. return false;
  547. }
  548. }
  549. }
  550. return true;
  551. }
  552. /**
  553. * Ask for database settings, verify and save them.
  554. */
  555. function action_databaseSettings()
  556. {
  557. global $txt, $databases, $incontext, $smcFunc;
  558. $incontext['sub_template'] = 'database_settings';
  559. $incontext['page_title'] = $txt['db_settings'];
  560. $incontext['continue'] = 1;
  561. // Set up the defaults.
  562. $incontext['db']['server'] = 'localhost';
  563. $incontext['db']['user'] = '';
  564. $incontext['db']['name'] = '';
  565. $incontext['db']['pass'] = '';
  566. $incontext['db']['type'] = '';
  567. $incontext['supported_databases'] = array();
  568. $foundOne = false;
  569. foreach ($databases as $key => $db)
  570. {
  571. // Override with the defaults for this DB if appropriate.
  572. if ($db['supported'])
  573. {
  574. $incontext['supported_databases'][$key] = $db;
  575. if (!$foundOne)
  576. {
  577. if (isset($db['default_host']))
  578. $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
  579. if (isset($db['default_user']))
  580. {
  581. $incontext['db']['user'] = ini_get($db['default_user']);
  582. $incontext['db']['name'] = ini_get($db['default_user']);
  583. }
  584. if (isset($db['default_password']))
  585. $incontext['db']['pass'] = ini_get($db['default_password']);
  586. if (isset($db['default_port']))
  587. $db_port = ini_get($db['default_port']);
  588. $incontext['db']['type'] = $key;
  589. $foundOne = true;
  590. }
  591. }
  592. }
  593. // Override for repost.
  594. if (isset($_POST['db_user']))
  595. {
  596. $incontext['db']['user'] = $_POST['db_user'];
  597. $incontext['db']['name'] = $_POST['db_type'] == 'sqlite' && isset($_POST['db_filename']) ? $_POST['db_filename'] : $_POST['db_name'];
  598. $incontext['db']['server'] = $_POST['db_server'];
  599. $incontext['db']['prefix'] = $_POST['db_prefix'];
  600. }
  601. else
  602. {
  603. $incontext['db']['prefix'] = 'elkarte_';
  604. // Should we use a non standard port?
  605. if (!empty($db_port))
  606. $incontext['db']['server'] .= ':' . $db_port;
  607. }
  608. // Are we submitting?
  609. if (isset($_POST['db_type']))
  610. {
  611. if (isset($_POST['db_filename']))
  612. {
  613. // You better enter enter a database name for SQLite.
  614. if (trim($_POST['db_filename']) == '')
  615. {
  616. $incontext['error'] = $txt['error_db_filename'];
  617. return false;
  618. }
  619. // Duplicate name in the same dir? Can't do that with SQLite. Weird things happen.
  620. if (file_exists($_POST['db_filename'] . (substr($_POST['db_filename'], -3) != '.db' ? '.db' : '')))
  621. {
  622. $incontext['error'] = $txt['error_db_filename_exists'];
  623. return false;
  624. }
  625. }
  626. // What type are they trying?
  627. $db_type = preg_replace('~[^A-Za-z0-9]~', '', $_POST['db_type']);
  628. $db_prefix = $_POST['db_prefix'];
  629. // Validate the prefix.
  630. $valid_prefix = $databases[$db_type]['validate_prefix']($db_prefix);
  631. if ($valid_prefix !== true)
  632. {
  633. $incontext['error'] = $valid_prefix;
  634. return false;
  635. }
  636. // Take care of these variables...
  637. $vars = array(
  638. 'db_type' => $db_type,
  639. 'db_name' => $_POST['db_type'] == 'sqlite' && isset($_POST['db_filename']) ? $_POST['db_filename'] : $_POST['db_name'],
  640. 'db_user' => $_POST['db_user'],
  641. 'db_passwd' => isset($_POST['db_passwd']) ? $_POST['db_passwd'] : '',
  642. 'db_server' => $_POST['db_server'],
  643. 'db_prefix' => $db_prefix,
  644. // The cookiename is special; we want it to be the same if it ever needs to be reinstalled with the same info.
  645. 'cookiename' => 'ELKARTECookie' . abs(crc32($_POST['db_name'] . preg_replace('~[^A-Za-z0-9_$]~', '', $_POST['db_prefix'])) % 1000),
  646. );
  647. // God I hope it saved!
  648. if (!updateSettingsFile($vars) && substr(__FILE__, 1, 2) == ':\\')
  649. {
  650. $incontext['error'] = $txt['error_windows_chmod'];
  651. return false;
  652. }
  653. // Make sure it works.
  654. require(dirname(__FILE__) . '/Settings.php');
  655. if (!defined('SOURCEDIR'))
  656. define('SOURCEDIR', dirname(__FILE__) . '/sources');
  657. // Better find the database file!
  658. if (!file_exists(SOURCEDIR . '/database/Db-' . $db_type . '.subs.php'))
  659. {
  660. $incontext['error'] = sprintf($txt['error_db_file'], 'Db-' . $db_type . '.subs.php');
  661. return false;
  662. }
  663. // Now include it for database functions!
  664. define('ELKARTE', 1);
  665. $modSettings['disableQueryCheck'] = true;
  666. if (empty($smcFunc))
  667. $smcFunc = array();
  668. require_once(SOURCEDIR . '/database/Db-' . $db_type . '.subs.php');
  669. // Attempt a connection.
  670. $needsDB = !empty($databases[$db_type]['always_has_db']);
  671. $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true, 'dont_select_db' => !$needsDB));
  672. // No dice? Let's try adding the prefix they specified, just in case they misread the instructions ;)
  673. if ($db_connection == null)
  674. {
  675. $db_error = @$smcFunc['db_error']();
  676. $db_connection = smf_db_initiate($db_server, $db_name, $_POST['db_prefix'] . $db_user, $db_passwd, $db_prefix, array('non_fatal' => true, 'dont_select_db' => !$needsDB));
  677. if ($db_connection != null)
  678. {
  679. $db_user = $_POST['db_prefix'] . $db_user;
  680. updateSettingsFile(array('db_user' => $db_user));
  681. }
  682. }
  683. // Still no connection? Big fat error message :P.
  684. if (!$db_connection)
  685. {
  686. $incontext['error'] = $txt['error_db_connect'] . '<div style="margin: 2.5ex; font-family: monospace;"><strong>' . $db_error . '</strong></div>';
  687. return false;
  688. }
  689. // Do they meet the install requirements?
  690. // @todo Old client, new server?
  691. if (version_compare($databases[$db_type]['version'], preg_replace('~^\D*|\-.+?$~', '', eval($databases[$db_type]['version_check']))) > 0)
  692. {
  693. $incontext['error'] = $txt['error_db_too_low'];
  694. return false;
  695. }
  696. // Let's try that database on for size... assuming we haven't already lost the opportunity.
  697. if ($db_name != '' && !$needsDB)
  698. {
  699. $smcFunc['db_query']('', "
  700. CREATE DATABASE IF NOT EXISTS `$db_name`",
  701. array(
  702. 'security_override' => true,
  703. 'db_error_skip' => true,
  704. ),
  705. $db_connection
  706. );
  707. // Okay, let's try the prefix if it didn't work...
  708. if (!$smcFunc['db_select_db']($db_name, $db_connection) && $db_name != '')
  709. {
  710. $smcFunc['db_query']('', "
  711. CREATE DATABASE IF NOT EXISTS `$_POST[db_prefix]$db_name`",
  712. array(
  713. 'security_override' => true,
  714. 'db_error_skip' => true,
  715. ),
  716. $db_connection
  717. );
  718. if ($smcFunc['db_select_db']($_POST['db_prefix'] . $db_name, $db_connection))
  719. {
  720. $db_name = $_POST['db_prefix'] . $db_name;
  721. updateSettingsFile(array('db_name' => $db_name));
  722. }
  723. }
  724. // Okay, now let's try to connect...
  725. if (!$smcFunc['db_select_db']($db_name, $db_connection))
  726. {
  727. $incontext['error'] = sprintf($txt['error_db_database'], $db_name);
  728. return false;
  729. }
  730. }
  731. return true;
  732. }
  733. return false;
  734. }
  735. /**
  736. * Basic forum type settings.
  737. */
  738. function action_forumSettings()
  739. {
  740. global $txt, $incontext, $databases, $smcFunc, $db_connection, $db_type;
  741. $incontext['sub_template'] = 'forum_settings';
  742. $incontext['page_title'] = $txt['install_settings'];
  743. // Let's see if we got the database type correct.
  744. if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
  745. $db_type = $_POST['db_type'];
  746. // Else we'd better be able to get the connection.
  747. else
  748. load_database();
  749. $db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
  750. // What host and port are we on?
  751. $host = empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
  752. // Now, to put what we've learned together... and add a path.
  753. $incontext['detected_url'] = 'http' . (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
  754. // Check if the database sessions will even work.
  755. $incontext['test_dbsession'] = ini_get('session.auto_start') != 1;
  756. $incontext['continue'] = 1;
  757. // Submitting?
  758. if (isset($_POST['boardurl']))
  759. {
  760. if (substr($_POST['boardurl'], -10) == '/index.php')
  761. $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
  762. elseif (substr($_POST['boardurl'], -1) == '/')
  763. $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
  764. if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
  765. $_POST['boardurl'] = 'http://' . $_POST['boardurl'];
  766. // Save these variables.
  767. $vars = array(
  768. 'boardurl' => $_POST['boardurl'],
  769. 'boarddir' => addslashes(dirname(__FILE__)),
  770. 'sourcedir' => addslashes(dirname(__FILE__)) . '/sources',
  771. 'cachedir' => addslashes(dirname(__FILE__)) . '/cache',
  772. 'mbname' => strtr($_POST['mbname'], array('\"' => '"')),
  773. 'language' => substr($_SESSION['installer_temp_lang'], 8, -4),
  774. 'extdir' => addslashes(dirname(__FILE__)) . '/sources/subs',
  775. );
  776. // Must save!
  777. if (!updateSettingsFile($vars) && substr(__FILE__, 1, 2) == ':\\')
  778. {
  779. $incontext['error'] = $txt['error_windows_chmod'];
  780. return false;
  781. }
  782. // Make sure it works.
  783. require(dirname(__FILE__) . '/Settings.php');
  784. // UTF-8 requires a setting to override any language charset.
  785. if (!empty($databases[$db_type]['utf8_version_check']) && version_compare($databases[$db_type]['utf8_version'], preg_replace('~\-.+?$~', '', eval($databases[$db_type]['utf8_version_check'])), '>'))
  786. {
  787. // our uft-8 check support on the db failed ....
  788. $incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
  789. return false;
  790. }
  791. else
  792. // Set our db character_set to utf8
  793. updateSettingsFile(array('db_character_set' => 'utf8'));
  794. // Good, skip on.
  795. return true;
  796. }
  797. return false;
  798. }
  799. /**
  800. * Step one. Populate database.
  801. */
  802. function action_databasePopulation()
  803. {
  804. global $db_character_set, $txt, $db_connection, $smcFunc, $databases, $modSettings, $db_type, $db_prefix, $incontext, $db_name, $boardurl;
  805. $incontext['sub_template'] = 'populate_database';
  806. $incontext['page_title'] = $txt['db_populate'];
  807. $incontext['continue'] = 1;
  808. // Already done?
  809. if (isset($_POST['pop_done']))
  810. return true;
  811. // Reload settings.
  812. require(dirname(__FILE__) . '/Settings.php');
  813. load_database();
  814. // Before running any of the queries, let's make sure another version isn't already installed.
  815. $result = $smcFunc['db_query']('', '
  816. SELECT variable, value
  817. FROM {db_prefix}settings',
  818. array(
  819. 'db_error_skip' => true,
  820. )
  821. );
  822. $modSettings = array();
  823. if ($result !== false)
  824. {
  825. while ($row = $smcFunc['db_fetch_assoc']($result))
  826. $modSettings[$row['variable']] = $row['value'];
  827. $smcFunc['db_free_result']($result);
  828. // Do they match? If so, this is just a refresh so charge on!
  829. if (!isset($modSettings['elkVersion']) || $modSettings['elkVersion'] != $GLOBALS['current_version'])
  830. {
  831. $incontext['error'] = $txt['error_versions_do_not_match'];
  832. return false;
  833. }
  834. }
  835. $modSettings['disableQueryCheck'] = true;
  836. // Since we are UTF8, select it. PostgreSQL requires passing it as a string...
  837. $smcFunc['db_query']('', '
  838. SET NAMES {'. ($db_type == 'postgresql' ? 'string' : 'raw') . ':utf8}',
  839. array(
  840. 'db_error_skip' => true,
  841. 'utf8' => 'utf8',
  842. )
  843. );
  844. $replaces = array(
  845. '{$db_prefix}' => $db_prefix,
  846. '{BOARDDIR}' => $smcFunc['db_escape_string'](dirname(__FILE__)),
  847. '{$boardurl}' => $boardurl,
  848. '{$enableCompressedOutput}' => isset($_POST['compress']) ? '1' : '0',
  849. '{$databaseSession_enable}' => isset($_POST['dbsession']) ? '1' : '0',
  850. '{$current_version}' => $GLOBALS['current_version'],
  851. '{$current_time}' => time(),
  852. '{$sched_task_offset}' => 82800 + mt_rand(0, 86399),
  853. );
  854. foreach ($txt as $key => $value)
  855. {
  856. if (substr($key, 0, 8) == 'default_')
  857. $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
  858. }
  859. $replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
  860. // If the UTF-8 setting was enabled, add it to the table definitions.
  861. if (!empty($databases[$db_type]['utf8_support']))
  862. $replaces[') ENGINE=MyISAM;'] = ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;';
  863. // Read in the SQL. Turn this on and that off... internationalize... etc.
  864. $sql_lines = explode("\n", strtr(implode(' ', file(dirname(__FILE__) . '/install_' . $GLOBALS['db_script_version'] . '_' . $db_type . '.sql')), $replaces));
  865. // Execute the SQL.
  866. $current_statement = '';
  867. $exists = array();
  868. $incontext['failures'] = array();
  869. $incontext['sql_results'] = array(
  870. 'tables' => 0,
  871. 'inserts' => 0,
  872. 'table_dups' => 0,
  873. 'insert_dups' => 0,
  874. );
  875. foreach ($sql_lines as $count => $line)
  876. {
  877. // No comments allowed!
  878. if (substr(trim($line), 0, 1) != '#')
  879. $current_statement .= "\n" . rtrim($line);
  880. // Is this the end of the query string?
  881. if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
  882. continue;
  883. // Does this table already exist? If so, don't insert more data into it!
  884. if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
  885. {
  886. $incontext['sql_results']['insert_dups']++;
  887. $current_statement = '';
  888. continue;
  889. }
  890. if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
  891. {
  892. // Error 1050: Table already exists!
  893. // @todo Needs to be made better!
  894. if (($db_type != 'mysql' || mysql_errno($db_connection) === 1050) && preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
  895. {
  896. $exists[] = $match[1];
  897. $incontext['sql_results']['table_dups']++;
  898. }
  899. // Don't error on duplicate indexes (or duplicate operators in PostgreSQL.)
  900. elseif (!preg_match('~^\s*CREATE( UNIQUE)? INDEX ([^\n\r]+?)~', $current_statement, $match) && !($db_type == 'postgresql' && preg_match('~^\s*CREATE OPERATOR (^\n\r]+?)~', $current_statement, $match)))
  901. {
  902. $incontext['failures'][$count] = $smcFunc['db_error']();
  903. }
  904. }
  905. else
  906. {
  907. if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
  908. $incontext['sql_results']['tables']++;
  909. else
  910. {
  911. preg_match_all('~\)[,;]~', $current_statement, $matches);
  912. if (!empty($matches[0]))
  913. $incontext['sql_results']['inserts'] += count($matches[0]);
  914. else
  915. $incontext['sql_results']['inserts']++;
  916. }
  917. }
  918. $current_statement = '';
  919. }
  920. // Sort out the context for the SQL.
  921. foreach ($incontext['sql_results'] as $key => $number)
  922. {
  923. if ($number == 0)
  924. unset($incontext['sql_results'][$key]);
  925. else
  926. $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
  927. }
  928. // Make sure UTF will be used globally.
  929. $smcFunc['db_insert']('replace',
  930. $db_prefix . 'settings',
  931. array(
  932. 'variable' => 'string-255', 'value' => 'string-65534',
  933. ),
  934. array(
  935. 'global_character_set', 'UTF-8',
  936. ),
  937. array('variable')
  938. );
  939. // Maybe we can auto-detect better cookie settings?
  940. preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
  941. if (!empty($matches))
  942. {
  943. // Default = both off.
  944. $localCookies = false;
  945. $globalCookies = false;
  946. // Okay... let's see. Using a subdomain other than www.? (not a perfect check.)
  947. if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
  948. $globalCookies = true;
  949. // If there's a / in the middle of the path, or it starts with ~... we want local.
  950. if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
  951. $localCookies = true;
  952. if ($globalCookies)
  953. $rows[] = array('globalCookies', '1');
  954. if ($localCookies)
  955. $rows[] = array('localCookies', '1');
  956. if (!empty($rows))
  957. {
  958. $smcFunc['db_insert']('replace',
  959. $db_prefix . 'settings',
  960. array('variable' => 'string-255', 'value' => 'string-65534'),
  961. $rows,
  962. array('variable')
  963. );
  964. }
  965. }
  966. // As of PHP 5.1, setting a timezone is required.
  967. if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
  968. {
  969. $server_offset = mktime(0, 0, 0, 1, 1, 1970);
  970. $timezone_id = 'Etc/GMT' . ($server_offset > 0 ? '+' : '') . ($server_offset / 3600);
  971. if (date_default_timezone_set($timezone_id))
  972. $smcFunc['db_insert']('',
  973. $db_prefix . 'settings',
  974. array(
  975. 'variable' => 'string-255', 'value' => 'string-65534',
  976. ),
  977. array(
  978. 'default_timezone', $timezone_id,
  979. ),
  980. array('variable')
  981. );
  982. }
  983. // Let's optimize those new tables.
  984. db_extend();
  985. $tables = $smcFunc['db_list_tables']($db_name, $db_prefix . '%');
  986. foreach ($tables as $table)
  987. {
  988. $smcFunc['db_optimize_table']($table) != -1 or $db_messed = true;
  989. // Optimizing one sqlite table, optimizes them all
  990. if ($db_type == 'sqlite')
  991. break;
  992. if (!empty($db_messed))
  993. {
  994. $incontext['failures'][-1] = $smcFunc['db_error']();
  995. break;
  996. }
  997. }
  998. // Check for the ALTER privilege.
  999. if (!empty($databases[$db_type]['alter_support']) && $smcFunc['db_query']('', "ALTER TABLE {$db_prefix}boards ORDER BY id_board", array('security_override' => true, 'db_error_skip' => true)) === false)
  1000. {
  1001. $incontext['error'] = $txt['error_db_alter_priv'];
  1002. return false;
  1003. }
  1004. if (!empty($exists))
  1005. {
  1006. $incontext['page_title'] = $txt['user_refresh_install'];
  1007. $incontext['was_refresh'] = true;
  1008. }
  1009. return false;
  1010. }
  1011. /**
  1012. * Ask for the administrator login information.
  1013. */
  1014. function action_adminAccount()
  1015. {
  1016. global $txt, $db_type, $db_connection, $databases, $smcFunc, $incontext, $db_prefix, $db_passwd;
  1017. $incontext['sub_template'] = 'admin_account';
  1018. $incontext['page_title'] = $txt['user_settings'];
  1019. $incontext['continue'] = 1;
  1020. // Skipping?
  1021. if (!empty($_POST['skip']))
  1022. return true;
  1023. // Need this to check whether we need the database password.
  1024. require(dirname(__FILE__) . '/Settings.php');
  1025. load_database();
  1026. if (!isset($_POST['username']))
  1027. $_POST['username'] = '';
  1028. if (!isset($_POST['email']))
  1029. $_POST['email'] = '';
  1030. $incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
  1031. $incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
  1032. $incontext['require_db_confirm'] = empty($db_type) || $db_type != 'sqlite';
  1033. // Only allow skipping if we think they already have an account setup.
  1034. $request = $smcFunc['db_query']('', '
  1035. SELECT id_member
  1036. FROM {db_prefix}members
  1037. WHERE id_group = {int:admin_group} OR FIND_IN_SET({int:admin_group}, additional_groups) != 0
  1038. LIMIT 1',
  1039. array(
  1040. 'db_error_skip' => true,
  1041. 'admin_group' => 1,
  1042. )
  1043. );
  1044. if ($smcFunc['db_num_rows']($request) != 0)
  1045. $incontext['skip'] = 1;
  1046. $smcFunc['db_free_result']($request);
  1047. // Trying to create an account?
  1048. if (isset($_POST['password1']) && !empty($_POST['contbutt']))
  1049. {
  1050. // Wrong password?
  1051. if ($incontext['require_db_confirm'] && $_POST['password3'] != $db_passwd)
  1052. {
  1053. $incontext['error'] = $txt['error_db_connect'];
  1054. return false;
  1055. }
  1056. // Not matching passwords?
  1057. if ($_POST['password1'] != $_POST['password2'])
  1058. {
  1059. $incontext['error'] = $txt['error_user_settings_again_match'];
  1060. return false;
  1061. }
  1062. // No password?
  1063. if (strlen($_POST['password1']) < 4)
  1064. {
  1065. $incontext['error'] = $txt['error_user_settings_no_password'];
  1066. return false;
  1067. }
  1068. if (!file_exists(SOURCEDIR . '/Subs.php'))
  1069. {
  1070. $incontext['error'] = $txt['error_subs_missing'];
  1071. return false;
  1072. }
  1073. // Update the main contact email?
  1074. if (!empty($_POST['email']) && (empty($webmaster_email) || $webmaster_email == 'noreply@myserver.com'))
  1075. updateSettingsFile(array('webmaster_email' => $_POST['email']));
  1076. // Work out whether we're going to have dodgy characters and remove them.
  1077. $invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
  1078. $_POST['username'] = preg_replace('~[<>&"\'=\\\]~', '', $_POST['username']);
  1079. $result = $smcFunc['db_query']('', '
  1080. SELECT id_member, password_salt
  1081. FROM {db_prefix}members
  1082. WHERE member_name = {string:username} OR email_address = {string:email}
  1083. LIMIT 1',
  1084. array(
  1085. 'username' => stripslashes($_POST['username']),
  1086. 'email' => stripslashes($_POST['email']),
  1087. 'db_error_skip' => true,
  1088. )
  1089. );
  1090. if ($smcFunc['db_num_rows']($result) != 0)
  1091. {
  1092. list ($incontext['member_id'], $incontext['member_salt']) = $smcFunc['db_fetch_row']($result);
  1093. $smcFunc['db_free_result']($result);
  1094. $incontext['account_existed'] = $txt['error_user_settings_taken'];
  1095. }
  1096. elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
  1097. {
  1098. // Try the previous step again.
  1099. $incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
  1100. return false;
  1101. }
  1102. elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
  1103. {
  1104. // Try the previous step again.
  1105. $incontext['error'] = $txt['error_invalid_characters_username'];
  1106. return false;
  1107. }
  1108. elseif (empty($_POST['email']) || preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', stripslashes($_POST['email'])) === 0 || strlen(stripslashes($_POST['email'])) > 255)
  1109. {
  1110. // One step back, this time fill out a proper email address.
  1111. $incontext['error'] = sprintf($txt['error_valid_email_needed'], $_POST['username']);
  1112. return false;
  1113. }
  1114. elseif ($_POST['username'] != '')
  1115. {
  1116. $incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
  1117. // Format the username properly.
  1118. $_POST['username'] = preg_replace('~[\t\n\r\x0B\0\xA0]+~', ' ', $_POST['username']);
  1119. $ip = isset($_SERVER['REMOTE_ADDR']) ? substr($_SERVER['REMOTE_ADDR'], 0, 255) : '';
  1120. $request = $smcFunc['db_insert']('',
  1121. $db_prefix . 'members',
  1122. array(
  1123. 'member_name' => 'string-25', 'real_name' => 'string-25', 'passwd' => 'string', 'email_address' => 'string',
  1124. 'id_group' => 'int', 'posts' => 'int', 'date_registered' => 'int', 'hide_email' => 'int',
  1125. 'password_salt' => 'string', 'lngfile' => 'string', 'personal_text' => 'string', 'avatar' => 'string',
  1126. 'member_ip' => 'string', 'member_ip2' => 'string', 'buddy_list' => 'string', 'pm_ignore_list' => 'string',
  1127. 'message_labels' => 'string', 'website_title' => 'string', 'website_url' => 'string', 'location' => 'string',
  1128. 'signature' => 'string', 'usertitle' => 'string', 'secret_question' => 'string',
  1129. 'additional_groups' => 'string', 'ignore_boards' => 'string', 'openid_uri' => 'string',
  1130. ),
  1131. array(
  1132. stripslashes($_POST['username']), stripslashes($_POST['username']), sha1(strtolower(stripslashes($_POST['username'])) . stripslashes($_POST['password1'])), stripslashes($_POST['email']),
  1133. 1, 0, time(), 0,
  1134. $incontext['member_salt'], '', '', '',
  1135. $ip, $ip, '', '',
  1136. '', '', '', '',
  1137. '', '', '',
  1138. '', '', '',
  1139. ),
  1140. array('id_member')
  1141. );
  1142. // Awww, crud!
  1143. if ($request === false)
  1144. {
  1145. $incontext['error'] = $txt['error_user_settings_query'] . '<br />
  1146. <div style="margin: 2ex;">' . nl2br(htmlspecialchars($smcFunc['db_error']($db_connection))) . '</div>';
  1147. return false;
  1148. }
  1149. $incontext['member_id'] = $smcFunc['db_insert_id']("{$db_prefix}members", 'id_member');
  1150. }
  1151. // If we're here we're good.
  1152. return true;
  1153. }
  1154. return false;
  1155. }
  1156. /**
  1157. * Final step, clean up and a complete message!
  1158. */
  1159. function action_deleteInstall()
  1160. {
  1161. global $txt, $db_prefix, $db_connection, $HTTP_SESSION_VARS, $cookiename, $incontext;
  1162. global $smcFunc, $db_character_set, $mbname, $context, $scripturl, $boardurl;
  1163. global $current_version, $databases, $forum_version, $modSettings, $user_info, $language, $db_type;
  1164. $incontext['page_title'] = $txt['congratulations'];
  1165. $incontext['sub_template'] = 'delete_install';
  1166. $incontext['continue'] = 0;
  1167. require(dirname(__FILE__) . '/Settings.php');
  1168. load_database();
  1169. if (!defined('SUBSDIR'))
  1170. define('SUBSDIR', dirname(__FILE__) . '/sources/subs');
  1171. chdir(dirname(__FILE__));
  1172. require_once(SOURCEDIR . '/Errors.php');
  1173. require_once(SOURCEDIR . '/Logging.php');
  1174. require_once(SOURCEDIR . '/Subs.php');
  1175. require_once(SOURCEDIR . '/Load.php');
  1176. require_once(SUBSDIR . '/Cache.subs.php');
  1177. require_once(SOURCEDIR . '/Security.php');
  1178. require_once(SUBSDIR . '/Auth.subs.php');
  1179. // Bring a warning over.
  1180. if (!empty($incontext['account_existed']))
  1181. $incontext['warning'] = $incontext['account_existed'];
  1182. if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
  1183. $smcFunc['db_query']('', '
  1184. SET NAMES {raw:db_character_set}',
  1185. array(
  1186. 'db_character_set' => $db_character_set,
  1187. 'db_error_skip' => true,
  1188. )
  1189. );
  1190. // As track stats is by default enabled let's add some activity.
  1191. $smcFunc['db_insert']('ignore',
  1192. '{db_prefix}log_activity',
  1193. array('date' => 'date', 'topics' => 'int', 'posts' => 'int', 'registers' => 'int'),
  1194. array(strftime('%Y-%m-%d', time()), 1, 1, (!empty($incontext['member_id']) ? 1 : 0)),
  1195. array('date')
  1196. );
  1197. // We're going to want our lovely $modSettings now.
  1198. $request = $smcFunc['db_query']('', '
  1199. SELECT variable, value
  1200. FROM {db_prefix}settings',
  1201. array(
  1202. 'db_error_skip' => true,
  1203. )
  1204. );
  1205. // Only proceed if we can load the data.
  1206. if ($request)
  1207. {
  1208. while ($row = $smcFunc['db_fetch_row']($request))
  1209. $modSettings[$row[0]] = $row[1];
  1210. $smcFunc['db_free_result']($request);
  1211. }
  1212. // Automatically log them in ;)
  1213. if (isset($incontext['member_id']) && isset($incontext['member_salt']))
  1214. setLoginCookie(3153600 * 60, $incontext['member_id'], sha1(sha1(strtolower($_POST['username']) . $_POST['password1']) . $incontext['member_salt']));
  1215. $result = $smcFunc['db_query']('', '
  1216. SELECT value
  1217. FROM {db_prefix}settings
  1218. WHERE variable = {string:db_sessions}',
  1219. array(
  1220. 'db_sessions' => 'databaseSession_enable',
  1221. 'db_error_skip' => true,
  1222. )
  1223. );
  1224. if ($smcFunc['db_num_rows']($result) != 0)
  1225. list ($db_sessions) = $smcFunc['db_fetch_row']($result);
  1226. $smcFunc['db_free_result']($result);
  1227. if (empty($db_sessions))
  1228. $_SESSION['admin_time'] = time();
  1229. else
  1230. {
  1231. $_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
  1232. $smcFunc['db_insert']('replace',
  1233. '{db_prefix}sessions',
  1234. array(
  1235. 'session_id' => 'string', 'last_update' => 'int', 'data' => 'string',
  1236. ),
  1237. array(
  1238. session_id(), time(), 'USER_AGENT|s:' . strlen($_SERVER['HTTP_USER_AGENT']) . ':"' . $_SERVER['HTTP_USER_AGENT'] . '";admin_time|i:' . time() . ';',
  1239. ),
  1240. array('session_id')
  1241. );
  1242. }
  1243. updateStats('member');
  1244. updateStats('message');
  1245. updateStats('topic');
  1246. // This function is needed to do the updateStats('subject') call.
  1247. $smcFunc['strtolower'] = create_function('$string', '
  1248. return $string;');
  1249. $request = $smcFunc['db_query']('', '
  1250. SELECT id_msg
  1251. FROM {db_prefix}messages
  1252. WHERE id_msg = 1
  1253. AND modified_time = 0
  1254. LIMIT 1',
  1255. array(
  1256. 'db_error_skip' => true,
  1257. )
  1258. );
  1259. if ($smcFunc['db_num_rows']($request) > 0)
  1260. updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
  1261. $smcFunc['db_free_result']($request);
  1262. // Now is the perfect time to fetch the SM files.
  1263. require_once(SOURCEDIR . '/ScheduledTasks.php');
  1264. // Sanity check that they loaded earlier!
  1265. if (isset($modSettings['recycle_board']))
  1266. {
  1267. // The variable is usually defined in index.php so lets just use our variable to do it for us.
  1268. $forum_version = $current_version;
  1269. // Now go get those files!
  1270. scheduled_fetchFiles();
  1271. // We've just installed!
  1272. $user_info['ip'] = $_SERVER['REMOTE_ADDR'];
  1273. $user_info['id'] = isset($incontext['member_id']) ? $incontext['member_id'] : 0;
  1274. logAction('install', array('version' => $forum_version), 'admin');
  1275. }
  1276. // Check if we need some stupid MySQL fix.
  1277. $server_version = $smcFunc['db_server_info']();
  1278. if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
  1279. updateSettings(array('db_mysql_group_by_fix' => '1'));
  1280. // Some final context for the template.
  1281. $incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
  1282. $incontext['probably_delete_install'] = isset($_SESSION['installer_temp_ftp']) || is_writable(dirname(__FILE__)) || is_writable(__FILE__);
  1283. return false;
  1284. }
  1285. /**
  1286. * FTP connection class.
  1287. * The installer will try to use this when it needs writable files
  1288. * and it fails to make them writable otherwise.
  1289. *
  1290. * Credit: http://www.faqs.org/rfcs/rfc959.html
  1291. */
  1292. class Ftp_Connection
  1293. {
  1294. var $connection = 'no_connection', $error = false, $last_message, $pasv = array();
  1295. // Create a new FTP connection...
  1296. function ftp_connection($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = 'ftpclient@yourdomain.org')
  1297. {
  1298. if ($ftp_server !== null)
  1299. $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass);
  1300. }
  1301. function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = 'ftpclient@yourdomain.org')
  1302. {
  1303. if (substr($ftp_server, 0, 6) == 'ftp://')
  1304. $ftp_server = substr($ftp_server, 6);
  1305. elseif (substr($ftp_server, 0, 7) == 'ftps://')
  1306. $ftp_server = 'ssl://' . substr($ftp_server, 7);
  1307. if (substr($ftp_server, 0, 7) == 'http://')
  1308. $ftp_server = substr($ftp_server, 7);
  1309. $ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => ''));
  1310. // Connect to the FTP server.
  1311. $this->connection = @fsockopen($ftp_server, $ftp_port, $err, $err, 5);
  1312. if (!$this->connection)
  1313. {
  1314. $this->error = 'bad_server';
  1315. return;
  1316. }
  1317. // Get the welcome message...
  1318. if (!$this->check_response(220))
  1319. {
  1320. $this->error = 'bad_response';
  1321. return;
  1322. }
  1323. // Send the username, it should ask for a password.
  1324. fwrite($this->connection, 'USER ' . $ftp_user . "\r\n");
  1325. if (!$this->check_response(331))
  1326. {
  1327. $this->error = 'bad_username';
  1328. return;
  1329. }
  1330. // Now send the password... and hope it goes okay.
  1331. fwrite($this->connection, 'PASS ' . $ftp_pass . "\r\n");
  1332. if (!$this->check_response(230))
  1333. {
  1334. $this->error = 'bad_password';
  1335. return;
  1336. }
  1337. }
  1338. function chdir($ftp_path)
  1339. {
  1340. if (!is_resource($this->connection))
  1341. return false;
  1342. // No slash on the end, please...
  1343. if (substr($ftp_path, -1) == '/')
  1344. $ftp_path = substr($ftp_path, 0, -1);
  1345. fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n");
  1346. if (!$this->check_response(250))
  1347. {
  1348. $this->error = 'bad_path';
  1349. return false;
  1350. }
  1351. return true;
  1352. }
  1353. function chmod($ftp_file, $chmod)
  1354. {
  1355. if (!is_resource($this->connection))
  1356. return false;
  1357. // Convert the chmod value from octal (0777) to text ("777")
  1358. fwrite($this->connection, 'SITE CHMOD ' . decoct($chmod) . ' ' . $ftp_file . "\r\n");
  1359. if (!$this->check_response(200))
  1360. {
  1361. $this->error = 'bad_file';
  1362. return false;
  1363. }
  1364. return true;
  1365. }
  1366. function unlink($ftp_file)
  1367. {
  1368. // We are actually connected, right?
  1369. if (!is_resource($this->connection))
  1370. return false;
  1371. // Delete file X.
  1372. fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n");
  1373. if (!$this->check_response(250))
  1374. {
  1375. fwrite($this->connection, 'RMD ' . $ftp_file . "\r\n");
  1376. // Still no love?
  1377. if (!$this->check_response(250))
  1378. {
  1379. $this->error = 'bad_file';
  1380. return false;
  1381. }
  1382. }
  1383. return true;
  1384. }
  1385. function check_response($desired)
  1386. {
  1387. // Wait for a response that isn't continued with -, but don't wait too long.
  1388. $time = time();
  1389. do
  1390. $this->last_message = fgets($this->connection, 1024);
  1391. while (substr($this->last_message, 3, 1) != ' ' && time() - $time < 5);
  1392. // Was the desired response returned?
  1393. return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired;
  1394. }
  1395. function passive()
  1396. {
  1397. // We can't create a passive data connection without a primary one first being there.
  1398. if (!is_resource($this->connection))
  1399. return false;
  1400. // Request a passive connection - this means, we'll talk to you, you don't talk to us.
  1401. @fwrite($this->connection, "PASV\r\n");
  1402. $time = time();
  1403. do
  1404. $response = fgets($this->connection, 1024);
  1405. while (substr($response, 3, 1) != ' ' && time() - $time < 5);
  1406. // If it's not 227, we weren't given an IP and port, which means it failed.
  1407. if (substr($response, 0, 4) != '227 ')
  1408. {
  1409. $this->error = 'bad_response';
  1410. return false;
  1411. }
  1412. // Snatch the IP and port information, or die horribly trying...
  1413. if (preg_match('~\((\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))\)~', $response, $match) == 0)
  1414. {
  1415. $this->error = 'bad_response';
  1416. return false;
  1417. }
  1418. // This is pretty simple - store it for later use ;)
  1419. $this->pasv = array('ip' => $match[1] . '.' . $match[2] . '.' . $match[3] . '.' . $match[4], 'port' => $match[5] * 256 + $match[6]);
  1420. return true;
  1421. }
  1422. function create_file($ftp_file)
  1423. {
  1424. // First, we have to be connected... very important.
  1425. if (!is_resource($this->connection))
  1426. return false;
  1427. // I'd like one passive mode, please!
  1428. if (!$this->passive())
  1429. return false;
  1430. // Seems logical enough, so far...
  1431. fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n");
  1432. // Okay, now we connect to the data port. If it doesn't work out, it's probably "file already exists", etc.
  1433. $fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5);
  1434. if (!$fp || !$this->check_response(150))
  1435. {
  1436. $this->error = 'bad_file';
  1437. @fclose($fp);
  1438. return false;
  1439. }
  1440. // This may look strange, but we're just closing it to indicate a zero-byte upload.
  1441. fclose($fp);
  1442. if (!$this->check_response(226))
  1443. {
  1444. $this->error = 'bad_response';
  1445. return false;
  1446. }
  1447. return true;
  1448. }
  1449. function list_dir($ftp_path = '', $search = false)
  1450. {
  1451. // Are we even connected...?
  1452. if (!is_resource($this->connection))
  1453. return false;
  1454. // Passive... non-agressive...
  1455. if (!$this->passive())
  1456. return false;
  1457. // Get the listing!
  1458. fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n");
  1459. // Connect, assuming we've got a connection.
  1460. $fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5);
  1461. if (!$fp || !$this->check_response(array(150, 125)))
  1462. {
  1463. $this->error = 'bad_response';
  1464. @fclose($fp);
  1465. return false;
  1466. }
  1467. // Read in the file listing.
  1468. $data = '';
  1469. while (!feof($fp))
  1470. $data .= fread($fp, 4096);
  1471. fclose($fp);
  1472. // Everything go okay?
  1473. if (!$this->check_response(226))
  1474. {
  1475. $this->error = 'bad_response';
  1476. return false;
  1477. }
  1478. return $data;
  1479. }
  1480. function locate($file, $listing = null)
  1481. {
  1482. if ($listing === null)
  1483. $listing = $this->list_dir('', true);
  1484. $listing = explode("\n", $listing);
  1485. @fwrite($this->connection, "PWD\r\n");
  1486. $time = time();
  1487. do
  1488. $response = fgets($this->connection, 1024);
  1489. while (substr($response, 3, 1) != ' ' && time() - $time < 5);
  1490. // Check for 257!
  1491. if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0)
  1492. $current_dir = strtr($match[1], array('""' => '"'));
  1493. else
  1494. $current_dir = '';
  1495. for ($i = 0, $n = count($listing); $i < $n; $i++)
  1496. {
  1497. if (trim($listing[$i]) == '' && isset($listing[$i + 1]))
  1498. {
  1499. $current_dir = substr(trim($listing[++$i]), 0, -1);
  1500. $i++;
  1501. }
  1502. // Okay, this file's name is:
  1503. $listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]);
  1504. if (substr($file, 0, 1) == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1))
  1505. return $listing[$i];
  1506. if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1))
  1507. return $listing[$i];
  1508. if (basename($listing[$i]) == $file || $listing[$i] == $file)
  1509. return $listing[$i];
  1510. }
  1511. return false;
  1512. }
  1513. function create_dir($ftp_dir)
  1514. {
  1515. // We must be connected to the server to do something.
  1516. if (!is_resource($this->connection))
  1517. return false;
  1518. // Make this new beautiful directory!
  1519. fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n");
  1520. if (!$this->check_response(257))
  1521. {
  1522. $this->error = 'bad_file';
  1523. return false;
  1524. }
  1525. return true;
  1526. }
  1527. function detect_path($filesystem_path, $lookup_file = null)
  1528. {
  1529. $username = '';
  1530. if (isset($_SERVER['DOCUMENT_ROOT']))
  1531. {
  1532. if (preg_match('~^/home[2]?/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match))
  1533. {
  1534. $username = $match[1];
  1535. $path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => ''));
  1536. if (substr($path, -1) == '/')
  1537. $path = substr($path, 0, -1);
  1538. if (strlen(dirname($_SERVER['PHP_SELF'])) > 1)
  1539. $path .= dirname($_SERVER['PHP_SELF']);
  1540. }
  1541. elseif (substr($filesystem_path, 0, 9) == '/var/www/')
  1542. $path = substr($filesystem_path, 8);
  1543. else
  1544. $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => ''));
  1545. }
  1546. else
  1547. $path = '';
  1548. if (is_resource($this->connection) && $this->list_dir($path) == '')
  1549. {
  1550. $data = $this->list_dir('', true);
  1551. if ($lookup_file === null)
  1552. $lookup_file = $_SERVER['PHP_SELF'];
  1553. $found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data));
  1554. if ($found_path == false)
  1555. $found_path = dirname($this->locate(basename($lookup_file)));
  1556. if ($found_path != false)
  1557. $path = $found_path;
  1558. }
  1559. elseif (is_resource($this->connection))
  1560. $found_path = true;
  1561. return array($username, $path, isset($found_path));
  1562. }
  1563. function close()
  1564. {
  1565. // Goodbye!
  1566. fwrite($this->connection, "QUIT\r\n");
  1567. fclose($this->connection);
  1568. return true;
  1569. }
  1570. }
  1571. /**
  1572. * Write out the contents of Settings.php file.
  1573. * This function will add the variables passed to it in $vars,
  1574. * to the Settings.php file.
  1575. *
  1576. * @param array $vars the configuration variables to write out.
  1577. */
  1578. function updateSettingsFile($vars)
  1579. {
  1580. // Modify Settings.php.
  1581. $settingsArray = file(dirname(__FILE__) . '/Settings.php');
  1582. // @todo Do we just want to read the file in clean, and split it this way always?
  1583. if (count($settingsArray) == 1)
  1584. $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
  1585. for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
  1586. {
  1587. // Remove the redirect...
  1588. if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 3]) == '}')
  1589. {
  1590. // Get the four lines to nothing.
  1591. $settingsArray[$i] = '';
  1592. $settingsArray[++$i] = '';
  1593. $settingsArray[++$i] = '';
  1594. $settingsArray[++$i] = '';
  1595. continue;
  1596. }
  1597. // Don't trim or bother with it if it's not a variable.
  1598. if (substr($settingsArray[$i], 0, 1) != '$')
  1599. continue;
  1600. $settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
  1601. foreach ($vars as $var => $val)
  1602. if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
  1603. {
  1604. $comment = strstr($settingsArray[$i], '#');
  1605. $settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
  1606. unset($vars[$var]);
  1607. }
  1608. }
  1609. // Uh oh... the file wasn't empty... was it?
  1610. if (!empty($vars))
  1611. {
  1612. $settingsArray[$i++] = '';
  1613. foreach ($vars as $var => $val)
  1614. $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
  1615. }
  1616. // Blank out the file - done to fix a oddity with some servers.
  1617. $fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
  1618. if (!$fp)
  1619. return false;
  1620. fclose($fp);
  1621. $fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
  1622. // Gotta have one of these ;)
  1623. if (trim($settingsArray[0]) != '<?php')
  1624. fwrite($fp, "<?php\n");
  1625. $lines = count($settingsArray);
  1626. for ($i = 0; $i < $lines; $i++)
  1627. {
  1628. // Don't just write a bunch of blank lines.
  1629. if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
  1630. fwrite($fp, strtr($settingsArray[$i], "\r", ''));
  1631. }
  1632. fclose($fp);
  1633. return true;
  1634. }
  1635. /**
  1636. * Write the db_last_error file.
  1637. */
  1638. function updateDbLastError()
  1639. {
  1640. // Write out the db_last_error file with the error timestamp
  1641. file_put_contents(dirname(__FILE__) . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;');
  1642. return true;
  1643. }
  1644. /**
  1645. * Create an .htaccess file to prevent mod_security.
  1646. * Elkarte has filtering built-in.
  1647. */
  1648. function fixModSecurity()
  1649. {
  1650. $htaccess_addition = '
  1651. <IfModule mod_security.c>
  1652. # Turn off mod_security filtering. We don\'t need our hands held.
  1653. SecFilterEngine Off
  1654. # The below probably isn\'t needed, but better safe than sorry.
  1655. SecFilterScanPOST Off
  1656. </IfModule>';
  1657. if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
  1658. return true;
  1659. elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
  1660. {
  1661. $current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
  1662. // Only change something if mod_security hasn't been addressed yet.
  1663. if (strpos($current_htaccess, '<IfModule mod_security.c>') === false)
  1664. {
  1665. if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'a'))
  1666. {
  1667. fwrite($ht_handle, $htaccess_addition);
  1668. fclose($ht_handle);
  1669. return true;
  1670. }
  1671. else
  1672. return false;
  1673. }
  1674. else
  1675. return true;
  1676. }
  1677. elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
  1678. return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
  1679. elseif (is_writable(dirname(__FILE__)))
  1680. {
  1681. if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
  1682. {
  1683. fwrite($ht_handle, $htaccess_addition);
  1684. fclose($ht_handle);
  1685. return true;
  1686. }
  1687. else
  1688. return false;
  1689. }
  1690. else
  1691. return false;
  1692. }
  1693. /**
  1694. * Delete the installer and its additional files.
  1695. * Called by ?delete
  1696. */
  1697. function action_deleteInstaller()
  1698. {
  1699. if (isset($_SESSION['installer_temp_ftp']))
  1700. {
  1701. $ftp = new Ftp_Connection($_SESSION['installer_temp_ftp']['server'], $_SESSION['installer_temp_ftp']['port'], $_SESSION['installer_temp_ftp']['username'], $_SESSION['installer_temp_ftp']['password']);
  1702. $ftp->chdir($_SESSION['installer_temp_ftp']['path']);
  1703. $ftp->unlink('install.php');
  1704. $ftp->unlink('webinstall.php');
  1705. foreach ($databases as $key => $dummy)
  1706. $ftp->unlink('install_' . $GLOBALS['db_script_version'] . '_' . $key . '.sql');
  1707. $ftp->close();
  1708. unset($_SESSION['installer_temp_ftp']);
  1709. }
  1710. else
  1711. {
  1712. @unlink(__FILE__);
  1713. @unlink(dirname(__FILE__) . '/webinstall.php');
  1714. foreach ($databases as $key => $dummy)
  1715. @unlink(dirname(__FILE__) . '/install_' . $GLOBALS['db_script_version'] . '_' . $key . '.sql');
  1716. }
  1717. // Now just redirect to a blank.png...
  1718. header('Location: http://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/themes/default/images/blank.png');
  1719. exit;
  1720. }
  1721. function template_install_above()
  1722. {
  1723. global $incontext, $txt, $oursite, $installurl;
  1724. echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  1725. <html xmlns="http://www.w3.org/1999/xhtml"', !empty($txt['lang_rtl']) ? ' dir="rtl"' : '', '>
  1726. <head>
  1727. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  1728. <meta name="robots" content="noindex" />
  1729. <title>', $txt['installer'], '</title>
  1730. <link rel="stylesheet" type="text/css" href="themes/default/css/index.css?alp10" />
  1731. <link rel="stylesheet" type="text/css" href="themes/default/css/install.css?alp10" />
  1732. <script type="text/javascript" src="themes/default/scripts/script.js"></script>
  1733. </head>
  1734. <body>
  1735. <div id="header">
  1736. <div class="frame">
  1737. <h1 class="forumtitle">', $txt['installer'], '</h1>
  1738. <img id="logo" src="themes/default/images/logo.png" alt="Elkarte Community" title="Elkarte Community" />
  1739. </div>
  1740. </div>
  1741. <div id="wrapper">
  1742. <div id="upper_section">
  1743. <div id="inner_section">
  1744. <div id="inner_wrap">';
  1745. // Have we got a language drop down - if so do it on the first step only.
  1746. if (!empty($incontext['detected_languages']) && count($incontext['detected_languages']) > 1 && $incontext['current_step'] == 0)
  1747. {
  1748. echo '
  1749. <div class="news">
  1750. <form action="', $installurl, '" method="get">
  1751. <label for="installer_language">', $txt['installer_language'], ':</label>
  1752. <select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
  1753. foreach ($incontext['detected_languages'] as $lang => $name)
  1754. echo '
  1755. <option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected="selected"' : '', ' value="', $lang, '">', $name, '</option>';
  1756. echo '
  1757. </select>
  1758. <noscript><input type="submit" value="', $txt['installer_language_set'], '" class="button_submit" /></noscript>
  1759. </form>
  1760. </div>
  1761. <hr class="clear" />';
  1762. }
  1763. echo '
  1764. </div>
  1765. </div>
  1766. </div>
  1767. <div id="content_section">
  1768. <div id="main_content_section">
  1769. <div id="main_steps">
  1770. <h2>', $txt['upgrade_progress'], '</h2>
  1771. <ul>';
  1772. foreach ($incontext['steps'] as $num => $step)
  1773. echo '
  1774. <li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
  1775. echo '
  1776. </ul>
  1777. </div>
  1778. <div id="progress_bar">
  1779. <div id="overall_text">', $incontext['overall_percent'], '%</div>
  1780. <div id="overall_progress" style="width: ', $incontext['overall_percent'], '%;">&nbsp;</div>
  1781. <div class="overall_progress">', $txt['upgrade_overall_progress'], '</div>
  1782. </div>
  1783. <div id="main_screen" class="clear">
  1784. <h2>', $incontext['page_title'], '</h2>
  1785. <div class="panel">';
  1786. }
  1787. function template_install_below()
  1788. {
  1789. global $incontext, $txt;
  1790. if (!empty($incontext['continue']) || !empty($incontext['skip']))
  1791. {
  1792. echo '
  1793. <div class="clear">';
  1794. if (!empty($incontext['continue']))
  1795. echo '
  1796. <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
  1797. if (!empty($incontext['skip']))
  1798. echo '
  1799. <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
  1800. echo '
  1801. </div>';
  1802. }
  1803. // Show the closing form tag and other data only if not in the last step
  1804. if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
  1805. echo '
  1806. </form>';
  1807. echo '
  1808. </div>
  1809. </div>
  1810. </div>
  1811. </div>
  1812. </div>
  1813. <div id="footer_section">
  1814. <div class="frame">
  1815. <ul class="reset">
  1816. <li class="copyright"><a href="http://www.elkarte.net/" title="Elkarte Community" target="_blank" class="new_win">Elkarte &copy; 2012, Elkarte Community</a></li>
  1817. </ul>
  1818. </div>
  1819. </div>
  1820. </body>
  1821. </html>';
  1822. }
  1823. /**
  1824. * Welcome them to the wonderful world of Elkarte!
  1825. */
  1826. function template_welcome_message()
  1827. {
  1828. global $incontext, $installurl, $txt;
  1829. echo '
  1830. <script type="text/javascript" src="http://www.spudsdesign.com/site/current-version.js?version=' . $GLOBALS['current_version'] . '"></script>
  1831. <form action="', $incontext['form_url'], '" method="post">
  1832. <p>', sprintf($txt['install_welcome_desc'], $GLOBALS['current_version']), '</p>
  1833. <div id="version_warning" style="margin: 2ex; padding: 2ex; border: 2px dashed #a92174; color: black; background-color: #fbbbe2; display: none;">
  1834. <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
  1835. <strong style="text-decoration: underline;">', $txt['error_warning_notice'], '</strong><br />
  1836. <div style="padding-left: 6ex;">
  1837. ', sprintf($txt['error_script_outdated'], '<em id="ourVersion" style="white-space: nowrap;">??</em>', '<em id="yourVersion" style="white-space: nowrap;">' . $GLOBALS['current_version'] . '</em>'), '
  1838. </div>
  1839. </div>';
  1840. // Show the warnings, or not.
  1841. if (template_warning_divs())
  1842. echo '
  1843. <h3>', $txt['install_all_lovely'], '</h3>';
  1844. // Say we want the continue button!
  1845. if (empty($incontext['error']))
  1846. $incontext['continue'] = 1;
  1847. // For the latest version stuff.
  1848. echo '
  1849. <script type="text/javascript"><!-- // --><![CDATA[
  1850. // Latest version?
  1851. function ourCurrentVersion()
  1852. {
  1853. var ourVer, yourVer;
  1854. if (!(\'ourVersion\' in window))
  1855. return;
  1856. window.ourVersion = window.ourVersion.replace(/ELKARTE\s?/g, \'\');
  1857. ourVer = document.getElementById("ourVersion");
  1858. yourVer = document.getElementById("yourVersion");
  1859. setInnerHTML(ourVer, window.ourVersion);
  1860. var currentVersion = getInnerHTML(yourVer);
  1861. if (currentVersion < window.ourVersion)
  1862. document.getElementById(\'version_warning\').style.display = \'\';
  1863. }
  1864. addLoadEvent(CurrentVersion);
  1865. // ]]></script>';
  1866. }
  1867. /**
  1868. * A shortcut for any warning stuff.
  1869. */
  1870. function template_warning_divs()
  1871. {
  1872. global $txt, $incontext;
  1873. // Errors are very serious..
  1874. if (!empty($incontext['error']))
  1875. echo '
  1876. <div class="errorbox">
  1877. <strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br />
  1878. <div>
  1879. ', $incontext['error'], '
  1880. </div>
  1881. </div>';
  1882. // A warning message?
  1883. elseif (!empty($incontext['warning']))
  1884. echo '
  1885. <div class="noticebox">
  1886. <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br />
  1887. <div>
  1888. ', $incontext['warning'], '
  1889. </div>
  1890. </div>';
  1891. return empty($incontext['error']) && empty($incontext['warning']);
  1892. }
  1893. function template_chmod_files()
  1894. {
  1895. global $txt, $incontext;
  1896. echo '
  1897. <p>', $txt['ftp_setup_why_info'], '</p>
  1898. <ul style="margin: 2.5ex; font-family: monospace;">
  1899. <li>', implode('</li>
  1900. <li>', $incontext['failed_files']), '</li>
  1901. </ul>';
  1902. // This is serious!
  1903. if (!template_warning_divs())
  1904. return;
  1905. echo '
  1906. <hr />
  1907. <p>', $txt['ftp_setup_info'], '</p>';
  1908. if (!empty($incontext['ftp_errors']))
  1909. echo '
  1910. <div class="errorbox">
  1911. <div style="color: red;">
  1912. ', $txt['error_ftp_no_connect'], '<br />
  1913. <br />
  1914. <code>', implode('<br />', $incontext['ftp_errors']), '</code>
  1915. </div>
  1916. </div>
  1917. <br />';
  1918. echo '
  1919. <form action="', $incontext['form_url'], '" method="post">
  1920. <table width="520" cellspacing="0" cellpadding="0" border="0" align="center" style="margin: 1em 0;">
  1921. <tr>
  1922. <td width="26%" valign="top" class="textbox"><label for="ftp_server">', $txt['ftp_server'], ':</label></td>
  1923. <td>
  1924. <div style="float: ', empty($txt['lang_rtl']) ? 'right' : 'left', '; margin-', empty($txt['lang_rtl']) ? 'right' : 'left', ': 1px;"><label for="ftp_port" class="textbox"><strong>', $txt['ftp_port'], ':&nbsp;</strong></label> <input type="text" size="3" name="ftp_port" id="ftp_port" value="', $incontext['ftp']['port'], '" class="input_text" /></div>
  1925. <input type="text" size="30" name="ftp_server" id="ftp_server" value="', $incontext['ftp']['server'], '" style="width: 70%;" class="input_text" />
  1926. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['ftp_server_info'], '</div>
  1927. </td>
  1928. </tr><tr>
  1929. <td width="26%" valign="top" class="textbox"><label for="ftp_username">', $txt['ftp_username'], ':</label></td>
  1930. <td>
  1931. <input type="text" size="50" name="ftp_username" id="ftp_username" value="', $incontext['ftp']['username'], '" style="width: 99%;" class="input_text" />
  1932. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['ftp_username_info'], '</div>
  1933. </td>
  1934. </tr><tr>
  1935. <td width="26%" valign="top" class="textbox"><label for="ftp_password">', $txt['ftp_password'], ':</label></td>
  1936. <td>
  1937. <input type="password" size="50" name="ftp_password" id="ftp_password" style="width: 99%;" class="input_password" />
  1938. <div style="font-size: smaller; margin-bottom: 3ex;">', $txt['ftp_password_info'], '</div>
  1939. </td>
  1940. </tr><tr>
  1941. <td width="26%" valign="top" class="textbox"><label for="ftp_path">', $txt['ftp_path'], ':</label></td>
  1942. <td style="padding-bottom: 1ex;">
  1943. <input type="text" size="50" name="ftp_path" id="ftp_path" value="', $incontext['ftp']['path'], '" style="width: 99%;" class="input_text" />
  1944. <div style="font-size: smaller; margin-bottom: 2ex;">', $incontext['ftp']['path_msg'], '</div>
  1945. </td>
  1946. </tr>
  1947. </table>
  1948. <div style="margin: 1ex; margin-top: 1ex; text-align: ', empty($txt['lang_rtl']) ? 'right' : 'left', ';"><input type="submit" value="', $txt['ftp_connect'], '" onclick="return submitThisOnce(this);" class="button_submit" /></div>
  1949. </form>
  1950. <a href="', $incontext['form_url'], '">', $txt['error_message_click'], '</a> ', $txt['ftp_setup_again'];
  1951. }
  1952. /**
  1953. * Template for the database settings form.
  1954. */
  1955. function template_database_settings()
  1956. {
  1957. global $incontext, $installurl, $txt;
  1958. echo '
  1959. <form action="', $incontext['form_url'], '" method="post">
  1960. <p>', $txt['db_settings_info'], '</p>';
  1961. template_warning_divs();
  1962. echo '
  1963. <table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin: 1em 0;">';
  1964. // More than one database type?
  1965. if (count($incontext['supported_databases']) > 1)
  1966. {
  1967. echo '
  1968. <tr>
  1969. <td width="20%" valign="top" class="textbox"><label for="db_type_input">', $txt['db_settings_type'], ':</label></td>
  1970. <td>
  1971. <select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
  1972. foreach ($incontext['supported_databases'] as $key => $db)
  1973. echo '
  1974. <option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected="selected"' : '', '>', $db['name'], '</option>';
  1975. echo '
  1976. </select><div id="db_sqlite_warning" style="color: blue; display: none;" class="smalltext">', $txt['db_sqlite_warning'], '</div>
  1977. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_type_info'], '</div>
  1978. </td>
  1979. </tr>';
  1980. }
  1981. else
  1982. {
  1983. echo '
  1984. <tr style="display: none;">
  1985. <td>
  1986. <input type="hidden" name="db_type" value="', $incontext['db']['type'], '" />
  1987. </td>
  1988. </tr>';
  1989. }
  1990. echo '
  1991. <tr id="db_server_contain">
  1992. <td width="20%" valign="top" class="textbox"><label for="db_server_input">', $txt['db_settings_server'], ':</label></td>
  1993. <td>
  1994. <input type="text" name="db_server" id="db_server_input" value="', $incontext['db']['server'], '" size="30" class="input_text" /><br />
  1995. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_server_info'], '</div>
  1996. </td>
  1997. </tr><tr id="db_user_contain">
  1998. <td valign="top" class="textbox"><label for="db_user_input">', $txt['db_settings_username'], ':</label></td>
  1999. <td>
  2000. <input type="text" name="db_user" id="db_user_input" value="', $incontext['db']['user'], '" size="30" class="input_text" /><br />
  2001. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_username_info'], '</div>
  2002. </td>
  2003. </tr><tr id="db_passwd_contain">
  2004. <td valign="top" class="textbox"><label for="db_passwd_input">', $txt['db_settings_password'], ':</label></td>
  2005. <td>
  2006. <input type="password" name="db_passwd" id="db_passwd_input" value="', $incontext['db']['pass'], '" size="30" class="input_password" /><br />
  2007. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_password_info'], '</div>
  2008. </td>
  2009. </tr><tr id="db_name_contain">
  2010. <td valign="top" class="textbox"><label for="db_name_input">', $txt['db_settings_database'], ':</label></td>
  2011. <td>
  2012. <input type="text" name="db_name" id="db_name_input" value="', empty($incontext['db']['name']) ? 'elkarte' : $incontext['db']['name'], '" size="30" class="input_text" /><br />
  2013. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_database_info'], '
  2014. <span id="db_name_info_warning">', $txt['db_settings_database_info_note'], '</span></div>
  2015. </td>
  2016. </tr><tr id="db_filename_contain" style="display: none;">
  2017. <td valign="top" class="textbox"><label for="db_filename_input">', $txt['db_settings_database_file'], ':</label></td>
  2018. <td>
  2019. <input type="text" name="db_filename" id="db_filename_input" value="', empty($incontext['db']['name']) ? dirname(__FILE__) . '/elkarte_' . substr(md5(microtime()), 0, 10) : stripslashes($incontext['db']['name']), '" size="30" class="input_text" /><br />
  2020. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_database_file_info'], '</div>
  2021. </td>
  2022. </tr><tr>
  2023. <td valign="top" class="textbox"><label for="db_prefix_input">', $txt['db_settings_prefix'], ':</label></td>
  2024. <td>
  2025. <input type="text" name="db_prefix" id="db_prefix_input" value="', $incontext['db']['prefix'], '" size="30" class="input_text" /><br />
  2026. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_prefix_info'], '</div>
  2027. </td>
  2028. </tr>
  2029. </table>';
  2030. // Allow the toggling of input boxes for SQLite etc.
  2031. echo '
  2032. <script type="text/javascript"><!-- // --><![CDATA[
  2033. function toggleDBInput()
  2034. {
  2035. // What state is it?';
  2036. if (!isset($incontext['supported_databases']['sqlite']))
  2037. echo '
  2038. var showAll = true;';
  2039. elseif (count($incontext['supported_databases']) < 2)
  2040. echo '
  2041. var showAll = false;';
  2042. // If we have more than one DB including SQLite, what should we be doing?
  2043. else
  2044. echo '
  2045. var showAll = document.getElementById(\'db_type_input\').value == \'sqlite\' ? false : true;';
  2046. echo '
  2047. document.getElementById(\'db_passwd_contain\').style.display = showAll ? \'\' : \'none\';
  2048. document.getElementById(\'db_server_contain\').style.display = showAll ? \'\' : \'none\';
  2049. document.getElementById(\'db_user_contain\').style.display = showAll ? \'\' : \'none\';
  2050. document.getElementById(\'db_name_contain\').style.display = showAll ? \'\' : \'none\';
  2051. document.getElementById(\'db_filename_contain\').style.display = !showAll ? \'\' : \'none\';
  2052. document.getElementById(\'db_sqlite_warning\').style.display = !showAll ? \'\' : \'none\';
  2053. if (document.getElementById(\'db_type_input\').value == \'postgresql\')
  2054. document.getElementById(\'db_name_info_warning\').style.display = \'none\';
  2055. else
  2056. document.getElementById(\'db_name_info_warning\').style.display = \'\';
  2057. }
  2058. toggleDBInput();
  2059. // ]]></script>';
  2060. }
  2061. /**
  2062. * Stick in their forum settings.
  2063. */
  2064. function template_forum_settings()
  2065. {
  2066. global $incontext, $installurl, $txt;
  2067. echo '
  2068. <form action="', $incontext['form_url'], '" method="post">
  2069. <h3>', $txt['install_settings_info'], '</h3>';
  2070. template_warning_divs();
  2071. echo '
  2072. <table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin: 1em 0;">
  2073. <tr>
  2074. <td width="20%" valign="top" class="textbox"><label for="mbname_input">', $txt['install_settings_name'], ':</label></td>
  2075. <td>
  2076. <input type="text" name="mbname" id="mbname_input" value="', $txt['install_settings_name_default'], '" size="65" class="input_text" />
  2077. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['install_settings_name_info'], '</div>
  2078. </td>
  2079. </tr>
  2080. <tr>
  2081. <td valign="top" class="textbox"><label for="boardurl_input">', $txt['install_settings_url'], ':</label></td>
  2082. <td>
  2083. <input type="text" name="boardurl" id="boardurl_input" value="', $incontext['detected_url'], '" size="65" class="input_text" /><br />
  2084. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['install_settings_url_info'], '</div>
  2085. </td>
  2086. </tr>
  2087. <tr>
  2088. <td valign="top" class="textbox">', $txt['install_settings_compress'], ':</td>
  2089. <td>
  2090. <input type="checkbox" name="compress" id="compress_check" checked="checked" class="input_check" /> <label for="compress_check">', $txt['install_settings_compress_title'], '</label><br />
  2091. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['install_settings_compress_info'], '</div>
  2092. </td>
  2093. </tr>
  2094. <tr>
  2095. <td valign="top" class="textbox">', $txt['install_settings_dbsession'], ':</td>
  2096. <td>
  2097. <input type="checkbox" name="dbsession" id="dbsession_check" checked="checked" class="input_check" /> <label for="dbsession_check">', $txt['install_settings_dbsession_title'], '</label><br />
  2098. <div style="font-size: smaller; margin-bottom: 2ex;">', $incontext['test_dbsession'] ? $txt['install_settings_dbsession_info1'] : $txt['install_settings_dbsession_info2'], '</div>
  2099. </td>
  2100. </tr>
  2101. </table>';
  2102. }
  2103. /**
  2104. * Show results of the database population.
  2105. */
  2106. function template_populate_database()
  2107. {
  2108. global $incontext, $installurl, $txt;
  2109. echo '
  2110. <form action="', $incontext['form_url'], '" method="post">
  2111. <p>', !empty($incontext['was_refresh']) ? $txt['user_refresh_install_desc'] : $txt['db_populate_info'], '</p>';
  2112. if (!empty($incontext['sql_results']))
  2113. {
  2114. echo '
  2115. <ul>
  2116. <li>', implode('</li><li>', $incontext['sql_results']), '</li>
  2117. </ul>';
  2118. }
  2119. if (!empty($incontext['failures']))
  2120. {
  2121. echo '
  2122. <div class="errorbox">', $txt['error_db_queries'], '
  2123. <ul>';
  2124. foreach ($incontext['failures'] as $line => $fail)
  2125. echo '
  2126. <li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
  2127. echo '
  2128. </ul>
  2129. </div>';
  2130. }
  2131. echo '
  2132. <p>', $txt['db_populate_info2'], '</p>';
  2133. template_warning_divs();
  2134. echo '
  2135. <input type="hidden" name="pop_done" value="1" />';
  2136. }
  2137. /**
  2138. * Template for the form to create the admin account.
  2139. */
  2140. function template_admin_account()
  2141. {
  2142. global $incontext, $installurl, $txt;
  2143. echo '
  2144. <form action="', $incontext['form_url'], '" method="post">
  2145. <p>', $txt['user_settings_info'], '</p>';
  2146. template_warning_divs();
  2147. echo '
  2148. <table width="100%" cellspacing="0" cellpadding="0" border="0" style="margin: 2em 0;">
  2149. <tr>
  2150. <td width="18%" valign="top" class="textbox"><label for="username">', $txt['user_settings_username'], ':</label></td>
  2151. <td>
  2152. <input type="text" name="username" id="username" value="', $incontext['username'], '" size="40" class="input_text" />
  2153. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['user_settings_username_info'], '</div>
  2154. </td>
  2155. </tr><tr>
  2156. <td valign="top" class="textbox"><label for="password1">', $txt['user_settings_password'], ':</label></td>
  2157. <td>
  2158. <input type="password" name="password1" id="password1" size="40" class="input_password" />
  2159. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['user_settings_password_info'], '</div>
  2160. </td>
  2161. </tr><tr>
  2162. <td valign="top" class="textbox"><label for="password2">', $txt['user_settings_again'], ':</label></td>
  2163. <td>
  2164. <input type="password" name="password2" id="password2" size="40" class="input_password" />
  2165. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['user_settings_again_info'], '</div>
  2166. </td>
  2167. </tr><tr>
  2168. <td valign="top" class="textbox"><label for="email">', $txt['user_settings_email'], ':</label></td>
  2169. <td>
  2170. <input type="text" name="email" id="email" value="', $incontext['email'], '" size="40" class="input_text" />
  2171. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['user_settings_email_info'], '</div>
  2172. </td>
  2173. </tr>
  2174. </table>';
  2175. if ($incontext['require_db_confirm'])
  2176. echo '
  2177. <h2>', $txt['user_settings_database'], '</h2>
  2178. <p>', $txt['user_settings_database_info'], '</p>
  2179. <div style="margin-bottom: 2ex; padding-', empty($txt['lang_rtl']) ? 'left' : 'right', ': 50px;">
  2180. <input type="password" name="password3" size="30" class="input_password" />
  2181. </div>';
  2182. }
  2183. /**
  2184. * Tell them it's done, and to delete.
  2185. */
  2186. function template_delete_install()
  2187. {
  2188. global $incontext, $installurl, $txt, $boardurl;
  2189. echo '
  2190. <p>', $txt['congratulations_help'], '</p>';
  2191. template_warning_divs();
  2192. // Install directory still writable?
  2193. if ($incontext['dir_still_writable'])
  2194. echo '
  2195. <em>', $txt['still_writable'], '</em><br />
  2196. <br />';
  2197. // Don't show the box if it's like 99% sure it won't work :P.
  2198. if ($incontext['probably_delete_install'])
  2199. echo '
  2200. <div style="margin: 1ex; font-weight: bold;">
  2201. <label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" class="input_check" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
  2202. </div>
  2203. <script type="text/javascript"><!-- // --><![CDATA[
  2204. function doTheDelete()
  2205. {
  2206. var theCheck = document.getElementById ? document.getElementById("delete_self") : document.all.delete_self;
  2207. var tempImage = new Image();
  2208. tempImage.src = "', $installurl, '?delete=1&ts_" + (new Date().getTime());
  2209. tempImage.width = 0;
  2210. theCheck.disabled = true;
  2211. }
  2212. // ]]></script>
  2213. <br />';
  2214. echo '
  2215. ', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br />
  2216. <br />
  2217. ', $txt['good_luck'];
  2218. }