Example #1
0
 public function channels_get(GalaxyContext $context)
 {
     $options = array('default' => GalaxyAPI::databaseForId($context->application));
     $channels = GalaxyAPI::database(GalaxyAPIConstants::kDatabaseMongoDB, GalaxyAPIConstants::kDatabaseChannels, $options);
     $result = $channels->find();
     $data = array();
     foreach ($result as $channel) {
         $data[] = array('id' => $channel['_id'], 'type' => $channel['type'], 'label' => $channel['label'], 'description' => $channel['description'], 'source' => array('id' => $channel['application'], 'description' => $context->origin_description, 'domain' => $context->origin_domain), 'requests' => $channel['requests']);
     }
     return GalaxyResponse::responseWithData($data);
 }
Example #2
0
 public static function responseWithData($data)
 {
     $response = new GalaxyResponse();
     $response->setData($data);
     return $response;
 }
Example #3
0
 private function requestWithAuthorizationOAuth()
 {
     //print_r($_POST);
     $authorization = new GalaxyAuthorizationOAuth($this->headers['Authorization']);
     if ($authorization->isAuthorized()) {
         // load the application command context:
         $api = null;
         $response = null;
         // GalaxyResponse
         // At this point we know the user has a valid application
         // if they are attempting to access a channel, we need to confirm the channel
         // permissions, if they are accessing the root of their application, they are good
         // to go at this point.
         $context = $this->context_for_realm($authorization->realm);
         $context->origin = $authorization->application;
         $context->origin_description = $authorization->description;
         $context->origin_domain = $authorization->domain;
         if ($context) {
             $api = $this->commandLibraryForType($authorization->instance);
             // format: command_method e.g., channels_get, topics_post, topics_delete
             $method = GalaxyAPI::methodForEndpoint(GalaxyAPI::endpoint());
             if (!$api) {
                 GalaxyResponse::unauthorized();
             }
             // accessing the application
             if (!$context->channel) {
                 if ($context->application == $authorization->application) {
                     if (method_exists($api, $method)) {
                         $response = $api->{$method}($context);
                     } else {
                         GalaxyResponse::unauthorized();
                     }
                     echo $response;
                 } else {
                     GalaxyResponse::unauthorized();
                 }
             } else {
                 $has_permission = false;
                 $db_certificates = GalaxyAPI::database(GalaxyAPIConstants::kDatabaseRedis, GalaxyAPIConstants::kDatabaseCertificates);
                 $permissions = json_decode($db_certificates->get(GalaxyAPIConstants::kTypeCertificate . ':' . $authorization->oauth_consumer_key . ':' . $context->channel));
                 $verb = strtolower($_SERVER['REQUEST_METHOD']);
                 switch ($verb) {
                     case 'get':
                         $has_permission = $permissions & GalaxyAPIConstants::kPermissionRead ? true : false;
                         break;
                     case 'post':
                     case 'put':
                         $has_permission = $permissions & GalaxyAPIConstants::kPermissionWrite ? true : false;
                         break;
                     case 'delete':
                         $has_permission = $permissions & GalaxyAPIConstants::kPermissionDelete ? true : false;
                         break;
                 }
                 if ($has_permission && method_exists($api, $method)) {
                     $log = new GalaxyLog();
                     $log->setEndpoint(GalaxyAPI::endpoint());
                     $log->setContext($context);
                     $log->setMethod($verb);
                     $log->write();
                     $response = $api->{$method}($context);
                 } else {
                     echo GalaxyResponse::unauthorized();
                 }
                 echo $response;
             }
         } else {
             echo GalaxyResponse::unauthorized();
         }
     } else {
         echo "*****";
         echo GalaxyResponse::unauthorized();
     }
 }
Example #4
0
 public function start()
 {
     $request = $this->requestWithCommand($this->command);
     // API Debugging
     /*
     echo "<h3>GalaxyClientConnection - request</h3>\n";
     echo $request."\n\n<hr>";
     $data = $this->connect($request);
     echo "<h3>GalaxyClientConnection - response</h3>\n";
     echo $data;exit;
     */
     $data = $this->connect($request);
     $response = GalaxyResponse::responseWithData($data);
     if ($response->error) {
         throw new Exception((string) $command . ' Failed with error ' . $response->error['error'] . ': ' . $response->error['reason']);
     }
     return $response;
 }
Example #5
0
 public function topics_get(GalaxyContext $context)
 {
     $options = array('default' => GalaxyAPI::databaseForId($context->application));
     $channel = GalaxyAPI::database(GalaxyAPIConstants::kDatabaseMongoDB, GalaxyAPI::databaseForId($context->channel), $options);
     $result = $channel->find(array('type' => GalaxyAPIConstants::kTypeForumTopic));
     $data = array();
     foreach ($result as $topic) {
         $data[] = array('id' => $topic['_id'], 'requests' => $topic['requests'], 'replies' => $topic['replies'], 'title' => $topic['title'], 'author' => $topic['author'], 'source' => $topic['source'], 'last_message' => $topic['last_message'], 'created' => $topic['created'], 'type' => $topic['type']);
     }
     return GalaxyResponse::responseWithData($data);
 }