Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

#1 2014-04-10 01:16:21

oli_v_ier
Member
Registered: 2008-09-21
Posts: 47

Dokuwiki integration with MySQL Authentication Backend

Hello,

FluxBB doesn't appear in the list of the forum in this page (Real World examples) :
https://www.dokuwiki.org/plugin:authmysql

I'm trying to use the fluxBB's user database with the last version of dokuwiki (2013-12-08 "Binky"), I cannot use this solution anymore.

The goal is to adapt this file : https://github.com/splitbrain/dokuwiki/ … hp.example to fluxBB database structure.

Can someone help me please ?

Offline

#2 2014-04-10 01:20:05

oli_v_ier
Member
Registered: 2008-09-21
Posts: 47

Re: Dokuwiki integration with MySQL Authentication Backend

Ps : If possible I'd like to use fluxBB's global variable in the file mysql.conf.php so I won't have the access codes in two different files (in a wiki file and forum file).

smile

Offline

#3 2014-04-11 00:29:57

oli_v_ier
Member
Registered: 2008-09-21
Posts: 47

Re: Dokuwiki integration with MySQL Authentication Backend

How to adapt the 3 statements below to fluxbb database structure ?

* This SQL statements are optimized for following table structure.
* If you use a different one you have to change them accordingly.
* See comments of every statement for details.
*
* TABLE users
*     uid   login   pass   firstname   lastname   email
*
* TABLE groups
*     gid   name
*
* TABLE usergroup
*     uid   gid

Statement 1
/* This statement is used to grant or deny access to the wiki. The result
 * should be a table with exact one line containing at least the password
 * of the user. If the result table is empty or contains more than one
 * row, access will be denied.
 *
 * The plugin accesses the password as 'pass' so a alias might be necessary.
 *
 * Following patters will be replaced:
 *   %{user}    user name
 *   %{pass}    encrypted or clear text password (depends on 'encryptPass')
 *   %{dgroup}  default group name
 */
$conf['plugin']['authmysql']['checkPass']   = "SELECT pass
                                               FROM usergroup AS ug
                                               JOIN users AS u ON u.uid=ug.uid
                                               JOIN groups AS g ON g.gid=ug.gid
                                               WHERE login='%{user}'
                                               AND name='%{dgroup}'";
Statement 2
/* This statement should return a table with exact one row containing
 * information about one user. The field needed are:
 * 'pass'  containing the encrypted or clear text password
 * 'name'  the user's full name
 * 'mail'  the user's email address
 *
 * Keep in mind that Dokuwiki will access thise information through the
 * names listed above so aliasses might be neseccary.
 *
 * Following patters will be replaced:
 *   %{user}    user name
 */
$conf['plugin']['authmysql']['getUserInfo'] = "SELECT pass, CONCAT(firstname,' ',lastname) AS name, email AS mail
                                               FROM users
                                               WHERE login='%{user}'";
Statement 3
/* This statement is used to get all groups a user is member of. The
 * result should be a table containing all groups the given user is
 * member of. The plugin accesses the group name as 'group' so an alias
 * might be nessecary.
 *
 * Following patters will be replaced:
 *   %{user}    user name
 */
$conf['plugin']['authmysql']['getGroups']   = "SELECT name as `group`
                                               FROM groups g, users u, usergroup ug
                                               WHERE u.uid = ug.uid
                                               AND g.gid = ug.gid
                                               AND u.login='%{user}'";

Offline

#4 2014-04-19 15:32:54

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,719
Website

Re: Dokuwiki integration with MySQL Authentication Backend

Here's the auth plugin we use on this site:

<?php
// Must be run within Dokuwiki
if (!defined('DOKU_INC')) die();


/**
 * FluxBB auth backend
 *
 * Check against FluxBB's user cookie.
 * Note that PUN_ROOT must be defined correctly.
 *
 * @author    Franz Liedke <franz@fluxbb.org>
 * @author    Andreas Gohr <andi@splitbrain.org>
 */
class auth_plugin_authfluxbb extends DokuWiki_Auth_Plugin {

