Beispiel #1
0
 /**
  * Validates a given API request as being sent from origin via request signature
  *
  * @param string $body
  *
  * @return void
  */
 private function validateRequest($request)
 {
     $token = $request['requestToken'];
     unset($request['requestToken']);
     if ($token === OriginAPI::generateSignedRequest(http_build_query($request))) {
         return;
     }
     Output::render404();
 }
Beispiel #2
0
 /**
  * Reports an error back to origin via OriginAPI
  *
  * @param array $error
  *
  * @return void
  */
 public static function reportError($error)
 {
     if (is_array($error) === false) {
         return;
     }
     \OriginAPI::makeRequest('reportError', array('host' => \Configuration::DEPLOYED_HOSTNAME, 'error' => $error));
 }
Beispiel #3
0
 /**
  * Constructor
  * On construct, Handler runs through everything needed to either render the requested page, or render a 404
  * No methods are called outside of this class, and no values are returned
  *
  * @param array $request
  *
  * @return void
  */
 public function __construct($request)
 {
     $this->buildSiteArray();
     $this->buildRequestArray($request);
     /**
      * Is this an API request to a client API that we need to proxy along?
      */
     if ($this->isClientApiRequest() === true) {
         \OriginAPI::makeClientAPIRequest($this->request, file_get_contents('php://input'));
     }
     if ($this->isPage() === true) {
         /**
          * Might have the mobile cookie, and just need to get redirected to mobile file on disk
          */
         if ($this->request['mobile'] === true && file_exists(\BASE_DOCROOT_DIR . '/mobile/' . $this->request['file']) === true) {
             \setcookie('is_mobile', 1, time() + 2592000, '/');
             \Output::sendHeader('Location: ' . $this->request['file']);
             $this->isRedirect = true;
             $this->finalizeOutput();
             exit;
         }
         /**
          * Do we have it in the page hierarchy, or is it a dynamic page? Go get it from Origin
          */
         if ($this->isPageInPublishedData($this->request['file']) === true || $this->isDynamicPage() === true) {
             $response = \OriginRequest::getObject($this->request);
             $this->handleOriginResponse($response);
         } else {
             \Output::render404();
         }
         /**
          * Should we try a simple redirect from .htm to .html?
          */
         if ($this->isPageInPublishedData($this->request['file'] . 'l') === true) {
             if (file_exists(\BASE_DOCROOT_DIR . '/' . $this->request['file']) === true) {
                 \Output::sendHeader('Location: ' . $this->request['file'] . 'l');
                 $this->isRedirect = true;
                 $this->finalizeOutput();
                 exit;
             } else {
                 /**
                  * Don't have it yet, go get it before forwarding
                  */
                 $this->request['file'] .= 'l';
                 $response = \OriginRequest::getObject($this->request);
                 $this->handleOriginResponse($response);
             }
         }
     } else {
         /**
          * Not a page, we have to use benefit of the doubt here for checking origin
          */
         // Assets files.
         // Set default memory_limit so wServer will send back retryRaw message for file larger than 1MB.
         // Not setting it means it's remote server published before this change,
         // then wServer will always return old type of response. (no retryRaw mechanism)
         $this->request['memory_limit'] = MEMORY_LIMIT;
         $response = \OriginRequest::getObject($this->request);
         $this->handleOriginResponse($response);
     }
     // if redirect header, then add text to prevent some ftp server's firewall from block pure header redirect.
     $this->finalizeOutput();
 }