Ejemplo n.º 1
0
 private function reloadConfiguration($instance, $serverKey)
 {
     if (HttpUtils::isLocal()) {
         // Update the .htaccess file with the new route settings
         updateHtaccess($instance);
         // Update the configuration
         RESTConfigurationLoader::reloadConfiguration($serverKey);
     }
 }
Ejemplo n.º 2
0
 private function validateRequest($serverKey)
 {
     // If the request comes from the local computer, then don't require authorization,
     // otherwise check the headers
     if (HttpUtils::isLocal()) {
         return true;
     } else {
         $providedServerkey = HttpUtils::getHeader(HEADER_SERVER_KEY);
         if (empty($serverKey)) {
             throw new MashapeException(EXCEPTION_EMPTY_SERVERKEY, EXCEPTION_XML_CODE);
         }
         if ($providedServerkey != null && md5($serverKey) == $providedServerkey) {
             return true;
         }
         return false;
     }
 }
Ejemplo n.º 3
0
 private function validateRequest($serverKey, $token, $method, $language, $version)
 {
     // If the request comes from the local computer, then don't require authorization,
     // otherwise check the headers
     if (HttpUtils::isLocal()) {
         return true;
     } else {
         if (empty($serverKey)) {
             throw new MashapeException(EXCEPTION_EMPTY_SERVERKEY, EXCEPTION_XML_CODE);
         }
         $url = MASHAPE_TOKEN_VALIDATION_URL . "?" . QUERY_PARAM_TOKEN . "=" . $token . "&" . QUERY_PARAM_SERVERKEY . "=" . $serverKey . "&" . QUERY_PARAM_METHOD . "=" . $method . "&" . QUERY_PARAM_LANGUAGE . "=" . $language . "&" . QUERY_PARAM_VERSION . "=" . $version;
         $response = HttpUtils::makeHttpRequest($url);
         if (empty($response)) {
             throw new MashapeException(EXCEPTION_EMPTY_REQUEST, EXCEPTION_SYSTEM_ERROR_CODE);
         }
         $validationResponse = json_decode($response);
         if (empty($validationResponse)) {
             throw new MashapeException(EXCEPTION_JSONDECODE_REQUEST, EXCEPTION_SYSTEM_ERROR_CODE);
         }
         if (!empty($validationResponse->errors)) {
             $error = $validationResponse->errors[0];
             throw new MashapeException($error->message, $error->code);
         }
         $authorization = $validationResponse->authorized;
         $GLOBALS[UID] = $validationResponse->uid;
         if ($authorization == true) {
             return true;
         } else {
             return false;
         }
     }
 }