vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Integrate or bridge with MediaWiki (https://vborg.vbsupport.ru/showthread.php?t=112973)

HolisticEarth 08-14-2006 12:44 PM

Quote:

Originally Posted by thenetbox
Hi,

Does any one know if this is working with VB 3.6? Thank you

I will be upgrading my vB very soon, so I will make sure it works

ElfMage 08-15-2006 01:34 AM

Initially I started on 3.5.x, but I upgraded as soon as 3.6 came out.

3.6 broke my vRewrite implementation (wiki-vB plugin doesn't need vRewrite, it can work with or without SEO), but I am sure that by now this has been discussed elsewhere, and/or a fix has been provided.

Other than that it was 100% compatible. I will provide a public build in the next couple of days.

dsl55dsl 08-18-2006 07:40 PM

I am using Wiki and vB integration and works great I was wondering if it would be possible to have the AuthPlugin_vBulletin.php to check the vB database under User Table under the 'membergroupids' for the value 29 and only at that moment to give access to Wiki.

I dont want all my vB users to have access to Wiki.

Thanks alot,

G.

ndahiya 08-20-2006 01:05 PM

in AuthPlugin_vBulletin find
Code:

      // Only registered and admins. Banned and unregistered don't belong here.
      if($usergroupid == "2" || $usergroupid == "5" || $usergroupid == "6" || $usergroupid == "7")

and change the if condition to include or exclude the groups you want. :)

dsl55dsl 08-21-2006 12:33 PM

Actually I dont really care about the usergroupid, What am I looking for is membergroupid that is a value of x.

ElfMage 08-21-2006 01:01 PM

Try the following changes:

First, let's change the allowed user groups to only 29.

Change the following code in the constructor:
Code:

$this->allowed_usergroups = Array(2, 5, 6, 7);
to
Code:

$this->allowed_usergroups = Array(29);
And then, change the following code in the function userExists
Code:

if (in_array($vb_userinfo['usergroupid'], $this->allowed_usergroups)) {
to the following:
Code:

$vb_usergroups = explode(",", $vb_userinfo['membergroupids']);        // make an array of membergroupids
$vb_usergroups[] = $vb_userinfo['usergroupid'];        // add the primary usergroup to the array
foreach ( $vb_usergroups as $vb_groupiter )
        if (in_array( $vb_groupiter, $this->allowed_usergroups))
                return TRUE;

This last piece of code checks the user's 'primary' group id as well as any other member group the user may belong to (membergroupids).

Notice that I haven't run this code, so it may not work, or it may have some small syntax errors ... :-)

dsl55dsl 08-21-2006 01:37 PM

I am getting the following error:

Parse error: parse error, unexpected T_RETURN, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /hsphere/local/home/mrshides/ww2.free-collective.us/wiki/AuthPlugin_vBulletin.php on line 73

this is how my AuthPlugin_vBulletin.php looks like:

Quote:

<?php
/**
* Authentication plugin interface. Instantiate a subclass of AuthPlugin
* and set $wgAuth to it to authenticate against some external tool.
*
* The default behavior is not to do anything, and use the local user
* database for all authentication. A subclass can require that all
* accounts authenticate externally, or use it only as a fallback; also
* you can transparently create internal wiki accounts the first time
* someone logs in who can be authenticated externally.
*
* This interface is new, and might change a bit before 1.4.0 final is
* done...
*
* AuthPlugin extension by Daniel Gravenor c/o HolisticEarth.org
* AuthPlugin original by Kai Backman
*
* @package MediaWiki
*/
require_once("includes/AuthPlugin.php");

class AuthPlugin_vBulletin extends AuthPlugin {

// Create a persistent DB connection
var $vb_database;

function AuthPlugin_vBulletin($host, $username, $password, $dbname, $prefix) {
$this->vb_database = mysql_pconnect($host, $username, $password);
mysql_select_db($dbname, $this->vb_database);
$this->vb_prefix = $prefix;
// set the usergroups for those who can edit the wiki
$this->allowed_usergroups = Array(29);
// set the usergroups for the administrators
$this->admin_usergroups = Array(6, 9);
$this->user_rights = Array("sysop");
// search pattern to only accept alphanumeric or underscore characters in usernames
// if they have illegal characters, their name cannot exist, period
$this->searchpattern = "/[^a-zA-Z0-9]+/";
}


/**
* Check whether there exists a user account with the given name.
* The name will be normalized to MediaWiki's requirements, so
* you might need to munge it (for instance, for lowercase initial
* letters).
*
* @param string $username
* @return bool
* @access public
*/
function userExists( $username ) {
// if no illegal characters are found in their username, then check to see if they exist
if (!preg_match($this->searchpattern, $username)) {
$username = addslashes($username);
$vb_find_user_query = "SELECT usergroupid FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . $username . "')";
$vb_find_result = mysql_query($vb_find_user_query, $this->vb_database);
// make sure that there is only one person with the username
if (mysql_num_rows($vb_find_result) == 1) {
$vb_userinfo = mysql_fetch_assoc($vb_find_result);
mysql_free_result($vb_find_result);
// Only registered and admins. Banned and unregistered don't belong here.
$vb_usergroups = explode(",", $vb_userinfo['membergroupids']); // make an array of membergroupids
$vb_usergroups[] = $vb_userinfo['usergroupid']; // add the primary usergroup to the array
foreach ( $vb_usergroups as $vb_groupiter )
if (in_array( $vb_groupiter, $this->allowed_usergroups))
return TRUE;
}
}
}
// if no one is registered with that username, or there are more than 1 entries
// or they have illegal characters return FALSE (they do not exist)
return FALSE;
}

/**
* Check if a username+password pair is a valid login.
* The name will be normalized to MediaWiki's requirements, so
* you might need to munge it (for instance, for lowercase initial
* letters).
*
* @param string $username
* @param string $password
* @return bool
* @access public
*/
function authenticate( $username, $password ) {
// if their name does not contain any illegal characters, let them try to login
if (!preg_match($this->searchpattern, $username)) {
$username = addslashes($username);
$vb_find_user_query = "SELECT password, salt, usergroupid FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . $username . "')";
$vb_find_result = mysql_query($vb_find_user_query, $this->vb_database);
if (mysql_num_rows($vb_find_result) == 1) {
$vb_userinfo = mysql_fetch_assoc($vb_find_result);
mysql_free_result($vb_find_result);
// Only registered and admins. Banned and unregistered don't belong here.
if (in_array($vb_userinfo['usergroupid'], $this->allowed_usergroups)) {
if(md5(md5($password) . $vb_userinfo['salt']) == $vb_userinfo['password']) return true;
}
}
}
return false;
}

/**
* When a user logs in, optionally fill in preferences and such.
* For instance, you might pull the email address or real name from the
* external user database.
*
* The User object is passed by reference so it can be modified; don't
* forget the & on your function declaration.
*
* @param User $user
* @access public
*/
function updateUser( &$user ) {
# Override this and do something
$vb_find_user_query = "SELECT usergroupid, membergroupids FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . addslashes($user->mName) . "')";
$vb_find_result = mysql_query($vb_find_user_query, $this->vb_database) or die("Could not find username");
if(mysql_num_rows($vb_find_result) == 1) {
$vb_userinfo = mysql_fetch_assoc($vb_find_result);
mysql_free_result($vb_find_result);
// go through the users member groups to see if one of them is administrative
$user_membergroups = explode(",", $vb_userinfo['membergroupids']);
$admin_secondary = FALSE;
for ($x = 0; $x < count($user_membergroups); $x++) {
if (in_array($user_membergroups[$x], $this->admin_usergroups)) $admin_secondary = TRUE;
}

if (in_array($vb_userinfo['usergroupid'], $this->admin_usergroups) || $admin_secondary === TRUE) {
// if a user is not a sysop, make them a sysop
if (!in_array("sysop", $user->getEffectiveGroups())) {
$user->addGroup('sysop');
return TRUE;
}
}
// if the user is not an administrator, but they were, and they are still a sysop, remove their sysop status
if (!in_array($vb_userinfo['usergroupid'], $this->admin_usergroups) && $admin_secondary === FALSE) {
if (in_array("sysop", $user->getEffectiveGroups())) {
$user->removeGroup('sysop');
return TRUE;
}
}
}
return FALSE;
}

/**
* Return true if the wiki should create a new local account automatically
* when asked to login a user who doesn't exist locally but does in the
* external auth database.
*
* If you don't automatically create accounts, you must still create
* accounts in some way. It's not possible to authenticate without
* a local account.
*
* This is just a question, and shouldn't perform any actions.
*
* @return bool
* @access public
*/
function autoCreate() {
return true;
}

/**
* Return true to prevent logins that don't authenticate here from being
* checked against the local database's password fields.
*
* This is just a question, and shouldn't perform any actions.
*
* @return bool
* @access public
*/
function strict() {
return true;
}

/**
* When creating a user account, optionally fill in preferences and such.
* For instance, you might pull the email address or real name from the
* external user database.
*
* The User object is passed by reference so it can be modified; don't
* forget the & on your function declaration.
*
* @param User $user
* @access public
*/
function initUser( &$user ) {
$vb_find_user_query = "SELECT email, usergroupid FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . addslashes($user->mName) . "')";
$vb_find_result = mysql_query($vb_find_user_query, $this->vb_database);
if(mysql_num_rows($vb_find_result) == 1) {
$vb_userinfo = mysql_fetch_assoc($vb_find_result);
mysql_free_result($vb_find_result);
$user->mEmail = $vb_userinfo['email'];
$user->mEmailAuthenticated = wfTimestampNow();
}
}
}
?>
Any help would be AWESOME.

ElfMage 08-21-2006 02:27 PM

In the function userExists, I left one '{' out (or didn't tell you to remove the extra '}'.. <g>)

Change this:
Code:

if (in_array( $vb_groupiter, $this->allowed_usergroups))
To this:
Code:

if (in_array( $vb_groupiter, $this->allowed_usergroups)) {

dsl55dsl 08-21-2006 02:37 PM

I dont get an error anymore really. I get:

Login error:Incorrect password entered. Please try again

I noticed that my membergroupids are the following: 6,25,26,29,30

Could that cause a problem?

ElfMage 08-21-2006 03:43 PM

I forgot to notice that the same filter is present in the function 'authenticate'. This is why you are getting the 'wrong password' error.

Make the same change to that function, there is a similar line there.

dsl55dsl 08-21-2006 03:53 PM

Still getting the same error.

Login error:Incorrect password entered. Please try again

This is what the AuthPlugin_Vbulletin.php file looks like:

Quote:

<?php
/**
* Authentication plugin interface. Instantiate a subclass of AuthPlugin
* and set $wgAuth to it to authenticate against some external tool.
*
* The default behavior is not to do anything, and use the local user
* database for all authentication. A subclass can require that all
* accounts authenticate externally, or use it only as a fallback; also
* you can transparently create internal wiki accounts the first time
* someone logs in who can be authenticated externally.
*
* This interface is new, and might change a bit before 1.4.0 final is
* done...
*
* AuthPlugin extension by Daniel Gravenor c/o HolisticEarth.org
* AuthPlugin original by Kai Backman
*
* @package MediaWiki
*/
require_once("includes/AuthPlugin.php");

class AuthPlugin_vBulletin extends AuthPlugin {

// Create a persistent DB connection
var $vb_database;

function AuthPlugin_vBulletin($host, $username, $password, $dbname, $prefix) {
$this->vb_database = mysql_pconnect($host, $username, $password);
mysql_select_db($dbname, $this->vb_database);
$this->vb_prefix = $prefix;
// set the usergroups for those who can edit the wiki
$this->allowed_usergroups = Array(29);
// set the usergroups for the administrators
$this->admin_usergroups = Array(6, 9);
$this->user_rights = Array("sysop");
// search pattern to only accept alphanumeric or underscore characters in usernames
// if they have illegal characters, their name cannot exist, period
$this->searchpattern = "/[^a-zA-Z0-9]+/";
}


/**
* Check whether there exists a user account with the given name.
* The name will be normalized to MediaWiki's requirements, so
* you might need to munge it (for instance, for lowercase initial
* letters).
*
* @param string $username
* @return bool
* @access public
*/
function userExists( $username ) {
// if no illegal characters are found in their username, then check to see if they exist
if (!preg_match($this->searchpattern, $username)) {
$username = addslashes($username);
$vb_find_user_query = "SELECT usergroupid FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . $username . "')";
$vb_find_result = mysql_query($vb_find_user_query, $this->vb_database);
// make sure that there is only one person with the username
if (mysql_num_rows($vb_find_result) == 1) {
$vb_userinfo = mysql_fetch_assoc($vb_find_result);
mysql_free_result($vb_find_result);
// Only registered and admins. Banned and unregistered don't belong here.
$vb_usergroups = explode(",", $vb_userinfo['membergroupids']); // make an array of membergroupids
$vb_usergroups[] = $vb_userinfo['usergroupid']; // add the primary usergroup to the array
foreach ( $vb_usergroups as $vb_groupiter )
if (in_array( $vb_groupiter, $this->allowed_usergroups)) {
return TRUE;
}
}
}
// if no one is registered with that username, or there are more than 1 entries
// or they have illegal characters return FALSE (they do not exist)
return FALSE;
}

/**
* Check if a username+password pair is a valid login.
* The name will be normalized to MediaWiki's requirements, so
* you might need to munge it (for instance, for lowercase initial
* letters).
*
* @param string $username
* @param string $password
* @return bool
* @access public
*/
function authenticate( $username, $password ) {
// if their name does not contain any illegal characters, let them try to login
if (!preg_match($this->searchpattern, $username)) {
$username = addslashes($username);
$vb_find_user_query = "SELECT password, salt, usergroupid FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . $username . "')";
$vb_find_result = mysql_query($vb_find_user_query, $this->vb_database);
if (mysql_num_rows($vb_find_result) == 1) {
$vb_userinfo = mysql_fetch_assoc($vb_find_result);
mysql_free_result($vb_find_result);
// Only registered and admins. Banned and unregistered don't belong here.
$vb_usergroups = explode(",", $vb_userinfo['membergroupids']); // make an array of membergroupids
$vb_usergroups[] = $vb_userinfo['usergroupid']; // add the primary usergroup to the array
foreach ( $vb_usergroups as $vb_groupiter )
if (in_array( $vb_groupiter, $this->allowed_usergroups)) {
return TRUE;
if(md5(md5($password) . $vb_userinfo['salt']) == $vb_userinfo['password']) return true;
}
}
}
return false;
}

/**
* When a user logs in, optionally fill in preferences and such.
* For instance, you might pull the email address or real name from the
* external user database.
*
* The User object is passed by reference so it can be modified; don't
* forget the & on your function declaration.
*
* @param User $user
* @access public
*/
function updateUser( &$user ) {
# Override this and do something
$vb_find_user_query = "SELECT usergroupid, membergroupids FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . addslashes($user->mName) . "')";
$vb_find_result = mysql_query($vb_find_user_query, $this->vb_database) or die("Could not find username");
if(mysql_num_rows($vb_find_result) == 1) {
$vb_userinfo = mysql_fetch_assoc($vb_find_result);
mysql_free_result($vb_find_result);
// go through the users member groups to see if one of them is administrative
$user_membergroups = explode(",", $vb_userinfo['membergroupids']);
$admin_secondary = FALSE;
for ($x = 0; $x < count($user_membergroups); $x++) {
if (in_array($user_membergroups[$x], $this->admin_usergroups)) $admin_secondary = TRUE;
}

if (in_array($vb_userinfo['usergroupid'], $this->admin_usergroups) || $admin_secondary === TRUE) {
// if a user is not a sysop, make them a sysop
if (!in_array("sysop", $user->getEffectiveGroups())) {
$user->addGroup('sysop');
return TRUE;
}
}
// if the user is not an administrator, but they were, and they are still a sysop, remove their sysop status
if (!in_array($vb_userinfo['usergroupid'], $this->admin_usergroups) && $admin_secondary === FALSE) {
if (in_array("sysop", $user->getEffectiveGroups())) {
$user->removeGroup('sysop');
return TRUE;
}
}
}
return FALSE;
}

/**
* Return true if the wiki should create a new local account automatically
* when asked to login a user who doesn't exist locally but does in the
* external auth database.
*
* If you don't automatically create accounts, you must still create
* accounts in some way. It's not possible to authenticate without
* a local account.
*
* This is just a question, and shouldn't perform any actions.
*
* @return bool
* @access public
*/
function autoCreate() {
return true;
}

/**
* Return true to prevent logins that don't authenticate here from being
* checked against the local database's password fields.
*
* This is just a question, and shouldn't perform any actions.
*
* @return bool
* @access public
*/
function strict() {
return true;
}

/**
* When creating a user account, optionally fill in preferences and such.
* For instance, you might pull the email address or real name from the
* external user database.
*
* The User object is passed by reference so it can be modified; don't
* forget the & on your function declaration.
*
* @param User $user
* @access public
*/
function initUser( &$user ) {
$vb_find_user_query = "SELECT email, usergroupid FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . addslashes($user->mName) . "')";
$vb_find_result = mysql_query($vb_find_user_query, $this->vb_database);
if(mysql_num_rows($vb_find_result) == 1) {
$vb_userinfo = mysql_fetch_assoc($vb_find_result);
mysql_free_result($vb_find_result);
$user->mEmail = $vb_userinfo['email'];
$user->mEmailAuthenticated = wfTimestampNow();
}
}
}
?>

ElfMage 08-22-2006 01:40 AM

:-) If I had dedicated some time to test the changes I was suggesting, we would have had it working by now... If this time it doesn't work, I will take the time to test it before my next post... <g>

Now, realize that this AuthPlugin_vBulletin was not written by me, and as such, the original author may not like/agree with my suggestions...

In the original code, the function authenticate checks for the allowed_usergroups. I personally think that this is not needed, since 'userExists' is always called before 'authenticate'.

Try changing the function 'authenticate' for the following code. Let me know if it doesn't work, and I will try it on my test server.

Code:


        function authenticate( $username, $password ) {
                // if their name does not contain any illegal characters, let them try to login
                if (!preg_match($this->searchpattern, $username)) {
                        $username = addslashes($username);
                        $vb_find_user_query = "SELECT password, salt, usergroupid FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . $username . "')";
                        $vb_find_result = mysql_query($vb_find_user_query, $this->vb_database);
                        if (mysql_num_rows($vb_find_result) == 1) {
                                $vb_userinfo = mysql_fetch_assoc($vb_find_result);
                                mysql_free_result($vb_find_result);
                                // check password
                                if(md5(md5($password) .  $vb_userinfo['salt']) == $vb_userinfo['password']) return true;
                        }
                }
                return false;
        }


Rowen 09-14-2006 04:59 PM

Does anyone know how this project is coming along?

vBulletin 3.6.1 is now out, last I heard, this was for 3.5.4

I would be willing to donate to help progression of this plugin.

yessir 09-14-2006 05:03 PM

The Luxury Wiki bridge is for 3.6 and Mediawiki 1.7.x

HolisticEarth 09-15-2006 01:41 PM

Quote:

Originally Posted by Rowen
Does anyone know how this project is coming along?

vBulletin 3.6.1 is now out, last I heard, this was for 3.5.4

I would be willing to donate to help progression of this plugin.

The plugin is still working good in its original format, for both 1.7.x and 3.6.0:
http://holisticearth.org/wiki/

3.6.1 must have just come out ... I will give my forum an upgrade asap to make sure it still works.

Clayton 10-20-2006 06:45 AM

some nice design styling done with wiki and your forums

:up:

mfarmerhi 12-03-2006 02:50 AM

Gah...!

3.5.7 board. For security I recently changed the DB username and password... The integration is no longer working.

I'm getting "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/totalli/public_html/wiki/AuthPlugin_vBulletin.php on line 73" and "The password you entered is incorrect (or missing). Please try again" errors upon trying to log in.

Ideas?

Hensa 03-03-2007 04:33 PM

Does this solution allow users to login to MW and vBulletin on the same domain with a single login? I want MW to be separate from, rather than integrated into, vBulletin, but with a single login.

ElfMage 03-03-2007 10:31 PM

Yes, vbWiki Standard will allow you to do that.

snoopy5 09-13-2007 04:16 PM

does this work with vb 3.68 also?

blue_asterisk 04-17-2008 07:41 PM

I can confirm that I got this working on vb3.6.7 with mediawiki 1.11svn
http://www.mediawiki.org/wiki/Extens...rs_Integration

Mancia 05-15-2008 08:06 PM

Anyone got this working for vBulletin 3.7?

or any other integration between mediawiki and vB 3.7?

Elenna 05-16-2008 06:01 PM

Update: This seems to work well with vBulletin 3.7 and MW 1.12.

Has anyone found a way to have it automatically log the user in?

pelicanparts 05-20-2008 08:29 AM

It seems that the later versions of MediaWiki no longer require no spaces in the usernames? So, the restriction in this extension is no longer required (apparently). Hence, I replaced this line:

$this->searchpattern = "/[^a-zA-Z0-9]+/";

with this line:

$this->searchpattern = "/[\#\<\>\[\]\|\{\}/";

So far so good. I will be now working on some additional features, like the auto-logon from vB.

-Wayne

Smitty 05-21-2008 05:09 AM

Thanks, pelicanparts. I have the 'Pro' version ElfMage was selling. As far as I can tell, ElfMage has 'left the premises' so to speak. Maybe I'll be able to apply some of your information to the Pro version so your information is appreciated very much!

pelicanparts 05-21-2008 05:40 AM

I'm working on it tonight - I've got it able to read the vB cookies, and it should work for autologon - it's just a matter of getting the details just right. I'll post my code here when I'm done.

-Wayne

Elenna 05-29-2008 08:19 PM

Hi Wayne!

Were you able to make any headway on what you're working on? I would sincerely love to have it automatically log my members in again.

pelicanparts 05-30-2008 04:15 AM

Yes, I was, and it is currently working. I will post it soon...

-Wayne

--------------- Added [DATE]1212124788[/DATE] at [TIME]1212124788[/TIME] ---------------

Add to end of LocalSettings.php. Change 123456789 to your vB license number. Change pelicanparts.com to your domain.

Make sure that in cookie settings in vBulletin's admin control panel, you set the cookie domain to be your domain, not blank. In my case I set it to be pelicanparts.com

Code:

# vBulletin integration script
require_once("D:/Wiki/extensions/AuthPlugin_vBulletin/AuthPlugin_vBulletin.php");
$wgCookieDomain = "pelicanparts.com";
define('COOKIE_SALT', '123456789');  ### VB LICENSE NUMBER, FROM LINE 37 OF FUNCTIONS
$wgAuth = new Auth_remoteuser();
$wgShowExceptionDetails = true;

--------------- Added [DATE]1212125151[/DATE] at [TIME]1212125151[/TIME] ---------------

Here's the code, still rough and with test messages printing.

Replace VBULLETINDATABASE with the name of your vb database
Replace MYSQLLOGIN with your mysql logon name
Replace MYSQLPASSWORD with your mysql password name

That does it, this does work on my site right now, I think the only thing I'm missing is sending people to vb for account creation...

-Wayne

Code:

<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
/**
 * Authentication plugin interface. Instantiate a subclass of AuthPlugin
 * and set $wgAuth to it to authenticate against some external tool.
 *
 * The default behavior is not to do anything, and use the local user
 * database for all authentication. A subclass can require that all
 * accounts authenticate externally, or use it only as a fallback; also
 * you can transparently create internal wiki accounts the first time
 * someone logs in who can be authenticated externally.
 *
 * This interface is new, and might change a bit before 1.4.0 final is
 * done...
 *
 * AuthPlugin extension by Daniel Gravenor c/o HolisticEarth.org
 * AuthPlugin original by Kai Backman
 *
 * @package MediaWiki
 */
require_once("includes/AuthPlugin.php");

$wgHooks['UserLogout'][] = 'fnMyVBLOGOUTHook';

class Auth_remoteuser extends AuthPlugin {

        //WAYNE'S STUFF FROM http://www.raskas.be/blog/2006/11/17/mediawiki-remote-user-authentication/
        function Auth_remoteuser() {
                global $wgExtensionFunctions;
                if (!isset($wgExtensionFunctions)) {
                    $wgExtensionFunctions = array();
                } else if (!is_array($wgExtensionFunctions)) {
                    $wgExtensionFunctions = array( $wgExtensionFunctions );
                }
                        //print "TEST: REMOTE HOOK2\n";
                array_push($wgExtensionFunctions, 'Auth_remote_user_hook');
                        //print "DONE2\n";
            return;
        }

// Create a persistent DB connection
        var $vb_database;
       
        function AuthPlugin_vBulletin($host, $username, $password, $dbname, $prefix) {
                global $wgCookiePrefix;
                global $exp;
                global $wgCookiePath;
                global $wgCookieDomain;
                global $wgCookieSecure;

                global $wgUser;
                global $wgRequest;
                global $_REQUEST;
                       
                $this->vb_database = mysql_pconnect($host, $username, $password);
                mysql_select_db($dbname, $this->vb_database);
                $this->vb_prefix = $prefix;
                // set the usergroups for those who can edit the wiki
                $this->allowed_usergroups = Array(2, 5, 6, 7);
                // set the usergroups for the administrators
                $this->admin_usergroups = Array(6, 9);
                $this->user_rights = Array("sysop");
                // search pattern to only accept alphanumeric or underscore characters in usernames
                // if they have illegal characters, their name cannot exist, period
                $this->searchpattern = "/[\#\<\>\[\]\|\{\}/";

                //print_r($_COOKIE);
               
                //print "Content-type: text/html\n\n";
                //print "bbsessionhash:" . $_COOKIE["bbsessionhash"] . "<br>\n";
                //print "bblastvisit:" . $_COOKIE["bblastvisit"] . "<br>\n";
                //print "bblastactivity:" . $_COOKIE["bblastactivity"] . "<br>\n";
                //print "bbuserid:" . $_COOKIE["bbuserid"] . "<br>\n";
                //print "bbpassword:" . $_COOKIE["bbpassword"] . "<br>\n";
        }
       
       
        /**
        * Check whether there exists a user account with the given name.
        * The name will be normalized to MediaWiki's requirements, so
        * you might need to munge it (for instance, for lowercase initial
        * letters).
        *
        * @param string $username
        * @return bool
        * @access public
        */
        function userExists( $username ) {
print "Content-type: text/html TEST1\n\n";       
                // if no illegal characters are found in their username, then check to see if they exist
                if (!preg_match($this->searchpattern, $username)) {
                        $username = addslashes($username);
                        $vb_find_user_query = "SELECT usergroupid FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . $username . "')";
                        $vb_find_result = mysql_query($vb_find_user_query, $this->vb_database);
                        // make sure that there is only one person with the username
                        if (mysql_num_rows($vb_find_result) == 1) {
                                $vb_userinfo = mysql_fetch_assoc($vb_find_result);
                                mysql_free_result($vb_find_result);
                                // Only registered and admins. Banned and unregistered don't belong here.
                                if (in_array($vb_userinfo['usergroupid'], $this->allowed_usergroups)) {
                                        return TRUE;
                                }
                        }
                }
                // if no one is registered with that username, or there are more than 1 entries
                // or they have illegal characters return FALSE (they do not exist)
                return FALSE;
        }
       
        /**
        * Check if a username+password pair is a valid login.
        * The name will be normalized to MediaWiki's requirements, so
        * you might need to munge it (for instance, for lowercase initial
        * letters).
        *
        * @param string $username
        * @param string $password
        * @return bool
        * @access public
        */
        function authenticate( $username, $password ) {
                $searchpattern = "/[\#\<\>\[\]\|\{\}]/";
                $dbh = mysql_pconnect("localhost", "MYSQL-LOGON", "MYSQL-PASSWORD");
                mysql_select_db("VBULLETINDBNAME", $dbh);
       
print "Content-type: text/html TEST2\n\n";       
                // if their name does not contain any illegal characters, let them try to login
                if (!preg_match($searchpattern, $username)) {
                print "TEST2A\n";
                        $username = addslashes($username);
                        $vb_find_user_query = "SELECT password, salt, usergroupid FROM VBULLETINDATABASE.user WHERE LOWER(username)=LOWER('" . $username . "')";
                        $vb_find_result = mysql_query($vb_find_user_query, $dbh);
                        if (mysql_num_rows($vb_find_result) == 1) {
                                print "FOUND!\n";
                                $vb_userinfo = mysql_fetch_assoc($vb_find_result);
                                mysql_free_result($vb_find_result);
                                // Only registered and admins. Banned and unregistered don't belong here.
                                $valid_usergroup_array = array(2, 5, 6, 7);
                                print "TEST2B\n";
                                if (in_array($vb_userinfo['usergroupid'], $valid_usergroup_array)) {
                                        if(md5(md5($password) .  $vb_userinfo['salt']) == $vb_userinfo['password'])
                                                {
                                                print "AUTH TRUE: NOW WE NEED TO UPDATE VBULLETIN WITH THE LOGIN INFORMATION?  OR NOT?\n";
                                                return true;
                                                }
                                }
                        }
                }
                return false;
        }
       
        /**
        * When a user logs in, optionally fill in preferences and such.
        * For instance, you might pull the email address or real name from the
        * external user database.
        *
        * The User object is passed by reference so it can be modified; don't
        * forget the & on your function declaration.
        *
        * @param User $user
        * @access public
        */
        function updateUser( &$user ) {
print "Content-type: text/html TEST3\n\n";       
                # Override this and do something
                $dbh = mysql_pconnect("localhost", "MYSQL-LOGON", "MYSQL-PASSWORD");
                mysql_select_db("VBULLETINDATABASE", $dbh);
               
                $vb_find_user_query = "SELECT usergroupid, membergroupids FROM VBULLETINDATABASE.user WHERE LOWER(username)=LOWER('" . addslashes($user->mName) . "')";
                $vb_find_result = mysql_query($vb_find_user_query, $dbh) or print("Could not find username");
                if(mysql_num_rows($vb_find_result) == 1) {
                        $vb_userinfo = mysql_fetch_assoc($vb_find_result);
                        mysql_free_result($vb_find_result);
                        // go through the users member groups to see if one of them is administrative
                        $user_membergroups = explode(",", $vb_userinfo['membergroupids']);
                        $admin_secondary = FALSE;
                        for ($x = 0; $x < count($user_membergroups); $x++) {
                                if (in_array($user_membergroups[$x], $this->admin_usergroups)) $admin_secondary = TRUE;
                        }
                       
                        if (in_array($vb_userinfo['usergroupid'], $this->admin_usergroups) || $admin_secondary === TRUE) {
                                // if a user is not a sysop, make them a sysop
                                if (!in_array("sysop", $user->getEffectiveGroups())) {
                                        $user->addGroup('sysop');
                                        return TRUE;
                                }
                        }
                        // if the user is not an administrator, but they were, and they are still a sysop, remove their sysop status
                        if (!in_array($vb_userinfo['usergroupid'], $this->admin_usergroups) && $admin_secondary === FALSE) {
                                if (in_array("sysop", $user->getEffectiveGroups())) {
                                        $user->removeGroup('sysop');
                                        return TRUE;
                                }
                        }
                }
                return FALSE;
        }

        /**
        * Return true if the wiki should create a new local account automatically
        * when asked to login a user who doesn't exist locally but does in the
        * external auth database.
        *
        * If you don't automatically create accounts, you must still create
        * accounts in some way. It's not possible to authenticate without
        * a local account.
        *
        * This is just a question, and shouldn't perform any actions.
        *
        * @return bool
        * @access public
        */
        function autoCreate() {
                return true;
        }
       
        /**
        * Return true to prevent logins that don't authenticate here from being
        * checked against the local database's password fields.
        *
        * This is just a question, and shouldn't perform any actions.
        *
        * @return bool
        * @access public
        */
        function strict() {
                return true;
        }
       
        /**
        * When creating a user account, optionally fill in preferences and such.
        * For instance, you might pull the email address or real name from the
        * external user database.
        *
        * The User object is passed by reference so it can be modified; don't
        * forget the & on your function declaration.
        *
        * @param User $user
        * @access public
        */
        function initUser( &$user ) {
print "Content-type: text/html TEST4\n\n";       
                $vb_find_user_query = "SELECT email, usergroupid FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . addslashes($user->mName) . "')";
                $vb_find_result = mysql_query($vb_find_user_query, $this->vb_database);
                if(mysql_num_rows($vb_find_result) == 1) {
                        $vb_userinfo = mysql_fetch_assoc($vb_find_result);
                        mysql_free_result($vb_find_result);
                        $user->mEmail = $vb_userinfo['email'];
                        $user->mEmailAuthenticated = wfTimestampNow();
                }
        }


       
} // END CLASS

        function Auth_remote_user_hook() {
            global $wgUser;
            global $wgRequest;
            global $_REQUEST;

                global $wgCookiePrefix;
                global $exp;
                global $wgCookiePath;
                global $wgCookieDomain;
                global $wgCookieSecure;

                //print_r($_COOKIE);
               
                //print "REMOTE HOOK77";       
            // For a few special pages, don't do anything.
            $title = $wgRequest->getVal('title') ;
            if ($title == 'Special:Userlogout' || $title == 'Special:Userlogin') {
                //print "TEST101\n";
                return;
            }

                  // Do nothing if session is valid
                  $wgUser = User::newFromSession();
                  if ($wgUser->isLoggedIn()) {
                        //print "TEST102\n"; 
                    return;  // User is already logged in and not anonymous.
                  }               
                //print "TEST: WGUSER\n" . $_COOKIE["bbsessionhash"];                 
                 
                $test = new Auth_remoteuser();
                $wgAuth = $test->AuthPlugin_vBulletin("localhost", "MYSQL-LOGON", "MYSQL-PASSWORD", "VBULLETINDATABASE", "VBULLETINDATABASE.");

                if ($_COOKIE["bbsessionhash"] != "")
                        {
                        //print "TEST: IS INT, CONNECT TO DB\n";
                        $dbh = mysql_pconnect("localhost", "MYSQL-LOGON", "MYSQL-PASSWORD");
                        mysql_select_db("VBULLETINDATABASE", $dbh);
                       
                        $vb_find_user_query = "SELECT password, salt, usergroupid, username FROM VBULLETINDATABASE.user WHERE userid IN (select userid from session where sessionhash = '" . $_COOKIE["bbsessionhash"] . "');";
                        $vb_find_result = mysql_query($vb_find_user_query, $dbh);
                        //print "SQL: $vb_find_user_query\n";
                        if (mysql_num_rows($vb_find_result) == 1) {
                        //print "FOUND";
                                $vb_userinfo = mysql_fetch_assoc($vb_find_result);
                                mysql_free_result($vb_find_result);
                                // Only registered and admins. Banned and unregistered don't belong here.
                                //print "USERNAME: " . $vb_userinfo['username'] ."\n";
                                setcookie( $wgCookiePrefix.'wikidbUserName', $vb_userinfo['username'], $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
// NEED TO FIX THIS TO BE CONSISTENT
                                $valid_usergroup_array = array(2, 5, 6, 7);                               
                                if (in_array($vb_userinfo['usergroupid'], $valid_usergroup_array))
                                        {
                                        //print "TEST33\n";
                                        //if(md5($vb_userinfo['password'] .  COOKIE_SALT) == $_COOKIE["bbpassword"])
                                        //        {
                                                //print "LOGGED INTO vB, NOW LOG INTO WIKI";\
                                                // THIS ROUTINE IS CALLED, AND THEN THE PAGE IS REFRESHED
                                                $username = $vb_userinfo['username'];
                                            $u = User::newFromName( $username );
                                            if (is_null($u))
                                                        {
                                                # Invalid username or some other error -- force login, just return
                                                        //print "INVALID";
                                                return;
                                                    }
                                            $wgUser = $u;
                                            if ($u->getId() != 0)
                                                        {
                                                $_REQUEST['wpName'] = $username;
                                                # also return, but user is know. set Cookies, et al
                                                $wgUser->setCookies();
                                                $wgUser->saveSettings();
                                                        //print "TEST103\n";
                                                return;
                                                    #include 'includes/SpecialUserlogin.php';
                                                    #$form = new LoginForm( $wgRequest );
                                                    #$form->initUser( $wgUser );
                                                    #$wgUser->saveSettings();
                                                        #return true;
                                                        }
                                                //print "TEST77:" . md5(md5($_COOKIE["bbpassword"])) ;       
                                                //print "<br>PWD: " . md5($vb_userinfo['password'] .  COOKIE_SALT) ."<br> TEST44:" . $_COOKIE["bbpassword"] . "\n";       
                                        //        }       
                                        }
                                }               
            }
       
        // Ok, now we need to create a user.
        //print "Location: http://forums.pelicanparts.com/newreply.php?do=newreply&noquote=1&p=3801901\n\n";               
        return;
       
//  $loginForm = new LoginForm($params);
//  $result = $loginForm->authenticateUserData();
//  if ($result != LoginForm::SUCCESS) {
//    error_log('Unexpected REMOTE_USER authentication failure.');
//    return;
//  }
               
}
       
function fnMyVBLOGOUTHook(&$user)
        {
        global $wgCookiePrefix;
        global $exp;
        global $wgCookiePath;
        global $wgCookieDomain;
        global $wgCookieSecure;
       
        //print "LOGOUT HOOK";
       
        setcookie('bbsessionhash', '', $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
        setcookie('bblastvisit', '', $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
        setcookie('bblastactivity', '', $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
        setcookie('bbuserid', '', $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
        setcookie('bbpassword', '', $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
        return true;
        }



#class AuthPlugin_vBulletin extends AuthPlugin {


       
?>


Elenna 05-30-2008 01:25 PM

Thank you, Wayne!

I get the following error:
Notice: Undefined index: bbsessionhash in /(path)/wiki/AuthPlugin_vBulletin.php on line 290

Also, would it be possible to make variables for the database name, sql username, and password, instead of manually putting them in each connection string? I'm not asking you to do it, I'm curious if it's possible - if it is, then I can work on that :)

pelicanparts 05-30-2008 09:44 PM

Turn off error reporting by deleting or commenting out lines 2 and 3. That's just a warning message, nothing serious there.

-Wayne

Elenna 05-31-2008 01:34 AM

Thanks, I'll try that :)

SuperGLS 06-26-2008 09:38 PM

Wayne,

Thanks for the additional work on this for 3.7.

I have had a forum for a long time and just set up a wiki (MW 1.12). In order to get this integration working do I have to follow the instructions from the first post, then make the changes you have suggested, or just make the changes that you have put forth? Thanks in advance.

SuperGLS 06-30-2008 06:19 PM

Anyone have any thoughts on this?

Elenna, have you gotten yours to work?

Arkidas 06-30-2008 10:21 PM

I bought vBWiki Pro, disliked it and got a refund. I am now wondering if this may be better for me. Does anyone have a demo of this?

Smitty 07-01-2008 01:17 AM

Quote:

Originally Posted by Arkidas (Post 1563462)
I bought vBWiki Pro, disliked it and got a refund. I am now wondering if this may be better for me. Does anyone have a demo of this?

I use the Pro version. I'm only running MediaWiki 1.11.0 but it works fine for me with vB 3.7.2. I haven't really looked to see what Mediawiki 1.12 will really do for me because my wiki is rarely used.

What didn't you like about the Pro version?

Is there a significant advantage in upgrading to Mediawiki 1.12?

Arkidas 07-01-2008 01:09 PM

I'm just wondering if this tutorial works better than vbwiki pro. I didn't like that there was no support and it doesn't work 100% with vB 3.7.2.

Smitty 07-01-2008 08:28 PM

Quote:

Originally Posted by Arkidas (Post 1563948)
I'm just wondering if this tutorial works better than vbwiki pro. I didn't like that there was no support and it doesn't work 100% with vB 3.7.2.

This is sorta off topic, but... What problems are you having with the pro version on 3.7.2?

Goomzee 07-02-2008 09:46 AM

I also have same question is this work with 3.7.2

Arkidas 07-02-2008 11:39 AM

Quote:

Originally Posted by Smitty (Post 1564263)
This is sorta off topic, but... What problems are you having with the pro version on 3.7.2?

It doesn't work with the current version of MediaWiki, I'd like spaced usernames to work.

I'm wondering, is it possible to disable areas in mediawiki that could confuse members ( e.g. 'discussion' ) ?

epaillac 07-02-2008 02:48 PM

Quote:

Originally Posted by ndahiya (Post 968221)
# Rehash of sammyman's and my posts in the old thread::


You might get the following error (looks like only with PHP 4.3.11):


Workaround: In includes/SpecialUserlogin.php, find:
$u =& $this->initUser( $u );
Replace this to this:
$u = $this->initUser( $u );



Excessive Database Pings



This works perfectly fine, but for one problem.... Inserting the code in LocalSettings.php creates a "session" to mysql every time someone accesses *any* page in the wiki... (you can see this by putting in the wrong password). On my server, this caused too many sessions being created in mysql, and resulted in the intermittent access problems (as the db was unavailable)!!


The way around this is (Thogh a less elegant solution, and one you have to reapply every time your upgrade mediawiki) to insert the same code near the begining of "includes/User.php"

This takes care of the excess pinging problem, as the vb database is accessed only when a user tries to login.


Well, concerning the "Excessive Database Pings" I can't make the modification work.
I've removed :
PHP Code:

require_once("AuthPlugin_vBulletin.php");
$wgAuth = new AuthPlugin_vBulletin($wgDBserver$wgDBuser$wgDBpassword$wgDBname"vb_"); 

in the LocalSettings.php

and put this (not in the class) at the beginning of those 2 files : User.php and SpecialUserLogin.php and... my bridge doesn't work anymore. Any ideas on how to debug this ?

I'm using MW12 and vB 3.7.2

Thanks,

Charles.


All times are GMT. The time now is 03:40 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01864 seconds
  • Memory Usage 2,043KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (10)bbcode_code_printable
  • (1)bbcode_php_printable
  • (8)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete