Welcome to mirror list, hosted at ThFree Co, Russian Federation.

users.inc.php « include « php « frontends - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8e4e419d20a7f508bdb9aba36b1c3c6f5a805e61 (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
<?php
/*
** Zabbix
** Copyright (C) 2000-2011 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., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
?>
<?php
function getUserTheme($user) {
	$config = select_config();
	if (isset($config['default_theme'])) {
		$css = $config['default_theme'];
	}
	if (isset($user['theme']) && $user['theme'] != ZBX_DEFAULT_CSS && $user['alias'] != ZBX_GUEST_USER) {
		$css = $user['theme'];
	}
	if (!isset($css)) {
		$css = 'css_ob.css';
	}
	return $css;
}

function user_type2str($user_type = null) {
	$user_types = array(
		USER_TYPE_ZABBIX_USER => _('Zabbix User'),
		USER_TYPE_ZABBIX_ADMIN => _('Zabbix Admin'),
		USER_TYPE_SUPER_ADMIN => _('Zabbix Super Admin'),
	);
	if (is_null($user_type)) {
		return $user_types;
	}
	elseif (isset($user_types[$user_type])) {
		return $user_types[$user_type];
	}
	else {
		return _('Unknown');
	}
}

function user_auth_type2str($auth_type) {
	if (is_null($auth_type)) {
		$auth_type = get_user_auth(CWebUser::$data['userid']);
	}
	$auth_user_type[GROUP_GUI_ACCESS_SYSTEM] = _('System default');
	$auth_user_type[GROUP_GUI_ACCESS_INTERNAL] = _('Internal');
	$auth_user_type[GROUP_GUI_ACCESS_DISABLED] = _('Disabled');

	if (isset($auth_user_type[$auth_type])) {
		return $auth_user_type[$auth_type];
	}
	return _('Unknown');
}

function unblock_user_login($userids) {
	zbx_value2array($userids);
	return DBexecute('UPDATE users SET attempt_failed=0 WHERE '.DBcondition('userid', $userids));
}

function get_userid_by_usrgrpid($usrgrpids) {
	zbx_value2array($usrgrpids);
	$userids = array();
	$sql = 'SELECT DISTINCT u.userid '.
			' FROM users u,users_groups ug '.
			' WHERE u.userid=ug.userid '.
				' AND '.DBcondition('ug.usrgrpid', $usrgrpids).
				' AND '.DBin_node('ug.usrgrpid', false);
	$db_users = DBselect($sql);
	while($user = DBFetch($db_users)){
		$userids[$user['userid']] = $user['userid'];
	}
	return $userids;
}

function add_user_to_group($userid, $usrgrpid) {
	$result = false;
	if (granted2move_user($userid,$usrgrpid)) {
		DBexecute('DELETE FROM users_groups WHERE userid='.$userid.' AND usrgrpid='.$usrgrpid);
		$users_groups_id = get_dbid('users_groups', 'id');
		$result = DBexecute('INSERT INTO users_groups (id,usrgrpid,userid) VALUES ('.$users_groups_id.','.$usrgrpid.','.$userid.')');
	}
	else{
		error(_('User cannot change status of himself'));
	}
	return $result;
}

function remove_user_from_group($userid, $usrgrpid) {
	$result = false;
	if (granted2move_user($userid,$usrgrpid)) {
		$result = DBexecute('DELETE FROM users_groups WHERE userid='.$userid.' AND usrgrpid='.$usrgrpid);
	}
	else {
		error(_('User cannot change status of himself'));
	}
	return $result;
}

// checks if user is adding himself to disabled group
function granted2update_group($usrgrpids) {
	zbx_value2array($usrgrpids);
	$users = get_userid_by_usrgrpid($usrgrpids);
	return (!isset($users[CWebUser::$data['userid']]));
}

// checks if user is adding himself to disabled group
function granted2move_user($userid, $usrgrpid) {
	$result = true;
	$group = API::UserGroup()->get(array('usrgrpids' => $usrgrpid, 'output' => API_OUTPUT_EXTEND));
	$group = reset($group);
	if ($group['gui_access'] == GROUP_GUI_ACCESS_DISABLED || $group['users_status'] == GROUP_STATUS_DISABLED){
		$result = (bccomp(CWebUser::$data['userid'], $userid) != 0);
	}
	return $result;
}

function change_group_status($usrgrpids, $users_status) {
	zbx_value2array($usrgrpids);
	$result = false;
	$grant = true;
	if ($users_status == GROUP_STATUS_DISABLED) {
		$grant = granted2update_group($usrgrpids);
	}
	if ($grant) {
		$result = DBexecute('UPDATE usrgrp SET users_status='.$users_status.' WHERE '.DBcondition('usrgrpid', $usrgrpids));
	}
	else {
		error(_('User cannot change status of himself'));
	}
	return $result;
}

function change_group_gui_access($usrgrpids, $gui_access) {
	zbx_value2array($usrgrpids);
	$result = false;
	$grant = true;
	if ($gui_access == GROUP_GUI_ACCESS_DISABLED) {
		$grant = granted2update_group($usrgrpids);
	}
	if ($grant) {
		$result = DBexecute('UPDATE usrgrp SET gui_access='.$gui_access.' WHERE '.DBcondition('usrgrpid',$usrgrpids));
	}
	else {
		error(_('User cannot change GUI access for himself'));
	}
	return $result;
}

function change_group_debug_mode($usrgrpids, $debug_mode){
	zbx_value2array($usrgrpids);
	return DBexecute('UPDATE usrgrp SET debug_mode='.$debug_mode.' WHERE '.DBcondition('usrgrpid', $usrgrpids));
}
?>