  /**
   * Constructor.
   *
   * Sets additional capabilities and config strings.
   */
  function __construct()
  {
    parent::__construct();

    $this->cando['addUser']      = false;
    $this->cando['delUser']      = false;
    $this->cando['modLogin']     = false;
    $this->cando['modPass']      = false;
    $this->cando['modName']      = false;
    $this->cando['modMail']      = false;
    $this->cando['modGroups']    = false;
    $this->cando['getUsers']     = false;
    $this->cando['getUserCount'] = false;
    $this->cando['getGroups']    = false;
    $this->cando['external']     = true;
    $this->cando['logout']       = false;

    // The auth system was successfully initialized.
    $this->success = true;
  }

  /**
   * Do all authentication against the external provider.
   *
   * @param  string  $user
   * @param  string  $pass
   * @param  bool    $sticky
   * @return bool
   */
  function trustExternal($user, $pass, $sticky = false)
  {
    global $USERINFO;
    global $conf;
    global $lang;
    global $pun_user;
    global $pun_config;
    global $cookie_name;

    if (isset($pun_user) && !$pun_user['is_guest'] && ($pun_user['is_admmod'] || $pun_user['num_posts'] >= 10))
    {
      // We're logged in - set the globals
      $USERINFO['pass'] = $pun_user['password'];
      $USERINFO['name'] = utf8_encode($pun_user['realname']);
      $USERINFO['mail'] = $pun_user['email'];
      $USERINFO['grps'] = array($pun_user['g_title']);

      if ($pun_user['is_admmod'])
        $USERINFO['grps'][] = 'admin';

      $_SERVER['REMOTE_USER'] = $pun_user['username'];
      $_SESSION[DOKU_COOKIE]['auth']['user'] = $pun_user['username'];
      $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO;
      return true;
    }

    // Make sure we're really logged off.
    auth_logoff();

    $USERINFO['grps'] = array();
    return false;
  }

  /**
   * Return case sensitivity of the backend
   *
   * @return bool
   */
  function isCaseSensitive()
  {
    return false;
  }

}

fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#5 2014-10-30 18:25:53

elodie
Member
Registered: 2013-06-01
Posts: 6

Re: Dokuwiki integration with MySQL Authentication Backend

Hello Franz smile

I'm using the last version or you auth plugin since several months without any problem.

Today, I try to makes working your auth plugin with the version 2014-09-29a "Hrun" of DokuWiki and it's don't work anymore.

I have created a folder "/wiki" and "/wiki2" with the new Dokuwiki without change nothing to my FluxBB ... only the folder name of DokuWiki is changed and i have replaced the old files of Doku with the new one inside "/wiki2". It's not my first update (i'm using your plugin since several years) but currently i don't find the problem.

Could you check if the current version of your plugin is working with the new version of DokuWiki please ?

Best regards,
Élodie

Offline

#6 2014-10-31 09:32:49

adaur
Developer
From: France
Registered: 2010-01-07
Posts: 843
Website

Re: Dokuwiki integration with MySQL Authentication Backend

Hi élodie,

My Hrun wiki is working fine using this file:

<?php
/**
 * FluxBB auth backend
 *
 * Uses external Trust mechanism to check against FluxBB's
 * user cookie. FluxBB's PUN_ROOT must be defined correctly.
 *
 * @author    Andreas Gohr <andi@splitbrain.org>
 */
#dbg($GLOBALS);
#dbg($forum_user);

class auth_plugin_authfluxbb extends DokuWiki_Auth_Plugin {

