DokuWiki

It's better when it's simple

ユーザ用ツール

サイト用ツール


ja:tips:integrate_with_phpbb3

phpBB3(の認証)との連携

特徴

  • phpBB の認証システムを用いるので、phpBB にログインしていればDokuWikiに再ログインする必要ありません(逆も同様)。もちろんログアウトも同じです。
  • Using phpBB's groups for DokuWiki's access control list. Some default groups are already implemented (even if they are not displayed on DokuWiki's configuration page):
    • REGISTERED: default group (replaces group user)
    • ADMINISTRATORS: administrator/super user (replaces group admin)
    • GLOBAL_MODERATORS: managers
  • 日付フォーマットとタイムゾーンを同期します。

失われる機能

  • ユーザ登録
  • フルネームの表示(phpBBがデフォルトでユーザプロフィールにフルネームの情報を持っていません。代わりにユーザ名が表示されます。)
  • メディアマネージャとの連携。Wikiで画像が全く表示されない。(パスの問題?)1)
  • Language support

インストール手順

これを適用するには、DokuWiki 2007-06-26b用のパッケージをダウンロードするか次のステップに従って下さい。

  1. inc/auth/phpbb3.class.php を作成
  2. inc/init.php を編集
  3. inc/utf8.php を編集
  4. inc/cache.php を編集
  5. 変数をセットする

Note that it does not function any more after the merge of the requireall branch on 2010-03-12.

inc/auth/phpbb3.class.php を作成

inc/auth/ ディレクトリに phpbb3.class.php というファイル名で次の内容のファイルを作成して下さい。 (エラーが発生するようであれば、コメントセクションにあるように修正して下さい。)

phpbb3.class.php
<?php
/**
* phpBB3 authentication backend
 *
 * Uses external Trust mechanism to check against phpBB's
 * user cookie. phpBB's PHPBB_ROOT_PATH must be defined correctly.
 *
 * @author    Markus Henn <brezelman@yahoo.de>
 */
 
define('IN_PHPBB', true);
$phpEx = substr(strrchr(__FILE__, '.'), 1);
global $phpbb_root_path;
if(strpos($_SERVER['PHP_SELF'], "/lib/plugins/") !== false) { $phpbb_root_path = '../../../'.$phpbb_root_path; }
if(strpos($_SERVER['PHP_SELF'], "/lib/exe/") !== false) { $phpbb_root_path = '../../'.$phpbb_root_path; }
 
require_once(DOKU_INC.'inc/auth/mysql.class.php');
require_once($phpbb_root_path.'common.'.$phpEx);
 
//config is loaded in common file, but $dbpasswd is unset there, too, so we have to reload it
require($phpbb_root_path.'config.'.$phpEx);
 
$user->session_begin();
 
//$auth will be used by DokuWiki, so copy phpBB's $auth to another variable
$phpbb_auth = $auth;
$phpbb_auth->acl($user->data);
 
