summaryrefslogtreecommitdiffstats
path: root/library/nagvis-includes/CoreAuthModIcingaweb2.php
blob: da042985bf2ecb3113e22852004587d66cae1d34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php

use Icinga\Application\Icinga;
use Icinga\Authentication\Auth;

class CoreAuthModIcingaweb2 extends CoreAuthModule
{
    private $app;
    private $auth;
    private $user;

    private $iUserId = -1;
    private $sUsername = '';
    private $sPassword = '';
    private $sPasswordnew = '';
    private $sPasswordHash = '';

    public function __construct()
    {
        parent::$aFeatures = array(
            // General functions for authentication
            'passCredentials' => false,
            'getCredentials' => false,
            'isAuthenticated' => true,
            'getUser' => true,
            'getUserId' => true,

            // Changing passwords
            'passNewPassword' => false,
            'changePassword' => false,
            'passNewPassword' => false,

            // Managing users
            'createUser' => false,
        );

        $oldname = session_name();
        session_write_close();
        $old_path = ini_get('session.cookie_path');
        $old_id = session_id();
        $cacheLimiter = ini_get('session.cache_limiter');
        ini_set('session.use_cookies', false);
        ini_set('session.use_only_cookies', false);
        ini_set('session.cache_limiter', null);
        ini_set('session.cookie_path', '/');
        $icookie = 'Icingaweb2';
        if (isset($_COOKIE[$icookie])) {
            session_id($_COOKIE[$icookie]);
        }

        $this->app = Icinga::app();
        $this->auth = Auth::getInstance();
        if ($this->auth->isAuthenticated()) {
            $this->user = $this->auth->getUser();
        }
        ini_set('session.cookie_path', $old_path);
        session_id($old_id);
        session_name($oldname);
        ini_set('session.use_cookies', true);
        ini_set('session.use_only_cookies', true);
        ini_set('session.cache_limiter', $cacheLimiter);
    }

    public function getAllUsers()
    {
        die('getAllUsers');
        return array();
        // assoc -> userId, name
    }

    public function checkUserExists($name)
    {
        return true;
    }

    private function updatePassword()
    {
        return true;
    }

    private function addUser($user, $hash)
    {
        return true;
    }

    public function passCredentials($aData)
    {
        // die('pass ' . print_r($aData, 1));
        // eventually has user, password and passwordHash
    }

    public function passNewPassword($aData)
    {
        // die('new pass');
        // eventually has user, password and passwordHash
    }

    public function getCredentials()
    {
        return Array('user' => $this->getUser(),
                     'passwordHash' => null,
                     'userId' => $this->getUserId());
    }

    public function createUser($user, $password)
    {
        return false;
    }

    public function changePassword()
    {
        return false;
    }

    public function isAuthenticated($bTrustUsername = AUTH_NOT_TRUST_USERNAME)
    {
        return $this->user !== null;
    }

    public function getUser()
    {
        return $this->user->getUsername();
    }

    public function getUserId()
    {
        return $this->getUser();
    }
}