  /**
   * Constructor.
   *
   * Sets additional capabilities and config strings
   */
  public function __construct() {
        parent::__construct();
    global $conf;
    $this->cando['external'] = true;

    $conf['passcrypt'] = 'sha1';

    // get global vars from fluxbb config
    global $db_host;
    global $db_name;
    global $db_username;
    global $db_password;
    global $db_prefix;

    // now set up the mysql config strings
    $conf['auth']['mysql']['server']   = $db_host;
    $conf['auth']['mysql']['user']     = $db_username;
    $conf['auth']['mysql']['password'] = $db_password;
    $conf['auth']['mysql']['database'] = $db_name;

    $conf['auth']['mysql']['checkPass']   = "SELECT u.password AS pass
                                               FROM ${db_prefix}users AS u, ${db_prefix}groups AS g
                                              WHERE u.group_id = g.g_id
                                                AND u.username = '%{user}'
                                                AND g.g_title   != 'Guest'";
    $conf['auth']['mysql']['getUserInfo'] = "SELECT password AS pass, realname AS name, email AS mail,
                                                    id, g_title as `group`
                                               FROM ${db_prefix}users AS u, ${db_prefix}groups AS g
                                              WHERE u.group_id = g.g_id
                                                AND u.username = '%{user}'";
    $conf['auth']['mysql']['getGroups']   = "SELECT g.g_title as `group`
                                               FROM ${db_prefix}users AS u, ${db_prefix}groups AS g
                                              WHERE u.group_id = g.g_id
                                                AND u.username = '%{user}'";
    $conf['auth']['mysql']['getUsers']    = "SELECT DISTINCT u.username AS user
                                               FROM ${db_prefix}users AS u, ${db_prefix}groups AS g
                                              WHERE u.group_id = g.g_id";
    $conf['auth']['mysql']['FilterLogin'] = "u.username LIKE '%{user}'";
    $conf['auth']['mysql']['FilterName']  = "u.realname LIKE '%{name}'";
    $conf['auth']['mysql']['FilterEmail'] = "u.email    LIKE '%{email}'";
    $conf['auth']['mysql']['FilterGroup'] = "g.g_title    LIKE '%{group}'";
    $conf['auth']['mysql']['SortOrder']   = "ORDER BY u.username";
    $conf['auth']['mysql']['addUser']     = "INSERT INTO ${db_prefix}users
                                                    (username, password, email, realname)
                                             VALUES ('%{user}', '%{pass}', '%{email}', '%{name}')";
    $conf['auth']['mysql']['addGroup']    = "INSERT INTO ${db_prefix}groups (g_title) VALUES ('%{group}')";
    $conf['auth']['mysql']['addUserGroup']= "UPDATE ${db_prefix}users
                                                SET group_id=%{gid}
                                              WHERE id='%{uid}'";
    $conf['auth']['mysql']['delGroup']    = "DELETE FROM ${db_prefix}groups WHERE g_id='%{gid}'";
    $conf['auth']['mysql']['getUserID']   = "SELECT id FROM ${db_prefix}users WHERE username='%{user}'";
    $conf['auth']['mysql']['updateUser']  = "UPDATE ${db_prefix}users SET";
    $conf['auth']['mysql']['UpdateLogin'] = "username='%{user}'";
    $conf['auth']['mysql']['UpdatePass']  = "password='%{pass}'";
    $conf['auth']['mysql']['UpdateEmail'] = "email='%{email}'";
    $conf['auth']['mysql']['UpdateName']  = "realname='%{name}'";
    $conf['auth']['mysql']['UpdateTarget']= "WHERE id=%{uid}";
    $conf['auth']['mysql']['delUserGroup']= "UPDATE ${db_prefix}users SET g_id=4 WHERE id=%{uid}";
    $conf['auth']['mysql']['getGroupID']  = "SELECT g_id AS id FROM ${db_prefix}groups WHERE g_title='%{group}'";

    $conf['auth']['mysql']['TablesToLock']= array("${db_prefix}users", "${db_prefix}users AS u",
                                                  "${db_prefix}groups", "${db_prefix}groups AS g");

    $conf['auth']['mysql']['debug'] = 1;
    // call mysql constructor
    parent::__construct();
  }

  /**
   * Just checks against the $forum_user variable
   */
  function trustExternal($user,$pass,$sticky=false){
    global $USERINFO;
    global $conf;
    global $lang;
    global $pun_user;
    global $pun_config;
    global $cookie_name;
    $sticky ? $sticky = true : $sticky = false; //sanity check

    if(isset($pun_user) && !$pun_user['is_guest']){
      // okay we're logged in - set the globals
      $USERINFO['pass'] = $pun_user['password'];
      $USERINFO['name'] = utf8_encode($pun_user['realname']);
      $USERINFO['mail'] = $pun_user['email'];
      $USERINFO['grps'] = array($pun_user['g_title']);
      if ($pun_user['is_admmod'])
        $USERINFO['grps'][] = 'admin';

      $_SERVER['REMOTE_USER'] = utf8_decode($pun_user['username']);
      $_SESSION[DOKU_COOKIE]['auth']['user'] = $pun_user['username'];
      $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO;
      return true;
    }

    // to be sure
    auth_logoff();

    $USERINFO['grps'] = array();
    return false;
  }
}
//Setup VIM: ex: et ts=2 enc=utf-8 :

(auth.php located in /lib/plugins/authfluxbb)

Then in /conf/local.protected.php

