public function buildStandardPageView()
 {
     $view = new PhabricatorStandardPageView();
     $view->setRequest($this->getRequest());
     if ($this->shouldRequireAdmin()) {
         $view->setIsAdminInterface(true);
     }
     return $view;
 }
Пример #2
0
 public function buildResponseString()
 {
     $failure = new AphrontRequestFailureView();
     $failure->setHeader('404 Not Found');
     $failure->appendChild('<p>The page you requested was not found.</p>');
     $view = new PhabricatorStandardPageView();
     $view->setTitle('404 Not Found');
     $view->setRequest($this->getRequest());
     $view->appendChild($failure);
     return $view->render();
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $path = phutil_escape_html($request->getPath());
     $host = phutil_escape_html($request->getHost());
     $controller_name = phutil_escape_html(get_class($this));
     $page = new PhabricatorStandardPageView();
     $response = new AphrontWebpageResponse();
     $response->setContent($page->render());
     return $response;
 }
Пример #4
0
 public function buildResponseString()
 {
     $forbidden_text = $this->getForbiddenText();
     if (!$forbidden_text) {
         $forbidden_text = 'You do not have privileges to access the requested page.';
     }
     $failure = new AphrontRequestFailureView();
     $failure->setHeader('403 Forbidden');
     $failure->appendChild('<p>' . $forbidden_text . '</p>');
     $view = new PhabricatorStandardPageView();
     $view->setTitle('403 Forbidden');
     $view->setRequest($this->getRequest());
     $view->appendChild($failure);
     return $view->render();
 }
 public function buildResponseString()
 {
     if ($this->shouldStopForDebugging()) {
         $request = $this->getRequest();
         $viewer = $request->getUser();
         $view = new PhabricatorStandardPageView();
         $view->setRequest($this->getRequest());
         $view->setApplicationName(pht('Debug'));
         $view->setTitle(pht('Stopped on Redirect'));
         $dialog = new AphrontDialogView();
         $dialog->setUser($viewer);
         $dialog->setTitle(pht('Stopped on Redirect'));
         $dialog->appendParagraph(pht('You were stopped here because %s is set in your configuration.', phutil_tag('tt', array(), 'debug.stop-on-redirect')));
         $dialog->appendParagraph(pht('You are being redirected to: %s', phutil_tag('tt', array(), $this->getURI())));
         $dialog->addCancelButton($this->getURI(), pht('Continue'));
         $dialog->appendChild(phutil_tag('br'));
         $dialog->appendChild(id(new AphrontStackTraceView())->setUser($viewer)->setTrace($this->stackWhenCreated));
         $dialog->setIsStandalone(true);
         $dialog->setWidth(AphrontDialogView::WIDTH_FULL);
         $box = id(new PHUIBoxView())->addMargin(PHUI::MARGIN_LARGE)->appendChild($dialog);
         $view->appendChild($box);
         return $view->render();
     }
     return '';
 }
 public function buildResponseString()
 {
     if ($this->shouldStopForDebugging()) {
         $view = new PhabricatorStandardPageView();
         $view->setRequest($this->getRequest());
         $view->setApplicationName('Debug');
         $view->setTitle('Stopped on Redirect');
         $error = new AphrontErrorView();
         $error->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
         $error->setTitle('Stopped on Redirect');
         $link = phutil_render_tag('a', array('href' => $this->getURI()), 'Continue to: ' . phutil_escape_html($this->getURI()));
         $error->appendChild('<p>You were stopped here because <tt>debug.stop-on-redirect</tt> ' . 'is set in your configuration.</p>' . '<p>' . $link . '</p>');
         $view->appendChild($error);
         return $view->render();
     }
     return '';
 }
 public function willSendResponse(AphrontResponse $response)
 {
     $request = $this->getRequest();
     $response->setRequest($request);
     if ($response instanceof AphrontDialogResponse) {
         if (!$request->isAjax()) {
             $view = new PhabricatorStandardPageView();
             $view->setRequest($request);
             $view->appendChild('<div style="padding: 2em 0;">' . $response->buildResponseString() . '</div>');
             $response = new AphrontWebpageResponse();
             $response->setContent($view->render());
             return $response;
         } else {
             return id(new AphrontAjaxResponse())->setContent(array('dialog' => $response->buildResponseString()));
         }
     } else {
         if ($response instanceof AphrontRedirectResponse) {
             if ($request->isAjax()) {
                 return id(new AphrontAjaxResponse())->setContent(array('redirect' => $response->getURI()));
             }
         } else {
             if ($response instanceof Aphront404Response) {
                 $failure = new AphrontRequestFailureView();
                 $failure->setHeader('404 Not Found');
                 $failure->appendChild('<p>The page you requested was not found.</p>');
                 $view = new PhabricatorStandardPageView();
                 $view->setTitle('404 Not Found');
                 $view->setRequest($this->getRequest());
                 $view->appendChild($failure);
                 $response = new AphrontWebpageResponse();
                 $response->setContent($view->render());
                 $response->setHTTPResponseCode(404);
                 return $response;
             }
         }
     }
     return $response;
 }
 public function buildStandardPageView()
 {
     $view = new PhabricatorStandardPageView();
     $view->setRequest($this->getRequest());
     $view->setController($this);
     return $view;
 }
 public function willSendResponse(AphrontResponse $response)
 {
     $request = $this->getRequest();
     $response->setRequest($request);
     if ($response instanceof AphrontDialogResponse) {
         if (!$request->isAjax()) {
             $view = new PhabricatorStandardPageView();
             $view->setRequest($request);
             $view->appendChild('<div style="padding: 2em 0;">' . $response->buildResponseString() . '</div>');
             $response = new AphrontWebpageResponse();
             $response->setContent($view->render());
             return $response;
         } else {
             return id(new AphrontAjaxResponse())->setContent(array('dialog' => $response->buildResponseString()));
         }
     } else {
         if ($response instanceof AphrontRedirectResponse) {
             if ($request->isAjax()) {
                 return id(new AphrontAjaxResponse())->setContent(array('redirect' => $response->getURI()));
             }
         }
     }
     return $response;
 }
 public function handleException(Exception $ex)
 {
     $request = $this->getRequest();
     // For Conduit requests, return a Conduit response.
     if ($request->isConduit()) {
         $response = new ConduitAPIResponse();
         $response->setErrorCode(get_class($ex));
         $response->setErrorInfo($ex->getMessage());
         return id(new AphrontJSONResponse())->setAddJSONShield(false)->setContent($response->toDictionary());
     }
     // For non-workflow requests, return a Ajax response.
     if ($request->isAjax() && !$request->isWorkflow()) {
         // Log these; they don't get shown on the client and can be difficult
         // to debug.
         phlog($ex);
         $response = new AphrontAjaxResponse();
         $response->setError(array('code' => get_class($ex), 'info' => $ex->getMessage()));
         return $response;
     }
     $user = $request->getUser();
     if (!$user) {
         // If we hit an exception very early, we won't have a user.
         $user = new PhabricatorUser();
     }
     if ($ex instanceof PhabricatorSystemActionRateLimitException) {
         $dialog = id(new AphrontDialogView())->setTitle(pht('Slow Down!'))->setUser($user)->setErrors(array(pht('You are being rate limited.')))->appendParagraph($ex->getMessage())->appendParagraph($ex->getRateExplanation())->addCancelButton('/', pht('Okaaaaaaaaaaaaaay...'));
         $response = new AphrontDialogResponse();
         $response->setDialog($dialog);
         return $response;
     }
     if ($ex instanceof PhabricatorAuthHighSecurityRequiredException) {
         $form = id(new PhabricatorAuthSessionEngine())->renderHighSecurityForm($ex->getFactors(), $ex->getFactorValidationResults(), $user, $request);
         $dialog = id(new AphrontDialogView())->setUser($user)->setTitle(pht('Entering High Security'))->setShortTitle(pht('Security Checkpoint'))->setWidth(AphrontDialogView::WIDTH_FORM)->addHiddenInput(AphrontRequest::TYPE_HISEC, true)->setErrors(array(pht('You are taking an action which requires you to enter ' . 'high security.')))->appendParagraph(pht('High security mode helps protect your account from security ' . 'threats, like session theft or someone messing with your stuff ' . 'while you\'re grabbing a coffee. To enter high security mode, ' . 'confirm your credentials.'))->appendChild($form->buildLayoutView())->appendParagraph(pht('Your account will remain in high security mode for a short ' . 'period of time. When you are finished taking sensitive ' . 'actions, you should leave high security.'))->setSubmitURI($request->getPath())->addCancelButton($ex->getCancelURI())->addSubmitButton(pht('Enter High Security'));
         $request_parameters = $request->getPassthroughRequestParameters($respect_quicksand = true);
         foreach ($request_parameters as $key => $value) {
             $dialog->addHiddenInput($key, $value);
         }
         $response = new AphrontDialogResponse();
         $response->setDialog($dialog);
         return $response;
     }
     if ($ex instanceof PhabricatorPolicyException) {
         if (!$user->isLoggedIn()) {
             // If the user isn't logged in, just give them a login form. This is
             // probably a generally more useful response than a policy dialog that
             // they have to click through to get a login form.
             //
             // Possibly we should add a header here like "you need to login to see
             // the thing you are trying to look at".
             $login_controller = new PhabricatorAuthStartController();
             $login_controller->setRequest($request);
             $auth_app_class = 'PhabricatorAuthApplication';
             $auth_app = PhabricatorApplication::getByClass($auth_app_class);
             $login_controller->setCurrentApplication($auth_app);
             return $login_controller->handleRequest($request);
         }
         $content = array(phutil_tag('div', array('class' => 'aphront-policy-rejection'), $ex->getRejection()));
         $list = null;
         if ($ex->getCapabilityName()) {
             $list = $ex->getMoreInfo();
             foreach ($list as $key => $item) {
                 $list[$key] = $item;
             }
             $content[] = phutil_tag('div', array('class' => 'aphront-capability-details'), pht('Users with the "%s" capability:', $ex->getCapabilityName()));
         }
         $dialog = id(new AphrontDialogView())->setTitle($ex->getTitle())->setClass('aphront-access-dialog')->setUser($user)->appendChild($content);
         if ($list) {
             $dialog->appendList($list);
         }
         if ($this->getRequest()->isAjax()) {
             $dialog->addCancelButton('/', pht('Close'));
         } else {
             $dialog->addCancelButton('/', pht('OK'));
         }
         $response = new AphrontDialogResponse();
         $response->setDialog($dialog);
         return $response;
     }
     if ($ex instanceof AphrontUsageException) {
         $error = new PHUIInfoView();
         $error->setTitle($ex->getTitle());
         $error->appendChild($ex->getMessage());
         $view = new PhabricatorStandardPageView();
         $view->setRequest($this->getRequest());
         $view->appendChild($error);
         $response = new AphrontWebpageResponse();
         $response->setContent($view->render());
         $response->setHTTPResponseCode(500);
         return $response;
     }
     // Always log the unhandled exception.
     phlog($ex);
     $class = get_class($ex);
     $message = $ex->getMessage();
     if ($ex instanceof AphrontSchemaQueryException) {
         $message .= "\n\n" . pht("NOTE: This usually indicates that the MySQL schema has not been " . "properly upgraded. Run '%s' to ensure your schema is up to date.", 'bin/storage upgrade');
     }
     if (PhabricatorEnv::getEnvConfig('phabricator.developer-mode')) {
         $trace = id(new AphrontStackTraceView())->setUser($user)->setTrace($ex->getTrace());
     } else {
         $trace = null;
     }
     $content = phutil_tag('div', array('class' => 'aphront-unhandled-exception'), array(phutil_tag('div', array('class' => 'exception-message'), $message), $trace));
     $dialog = new AphrontDialogView();
     $dialog->setTitle(pht('Unhandled Exception ("%s")', $class))->setClass('aphront-exception-dialog')->setUser($user)->appendChild($content);
     if ($this->getRequest()->isAjax()) {
         $dialog->addCancelButton('/', pht('Close'));
     }
     $response = new AphrontDialogResponse();
     $response->setDialog($dialog);
     $response->setHTTPResponseCode(500);
     return $response;
 }
 public function handleException(Exception $ex)
 {
     $request = $this->getRequest();
     // For Conduit requests, return a Conduit response.
     if ($request->isConduit()) {
         $response = new ConduitAPIResponse();
         $response->setErrorCode(get_class($ex));
         $response->setErrorInfo($ex->getMessage());
         return id(new AphrontJSONResponse())->setContent($response->toDictionary());
     }
     // For non-workflow requests, return a Ajax response.
     if ($request->isAjax() && !$request->isJavelinWorkflow()) {
         $response = new AphrontAjaxResponse();
         $response->setError(array('code' => get_class($ex), 'info' => $ex->getMessage()));
         return $response;
     }
     $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
     $user = $request->getUser();
     if (!$user) {
         // If we hit an exception very early, we won't have a user.
         $user = new PhabricatorUser();
     }
     if ($ex instanceof PhabricatorPolicyException) {
         if (!$user->isLoggedIn()) {
             // If the user isn't logged in, just give them a login form. This is
             // probably a generally more useful response than a policy dialog that
             // they have to click through to get a login form.
             //
             // Possibly we should add a header here like "you need to login to see
             // the thing you are trying to look at".
             $login_controller = new PhabricatorLoginController($request);
             return $login_controller->processRequest();
         }
         $content = '<div class="aphront-policy-exception">' . phutil_escape_html($ex->getMessage()) . '</div>';
         $dialog = new AphrontDialogView();
         $dialog->setTitle($is_serious ? 'Access Denied' : "You Shall Not Pass")->setClass('aphront-access-dialog')->setUser($user)->appendChild($content);
         if ($this->getRequest()->isAjax()) {
             $dialog->addCancelButton('/', 'Close');
         } else {
             $dialog->addCancelButton('/', $is_serious ? 'OK' : 'Away With Thee');
         }
         $response = new AphrontDialogResponse();
         $response->setDialog($dialog);
         return $response;
     }
     if ($ex instanceof AphrontUsageException) {
         $error = new AphrontErrorView();
         $error->setTitle(phutil_escape_html($ex->getTitle()));
         $error->appendChild(phutil_escape_html($ex->getMessage()));
         $view = new PhabricatorStandardPageView();
         $view->setRequest($this->getRequest());
         $view->appendChild($error);
         $response = new AphrontWebpageResponse();
         $response->setContent($view->render());
         return $response;
     }
     // Always log the unhandled exception.
     phlog($ex);
     $class = phutil_escape_html(get_class($ex));
     $message = phutil_escape_html($ex->getMessage());
     if ($ex instanceof AphrontQuerySchemaException) {
         $message .= "\n\n" . "NOTE: This usually indicates that the MySQL schema has not been " . "properly upgraded. Run 'bin/storage upgrade' to ensure your " . "schema is up to date.";
     }
     if (PhabricatorEnv::getEnvConfig('phabricator.show-stack-traces')) {
         $trace = $this->renderStackTrace($ex->getTrace(), $user);
     } else {
         $trace = null;
     }
     $content = '<div class="aphront-unhandled-exception">' . '<div class="exception-message">' . $message . '</div>' . $trace . '</div>';
     $dialog = new AphrontDialogView();
     $dialog->setTitle('Unhandled Exception ("' . $class . '")')->setClass('aphront-exception-dialog')->setUser($user)->appendChild($content);
     if ($this->getRequest()->isAjax()) {
         $dialog->addCancelButton('/', 'Close');
     }
     $response = new AphrontDialogResponse();
     $response->setDialog($dialog);
     return $response;
 }