2012-08-16 11:30:35 +00:00
|
|
|
<?php
|
2021-02-08 16:11:31 +00:00
|
|
|
class Auth_Remote extends Auth_Base {
|
2012-12-27 11:14:44 +00:00
|
|
|
|
|
|
|
function about() {
|
2021-03-01 09:11:42 +00:00
|
|
|
return array(null,
|
2012-12-27 11:14:44 +00:00
|
|
|
"Authenticates against remote password (e.g. supplied by Apache)",
|
|
|
|
"fox",
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
2021-02-08 16:11:31 +00:00
|
|
|
function init($host) {
|
2012-12-27 11:14:44 +00:00
|
|
|
$host->add_hook($host::HOOK_AUTH_USER, $this);
|
|
|
|
}
|
|
|
|
|
2021-11-14 18:09:53 +00:00
|
|
|
function get_login_by_ssl_certificate() : string {
|
2021-03-01 07:20:21 +00:00
|
|
|
$cert_serial = Pref_Prefs::_get_ssl_certificate_id();
|
2012-08-16 11:30:35 +00:00
|
|
|
|
|
|
|
if ($cert_serial) {
|
2021-02-25 09:46:13 +00:00
|
|
|
$sth = $this->pdo->prepare("SELECT login FROM ttrss_user_prefs2, ttrss_users
|
2017-12-03 06:21:08 +00:00
|
|
|
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 "";
|
|
|
|
}
|
|
|
|
|
2021-11-14 08:11:49 +00:00
|
|
|
function authenticate($login, $password, $service = '') {
|
2021-01-05 07:37:30 +00:00
|
|
|
$try_login = "";
|
2012-08-16 11:30:35 +00:00
|
|
|
|
2021-01-05 07:37:30 +00:00
|
|
|
foreach (["REMOTE_USER", "HTTP_REMOTE_USER", "REDIRECT_REMOTE_USER", "PHP_AUTH_USER"] as $hdr) {
|
2021-01-07 08:18:02 +00:00
|
|
|
if (!empty($_SERVER[$hdr])) {
|
2021-01-05 15:55:05 +00:00
|
|
|
$try_login = $_SERVER[$hdr];
|
2021-01-05 07:37:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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) {
|
2021-02-08 16:11:31 +00:00
|
|
|
$user_id = $this->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
|
2021-02-23 06:01:27 +00:00
|
|
|
if (Config::get(Config::AUTH_AUTO_CREATE)) {
|
2012-08-16 11:30:35 +00:00
|
|
|
// update user name
|
2021-02-11 06:57:57 +00:00
|
|
|
$fullname = isset($_SERVER['HTTP_USER_NAME']) ? $_SERVER['HTTP_USER_NAME'] : ($_SERVER['AUTHENTICATE_CN'] ?? "");
|
2012-08-16 11:30:35 +00:00
|
|
|
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
|
2021-02-11 06:57:57 +00:00
|
|
|
$email = isset($_SERVER['HTTP_USER_MAIL']) ? $_SERVER['HTTP_USER_MAIL'] : ($_SERVER['AUTHENTICATE_MAIL'] ?? "");
|
2012-08-16 11:30:35 +00:00
|
|
|
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
|
|
|
}
|