2012-08-16 11:30:35 +00:00
|
|
|
<?php
|
2012-12-27 11:14:44 +00:00
|
|
|
class Auth_Remote extends Plugin implements IAuthModule {
|
|
|
|
|
|
|
|
private $host;
|
2017-12-03 06:21:08 +00:00
|
|
|
/* @var Auth_Base $base */
|
2012-12-27 11:14:44 +00:00
|
|
|
private $base;
|
|
|
|
|
|
|
|
function about() {
|
|
|
|
return array(1.0,
|
|
|
|
"Authenticates against remote password (e.g. supplied by Apache)",
|
|
|
|
"fox",
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
2017-12-03 06:21:08 +00:00
|
|
|
/* @var PluginHost $host */
|
|
|
|
function init($host ) {
|
2012-12-27 11:14:44 +00:00
|
|
|
$this->host = $host;
|
2013-04-17 14:27:41 +00:00
|
|
|
$this->base = new Auth_Base();
|
2012-12-27 11:14:44 +00:00
|
|
|
|
|
|
|
$host->add_hook($host::HOOK_AUTH_USER, $this);
|
|
|
|
}
|
|
|
|
|
2012-08-16 11:30:35 +00:00
|
|
|
function get_login_by_ssl_certificate() {
|
2017-12-03 06:21:08 +00:00
|
|
|
$cert_serial = get_ssl_certificate_id();
|
2012-08-16 11:30:35 +00:00
|
|
|
|
|
|
|
if ($cert_serial) {
|
2017-12-03 06:21:08 +00:00
|
|
|
$sth = $this->pdo->prepare("SELECT login FROM ttrss_user_prefs, ttrss_users
|
|
|
|
WHERE pref_name = 'SSL_CERT_SERIAL' AND value = ? AND
|
2012-08-16 11:30:35 +00:00
|
|
|
owner_uid = ttrss_users.id");
|
2017-12-03 06:21:08 +00:00
|
|
|
$sth->execute([$cert_serial]);
|
2012-08-16 11:30:35 +00:00
|
|
|
|
2017-12-03 06:21:08 +00:00
|
|
|
if ($row = $sth->fetch()) {
|
|
|
|
return $row['login'];
|
2012-08-16 11:30:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-04-26 17:57:36 +00:00
|
|
|
/**
|
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
|
|
|
*/
|
2012-08-16 11:30:35 +00:00
|
|
|
function authenticate($login, $password) {
|
2017-12-03 06:21:08 +00:00
|
|
|
$try_login = $_SERVER["REMOTE_USER"];
|
2012-08-16 11:30:35 +00:00
|
|
|
|
2013-03-19 09:39:26 +00:00
|
|
|
// php-cgi
|
2017-12-03 06:21:08 +00:00
|
|
|
if (!$try_login) $try_login = $_SERVER["REDIRECT_REMOTE_USER"];
|
|
|
|
if (!$try_login) $try_login = $_SERVER["PHP_AUTH_USER"];
|
2013-03-19 09:39:26 +00:00
|
|
|
|
2012-08-16 11:30:35 +00:00
|
|
|
if (!$try_login) $try_login = $this->get_login_by_ssl_certificate();
|
|
|
|
|
|
|
|
if ($try_login) {
|
2013-05-07 07:35:10 +00:00
|
|
|
$user_id = $this->base->auto_create_user($try_login, $password);
|
2012-08-16 11:30:35 +00:00
|
|
|
|
|
|
|
if ($user_id) {
|
|
|
|
$_SESSION["fake_login"] = $try_login;
|
|
|
|
$_SESSION["fake_password"] = "******";
|
|
|
|
$_SESSION["hide_hello"] = true;
|
|
|
|
$_SESSION["hide_logout"] = true;
|
|
|
|
|
|
|
|
// LemonLDAP can send user informations via HTTP HEADER
|
|
|
|
if (defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE){
|
|
|
|
// update user name
|
|
|
|
$fullname = $_SERVER['HTTP_USER_NAME'] ? $_SERVER['HTTP_USER_NAME'] : $_SERVER['AUTHENTICATE_CN'];
|
|
|
|
if ($fullname){
|
2017-12-03 06:21:08 +00:00
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_users SET full_name = ? WHERE id = ?");
|
|
|
|
$sth->execute([$fullname, $user_id]);
|
2012-08-16 11:30:35 +00:00
|
|
|
}
|
|
|
|
// update user mail
|
|
|
|
$email = $_SERVER['HTTP_USER_MAIL'] ? $_SERVER['HTTP_USER_MAIL'] : $_SERVER['AUTHENTICATE_MAIL'];
|
|
|
|
if ($email){
|
2017-12-03 06:21:08 +00:00
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_users SET email = ? WHERE id = ?");
|
|
|
|
$sth->execute([$email, $user_id]);
|
2012-08-16 11:30:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $user_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-19 13:31:56 +00:00
|
|
|
|
|
|
|
function api_version() {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2012-08-16 11:30:35 +00:00
|
|
|
}
|