DokuWiki

It's better when it's simple

User Tools

Site Tools


Sidebar

Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community


Follow us on Facebook, Twitter and other social networks.

tips:integrate_with_phpbb

Integrate with phpBB

This is a description of how to integrate the user authentication and group facilities in phpBB with dokuWiki.

For integration with PHPBB3, please see this page.

Information regarding this topic could also be found in Authentication backend: MySQL. With the next release DokuWiki will get a revised authentication module system. Details can be found in The Dokuwiki Manual. Information on this page will become deprecated with the new authentication system.
Matthias Grimm 2005-11-22 22:29
A new authentication class has been added to the end of this document which should work with phpbb's cookie. — FatherNitwit 2006-7-14

Requirements

  • A working installation of phpBB
  • A working installation of dokuWiki
  • Some patience

Facts

  • This method of integrating relies on the use of groups in phpBB.

For the less knowledgeable…
With the setup below, DokuWiki assumes that the table prefix in your forum's mySQL database is set to the default 'phpbb'. You set the table prefix as part of the installation routine for phpBB so if you're about to set up a new forum then don't change this!
I'm sure there is some way of altering the DokuWiki code to account for any changes to the prefix that is made but I don't know the first thing about php or mySQL so I can't tell you what to change. I made the mistake of changing my phpBB table prefix and in the end I went back to my forum database, manually changed all the table names (which is very tedious) and then edited the /phpBB/config.php file so that the table prefix was set to phpbb instead of what I'd had previously.

Steps

Configure auth_mysql

The code below is best placed in conf/local.php, so that it will be easy to upgrade later.

We use phpBBs username as a replacement for name since phpBB does not provide us with any information about real names (first name, last name). If you are creating local.php for the first time, be sure the opening tag, <?php appears at the top of the file.

$conf['openregister']= 0;                //Should users to be allowed to register?
 
$conf['useacl']      = 1;                //Use Access Control Lists to restrict access?
 
$conf['authtype'] = 'mysql';
 
$conf['auth']['mysql']['server']   = '<host>';              // mySQL host, usually localhost
$conf['auth']['mysql']['user']     = '<database user>';     // mySQL database user for the database that is used by phpBB
$conf['auth']['mysql']['password'] = '<database password>'; // mySQL database password for the database that is used by phpBB
$conf['auth']['mysql']['database'] = '<database>';          // mySQL database that is used by phpBB
 
$conf['auth']['mysql']['passcheck']= "SELECT username AS login
                                        FROM phpbb_users
                                       WHERE username='%u'
                                         AND user_password=MD5('%p')";
$conf['auth']['mysql']['userinfo'] = "SELECT username AS name, user_email AS mail
                                        FROM phpbb_users
                                       WHERE username='%u'";
$conf['auth']['mysql']['groups']   = "SELECT group_name as `group`
                                        FROM phpbb_groups a, phpbb_users b, phpbb_user_group c
                                       WHERE b.user_id = c.user_id
                                         AND a.group_id = c.group_id
                                         AND b.username='%u'";

:!: This does not work with the new MySQL Backend!


To work with the new Backend the following appears to work:

$conf['openregister']= 0;                //Should users to be allowed to register?
 
$conf['useacl']      = 1;                //Use Access Control Lists to restrict access?
 
$conf['authtype'] = 'mysql';
 
$conf['auth']['mysql']['server']   = '<host>';              // mySQL host, usually localhost
$conf['auth']['mysql']['user']     = '<database user>';     // mySQL database user for the database that is used by phpBB
$conf['auth']['mysql']['password'] = '<database password>'; // mySQL database password for the database that is used by phpBB
$conf['auth']['mysql']['database'] = '<database>';          // mySQL database that is used by phpBB
 
$conf['auth']['mysql']['forwardClearPass'] = 1;
$conf['auth']['mysql']['checkPass']= "SELECT user_password AS login
                                        FROM phpbb_users
                                        WHERE username='%{user}'
                                        AND user_password=MD5('%{pass}')";
$conf['auth']['mysql']['getUserInfo'] = "SELECT user_password AS pass, username AS name, user_email AS mail
                                        FROM phpbb_users
                                        WHERE username='%{user}'";
$conf['auth']['mysql']['getGroups']   = "SELECT group_name as `group`
                                        FROM phpbb_groups a, phpbb_users b, phpbb_user_group c
                                        WHERE b.user_id = c.user_id
                                        AND a.group_id = c.group_id
                                        AND b.username='%{user}'";

