DokuWiki

It's better when it's simple

ユーザ用ツール

サイト用ツール


ja:tips:integrate_with_phpbb

phpBBとの連携

日本人のPHPBB使いの方、ここに情報を集めましょう ^_^

この改造は、phpBBユーザーを、dokuWikiのユーザーとして利用します。dokuWikiに対する権限は、phpBBのグループをdokuWikiのアクセスコントロール>グループで登録することにより操作できます。 phpBBユーザーの所属するグループと、dokuWikiのグループが一致しない場合 dokuWikiは グループ ALL として動作します

Information regarding this topic could also be found in Authenticationbackend: MySQL and New MySQL Authentication Back end. 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
phpBB3に対応したページを和訳しましたので、よろしければご覧下さい。— akkie 2010-01-14

Requirements

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

Facts

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

動作確認済みの作業流れ

前提:

  1. dokuwiki の管理権限Gr(デフォルトグループ:admin) と、編集Gr(デフォルトグループ:user) の2つを確認。
  2. phpbb側に グループ adminとuserを作成。 adminは隠れグループ。userは、オープングループまたはクローズドグループを推奨。
  3. phpbb側のadminグループのモデレータはphpBBの管理者 phpbb側のuserグループには一般ユーザーを登録

 編集Grを新たに作成する(追加する)場合、user のu より前のアルファベットでないと、グループが認識されないようだ.・・・vwxyzで始まるグループ名は使用しない。userグループは削除しないほうが無難(dokuwiki-2007-06-26b)

その後

で、簡単に動作しました

Steps

 管理権限を持つadminグループと、編集可能なuserグループのみの単純な管理であれば、1と4のみ。

Configure auth_mysql

:!: 私の環境ではこの方法では動作しませんでした。(phpBB 2.0.22 / dokuwiki-2007-06-26b) 動作したのは →Configure auth_mysql Fix

conf/local.php, を修正しますが、変更できない場合(上書きされない場合)は、telnet等でファイルのアクセス権を666に変更。 (もしくは所有者、所有グループを同位にあるmsgファイルなど同じに変更してください。所有者、所有グループを変更した場合、ACLが操作できなくなる可能性があるため、作業終了後に元に戻してください。)

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'";

Configure auth_mysql Fix

:!: 私の環境では上記は動作せず、下記で動作しました(phpBB 2.0.22 / dokuwiki-2007-06-26b)

conf/local.php, を修正しますが、変更できない場合(上書きされない場合)は、telnet等でファイルのアクセス権を666に変更。 (もしくは所有者、所有グループを同位にあるmsgファイルなど同じに変更してください。所有者、所有グループを変更した場合、ACLが操作できなくなる可能性があるため、作業終了後に元に戻してください。)

$conf['title'] $conf['auth']['mysql']['server'] = '<host>' ~ $conf['auth']['mysql']['database'] = '<database>' を自分の環境に合わせてください。 文字コードはUTF-8です

<?php
/*
 * Dokuwiki's Main Configuration File - Local Settings 
 * Auto-generated by config plugin 
 * Date: 
 */
 
$conf['title'] = 'Wikiのタイトル';
$conf['lang'] = 'ja';
$conf['useheading'] = 1;
$conf['useacl'] = 1;
$conf['authtype'] = 'mysql';
$conf['superuser'] = '@admin';
$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}'";
 
@include(DOKU_CONF.'local.protected.php');
 
// end auto-generated content

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:

UNIONが使用できるのはMysql4.0以降です

$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? FIXME

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

inc/auth/punbb.class.php の内容を全て変更します,

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/wiki: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/wiki: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

:!: 動作確認済み(phpBB 2.0.22 /dokuwiki-2007-06-26b)

$phpbb_root_path = $location.'../phpBB2/'; の値は各自の環境に合わせてください

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

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>';
    }
  ?>

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!

Is there going to be a similar write-up for the new phpBB3 forums?

ja/tips/integrate_with_phpbb.txt · 最終更新: 2011-01-14 15:56 by 61.213.142.216

特に明示されていない限り、本Wikiの内容は次のライセンスに従います: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki