| 1 |
weitzman |
1.1 |
<?php
|
| 2 |
weitzman |
1.12 |
// $Id: webserver_auth.module,v 1.11 2004/11/24 22:03:33 dries Exp $
|
| 3 |
weitzman |
1.1 |
|
| 4 |
weitzman |
1.5 |
function webserver_auth_init() {
|
| 5 |
|
|
global $user, $account;
|
| 6 |
weitzman |
1.10 |
|
| 7 |
weitzman |
1.1 |
if ($user->uid) {
|
| 8 |
weitzman |
1.5 |
//do nothing because user is already logged into Drupal
|
| 9 |
weitzman |
1.1 |
}
|
| 10 |
|
|
else {
|
| 11 |
weitzman |
1.4 |
if ($name = $_SERVER["REMOTE_USER"]) {
|
| 12 |
weitzman |
1.10 |
// user is logged into webserver.
|
| 13 |
weitzman |
1.5 |
$account->name = $name;
|
| 14 |
|
|
//modules get to change the user bits before saving. use a global $account to do so.
|
| 15 |
weitzman |
1.12 |
// only loaded modules will see this hook
|
| 16 |
weitzman |
1.5 |
module_invoke_all("webserver_auth");
|
| 17 |
weitzman |
1.12 |
// if we are in bootstrap, load user.module ourselves
|
| 18 |
|
|
if (!module_exist('user')) {
|
| 19 |
|
|
drupal_load('module', 'user');
|
| 20 |
|
|
}
|
| 21 |
weitzman |
1.10 |
|
| 22 |
weitzman |
1.5 |
// try to log into Drupal. if unsuccessful, register the user
|
| 23 |
weitzman |
1.7 |
$user = user_external_load($account->name);
|
| 24 |
weitzman |
1.1 |
if (!$user->uid) {
|
| 25 |
|
|
if (variable_get("user_register", 1) == 1) {
|
| 26 |
dries |
1.11 |
$user_default = array("name" => $account->name, "pass" => "cyan", "init" => db_escape_string($name), "authname_webserver_auth" => $account->name, "status" => 1, "roles" => array(_user_authenticated_id()));
|
| 27 |
weitzman |
1.12 |
// TODO - the hook_user('register') will fire but only for loaded modules. cold be a problem for sites using page cache and that hook+operation
|
| 28 |
weitzman |
1.5 |
$user = user_save("", array_merge($user_default, $account));
|
| 29 |
|
|
watchdog("user", "new user: $user->name (webserver_auth)", l(t("edit user"), "admin/user/edit/$user->uid"));
|
| 30 |
weitzman |
1.1 |
}
|
| 31 |
|
|
}
|
| 32 |
|
|
}
|
| 33 |
|
|
else {
|
| 34 |
|
|
// do nothing. user isn't logged into web server
|
| 35 |
|
|
}
|
| 36 |
|
|
}
|
| 37 |
|
|
}
|
| 38 |
|
|
|
| 39 |
weitzman |
1.5 |
// using a global to change your bits. module_invoke_all miffs me.
|
| 40 |
|
|
function webserver_auth_webserver_auth() {
|
| 41 |
|
|
global $account;
|
| 42 |
weitzman |
1.10 |
|
| 43 |
weitzman |
1.3 |
// pretties up the username for NTLM authentication (i.e. Windows)
|
| 44 |
weitzman |
1.6 |
if ($_SERVER["AUTH_TYPE"] == "NTLM" || $_SERVER["AUTH_TYPE"] == 'Negotiate') {
|
| 45 |
|
|
$account->name = substr(trim($account->name), strrpos(trim($account->name), "\\")+1);
|
| 46 |
weitzman |
1.5 |
}
|
| 47 |
weitzman |
1.10 |
|
| 48 |
weitzman |
1.5 |
if ($domain = variable_get("webserver_auth_domain", "")) {
|
| 49 |
|
|
if ($account->name) {
|
| 50 |
|
|
$account->mail = $account->name. "@$domain";
|
| 51 |
|
|
}
|
| 52 |
weitzman |
1.3 |
}
|
| 53 |
|
|
}
|
| 54 |
|
|
|
| 55 |
weitzman |
1.5 |
function webserver_auth_settings() {
|
| 56 |
|
|
$output = form_textfield(t("Email Domain"), "webserver_auth_domain", variable_get("webserver_auth_domain", ""), 30, 55, t("Append this domain name to each new user in order generate his email address."));
|
| 57 |
|
|
return $output;
|
| 58 |
|
|
}
|
| 59 |
|
|
|
| 60 |
weitzman |
1.3 |
function webserver_auth_help($section) {
|
| 61 |
|
|
$output ="";
|
| 62 |
|
|
|
| 63 |
|
|
switch ($section) {
|
| 64 |
|
|
case 'admin/help#webserver_auth':
|
| 65 |
|
|
break;
|
| 66 |
weitzman |
1.8 |
case 'admin/modules#description':
|
| 67 |
weitzman |
1.3 |
$output .= t("Use web server authentication instead of Drupal");
|
| 68 |
|
|
break;
|
| 69 |
|
|
}
|
| 70 |
|
|
|
| 71 |
|
|
return $output;
|
| 72 |
|
|
}
|
| 73 |
|
|
|
| 74 |
|
|
|
| 75 |
uwe |
1.9 |
?>
|