public function testRemoveUsersCapabilities()
 {
     $a = array('RequestMethod' => 'RemoveUserCapabilities', 'OwnerID' => 'efb00dbb-d4ab-46dc-aebc-4ba83288c3c0');
     $r = new HttpRequest($this->server_url, HttpRequest::METH_POST);
     $r->addPostFields($a);
     $r->send();
     echo $r->getRawRequestMessage();
     echo "\n";
     echo $r->getRawResponseMessage();
     echo "\n";
     $this->assertEquals(200, $r->getResponseCode());
 }
Example #2
0
 public function request($method, stdClass $params = null, $namespace = null)
 {
     if (!$namespace) {
         $namespace = $this->namespace;
     }
     $requestObj = new stdClass();
     $requestObj->id = microtime(true);
     $requestObj->method = $method;
     $requestObj->params = new stdClass();
     $this->walkSerialize($params, $requestObj->params, 'underScope');
     $jsonRequest = $this->cryptoTool->encrypt(json_encode($requestObj), $this->dbServer->GetKey(true));
     $dt = new DateTime('now', new DateTimeZone("UTC"));
     $timestamp = $dt->format("D d M Y H:i:s e");
     $canonical_string = $jsonRequest . $timestamp;
     $signature = base64_encode(hash_hmac('SHA1', $canonical_string, $this->dbServer->GetKey(true), 1));
     $request = new HttpRequest();
     $request->setMethod(HTTP_METH_POST);
     // If no VPC router communicating via local inteface (Scalr should be setup within the esame network)
     $requestHost = $this->dbServer->getSzrHost() . ":{$this->port}";
     if ($this->isVPC) {
         $routerFarmRoleId = $this->dbServer->GetFarmRoleObject()->GetSetting(Scalr_Role_Behavior_Router::ROLE_VPC_SCALR_ROUTER_ID);
         if ($routerFarmRoleId) {
             $routerRole = DBFarmRole::LoadByID($routerFarmRoleId);
         } else {
             $routerRole = $this->dbServer->GetFarmObject()->GetFarmRoleByBehavior(ROLE_BEHAVIORS::VPC_ROUTER);
         }
         if ($routerRole) {
             // No public IP need to use proxy
             if (!$this->dbServer->remoteIp) {
                 $requestHost = $routerRole->GetSetting(Scalr_Role_Behavior_Router::ROLE_VPC_IP) . ":80";
                 $request->addHeaders(array("X-Receiver-Host" => $this->dbServer->localIp, "X-Receiver-Port" => $this->port));
                 // There is public IP, can use it
             } else {
                 $requestHost = "{$this->dbServer->remoteIp}:{$this->port}";
             }
         }
     }
     $request->setUrl("http://{$requestHost}/{$namespace}");
     $request->setOptions(array('timeout' => $this->timeout, 'connecttimeout' => 10));
     $request->addHeaders(array("Date" => $timestamp, "X-Signature" => $signature, "X-Server-Id" => $this->dbServer->serverId));
     $request->setBody($jsonRequest);
     try {
         // Send request
         $request->send();
         $this->debug['responseCode'] = $request->getResponseCode();
         $this->debug['fullResponse'] = $request->getRawResponseMessage();
         if ($request->getResponseCode() == 200) {
             $response = $request->getResponseData();
             $body = $this->cryptoTool->decrypt($response['body'], $this->dbServer->GetKey(true));
             $jResponse = @json_decode($body);
             if ($jResponse->error) {
                 throw new Exception("{$jResponse->error->message} ({$jResponse->error->code}): {$jResponse->error->data}");
             }
             return $jResponse;
         } else {
             $response = $request->getResponseData();
             throw new Exception(sprintf("Unable to perform request to scalarizr: %s (%s)", $response['body'], $request->getResponseCode()));
         }
     } catch (HttpException $e) {
         if (isset($e->innerException)) {
             $msg = $e->innerException->getMessage();
         } else {
             $msg = $e->getMessage();
         }
         if (stristr($msg, "Namespace not found")) {
             $msg = "Feature not supported by installed version of scalarizr. Please update it to the latest version and try again.";
         }
         throw new Exception(sprintf("Unable to perform request to scalarizr: %s", $msg));
     }
 }
Example #3
0
    exit;
}
// Header handling
foreach (array('Content-Type') as $name) {
    $content = $response->getHeader($name);
    if ($content) {
        header("{$name}: {$content}");
    }
}
$debug = 0;
// debugging
if ($debug) {
    echo "DEBUGGING CALL TO <a href='{$url}'>{$url}</a>:\n<br>";
    echo 'Seen by pecl extension as:' . $request->getUrl();
    echo '<h2>Request</h2> <pre>' . $request->getRawRequestMessage() . '</pre>';
    echo '<h2>Response</h2> <pre>' . $request->getRawResponseMessage() . '</pre>';
    echo '<h2>Output headers</h2> <pre>';
    print_r(headers_list());
    print '</pre>';
    echo '<h2>Content</h2>';
    echo $response->getBody();
    exit;
}
// well, that's our body
$contents = $response->getBody();
// Take a short look if we got HTML (important for rewrite engine)
$is_html = stripos($response->getHeader('Content-Type'), 'html') !== false;
// rewrite the page...
$db->driver->rewrite_page($url, $contents, $is_html);
// and print it out.
echo $contents;