/usr/share/zabbix/include/perm.inc.php is in zabbix-frontend-php 1:2.4.7+dfsg-2ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | <?php
/*
** Zabbix
** Copyright (C) 2001-2015 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/**
* Get permission label.
*
* @param int $permission
*
* @return string
*/
function permission2str($permission) {
$permissions = array(
PERM_READ_WRITE => _('Read-write'),
PERM_READ => _('Read only'),
PERM_DENY => _('Deny')
);
return isset($permissions[$permission]) ? $permissions[$permission] : _('Unknown');
}
/**
* Get authentication label.
*
* @param int $type
*
* @return string
*/
function authentication2str($type) {
$authentications = array(
ZBX_AUTH_INTERNAL => _('Zabbix internal authentication'),
ZBX_AUTH_LDAP => _('LDAP authentication'),
ZBX_AUTH_HTTP => _('HTTP authentication')
);
return isset($authentications[$type]) ? $authentications[$type] : _('Unknown');
}
/***********************************************
CHECK USER ACCESS TO SYSTEM STATUS
************************************************/
/* Function: check_perm2system()
*
* Description:
* Checking user permissions to access system (affects server side: no notification will be sent)
*
* Comments:
* return true if permission is positive
*
* Author: Aly
*/
function check_perm2system($userid) {
$sql = 'SELECT g.usrgrpid'.
' FROM usrgrp g,users_groups ug'.
' WHERE ug.userid='.zbx_dbstr($userid).
' AND g.usrgrpid=ug.usrgrpid'.
' AND g.users_status='.GROUP_STATUS_DISABLED;
if ($res = DBfetch(DBselect($sql, 1))) {
return false;
}
return true;
}
/**
* Checking user permissions to login in frontend.
*
* @param string $userId
*
* @return bool
*/
function check_perm2login($userId) {
return (getUserGuiAccess($userId) != GROUP_GUI_ACCESS_DISABLED);
}
/**
* Get user gui access.
*
* @param string $userId
* @param int $maxGuiAccess
*
* @return int
*/
function getUserGuiAccess($userId, $maxGuiAccess = null) {
if (bccomp($userId, CWebUser::$data['userid']) == 0 && isset(CWebUser::$data['gui_access'])) {
return CWebUser::$data['gui_access'];
}
$guiAccess = DBfetch(DBselect(
'SELECT MAX(g.gui_access) AS gui_access'.
' FROM usrgrp g,users_groups ug'.
' WHERE ug.userid='.zbx_dbstr($userId).
' AND g.usrgrpid=ug.usrgrpid'.
(($maxGuiAccess === null) ? '' : ' AND g.gui_access<='.zbx_dbstr($maxGuiAccess))
));
return $guiAccess ? $guiAccess['gui_access'] : GROUP_GUI_ACCESS_SYSTEM;
}
/**
* Get user authentication type.
*
* @param string $userId
* @param int $maxGuiAccess
*
* @return int
*/
function getUserAuthenticationType($userId, $maxGuiAccess = null) {
$config = select_config();
switch (getUserGuiAccess($userId, $maxGuiAccess)) {
case GROUP_GUI_ACCESS_SYSTEM:
return $config['authentication_type'];
case GROUP_GUI_ACCESS_INTERNAL:
return ($config['authentication_type'] == ZBX_AUTH_HTTP) ? ZBX_AUTH_HTTP : ZBX_AUTH_INTERNAL;
default:
return $config['authentication_type'];
}
}
/**
* Get groups gui access.
*
* @param array $groupIds
* @param int $maxGuiAccess
*
* @return int
*/
function getGroupsGuiAccess($groupIds, $maxGuiAccess = null) {
$guiAccess = DBfetch(DBselect(
'SELECT MAX(g.gui_access) AS gui_access'.
' FROM usrgrp g'.
' WHERE '.dbConditionInt('g.usrgrpid', $groupIds).
(($maxGuiAccess === null) ? '' : ' AND g.gui_access<='.zbx_dbstr($maxGuiAccess))
));
return $guiAccess ? $guiAccess['gui_access'] : GROUP_GUI_ACCESS_SYSTEM;
}
/**
* Get group authentication type.
*
* @param array $groupIds
* @param int $maxGuiAccess
*
* @return int
*/
function getGroupAuthenticationType($groupIds, $maxGuiAccess = null) {
$config = select_config();
switch (getGroupsGuiAccess($groupIds, $maxGuiAccess)) {
case GROUP_GUI_ACCESS_SYSTEM:
return $config['authentication_type'];
case GROUP_GUI_ACCESS_INTERNAL:
return ($config['authentication_type'] == ZBX_AUTH_HTTP) ? ZBX_AUTH_HTTP : ZBX_AUTH_INTERNAL;
default:
return $config['authentication_type'];
}
}
/***********************************************
GET ACCESSIBLE RESOURCES BY RIGHTS
************************************************/
/* NOTE: right structure is
$rights[i]['type'] = type of resource
$rights[i]['permission']= permission for resource
$rights[i]['id'] = resource id
*/
function get_accessible_hosts_by_rights(&$rights, $user_type, $perm) {
$result = array();
$res_perm = array();
foreach ($rights as $id => $right) {
$res_perm[$right['id']] = $right['permission'];
}
$host_perm = array();
$where = array();
array_push($where, 'h.status in ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.','.HOST_STATUS_TEMPLATE.')');
array_push($where, dbConditionInt('h.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)));
$where = count($where) ? $where = ' WHERE '.implode(' AND ', $where) : '';
$perm_by_host = array();
$dbHosts = DBselect(
'SELECT hg.groupid AS groupid,h.hostid,h.host,h.name AS host_name,h.status'.
' FROM hosts h'.
' LEFT JOIN hosts_groups hg ON hg.hostid=h.hostid'.
$where
);
while ($dbHost = DBfetch($dbHosts)) {
if (isset($dbHost['groupid']) && isset($res_perm[$dbHost['groupid']])) {
if (!isset($perm_by_host[$dbHost['hostid']])) {
$perm_by_host[$dbHost['hostid']] = array();
}
$perm_by_host[$dbHost['hostid']][] = $res_perm[$dbHost['groupid']];
$host_perm[$dbHost['hostid']][$dbHost['groupid']] = $res_perm[$dbHost['groupid']];
}
$host_perm[$dbHost['hostid']]['data'] = $dbHost;
}
foreach ($host_perm as $hostid => $dbHost) {
$dbHost = $dbHost['data'];
// select min rights from groups
if (USER_TYPE_SUPER_ADMIN == $user_type) {
$dbHost['permission'] = PERM_READ_WRITE;
}
else {
if (isset($perm_by_host[$hostid])) {
$dbHost['permission'] = (min($perm_by_host[$hostid]) == PERM_DENY)
? PERM_DENY
: max($perm_by_host[$hostid]);
}
else {
$dbHost['permission'] = PERM_DENY;
}
}
if ($dbHost['permission'] < $perm) {
continue;
}
$result[$dbHost['hostid']] = $dbHost;
}
CArrayHelper::sort($result, array(
array('field' => 'host_name', 'order' => ZBX_SORT_UP)
));
return $result;
}
function get_accessible_groups_by_rights(&$rights, $user_type, $perm) {
$result = array();
$group_perm = array();
foreach ($rights as $right) {
$group_perm[$right['id']] = $right['permission'];
}
$dbHostGroups = DBselect('SELECT g.*,'.PERM_DENY.' AS permission FROM groups g');
while ($dbHostGroup = DBfetch($dbHostGroups)) {
if ($user_type == USER_TYPE_SUPER_ADMIN) {
$dbHostGroup['permission'] = PERM_READ_WRITE;
}
elseif (isset($group_perm[$dbHostGroup['groupid']])) {
$dbHostGroup['permission'] = $group_perm[$dbHostGroup['groupid']];
}
else {
$dbHostGroup['permission'] = PERM_DENY;
}
if ($dbHostGroup['permission'] < $perm) {
continue;
}
$result[$dbHostGroup['groupid']] = $dbHostGroup;
}
CArrayHelper::sort($result, array(
array('field' => 'name', 'order' => ZBX_SORT_UP)
));
return $result;
}
/**
* Returns array of user groups by $userId
*
* @param int $userId
*
* @return array
*/
function getUserGroupsByUserId($userId) {
static $userGroups;
if (!isset($userGroups[$userId])) {
$userGroups[$userId] = array();
$result = DBselect('SELECT usrgrpid FROM users_groups WHERE userid='.zbx_dbstr($userId));
while ($row = DBfetch($result)) {
$userGroups[$userId][] = $row['usrgrpid'];
}
}
return $userGroups[$userId];
}
|