1<?php declare(strict_types=1); 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$widget = (new CWidget()) 27 ->setTitle(_('API tokens')) 28 ->setTitleSubmenu(getUserSettingsSubmenu()); 29 30$token_form = (new CForm()) 31 ->setId('token_form') 32 ->setName('token') 33 ->setAttribute('aria-labeledby', ZBX_STYLE_PAGE_TITLE); 34 35$token_from_list = (new CFormList()) 36 ->addRow(_('Name').':', $data['name']) 37 ->addRow(_('Auth token').':', [ 38 $data['auth_token'], 39 ' ', 40 makeWarningIcon( 41 _("Make sure to copy the auth token as you won't be able to view it after the page is closed.") 42 ), 43 ' ', 44 (new CLinkAction(_('Copy to clipboard'))) 45 ->onClick('writeTextClipboard("'.$data['auth_token'].'")') 46 ->setAttribute('autofocus', 'autofocus') 47 ]) 48 ->addRow(_('Expires at').':', [ 49 ($data['expires_at'] == 0) ? '-' : date(DATE_TIME_FORMAT_SECONDS, (int) $data['expires_at']), 50 ($data['expires_at'] != 0 && time() > $data['expires_at']) 51 ? [' ', makeErrorIcon(_('The token has expired. Please update the expiry date to use the token.'))] 52 : null 53 ]) 54 ->addRow(_('Description').':', (new CDiv($data['description']))->addClass(ZBX_STYLE_WORDBREAK)) 55 ->addRow(new CLabel(_('Enabled').':', 'enabled'), 56 (new CCheckBox('enabled')) 57 ->setChecked($data['status'] == ZBX_AUTH_TOKEN_ENABLED) 58 ->setEnabled(false) 59 ); 60 61$token_view = (new CTabView())->addTab('token', '', $token_from_list); 62 63$token_view->setFooter(makeFormFooter((new CRedirectButton(_('Close'), (new CUrl('zabbix.php')) 64 ->setArgument('action', 'user.token.list') 65 ->setArgument('page', CPagerHelper::loadPage('user.token.list', null)) 66)))); 67 68$token_form->addItem($token_view); 69$widget 70 ->addItem($token_form) 71 ->show(); 72