Welcome to mirror list, hosted at ThFree Co, Russian Federation.

administration.script.edit.php « views « app « ui - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4811b6cfc534d903270c27f63cb1716c4cea4b6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
/*
** Zabbix
** Copyright (C) 2001-2022 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
 */

$this->addJsFile('multilineinput.js');

$this->includeJsFile('administration.script.edit.js.php');

$html_page = (new CHtmlPage())
	->setTitle(_('Scripts'))
	->setDocUrl(CDocHelper::getUrl(CDocHelper::ALERTS_SCRIPT_EDIT));

$row_template = (new CTag('script', true))
	->setId('parameters-row')
	->setAttribute('type', 'text/x-jquery-tmpl')
	->addItem(
		(new CRow([
			(new CTextBox('parameters[name][]', '', false, DB::getFieldLength('script_param', 'name')))
				->setAttribute('style', 'width: 100%;')
				->removeId(),
			(new CTextBox('parameters[value][]', '', false, DB::getFieldLength('script_param', 'value')))
				->setAttribute('style', 'width: 100%;')
				->removeId(),
			(new CButton('', _('Remove')))
				->removeId()
				->onClick('$(this).closest("tr").remove()')
				->addClass(ZBX_STYLE_BTN_LINK)
				->addClass('element-table-remove')
		]))->addClass('form_row')
	);

$html_page->addItem($row_template);

$form = (new CForm())
	->setId('script-form')
	->setName('scripts')
	->setAttribute('aria-labelledby', CHtmlPage::PAGE_TITLE_ID)
	->addVar('form', 1)
	->addVar('scriptid', $data['scriptid']);

$parameters_table = (new CTable())
	->setId('parameters-table')
	->setHeader([
		(new CColHeader(_('Name')))->setWidth('50%'),
		(new CColHeader(_('Value')))->setWidth('50%'),
		_('Action')
	])
	->setAttribute('style', 'width: 100%;');

foreach ($data['parameters'] as $parameter) {
	$parameters_table->addRow([
		(new CTextBox('parameters[name][]', $parameter['name'], false, DB::getFieldLength('script_param', 'name')))
			->setAttribute('style', 'width: 100%;')
			->removeId(),
		(new CTextBox('parameters[value][]', $parameter['value'], false, DB::getFieldLength('script_param', 'value')))
			->setAttribute('style', 'width: 100%;')
			->removeId(),
		(new CButton('', _('Remove')))
			->removeId()
			->onClick('$(this).closest("tr").remove()')
			->addClass(ZBX_STYLE_BTN_LINK)
			->addClass('element-table-remove')
	], 'form_row');
}

$parameters_table->addRow([
	(new CButton('parameter_add', _('Add')))
		->addClass(ZBX_STYLE_BTN_LINK)
		->addClass('element-table-add')
]);