class auth_phpbb3 extends auth_mysql
{
	function auth_phpbb3()
	{
		$this->cando['external'] = true;
		$this->cando['logoff']   = true;
 
		global $conf;
 
		// get global vars from phpBB config
		global $dbhost;
		global $dbport;
		global $dbname;
		global $dbuser;
		global $dbpasswd;
		global $table_prefix;
 
		// set group config vars
		$conf['defaultgroup'] = 'REGISTERED';
		$conf['superuser'] = '@ADMINISTRATORS';
		$conf['manager'] = '@GLOBAL_MODERATORS';
 
		// now set up the mysql config strings
		$conf['auth']['mysql']['server']   = $dbhost.':'.$dbport;
		$conf['auth']['mysql']['user']     = $dbuser;
		$conf['auth']['mysql']['password'] = $dbpasswd;
		$conf['auth']['mysql']['database'] = $dbname;
 
		//unset $db* variables, so noone can hack them
		unset($dbpasswd);
		unset($dbuser);
		unset($dbhost);
		unset($dbport);
		unset($dbname);
 
		$conf['auth']['mysql']['TablesToLock']= array("{$table_prefix}users", "{$table_prefix}users AS u",
		                                              "{$table_prefix}groups", "{$table_prefix}groups AS g",
		                                              "{$table_prefix}user_group", "{$table_prefix}user_group AS ug");
 
		$conf['auth']['mysql']['checkPass']   = "SELECT user_password AS pass
		                                         FROM {$table_prefix}users
		                                         WHERE username='%{user}'";
 
		$conf['auth']['mysql']['getUserInfo'] = "SELECT user_password AS pass, username AS name, user_email AS mail
		                                         FROM {$table_prefix}users
		                                         WHERE username='%{user}'";
 
		$conf['auth']['mysql']['getGroups']   = "SELECT group_name as `group`
		                                         FROM {$table_prefix}groups g, {$table_prefix}users u, {$table_prefix}user_group ug
		                                         WHERE u.user_id = ug.user_id
		                                         AND g.group_id = ug.group_id
		                                         AND u.username='%{user}'";
 
 
 
		$conf['auth']['mysql']['getUsers']    = "SELECT DISTINCT username AS user
		                                         FROM {$table_prefix}users AS u
		                                         LEFT JOIN {$table_prefix}user_group AS ug ON u.user_id=ug.user_id
		                                         LEFT JOIN {$table_prefix}groups AS g ON ug.group_id=g.group_id";
		$conf['auth']['mysql']['FilterLogin'] = "username LIKE '%{user}'";
		$conf['auth']['mysql']['FilterName']  = "username LIKE '%{name}'";
		$conf['auth']['mysql']['FilterEmail'] = "user_email LIKE '%{email}'";
		$conf['auth']['mysql']['FilterGroup'] = "group_name LIKE '%{group}'";
		$conf['auth']['mysql']['SortOrder']   = "ORDER BY username";
 
		$conf['auth']['mysql']['getUserID']   = "SELECT user_id AS id
		                                         FROM {$table_prefix}users
		                                         WHERE username='%{user}'";
 
		$conf['auth']['mysql']['getGroupID']  = "SELECT group_id AS id
		                                         FROM {$table_prefix}groups
		                                         WHERE group_name='%{group}'";
 
/*		$conf['auth']['mysql']['addUser']     = "INSERT INTO {$table_prefix}users
		                                         (username, user_password, user_email)
		                                         VALUES ('%{user}', '%{pass}', '%{email}')";
 
		$conf['auth']['mysql']['addGroup']    = "INSERT INTO {$table_prefix}groups (group_name)
		                                         VALUES ('%{group}')";
 
		$conf['auth']['mysql']['addUserGroup']= "INSERT INTO {$table_prefix}user_group (user_id, group_id)
		                                         VALUES ('%{uid}', '%{gid}')";
 
		$conf['auth']['mysql']['updateUser']  = "UPDATE {$table_prefix}users SET";
		$conf['auth']['mysql']['UpdateLogin'] = "username='%{user}'";
		$conf['auth']['mysql']['UpdatePass']  = "user_password='%{pass}'";
		$conf['auth']['mysql']['UpdateEmail'] = "user_email='%{email}'";
		//$conf['auth']['mysql']['UpdateName']  = $conf['auth']['mysql']['UpdateLogin'];
		$conf['auth']['mysql']['UpdateTarget']= "WHERE user_id=%{uid}";
 
		$conf['auth']['mysql']['delGroup']    = "DELETE FROM {$table_prefix}groups
		                                         WHERE group_id='%{gid}'";
 
		$conf['auth']['mysql']['delUser']     = "DELETE FROM {$table_prefix}users
		                                         WHERE user_id='%{uid}'";
 
		$conf['auth']['mysql']['delUserRefs'] = "DELETE FROM {$table_prefix}user_group
		                                         WHERE user_id='%{uid}'";
 
		$conf['auth']['mysql']['delUserGroup']= "DELETE FROM {$table_prefix}user_group
		                                         WHERE user_id='%{uid}'
		                                         AND group_id='%{gid}'";
*/
 
		// call mysql constructor
		$this->auth_mysql();
	}
 
 
	function trustExternal($username, $password, $sticky = false)
	{
		global $USERINFO;
		global $conf;
		global $user;
		global $phpbb_auth;
 
		$sticky ? $sticky = true : $sticky = false; // sanity check
 
		// someone used the login form
		if(!empty($username)) {
			// run phpBB's login function
			define('IN_LOGIN', true);
			$login = $phpbb_auth->login($username, $password, $sticky);
			if($login['status'] != LOGIN_SUCCESS) { return false; }
		}
 
		if(!$user->data['is_registered']) { return false; }
 
		$USERINFO['name'] = $user->data['username'];
		$USERINFO['mail'] = $user->data['user_email'];
		if($this->_openDB()) {
			$USERINFO['grps'] = $this->_getGroups($USERINFO['name']);
		}
 
		$_SERVER['REMOTE_USER'] = $user->data['username'];
		$_SESSION[DOKU_COOKIE]['auth']['user'] = $user->data['username'];
		$_SESSION[DOKU_COOKIE]['auth']['pass'] = $user->data['user_password'];
		$_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO;
 
		return true;
	}
 
 
	function logoff()
	{
		global $user;
		$user->session_kill();
	}
}
?>

