Not logged in. · Lost password · Register
Forum: General Help and Support Plugins RSS
DokuMyBB
integrate MyBB user table in DokuWiki
Avatar
flash.tato #1
Member since Oct 2007 · 7 posts
Group memberships: Members
Show profile · Link to this post
Subject: DokuMyBB
Hi,

this is an auth backend for bridging MyBB's user table in DokuWiki :-), all instructions are available in the readme file.

Also the usergroup conversion is highly customisable infact you have to edit only this line:
var $rules = array("4" => array("admin", "user"), "default" => array("user"));

The function mybb_2_dw_usergroups will handle the conversion in according with data present in it.

ToDo
- Share sessions
The author has attached one file to this post:
DokuMyBB.zip 27.7 kBytes
You have no permission to open this file.
Avatar
chuyskywalker #2
Member since Nov 2008 · 1 post
Group memberships: Members
Show profile · Link to this post
This script made some assumptions that were incorrect:

1) The script assumes that column values come out in the same order always when selecting on *. This is not always so.
2) The script only gives out doku permissions for the mybb user's primary group -- however, mybb users can be part of multiple groups.

I have fixed both issues.

I didn't do a very thorough fix though, you could further clean up the SQL queries to be ultra specific, but I wasn't bothered by that for now.

<?php
/**
 * MyBB auth backend
 *
 * Bridges user login with MyBB database.
 *
 */
 
define('TABLE_PREFIX', '');
define('DB_HOST', 'localhost');
define('DB_USER', '');
define('DB_PWD', '');
define('DB_NAME', '');

define('DOKU_AUTH', dirname(__FILE__));
require_once(DOKU_AUTH.'/basic.class.php');

class auth_mybb extends auth_basic
{
    //Link to database's resource connection
    var $link;
   
    //Usergroup conversion rules
    var $rules = array(
        "4" => array("admin", "user"),
        "default" => array("user")
    );
   
    //The constructor
    function auth_mybb()
    {
        $this->link = mysql_connect(DB_HOST, DB_USER, DB_PWD) or die('Connection to MySQL Server failed');
        mysql_select_db(DB_NAME, $this->link) or die('Select Database failed');
        $this->success = true;
    }
   
    //Check if an user exists and if a password is exact [OVERRIDEN]
    function checkPass($user, $pass)
    {
        $q = mysql_query("SELECT * FROM ".TABLE_PREFIX."users WHERE username='$user' LIMIT 0,1", $this->link);
        $r = mysql_fetch_assoc($q);
        if($r['password'] == $this->mybb_psw($pass, $r['salt'])) return true;
        return false;
    }
   
    //Generate MyBB's Password Hash
    function mybb_psw($password, $salt)
    {
        $password = md5($password);
        return md5(md5($salt).$password);
    }
   
    //Get user data [OVERRIDEN]
    function getUserData($user)
    {
        $q = mysql_query("SELECT * FROM ".TABLE_PREFIX."users WHERE username='$user' LIMIT 0,1", $this->link);
        $r = mysql_fetch_assoc($q);
        $retn = array('name' => $r['username'], 'mail' => $r['email'], 'grps' => $this->mybb_2_dw_usergroups($r['usergroup'],$r['additionalgroups']));
        return $retn;
    }
   
    //Function for converting mybb usergroups to DokuWiki usergroups
    function mybb_2_dw_usergroups($usergroup, $additional_groups)
    {
        // a user could have multiple groups which could end up mappig to multiple doku permission sets
        if( ! empty($additional_groups) )
        {
            $groups = explode(',', $usergroup .','. $additional_groups);
        }
        else
        {
            $groups = array($usergroup);
        }       
        $doku_groups = array();
        foreach( $groups as $mybb_group_id )
        {
            if(isset($this->rules[$mybb_group_id]))
            {
                foreach($this->rules[$mybb_group_id] as $target_group)
                {
                    $doku_groups[] = $target_group;
                }
            }
        }       
        // return the unique set of groups or the default values
        if(count($doku_groups))
        {
            return array_unique($doku_groups);
        }
        else
        {
            return $this->rules["default"];
        }       
    }
}

