PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/install/index.php

https://bitbucket.org/varad/usebb-freddy-cannon-edition
PHP | 282 lines | 192 code | 65 blank | 25 comment | 43 complexity | ab39cfd312b25e1183c47b447877091b MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. Copyright (C) 2003-2007 UseBB Team
  4. http://www.usebb.net
  5. $Header: /cvsroot/usebb/UseBB/install/index.php,v 1.20 2009/10/24 15:18:41 pc_freak Exp $
  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', '<') ) ? array('mysql' => 'MySQL') : array('mysql' => 'MySQL 3.x/4.0', 'mysqli' => 'MySQL 4.1/5.x');
  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']) && preg_match(PWD_PREG, $_POST['admin_passwd1']) && $_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($_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 (<em>chmod</em> it to 0777) and <a href="index.php">refresh</a> this wizard.</p>' : '';
  78. $out .= ' <p>Hello and welcome to the UseBB installation script. First, thanks for choosing UseBB for your forum needs!</p>
  79. <p>This wizard will install a basic UseBB 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 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. Note a username can only contain alphanumeric characters, spaces, _ and -. The password can only contain alphanumeric characters.</p>
  136. <table>
  137. <tr>
  138. <th colspan="2">Administrator account</th>
  139. </tr>
  140. <tr>
  141. <td class="title">Username <small>*</small></td>
  142. <td><input type="text" size="35" name="admin_username" value="'.unhtml($_POST['admin_username']).'" /></td>
  143. </tr>
  144. <tr>
  145. <td class="title">E-mail <small>*</small></td>
  146. <td><input type="text" size="35" name="admin_email" value="'.unhtml($_POST['admin_email']).'" /></td>
  147. </tr>
  148. <tr>
  149. <td class="title">Password <small>*</small></td>
  150. <td><input type="password" size="35" name="admin_passwd1" /></td>
  151. </tr>
  152. <tr>
  153. <td class="title">Repeat password <small>*</small></td>
  154. <td><input type="password" size="35" name="admin_passwd2" /></td>
  155. </tr>
  156. </table>
  157. '.$submit.'
  158. <p>If you encounter a <em>General Error</em>, the configuration values may be wrong. Check them and restart the installation.</p>
  159. ';
  160. }
  161. } 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']) ) {
  162. $lines_schema = file('./schemas/mysql.sql');
  163. $lines_data = file('./usebb.sql');
  164. $lines = array_merge($lines_schema, $lines_data);
  165. $queries = array();
  166. $i = 0;
  167. foreach ($lines as $sql) {
  168. $sql = trim(stripslashes($sql));
  169. if ( !empty($sql) && !preg_match('#^[-\#]#', $sql) ) {
  170. if ( !array_key_exists($i, $queries) )
  171. $queries[$i] = '';
  172. $queries[$i] .= $sql.' ';
  173. if ( preg_match('#;$#', $sql) ) {
  174. $query = trim(str_replace('usebb_', TABLE_PREFIX, preg_replace("#\s#", ' ', $queries[$i])));
  175. $queries[$i] = substr($query, 0, strlen($query)-1);
  176. $i++;
  177. }
  178. }
  179. }
  180. $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').", '', '' )";
  181. $queries[] = "UPDATE ".TABLE_PREFIX."stats SET content = content+1 WHERE name = 'members'";
  182. foreach ( $queries as $query )
  183. $db->query($query);
  184. unset($_SESSION['installer_running'], $_SESSION['admin_username'], $_SESSION['admin_email'], $_SESSION['admin_passwd']);
  185. $out .= ' <p>The installation is now complete. You can now log in into <a href="../">your UseBB forum</a>. If you need any help, feel free to visit the <a href="http://www.usebb.net/community/">community forums</a> at UseBB.net.</p>
  186. <p class="important"><strong>Warning:</strong> please remove the <code>install/</code> directory to keep your forum safe.</p>
  187. <p>Thanks for choosing UseBB!</p>
  188. ';
  189. } else {
  190. $functions->redirect('index.php');
  191. }
  192. $out .= ' </form>
  193. </div>
  194. </div>
  195. <p id="copyright">Powered by UseBB &middot; Copyright &copy; 2003-2009 <a href="http://www.usebb.net">UseBB Team</a></p>
  196. </body>
  197. </html>';
  198. $template->add_raw_content($out);
  199. $template->body();
  200. ?>