NBZ SubDomain Script - NBS






 

 

NBZ SubDomain Script - NBS

View Full Version : NBZ SubDomain Script


Cronos
08-Sep-2006, 11:34 AM
Requirements
Before you get too excited, you should know that only a minority of all web hosts meet the requirements of this script. To use Subdomains, you need a web site account with the following features:
Your own domain, i.e. yoursite.com.
Wildcarded DNS. The script will not function without this feature. To check if your web host offers wildcarded DNS, you can perform the following test: Start your browser, pick a random word (i.e. "asdf"), and enter your domain name with the random word in front of it like this: asdf.yoursite.com. If you can see the front page of your web site in your browser now, your web host offers wildcarded DNS. However, if the browser response is something like "unable to locate the server asdf.yoursite.com", then your web host does not offer wildcarded DNS, and you cannot use Subdomains (unless, of course, you move to a server that offers this feature).
PHP (version 3 or later). Ask your web hosting company if you don't know if they offer PHP.
.htaccess. In some cases it is necessary to edit the .htaccess file in order to make the script work. This means that your web host must provide you with the ability to use .htaccess files. If the name of the web server software is Apache, then it is very likely that you can use .htaccess files -- but ask your web hosting company if you are unsure.

The requirement is the same as mentioned by ForumZClub

