xref: /dokuwiki/conf/mysql.conf.php.example (revision 0440ff150cefe9088c8aa126e646f901c69a7793)
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/* Options to configure database access. You need to set up this
23 * options carefully, otherwise you won't be able to access you
24 * database.
25 */
26$conf['auth']['mysql']['server']   = '';
27$conf['auth']['mysql']['user']     = '';
28$conf['auth']['mysql']['password'] = '';
29$conf['auth']['mysql']['database'] = '';
30
31/* This option enables debug messages in the mysql module. It is
32 * mostly usefull for system admins.
33 */
34$conf['auth']['mysql']['debug'] = 0;
35
36/* Normally password encryptionis done by DokuWiki (recommended) but for
37 * some reasons it might be usefull to let the database do the encryption.
38 * Set 'encryptPass' to '1' and the cleartext password is forwarded to
39 * the database, otherwise the encrypted one.
40 */
41$conf['auth']['mysql']['encryptPass'] = 0;
42
43/* Multiple table operations will be protected by locks. This array tolds
44 * the module which tables to lock. If you use any aliases for table names
45 * these array must also contain these aliases. Any unamed alias will cause
46 * a warning during operation. See the example below.
47 */
48$conf['auth']['mysql']['TablesToLock']= array("users", "users AS u","groups", "groups AS g", "usergroup", "usergroup AS ug");
49
50/* This statement should return the database index of a given user name.
51 * The module will access the index with the name 'id' so a alias might be
52 * necessary.
53 * following patters will be replaced:
54 *   %{user}	user name
55 */
56$conf['auth']['mysql']['getUserID']   = "SELECT uid AS id
57                                         FROM users
58                                         WHERE login='%{user}'";
59
60/* This statement should return the database index of a given group name.
61 * The module will access the index with the name 'id' so a alias might be
62 * necessary.
63 * following patters will be replaced:
64 *   %{group}	group name
65 */
66$conf['auth']['mysql']['getGroupID']  = "SELECT gid AS id
67                                         FROM groups
68                                         WHERE name='%{group}'";
69
70/* This statement is used to grant or deny access to the wiki. The result should
71 * be a table with exact one line containing at least the password of the user.
72 * If the result table is empty or contains more than one row, access will be denied.
73 * The module access the password as 'pass' so a alias might be necessary.
74 * following patters will be replaced:
75 *   %{user}	user name
76 *   %{pass}	encrypted or clear text password (depends on 'encryptPass')
77 *   %{dgroup}	default group name
78 */
79$conf['auth']['mysql']['checkPass']   = "SELECT pass
80                                         FROM usergroup AS ug
81                                         JOIN users AS u ON u.uid=ug.uid
82                                         JOIN groups AS g ON g.gid=ug.gid
83                                         WHERE login='%{user}'
84                                         AND name='%{dgroup}'";
85
86/* This statement is used to get all groups a user is member of. The result should
87 * be a table containing all groups the given user is member of. The module access
88 * the group name as 'group' so a alias might be nessecary.
89 * following patters will be replaced:
90 *   %{user}	user name
91 */
92$conf['auth']['mysql']['getGroups']   = "SELECT name as `group`
93                                         FROM groups g, users u, usergroup ug
94                                         WHERE u.uid = ug.uid
95                                         AND g.gid = ug.gid
96                                         AND u.login='%{user}'";
97
98/* This statement should return a table with exact one row containing information
99 * about one user. The field needed are:
100 * 'pass'  containing the encrypted or clear text password
101 * 'name'  the user's full name
102 * 'mail'  the user's email address
103 * Keep in mind that Dokuwiki will access thise information through the names
104 * listed above so aliasses might be neseccary.
105 * following patters will be replaced:
106 *   %{user}	user name
107 */
108$conf['auth']['mysql']['getUserInfo'] = "SELECT pass, CONCAT(firstname,' ',lastname) AS name, email AS mail
109                                         FROM users
110                                         WHERE login='%{user}'";
111
112/* This statement should return a table containing all user login names that meet
113 * certain filter criteria. The filter expressions will be added case dependend by
114 * the module. At the end a sort expression will be added.
115 * Important is that this list contains no double entries fo a user. Each user
116 * name is only allowed once in the table.
117 * The login name will be accessed as 'user' to a alias might be neseccary.
118 * No patterns will be replaced in this statement but following patters will be
119 * replaced in the filter expressions:
120 *   %{user}	in FilterLogin  user's login name
121 *   %{name}	in FilterName   user's full name
122 *   %{email}	in FilterEmail  user's email address
123 *   %{group}	in FilterGroup  group name
124 */
125$conf['auth']['mysql']['getUsers']    = "SELECT DISTINCT login AS user
126                                         FROM users AS u
127                                         LEFT JOIN usergroup AS ug ON u.uid=ug.uid
128                                         LEFT JOIN groups AS g ON ug.gid=g.gid";
129$conf['auth']['mysql']['FilterLogin'] = "login LIKE '%{user}'";
130$conf['auth']['mysql']['FilterName']  = "CONCAT(firstname,' ',lastname) LIKE '%{name}'";
131$conf['auth']['mysql']['FilterEmail'] = "email LIKE '%{email}'";
132$conf['auth']['mysql']['FilterGroup'] = "name LIKE '%{group}'";
133$conf['auth']['mysql']['SortOrder']   = "ORDER BY login";
134
135/* This statement should add a user to the database. Minimum information to
136 * store are: login name, password, email address and full name.
137 * Following patterns will be replaced:
138 *   %{user}	user's login name
139 *   %{pass}	password (encrypted or clear text, depends on 'encryptPass')
140 *   %{email}	email address
141 *   %{name}	user's full name
142 */
143$conf['auth']['mysql']['addUser']     = "INSERT INTO users
144                                         (login, pass, email, firstname, lastname)
145                                         VALUES ('%{user}', '%{pass}', '%{email}',
146                                         SUBSTRING_INDEX('%{name}',' ', 1),
147                                         SUBSTRING_INDEX('%{name}',' ', -1))";
148
149/* This statements should modify a user entry in the database. The statements
150 * UpdateLogin, UpdatePass, UpdateEmail and UpdateName will be added to
151 * updateUser on demand. Only changed parameters will be used.
152 * Following patterns will be replaced:
153 *   %{user}	user's login name
154 *   %{pass}	password (encrypted or clear text, depends on 'encryptPass')
155 *   %{email}	email address
156 *   %{name}	user's full name
157 *   %{uid}     user id that should be updated
158 */
159$conf['auth']['mysql']['updateUser']  = "UPDATE users SET";
160$conf['auth']['mysql']['UpdateLogin'] = "login='%{user}'";
161$conf['auth']['mysql']['UpdatePass']  = "pass='%{pass}'";
162$conf['auth']['mysql']['UpdateEmail'] = "email='%{email}'";
163$conf['auth']['mysql']['UpdateName']  = "firstname=SUBSTRING_INDEX('%{name}',' ', 1),
164                                         lastname=SUBSTRING_INDEX('%{name}',' ', -1)";
165$conf['auth']['mysql']['UpdateTarget']= "WHERE uid=%{uid}";
166
167/* This statement should remove a user fom the database.
168 * Following patterns will be replaced:
169 *   %{user}	user's login name
170 *   %{uid}		id of a user dataset
171 */
172$conf['auth']['mysql']['delUser']     = "DELETE FROM users
173                                         WHERE uid='%{uid}'";
174
175/* This statement should add a group to the database.
176 * Following patterns will be replaced:
177 *   %{group}	group name
178 */
179$conf['auth']['mysql']['addGroup']    = "INSERT INTO groups (name)
180                                         VALUES ('%{group}')";
181
182/* This statement should remove a group fom the database.
183 * Following patterns will be replaced:
184 *   %{group}	group name
185 *   %{gid}		id of a group dataset
186 */
187$conf['auth']['mysql']['delGroup']    = "DELETE FROM groups
188                                         WHERE gid='%{gid}'";
189
190/* This statement should connect a user to a group (a user become member
191 * of that group).
192 * Following patterns will be replaced:
193 *   %{user}	user's login name
194 *   %{uid}		id of a user dataset
195 *   %{group}	group name
196 *   %{gid}		id of a group dataset
197 */
198$conf['auth']['mysql']['addUserGroup']= "INSERT INTO usergroup (uid, gid)
199                                         VALUES ('%{uid}', '%{gid}')";
200
201/* This statement should remove a single connection from a user to a
202 * group (a user quits membership of that group).
203 * Following patterns will be replaced:
204 *   %{user}	user's login name
205 *   %{uid}		id of a user dataset
206 *   %{group}	group name
207 *   %{gid}		id of a group dataset
208 */
209$conf['auth']['mysql']['delUserGroup']= "DELETE FROM usergroup
210                                         WHERE uid='%{uid}'
211                                         AND gid='%{gid}'";
212
213/* This statement should remove all connections from a user to any group
214 * (a user quits membership of all groups).
215 * Following patterns will be replaced:
216 *   %{uid}		id of a user dataset
217 */
218$conf['auth']['mysql']['delUserRefs'] = "DELETE FROM usergroup
219                                         WHERE uid='%{uid}'";
220
221