Commit a4748c85 authored by jacmoe2's avatar jacmoe2

[NEW] PhpBB authentication method - using a phpBB database for user validation (see rev. 23847)

Changed from mysql_connect to using adodb. User interface cleanup remains. Still hardcoded for mysql.
parent 7e2adf8f
......@@ -247,5 +247,3 @@ class PasswordHash {
return $hash == $stored_hash;
}
}
?>
<?php
// Tikiwiki authentication backend for phpBB3 with mysql4
// By Jacob Moen 10 Dec 2009
// Tikiwiki authentication backend for phpBB3 with adodb
// By Jacob 'jacmoe2' Moen 10 Dec 2009
// Based on:
// Mediawiki authentication plugin for phpBB3 with mysql4
// By Steve Streeting 26 Dec 2008
require_once ("lib/auth/PasswordHash.php");
require_once('lib/adodb/adodb.inc.php');
require_once ('lib/auth/PasswordHash.php');
// some definitions for helping with authentication
// Er, what about definition clashes ?
......@@ -20,6 +21,8 @@ define("SERVER_ERROR", -1);
class TikiPhpBBLib {
var $db;
function check($user, $pass) {
// no need to progress further if the user doesn't even exist
......@@ -44,15 +47,12 @@ class TikiPhpBBLib {
$dbuser = $prefs['auth_phpbb_dbuser'];
$dbpasswd = $prefs['auth_phpbb_dbpasswd'];
$dbname = $prefs['auth_phpbb_dbname'];
// not really used - will it be used?
//$dbport = $prefs['auth_phpbb_dbport'];
$dbtype = 'mysql';//$prefs['auth_phpbb_dbtype'];
//$dbconnection = mysql_connect($dbhost.':'.$dbport, $dbuser, $dbpasswd)
$dbconnection = mysql_connect($dbhost, $dbuser, $dbpasswd)
or die('AuthPhpBB : Could not connect: ' . mysql_error());
$dbconnection = NewADOConnection($dbtype);
$dbconnection->Connect($dbhost, $dbuser, $dbpasswd, $dbname);
if($dbconnection) {
mysql_select_db($dbname, $dbconnection);
return $dbconnection;
}
return false;
......@@ -72,15 +72,12 @@ class TikiPhpBBLib {
// MySQL queries are case insensitive anyway
$query = "select username from ".$prefs['auth_phpbb_table_prefix']."users where lcase(username) = lcase('". $username ."')";
$result = mysql_query($query, $dbconnection)
or die('AuthPhpBB : Query failed: ' . mysql_error());
$result = $dbconnection->Execute($query);
if ($result === false) die('AuthPhpBB : Query failed: ' . $dbconnection->ErrorMsg());
$numrows = mysql_num_rows($result);
// Free resultset
mysql_free_result($result);
return $numrows > 0;
return $result->RecordCount() > 0;
}
......@@ -98,10 +95,10 @@ class TikiPhpBBLib {
$dbconnection = $this->connectdb();
$query = "select user_password from ".$prefs['auth_phpbb_table_prefix']."users where lcase(username) = lcase('". $username ."')";
$result = mysql_query($query, $dbconnection)
or die('AuthPhpBB : Query failed: ' . mysql_error());
$result = $dbconnection->Execute($query);
if ($result === false) die('AuthPhpBB : Query failed: ' . $dbconnection->ErrorMsg());
if (mysql_num_rows($result) == 0) {
if ($result->RecordCount() == 0) {
return false;
}
else {
......@@ -109,8 +106,7 @@ class TikiPhpBBLib {
// This one is hardcoded for phpbb3
$PasswordHasher = new PasswordHash(8, TRUE);
$row = mysql_fetch_row($result);
if ($PasswordHasher->CheckPassword($password, $row[0])) {
if ($PasswordHasher->CheckPassword($password, $result->fields[0])) {
return true;
}
else {
......@@ -132,12 +128,11 @@ class TikiPhpBBLib {
// Just add email
$query = "select user_email from ".$prefs['auth_phpbb_table_prefix'] . "users where lcase(username) = lcase('". $username ."')";
$result = mysql_query($query, $dbconnection)
or die('AuthPhpBB : Query failed: ' . mysql_error());
$result = $dbconnection->Execute($query);
if ($result === false) die('AuthPhpBB : Query failed: ' . $dbconnection->ErrorMsg());
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_row($result);
return $row[0];
if ($result->RecordCount() > 0) {
return $result->field[0];
}
return 0;
......
......@@ -1023,6 +1023,7 @@ function get_default_prefs() {
'auth_phpbb_dbuser' => '',
'auth_phpbb_dbpasswd' => '',
'auth_phpbb_dbname' => '',
'auth_phpbb_dbtype' => 'mysql',
'auth_phpbb_table_prefix' => 'phpbb_',
'https_login' => 'allowed',
......
......@@ -38,6 +38,11 @@ function wikiplugin_toc_info()
'description' => tra('plain|fancy'),
'required' => false,
),
'pagename' => array(
'name' => tra('Page Name'),
'description' => tra('By default, toc for current page will be displayed. Alternate page may be provided.'),
'required' => false,
),
),
);
}
......@@ -52,6 +57,7 @@ function wikiplugin_toc( $data, $params )
'structId' => '',
'maxdepth' => 0,
'numberPrefix' => '',
'pagename' => '',
);
$params = array_merge( $defaults, $params );
......@@ -61,10 +67,16 @@ function wikiplugin_toc( $data, $params )
include_once ("lib/structures/structlib.php");
if (empty($structId)) {
if (!empty($page_ref_id)) { //And we are currently viewing a structure
$page_info = $structlib->s_get_page_info($page_ref_id);
$structure_info = $structlib->s_get_structure_info($page_ref_id);
$pageName_ref_id = null;
if(!empty($pagename)) {
$pageName_ref_id = $structlib->get_struct_ref_id($pagename);
} else {
$pageName_ref_id = $page_ref_id;
}
$page_info = $structlib->s_get_page_info($pageName_ref_id);
$structure_info = $structlib->s_get_structure_info($pageName_ref_id);
if (isset($page_info)) {
$html = $structlib->get_toc($page_ref_id, $order, $showdesc, $shownum, $numberPrefix, $type, '', $maxdepth, $structure_info['pageName']);
$html = $structlib->get_toc($pageName_ref_id, $order, $showdesc, $shownum, $numberPrefix, $type, '', $maxdepth, $structure_info['pageName']);
return "~np~$html~/np~";
}
}
......
......@@ -23,6 +23,7 @@
<option value="cas" {if $prefs.auth_method eq 'cas'} selected="selected"{/if}>{tr}CAS (Central Authentication Service){/tr}</option>
<option value="shib" {if $prefs.auth_method eq 'shib'} selected="selected"{/if}>{tr}Shibboleth{/tr}</option>
<option value="ws" {if $prefs.auth_method eq 'ws'} selected="selected"{/if}>{tr}Web Server{/tr}</option>
<option value="phpbb" {if $prefs.auth_method eq 'phpbb'} selected="selected"{/if}>{tr}phpBB{/tr}</option>
</select> {if $prefs.feature_help eq 'y'} {help url="Login+Authentication+Methods"}{/if}
</div>
</div>
......@@ -599,6 +600,70 @@
</fieldset>
</fieldset>
{/tab}
{tab name="{tr}phpBB{/tr}"}
<fieldset><legend>{tr}phpBB{/tr} {if $prefs.feature_help eq 'y'}{help url="AuthphpBB" desc="{tr}phpBB User Database Authentication {/tr}"}{/if}</legend>
<input type="hidden" name="auth_phpbb" />
{if $prefs.auth_method ne 'phpbb'}
<div style="padding:0.5em;clear:both" class="simplebox">
<div>{icon _id=information} {tr}You must change the Authentication Method to phpBB for these changes to take effect{/tr}.</div>
</div>
{/if}
<div class="adminoptionbox">
<div class="adminoption"><input id="auth_phpbb_create_tiki" type="checkbox" name="auth_phpbb_create_tiki" {if $prefs.auth_phpbb_create_tiki eq 'y'}checked="checked"{/if} /></div>
<div class="adminoptionlabel"><label for="auth_phpbb_create_tiki">{tr}Create user if not in Tiki{/tr}.</label></div>
</div>
<div class="adminoptionbox">
<div class="adminoption"><input id="auth_phpbb_skip_admin" type="checkbox" name="auth_phpbb_skip_admin" {if $prefs.auth_phpbb_skip_admin eq 'y'}checked="checked"{/if} /></div>
<div class="adminoptionlabel"><label for="auth_phpbb_skip_admin">{tr}Skip admin user{/tr}.</label></div>
</div>
<div class="adminoptionbox">
<div class="adminoption"><input id="auth_phpbb_disable_tikionly" type="checkbox" name="auth_phpbb_disable_tikionly" {if $prefs.auth_phpbb_disable_tikionly eq 'y'}checked="checked"{/if} /></div>
<div class="adminoptionlabel"><label for="auth_phpbb_disable_tikionly">{tr}Disable Tiki users who doesn't have a phpBB login. (They could have been deleted).{/tr}.</label></div>
</div>
<div class="adminoptionbox">
<div class="adminoptionlabel"><label for="auth_phpbb_version">{tr}phpBB Version:{/tr}</label>
<select name="auth_phpbb_version" id="auth_phpbb_version">
<option value="3" {if $prefs.auth_phpbb_version eq '3'} selected="selected"{/if}>{tr}3{/tr}</option>
</select>
</div>
</div>
<div style="padding:0.5em;clear:both" class="simplebox">
<div>{icon _id=information} {tr}MySql only (for now){/tr}.</div>
</div>
<div class="adminoptionbox">
<div class="adminoptionlabel"><label for="auth_phpbb_dbhost">{tr}phpBB Database Hostname:{/tr}</label>
<input type="text" id="auth_phpbb_dbhost" name="auth_phpbb_dbhost" value="{$prefs.auth_phpbb_dbhost}" size="50" />
</div>
</div>
<!-- // commented out - will we use a db port?
<div class="adminoptionbox">
<div class="adminoptionlabel"><label for="auth_phpbb_dbport">{tr}phpBB Database Port:{/tr}</label>
<input type="text" id="auth_phpbb_dbport" name="auth_phpbb_dbport" value="{$prefs.auth_phpbb_dbport}" size="50" />
</div>
</div> /-->
<div class="adminoptionbox">
<div class="adminoptionlabel"><label for="auth_phpbb_dbuser">{tr}phpBB Database Username:{/tr}</label>
<input type="text" id="auth_phpbb_dbuser" name="auth_phpbb_dbuser" value="{$prefs.auth_phpbb_dbuser}" size="50" />
</div>
</div>
<div class="adminoptionbox">
<div class="adminoptionlabel"><label for="auth_phpbb_dbpasswd">{tr}phpBB Database Password:{/tr}</label>
<input type="password" id="auth_phpbb_dbpasswd" name="auth_phpbb_dbpasswd" value="{$prefs.auth_phpbb_dbpasswd}" size="50" />
</div>
</div>
<div class="adminoptionbox">
<div class="adminoptionlabel"><label for="auth_phpbb_dbname">{tr}phpBB Database Name:{/tr}</label>
<input type="text" id="auth_phpbb_dbname" name="auth_phpbb_dbname" value="{$prefs.auth_phpbb_dbname}" size="50" />
</div>
</div>
<div class="adminoptionbox">
<div class="adminoptionlabel"><label for="auth_phpbb_table_prefix">{tr}phpBB Table Prefix:{/tr}</label>
<input type="text" id="auth_phpbb_table_prefix" name="auth_phpbb_table_prefix" value="{$prefs.auth_phpbb_table_prefix}" size="50" />
</div>
</div>
</fieldset>
{/tab}
{/tabset}
<div class="heading input_submit_container" style="text-align: center">
<input type="submit" value="{tr}Change preferences{/tr}" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment