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

/install/index.php

http://github.com/usebb/UseBB
PHP | 287 lines | 196 code | 66 blank | 25 comment | 45 complexity | e5031cb5f91bbb31902eba1079ef15c0 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. Copyright (C) 2003-2012 UseBB Team
  4. http://www.usebb.net
  5. $Id$
  6. This file is part of UseBB.
  7. UseBB is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. UseBB is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with UseBB; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. define('INCLUDED', true);
  20. define('ROOT_PATH', '../');
  21. if ( empty($_GET['step']) || intval($_GET['step']) < 2 )
  22. define('NO_DB', true);
  23. define('IS_INSTALLER', true);
  24. //
  25. // Include usebb engine
  26. //
  27. require(ROOT_PATH.'sources/common.php');
  28. $lang = $functions->fetch_language('English');
  29. require(ROOT_PATH.'sources/functions_admin.php');
  30. $admin_functions = new admin_functions;
  31. $_GET['step'] = ( !empty($_GET['step']) && valid_int($_GET['step']) ) ? intval($_GET['step']) : 1;
  32. $out = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  33. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  34. <head>
  35. <title>UseBB Installation</title>
  36. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
  37. <link rel="stylesheet" type="text/css" href="../docs/styles.css" />
  38. </head>
  39. <body>
  40. <div id="wrapper">
  41. <h1>UseBB Installation</h1>
  42. <div id="content">
  43. <form action="'.$_SERVER['REQUEST_URI'].'" method="post">
  44. ';
  45. if ( empty($_SESSION['installer_running']) && $functions->get_config('installer_run') ) {
  46. $out .= ' <p>This installer has been run already. To enable it again, delete the <code>installer_run</code> config value from <code>config.php</code>.</p>
  47. ';
  48. } elseif ( $_GET['step'] === 1 ) {
  49. foreach ( array('db_type', 'db_server', 'db_username', 'db_passwd', 'db_dbname', 'db_prefix', 'admin_username', 'admin_email', 'admin_passwd1', 'admin_passwd2') as $key )
  50. $_POST[$key] = ( !empty($_POST[$key]) ) ? $_POST[$key] : '';
  51. $db_servers = ( version_compare(phpversion(), '5.0.0', '<') || !extension_loaded('mysqli') ) ? array('mysql' => 'MySQL') : array('mysqli' => 'MySQL 4.1/5.x &mdash; mysqli', 'mysql' => 'MySQL 3.x/4.0 &mdash; mysql');
  52. if ( !empty($_POST['start']) && !is_writable(ROOT_PATH.'config.php') && !empty($_SESSION['installer_running']) ) {
  53. $functions->redirect('index.php', array('step' => 2));
  54. } elseif ( !empty($_POST['db_type']) && array_key_exists($_POST['db_type'], $db_servers) && !empty($_POST['db_server']) && !empty($_POST['db_username']) && !empty($_POST['db_dbname']) && !empty($_POST['admin_username']) && preg_match(USER_PREG, $_POST['admin_username']) && !empty($_POST['admin_email']) && preg_match(EMAIL_PREG, $_POST['admin_email']) && !empty($_POST['admin_passwd1']) && !empty($_POST['admin_passwd2']) && $functions->validate_password(stripslashes($_POST['admin_passwd1']), true) && strlen(stripslashes($_POST['admin_passwd1'])) >= $functions->get_config('passwd_min_length') && $_POST['admin_passwd1'] == $_POST['admin_passwd2'] ) {
  55. $_SESSION['installer_running'] = 1;
  56. $_SESSION['admin_username'] = $_POST['admin_username'];
  57. $_SESSION['admin_email'] = $_POST['admin_email'];
  58. $_SESSION['admin_passwd'] = md5(stripslashes($_POST['admin_passwd1']));
  59. $admin_functions->set_config(array(
  60. 'type' => $_POST['db_type'],
  61. 'server' => $_POST['db_server'],
  62. 'username' => $_POST['db_username'],
  63. 'passwd' => $_POST['db_passwd'],
  64. 'dbname' => $_POST['db_dbname'],
  65. 'prefix' => $_POST['db_prefix'],
  66. 'admin_email' => $_POST['admin_email'],
  67. 'installer_run' => 1
  68. ));
  69. if ( is_writable(ROOT_PATH.'config.php') )
  70. $functions->redirect('index.php', array('step' => 2));
  71. } else {
  72. if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
  73. $out .= ' <p class="important"><strong>Important:</strong> some values were missing or filled in incorrectly. Please check them.</p>
  74. <p>Please fill in all the required fields below (marked with <small>*</small>). If you don\'t know what a field means or you don\'t know what to fill in, please ask your web hosting company for the right values.</p>
  75. ';
  76. } else {
  77. $config_warning = ( !is_writable(ROOT_PATH.'config.php') ) ? '<p class="important"><strong>Tip:</strong> <code>config.php</code> is at this moment not writable by the webserver. Therefore, you will be asked to download the file after filling in this form. If you would like UseBB to edit the file automatically, make <code>config.php</code> writable and <a href="index.php">refresh</a> this wizard.</p>' : '';
  78. $out .= ' <p>Hello and welcome to the UseBB 1 installation script. First, thanks for choosing UseBB for your forum needs!</p>
  79. <p>This wizard will install a basic UseBB 1 forum at your website. Therefore, we need some information from you. Please fill in all the required fields below (marked with <small>*</small>). If you don\'t know what a field means or you don\'t know what to fill in, please ask your web hosting company or server administrator for the right values.</p>
  80. <p class="important"><strong>Important:</strong> this wizard does <strong>not</strong> upgrade an existing installation. Please see the <a href="../docs/index.html"><em>Readme</em> document</a> for upgrading instructions.</p>
  81. <p class="important"><strong>Important:</strong> If you use <strong>MySQL 4.1 or higher</strong>, it is highly recommended to use a <strong><code>latin1</code> collation</strong> instead of a Unicode one. Should your host use Unicode as default database collation, please change this for your database using phpMyAdmin or a similar administration tool or contact your host <em>before</em> installing UseBB. In most cases though, no action will be necessary.</p>
  82. '.$config_warning.'
  83. <p>You can also manually install UseBB. The instructions can be found in the <a href="../docs/index.html"><em>Readme</em> document</a>. Also, check the system requirements found in that file.</p>
  84. ';
  85. }
  86. $_POST['db_server'] = ( $_SERVER['REQUEST_METHOD'] == 'GET' ) ? 'localhost' : $_POST['db_server'];
  87. $_POST['db_prefix'] = ( $_SERVER['REQUEST_METHOD'] == 'GET' ) ? 'usebb_' : $_POST['db_prefix'];
  88. if ( count($db_servers) > 1 ) {
  89. $db_server = '<select name="db_type">';
  90. foreach ( $db_servers as $key => $val ) {
  91. $selected = ( $_POST['db_type'] == $key ) ? ' selected="selected"' : '';
  92. $db_server .= '<option value="'.$key.'"'.$selected.'>'.$val.'</option>';
  93. }
  94. $db_server .= '</select>';
  95. } else {
  96. $db_server = current($db_servers).' <input type="hidden" name="db_type" value="'.key($db_servers).'" />';
  97. }
  98. if ( is_writable(ROOT_PATH.'config.php') ) {
  99. $submit = '<p>Start the installation when you are sure everything is filled in correctly.</p>
  100. <p id="submit"><input type="submit" value="Start installation" /></p>';
  101. } else {
  102. $submit = '<p>When you are sure everything is filled in correctly, click the button <em>Download config.php</em> to save the configuration file and upload it to your web space. When this is done, click <em>Start Installation</em>.</p>
  103. <p id="submit"><input type="submit" value="Download config.php" /> <input type="submit" name="start" value="Start installation" /></p>';
  104. }
  105. $out .= '
  106. <table>
  107. <tr>
  108. <th colspan="2">Database configuration</th>
  109. </tr>
  110. <tr>
  111. <td class="title">Server type <small>*</small></td>
  112. <td>'.$db_server.'</td>
  113. </tr>
  114. <tr>
  115. <td class="title">Server host <small>*</small></td>
  116. <td><input type="text" size="35" name="db_server" value="'.unhtml($_POST['db_server']).'" /></td>
  117. </tr>
  118. <tr>
  119. <td class="title">Username <small>*</small></td>
  120. <td><input type="text" size="35" name="db_username" value="'.unhtml($_POST['db_username']).'" /></td>
  121. </tr>
  122. <tr>
  123. <td class="title">Password</td>
  124. <td><input type="password" size="35" name="db_passwd" /></td>
  125. </tr>
  126. <tr>
  127. <td class="title">DB name <small>*</small></td>
  128. <td><input type="text" size="35" name="db_dbname" value="'.unhtml($_POST['db_dbname']).'" /></td>
  129. </tr>
  130. <tr>
  131. <td class="title">Table prefix</td>
  132. <td><input type="text" size="35" name="db_prefix" value="'.unhtml($_POST['db_prefix']).'" /></td>
  133. </tr>
  134. </table>
  135. <p>This will also create an admin account for your forum. Fill in the fields below.</p>
  136. <p>Please note...</p>
  137. <ul>
  138. <li>'.$lang['UsernameInfo'].'</li>
  139. <li>'.sprintf($lang['PasswdInfoNew'], $functions->get_config('passwd_min_length')).'</li>
  140. </ul>
  141. <table>
  142. <tr>
  143. <th colspan="2">Administrator account</th>
  144. </tr>
  145. <tr>
  146. <td class="title">Username <small>*</small></td>
  147. <td><input type="text" size="35" name="admin_username" value="'.unhtml($_POST['admin_username']).'" /></td>
  148. </tr>
  149. <tr>
  150. <td class="title">E-mail <small>*</small></td>
  151. <td><input type="text" size="35" name="admin_email" value="'.unhtml($_POST['admin_email']).'" /></td>
  152. </tr>
  153. <tr>
  154. <td class="title">Password <small>*</small></td>
  155. <td><input type="password" size="35" name="admin_passwd1" /></td>
  156. </tr>
  157. <tr>
  158. <td class="title">Repeat password <small>*</small></td>
  159. <td><input type="password" size="35" name="admin_passwd2" /></td>
  160. </tr>
  161. </table>
  162. '.$submit.'
  163. <p>If you encounter a <em>General Error</em>, the configuration values may be wrong. Check them and restart the installation.</p>
  164. ';
  165. }
  166. } elseif ( $_GET['step'] === 2 && !empty($_SESSION['admin_username']) && preg_match(USER_PREG, $_SESSION['admin_username']) && !empty($_SESSION['admin_email']) && preg_match(EMAIL_PREG, $_SESSION['admin_email']) && !empty($_SESSION['admin_passwd']) ) {
  167. $lines_schema = file('./schemas/mysql.sql');
  168. $lines_data = file('./usebb.sql');
  169. $lines = array_merge($lines_schema, $lines_data);
  170. $queries = array();
  171. $i = 0;
  172. foreach ($lines as $sql) {
  173. $sql = trim($sql);
  174. if ( !empty($sql) && !preg_match('#^[-\#]#', $sql) ) {
  175. if ( !array_key_exists($i, $queries) )
  176. $queries[$i] = '';
  177. $queries[$i] .= $sql.' ';
  178. if ( preg_match('#;$#', $sql) ) {
  179. $query = trim(str_replace('usebb_', TABLE_PREFIX, preg_replace("#\s#", ' ', $queries[$i])));
  180. $queries[$i] = substr($query, 0, strlen($query)-1);
  181. $i++;
  182. }
  183. }
  184. }
  185. $queries[] = "INSERT INTO ".TABLE_PREFIX."members ( id, name, displayed_name, email, passwd, regdate, level, active, template, language, date_format, enable_quickreply, return_to_topic_after_posting, target_blank, hide_avatars, hide_userinfo, hide_signatures, banned_reason, signature ) VALUES ( NULL, '".$_SESSION['admin_username']."', '".$_SESSION['admin_username']."', '".$_SESSION['admin_email']."', '".$_SESSION['admin_passwd']."', ".time().", 3, 1, '".$functions->get_config('template')."', '".$functions->get_config('language')."', '".$functions->get_config('date_format')."', ".$functions->get_config('enable_quickreply').", ".$functions->get_config('return_to_topic_after_posting').", ".$functions->get_config('target_blank').", ".$functions->get_config('hide_avatars').", ".$functions->get_config('hide_userinfo').", ".$functions->get_config('hide_signatures').", '', '' )";
  186. foreach ( $queries as $query )
  187. $db->query($query);
  188. $functions->set_stats('members', 1, true);
  189. unset($_SESSION['installer_running'], $_SESSION['admin_username'], $_SESSION['admin_email'], $_SESSION['admin_passwd']);
  190. $out .= ' <p>The installation is complete. You must now <strong>remove the <code>install</code> directory</strong> from your forum\'s files. After this, you can log in into <a href="../">your UseBB forum</a>.</p>
  191. <p>If you need any help, feel free to visit the <a href="http://www.usebb.net/community/">community forums</a> at UseBB.net. Thanks for choosing UseBB!</p>
  192. ';
  193. } else {
  194. $functions->redirect('index.php');
  195. }
  196. $out .= ' </form>
  197. </div>
  198. </div>
  199. <p id="copyright">&copy; <a href="http://www.usebb.net">UseBB Project</a></p>
  200. </body>
  201. </html>';
  202. $template->add_raw_content($out);
  203. $template->body();
  204. ?>