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$output = [
23	'header' => $data['title']
24];
25
26$options = $data['options'];
27
28$http_popup_form = (new CForm())
29	->cleanItems()
30	->setId('http_step')
31	->addVar('no', $options['no'])
32	->addVar('httpstepid', $options['httpstepid'])
33	->addItem((new CVar('templated', $options['templated']))->removeId())
34	->addVar('old_name', $options['old_name'])
35	->addVar('steps_names', $options['steps_names'])
36	->addVar('action', 'popup.httpstep')
37	->addItem((new CInput('submit', 'submit'))->addStyle('display: none;'));
38
39$http_popup_form_list = (new CFormList())
40	->addRow(
41		(new CLabel(_('Name'), 'step_name'))->setAsteriskMark(),
42		(new CTextBox('name', $options['name'], (bool) $options['templated'], 64))
43			->setAriaRequired()
44			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
45			->setId('step_name')
46	)
47	->addRow(
48		(new CLabel(_('URL'), 'url'))->setAsteriskMark(),
49		new CDiv([
50			(new CTextBox('url', $options['url'], false, null))
51				->setAriaRequired()
52				->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
53			(new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN),
54			(new CButton('parse', _('Parse')))
55				->onClick('httpconf.steps.edit_form.parseUrl();')
56				->addClass(ZBX_STYLE_BTN_GREY)
57		])
58	);
59
60$http_popup_form_list->addRow(_('Query fields'),
61	(new CDiv(
62		(new CTable())
63			->addClass('httpconf-dynamic-row')
64			->addStyle('width: 100%;')
65			->setAttribute('data-type', 'query_fields')
66			->setHeader(['', _('Name'), '', _('Value'), ''])
67			->addRow((new CRow([
68				(new CCol(
69					(new CButton(null, _('Add')))
70						->addClass('element-table-add')
71						->addClass(ZBX_STYLE_BTN_LINK)
72				))->setColSpan(5)
73			])))
74	))
75		->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)
76		->addStyle('min-width: '.ZBX_TEXTAREA_BIG_WIDTH . 'px;'),
77		'query-fields-row'
78);
79
80$http_popup_form_list->addRow(_('Post type'), (new CRadioButtonList('post_type', (int) $options['post_type']))
81	->addValue(_('Form data'), ZBX_POSTTYPE_FORM)
82	->addValue(_('Raw data'), ZBX_POSTTYPE_RAW)
83	->setModern(true)
84);
85
86$http_popup_form_list->addRow(_('Post fields'),
87	(new CDiv(
88		(new CTable())
89			->addClass('httpconf-dynamic-row')
90			->addStyle('width: 100%;')
91			->setAttribute('data-type', 'post_fields')
92			->setHeader(['', _('Name'), '', _('Value'), ''])
93			->addRow((new CRow([
94				(new CCol(
95					(new CButton(null, _('Add')))
96						->addClass('element-table-add')
97						->addClass(ZBX_STYLE_BTN_LINK)
98				))->setColSpan(5)
99			])))
100	))
101		->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)
102		->addStyle('min-width: '.ZBX_TEXTAREA_BIG_WIDTH . 'px;'),
103		'post-fields-row'
104);
105
106$http_popup_form_list->addRow(_('Raw post'), (new CTextArea('posts', $options['posts']))
107	->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), 'post-raw-row'
108);
109
110$http_popup_form_list->addRow(_('Variables'),
111	(new CDiv(
112		(new CTable())
113			->addClass('httpconf-dynamic-row')
114			->setAttribute('data-type', 'variables')
115			->addStyle('width: 100%;')
116			->setHeader(['', _('Name'), '', _('Value'), ''])
117			->addRow((new CRow([
118				(new CCol(
119					(new CButton(null, _('Add')))
120						->addClass('element-table-add')
121						->addClass(ZBX_STYLE_BTN_LINK)
122				))->setColSpan(5)
123			])))
124	))
125		->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)
126		->addStyle('min-width: '.ZBX_TEXTAREA_BIG_WIDTH . 'px;')
127);
128
129$http_popup_form_list->addRow(_('Headers'),
130	(new CDiv(
131		(new CTable())
132			->addClass('httpconf-dynamic-row')
133			->setAttribute('data-type', 'headers')
134			->addStyle('width: 100%;')
135			->setHeader(['', _('Name'), '', _('Value'), ''])
136			->addRow((new CRow([
137				(new CCol(
138					(new CButton(null, _('Add')))
139						->addClass('element-table-add')
140						->addClass(ZBX_STYLE_BTN_LINK)
141				))->setColSpan(5)
142			])))
143	))
144		->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)
145		->addStyle('min-width: '.ZBX_TEXTAREA_BIG_WIDTH . 'px;')
146);
147
148$http_popup_form_list
149	->addRow(_('Follow redirects'),
150		(new CCheckBox('follow_redirects'))
151			->setChecked($options['follow_redirects'] == HTTPTEST_STEP_FOLLOW_REDIRECTS_ON)
152	)
153	->addRow(_('Retrieve only headers'),
154		(new CCheckBox('retrieve_mode'))
155			->setChecked($options['retrieve_mode'] == HTTPTEST_STEP_RETRIEVE_MODE_HEADERS)
156	)
157	->addRow((new CLabel(_('Timeout'), 'timeout'))->setAsteriskMark(),
158		(new CTextBox('timeout', $options['timeout']))
159			->setAriaRequired()
160			->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
161	)
162	->addRow(_('Required string'),
163		(new CTextBox('required', $options['required']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
164	)
165	->addRow(_('Required status codes'),
166		(new CTextBox('status_codes', $options['status_codes']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
167	);
168
169$output['buttons'] = [
170	[
171		'title' => $options['old_name'] ? _('Update') : _('Add'),
172		'class' => '',
173		'keepOpen' => true,
174		'isSubmit' => true,
175		'action' => 'return httpconf.steps.edit_form.validate();'
176	]
177];
178
179$http_popup_form->addItem($http_popup_form_list);
180
181// HTTP test step editing form.
182$output['body'] = (new CDiv($http_popup_form))->toString();
183$output['script_inline'] = 'httpconf.steps.onStepOverlayReadyCb('.$options['no'].');';
184
185if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) {
186	CProfiler::getInstance()->stop();
187	$output['debug'] = CProfiler::getInstance()->make()->toString();
188}
189
190echo (new CJson())->encode($output);
191