Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Service/Amazon/Ec2/Securitygroups.php
Go to the documentation of this file.
00001 <?php
00026 require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
00027 
00037 class Zend_Service_Amazon_Ec2_Securitygroups extends Zend_Service_Amazon_Ec2_Abstract
00038 {
00054     public function create($name, $description)
00055     {
00056         $params = array();
00057         $params['Action'] = 'CreateSecurityGroup';
00058         $params['GroupName'] = $name;
00059         $params['GroupDescription'] = $description;
00060 
00061         $response = $this->sendRequest($params);
00062         $xpath = $response->getXPath();
00063         $success  = $xpath->evaluate('string(//ec2:return/text())');
00064 
00065         return ($success === "true");
00066     }
00067 
00078     public function describe($name = null)
00079     {
00080         $params = array();
00081         $params['Action'] = 'DescribeSecurityGroups';
00082         if(is_array($name) && !empty($name)) {
00083             foreach($name as $k=>$name) {
00084                 $params['GroupName.' . ($k+1)] = $name;
00085             }
00086         } elseif($name) {
00087             $params['GroupName.1'] = $name;
00088         }
00089 
00090         $response = $this->sendRequest($params);
00091         $xpath = $response->getXPath();
00092 
00093         $return = array();
00094 
00095         $nodes = $xpath->query('//ec2:securityGroupInfo/ec2:item');
00096 
00097         foreach($nodes as $node) {
00098             $item = array();
00099 
00100             $item['ownerId'] = $xpath->evaluate('string(ec2:ownerId/text())', $node);
00101             $item['groupName'] = $xpath->evaluate('string(ec2:groupName/text())', $node);
00102             $item['groupDescription'] = $xpath->evaluate('string(ec2:groupDescription/text())', $node);
00103 
00104             $ip_nodes = $xpath->query('ec2:ipPermissions/ec2:item', $node);
00105 
00106             foreach($ip_nodes as $ip_node) {
00107                 $sItem = array();
00108 
00109                 $sItem['ipProtocol'] = $xpath->evaluate('string(ec2:ipProtocol/text())', $ip_node);
00110                 $sItem['fromPort'] = $xpath->evaluate('string(ec2:fromPort/text())', $ip_node);
00111                 $sItem['toPort'] = $xpath->evaluate('string(ec2:toPort/text())', $ip_node);
00112 
00113                 $ips = $xpath->query('ec2:ipRanges/ec2:item', $ip_node);
00114 
00115                 $sItem['ipRanges'] = array();
00116                 foreach($ips as $ip) {
00117                     $sItem['ipRanges'][] = $xpath->evaluate('string(ec2:cidrIp/text())', $ip);
00118                 }
00119 
00120                 if(count($sItem['ipRanges']) == 1) {
00121                     $sItem['ipRanges'] = $sItem['ipRanges'][0];
00122                 }
00123 
00124                 $item['ipPermissions'][] = $sItem;
00125                 unset($ip_node, $sItem);
00126             }
00127 
00128             $return[] = $item;
00129 
00130             unset($item, $node);
00131         }
00132 
00133 
00134         return $return;
00135     }
00136 
00148     public function delete($name)
00149     {
00150         $params = array();
00151         $params['Action'] = 'DeleteSecurityGroup';
00152         $params['GroupName'] = $name;
00153 
00154         $response = $this->sendRequest($params);
00155         $xpath = $response->getXPath();
00156         $success  = $xpath->evaluate('string(//ec2:return/text())');
00157 
00158         return ($success === "true");
00159     }
00160 
00182     public function authorizeIp($name, $ipProtocol, $fromPort, $toPort, $cidrIp)
00183     {
00184         $params = array();
00185         $params['Action'] = 'AuthorizeSecurityGroupIngress';
00186         $params['GroupName'] = $name;
00187         $params['IpProtocol'] = $ipProtocol;
00188         $params['FromPort'] = $fromPort;
00189         $params['ToPort'] = $toPort;
00190         $params['CidrIp'] = $cidrIp;
00191 
00192         $response = $this->sendRequest($params);
00193         $xpath = $response->getXPath();
00194         $success  = $xpath->evaluate('string(//ec2:return/text())');
00195 
00196         return ($success === "true");
00197 
00198     }
00199 
00214     public function authorizeGroup($name, $groupName, $ownerId)
00215     {
00216         $params = array();
00217         $params['Action'] = 'AuthorizeSecurityGroupIngress';
00218         $params['GroupName'] = $name;
00219         $params['SourceSecurityGroupName'] = $groupName;
00220         $params['SourceSecurityGroupOwnerId'] = $ownerId;
00221 
00222 
00223         $response = $this->sendRequest($params);
00224         $xpath = $response->getXPath();
00225         $success  = $xpath->evaluate('string(//ec2:return/text())');
00226 
00227 
00228         return ($success === "true");
00229     }
00230 
00253     public function revokeIp($name, $ipProtocol, $fromPort, $toPort, $cidrIp)
00254     {
00255         $params = array();
00256         $params['Action'] = 'RevokeSecurityGroupIngress';
00257         $params['GroupName'] = $name;
00258         $params['IpProtocol'] = $ipProtocol;
00259         $params['FromPort'] = $fromPort;
00260         $params['ToPort'] = $toPort;
00261         $params['CidrIp'] = $cidrIp;
00262 
00263         $response = $this->sendRequest($params);
00264         $xpath = $response->getXPath();
00265         $success  = $xpath->evaluate('string(//ec2:return/text())');
00266 
00267         return ($success === "true");
00268     }
00269 
00285     public function revokeGroup($name, $groupName, $ownerId)
00286     {
00287         $params = array();
00288         $params['Action'] = 'RevokeSecurityGroupIngress';
00289         $params['GroupName'] = $name;
00290         $params['SourceSecurityGroupName'] = $groupName;
00291         $params['SourceSecurityGroupOwnerId'] = $ownerId;
00292 
00293 
00294         $response = $this->sendRequest($params);
00295         $xpath = $response->getXPath();
00296         $success  = $xpath->evaluate('string(//ec2:return/text())');
00297 
00298 
00299         return ($success === "true");
00300     }
00301 }
 All Data Structures Namespaces Files Functions Variables Enumerations