/** * Process the given request using this form * * Redirects to the url set with setRedirectUrl() upon success. See onSuccess() * and onRequest() wherewith you can customize the processing logic. * * @param Request $request The request to be processed * * @return Request The request supposed to be processed */ public function handleRequest(Request $request = null) { if ($request === null) { $request = $this->getRequest(); } else { $this->request = $request; } $formData = $this->getRequestData(); if ($this->getIsApiTarget() || $this->getUidDisabled() || $this->wasSent($formData)) { if ($frameUpload = (bool) $request->getUrl()->shift('_frameUpload', false)) { $this->getView()->layout()->setLayout('wrapped'); } $this->populate($formData); // Necessary to get isSubmitted() to work if (!$this->getSubmitLabel() || $this->isSubmitted()) { if ($this->isValid($formData) && ($this->onSuccess !== null && false !== call_user_func($this->onSuccess, $this) || $this->onSuccess === null && false !== $this->onSuccess())) { if ($this->getIsApiTarget() || $this->getRequest()->isApiRequest()) { // API targets and API requests will never redirect but immediately respond w/ JSON-encoded // notifications $notifications = Notification::getInstance()->popMessages(); $message = null; foreach ($notifications as $notification) { if ($notification->type === Notification::SUCCESS) { $message = $notification->message; break; } } $this->getResponse()->json()->setSuccessData($message !== null ? array('message' => $message) : null)->sendResponse(); } elseif (!$frameUpload) { $this->getResponse()->redirectAndExit($this->getRedirectUrl()); } else { $this->getView()->layout()->redirectUrl = $this->getRedirectUrl()->getAbsoluteUrl(); } } elseif ($this->getIsApiTarget()) { $this->getResponse()->sendJson(array('status' => 'fail', 'data' => array_merge($this->getMessages(), $this->getErrorMessages()))); } } elseif ($this->getValidatePartial()) { // The form can't be processed but we may want to show validation errors though $this->isValidPartial($formData); } } else { $this->onRequest(); } return $request; }
protected function postDispatchXhr() { $layout = $this->_helper->layout(); $layout->setLayout($this->xhrLayout); $resp = $this->getResponse(); $notifications = Notification::getInstance(); if ($notifications->hasMessages()) { $notificationList = array(); foreach ($notifications->popMessages() as $m) { $notificationList[] = rawurlencode($m->type . ' ' . $m->message); } $resp->setHeader('X-Icinga-Notification', implode('&', $notificationList), true); } if ($this->reloadCss) { $resp->setHeader('X-Icinga-CssReload', 'now', true); } if ($this->view->title) { if (preg_match('~[\\r\\n]~', $this->view->title)) { // TODO: Innocent exception and error log for hack attempts throw new IcingaException('No way, guy'); } $resp->setHeader('X-Icinga-Title', rawurlencode($this->view->title . ' :: Icinga Web'), true); } else { $resp->setHeader('X-Icinga-Title', rawurlencode('Icinga Web'), true); } if ($this->rerenderLayout) { $this->getResponse()->setHeader('X-Icinga-Container', 'layout', true); } if ($this->autorefreshInterval !== null) { $resp->setHeader('X-Icinga-Refresh', $this->autorefreshInterval, true); } }
/** * Initialize notifications to remove them immediately from session * * @return $this */ private function setupNotifications() { Notification::getInstance(); return $this; }
/** * Detect whether the current request requires changes in the layout and apply them before rendering * * @see Zend_Controller_Action::postDispatch() */ public function postDispatch() { Benchmark::measure('Action::postDispatch()'); $layout = $this->_helper->layout(); // $this->addModuleContainer(); $isXhr = $this->_request->isXmlHttpRequest(); $layout->moduleName = $this->_request->getModuleName(); if ($layout->moduleName === 'default') { $layout->moduleName = false; } elseif ($isXhr) { header('X-Icinga-Module: ' . $layout->moduleName); } if ($user = $this->getRequest()->getUser()) { // Cast preference app.show_benchmark to bool because preferences loaded from a preferences storage are // always strings if ((bool) $user->getPreferences()->get('app.show_benchmark', false) === true) { Benchmark::measure('Response ready'); $layout->benchmark = $this->renderBenchmark(); } } if ($this->_request->getParam('format') === 'pdf') { $layout->setLayout('pdf'); $this->sendAsPdf(); exit; } if ($isXhr) { $layout->setLayout('inline'); } $notifications = Notification::getInstance(); if ($isXhr && !$this->isRedirect && $notifications->hasMessages()) { foreach ($notifications->getMessages() as $m) { header('X-Icinga-Notification: ' . rawurlencode($m->type . ' ' . $m->message)); } } if ($isXhr && ($this->reloadCss || $this->getParam('_reload') === 'css')) { header('X-Icinga-CssReload: now'); } if ($isXhr && $this->noXhrBody) { header('X-Icinga-Container: ignore'); return; } if ($isXhr && $this->getWindowId() === 'undefined') { header('X-Icinga-WindowId: ' . $this->generateWindowId()); } if ($this->view->title) { if (preg_match('~[\\r\\n]~', $this->view->title)) { // TODO: Innocent exception and error log for hack attempts throw new Exception('No way, guy'); } header('X-Icinga-Title: ' . rawurlencode($this->view->title . ' :: Icinga Web')); } // TODO: _render=layout? if ($this->getParam('_render') === 'layout') { $layout->setLayout('body'); header('X-Icinga-Container: layout'); } if ($this->autorefreshInterval !== null) { header('X-Icinga-Refresh: ' . $this->autorefreshInterval); } }