User:Rjhodson/phpBB Installation

From WolfTech
Jump to navigation Jump to search

phpBB on Engineering Servers

To add forum functionality to your site, you may wish to use pre-existing forum software. One such example is phpBB. PhpBB is a free, open-source, php-based internet forum software suite. Using phpBB on an Engineering server, however, requires a custom installation process.

Downloading phpBB

The first step to intalling phpBB is to download the most current stable release of phpBB2. Unzip this file to where you wish host the forum.

Compensating for basedir Restrictions

To compensate for basedir restrictions, you will have to copy the necessary included files to the subdirectories within the phpBB directory that calls them.

Both the install and admin directories need copies of the following:

  • the db directory
  • the includes directory
  • the language directory
  • the templates directory
  • the contrib directory (for the install directory only)
  • the common.php file
  • the extension.inc file
  • the config.php file

All instances of the PHP variable phpbb_root_path should be set to a blank state.

$phpbb_root_path = '';

Additionally, in the /install/install.php file, FTP should be disabled.

// Begin main prog
define('IN_PHPBB', true);
// Uncomment the following line to completely disable the ftp option...
// define('NO_FTP', true);
$phpbb_root_path = './../';
include($phpbb_root_path.'extension.inc');

should be changed to

// Begin main prog
define('IN_PHPBB', true);
// Uncomment the following line to completely disable the ftp option...
define('NO_FTP', true);
$phpbb_root_path = '';
include($phpbb_root_path.'extension.inc');

Setting up the database

PhpBB requires a MySQL database to store much of it's information. Once a database has been created, the forum will need a username and password set up for it. Give the following permissions to this user:

  • SELECT
  • INSERT
  • UPDATE
  • DELETE
  • CREATE (NOTE: this permission will be removed after installation)

Running the installation script

Once all the above modifications have been made, it is time to install phpBB. To begin the installation process, visit the forum's web address. This will auto-direct you to the installation wizard. Once everything has been submitted to the wizard, you will be taken to a page that will prompt you to download a config.php file. Save this file to your forum directory, then put a copy of this file in your admin directory. This file should overwrite the existing config.php file.

  • NOTE: If you intend to use the WRAP Auto-login Script, it is recommended that you set the Site Admin in the installation wizard form as your WRAP id.

Once that is done, visit the web address of the forum once again. The page will prompt you to delete the install directory and the contrib directory - do so. At this point, you will want to go back and remove the CREATE permission from the forum's MySQL privileges.

Congratulations, phpBB has successfully been installed!

Troubleshooting the Administrator Panel

Depending on your server settings, you may be missing some options in your Administrative Panel. If you see only three options, Admin Index, Forum Index, and Preview Forum, try the following fix.

