Esempio n. 1
0
 $pattern_certificate = '/^' . RenegadeConstants::kTypeCertificate . ':[a-z0-9]{32}$/';
 $form->addValidator(new AMInputValidator('inputDescription', true, 4, null, 'Channel Description must be at least 4 characters long'));
 $form->addValidator(new AMPatternValidator('inputLabel', true, '/^[\\w -]+$/', 'Channel Name may only container letters, numbers, spaces, underscores or hyphens'));
 $form->addValidator(new AMPatternValidator('inputId', true, '/^[a-z0-9][a-z0-9-]+$/', 'Channel Id may only container letters, numbers, or hyphens.  It cannot begin with a hyphen'));
 $form->addValidator(new AMPatternValidator('inputCertificate', true, $pattern_certificate, 'Invalid certificate'));
 $form->addValidator(new ApplicationIdValidator('inputApplicationId', true, 'Invalid application id'));
 if ($form->isValid) {
     // make sure we are authorized to create the channel for this application
     $mongodb = Renegade::database(RenegadeConstants::kDatabaseMongoDB, RenegadeConstants::kDatabaseApplications);
     $redis = Renegade::database(RenegadeConstants::kDatabaseRedis, RenegadeConstants::kDatabaseCertificates);
     $certificate = json_decode($redis->get($form->inputCertificate), true);
     $data = $mongodb->findOne(array('_id' => $form->inputApplicationId));
     if ($data['owner'] == $session->user && $certificate['owner'] == $session->user) {
         // create the channel
         $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);
Esempio n. 2
0
     //Renegade::redirect('/applications/'.$form->inputApplicationId.'./channels');
 } else {
     // is subscribing to a subscription channel in another application even possible?
     // I dont think so, since you would need the channel id anyway, which would point you to
     // the origin application.
     /*
     	TODO 
     	We need to add a subscription to the remote subscriptions db for the remote collection
     	We need to add the certificate for this channel
     	We need to add the channel to the local application's channels
     	Send an e-mail requesting extended permissions here if requested
     */
     // 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());