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