<?php declare(strict_types = 0);
class CControllerSoftwareVersionCheckUpdate extends CController {
private const NEXTCHECK_DELAY = 28800;
private const NEXTCHECK_DELAY_ON_FAIL = 259200;
private const MAX_NO_DATA_PERIOD = 604800;
private array $versions = [];
protected function init(): void {
$this->setPostContentType(self::POST_CONTENT_TYPE_JSON);
protected function checkInput(): bool {
'versions' => 'required|array'
if ($this->validateInput($fields) && $this->validateVersions()) {
$this->versions = $this->getInput('versions');
private function validateVersions(): bool {
foreach (array_values($this->getInput('versions')) as $i => $version) {
$path = '/versions/'.($i + 1);
if (!is_array($version)) {
error(_s('Invalid parameter "%1$s": %2$s.', $path, 'an array is expected'));
$validator = new CNewValidator($version, [
'version' => 'required|not_empty|string',
'end_of_full_support' => 'required|bool',
'latest_release' => 'required|array'
foreach ($validator->getAllErrors() as $error) {
if ($validator->isErrorFatal() || $validator->isError()) {
if (strlen($version['version']) > 5 || !preg_match('/^\d+\.\d+$/', $version['version'])) {
error(sprintf('Invalid parameter "%1$s": %2$s.', $path.'/version', 'invalid version'));
$validator = new CNewValidator($version['latest_release'], [
'created' => 'required|not_empty|string',
'release' => 'required|not_empty|string'
foreach ($validator->getAllErrors() as $error) {
if ($validator->isErrorFatal() || $validator->isError()) {
if (!is_numeric($version['latest_release']['created'])
|| bccomp($version['latest_release']['created'], ZBX_MAX_DATE) > 0) {
error(sprintf('Invalid parameter "%1$s": %2$s.', $path.'/latest_release/created', 'invalid timestamp'));
if (strlen($version['latest_release']['release']) > 16