<?php declare(strict_types = 0);
class CControllerWebScenarioStepCheck extends CController {
protected function init(): void {
$this->setPostContentType(self::POST_CONTENT_TYPE_JSON);
$this->disableCsrfValidation();
protected function checkInput(): bool {
'httpstepid' => 'db httpstep.httpstepid',
'name' => 'required|not_empty|db httpstep.name',
'url' => 'required|not_empty|db httpstep.url',
'timeout' => 'required|not_empty|db httpstep.timeout',
'posts' => 'db httpstep.posts',
'required' => 'db httpstep.required',
'status_codes' => 'db httpstep.status_codes',
'follow_redirects' => 'db httpstep.follow_redirects|in '.implode(',', [HTTPTEST_STEP_FOLLOW_REDIRECTS_OFF, HTTPTEST_STEP_FOLLOW_REDIRECTS_ON]),
'retrieve_mode' => 'db httpstep.retrieve_mode|in '.implode(',', [HTTPTEST_STEP_RETRIEVE_MODE_CONTENT, HTTPTEST_STEP_RETRIEVE_MODE_HEADERS, HTTPTEST_STEP_RETRIEVE_MODE_BOTH]),
'post_type' => 'db httpstep.post_type|in '.implode(',', [ZBX_POSTTYPE_RAW, ZBX_POSTTYPE_FORM]),
'query_fields' => 'array',
'post_fields' => 'array',
$ret = $this->validateInput($fields) && $this->validateFields();
(new CControllerResponseData(['main_block' => json_encode([
'title' => $this->getInput('old_name', '') === ''
? _('Cannot create web scenario step')
: _('Cannot update web scenario step'),
'messages' => array_column(get_and_clear_messages(), 'message')
private function validateFields(): bool {
$name = $this->getInput('name');
if ($name !== $this->getInput('old_name', '') && in_array($name, $this->getInput('names', []))) {
error(_s('Step with name "%1$s" already exists.', $name));
if (CHtmlUrlValidator::validate($this->getInput('url')) === false) {
error(_s('Incorrect value for field "%1$s": %2$s.', 'url', _('unacceptable URL')));
$timeout = $this->getInput('timeout');
$simple_interval_parser = new CSimpleIntervalParser(['usermacros' => true]);
if ($simple_interval_parser->parse($timeout) != CParser::PARSE_SUCCESS) {
error(_s('Incorrect value for field "%1$s": %2$s.', 'timeout', _('a time unit is expected')));
elseif ($timeout[0] !== '{') {
$seconds = timeUnitToSeconds($timeout);
if ($seconds < 1 || $seconds > SEC_PER_HOUR) {
error(_s('Incorrect value for field "%1$s": %2$s.', 'timeout',