summaryrefslogtreecommitdiffstats
path: root/library/nagvis-includes/CoreAuthorisationModIcingaweb2.php
blob: 111ecbae78fb0db49c6557e4d584f3fb804bd33b (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php

use Icinga\Application\Icinga;
use Icinga\Authentication\Auth;
use Icinga\Module\Nagvis\RestrictionHelper;

class CoreAuthorisationModIcingaweb2 extends CoreAuthorisationModule
{
    public $rolesConfigurable = false;

    private $auth;

    public function __construct()
    {
        $this->auth = Auth::getInstance();
    }

    public function parsePermissions($sUsername = null)
    {
        global $CORE;

        if ($sUsername !== null) {
            die('parsePermissions() with username is not supported');
        }

        $perms = array(
            'General'  => array('*' => array('*' => true)),
            'User'     => array('setOption' => array('*' => true)),
            'Search'   => array('view' => array('*' => true)),
            'Rotation' => array('view' => array('*' => true))
        );

        $restriction = RestrictionHelper::getRegex();
        if ($restriction !== null) {
            $maps = array();
            foreach ($CORE->getAvailableMaps($restriction) as $map) {
                $maps[$map] = true;
            }
            if (! empty($maps)) {
                $perms['Map'] = array('view' => $maps);
            }
        } else {
            $perms['Map'] = array('view' => array('*' => true));
        }

        if ($this->auth->hasPermission('nagvis/overview')) {
            $perms['Overview'] = array('view' => array('*' => true));
        }

        // Never allowed:
        // ChangePassword - change
        // Auth - logout
        // UserMgmt - manage
        // RoleMgmt - manage
        // Action - perform - *

        if ($this->auth->hasPermission('nagvis/edit')) {
            $perms['ManageShapes']      = array('manage' => array('*' => true));
            $perms['ManageBackgrounds'] = array('manage' => array('*' => true));
            $perms['Overview']['edit']  = array('*' => true);
            $perms['Map']['add']    = array('*' => true);
            $perms['Map']['edit']   = array('*' => true);
            $perms['Map']['manage'] = array('*' => true);
        }

        if ($this->auth->hasPermission('nagvis/admin')) {
            $perms['MainCfg'] = array('edit' => array('*' => true));
        }

        return $perms;
    }

    public function getUserRoles($userId)
    {
        // $userId is now the username
        return array();
        die("getUserRoles($userId)");
        return array(0 => array('name' => 'Administrators'));
        // [ { roleId, name }, ... ]
    }

    public function getAllRoles()
    {
        // die('getAllRoles');
        // User menu -> Manage Users
        return array();
        // [ { roleId, name }, ... ]
    }


    // I want to get rid of those :(

    public function isPermitted($sModule, $sAction, $sObj = null)
    {
        die("isPermitted($sModule, $sAction, $sObj) - should never be called");
        return false;
    }

    public function deletePermission($mod, $name)
    {
        return false;
        // $mod -> Map, Rotation
    }

    public function createPermission($mod, $name)
    {
        return false;
    }

    public function roleUsedBy($roleId)
    {
        die("roleUsedBy($roleId)");
        return array();
        // [ name , ... ]
    }

    public function deleteRole($roleId)
    {
        return false;
    }

    public function deleteUser($userId)
    {
        return false;
    }

    public function updateUserRoles($userId, $roles)
    {
        return false;
        // roles = [roleId, ...]
    }


    public function getRoleId($sRole)
    {
        die("getRoleId($sRole)");
        return 0;
    }

    public function getAllPerms()
    {
        die('getAllPerms');
        return array();
        // [ { permId, mod, act, obj }, ... ]
    }

    public function getRolePerms($roleId) {
        die("getRolePerms($roleId)");
        return array();
        // [ permId => true, ... ]
    }

    public function updateRolePerms($roleId, $perms)
    {
        // $perms = [ permId, ... ]
        return false;
    }

    public function checkRoleExists($name)
    {
        die("checkRoleExists($name)");
        return false;
    }

    public function createRole($name)
    {
        die("createRole($name)");
        return true;
    }


    private function checkUserExistsById($id)
    {
        die('checkUserExistsById');
        return false;
    }

    public function getUserId($sUsername)
    {
        die('getUserId');
        return 0;
    }
}