2021-02-06 19:14:58 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class mailu extends rcube_plugin
|
|
|
|
{
|
|
|
|
|
|
|
|
function init()
|
|
|
|
{
|
|
|
|
$this->add_hook('startup', array($this, 'startup'));
|
|
|
|
$this->add_hook('authenticate', array($this, 'authenticate'));
|
|
|
|
$this->add_hook('login_after', array($this, 'login'));
|
|
|
|
$this->add_hook('login_failed', array($this, 'login_failed'));
|
|
|
|
$this->add_hook('logout_after', array($this, 'logout'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function startup($args)
|
|
|
|
{
|
|
|
|
if (empty($_SESSION['user_id'])) {
|
2021-12-18 17:43:18 +02:00
|
|
|
$args['action'] = 'login';
|
|
|
|
}
|
|
|
|
|
|
|
|
$ua = $_SERVER['HTTP_USER_AGENT'];
|
|
|
|
$ra = $_SERVER['REMOTE_ADDR'];
|
|
|
|
if ($ua == 'health' and ($ra == '127.0.0.1' or $ra == '::1')) {
|
|
|
|
print('OK');
|
|
|
|
exit();
|
2021-02-06 19:14:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $args;
|
|
|
|
}
|
|
|
|
|
|
|
|
function authenticate($args)
|
|
|
|
{
|
2021-11-03 16:18:00 +02:00
|
|
|
if (!array_key_exists('HTTP_X_REMOTE_USER', $_SERVER) or !array_key_exists('HTTP_X_REMOTE_USER_TOKEN', $_SERVER)) {
|
2021-12-18 17:43:18 +02:00
|
|
|
if ($_SERVER['PHP_SELF'] == '/sso.php') {
|
|
|
|
header('HTTP/1.0 403 Forbidden');
|
|
|
|
print('mailu sso failure');
|
|
|
|
} else {
|
|
|
|
header('Location: sso.php');
|
|
|
|
}
|
|
|
|
exit();
|
2021-02-06 19:14:58 +02:00
|
|
|
}
|
2021-11-03 20:16:37 +02:00
|
|
|
|
2021-02-06 19:14:58 +02:00
|
|
|
$args['user'] = $_SERVER['HTTP_X_REMOTE_USER'];
|
|
|
|
$args['pass'] = $_SERVER['HTTP_X_REMOTE_USER_TOKEN'];
|
|
|
|
|
|
|
|
$args['cookiecheck'] = false;
|
|
|
|
$args['valid'] = true;
|
|
|
|
|
|
|
|
return $args;
|
|
|
|
}
|
|
|
|
|
2021-11-03 20:16:37 +02:00
|
|
|
// Redirect to global SSO logout path.
|
|
|
|
function logout($args)
|
|
|
|
{
|
2021-02-06 19:14:58 +02:00
|
|
|
$this->load_config();
|
|
|
|
$sso_logout_url = rcmail::get_instance()->config->get('sso_logout_url');
|
2021-11-03 20:16:37 +02:00
|
|
|
header('Location: ' . $sso_logout_url, true);
|
|
|
|
exit();
|
2021-02-06 19:14:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function login($args)
|
|
|
|
{
|
2021-12-18 17:43:18 +02:00
|
|
|
header('Location: index.php');
|
|
|
|
exit();
|
2021-02-06 19:14:58 +02:00
|
|
|
}
|
2021-11-03 20:16:37 +02:00
|
|
|
|
2021-02-06 19:14:58 +02:00
|
|
|
function login_failed($args)
|
|
|
|
{
|
2021-12-18 17:43:18 +02:00
|
|
|
header('Location: sso.php');
|
|
|
|
exit();
|
2021-02-06 19:14:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|