Issues (1270)

plugins/auth_remote/init.php (1 issue)

Labels
Severity
1
<?php
2
class Auth_Remote extends Plugin implements IAuthModule {
3
4
    private $host;
5
    /* @var Auth_Base $base */
6
    private $base;
7
8
    public function about() {
9
        return array(1.0,
10
            "Authenticates against remote password (e.g. supplied by Apache)",
11
            "fox",
12
            true);
13
    }
14
15
    /* @var PluginHost $host */
16
    public function init($host) {
17
        $this->host = $host;
18
        $this->base = new Auth_Base();
19
20
        $host->add_hook($host::HOOK_AUTH_USER, $this);
21
    }
22
23
    public function get_login_by_ssl_certificate() {
24
        $cert_serial = get_ssl_certificate_id();
25
26
        if ($cert_serial) {
27
            $sth = $this->pdo->prepare("SELECT login FROM ttrss_user_prefs, ttrss_users
28
				WHERE pref_name = 'SSL_CERT_SERIAL' AND value = ? AND
29
				owner_uid = ttrss_users.id");
30
            $sth->execute([$cert_serial]);
31
32
            if ($row = $sth->fetch()) {
33
                return $row['login'];
34
            }
35
        }
36
37
        return "";
38
    }
39
40
    /**
41
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
42
     */
43
    public function authenticate($login, $password) {
44
        $try_login = $_SERVER["REMOTE_USER"];
45
46
        // php-cgi
47
        if (!$try_login) {
48
            $try_login = $_SERVER["REDIRECT_REMOTE_USER"];
49
        }
50
        if (!$try_login) {
51
            $try_login = $_SERVER["PHP_AUTH_USER"];
52
        }
53
54
        if (!$try_login) {
55
            $try_login = $this->get_login_by_ssl_certificate();
56
        }
57
58
        if ($try_login) {
59
            $user_id = $this->base->auto_create_user($try_login, $password);
60
61
            if ($user_id) {
62
                $_SESSION["fake_login"] = $try_login;
63
                $_SESSION["fake_password"] = "******";
64
                $_SESSION["hide_hello"] = true;
65
                $_SESSION["hide_logout"] = true;
66
67
                // LemonLDAP can send user informations via HTTP HEADER
68
                if (defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE) {
0 ignored issues
show
The constant AUTH_AUTO_CREATE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
69
                    // update user name
70
                    $fullname = $_SERVER['HTTP_USER_NAME'] ? $_SERVER['HTTP_USER_NAME'] : $_SERVER['AUTHENTICATE_CN'];
71
                    if ($fullname) {
72
                        $sth = $this->pdo->prepare("UPDATE ttrss_users SET full_name = ? WHERE id = ?");
73
                        $sth->execute([$fullname, $user_id]);
74
                    }
75
                    // update user mail
76
                    $email = $_SERVER['HTTP_USER_MAIL'] ? $_SERVER['HTTP_USER_MAIL'] : $_SERVER['AUTHENTICATE_MAIL'];
77
                    if ($email) {
78
                        $sth = $this->pdo->prepare("UPDATE ttrss_users SET email = ? WHERE id = ?");
79
                        $sth->execute([$email, $user_id]);
80
                    }
81
                }
82
83
                return $user_id;
84
            }
85
        }
86
87
        return false;
88
    }
89
90
    public function api_version() {
91
        return 2;
92
    }
93
94
}
95