]> git.wh0rd.org - tt-rss.git/blob - plugins/auth_remote/auth_remote.php
move authentication modules to plugins/
[tt-rss.git] / plugins / auth_remote / auth_remote.php
1 <?php
2 class Auth_Remote extends Plugin implements IAuthModule {
3
4 private $link;
5 private $host;
6 private $base;
7
8 function about() {
9 return array(1.0,
10 "Authenticates against remote password (e.g. supplied by Apache)",
11 "fox",
12 true);
13 }
14
15 function init($host) {
16 $this->link = $host->get_link();
17 $this->host = $host;
18 $this->base = new Auth_Base($this->link);
19
20 $host->add_hook($host::HOOK_AUTH_USER, $this);
21 }
22
23 function get_login_by_ssl_certificate() {
24 $cert_serial = db_escape_string(get_ssl_certificate_id());
25
26 if ($cert_serial) {
27 $result = db_query($this->link, "SELECT login FROM ttrss_user_prefs, ttrss_users
28 WHERE pref_name = 'SSL_CERT_SERIAL' AND value = '$cert_serial' AND
29 owner_uid = ttrss_users.id");
30
31 if (db_num_rows($result) != 0) {
32 return db_escape_string(db_fetch_result($result, 0, "login"));
33 }
34 }
35
36 return "";
37 }
38
39
40 function authenticate($login, $password) {
41 $try_login = db_escape_string($_SERVER["REMOTE_USER"]);
42
43 if (!$try_login) $try_login = $this->get_login_by_ssl_certificate();
44 # if (!$try_login) $try_login = "test_qqq";
45
46 if ($try_login) {
47 $user_id = $this->base->auto_create_user($try_login);
48
49 if ($user_id) {
50 $_SESSION["fake_login"] = $try_login;
51 $_SESSION["fake_password"] = "******";
52 $_SESSION["hide_hello"] = true;
53 $_SESSION["hide_logout"] = true;
54
55 // LemonLDAP can send user informations via HTTP HEADER
56 if (defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE){
57 // update user name
58 $fullname = $_SERVER['HTTP_USER_NAME'] ? $_SERVER['HTTP_USER_NAME'] : $_SERVER['AUTHENTICATE_CN'];
59 if ($fullname){
60 $fullname = db_escape_string($fullname);
61 db_query($this->link, "UPDATE ttrss_users SET full_name = '$fullname' WHERE id = " .
62 $user_id);
63 }
64 // update user mail
65 $email = $_SERVER['HTTP_USER_MAIL'] ? $_SERVER['HTTP_USER_MAIL'] : $_SERVER['AUTHENTICATE_MAIL'];
66 if ($email){
67 $email = db_escape_string($email);
68 db_query($this->link, "UPDATE ttrss_users SET email = '$email' WHERE id = " .
69 $user_id);
70 }
71 }
72
73 return $user_id;
74 }
75 }
76
77 return false;
78 }
79 }
80
81 ?>