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
27new CViewSwitcher('type-select', 'change', <?= json_encode([
28	SVC_SSH => ['row_dcheck_ports'],
29	SVC_LDAP => ['row_dcheck_ports'],
30	SVC_SMTP => ['row_dcheck_ports'],
31	SVC_FTP => ['row_dcheck_ports'],
32	SVC_HTTP => ['row_dcheck_ports'],
33	SVC_POP => ['row_dcheck_ports'],
34	SVC_NNTP => ['row_dcheck_ports'],
35	SVC_IMAP => ['row_dcheck_ports'],
36	SVC_TCP => ['row_dcheck_ports'],
37	SVC_AGENT => ['row_dcheck_ports', 'row_dcheck_key'],
38	SVC_SNMPv1 => ['row_dcheck_ports', 'row_dcheck_snmp_community', 'row_dcheck_snmp_oid'],
39	SVC_SNMPv2c => ['row_dcheck_ports', 'row_dcheck_snmp_community', 'row_dcheck_snmp_oid'],
40	SVC_ICMPPING => [],
41	SVC_SNMPv3 => ['row_dcheck_ports', 'row_dcheck_snmp_oid', 'row_dcheck_snmpv3_contextname',
42		'row_dcheck_snmpv3_securityname', 'row_dcheck_snmpv3_securitylevel', 'row_dcheck_snmpv3_authprotocol',
43		'row_dcheck_snmpv3_authpassphrase', 'row_dcheck_snmpv3_privprotocol', 'row_dcheck_snmpv3_privpassphrase'
44	],
45	SVC_HTTPS => ['row_dcheck_ports'],
46	SVC_TELNET => ['row_dcheck_ports']
47]) ?>);
48
49var $type = jQuery('#type-select'),
50	$snmpv3_securitylevel = jQuery('#snmpv3-securitylevel');
51
52$type.on('change', function() {
53	$snmpv3_securitylevel.off('change');
54
55	if (jQuery(this).val() == <?= SVC_SNMPv3 ?>) {
56		new CViewSwitcher('snmpv3-securitylevel', 'change', <?= json_encode([
57			ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV => [],
58			ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV => ['row_dcheck_snmpv3_authprotocol',
59				'row_dcheck_snmpv3_authpassphrase'
60			],
61			ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV => ['row_dcheck_snmpv3_authprotocol', 'row_dcheck_snmpv3_authpassphrase',
62				'row_dcheck_snmpv3_privprotocol', 'row_dcheck_snmpv3_privpassphrase'
63			]
64		]) ?>);
65
66		$snmpv3_securitylevel.on('change', function() {
67			jQuery(window).trigger('resize');
68		});
69	}
70
71	jQuery(window).trigger('resize');
72});
73
74if ($type.val() == <?= SVC_SNMPv3 ?>) {
75	// Fires the change event to initialize CViewSwitcher.
76	$type.trigger('change');
77
78	// Now we can add the event to clear the form on type change.
79	$type.on('change', function() {
80		clearDCheckForm();
81		setDCheckDefaultPort();
82	});
83}
84else {
85	$type.on('change', function() {
86		clearDCheckForm();
87		setDCheckDefaultPort();
88	});
89}
90
91/**
92 * Resets fields of the discovery check form to default values.
93 */
94function clearDCheckForm() {
95	jQuery('#key_, #snmp_community, #snmp_oid, #snmpv3_contextname, #snmpv3_securityname, #snmpv3_authpassphrase, ' +
96		'#snmpv3_privpassphrase').val('');
97	jQuery('#snmpv3-securitylevel').val(<?= ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV ?>);
98	jQuery('#snmpv3_authprotocol_0, #snmpv3_privprotocol_0').prop('checked', true);
99}
100