2012-08-16 13:30:35 +02:00
|
|
|
<?php
|
2012-12-27 12:14:44 +01:00
|
|
|
class Auth_Remote extends Plugin implements IAuthModule {
|
|
|
|
|
|
|
|
private $host;
|
|
|
|
private $base;
|
|
|
|
|
|
|
|
function about() {
|
|
|
|
return array(1.0,
|
|
|
|
"Authenticates against remote password (e.g. supplied by Apache)",
|
|
|
|
"fox",
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
2013-04-17 16:27:41 +02:00
|
|
|
function init($host) {
|
2012-12-27 12:14:44 +01:00
|
|
|
$this->host = $host;
|
2013-04-17 16:27:41 +02:00
|
|
|
$this->base = new Auth_Base();
|
2012-12-27 12:14:44 +01:00
|
|
|
|
|
|
|
$host->add_hook($host::HOOK_AUTH_USER, $this);
|
|
|
|
}
|
|
|
|
|
2012-08-16 13:30:35 +02:00
|
|
|
function get_login_by_ssl_certificate() {
|
2013-04-17 14:23:15 +02:00
|
|
|
$cert_serial = db_escape_string( get_ssl_certificate_id());
|
2012-08-16 13:30:35 +02:00
|
|
|
|
|
|
|
if ($cert_serial) {
|
2013-04-17 14:23:15 +02:00
|
|
|
$result = db_query( "SELECT login FROM ttrss_user_prefs, ttrss_users
|
2012-08-16 13:30:35 +02:00
|
|
|
WHERE pref_name = 'SSL_CERT_SERIAL' AND value = '$cert_serial' AND
|
|
|
|
owner_uid = ttrss_users.id");
|
|
|
|
|
|
|
|
if (db_num_rows($result) != 0) {
|
2013-04-17 14:23:15 +02:00
|
|
|
return db_escape_string( db_fetch_result($result, 0, "login"));
|
2012-08-16 13:30:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function authenticate($login, $password) {
|
2013-04-17 14:23:15 +02:00
|
|
|
$try_login = db_escape_string( $_SERVER["REMOTE_USER"]);
|
2012-08-16 13:30:35 +02:00
|
|
|
|
2013-03-19 10:39:26 +01:00
|
|
|
// php-cgi
|
2013-04-17 14:23:15 +02:00
|
|
|
if (!$try_login) $try_login = db_escape_string( $_SERVER["REDIRECT_REMOTE_USER"]);
|
2013-03-19 10:39:26 +01:00
|
|
|
|
2012-08-16 13:30:35 +02:00
|
|
|
if (!$try_login) $try_login = $this->get_login_by_ssl_certificate();
|
|
|
|
# if (!$try_login) $try_login = "test_qqq";
|
|
|
|
|
|
|
|
if ($try_login) {
|
2012-12-27 12:14:44 +01:00
|
|
|
$user_id = $this->base->auto_create_user($try_login);
|
2012-08-16 13:30:35 +02: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){
|
2013-04-17 14:23:15 +02:00
|
|
|
$fullname = db_escape_string( $fullname);
|
|
|
|
db_query( "UPDATE ttrss_users SET full_name = '$fullname' WHERE id = " .
|
2012-08-16 13:30:35 +02:00
|
|
|
$user_id);
|
|
|
|
}
|
|
|
|
// update user mail
|
|
|
|
$email = $_SERVER['HTTP_USER_MAIL'] ? $_SERVER['HTTP_USER_MAIL'] : $_SERVER['AUTHENTICATE_MAIL'];
|
|
|
|
if ($email){
|
2013-04-17 14:23:15 +02:00
|
|
|
$email = db_escape_string( $email);
|
|
|
|
db_query( "UPDATE ttrss_users SET email = '$email' WHERE id = " .
|
2012-08-16 13:30:35 +02:00
|
|
|
$user_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $user_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|