示例#1
0
 public function showChannels()
 {
     $options = array('default' => Renegade::databaseForId($_GET['id']));
     $db = Renegade::database(RenegadeConstants::kDatabaseMongoDB, RenegadeConstants::kDatabaseChannels, $options);
     $channels = $db->find();
     if ($channels->count()) {
         foreach ($channels as $channel) {
             /*
             	TODO Need a way to include the channels permissions in the channel view
             	just to let people know what they are allowed to do to their respective channels.
             	below are just the default permissions, they don't reflect the actual permissions for this user.
             	this will also be important when the application owner manages subscriptions.
             */
             $channel['permission_read'] = $channel['defaultPermissions'] & RenegadeConstants::kPermissionRead ? 'Yes' : 'No';
             $channel['permission_write'] = $channel['defaultPermissions'] & RenegadeConstants::kPermissionWrite ? 'Yes' : 'No';
             $channel['permission_delete'] = $channel['defaultPermissions'] & RenegadeConstants::kPermissionDelete ? 'Yes' : 'No';
             $channel['current_application'] = $this->application['_id'];
             if ($channel['application'] != $this->application['_id']) {
                 echo new ChannelDetail($channel, ChannelDetail::kContextSubscription);
             } else {
                 echo new ChannelDetail($channel);
             }
         }
     } else {
         echo 'No Channels';
     }
 }
示例#2
0
 public function generate_metadata()
 {
     if (!$this->certificate) {
         $this->generate_certificate();
     }
     $metadata = false;
     if ($this->owner && $this->id) {
         $metadata = array('_id' => $this->id, 'database' => Renegade::databaseForId($this->id), 'instance' => $this->type, 'owner' => $this->owner, 'certificate' => $this->certificate['key'], 'description' => $this->description, 'domain' => $this->domain, 'defaultPermissions' => $this->defaultPermissions, 'created' => Renegade::datetime(), 'type' => RenegadeConstants::kTypeApplication);
     }
     return $metadata;
 }
示例#3
0
 $context = array(AMForm::kDataKey => $_POST);
 $form = AMForm::formWithContext($context);
 $form->addValidator(new AMPatternValidator('inputCertificate', true, '/^' . RenegadeConstants::kTypeCertificate . ':[a-z0-9]{32,32}$/', 'Invalid Certificate'));
 $form->addValidator(new ApplicationIdValidator('inputId', true, 'Invalid application id'));
 if ($form->isValid) {
     $options_local = array('default' => Renegade::databaseForId($form->inputId));
     $subscriptions = Renegade::database(RenegadeConstants::kDatabaseMongoDB, RenegadeConstants::kDatabaseSubscriptions, $options_local);
     $certificates = Renegade::database(RenegadeConstants::kDatabaseRedis, RenegadeConstants::kDatabaseCertificates);
     $applications = Renegade::database(RenegadeConstants::kDatabaseMongoDB, RenegadeConstants::kDatabaseApplications);
     $store = Renegade::database(RenegadeConstants::kDatabaseMongoDB, null, $options_local);
     $data = $subscriptions->find();
     // flush all the channels
     foreach ($data as $subscription) {
         if ($subscription['application'] != $form->inputId) {
             // we need to clear the channel from a remote application
             $options_remote = array('default' => Renegade::databaseForId($subscription['application']));
             $channels_remote = Renegade::database(RenegadeConstants::kDatabaseMongoDB, RenegadeConstants::kDatabaseChannels, $options_remote);
             $channels_remote->remove(array('_id' => $subscription['channel']));
             /*
             	TODO need to remember if whenyou subscribe to a channel if a channel gets written + a subscription to the subscribing applications
             	info.  I forget...  If it does we need to delete the remote subscription too not just the channel.  I don't think it works tha way
             	but I don't have that part fully written yet either.
             	$subscriptions_remote = Renegade::database(RenegadeConstants::kDatabaseMongoDB, RenegadeConstants::kDatabaseSubscription, $options_remote);
             */
         }
         //echo $subscription['certificate'];
         $certificates->delete($subscription['certificate']);
     }
     $applications->remove(array('_id' => $form->inputId));
     $store->drop();
     $certificates->delete($form->inputCertificate);
示例#4
0
            if ($master) {
                $data = $subscriptions->find(array('channel' => $form->inputChannelId));
                foreach ($data as $subscription) {
                    $options = array('default' => Renegade::databaseForId($subscription['application']));
                    $channels = Renegade::database(RenegadeConstants::kDatabaseMongoDB, RenegadeConstants::kDatabaseChannels, $options);
                    $channels->remove(array('_id' => $subscription['channel']));
                    $subscriptions->remove(array('_id' => $subscription['_id']));
                    $redis->delete($subscription['certificate']);
                }
            } else {
                // we are deleting a subscription only
                $options_channels = array('default' => Renegade::databaseForId($form->inputApplicationId));
                $options_subscriptions = array('default' => null);
                $channels = Renegade::database(RenegadeConstants::kDatabaseMongoDB, RenegadeConstants::kDatabaseChannels, $options_channels);
                $data = $channels->findOne(array('_id' => $form->inputChannelId));
                $options_subscriptions['default'] = Renegade::databaseForId($data['application']);
                $subscriptions = Renegade::database(RenegadeConstants::kDatabaseMongoDB, RenegadeConstants::kDatabaseSubscriptions, $options_subscriptions);
                $record = $subscriptions->findOne(array('application' => $form->inputApplicationId, 'channel' => $data['_id']));
                $subscriptions->remove(array('_id' => $record['_id']));
                $channels->remove(array('_id' => $form->inputChannelId));
                $redis->delete($record['certificate']);
            }
            header('Location:/applications/' . $form->inputApplicationId . '/channels');
            exit;
        } else {
            header('Location:/applications');
            exit;
        }
    }
}
header('Location:/applications');
示例#5
0
 private function processDelete(AMForm $form)
 {
     $options = array('default' => Renegade::databaseForId($this->application_id));
     $subscriptions = Renegade::database(RenegadeConstants::kDatabaseMongoDB, RenegadeConstants::kDatabaseSubscriptions, $options);
     $certificates = Renegade::database(RenegadeConstants::kDatabaseRedis, RenegadeConstants::kDatabaseCertificates);
     $data = $subscriptions->findOne(array('_id' => new MongoId($form->inputSubscription)));
     $remote_options = array('default' => Renegade::databaseForId($data['application']));
     $remote_channels = Renegade::database(RenegadeConstants::kDatabaseMongoDB, RenegadeConstants::kDatabaseChannels, $remote_options);
     $subscriptions->remove(array('_id' => new MongoId($form->inputSubscription)));
     $remote_channels->remove(array('_id' => $data['channel']));
     $certificates->delete($data['certificate']);
 }
