/[drupal]/contributions/modules/ldap_lookup/ldap_lookup.forms
ViewVC logotype

Contents of /contributions/modules/ldap_lookup/ldap_lookup.forms

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download)
Mon Oct 8 12:24:02 2007 UTC (2 years, 1 month ago) by kibble
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +2 -2 lines
Fix to the group listing while creating associations. Only last configured
domain controller groups would show.
1 <?php
2 // $Id: ldap_lookup.forms,v 1.4 2007/10/04 10:07:03 kibble Exp $
3
4 function ldap_lookup_admin_form() {
5
6 $form = array();
7 $ldap_name = arg(4);
8
9 if ((arg(3) == "edit") && ($ldap_name != NULL)) {
10 $edit = db_fetch_array(db_query("SELECT * FROM {ldap_lookup} WHERE name = '%s'", $ldap_name));
11 $form['old-name'] = array(
12 '#type' => 'hidden',
13 '#value' => $edit['name']
14 );
15 }
16
17 $form['server-settings'] = array(
18 '#type' => 'fieldset',
19 '#title' => t('Server settings'),
20 '#collapsible' => TRUE,
21 '#collapsed' => FALSE
22 );
23
24 $form['server-settings']['status'] = array(
25 '#type' => 'checkbox',
26 '#title' => t('Activate'),
27 '#return_value' => 1,
28 '#default_value' => $edit['status'],
29 '#description' => t('Activate this directory source for authentication.')
30 );
31
32 $form['server-settings']['name'] = array(
33 '#type' => 'textfield',
34 '#title' => t('Name'),
35 '#default_value' => $edit['name'],
36 '#description' => t('Choose a <em><strong>unique</strong></em> name for this server configuration.'),
37 '#required' => TRUE
38 );
39
40 $form['server-settings']['server'] = array(
41 '#type' => 'textfield',
42 '#title' => t('LDAP server'),
43 '#default_value' => $edit['server'],
44 '#description' => t('The domain name or IP address of your LDAP Server.'),
45 '#required' => TRUE
46 );
47
48 $form['server-settings']['port'] = array(
49 '#type' => 'textfield',
50 '#title' => t('LDAP port'),
51 '#default_value' => $edit['port'] ? $edit['port'] : 389,
52 '#description' => t('The TCP/IP port on the above server which accepts LDAP connections. Must be an integer.')
53 );
54
55 $form['server-settings']['tls'] = array(
56 '#type' => 'checkbox',
57 '#title' => t('Use TLS encryption'),
58 '#return_value' => 1,
59 '#default_value' => $edit['tls'],
60 '#description' => t('Secure the connection between Drupal and the LDAP servers using TLS. (not fully supported)')
61 );
62
63 $form['login-procedure'] = array(
64 '#type' => 'fieldset',
65 '#title' => 'Login procedure',
66 '#collapsible' => TRUE,
67 '#collapsed' => TRUE
68 );
69
70 $form['login-procedure']['basedn'] = array(
71 '#type' => 'textarea',
72 '#title' => t('Base DNs'),
73 '#default_value' => $edit['basedn'],
74 '#cols' => 50,
75 '#rows' => 6,
76 '#description' => t('Base DNs for users. Enter one per line in case you need several of them. They must be valid DNs or it will fail.'),
77 '#required' => TRUE
78 );
79
80 $form['login-procedure']['groupdn'] = array(
81 '#type' => 'textarea',
82 '#title' => t('Group DNs'),
83 '#default_value' => $edit['groupdn'],
84 '#cols' => 50,
85 '#rows' => 6,
86 '#description' => t('Group DNs for active directory group lookups. Enter one per line in case you need several of them.'),
87 '#required' => FALSE
88 );
89
90 $form['login-procedure']['user_attr'] = array(
91 '#type' => 'textfield',
92 '#title' => t('Username attribute'),
93 '#default_value' => $edit['user_attr'] ? $edit['user_attr'] : 'sAMAccountName',
94 '#description' => t('The attribute that holds the user login name. (e.g. sAMAccountName)')
95 );
96
97 $form['login-procedure']['email_attr'] = array(
98 '#type' => 'textfield',
99 '#title' => t('Email attribute'),
100 '#default_value' => $edit['email_attr'] ? $edit['email_attr'] : 'mail',
101 '#description' => t('The attribute that holds the mail address. (e.g. mail)')
102 );
103
104 $form['binding'] = array(
105 '#type' => 'fieldset',
106 '#title' => 'Binding configuration',
107 '#collapsible' => TRUE,
108 '#collapsed' => TRUE
109 );
110
111 $form['binding']['binddn'] = array(
112 '#type' => 'textfield',
113 '#title' => t('DN for non-anonymous LDAP binding'),
114 '#default_value' => $edit['binddn'],
115 '#required' => TRUE
116 );
117
118 if ( ! $edit['bindpw']) {
119 $form['binding']['bindpw'] = array(
120 '#type' => 'password',
121 '#title' => t('Password for non-anonymous LDAP binding')
122 );
123 } else {
124
125 $form['binding']['bindpw'] = array(
126 '#type' => 'hidden',
127 '#value' => $edit['bindpw']
128 );
129
130 $form['binding']['bindpw_clear'] = array(
131 '#type' => 'checkbox',
132 '#title' => t('Clear current password'),
133 '#default_value' => FALSE
134 );
135
136 }
137
138 $form['submit'] = array(
139 '#type' => 'submit',
140 '#value' => 'Save configuration'
141 );
142
143 return($form);
144 }
145
146 function ldap_lookup_admin_delete() {
147
148 $ldap_name = arg(4);
149
150 if (!$ldap_name) {
151 drupal_goto('admin/settings/ldapauth');
152 }
153
154 if ($result = db_fetch_object(db_query("SELECT name FROM {ldap_lookup} WHERE name = '%s'", $ldap_name))) {
155 return confirm_form(
156 array(),
157 t('Are you sure you want to delete the ldap configration named <em><strong>%server</strong></em>?', array('%server' => $ldap_name)),
158 'admin/settings/ldap_lookup',
159 t('This action cannot be undone.'),
160 t('Delete'),
161 t('Cancel')
162 );
163 } else {
164 drupal_set_message(t('No such LDAP config: %config', array('%config' => $ldap_name)));
165 drupal_goto('admin/settings/ldapauth');
166 }
167
168 return;
169
170 }
171
172 function ldap_lookup_admin_associate() {
173
174 $results = db_query("SELECT * FROM {ldap_lookup}");
175
176 if (( ! isset($pass)) || ($pass == "") || ($pass == NULL)) {
177 unset($pass);
178 $pass = NULL;
179 }
180
181 $group_array = array();
182 while ($row = db_fetch_object($results)) {
183
184 $ldap = new ldap_lookup_class($row->name, $row->server, $row->port, $row->basedn, $row->groupdn, $row->binddn, $row->bindpw, $row->use_tls, $row->user_attr, $row->email_attr);
185
186 if ($ldap->connect()) {
187
188 $possible_group_dns = explode("\r\n", $row->groupdn);
189 foreach ($possible_group_dns as $group_dn) {
190
191 $filter = "(objectCategory=group)";
192 $records = $ldap->search($group_dn, $filter);
193
194 for($rcount = 0; $rcount != $records['count']; $rcount++) {
195 $group_array['CN=' . $records[$rcount]['cn'][0] . ',' . $group_dn] = $records[$rcount]['cn'][0];
196 }
197
198 }
199
200 }
201
202 unset($ldap);
203
204 }
205
206 $form = array();
207 if (is_numeric(arg(4))) {
208
209 $result = db_fetch_object(db_query("SELECT rid, name FROM {role} WHERE rid = " . arg(4) . " LIMIT 1"));
210
211 $form['associate'] = array(
212 '#type' => 'fieldset',
213 '#collapsible' => TRUE,
214 '#collapsed' => FALSE,
215 '#title' => t('Create new association')
216 );
217
218 $form['associate']['role_display'] = array(
219 '#type' => 'item',
220 '#title' => t('Selected Role'),
221 '#value' => ucwords($result->name)
222 );
223
224 $form['associate']['role'] = array(
225 '#type' => 'hidden',
226 '#value' => $result->name,
227 '#required' => TRUE
228 );
229
230 $form['associate']['rid'] = array(
231 '#type' => 'hidden',
232 '#value' => arg(4),
233 '#required' => TRUE
234 );
235
236 $form['associate']['group_name'] = array(
237 '#type' => 'select',
238 '#title' => t('Select a group'),
239 '#options' => $group_array,
240 '#description' => t('Select a group to associate with current selected role.'),
241 '#required' => TRUE
242 );
243
244 $form['associate']['submit'] = array(
245 '#type' => 'submit',
246 '#value' => t('Associate')
247 );
248
249 $sql_q = "SELECT id, rid, group_name FROM {ldap_lookup_associate} WHERE rid = " . arg(4);
250 $associate_row_header = array(
251 array('data' => t('Name'), 'field' => 'group_name', 'style' => 'vertical-align: top;', 'sort' => 'asc'),
252 array('data' => t('Operations'), 'style' => 'vertical-align: top;')
253 );
254 $sql_q .= tablesort_sql($associate_row_header);
255 $results = pager_query($sql_q, 31);
256
257 if (db_num_rows($results)) {
258 while ($row = db_fetch_object($results)) {
259 $associate_row_data[] = array(
260 array('data' => $row->group_name, 'style' => 'vertical-align: top;'),
261 array('data' => l(t('Delete'), 'admin/settings/ldap_lookup/grouproles/'. $row->rid . '/delete', array('onclick' => "javascript:return confirm('Are you sure you want to delete this association?')"), 'id=' . $row->id), 'style' => 'vertical-align: top;')
262 );
263 }
264 $form['groups'] = array(
265 '#type' => 'item',
266 '#title' => t('Current Associated Groups'),
267 '#value' => theme('table', $associate_row_header, $associate_row_data, array('cellspacing' => '1'))
268 );
269
270 $form['pager'] = array(
271 '#type' => 'item',
272 '#value' => theme('pager', NULL, 31, 0)
273 );
274 }
275
276 }
277
278 return($form);
279
280 }
281
282 function ldap_lookup_admin_associate_insert($edit) {
283
284 $dbq = "INSERT INTO {ldap_lookup_associate} (rid, group_name) VALUES (" . $edit['rid'] . ", '" . $edit['group_name'] . "')";
285
286 return(db_query($dbq));
287
288 }
289
290 function ldap_lookup_admin_associate_check_duplicate($edit) {
291
292 return(db_result(db_query("SELECT COUNT(*) FROM {ldap_lookup_associate} WHERE rid = " . $edit['rid'] . " AND group_name = '" . $edit['group_name'] . "'")));
293 }
294
295 function ldap_lookup_admin_associate_delete() {
296
297 if ( ! is_numeric(arg(4))) {
298 drupal_set_message(t('Not a valid role id.'), 'error');
299 watchdog('ldap_lookup', t('Not a valid role id.'));
300 return;
301 }
302
303 if (db_query("DELETE FROM {ldap_lookup_associate} WHERE id = " . $_GET['id'])) {
304 drupal_set_message(t('The association has been removed from the database.'));
305 drupal_goto('admin/settings/ldap_lookup/grouproles/' . arg(4));
306 } else {
307 form_set_error('null', t('Association has failed to be removed into database.'));
308 drupal_goto('admin/settings/ldap_lookup/grouproles/' . arg(4));
309 }
310
311 }
312
313 function ldap_lookup_admin_associate_validate($form_id, $form_values) {
314
315 if ( ! is_numeric(arg(4))) {
316 form_set_error('role_display', t('This is not a valid role. Site admin has been informed.'));
317 watchdog('ldap_lookup', t('Invalid group and role association has been attempted.'));
318 return;
319 }
320
321 if (ldap_lookup_admin_associate_check_duplicate($form_values) != 0) {
322 form_set_error('group_name', t('An association with this name already exists.') . " [" . $form_values['group_name'] . "]");
323 return;
324 }
325
326 }
327
328 function ldap_lookup_admin_associate_submit($form_id, $form_values) {
329
330 if ( ! is_numeric(arg(4))) {
331 form_set_error('role_display', t('This is not a valid role. Site admin has been informed.'));
332 watchdog('ldap_lookup', t('Invalid group and role association has been attempted.'));
333 return;
334 }
335
336 if (ldap_lookup_admin_associate_check_duplicate($form_values) != 0) {
337 form_set_error('group_name', t('An association with this name already exists.') . " [" . $form_values['group_name'] . "]");
338 return;
339 }
340
341 if (ldap_lookup_admin_associate_insert($form_values)) {
342 drupal_set_message(t('The association has been added to the database.'));
343 return($_GET['q']);
344 } else {
345 form_set_error('null', t('Association has failed to be entered into database.'));
346 return;
347 }
348
349 }
350
351 function ldap_lookup_admin_grouproles() {
352
353 $form = array();
354
355 $sql_q = "SELECT rid, name FROM {role}";
356 $roles_row_header = array(
357 array('data' => t('Name'), 'field' => 'name', 'style' => 'vertical-align: top;', 'sort' => 'asc'),
358 array('data' => t('Operations'), 'style' => 'vertical-align: top;')
359 );
360 $sql_q .= tablesort_sql($roles_row_header);
361 $result = pager_query($sql_q, 31);
362
363 if (db_num_rows($result)) {
364 while ($row = db_fetch_object($result)) {
365 $roles_row_data[] = array(
366 array('data' => $row->name, 'style' => 'vertical-align: top;'),
367 array('data' => l(t('Associate'), 'admin/settings/ldap_lookup/grouproles/'. $row->rid), 'style' => 'vertical-align: top;')
368 );
369 }
370 }
371
372 $form['roles'] = array(
373 '#type' => 'item',
374 '#title' => t('Current Roles'),
375 '#value' => theme('table', $roles_row_header, $roles_row_data, array('cellspacing' => '1'))
376 );
377
378 $form['pager'] = array(
379 '#type' => 'item',
380 '#value' => theme('pager', NULL, 31, 0)
381 );
382
383
384
385 return($form);
386
387 }
388
389 ?>

  ViewVC Help
Powered by ViewVC 1.1.2