PageRenderTime 30ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/install.php

https://bitbucket.org/gencer/punbb
PHP | 1977 lines | 1749 code | 179 blank | 49 comment | 88 complexity | 31890908d8697fa6bc3d162aca3f9ade MD5 | raw file
Possible License(s): GPL-2.0

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

  1. <?php
  2. /**
  3. * Installation script.
  4. *
  5. * Used to actually install PunBB.
  6. *
  7. * @copyright (C) 2008-2012 PunBB, partially based on code (C) 2008-2009 FluxBB.org
  8. * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  9. * @package PunBB
  10. */
  11. define('MIN_PHP_VERSION', '5.0.0');
  12. define('MIN_MYSQL_VERSION', '4.1.2');
  13. define('FORUM_ROOT', '../');
  14. define('FORUM', 1);
  15. define('FORUM_DEBUG', 1);
  16. if (file_exists(FORUM_ROOT.'config.php'))
  17. exit('The file \'config.php\' already exists which would mean that PunBB is already installed. You should go <a href="'.FORUM_ROOT.'index.php">here</a> instead.');
  18. // Make sure we are running at least MIN_PHP_VERSION
  19. if (!function_exists('version_compare') || version_compare(PHP_VERSION, MIN_PHP_VERSION, '<'))
  20. exit('You are running PHP version '.PHP_VERSION.'. PunBB requires at least PHP '.MIN_PHP_VERSION.' to run properly. You must upgrade your PHP installation before you can continue.');
  21. // Disable error reporting for uninitialized variables
  22. error_reporting(E_ALL);
  23. // Turn off PHP time limit
  24. @set_time_limit(0);
  25. require FORUM_ROOT.'include/constants.php';
  26. // We need some stuff from functions.php
  27. require FORUM_ROOT.'include/functions.php';
  28. // Load UTF-8 functions
  29. require FORUM_ROOT.'include/utf8/utf8.php';
  30. require FORUM_ROOT.'include/utf8/ucwords.php';
  31. require FORUM_ROOT.'include/utf8/trim.php';
  32. // Strip out "bad" UTF-8 characters
  33. forum_remove_bad_characters();
  34. //
  35. // Generate output to be used for config.php
  36. //
  37. function generate_config_file()
  38. {
  39. global $db_type, $db_host, $db_name, $db_username, $db_password, $db_prefix, $base_url, $cookie_name;
  40. $config_body = '<?php'."\n\n".'$db_type = \''.$db_type."';\n".'$db_host = \''.$db_host."';\n".'$db_name = \''.addslashes($db_name)."';\n".'$db_username = \''.addslashes($db_username)."';\n".'$db_password = \''.addslashes($db_password)."';\n".'$db_prefix = \''.addslashes($db_prefix)."';\n".'$p_connect = false;'."\n\n".'$base_url = \''.$base_url.'\';'."\n\n".'$cookie_name = '."'".$cookie_name."';\n".'$cookie_domain = '."'';\n".'$cookie_path = '."'/';\n".'$cookie_secure = 0;'."\n\ndefine('FORUM', 1);";
  41. // Add forum options
  42. $config_body .= "\n\n// Enable DEBUG mode by removing // from the following line\n//define('FORUM_DEBUG', 1);";
  43. $config_body .= "\n\n// Enable show DB Queries mode by removing // from the following line\n//define('FORUM_SHOW_QUERIES', 1);";
  44. $config_body .= "\n\n// Enable forum IDNA support by removing // from the following line\n//define('FORUM_ENABLE_IDNA', 1);";
  45. $config_body .= "\n\n// Disable forum CSRF checking by removing // from the following line\n//define('FORUM_DISABLE_CSRF_CONFIRM', 1);";
  46. $config_body .= "\n\n// Disable forum hooks (extensions) by removing // from the following line\n//define('FORUM_DISABLE_HOOKS', 1);";
  47. $config_body .= "\n\n// Disable forum output buffering by removing // from the following line\n//define('FORUM_DISABLE_BUFFERING', 1);";
  48. $config_body .= "\n\n// Disable forum async JS loader by removing // from the following line\n//define('FORUM_DISABLE_ASYNC_JS_LOADER', 1);";
  49. $config_body .= "\n\n// Disable forum extensions version check by removing // from the following line\n//define('FORUM_DISABLE_EXTENSIONS_VERSION_CHECK', 1);";
  50. return $config_body;
  51. }
  52. $language = isset($_GET['lang']) ? $_GET['lang'] : (isset($_POST['req_language']) ? forum_trim($_POST['req_language']) : 'English');
  53. $language = preg_replace('#[\.\\\/]#', '', $language);
  54. if (!file_exists(FORUM_ROOT.'lang/'.$language.'/install.php'))
  55. exit('The language pack you have chosen doesn\'t seem to exist or is corrupt. Please recheck and try again.');
  56. // Load the language files
  57. require FORUM_ROOT.'lang/'.$language.'/install.php';
  58. require FORUM_ROOT.'lang/'.$language.'/admin_settings.php';
  59. if (isset($_POST['generate_config']))
  60. {
  61. header('Content-Type: text/x-delimtext; name="config.php"');
  62. header('Content-disposition: attachment; filename=config.php');
  63. $db_type = $_POST['db_type'];
  64. $db_host = $_POST['db_host'];
  65. $db_name = $_POST['db_name'];
  66. $db_username = $_POST['db_username'];
  67. $db_password = $_POST['db_password'];
  68. $db_prefix = $_POST['db_prefix'];
  69. $base_url = $_POST['base_url'];
  70. $cookie_name = $_POST['cookie_name'];
  71. echo generate_config_file();
  72. exit;
  73. }
  74. header('Content-Type: text/html; charset=utf-8');
  75. header('Cache-Control: cache-control: no-store', false);
  76. if (!isset($_POST['form_sent']))
  77. {
  78. // Determine available database extensions
  79. $db_extensions = array();
  80. if (function_exists('mysqli_connect'))
  81. {
  82. $db_extensions[] = array('mysqli', 'MySQL Improved');
  83. $db_extensions[] = array('mysqli_innodb', 'MySQL Improved (InnoDB)');
  84. }
  85. if (function_exists('mysql_connect'))
  86. {
  87. $db_extensions[] = array('mysql', 'MySQL Standard');
  88. $db_extensions[] = array('mysql_innodb', 'MySQL Standard (InnoDB)');
  89. }
  90. if (function_exists('sqlite_open'))
  91. $db_extensions[] = array('sqlite', 'SQLite');
  92. if (class_exists('SQLite3'))
  93. $db_extensions[] = array('sqlite3', 'SQLite3');
  94. if (function_exists('pg_connect'))
  95. $db_extensions[] = array('pgsql', 'PostgreSQL');
  96. if (empty($db_extensions))
  97. error($lang_install['No database support']);
  98. // Make an educated guess regarding base_url
  99. $base_url_guess = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://').preg_replace('/:80$/', '', $_SERVER['HTTP_HOST']).substr(str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'])), 0, -6);
  100. if (substr($base_url_guess, -1) == '/')
  101. $base_url_guess = substr($base_url_guess, 0, -1);
  102. // Check for available language packs
  103. $languages = get_language_packs();
  104. ?>
  105. <!DOCTYPE html>
  106. <!--[if lt IE 7 ]> <html class="oldie ie6" lang="en" dir="ltr"> <![endif]-->
  107. <!--[if IE 7 ]> <html class="oldie ie7" lang="en" dir="ltr"> <![endif]-->
  108. <!--[if IE 8 ]> <html class="oldie ie8" lang="en" dir="ltr"> <![endif]-->
  109. <!--[if gt IE 8]><!--> <html lang="en" dir="ltr"> <!--<![endif]-->
  110. <head>
  111. <meta charset="utf-8" />
  112. <title>PunBB Installation</title>
  113. <link rel="stylesheet" type="text/css" href="<?php echo FORUM_ROOT ?>style/Oxygen/Oxygen.min.css" />
  114. </head>
  115. <body>
  116. <div id="brd-install" class="brd-page">
  117. <div id="brd-wrap" class="brd">
  118. <div id="brd-head" class="gen-content">
  119. <p id="brd-title"><strong><?php printf($lang_install['Install PunBB'], FORUM_VERSION) ?></strong></p>
  120. <p id="brd-desc"><?php echo $lang_install['Install intro'] ?></p>
  121. </div>
  122. <div id="brd-main" class="main">
  123. <div class="main-head">
  124. <h1 class="hn"><span><?php printf($lang_install['Install PunBB'], FORUM_VERSION) ?></span></h1>
  125. </div>
  126. <?php
  127. if (count($languages) > 1)
  128. {
  129. ?> <form class="frm-form" method="get" accept-charset="utf-8" action="install.php">
  130. <div class="main-subhead">
  131. <h2 class="hn"><span><?php echo $lang_install['Choose language'] ?></span></h2>
  132. </div>
  133. <div class="main-content main-frm">
  134. <fieldset class="frm-group group1">
  135. <legend class="group-legend"><strong><?php echo $lang_install['Choose language legend'] ?></strong></legend>
  136. <div class="sf-set set1">
  137. <div class="sf-box text">
  138. <label for="fld0"><span><?php echo $lang_install['Installer language'] ?></span> <small><?php echo $lang_install['Choose language help'] ?></small></label><br />
  139. <span class="fld-input"><select id="fld0" name="lang">
  140. <?php
  141. foreach ($languages as $lang)
  142. echo "\t\t\t\t\t".'<option value="'.$lang.'"'.($language == $lang ? ' selected="selected"' : '').'>'.$lang.'</option>'."\n";
  143. ?> </select></span>
  144. </div>
  145. </div>
  146. </fieldset>
  147. <div class="frm-buttons">
  148. <span class="submit primary"><input type="submit" name="changelang" value="<?php echo $lang_install['Choose language'] ?>" /></span>
  149. </div>
  150. </div>
  151. </form>
  152. <?php
  153. }
  154. ?> <form class="frm-form frm-suggest-username" method="post" accept-charset="utf-8" action="install.php">
  155. <div class="hidden">
  156. <input type="hidden" name="form_sent" value="1" />
  157. </div>
  158. <div class="main-subhead">
  159. <h2 class="hn"><span><?php echo $lang_install['Part1'] ?></span></h2>
  160. </div>
  161. <div class="main-content main-frm">
  162. <div class="ct-box info-box">
  163. <p><?php echo $lang_install['Part1 intro'] ?></p>
  164. <ul class="spaced list-clean">
  165. <li><span><strong><?php echo $lang_install['Database type'] ?></strong> <?php echo $lang_install['Database type info']; if (count($db_extensions) > 1) echo ' '.$lang_install['Mysql type info'] ?></span></li>
  166. <li><span><strong><?php echo $lang_install['Database server'] ?></strong> <?php echo $lang_install['Database server info'] ?></span></li>
  167. <li><span><strong><?php echo $lang_install['Database name'] ?></strong> <?php echo $lang_install['Database name info'] ?></span></li>
  168. <li><span><strong><?php echo $lang_install['Database user pass'] ?></strong> <?php echo $lang_install['Database username info'] ?></span></li>
  169. <li><span><strong><?php echo $lang_install['Table prefix'] ?></strong> <?php echo $lang_install['Table prefix info'] ?></span></li>
  170. </ul>
  171. </div>
  172. <div id="req-msg" class="req-warn ct-box error-box">
  173. <p class="important"><?php echo $lang_install['Required warn'] ?></p>
  174. </div>
  175. <fieldset class="frm-group group1">
  176. <legend class="group-legend"><strong><?php echo $lang_install['Part1 legend'] ?></strong></legend>
  177. <div class="sf-set set1">
  178. <div class="sf-box select required">
  179. <label for="req_db_type"><span><?php echo $lang_install['Database type'] ?></span> <small><?php echo $lang_install['Database type help'] ?></small></label><br />
  180. <span class="fld-input"><select id="req_db_type" name="req_db_type">
  181. <?php
  182. foreach ($db_extensions as $db_type)
  183. echo "\t\t\t\t\t".'<option value="'.$db_type[0].'">'.$db_type[1].'</option>'."\n";
  184. ?> </select></span>
  185. </div>
  186. </div>
  187. <div class="sf-set set1" id="db_host_block">
  188. <div class="sf-box text required">
  189. <label for="db_host"><span><?php echo $lang_install['Database server'] ?></span> <small><?php echo $lang_install['Database server help'] ?></small></label><br />
  190. <span class="fld-input"><input id="db_host" type="text" name="req_db_host" value="localhost" size="35" maxlength="100" required /></span>
  191. </div>
  192. </div>
  193. <div class="sf-set set2">
  194. <div class="sf-box text required">
  195. <label for="fld3"><span><?php echo $lang_install['Database name'] ?></span> <small><?php echo $lang_install['Database name help'] ?></small></label><br />
  196. <span class="fld-input"><input id="fld3" type="text" name="req_db_name" size="35" maxlength="50" required /></span>
  197. </div>
  198. </div>
  199. <div class="sf-set set3" id="db_username_block">
  200. <div class="sf-box text">
  201. <label for="fld4"><span><?php echo $lang_install['Database username'] ?></span> <small><?php echo $lang_install['Database username help'] ?></small></label><br />
  202. <span class="fld-input"><input id="fld4" type="text" name="db_username" size="35" maxlength="50" /></span>
  203. </div>
  204. </div>
  205. <div class="sf-set set4" id="db_password_block">
  206. <div class="sf-box text">
  207. <label for="fld5"><span><?php echo $lang_install['Database password'] ?></span> <small><?php echo $lang_install['Database password help'] ?></small></label><br />
  208. <span class="fld-input"><input id="fld5" type="text" name="db_password" size="35" autocomplete="off" /></span>
  209. </div>
  210. </div>
  211. <div class="sf-set set5">
  212. <div class="sf-box text">
  213. <label for="fld6"><span><?php echo $lang_install['Table prefix'] ?></span> <small><?php echo $lang_install['Table prefix help'] ?></small></label><br />
  214. <span class="fld-input"><input id="fld6" type="text" name="db_prefix" size="35" maxlength="30" /></span>
  215. </div>
  216. </div>
  217. </fieldset>
  218. </div>
  219. <div class="main-subhead">
  220. <h2 class="hn"><span><?php echo $lang_install['Part2'] ?></span></h2>
  221. </div>
  222. <div class="main-content main-frm">
  223. <div class="ct-box info-box">
  224. <p><?php echo $lang_install['Part2 intro'] ?></p>
  225. </div>
  226. <fieldset class="frm-group group1">
  227. <legend class="group-legend"><strong><?php echo $lang_install['Part2 legend'] ?></strong></legend>
  228. <div class="sf-set set4">
  229. <div class="sf-box text required">
  230. <label for="admin_email"><span><?php echo $lang_install['Admin e-mail'] ?></span> <small><?php echo $lang_install['E-mail address help'] ?></small></label><br />
  231. <span class="fld-input"><input id="admin_email" type="email" data-suggest-role="email" name="req_email" size="35" maxlength="80" required /></span>
  232. </div>
  233. </div>
  234. <div class="sf-set set1 prepend-top">
  235. <div class="sf-box text required">
  236. <label for="admin_username"><span><?php echo $lang_install['Admin username'] ?></span> <small><?php echo $lang_install['Username help'] ?></small></label><br />
  237. <span class="fld-input"><input id="admin_username" type="text" data-suggest-role="username" name="req_username" size="35" maxlength="25" required /></span>
  238. </div>
  239. </div>
  240. <div class="sf-set set2">
  241. <div class="sf-box text required">
  242. <label for="fld8"><span><?php echo $lang_install['Admin password'] ?></span> <small><?php echo $lang_install['Password help'] ?></small></label><br />
  243. <span class="fld-input"><input id="fld8" type="text" name="req_password1" size="35" required autocomplete="off" /></span>
  244. </div>
  245. </div>
  246. </fieldset>
  247. </div>
  248. <div class="main-subhead">
  249. <h2 class="hn"><span><?php echo $lang_install['Part3'] ?></span></h2>
  250. </div>
  251. <div class="main-content main-frm">
  252. <div class="ct-box info-box">
  253. <p><?php echo $lang_install['Part3 intro'] ?></p>
  254. <ul class="spaced list-clean">
  255. <li><span><strong><?php echo $lang_install['Base URL'] ?></strong> <?php echo $lang_install['Base URL info'] ?></span></li>
  256. </ul>
  257. </div>
  258. <fieldset class="frm-group group1">
  259. <legend class="group-legend"><strong><?php echo $lang_install['Part3 legend'] ?></strong></legend>
  260. <div class="sf-set set3">
  261. <div class="sf-box text required">
  262. <label for="fld10"><span><?php echo $lang_install['Base URL'] ?></span> <small><?php echo $lang_install['Base URL help'] ?></small></label><br />
  263. <span class="fld-input"><input id="fld10" type="url" name="req_base_url" value="<?php echo $base_url_guess ?>" size="35" maxlength="100" required /></span>
  264. </div>
  265. </div>
  266. <?php
  267. if (count($languages) > 1)
  268. {
  269. ?> <div class="sf-set set4">
  270. <div class="sf-box text">
  271. <label for="fld11"><span><?php echo $lang_install['Default language'] ?></span> <small><?php echo $lang_install['Default language help'] ?></small></label><br />
  272. <span class="fld-input"><select id="fld11" name="req_language">
  273. <?php
  274. foreach ($languages as $lang)
  275. echo "\t\t\t\t\t".'<option value="'.$lang.'"'.($language == $lang ? ' selected="selected"' : '').'>'.$lang.'</option>'."\n";
  276. ?> </select></span>
  277. </div>
  278. </div>
  279. <?php
  280. }
  281. else
  282. {
  283. ?> <div class="hidden">
  284. <input type="hidden" name="req_language" value="<?php echo $languages[0] ?>" />
  285. </div>
  286. <?php
  287. }
  288. if (file_exists(FORUM_ROOT.'extensions/pun_repository/manifest.xml'))
  289. {
  290. ?> <div class="sf-set set5">
  291. <div class="sf-box checkbox">
  292. <span class="fld-input"><input id="fld12" type="checkbox" name="install_pun_repository" value="1" checked="checked" /></span>
  293. <label for="fld12"><span><?php echo $lang_install['Pun repository'] ?></span> <?php echo $lang_install['Pun repository help'] ?></label><br />
  294. </div>
  295. </div>
  296. <?php
  297. }
  298. ?>
  299. </fieldset>
  300. <div class="frm-buttons">
  301. <span class="submit primary"><input type="submit" name="start" value="<?php echo $lang_install['Start install'] ?>" /></span>
  302. </div>
  303. </div>
  304. </form>
  305. </div>
  306. </div>
  307. </div>
  308. <script src="<?php echo FORUM_ROOT ?>include/js/min/punbb.common.min.js"></script>
  309. <script src="<?php echo FORUM_ROOT ?>include/js/min/punbb.install.min.js"></script>
  310. </body>
  311. </html>
  312. <?php
  313. }
  314. else
  315. {
  316. //
  317. // Strip slashes only if magic_quotes_gpc is on.
  318. //
  319. function unescape($str)
  320. {
  321. return (get_magic_quotes_gpc() == 1) ? stripslashes($str) : $str;
  322. }
  323. $db_type = $_POST['req_db_type'];
  324. $db_host = forum_trim($_POST['req_db_host']);
  325. $db_name = forum_trim($_POST['req_db_name']);
  326. $db_username = unescape(forum_trim($_POST['db_username']));
  327. $db_password = unescape(forum_trim($_POST['db_password']));
  328. $db_prefix = forum_trim($_POST['db_prefix']);
  329. $username = unescape(forum_trim($_POST['req_username']));
  330. $email = unescape(strtolower(forum_trim($_POST['req_email'])));
  331. $password1 = unescape(forum_trim($_POST['req_password1']));
  332. $default_lang = preg_replace('#[\.\\\/]#', '', unescape(forum_trim($_POST['req_language'])));
  333. $install_pun_repository = !empty($_POST['install_pun_repository']);
  334. // Make sure base_url doesn't end with a slash
  335. if (substr($_POST['req_base_url'], -1) == '/')
  336. $base_url = substr($_POST['req_base_url'], 0, -1);
  337. else
  338. $base_url = $_POST['req_base_url'];
  339. // Validate form
  340. if (utf8_strlen($db_name) == 0)
  341. error($lang_install['Missing database name']);
  342. if (utf8_strlen($username) < 2)
  343. error($lang_install['Username too short']);
  344. if (utf8_strlen($username) > 25)
  345. error($lang_install['Username too long']);
  346. if (utf8_strlen($password1) < 4)
  347. error($lang_install['Pass too short']);
  348. if (strtolower($username) == 'guest')
  349. error($lang_install['Username guest']);
  350. if (preg_match('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $username) || preg_match('/((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))/', $username))
  351. error($lang_install['Username IP']);
  352. if ((strpos($username, '[') !== false || strpos($username, ']') !== false) && strpos($username, '\'') !== false && strpos($username, '"') !== false)
  353. error($lang_install['Username reserved chars']);
  354. if (preg_match('/(?:\[\/?(?:b|u|i|h|colou?r|quote|code|img|url|email|list)\]|\[(?:code|quote|list)=)/i', $username))
  355. error($lang_install['Username BBCode']);
  356. // Validate email
  357. if (!defined('FORUM_EMAIL_FUNCTIONS_LOADED'))
  358. require FORUM_ROOT.'include/email.php';
  359. if (!is_valid_email($email))
  360. error($lang_install['Invalid email']);
  361. // Make sure board title and description aren't left blank
  362. $board_title = 'My PunBB forum';
  363. $board_descrip = 'Unfortunately no one can be told what PunBB is — you have to see it for yourself';
  364. if (utf8_strlen($base_url) == 0)
  365. error($lang_install['Missing base url']);
  366. if (!file_exists(FORUM_ROOT.'lang/'.$default_lang.'/common.php'))
  367. error($lang_install['Invalid language']);
  368. // Load the appropriate DB layer class
  369. switch ($db_type)
  370. {
  371. case 'mysql':
  372. require FORUM_ROOT.'include/dblayer/mysql.php';
  373. break;
  374. case 'mysql_innodb':
  375. require FORUM_ROOT.'include/dblayer/mysql_innodb.php';
  376. break;
  377. case 'mysqli':
  378. require FORUM_ROOT.'include/dblayer/mysqli.php';
  379. break;
  380. case 'mysqli_innodb':
  381. require FORUM_ROOT.'include/dblayer/mysqli_innodb.php';
  382. break;
  383. case 'pgsql':
  384. require FORUM_ROOT.'include/dblayer/pgsql.php';
  385. break;
  386. case 'sqlite':
  387. require FORUM_ROOT.'include/dblayer/sqlite.php';
  388. break;
  389. case 'sqlite3':
  390. require FORUM_ROOT.'include/dblayer/sqlite3.php';
  391. break;
  392. default:
  393. error(sprintf($lang_install['No such database type'], forum_htmlencode($db_type)));
  394. }
  395. // Create the database object (and connect/select db)
  396. $forum_db = new DBLayer($db_host, $db_username, $db_password, $db_name, $db_prefix, false);
  397. // If MySQL, make sure it's at least 4.1.2
  398. if (in_array($db_type, array('mysql', 'mysqli', 'mysql_innodb', 'mysqli_innodb')))
  399. {
  400. $mysql_info = $forum_db->get_version();
  401. if (version_compare($mysql_info['version'], MIN_MYSQL_VERSION, '<'))
  402. error(sprintf($lang_install['Invalid MySQL version'], forum_htmlencode($mysql_info['version']), MIN_MYSQL_VERSION));
  403. // Check InnoDB support in DB
  404. if (in_array($db_type, array('mysql_innodb', 'mysqli_innodb')))
  405. {
  406. $result = $forum_db->query('SHOW VARIABLES LIKE \'have_innodb\'');
  407. $row = $forum_db->fetch_assoc($result);
  408. if (!$row || !isset($row['Value']) || strtolower($row['Value']) != 'yes')
  409. {
  410. error($lang_install['MySQL InnoDB Not Supported']);
  411. }
  412. }
  413. }
  414. // Validate prefix
  415. if (strlen($db_prefix) > 0 && (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $db_prefix) || strlen($db_prefix) > 40))
  416. error(sprintf($lang_install['Invalid table prefix'], $db_prefix));
  417. // Check SQLite prefix collision
  418. if (in_array($db_type, array('sqlite', 'sqlite3')) && strtolower($db_prefix) == 'sqlite_')
  419. error($lang_install['SQLite prefix collision']);
  420. // Make sure PunBB isn't already installed
  421. if ($forum_db->table_exists('users'))
  422. {
  423. $query = array(
  424. 'SELECT' => 'COUNT(id)',
  425. 'FROM' => 'users',
  426. 'WHERE' => 'id=1'
  427. );
  428. $result = $forum_db->query_build($query);
  429. if ($forum_db->result($result) > 0)
  430. error(sprintf($lang_install['PunBB already installed'], $db_prefix, $db_name));
  431. }
  432. // Start a transaction
  433. $forum_db->start_transaction();
  434. // Create all tables
  435. $schema = array(
  436. 'FIELDS' => array(
  437. 'id' => array(
  438. 'datatype' => 'SERIAL',
  439. 'allow_null' => false
  440. ),
  441. 'username' => array(
  442. 'datatype' => 'VARCHAR(200)',
  443. 'allow_null' => true
  444. ),
  445. 'ip' => array(
  446. 'datatype' => 'VARCHAR(255)',
  447. 'allow_null' => true
  448. ),
  449. 'email' => array(
  450. 'datatype' => 'VARCHAR(80)',
  451. 'allow_null' => true
  452. ),
  453. 'message' => array(
  454. 'datatype' => 'VARCHAR(255)',
  455. 'allow_null' => true
  456. ),
  457. 'expire' => array(
  458. 'datatype' => 'INT(10) UNSIGNED',
  459. 'allow_null' => true
  460. ),
  461. 'ban_creator' => array(
  462. 'datatype' => 'INT(10) UNSIGNED',
  463. 'allow_null' => false,
  464. 'default' => '0'
  465. )
  466. ),
  467. 'PRIMARY KEY' => array('id')
  468. );
  469. $forum_db->create_table('bans', $schema);
  470. $schema = array(
  471. 'FIELDS' => array(
  472. 'id' => array(
  473. 'datatype' => 'SERIAL',
  474. 'allow_null' => false
  475. ),
  476. 'cat_name' => array(
  477. 'datatype' => 'VARCHAR(80)',
  478. 'allow_null' => false,
  479. 'default' => '\'New Category\''
  480. ),
  481. 'disp_position' => array(
  482. 'datatype' => 'INT(10)',
  483. 'allow_null' => false,
  484. 'default' => '0'
  485. )
  486. ),
  487. 'PRIMARY KEY' => array('id')
  488. );
  489. $forum_db->create_table('categories', $schema);
  490. $schema = array(
  491. 'FIELDS' => array(
  492. 'id' => array(
  493. 'datatype' => 'SERIAL',
  494. 'allow_null' => false
  495. ),
  496. 'search_for' => array(
  497. 'datatype' => 'VARCHAR(60)',
  498. 'allow_null' => false,
  499. 'default' => '\'\''
  500. ),
  501. 'replace_with' => array(
  502. 'datatype' => 'VARCHAR(60)',
  503. 'allow_null' => false,
  504. 'default' => '\'\''
  505. )
  506. ),
  507. 'PRIMARY KEY' => array('id')
  508. );
  509. $forum_db->create_table('censoring', $schema);
  510. $schema = array(
  511. 'FIELDS' => array(
  512. 'conf_name' => array(
  513. 'datatype' => 'VARCHAR(255)',
  514. 'allow_null' => false,
  515. 'default' => '\'\''
  516. ),
  517. 'conf_value' => array(
  518. 'datatype' => 'TEXT',
  519. 'allow_null' => true
  520. )
  521. ),
  522. 'PRIMARY KEY' => array('conf_name')
  523. );
  524. $forum_db->create_table('config', $schema);
  525. $schema = array(
  526. 'FIELDS' => array(
  527. 'id' => array(
  528. 'datatype' => 'VARCHAR(150)',
  529. 'allow_null' => false,
  530. 'default' => '\'\''
  531. ),
  532. 'title' => array(
  533. 'datatype' => 'VARCHAR(255)',
  534. 'allow_null' => false,
  535. 'default' => '\'\''
  536. ),
  537. 'version' => array(
  538. 'datatype' => 'VARCHAR(25)',
  539. 'allow_null' => false,
  540. 'default' => '\'\''
  541. ),
  542. 'description' => array(
  543. 'datatype' => 'TEXT',
  544. 'allow_null' => true
  545. ),
  546. 'author' => array(
  547. 'datatype' => 'VARCHAR(50)',
  548. 'allow_null' => false,
  549. 'default' => '\'\''
  550. ),
  551. 'uninstall' => array(
  552. 'datatype' => 'TEXT',
  553. 'allow_null' => true
  554. ),
  555. 'uninstall_note' => array(
  556. 'datatype' => 'TEXT',
  557. 'allow_null' => true
  558. ),
  559. 'disabled' => array(
  560. 'datatype' => 'TINYINT(1)',
  561. 'allow_null' => false,
  562. 'default' => '0'
  563. ),
  564. 'dependencies' => array(
  565. 'datatype' => 'VARCHAR(255)',
  566. 'allow_null' => false,
  567. 'default' => '\'\''
  568. )
  569. ),
  570. 'PRIMARY KEY' => array('id')
  571. );
  572. $forum_db->create_table('extensions', $schema);
  573. $schema = array(
  574. 'FIELDS' => array(
  575. 'id' => array(
  576. 'datatype' => 'VARCHAR(150)',
  577. 'allow_null' => false,
  578. 'default' => '\'\''
  579. ),
  580. 'extension_id' => array(
  581. 'datatype' => 'VARCHAR(50)',
  582. 'allow_null' => false,
  583. 'default' => '\'\''
  584. ),
  585. 'code' => array(
  586. 'datatype' => 'TEXT',
  587. 'allow_null' => true
  588. ),
  589. 'installed' => array(
  590. 'datatype' => 'INT(10) UNSIGNED',
  591. 'allow_null' => false,
  592. 'default' => '0'
  593. ),
  594. 'priority' => array(
  595. 'datatype' => 'TINYINT(1) UNSIGNED',
  596. 'allow_null' => false,
  597. 'default' => '5'
  598. )
  599. ),
  600. 'PRIMARY KEY' => array('id', 'extension_id')
  601. );
  602. $forum_db->create_table('extension_hooks', $schema);
  603. $schema = array(
  604. 'FIELDS' => array(
  605. 'group_id' => array(
  606. 'datatype' => 'INT(10)',
  607. 'allow_null' => false,
  608. 'default' => '0'
  609. ),
  610. 'forum_id' => array(
  611. 'datatype' => 'INT(10)',
  612. 'allow_null' => false,
  613. 'default' => '0'
  614. ),
  615. 'read_forum' => array(
  616. 'datatype' => 'TINYINT(1)',
  617. 'allow_null' => false,
  618. 'default' => '1'
  619. ),
  620. 'post_replies' => array(
  621. 'datatype' => 'TINYINT(1)',
  622. 'allow_null' => false,
  623. 'default' => '1'
  624. ),
  625. 'post_topics' => array(
  626. 'datatype' => 'TINYINT(1)',
  627. 'allow_null' => false,
  628. 'default' => '1'
  629. )
  630. ),
  631. 'PRIMARY KEY' => array('group_id', 'forum_id')
  632. );
  633. $forum_db->create_table('forum_perms', $schema);
  634. $schema = array(
  635. 'FIELDS' => array(
  636. 'id' => array(
  637. 'datatype' => 'SERIAL',
  638. 'allow_null' => false
  639. ),
  640. 'forum_name' => array(
  641. 'datatype' => 'VARCHAR(80)',
  642. 'allow_null' => false,
  643. 'default' => '\'New forum\''
  644. ),
  645. 'forum_desc' => array(
  646. 'datatype' => 'TEXT',
  647. 'allow_null' => true
  648. ),
  649. 'redirect_url' => array(
  650. 'datatype' => 'VARCHAR(100)',
  651. 'allow_null' => true
  652. ),
  653. 'moderators' => array(
  654. 'datatype' => 'TEXT',
  655. 'allow_null' => true
  656. ),
  657. 'num_topics' => array(
  658. 'datatype' => 'MEDIUMINT(8) UNSIGNED',
  659. 'allow_null' => false,
  660. 'default' => '0'
  661. ),
  662. 'num_posts' => array(
  663. 'datatype' => 'MEDIUMINT(8) UNSIGNED',
  664. 'allow_null' => false,
  665. 'default' => '0'
  666. ),
  667. 'last_post' => array(
  668. 'datatype' => 'INT(10) UNSIGNED',
  669. 'allow_null' => true
  670. ),
  671. 'last_post_id' => array(
  672. 'datatype' => 'INT(10) UNSIGNED',
  673. 'allow_null' => true
  674. ),
  675. 'last_poster' => array(
  676. 'datatype' => 'VARCHAR(200)',
  677. 'allow_null' => true
  678. ),
  679. 'sort_by' => array(
  680. 'datatype' => 'TINYINT(1)',
  681. 'allow_null' => false,
  682. 'default' => '0'
  683. ),
  684. 'disp_position' => array(
  685. 'datatype' => 'INT(10)',
  686. 'allow_null' => false,
  687. 'default' => '0'
  688. ),
  689. 'cat_id' => array(
  690. 'datatype' => 'INT(10) UNSIGNED',
  691. 'allow_null' => false,
  692. 'default' => '0'
  693. )
  694. ),
  695. 'PRIMARY KEY' => array('id')
  696. );
  697. $forum_db->create_table('forums', $schema);
  698. $schema = array(
  699. 'FIELDS' => array(
  700. 'g_id' => array(
  701. 'datatype' => 'SERIAL',
  702. 'allow_null' => false
  703. ),
  704. 'g_title' => array(
  705. 'datatype' => 'VARCHAR(50)',
  706. 'allow_null' => false,
  707. 'default' => '\'\''
  708. ),
  709. 'g_user_title' => array(
  710. 'datatype' => 'VARCHAR(50)',
  711. 'allow_null' => true
  712. ),
  713. 'g_moderator' => array(
  714. 'datatype' => 'TINYINT(1)',
  715. 'allow_null' => false,
  716. 'default' => '0'
  717. ),
  718. 'g_mod_edit_users' => array(
  719. 'datatype' => 'TINYINT(1)',
  720. 'allow_null' => false,
  721. 'default' => '0'
  722. ),
  723. 'g_mod_rename_users' => array(
  724. 'datatype' => 'TINYINT(1)',
  725. 'allow_null' => false,
  726. 'default' => '0'
  727. ),
  728. 'g_mod_change_passwords' => array(
  729. 'datatype' => 'TINYINT(1)',
  730. 'allow_null' => false,
  731. 'default' => '0'
  732. ),
  733. 'g_mod_ban_users' => array(
  734. 'datatype' => 'TINYINT(1)',
  735. 'allow_null' => false,
  736. 'default' => '0'
  737. ),
  738. 'g_read_board' => array(
  739. 'datatype' => 'TINYINT(1)',
  740. 'allow_null' => false,
  741. 'default' => '1'
  742. ),
  743. 'g_view_users' => array(
  744. 'datatype' => 'TINYINT(1)',
  745. 'allow_null' => false,
  746. 'default' => '1'
  747. ),
  748. 'g_post_replies' => array(
  749. 'datatype' => 'TINYINT(1)',
  750. 'allow_null' => false,
  751. 'default' => '1'
  752. ),
  753. 'g_post_topics' => array(
  754. 'datatype' => 'TINYINT(1)',
  755. 'allow_null' => false,
  756. 'default' => '1'
  757. ),
  758. 'g_edit_posts' => array(
  759. 'datatype' => 'TINYINT(1)',
  760. 'allow_null' => false,
  761. 'default' => '1'
  762. ),
  763. 'g_delete_posts' => array(
  764. 'datatype' => 'TINYINT(1)',
  765. 'allow_null' => false,
  766. 'default' => '1'
  767. ),
  768. 'g_delete_topics' => array(
  769. 'datatype' => 'TINYINT(1)',
  770. 'allow_null' => false,
  771. 'default' => '1'
  772. ),
  773. 'g_set_title' => array(
  774. 'datatype' => 'TINYINT(1)',
  775. 'allow_null' => false,
  776. 'default' => '1'
  777. ),
  778. 'g_search' => array(
  779. 'datatype' => 'TINYINT(1)',
  780. 'allow_null' => false,
  781. 'default' => '1'
  782. ),
  783. 'g_search_users' => array(
  784. 'datatype' => 'TINYINT(1)',
  785. 'allow_null' => false,
  786. 'default' => '1'
  787. ),
  788. 'g_send_email' => array(
  789. 'datatype' => 'TINYINT(1)',
  790. 'allow_null' => false,
  791. 'default' => '1'
  792. ),
  793. 'g_post_flood' => array(
  794. 'datatype' => 'SMALLINT(6)',
  795. 'allow_null' => false,
  796. 'default' => '30'
  797. ),
  798. 'g_search_flood' => array(
  799. 'datatype' => 'SMALLINT(6)',
  800. 'allow_null' => false,
  801. 'default' => '30'
  802. ),
  803. 'g_email_flood' => array(
  804. 'datatype' => 'SMALLINT(6)',
  805. 'allow_null' => false,
  806. 'default' => '60'
  807. )
  808. ),
  809. 'PRIMARY KEY' => array('g_id')
  810. );
  811. $forum_db->create_table('groups', $schema);
  812. $schema = array(
  813. 'FIELDS' => array(
  814. 'user_id' => array(
  815. 'datatype' => 'INT(10) UNSIGNED',
  816. 'allow_null' => false,
  817. 'default' => '1'
  818. ),
  819. 'ident' => array(
  820. 'datatype' => 'VARCHAR(200)',
  821. 'allow_null' => false,
  822. 'default' => '\'\''
  823. ),
  824. 'logged' => array(
  825. 'datatype' => 'INT(10) UNSIGNED',
  826. 'allow_null' => false,
  827. 'default' => '0'
  828. ),
  829. 'idle' => array(
  830. 'datatype' => 'TINYINT(1)',
  831. 'allow_null' => false,
  832. 'default' => '0'
  833. ),
  834. 'csrf_token' => array(
  835. 'datatype' => 'VARCHAR(40)',
  836. 'allow_null' => false,
  837. 'default' => '\'\''
  838. ),
  839. 'prev_url' => array(
  840. 'datatype' => 'VARCHAR(255)',
  841. 'allow_null' => true
  842. ),
  843. 'last_post' => array(
  844. 'datatype' => 'INT(10) UNSIGNED',
  845. 'allow_null' => true
  846. ),
  847. 'last_search' => array(
  848. 'datatype' => 'INT(10) UNSIGNED',
  849. 'allow_null' => true
  850. ),
  851. ),
  852. 'UNIQUE KEYS' => array(
  853. 'user_id_ident_idx' => array('user_id', 'ident')
  854. ),
  855. 'INDEXES' => array(
  856. 'ident_idx' => array('ident'),
  857. 'logged_idx' => array('logged')
  858. ),
  859. 'ENGINE' => 'HEAP'
  860. );
  861. if (in_array($db_type, array('mysql', 'mysqli', 'mysql_innodb', 'mysqli_innodb')))
  862. {
  863. $schema['UNIQUE KEYS']['user_id_ident_idx'] = array('user_id', 'ident(25)');
  864. $schema['INDEXES']['ident_idx'] = array('ident(25)');
  865. }
  866. $forum_db->create_table('online', $schema);
  867. $schema = array(
  868. 'FIELDS' => array(
  869. 'id' => array(
  870. 'datatype' => 'SERIAL',
  871. 'allow_null' => false
  872. ),
  873. 'poster' => array(
  874. 'datatype' => 'VARCHAR(200)',
  875. 'allow_null' => false,
  876. 'default' => '\'\''
  877. ),
  878. 'poster_id' => array(
  879. 'datatype' => 'INT(10) UNSIGNED',
  880. 'allow_null' => false,
  881. 'default' => '1'
  882. ),
  883. 'poster_ip' => array(
  884. 'datatype' => 'VARCHAR(39)',
  885. 'allow_null' => true
  886. ),
  887. 'poster_email' => array(
  888. 'datatype' => 'VARCHAR(80)',
  889. 'allow_null' => true
  890. ),
  891. 'message' => array(
  892. 'datatype' => 'TEXT',
  893. 'allow_null' => true
  894. ),
  895. 'hide_smilies' => array(
  896. 'datatype' => 'TINYINT(1)',
  897. 'allow_null' => false,
  898. 'default' => '0'
  899. ),
  900. 'posted' => array(
  901. 'datatype' => 'INT(10) UNSIGNED',
  902. 'allow_null' => false,
  903. 'default' => '0'
  904. ),
  905. 'edited' => array(
  906. 'datatype' => 'INT(10) UNSIGNED',
  907. 'allow_null' => true
  908. ),
  909. 'edited_by' => array(
  910. 'datatype' => 'VARCHAR(200)',
  911. 'allow_null' => true
  912. ),
  913. 'topic_id' => array(
  914. 'datatype' => 'INT(10) UNSIGNED',
  915. 'allow_null' => false,
  916. 'default' => '0'
  917. )
  918. ),
  919. 'PRIMARY KEY' => array('id'),
  920. 'INDEXES' => array(
  921. 'topic_id_idx' => array('topic_id'),
  922. 'multi_idx' => array('poster_id', 'topic_id'),
  923. 'posted_idx' => array('posted')
  924. )
  925. );
  926. $forum_db->create_table('posts', $schema);
  927. $schema = array(
  928. 'FIELDS' => array(
  929. 'id' => array(
  930. 'datatype' => 'SERIAL',
  931. 'allow_null' => false
  932. ),
  933. 'rank' => array(
  934. 'datatype' => 'VARCHAR(50)',
  935. 'allow_null' => false,
  936. 'default' => '\'\''
  937. ),
  938. 'min_posts' => array(
  939. 'datatype' => 'MEDIUMINT(8) UNSIGNED',
  940. 'allow_null' => false,
  941. 'default' => '0'
  942. )
  943. ),
  944. 'PRIMARY KEY' => array('id')
  945. );
  946. $forum_db->create_table('ranks', $schema);
  947. $schema = array(
  948. 'FIELDS' => array(
  949. 'id' => array(
  950. 'datatype' => 'SERIAL',
  951. 'allow_null' => false
  952. ),
  953. 'post_id' => array(
  954. 'datatype' => 'INT(10) UNSIGNED',
  955. 'allow_null' => false,
  956. 'default' => '0'
  957. ),
  958. 'topic_id' => array(
  959. 'datatype' => 'INT(10) UNSIGNED',
  960. 'allow_null' => false,
  961. 'default' => '0'
  962. ),
  963. 'forum_id' => array(
  964. 'datatype' => 'INT(10) UNSIGNED',
  965. 'allow_null' => false,
  966. 'default' => '0'
  967. ),
  968. 'reported_by' => array(
  969. 'datatype' => 'INT(10) UNSIGNED',
  970. 'allow_null' => false,
  971. 'default' => '0'
  972. ),
  973. 'created' => array(
  974. 'datatype' => 'INT(10) UNSIGNED',
  975. 'allow_null' => false,
  976. 'default' => '0'
  977. ),
  978. 'message' => array(
  979. 'datatype' => 'TEXT',
  980. 'allow_null' => true
  981. ),
  982. 'zapped' => array(
  983. 'datatype' => 'INT(10) UNSIGNED',
  984. 'allow_null' => true
  985. ),
  986. 'zapped_by' => array(
  987. 'datatype' => 'INT(10) UNSIGNED',
  988. 'allow_null' => true
  989. )
  990. ),
  991. 'PRIMARY KEY' => array('id'),
  992. 'INDEXES' => array(
  993. 'zapped_idx' => array('zapped')
  994. )
  995. );
  996. $forum_db->create_table('reports', $schema);
  997. $schema = array(
  998. 'FIELDS' => array(
  999. 'id' => array(
  1000. 'datatype' => 'INT(10) UNSIGNED',
  1001. 'allow_null' => false,
  1002. 'default' => '0'
  1003. ),
  1004. 'ident' => array(
  1005. 'datatype' => 'VARCHAR(200)',
  1006. 'allow_null' => false,
  1007. 'default' => '\'\''
  1008. ),
  1009. 'search_data' => array(
  1010. 'datatype' => 'TEXT',
  1011. 'allow_null' => true
  1012. )
  1013. ),
  1014. 'PRIMARY KEY' => array('id'),
  1015. 'INDEXES' => array(
  1016. 'ident_idx' => array('ident')
  1017. )
  1018. );
  1019. if (in_array($db_type, array('mysql', 'mysqli', 'mysql_innodb', 'mysqli_innodb')))
  1020. $schema['INDEXES']['ident_idx'] = array('ident(8)');
  1021. $forum_db->create_table('search_cache', $schema);
  1022. $schema = array(
  1023. 'FIELDS' => array(
  1024. 'post_id' => array(
  1025. 'datatype' => 'INT(10) UNSIGNED',
  1026. 'allow_null' => false,
  1027. 'default' => '0'
  1028. ),
  1029. 'word_id' => array(
  1030. 'datatype' => 'INT(10) UNSIGNED',
  1031. 'allow_null' => false,
  1032. 'default' => '0'
  1033. ),
  1034. 'subject_match' => array(
  1035. 'datatype' => 'TINYINT(1)',
  1036. 'allow_null' => false,
  1037. 'default' => '0'
  1038. )
  1039. ),
  1040. 'INDEXES' => array(
  1041. 'word_id_idx' => array('word_id'),
  1042. 'post_id_idx' => array('post_id')
  1043. )
  1044. );
  1045. $forum_db->create_table('search_matches', $schema);
  1046. $schema = array(
  1047. 'FIELDS' => array(
  1048. 'id' => array(
  1049. 'datatype' => 'SERIAL',
  1050. 'allow_null' => false
  1051. ),
  1052. 'word' => array(
  1053. 'datatype' => 'VARCHAR(20)',
  1054. 'allow_null' => false,
  1055. 'default' => '\'\'',
  1056. 'collation' => 'bin'
  1057. )
  1058. ),
  1059. 'PRIMARY KEY' => array('word'),
  1060. 'INDEXES' => array(
  1061. 'id_idx' => array('id')
  1062. )
  1063. );
  1064. if ($db_type == 'sqlite' || $db_type == 'sqlite3')
  1065. {
  1066. $schema['PRIMARY KEY'] = array('id');
  1067. $schema['UNIQUE KEYS'] = array('word_idx' => array('word'));
  1068. }
  1069. $forum_db->create_table('search_words', $schema);
  1070. $schema = array(
  1071. 'FIELDS' => array(
  1072. 'user_id' => array(
  1073. 'datatype' => 'INT(10) UNSIGNED',
  1074. 'allow_null' => false,
  1075. 'default' => '0'
  1076. ),
  1077. 'topic_id' => array(
  1078. 'datatype' => 'INT(10) UNSIGNED',
  1079. 'allow_null' => false,
  1080. 'default' => '0'
  1081. )
  1082. ),
  1083. 'PRIMARY KEY' => array('user_id', 'topic_id')
  1084. );
  1085. $forum_db->create_table('subscriptions', $schema);
  1086. $schema = array(
  1087. 'FIELDS' => array(
  1088. 'user_id' => array(
  1089. 'datatype' => 'INT(10) UNSIGNED',
  1090. 'allow_null' => false,
  1091. 'default' => '0'
  1092. ),
  1093. 'forum_id' => array(
  1094. 'datatype' => 'INT(10) UNSIGNED',
  1095. 'allow_null' => false,
  1096. 'default' => '0'
  1097. )
  1098. ),
  1099. 'PRIMARY KEY' => array('user_id', 'forum_id')
  1100. );
  1101. $forum_db->create_table('forum_subscriptions', $schema);
  1102. $schema = array(
  1103. 'FIELDS' => array(
  1104. 'id' => array(
  1105. 'datatype' => 'SERIAL',
  1106. 'allow_null' => false
  1107. ),
  1108. 'poster' => array(
  1109. 'datatype' => 'VARCHAR(200)',
  1110. 'allow_null' => false,
  1111. 'default' => '\'\''
  1112. ),
  1113. 'subject' => array(
  1114. 'datatype' => 'VARCHAR(255)',
  1115. 'allow_null' => false,
  1116. 'default' => '\'\''
  1117. ),
  1118. 'posted' => array(
  1119. 'datatype' => 'INT(10) UNSIGNED',
  1120. 'allow_null' => false,
  1121. 'default' => '0'
  1122. ),
  1123. 'first_post_id' => array(
  1124. 'datatype' => 'INT(10) UNSIGNED',
  1125. 'allow_null' => false,
  1126. 'default' => '0'
  1127. ),
  1128. 'last_post' => array(
  1129. 'datatype' => 'INT(10) UNSIGNED',
  1130. 'allow_null' => false,
  1131. 'default' => '0'
  1132. ),
  1133. 'last_post_id' => array(
  1134. 'datatype' => 'INT(10) UNSIGNED',
  1135. 'allow_null' => false,
  1136. 'default' => '0'
  1137. ),
  1138. 'last_poster' => array(
  1139. 'datatype' => 'VARCHAR(200)',
  1140. 'allow_null' => true
  1141. ),
  1142. 'num_views' => array(
  1143. 'datatype' => 'MEDIUMINT(8) UNSIGNED',
  1144. 'allow_null' => false,
  1145. 'default' => '0'
  1146. ),
  1147. 'num_replies' => array(
  1148. 'datatype' => 'MEDIUMINT(8) UNSIGNED',
  1149. 'allow_null' => false,
  1150. 'default' => '0'
  1151. ),
  1152. 'closed' => array(
  1153. 'datatype' => 'TINYINT(1)',
  1154. 'allow_null' => false,
  1155. 'default' => '0'
  1156. ),
  1157. 'sticky' => array(
  1158. 'datatype' => 'TINYINT(1)',
  1159. 'allow_null' => false,
  1160. 'default' => '0'
  1161. ),
  1162. 'moved_to' => array(
  1163. 'datatype' => 'INT(10) UNSIGNED',
  1164. 'allow_null' => true
  1165. ),
  1166. 'forum_id' => array(
  1167. 'datatype' => 'INT(10) UNSIGNED',
  1168. 'allow_null' => false,
  1169. 'default' => '0'
  1170. )
  1171. ),
  1172. 'PRIMARY KEY' => array('id'),
  1173. 'INDEXES' => array(
  1174. 'forum_id_idx' => array('forum_id'),
  1175. 'moved_to_idx' => array('moved_to'),
  1176. 'last_post_idx' => array('last_post'),
  1177. 'first_post_id_idx' => array('first_post_id')
  1178. )
  1179. );
  1180. $forum_db->create_table('topics', $schema);
  1181. $schema = array(
  1182. 'FIELDS' => array(
  1183. 'id' => array(
  1184. 'datatype' => 'SERIAL',
  1185. 'allow_null' => false
  1186. ),
  1187. 'group_id' => array(
  1188. 'datatype' => 'INT(10) UNSIGNED',
  1189. 'allow_null' => false,
  1190. 'default' => '3'
  1191. ),
  1192. 'username' => array(
  1193. 'datatype' => 'VARCHAR(200)',
  1194. 'allow_null' => false,
  1195. 'default' => '\'\''
  1196. ),
  1197. 'password' => array(
  1198. 'datatype' => 'VARCHAR(40)',
  1199. 'allow_null' => false,
  1200. 'default' => '\'\''
  1201. ),
  1202. 'salt' => array(
  1203. 'datatype' => 'VARCHAR(12)',
  1204. 'allow_null' => true
  1205. ),
  1206. 'email' => array(
  1207. 'datatype' => 'VARCHAR(80)',
  1208. 'allow_null' => false,
  1209. 'default' => '\'\''
  1210. ),
  1211. 'title' => array(
  1212. 'datatype' => 'VARCHAR(50)',
  1213. 'allow_null' => true
  1214. ),
  1215. 'realname' => array(
  1216. 'datatype' => 'VARCHAR(40)',
  1217. 'allow_null' => true
  1218. ),
  1219. 'url' => array(
  1220. 'datatype' => 'VARCHAR(100)',
  1221. 'allow_null' => true
  1222. ),
  1223. 'facebook' => array(
  1224. 'datatype' => 'VARCHAR(100)',
  1225. 'allow_null' => true
  1226. ),
  1227. 'twitter' => array(
  1228. 'datatype' => 'VARCHAR(100)',
  1229. 'allow_null' => true
  1230. ),
  1231. 'linkedin' => array(
  1232. 'datatype' => 'VARCHAR(100)',
  1233. 'allow_null' => true
  1234. ),
  1235. 'skype' => array(
  1236. 'datatype' => 'VARCHAR(100)',
  1237. 'allow_null' => true
  1238. ),
  1239. 'jabber' => array(
  1240. 'datatype' => 'VARCHAR(80)',
  1241. 'allow_null' => true
  1242. ),
  1243. 'icq' => array(
  1244. 'datatype' => 'VARCHAR(12)',
  1245. 'allow_null' => true
  1246. ),
  1247. 'msn' => array(
  1248. 'datatype' => 'VARCHAR(80)',
  1249. 'allow_null' => true
  1250. ),
  1251. 'aim' => array(
  1252. 'datatype' => 'VARCHAR(30)',
  1253. 'allow_null' => true
  1254. ),
  1255. 'yahoo' => array(
  1256. 'datatype' => 'VARCHAR(30)',
  1257. 'allow_null' => true
  1258. ),
  1259. 'location' => array(
  1260. 'datatype' => 'VARCHAR(30)',
  1261. 'allow_null' => true
  1262. ),
  1263. 'signature' => array(
  1264. 'datatype' => 'TEXT',
  1265. 'allow_null' => true
  1266. ),
  1267. 'disp_topics' => array(
  1268. 'datatype' => 'TINYINT(3) UNSIGNED',
  1269. 'allow_null' => true
  1270. ),
  1271. 'disp_posts' => array(
  1272. 'datatype' => 'TINYINT(3) UNSIGNED',
  1273. 'allow_null' => true
  1274. ),
  1275. 'email_setting' => array(
  1276. 'datatype' => 'TINYINT(1)',
  1277. 'allow_null' => false,
  1278. 'default' => '1'
  1279. ),
  1280. 'notify_with_post' => array(
  1281. 'datatype' => 'TINYINT(1)',
  1282. 'allow_null' => false,
  1283. 'default' => '0'
  1284. ),
  1285. 'auto_notify' => array(
  1286. 'datatype' => 'TINYINT(1)',
  1287. 'allow_null' => false,
  1288. 'default' => '0'
  1289. ),
  1290. 'show_smilies' => array(
  1291. 'datatype' => 'TINYINT(1)',
  1292. 'allow_null' => false,
  1293. 'default' => '1'
  1294. ),
  1295. 'show_img' => array(
  1296. 'datatype' => 'TINYINT(1)',
  1297. 'allow_null' => false,
  1298. 'default' => '1'
  1299. ),
  1300. 'show_img_sig' => array(
  1301. 'datatype' => 'TINYINT(1)',
  1302. 'allow_null' => false,
  1303. 'default' => '1'
  1304. ),
  1305. 'show_avatars' => array(
  1306. 'datatype' => 'TINYINT(1)',
  1307. 'allow_null' => false,
  1308. 'default' => '1'
  1309. ),
  1310. 'show_sig' => array(
  1311. 'datatype' => 'TINYINT(1)',
  1312. 'allow_null' => false,
  1313. 'default' => '1'
  1314. ),
  1315. 'access_keys' => array(
  1316. 'datatype' => 'TINYINT(1)',
  1317. 'allow_null' => false,
  1318. 'default' => '0'
  1319. ),
  1320. 'timezone' => array(
  1321. 'datatype' => 'FLOAT',
  1322. 'allow_null' => false,
  1323. 'default' => '0'
  1324. ),
  1325. 'dst' => array(
  1326. 'datatype' => 'TINYINT(1)',
  1327. 'allow_null' => false,
  1328. 'default' => '0'
  1329. ),
  1330. 'time_format' => array(
  1331. 'datatype' => 'INT(10) UNSIGNED',
  1332. 'allow_null' => false,
  1333. 'default' => '0'
  1334. ),
  1335. 'date_format' => array(
  1336. 'datatype' => 'INT(10) UNSIGNED',
  1337. 'allow_null' => false,
  1338. 'default' => '0'
  1339. ),
  1340. 'language' => array(
  1341. 'datatype' => 'VARCHAR(25)',
  1342. 'allow_null' => false,
  1343. 'default' => '\'English\''
  1344. ),
  1345. 'style' => array(
  1346. 'datatype' => 'VARCHAR(25)',
  1347. 'allow_null' => false,
  1348. 'default' => '\'Oxygen\''
  1349. ),
  1350. 'num_posts' => array(
  1351. 'datatype' => 'INT(10) UNSIGNED',
  1352. 'allow_null' => false,
  1353. 'default' => '0'
  1354. ),
  1355. 'last_post' => array(
  1356. 'datatype' => 'INT(10) UNSIGNED',
  1357. 'allow_null' => true
  1358. ),
  1359. 'last_search' => array(
  1360. 'datatype' => 'INT(10) UNSIGNED',
  1361. 'allow_null' => true
  1362. ),
  1363. 'last_email_sent' => array(
  1364. 'datatype' => 'INT(10) UNSIGNED',
  1365. 'allow_null' => true
  1366. ),
  1367. 'registered' => array(
  1368. 'datatype' => 'INT(10) UNSIGNED',
  1369. 'allow_null' => false,
  1370. 'default' => '0'
  1371. ),
  1372. 'registration_ip' => array(
  1373. 'datatype' => 'VARCHAR(39)',
  1374. 'allow_null' => false,
  1375. 'default' => '\'0.0.0.0\''
  1376. ),
  1377. 'last_visit' => array(
  1378. 'datatype' => 'INT(10) UNSIGNED',
  1379. 'allow_null' => false,
  1380. 'default' => '0'
  1381. ),
  1382. 'admin_note' => array(
  1383. 'datatype' => 'VARCHAR(30)',
  1384. 'allow_null' => true
  1385. ),
  1386. 'activate_string' => array(
  1387. 'datatype' => 'VARCHAR(80)',
  1388. 'allow_null' => true
  1389. ),
  1390. 'activate_key' => array(
  1391. 'datatype' => 'VARCHAR(8)',
  1392. 'allow_null' => true
  1393. ),
  1394. 'avatar' => array(
  1395. 'datatype' => 'TINYINT(3) UNSIGNED',
  1396. 'allow_null' => false,
  1397. 'default' => 0,
  1398. ),
  1399. 'avatar_width' => array(
  1400. 'datatype' => 'TINYINT(3) UNSIGNED',
  1401. 'allow_null' => false,
  1402. 'default' => 0,
  1403. ),
  1404. 'avatar_height' => array(
  1405. 'datatype' => 'TINYINT(3) UNSIGNED',
  1406. 'allow_null' => false,
  1407. 'default' => 0,
  1408. ),
  1409. ),
  1410. 'PRIMARY KEY' => array('id'),
  1411. 'INDEXES' => array(
  1412. 'registered_idx' => array('registered'),
  1413. 'username_idx' => array('username')
  1414. )
  1415. );
  1416. if (in_array($db_type, array('mysql', 'mysqli', 'mysql_innodb', 'mysqli_innodb')))
  1417. $schema['INDEXES']['username_idx'] = array('username(8)');
  1418. $forum_db->create_table('users', $schema);
  1419. $now = time();
  1420. // Insert the four preset groups
  1421. $query = array(
  1422. 'INSERT' => 'g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood',
  1423. 'INTO' => 'groups',
  1424. 'VALUES' => '\'Administrators\', \'Administrator\', 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0'
  1425. );
  1426. if ($db_type != 'pgsql')
  1427. {
  1428. $query['INSERT'] .= ', g_id';
  1429. $query['VALUES'] .= ', 1';
  1430. }
  1431. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  1432. $query = array(
  1433. 'INSERT' => 'g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood',
  1434. 'INTO' => 'groups',
  1435. 'VALUES' => '\'Guest\', NULL, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 60, 30, 0'
  1436. );
  1437. if ($db_type != 'pgsql')
  1438. {
  1439. $query['INSERT'] .= ', g_id';
  1440. $query['VALUES'] .= ', 2';
  1441. }
  1442. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  1443. $query = array(
  1444. 'INSERT' => 'g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood',
  1445. 'INTO' => 'groups',
  1446. 'VALUES' => '\'Members\', NULL, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 60, 30, 60'
  1447. );
  1448. if ($db_type != 'pgsql')
  1449. {
  1450. $query['INSERT'] .= ', g_id';
  1451. $query['VALUES'] .= ', 3';
  1452. }
  1453. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  1454. $query = array(
  1455. 'INSERT' => 'g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood',
  1456. 'INTO' => 'groups',
  1457. 'VALUES' => '\'Moderators\', \'Moderator\', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0'
  1458. );
  1459. if ($db_type != 'pgsql')
  1460. {
  1461. $query['INSERT'] .= ', g_id';
  1462. $query['VALUES'] .= ', 4';
  1463. }
  1464. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  1465. // Insert guest and first admin user
  1466. $query = array(
  1467. 'INSERT' => 'group_id, username, password, email',
  1468. 'INTO' => 'users',
  1469. 'VALUES' => '2, \'Guest\', \'Guest\', \'Guest\''
  1470. );
  1471. if ($db_type != 'pgsql')
  1472. {
  1473. $query['INSERT'] .= ', id';
  1474. $query['VALUES'] .= ', 1';
  1475. }
  1476. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  1477. $salt = random_key(12);
  1478. $query = array(
  1479. 'INSERT' => 'group_id, username, password, email, language, num_posts, last_post, registered, registration_ip, last_visit, salt',
  1480. 'INTO' => 'users',
  1481. 'VALUES' => '1, \''.$forum_db->escape($username).'\', \''.forum_hash($password1, $salt).'\', \''.$forum_db->escape($email).'\', \''.$forum_db->escape($default_lang).'\', 1, '.$now.', '.$now.', \'127.0.0.1\', '.$now.', \''.$forum_db->escape($salt).'\''
  1482. );
  1483. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  1484. $new_uid = $forum_db->insert_id();
  1485. // Enable/disable avatars depending on file_uploads setting in PHP configuration
  1486. $avatars = in_array(strtolower(@ini_get('file_uploads')), array('on', 'true', '1')) ? 1 : 0;
  1487. // Enable/disable automatic check for updates depending on PHP environment (require cURL, fsockopen or allow_url_fopen)
  1488. $check_for_updates = (function_exists('curl_init') || function_exists('fsockopen') || in_array(strtolower(@ini_get('allow_url_fopen')), array('on', 'true', '1'))) ? 1 : 0;
  1489. // Insert config data
  1490. $config = array(
  1491. 'o_cur_version' => "'".FORUM_VERSION."'",
  1492. 'o_database_revision' => "'".FORUM_DB_REVISION."'",
  1493. 'o_board_title' => "'".$forum_db->escape($board_title)."'",
  1494. 'o_board_desc' => "'".$forum_db->escape($board_descrip)."'",
  1495. 'o_default_timezone' => "'0'",
  1496. 'o_time_format' => "'H:i:s'",
  1497. 'o_date_format' => "'Y-m-d'",
  1498. 'o_check_for_updates' => "'$check_for_updates'",
  1499. 'o_check_for_versions' => "'$check_for_updates'",
  1500. 'o_timeout_visit' => "'5400'",
  1501. 'o_timeout_online' => "'300'",
  1502. 'o_redirect_delay' => "'0'",
  1503. 'o_show_version' => "'0'",
  1504. 'o_show_user_info' => "'1'",
  1505. 'o_show_post_count' => "'1'",
  1506. 'o_signatures' => "'1'",
  1507. 'o_smilies' => "'1'",
  1508. 'o_smilies_sig' => "'1'",
  1509. 'o_make_links' => "'1'",
  1510. 'o_default_lang' => "'".$forum_db->escape($default_lang)."'",
  1511. 'o_default_style' => "'Oxygen'",
  1512. 'o_default_user_group' => "'3'",
  1513. 'o_topic_review' => "'15'",
  1514. 'o_disp_topics_default' => "'30'",
  1515. 'o_disp_posts_default' => "'25'",
  1516. 'o_indent_num_spaces' => "'4'",
  1517. 'o_quote_depth' => "'3'",
  1518. 'o_quickpost' => "'1'",
  1519. 'o_users_online' => "'1'",
  1520. 'o_censoring' => "'0'",
  1521. 'o_ranks'

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