diff --git a/conf/local.php.dist b/conf/local.php.dist index bcbb19e638ae27eb5413e24dc8d7f4f147d9b2ca..53d7cc7201f063daee22e89fa42192ecb2a60546 100644 --- a/conf/local.php.dist +++ b/conf/local.php.dist @@ -10,3 +10,13 @@ $conf['title'] = 'My Wiki'; //what to show in the title $conf['useacl'] = 1; //Use Access Control Lists to restrict access? $conf['superuser'] = 'joe'; + +/* The following options are usefull, if you use a MySQL + * database as autentication backend. Have a look into + * mysql.conf.php too and adjust the options to match + * your database installation. + */ +$conf['authtype'] = 'mysql'; +require_once ("mysql.conf.php"); + + diff --git a/conf/mysql.conf.php.example b/conf/mysql.conf.php.example index ffe35c466aa41b3b93a1796eb94d05430b427540..fe0664903f0e2986926d0608bc12013fe42f4eab 100644 --- a/conf/mysql.conf.php.example +++ b/conf/mysql.conf.php.example @@ -1,24 +1,32 @@ <?php /* - This is an example configuration for the mysql auth module. - - 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 - - To use this configuration you have to copy them to local.php - or at least include this file in local.php. + * This is an example configuration for the mysql auth module. + * + * 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 + * + * To use this configuration you have to copy them to local.php + * or at least include this file in local.php. */ +/* Options to configure database access. You need to set up this + * options carefully, otherwise you won't be able to access you + * database. + */ +$conf['auth']['mysql']['server'] = ''; +$conf['auth']['mysql']['user'] = ''; +$conf['auth']['mysql']['password'] = ''; +$conf['auth']['mysql']['database'] = ''; /* Normally password encryptionis done by DokuWiki (recommended) but for * some reasons it might be usefull to let the database do the encryption. @@ -30,7 +38,7 @@ $conf['auth']['mysql']['encryptPass'] = 0; /* Multiple table operations will be protected by locks. This array tolds * the module which tables to lock. If you use any aliases for table names * these array must also contain these aliases. Any unamed alias will cause - * a warning suring operation. See the example below. + * a warning during operation. See the example below. */ $conf['auth']['mysql']['TablesToLock']= array("users", "users AS u","groups", "groups AS g", "usergroup", "usergroup AS ug"); @@ -38,45 +46,45 @@ $conf['auth']['mysql']['TablesToLock']= array("users", "users AS u","groups", "g * The module will access the index with the name 'id' so a alias might be * necessary. * following patters will be replaced: - * %u user name + * %{user} user name */ -$conf['auth']['mysql']['getUserID'] = "SELECT uid AS id FROM users WHERE login='%u'"; +$conf['auth']['mysql']['getUserID'] = "SELECT uid AS id FROM users WHERE login='%{user}'"; /* This statement should return the database index of a given group name. * The module will access the index with the name 'id' so a alias might be * necessary. * following patters will be replaced: - * %g group name + * %{group} group name */ -$conf['auth']['mysql']['getGroupID'] = "SELECT gid AS id FROM groups WHERE name='%g'"; +$conf['auth']['mysql']['getGroupID'] = "SELECT gid AS id FROM groups WHERE name='%{group}'"; /* 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 module access the password as 'pass' so a alias might be necessary. * following patters will be replaced: - * %u user name - * %p encrypted or clear text password (depends on 'encryptPass') - * %g default group name + * %{user} user name + * %{pass} encrypted or clear text password (depends on 'encryptPass') + * %{dgroup} default group name */ $conf['auth']['mysql']['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='%u' - AND name='%g'"; + WHERE login='%{user}' + AND name='%{dgroup}'"; /* 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 module access * the group name as 'group' so a alias might be nessecary. * following patters will be replaced: - * %u user name + * %{user} user name */ $conf['auth']['mysql']['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='%u'"; + AND u.login='%{user}'"; /* This statement should return a table with exact one row containing information * about one user. The field needed are: @@ -86,11 +94,11 @@ $conf['auth']['mysql']['getGroups'] = "SELECT name as `group` * Keep in mind that Dokuwiki will access thise information through the names * listed above so aliasses might be neseccary. * following patters will be replaced: - * %u user name + * %{user} user name */ $conf['auth']['mysql']['getUserInfo'] = "SELECT pass, CONCAT(firstname,' ',lastname) AS name, email AS mail FROM users - WHERE login='%u'"; + WHERE login='%{user}'"; /* This statement should return a table containing all user login names that meet * certain filter criteria. The filter expressions will be added case dependend by @@ -100,86 +108,86 @@ $conf['auth']['mysql']['getUserInfo'] = "SELECT pass, CONCAT(firstname,' ',lastn * The login name will be accessed as 'user' to a alias might be neseccary. * No patterns will be replaced in this statement but following patters will be * replaced in the filter expressions: - * %u in FilterLogin user's login name - * %n in FilterName user's full name - * %e in FilterEmail user's email address - * %g in FilterGroup group name + * %{user} in FilterLogin user's login name + * %{name} in FilterName user's full name + * %{email} in FilterEmail user's email address + * %{group} in FilterGroup group name */ $conf['auth']['mysql']['getUsers'] = "SELECT DISTINCT login AS user FROM users AS u LEFT JOIN usergroup AS ug ON u.uid=ug.uid LEFT JOIN groups AS g ON ug.gid=g.gid"; -$conf['auth']['mysql']['FilterLogin'] = "login LIKE '%u'"; -$conf['auth']['mysql']['FilterName'] = "CONCAT(firstname,' ',lastname) LIKE '%n'"; -$conf['auth']['mysql']['FilterEmail'] = "email LIKE '%e'"; -$conf['auth']['mysql']['FilterGroup'] = "name LIKE '%g'"; +$conf['auth']['mysql']['FilterLogin'] = "login LIKE '%{user}'"; +$conf['auth']['mysql']['FilterName'] = "CONCAT(firstname,' ',lastname) LIKE '%{name}'"; +$conf['auth']['mysql']['FilterEmail'] = "email LIKE '%{email}'"; +$conf['auth']['mysql']['FilterGroup'] = "name LIKE '%{group}'"; $conf['auth']['mysql']['SortOrder'] = "ORDER BY login"; /* This statement should add a user to the database. Minimum information to * store are: login name, password, email address and full name. * Following patterns will be replaced: - * %u user's login name - * %p password (encrypted or clear text, depends on 'encryptPass') - * %e email address - * %n user's full name + * %{user} user's login name + * %{pass} password (encrypted or clear text, depends on 'encryptPass') + * %{email} email address + * %{name} user's full name */ $conf['auth']['mysql']['addUser'] = "INSERT INTO users (login, pass, email, firstname, lastname) - VALUES ('%u', '%p', '%e', - SUBSTRING_INDEX('%n',' ', 1), - SUBSTRING_INDEX('%n',' ', -1))"; + VALUES ('%{user}', '%{pass}', '%{email}', + SUBSTRING_INDEX('%{name}',' ', 1), + SUBSTRING_INDEX('%{name}',' ', -1))"; /* This statement should remove a user fom the database. * Following patterns will be replaced: - * %u user's login name - * %uid id of a user dataset + * %{user} user's login name + * %{uid} id of a user dataset */ $conf['auth']['mysql']['delUser'] = "DELETE FROM users - WHERE uid='%uid'"; + WHERE uid='%{uid}'"; /* This statement should add a group to the database. * Following patterns will be replaced: - * %g group name + * %{group} group name */ $conf['auth']['mysql']['addGroup'] = "INSERT INTO groups (name) - VALUES ('%g')"; + VALUES ('%{group}')"; /* This statement should remove a group fom the database. * Following patterns will be replaced: - * %g group name - * %gid id of a group dataset + * %{group} group name + * %{gid} id of a group dataset */ $conf['auth']['mysql']['delGroup'] = "DELETE FROM groups - WHERE gid='%gid'"; + WHERE gid='%{gid}'"; /* This statement should connect a user to a group (a user become member * of that group). * Following patterns will be replaced: - * %u user's login name - * %uid id of a user dataset - * %g group name - * %gid id of a group dataset + * %{user} user's login name + * %{uid} id of a user dataset + * %{group} group name + * %{gid} id of a group dataset */ $conf['auth']['mysql']['addUserGroup']= "INSERT INTO usergroup (uid, gid) - VALUES ('%uid', '%gid')"; + VALUES ('%{uid}', '%{gid}')"; /* This statement should remove a single connection from a user to a * group (a user quits membership of that group). * Following patterns will be replaced: - * %u user's login name - * %uid id of a user dataset - * %g group name - * %gid id of a group dataset + * %{user} user's login name + * %{uid} id of a user dataset + * %{group} group name + * %{gid} id of a group dataset */ $conf['auth']['mysql']['delUserGroup']= "DELETE FROM usergroup - WHERE uid='%uid' - AND gid='%gid'"; + WHERE uid='%{uid}' + AND gid='%{gid}'"; /* This statement should remove all connections from a user to any group * (a user quits membership of all groups). * Following patterns will be replaced: - * %uid id of a user dataset + * %{uid} id of a user dataset */ $conf['auth']['mysql']['delUserRefs'] = "DELETE FROM usergroup - WHERE uid='%uid'"; -?> + WHERE uid='%{uid}'"; + diff --git a/inc/auth/mysql.class.php b/inc/auth/mysql.class.php index 5017d5b8388f6759320cc2d13003dfe99d1e9eed..41d45e940a963980ec49ef6d2e8dd365df2b7716 100644 --- a/inc/auth/mysql.class.php +++ b/inc/auth/mysql.class.php @@ -351,17 +351,17 @@ class auth_mysql extends auth_basic { function _addUserToGroup($user, $group, $force=0) { $newgroup = 0; - if($this->_dbcon) { + if($this->dbcon) { $uid = $this->_getUserID($user); if ($uid) { $gid = $this->_getGroupID($group); if (!$gid) { if ($force) { // create missing groups - $sql = str_replace('%g',addslashes($group),$this->cnf['addGroup']); + $sql = str_replace('%{group}',addslashes($group),$this->cnf['addGroup']); $gid = $this->_modifyDB($sql); $newgroup = 1; // group newly created } - if (!$gid) return false; // group didm't exist and can't be created + if (!$gid) return false; // group didn't exist and can't be created } $sql = str_replace('%{uid}', addslashes($uid),$this->cnf['addUserGroup']); @@ -396,8 +396,8 @@ class auth_mysql extends auth_basic { function _getGroups($user) { $groups = array(); - if($this->_dbcon) { - $sql = str_replace('%u',addslashes($user),$this->cnf['getGroups']); + if($this->dbcon) { + $sql = str_replace('%{user}',addslashes($user),$this->cnf['getGroups']); $result = $this->_queryDB($sql); if(count($result)) { @@ -422,8 +422,8 @@ class auth_mysql extends auth_basic { * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> */ function _getUserID($user) { - if($this->_dbcon) { - $sql = str_replace('%u',addslashes($user),$this->cnf['getUserID']); + if($this->dbcon) { + $sql = str_replace('%{user}',addslashes($user),$this->cnf['getUserID']); $result = $this->_queryDB($sql); return $result === false ? false : $result[0]['id']; } @@ -449,7 +449,7 @@ class auth_mysql extends auth_basic { * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> */ function _addUser($user,$pwd,$name,$mail,$grps){ - if($this->_dbcon && is_array($grps)) { + if($this->dbcon && is_array($grps)) { $sql = str_replace('%{user}', addslashes($user),$this->cnf['addUser']); $sql = str_replace('%{pass}', addslashes($pwd),$sql); $sql = str_replace('%{name}', addslashes($name),$sql); @@ -470,8 +470,8 @@ class auth_mysql extends auth_basic { * is not a big issue so we ignore this problem here. */ $this->_delUser($user); - $text = str_replace('%u',addslashes($user),$this->cnf['joinGroupFailed']); - $text = str_replace('%g',addslashes($group),$text); + $text = str_replace('%{user}',addslashes($user),$this->cnf['joinGroupFailed']); + $text = str_replace('%{group}',addslashes($group),$text); msg($text, -1); } } @@ -492,7 +492,7 @@ class auth_mysql extends auth_basic { * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> */ function _delUser($user) { - if($this->_dbcon) { + if($this->dbcon) { $uid = $this->_getUserID($user); if ($uid) { $sql = str_replace('%{uid}',addslashes($uid),$this->cnf['delUser']); @@ -673,7 +673,7 @@ class auth_mysql extends auth_basic { if ($cnt++ != 0) $sql .= ", "; $sql .= "$table $mode"; } - $this->modifyDB($sql); + $this->_modifyDB($sql); return true; } } @@ -689,7 +689,7 @@ class auth_mysql extends auth_basic { */ function _unlockTables() { if ($this->dbcon) { - $this->modifyDB("UNLOCK TABLES"); + $this->_modifyDB("UNLOCK TABLES"); return true; } return false;