:!: This does not work with phpBB 3!

Create groups in phpBB

Use existing phpBB groups only

The details of how you create groups are described in a very good tutorial that phpBB has in their knowledge base.

There is basically one thing that you have to keep in mind when you name the groups. Group names with whitespaces do not work.

:!: Warning the group names should be made lowercase as the ACL script is translating the group names to lowercase as well…

Add all forum users to a group "Users" with SQL-statement

I have nearly 1000 Users on my Forum, and i want that only Users are able to edit a page. Because I won't add every User to a Group “Users” I use the following SQL-Statement to select the Group of a User and add the User automaticaly to the Group “Users”, which dosn't exist in my PHPBB:

$conf['auth']['mysql']['groups']        =  "SELECT group_name as `group` 
                                           FROM phpbb_groups a, phpbb_users b, phpbb_user_group c 
                                           WHERE b.user_id = c.user_id AND a.group_id = c.group_id
                                           AND b.username='%u'
                                           UNION 
                                           SELECT 'users' as `group` 
                                           FROM phpbb_groups a, phpbb_users b, phpbb_user_group c 
                                           WHERE b.user_id = c.user_id 
                                           AND a.group_id = c.group_id 
                                           AND b.username='%u';"

I know its a little big, but I have my own server and a good performance (running on Gentoo *scnr* - the Querry do 0.12sec) so I do better this than adding all Users to Group Users and patch the login.php to add all new users to Users.

For the new MySQL backend

$conf['auth']['mysql']['getGroups']        =  "SELECT group_name as `group` 
                                           FROM phpbb_groups a, phpbb_users b, phpbb_user_group c 
                                           WHERE b.user_id = c.user_id 
	                                   AND a.group_id = c.group_id
                                           AND b.username='%{user}'
                                           UNION 
                                           SELECT '" . $conf['defaultgroup'] . "' as `group` 
                                           FROM phpbb_groups a, phpbb_users b, phpbb_user_group c 
                                           WHERE b.user_id = c.user_id 
                                           AND a.group_id = c.group_id 
                                           AND b.username='%{user}'";

Add all forum users to the default group with a script modification

I don't understand anything of mySQL, so I thought I'd better not touch that query, but instead modified inc/auth/mysql.php to achieve the same effect. You need to change one single line in the function auth_getUserData, namely in the loop foreach($result as $row){ replace the line $info['grps'][] = $row['group']; by this:

$info['grps'][] = $conf['defaultgroup'].','.$row['group'];

Each registered user in your phpBB forum is added to the default group defined in your conf-files.

Nice, thanks. This solution is much elegant than the MySQL-Query :-)integrate_with_phpbb defel 2005-03-30 00:30
It would be better to add the default group outside the foreach loop as right now you are adding it for every group the user is in.
So keep the foreach loop the way it is, and add the following code on the line before the loop:
$info['grps'][] = $conf['defaultgroup']; //Add the default group 

How to adapt this to the new mysql backend?

