public static create ( unknown_type $zoneName, unknown_type $soaRefresh, unknown_type $soaExpire, $soaOwner, $soaRetry = 7200 ) : DBDNSZone | ||
$zoneName | unknown_type | |
$soaRefresh | unknown_type | |
$soaExpire | unknown_type | |
Résultat | DBDNSZone |
public function xSaveAction() { $this->request->defineParams(array('domainId' => array('type' => 'int'), 'domainName', 'domainType', 'domainFarm' => array('type' => 'int'), 'domainFarmRole' => array('type' => 'int'), 'soaRefresh' => array('type' => 'int'), 'soaExpire' => array('type' => 'int'), 'soaRetry' => array('type' => 'int'), 'records' => array('type' => 'json'))); $errors = array(); // validate farmId, farmRoleId $farmId = 0; $farmRoleId = 0; if ($this->getParam('domainFarm')) { $DBFarm = DBFarm::LoadByID($this->getParam('domainFarm')); if (!$this->user->getPermissions()->check($DBFarm)) { $errors['domainFarm'] = _('Farm not found'); } else { $farmId = $DBFarm->ID; if ($this->getParam('domainFarmRole')) { $DBFarmRole = DBFarmRole::LoadByID($this->getParam('domainFarmRole')); if ($DBFarmRole->FarmID != $DBFarm->ID) { $errors['domainFarmRole'] = _('Role not found'); } else { $farmRoleId = $DBFarmRole->ID; } } } } // validate domain name $domainName = ''; if (!$this->getParam('domainId')) { if ($this->getParam('domainType') == 'own') { $Validator = new Validator(); if (!$Validator->IsDomain($this->getParam('domainName'))) { $errors['domainName'] = _("Invalid domain name"); } else { $domainChunks = explode(".", $this->getParam('domainName')); $chkDmn = ''; while (count($domainChunks) > 0) { $chkDmn = trim(array_pop($domainChunks) . ".{$chkDmn}", "."); $chkDomainId = $this->db->GetOne("SELECT id FROM dns_zones WHERE zone_name=? AND client_id != ?", array($chkDmn, $this->user->getAccountId())); if ($chkDomainId) { if ($chkDmn == $this->getParam('domainName')) { $errors['domainName'] = sprintf(_("%s already exists on scalr nameservers"), $this->getParam('domainName')); } else { $chkDnsZone = DBDNSZone::loadById($chkDomainId); $access = false; foreach (explode(";", $chkDnsZone->allowedAccounts) as $email) { if ($email == $this->user->getEmail()) { $access = true; } } if (!$access) { $errors['domainName'] = sprintf(_("You cannot use %s domain name because top level domain %s does not belong to you"), $this->getParam('domainName'), $chkDmn); } } } } //if (! $errors['domainName']) $domainName = $this->getParam('domainName'); } } else { $domainName = Scalr::GenerateUID() . '.' . CONFIG::$DNS_TEST_DOMAIN_NAME; } // check in DB $rez = $this->db->GetOne("SELECT id FROM dns_zones WHERE zone_name = ?", array($domainName)); if ($rez) { $errors['domainName'] = 'Domain name already exist in database'; } } $records = array(); foreach ($this->getParam('records') as $key => $r) { if (($r['name'] || $r['value']) && $r['issystem'] == 0) { $r['name'] = str_replace("%hostname%", "{$domainName}", $r['name']); $r['value'] = str_replace("%hostname%", "{$domainName}", $r['value']); $records[$key] = $r; } } $recordsValidation = Scalr_Net_Dns_Zone::validateRecords($records); if ($recordsValidation !== true) { $errors = array_merge($errors, $recordsValidation); } if (count($errors) == 0) { if ($this->getParam('domainId')) { $DBDNSZone = DBDNSZone::loadById($this->getParam('domainId')); $this->user->getPermissions()->validate($DBDNSZone); $DBDNSZone->soaRefresh = $this->getParam('soaRefresh'); $DBDNSZone->soaExpire = $this->getParam('soaExpire'); $DBDNSZone->soaRetry = $this->getParam('soaRetry'); $this->response->success("DNS zone successfully updated. It could take up to 5 minutes to update it on NS servers."); } else { $DBDNSZone = DBDNSZone::create($domainName, $this->getParam('soaRefresh'), $this->getParam('soaExpire'), str_replace('@', '.', $this->user->getEmail()), $this->getParam('soaRetry')); $DBDNSZone->clientId = $this->user->getAccountId(); $DBDNSZone->envId = $this->getEnvironmentId(); $this->response->success("DNS zone successfully added to database. It could take up to 5 minutes to setup it on NS servers."); } if ($DBDNSZone->farmRoleId != $farmRoleId || $DBDNSZone->farmId != $farmId) { $DBDNSZone->farmId = 0; $DBDNSZone->updateSystemRecords(); } $DBDNSZone->farmRoleId = $farmRoleId; $DBDNSZone->farmId = $farmId; $DBDNSZone->setRecords($records); $DBDNSZone->save(true); } else { $this->response->failure(); $this->response->data(array('errors' => $errors)); } }
public function DNSZoneCreate($DomainName, $FarmID = null, $FarmRoleID = null) { $this->restrictAccess(Acl::RESOURCE_DNS_ZONES); if (!Scalr::config('scalr.dns.global.enabled')) { throw new Exception("DNS functionality is not enabled. Please contact your Scalr administrator."); } $DomainName = trim($DomainName); $Validator = new Scalr_Validator(); if ($Validator->validateDomain($DomainName) !== true) { throw new Exception(_("Invalid domain name")); } $domain_chunks = explode(".", $DomainName); $chk_dmn = ''; while (count($domain_chunks) > 0) { $chk_dmn = trim(array_pop($domain_chunks) . ".{$chk_dmn}", "."); if ($this->DB->GetOne("SELECT id FROM dns_zones WHERE zone_name=? AND client_id != ? LIMIT 1", array($chk_dmn, $this->user->getAccountId()))) { if ($chk_dmn == $DomainName) { throw new Exception(sprintf(_("%s already exists on scalr nameservers"), $DomainName)); } else { throw new Exception(sprintf(_("You cannot use %s domain name because top level domain %s does not belong to you"), $DomainName, $chk_dmn)); } } } if ($FarmID) { $DBFarm = DBFarm::LoadByID($FarmID); if ($DBFarm->EnvID != $this->Environment->id) { throw new Exception(sprintf("Farm #%s not found", $FarmID)); } $this->user->getPermissions()->validate($DBFarm); } if ($FarmRoleID) { $DBFarmRole = DBFarmRole::LoadByID($FarmRoleID); if ($DBFarm->ID != $DBFarmRole->FarmID) { throw new Exception(sprintf("FarmRole #%s not found on Farm #%s", $FarmRoleID, $FarmID)); } } $response = $this->CreateInitialResponse(); $DBDNSZone = DBDNSZone::create($DomainName, 14400, 86400, str_replace('@', '.', $this->user->getEmail())); $DBDNSZone->farmRoleId = (int) $FarmRoleID; $DBDNSZone->farmId = (int) $FarmID; $DBDNSZone->clientId = $this->user->getAccountId(); $DBDNSZone->envId = $this->Environment->id; $def_records = $this->DB->GetAll("SELECT * FROM default_records WHERE clientid=?", array($this->user->getAccountId())); foreach ($def_records as $record) { $record["name"] = str_replace(array("%hostname%", "%zonename%"), array("{$DomainName}.", "{$DomainName}."), $record["name"]); $record["value"] = str_replace(array("%hostname%", "%zonename%"), array("{$DomainName}.", "{$DomainName}."), $record["value"]); $records[] = $record; } $nameservers = Scalr::config('scalr.dns.global.nameservers'); foreach ($nameservers as $ns) { $records[] = array("id" => "c" . rand(10000, 999999), "type" => "NS", "ttl" => 14400, "value" => "{$ns}.", "name" => "{$DomainName}.", "issystem" => 0); } $DBDNSZone->setRecords($records); $DBDNSZone->save(true); $response->Result = 1; return $response; }
public function DNSZoneCreate($DomainName, $FarmID = null, $FarmRoleID = null) { $DomainName = trim($DomainName); $Validator = new Validator(); if (!$Validator->IsDomain($DomainName)) { throw new Exception(_("Invalid domain name")); } $domain_chunks = explode(".", $DomainName); $chk_dmn = ''; while (count($domain_chunks) > 0) { $chk_dmn = trim(array_pop($domain_chunks) . ".{$chk_dmn}", "."); if ($this->DB->GetOne("SELECT id FROM dns_zones WHERE zone_name=? AND client_id != ?", array($chk_dmn, $this->user->getAccountId()))) { if ($chk_dmn == $DomainName) { throw new Exception(sprintf(_("%s already exists on scalr nameservers"), $DomainName)); } else { throw new Exception(sprintf(_("You cannot use %s domain name because top level domain %s does not belong to you"), $DomainName, $chk_dmn)); } } } if ($FarmID) { $DBFarm = DBFarm::LoadByID($FarmID); if ($DBFarm->EnvID != $this->Environment->id) { throw new Exception(sprintf("Farm #%s not found", $FarmID)); } } if ($FarmRoleID) { $DBFarmRole = DBFarmRole::LoadByID($FarmRoleID); if ($DBFarm->ID != $DBFarmRole->FarmID) { throw new Exception(sprintf("FarmRole #%s not found on Farm #%s", $FarmRoleID, $FarmID)); } } $response = $this->CreateInitialResponse(); $DBDNSZone = DBDNSZone::create($DomainName, 14400, 86400, str_replace('@', '.', $this->user->getEmail())); $DBDNSZone->farmRoleId = (int) $FarmRoleID; $DBDNSZone->farmId = (int) $FarmID; $DBDNSZone->clientId = $this->user->getAccountId(); $DBDNSZone->envId = $this->Environment->id; $def_records = $this->DB->GetAll("SELECT * FROM default_records WHERE clientid=?", array($this->user->getAccountId())); foreach ($def_records as $record) { $record["name"] = str_replace("%hostname%", "{$DomainName}.", $record["name"]); $record["value"] = str_replace("%hostname%", "{$DomainName}.", $record["value"]); $records[] = $record; } $nss = $this->DB->GetAll("SELECT * FROM nameservers WHERE isbackup='0'"); foreach ($nss as $ns) { $records[] = array("id" => "c" . rand(10000, 999999), "type" => "NS", "ttl" => 14400, "value" => "{$ns["host"]}.", "name" => "{$DomainName}.", "issystem" => 0); } $DBDNSZone->setRecords($records); $DBDNSZone->save(true); $response->Result = 1; return $response; }