示例#6
0
     $channel = new Channel($form->inputId);
     $channel->setCertificate($form->inputCertificate);
     $channel->setApplication($form->inputApplicationId);
     $channel->setLabel($form->inputLabel);
     $channel->setDescription($form->inputDescription);
     $channel->setDefaultPermissions((int) $form->inputRead | (int) $form->inputWrite | (int) $form->inputDelete);
     // channel owner gets all permissions by default
     $certificate = $channel->generate_certificate(RenegadeConstants::kPermissionRead | RenegadeConstants::kPermissionWrite | RenegadeConstants::kPermissionDelete);
     $metadata = $channel->generate_metadata();
     $subscription = new Subscription();
     $subscription->setCertificate($certificate['key']);
     $subscription->setApplication($metadata['application']);
     $subscription->setChannel($metadata['_id']);
     $subscription->setMaster(true);
     // place us in the application db context
     $options = array('default' => Renegade::databaseForId($form->inputApplicationId));
     $channels = Renegade::database(RenegadeConstants::kDatabaseMongoDB, RenegadeConstants::kDatabaseChannels, $options);
     $subscriptions = Renegade::database(RenegadeConstants::kDatabaseMongoDB, RenegadeConstants::kDatabaseSubscriptions, $options);
     $redis->set($certificate['key'], $certificate['value']);
     $channels->insert($metadata);
     $subscriptions->insert($subscription->toArray());
 } else {
     // error, something is potentially wrong, either from the user or the system
     // lets assume the system, it's easy to throw guilt at the user =)
     echo 'Error';
     exit;
     header('Location: /applications');
     exit;
 }
 header('Location:/applications/' . $form->inputApplicationId . '/channels');
 exit;
示例#7
0
 public function generate_metadata()
 {
     $metadata = false;
     $metadata = array('_id' => $this->channelId(), 'database' => Renegade::databaseForId($this->channelId()), 'application' => $this->application, 'label' => $this->label, 'description' => $this->description, 'defaultPermissions' => $this->defaultPermissions, 'requests' => 0, 'created' => Renegade::datetime(), 'type' => RenegadeConstants::kTypeChannel);
     return $metadata;
 }
示例#8
0
                     // we are giving the fully qualified channel id here
                     // so we will not need to set the application, it will be done for us
                     $channel = new Channel($remote_channel['_id']);
                     $channel->setCertificate($application['certificate']);
                     $channel->setLabel($remote_channel['label']);
                     $channel->setDescription($remote_channel['description']);
                     $channel->setDefaultPermissions($remote_channel['defaultPermissions']);
                     $certificate = $channel->generate_certificate($remote_channel['defaultPermissions']);
                     $metadata = $channel->generate_metadata();
                     $metadata['requests'] = $remote_channel['requests'];
                     $subscription = new Subscription();
                     $subscription->setCertificate($certificate['key']);
                     $subscription->setApplication($form->inputApplicationId);
                     $subscription->setChannel($metadata['_id']);
                     $subscription->setMaster(false);
                     $db_remote_options = array('default' => Renegade::databaseForId($remote_application));
                     $db_remote_subscriptions = Renegade::database(RenegadeConstants::kDatabaseMongoDB, RenegadeConstants::kDatabaseSubscriptions, $db_remote_options);
                     $certificates = Renegade::database(RenegadeConstants::kDatabaseRedis, RenegadeConstants::kDatabaseCertificates);
                     $db_remote_subscriptions->insert($subscription->toArray());
                     $db_channels->insert($metadata);
                     $certificates->set($certificate['key'], $certificate['value']);
                     // All Done
                     Renegade::redirect('/applications/' . $form->inputApplicationId . '/channels');
                 }
             } else {
                 echo 'channel not found';
                 //Renegade::redirect('/applications/'.$form->inputApplicationId.'./channels');
             }
         }
     }
 }