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.

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!

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.

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 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 forum_users ORDER BY user_id DESC LIMIT 1"))->user_id;
		mysql_query("INSERT INTO forum_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 forum_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 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

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

to

<!--   <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> -->