assertHttpMethod('post'); if (! $this->getRequest()->isApiRequest()) { $this->httpBadRequest('No API request'); } if ( ! preg_match('/([^;]*);?/', $this->getRequest()->getHeader('Content-Type'), $matches) || $matches[1] !== 'application/json' ) { $this->httpBadRequest('No JSON content'); } $urls = $this->getRequest()->getPost(); $result = []; $errors = []; foreach ($urls as $urlString) { $url = Url::fromPath($urlString); if (UrlMigrator::isSupportedUrl($url)) { try { $urlString = UrlMigrator::transformUrl($url)->getAbsoluteUrl(); } catch (Exception $e) { $errors[$urlString] = [ IcingaException::describe($e), IcingaException::getConfidentialTraceAsString($e) ]; $urlString = false; } } $result[] = $urlString; } $response = $this->getResponse()->json(); if (empty($errors)) { $response->setSuccessData($result); } else { $response->setFailData([ 'result' => $result, 'errors' => $errors ]); } $response->sendResponse(); } public function checkboxStateAction() { $this->assertHttpMethod('get'); $this->getResponse() ->setBody(IcingadbSupportHook::isIcingaDbSetAsPreferredBackend()) ->sendResponse(); exit; } public function checkboxSubmitAction() { $this->assertHttpMethod('post'); $form = (new SetAsBackendForm()) ->setOnSuccess(function () use (&$form) { $this->addPart(HtmlString::create('"bogus"'), 'Behavior:Migrate'); $form->save($form->getElement('backend')->isChecked()); return false; }); $form->handleRequest(); } public function backendSupportAction() { $this->assertHttpMethod('post'); if (! $this->getRequest()->isApiRequest()) { $this->httpBadRequest('No API request'); } if ( ! preg_match('/([^;]*);?/', $this->getRequest()->getHeader('Content-Type'), $matches) || $matches[1] !== 'application/json' ) { $this->httpBadRequest('No JSON content'); } $supportList = []; foreach (Hook::all('Icingadb/IcingadbSupport') as $hook) { /** @var IcingadbSupportHook $hook */ $supportList[$hook->getModule()->getName()] = $hook->supportsIcingaDb(); } $moduleSupportStates = []; foreach ($this->getRequest()->getPost() as $moduleName) { if (isset($supportList[$moduleName])) { $moduleSupportStates[] = $supportList[$moduleName]; } else { $moduleSupportStates[] = false; } } $this->getResponse() ->json() ->setSuccessData($moduleSupportStates) ->sendResponse(); } }