$form_list = (new CFormList())
	->addRow((new CLabel(_('Name'), 'name'))->setAsteriskMark(),
		(new CTextBox('name', $data['name'], false, DB::getFieldLength('scripts', 'name')))
			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
			->setAttribute('autofocus', 'autofocus')
			->setAriaRequired()
	)
	->addRow(new CLabel(_('Scope'), 'scope'),
		(new CRadioButtonList('scope', (int) $data['scope']))
			->addValue(_('Action operation'), ZBX_SCRIPT_SCOPE_ACTION)
			->addValue(_('Manual host action'), ZBX_SCRIPT_SCOPE_HOST)
			->addValue(_('Manual event action'), ZBX_SCRIPT_SCOPE_EVENT)
			->setModern(true)
			->setEnabled(!$data['actions'])
	)
	->addRow(new CLabel(_('Menu path'), 'menu_path'),
		(new CTextBox('menu_path', $data['menu_path'], false, DB::getFieldLength('scripts', 'menu_path')))
			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
			->setAttribute('placeholder', _('<sub-menu/sub-menu/...>'))
			->setId('menu-path')
	)
	->addRow((new CLabel(_('Type'), 'type')),
		(new CRadioButtonList('type', (int) $data['type']))
			->addValue(_('URL'), ZBX_SCRIPT_TYPE_URL)
			->addValue(_('Webhook'), ZBX_SCRIPT_TYPE_WEBHOOK)
			->addValue(_('Script'), ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT)
			->addValue(_('SSH'), ZBX_SCRIPT_TYPE_SSH)
			->addValue(_('Telnet'), ZBX_SCRIPT_TYPE_TELNET)
			->addValue(_('IPMI'), ZBX_SCRIPT_TYPE_IPMI)
			->setModern(true)
	)
	->addRow(new CLabel(_('Execute on'), 'execute_on'),
		(new CRadioButtonList('execute_on', (int) $data['execute_on']))
			->addValue(_('Zabbix agent'), ZBX_SCRIPT_EXECUTE_ON_AGENT)
			->addValue(_('Zabbix server (proxy)'), ZBX_SCRIPT_EXECUTE_ON_PROXY)
			->addValue(_('Zabbix server'), ZBX_SCRIPT_EXECUTE_ON_SERVER)
			->setModern(true)
			->setId('execute-on')
	)
	->addRow(new CLabel(_('Authentication method'), 'authtype'),
		(new CSelect('authtype'))
			->setId('authtype')
			->setValue($data['authtype'])
			->setFocusableElementId('authtype')
			->addOptions(CSelect::createOptionsFromArray([
				ITEM_AUTHTYPE_PASSWORD => _('Password'),
				ITEM_AUTHTYPE_PUBLICKEY => _('Public key')
			]))
	)
	->addRow((new CLabel(_('Username'), 'username'))->setAsteriskMark(),
		(new CTextBox('username', $data['username'], false, DB::getFieldLength('scripts', 'username')))
			->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
			->setAriaRequired()
	)
	->addRow((new CLabel(_('Public key file'), 'publickey'))->setAsteriskMark(),
		(new CTextBox('publickey', $data['publickey'], false, DB::getFieldLength('scripts', 'publickey')))
			->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
			->setAriaRequired()
	)
	->addRow((new CLabel(_('Private key file'), 'privatekey'))->setAsteriskMark(),
		(new CTextBox('privatekey', $data['privatekey'], false, DB::getFieldLength('scripts', 'privatekey')))
			->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
			->setAriaRequired()
	)
	->addRow(new CLabel(_('Password'), 'password'),
		(new CTextBox('password', $data['password'], false, DB::getFieldLength('scripts', 'password')))
			->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
	)
	->addRow(new CLabel(_('Key passphrase'), 'passphrase'),
		(new CTextBox('passphrase', $data['passphrase'], false, DB::getFieldLength('scripts', 'password')))
			->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
	)
	->addRow(new CLabel(_('Port'), 'port'),
		(new CTextBox('port', $data['port'], false, DB::getFieldLength('scripts', 'port')))
			->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
	)
	->addRow((new CLabel(_('Commands'), 'command'))->setAsteriskMark(),
		(new CTextArea('command', $data['command']))
			->addClass(ZBX_STYLE_MONOSPACE_FONT)
			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
			->setMaxlength(DB::getFieldLength('scripts', 'command'))
			->setAriaRequired()
	)
	->addRow((new CLabel(_('Command'), 'commandipmi'))->setAsteriskMark(),
		(new CTextBox('commandipmi', $data['commandipmi'], false, DB::getFieldLength('scripts', 'command')))
			->addClass(ZBX_STYLE_MONOSPACE_FONT)
			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
			->setAriaRequired()
	)
	->addRow(new CLabel(_('Parameters'), $parameters_table->getId()),
		(new CDiv($parameters_table))
			->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)
			->setAttribute('style', 'min-width: '.ZBX_TEXTAREA_STANDARD_WIDTH.'px;'),
		'row-webhook-parameters'
	)
	->addRow((new CLabel(_('URL'), 'url'))->setAsteriskMark(),
		(new CTextBox('url', $data['url'], false, DB::getFieldLength('scripts', 'url')))
			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
			->setAriaRequired()
	)
	->addRow(_('Open in a new window'),
		(new CCheckBox('new_window'))
			->setChecked($data['new_window'])
			->setUncheckedValue(ZBX_SCRIPT_URL_NEW_WINDOW_NO)
	)
	->addRow((new CLabel(_('Script'), 'script'))->setAsteriskMark(),
		(new CMultilineInput('script', $data['script'], [
			'title' => _('JavaScript'),
			'placeholder' => _('script'),
			'placeholder_textarea' => 'return value',
			'grow' => 'auto',
			'rows' => 0,
			'maxlength' => DB::getFieldLength('scripts', 'command')
		]))
			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
			->setAriaRequired()
	)
	->addRow((new CLabel(_('Timeout'), 'timeout'))->setAsteriskMark(),
		(new CTextBox('timeout', $data['timeout'], false, DB::getFieldLength('scripts', 'timeout')))
			->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
			->setAriaRequired()
	)
	->addRow(_('Description'),
		(new CTextArea('description', $data['description']))
			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
			->setMaxlength(DB::getFieldLength('scripts', 'description'))
	);