Well, like above. To add the defaultgroup by “default” to a user, just add the defaultgroup to the array of groups, befor it is returned. ;-)integrate_with_phpbb anniyka 2006-07-29 23:22

    function _getGroups($user) {
      $groups = array();
 
      if($this->dbcon) {
        $sql = str_replace('%{user}',$this->_escape($user),$this->cnf['getGroups']);
        $result = $this->_queryDB($sql);
 
        if(count($result)) {
          foreach($result as $row)
            $groups[] = $row['group'];
        }
        $groups[] = $this->defaultgroup;    //    .......... add this line ..........
        return $groups;
      }
      return false;

Configure acl.auth

How to configure the acl.auth is described in acl. The group names are the ones that you have created in phpBB.

Other settings

Signature linking to phpBB user profile

I don't want to publish the email addresses of my privacy concerned users, so I've decided to have their signatures point to their user profiles, which they can configure as they like through phpBB.

I've used the “mail” field of userinfo to hold their user ID:

$conf['auth']['mysql']['userinfo'] = "SELECT username AS name, user_id AS mail
                                        FROM phpbb_users
                                       WHERE username='%u'";

Then I've set the signature template to:

$conf['signature']     = '//[[user>@MAIL@|@NAME@]] @DATE@//';

(both modifications go into local.php, see config)

The signature is now an interwiki link, which i have set to:

user      /forum/profile.php?mode=viewprofile&u=

(put this line in your interwiki.conf) — Andrea 2005-09-17 11:58


The above was the basis for my phpbb signature mod. This is a more up to date version of above.

Add these lines to your local.php file.

$conf['auth']['mysql']['getUserInfo'] = "SELECT username AS name, user_id AS mail
                                        FROM phpbb_users
                                       WHERE username='%{user}'";
 
$conf['signature']     = '//[[user>@MAIL@|@NAME@]] @DATE@//';

If you followed the instructions to integrate with phpBB above you already have lines like this.

$conf['auth']['mysql']['getUserInfo'] = "SELECT user_password AS pass, username AS name, user_email AS mail
                                        FROM phpbb_users
                                        WHERE username='%{user}'";

I commented that line out so that it looked like this.

//$conf['auth']['mysql']['getUserInfo'] = "SELECT user_password AS pass, username AS name, user_email AS mail
//                                        FROM phpbb_users
//                                        WHERE username='%{user}'";

Then I added this line to the interwiki.conf file at the bottom.

user      /forum/profile.php?mode=viewprofile&u=

Save your files and that's it. Now when you add your signature it points back to the profile page in phpBB. This worked for phpBB version 2.0.20.

[Clint] 2007-07-09

phpBB.CLASS.PHP

I changed PUNBB.CLASS.PHP to be compable with PHPBB,

here is the ,it is not compable with PHPBB too much ,especially the cookie & session functions,cos i do not know much more about punbb !

but it work for me ! Anybody can rechange it more and deeply

<?php
/**
 * phpbb auth backend
 *
 * Uses external Trust mechanism to check against phpbb's
 * user cookie. phpbb's PHPBB_ROOT must be defined correctly.
 *
 * @author    Andreas Gohr <andi@splitbrain.org>
 * @hacked    Yanni.Zheng <ynzheng@gmail.com>
 */
 
if(!defined('PHPBB_ROOT')) define('PHPBB_ROOT', DOKU_INC.'../bbs/');
if(get_magic_quotes_gpc()){
  nice_die('Sorry the phpbb auth backend requires the PHP option
  <a href="http://www.php.net/manual/en/ref.info.php#ini.magic-quotes-gpc">magic_quotes_gpc</a>
  to be disabled for proper operation. Either setup your PHP install accordingly or
  choose a different auth backend.');
}
 
require_once PHPBB_ROOT.'/config.php';
require_once DOKU_INC.'inc/auth/mysql.class.php';
 
#dbg($GLOBALS);
#dbg($pun_user);

class auth_phpbb extends auth_mysql {
 
  /**
   * Constructor.
   *
   * Sets additional capabilities and config strings
   */
  function auth_phpbb(){
    global $conf;
    $this->cando['external'] = true;
    $this->cando['logoff']   = true;
 
    // make sure we use a crypt understood by phpbb
    if(function_exists('sha1')){
      $conf['passcrypt'] = 'sha1';
    }else{
      $conf['passcrypt'] = 'md5';
    }
 
    // get global vars from phpbb config
    global $dbhost;
    global $dbname;
    global $dbuser;
    global $dbpasswd;
    global $table_prefix;
 
    // now set up the mysql config strings
    $conf['auth']['mysql']['server']   = $dbhost;
    $conf['auth']['mysql']['user']     = $dbuser;
    $conf['auth']['mysql']['password'] = $dbpasswd;
    $conf['auth']['mysql']['database'] = $dbname;
 
//see http://www.dokuwiki.org/tips:integrate_with_phpbb
$conf['auth']['mysql']['forwardClearPass'] = 1; 
 
$conf['auth']['mysql']['checkPass']= "SELECT u.user_password AS login
                                        FROM ${table_prefix}users AS u
                                        WHERE u.username='%{user}'
                                        AND u.user_password=MD5('%{pass}')";
 
//$conf['auth']['mysql']['getUserInfo'] = "SELECT u.user_password AS pass, u.user_fullname AS name, u.user_id AS mail
//                                        FROM ${table_prefix}users AS u
//                                        WHERE u.username='%{user}'";
$conf['auth']['mysql']['getUserInfo'] = "SELECT u.user_password AS pass, u.user_fullname AS name, u.user_email AS mail
                                        FROM ${table_prefix}users AS u
                                        WHERE u.username='%{user}'";
 
//$conf['auth']['mysql']['getGroups']   = "SELECT g.group_name as `group`
//                                        FROM ${table_prefix}groups AS g, ${table_prefix}users AS u, ${table_prefix}user_group c
//                                        WHERE u.user_id = c.user_id
//                                        AND g.group_id = c.group_id
//                                        AND u.username='%{user}'";
$conf['auth']['mysql']['getGroups']   = "SELECT g.group_name as `group`
                                        FROM ${table_prefix}groups AS g, ${table_prefix}users AS u, ${table_prefix}user_group c
                                        WHERE u.user_id = c.user_id
                                        AND g.group_id = c.group_id
                                        AND u.username='%{user}'
                                        UNION 
                                        SELECT '" . $conf['defaultgroup'] . "' as `group`
                                        FROM ${table_prefix}groups AS g, ${table_prefix}users AS u, ${table_prefix}user_group c
                                        WHERE u.user_id = c.user_id
                                        AND g.group_id = c.group_id
                                        AND u.username='%{user}'";
$conf['auth']['mysql']['getUsers']    = "SELECT DISTINCT u.username AS user
                                        FROM ${table_prefix}users AS u";    
 
$conf['auth']['mysql']['FilterLogin'] = "u.username LIKE '%{user}'";
$conf['auth']['mysql']['FilterName']  = "u.user_fullname LIKE '%{name}'";
$conf['auth']['mysql']['FilterEmail'] = "u.user_email    LIKE '%{email}'";
$conf['auth']['mysql']['FilterGroup'] = "g.group_name    LIKE '%{group}'";
$conf['auth']['mysql']['SortOrder']   = "ORDER BY u.username";
 
//$conf['auth']['mysql']['addUser']     = "INSERT INTO ${table_prefix}users
//                                                (username, user_password, user_email, user_fullname)
//                                         VALUES ('%{user}', '%{pass}', '%{email}', '%{name}')";
//$conf['auth']['mysql']['addGroup']    = "INSERT INTO ${table_prefix}groups (group_name) VALUES ('%{group}')";
//$conf['auth']['mysql']['addUserGroup']= "UPDATE ${table_prefix}users
//                                            SET group_id=%{gid}
//                                          WHERE id='%{uid}'";
//$conf['auth']['mysql']['delGroup']    = "DELETE FROM ${table_prefix}groups WHERE g_id='%{gid}'";
//$conf['auth']['mysql']['getUserID']   = "SELECT id FROM ${table_prefix}users WHERE username='%{user}'";
//$conf['auth']['mysql']['updateUser']  = "UPDATE ${table_prefix}users SET";
//$conf['auth']['mysql']['UpdateLogin'] = "username='%{user}'";
//$conf['auth']['mysql']['UpdatePass']  = "password='%{pass}'";
//$conf['auth']['mysql']['UpdateEmail'] = "email='%{email}'";
//$conf['auth']['mysql']['UpdateName']  = "realname='%{name}'";
//$conf['auth']['mysql']['UpdateTarget']= "WHERE id=%{uid}";
//$conf['auth']['mysql']['delUserGroup']= "UPDATE ${table_prefix}users SET g_id=4 WHERE id=%{uid}";
$conf['auth']['mysql']['getGroupID']  = "SELECT group_id AS id FROM ${table_prefix}groups WHERE group_name='%{group}'";
 
//$conf['auth']['mysql']['TablesToLock']= array("${table_prefix}users", "${table_prefix}users AS u",
//                                              "${table_prefix}groups", "${table_prefix}groups AS g");
 
//end see http://www.dokuwiki.org/tips:integrate_with_phpbb                                        
 
/*
    $conf['auth']['mysql']['checkPass']   = "SELECT u.password AS pass
                                               FROM ${table_prefix}users AS u, ${table_prefix}groups AS g
                                              WHERE u.group_id = g.g_id
                                                AND u.username = '%{user}'
                                                AND g.g_title   != 'Guest'";
    $conf['auth']['mysql']['getUserInfo'] = "SELECT password AS pass, realname AS name, email AS mail,
                                                    id, g_title as `group`
                                               FROM ${table_prefix}users AS u, ${table_prefix}groups AS g
                                              WHERE u.group_id = g.g_id
                                                AND u.username = '%{user}'";
    $conf['auth']['mysql']['getGroups']   = "SELECT g.g_title as `group`
                                               FROM ${table_prefix}users AS u, ${table_prefix}groups AS g
                                              WHERE u.group_id = g.g_id
                                                AND u.username = '%{user}'";
 
    $conf['auth']['mysql']['getUsers']    = "SELECT DISTINCT u.username AS user
                                               FROM ${table_prefix}users AS u, ${table_prefix}groups AS g
                                              WHERE u.group_id = g.g_id";
 
    $conf['auth']['mysql']['FilterLogin'] = "u.username LIKE '%{user}'";
    $conf['auth']['mysql']['FilterName']  = "u.realname LIKE '%{name}'";
    $conf['auth']['mysql']['FilterEmail'] = "u.email    LIKE '%{email}'";
    $conf['auth']['mysql']['FilterGroup'] = "g.g_title    LIKE '%{group}'";
    $conf['auth']['mysql']['SortOrder']   = "ORDER BY u.username";
    $conf['auth']['mysql']['addUser']     = "INSERT INTO ${table_prefix}users
                                                    (username, password, email, realname)
                                             VALUES ('%{user}', '%{pass}', '%{email}', '%{name}')";
    $conf['auth']['mysql']['addGroup']    = "INSERT INTO ${table_prefix}groups (g_title) VALUES ('%{group}')";
    $conf['auth']['mysql']['addUserGroup']= "UPDATE ${table_prefix}users
                                                SET group_id=%{gid}
                                              WHERE id='%{uid}'";
    $conf['auth']['mysql']['delGroup']    = "DELETE FROM ${table_prefix}groups WHERE g_id='%{gid}'";
    $conf['auth']['mysql']['getUserID']   = "SELECT id FROM ${table_prefix}users WHERE username='%{user}'";
    $conf['auth']['mysql']['updateUser']  = "UPDATE ${table_prefix}users SET";
    $conf['auth']['mysql']['UpdateLogin'] = "username='%{user}'";
    $conf['auth']['mysql']['UpdatePass']  = "password='%{pass}'";
    $conf['auth']['mysql']['UpdateEmail'] = "email='%{email}'";
    $conf['auth']['mysql']['UpdateName']  = "realname='%{name}'";
    $conf['auth']['mysql']['UpdateTarget']= "WHERE id=%{uid}";
    $conf['auth']['mysql']['delUserGroup']= "UPDATE ${table_prefix}users SET g_id=4 WHERE id=%{uid}";
    $conf['auth']['mysql']['getGroupID']  = "SELECT g_id AS id FROM ${table_prefix}groups WHERE g_title='%{group}'";
 
    $conf['auth']['mysql']['TablesToLock']= array("${table_prefix}users", "${table_prefix}users AS u",
                                                  "${table_prefix}groups", "${table_prefix}groups AS g");
*/
 
    $conf['auth']['mysql']['debug'] = 1;
    // call mysql constructor
    $this->auth_mysql();
  }
 
  /**
   * Just checks against the $pun_user variable
   */
  function trustExternal($user,$pass,$sticky=false){
    global $USERINFO;
    global $conf;
    global $lang;
    global $pun_user;
    global $pun_config;
    $sticky ? $sticky = true : $sticky = false; //sanity check
 
    // someone used the login form
    if(isset($user)){
      if($this->checkPass($user,$pass)){
        $expire = ($sticky) ? time() + 31536000 : 0;
        $uinfo  = $this->getUserData($user);
        //pun_setcookie($uinfo['id'], auth_cryptPassword($pass), $expire);
        setcookie($uinfo['id'], auth_cryptPassword($pass), $expire);
        $pun_user = array();
        $pun_user['password'] = auth_cryptPassword($pass);
        $pun_user['username'] = $user;
        $pun_user['realname'] = $uinfo['name'];
        $pun_user['email']    = $uinfo['mail'];
        $pun_user['g_title']  = $uinfo['group'];
      }else{
        //invalid credentials - log off
        msg($lang['badlogin'],-1);
        auth_logoff();
        return false;
      }
    }
 
    if(isset($pun_user) && !$pun_user['is_guest']){
      // okay we're logged in - set the globals
      $USERINFO['pass'] = $pun_user['password'];
      $USERINFO['name'] = $pun_user['realname'];
      $USERINFO['mail'] = $pun_user['email'];
      $USERINFO['grps'] = array($pun_user['g_title']);
 
      $_SERVER['REMOTE_USER'] = $pun_user['username'];
      $_SESSION[$conf['title']]['auth']['user'] = $pun_user['username'];
      $_SESSION[$conf['title']]['auth']['info'] = $USERINFO;
      return true;
    }
 
    // to be sure
    auth_logoff();
    return false;
  }
 
  /**
   * remove phpbb cookie on logout
   */
  function logOff(){
    global $pun_user;
    $pun_user = array();
    //pun_setcookie(1, random_pass(8), time() + 31536000);
    setcookie(1, '', time() + 31536000);
  }
}
//Setup VIM: ex: et ts=2 enc=utf-8 :

Yanni.Zheng 2006-06-12 11:58

Another phpbb.class.php

I have developed this phpbb.class.php auth backend to be more tightly integrated with phpbb's auth system. It should cooperate with phpbb's cookie authentication (given that your cookie path is set up properly), such that logging in or out of either app will log you in or out of both.

You should just be able to drop this into your int/auth folder, edit $phpbb_root_path, and change your auth mode to phpbb and off you go. You should NOT need to configure any of the mysql query stuff mentioned above for this to work.

:!: It appears to me that “int/auth” should be “inc/auth”. It also appears to me that you need to create the auth folder, since it does not exist by default in the wiki installation (at least, it wasn't created in mine). However, when I did all the other coding suggestions here, I got an error message saying that inc/auth.php was looking for and couldn't find “inc/auth/phpbb.php”, which suggests to me that I am correct (I am getting the error message because I am - for the moment I hope - unable to create the inc/auth folder. - Bill :!: My mistake…the folder inc/auth does exist, but my File Manager GUI for my domain would not let me see it…I had to open a DOS FTP session (I assume this is part of the mystery of UNIX). I was able to upload and use inc/auth/phpbb.php . I am now wrestling with finding basic.class.php (see phpbb.php below) which does not appear to be in the expected folder. If I comment “require_once(DOKU_AUTH.'/basic.class.php');” out, then the statement “class auth_phpbb extends auth_basic” fails, since the auth_basic class was probably defined in the basic.class.php file (which I don't know where it is)…oh, well… - Bill

It shouldent be too hard to get group support working, but I did not have a chance to get to it yet.

<?php
/**
 * PHPBB authentication backend
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author FatherNitwit
 */
 
define('DOKU_AUTH', dirname(__FILE__));
require_once(DOKU_AUTH.'/basic.class.php');
 
 
define("IN_LOGIN", true);
define('IN_PHPBB', true);
$phpbb_root_path = $location.'../phpBB2/';
$dlang = $lang;	#phpbb uses $lang too..
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$lang = $dlang;
 
 
// we only accept page ids for auth_plain
if(isset($_REQUEST['u']))
  $_REQUEST['u'] = cleanID($_REQUEST['u']);
if(isset($_REQUEST['acl_user']))
  $_REQUEST['acl_user'] = cleanID($_REQUEST['acl_user']);
 
class auth_phpbb extends auth_basic {
	var $userdata;
 
    /**
     * Constructor
     *
     * Carry out sanity checks to ensure the object is
     * able to operate. Set capabilities.
     *
     */
    function auth_phpbb() {
		global $user_ip;
        $this->success = true;
		$this->cando['logoff'] = true;
		//$this->cando['getGroups'] = true;
		$this->cando['external'] = true;
		//
		// Set page ID for session management
		//
		$this->userdata = session_pagestart($user_ip, PAGE_LOGIN);
		init_userprefs($this->userdata);
		//
		// End session management
		//
    }
 
	function trustExternal($user,$pass,$sticky=false){
		$sticky ? $sticky = true : $sticky = false;
		if($this->userdata['session_logged_in']) {
			//already logged in...
		} else {
			if(!$this->checkPass2($user,$pass,$sticky)) {
				return;
			}
		}
		global $USERINFO;
		$USERINFO = $this->getUserData($this->userdata['username']);
 
		$_SERVER['REMOTE_USER'] = $this->userdata['username'];
		$_SESSION[$conf['title']]['auth']['user'] = $this->userdata['username'];
		$_SESSION[$conf['title']]['auth']['pass'] = "__";
		$_SESSION[$conf['title']]['auth']['buid'] = auth_browseruid();
		$_SESSION[$conf['title']]['auth']['info'] = $USERINFO;
		/*var_dump($_SESSION[$conf['title']]['auth']);
		die("fff");*/
	}
 
    function checkPass($user,$pass){
		return($this->checkPass2($user,$pass,0));
	}
    function checkPass2($user,$pass,$auto){
		global $user_ip;
		global $db;
 
		$sql = "SELECT user_id, username, user_password, user_active, user_level, user_login_tries, user_last_login_try
			FROM " . USERS_TABLE . "
			WHERE username = '" . str_replace("\\'", "''", $user) . "'";
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, 'Error in obtaining userdata', '', __LINE__, __FILE__, $sql);
		}
 
		if( $row = $db->sql_fetchrow($result) )
		{
			if( md5($pass) == $row['user_password'] && $row['user_active'] ) {
 
				$this->userdata = session_begin($row['user_id'], $user_ip, PAGE_INDEX, FALSE, $auto, 0);
 
				if( !$this->userdata )
				{
					message_die(CRITICAL_ERROR, "Couldn't start session : login", "", __LINE__, __FILE__);
				}
				return(true);
			}
		}
		msg($lang['badlogin'],-1);
		return(false);
    }
 
    /**
     * Return user info
     *
     * Returns info about the given user needs to contain
     * at least these fields:
     *
     * name string  full name of the user
     * mail string  email addres of the user
     * grps array   list of groups the user is in
     *
     */
    function getUserData($user){
		global $conf;
		if($this->userdata['session_logged_in']) {
			global $db;
			//ok, figure out what groups they are in
			$sql = "SELECT g.group_name, ug.user_pending 
				FROM " . GROUPS_TABLE . " g, " . USER_GROUP_TABLE . " ug
				WHERE ug.user_id = " . $this->userdata['user_id'] . "  
					AND ug.group_id = g.group_id
					AND g.group_single_user <> " . TRUE . "
				ORDER BY g.group_name, ug.user_id";
			if ( !($result = $db->sql_query($sql)) )
			{
				message_die(GENERAL_ERROR, 'Error getting users group information', '', __LINE__, __FILE__, $sql);
			}
			$groups = array($conf['defaultgroup']);
			while( $row = $db->sql_fetchrow($result) ) {
				if(!$row['user_pending'])
					$groups[] = $row['group_name'];
			}
 
			return(array('name' => $user, 
						 'mail' => $this->userdata['user_email'], 
						 'grps' => $groups
						 )
				   );
		}
		return(false);
    }
 
	function logOff(){
		if( $this->userdata['session_logged_in'] )
		{
			session_end($this->userdata['session_id'], $this->userdata['user_id']);
		}
	}
 
	/*
	I didnt get this working...
	function retrieveGroups($start=0,$limit=0) {
		die("hi g");
		$sql = "SELECT g.group_name 
			FROM " . GROUPS_TABLE . " g
				AND g.group_single_user <> " . TRUE;
		if($limit != 0)
			$sql = $sql . " LIMIT $start,$limit";
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, 'Error getting group information', '', __LINE__, __FILE__, $sql);
		}
		$groups = array("User");
		while( $row = $db->sql_fetchrow($result) ) {
			$groups[] = $row['group_name'];
		}
		return $groups;
  }*/
 
}

FatherNitwit 2006-7-14

Now, you must edit the files in dokuwiki/lib/exe. In all these files add before if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(FILE).'/../../').'/'); this code:

$location = '../../';

This is important to find the phpBB path.

DevO 2007-06-14

Why not change the code to this?

$location = DOKU_AUTH.'/../../'; //???
$phpbb_root_path = $location.$conf['phpbb_path'];

Then set in dokuwiki.php

$conf['phpbb_path'] = '../phpBB'; //relative phpBB path




Be careful!
Make sure, that register_globals is set to off. This can be done in a .htaccess-File by

php_flag register_globals off

Otherwise it can cause problems with automatically updating the searchindex!
See http://forum.dokuwiki.org/thread/1895 for problem description.
See http://irc.dokuwiki.org/index.php?d=2008-03-29 for problem analysis.
berlindave 2008/03/29 15:11


Change the links in the inc/html.php file.

 <?php
    if($auth->canDo('addUser') && actionOK('register')){
      print '<p>';
      print $lang['reghere'];
      print ': <a href="../phpbb/profile.php?mode=register&agreed=true" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>';
 
      print '</p>';
    }
 
    if ($auth->canDo('modPass') && actionOK('resendpwd')) {
      print '<p>';
      print $lang['pwdforget'];
      print ': <a href="../phpbb/profile.php?mode=sendpassword" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
      print '</p>';
    }
  ?>

phpBB 3 integration

phpBB changed the password hashing method in the RC7 version. I hacked together a solution for making it work with auth_mysql. Nothing fancy but it works for me.

Add the following setting to conf/local.php:

$conf['passcrypt']    = 'phpbb';

The important changes to mysql.conf.php are:

$conf['auth']['mysql']['forwardClearPass'] = 0;
 
$conf['auth']['mysql']['checkPass']   = "SELECT user_password AS pass
                                         FROM phpbb_users
                                         WHERE username='%{user}'";

You then need to add some code to 2 functions in inc/auth.php:

In the auth_verifyPassword function, add the following check.

    }elseif (substr($crypt,0,3) == '$H$'){
     $method = 'phpbb';
     $salt = $crypt;

Then in the auth_cryptPassword function, add this case:

case 'phpbb':
      $phpbb_path = '../forum/'; // this is the path to phpBB relative to your wiki
      define('IN_PHPBB', true);
      include_once(DOKU_INC . $phpbb_path . 'includes/functions.php');
      $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
      return _hash_crypt_private($clear, $salt, $itoa64);

Be sure to change the $phpbb_path variable to your phpBB install directory!

Comments

Just to say thanks - many (perhaps most) of my phpBB forum users use cookie authentication so to integrate this with DokuWiki is very useful. — Ben Pollinger

Thanks for this plugin first of all… Do have any sample or demo site that has used this setup? Thnx…. Andrew Abogado

Ok, I'm terribly sorry but I don't completely understand what all I should be doing to integrate these two things. Is there any way someone could make this a little clearer about which files are being edited where, which of it is mysql, which of the files should be created. That sort of thing.

This is written so poorly.

Very useful idea, but this doesn't really explain what to do! I'm not very good with mySQL or php, so it'd be great if someone could simplify this for us (most of the work is already done I imagine)….

I agree written extremely poorly I am still trying to fix the problems and I've been working on it for 4 hours now!

A try to explain how to do integration - 26.11.2007

After hours (And days, believe me) of struggling with all those changes in local.conf and SQL commands I found out that it is so easy….
Well….there is a lot of stuff mentioned above which is not needed to integrate Dokuwiki in a phpBB board. You need these changes:

Changes to conf/local.php:
$conf['authtype'] = 'phpbb'; Add it or change the existing one
$conf['defaultgroup']= 'user'; This one has to be in sync with your existing group in phpBB
$conf['superuser'] = '<site admin>'; The admin of the board. Additional superusers can be configured via config tool in the Dokuwiki
$conf['disableactions'] = 'register'; To stop registering via Dokuwiki, I just want new users to register via my phpBB board, got a self-made registering form
$conf['openregister']= 0; No self-Registering allowed (Maybe obsolete because of disable register, did not try this)

$conf['auth']['mysql']['server'] and ['user'] is not needed!

Then follow the instructions behind Another phpbb.class.php
That means: Copy the code completely to a plain text file named phpbb.class.php and store it in inc/auth.
Change the path ($phpbb_root_path = $location.'../phpbb2/';) in the script to the path to your phpBB board (Important, otherwise the script will not find files stored there). So if your board resides in the root of your webspace, type '../' or if it resides in a sub-folder named phpbb, type '../phpbb/' Next, do the changes below the code window:

Now, you must edit the files in dokuwiki/lib/exe. In all these files add before if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(FILE).'/../../').'/'); this code:
$location = '../../';

