|
<?php |
|
|
// $Id: webserver_auth.module,v 1.11 2004/11/24 22:03:33 dries Exp $ |
|
|
|
|
|
function webserver_auth_init() { |
|
|
global $user, $account; |
|
|
|
|
|
if ($user->uid) { |
|
|
//do nothing because user is already logged into Drupal |
|
|
} |
|
|
else { |
|
|
if ($name = $_SERVER["REMOTE_USER"]) { |
|
|
// user is logged into webserver. |
|
|
$account->name = $name; |
|
|
//modules get to change the user bits before saving. use a global $account to do so. |
|
|
module_invoke_all("webserver_auth"); |
|
|
|
|
|
// try to log into Drupal. if unsuccessful, register the user |
|
|
$user = user_external_load($account->name); |
|
|
if (!$user->uid) { |
|
|
if (variable_get("user_register", 1) == 1) { |
|
|
$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())); |
|
|
$user = user_save("", array_merge($user_default, $account)); |
|
|
watchdog("user", "new user: $user->name (webserver_auth)", l(t("edit user"), "admin/user/edit/$user->uid")); |
|
|
} |
|
|
} |
|
|
} |
|
|
else { |
|
|
// do nothing. user isn't logged into web server |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
// using a global to change your bits. module_invoke_all miffs me. |
|
|
function webserver_auth_webserver_auth() { |
|
|
global $account; |
|
|
|
|
|
// pretties up the username for NTLM authentication (i.e. Windows) |
|
|
if ($_SERVER["AUTH_TYPE"] == "NTLM" || $_SERVER["AUTH_TYPE"] == 'Negotiate') { |
|
|
$account->name = substr(trim($account->name), strrpos(trim($account->name), "\\")+1); |
|
|
} |
|
|
|
|
|
if ($domain = variable_get("webserver_auth_domain", "")) { |
|
|
if ($account->name) { |
|
|
$account->mail = $account->name. "@$domain"; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
function webserver_auth_settings() { |
|
|
$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.")); |
|
|
return $output; |
|
|
} |
|
|
|
|
|
function webserver_auth_help($section) { |
|
|
$output =""; |
|
|
|
|
|
switch ($section) { |
|
|
case 'admin/help#webserver_auth': |
|
|
break; |
|
|
case 'admin/modules#description': |
|
|
$output .= t("Use web server authentication instead of Drupal"); |
|
|
break; |
|
|
} |
|
|
|
|
|
return $output; |
|
|
} |
|
|
|
|
|
|
|
|
?> |
|
| 1 |
|
<?php |
| 2 |
|
// $Id: webserver_auth.module,v 1.12 2005/04/29 19:27:31 weitzman Exp $ |
| 3 |
|
|
| 4 |
|
function webserver_auth_init() { |
| 5 |
|
global $user, $account; |
| 6 |
|
|
| 7 |
|
if ($user->uid) { |
| 8 |
|
//do nothing because user is already logged into Drupal |
| 9 |
|
} |
| 10 |
|
else { |
| 11 |
|
if ($name = $_SERVER["REMOTE_USER"]) { |
| 12 |
|
// user is logged into webserver. |
| 13 |
|
$account->name = $name; |
| 14 |
|
//modules get to change the user bits before saving. use a global $account to do so. |
| 15 |
|
// only loaded modules will see this hook |
| 16 |
|
module_invoke_all("webserver_auth"); |
| 17 |
|
// if we are in bootstrap, load user.module ourselves |
| 18 |
|
if (!module_exist('user')) { |
| 19 |
|
drupal_load('module', 'user'); |
| 20 |
|
} |
| 21 |
|
|
| 22 |
|
// try to log into Drupal. if unsuccessful, register the user |
| 23 |
|
$user = user_external_load($account->name); |
| 24 |
|
if (!$user->uid) { |
| 25 |
|
if (variable_get("user_register", 1) == 1) { |
| 26 |
|
$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 |
|
// 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 |
|
$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 |
|
} |
| 31 |
|
} |
| 32 |
|
} |
| 33 |
|
else { |
| 34 |
|
// do nothing. user isn't logged into web server |
| 35 |
|
} |
| 36 |
|
} |
| 37 |
|
} |
| 38 |
|
|
| 39 |
|
// using a global to change your bits. module_invoke_all miffs me. |
| 40 |
|
function webserver_auth_webserver_auth() { |
| 41 |
|
global $account; |
| 42 |
|
|
| 43 |
|
// pretties up the username for NTLM authentication (i.e. Windows) |
| 44 |
|
if ($_SERVER["AUTH_TYPE"] == "NTLM" || $_SERVER["AUTH_TYPE"] == 'Negotiate') { |
| 45 |
|
$account->name = substr(trim($account->name), strrpos(trim($account->name), "\\")+1); |
| 46 |
|
} |
| 47 |
|
|
| 48 |
|
if ($domain = variable_get("webserver_auth_domain", "")) { |
| 49 |
|
if ($account->name) { |
| 50 |
|
$account->mail = $account->name. "@$domain"; |
| 51 |
|
} |
| 52 |
|
} |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
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 |
|
function webserver_auth_help($section) { |
| 61 |
|
$output =""; |
| 62 |
|
|
| 63 |
|
switch ($section) { |
| 64 |
|
case 'admin/help#webserver_auth': |
| 65 |
|
break; |
| 66 |
|
case 'admin/modules#description': |
| 67 |
|
$output .= t("Use web server authentication instead of Drupal"); |
| 68 |
|
break; |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
return $output; |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
|
| 75 |
|
?> |