DokuWiki

It's better when it's simple

User Tools

Site Tools


tips:integrate_with_phpbb3

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tips:integrate_with_phpbb3 [2012-10-14 03:52] – [Edit lib/exe/css.php] added Angua to the angua edits this is making it clearer 88.67.116.212tips:integrate_with_phpbb3 [2023-09-20 21:09] (current) – remove old auth backend docs, use plugin:authphpbb3 instead Klap-in
Line 1: Line 1:
-====== phpBB 3 (authentication) integration ====== 
  
-===== Features ===== 
- 
-  * Completely using phpBB's authentication system, you don't have to login in DokuWiki again if you're already logged in in phpBB and vice versa. The same applies to log out of course. 
-  * 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 
- 
-==== Features missing ==== 
- 
-  * User registration 
-  * Full name display (phpBB doesn't have full name information in the user profile by default, username is displayed instead) 
-  * Integration with Mediamanager, pictures are not shown in the wiki anymore (path problem?)((seems to be fully functional now, see the Comments section below)) 
-  * Language support 
- 
-===== Installation instructions ===== 
- 
-//To get this to work with the most Release Candidate version of DokuWiki “Adora Bell 10-09-2912” and PHPBB3 only do the following steps marked with //**=Adora Bell=** 
- 
-//To get this to work with the most recent stable version of DokuWiki “Angua 25-01-2012” and PHPBB3 only do the following steps marked with //**=Angua=** 
- 
-//To get this to work with the outdated version of DokuWiki “Rincewind” and PHPBB3 only do the following steps marked with //**=Rincewind=** 
- 
-To install this mod, you can: 
-  * use this [[http://www.crocko.com/F8D5FF634CE744DB9413C13F7FF7B3D4/AnguaRC1_phpbb3login.rar|download package for DokuWiki 2011-11-10 RC1 Angua]] FIXME or 
-  * follow these steps: 
-    - create ''[[#create_inc_auth_phpbb3classphp|inc/auth/phpbb3.class.php]]'' 
-    - edit ''[[#edit_inc_initphp|inc/init.php]]'' 
-    - edit ''[[#edit_inc_utf8php|inc/utf8.php]]'' 
-    - edit ''[[#edit_inc_cachephp|inc/cache.php]]'' 
-    - edit ''[[#edit_feedphp|feed.php]]'' 
-    - edit ''[[#edit_inc_auth_mysql.classphp|inc/auth/mysql.class.php]]'' **=Adora Belle=** 
-    - [[#set configuration variables]] 
- 
-==== Create inc/auth/phpbb3.class.php ==== 
- 
-**=Angua=** **=Rincewind=** **=Adora Belle=** 
-\\ 
-Create a file in the **inc/auth/** directory with the filename **phpbb3.class.php** and the following content: 
-<file 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); 
-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 
-{ 
- 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(); 
- } 
-} 
-?> 
-</file> 
- 
-==== Edit inc/init.php === 
- 
-**=Angua=** **=Rincewind=** **=Adora Belle=** 
-\\ 
-In the file **inc/init.php** search for the following line: 
-<code php>$_REQUEST = array_merge($_GET,$_POST);</code> 
-Comment it out by adding **%%//%%** in front of the line like this: 
-<code php>//$_REQUEST = array_merge($_GET,$_POST);</code> 
-We have to do this because phpBB uses $_REQUEST for its cookies. 
- 
-==== Edit inc/utf8.php ==== 
- 
-**=Angua=** **=Rincewind=** **=Adora Belle=** 
- 
-There are some functions in the file **inc/utf8.php** already defined by phpBB, these are: 
-  * utf8_strlen 
-  * utf8_substr 
-  * utf8_strtolower 
-  * utf8_strtoupper 
-  * utf8_ucfirst 
-  * utf8_strpos 
-  * utf8_basename **=Adora Belle=** 
- 
-So we only let DokuWiki define these functions if we're not using phpBB by adding an check around these function: <code php>if(!defined('IN_PHPBB')) { ... }</code> 
- 
-=== Example: utf8_strlen === 
- 
-replace: 
-<code php>function utf8_strlen($string){ 
-  return strlen(utf8_decode($string)); 
-}</code> 
-with: 
-<code php>if(!defined('IN_PHPBB')){ 
- function utf8_strlen($string){ 
-   return strlen(utf8_decode($string)); 
- } 
-}</code> 
- 
-==== Edit inc/cache.php ==== 
- 
-**=Angua=** **=Rincewind=** **=Adora Belle=** 
- 
-The last problem we have is that DokuWiki and phpBB both have a cache class. We can just rename this class in DokuWiki. To do so we open the file **inc/cache.php** and search for: 
-<code php>class cache {</code> 
-replace this line with: 
-<code php>class wiki_cache {</code> 
- 
-Search for: 
-<code php>function cache($key,$ext) {</code> 
-and replace it with: 
-<code php>function wiki_cache($key,$ext) {</code> 
- 
-Search for: 
-<code php>class cache_parser extends cache {</code> 
-and replace it with: 
-<code php>class cache_parser extends wiki_cache {</code> 
- 
-Search for: 
-<code php>parent::cache($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'],'.'.$mode);</code> 
-and replace it with: 
-<code php>parent::wiki_cache($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'],'.'.$mode);</code> 
- 
-==== Edit feed.php ====  
- 
-**=Angua=** **=Rincewind=** **=Adora Belle=** 
- 
-Knowing we have just renamed the cache class (see above) and knowing this class is called in feed.php, we also need to rename the calling to make RSS/Atom feeds works. 
-Find: 
-<code php> 
-$cache = new cache($key, '.feed'); 
-</code> 
-and replace with: 
-<code php> 
-$cache = new wiki_cache($key, '.feed'); 
-</code> 
- 
-Otherwise you will have a very nice "XML Parsing Error". 
- 
-==== Edit lib/exe/css.php ====  
- 
-**=Angua=** **=Adora Belle=** **Do __Not__ do for Rincewind** 
- 
-**=Angua=** 
- 
-Knowing we have just renamed the cache class (see above) and knowing this class is called in lib/exe/css.php, we also need to rename the calling to make skin works. 
-Find: 
-<code php> 
-// The generated script depends on some dynamic options 
-    $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tplinc.$mediatype,'.css'); 
-</code> 
-and replace with: 
-<code php> 
-// The generated script depends on some dynamic options 
-    $cache = new wiki_cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tplinc.$mediatype,'.css'); 
-</code> 
- 
-**=Adora Belle=** 
- 
-Find: 
-<code php> 
-// The generated script depends on some dynamic options 
-    $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tplinc.$type,'.css'); 
-</code> 
-and replace with: 
-<code php> 
-// The generated script depends on some dynamic options 
-    $cache = new wiki_cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tplinc.$type,'.css'); 
-</code> 
- 
-==== Edit lib/exe/js.php ====  
- 
-**=Angua=** **=Adora Belle=** **Do __Not__ do for Rincewind** 
- 
-Knowing we have just renamed the cache class (see above) and knowing this class is called in lib/exe/js.php, we also need to rename the calling to make javascript works. 
-Find: 
-<code php> 
- // The generated script depends on some dynamic options 
-    $cache = new cache('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'], 
-                       '.js'); 
-</code> 
-and replace with: 
-<code php> 
- // The generated script depends on some dynamic options 
-    $cache = new wiki_cache('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'], 
-                       '.js'); 
-</code> 
- 
-==== Edit inc/load.php ====  
- 
-**=Angua=** **=Adora Belle=** **Do __Not__ do for Rincewind** 
- 
-Knowing we have just renamed the cache class (see above) and knowing this class is in inc/load.php, we also need to rename the name to make css and javascript works. 
-Find: 
-<code php> 
-        'cache'                 => DOKU_INC.'inc/cache.php', 
-</code> 
-and replace with: 
-<code php> 
-        'wiki_cache'            => DOKU_INC.'inc/cache.php',  
-</code> 
-    
-==== Edit inc/auth/mysql.class.php ====  
- 
-**=Adora Belle=** 
- 
-Due to new code changes if your running php 5.3+ this step will get it working for you. 
- 
-Find: 
-<code php> 
-    function __construct() { 
-</code> 
-and replace with: 
-<code php> 
-    function construct() { 
-</code> 
- 
-==== Set configuration variables ==== 
- 
-**=Angua=** **=Rincewind=** **=Adora Belle=** 
- 
-The last thing we have to do is: enable it! The file **conf/local.protected.php** is the best location to do so, because DokuWiki doesn't touch this file. If the file doesn't exist, you have to create it. Add these lines: 
-<code php local.protected.php><?php 
-/* 
- * phpBB3 
- */ 
-  
-define('IN_PHPBB', true); 
-$phpbb_root_path = 'phpBB3/'; 
-$conf['authtype'] = 'phpbb3'; 
-?></code> 
-$phpbb_root_path has to be the relative path to phpBB from the DokuWiki directory, e.g. if phpBB is installed on the same level as DokuWiki, e.g. DokuWiki in **var/user/dokuwiki** and phpBB in **var/user/forum/**, **$php_root_path** has to be set to **../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 Settings ===== 
- 
-==== Cookie Settings ==== 
- 
-**=Angua=** **=Rincewind=** **=Adora Belle=** 
- 
-In order for the above integration to work well, it is important that the cookie settings in the phpBB3 ACP (admin control panel) are set right. For example, with wrong cookie settings, first logging in at your phpBB3 forum, then browsing your DokuWiki pages will forcibly log you out when you next load a page of your forum. 
- 
-If your phpBB3 forum is installed at **%%www.yourdomain.com/phpBB3/%%** and your DokuWiki is installed at **%%www.yourdomain.com/dokuwiki/%%**, then you should //not// set the "Cookie path" on the "Cookie Settings" page in the phpBB3 ACP to **/phpBB3/** -- that will cause the very behaviour mentioned in the example above. 
-Instead, set the "Cookie path" to **/**, and it should work as expected. 
-<carstenfuchs@t-online.de> 
- 
-==== Security Settings ==== 
- 
-An other thing to check in the phpbb3 ACP is  "Validate referrer" in the Security settings. If this setting is set to "Validate path too" the integration will not work and you will experience exactly the same issue that is described above in case of wrong cookie path. For this reason please set "Validate referrer" to "Validate host" or "none" but never to "Validate path". 
-Be care... 
- 
-===== Credits ===== 
- 
-  * Thanks to [[http://www.phpbb.com/community/memberlist.php?mode=viewprofile&u=199689|Nathan Brittles]] who gave me the basic ideas in a [[http://www.phpbb.com/community/viewtopic.php?f=72&t=590246|thread]] in the official phpBB (phpBB3) forum. 
- 
-===== Comments / Problems ===== 
- 
-  * 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. 
- 
-  * For German phpbb3: Dont use ÄÖÜ for Usernames, it will not authenticate! It is possible to restrict those usernames in phpbb3 registration settings. Use ASCII Usernames instead. 
- 
-  * Additional info provided for Adora Belle (fixed now for me with php 5.3) Regards, djSupport  
tips/integrate_with_phpbb3.1350179578.txt.gz · Last modified: 2012-10-14 03:52 by 88.67.116.212

Except where otherwise noted, content on this wiki is licensed under the following license: 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