1<?php 2/* 3** Zabbix 4** Copyright (C) 2001-2021 Zabbix SIA 5** 6** This program is free software; you can redistribute it and/or modify 7** it under the terms of the GNU General Public License as published by 8** the Free Software Foundation; either version 2 of the License, or 9** (at your option) any later version. 10** 11** This program is distributed in the hope that it will be useful, 12** but WITHOUT ANY WARRANTY; without even the implied warranty of 13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14** GNU General Public License for more details. 15** 16** You should have received a copy of the GNU General Public License 17** along with this program; if not, write to the Free Software 18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19**/ 20 21 22/** 23 * @var CView $this 24 */ 25 26$this->addJsFile('multiselect.js'); 27$this->includeJsFile('administration.user.list.js.php'); 28 29if ($data['uncheck']) { 30 uncheckTableRows('user'); 31} 32 33$widget = (new CWidget()) 34 ->setTitle(_('Users')) 35 ->setControls((new CList([ 36 (new CForm('get')) 37 ->cleanItems() 38 ->setName('main_filter') 39 ->setAttribute('aria-label', _('Main filter')) 40 ->addItem((new CVar('action', 'user.list'))->removeId()) 41 ->addItem((new CList()) 42 ->addItem([ 43 new CLabel(_('User group'), 'label-filter-usrgrpid'), 44 (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), 45 (new CSelect('filter_usrgrpid')) 46 ->setId('filter-usrgrpid') 47 ->setValue($data['filter_usrgrpid']) 48 ->setFocusableElementId('label-filter-usrgrpid') 49 ->addOptions(CSelect::createOptionsFromArray($data['user_groups'])) 50 ]) 51 ), 52 (new CTag('nav', true, 53 (new CList()) 54 ->addItem(new CRedirectButton(_('Create user'), 'zabbix.php?action=user.edit')) 55 ))->setAttribute('aria-label', _('Content controls')) 56 ])) 57 ) 58 ->addItem((new CFilter((new CUrl('zabbix.php'))->setArgument('action', 'user.list'))) 59 ->setProfile($data['profileIdx']) 60 ->setActiveTab($data['active_tab']) 61 ->addFilterTab(_('Filter'), [ 62 (new CFormList())->addRow(_('Username'), 63 (new CTextBox('filter_username', $data['filter']['username'])) 64 ->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH) 65 ->setAttribute('autofocus', 'autofocus') 66 ), 67 (new CFormList())->addRow(_('Name'), 68 (new CTextBox('filter_name', $data['filter']['name']))->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH) 69 ), 70 (new CFormList())->addRow(_('Surname'), 71 (new CTextBox('filter_surname', $data['filter']['surname']))->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH) 72 ), 73 (new CFormList())->addRow((new CLabel(_('User roles'), 'filter_roles')), 74 (new CMultiSelect([ 75 'name' => 'filter_roles[]', 76 'object_name' => 'roles', 77 'data' => $data['filter']['roles'], 78 'popup' => [ 79 'parameters' => [ 80 'srctbl' => 'roles', 81 'srcfld1' => 'roleid', 82 'dstfrm' => 'zbx_filter', 83 'dstfld1' => 'filter_roles_' 84 ] 85 ] 86 ]))->setWidth(ZBX_TEXTAREA_MEDIUM_WIDTH) 87 ) 88 ]) 89 ->addVar('action', 'user.list') 90 ); 91 92$form = (new CForm()) 93 ->setName('user_form') 94 ->setId('users'); 95 96// create users table 97$url = (new CUrl('zabbix.php')) 98 ->setArgument('action', 'user.list') 99 ->getUrl(); 100 101$table = (new CTableInfo()) 102 ->setHeader([ 103 (new CColHeader( 104 (new CCheckBox('all_users'))->onClick("checkAll('".$form->getName()."', 'all_users', 'userids');") 105 ))->addClass(ZBX_STYLE_CELL_WIDTH), 106 make_sorting_header(_('Username'), 'username', $data['sort'], $data['sortorder'], $url), 107 make_sorting_header(_x('Name', 'user first name'), 'name', $data['sort'], $data['sortorder'], $url), 108 make_sorting_header(_('Surname'), 'surname', $data['sort'], $data['sortorder'], $url), 109 make_sorting_header(_('User role'), 'role_name', $data['sort'], $data['sortorder'], $url), 110 _('Groups'), 111 _('Is online?'), 112 _('Login'), 113 _('Frontend access'), 114 _('API access'), 115 _('Debug mode'), 116 _('Status') 117 ]); 118 119foreach ($data['users'] as $user) { 120 $userid = $user['userid']; 121 $session = $data['sessions'][$userid]; 122 123 // Online time. 124 if ($session['lastaccess']) { 125 $autologout = timeUnitToSeconds($user['autologout']); 126 127 $online_time = ($autologout == 0 || ZBX_USER_ONLINE_TIME < $autologout) 128 ? ZBX_USER_ONLINE_TIME 129 : $autologout; 130 131 $online = ($session['status'] == ZBX_SESSION_ACTIVE && $user['users_status'] == GROUP_STATUS_ENABLED 132 && ($session['lastaccess'] + $online_time) >= time()) 133 ? (new CCol(_('Yes').' ('.zbx_date2str(DATE_TIME_FORMAT_SECONDS, $session['lastaccess']).')')) 134 ->addClass(ZBX_STYLE_GREEN) 135 : (new CCol(_('No').' ('.zbx_date2str(DATE_TIME_FORMAT_SECONDS, $session['lastaccess']).')')) 136 ->addClass(ZBX_STYLE_RED); 137 } 138 else { 139 $online = (new CCol(_('No')))->addClass(ZBX_STYLE_RED); 140 } 141 142 $blocked = ($user['attempt_failed'] >= $data['config']['login_attempts']) 143 ? (new CLink(_('Blocked'), 'zabbix.php?action=user.unblock&userids[]='.$userid)) 144 ->addClass(ZBX_STYLE_LINK_ACTION) 145 ->addClass(ZBX_STYLE_RED) 146 ->addSID() 147 : (new CSpan(_('Ok')))->addClass(ZBX_STYLE_GREEN); 148 149 order_result($user['usrgrps'], 'name'); 150 151 $users_groups = []; 152 $i = 0; 153 154 foreach ($user['usrgrps'] as $user_group) { 155 $i++; 156 157 if ($i > $data['config']['max_in_table']) { 158 $users_groups[] = ' …'; 159 160 break; 161 } 162 163 if ($users_groups) { 164 $users_groups[] = ', '; 165 } 166 167 $group = $data['allowed_ui_user_grpups'] 168 ? (new CLink($user_group['name'], (new CUrl('zabbix.php')) 169 ->setArgument('action', 'usergroup.edit') 170 ->setArgument('usrgrpid', $user_group['usrgrpid']) 171 ->getUrl() 172 ))->addClass(ZBX_STYLE_LINK_ALT) 173 : new CSpan($user_group['name']); 174 175 $style = ($user_group['gui_access'] == GROUP_GUI_ACCESS_DISABLED 176 || $user_group['users_status'] == GROUP_STATUS_DISABLED) 177 ? ZBX_STYLE_RED 178 : ZBX_STYLE_GREEN; 179 180 $users_groups[] = $group->addClass($style); 181 } 182 183 // GUI Access style. 184 switch ($user['gui_access']) { 185 case GROUP_GUI_ACCESS_INTERNAL: 186 $gui_access_style = ZBX_STYLE_ORANGE; 187 break; 188 189 case GROUP_GUI_ACCESS_DISABLED: 190 $gui_access_style = ZBX_STYLE_GREY; 191 break; 192 193 default: 194 $gui_access_style = ZBX_STYLE_GREEN; 195 } 196 197 $username = new CLink($user['username'], (new CUrl('zabbix.php')) 198 ->setArgument('action', 'user.edit') 199 ->setArgument('userid', $userid) 200 ); 201 202 if (!CRoleHelper::checkAccess(CRoleHelper::API_ACCESS, $user['roleid'])) { 203 $api_access = (new CSpan(_('Disabled')))->addClass(ZBX_STYLE_RED); 204 } 205 else { 206 $api_access = (new CSpan(_('Enabled')))->addClass(ZBX_STYLE_GREEN); 207 $api_methods = CRoleHelper::getRoleApiMethods($user['roleid']); 208 209 if ($api_methods) { 210 $hint_api_methods = []; 211 $status_class = CRoleHelper::checkAccess(CRoleHelper::API_MODE, $user['roleid']) 212 ? ZBX_STYLE_STATUS_GREEN 213 : ZBX_STYLE_STATUS_GREY; 214 215 foreach ($api_methods as $api_method) { 216 $hint_api_methods[] = (new CSpan($api_method))->addClass($status_class); 217 } 218 219 $api_access->setHint((new CDiv($hint_api_methods))->addClass('rules-status-container')); 220 } 221 } 222 223 // Append user to table. 224 $table->addRow([ 225 new CCheckBox('userids['.$userid.']', $userid), 226 (new CCol($username))->addClass(ZBX_STYLE_NOWRAP), 227 $user['name'], 228 $user['surname'], 229 $user['role']['name'], 230 $users_groups, 231 $online, 232 $blocked, 233 (new CSpan(user_auth_type2str($user['gui_access'])))->addClass($gui_access_style), 234 $api_access, 235 ($user['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) 236 ? (new CSpan(_('Enabled')))->addClass(ZBX_STYLE_ORANGE) 237 : (new CSpan(_('Disabled')))->addClass(ZBX_STYLE_GREEN), 238 ($user['users_status'] == GROUP_STATUS_DISABLED) 239 ? (new CSpan(_('Disabled')))->addClass(ZBX_STYLE_RED) 240 : (new CSpan(_('Enabled')))->addClass(ZBX_STYLE_GREEN) 241 ]); 242} 243 244// Append table to form. 245$form->addItem([ 246 $table, 247 $data['paging'], 248 new CActionButtonList('action', 'userids', [ 249 'user.unblock' => ['name' => _('Unblock'), 'confirm' => _('Unblock selected users?')], 250 'user.delete' => ['name' => _('Delete'), 'confirm' => _('Delete selected users?')] 251 ], 'user') 252]); 253 254// Append form to widget. 255$widget 256 ->addItem($form) 257 ->show(); 258