$select_usrgrpid = (new CSelect('usrgrpid'))
	->setId('user-group')
	->setValue($data['usrgrpid'])
	->setFocusableElementId('usrgrpid')
	->addOption(new CSelectOption(0, _('All')))
	->addOptions(CSelect::createOptionsFromArray($data['usergroups']));

$select_hgstype = (new CSelect('hgstype'))
	->setId('hgstype-select')
	->setValue($data['hgstype'])
	->setFocusableElementId('hgstype')
	->addOption(new CSelectOption(0, _('All')))
	->addOption(new CSelectOption(1, _('Selected')));

$form_list
	->addRow(new CLabel(_('Host group'), $select_hgstype->getFocusableElementId()), $select_hgstype)
	->addRow(null,
		(new CMultiSelect([
			'name' => 'groupid',
			'object_name' => 'hostGroup',
			'multiple' => false,
			'data' => $data['hostgroup'],
			'popup' => [
				'parameters' => [
					'srctbl' => 'host_groups',
					'srcfld1' => 'groupid',
					'dstfrm' => $form->getName(),
					'dstfld1' => 'groupid'
				]
			]
		]))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
		'host-group-selection'
	)
	->addRow(new CLabel(_('User group'), $select_usrgrpid->getFocusableElementId()), $select_usrgrpid)
	->addRow((new CLabel(_('Required host permissions'), 'host_access')),
		(new CRadioButtonList('host_access', (int) $data['host_access']))
			->addValue(_('Read'), PERM_READ)
			->addValue(_('Write'), PERM_READ_WRITE)
			->setModern(true)
			->setId('host-access')
	)
	->addRow(_('Enable confirmation'),
		(new CCheckBox('enable_confirmation'))
			->setChecked($data['enable_confirmation'])
			->setId('enable-confirmation')
	)
	->addRow(new CLabel(_('Confirmation text'), 'confirmation'), [
		(new CTextBox('confirmation', $data['confirmation'], false, DB::getFieldLength('scripts', 'confirmation')))
			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
		SPACE,
		(new CButton('testConfirmation', _('Test confirmation')))
			->addClass(ZBX_STYLE_BTN_GREY)
			->setId('test-confirmation')
	]
);

$scriptView = (new CTabView())->addTab('scripts', _('Script'), $form_list);

// footer
$cancelButton = (new CRedirectButton(_('Cancel'),
	(new CUrl('zabbix.php'))
		->setArgument('action', 'script.list')
		->setArgument('page', CPagerHelper::loadPage('script.list', null))
))->setId('cancel');

if ($data['scriptid'] == 0) {
	$addButton = (new CSubmitButton(_('Add'), 'action', 'script.create'))->setId('add');

	$scriptView->setFooter(makeFormFooter(
		$addButton,
		[$cancelButton]
	));
}
else {
	$updateButton = (new CSubmitButton(_('Update'), 'action', 'script.update'))->setId('update');
	$cloneButton = (new CSimpleButton(_('Clone')))->setId('clone');
	$deleteButton = (new CRedirectButton(_('Delete'),
		(new CUrl('zabbix.php'))
			->setArgument('action', 'script.delete')
			->setArgument('scriptids[]', $data['scriptid'])
			->setArgumentSID(),
		_('Delete script?')
	))->setId('delete');

	$scriptView->setFooter(makeFormFooter(
		$updateButton,
		[
			$cloneButton,
			$deleteButton,
			$cancelButton
		]
	));
}

$form->addItem($scriptView);

$html_page->addItem($form)->show();