public void Delete(RhspDataID dataID)
        {
            DnsZone dnsZone = HostingConfig.GetSingle <DnsZone>(dataID);

            HostingConfig.Delete <DnsZone>(dataID);
            CreateManager <IscBindManager>().DeleteZone(dnsZone);
        }
 private string getZoneConfigIndex(DnsZone z)
 {
     return(string.Format(
                "zone \"{0}\" IN {{ type master; file \"{1}\"; allow-transfer {{ none; }}; }};",
                z.Name,
                getZoneConfigPath(zoneConfigFileDirectory, z)));
 }
        private void deleteZoneConfigFile(DnsZone zone)
        {
            string   zoneConfigFilePath = getZoneConfigPath(getZonesDirectory().FullName, zone);
            FileInfo zoneConfigFile     = new FileInfo(zoneConfigFilePath);

            zoneConfigFile.Delete();
        }
Ejemplo n.º 4
0
        public DnsZone UpdateDnsZone(DnsZone zone, bool overwrite)
        {
            ZoneCreateOrUpdateResponse response = this.DnsManagementClient.Zones.CreateOrUpdate(
                zone.ResourceGroupName,
                zone.Name,
                new ZoneCreateOrUpdateParameters
            {
                Zone = new Management.Dns.Models.Zone
                {
                    Location   = DnsResourceLocation,
                    Name       = zone.Name,
                    Tags       = TagsConversionHelper.CreateTagDictionary(zone.Tags, validate: true),
                    ETag       = overwrite ? "*" : zone.Etag,
                    Properties = new ZoneProperties
                    {
                    }
                }
            });

            return(new DnsZone
            {
                Name = response.Zone.Name,
                ResourceGroupName = zone.ResourceGroupName,
                Etag = response.Zone.ETag,
                Tags = TagsConversionHelper.CreateTagHashtable(response.Zone.Tags),
            });
        }
Ejemplo n.º 5
0
        private void deleteDnsZone(DnsZone dnsZone)
        {
            // Mark deleted so that it is deleted on server request.
            dnsZone.PendingAction = ChildPendingAction.Delete;

            // Remove from visual binding list.
            bindingList.Remove(dnsZone);
        }
        private DnsZone convertToDnsZone(MsDnsZone mdz)
        {
            DnsZone dnsZone = new DnsZone(RhspDataID.Generate());

            dnsZone.DefaultTtl  = defaultTtl;
            dnsZone.Name        = mdz.Name;
            dnsZone.RecordArray = convertToDnsRecords(mdz.MixedReords).ToArray();
            return(dnsZone);
        }
Ejemplo n.º 7
0
        /// <inheritdoc/>
        public override void DeleteZone(DnsZone zone)
        {
            if (zone == null)
            {
                throw new ArgumentNullException(nameof(zone));
            }

            DeleteZone(zone.DomainName);
        }
Ejemplo n.º 8
0
        /// <inheritdoc/>
        public override DnsZone CreateZone(DnsZone zoneTemplate)
        {
            if (zoneTemplate == null)
            {
                throw new ArgumentNullException(nameof(zoneTemplate));
            }

            return(CreateZone(zoneTemplate.DomainName));
        }
Ejemplo n.º 9
0
 public void DeleteDnsZone(
     DnsZone zone,
     bool overwrite)
 {
     this.DnsManagementClient.Zones.Delete(
         zone.ResourceGroupName,
         zone.Name,
         ifMatch: overwrite?null: zone.Etag);
 }
