xref: /dokuwiki/conf/mysql.conf.php.example (revision 5fb14d63b6a7de75860bd8a94caa8d2f2fe8ee5e)
1<?php
2/*
3  This is an example configuration for the mysql auth module.
4
5  This SQL statements are optimized for following table structure.
6  If you use a different one you have to change them accordingly.
7  See comments of every statement for details.
8
9  TABLE users
10      uid   login   pass   firstname   lastname   email
11
12  TABLE groups
13      gid   name
14
15  TABLE usergroup
16      uid   gid
17
18  To use this configuration you have to copy them to local.php
19  or at least include this file in local.php.
20 */
21
22
23/* Normally password encryptionis done by DokuWiki (recommended) but for
24 * some reasons it might be usefull to let the database do the encryption.
25 * Set 'encryptPass' to '1' and the cleartext password is forwarded to
26 * the database, otherwise the encrypted one.
27 */
28$conf['auth']['mysql']['encryptPass'] = 0;
29
30/* Multiple table operations will be protected by locks. This array tolds
31 * the module which tables to lock. If you use any aliases for table names
32 * these array must also contain these aliases. Any unamed alias will cause
33 * a warning suring operation. See the example below.
34 */
35$conf['auth']['mysql']['TablesToLock']= array("users", "users AS u","groups", "groups AS g", "usergroup", "usergroup AS ug");
36
37/* This statement should return the database index of a given user name.
38 * The module will access the index with the name 'id' so a alias might be
39 * necessary.
40 * following patters will be replaced:
41 *   %u    user name
42 */
43$conf['auth']['mysql']['getUserID']   = "SELECT uid AS id FROM users WHERE login='%u'";
44
45/* This statement should return the database index of a given group name.
46 * The module will access the index with the name 'id' so a alias might be
47 * necessary.
48 * following patters will be replaced:
49 *   %g    group name
50 */
51$conf['auth']['mysql']['getGroupID']  = "SELECT gid AS id FROM groups WHERE name='%g'";
52
53/* This statement is used to grant or deny access to the wiki. The result should
54 * be a table with exact one line containing at least the password of the user.
55 * If the result table is empty or contains more than one row, access will be denied.
56 * The module access the password as 'pass' so a alias might be necessary.
57 * following patters will be replaced:
58 *   %u    user name
59 *   %p    encrypted or clear text password (depends on 'encryptPass')
60 *   %g    default group name
61 */
62$conf['auth']['mysql']['checkPass']   = "SELECT pass
63                                         FROM usergroup AS ug
64                                         JOIN users AS u ON u.uid=ug.uid
65                                         JOIN groups AS g ON g.gid=ug.gid
66                                         WHERE login='%u'
67                                         AND name='%g'";
68
69/* This statement is used to get all groups a user is member of. The result should
70 * be a table containing all groups the given user is member of. The module access
71 * the group name as 'group' so a alias might be nessecary.
72 * following patters will be replaced:
73 *   %u    user name
74 */
75$conf['auth']['mysql']['getGroups']   = "SELECT name as `group`
76                                         FROM groups g, users u, usergroup ug
77                                         WHERE u.uid = ug.uid
78                                         AND g.gid = ug.gid
79                                         AND u.login='%u'";
80
81/* This statement should return a table with exact one row containing information
82 * about one user. The field needed are:
83 * 'pass'  containing the encrypted or clear text password
84 * 'name'  the user's full name
85 * 'mail'  the user's email address
86 * Keep in mind that Dokuwiki will access thise information through the names
87 * listed above so aliasses might be neseccary.
88 * following patters will be replaced:
89 *   %u    user name
90 */
91$conf['auth']['mysql']['getUserInfo'] = "SELECT pass, CONCAT(firstname,' ',lastname) AS name, email AS mail
92                                         FROM users
93                                         WHERE login='%u'";
94
95/* This statement should return a table containing all user login names that meet
96 * certain filter criteria. The filter expressions will be added case dependend by
97 * the module. At the end a sort expression will be added.
98 * Important is that this list contains no double entries fo a user. Each user
99 * name is only allowed once in the table.
100 * The login name will be accessed as 'user' to a alias might be neseccary.
101 * No patterns will be replaced in this statement but following patters will be
102 * replaced in the filter expressions:
103 *   %u  in FilterLogin  user's login name
104 *   %n  in FilterName   user's full name
105 *   %e  in FilterEmail  user's email address
106 *   %g  in FilterGroup  group name
107 */
108$conf['auth']['mysql']['getUsers']    = "SELECT DISTINCT login AS user
109                                         FROM users AS u
110                                         LEFT JOIN usergroup AS ug ON u.uid=ug.uid
111                                         LEFT JOIN groups AS g ON ug.gid=g.gid";
112$conf['auth']['mysql']['FilterLogin'] = "login LIKE '%u'";
113$conf['auth']['mysql']['FilterName']  = "CONCAT(firstname,' ',lastname) LIKE '%n'";
114$conf['auth']['mysql']['FilterEmail'] = "email LIKE '%e'";
115$conf['auth']['mysql']['FilterGroup'] = "name LIKE '%g'";
116$conf['auth']['mysql']['SortOrder']   = "ORDER BY login";
117
118/* This statement should add a user to the database. Minimum information to
119 * store are: login name, password, email address and full name.
120 * Following patterns will be replaced:
121 *   %u  user's login name
122 *   %p  password (encrypted or clear text, depends on 'encryptPass')
123 *   %e  email address
124 *   %n  user's full name
125 */
126$conf['auth']['mysql']['addUser']     = "INSERT INTO users
127                                         (login, pass, email, firstname, lastname)
128                                         VALUES ('%u', '%p', '%e',
129                                         SUBSTRING_INDEX('%n',' ', 1),
130                                         SUBSTRING_INDEX('%n',' ', -1))";
131
132/* This statement should remove a user fom the database.
133 * Following patterns will be replaced:
134 *   %u    user's login name
135 *   %uid  id of a user dataset
136 */
137$conf['auth']['mysql']['delUser']     = "DELETE FROM users
138                                         WHERE uid='%uid'";
139
140/* This statement should add a group to the database.
141 * Following patterns will be replaced:
142 *   %g    group name
143 */
144$conf['auth']['mysql']['addGroup']    = "INSERT INTO groups (name)
145                                         VALUES ('%g')";
146
147/* This statement should remove a group fom the database.
148 * Following patterns will be replaced:
149 *   %g    group name
150 *   %gid  id of a group dataset
151 */
152$conf['auth']['mysql']['delGroup']    = "DELETE FROM groups
153                                         WHERE gid='%gid'";
154
155/* This statement should connect a user to a group (a user become member
156 * of that group).
157 * Following patterns will be replaced:
158 *   %u    user's login name
159 *   %uid  id of a user dataset
160 *   %g    group name
161 *   %gid  id of a group dataset
162 */
163$conf['auth']['mysql']['addUserGroup']= "INSERT INTO usergroup (uid, gid)
164                                         VALUES ('%uid', '%gid')";
165
166/* This statement should remove a single connection from a user to a
167 * group (a user quits membership of that group).
168 * Following patterns will be replaced:
169 *   %u    user's login name
170 *   %uid  id of a user dataset
171 *   %g    group name
172 *   %gid  id of a group dataset
173 */
174$conf['auth']['mysql']['delUserGroup']= "DELETE FROM usergroup
175                                         WHERE uid='%uid'
176                                         AND gid='%gid'";
177
178/* This statement should remove all connections from a user to any group
179 * (a user quits membership of all groups).
180 * Following patterns will be replaced:
181 *   %uid  id of a user dataset
182 */
183$conf['auth']['mysql']['delUserRefs'] = "DELETE FROM usergroup
184                                         WHERE uid='%uid'";
185?>
186