| 1 |
<?php
|
| 2 |
// $Id: ldap_lookup.module,v 1.1.4.14.2.3 2007/01/28 05:21:29 kreaper Exp $
|
| 3 |
|
| 4 |
define(LDAP_ALL_OFF, 0);
|
| 5 |
define(LDAP_DEBUG_ON, 1);
|
| 6 |
define(LDAP_MESG_ON, 2);
|
| 7 |
|
| 8 |
include_once('ldap_lookup.class');
|
| 9 |
include_once('ldap_lookup.forms');
|
| 10 |
include_once('ldap_lookup.admin');
|
| 11 |
include_once('ldap_lookup.auth');
|
| 12 |
include_once('ldap_lookup.user');
|
| 13 |
include_once('ldap_lookup.blocks');
|
| 14 |
|
| 15 |
/*********************************
|
| 16 |
* 1. Drupal hooks *
|
| 17 |
*********************************/
|
| 18 |
/**
|
| 19 |
* Implements hook_help()
|
| 20 |
**/
|
| 21 |
function ldap_lookup_help($section) {
|
| 22 |
|
| 23 |
$output = "";
|
| 24 |
|
| 25 |
switch ($section) {
|
| 26 |
case 'admin/modules#name':
|
| 27 |
$output = 'ldap_lookup';
|
| 28 |
break;
|
| 29 |
case 'admin/modules#description':
|
| 30 |
case 'admin/help#ldap_lookup':
|
| 31 |
$output = t('Enables authentication via LDAP.');
|
| 32 |
break;
|
| 33 |
case 'user/help#ldap_lookup':
|
| 34 |
$output = t('Login using LDAP.');
|
| 35 |
break;
|
| 36 |
}
|
| 37 |
|
| 38 |
return($output);
|
| 39 |
|
| 40 |
}
|
| 41 |
|
| 42 |
function ldap_lookup_perm() {
|
| 43 |
return array('access administration pages', 'impersonate other users');
|
| 44 |
}
|
| 45 |
|
| 46 |
/**
|
| 47 |
* Implements hook_menu()
|
| 48 |
**/
|
| 49 |
|
| 50 |
function ldap_lookup_menu($may_cache) {
|
| 51 |
|
| 52 |
$items = array();
|
| 53 |
|
| 54 |
if ($may_cache) {
|
| 55 |
|
| 56 |
$items[] = array(
|
| 57 |
'path' => 'admin/settings/ldap_lookup',
|
| 58 |
'title' => t('LDAP Lookup'),
|
| 59 |
'callback' => 'ldap_lookup_admin_list',
|
| 60 |
'description' => t('Configure LDAP settings for Active Directory systems only.'),
|
| 61 |
'access' => user_access('access administration pages')
|
| 62 |
);
|
| 63 |
|
| 64 |
$items[] = array(
|
| 65 |
'path' => 'admin/settings/ldap_lookup/list',
|
| 66 |
'title' => t('List'),
|
| 67 |
'callback' => 'ldap_lookup_admin_list',
|
| 68 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 69 |
'access' => user_access('access administration pages'),
|
| 70 |
'weight' => 1
|
| 71 |
);
|
| 72 |
|
| 73 |
$items[] = array(
|
| 74 |
'path' => 'admin/settings/ldap_lookup/add',
|
| 75 |
'title' => t('Configure LDAP Server'),
|
| 76 |
'callback' => 'drupal_get_form',
|
| 77 |
'callback arguments' => array('ldap_lookup_admin_form'),
|
| 78 |
'type' => MENU_LOCAL_TASK,
|
| 79 |
'access' => user_access('access administration pages'),
|
| 80 |
'weight' => 2
|
| 81 |
);
|
| 82 |
|
| 83 |
$items[] = array(
|
| 84 |
'path' => 'admin/settings/ldap_lookup/edit',
|
| 85 |
'title' => t('Configure LDAP Server'),
|
| 86 |
'callback' => 'drupal_get_form',
|
| 87 |
'callback arguments' => array('ldap_lookup_admin_form'),
|
| 88 |
'type' => MENU_CALLBACK,
|
| 89 |
'access' => user_access('access administration pages')
|
| 90 |
);
|
| 91 |
|
| 92 |
$items[] = array(
|
| 93 |
'path' => 'admin/settings/ldap_lookup/delete',
|
| 94 |
'title' => t('Configure LDAP Server'),
|
| 95 |
'callback' => 'drupal_get_form',
|
| 96 |
'callback arguments' => array('ldap_lookup_admin_delete'),
|
| 97 |
'type' => MENU_CALLBACK,
|
| 98 |
'access' => user_access('access administration pages')
|
| 99 |
);
|
| 100 |
|
| 101 |
$items[] = array(
|
| 102 |
'path' => 'admin/settings/ldap_lookup/configurations',
|
| 103 |
'title' => t('Configure LDAP Settings'),
|
| 104 |
'callback' => 'drupal_get_form',
|
| 105 |
'callback arguments' => array('ldap_lookup_admin_settings'),
|
| 106 |
'type' => MENU_LOCAL_TASK,
|
| 107 |
'access' => user_access('access administration pages'),
|
| 108 |
'weight' => 2
|
| 109 |
);
|
| 110 |
|
| 111 |
$items[] = array(
|
| 112 |
'path' => 'admin/settings/ldap_lookup/grouproles',
|
| 113 |
'title' => t('Configure Groups and Roles'),
|
| 114 |
'callback' => 'drupal_get_form',
|
| 115 |
'callback arguments' => array('ldap_lookup_admin_grouproles'),
|
| 116 |
'type' => MENU_LOCAL_TASK,
|
| 117 |
'access' => user_access('access administration pages'),
|
| 118 |
'weight' => 2
|
| 119 |
);
|
| 120 |
|
| 121 |
} else {
|
| 122 |
|
| 123 |
$items[] = array(
|
| 124 |
'path' => 'admin/settings/ldap_lookup/grouproles/' . arg(4),
|
| 125 |
'title' => t('Associate Role to Group'),
|
| 126 |
'callback' => 'drupal_get_form',
|
| 127 |
'callback arguments' => array('ldap_lookup_admin_associate'),
|
| 128 |
'type' => MENU_CALLBACK,
|
| 129 |
'access' => user_access('access administration pages')
|
| 130 |
);
|
| 131 |
|
| 132 |
$items[] = array(
|
| 133 |
'path' => 'admin/settings/ldap_lookup/grouproles/' . arg(4) . '/delete',
|
| 134 |
'callback' => 'ldap_lookup_admin_associate_delete',
|
| 135 |
'type' => MENU_CALLBACK,
|
| 136 |
'access' => user_access('access administration pages')
|
| 137 |
);
|
| 138 |
|
| 139 |
}
|
| 140 |
|
| 141 |
/** $items[] = array(
|
| 142 |
'path' => 'logout',
|
| 143 |
'title' => t('Log out'),
|
| 144 |
'access' => $user->id,
|
| 145 |
'callback' => user_access('impersonate other users'),
|
| 146 |
'type' => MENU_CALLBACK,
|
| 147 |
'weight' => 10
|
| 148 |
); */
|
| 149 |
|
| 150 |
return($items);
|
| 151 |
|
| 152 |
}
|
| 153 |
|
| 154 |
function ldap_lookup_admin_list() {
|
| 155 |
|
| 156 |
$sql = "SELECT sid, name FROM {ldap_lookup} ORDER BY sid";
|
| 157 |
$result = db_query($sql);
|
| 158 |
|
| 159 |
$rows = array();
|
| 160 |
while ($row = db_fetch_object($result)) {
|
| 161 |
$rows[] = array($row->name, l(t('edit'), 'admin/settings/ldap_lookup/edit/' . $row->name), l(t('delete'), 'admin/settings/ldap_lookup/delete/' . $row->name));
|
| 162 |
}
|
| 163 |
|
| 164 |
$header = array(
|
| 165 |
t('LDAP Config'),
|
| 166 |
array(
|
| 167 |
'data' => t('Operations'),
|
| 168 |
'colspan' => 2
|
| 169 |
)
|
| 170 |
);
|
| 171 |
|
| 172 |
return(theme('table', $header, $rows));
|
| 173 |
|
| 174 |
}
|
| 175 |
|
| 176 |
function ldap_lookup_admin_form_submit($form_id, $form_values) {
|
| 177 |
|
| 178 |
if ((arg(3) == 'add')) {
|
| 179 |
|
| 180 |
if (db_fetch_object(db_query("SELECT name FROM {ldap_lookup} WHERE name = '%s'", $form_values['name']))) {
|
| 181 |
form_set_error('name', t('An LDAP config with that name already exists.'));
|
| 182 |
}
|
| 183 |
|
| 184 |
db_query("INSERT INTO {ldap_lookup} SET name = '%s', status = '%d', server = '%s', port = '%d', tls = '%d', basedn = '%s', groupdn = '%s', user_attr = '%s', email_attr = '%s', binddn = '%s', bindpw = '%s'", $form_values['name'], $form_values['status'], $form_values['server'], $form_values['port'], $form_values['tls'], $form_values['basedn'], $form_values['groupdn'], $form_values['user_attr'], $form_values['email_attr'], $form_values['binddn'], $form_values['bindpw']);
|
| 185 |
drupal_set_message(t('LDAP Configuration %config has been added.', array('%config' => $form_values['name'])));
|
| 186 |
|
| 187 |
} else {
|
| 188 |
|
| 189 |
if ($form_values['bindpw_clear'] == 1) {
|
| 190 |
db_query("UPDATE {ldap_lookup} SET name = '%s', status = '%d', server = '%s', port = '%d', tls = '%d', basedn = '%s', groupdn = '%s', user_attr = '%s', email_attr = '%s', binddn = '%s', bindpw = NULL WHERE name = '%s'", $form_values['name'], $form_values['status'], $form_values['server'], $form_values['port'], $form_values['tls'], $form_values['basedn'], $form_values['groupdn'], $form_values['user_attr'], $form_values['email_attr'], $form_values['binddn'], $form_values['old-name']);
|
| 191 |
} else {
|
| 192 |
db_query("UPDATE {ldap_lookup} SET name = '%s', status = '%d', server = '%s', port = '%d', tls = '%d', basedn = '%s', groupdn = '%s', user_attr = '%s', email_attr = '%s', binddn = '%s', bindpw = '%s' WHERE name = '%s'", $form_values['name'], $form_values['status'], $form_values['server'], $form_values['port'], $form_values['tls'], $form_values['basedn'], $form_values['groupdn'], $form_values['user_attr'], $form_values['email_attr'], $form_values['binddn'], $form_values['bindpw'], $form_values['old-name']);
|
| 193 |
}
|
| 194 |
drupal_set_message(t('LDAP Configuration %config has been updated.', array('%config' => $form_values['name'])));
|
| 195 |
|
| 196 |
}
|
| 197 |
|
| 198 |
return('admin/settings/ldap_lookup');
|
| 199 |
}
|
| 200 |
|
| 201 |
function ldap_lookup_admin_delete_submit($form_id, $form_values) {
|
| 202 |
|
| 203 |
if ($form_values['confirm']) {
|
| 204 |
db_query("DELETE FROM {ldap_lookup} WHERE name = '%s'", arg(4));
|
| 205 |
drupal_set_message(t('LDAP Configuration %config has been deleted.', array('%config' => $form_values['name'])));
|
| 206 |
}
|
| 207 |
|
| 208 |
return('admin/settings/ldap_lookup');
|
| 209 |
|
| 210 |
}
|
| 211 |
|
| 212 |
?>
|