<?php
define('PUN_ROOT', dirname(__FILE__).'/../../pathtoyourforum/');
include PUN_ROOT.'include/common.php';
 
$conf['useacl'] = 1;
$conf['superuser'] = '@admin';
$conf['authtype'] = 'authfluxbb';

Cheers

adaur

Last edited by adaur (2014-11-10 21:33:24)


FeatherBB - A simple and lightweight new generation forum system
Based on FluxBB, written in PHP, using Slim Framework for a proper OOP-MVC architecture.

Offline

#7 2014-10-31 14:51:03

elodie
Member
Registered: 2013-06-01
Posts: 6

Re: Dokuwiki integration with MySQL Authentication Backend

Thanks so much adaur smile

Your code is working for me, i continue the integration of the new version inside my website, thanks again smile

Offline

#8 2014-11-06 18:08:47

brokenclouds
New member
Registered: 2014-11-06
Posts: 1

Re: Dokuwiki integration with MySQL Authentication Backend

Also a thank you to adaur from here.

One comment:  When defining the PUN_ROOT constant, it is advantageous to define the path using the absolute path of the script snippet. E.g.

<?php
define('PUN_ROOT', dirname(__FILE__).'/../../forum/');
include PUN_ROOT.'include/common.php';
 
$conf['useacl'] = 1;
$conf['defaultgroup'] = 'Members';
$conf['superuser'] = '@Administrators';
$conf['manager'] = '@Moderators';

Why?  Because "ACL management" and the upload feature of "Media Manager" breaks in DokuWiki if the path is given relatively.  At least, is does for me with the 2014-09-29a "Hrun" version of DokuWiki and FluxBB 1.5.7.

Anyway, thought it might be helpful for some. I just wasted more than an hour figuring out why it broke neutral

Offline

#9 2014-11-10 21:33:42

adaur
Developer
From: France
Registered: 2010-01-07
Posts: 843
Website

Re: Dokuwiki integration with MySQL Authentication Backend

I edited my post, thanks! smile


FeatherBB - A simple and lightweight new generation forum system
Based on FluxBB, written in PHP, using Slim Framework for a proper OOP-MVC architecture.

Offline

#10 2015-10-23 18:30:31

oli_v_ier
Member
Registered: 2008-09-21
Posts: 47

Re: Dokuwiki integration with MySQL Authentication Backend

Hi,

adaur wrote:

My Hrun wiki is working fine using this file: (...)

Is your Hrun still working with fluxBB 1.5.8 ?

I have a strange problem : if I put an 'include' function in local.protected.php, the images saved in /data/media/ don't show on my wiki pages.

Any idea how to solve this ?

Offline

#11 2015-10-24 00:54:19

oli_v_ier
Member
Registered: 2008-09-21
Posts: 47

Re: Dokuwiki integration with MySQL Authentication Backend

Solved. A whitespace at the beginning of file in /lang/ ...

Usefull script :

<?php
/**
 * This script will search all PHP files in the same directory
 * and below and will check for trailing or leading whitespaces
 * and UTF-8 BOMs
 */

header("Content-Type: text/plain");

echo "starting...\n";
flush();
traverse(dirname(__FILE__));
echo "finished...\n";

function traverse($dir){
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            //skip hidden files and upper dirs
            if(preg_match('/^[\._]/',$file)) continue;
            if(is_dir($dir.'/'.$file)){
                traverse($dir.'/'.$file);
                continue;
            }
            flush();

            if(!preg_match('/\.php$/',$file)) continue;
            $check = @file_get_contents("$dir/$file",0,null,0,3);
            if(!$check){
                echo "$dir/$file is not readable.\n";
                continue;
            }

            if($check == "\xef\xbb\xbf"){
                echo "$dir/$file has UTF-8 BOM at start.\n";
                continue;
            }

            if($check != '<?p'){
                echo "$dir/$file doesn't start with <?php\n";
                continue;
            }

            $check = file_get_contents("$dir/$file",0,null,
                                filesize("$dir/$file")-5,5);
            $pos = strpos($check, '?>');
            if($pos !== false && !(substr($check,-2) == '?>' || substr($check,-3) == "?>\n") ){
                echo "$dir/$file has trailing chars after closing ?>\n";
                continue;
            }
       }
       closedir($dh);
   }
}

Offline

Board footer

Powered by FluxBB