public function xSaveAction() { $platform = $this->getParam('platform'); $cloudLocation = $this->getParam('cloudLocation'); $this->request->defineParams(array('rules' => array('type' => 'json'), 'sgRules' => array('type' => 'json'))); $groupData = array('id' => $this->getParam('securityGroupId'), 'name' => trim($this->getParam('name')), 'description' => trim($this->getParam('description')), 'rules' => $this->getParam('rules'), 'sgRules' => $this->getParam('sgRules'), 'vpcId' => $this->getParam('vpcId') ? $this->getParam('vpcId') : null); $invalidRules = array(); foreach ($groupData['rules'] as $r) { if (!Scalr_Util_Network::isValidCidr($r['cidrIp'])) { $invalidRules[] = $this->request->stripValue($r['cidrIp']); } } if (count($invalidRules)) { throw new Scalr_Exception_Core(sprintf('Not valid CIDR(s): "%s"', join(', ', $invalidRules))); } if (!$groupData['id']) { $groupData['id'] = $this->callPlatformMethod($platform, 'createGroup', array($platform, $cloudLocation, $groupData)); sleep(2); } $currentGroupData = $this->getGroup($platform, $cloudLocation, $groupData['id']); $warning = null; try { $this->saveGroupRules($platform, $cloudLocation, $currentGroupData, array('rules' => $groupData['rules'], 'sgRules' => $groupData['sgRules'])); } catch (QueryClientException $e) { $warning = $e->getErrorData()->getMessage(); } if ($this->getParam('returnData') && $groupData['id']) { $this->response->data(array('group' => $this->getGroup($this->getParam('platform'), $this->getParam('cloudLocation'), $groupData['id']))); } if ($warning) { $this->response->warning('Security group saved with warning: ' . $warning); } else { $this->response->success("Security group successfully saved"); } }
public function xSaveAction() { $this->request->defineParams(array('rules' => array('type' => 'json'), 'sgRules' => array('type' => 'json'))); $securityGroupId = $this->getParam('securityGroupId'); $securityGroupName = trim($this->getParam('name')); $vpcId = $this->getParam('vpcId'); $vpcId = !empty($vpcId) ? $vpcId : null; $newRules = $this->getParam('rules'); $notValid = array(); foreach ($newRules as $r) { if (!Scalr_Util_Network::isValidCidr($r['cidrIp'])) { $notValid[] = strip_tags($r['cidrIp']); } } if (count($notValid)) { throw new Scalr_Exception_Core(sprintf('Not valid CIDR(s): "%s"', join(', ', $notValid))); } if (!$securityGroupId) { $securityGroupId = $this->getCloudInstance($this->getParam('platform'), $this->getParam('cloudLocation'))->ec2->securityGroup->create($securityGroupName, $this->getParam('description'), $vpcId); sleep(5); $groupData = array('id' => $securityGroupId, 'platform' => $this->getParam('platform'), 'cloudLocation' => $this->getParam('cloudLocation'), 'name' => $securityGroupName, 'rules' => array(), 'sgRules' => array()); } else { $groupData = $this->getGroupData($this->getParam('platform'), $this->getParam('cloudLocation'), $securityGroupId); } $this->saveRules($groupData, array('rules' => $this->getParam('rules'), 'sgRules' => $this->getParam('sgRules'))); if ($this->getParam('returnData')) { $this->response->data(array('group' => $this->getGroupData($this->getParam('platform'), $this->getParam('cloudLocation'), $securityGroupId))); } $this->response->success("Security group successfully saved"); }
public function xSaveAction() { $this->request->restrictAccess(Acl::RESOURCE_SECURITY_SECURITY_GROUPS, Acl::PERM_SECURITY_SECURITY_GROUPS_MANAGE); $platform = $this->getParam('platform'); $cloudLocation = $this->getParam('cloudLocation'); $extraParams = []; $this->request->defineParams(array('rules' => array('type' => 'json'), 'sgRules' => array('type' => 'json'))); $groupData = array('id' => $this->getParam('securityGroupId'), 'name' => trim($this->getParam('name')), 'description' => trim($this->getParam('description')), 'rules' => $this->getParam('rules'), 'sgRules' => $this->getParam('sgRules'), 'vpcId' => $this->getParam('vpcId') ? $this->getParam('vpcId') : null); if ($platform == SERVER_PLATFORMS::AZURE) { $extraParams['resourceGroup'] = $this->getParam('resourceGroup'); $groupData['resourceGroup'] = $this->getParam('resourceGroup'); } $invalidRules = array(); foreach ($groupData['rules'] as $r) { if ($r['cidrIp'] != '*' && !Scalr_Util_Network::isValidCidr($r['cidrIp'])) { $invalidRules[] = $this->request->stripValue($r['cidrIp']); } } if (count($invalidRules)) { throw new Scalr_Exception_Core(sprintf('Not valid CIDR(s): "%s"', join(', ', $invalidRules))); } foreach ($groupData['rules'] as &$rule) { $rule['comment'] = $this->request->stripValue($rule['comment']); } foreach ($groupData['sgRules'] as &$rule) { $rule['comment'] = $this->request->stripValue($rule['comment']); } if (!$groupData['id']) { $groupData['id'] = $this->callPlatformMethod($platform, 'createGroup', array($platform, $cloudLocation, $groupData)); sleep(2); } $warning = null; if ($platform !== 'rds') { $currentGroupData = $this->getGroup($platform, $cloudLocation, $groupData['id'], $extraParams); try { $this->saveGroupRules($platform, $cloudLocation, $currentGroupData, array('rules' => $groupData['rules'], 'sgRules' => $groupData['sgRules']), $extraParams); } catch (QueryClientException $e) { $warning = $e->getErrorData()->getMessage(); } } if ($this->getParam('returnData') && $groupData['id']) { $this->response->data(array('group' => $this->getGroup($this->getParam('platform'), $this->getParam('cloudLocation'), $groupData['id'], $extraParams))); } if ($warning) { $this->response->warning('Security group saved with warning: ' . $warning); } else { $this->response->success("Security group successfully saved"); } }