xref: /dokuwiki/conf/mysql.conf.php.example (revision bc87043b7847c13380205af0accec67b3d7dc974)
13ff230f7SMatthias Grimm<?php
23ff230f7SMatthias Grimm/*
3a771ad3aSmatthiasgrimm * This is an example configuration for the mysql auth module.
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 *
18*bc87043bSAndreas Gohr * To use this configuration you have to copy them to local.protected.php
19*bc87043bSAndreas 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 */
26a771ad3aSmatthiasgrimm$conf['auth']['mysql']['server']   = '';
27a771ad3aSmatthiasgrimm$conf['auth']['mysql']['user']     = '';
28a771ad3aSmatthiasgrimm$conf['auth']['mysql']['password'] = '';
29a771ad3aSmatthiasgrimm$conf['auth']['mysql']['database'] = '';
303ff230f7SMatthias Grimm
31dfdd92d5Smatthiasgrimm/* This option enables debug messages in the mysql module. It is
32dfdd92d5Smatthiasgrimm * mostly usefull for system admins.
33dfdd92d5Smatthiasgrimm */
34dfdd92d5Smatthiasgrimm$conf['auth']['mysql']['debug'] = 0;
35dfdd92d5Smatthiasgrimm
363ff230f7SMatthias Grimm/* Normally password encryption is done by DokuWiki (recommended) but for
373ff230f7SMatthias Grimm * some reasons it might be usefull 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 */
4124bc1a35Smatthiasgrimm$conf['auth']['mysql']['forwardClearPass'] = 0;
423ff230f7SMatthias Grimm
433ff230f7SMatthias Grimm/* Multiple table operations will be protected by locks. This array tolds
443ff230f7SMatthias Grimm * the module which tables to lock. If you use any aliases for table names
453ff230f7SMatthias Grimm * these array must also contain these aliases. Any unamed alias will cause
46a771ad3aSmatthiasgrimm * a warning during operation. See the example below.
473ff230f7SMatthias Grimm */
483ff230f7SMatthias Grimm$conf['auth']['mysql']['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 *
593ff230f7SMatthias Grimm * The module access the password as 'pass' so a 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 */
663ff230f7SMatthias Grimm$conf['auth']['mysql']['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 *
7924bc1a35Smatthiasgrimm * Keep in mind that Dokuwiki will access thise information through the
8024bc1a35Smatthiasgrimm * names listed above so aliasses might be neseccary.
8124bc1a35Smatthiasgrimm *
8224bc1a35Smatthiasgrimm * Following patters will be replaced:
8324bc1a35Smatthiasgrimm *   %{user}    user name
8424bc1a35Smatthiasgrimm */
8524bc1a35Smatthiasgrimm$conf['auth']['mysql']['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
9124bc1a35Smatthiasgrimm * member of. The module access the group name as 'group' so a alias
9224bc1a35Smatthiasgrimm * might be nessecary.
9324bc1a35Smatthiasgrimm *
9424bc1a35Smatthiasgrimm * Following patters will be replaced:
95a771ad3aSmatthiasgrimm *   %{user}    user name
9675bfc19cSMatthias Grimm */
973ff230f7SMatthias Grimm$conf['auth']['mysql']['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
10924bc1a35Smatthiasgrimm * case dependend by the module. At the end a sort expression will be added.
11024bc1a35Smatthiasgrimm * Important is that this list contains no double entries fo a user. Each
11124bc1a35Smatthiasgrimm * user name is only allowed once in the table.
11224bc1a35Smatthiasgrimm *
11375bfc19cSMatthias Grimm * The login name will be accessed as 'user' to a alias might be neseccary.
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 */
1213ff230f7SMatthias Grimm$conf['auth']['mysql']['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";
125a771ad3aSmatthiasgrimm$conf['auth']['mysql']['FilterLogin'] = "login LIKE '%{user}'";
126a771ad3aSmatthiasgrimm$conf['auth']['mysql']['FilterName']  = "CONCAT(firstname,' ',lastname) LIKE '%{name}'";
127a771ad3aSmatthiasgrimm$conf['auth']['mysql']['FilterEmail'] = "email LIKE '%{email}'";
128a771ad3aSmatthiasgrimm$conf['auth']['mysql']['FilterGroup'] = "name LIKE '%{group}'";
1293ff230f7SMatthias Grimm$conf['auth']['mysql']['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 */
1443ff230f7SMatthias Grimm$conf['auth']['mysql']['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 */
15424bc1a35Smatthiasgrimm$conf['auth']['mysql']['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 */
16524bc1a35Smatthiasgrimm$conf['auth']['mysql']['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 */
17324bc1a35Smatthiasgrimm$conf['auth']['mysql']['delGroup']    = "DELETE FROM groups
17424bc1a35Smatthiasgrimm                                         WHERE gid='%{gid}'";
17524bc1a35Smatthiasgrimm
17624bc1a35Smatthiasgrimm/* This statement should return the database index of a given user name.
17724bc1a35Smatthiasgrimm * The module will access the index with the name 'id' so a alias might be
17824bc1a35Smatthiasgrimm * necessary.
17924bc1a35Smatthiasgrimm * following patters will be replaced:
18024bc1a35Smatthiasgrimm *   %{user}    user name
18124bc1a35Smatthiasgrimm */
18224bc1a35Smatthiasgrimm$conf['auth']['mysql']['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 */
19524bc1a35Smatthiasgrimm$conf['auth']['mysql']['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 */
20324bc1a35Smatthiasgrimm$conf['auth']['mysql']['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 */
221dfdd92d5Smatthiasgrimm$conf['auth']['mysql']['updateUser']  = "UPDATE users SET";
222dfdd92d5Smatthiasgrimm$conf['auth']['mysql']['UpdateLogin'] = "login='%{user}'";
223dfdd92d5Smatthiasgrimm$conf['auth']['mysql']['UpdatePass']  = "pass='%{pass}'";
224dfdd92d5Smatthiasgrimm$conf['auth']['mysql']['UpdateEmail'] = "email='%{email}'";
225dfdd92d5Smatthiasgrimm$conf['auth']['mysql']['UpdateName']  = "firstname=SUBSTRING_INDEX('%{name}',' ', 1),
226dfdd92d5Smatthiasgrimm                                         lastname=SUBSTRING_INDEX('%{name}',' ', -1)";
227dfdd92d5Smatthiasgrimm$conf['auth']['mysql']['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 */
2383ff230f7SMatthias Grimm$conf['auth']['mysql']['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.
24324bc1a35Smatthiasgrimm * The module will access the index with the name 'id' so a alias might
24424bc1a35Smatthiasgrimm * be necessary.
24524bc1a35Smatthiasgrimm *
24624bc1a35Smatthiasgrimm * Following patters will be replaced:
24724bc1a35Smatthiasgrimm *   %{group}   group name
24875bfc19cSMatthias Grimm */
24924bc1a35Smatthiasgrimm$conf['auth']['mysql']['getGroupID']  = "SELECT gid AS id
25024bc1a35Smatthiasgrimm                                         FROM groups
25124bc1a35Smatthiasgrimm                                         WHERE name='%{group}'";
25224bc1a35Smatthiasgrimm
253a771ad3aSmatthiasgrimm
254