The following authentication class backend makes DokuWiki automatically use Vanilla’s sessions for authentication. Logging in and out, and all user and group management is handled by Vanilla.
Works for me, hope it works for you too... :) Enjoy!
/* Mandatory */ define('NOSESSION', true); $conf['authtype'] = 'vanilla'; /* Optional */ define('VANILLA_ROOT', DOKU_ROOT . '../forum'); /* This is the default */ $conf['acl'] = 1; /* You probably have this set already */ $conf['disableactions'] = 'login,logout,profile,register,resendpwd'; /* Now handled by Vanilla */ $conf['passcrypt'] = 'md5'; /* Not really necessary, set automatically by the authentication backend */
<?php /** * Vanilla auth backend * * Uses external trust mechanism to check against Vanilla's * user cookie. Vanilla's VANILLA_ROOT must be defined correctly. * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Piotr Szczepanski <piotr@szczepanski.name> * * Based on work by: * * Andreas Gohr <andi@splitbrain.org> (PunBB backend) * * Brent Shultz <bshultz@gmail.com> (http://lussumo.com/community/discussion/1158/) * * WARNING: Remember to define NOSESSION in conf/dokuwiki.php or this backend will not work. * * More information: * * DokuWiki: http://wiki/splitbrain.org/wiki:dokuwiki * * Vanilla: http://getvanilla.com/ */ if (!defined('VANILLA_ROOT')) define('VANILLA_ROOT', DOKU_INC . "../forum/"); if (get_magic_quotes_gpc()) { nice_die("Sorry the Vanilla 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."); } // Include Vanilla configuration arrays and People framework require_once VANILLA_ROOT . "appg/settings.php"; require_once VANILLA_ROOT . "appg/init_people.php"; // Include parent class (MySQL) require_once DOKU_INC . "inc/auth/mysql.class.php"; // This class is based on the MySQL backend class auth_vanilla extends auth_mysql { // Constructor, initialization function auth_vanilla() { global $conf; // Include Vanilla configuration array global $Configuration, $DatabaseColumns, $DatabaseTables; // Set backend capabilities $this->cando['external'] = true; /* Also: getGroups, getUsers, but these are set by parent class by checking, which functions are available. */ // This is how Vanilla stores passwords $conf['passcrypt'] = "md5"; /* The first user (admin's) password may be stored in plain text if you used Vanilla's default schema file to create the database. If so, you will need to convert the password to MD5 hash manually. */ // Database connection parameters, only set here if not set in DokuWiki config // MySQL character set if (empty($conf['auth']['mysql']['charset'])) if (!empty($Configuration['DATABASE_CHARACTER_ENCODING'])) $conf['auth']['mysql']['charset'] = $Configuration['DATABASE_CHARACTER_ENCODING']; /* Vanilla typically uses "utf8", but it could have been modified */ // MySQL server host if (empty($conf['auth']['mysql']['server'])) $conf['auth']['mysql']['server'] = $Configuration['DATABASE_HOST']; // MySQL user name if (empty($conf['auth']['mysql']['user'])) $conf['auth']['mysql']['user'] = $Configuration['DATABASE_USER']; // MySQL password if (empty($conf['auth']['mysql']['password'])) $conf['auth']['mysql']['password'] = $Configuration['DATABASE_PASSWORD']; // MySQL database name if (empty($conf['auth']['mysql']['database'])) $conf['auth']['mysql']['database'] = $Configuration['DATABASE_NAME']; // Set MySQL queries for Vanilla // Shortcuts for group table (default: LUM_Role) $g = $Configuration['DATABASE_TABLE_PREFIX'] . $DatabaseTables['Role']; $g_i = $DatabaseColumns['Role']['RoleID']; $g_n = $DatabaseColumns['Role']['Name']; // Shortcuts for user table (default: LUM_User) $u = $DatabaseTables['User']; /* User table is not prefixed in Vanilla */ $u_i = $DatabaseColumns['User']['UserID']; $u_e = $DatabaseColumns['User']['Email']; $u_f = $DatabaseColumns['User']['FirstName']; $u_g = $DatabaseColumns['User']['RoleID']; $u_l = $DatabaseColumns['User']['LastName']; $u_n = $DatabaseColumns['User']['Name']; $u_p = $DatabaseColumns['User']['Password']; // Password check $conf['auth']['mysql']['checkPass'] = "SELECT u." . $u_p. " AS pass FROM " . $u . " AS u, " . $g . " AS g WHERE u." . $u_g . " = g." . $g_i . " AND u." . $u_n . " = '%{user}'"; // Retrieve group ID for a given group name $conf['auth']['mysql']['getGroupID'] = "SELECT g." . $g_i . " AS id FROM " . $g . " AS g WHERE " . $g_n . " = '%{group}'"; // Retrieve group list $conf['auth']['mysql']['getGroups'] = "SELECT g." . $g_n . " AS \"group\" FROM " . $u . " AS u, " . $g . " AS g WHERE u." . $u_g . " = g." . $g_i . " AND u." . $u_n . " = '%{user}'"; /* "group" is a reserved word and must be escaped. */ // Retrieve user ID for a given login name $conf['auth']['mysql']['getUserID'] = "SELECT u." . $u_i . " FROM " . $u . " AS u WHERE u." . $u_n . " = '%{user}'"; // Retrieve user information $conf['auth']['mysql']['getUserInfo'] = "SELECT u." . $u_p . " AS pass, CONCAT(u." . $u_f . ", ' ', u." . $u_l . ") AS name, u." . $u_e . " AS mail, u." . $u_i . " AS id, g." . $g_n . " AS \"group\" FROM " . $u . " AS u, " . $g . " AS g WHERE u." . $u_g . " = g." . $g_i . " AND u." . $u_n . " = '%{user}'"; /* "group" is a reserved word and must be escaped. */ // Retrieve user list $conf['auth']['mysql']['getUsers'] = "SELECT DISTINCT u." . $u_n . " AS user FROM " . $u . " AS u, " . $g . " AS g WHERE u." . $u_g . " = g." . $g_i; // Partial queries (filters) // Filter by user login name $conf['auth']['mysql']['FilterLogin'] = "u." . $u_n . " LIKE '%{user}'"; // Filter by user real name $conf['auth']['mysql']['FilterName'] = "CONCAT(u." . $u_f . ", ' ', u." . $u_l . ") LIKE '%{name}'"; // Filter by user e-mail address $conf['auth']['mysql']['FilterEmail'] = "u." . $u_e . " LIKE '%{email}'"; // Filter by user group $conf['auth']['mysql']['FilterGroup'] = "g." . $g_n . " LIKE '%{group}'"; // Sort by user login name $conf['auth']['mysql']['SortOrder'] = "ORDER BY u." . $u_n; // Table locks $conf['auth']['mysql']['TablesToLock']= array( $u, $u . " AS u", $g, $g . " AS g", ); /* Table locks should also include variants with aliases. */ /* Adding, modifying and deleting users could be added here but you are probably better off leaving it to Vanilla. */ // Debugging $conf['auth']['mysql']['debug'] = 0; // Call parent class constructor $this->auth_mysql(); // Set session encoding to UTF8 $this->_openDB(); $this->_modifyDB("SET NAMES \"utf8\""); // Report initialization success $this->success = true; } // Establish external trust function trustExternal($user, $pass, $sticky = false) { // DokuWiki globals global $conf, $lang, $USERINFO; // Vanilla globals global $Configuration, $Context; // Login information is processed by Vanilla's People framework // We only take action based on the outcome if ($Context->Session->UserID > 0) { $this->_openDB(); if($userInfoArr = $this->_getUserInfo($Context->Session->User->Name)) { $USERINFO['pass'] = $userInfoArr['pass']; $USERINFO['name'] = $userInfoArr['name']; $USERINFO['mail'] = $userInfoArr['mail']; $USERINFO['grps'][] = $userInfoArr['group']; $_SERVER['REMOTE_USER'] = $userInfoArr['name']; $_SESSION[DOKU_COOKIE]['auth']['user'] = $userInfoArr['name']; $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO; } return true; } auth_logoff(); return false; } } /* class auth_vanilla */
At you own risk, of course. This will work with an installed MultiRoles Addon (Version: 2b) and the Dokuwiki (Version: RC2 of April 11th, 2008). With some slight changes it should also work for a normal vanilla. Focus on the UNION-SQL-Statments. The changes have to be done there.
do not forget to check conf/local.php. Dokuwiki saves changes you make in the admin-menu in that file and thus might overwrite some changes you made to conf/dokuwiki.php.
<?php /** * Vanilla auth backend * * Uses external trust mechanism to check against Vanilla's * user cookie. Vanilla's VANILLA_ROOT must be defined correctly. * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Vincent Kahl * * Based on work by: * * Andreas Gohr <andi@splitbrain.org> (PunBB backend) * * Brent Shultz <bshultz@gmail.com> (http://lussumo.com/community/discussion/1158/) * * Piotr Szczepanski <piotr@szczepanski.name> * * WARNING: Remember to define NOSESSION in conf/dokuwiki.php or this backend will not work. * * More information: * * DokuWiki: http://wiki/splitbrain.org/wiki:dokuwiki * * Vanilla: http://getvanilla.com/ */ if (!defined('VANILLA_ROOT')) define('VANILLA_ROOT', DOKU_INC . "../"); if (get_magic_quotes_gpc()) { nice_die("Sorry the Vanilla 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."); } // Include Vanilla configuration arrays and People framework require_once VANILLA_ROOT . "appg/settings.php"; require_once VANILLA_ROOT . "appg/init_people.php"; // Include parent class (MySQL) require_once DOKU_INC . "inc/auth/mysql.class.php"; // This class is based on the MySQL backend class auth_vanilla extends auth_mysql { // Constructor, initialization function auth_vanilla() { global $conf; // Include Vanilla configuration array global $Configuration, $DatabaseColumns, $DatabaseTables; // Set backend capabilities $this->cando['external'] = true; /* Also: getGroups, getUsers, but these are set by parent class by checking, which functions are available. */ // This is how Vanilla stores passwords $conf['passcrypt'] = "md5"; /* The first user (admin's) password may be stored in plain text if you used Vanilla's default schema file to create the database. If so, you will need to convert the password to MD5 hash manually. */ // Database connection parameters, only set here if not set in DokuWiki config // MySQL character set if (empty($conf['auth']['mysql']['charset'])) if (!empty($Configuration['DATABASE_CHARACTER_ENCODING'])) $conf['auth']['mysql']['charset'] = $Configuration['DATABASE_CHARACTER_ENCODING']; /* Vanilla typically uses "utf8", but it could have been modified */ // MySQL server host if (empty($conf['auth']['mysql']['server'])) $conf['auth']['mysql']['server'] = $Configuration['DATABASE_HOST']; // MySQL user name if (empty($conf['auth']['mysql']['user'])) $conf['auth']['mysql']['user'] = $Configuration['DATABASE_USER']; // MySQL password if (empty($conf['auth']['mysql']['password'])) $conf['auth']['mysql']['password'] = $Configuration['DATABASE_PASSWORD']; // MySQL database name if (empty($conf['auth']['mysql']['database'])) $conf['auth']['mysql']['database'] = $Configuration['DATABASE_NAME']; // Set MySQL queries for Vanilla // Shortcuts for group table (default: LUM_Role) $g = $Configuration['DATABASE_TABLE_PREFIX'] . $DatabaseTables['Role']; $g_i = $DatabaseColumns['Role']['RoleID']; $g_n = $DatabaseColumns['Role']['Name']; // Shortcuts for multiroles plugin groups (default: LUM_UserRole) $mr = $Configuration['DATABASE_TABLE_PREFIX'] . $DatabaseTables['UserRole']; $mr_g = $DatabaseColumns['UserRole']['RoleID']; $mr_u = $DatabaseColumns['UserRole']['UserID']; $mr_a = $DatabaseColumns['UserRole']['Activated']; // Shortcuts for user table (default: LUM_User) $u = $DatabaseTables['User']; /* User table is not prefixed in Vanilla */ $u_i = $DatabaseColumns['User']['UserID']; $u_e = $DatabaseColumns['User']['Email']; $u_f = $DatabaseColumns['User']['FirstName']; $u_g = $DatabaseColumns['User']['RoleID']; $u_l = $DatabaseColumns['User']['LastName']; $u_n = $DatabaseColumns['User']['Name']; $u_p = $DatabaseColumns['User']['Password']; // Password check $conf['auth']['mysql']['checkPass'] = "SELECT u." . $u_p. " AS pass FROM " . $u . " AS u WHERE AND u." . $u_n . " = '%{user}'"; // Retrieve group ID for a given group name $conf['auth']['mysql']['getGroupID'] = "SELECT g." . $g_i . " AS id FROM " . $g . " AS g WHERE " . $g_n . " = '%{group}'"; // Retrieve group list $conf['auth']['mysql']['getGroups'] = "SELECT g." . $g_n . " AS \"group\" FROM " . $u . " AS u, " . $g . " AS g WHERE u." . $u_g . " = g." . $g_i . " AND u." . $u_n . " = '%{user}' UNION SELECT g." . $g_n . " AS \"group\" FROM " . $u . " AS u, " . $g . " AS g, " . $mr . " AS mr WHERE u." . $u_i . " = mr." . $mr_u . " AND g." . $g_i . " = mr." . $mr_g . " AND u." . $u_n . " = '%{user}'"; /* "group" is a reserved word and must be escaped. */ // Retrieve user ID for a given login name $conf['auth']['mysql']['getUserID'] = "SELECT u." . $u_i . " FROM " . $u . " AS u WHERE u." . $u_n . " = '%{user}'"; // Retrieve user information $conf['auth']['mysql']['getUserInfo'] = "SELECT u." . $u_p . " AS pass, CONCAT(u." . $u_f . ", ' ', u." . $u_l . ") AS name, u." . $u_e . " AS mail, u." . $u_i . " AS id FROM " . $u . " AS u WHERE u." . $u_n . " = '%{user}'"; /* "group" is a reserved word and must be escaped. */ // Retrieve user list /*$conf['auth']['mysql']['getUsers'] = "SELECT DISTINCT u." . $u_n . " AS user FROM " . $u . " AS u, " . $g . " AS g WHERE u." . $u_g . " = g." . $g_i;*/ /*$conf['auth']['mysql']['getUsers'] = "SELECT DISTINCT u." . $u_n . " AS user FROM " . $u . " AS u";*/ $conf['auth']['mysql']['getUsers'] = "SELECT DISTINCT u." . $u_n . " AS user FROM " . $u . " AS u, " . $g . " AS g WHERE u." . $u_g . " = g." . $g_i . " UNION SELECT DISTINCT u." . $u_n . " AS user FROM " . $u . " AS u, " . $mr . " AS mr WHERE u." . $u_i . " = mr." . $mr_u . " AND g." . $g_i . " = mr." . $mr_g; // Partial queries (filters) // Filter by user login name $conf['auth']['mysql']['FilterLogin'] = "u." . $u_n . " LIKE '%{user}'"; // Filter by user real name $conf['auth']['mysql']['FilterName'] = "CONCAT(u." . $u_f . ", ' ', u." . $u_l . ") LIKE '%{name}'"; // Filter by user e-mail address $conf['auth']['mysql']['FilterEmail'] = "u." . $u_e . " LIKE '%{email}'"; // Filter by user group $conf['auth']['mysql']['FilterGroup'] = "g." . $g_n . " LIKE '%{group}'"; // Sort by user login name $conf['auth']['mysql']['SortOrder'] = "ORDER BY u." . $u_n; // Table locks $conf['auth']['mysql']['TablesToLock']= array( $u, $u . " AS u", $g, $g . " AS g", ); /* Table locks should also include variants with aliases. */ /* Adding, modifying and deleting users could be added here but you are probably better off leaving it to Vanilla. */ // Debugging $conf['auth']['mysql']['debug'] = 0; // Call parent class constructor $this->auth_mysql(); // Set session encoding to UTF8 $this->_openDB(); $this->_modifyDB("SET NAMES \"utf8\""); // Report initialization success $this->success = true; } // Establish external trust function trustExternal($user, $pass, $sticky = false) { // DokuWiki globals global $conf, $lang, $USERINFO; // Vanilla globals global $Configuration, $Context; // Login information is processed by Vanilla's People framework // We only take action based on the outcome if ($Context->Session->UserID > 0) { $this->_openDB(); if($userInfoArr = $this->_getUserInfo($Context->Session->User->Name)) { $USERINFO['pass'] = $userInfoArr['pass']; $USERINFO['name'] = $userInfoArr['name']; $USERINFO['mail'] = $userInfoArr['mail']; $USERINFO['grps'] = $userInfoArr['grps']; $_SERVER['REMOTE_USER'] = $userInfoArr['name']; $_SESSION[DOKU_COOKIE]['auth']['user'] = $userInfoArr['name']; $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO; } return true; } auth_logoff(); return false; } } /* class auth_vanilla */