You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
280 lines
8.1 KiB
280 lines
8.1 KiB
<?php declare(strict_types = 0);
|
|
/*
|
|
** Zabbix
|
|
** Copyright (C) 2001-2023 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.
|
|
**/
|
|
|
|
|
|
/**
|
|
* @var CView $this
|
|
* @var array $data
|
|
*/
|
|
|
|
$form = (new CForm('post'))
|
|
->addItem((new CVar(CCsrfTokenHelper::CSRF_TOKEN_NAME, CCsrfTokenHelper::get('proxy')))->removeId())
|
|
->setId('proxy-form')
|
|
->setName('proxy_form')
|
|
->addStyle('display: none;')
|
|
->addItem(getMessages());
|
|
|
|
// Enable form submitting on Enter.
|
|
$form->addItem((new CSubmitButton())->addClass(ZBX_STYLE_FORM_SUBMIT_HIDDEN));
|
|
|
|
// Proxy tab.
|
|
|
|
$interface = (new CTable())
|
|
->setHeader([_('Address'), _('Port')])
|
|
->addRow([
|
|
(new CTextBox('address', $data['form']['address'], false, DB::getFieldLength('proxy', 'address')))
|
|
->setWidth(336),
|
|
(new CTextBox('port', $data['form']['port'], false, DB::getFieldLength('proxy', 'port')))
|
|
->setWidth(ZBX_TEXTAREA_INTERFACE_PORT_WIDTH)
|
|
->setAriaRequired()
|
|
]);
|
|
|
|
$proxy_tab = (new CFormGrid())
|
|
->addItem([
|
|
(new CLabel(_('Proxy name'), 'name'))->setAsteriskMark(),
|
|
new CFormField(
|
|
(new CTextBox('name', $data['form']['name'], false, DB::getFieldLength('proxy', 'name')))
|
|
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
|
|
->setAriaRequired()
|
|
)
|
|
])
|
|
->addItem([
|
|
new CLabel(_('Proxy mode'), 'operating_mode'),
|
|
new CFormField(
|
|
(new CRadioButtonList('operating_mode', $data['form']['operating_mode']))
|
|
->addValue(_('Active'), PROXY_OPERATING_MODE_ACTIVE)
|
|
->addValue(_('Passive'), PROXY_OPERATING_MODE_PASSIVE)
|
|
->setModern(true)
|
|
)
|
|
])
|
|
->addItem([
|
|
(new CLabel(_('Interface')))
|
|
->addClass('js-interface')
|
|
->setAsteriskMark(),
|
|
(new CFormField(
|
|
(new CDiv($interface))->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)
|
|
))->addClass('js-interface')
|
|
])
|
|
->addItem([
|
|
(new CLabel(_('Proxy address'), 'allowed_addresses'))->addClass('js-proxy-address'),
|
|
(new CFormField(
|
|
(new CTextBox('allowed_addresses', $data['form']['allowed_addresses'], false,
|
|
DB::getFieldLength('proxy', 'allowed_addresses')
|
|
))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
|
|
))->addClass('js-proxy-address')
|
|
])
|
|
->addItem([
|
|
new CLabel(_('Description'), 'description'),
|
|
new CFormField(
|
|
(new CTextArea('description', $data['form']['description']))
|
|
->setMaxlength(DB::getFieldLength('proxy', 'description'))
|
|
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
|
|
)
|
|
]);
|
|
|
|
// Encryption tab.
|
|
|
|
$encryption_tab = (new CFormGrid())
|
|
->addItem([
|
|
new CLabel(_('Connections to proxy'), 'tls_connect'),
|
|
new CFormField(
|
|
(new CRadioButtonList('tls_connect', $data['form']['tls_connect']))
|
|
->addValue(_('No encryption'), HOST_ENCRYPTION_NONE)
|
|
->addValue(_('PSK'), HOST_ENCRYPTION_PSK)
|
|
->addValue(_('Certificate'), HOST_ENCRYPTION_CERTIFICATE)
|
|
->setModern(true)
|
|
)
|
|
])
|
|
->addItem([
|
|
new CLabel(_('Connections from proxy')),
|
|
new CFormField(
|
|
(new CList())
|
|
->addClass(ZBX_STYLE_LIST_CHECK_RADIO)
|
|
->addItem(
|
|
(new CCheckBox('tls_accept_none'))
|
|
->setLabel(_('No encryption'))
|
|
->setChecked(($data['form']['tls_accept'] & HOST_ENCRYPTION_NONE) != 0)
|
|
)
|
|
->addItem(
|
|
(new CCheckBox('tls_accept_psk'))
|
|
->setLabel(_('PSK'))
|
|
->setChecked(($data['form']['tls_accept'] & HOST_ENCRYPTION_PSK) != 0)
|
|
)
|
|
->addItem(
|
|
(new CCheckBox('tls_accept_certificate'))
|
|
->setLabel(_('Certificate'))
|
|
->setChecked(($data['form']['tls_accept'] & HOST_ENCRYPTION_CERTIFICATE) != 0)
|
|
)
|
|
)
|
|
])
|
|
->addItem([
|
|
(new CLabel(_('PSK identity'), 'tls_psk_identity'))
|
|
->addClass('js-tls-psk-identity')
|
|
->setAsteriskMark(),
|
|
(new CFormField(
|
|
(new CTextBox('tls_psk_identity', $data['form']['tls_psk_identity'], false,
|
|
DB::getFieldLength('proxy', 'tls_psk_identity')
|
|
))
|
|
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
|
|
->setAriaRequired()
|
|
))->addClass('js-tls-psk-identity')
|
|
])
|
|
->addItem([
|
|
(new CLabel(_('PSK'), 'tls_psk'))
|
|
->addClass('js-tls-psk')
|
|
->setAsteriskMark(),
|
|
(new CFormField(
|
|
(new CTextBox('tls_psk', $data['form']['tls_psk'], false, DB::getFieldLength('proxy', 'tls_psk')))
|
|
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
|
|
->setAriaRequired()
|
|
->disableAutocomplete()
|
|
))->addClass('js-tls-psk')
|
|
]);
|
|
|
|
if ($data['form']['tls_connect'] == HOST_ENCRYPTION_PSK
|
|
|| ($data['form']['tls_accept'] & HOST_ENCRYPTION_PSK) != 0) {
|
|
$encryption_tab->addItem([
|
|
(new CLabel(_('PSK')))
|
|
->addClass('js-tls-psk-change')
|
|
->setAsteriskMark(),
|
|
(new CFormField(
|
|
(new CSimpleButton(_('Change PSK')))
|
|
->setId('tls-psk-change')
|
|
->addClass(ZBX_STYLE_BTN_GREY)
|
|
))->addClass('js-tls-psk-change')
|
|
]);
|
|
}
|
|
|
|
$encryption_tab
|
|
->addItem([
|
|
(new CLabel(_('Issuer'), 'tls_issuer'))->addClass('js-tls-issuer'),
|
|
(new CFormField(
|
|
(new CTextBox('tls_issuer', $data['form']['tls_issuer'], false,
|
|
DB::getFieldLength('hosts', 'tls_issuer')
|
|
))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
|
|
))->addClass('js-tls-issuer')
|
|
])
|
|
->addItem([
|
|
(new CLabel(_x('Subject', 'encryption certificate'), 'tls_subject'))->addClass('js-tls-subject'),
|
|
(new CFormField(
|
|
(new CTextBox('tls_subject', $data['form']['tls_subject'], false,
|
|
DB::getFieldLength('hosts', 'tls_subject')
|
|
))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
|
|
))->addClass('js-tls-subject')
|
|
]);
|
|
|
|
$tabs = (new CTabView())
|
|
->setSelected(0)
|
|
->addTab('proxy-tab', _('Proxy'), $proxy_tab)
|
|
->addTab('proxy-encryption-tab', _('Encryption'), $encryption_tab, TAB_INDICATOR_PROXY_ENCRYPTION);
|
|
|
|
// Output.
|
|
|
|
$form
|
|
->addItem($tabs)
|
|
->addItem(
|
|
(new CScriptTag('
|
|
proxy_edit_popup.init('.json_encode([
|
|
'proxyid' => $data['proxyid']
|
|
]).');
|
|
'))->setOnDocumentReady()
|
|
);
|
|
|
|
if ($data['proxyid'] !== null) {
|
|
$title = _('Proxy');
|
|
$buttons = [
|
|
[
|
|
'title' => _('Update'),
|
|
'class' => 'js-update',
|
|
'keepOpen' => true,
|
|
'isSubmit' => true,
|
|
'action' => 'proxy_edit_popup.submit();'
|
|
],
|
|
[
|
|
'title' => _('Refresh configuration'),
|
|
'confirmation' => _('Refresh configuration of the selected proxy?'),
|
|
'class' => implode(' ', [ZBX_STYLE_BTN_ALT, 'js-refresh-config']),
|
|
'keepOpen' => true,
|
|
'isSubmit' => false,
|
|
'action' => 'proxy_edit_popup.refreshConfig();'
|
|
],
|
|
[
|
|
'title' => _('Clone'),
|
|
'class' => implode(' ', [ZBX_STYLE_BTN_ALT, 'js-clone']),
|
|
'keepOpen' => true,
|
|
'isSubmit' => false,
|
|
'action' => 'proxy_edit_popup.clone('.json_encode([
|
|
'title' => _('New proxy'),
|
|
'buttons' => [
|
|
[
|
|
'title' => _('Add'),
|
|
'class' => 'js-add',
|
|
'keepOpen' => true,
|
|
'isSubmit' => true,
|
|
'action' => 'proxy_edit_popup.submit();'
|
|
],
|
|
[
|
|
'title' => _('Cancel'),
|
|
'class' => implode(' ', [ZBX_STYLE_BTN_ALT, 'js-cancel']),
|
|
'cancel' => true,
|
|
'action' => ''
|
|
]
|
|
]
|
|
]).');'
|
|
],
|
|
[
|
|
'title' => _('Delete'),
|
|
'confirmation' => _('Delete selected proxy?'),
|
|
'class' => implode(' ', [ZBX_STYLE_BTN_ALT, 'js-delete']),
|
|
'keepOpen' => true,
|
|
'isSubmit' => false,
|
|
'action' => 'proxy_edit_popup.delete();'
|
|
]
|
|
];
|
|
}
|
|
else {
|
|
$title = _('New proxy');
|
|
$buttons = [
|
|
[
|
|
'title' => _('Add'),
|
|
'class' => 'js-add',
|
|
'keepOpen' => true,
|
|
'isSubmit' => true,
|
|
'action' => 'proxy_edit_popup.submit();'
|
|
]
|
|
];
|
|
}
|
|
|
|
$output = [
|
|
'header' => $title,
|
|
'doc_url' => CDocHelper::getUrl(CDocHelper::ADMINISTRATION_PROXY_EDIT),
|
|
'body' => $form->toString(),
|
|
'buttons' => $buttons,
|
|
'script_inline' => getPagePostJs().
|
|
$this->readJsFile('popup.proxy.edit.js.php')
|
|
];
|
|
|
|
if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) {
|
|
CProfiler::getInstance()->stop();
|
|
$output['debug'] = CProfiler::getInstance()->make()->toString();
|
|
}
|
|
|
|
echo json_encode($output);
|