/
// Generate relevant output
//
if( isset($HTTP_GET_VARS['pane']) && $HTTP_GET_VARS['pane'] == 'left' )
{
	$dir = @opendir(".");

	$setmodules = 1;
	while( $file = @readdir($dir) )
	{
		if( preg_match("/^admin_.*?\." . $phpEx . "$/", $file) )
		{
			include('./' . $file);
		}
	}

	@closedir($dir);

	unset($setmodules);

should be replaced with

//
// Generate relevant output
//
if( isset($HTTP_GET_VARS['pane']) && $HTTP_GET_VARS['pane'] == 'left' )
{
	$dir = opendir("./") or die("i died");

	$setmodules = 1;
	while( $file = @readdir($dir) )
	{
		if( preg_match("/^admin_.*?\." . $phpEx . "$/", $file) )
		{
			include($file);
		}
	}

	@closedir($dir);

	unset($setmodules);


WRAP Authentication and User Generation with phpBB

If your phpBB forum is WRAP protected, some slight code modifications can be made to automatically create and log-in users based on their WRAP ids. An easy WRAP management system that the WolfTech Team provides is Guarddog.

Give your WRAP ID administrator privileges

Before we begin, you'll first need to manually add in your WRAP id and give it Administrative privileges. If the site administrator you designated on the phpBB install wizard was your WRAP id, you can skip this step.

To add yourself to the forum, you can register the normal way, then have the current admin user alter your WRAP user's privileges to 'Site Admin'. Alternately, you can WRAP in and run the following script from the main level of your forum directory:

<?PHP
include('config.php');
mysql_connect($dbhost, $dbuser, $dbpasswrd);
mysql_select_db($dbname);

$password = "my_password";

$checkWRAP = mysql_query("SELECT user_id FROM forum_users WHERE username='{$_SERVER['WRAP_USERID']}'");
if(mysql_num_rows($checkWRAP)==0) { //check to see if this user already has an account; if not, create one
	$newID = mysql_fetch_object(mysql_query("SELECT user_id FROM {$table_prefix}_users ORDER BY user_id DESC LIMIT 1"))->user_id;

	mysql_query("INSERT INTO {$table_prefix}_users (user_id, username, user_password, user_level, user_rank) VALUES ('".($newID+1)."', '{$_SERVER['WRAP_USERID']}', '".md5($password)."', '1', '1')") or die(mysql_error());

	mysql_query("INSERT INTO {$table_prefix}_user_group (group_id, user_id, user_pending) VALUES ('2', '".($newID+1)."', '0')") or die(mysql_error());
}
mysql_close();

echo 'COMPLETED';
?>

You can set the variable $password to whatever you wish. Also, remember to delete this script once it has been run once.

Create a custom include file

To make it easier to install, you'll want to make a custom include file to contain your code modifications. We'll call it WRAPcheck.php and make it in the includes directory of the forum's main directory.

Within WRAPcheck, put the following code:

<?PHP
$wolftech_unity_id = NULL;
$wolftech_group = 1;

if(!empty($_SERVER["WRAP_USERID"])) {
	$checkWRAP = mysql_query("SELECT user_id FROM {$table_prefix}_users WHERE username='{$_SERVER['WRAP_USERID']}'");
	if(mysql_num_rows($checkWRAP)==0) { //check to see if this user already has an account; if not, create one
		$newID = mysql_fetch_object(mysql_query("SELECT user_id FROM {$table_prefix}_users ORDER BY user_id DESC LIMIT 1"))->user_id;
		mysql_query("INSERT INTO {$table_prefix}_users (user_id, username, user_password) VALUES ('".($newID+1)."', '{$_SERVER['WRAP_USERID']}', '".md5($_SERVER['WRAP_USERID'].microtime())."')") or die(mysql_error());
		mysql_query("INSERT INTO {$table_prefix}_user_group (group_id, user_id, user_pending) VALUES ('{$wolftech_group}', '".($newID+1)."', '0')") or die(mysql_error());
		$wolftech_unity_id = ($newID+1);		
	} else {
		//$userdata = session_begin(mysql_fetch_object($checkWRAP)->user_id, $user_ip, PAGE_INDEX, FALSE, TRUE);
		$wolftech_unity_id = mysql_fetch_object($checkWRAP)->user_id;
	}
}

function wolftech_session_pagestart($unity_ip, $page_index) {
	global $wolftech_unity_id;
	if($wolftech_unity_id) return session_begin($wolftech_unity_id, $unity_ip, $page_index, FALSE, TRUE);
	else return NULL;
}
?>

You can change the variable names wolftech_unity_id and wolftech_group if you desire.

  • wolftech_unity_id is the id number of the user associated with the WRAP id.
  • wolftech_group is the group number you wish to put the user in. A list of groups and their ids can be found in the phpbb_groups table in the phpBB MySQL database.

Additionally, you can rename the wolftech_session_pagestart function if you'd like.

Including the WRAPcheck script

Now that we have the code, we now have to include it so that every page of the forum has access to it. As such, we'll put the script call in the common.php file, located in the forum's main directory. Do not alter the common.php file in the admin directory.

Replace the following code

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);

with

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);

//
// 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);

//WOLFTECH ADDED CODE
include($phpbb_root_path . 'includes/WRAPcheck.'.$phpEx);

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

Replacing the session_pagestart Function

For the script to work, you'll need to swap out a function from all the files in the forum's main directory level. Do not alter anything in the admin or includes directory.

Replace all instances of

$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);

with

if(!($userdata = wolftech_session_pagestart($user_ip, PAGE_INDEX))) die('Error Message');
init_userprefs($userdata);

Where:

  • wolftech_session_pagestart is the function we defined in the WRAPcheck script
  • PAGE_INDEX is the index of the page the function is called in (this will differ in each of the files - PAGE_INDEX is just used as an example in this case)
  • 'Error Message' is the error message you'd like it to display if the script malfunctions.

Removal of Login/Logout Link (optional)

Since the only users that can access the forum are WRAPed in, and since all WRAPed users are autologged, you may want to remove the login/logout link from the page since it doesn't work. To do so, open the templates/subSilver/overall_header.tpl file and comment out or delete the login/logout link code.

Change the following

&nbsp; &nbsp;<a href="{U_LOGIN_LOGOUT}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_login.gif" width="12" height="13" border="0" alt="{L_LOGIN_LOGOUT}" hspace="3" />{L_LOGIN_LOGOUT}</a>&nbsp;

to

<!--&nbsp; &nbsp;<a href="{U_LOGIN_LOGOUT}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_login.gif" width="12" height="13" border="0" alt="{L_LOGIN_LOGOUT}" hspace="3" />{L_LOGIN_LOGOUT}</a>&nbsp;-->