13ff230f7SMatthias Grimm<?php 23ff230f7SMatthias Grimm/* 301fb97e2SAnika Henke * This is an example configuration for the mysql auth plugin. 4a771ad3aSmatthiasgrimm * 5a771ad3aSmatthiasgrimm * This SQL statements are optimized for following table structure. 6a771ad3aSmatthiasgrimm * If you use a different one you have to change them accordingly. 7a771ad3aSmatthiasgrimm * See comments of every statement for details. 8a771ad3aSmatthiasgrimm * 9a771ad3aSmatthiasgrimm * TABLE users 10a771ad3aSmatthiasgrimm * uid login pass firstname lastname email 11a771ad3aSmatthiasgrimm * 12a771ad3aSmatthiasgrimm * TABLE groups 13a771ad3aSmatthiasgrimm * gid name 14a771ad3aSmatthiasgrimm * 15a771ad3aSmatthiasgrimm * TABLE usergroup 16a771ad3aSmatthiasgrimm * uid gid 17a771ad3aSmatthiasgrimm * 18bc87043bSAndreas Gohr * To use this configuration you have to copy them to local.protected.php 19bc87043bSAndreas Gohr * or at least include this file in local.protected.php. 203ff230f7SMatthias Grimm */ 213ff230f7SMatthias Grimm 22a771ad3aSmatthiasgrimm/* Options to configure database access. You need to set up this 23a771ad3aSmatthiasgrimm * options carefully, otherwise you won't be able to access you 24a771ad3aSmatthiasgrimm * database. 25a771ad3aSmatthiasgrimm */ 2601fb97e2SAnika Henke$conf['plugin']['authmysql']['server'] = ''; 2701fb97e2SAnika Henke$conf['plugin']['authmysql']['user'] = ''; 2801fb97e2SAnika Henke$conf['plugin']['authmysql']['password'] = ''; 2901fb97e2SAnika Henke$conf['plugin']['authmysql']['database'] = ''; 303ff230f7SMatthias Grimm 3101fb97e2SAnika Henke/* This option enables debug messages in the mysql plugin. It is 3201fb97e2SAnika Henke * mostly useful for system admins. 33dfdd92d5Smatthiasgrimm */ 3401fb97e2SAnika Henke$conf['plugin']['authmysql']['debug'] = 0; 35dfdd92d5Smatthiasgrimm 363ff230f7SMatthias Grimm/* Normally password encryption is done by DokuWiki (recommended) but for 37*9612843eSAndrew Dawes * some reasons it might be useful to let the database do the encryption. 3824bc1a35Smatthiasgrimm * Set 'forwardClearPass' to '1' and the cleartext password is forwarded to 393ff230f7SMatthias Grimm * the database, otherwise the encrypted one. 403ff230f7SMatthias Grimm */ 4101fb97e2SAnika Henke$conf['plugin']['authmysql']['forwardClearPass'] = 0; 423ff230f7SMatthias Grimm 43*9612843eSAndrew Dawes/* Multiple table operations will be protected by locks. This array tells 4401fb97e2SAnika Henke * the plugin which tables to lock. If you use any aliases for table names 45*9612843eSAndrew Dawes * these array must also contain these aliases. Any unnamed alias will cause 46a771ad3aSmatthiasgrimm * a warning during operation. See the example below. 473ff230f7SMatthias Grimm */ 4801fb97e2SAnika Henke$conf['plugin']['authmysql']['TablesToLock']= array("users", "users AS u","groups", "groups AS g", "usergroup", "usergroup AS ug"); 493ff230f7SMatthias Grimm 5024bc1a35Smatthiasgrimm/***********************************************************************/ 5124bc1a35Smatthiasgrimm/* Basic SQL statements for user authentication (required) */ 5224bc1a35Smatthiasgrimm/***********************************************************************/ 533ff230f7SMatthias Grimm 5424bc1a35Smatthiasgrimm/* This statement is used to grant or deny access to the wiki. The result 5524bc1a35Smatthiasgrimm * should be a table with exact one line containing at least the password 5624bc1a35Smatthiasgrimm * of the user. If the result table is empty or contains more than one 5724bc1a35Smatthiasgrimm * row, access will be denied. 5824bc1a35Smatthiasgrimm * 592cabdb62SRainbow Spike * The plugin accesses the password as 'pass' so an alias might be necessary. 6024bc1a35Smatthiasgrimm * 6124bc1a35Smatthiasgrimm * Following patters will be replaced: 62a771ad3aSmatthiasgrimm * %{user} user name 63a771ad3aSmatthiasgrimm * %{pass} encrypted or clear text password (depends on 'encryptPass') 64a771ad3aSmatthiasgrimm * %{dgroup} default group name 653ff230f7SMatthias Grimm */ 6601fb97e2SAnika Henke$conf['plugin']['authmysql']['checkPass'] = "SELECT pass 673ff230f7SMatthias Grimm FROM usergroup AS ug 683ff230f7SMatthias Grimm JOIN users AS u ON u.uid=ug.uid 693ff230f7SMatthias Grimm JOIN groups AS g ON g.gid=ug.gid 70a771ad3aSmatthiasgrimm WHERE login='%{user}' 71a771ad3aSmatthiasgrimm AND name='%{dgroup}'"; 723ff230f7SMatthias Grimm 7324bc1a35Smatthiasgrimm/* This statement should return a table with exact one row containing 7424bc1a35Smatthiasgrimm * information about one user. The field needed are: 7524bc1a35Smatthiasgrimm * 'pass' containing the encrypted or clear text password 7624bc1a35Smatthiasgrimm * 'name' the user's full name 7724bc1a35Smatthiasgrimm * 'mail' the user's email address 7824bc1a35Smatthiasgrimm * 79*9612843eSAndrew Dawes * Keep in mind that Dokuwiki will access this information through the 80*9612843eSAndrew Dawes * names listed above so aliases might be necessary. 8124bc1a35Smatthiasgrimm * 8224bc1a35Smatthiasgrimm * Following patters will be replaced: 8324bc1a35Smatthiasgrimm * %{user} user name 8424bc1a35Smatthiasgrimm */ 8501fb97e2SAnika Henke$conf['plugin']['authmysql']['getUserInfo'] = "SELECT pass, CONCAT(firstname,' ',lastname) AS name, email AS mail 8624bc1a35Smatthiasgrimm FROM users 8724bc1a35Smatthiasgrimm WHERE login='%{user}'"; 8824bc1a35Smatthiasgrimm 8924bc1a35Smatthiasgrimm/* This statement is used to get all groups a user is member of. The 9024bc1a35Smatthiasgrimm * result should be a table containing all groups the given user is 9101fb97e2SAnika Henke * member of. The plugin accesses the group name as 'group' so an alias 92*9612843eSAndrew Dawes * might be necessary. 9324bc1a35Smatthiasgrimm * 9424bc1a35Smatthiasgrimm * Following patters will be replaced: 95a771ad3aSmatthiasgrimm * %{user} user name 9675bfc19cSMatthias Grimm */ 9701fb97e2SAnika Henke$conf['plugin']['authmysql']['getGroups'] = "SELECT name as `group` 983ff230f7SMatthias Grimm FROM groups g, users u, usergroup ug 993ff230f7SMatthias Grimm WHERE u.uid = ug.uid 1003ff230f7SMatthias Grimm AND g.gid = ug.gid 101a771ad3aSmatthiasgrimm AND u.login='%{user}'"; 10275bfc19cSMatthias Grimm 10324bc1a35Smatthiasgrimm/***********************************************************************/ 10424bc1a35Smatthiasgrimm/* Additional minimum SQL statements to use the user manager */ 10524bc1a35Smatthiasgrimm/***********************************************************************/ 10675bfc19cSMatthias Grimm 10724bc1a35Smatthiasgrimm/* This statement should return a table containing all user login names 10824bc1a35Smatthiasgrimm * that meet certain filter criteria. The filter expressions will be added 109*9612843eSAndrew Dawes * case dependent by the plugin. At the end a sort expression will be added. 1102cabdb62SRainbow Spike * Important is that this list contains no double entries for a user. Each 11124bc1a35Smatthiasgrimm * user name is only allowed once in the table. 11224bc1a35Smatthiasgrimm * 113*9612843eSAndrew Dawes * The login name will be accessed as 'user' to an alias might be necessary. 11424bc1a35Smatthiasgrimm * No patterns will be replaced in this statement but following patters 11524bc1a35Smatthiasgrimm * will be replaced in the filter expressions: 116a771ad3aSmatthiasgrimm * %{user} in FilterLogin user's login name 117a771ad3aSmatthiasgrimm * %{name} in FilterName user's full name 118a771ad3aSmatthiasgrimm * %{email} in FilterEmail user's email address 119a771ad3aSmatthiasgrimm * %{group} in FilterGroup group name 12075bfc19cSMatthias Grimm */ 12101fb97e2SAnika Henke$conf['plugin']['authmysql']['getUsers'] = "SELECT DISTINCT login AS user 1223ff230f7SMatthias Grimm FROM users AS u 1233ff230f7SMatthias Grimm LEFT JOIN usergroup AS ug ON u.uid=ug.uid 1243ff230f7SMatthias Grimm LEFT JOIN groups AS g ON ug.gid=g.gid"; 12501fb97e2SAnika Henke$conf['plugin']['authmysql']['FilterLogin'] = "login LIKE '%{user}'"; 12601fb97e2SAnika Henke$conf['plugin']['authmysql']['FilterName'] = "CONCAT(firstname,' ',lastname) LIKE '%{name}'"; 12701fb97e2SAnika Henke$conf['plugin']['authmysql']['FilterEmail'] = "email LIKE '%{email}'"; 12801fb97e2SAnika Henke$conf['plugin']['authmysql']['FilterGroup'] = "name LIKE '%{group}'"; 12901fb97e2SAnika Henke$conf['plugin']['authmysql']['SortOrder'] = "ORDER BY login"; 1303ff230f7SMatthias Grimm 13124bc1a35Smatthiasgrimm/***********************************************************************/ 13224bc1a35Smatthiasgrimm/* Additional SQL statements to add new users with the user manager */ 13324bc1a35Smatthiasgrimm/***********************************************************************/ 13424bc1a35Smatthiasgrimm 13524bc1a35Smatthiasgrimm/* This statement should add a user to the database. Minimum information 13624bc1a35Smatthiasgrimm * to store are: login name, password, email address and full name. 13724bc1a35Smatthiasgrimm * 13875bfc19cSMatthias Grimm * Following patterns will be replaced: 139a771ad3aSmatthiasgrimm * %{user} user's login name 140a771ad3aSmatthiasgrimm * %{pass} password (encrypted or clear text, depends on 'encryptPass') 141a771ad3aSmatthiasgrimm * %{email} email address 142a771ad3aSmatthiasgrimm * %{name} user's full name 14375bfc19cSMatthias Grimm */ 14401fb97e2SAnika Henke$conf['plugin']['authmysql']['addUser'] = "INSERT INTO users 1453ff230f7SMatthias Grimm (login, pass, email, firstname, lastname) 146a771ad3aSmatthiasgrimm VALUES ('%{user}', '%{pass}', '%{email}', 147a771ad3aSmatthiasgrimm SUBSTRING_INDEX('%{name}',' ', 1), 148a771ad3aSmatthiasgrimm SUBSTRING_INDEX('%{name}',' ', -1))"; 14975bfc19cSMatthias Grimm 15024bc1a35Smatthiasgrimm/* This statement should add a group to the database. 15124bc1a35Smatthiasgrimm * Following patterns will be replaced: 15224bc1a35Smatthiasgrimm * %{group} group name 15324bc1a35Smatthiasgrimm */ 15401fb97e2SAnika Henke$conf['plugin']['authmysql']['addGroup'] = "INSERT INTO groups (name) 15524bc1a35Smatthiasgrimm VALUES ('%{group}')"; 15624bc1a35Smatthiasgrimm 15724bc1a35Smatthiasgrimm/* This statement should connect a user to a group (a user become member 15824bc1a35Smatthiasgrimm * of that group). 15924bc1a35Smatthiasgrimm * Following patterns will be replaced: 16024bc1a35Smatthiasgrimm * %{user} user's login name 16124bc1a35Smatthiasgrimm * %{uid} id of a user dataset 16224bc1a35Smatthiasgrimm * %{group} group name 16324bc1a35Smatthiasgrimm * %{gid} id of a group dataset 16424bc1a35Smatthiasgrimm */ 16501fb97e2SAnika Henke$conf['plugin']['authmysql']['addUserGroup']= "INSERT INTO usergroup (uid, gid) 16624bc1a35Smatthiasgrimm VALUES ('%{uid}', '%{gid}')"; 16724bc1a35Smatthiasgrimm 16824bc1a35Smatthiasgrimm/* This statement should remove a group fom the database. 16924bc1a35Smatthiasgrimm * Following patterns will be replaced: 17024bc1a35Smatthiasgrimm * %{group} group name 17124bc1a35Smatthiasgrimm * %{gid} id of a group dataset 17224bc1a35Smatthiasgrimm */ 17301fb97e2SAnika Henke$conf['plugin']['authmysql']['delGroup'] = "DELETE FROM groups 17424bc1a35Smatthiasgrimm WHERE gid='%{gid}'"; 17524bc1a35Smatthiasgrimm 17624bc1a35Smatthiasgrimm/* This statement should return the database index of a given user name. 1772cabdb62SRainbow Spike * The plugin will access the index with the name 'id' so an alias might be 17824bc1a35Smatthiasgrimm * necessary. 17924bc1a35Smatthiasgrimm * following patters will be replaced: 18024bc1a35Smatthiasgrimm * %{user} user name 18124bc1a35Smatthiasgrimm */ 18201fb97e2SAnika Henke$conf['plugin']['authmysql']['getUserID'] = "SELECT uid AS id 18324bc1a35Smatthiasgrimm FROM users 18424bc1a35Smatthiasgrimm WHERE login='%{user}'"; 18524bc1a35Smatthiasgrimm 18624bc1a35Smatthiasgrimm/***********************************************************************/ 18724bc1a35Smatthiasgrimm/* Additional SQL statements to delete users with the user manager */ 18824bc1a35Smatthiasgrimm/***********************************************************************/ 18924bc1a35Smatthiasgrimm 19024bc1a35Smatthiasgrimm/* This statement should remove a user fom the database. 19124bc1a35Smatthiasgrimm * Following patterns will be replaced: 19224bc1a35Smatthiasgrimm * %{user} user's login name 19324bc1a35Smatthiasgrimm * %{uid} id of a user dataset 19424bc1a35Smatthiasgrimm */ 19501fb97e2SAnika Henke$conf['plugin']['authmysql']['delUser'] = "DELETE FROM users 19624bc1a35Smatthiasgrimm WHERE uid='%{uid}'"; 19724bc1a35Smatthiasgrimm 19824bc1a35Smatthiasgrimm/* This statement should remove all connections from a user to any group 19924bc1a35Smatthiasgrimm * (a user quits membership of all groups). 20024bc1a35Smatthiasgrimm * Following patterns will be replaced: 20124bc1a35Smatthiasgrimm * %{uid} id of a user dataset 20224bc1a35Smatthiasgrimm */ 20301fb97e2SAnika Henke$conf['plugin']['authmysql']['delUserRefs'] = "DELETE FROM usergroup 20424bc1a35Smatthiasgrimm WHERE uid='%{uid}'"; 20524bc1a35Smatthiasgrimm 20624bc1a35Smatthiasgrimm/***********************************************************************/ 20724bc1a35Smatthiasgrimm/* Additional SQL statements to modify users with the user manager */ 20824bc1a35Smatthiasgrimm/***********************************************************************/ 20924bc1a35Smatthiasgrimm 21024bc1a35Smatthiasgrimm/* This statements should modify a user entry in the database. The 21124bc1a35Smatthiasgrimm * statements UpdateLogin, UpdatePass, UpdateEmail and UpdateName will be 21224bc1a35Smatthiasgrimm * added to updateUser on demand. Only changed parameters will be used. 21324bc1a35Smatthiasgrimm * 214dfdd92d5Smatthiasgrimm * Following patterns will be replaced: 215dfdd92d5Smatthiasgrimm * %{user} user's login name 216dfdd92d5Smatthiasgrimm * %{pass} password (encrypted or clear text, depends on 'encryptPass') 217dfdd92d5Smatthiasgrimm * %{email} email address 218dfdd92d5Smatthiasgrimm * %{name} user's full name 219dfdd92d5Smatthiasgrimm * %{uid} user id that should be updated 220dfdd92d5Smatthiasgrimm */ 22101fb97e2SAnika Henke$conf['plugin']['authmysql']['updateUser'] = "UPDATE users SET"; 22201fb97e2SAnika Henke$conf['plugin']['authmysql']['UpdateLogin'] = "login='%{user}'"; 22301fb97e2SAnika Henke$conf['plugin']['authmysql']['UpdatePass'] = "pass='%{pass}'"; 22401fb97e2SAnika Henke$conf['plugin']['authmysql']['UpdateEmail'] = "email='%{email}'"; 22501fb97e2SAnika Henke$conf['plugin']['authmysql']['UpdateName'] = "firstname=SUBSTRING_INDEX('%{name}',' ', 1), 226dfdd92d5Smatthiasgrimm lastname=SUBSTRING_INDEX('%{name}',' ', -1)"; 22701fb97e2SAnika Henke$conf['plugin']['authmysql']['UpdateTarget']= "WHERE uid=%{uid}"; 228dfdd92d5Smatthiasgrimm 22975bfc19cSMatthias Grimm/* This statement should remove a single connection from a user to a 23075bfc19cSMatthias Grimm * group (a user quits membership of that group). 23124bc1a35Smatthiasgrimm * 23275bfc19cSMatthias Grimm * Following patterns will be replaced: 233a771ad3aSmatthiasgrimm * %{user} user's login name 234a771ad3aSmatthiasgrimm * %{uid} id of a user dataset 235a771ad3aSmatthiasgrimm * %{group} group name 236a771ad3aSmatthiasgrimm * %{gid} id of a group dataset 23775bfc19cSMatthias Grimm */ 23801fb97e2SAnika Henke$conf['plugin']['authmysql']['delUserGroup']= "DELETE FROM usergroup 239a771ad3aSmatthiasgrimm WHERE uid='%{uid}' 240a771ad3aSmatthiasgrimm AND gid='%{gid}'"; 24175bfc19cSMatthias Grimm 24224bc1a35Smatthiasgrimm/* This statement should return the database index of a given group name. 2432cabdb62SRainbow Spike * The plugin will access the index with the name 'id' so an alias might 24424bc1a35Smatthiasgrimm * be necessary. 24524bc1a35Smatthiasgrimm * 24624bc1a35Smatthiasgrimm * Following patters will be replaced: 24724bc1a35Smatthiasgrimm * %{group} group name 24875bfc19cSMatthias Grimm */ 24901fb97e2SAnika Henke$conf['plugin']['authmysql']['getGroupID'] = "SELECT gid AS id 25024bc1a35Smatthiasgrimm FROM groups 25124bc1a35Smatthiasgrimm WHERE name='%{group}'"; 25224bc1a35Smatthiasgrimm 253a771ad3aSmatthiasgrimm 254