Do it word by word. Exactly in the way how it is described.
Now you should be done. The users have to be registered with the forum and if they open the wiki accordingly, their usernames should be displayed in the lower left corner of the main Dokuwiki window.
After all a little right adjustment should be done via the config tool / rights management. My users (Group: User like the usergroup in phpBB) have the right to write in the namespace where the info files are stored and the board admins rights to manage every page.
I created that on my local XAMPP installation and after successful testing I copied the changed files to the installation on my webspace. Now it runs like a charm.
Please drop a note if you got this to work. If not, too. ;-) And a big “THANK YOU” goes out to FatherNitwit for creating the phpBB.Class. by gonzo99

@gonzo99 It worked! (phpBB 2.0.22 & DokuWiki 2007-06-26b)
But I discovered one Problem yet:
When editing a page, if I try to use “insert signature”, there's always the signature of the old Admin (the one I defined when setting up DokuWiki) inserted. Any suggestions for solution?
But: Many thanks to gonzo99!
berlindave 2007-12-15 21:45

I just wrote a new phpBB 3 integration guide. I hope it's useful for someone. :-)
P.S.: This page should really be splitted in several ones. — Markus -voks- Henn 2007-12-26 02:10

tips/integrate_with_phpbb.txt · Last modified: 2017-12-05 18:38 by LarsDW223