목차
Dokuwiki와 phpBB3통합
특징
- 만약 phpBB에서 로그인이 되어있다면 phpBB의 인증시스템 만을 이용해서, dokuwiki에서는 또 다시 로그인을 하지 않는다.
- dokuwiki의 access control list를 조작하는데에 phpBB의 그룹을 이용한다. 몇몇 기본 그룹들은 이미 구현이 되어있다.
- REGISTERED. 기본 그룹(user그룹으로 치환한다)
- ADMINISTRATORS administrator/super 유저(admin 그룹으로 치환된다.)
- GLOBAL_MODERATORS 관리자들.
없는 기능
- 사용자 등록
- Full name display
- Integration with Mediamanager, pictures are not shown in the wiki anymore (pathproblem?)
설치 과정
download package for DokuWiki 2007-06-26b ←이 것을 사용하거나, 다음 스텝들을 따라해서 이 mod를 설치 할 수 있다.
- inc/auth/phpbb3.class.php 를 만든다.
- inc/init.php 를 수정한다.
- inc/utf8.php 를 수정한다.
- inc/cache.php 를 수정한다.
- 설정 변수를 세팅한다.
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);
inc/utf8.php 수정
inc/utf8.php에는 이미 아래와 같은 몇몇 함수가 있다.
- utf8_strlen
- utf8_substr
- utf8_strtolower
- utf8_strtoupper
- utf8_strpos
그래서 우리는 Dokuwiki에서 이 함수들을 사용하기만 하면 된다. 단 phpBB에 있는 것처럼 하기 위해서 다음 줄을 추가해줘야 한다.
if(!defined('IN_PHPBB')) { ... }
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);
이렇게 바꿔준다.
설정 변수 세팅
마지막으로 사용 가능하게 만들어야 한다. dokuwiki는 conf/local.protected.php를 건들지 않기 때문에, 이 파일은 이러한 일을 하기에 최고의 위치에 있다. 만약 이 파일이 없다면 만들고 다음과 같은 줄을 추가하자.
<?php /* * phpBB3 */ define('IN_PHPBB', true); $phpbb_root_path = 'phpBB3/'; $conf['authtype'] = 'phpbb3'; ?>
$phpbb_root_path는 dokuwiki 디렉토리에서의 phpBB의 위치에 대한 상대경로이다.
phpBB3 쿠키 세팅
위의 순서들을 잘 따라왔다면, phpBB의 ACP에서 쿠키를 세팅해야하는 중요한 과정이 남았다. 예를 들어, 쿠키 세팅이 잘못되면, phpBB3 포럼에서 로그인 하고, dokuwiki페이지로 가면 강제로 로그아웃이 되어버린다.
만약 phpBB3가 www.yourdomain.com/phpBB3/에 설치되어 있고, dokuwiki가 www.yourdomain.com/dokiwiki/에 설치가 되어있다면, phpBB3ACP에 있는 Cookie Settings의 Cookie path를 절대로 /phpBB3/로 설정하면 안된다. 이 예제와 같은 상황에서는 Cookie path를 /로 설정해야한다.