now, this is the file you have to edit to enable this edit of the code
( if you aren't expert in php programming or similar take mind you coul make some mistake, or irreparabile damage to your script )
first of all my hints is to do a backup of your current file
after this, this modification is in 'unstable' version, this means you could find much bug

ok, if you are ready to continue, all you have to do is simply to replace this file:

handler.php

<?php
define('THIS_SCRIPT', 'handler');
define('IN_NBS', true);
define('CVS_REVISION', '$RCSfile: handler.php,v $ - $Revision: 1.16 $');
require_once('nbs/global.php');

$domainName = $nbs->setting['domain'];

$server = $_SERVER['SERVER_NAME'];
$url = $_GET['_url'];

$param = $HTTP_SERVER_VARS['QUERY_STRING'];
$param = substr($param,strpos($param,'&'));
$param[0] = '?';

preg_match('#(.*?)\/(.*?)$#', $_GET['_url'], $matches);

$forum = $matches[1];
$script = $matches[2];
if ($forum == '')
{
preg_match('#(.*?)$#', $_GET['_url'], $match);
$forum = $match[1];
if ($forum != '')
header("Location: http://" . $forum . "." . $nbs->setting['domain'] . $nbs->setting['path'] . $param);
//header("Location: http://" . $forum . "." . $nbs->setting['domain'] . $nbs->setting['path'] . $redirect . $sid . $admin);
}
else
{
header("Location: http://" . $forum . "." . $nbs->setting['domain'] . $nbs->setting['path'] . $script . $param);
//header("Location: http://" . $forum . "." . $nbs->setting['domain'] . $nbs->setting['path'] . $script . $redirect . $sid . $admin);
}
if ($forum == '')
{
if ($domainName != $server)
{
$subSize = strlen($server)-strlen($domainName)-1;
$subDomain = substr($server,0,$subSize);
$forum = $subDomain;
}
else
{
$slashPosition = strpos($url,'/');
$forum = substr($url,0,$slashPosition);
$script = substr($url,$slashPosition+1,1000);
}
}

if ($forum == '')
header("Location: http://www.".$domainName."/");
else
{
// Se ho scelto un qualche forum
// Non ho scelto nessuno script in particolare, il default è index.php
if ($script == '')
$script = 'index.php';

$global_ads = $nbs->setting['global_ads'];

$misc1 = "SELECT status, header_ads, footer_ads FROM " . TABLE_PREFIX . "users WHERE accessname='" . $db->escape_string($forum) . "'";
$misc2 = $db->query($misc1);
$misc3 = $db->fetch_array($misc2);

$status = $misc3['status'];

$header_ads = $misc3['header_ads'];
$footer_ads = $misc3['footer_ads'];

$db->free_result($misc2);

$db->close();

unset($misc1, $misc3, $nbs, $db);

if (file_exists($script))
{
if (substr($script, 0, 5) == 'admin')
{
chdir('admin');

include($script);
}
else
{
if (substr($script, -3) == 'gif' OR substr($script, -3) == 'jpg' OR substr($script, -3) == 'png' OR substr($script, -4) == 'jpeg')
{
$contents = file_get_contents($script);

echo $contents;
}
else
{
include($script);
}
}
}
}
?>


.htaccess

DirectoryIndex handler.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ handler.php?_url=$1&%{QUERY_STRING} [L]

( i don't matter about the credit to chroder, i don't know what i've to do, if keep the credits, edit it, or other.. anyway.. )

common.php

<?php
/************************************************** *************************
* common.php
* -------------------
* begin : Saturday, Feb 23, 2001
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id: common.php,v 1.74.2.25 2006/05/26 17:46:59 grahamje Exp $
*
************************************************** *************************/
/************************************************** *************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
************************************************** *************************/

if (!$forum)
{
define('THIS_SCRIPT', 'common');
define('IN_NBS', true);
define('CVS_REVISION', '$RCSfile: common.php,v $ - $Revision: 1.16 $');
require_once('nbs/global.php');

$domainName = $nbs->setting['domain'];

$server = $_SERVER['SERVER_NAME'];
$url = $_GET['_url'];

if ($domainName != $server)
{
$subSize = strlen($server)-strlen($domainName)-1;
$subDomain = substr($server,0,$subSize);
$forum = $subDomain;
}
else
{
$slashPosition = strpos($url,'/');
$forum = substr($url,0,$slashPosition);
$script = substr($url,$slashPosition+1,1000);
}
if ($script == '')
$script = 'index.php';

$global_ads = $nbs->setting['global_ads'];

$misc1 = "SELECT status, header_ads, footer_ads FROM " . TABLE_PREFIX . "users WHERE accessname='" . $db->escape_string($forum) . "'";
$misc2 = $db->query($misc1);
$misc3 = $db->fetch_array($misc2);

$status = $misc3['status'];

$header_ads = $misc3['header_ads'];
$footer_ads = $misc3['footer_ads'];

$db->free_result($misc2);

$db->close();

unset($misc1, $misc3, $nbs, $db);
}


if ( !defined('IN_PHPBB') )
{
die("Hacking attempt");
}

//
error_reporting (E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitialized variables
set_magic_quotes_runtime(0); // Disable magic_quotes_runtime

// The following code (unsetting globals)
// Thanks to Matt Kavanagh and Stefan Esser for providing feedback as well as patch files

// PHP5 with register_long_arrays off?
if (@phpversion() >= '5.0.0' && (!@ini_get('register_long_arrays') || @ini_get('register_long_arrays') == '0' || strtolower(@ini_get('register_long_arrays')) == 'off'))
{
$HTTP_POST_VARS = $_POST;
$HTTP_GET_VARS = $_GET;
$HTTP_SERVER_VARS = $_SERVER;
$HTTP_COOKIE_VARS = $_COOKIE;
$HTTP_ENV_VARS = $_ENV;
$HTTP_POST_FILES = $_FILES;

// _SESSION is the only superglobal which is conditionally set
if (isset($_SESSION))
{
$HTTP_SESSION_VARS = $_SESSION;
}
}

// Protect against GLOBALS tricks
if (isset($HTTP_POST_VARS['GLOBALS']) || isset($HTTP_POST_FILES['GLOBALS']) || isset($HTTP_GET_VARS['GLOBALS']) || isset($HTTP_COOKIE_VARS['GLOBALS']))
{
die("Hacking attempt");
}

// Protect against HTTP_SESSION_VARS tricks
if (isset($HTTP_SESSION_VARS) && !is_array($HTTP_SESSION_VARS))
{
die("Hacking attempt");
}

if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on')
{
// PHP4+ path
$not_unset = array('HTTP_GET_VARS', 'HTTP_POST_VARS', 'HTTP_COOKIE_VARS', 'HTTP_SERVER_VARS', 'HTTP_SESSION_VARS', 'HTTP_ENV_VARS', 'HTTP_POST_FILES', 'phpEx', 'phpbb_root_path');

// Not only will array_merge give a warning if a parameter
// is not an array, it will actually fail. So we check if
// HTTP_SESSION_VARS has been initialised.
if (!isset($HTTP_SESSION_VARS) || !is_array($HTTP_SESSION_VARS))
{
$HTTP_SESSION_VARS = array();
}

// Merge all into one extremely huge array; unset
// this later
$input = array_merge($HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES);

unset($input['input']);
unset($input['not_unset']);

while (list($var,) = @each($input))
{
if (in_array($var, $not_unset))
{
die('Hacking attempt!');
}
unset($$var);
}

unset($input);
}

//
// addslashes to vars if magic_quotes_gpc is off
// this is a security precaution to prevent someone
// trying to break out of a SQL statement.
//
if( !get_magic_quotes_gpc() )
{
if( is_array($HTTP_GET_VARS) )
{
while( list($k, $v) = each($HTTP_GET_VARS) )
{
if( is_array($HTTP_GET_VARS[$k]) )
{
while( list($k2, $v2) = each($HTTP_GET_VARS[$k]) )
{
$HTTP_GET_VARS[$k][$k2] = addslashes($v2);
}
@reset($HTTP_GET_VARS[$k]);
}
else
{
$HTTP_GET_VARS[$k] = addslashes($v);
}
}
@reset($HTTP_GET_VARS);
}

if( is_array($HTTP_POST_VARS) )
{
while( list($k, $v) = each($HTTP_POST_VARS) )
{
if( is_array($HTTP_POST_VARS[$k]) )
{
while( list($k2, $v2) = each($HTTP_POST_VARS[$k]) )
{
$HTTP_POST_VARS[$k][$k2] = addslashes($v2);
}
@reset($HTTP_POST_VARS[$k]);
}
else
{
$HTTP_POST_VARS[$k] = addslashes($v);
}
}
@reset($HTTP_POST_VARS);
}

if( is_array($HTTP_COOKIE_VARS) )
{
while( list($k, $v) = each($HTTP_COOKIE_VARS) )
{
if( is_array($HTTP_COOKIE_VARS[$k]) )
{
while( list($k2, $v2) = each($HTTP_COOKIE_VARS[$k]) )
{
$HTTP_COOKIE_VARS[$k][$k2] = addslashes($v2);
}
@reset($HTTP_COOKIE_VARS[$k]);
}
else
{
$HTTP_COOKIE_VARS[$k] = addslashes($v);
}
}
@reset($HTTP_COOKIE_VARS);
}
}

//
// Define some basic configuration arrays this also prevents
// malicious rewriting of language and otherarray values via
// URI params
//
$board_config = array();
$userdata = array();
$theme = array();
$images = array();
$lang = array();
$nav_links = array();
$dss_seeded = false;
$gen_simple_header = FALSE;

// Start: NBSdesignz Multi-Forums phpBB
define('THIS_SCRIPT', 'common');
define('IN_NBS', true);

require('nbs/global.php');

if ($forum)
{
if (file_exists($phpbb_root_path . 'nbs/configs/config_' . $forum . '.php'))
{
if ($status != 'Active')
{
include($nbs->setting['forum_not_active_url']);
exit;
}
else
{
unset($status, $nbs);

include($phpbb_root_path . 'nbs/configs/config_' . $forum . '.php');
}
}
else
{
include($nbs->setting['forum_does_not_exist_url']);
exit;
}
}
else
{
include($nbs->setting['no_forum_selected_url']);
exit;
}
// End: NBSdesignz Multi-Forums phpBB



include($phpbb_root_path . 'includes/constants.'.$phpEx);
include($phpbb_root_path . 'includes/template.'.$phpEx);
include($phpbb_root_path . 'includes/sessions.'.$phpEx);
include($phpbb_root_path . 'includes/auth.'.$phpEx);
include($phpbb_root_path . 'includes/functions.'.$phpEx);
include($phpbb_root_path . 'includes/db.'.$phpEx);

// We do not need this any longer, unset for safety purposes
unset($dbpasswd);

//
// Obtain and encode users IP
//
// I'm removing HTTP_X_FORWARDED_FOR ... this may well cause other problems such as
// private range IP's appearing instead of the guilty routable IP, tough, don't
// even bother complaining ... go scream and shout at the idiots out there who feel
// "clever" is doing harm rather than good ... karma is a great thing ... :)
//
$client_ip = ( !empty($HTTP_SERVER_VARS['REMOTE_ADDR']) ) ? $HTTP_SERVER_VARS['REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARS['REMOTE_ADDR']) ) ? $HTTP_ENV_VARS['REMOTE_ADDR'] : getenv('REMOTE_ADDR') );
$user_ip = encode_ip($client_ip);

//
// Setup forum wide options, if this fails
// then we output a CRITICAL_ERROR since
// basic forum information is not available
//
$sql = "SELECT *
FROM " . CONFIG_TABLE;
if( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, "Could not query config information", "", __LINE__, __FILE__, $sql);
}

while ( $row = $db->sql_fetchrow($result) )
{
$board_config[$row['config_name']] = $row['config_value'];
}

if (file_exists('install') || file_exists('contrib'))
{
message_die(GENERAL_MESSAGE, 'Please_remove_install_contrib');
}

//
// Show 'Board is disabled' message if needed.
//
if( $board_config['board_disable'] && !defined("IN_ADMIN") && !defined("IN_LOGIN") )
{
message_die(GENERAL_MESSAGE, 'Board_disable', 'Information');
}

?>


under the folder NBS
you have to edit:

class_nbs.php

<?php

/*
+================================================= =======================+
|| NBSdesignz Multi-Forums phpBB - Version 1.0.0 Beta 7
|| -----------------------------------------------------------------------
|| By NBSdesignz (http://www.nbsdesignz.com)
|| Copyright © 2006 NBSdesignz
|| This file may not be redistributed in whole or significant part.
|| --------------------- THIS SCRIPT IS FREEWARE. ------------------------
|| All copyright notices in this script must stay intact unless
|| copyright removal has been purchased!
|| -----------------------------------------------------------------------
|| Although this script has been tested by us, we are not responsible for
|| any damage it may cause!
|| -----------------------------------------------------------------------
|| $Id: class_nbs.php,v 1.5 2006/08/11 01:41:44 derek Exp $
|| Downloaded: Friday, September 08, 2006 07:51:38
+================================================= =======================+
*/

if (!defined('IN_NBS'))
{
die('Hacking attempt!');
}

/**
* NBS
*
* Holds config info, database connection, phrases, settings, userinfo, etc.
*/
class NBS
{
/**
* The Config Array.
*
* @var array
*/
var $config = array();

/**
* The Database Object.
*
* @var NBS_Database
*/
var $db = null;

/**
* The Phrases Array.
*
* @var array
*/
var $phrase = array();

/**
* The Settings Array.
*
* @var array
*/
var $setting = array();

/**
* The User Info Array.
*
* @var array
*/
var $userinfo = array();

/**
* Constructor. Fetches config file, Instantiates database class,
* fetches settings, phrases, and userinfo.
*/
function NBS()
{
// fetch config file.
// config file found.
$pathConfig = '';
if (substr(CWD, -3) == 'nbs')
$pathConfig = 'nbs_config.php';
else if (THIS_SCRIPT == 'install' OR THIS_SCRIPT == 'upgrade')
$pathConfig = '../nbs_config.php';
elseif (substr(CWD,-5) == 'admin')
$pathConfig = '../nbs/nbs_config.php';
else
$pathConfig = CWD . '/nbs/nbs_config.php';

if (file_exists($pathConfig))
include($pathConfig);
else
die('<br /><strong>Configuration</strong>: Unable to fetch config file. Make sure /nbs/nbs_config.php exists. ');


$this->config =& $config;

define('TABLE_PREFIX', $this->config['Database']['prefix']);

// fetch database class.
if (!class_exists('NBS_Database'))
{
if (THIS_SCRIPT == 'install' OR THIS_SCRIPT == 'upgrade')
{
require_once('../class_database.php');
}
else
{
require_once(DIR . 'nbs/class_database.php');
}
}

// instantiate database class.
$this->db = new NBS_Database($this->config['Database']['host'], $this->config['Database']['username'], $this->config['Database']['password'], $this->config['Database']['name'], ($this->config['Database']['pconnect'] ? 1 : 0));

// fetch settings.
$this->fetch_settings();

// fetch userinfo.
$this->fetch_userinfo();

if (THIS_SCRIPT != 'handler' AND THIS_SCRIPT != 'common' AND THIS_SCRIPT != 'install' AND THIS_SCRIPT != 'upgrade')
{
// fetch phrases.
$this->fetch_phrases(PHRASE_TYPE, $this->setting['language']);
}
}

/**
* Fetches requested phrases from the phrases table.
*
* @param integer Requested phrase type id.
* @param integer Requested language id.
*/
function fetch_phrases($phrasetypeid = 0, $languageid = 1)
{
// fetch requested phrases from phrases table.
$phrase1 = "SELECT `varname`, `text`, `languageid` FROM " . TABLE_PREFIX . "phrases
WHERE phrasetypeid IN(" . $phrasetypeid . ", 1" . (THIS_SCRIPT != 'admin' ? ' , 2' : '') . ") " . (empty($languageid) ? "AND languageid = -1" : "AND languageid IN(-1, " . $languageid . ") ORDER BY languageid ASC");

$phrase2 = $this->db->query($phrase1);

// put phrases into the phrase array.
while ($phrase3 = $this->db->fetch_array($phrase2))
{
// check to see if master phrase is already in the array and delete if there is a custom phrase.
if (in_array($phrase3['varname'], $this->phrase))
{
unset ($this->phrase[$phrase3['varname']]);
}

if ($phrase3['varname'] != 'verify_email_message' AND $phrase['varname'] != 'send_pass_email_message')
{
$this->phrase[$phrase3['varname']] = stripslashes($phrase3['text']);
}
else
{
$this->phrase[$phrase3['varname']] = $phrase3['text'];
}
}

$this->db->free_result($phrase2);

unset($phrase1, $phrase3);
}

/**
* Fetches all settings from the phrases table.
*/
function fetch_settings()
{
// fetch all settings from settings table.
$setting1 = "SELECT `varname`, `value` FROM " . TABLE_PREFIX . "settings";
$setting2 = $this->db->query($setting1);

// put settings into the setting array.
while ($setting3 = $this->db->fetch_array($setting2))
{
$this->setting[$setting3['varname']] = stripslashes($setting3['value']);
}

$this->db->free_result($setting2);

unset($setting1, $setting3);
}

/**
* Fetches logged in user's userinfo from the users table.
*/
function fetch_userinfo()
{
if (isset($_COOKIE['accessname']) AND isset($_COOKIE['random_key']) AND !isset($_SESSION['accessname']))
{
// user has a cookie from the script, get accessname from it, and validate random key...
$verifyc1 = "SELECT `random_key` FROM " . TABLE_PREFIX . "users WHERE accessname = '" . $this->db->escape_string($_COOKIE['accessname']) . "'";
$verifyc2 = $this->db->query($verifyc1);
$verifyc = $this->db->fetch_array($verifyc2);

if ($verifyc['random_key'] == $_COOKIE['random_key'])
{
// key has been validated. Initiate session.
$_SESSION['accessname'] = $_COOKIE['accessname'];
}
else
{
// key has not been validated. Delete any sessions and cookies.
$_SESSION = array();

session_destroy();

setcookie('accessname', '', time()-1, $nbs->setting['cookie_path'], $nbs->setting['cookie_domain'], $nbs->setting['cookie_secure']);
setcookie('random_key', '', time()-1, $nbs->setting['cookie_path'], $nbs->setting['cookie_domain'], $nbs->setting['cookie_secure']);
}

$this->db->free_result($verifyc2);

unset($verifyc1, $verifyc);
}

if ($_SESSION['accessname'])
{
// user is logged in, fetch userinfo.
$userinfo1 = "SELECT * FROM " . TABLE_PREFIX . "users WHERE accessname = '" . $this->db->escape_string($_SESSION['accessname']) . "' LIMIT 1";
$userinfo2 = $this->db->query($userinfo1);

// put userinfo into the userinfo array.
$this->userinfo = $this->db->fetch_array($userinfo2);
$this->userinfo = array_merge($this->userinfo, array('ipaddress' => $_SERVER['REMOTE_ADDR']));

$this->db->free_result($userinfo2);

unset($userinfo1);
}
else
{
// user is a guest.
$this->userinfo = '';
}
}
}
?>


new_forum_sql.php

<?php

/*
+================================================= =======================+
|| NBSdesignz Multi-Forums phpBB - Version 1.0.0 Beta 7
|| -----------------------------------------------------------------------
|| By NBSdesignz (http://www.nbsdesignz.com)
|| Copyright © 2006 NBSdesignz
|| This file may not be redistributed in whole or significant part.
|| --------------------- THIS SCRIPT IS FREEWARE. ------------------------
|| All copyright notices in this script must stay intact unless
|| copyright removal has been purchased!
|| -----------------------------------------------------------------------
|| Although this script has been tested by us, we are not responsible for
|| any damage it may cause!
|| -----------------------------------------------------------------------
|| $Id: new_forum_sql.php,v 1.19 2006/08/09 03:25:32 derek Exp $
|| Downloaded: Friday, September 08, 2006 07:51:38
+================================================= =======================+
*/

if (!defined('IN_NBS'))
{
die('Hacking attempt!');
}

$sql[] = "
CREATE TABLE " . $accessname . "_auth_access (
group_id mediumint(8) DEFAULT '0' NOT NULL,
forum_id smallint(5) UNSIGNED DEFAULT '0' NOT NULL,
auth_view tinyint(1) DEFAULT '0' NOT NULL,
auth_read tinyint(1) DEFAULT '0' NOT NULL,
auth_post tinyint(1) DEFAULT '0' NOT NULL,
auth_reply tinyint(1) DEFAULT '0' NOT NULL,
auth_edit tinyint(1) DEFAULT '0' NOT NULL,
auth_delete tinyint(1) DEFAULT '0' NOT NULL,
auth_sticky tinyint(1) DEFAULT '0' NOT NULL,
auth_announce tinyint(1) DEFAULT '0' NOT NULL,
auth_vote tinyint(1) DEFAULT '0' NOT NULL,
auth_pollcreate tinyint(1) DEFAULT '0' NOT NULL,
auth_attachments tinyint(1) DEFAULT '0' NOT NULL,
auth_mod tinyint(1) DEFAULT '0' NOT NULL,
KEY group_id (group_id),
KEY forum_id (forum_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_user_group (
group_id mediumint(8) DEFAULT '0' NOT NULL,
user_id mediumint(8) DEFAULT '0' NOT NULL,
user_pending tinyint(1),
KEY group_id (group_id),
KEY user_id (user_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_groups (
group_id mediumint(8) NOT NULL auto_increment,
group_type tinyint(4) DEFAULT '1' NOT NULL,
group_name varchar(40) NOT NULL,
group_description varchar(255) NOT NULL,
group_moderator mediumint(8) DEFAULT '0' NOT NULL,
group_single_user tinyint(1) DEFAULT '1' NOT NULL,
PRIMARY KEY (group_id),
KEY group_single_user (group_single_user)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_banlist (
ban_id mediumint(8) UNSIGNED NOT NULL auto_increment,
ban_userid mediumint(8) NOT NULL,
ban_ip char(8) NOT NULL,
ban_email varchar(255),
PRIMARY KEY (ban_id),
KEY ban_ip_user_id (ban_ip, ban_userid)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_categories (
cat_id mediumint(8) UNSIGNED NOT NULL auto_increment,
cat_title varchar(100),
cat_order mediumint(8) UNSIGNED NOT NULL,
PRIMARY KEY (cat_id),
KEY cat_order (cat_order)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_config (
config_name varchar(255) NOT NULL,
config_value varchar(255) NOT NULL,
PRIMARY KEY (config_name)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_confirm (
confirm_id char(32) DEFAULT '' NOT NULL,
session_id char(32) DEFAULT '' NOT NULL,
code char(6) DEFAULT '' NOT NULL,
PRIMARY KEY (session_id,confirm_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_disallow (
disallow_id mediumint(8) UNSIGNED NOT NULL auto_increment,
disallow_username varchar(25) DEFAULT '' NOT NULL,
PRIMARY KEY (disallow_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_forum_prune (
prune_id mediumint(8) UNSIGNED NOT NULL auto_increment,
forum_id smallint(5) UNSIGNED NOT NULL,
prune_days smallint(5) UNSIGNED NOT NULL,
prune_freq smallint(5) UNSIGNED NOT NULL,
PRIMARY KEY(prune_id),
KEY forum_id (forum_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_forums (
forum_id smallint(5) UNSIGNED NOT NULL,
cat_id mediumint(8) UNSIGNED NOT NULL,
forum_name varchar(150),
forum_desc text,
forum_status tinyint(4) DEFAULT '0' NOT NULL,
forum_order mediumint(8) UNSIGNED DEFAULT '1' NOT NULL,
forum_posts mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
forum_topics mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
forum_last_post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
prune_next int(11),
prune_enable tinyint(1) DEFAULT '0' NOT NULL,
auth_view tinyint(2) DEFAULT '0' NOT NULL,
auth_read tinyint(2) DEFAULT '0' NOT NULL,
auth_post tinyint(2) DEFAULT '0' NOT NULL,
auth_reply tinyint(2) DEFAULT '0' NOT NULL,
auth_edit tinyint(2) DEFAULT '0' NOT NULL,
auth_delete tinyint(2) DEFAULT '0' NOT NULL,
auth_sticky tinyint(2) DEFAULT '0' NOT NULL,
auth_announce tinyint(2) DEFAULT '0' NOT NULL,
auth_vote tinyint(2) DEFAULT '0' NOT NULL,
auth_pollcreate tinyint(2) DEFAULT '0' NOT NULL,
auth_attachments tinyint(2) DEFAULT '0' NOT NULL,
PRIMARY KEY (forum_id),
KEY forums_order (forum_order),
KEY cat_id (cat_id),
KEY forum_last_post_id (forum_last_post_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_posts (
post_id mediumint(8) UNSIGNED NOT NULL auto_increment,
topic_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
forum_id smallint(5) UNSIGNED DEFAULT '0' NOT NULL,
poster_id mediumint(8) DEFAULT '0' NOT NULL,
post_time int(11) DEFAULT '0' NOT NULL,
poster_ip char(8) NOT NULL,
post_username varchar(25),
enable_bbcode tinyint(1) DEFAULT '1' NOT NULL,
enable_html tinyint(1) DEFAULT '0' NOT NULL,
enable_smilies tinyint(1) DEFAULT '1' NOT NULL,
enable_sig tinyint(1) DEFAULT '1' NOT NULL,
post_edit_time int(11),
post_edit_count smallint(5) UNSIGNED DEFAULT '0' NOT NULL,
PRIMARY KEY (post_id),
KEY forum_id (forum_id),
KEY topic_id (topic_id),
KEY poster_id (poster_id),
KEY post_time (post_time)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_posts_text (
post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
bbcode_uid char(10) DEFAULT '' NOT NULL,
post_subject char(60),
post_text text,
PRIMARY KEY (post_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_privmsgs (
privmsgs_id mediumint(8) UNSIGNED NOT NULL auto_increment,
privmsgs_type tinyint(4) DEFAULT '0' NOT NULL,
privmsgs_subject varchar(255) DEFAULT '0' NOT NULL,
privmsgs_from_userid mediumint(8) DEFAULT '0' NOT NULL,
privmsgs_to_userid mediumint(8) DEFAULT '0' NOT NULL,
privmsgs_date int(11) DEFAULT '0' NOT NULL,
privmsgs_ip char(8) NOT NULL,
privmsgs_enable_bbcode tinyint(1) DEFAULT '1' NOT NULL,
privmsgs_enable_html tinyint(1) DEFAULT '0' NOT NULL,
privmsgs_enable_smilies tinyint(1) DEFAULT '1' NOT NULL,
privmsgs_attach_sig tinyint(1) DEFAULT '1' NOT NULL,
PRIMARY KEY (privmsgs_id),
KEY privmsgs_from_userid (privmsgs_from_userid),
KEY privmsgs_to_userid (privmsgs_to_userid)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_privmsgs_text (
privmsgs_text_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
privmsgs_bbcode_uid char(10) DEFAULT '0' NOT NULL,
privmsgs_text text,
PRIMARY KEY (privmsgs_text_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_ranks (
rank_id smallint(5) UNSIGNED NOT NULL auto_increment,
rank_title varchar(50) NOT NULL,
rank_min mediumint(8) DEFAULT '0' NOT NULL,
rank_special tinyint(1) DEFAULT '0',
rank_image varchar(255),
PRIMARY KEY (rank_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_search_results (
search_id int(11) UNSIGNED NOT NULL default '0',
session_id char(32) NOT NULL default '',
search_time int(11) DEFAULT '0' NOT NULL,
search_array text NOT NULL,
PRIMARY KEY (search_id),
KEY session_id (session_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_search_wordlist (
word_text varchar(50) binary NOT NULL default '',
word_id mediumint(8) UNSIGNED NOT NULL auto_increment,
word_common tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (word_text),
KEY word_id (word_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_search_wordmatch (
post_id mediumint(8) UNSIGNED NOT NULL default '0',
word_id mediumint(8) UNSIGNED NOT NULL default '0',
title_match tinyint(1) NOT NULL default '0',
KEY post_id (post_id),
KEY word_id (word_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_sessions (
session_id char(32) DEFAULT '' NOT NULL,
session_user_id mediumint(8) DEFAULT '0' NOT NULL,
session_start int(11) DEFAULT '0' NOT NULL,
session_time int(11) DEFAULT '0' NOT NULL,
session_ip char(8) DEFAULT '0' NOT NULL,
session_page int(11) DEFAULT '0' NOT NULL,
session_logged_in tinyint(1) DEFAULT '0' NOT NULL,
session_admin tinyint(2) DEFAULT '0' NOT NULL,
PRIMARY KEY (session_id),
KEY session_user_id (session_user_id),
KEY session_id_ip_user_id (session_id, session_ip, session_user_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_sessions_keys (
key_id varchar(32) DEFAULT '0' NOT NULL,
user_id mediumint(8) DEFAULT '0' NOT NULL,
last_ip varchar(8) DEFAULT '0' NOT NULL,
last_login int(11) DEFAULT '0' NOT NULL,
PRIMARY KEY (key_id, user_id),
KEY last_login (last_login)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_smilies (
smilies_id smallint(5) UNSIGNED NOT NULL auto_increment,
code varchar(50),
smile_url varchar(100),
emoticon varchar(75),
PRIMARY KEY (smilies_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_themes (
themes_id mediumint(8) UNSIGNED NOT NULL auto_increment,
template_name varchar(30) NOT NULL default '',
style_name varchar(30) NOT NULL default '',
head_stylesheet varchar(100) default NULL,
body_background varchar(100) default NULL,
body_bgcolor varchar(6) default NULL,
body_text varchar(6) default NULL,
body_link varchar(6) default NULL,
body_vlink varchar(6) default NULL,
body_alink varchar(6) default NULL,
body_hlink varchar(6) default NULL,
tr_color1 varchar(6) default NULL,
tr_color2 varchar(6) default NULL,
tr_color3 varchar(6) default NULL,
tr_class1 varchar(25) default NULL,
tr_class2 varchar(25) default NULL,
tr_class3 varchar(25) default NULL,
th_color1 varchar(6) default NULL,
th_color2 varchar(6) default NULL,
th_color3 varchar(6) default NULL,
th_class1 varchar(25) default NULL,
th_class2 varchar(25) default NULL,
th_class3 varchar(25) default NULL,
td_color1 varchar(6) default NULL,
td_color2 varchar(6) default NULL,
td_color3 varchar(6) default NULL,
td_class1 varchar(25) default NULL,
td_class2 varchar(25) default NULL,
td_class3 varchar(25) default NULL,
fontface1 varchar(50) default NULL,
fontface2 varchar(50) default NULL,
fontface3 varchar(50) default NULL,
fontsize1 tinyint(4) default NULL,
fontsize2 tinyint(4) default NULL,
fontsize3 tinyint(4) default NULL,
fontcolor1 varchar(6) default NULL,
fontcolor2 varchar(6) default NULL,
fontcolor3 varchar(6) default NULL,
span_class1 varchar(25) default NULL,
span_class2 varchar(25) default NULL,
span_class3 varchar(25) default NULL,
img_size_poll smallint(5) UNSIGNED,
img_size_privmsg smallint(5) UNSIGNED,
PRIMARY KEY (themes_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_themes_name (
themes_id smallint(5) UNSIGNED DEFAULT '0' NOT NULL,
tr_color1_name char(50),
tr_color2_name char(50),
tr_color3_name char(50),
tr_class1_name char(50),
tr_class2_name char(50),
tr_class3_name char(50),
th_color1_name char(50),
th_color2_name char(50),
th_color3_name char(50),
th_class1_name char(50),
th_class2_name char(50),
th_class3_name char(50),
td_color1_name char(50),
td_color2_name char(50),
td_color3_name char(50),
td_class1_name char(50),
td_class2_name char(50),
td_class3_name char(50),
fontface1_name char(50),
fontface2_name char(50),
fontface3_name char(50),
fontsize1_name char(50),
fontsize2_name char(50),
fontsize3_name char(50),
fontcolor1_name char(50),
fontcolor2_name char(50),
fontcolor3_name char(50),
span_class1_name char(50),
span_class2_name char(50),
span_class3_name char(50),
PRIMARY KEY (themes_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_topics (
topic_id mediumint(8) UNSIGNED NOT NULL auto_increment,
forum_id smallint(8) UNSIGNED DEFAULT '0' NOT NULL,
topic_title char(60) NOT NULL,
topic_poster mediumint(8) DEFAULT '0' NOT NULL,
topic_time int(11) DEFAULT '0' NOT NULL,
topic_views mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
topic_replies mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
topic_status tinyint(3) DEFAULT '0' NOT NULL,
topic_vote tinyint(1) DEFAULT '0' NOT NULL,
topic_type tinyint(3) DEFAULT '0' NOT NULL,
topic_first_post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
topic_last_post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
topic_moved_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
PRIMARY KEY (topic_id),
KEY forum_id (forum_id),
KEY topic_moved_id (topic_moved_id),
KEY topic_status (topic_status),
KEY topic_type (topic_type)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_topics_watch (
topic_id mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
user_id mediumint(8) NOT NULL DEFAULT '0',
notify_status tinyint(1) NOT NULL default '0',
KEY topic_id (topic_id),
KEY user_id (user_id),
KEY notify_status (notify_status)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_users (
user_id mediumint(8) NOT NULL,
user_active tinyint(1) DEFAULT '1',
username varchar(25) NOT NULL,
user_password varchar(32) NOT NULL,
user_session_time int(11) DEFAULT '0' NOT NULL,
user_session_page smallint(5) DEFAULT '0' NOT NULL,
user_lastvisit int(11) DEFAULT '0' NOT NULL,
user_regdate int(11) DEFAULT '0' NOT NULL,
user_level tinyint(4) DEFAULT '0',
user_posts mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_timezone decimal(5,2) DEFAULT '0' NOT NULL,
user_style tinyint(4),
user_lang varchar(255),
user_dateformat varchar(14) DEFAULT 'd M Y H:i' NOT NULL,
user_new_privmsg smallint(5) UNSIGNED DEFAULT '0' NOT NULL,
user_unread_privmsg smallint(5) UNSIGNED DEFAULT '0' NOT NULL,
user_last_privmsg int(11) DEFAULT '0' NOT NULL,
user_login_tries smallint(5) UNSIGNED DEFAULT '0' NOT NULL,
user_last_login_try int(11) DEFAULT '0' NOT NULL,
user_emailtime int(11),
user_viewemail tinyint(1),
user_attachsig tinyint(1),
user_allowhtml tinyint(1) DEFAULT '1',
user_allowbbcode tinyint(1) DEFAULT '1',
user_allowsmile tinyint(1) DEFAULT '1',
user_allowavatar tinyint(1) DEFAULT '1' NOT NULL,
user_allow_pm tinyint(1) DEFAULT '1' NOT NULL,
user_allow_viewonline tinyint(1) DEFAULT '1' NOT NULL,
user_notify tinyint(1) DEFAULT '1' NOT NULL,
user_notify_pm tinyint(1) DEFAULT '0' NOT NULL,
user_popup_pm tinyint(1) DEFAULT '0' NOT NULL,
user_rank int(11) DEFAULT '0',
user_avatar varchar(100),
user_avatar_type tinyint(4) DEFAULT '0' NOT NULL,
user_email varchar(255),
user_icq varchar(15),
user_website varchar(100),
user_from varchar(100),
user_sig text,
user_sig_bbcode_uid char(10),
user_aim varchar(255),
user_yim varchar(255),
user_msnm varchar(255),
user_occ varchar(100),
user_interests varchar(255),
user_actkey varchar(32),
user_newpasswd varchar(32),
PRIMARY KEY (user_id),
KEY user_session_time (user_session_time)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_vote_desc (
vote_id mediumint(8) UNSIGNED NOT NULL auto_increment,
topic_id mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
vote_text text NOT NULL,
vote_start int(11) NOT NULL DEFAULT '0',
vote_length int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (vote_id),
KEY topic_id (topic_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_vote_results (
vote_id mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
vote_option_id tinyint(4) UNSIGNED NOT NULL DEFAULT '0',
vote_option_text varchar(255) NOT NULL,
vote_result int(11) NOT NULL DEFAULT '0',
KEY vote_option_id (vote_option_id),
KEY vote_id (vote_id)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_vote_voters (
vote_id mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
vote_user_id mediumint(8) NOT NULL DEFAULT '0',
vote_user_ip char(8) NOT NULL,
KEY vote_id (vote_id),
KEY vote_user_id (vote_user_id),
KEY vote_user_ip (vote_user_ip)
);";


$sql[] = "
CREATE TABLE " . $accessname . "_words (
word_id mediumint(8) UNSIGNED NOT NULL auto_increment,
word char(100) NOT NULL,
replacement char(100) NOT NULL,
PRIMARY KEY (word_id)
);";


$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('config_id','1');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('board_disable','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('sitename','" . $_POST['forumname'] . "');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('site_desc','" . $_POST['forumdescription'] . "');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('cookie_name','phpbb2mysql');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('cookie_path','" . $nbs->setting['path'] . "/');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('cookie_domain','');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('cookie_secure','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('session_length','3600');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('allow_html','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('allow_html_tags','b,i,u,pre');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('allow_bbcode','1');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('allow_smilies','1');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('allow_sig','1');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('allow_namechange','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('allow_theme_create','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('allow_avatar_local','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('allow_avatar_remote','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('allow_avatar_upload','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('enable_confirm', '0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('allow_autologin','1');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('max_autologin_time','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('override_user_style','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('posts_per_page','15');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('topics_per_page','50');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('hot_threshold','25');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('max_poll_options','10');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('max_sig_chars','255');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('max_inbox_privmsgs','50');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('max_sentbox_privmsgs','25');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('max_savebox_privmsgs','50');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('board_email_sig','Thanks, The Management');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('board_email','" . $_POST['adminemail'] . "');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('smtp_delivery','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('smtp_host','');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('smtp_username','');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('smtp_password','');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('sendmail_fix','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('require_activation','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('flood_interval','15');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('max_login_attempts', '5');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('login_reset_time', '30');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('board_email_form','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('avatar_filesize','6144');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('avatar_max_width','80');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('avatar_max_height','80');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('avatar_path','images/" . $accessname . "/avatars');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('avatar_gallery_path','images/" . $accessname . "/avatars/gallery');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('smilies_path','images/" . $accessname . "/smiles');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('default_style','1');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('default_dateformat','D M d, Y g:i a');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('board_timezone','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('prune_enable','1');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('privmsg_disable','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('gzip_compress','0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('coppa_fax', '');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('coppa_mail', '');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('record_online_users', '0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('record_online_date', '0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('server_name', '" . $nbs->setting['domain'] . "');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('server_port', '80');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('script_path', '" . $nbs->setting['path'].$accessname . "/');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('version', '.0.21');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('board_startdate', '" . time() . "');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('default_lang', 'english');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('search_flood_interval', '15');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('rand_seed', '0');";
$sql[] = "INSERT INTO " . $accessname . "_config (config_name, config_value) VALUES ('search_min_chars','3');";

$sql[] = "INSERT INTO " . $accessname . "_categories (cat_id, cat_title, cat_order) VALUES (1, 'Test category 1', 10);";

$sql[] = "INSERT INTO " . $accessname . "_forums (forum_id, forum_name, forum_desc, cat_id, forum_order, forum_posts, forum_topics, forum_last_post_id, auth_view, auth_read, auth_post, auth_reply, auth_edit, auth_delete, auth_announce, auth_sticky, auth_pollcreate, auth_vote, auth_attachments) VALUES (1, 'Test Forum 1', 'This is just a test forum.', 1, 10, 1, 1, 1, 0, 0, 0, 0, 1, 1, 3, 3, 1, 1, 3);";

$sql[] = "INSERT INTO " . $accessname . "_users (user_id, username, user_level, user_regdate, user_password, user_email, user_icq, user_website, user_occ, user_from, user_interests, user_sig, user_viewemail, user_style, user_aim, user_yim, user_msnm, user_posts, user_attachsig, user_allowsmile, user_allowhtml, user_allowbbcode, user_allow_pm, user_notify_pm, user_allow_viewonline, user_rank, user_avatar, user_lang, user_timezone, user_dateformat, user_actkey, user_newpasswd, user_notify, user_active) VALUES ( -1, 'Anonymous', 0, 0, '', '', '', '', '', '', '', '', 0, NULL, '', '', '', 0, 0, 1, 1, 1, 0, 1, 1, NULL, '', '', 0, '', '', '', 0, 0);";

$sql[] = "INSERT INTO " . $accessname . "_users (user_id, username, user_level, user_regdate, user_password, user_email, user_icq, user_website, user_occ, user_from, user_interests, user_sig, user_viewemail, user_style, user_aim, user_yim, user_msnm, user_posts, user_attachsig, user_allowsmile, user_allowhtml, user_allowbbcode, user_allow_pm, user_notify_pm, user_popup_pm, user_allow_viewonline, user_rank, user_avatar, user_lang, user_timezone, user_dateformat, user_actkey, user_newpasswd, user_notify, user_active) VALUES ( 2, '" . $_POST['adminuser'] . "', 1, '" . time() . "', '" . md5($_POST['adminpass']) . "', '" . $_POST['adminemail'] . "', '', '', '', '', '', '', 1, 1, '', '', '', 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, '', 'english', 0, 'd M Y h:i a', '', '', 0, 1);";

$sql[] = "INSERT INTO " . $accessname . "_ranks (rank_id, rank_title, rank_min, rank_special, rank_image) VALUES ( 1, 'Site Admin', -1, 1, NULL);";

$sql[] = "INSERT INTO " . $accessname . "_groups (group_id, group_name, group_description, group_single_user) VALUES (1, 'Anonymous', 'Personal User', 1);";
$sql[] = "INSERT INTO " . $accessname . "_groups (group_id, group_name, group_description, group_single_user) VALUES (2, 'Admin', 'Personal User', 1);";

$sql[] = "INSERT INTO " . $accessname . "_user_group (group_id, user_id, user_pending) VALUES (1, -1, 0);";
$sql[] = "INSERT INTO " . $accessname . "_user_group (group_id, user_id, user_pending) VALUES (2, 2, 0);";

$sql[] = "INSERT INTO " . $accessname . "_topics (topic_id, topic_title, topic_poster, topic_time, topic_views, topic_replies, forum_id, topic_status, topic_type, topic_vote, topic_first_post_id, topic_last_post_id) VALUES (1, 'Welcome to phpBB 2', 2, '972086460', 0, 0, 1, 0, 0, 0, 1, 1);";

$sql[] = "INSERT INTO " . $accessname . "_posts (post_id, topic_id, forum_id, poster_id, post_time, post_username, poster_ip) VALUES (1, 1, 1, 2, '" . time() . "', NULL, '7F000001');";
$sql[] = "INSERT INTO " . $accessname . "_posts_text (post_id, post_subject, post_text) VALUES (1, NULL, 'This is an example post in your phpBB 2 installation. You may delete this post, this topic and even this forum if you like since everything seems to be working!');";

$sql[] = "INSERT INTO " . $accessname . "_themes (themes_id, template_name, style_name, head_stylesheet, body_background, body_bgcolor, body_text, body_link, body_vlink, body_alink, body_hlink, tr_color1, tr_color2, tr_color3, tr_class1, tr_class2, tr_class3, th_color1, th_color2, th_color3, th_class1, th_class2, th_class3, td_color1, td_color2, td_color3, td_class1, td_class2, td_class3, fontface1, fontface2, fontface3, fontsize1, fontsize2, fontsize3, fontcolor1, fontcolor2, fontcolor3, span_class1, span_class2, span_class3) VALUES (1, 'subSilver', 'subSilver', 'subSilver.css', '', 'E5E5E5', '000000', '006699', '5493B4', '', 'DD6900', 'EFEFEF', 'DEE3E7', 'D1D7DC', '', '', '', '98AAB1', '006699', 'FFFFFF', 'cellpic1.gif', 'cellpic3.gif', 'cellpic2.jpg', 'FAFAFA', 'FFFFFF', '', 'row1', 'row2', '', 'Verdana, Arial, Helvetica, sans-serif', 'Trebuchet MS', 'Courier, \'Courier New\', sans-serif', 10, 11, 12, '444444', '006600', 'FFA34F', '', '', '');";

$sql[] = "INSERT INTO " . $accessname . "_themes_name (themes_id, tr_color1_name, tr_color2_name, tr_color3_name, tr_class1_name, tr_class2_name, tr_class3_name, th_color1_name, th_color2_name, th_color3_name, th_class1_name, th_class2_name, th_class3_name, td_color1_name, td_color2_name, td_color3_name, td_class1_name, td_class2_name, td_class3_name, fontface1_name, fontface2_name, fontface3_name, fontsize1_name, fontsize2_name, fontsize3_name, fontcolor1_name, fontcolor2_name, fontcolor3_name, span_class1_name, span_class2_name, span_class3_name) VALUES (1, 'The lightest row colour', 'The medium row color', 'The darkest row colour', '', '', '', 'Border round the whole page', 'Outer table border', 'Inner table border', 'Silver gradient picture', 'Blue gradient picture', 'Fade-out gradient on index', 'Background for quote boxes', 'All white areas', '', 'Background for topic posts', '2nd background for topic posts', '', 'Main fonts', 'Additional topic title font', 'Form fonts', 'Smallest font size', 'Medium font size', 'Normal font size (post body etc)', 'Quote & copyright text', 'Code text colour', 'Main table header text colour', '', '', '');";

$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 1, ':D', 'icon_biggrin.gif', 'Very Happy');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 2, ':-D', 'icon_biggrin.gif', 'Very Happy');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 3, ':grin:', 'icon_biggrin.gif', 'Very Happy');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 4, ':)', 'icon_smile.gif', 'Smile');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 5, ':-)', 'icon_smile.gif', 'Smile');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 6, ':smile:', 'icon_smile.gif', 'Smile');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 7, ':(', 'icon_sad.gif', 'Sad');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 8, ':-(', 'icon_sad.gif', 'Sad');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 9, ':sad:', 'icon_sad.gif', 'Sad');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 10, ':o', 'icon_surprised.gif', 'Surprised');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 11, ':-o', 'icon_surprised.gif', 'Surprised');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 12, ':eek:', 'icon_surprised.gif', 'Surprised');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 13, ':shock:', 'icon_eek.gif', 'Shocked');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 14, ':?', 'icon_confused.gif', 'Confused');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 15, ':-?', 'icon_confused.gif', 'Confused');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 16, ':???:', 'icon_confused.gif', 'Confused');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 17, '8)', 'icon_cool.gif', 'Cool');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 18, '8-)', 'icon_cool.gif', 'Cool');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 19, ':cool:', 'icon_cool.gif', 'Cool');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 20, ':lol:', 'icon_lol.gif', 'Laughing');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 21, ':x', 'icon_mad.gif', 'Mad');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 22, ':-x', 'icon_mad.gif', 'Mad');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 23, ':mad:', 'icon_mad.gif', 'Mad');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 24, ':P', 'icon_razz.gif', 'Razz');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 25, ':-P', 'icon_razz.gif', 'Razz');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 26, ':razz:', 'icon_razz.gif', 'Razz');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 27, ':oops:', 'icon_redface.gif', 'Embarassed');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 28, ':cry:', 'icon_cry.gif', 'Crying or Very sad');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 29, ':evil:', 'icon_evil.gif', 'Evil or Very Mad');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 30, ':twisted:', 'icon_twisted.gif', 'Twisted Evil');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 31, ':roll:', 'icon_rolleyes.gif', 'Rolling Eyes');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 32, ':wink:', 'icon_wink.gif', 'Wink');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 33, ';)', 'icon_wink.gif', 'Wink');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 34, ';-)', 'icon_wink.gif', 'Wink');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 35, ':!:', 'icon_exclaim.gif', 'Exclamation');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 36, ':?:', 'icon_question.gif', 'Question');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 37, ':idea:', 'icon_idea.gif', 'Idea');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 38, ':arrow:', 'icon_arrow.gif', 'Arrow');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 39, ':|', 'icon_neutral.gif', 'Neutral');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 40, ':-|', 'icon_neutral.gif', 'Neutral');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 41, ':neutral:', 'icon_neutral.gif', 'Neutral');";
$sql[] = "INSERT INTO " . $accessname . "_smilies (smilies_id, code, smile_url, emoticon) VALUES ( 42, ':mrgreen:', 'icon_mrgreen.gif', 'Mr. Green');";

$sql[] = "INSERT INTO " . $accessname . "_search_wordlist (word_id, word_text, word_common) VALUES ( 1, 'example', 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordlist (word_id, word_text, word_common) VALUES ( 2, 'post', 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordlist (word_id, word_text, word_common) VALUES ( 3, 'phpbb', 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordlist (word_id, word_text, word_common) VALUES ( 4, 'installation', 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordlist (word_id, word_text, word_common) VALUES ( 5, 'delete', 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordlist (word_id, word_text, word_common) VALUES ( 6, 'topic', 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordlist (word_id, word_text, word_common) VALUES ( 7, 'forum', 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordlist (word_id, word_text, word_common) VALUES ( 8, 'since', 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordlist (word_id, word_text, word_common) VALUES ( 9, 'everything', 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordlist (word_id, word_text, word_common) VALUES ( 10, 'seems', 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordlist (word_id, word_text, word_common) VALUES ( 11, 'working', 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordlist (word_id, word_text, word_common) VALUES ( 12, 'welcome', 0 );";

$sql[] = "INSERT INTO " . $accessname . "_search_wordmatch (word_id, post_id, title_match) VALUES ( 1, 1, 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordmatch (word_id, post_id, title_match) VALUES ( 2, 1, 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordmatch (word_id, post_id, title_match) VALUES ( 3, 1, 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordmatch (word_id, post_id, title_match) VALUES ( 4, 1, 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordmatch (word_id, post_id, title_match) VALUES ( 5, 1, 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordmatch (word_id, post_id, title_match) VALUES ( 6, 1, 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordmatch (word_id, post_id, title_match) VALUES ( 7, 1, 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordmatch (word_id, post_id, title_match) VALUES ( 8, 1, 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordmatch (word_id, post_id, title_match) VALUES ( 9, 1, 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordmatch (word_id, post_id, title_match) VALUES ( 10, 1, 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordmatch (word_id, post_id, title_match) VALUES ( 11, 1, 0 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordmatch (word_id, post_id, title_match) VALUES ( 12, 1, 1 );";
$sql[] = "INSERT INTO " . $accessname . "_search_wordmatch (word_id, post_id, title_match) VALUES ( 3, 1, 1 );";

if ($nbs->setting['verify_email_address'] == 1)
{
$sql[] = "INSERT INTO " . TABLE_PREFIX . "users (accessname, password, email, joindate, ipaddress, act_key, header_ads, footer_ads, cid) VALUES ('" . $accessname . "', '" . md5($_POST['adminpass']) . "', '" . $_POST['adminemail'] . "', '" . time() . "', '" . $_SERVER['REMOTE_ADDR'] . "', '" . $act_key . "', '1', '1', '" . $_POST['category'] . "');";
}
else
{
$sql[] = "INSERT INTO " . TABLE_PREFIX . "users (accessname, password, email, joindate, ipaddress, status, act_key, header_ads, footer_ads, cid) VALUES ('" . $accessname . "', '" . md5($_POST['adminpass']) . "', '" . $_POST['adminemail'] . "', '" . time() . "', '" . $_SERVER['REMOTE_ADDR'] . "', 'Active', '" . $act_key . "', '1', '1', '" . $_POST['category'] . "');";

$sql[] = "UPDATE " . TABLE_PREFIX . "categories SET total_forums=total_forums+1 WHERE id='" . $db->escape_string($_POST['category']) . "'";
}

?>



take mind that
http://domain/
will be redirected to
http://www.domain/
if you don't want this simply edit the handler.php

when you find

if ($forum == '')
header("Location: http://www.".$domainName."/");
else
{
// Se ho scelto un qualche forum
// Non ho scelto nessuno script in particolare, il default è index.php
if ($script == '')
$script = 'index.php';

$global_ads = $nbs->setting['global_ads'];

$misc1 = "SELECT status, header_ads, footer_ads FROM " . TABLE_PREFIX . "users WHERE accessname='" . $db->escape_string($forum) . "'";
$misc2 = $db->query($misc1);
$misc3 = $db->fetch_array($misc2);

$status = $misc3['status'];

$header_ads = $misc3['header_ads'];
$footer_ads = $misc3['footer_ads'];

$db->free_result($misc2);

$db->close();

unset($misc1, $misc3, $nbs, $db);

if (file_exists($script))
{
if (substr($script, 0, 5) == 'admin')
{
chdir('admin');

include($script);
}
else
{
if (substr($script, -3) == 'gif' OR substr($script, -3) == 'jpg' OR substr($script, -3) == 'png' OR substr($script, -4) == 'jpeg')
{
$contents = file_get_contents($script);

echo $contents;
}
else
{
include($script);
}
}
}
}

just replace it with

// Non ho scelto nessuno script in particolare, il default è index.php
if ($script == '')
$script = 'index.php';

$global_ads = $nbs->setting['global_ads'];

$misc1 = "SELECT status, header_ads, footer_ads FROM " . TABLE_PREFIX . "users WHERE accessname='" . $db->escape_string($forum) . "'";
$misc2 = $db->query($misc1);
$misc3 = $db->fetch_array($misc2);

$status = $misc3['status'];

$header_ads = $misc3['header_ads'];
$footer_ads = $misc3['footer_ads'];

$db->free_result($misc2);

$db->close();

unset($misc1, $misc3, $nbs, $db);

if (file_exists($script))
{
if (substr($script, 0, 5) == 'admin')
{
chdir('admin');

include($script);
}
else
{
if (substr($script, -3) == 'gif' OR substr($script, -3) == 'jpg' OR substr($script, -3) == 'png' OR substr($script, -4) == 'jpeg')
{
$contents = file_get_contents($script);

echo $contents;
}
else
{
include($script);
}
}
}


under the include folder
you have to replace function.php with

<?php
/************************************************** *************************
* functions.php
* -------------------
* begin : Saturday, Feb 13, 2001
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id: functions.php,v 1.133.2.47 2006/06/08 21:11:04 grahamje Exp $
*
*
************************************************** *************************/

/************************************************** *************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
************************************************** *************************/

function get_db_stat($mode)
{
global $db;

switch( $mode )
{
case 'usercount':
$sql = "SELECT COUNT(user_id) AS total
FROM " . USERS_TABLE . "
WHERE user_id <> " . ANONYMOUS;
break;

case 'newestuser':
$sql = "SELECT user_id, username
FROM " . USERS_TABLE . "
WHERE user_id <> " . ANONYMOUS . "
ORDER BY user_id DESC
LIMIT 1";
break;

case 'postcount':
case 'topiccount':
$sql = "SELECT SUM(forum_topics) AS topic_total, SUM(forum_posts) AS post_total
FROM " . FORUMS_TABLE;
break;
}

if ( !($result = $db->sql_query($sql)) )
{
return false;
}

$row = $db->sql_fetchrow($result);

switch ( $mode )
{
case 'usercount':
return $row['total'];
break;
case 'newestuser':
return $row;
break;
case 'postcount':
return $row['post_total'];
break;
case 'topiccount':
return $row['topic_total'];
break;
}

return false;
}

// added at phpBB 2.0.11 to properly format the username
function phpbb_clean_username($username)
{
$username = substr(htmlspecialchars(str_replace("\'", "'", trim($username))), 0, 25);
$username = phpbb_rtrim($username, "\\");
$username = str_replace("'", "\'", $username);

return $username;
}

/**
* This function is a wrapper for ltrim, as charlist is only supported in php >= 4.1.0
* Added in phpBB 2.0.18
*/
function phpbb_ltrim($str, $charlist = false)
{
if ($charlist === false)
{
return ltrim($str);
}

$php_version = explode('.', PHP_VERSION);

// php version < 4.1.0
if ((int) $php_version[0] < 4 || ((int) $php_version[0] == 4 && (int) $php_version[1] < 1))
{
while ($str{0} == $charlist)
{
$str = substr($str, 1);
}
}
else
{
$str = ltrim($str, $charlist);
}

return $str;
}

// added at phpBB 2.0.12 to fix a bug in PHP 4.3.10 (only supporting charlist in php >= 4.1.0)
function phpbb_rtrim($str, $charlist = false)
{
if ($charlist === false)
{
return rtrim($str);
}

$php_version = explode('.', PHP_VERSION);

// php version < 4.1.0
if ((int) $php_version[0] < 4 || ((int) $php_version[0] == 4 && (int) $php_version[1] < 1))
{
while ($str{strlen($str)-1} == $charlist)
{
$str = substr($str, 0, strlen($str)-1);
}
}
else
{
$str = rtrim($str, $charlist);
}

return $str;
}

/**
* Our own generator of random values
* This uses a constantly changing value as the base for generating the values
* The board wide setting is updated once per page if this code is called
* With thanks to Anthrax101 for the inspiration on this one
* Added in phpBB 2.0.20
*/
function dss_rand()
{
global $db, $board_config, $dss_seeded;

$val = $board_config['rand_seed'] . microtime();
$val = md5($val);
$board_config['rand_seed'] = md5($board_config['rand_seed'] . $val . 'a');

if($dss_seeded !== true)
{
$sql = "UPDATE " . CONFIG_TABLE . " SET
config_value = '" . $board_config['rand_seed'] . "'
WHERE config_name = 'rand_seed'";

if( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Unable to reseed PRNG", "", __LINE__, __FILE__, $sql);
}

$dss_seeded = true;
}

return substr($val, 4, 16);
}
//
// Get Userdata, $user can be username or user_id. If force_str is true, the username will be forced.
//
function get_userdata($user, $force_str = false)
{
global $db;

if (!is_numeric($user) || $force_str)
{
$user = phpbb_clean_username($user);
}
else
{
$user = intval($user);
}

$sql = "SELECT *
FROM " . USERS_TABLE . "
WHERE ";
$sql .= ( ( is_integer($user) ) ? "user_id = $user" : "username = '" . str_replace("\'", "''", $user) . "'" ) . " AND user_id <> " . ANONYMOUS;
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Tried obtaining data for a non-existent user', '', __LINE__, __FILE__, $sql);
}

return ( $row = $db->sql_fetchrow($result) ) ? $row : false;
}

function make_jumpbox($action, $match_forum_id = 0)
{
global $template, $userdata, $lang, $db, $nav_links, $phpEx, $SID;

// $is_auth = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata);

$sql = "SELECT c.cat_id, c.cat_title, c.cat_order
FROM " . CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f
WHERE f.cat_id = c.cat_id
GROUP BY c.cat_id, c.cat_title, c.cat_order
ORDER BY c.cat_order";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Couldn't obtain category list.", "", __LINE__, __FILE__, $sql);
}

$category_rows = array();
while ( $row = $db->sql_fetchrow($result) )
{
$category_rows[] = $row;
}

if ( $total_categories = count($category_rows) )
{
$sql = "SELECT *
FROM " . FORUMS_TABLE . "
ORDER BY cat_id, forum_order";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql);
}

$boxstring = '<select name="' . POST_FORUM_URL . '" onchange="if(this.options[this.selectedIndex].value != -1){ forms[\'jumpbox\'].submit() }"><option value="-1">' . $lang['Select_forum'] . '</option>';

$forum_rows = array();
while ( $row = $db->sql_fetchrow($result) )
{
$forum_rows[] = $row;
}

if ( $total_forums = count($forum_rows) )
{
for($i = 0; $i < $total_categories; $i++)
{
$boxstring_forums = '';
for($j = 0; $j < $total_forums; $j++)
{
if ( $forum_rows[$j]['cat_id'] == $category_rows[$i]['cat_id'] && $forum_rows[$j]['auth_view'] <= AUTH_REG )
{

// if ( $forum_rows[$j]['cat_id'] == $category_rows[$i]['cat_id'] && $is_auth[$forum_rows[$j]['forum_id']]['auth_view'] )
// {
$selected = ( $forum_rows[$j]['forum_id'] == $match_forum_id ) ? 'selected="selected"' : '';
$boxstring_forums .= '<option value="' . $forum_rows[$j]['forum_id'] . '"' . $selected . '>' . $forum_rows[$j]['forum_name'] . '</option>';

//
// Add an array to $nav_links for the Mozilla navigation bar.
// 'chapter' and 'forum' can create multiple items, therefore we are using a nested array.
//
$nav_links['chapter forum'][$forum_rows[$j]['forum_id']] = array (
'url' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=" . $forum_rows[$j]['forum_id']),
'title' => $forum_rows[$j]['forum_name']
);

}
}

if ( $boxstring_forums != '' )
{
$boxstring .= '<option value="-1">&nbsp;</option>';
$boxstring .= '<option value="-1">' . $category_rows[$i]['cat_title'] . '</option>';
$boxstring .= '<option value="-1">----------------</option>';
$boxstring .= $boxstring_forums;
}
}
}

$boxstring .= '</select>';
}
else
{
$boxstring .= '<select name="' . POST_FORUM_URL . '" onchange="if(this.options[this.selectedIndex].value != -1){ forms[\'jumpbox\'].submit() }"></select>';
}

// Let the jumpbox work again in sites having additional session id checks.
// if ( !empty($SID) )
// {
$boxstring .= '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />';
// }

$template->set_filenames(array(
'jumpbox' => 'jumpbox.tpl')
);
$template->assign_vars(array(
'L_GO' => $lang['Go'],
'L_JUMP_TO' => $lang['Jump_to'],
'L_SELECT_FORUM' => $lang['Select_forum'],

'S_JUMPBOX_SELECT' => $boxstring,
'S_JUMPBOX_ACTION' => append_sid($action))
);
$template->assign_var_from_handle('JUMPBOX', 'jumpbox');

return;
}

//
// Initialise user settings on page load
function init_userprefs($userdata)
{
global $board_config, $theme, $images;
global $template, $lang, $phpEx, $phpbb_root_path, $db;
global $nav_links;

if ( $userdata['user_id'] != ANONYMOUS )
{
if ( !empty($userdata['user_lang']))
{
$default_lang = phpbb_ltrim(basename(phpbb_rtrim($userdata['user_lang'])), "'");
}

if ( !empty($userdata['user_dateformat']) )
{
$board_config['default_dateformat'] = $userdata['user_dateformat'];
}

if ( isset($userdata['user_timezone']) )
{
$board_config['board_timezone'] = $userdata['user_timezone'];
}
}
else
{
$default_lang = phpbb_ltrim(basename(phpbb_rtrim($board_config['default_lang'])), "'");
}

if ( !file_exists(@phpbb_realpath($phpbb_root_path . 'language/lang_' . $default_lang . '/lang_main.'.$phpEx)) )
{
if ( $userdata['user_id'] != ANONYMOUS )
{
// For logged in users, try the board default language next
$default_lang = phpbb_ltrim(basename(phpbb_rtrim($board_config['default_lang'])), "'");
}
else
{
// For guests it means the default language is not present, try english
// This is a long shot since it means serious errors in the setup to reach here,
// but english is part of a new install so it's worth us trying
$default_lang = 'english';
}

if ( !file_exists(@phpbb_realpath($phpbb_root_path . 'language/lang_' . $default_lang . '/lang_main.'.$phpEx)) )
{
message_die(CRITICAL_ERROR, 'Could not locate valid language pack');
}
}

// If we've had to change the value in any way then let's write it back to the database
// before we go any further since it means there is something wrong with it
if ( $userdata['user_id'] != ANONYMOUS && $userdata['user_lang'] !== $default_lang )
{
$sql = 'UPDATE ' . USERS_TABLE . "
SET user_lang = '" . $default_lang . "'
WHERE user_lang = '" . $userdata['user_lang'] . "'";

if ( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, 'Could not update user language info');
}

$userdata['user_lang'] = $default_lang;
}
elseif ( $userdata['user_id'] === ANONYMOUS && $board_config['default_lang'] !== $default_lang )
{
$sql = 'UPDATE ' . CONFIG_TABLE . "
SET config_value = '" . $default_lang . "'
WHERE config_name = 'default_lang'";

if ( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, 'Could not update user language info');
}
}

$board_config['default_lang'] = $default_lang;

include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx);

if ( defined('IN_ADMIN') )
{
if( !file_exists(@phpbb_realpath($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.'.$phpEx)) )
{
$board_config['default_lang'] = 'english';
}

include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.' . $phpEx);
}

//
// Set up style
//
if ( !$board_config['override_user_style'] )
{
if ( $userdata['user_id'] != ANONYMOUS && $userdata['user_style'] > 0 )
{
if ( $theme = setup_style($userdata['user_style']) )
{
return;
}
}
}

$theme = setup_style($board_config['default_style']);

//
// Mozilla navigation bar
// Default items that should be valid on all pages.
// Defined here to correctly assign the Language Variables
// and be able to change the variables within code.
//
$nav_links['top'] = array (
'url' => append_sid($phpbb_root_path . 'index.' . $phpEx),
'title' => sprintf($lang['Forum_Index'], $board_config['sitename'])
);
$nav_links['search'] = array (
'url' => append_sid($phpbb_root_path . 'search.' . $phpEx),
'title' => $lang['Search']
);
$nav_links['help'] = array (
'url' => append_sid($phpbb_root_path . 'faq.' . $phpEx),
'title' => $lang['FAQ']
);
$nav_links['author'] = array (
'url' => append_sid($phpbb_root_path . 'memberlist.' . $phpEx),
'title' => $lang['Memberlist']
);

return;
}

function setup_style($style)
{
global $db, $board_config, $template, $images, $phpbb_root_path;

$sql = 'SELECT *
FROM ' . THEMES_TABLE . '
WHERE themes_id = ' . (int) $style;
if ( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, 'Could not query database for theme info');
}

if ( !($row = $db->sql_fetchrow($result)) )
{
// We are trying to setup a style which does not exist in the database
// Try to fallback to the board default (if the user had a custom style)
// and then any users using this style to the default if it succeeds
if ( $style != $board_config['default_style'])
{
$sql = 'SELECT *
FROM ' . THEMES_TABLE . '
WHERE themes_id = ' . (int) $board_config['default_style'];
if ( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, 'Could not query database for theme info');
}

if ( $row = $db->sql_fetchrow($result) )
{
$db->sql_freeresult($result);

$sql = 'UPDATE ' . USERS_TABLE . '
SET user_style = ' . (int) $board_config['default_style'] . "
WHERE user_style = $style";
if ( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, 'Could not update user theme info');
}
}
else
{
message_die(CRITICAL_ERROR, "Could not get theme data for themes_id [$style]");
}
}
else
{
message_die(CRITICAL_ERROR, "Could not get theme data for themes_id [$style]");
}
}

$template_path = 'templates/' ;
$template_name = $row['template_name'] ;

$template = new Template($phpbb_root_path . $template_path . $template_name);

if ( $template )
{
$current_template_path = $template_path . $template_name;
@include($phpbb_root_path . $template_path . $template_name . '/' . $template_name . '.cfg');

if ( !defined('TEMPLATE_CONFIG') )
{
message_die(CRITICAL_ERROR, "Could not open $template_name template config file", '', __LINE__, __FILE__);
}

$img_lang = ( file_exists(@phpbb_realpath($phpbb_root_path . $current_template_path . '/images/lang_' . $board_config['default_lang'])) ) ? $board_config['default_lang'] : 'english';

while( list($key, $value) = @each($images) )
{
if ( !is_array($value) )
{
$images[$key] = str_replace('{LANG}', 'lang_' . $img_lang, $value);
}
}
}

return $row;
}

function encode_ip($dotquad_ip)
{
$ip_sep = explode('.', $dotquad_ip);
return sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]);
}

function decode_ip($int_ip)
{
$hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]);
}

//
// Create date/time from format and timezone
//
function create_date($format, $gmepoch, $tz)
{
global $board_config, $lang;
static $translate;

if ( empty($translate) && $board_config['default_lang'] != 'english' )
{
@reset($lang['datetime']);
while ( list($match, $replace) = @each($lang['datetime']) )
{
$translate[$match] = $replace;
}
}

return ( !empty($translate) ) ? strtr(@gmdate($format, $gmepoch + (3600 * $tz)), $translate) : @gmdate($format, $gmepoch + (3600 * $tz));
}

//
// Pagination routine, generates
// page number sequence
//
function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE)
{
global $lang;

$total_pages = ceil($num_items/$per_page);

if ( $total_pages == 1 )
{
return '';
}

$on_page = floor($start_item / $per_page) + 1;

$page_string = '';
if ( $total_pages > 10 )
{
$init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages;

for($i = 1; $i < $init_page_max + 1; $i++)
{
$page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&amp;start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
if ( $i < $init_page_max )
{
$page_string .= ", ";
}
}

if ( $total_pages > 3 )
{
if ( $on_page > 1 && $on_page < $total_pages )
{
$page_string .= ( $on_page > 5 ) ? ' ... ' : ', ';

$init_page_min = ( $on_page > 4 ) ? $on_page : 5;
$init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4;

for($i = $init_page_min - 1; $i < $init_page_max + 2; $i++)
{
$page_string .= ($i == $on_page) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&amp;start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
if ( $i < $init_page_max + 1 )
{
$page_string .= ', ';
}
}

$page_string .= ( $on_page < $total_pages - 4 ) ? ' ... ' : ', ';
}
else
{
$page_string .= ' ... ';
}

for($i = $total_pages - 2; $i < $total_pages + 1; $i++)
{
$page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&amp;start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
if( $i < $total_pages )
{
$page_string .= ", ";
}
}
}
}
else
{
for($i = 1; $i < $total_pages + 1; $i++)
{
$page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&amp;start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
if ( $i < $total_pages )
{
$page_string .= ', ';
}
}
}

if ( $add_prevnext_text )
{
if ( $on_page > 1 )
{
$page_string = ' <a href="' . append_sid($base_url . "&amp;start=" . ( ( $on_page - 2 ) * $per_page ) ) . '">' . $lang['Previous'] . '</a>&nbsp;&nbsp;' . $page_string;
}

if ( $on_page < $total_pages )
{
$page_string .= '&nbsp;&nbsp;<a href="' . append_sid($base_url . "&amp;start=" . ( $on_page * $per_page ) ) . '">' . $lang['Next'] . '</a>';
}

}

$page_string = $lang['Goto_page'] . ' ' . $page_string;

return $page_string;
}

//
// This does exactly what preg_quote() does in PHP 4-ish
// If you just need the 1-parameter preg_quote call, then don't bother using this.
//
function phpbb_preg_quote($str, $delimiter)
{
$text = preg_quote($str);
$text = str_replace($delimiter, '\\' . $delimiter, $text);

return $text;
}

//
// Obtain list of naughty words and build preg style replacement arrays for use by the
// calling script, note that the vars are passed as references this just makes it easier
// to return both sets of arrays
//
function obtain_word_list(&$orig_word, &$replacement_word)
{
global $db;

//
// Define censored word matches
//
$sql = "SELECT word, replacement
FROM " . WORDS_TABLE;
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not get censored words from database', '', __LINE__, __FILE__, $sql);
}

if ( $row = $db->sql_fetchrow($result) )
{
do
{
$orig_word[] = '#\b(' . str_replace('\*', '\w*?', preg_quote($row['word'], '#')) . ')\b#i';
$replacement_word[] = $row['replacement'];
}
while ( $row = $db->sql_fetchrow($result) );
}

return true;
}

//
// This is general replacement for die(), allows templated
// output in users (or default) language, etc.
//
// $msg_code can be one of these constants:
//
// GENERAL_MESSAGE : Use for any simple text message, eg. results
// of an operation, authorisation failures, etc.
//
// GENERAL ERROR : Use for any error which occurs _AFTER_ the
// common.php include and session code, ie. most errors in
// pages/functions
//
// CRITICAL_MESSAGE : Used when basic config data is available but
// a session may not exist, eg. banned users
//
// CRITICAL_ERROR : Used when config data cannot be obtained, eg
// no database connection. Should _not_ be used in 99.5% of cases
//
function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '')
{
global $db, $template, $board_config, $theme, $lang, $phpEx, $phpbb_root_path, $nav_links, $gen_simple_header, $images;
global $userdata, $user_ip, $session_length;
global $starttime;

if(defined('HAS_DIED'))
{
die("message_die() was called multiple times. This isn't supposed to happen. Was message_die() used in page_tail.php?");
}

define('HAS_DIED', 1);


$sql_store = $sql;

//
// Get SQL error if we are debugging. Do this as soon as possible to prevent
// subsequent queries from overwriting the status of sql_error()
//
if ( DEBUG && ( $msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR ) )
{
$sql_error = $db->sql_error();

$debug_text = '';

if ( $sql_error['message'] != '' )
{
$debug_text .= '<br /><br />SQL Error : ' . $sql_error['code'] . ' ' . $sql_error['message'];
}

if ( $sql_store != '' )
{
$debug_text .= "<br /><br />$sql_store";
}

if ( $err_line != '' && $err_file != '' )
{
$debug_text .= '<br /><br />Line : ' . $err_line . '<br />File : ' . basename($err_file);
}
}

if( empty($userdata) && ( $msg_code == GENERAL_MESSAGE || $msg_code == GENERAL_ERROR ) )
{
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
}

//
// If the header hasn't been output then do it
//
if ( !defined('HEADER_INC') && $msg_code != CRITICAL_ERROR )
{
if ( empty($lang) )
{
if ( !empty($board_config['default_lang']) )
{
include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.'.$phpEx);
}
else
{
include($phpbb_root_path . 'language/lang_english/lang_main.'.$phpEx);
}
}

if ( empty($template) || empty($theme) )
{
$theme = setup_style($board_config['default_style']);
}

//
// Load the Page Header
//
if ( !defined('IN_ADMIN') )
{
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
}
else
{
include($phpbb_root_path . 'admin/page_header_admin.'.$phpEx);
}
}

switch($msg_code)
{
case GENERAL_MESSAGE:
if ( $msg_title == '' )
{
$msg_title = $lang['Information'];
}
break;

case CRITICAL_MESSAGE:
if ( $msg_title == '' )
{
$msg_title = $lang['Critical_Information'];
}
break;

case GENERAL_ERROR:
if ( $msg_text == '' )
{
$msg_text = $lang['An_error_occured'];
}

if ( $msg_title == '' )
{
$msg_title = $lang['General_Error'];
}
break;

case CRITICAL_ERROR:
//
// Critical errors mean we cannot rely on _ANY_ DB information being
// available so we're going to dump out a simple echo'd statement
//
include($phpbb_root_path . 'language/lang_english/lang_main.'.$phpEx);

if ( $msg_text == '' )
{
$msg_text = $lang['A_critical_error'];
}

if ( $msg_title == '' )
{
$msg_title = 'phpBB : <b>' . $lang['Critical_Error'] . '</b>';
}
break;
}

//
// Add on DEBUG info if we've enabled debug mode and this is an error. This
// prevents debug info being output for general messages should DEBUG be
// set TRUE by accident (preventing confusion for the end user!)
//
if ( DEBUG && ( $msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR ) )
{
if ( $debug_text != '' )
{
$msg_text = $msg_text . '<br /><br /><b><u>DEBUG MODE</u></b>' . $debug_text;
}
}

if ( $msg_code != CRITICAL_ERROR )
{
if ( !empty($lang[$msg_text]) )
{
$msg_text = $lang[$msg_text];
}

if ( !defined('IN_ADMIN') )
{
$template->set_filenames(array(
'message_body' => 'message_body.tpl')
);
}
else
{
$template->set_filenames(array(
'message_body' => 'admin/admin_message_body.tpl')
);
}

$template->assign_vars(array(
'MESSAGE_TITLE' => $msg_title,
'MESSAGE_TEXT' => $msg_text)
);
$template->pparse('message_body');

if ( !defined('IN_ADMIN') )
{
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
}
else
{
include($phpbb_root_path . 'admin/page_footer_admin.'.$phpEx);
}
}
else
{
echo "<html>\n<body>\n" . $msg_title . "\n<br /><br />\n" . $msg_text . "</body>\n</html>";
}

exit;
}

//
// This function is for compatibility with PHP 4.x's realpath()
// function. In later versions of PHP, it needs to be called
// to do checks with some functions. Older versions of PHP don't
// seem to need this, so we'll just return the original value.
// dougk_ff7 <October 5, 2002>
function phpbb_realpath($path)
{
global $phpbb_root_path, $phpEx;

return (!@function_exists('realpath') || !@realpath($phpbb_root_path . 'includes/functions.'.$phpEx)) ? $path : @realpath($path);
}

function redirect($url)
{
global $db, $board_config;

if (!empty($db))
{
$db->sql_close();
}

if (strstr(urldecode($url), "\n") || strstr(urldecode($url), "\r"))
{
message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.');
}

$server_protocol = ($board_config['cookie_secure']) ? 'https://' : 'http://';
$server_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim($board_config['server_name']));
$server_port = ($board_config['server_port'] <> 80) ? ':' . trim($board_config['server_port']) : '';
$script_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim($board_config['script_path']));
$script_name = ($script_name == '') ? $script_name : $script_name . '.';
$url = preg_replace('#^\/?(.*?)\/?$#', '/\1', trim($url));

// Redirect via an HTML form for PITA webservers
if (@preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')))
{
header('Refresh: 0; URL=' . $server_protocol . $script_name . $server_name . $server_port . $url);
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta http-equiv="refresh" content="10; url=' . $server_protocol . $script_name . $server_name . $server_port . $url . '"><title>Redirect</title></head><body><div align="center">If your browser does not support meta redirection please click <a href="' . $server_protocol . $server_name . $server_port . $script_name . $url . '">HERE</a> to be redirected</div></body></html>';
exit;
}

// Behave as per HTTP/1.1 spec for others
header('Location: ' . $server_protocol . $script_name . $server_name . $server_port . $url);
exit;
}

?>



new_forum.php

<?php

/*
+================================================= =======================+
|| NBSdesignz Multi-Forums phpBB - Version 1.0.0 Beta 7
|| -----------------------------------------------------------------------
|| By NBSdesignz (http://www.nbsdesignz.com)
|| Copyright © 2006 NBSdesignz
|| This file may not be redistributed in whole or significant part.
|| --------------------- THIS SCRIPT IS FREEWARE. ------------------------
|| All copyright notices in this script must stay intact unless
|| copyright removal has been purchased!
|| -----------------------------------------------------------------------
|| Although this script has been tested by us, we are not responsible for
|| any damage it may cause!
|| -----------------------------------------------------------------------
|| $Id: new_forum.php,v 1.29 2006/08/13 02:24:48 derek Exp $
|| Downloaded: Friday, September 08, 2006 07:51:38
+================================================= =======================+
*/

// ######################### DEFINE CONSTANTS ############################
define('THIS_SCRIPT', 'new_forum');
define('IN_NBS', true);
define('PHRASE_TYPE', 4);
define('CVS_REVISION', '$RCSfile: new_forum.php,v $ - $Revision: 1.29 $');

// #################### REQUIRE IMPORTANT FILES ##########################
require_once('nbs/global.php');

// ################################################## #####################
// ######################### START MAIN SCRIPT ###########################
// ################################################## #####################

if ($_REQUEST['do'] == 'tos')
{
$title = $nbs->phrase['terms_of_service'];
}
else
{
$title = $nbs->phrase['create_a_new_forum'];
}

check_script_status();
check_registration_status();

if ($_REQUEST['do'] == 'check')
{
if ($_GET['accessname'])
{
$accessname = trim($_GET['accessname']);
$accessname = str_replace(' ', '_', $accessname);
$accessname = str_replace('!', '', $accessname);
$accessname = str_replace('"', '', $accessname);
$accessname = str_replace('\'', '', $accessname);
$accessname = str_replace('/', '', $accessname);
$accessname = str_replace('@', '', $accessname);
$accessname = str_replace('#', '', $accessname);
$accessname = str_replace('$', '', $accessname);
$accessname = str_replace('%', '', $accessname);
$accessname = str_replace('^', '', $accessname);
$accessname = str_replace('&', '', $accessname);
$accessname = str_replace('*', '', $accessname);
$accessname = str_replace('(', '', $accessname);
$accessname = str_replace(')', '', $accessname);
$accessname = str_replace('-', '_', $accessname);
$accessname = str_replace('?', '', $accessname);
$accessname = str_replace(',', '', $accessname);
$accessname = str_replace('.', '', $accessname);
$accessname = str_replace('<', '', $accessname);
$accessname = str_replace('>', '', $accessname);
$accessname = str_replace(':', '', $accessname);
$accessname = str_replace(';', '', $accessname);
$accessname = str_replace('{', '', $accessname);
$accessname = str_replace('}', '', $accessname);
$accessname = str_replace('|', '', $accessname);
$accessname = str_replace('=', '', $accessname);
$accessname = str_replace('+', '', $accessname);
$accessname = str_replace('`', '', $accessname);
$accessname = str_replace('~', '', $accessname);
$accessname = str_replace('[', '', $accessname);
$accessname = str_replace(']', '', $accessname);

$query = "SELECT accessname FROM " . TABLE_PREFIX . "users WHERE accessname = '" . $db->escape_string($accessname) . "' LIMIT 1";
$result = $db->query($query);
$num_rows = $db->num_rows($result);

$reserved_accessnames = explode(',', $nbs->setting['reserved_accessnames']);

$connection = @ftp_connect($nbs->setting['ftp_server']);
$login = @ftp_login($connection, $nbs->setting['ftp_username'], $nbs->setting['ftp_password']);
$list = @ftp_nlist($connection, $nbs->setting['ftp_path']);

if (!empty($list))
{
foreach ($list AS $file)
{
if ($accessname == $file)
{
print '<span class="gen" style="color: #FF0000;"><strong>' . $nbs->phrase['access_name_reserved'] . '</strong></span>';
exit;
}
}
}

foreach ($reserved_accessnames AS $reserved_accessname)
{
if ($accessname == $reserved_accessname)
{
print '<span class="gen" style="color: #FF0000;"><strong>' . $nbs->phrase['access_name_reserved'] . '</strong></span>';
exit;
}
}

if ($num_rows == 0)
{
print '<span class="gen" style="color: #00FF00;"><strong>' . $nbs->phrase['access_name_available'] . '</strong></span>';
}
else
{
print '<span class="gen" style="color: #FF0000;"><strong>' . $nbs->phrase['access_name_not_available'] . '</strong></span>';
}
}
else
{
print '<span class="gen" style="color: #FF0000;"><strong>' . $nbs->phrase['please_enter_an_access_name'] . '</strong></span>';
}
exit;
}

if ($nbs->setting['num_forums_to_allow'] != 0)
{
$forumchk1 = "SELECT `id` FROM " . TABLE_PREFIX . "users WHERE user_level <> 1";
$forumchk2 = $db->query($forumchk1);
$forumchk3 = $db->num_rows($forumchk2);

if ($forumchk3 >= $nbs->setting['num_forums_to_allow'])
{
print_error_message($nbs->phrase['maximum_forums_on_site_reached_error']);
}

$db->free_result($forumchk2);

unset($forumchk1, $forumchk3);
}

if ($_POST['do'] == 'setup')
{
if (empty($_POST['accessname']) OR empty($_POST['forumname']) OR empty($_POST['forumdescription']) OR empty($_POST['adminuser']) OR empty($_POST['adminpass']) OR empty($_POST['cadminpass']) OR empty($_POST['adminemail']) OR ($nbs->setting['captcha'] AND empty($_POST['captcha_code'])))
{
print_error_message($nbs->phrase['multiple_fields_blank_error']);
}

if (md5($_POST['adminpass']) != md5($_POST['cadminpass']))
{
print_error_message($nbs->phrase['password_fields_do_not_match_error']);
}

if ($nbs->setting['check_email_domain'])
{
list($user, $domain) = split('@', $_POST['adminemail']);

if (!checkdnsrr($domain, 'MX'))
{
print_error_message($nbs->phrase['invalid_email_address_error']);
}
}

if ($nbs->setting['captcha'])
{
// include captcha class
require('nbs/php-captcha.inc.php');

if (!PhpCaptcha::Validate($_POST['captcha_code']))
{
print_error_message($nbs->phrase['image_verification_code_incorrect_error']);
}
}

if (empty($_POST['tos']))
{
print_error_message($nbs->phrase['terms_of_service_not_checked_error']);
}

// clean accessname.
$accessname = trim($_POST['accessname']);
$accessname = str_replace(' ', '_', $accessname);
$accessname = str_replace('!', '', $accessname);
$accessname = str_replace('"', '', $accessname);
$accessname = str_replace('\'', '', $accessname);
$accessname = str_replace('/', '', $accessname);
$accessname = str_replace('@', '', $accessname);
$accessname = str_replace('#', '', $accessname);
$accessname = str_replace('$', '', $accessname);
$accessname = str_replace('%', '', $accessname);
$accessname = str_replace('^', '', $accessname);
$accessname = str_replace('&', '', $accessname);
$accessname = str_replace('*', '', $accessname);
$accessname = str_replace('(', '', $accessname);
$accessname = str_replace(')', '', $accessname);
$accessname = str_replace('-', '_', $accessname);
$accessname = str_replace('?', '', $accessname);
$accessname = str_replace(',', '', $accessname);
$accessname = str_replace('.', '', $accessname);
$accessname = str_replace('<', '', $accessname);
$accessname = str_replace('>', '', $accessname);
$accessname = str_replace(':', '', $accessname);
$accessname = str_replace(';', '', $accessname);
$accessname = str_replace('{', '', $accessname);
$accessname = str_replace('}', '', $accessname);
$accessname = str_replace('|', '', $accessname);
$accessname = str_replace('=', '', $accessname);
$accessname = str_replace('+', '', $accessname);
$accessname = str_replace('`', '', $accessname);
$accessname = str_replace('~', '', $accessname);
$accessname = str_replace('[', '', $accessname);
$accessname = str_replace(']', '', $accessname);
$accessname = strtolower($accessname);

$reserved_accessnames = explode(',', $nbs->setting['reserved_accessnames']);

$connection = @ftp_connect($nbs->setting['ftp_server']);
$login = @ftp_login($connection, $nbs->setting['ftp_username'], $nbs->setting['ftp_password']);
$list = @ftp_nlist($connection, $nbs->setting['ftp_path']);

if (!empty($list))
{
foreach ($list AS $file)
{
if ($accessname == $file)
{
print_error_message($nbs->phrase['reserved_access_name_error']);
}
}
}

foreach ($reserved_accessnames AS $reserved_accessname)
{
if ($accessname == $reserved_accessname)
{
print_error_message($nbs->phrase['reserved_access_name_error']);
}
}

$check1 = "SELECT `id` FROM " . TABLE_PREFIX . "users WHERE accessname = '" . $db->escape_string($accessname) . "' LIMIT 1";
$check2 = $db->query($check1);
$check = $db->num_rows($check2);

if ($check == 1 OR file_exists('nbs/configs/config_' . $accessname . '.php'))
{
print_error_message($nbs->phrase['access_name_exists_error']);
}

$db->free_result($check2);

unset($check1, $check);

if ($nbs->setting['limit_forums_per_email'])
{
$emailchk1 = "SELECT `id` FROM " . TABLE_PREFIX . "users WHERE email = '" . $db->escape_string($_POST['adminemail']) . "' AND user_level <> 1";
$emailchk2 = $db->query($emailchk1);
$emailchk3 = $db->num_rows($emailchk2);

if ($emailchk3 >= $nbs->setting['num_accounts_allowed_per_email'])
{
print_error_message($nbs->phrase['maximum_forums_limit_reached_error']);
}

$db->free_result($emailchk2);

unset($emailchk1, $emailchk3);
}

$_POST['forumname'] = $db->escape_string($_POST['forumname']);
$_POST['forumdescription'] = $db->escape_string($_POST['forumdescription']);
$_POST['adminuser'] = $db->escape_string($_POST['adminuser']);
$_POST['adminpass'] = $db->escape_string($_POST['adminpass']);
$_POST['adminemail'] = $db->escape_string($_POST['adminemail']);

$length = 25;
$key_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ0123456789';
$rand_max = strlen($key_chars) - 1;

for ($i = 0; $i < $length; $i++)
{
$rand = rand(0, $rand_max);
$rand_key[] = $key_chars{$rand};
}

$act_key = implode('', $rand_key);

require_once('nbs/new_forum_sql.php');

foreach ($sql AS $query)
{
$db->query($query);
}

$dbms = 'mysql4';

$config_data = '<?php' . "\n\n";
$config_data .= "\n// phpBB 2.x auto-generated config file\n// Do not change anything in this file!\n\n";
$config_data .= '$dbms = \'' . $dbms . '\';' . "\n\n";
$config_data .= '$dbhost = \'' . $nbs->config['Database']['host'] . '\';' . "\n";
$config_data .= '$dbname = \'' . $nbs->config['Database']['name'] . '\';' . "\n";
$config_data .= '$dbuser = \'' . $nbs->config['Database']['username'] . '\';' . "\n";
$config_data .= '$dbpasswd = \'' . $nbs->config['Database']['password'] . '\';' . "\n\n";
$config_data .= '$table_prefix = \'' . $accessname . '_\';' . "\n\n";
$config_data .= 'define(\'PHPBB_INSTALLED\', true);' . "\n\n";
$config_data .= '?' . '>';

$file = fopen('nbs/configs/config_' . $accessname . '.php', 'w');
fwrite($file, $config_data);

mkdirftp($nbs->setting['ftp_server'], $nbs->setting['ftp_username'], $nbs->setting['ftp_password'], $nbs->setting['ftp_path'] . 'images/', $accessname);

mkdirftp($nbs->setting['ftp_server'], $nbs->setting['ftp_username'], $nbs->setting['ftp_password'], $nbs->setting['ftp_path'] . 'images/' . $accessname . '/', 'avatars', 777);

mkdirftp($nbs->setting['ftp_server'], $nbs->setting['ftp_username'], $nbs->setting['ftp_password'], $nbs->setting['ftp_path'] . 'images/' . $accessname . '/avatars/', 'gallery');

mkdirftp($nbs->setting['ftp_server'], $nbs->setting['ftp_username'], $nbs->setting['ftp_password'], $nbs->setting['ftp_path'] . 'images/' . $accessname . '/', 'smiles');

upload_file($nbs->setting['ftp_server'], $nbs->setting['ftp_username'], $nbs->setting['ftp_password'], 'images/index.htm', $nbs->setting['ftp_path'] . 'images/' . $accessname . '/index.htm', FTP_ASCII);

upload_file($nbs->setting['ftp_server'], $nbs->setting['ftp_username'], $nbs->setting['ftp_password'], 'images/spacer.gif', $nbs->setting['ftp_path'] . 'images/' . $accessname . '/spacer.gif', FTP_BINARY);

upload_file($nbs->setting['ftp_server'], $nbs->setting['ftp_username'], $nbs->setting['ftp_password'], 'images/index.htm', $nbs->setting['ftp_path'] . 'images/' . $accessname . '/avatars/index.htm', FTP_ASCII);

upload_file($nbs->setting['ftp_server'], $nbs->setting['ftp_username'], $nbs->setting['ftp_password'], 'images/index.htm', $nbs->setting['ftp_path'] . 'images/' . $accessname . '/avatars/gallery/index.htm', FTP_ASCII);
if ($nbs->setting['verify_email_address'])
{
$nbs->phrase['verify_email_message'] = str_replace('\n', "\n", $nbs->phrase['verify_email_message']);

$message = wordwrap(construct_phrase($nbs->phrase['verify_email_message'], $accessname, $nbs->setting['domain'], $nbs->setting['path'], $_SERVER['REMOTE_ADDR'], $_POST['forumname'], $_POST['forumdescription'], $_POST['adminuser'], $_POST['adminpass'], $_POST['adminemail'], $act_key, $nbs->setting['email_signature']), 70);

$headers = 'From: ' . $nbs->setting['script_email_address'] . "\r\n" . 'Reply-To: ' . $nbs->setting['script_email_address'] . "\r\n" . 'X-Mailer: PHP/' . phpversion();

mail($_POST['adminemail'], $nbs->phrase['verify_email_subject'], $message, $headers);
}

if ($nbs->setting['verify_email_address'])
{
$message = $nbs->phrase['forum_setup_successfully'] . '<br /><br />' . $nbs->phrase['verification_message'] . '<br /><br />' . construct_phrase($nbs->phrase['forum_setup_link'], $nbs->setting['domain'], $nbs->setting['path'], $accessname);
}
else
{
$message = $nbs->phrase['forum_setup_successfully'] . '<br /><br />' . construct_phrase($nbs->phrase['forum_setup_link'], $nbs->setting['domain'], $nbs->setting['path'], $accessname);
}

print_information_message($message);
}
else if ($_REQUEST['do'] == 'tos')
{
require_once('nbs/header.php');
require_once('nbs/footer.php');

$tos = file_get_contents('nbs/tos.txt');

$tpl->assign('header', $header);
$tpl->assign('L_terms_of_service', $nbs->phrase['terms_of_service']);
$tpl->assign('tos', $tos);
$tpl->assign('footer', $footer);

$tpl->display('tos.tpl');
}
else if ($_REQUEST['do'] == 'activate')
{
if ($_GET['accessname'] AND $_GET['key'])
{
$sql = "SELECT `status`, `act_key` FROM " . TABLE_PREFIX . "users WHERE accessname = '" . $db->escape_string($_GET['accessname']) . "' LIMIT 1";
$sqlr = $db->query($sql);
$sr = $db->fetch_array($sqlr)