Ejemplo n.º 10
0
        public override DnsZone GetDnsZone(string domainName)
        {
            var _tmp = new DnsZone();

            _tmp.Name = domainName;

            using (SqlConnection _conn = new SqlConnection(connectionString))
            {
                _conn.Open();

                using (SqlCommand _cmd = new SqlCommand(@"SELECT  Domain.Name, DomainZone.Id, DomainZone.ZoneType, 
			                                                DomainZone.AllowZoneTransfers, 
				                                                DomainZone.SecondaryServers, DomainZone.SerialNumber, 
				                                                DomainZone.PrimaryServer, DomainZone.ResponsiblePerson, 
				                                                DomainZone.RefreshInterval, DomainZone.RetryInterval, 
				                                                DomainZone.Expires, DomainZone.TTL
                                                FROM DomainZone 
	                                                INNER JOIN Domain ON DomainZone.DomainId = Domain.DomainId WHERE (Domain.Name = @NAME)"    , _conn))
                {
                    _cmd.Parameters.AddWithValue("@NAME", domainName);

                    using (SqlDataReader _read = _cmd.ExecuteReader(System.Data.CommandBehavior.SingleRow))
                    {
                        if (_read.Read())
                        {
                            _tmp.Name    = DataExtensions.GetColumnValue <string>(_read, "Name").ToLower();
                            _tmp.mininum = -1;
                            _tmp.refresh = DataExtensions.GetColumnValue <int>(_read, "RefreshInterval");
                            _tmp.retry   = DataExtensions.GetColumnValue <int>(_read, "RetryInterval");
                            _tmp.expire  = DataExtensions.GetColumnValue <int>(_read, "Expires");

                            var serial = DataExtensions.GetColumnValue <string>(_read, "SerialNumber");

                            if (!String.IsNullOrEmpty(serial))
                            {
                                int intSerial = 0;

                                if (int.TryParse(serial, out intSerial))
                                {
                                    _tmp.serial = intSerial;
                                }
                            }

                            _tmp.ttl   = DataExtensions.GetColumnValue <int>(_read, "TTL");
                            _tmp.Email = DataExtensions.GetColumnValue <string>(_read, "ResponsiblePerson");
                        }
                    }
                }

                _conn.Close();
            }

            _tmp.Records = GetZoneRecords(domainName);

            return(_tmp);
        }
Ejemplo n.º 11
0
        static void DumpDnsZone(DnsZone zone)
        {
            WriteLine(zone);

            WriteLine("Records:");
            foreach (var record in zone.Records)
            {
                WriteLine(record);
            }
        }
Ejemplo n.º 12
0
        public override bool AddZone(DnsZone zone, string subdomain, string ipAddress)
        {
            var request = new RestRequest("zones");

            request.AddParameter("name", $"{subdomain}.{zone.Id}");
            request.AddParameter("ipv4address", $"{ipAddress}");
            var restResponse = Client.RestClient.Post(request);

            return(restResponse.IsSuccessful);
        }
Ejemplo n.º 13
0
        public int RestoreItem(string tempFolder, XmlNode itemNode, int itemId, Type itemType,
                               string itemName, int packageId, int serviceId, ResourceGroupInfo group)
        {
            if (itemType != typeof(DnsZone))
            {
                return(0);
            }

            // DNS provider
            DNSServer dns = GetDNSServer(serviceId);

            // check service item
            if (!dns.ZoneExists(itemName))
            {
                // create primary and secondary zones
                AddZone(packageId, serviceId, itemName, false, false);

                // restore records
                XmlSerializer    serializer = new XmlSerializer(typeof(DnsRecord));
                List <DnsRecord> records    = new List <DnsRecord>();
                foreach (XmlNode childNode in itemNode.ChildNodes)
                {
                    if (childNode.Name == "DnsRecord")
                    {
                        records.Add((DnsRecord)serializer.Deserialize(new XmlNodeReader(childNode)));
                    }
                }

                dns.AddZoneRecords(itemName, records.ToArray());
            }

            // check if meta-item exists
            int     zoneId = 0;
            DnsZone item   = (DnsZone)PackageController.GetPackageItemByName(packageId, itemName, typeof(DnsZone));

            if (item == null)
            {
                // restore meta-item
                item           = new DnsZone();
                item.Name      = itemName;
                item.PackageId = packageId;
                item.ServiceId = serviceId;
                zoneId         = PackageController.AddPackageItem(item);
            }
            else
            {
                zoneId = item.Id;
            }

            // restore domains
            RestoreDomainByZone(itemName, packageId, zoneId);

            return(0);
        }
        public void Process(DnsZone dnsZone)
        {
            switch (dnsZone.PendingAction)
            {
            case ChildPendingAction.Create: Create(dnsZone); break;

            case ChildPendingAction.Update: Update(dnsZone); break;

            case ChildPendingAction.Delete: Delete(dnsZone.DataID); break;
            }
        }
Ejemplo n.º 15
0
        public void DomainSetDnsZone()
        {
            DnsZone dnsZone = new DnsZone();

            dnsZone.Name = "demodemo.com";

            PanelResult result = panel.DomainSetDnsZone(dnsZone);


            Assert.AreEqual(200, result.Code);
        }
        public void Replace(DnsZone dnsZone)
        {
            // Remove any existing zones with matching name.
            var existing = from dz in HostingConfig.GetArray <DnsZone>()
                           where dz.Name == dnsZone.Name
                           select dz;

            existing.ToList().ForEach(dz => Delete(dz.DataID));

            // Now proceed to create the new zone.
            Create(dnsZone);
        }
        public async Task CreateTxtRecordAsync(DnsZone zone, string relativeRecordName, IEnumerable <string> values)
        {
            var urlTemplate = "/domains/{zone}/records/{type}/{name}";
            var url         = String.Format(urlTemplate, zone.Name, GodaddyConstants.DNS_TXT_RECORD, relativeRecordName);
            var txtRecord   = new GoDaddyDnsRecord()
            {
                name = relativeRecordName,
                data = string.Join(" ", values)
            };

            await _httpClient.PutAsJsonAsync <GoDaddyDnsRecord>(url, txtRecord);
        }
Ejemplo n.º 18
0
        public bool DeleteDnsZone(
            DnsZone zone,
            bool overwrite)
        {
            var deleteResult = this.DnsManagementClient.Zones.Delete(
                zone.ResourceGroupName,
                zone.Name,
                ifMatch: overwrite ? null : zone.Etag,
                ifNoneMatch: null);

            return(deleteResult.Status == Sdk.OperationStatus.Succeeded);
        }
Ejemplo n.º 19
0
        public bool DeleteDnsZone(DnsZone zone, bool overwrite)
        {
            AzureOperationResponse resp = this.DnsManagementClient.Zones.Delete(
                zone.ResourceGroupName,
                zone.Name,
                new ZoneDeleteParameters
            {
                IfMatch = overwrite ? null : zone.Etag,
            });

            return(resp.StatusCode == System.Net.HttpStatusCode.NoContent || resp.StatusCode == System.Net.HttpStatusCode.OK ? true : false);
        }
Ejemplo n.º 20
0
        private static int RegisterZoneItems(int spaceId, int serviceId, string zoneName, bool primaryZone)
        {
            // zone item
            DnsZone zone = primaryZone ? new DnsZone() : new SecondaryDnsZone();

            zone.Name      = GetAsciiZoneName(zoneName);
            zone.PackageId = spaceId;
            zone.ServiceId = serviceId;
            int zoneItemId = PackageController.AddPackageItem(zone);

            return(zoneItemId);
        }
        private void enforceUniqueZone(DnsZone zone)
        {
            // Find zones with same name other than the current one.
            var q = from z in HostingConfig.GetArray <DnsZone>()
                    where z.Name == zone.Name
                    where !z.DataID.Equals(zone.DataID)
                    select z;

            if (q.Count() != 0)
            {
                throw new Exception(
                          "A DNS zone with the name '" + zone.Name + "' already exists.");
            }
        }
Ejemplo n.º 22
0
        public DnsZone UpdateDnsZone(DnsZone zone, bool overwrite)
        {
            var response = this.DnsManagementClient.Zones.CreateOrUpdate(
                zone.ResourceGroupName,
                zone.Name,
                new Zone
            {
                Location = DnsResourceLocation,
                Tags     = TagsConversionHelper.CreateTagDictionary(zone.Tags, validate: true),
            },
                ifMatch: overwrite ? "*" : zone.Etag,
                ifNoneMatch: null);

            return(ToDnsZone(response));
        }
Ejemplo n.º 23
0
        public override bool SubdomainAvailable(DnsZone zone, string subdomain)
        {
            using (var wc = new HttpClient())
            {
                var dns           = _cloudFlareContext.Zone(zone.Id).Dns;
                var dnsListSyntax = dns.List().CallAsync(wc).Result;
                if (dnsListSyntax.Select(dnsRecord => dnsRecord.Name.Replace(zone.Name, ""))
                    .Any(name => name.Trim('.') == subdomain.Trim('.')))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 24
0
        public override bool RemoveZone(DnsZone zone, string subdomain)
        {
            var dynv6Zone = GetRegisteredZones().FirstOrDefault(x =>
                                                                string.Equals(x.Name, $"{subdomain}.{zone.Id}", StringComparison.CurrentCultureIgnoreCase));

            if (dynv6Zone == null)
            {
                return(false);
            }

            var deleteRequest = new RestRequest($"zones/{dynv6Zone.Id}");
            var restResponse2 = Client.RestClient.Delete(deleteRequest);

            return(restResponse2.IsSuccessful);
        }
        private string getZoneConfigContent(DnsZone zone)
        {
            if (string.IsNullOrEmpty(zone.Name))
            {
                throw new Exception("The DNS zone name cannot be empty.");
            }

            if (string.IsNullOrEmpty(zone.DefaultTtl))
            {
                throw new Exception("The DNS zone default TTL cannot be empty.");
            }

            StringBuilder builder = new StringBuilder();

            builder.AppendFormat(";\r\n; {0}\r\n;\r\n", generatedConfigFileComment);
            builder.AppendFormat("$TTL {0}\r\n", zone.DefaultTtl);

            builder.AppendFormat(
                "@ IN SOA {0} {1} ({2}{3} {4} {5} {6} {7})",
                ServerConfig.FirstDnsNameServer,
                ServerConfig.DnsHostmasterName,
                DateTime.Today.ToString("yyyyMMdd"),
                "00",                                  // TODO: Implement revision increment.
                TimeSpan.FromHours(1).TotalSeconds,    // Refesh
                TimeSpan.FromMinutes(10).TotalSeconds, // Retry
                TimeSpan.FromDays(14).TotalSeconds,    // Expire
                TimeSpan.FromHours(1).TotalSeconds     // Minimum
                );
            builder.AppendLine();

            if (zone.RecordArray.Count(r => r.RecordType == DnsRecordType.NS) == 0)
            {
                throw new InvalidOperationException(
                          "Record array must contain at least one NS record.");
            }

            // Get zones that aren't due to be deleted.
            var rq = from r in zone.RecordArray
                     where r.PendingAction != ChildPendingAction.Delete
                     select r;

            // Append a config string for each record to the builder.
            rq.ToList().ForEach(r => builder.AppendLine(getRecordConfig(r)));

            return(builder.ToString());
        }
Ejemplo n.º 26
0
        private void dataGridView_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.RowIndex != -1)
            {
                DnsZone       dnsZone = (DnsZone)dataGridView.Rows[e.RowIndex].DataBoundItem;
                DnsZoneEditor editor  = new DnsZoneEditor();
                editor.ReflectDataToForm(dnsZone);
                DialogResult result = editor.ShowDialog();

                if (result == DialogResult.OK)
                {
                    editor.ReflectFormToData(dnsZone);
                    dnsZone.PendingAction = ChildPendingAction.Update;
                    bindingList.ResetBindings();
                }
            }
        }
Ejemplo n.º 27
0
        public void ReflectDataToForm(DnsZone dnsZone)
        {
            nameTextBox.Text       = dnsZone.Name;
            defaultTtlTextBox.Text = dnsZone.DefaultTtl;

            if (dnsZone.RecordArray != null)
            {
                var q = from r in dnsZone.RecordArray
                        orderby r.RecordType, r.Name, r.Value, r.Ttl
                select r;

                //dnsZone.RecordArray.OrderBy(r => r.Name).ToList().ForEach(r => addRecord(r));
                q.ToList().ForEach(r => addRecord(r));
            }

            recordBindingList.ResetBindings();
        }
Ejemplo n.º 28
0
        public override DnsZone GetDnsZone(string domainName)
        {
            var _tmp = new DnsZone();

            using (MySqlConnection _conn = new MySqlConnection(connectionString))
            {
                _conn.Open();
                using (MySqlCommand _cmd = new MySqlCommand(@"SELECT dns_zone.* FROM dns_zone 
                                                                        LEFT JOIN domains ON dns_zone.name = domains.name 
                                                                            WHERE domains.name = @NAME", _conn))
                {
                    _cmd.Parameters.AddWithValue("@NAME", domainName);

                    using (MySqlDataReader _read = _cmd.ExecuteReader())
                    {
                        while (_read.Read())
                        {
                            _tmp.Name    = DataExtensions.GetColumnValue <string>(_read, "name").ToLower();
                            _tmp.mininum = Convert.ToInt32(DataExtensions.GetColumnValue <uint>(_read, "minimum"));
                            _tmp.refresh = Convert.ToInt32(DataExtensions.GetColumnValue <uint>(_read, "refresh"));
                            _tmp.retry   = Convert.ToInt32(DataExtensions.GetColumnValue <uint>(_read, "retry"));
                            _tmp.expire  = Convert.ToInt32(DataExtensions.GetColumnValue <uint>(_read, "expire"));

                            var serial_number = 0;

                            var serial = DataExtensions.GetColumnValue <string>(_read, "serial");
                            _tmp.serial = 0;

                            if (int.TryParse(serial, out serial_number))
                            {
                                _tmp.serial = serial_number;
                            }

                            _tmp.ttl   = Convert.ToInt32(DataExtensions.GetColumnValue <uint>(_read, "ttl"));
                            _tmp.Email = DataExtensions.GetColumnValue <string>(_read, "email");
                        }
                    }
                }
                _conn.Close();
            }

            _tmp.Records = GetZoneRecords(domainName);

            return(_tmp);
        }
Ejemplo n.º 29
0
        public DnsZone GetDnsZoneHandleNonExistentZone(string zoneName, string resourceGroupName)
        {
            DnsZone retrievedZone = null;

            try
            {
                retrievedZone = this.GetDnsZone(zoneName, resourceGroupName);
            }
            catch (CloudException exception)
            {
                if (exception.Body.Code != "ResourceNotFound")
                {
                    throw;
                }
            }

            return(retrievedZone);
        }
Ejemplo n.º 30
0
        public DnsZone UpdateDnsZone(DnsZone zone, bool overwrite)
        {
            var response = this.DnsManagementClient.Zones.CreateOrUpdate(
                zone.ResourceGroupName,
                zone.Name,
                new Zone
            {
                Location = DnsResourceLocation,
                Tags     = TagsConversionHelper.CreateTagDictionary(zone.Tags, validate: true),
                ZoneType = zone.ZoneType,
                RegistrationVirtualNetworks = zone.RegistrationVirtualNetworkIds.ToVirtualNetworkResources(),
                ResolutionVirtualNetworks   = zone.ResolutionVirtualNetworkIds.ToVirtualNetworkResources(),
            },
                ifMatch: overwrite?null: zone.Etag,
                ifNoneMatch: null);

            return(ToDnsZone(response));
        }