Example #1
0
 public function postTerminate($group_id)
 {
     $input = Input::all();
     if (isset($input['invite_id'])) {
         //Terminate Invite
         // Check for existence of invite
         try {
             $invite = Invite::findorFail($input['invite_id']);
         } catch (Exception $e) {
             $message = "Invite not found";
             return Redirect::to("/manage/{$group_id}")->with('message', $message);
         }
         $invite->delete();
         return Redirect::to("/manage/{$group_id}")->with('message', "Invite terminated successfully");
     } elseif (isset($input['lease_id'])) {
         //Terminate Lease
         // Check for existence of lease
         try {
             $lease = Lease::findorFail($input['lease_id']);
         } catch (Exception $e) {
             $message = "Lease not found";
             return Redirect::to("/manage/{$group_id}")->with('message', $message);
         }
         // Terminate the lease on AWS
         $result = $this->terminateLease($lease->toArray());
         //Delete from DB
         $lease->delete();
         $this->NotificationMail($lease, FALSE);
         if (!$result) {
             //Should not occur even if lease doesn't exist with AWS. Check AWS API Conf.
             return Redirect::to("/manage/{$group_id}")->with('message', "Lease Termination returned error. Assumed the lease was already deleted");
         }
         return Redirect::to("/manage/{$group_id}")->with('message', "Lease terminated successfully");
     } else {
         App::abort(403, 'Unauthorized action.');
     }
     //get security group details
     $ec2 = App::make('aws')->get('ec2');
     $security_group = $ec2->describeSecurityGroups(array('GroupIds' => array($group_id)));
     $security_group = $security_group['SecurityGroups'][0];
     //get Active Leases
     $leases = Lease::getByGroupId($group_id);
     //get Active Invites
     $invites = Invite::getByGroupId($group_id);
     return View::make('getManage')->with('security_group', $security_group)->with('leases', $leases)->with('invites', $invites);
 }