File phpbbsession.php in PhpBBSessionManager
<?php if (!defined('PmWiki')) exit(); /* Author: Christopher Sexton < sexton@fuzzymonk.com > http://www.fuzzymonk.com Title: External phpBB session management for PmWiki Description: This is a PmWiki plug-in that will handle user authentication and session management though the cookies and database tables from a phpBB installation. This will only work if you have phpBB running on MySQL (or modify the database calls and configuration for your database). /*************************************************************************** * * This script is based on userauth.php which is Copyright 2004, by James * McDuffie (ttq3sxl02@sneakemail.com) * ***************************************************************************/ /*************************************************************************** * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ /* Aurthor Notes: I originally wanted to wrote a replacement for HtPasswd.php in James McDuffie's "Username Authentification" since he made his plug-in nice an object orented, however the extent of the changes required to userauth.php lead me to scrap it and simply rewrite the entire thing custom for my needs. If you want more details on how to further modify this for more complex functionality I recommend looking at his plug-in’s documentation. I set up the user authentication to do two simple tasks. -Only members of the admin group (defined by $phpbb_adminusergroup) can perform attr and admin level functions. Read and Edit are open to everyone. -Put the username in the Author field. Make sure to perform all the needed changes within the config block in both this file and in phpbbsession.php. The last step is to add this to your config.php: require_once("phpbbsession/phpbbsession4pmwiki.php"); Assuming 'phpbbsession' is a directory in your pmwiki install directory */ /*Config Block */ require_once("phpbbsession.php"); //The relitive path to the wiki from phpBB $phpbb_relpathtowiki = "../wiki"; //url pointing to the login page in phpBB $phpbb_pathtologin = "http://www.fuzzymonk.com/forum/login.php"; //Name of the group you want to have admin rights in the wiki $phpbb_adminusergroup = "Powerful"; /* End Config Block */ // // Call the external phpBB session manager // $phpbb_userdata = phpbb_session_pagestart($user_ip, $phpbb_page_id); // // phpBBSession4PmWiki Functions // function GetUserLoginForm($no_title) { global $Author, $WikiTitle, $phpbb_relpathtowiki, $phpbb_pathtologin; if( $Author == "" ) { //if (!$no_title) { // $login_form .= "<h1>Login to $WikiTitle</h1>"; //} $login_form .= "<a href=\"$phpbb_pathtologin?redirect=$phpbb_relpathtowiki/\">Login</a>"; } else { $login_form = "Logged in as: " . $Author . "<br> <a href=\"$phpbb_pathtologin?logout=true&redirect=$phpbb_relpathtowiki/\">Logout</a>"; } return $login_form; } function UserAuth($pagename,$level,$authprompt=true) { global $phpbb_userdata, $Author; global $phpbb_dbname , $phpbb_db, $phpbb_adminusergroup; mysql_select_db($phpbb_dbname,$phpbb_db); $page = ReadPage($pagename); if (!$page) { return false; } //Anyone can read and edit a page if ($level == "read" || $level == "edit"){ return $page; } else { // // Query the DB to see if the user is in an admin group // $sql = "SELECT pdpbb_groups.group_id FROM pdpbb_groups, pdpbb_user_group, ". USERS_TABLE . " WHERE pdpbb_groups.group_name = \"$phpbb_adminusergroup\" AND pdpbb_user_group.group_id = pdpbb_groups.group_id AND pdpbb_user_group.user_id = ". USERS_TABLE . ".user_id AND pdpbb_user_group.user_pending = 0 AND ". USERS_TABLE . ".username = \"$Author\""; if ( !($result = mysql_query($sql)) ) { die('<h1>Could not obtain user group information<br>SQL:<br>' . $sql); } if (mysql_num_rows($result) > 0){ return $page; } PrintEmbeddedPage( $pagename, GetWikiPasswordForm($pagename) ); } //return $page; exit; } function PrintStandalonePage($prompt) { global $HTMLBodyFmt,$SessionAuthFmt, $AuthPageTitle; $action = $GLOBALS['action']; StartHTML($pagename, $AuthPageTitle); PrintFmt($pagename, $prompt); EndHTML(); } function PrintEmbeddedPage($pagename, $prompt) { global $PageStartFmt, $PageEndFmt, $AuthPageTitle, $TimeFmt, $Now; $GLOBALS['LastModified'] = strftime($TimeFmt, $Now); $GLOBALS['LastModifiedBy'] = 'NoOne'; $GLOBALS['LastModifiedHost'] = 'NoHost'; $GLOBALS['HTMLTitle'] = $AuthPageTitle; $GLOBALS['GCount'] = 0; $AuthEmbeddedFmt = array( &$PageStartFmt, $prompt, &$PageEndFmt); $AuthEmbeddedFmt = FmtPageName($AuthEmbeddedFmt, $pagename); PrintFmt($pagename, $AuthEmbeddedFmt); } function GetWikiPasswordForm($pagename) { global $phpbb_relpathtowiki, ; $password_form .= "<h3>Login required for for $pagename</h3> <a href=\"$phpbb_pathtologin?redirect=$phpbb_relpathtowiki/index.php?pagename=$pagename\">Login</a> "; return $password_form; } //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// // // Override PmWiki variables // if ( $phpbb_userdata[user_id] == ANONYMOUS ) { $Author = "";} else {$Author = $phpbb_userdata['username'];} SDV( $InlineReplacements['/\\[\\[loginform\\]\\]/e'], 'GetUserLoginForm(true);' ); $AuthFunction = "UserAuth"; ?>
