forked from NagVis/nagvis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stub_multisite_auth.php
106 lines (92 loc) · 2.61 KB
/
stub_multisite_auth.php
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
<?php
// This file exists to make static analysis understand what NagVis includes at runtime. This file is
// created by Checkmk in real environments to hand over user, group and role information to NagVis.
global $mk_users, $mk_roles, $mk_groups;
$mk_users = array();
$mk_roles = array();
$mk_groups = array();
function all_users() {
global $mk_users;
return $mk_users;
}
function user_roles($username) {
global $mk_users;
if(!isset($mk_users[$username]))
return array();
else
return $mk_users[$username]['roles'];
}
function user_groups($username) {
global $mk_users;
if(!isset($mk_users[$username]) || !isset($mk_users[$username]['contactgroups']))
return array();
else
return $mk_users[$username]['contactgroups'];
}
function user_permissions($username) {
global $mk_roles;
$permissions = array();
foreach(user_roles($username) AS $role)
$permissions = array_merge($permissions, $mk_roles[$role]);
// Make the array uniq
array_flip($permissions);
array_flip($permissions);
return $permissions;
}
function users_with_role($want_role) {
global $mk_users, $mk_roles;
$result = array();
foreach($mk_users AS $username => $user) {
foreach($user['roles'] AS $role) {
if($want_role == $role) {
$result[] = $username;
}
}
}
return $result;
}
function roles_with_permission($want_permission) {
global $mk_roles;
$result = array();
foreach($mk_roles AS $rolename => $role) {
foreach($role AS $permission) {
if($permission == $want_permission) {
$result[] = $rolename;
break;
}
}
}
return $result;
}
function users_with_permission($need_permission) {
global $mk_users;
$result = array();
foreach(roles_with_permission($need_permission) AS $rolename) {
$result = array_merge($result, users_with_role($rolename));
}
return $result;
}
function may($username, $need_permission) {
global $mk_roles;
foreach(user_roles($username) AS $role) {
foreach($mk_roles[$role] AS $permission) {
if($need_permission == $permission) {
return true;
}
}
}
return false;
}
function permitted_maps($username) {
global $mk_groups;
$maps = array();
foreach (user_groups($username) AS $groupname) {
if (isset($mk_groups[$groupname])) {
foreach ($mk_groups[$groupname] AS $mapname) {
$maps[$mapname] = null;
}
}
}
return array_keys($maps);
}
?>