commit | author | age
|
48e9c1
|
1 |
<?php |
T |
2 |
|
|
3 |
/** |
|
4 |
* HTTP Basic Authentication |
|
5 |
* |
|
6 |
* Make use of an existing HTTP authentication and perform login with the existing user credentials |
|
7 |
* |
|
8 |
* Configuration: |
|
9 |
* // redirect the client to this URL after logout. This page is then responsible to clear HTTP auth |
|
10 |
* $rcmail_config['logout_url'] = 'http://server.tld/logout.html'; |
|
11 |
* |
|
12 |
* See logout.html (in this directory) for an example how HTTP auth can be cleared. |
|
13 |
* |
|
14 |
* @version @package_version@ |
|
15 |
* @license GNU GPLv3+ |
|
16 |
* @author Thomas Bruederli |
|
17 |
*/ |
|
18 |
class http_authentication extends rcube_plugin |
|
19 |
{ |
|
20 |
public $task = 'login|logout'; |
|
21 |
|
|
22 |
function init() |
|
23 |
{ |
|
24 |
$this->add_hook('startup', array($this, 'startup')); |
|
25 |
$this->add_hook('authenticate', array($this, 'authenticate')); |
|
26 |
$this->add_hook('logout_after', array($this, 'logout')); |
|
27 |
} |
|
28 |
|
|
29 |
function startup($args) |
|
30 |
{ |
|
31 |
// change action to login |
|
32 |
if (empty($args['action']) && empty($_SESSION['user_id']) |
|
33 |
&& !empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) |
|
34 |
$args['action'] = 'login'; |
|
35 |
|
|
36 |
return $args; |
|
37 |
} |
|
38 |
|
|
39 |
function authenticate($args) |
|
40 |
{ |
|
41 |
// Allow entering other user data in login form, |
|
42 |
// e.g. after log out (#1487953) |
|
43 |
if (!empty($args['user'])) { |
|
44 |
return $args; |
|
45 |
} |
|
46 |
|
|
47 |
if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) { |
|
48 |
$args['user'] = $_SERVER['PHP_AUTH_USER']; |
|
49 |
$args['pass'] = $_SERVER['PHP_AUTH_PW']; |
|
50 |
} |
|
51 |
|
|
52 |
$args['cookiecheck'] = false; |
|
53 |
$args['valid'] = true; |
|
54 |
|
|
55 |
return $args; |
|
56 |
} |
|
57 |
|
|
58 |
function logout($args) |
|
59 |
{ |
|
60 |
// redirect to configured URL in order to clear HTTP auth credentials |
|
61 |
if (!empty($_SERVER['PHP_AUTH_USER']) && $args['user'] == $_SERVER['PHP_AUTH_USER'] && ($url = rcmail::get_instance()->config->get('logout_url'))) { |
|
62 |
header("Location: $url", true, 307); |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
} |
|
67 |
|