<?php declare(strict_types = 0);
class CControllerActionOperationCheck extends CController {
protected function init(): void {
$this->setPostContentType(self::POST_CONTENT_TYPE_JSON);
$this->disableCsrfValidation();
protected function checkInput(): bool {
'actionid' => 'db actions.actionid',
$ret = $this->validateInput($fields) && $this->validateOperation();
new CControllerResponseData(['main_block' => json_encode([
'messages' => array_column(get_and_clear_messages(), 'message')
protected function validateOperation(): bool {
$operation = $this->getInput('operation', []);
$required_fields = ['eventsource', 'recovery', 'operationtype'];
foreach ($required_fields as $field) {
if (!array_key_exists($field, $operation)) {
error(_s('Field "%1$s" is mandatory.', $field));
$eventsource = $operation['eventsource'];
$recovery = $operation['recovery'];
$operationtype = preg_replace('[\D]', '', $operation['operationtype']);
$allowed_operations = getAllowedOperations($eventsource);
if (preg_match('/\bscriptid\b/', $operation['operationtype'])) {
$operationtype = OPERATION_TYPE_COMMAND;
if (!array_key_exists($recovery, $allowed_operations)
|| !in_array($operationtype, $allowed_operations[$recovery])) {
error(_s('Incorrect action operation type "%1$s" for event source "%2$s".', $operationtype, $eventsource));
$default_msg_validator = new CLimitedSetValidator(['values' => [0, 1]]);
if ($recovery == ACTION_OPERATION) {
if ((array_key_exists('esc_step_from', $operation) || array_key_exists('esc_step_to', $operation))
&& (!array_key_exists('esc_step_from', $operation)
|| !array_key_exists('esc_step_to', $operation))) {
error(_('Parameters "esc_step_from" and "esc_step_to" must be set together.'));
if (array_key_exists('esc_step_from', $operation) && array_key_exists('esc_step_to', $operation)) {
if ($operation['esc_step_from'] < 1 || $operation['esc_step_to'] < 0) {
error(_('Incorrect action operation escalation step values.'));