?>
Avatar
Bart #3
Member since Feb 2011 · 3 posts
Group memberships: Members
Show profile · Link to this post
Hi,

I just wanted to bump this article and plugin ;)

This authentication plugin works for MyBB 1.6.x as well. Given that you use the modified code by chuyskywalker. (though I guess the original post will also work)

Setting it up is really easy, it's done in three steps:

1) Modify the mybb.class.php file. Add the proper database settings.

2) Upload mybb.class.php to the following directory:

    /inc/auth/

3) In the admin screen you then set the authentication method to mybb.

And your done, from that moment on you'll need to login with a MyBB user. The old dw users won't be working anymore. (thus the MyBB admin will become admin)

This part of the script is very interesting:

    //Usergroup conversion rules
    var $rules = array(
        "4" => array("admin", "user"),
        "default" => array("user")
    );

In my case I've created a group inside MyBB called "dw", in my case I want to have some form of control over who gets to write on the wiki and who doesn't.

As you can see in the code, number 4 is given admin and user rights. I guess only admin would suffice, but it works so no worries. The second one gives the default MyBB group (usually registered users) user rights. Which by default means that you get upload privileges but no delete privileges.

The new group that I've created was actually the first new group to MyBB so the number to that is number 8. When your inside MyBB looking at all the groups in a table view then you can count the rows to figure out the number, if your on the right screen then you'll see that number 4 is the admin user and number 8 in my case the new custom group.

In my case the code now looks like this:

    //Usergroup conversion rules
    var $rules = array(
        "4" => array("admin", "user"),
        "8" => array("user")
    );

Which means that default users only get read rights and people that were manually added to the dw group get upload rights.

I.m.h.o. a nice way of securing access to your wiki :)

Thanks for the plugin, much appreciated.

Best regards,

Bart
Avatar
breaker27 #4
Member since Oct 2013 · 1 post
Group memberships: Members
Show profile · Link to this post
I tried this plugin today and it worked very well.

But I also wanted to update to the newest "weatherwax" version of DokuWiki.

As it seems, the auth mechanisms have been reworked and this plugin does not work anymore. :-(

What can I do now to have the same mechanism (users get access by having a myBB account)?
Seems I have to stay on the old DokuWiki version a little longer. :(
Avatar
pxwee5 #5
Member since Aug 2014 · 9 posts
Group memberships: Members
Show profile · Link to this post
MyBB is releasing their latest forum MyBB 1.8 in this or next week.

Any plans to support the integration?
Avatar
Klap-in #6
Member since Nov 2009 · 239 posts · Location: Alkmaar, The Netherlands
Group memberships: Documentation Team, Members
Show profile · Link to this post
To clear my mind: MyBB is something different then phpBB, isn't?

For phpBB there's already a new style auth plugin.
https://www.dokuwiki.org/plugin:authphpbb3

You need someone who will be able to create such auth plugin from the old MyBB dokuwiki backend. Often many bits are reusable.
This post was edited on 2014-08-31, 16:15 by Klap-in.
Avatar
Klap-in #7
Member since Nov 2009 · 239 posts · Location: Alkmaar, The Netherlands
Group memberships: Documentation Team, Members
Show profile · Link to this post
More info about creating such new style auth plugin can be found in the docs:
https://www.dokuwiki.org/devel:auth_plugins
Also some tips for porting the old auth backends are provided.
Avatar
sioc #8
Member since Dec 2015 · 3 posts
Group memberships: Members
Show profile · Link to this post
succeed to auth with mybb 1.8.12 cf. https://forum.dokuwiki.org/post/57608
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2018-12-16, 15:02:57 (UTC +01:00)