inc/init.php を編集

inc/init.php ファイルから次の行を探して下さい。

$_REQUEST = array_merge($_GET,$_POST);

それをコメントアウトするために行頭に//を追加して下さい。

//$_REQUEST = array_merge($_GET,$_POST);

これは、phpBBが$_REQUESTをクッキーで使用するためです。

inc/utf8.php を編集

inc/utf8.phpにはすでにphpBBによって定義された次の関数があります。

  • utf8_strlen
  • utf8_substr
  • utf8_strtolower
  • utf8_strtoupper
  • utf8_ucfirst
  • utf8_strpos

なので、これらの関数の前後に

if(!defined('IN_PHPBB')) { ... }

を追加し、phpBBを使わなくなった時にDokuWikiがこれらの関数を定義するようにしましょう。

例: utf8_strlen

変更前:

function utf8_strlen($string){
  return strlen(utf8_decode($string));
}

変更後:

if(!defined('IN_PHPBB')){
	function utf8_strlen($string){
	  return strlen(utf8_decode($string));
	}
}

inc/cache.php を編集

最後の問題は、DokuWiki と phpBB が同じcacheクラスを持っている事です。そこで、DokuWikiのクラスの名前を変更します。inc/cache.php ファイルの中で次の行を探して下さい。

class cache {

そして、次のように変更して下さい。:

class wiki_cache {

変更前:

function cache($key,$ext) {

変更後:

function wiki_cache($key,$ext) {

変更前:

class cache_parser extends cache {

変更後:

class cache_parser extends wiki_cache {

変更前:

parent::cache($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'],'.'.$mode);

変更後:

parent::wiki_cache($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'],'.'.$mode);

feed.php を編集

cacheクラスの名前を変更した(上記参照)ので、このクラスが呼び出される feed.php でも、RSS/Atom フィードが生成されるように名前を変更しましょう。

変更前:

$cache = new cache($key, '.feed');

変更後:

$cache = new wiki_cache($key, '.feed');

もしこれを変更しないと “XML Parsing Error” が発生します。

inc/common.php を編集

phpBBとDokuWikiの日付フォーマットとタイムゾーンを同期するため、inc/common.php ファイルの dformat() 関数を変更しましょう。(コメントセクションにあるように、この修正を行うと逆にエラーが発生する可能性があります。)

変更前:

function dformat($dt=null,$format=''){
  global $conf;
 
  if(is_null($dt)) $dt = time();
  $dt = (int) $dt;
  if(!$format) $format = $conf['dformat'];
 
  $format = str_replace('%f',datetime_h($dt),$format);
  return strftime($format,$dt);
}

変更後:

function dformat($dt=null){
  global $user;
 
  if(is_null($dt)) $dt = time();
  $dt = (int) $dt;
 
  return $user->format_date($dt);
}

DokuWikiはphpBB3の日付設定を使用します。

変数をセットする

最後にすることは、今までの変更を適用することです。conf/local.protected.php ファイルはDokuWikiが操作しないので最も良い場所です。もしこのファイルがない場合は、新たに作成して下さい。そして、ファイルに次の記述を追加して下さい。

<?php
/*
 * phpBB3
 */
 
define('IN_PHPBB', true);
$phpbb_root_path = 'phpBB3/';
$conf['authtype'] = 'phpbb3';
?>

$phpbb_root_path はDokuWikiのディレクトリから見たphpBBの相対パスです。例えば、DokuWikiを“var/user/dokuwiki“に、phpBBを”var/user/forum/“というように、phpBBをDokuWikiと同じ階層にインストールしたのであれば、$php_root_path../forum/というようにしなければいけません。

I did this, but it wouldn't authenticate me. I tried pasting it in local.php, and it worked just fine. Is there a step missing?

phpBB3の設定

cookieの設定

上で行った変更がうまく動くようにするためには、phpBB3のACP (admin control panel)でのcookieを正しく設定することが重要です。例えば、cookieの設定が間違っていると、まずphpBB3にログインし、あるページをロードするとDokuWikiから強制的にログアウトさせられます。

もし、phpBB3を”www.yourdomain.com/phpBB3/“に、DokuWikiを”www.yourdomain.com/dokuwiki/“にインストールしている場合は、phpBB3のACPで“cookie 設定”の“cookie パス”を”/phpBB3/“と設定してはいけません。正しくは、“cookie パス”には”/“と設定して下さい。 carstenfuchs [at] t [dash] online [dot] de

セキュリティ設定

phpBB3のACPで他にチェックすることは、セキュリティ設定の“リファラ設定”です。もし、この設定が“ホストとスクリプトパス”になっていると、上記の間違ったcookieパスの設定のように、うまく動作しません。このため、“リファラ設定”では“ホストとスクリプトパス”または“なし”を選択して下さい。

クレジット

コメント

  • Integration with Mediamanager, pictures are not shown in the wiki anymore (pathproblem?) I just followed these instructions and I got no problem with Mediamanager, using DokuWiki 2009-02-14 and phpBB3 3.0.4, all works fine :-) and by the way, thanks for this page!
  • it doesn't work well for me. contents of conf/local.protected.php appears on site. like this http://gimp.kr/wiki/ I use phpbb3.0 gold and DokuWiki 2007-06-26b on centos5 and MySQL. what do I miss?
    • Make sure their isn't spaces or characters before <?php in your local.protected.php file.
  • Be careful if you are using this on your local testsite: it is REQUIRED that you are using a password in accessing your database, otherwise the mysql_auth class will throw errors!
  • What did I do wrong here? DokuWiki is located at http://test.iphexx.net/dokuwiki . I did everything as described above…
  • Do these instructions only work for DokuWiki 2007-06-26b? I'm trying, with no success to use it with 2008-05-05. I get an error “Fatal error: Call to undefined function utf8_strtolower() in /hsphere/local/home/eriebuoy/forums.pygmyisland.net/dokuwiki/inc/pageutils.php on line 108” Installation is in /dokuwiki and phpBB3 is in /phpBB3 on same subdomain at forums.pygmyisland.net – anyone give me some hints of what I've done wrong? I did perform all of the instructions above including the edit of the utf8.php file.
  • hi! I've followed all steps and it work but if I go in Administration → Access Control List Management it send me this error
Warning: require_once(../phpBB3/common.php) [function.require-once]: failed to open stream: No such file or directory in C:\www\DokuWiki-2008-05-05\inc\auth\phpbb3.class.php on line 18

I have a forum in: C:\www\phpBB3\ and DokuWiki in C:\www\dokuwiki-2008-05-05\ so I have this config file:

<?php
/*
 * phpBB3
 */
 
define('IN_PHPBB', true);
$phpbb_root_path = '../phpBB3/';
$conf['authtype'] = 'phpbb3';
?>
  • It's because this line in phpbb3.class.php doesn't really work. /lib/exe doesn't get a match on my server, and the depth it must go down is variable.
if(strpos($_SERVER['PHP_SELF'], "/lib/exe/") !== false) { $phpbb_root_path = '../../'.$phpbb_root_path; }
  • You can solve it adding this line before (it could be coded better. I am just too busy at the moment):
if(strpos($_SERVER['PHP_SELF'], "/lib/plugins/") !== false) { $phpbb_root_path = '../../../'.$phpbb_root_path; }
if(strpos($_SERVER['PHP_SELF'], "/lib/exe/") !== false) { $phpbb_root_path = '../../'.$phpbb_root_path; }

Mauro Artizzu 2008/10/17 13:38

  • Hi, I've been using DokuWiki with PunBB before and the bridge worked quite well. Now I installed phpBB3, a new version of DokuWiki and this integration mod. If I click on the wiki link in the forum portal all I get is a blank page, no errors or unwanted display, just a blank page. Even the source view of the page is blank.
  • I just want to say that I'm not using DokuWiki anymore, so I'm not using this mod anymore, too, of course and so I can't help anyone with problems regarding DokuWiki and phpbb3. — Markus -voks- Henn 2008/10/16 10:34
  • Just a few words for integrating authentication with phpBB 3.0.4:
There were only a few errors I run into. All the functions mentioned below utf8.php (utf8_strlen, utf8_substr, utf8_strtolower, utf8_strtoupper, utf8_strpos) have to be excluded from being defined in DokuWiki, not only that one which is declared in this example. Same way to exclude with if(!defined('IN_PHPBB')). The last one I found was the name of the standard user group which has been changed since phpBB2 from “user” to “registered user”. I was updating my existing config from 2 to 3 and any other settings except that ones mentioned above could remain unchanged. gonzo99/27.02.2009
  • lonney@gmail.com 09/04/01 After doing all these mods: Parse error: syntax error, unexpected '}' in /home/../web/wiki/inc/utf8.php on line 248
  • nammyung 2009/10/31: If the paths are not resolving properly, just replace them with absolute path to the phpbb3 install. For example, $php_root_path='/var/www/html/forum/'; If you do this, you can just comment out the two “if(strpos($_SERVER['PHP_SELF']” lines.

Cant you just make DokuWiki PLUG into the MySQL auth part of phpbb3? so what if you have to login twice!@

Worked fine for me (please note the phpbb cookies value and my subdomains) :

  • 2010 Jan 06 - I have two subdomains on a Mandriva server : a restricted access DokuWiki Release 2009-12-25 Lemming at wiki.xxx.org (in /dokuwiki) and phpBB 3.0.6 at forum.xxx.org (in /phpbb). The instructions work perfectly after setting $phpbb_root_path = '../phpbb/' in conf/local.protected.php, and after setting the cookies domain in the phpbb admin panel to '.xxx.org' : I can login in phpBB and use the wiki, I see the phpBB users list in DokuWiki, etc.

Problem:

  • 2010 jan 07:

I have phpBB 3.0.6 and i used the latest 5 versions of DokuWiki. Then i used this tutorial here, did everything 10 times but with no success. The forum is at: http://192.168.69.87:4001/forum2/forum/ The wiki is at : http://192.168.69.87:4001/forum2/wiki/ – Settings in the phpBB-forums for cookies are: Cookie-Domain: http://192.168.69.87:4001/forum2/forum/ – and – Cookie-Path: / – Do we need to edit the “mysql.conf.php” file ? Because i get the error: “User authentication is temporarily unavailable. If this situation persists, please inform your Wiki Admin.” – Thanks for HELP ! FIXME

  • 2010 May 10: RSS/Atom issue fixed. Refer to “Edit feed.php” above in this page to view fix.

Problem:

  • 2010 July 1: I installed this plug in manually and everything works great however I believe I am having a problem with the date because I am getting this error where the date should be displayed:
[phpBB Debug] PHP Notice: in file /includes/session.php on line 2167: strtr() [function.strtr]: The second argument is not an array

When I check that line of code for errors this is what the code is:

return strtr(@gmdate($date_cache[$format]['format_long'], $gmepoch + $zone_offset), $date_cache[$format]['lang']);

Update - 2010 July 6th: I returned the date mod back to the original code and the error is fixed. Update2 - 2010 July 7th: The toolbar does NOT work and it just gives me a link to “Media Files”! I've tried all of the troubleshooting tips offered here and nothing fixes it. Any help?! Update3 - 2010 July7th: Make sure the permissions of the dokuwiki/lib/exe/js.php file are set to 755 otherwise the toolbar will not work!

  • I had some problems getting this integration to work, it would not authenticate. But, I found the problem: If $_SERVER['PHP_AUTH_USER'] is set on your server, it will try to log in with that. If you have that problem, you can either unset it, or remove the corresponding code in inc/auth.php
  • 私は、DokuWikiの最新バージョン(Anteater)でこれを解決する方法を見つけました。要するに、クラスが宣言される前にグローバル変数を宣言します。
  • phpbb3.class.php ファイルの最初にグローバル変数を追加します。
<?php
/**
* phpBB3 authentication backend
 *
 * Uses external Trust mechanism to check against phpBB's
 * user cookie. phpBB's PHPBB_ROOT_PATH must be defined correctly.
 *
 * @author    Markus Henn <brezelman@yahoo.de>
 */
 
define('IN_PHPBB', true);
global $phpbb_root_path;
global $db;
global $cache;
global $phpEx;
global $user;
global $config;
global $conf;
global $dbhost;
global $dbport;
global $dbname;
global $dbuser;
global $dbpasswd;
global $table_prefix;
global $phpbb_auth;
 
$phpEx = substr(strrchr(__FILE__, '.'), 1);
 
if(strpos($_SERVER['PHP_SELF'], "/lib/plugins/") !== false) { $phpbb_root_path = '../../../'.$phpbb_root_path; }
if(strpos($_SERVER['PHP_SELF'], "/lib/exe/") !== false) { $phpbb_root_path = '../../'.$phpbb_root_path; }
 
require_once(DOKU_INC.'inc/auth/mysql.class.php');
require_once($phpbb_root_path.'common.'.$phpEx);
 
//config is loaded in common file, but $dbpasswd is unset there, too, so we have to reload it
require($phpbb_root_path.'config.'.$phpEx);
 
$user->session_begin();
 
//$auth will be used by DokuWiki, so copy phpBB's $auth to another variable
$phpbb_auth = $auth;
$phpbb_auth->acl($user->data);
 
class auth_phpbb3 extends auth_mysql
{
 
この下には、手順の一番上にある phpbb3.class.php のコードが続きます。
  • 今、私はこれがなぜうまく動作するのか分からないので、セキュリティの問題が起こるのを避けるために手順には加えていません。— Eivind 2010/09/12
1)
現在は完全に動作しているようです。下のコメントセクションを参照して下さい。
ja/tips/integrate_with_phpbb3.txt · 最終更新: 2011-01-14 15:43 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