Integrate PunBB 1.2 with DokuWiki

From PunBB Resource Wiki

Jump to: navigation, search

This backend allows you to use your PunBB account for logging in to DokuWiki.

Instructions for intregrating DokuWiki-2012-10-13 "Adora Belle" and DokuWiki-2013-05-10a "Weatherwax" are provided below.

Contents

Instructions for integrating DokuWiki-2012-10-13 "Adora Belle"

Step 1: Create the class

Create a new file punbb.class.php in the folder <dokuwiki_folder>/inc/auth/. Paste the following code into the file:

<?php
/**
 * PunBB auth backend
 *
 * Uses external Trust mechanism to check against PunBB's
 * user cookie. PunBB's PUN_ROOT must be defined correctly.
 *
 * @author    Andreas Gohr <andi@splitbrain.org>
 */
 
require_once DOKU_INC.'inc/auth/mysql.class.php';
 
#dbg($GLOBALS);
#dbg($pun_user);

class auth_punbb extends auth_mysql {
 
  /**
   * Constructor.
   *
   * Sets additional capabilities and config strings
   */
  function auth_punbb(){
    global $conf;
    $this->cando['external'] = true;
 
    $conf['passcrypt'] = 'sha1';
 
    // get global vars from PunBB config
    global $db_host;
    global $db_name;
    global $db_username;
    global $db_password;
    global $db_prefix;
 
    // now set up the mysql config strings
    $conf['auth']['mysql']['server']   = $db_host;
    $conf['auth']['mysql']['user']     = $db_username;
    $conf['auth']['mysql']['password'] = $db_password;
    $conf['auth']['mysql']['database'] = $db_name;
 
    $conf['auth']['mysql']['checkPass']   = "SELECT u.password AS pass
                                               FROM ${db_prefix}users AS u, ${db_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 ${db_prefix}users AS u, ${db_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 ${db_prefix}users AS u, ${db_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 ${db_prefix}users AS u, ${db_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 ${db_prefix}users
                                                    (username, password, email, realname)
                                             VALUES ('%{user}', '%{pass}', '%{email}', '%{name}')";
    $conf['auth']['mysql']['addGroup']    = "INSERT INTO ${db_prefix}groups (g_title) VALUES ('%{group}')";
    $conf['auth']['mysql']['addUserGroup']= "UPDATE ${db_prefix}users
                                                SET group_id=%{gid}
                                              WHERE id='%{uid}'";
    $conf['auth']['mysql']['delGroup']    = "DELETE FROM ${db_prefix}groups WHERE g_id='%{gid}'";
    $conf['auth']['mysql']['getUserID']   = "SELECT id FROM ${db_prefix}users WHERE username='%{user}'";
    $conf['auth']['mysql']['updateUser']  = "UPDATE ${db_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 ${db_prefix}users SET g_id=4 WHERE id=%{uid}";
    $conf['auth']['mysql']['getGroupID']  = "SELECT g_id AS id FROM ${db_prefix}groups WHERE g_title='%{group}'";
 
    $conf['auth']['mysql']['TablesToLock']= array("${db_prefix}users", "${db_prefix}users AS u",
                                                  "${db_prefix}groups", "${db_prefix}groups AS g");
 
    $conf['auth']['mysql']['debug'] = 1;
    // call mysql constructor
    parent::__construct();
  }
 
  /**
   * 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;
    global $cookie_name;
    $sticky ? $sticky = true : $sticky = false; //sanity check
 
    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']);
      if ($pun_user['g_id'] < PUN_GUEST)
        $USERINFO['grps'][] = 'admin';
      else
	$USERINFO['grps'][] = 'user';
 
      $_SERVER['REMOTE_USER'] = $pun_user['username'];
      $_SESSION[DOKU_COOKIE]['auth']['user'] = $pun_user['username'];
      $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO;
      return true;
    }
 
    // to be sure
    auth_logoff();
 
    $USERINFO['grps'] = array();
    return false;
  }
}
//Setup VIM: ex: et ts=2 enc=utf-8 :

Step 2: Call the class

Then create a file local.protected.php in the folder <dokuwiki_folder>/conf/, and paste the following code:

<?php
define('PUN_ROOT', '../');
include PUN_ROOT.'include/common.php';
 
$conf['useacl'] = 1;
$conf['superuser'] = '@admin,@Administrator';
$conf['defaultgroup'] = 'Member';
$conf['authtype'] = 'punbb';
//$conf['disableactions'] = 'register,resendpwd,login,profile';
$conf['disableactions'] = 'register,resendpwd,profile,logout,login';
 
// end auto-generated content

Indicating the relative path to access your forum at this line:

define('PUN_ROOT', '../');

In this example:

Instructions for integrating DokuWiki-2013-05-10a "Weatherwax"

DokuWiki-2013-05-10a "Weatherwax" requires authentication to be done with a proper authentication plugin. The following are instructions for creating such a plugin.

Step 1: Create the plugin

In your DokuWiki installation, create the folder <dokuwiki_folder>/lib/plugins/authpunbb/ and create the two files auth.php and plugin.info.txt in it.

Copy and paste the following into the file auth.php:

<?php
// Must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
 
 
/**
* PunBB 1.2 auth backend
*
* Check against PunBB's user cookie.
* Note that PUN_ROOT must be defined correctly.
*
* @author Koos <pampoen10@yahoo.com>
* @author Franz Liedke <franz@fluxbb.org>
* @author Andreas Gohr <andi@splitbrain.org>
*/
class auth_plugin_authpunbb extends DokuWiki_Auth_Plugin
{
 
	/**
	* Constructor.
	*
	* Sets additional capabilities and config strings.
	*/
	function __construct()
	{
		parent::__construct();
 
		$this->cando['addUser'] = false;
		$this->cando['delUser'] = false;
		$this->cando['modLogin'] = false;
		$this->cando['modPass'] = false;
		$this->cando['modName'] = false;
		$this->cando['modMail'] = false;
		$this->cando['modGroups'] = false;
		$this->cando['getUsers'] = false;
		$this->cando['getUserCount'] = false;
		$this->cando['getGroups'] = false;
		$this->cando['external'] = true;
		$this->cando['logout'] = false;
 
		// The auth system was successfully initialized.
		$this->success = true;
	}
 
	/**
	* Do all authentication against the external provider.
	*
	* @param string $user
	* @param string $pass
	* @param bool $sticky
	* @return bool
	*/
	function trustExternal($user, $pass, $sticky = false)
	{
		global $USERINFO;
		global $conf;
		global $lang;
		global $pun_user;
		global $pun_config;
		global $cookie_name;
 
		if (isset($pun_user) && !$pun_user['is_guest'] && ($pun_user['g_id'] < PUN_GUEST || $pun_user['num_posts'] >= 10))
		{
			// 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']);
 
			if ($pun_user['g_id'] == PUN_ADMIN)
				$USERINFO['grps'][] = 'admin';
			else
				$USERINFO['grps'][] = 'user';
 
			$_SERVER['REMOTE_USER'] = $pun_user['username'];
			$_SESSION[DOKU_COOKIE]['auth']['user'] = $pun_user['username'];
			$_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO;
			return true;
		}
 
		// Make sure we're really logged off.
		auth_logoff();
 
		$USERINFO['grps'] = array();
		return false;
	}
 
	/**
	* Return case sensitivity of the backend
	*
	* @return bool
	*/
	function isCaseSensitive()
	{
		return false;
	}
}

Copy and paste the following into the file plugin.info.txt:

base authpunbb
author Koos
email pampoen10@yahoo.com
date 2013-08-22
name PunBB auth plugin
desc Provides authentication using a PunBB 1.2 forum
url http://www.punres.net

Step 2: Call the plugin

Then create a file local.protected.php in the folder <dokuwiki_folder>/conf/, and paste the following code:

<?php
define('PUN_ROOT', '../');
include PUN_ROOT.'include/common.php';
 
$conf['useacl'] = 1;
$conf['superuser'] = '@admin,@Administrator';
$conf['defaultgroup'] = 'Member';
$conf['authtype'] = 'authpunbb';
//$conf['disableactions'] = 'register,resendpwd,login,profile';
$conf['disableactions'] = 'register,resendpwd,profile,logout,login';
 
// end auto-generated content

Indicating the relative path to access your forum at this line:

define('PUN_ROOT', '../');

In this example:

Notes

Note 1: Check ACLs (Access Control Lists)

If you only want logged in users to be able to edit pages (i.e. want a closed wiki), make sure the file acl.auth.php in the folder <dokuwiki_folder>/conf/ looks like this:

# acl.auth.php
# <?php exit()?>
# Don't modify the lines above
#
# Access Control Lists
#
# Auto-generated by install script
# Date: Wed, 21 Aug 2013 16:28:44 +0000
*               @ALL          1
*               @user         8

Where "1" means that the group has Read permission only and "8" means the group has Read / Edit / Create / Upload permissions (but not Delete permission).

Note 2: Login

You should automatically be connected in DokuWiki after logging in to your forum, with the following permissions:

Note 3: Disabling update messages

To disable/suppress DokuWiku update messages (which are displayed to administrators), open the file local.php in the folder <dokuwiki_folder>/conf/, and add the following line:

$conf['updatecheck'] = 0;

Note 4: Select template

If the CSS style sheet is not loading after installing DokuWiki, log in as admin and go to Admin->Configuration Manager and under "template" select "default" and then click "Save".

References

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox