public bool UpdateDNSRecord(string zoneId, string dnsRecordId, UpdateDNSRecordDto dto)
        {
            //PUT / zones /:zone_identifier / dns_records /:identifier
            var _client = new RestClient(CloudflareBaseUrl);
            var request = new RestRequest(string.Format("zones/{0}/dns_records/{1}", zoneId, dnsRecordId), Method.PUT)
            {
                RequestFormat = DataFormat.Json
            };

            request.AddBody(dto);
            //request.AddHeader("Authorization", "06272372527cf531fa0535ccbb33faf0fa2a2d9f");

            var response = _client.Execute(request);

            if (response != null && response.StatusCode == HttpStatusCode.OK)
            {
                var apiResult = JsonHelper.DeserializeObject <CloudflareApiResult <DNSRecord> >(response.Content);
                if (apiResult.success)
                {
                    DNSRecordAdded = apiResult.result;
                    return(true);
                }
                else
                {
                    this.EwhErrorMessage = JsonHelper.SerializeObject(apiResult.errors);
                    EwhLogger.Common.Error(string.Format("CREATE_DNS_ERROR: {0}"), apiResult.errors);
                }
            }
            else
            {
                this.EwhErrorMessage = response.ErrorMessage;
                this.EwhException    = response.ErrorException;
            }
            return(false);
        }
Example #2
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            this.DNSRecords = new List <DNSRecord>();
            StringBuilder errors = new StringBuilder();

            foreach (string line in tbInput.Lines)
            {
                try
                {
                    if (line.Trim() == "")
                    {
                        continue;
                    }
                    DNSRecord record = BindParser.ParseLine(line);
                    this.DNSRecords.Add(record);
                } catch (Exception E)
                {
                    errors.Append(line);
                    errors.Append(Environment.NewLine);
                }
            }

            this.Errors = errors.ToString();

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Example #3
0
        public void InvalidDNSRecord()
        {
            DNSRecord dnsRecord = new DNSRecord
            {
                Data     = "boom",
                Flags    = 0,
                Id       = "goes",
                Priority = 0,
                Name     = string.Empty,
                Tag      = "the dynamite",
                TTL      = 0,
                Type     = DNSRecordType.SRV
            };

            IValidator <DNSRecord> validator        = new DigitalOceanDNSRecordValidator();
            ValidationResult       validationResult = validator.Validate(dnsRecord);

            Assert.False(validationResult.IsValid);

            Assert.Contains(validationResult.Errors, f => f.PropertyName == nameof(DNSRecord.Data));
            Assert.Contains(validationResult.Errors, f => f.PropertyName == nameof(DNSRecord.Flags));
            Assert.Contains(validationResult.Errors, f => f.PropertyName == nameof(DNSRecord.Id));
            Assert.Contains(validationResult.Errors, f => f.PropertyName == nameof(DNSRecord.Priority));
            Assert.Contains(validationResult.Errors, f => f.PropertyName == nameof(DNSRecord.Name));
            Assert.Contains(validationResult.Errors, f => f.PropertyName == nameof(DNSRecord.Tag));
            Assert.Contains(validationResult.Errors, f => f.PropertyName == nameof(DNSRecord.TTL));
            Assert.Contains(validationResult.Errors, f => f.PropertyName == nameof(DNSRecord.Type));
        }
        public void UpdatedRecords()
        {
            DNSRecord record1 = new DNSRecord {
                Data = "192.168.10.1", Name = "record1", Type = DNSRecordType.A
            };
            DNSRecord record2 = new DNSRecord {
                Data = "192.168.10.2", Name = "record2", Type = DNSRecordType.A
            };
            DNSRecord record3 = new DNSRecord {
                Data = "192.168.10.3", Name = "record1", Type = DNSRecordType.A
            };
            DNSRecord record4 = new DNSRecord {
                Data = "192.168.10.2", Name = "record2", Type = DNSRecordType.A
            };
            DNSRecord record5 = new DNSRecord {
                Data = "192.168.10.5", Name = "record5", Type = DNSRecordType.A
            };
            DNSRecord record6 = new DNSRecord {
                Data = "192.168.10.6", Name = "record6", Type = DNSRecordType.A
            };

            DNSRecordCollection compareWith = new DNSRecordCollection(record1, record2, record5);

            DNSRecordCollection compareTo = new DNSRecordCollection(record3, record4, record6);

            DNSRecordCollection updateRecords = compareWith.WhereUpdated(compareTo);

            Assert.Contains(record3, updateRecords, DNSRecordEqualityComparer.Instance);
            Assert.DoesNotContain(record1, updateRecords, DNSRecordEqualityComparer.Instance);
            Assert.DoesNotContain(record2, updateRecords, DNSRecordEqualityComparer.Instance);
            Assert.DoesNotContain(record4, updateRecords, DNSRecordEqualityComparer.Instance);
            Assert.DoesNotContain(record5, updateRecords, DNSRecordEqualityComparer.Instance);
            Assert.DoesNotContain(record6, updateRecords, DNSRecordEqualityComparer.Instance);
        }
Example #5
0
        public void Returns_Non_Null_Update_Request_When_Passed_Null()
        {
            DNSRecordToGoDaddyUpdateDNSRecordRequestConverter converter = new DNSRecordToGoDaddyUpdateDNSRecordRequestConverter();
            DNSRecord record = new DNSRecord()
            {
                Data     = "recordData",
                Name     = "recordName",
                Port     = 1,
                Priority = 1,
                TTL      = 1,
                Weight   = 1,
                Tag      = "something",
                Type     = DNSRecordType.A
            };

            GoDaddyUpdateDNSRecord result = converter.Convert(record, null, _resolutionContext);

            Assert.NotNull(result);
            Assert.Equal(record.Data, result.Data);
            Assert.Equal((int)record.Port, result.Port);
            Assert.Equal((int)record.Priority, result.Priority);
            Assert.Null(result.Protocol);
            Assert.Null(result.Service);
            Assert.Equal(record.TTL, (int)result.Ttl);
            Assert.Equal(record.Weight, (int)result.Weight);
        }
        public void Convert_PassedNullRequest_ReturnsNewRequest()
        {
            DNSRecordToGoDaddyCreateToDNSRecordRequestConverter converter = new DNSRecordToGoDaddyCreateToDNSRecordRequestConverter();
            DNSRecord record = new DNSRecord()
            {
                Data     = "recordData",
                Name     = "recordName",
                Port     = 1,
                Priority = 1,
                TTL      = 1,
                Weight   = 1,
                Tag      = "recordTag",
                Type     = DNSRecordType.A
            };

            GoDaddyCreateDNSRecordRequest result = converter.Convert(record, null, _resolutionContext);

            Assert.NotNull(result);
            Assert.Equal(record.Data, result.Data);
            Assert.Equal(record.Name, result.Name);
            Assert.Equal(record.Port, result.Port);
            Assert.Equal(record.Priority, result.Priority);
            Assert.Null(result.Protocol);
            Assert.Null(result.Service);
            Assert.Equal(record.TTL, result.Ttl);
            Assert.Equal(record.Weight, result.Weight);
        }
        public void ReturnsNewDNSRecordWhenPassedNull()
        {
            DigitalOceanGetDomainRecordResponseToDNSRecordConverter converter = new DigitalOceanGetDomainRecordResponseToDNSRecordConverter();
            DigitalOceanGetDomainRecordResponse response = new DigitalOceanGetDomainRecordResponse()
            {
                Data     = "data",
                Flags    = 1,
                Id       = 1,
                Name     = "name",
                Port     = 1,
                Priority = 1,
                Tag      = "tag",
                Ttl      = 1,
                Type     = "A",
                Weight   = 1
            };

            DNSRecord actual = converter.Convert(response, null, _mappingHelper.ResolutionContext);

            Assert.Equal(response.Data, actual.Data);
            Assert.Equal(response.Flags, actual.Flags);
            Assert.Equal(response.Id.ToString(), actual.Id);
            Assert.Equal(response.Name, actual.Name);
            Assert.Equal(response.Port, actual.Port);
            Assert.Equal(response.Priority, actual.Priority);
            Assert.Equal(response.Tag, actual.Tag);
            Assert.Equal(response.Ttl, actual.TTL);
            Assert.Equal(DNSRecordType.A, actual.Type);
            Assert.Equal(response.Weight, actual.Weight);
        }
Example #8
0
        public void Given_Null_DNS_Record_Returns_New_DNS_Record()
        {
            GoDaddyGetDNSRecordResponseToDNSRecordConverter converter = new GoDaddyGetDNSRecordResponseToDNSRecordConverter();
            GoDaddyGetDNSRecordResponse response = new GoDaddyGetDNSRecordResponse()
            {
                Data     = "Data",
                Name     = "Name",
                Port     = 0,
                Priority = 0,
                Protocol = "Protocol",
                Service  = "Service",
                Ttl      = 0,
                Type     = "A",
                Weight   = 0
            };

            DNSRecord result = converter.Convert(response, null, _resolutionContext);

            Assert.NotNull(result);
            Assert.Equal(response.Data, result.Data);
            Assert.Equal(response.Name, result.Name);
            Assert.Equal(response.Port, result.Port);
            Assert.Equal(response.Priority, result.Priority);
            Assert.Equal(response.Ttl, result.TTL);
            Assert.Equal(response.Type, result.Type);
            Assert.Equal(response.Weight, result.Weight);
        }
Example #9
0
        public override void UpdateSoaRecord(string zoneName, string host, string primaryNsServer, string primaryPerson)
        {
            if (ZoneExists(zoneName))
            {
                //
                if (String.IsNullOrEmpty(primaryPerson))
                {
                    primaryPerson = "hostmaster";
                }
                //
                Connection cn = SetupProviderConnection();

                DNSZone dnsZone = cn.GetZone(zoneName);
                dnsZone.Comments = "Updated by WebsitePanel DNS API at " + DateTime.Now.ToString();

                DNSRecord soaRecord = (dnsZone.Records.Count == 0) ? dnsZone.Records.Add("@", "SOA") : dnsZone.Records[0];
                // Fill record fields with the data
                soaRecord.DataFields[SOA_PRIMARY_NAME_SERVER] = CorrectSOARecord(zoneName, primaryNsServer);
                soaRecord.DataFields[SOA_RESPONSIBLE_PERSON]  = primaryPerson;
                soaRecord.DataFields[SOA_SERIAL_NUMBER]       = UpdateSerialNumber(soaRecord.DataFields[SOA_SERIAL_NUMBER]);
                soaRecord.DataFields[SOA_REFRESH_INTERVAL]    = RefreshInterval.ToString();
                soaRecord.DataFields[SOA_RETRY_DELAY]         = RetryDelay.ToString();
                soaRecord.DataFields[SOA_EXPIRE_LIMIT]        = ExpireLimit.ToString();
                soaRecord.DataFields[SOA_MINIMUM_TTL]         = MinimumTTL.ToString();

                // remove "dumb" internal Name Server
                string internalNameServer = System.Net.Dns.GetHostEntry("LocalHost").HostName;
                dnsZone.Records.Remove(zoneName, "NS", internalNameServer);

                // save zone
                cn.UpdateZone(dnsZone, false);
            }
        }
Example #10
0
        public void ReturnsNewUpdateRequestWhenNull()
        {
            DNSRecordToDigitalOceanUpdateDomainRecordRequestConverter converter = new DNSRecordToDigitalOceanUpdateDomainRecordRequestConverter();

            DNSRecord record = new DNSRecord()
            {
                Data     = "DNSData",
                Flags    = 1,
                Name     = "DNSName",
                Port     = 1,
                Priority = 1,
                Tag      = "DNSTag",
                TTL      = 1,
                Weight   = 1,
                Type     = DNSRecordType.A
            };

            DigitalOceanUpdateDomainRecordRequest actual = converter.Convert(record, null, _mappingHelper.ResolutionContext);

            Assert.Equal(record.Data, actual.Data);
            Assert.Equal(record.Flags, actual.Flags);
            Assert.Equal(record.Name, actual.Name);
            Assert.Equal(record.Port, actual.Port);
            Assert.Equal(record.Priority, actual.Priority);
            Assert.Equal(record.Tag, actual.Tag);
            Assert.Equal(record.TTL, actual.Ttl);
            Assert.Equal(record.Weight, actual.Weight);
            Assert.Equal(DNSRecordType.A.Value, actual.Type);
        }
Example #11
0
 public DNSZone(DNSRecord start_of_authority, EndPoint[] relays)
 {
     zone_records     = new Dictionary <Tuple <Domain, ResourceRecordType, AddressClass>, HashSet <DNSRecord> >();
     StartOfAuthority = start_of_authority;
     Relays           = relays;
     sub_zones        = new HashSet <Domain>();
 }
Example #12
0
        protected DnsRecord ConvertToNative(DNSRecord record, string zoneName)
        {
            string recordName = ConvertRecordNameToInternalFormat(record.Name, zoneName);
            //
            DnsRecord dnsRecord = null;

            switch (record.Type)
            {
            case "A":
                dnsRecord = new DnsRecord
                {
                    RecordName = recordName,
                    RecordType = DnsRecordType.A,
                    RecordData = record.DataFields[0]
                };
                break;

            case "NS":
                dnsRecord = new DnsRecord
                {
                    RecordName = recordName,
                    RecordType = DnsRecordType.NS,
                    RecordData = record.DataFields[0]
                };
                break;

            case "CNAME":
                dnsRecord = new DnsRecord
                {
                    RecordName = recordName,
                    RecordType = DnsRecordType.CNAME,
                    RecordData = record.DataFields[0]
                };
                break;

            case "MX":
                dnsRecord = new DnsRecord
                {
                    RecordName = recordName,
                    RecordType = DnsRecordType.MX,
                    MxPriority = Convert.ToInt32(record.DataFields[MX_RECORD_PRIORITY]),
                    RecordData = record.DataFields[MX_RECORD_NAMESERVER]
                };
                break;

            case "TXT":
                dnsRecord = new DnsRecord
                {
                    RecordName = recordName,
                    RecordType = DnsRecordType.TXT,
                    RecordData = record.DataFields[0]
                };
                break;
            }
            //
            return(dnsRecord);
        }
Example #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private DNSRecord[] readRecords(NetPacket packet, int count) throws java.io.EOFException
        private DNSRecord[] readRecords(NetPacket packet, int count)
        {
            DNSRecord[] records = new DNSRecord[count];
            for (int i = 0; i < count; i++)
            {
                records[i] = new DNSRecord();
                records[i].read(packet);
            }

            return(records);
        }
Example #14
0
 protected void UpdateSoaRecord(string zoneName)
 {
     if (ZoneExists(zoneName))
     {
         Connection cn = SetupProviderConnection();
         //
         DNSZone   dnsZone   = cn.GetZone(zoneName);
         DNSRecord soaRecord = dnsZone.Records[0];
         //
         UpdateSoaRecord(zoneName, "", soaRecord.DataFields[SOA_PRIMARY_NAME_SERVER], soaRecord.DataFields[SOA_RESPONSIBLE_PERSON]);
     }
 }
Example #15
0
        public async void Sync()
        {
            string PublicIP = await Ext.GetPublicIP();

            if (string.IsNullOrEmpty(PublicIP))
            {
                return;
            }

            string[] ManagedHosts = (await Ext.Kube.ListIngressForAllNamespacesAsync())
                                    .Items
                                    .SelectMany(x => x.Spec.Rules.Select(x => x.Host))
                                    .ToArray()
            ;

            IEnumerable <Zone> Zones = (await APIClient.List <Zone>())
                                       .Items
                                       .Where(x => ManagedHosts.Any(h => h.EndsWith(x.Name)));

            foreach (Zone Zone in Zones)
            {
                List <DNSRecord> OldRecords = (await APIClient.List <DNSRecord>(Zone.Id))
                                              .Items
                                              .Where(x => x.Type == "A" && x.Content == PublicIP)
                                              .ToList();

                int ZoneNameLen = Zone.Name.Length;
                foreach (string Host in ManagedHosts)
                {
                    DNSRecord ActiveRecord = OldRecords.Where(x => Host.StartsWith(x.Name)).FirstOrDefault();
                    if (ActiveRecord == null)
                    {
                        await APIClient.Create(
                            new DNSRecord()
                        {
                            Type = "A", Name = Host.Substring(0, Host.Length - ZoneNameLen - 1), Content = PublicIP
                        }
                            , DryRun, Zone.Id
                            );
                    }
                    else
                    {
                        OldRecords.Remove(ActiveRecord);
                    }
                }

                foreach (DNSRecord OldRecord in OldRecords)
                {
                    await APIClient.Delete <DNSRecord>(DryRun, OldRecord, OldRecord.ZoneId, OldRecord.Id);
                }
            }
        }
Example #16
0
        public void TestStubResolverAcceptsSeveralAliasesForAAAARecords()
        {
            // Make sure that chains of aliases are supported
            var relay = new IPEndPoint(IPAddress.Parse("192.168.0.1"), 53);

            var expected_question = new DNSQuestion(
                new Domain("example.com"),
                ResourceRecordType.HOST_6ADDRESS,
                AddressClass.INTERNET);

            var expected_alias_answer_1 = new DNSRecord(
                new Domain("example.com"), AddressClass.INTERNET, 42,
                new CNAMEResource(new Domain("www.example.com")));

            var expected_alias_answer_2 = new DNSRecord(
                new Domain("www.example.com"), AddressClass.INTERNET, 42,
                new CNAMEResource(new Domain("web1.www.example.com")));

            var expected_addr_answer = new DNSRecord(
                new Domain("web1.www.example.com"), AddressClass.INTERNET, 42,
                new AAAAResource(IPv6Address.Parse("2001:cafe:beef::")));

            var expected_packet = new DNSPacket(
                42, false, QueryType.STANDARD_QUERY, false, false, true, true, ResponseType.NO_ERROR,
                new DNSQuestion[] { expected_question },
                new DNSRecord[] { expected_alias_answer_1, expected_alias_answer_2, expected_addr_answer },
                new DNSRecord[0], new DNSRecord[0]);


            Func <EndPoint, DNSQuestion, bool, DNSPacket> gives_direct_answers = (target, question, is_recursive) =>
            {
                Assert.That(target, Is.EqualTo(relay));
                Assert.That(question, Is.EqualTo(expected_question));
                return(expected_packet);
            };

            var resolver = new StubResolver(new NoopCache(), gives_direct_answers);
            var result   = resolver.Resolve(new Domain("example.com"),
                                            ResourceRecordType.HOST_6ADDRESS,
                                            AddressClass.INTERNET,
                                            new EndPoint[] { relay });

            var expected_result = new ResolverResult();

            expected_result.answers             = new DNSRecord[] { expected_addr_answer };
            expected_result.aliases             = new DNSRecord[] { expected_alias_answer_1, expected_alias_answer_2 };
            expected_result.referrals           = new DNSRecord[0];
            expected_result.referral_additional = new DNSRecord[0];

            Assert.That(result, Is.EqualTo(expected_result));
        }
Example #17
0
        public void ValidDNSRecord()
        {
            DNSRecord dnsRecord = new DNSRecord
            {
                Name = "validate",
                TTL  = 1800,
                Type = DNSRecordType.A
            };

            IValidator <DNSRecord> validator        = new DigitalOceanDNSRecordValidator();
            ValidationResult       validationResult = validator.Validate(dnsRecord);

            Assert.True(validationResult.IsValid);
        }
Example #18
0
        public void Validate_ValidDNSRecord_ReturnsIsValid()
        {
            DNSRecord dnsRecord = new DNSRecord
            {
                Name = "Valid",
                TTL  = 1800,
                Type = DNSRecordType.A
            };

            IValidator <DNSRecord> validator        = new GoDaddyDNSRecordValidator();
            ValidationResult       validationResult = validator.Validate(dnsRecord);

            Assert.True(validationResult.IsValid);
        }
Example #19
0
        public void TestAuthorityWhenPTRIsKnownV6()
        {
            // We should be an authority for a PTR record that we know about
            var zone = new DNSZone(start_of_authority, relays);
            var ptr  = new DNSRecord(
                new Domain("b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.ip6.arpa"),
                AddressClass.INTERNET,
                42,
                new PTRResource(new Domain("www.example.com")));

            zone.Add(ptr);

            Assert.That(zone.IsAuthorityFor(new Domain("b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.ip6.arpa")), Is.True);
        }
Example #20
0
        public void TestAuthorityWithDelegation()
        {
            // Ensures that we're not an authority for things that are subzones
            var zone    = new DNSZone(start_of_authority, relays);
            var subzone = new DNSRecord(
                new Domain("foo.example.com"),
                AddressClass.INTERNET,
                42,
                new NSResource(new Domain("ns.foo.example.com")));

            zone.Add(subzone);

            Assert.That(zone.IsAuthorityFor(new Domain("www.foo.example.com")), Is.False);
        }
Example #21
0
        public void TestStubResolverAcceptsSOARecords()
        {
            // The same as the previous test, but this makes sure that less common
            // record types are still recognized as answers for the appropriate queries
            var relay = new IPEndPoint(IPAddress.Parse("192.168.0.1"), 53);

            var expected_question = new DNSQuestion(
                new Domain("example.com"),
                ResourceRecordType.START_OF_AUTHORITY,
                AddressClass.INTERNET);

            var expected_answer = new DNSRecord(
                new Domain("example.com"), AddressClass.INTERNET, 42,
                new SOAResource(
                    new Domain("ns.example.com"),
                    new Domain("hostmaster.example.com"),
                    0,
                    360,
                    360,
                    360,
                    360));

            var expected_packet = new DNSPacket(
                42, false, QueryType.STANDARD_QUERY, false, false, true, true, ResponseType.NO_ERROR,
                new DNSQuestion[] { expected_question }, new DNSRecord[] { expected_answer }, new DNSRecord[0], new DNSRecord[0]);


            Func <EndPoint, DNSQuestion, bool, DNSPacket> gives_direct_answers = (target, question, is_recursive) =>
            {
                Assert.That(target, Is.EqualTo(relay));
                Assert.That(question, Is.EqualTo(expected_question));
                return(expected_packet);
            };

            var resolver = new StubResolver(new NoopCache(), gives_direct_answers);
            var result   = resolver.Resolve(new Domain("example.com"),
                                            ResourceRecordType.START_OF_AUTHORITY,
                                            AddressClass.INTERNET,
                                            new EndPoint[] { relay });

            var expected_result = new ResolverResult();

            expected_result.answers             = new DNSRecord[] { expected_answer };
            expected_result.aliases             = new DNSRecord[0];
            expected_result.referrals           = new DNSRecord[0];
            expected_result.referral_additional = new DNSRecord[0];

            Assert.That(result, Is.EqualTo(expected_result));
        }
Example #22
0
        public async void Update(string[] AddedHosts, string[] RemovedHosts)
        {
            string PublicIP = await Ext.GetPublicIP();

            if (string.IsNullOrEmpty(PublicIP))
            {
                return;
            }

            IEnumerable <Zone> Zones = (await APIClient.List <Zone>())
                                       .Items
                                       .Where(x => AddedHosts.Any(h => h.EndsWith(x.Name)) || RemovedHosts.Any(h => h.EndsWith(x.Name)));

            foreach (Zone Zone in Zones)
            {
                List <DNSRecord> OldRecords = (await APIClient.List <DNSRecord>(Zone.Id))
                                              .Items
                                              .Where(x => x.Type == "A" && (
                                                         AddedHosts.Any(x2 => x2.StartsWith(x.Name)) ||
                                                         RemovedHosts.Any(x2 => x2.StartsWith(x.Name))
                                                         ))
                                              .ToList();

                int ZoneNameLen = Zone.Name.Length;
                foreach (string Host in AddedHosts)
                {
                    DNSRecord ActiveRecord = OldRecords.Where(x => Host.StartsWith(x.Name)).FirstOrDefault();
                    if (ActiveRecord == null)
                    {
                        await APIClient.Create(
                            new DNSRecord()
                        {
                            Type = "A", Name = Host.Substring(0, Host.Length - ZoneNameLen - 1), Content = PublicIP
                        }
                            , DryRun, Zone.Id
                            );
                    }
                    else
                    {
                        OldRecords.Remove(ActiveRecord);
                    }
                }

                foreach (DNSRecord OldRecord in OldRecords)
                {
                    await APIClient.Delete <DNSRecord>(DryRun, OldRecord, OldRecord.ZoneId, OldRecord.Id);
                }
            }
        }
Example #23
0
        public void TestSubzoneWithDelegation()
        {
            // Ensure that we can find the subzone for a domain in that subzone
            var zone    = new DNSZone(start_of_authority, relays);
            var subzone = new DNSRecord(
                new Domain("foo.example.com"),
                AddressClass.INTERNET,
                42,
                new NSResource(new Domain("ns.foo.example.com")));

            zone.Add(subzone);

            Assert.That(zone.FindSubZone(new Domain("www.foo.example.com")),
                        Is.EqualTo(new Domain("foo.example.com")));
        }
Example #24
0
        public void TestAuthorityWhenEqualToDelegation()
        {
            // Ensure that we are an authority for the subzone's address itself (which can
            // occur if, say, there's a CNAME pointing to it)
            var zone    = new DNSZone(start_of_authority, relays);
            var subzone = new DNSRecord(
                new Domain("foo.example.com"),
                AddressClass.INTERNET,
                42,
                new NSResource(new Domain("ns.foo.example.com")));

            zone.Add(subzone);

            Assert.That(zone.IsAuthorityFor(new Domain("foo.example.com")), Is.True);
        }
Example #25
0
        public void TestStubResolverReturnsRedirectionsWithAAAAResourceGlue()
        {
            // Make sure that any redirections are returned, even if there aren't any actual
            // results, along with their glue if provided
            var relay = new IPEndPoint(IPAddress.Parse("192.168.0.1"), 53);

            var expected_question = new DNSQuestion(
                new Domain("example.com"),
                ResourceRecordType.HOST_ADDRESS,
                AddressClass.INTERNET);

            var expected_ns_answer = new DNSRecord(
                new Domain("example.com"), AddressClass.INTERNET, 42,
                new NSResource(new Domain("ns.example.com")));

            var expected_glue_answer = new DNSRecord(
                new Domain("ns.example.com"), AddressClass.INTERNET, 42,
                new AAAAResource(IPv6Address.Parse("2001:cafe:beef::")));

            var expected_packet = new DNSPacket(
                42, false, QueryType.STANDARD_QUERY, false, false, true, true, ResponseType.NO_ERROR,
                new DNSQuestion[] { expected_question }, new DNSRecord[0], new DNSRecord[] { expected_ns_answer },
                new DNSRecord[] { expected_glue_answer });


            Func <EndPoint, DNSQuestion, bool, DNSPacket> gives_direct_answers = (target, question, is_recursive) =>
            {
                Assert.That(target, Is.EqualTo(relay));
                Assert.That(question, Is.EqualTo(expected_question));
                return(expected_packet);
            };

            var resolver = new StubResolver(new NoopCache(), gives_direct_answers);
            var result   = resolver.Resolve(new Domain("example.com"),
                                            ResourceRecordType.HOST_ADDRESS,
                                            AddressClass.INTERNET,
                                            new EndPoint[] { relay });

            var expected_result = new ResolverResult();

            expected_result.answers             = new DNSRecord[0];
            expected_result.aliases             = new DNSRecord[0];
            expected_result.referrals           = new DNSRecord[] { expected_ns_answer };
            expected_result.referral_additional = new DNSRecord[] { expected_glue_answer };

            Assert.That(result, Is.EqualTo(expected_result));
        }
Example #26
0
        public void TestStubResolverSequenceOfRelays()
        {
            // Make sure that the resolver ignores failing resolvers, as long as at least one succeeds
            var good_relay = new IPEndPoint(IPAddress.Parse("192.168.0.1"), 53);
            var bad_relay  = new IPEndPoint(IPAddress.Parse("192.168.0.2"), 53);

            var expected_question = new DNSQuestion(
                new Domain("example.com"),
                ResourceRecordType.HOST_ADDRESS,
                AddressClass.INTERNET);

            var expected_answer = new DNSRecord(
                new Domain("example.com"), AddressClass.INTERNET, 42,
                new AResource(IPv4Address.Parse("192.168.0.1")));

            var expected_packet = new DNSPacket(
                42, false, QueryType.STANDARD_QUERY, false, false, true, true, ResponseType.NO_ERROR,
                new DNSQuestion[] { expected_question }, new DNSRecord[] { expected_answer }, new DNSRecord[0], new DNSRecord[0]);

            Func <EndPoint, DNSQuestion, bool, DNSPacket> gives_direct_answers = (target, question, is_recursive) =>
            {
                if (target.Equals(bad_relay))
                {
                    throw new SocketException();
                }

                Assert.That(target, Is.EqualTo(good_relay));
                Assert.That(question, Is.EqualTo(expected_question));
                return(expected_packet);
            };

            var resolver = new StubResolver(new NoopCache(), gives_direct_answers);
            var result   = resolver.Resolve(new Domain("example.com"),
                                            ResourceRecordType.HOST_ADDRESS,
                                            AddressClass.INTERNET,
                                            new EndPoint[] { bad_relay, good_relay });

            var expected_result = new ResolverResult();

            expected_result.answers             = new DNSRecord[] { expected_answer };
            expected_result.aliases             = new DNSRecord[0];
            expected_result.referrals           = new DNSRecord[0];
            expected_result.referral_additional = new DNSRecord[0];

            Assert.That(result, Is.EqualTo(expected_result));
        }
Example #27
0
        public void TestStubResolverRejectsIrrelevantGlue()
        {
            // Make sure that any redirections are returned, but rejects any bad glue
            var relay = new IPEndPoint(IPAddress.Parse("192.168.0.1"), 53);

            var expected_question = new DNSQuestion(
                new Domain("example.com"),
                ResourceRecordType.HOST_ADDRESS,
                AddressClass.INTERNET);

            var expected_ns_answer = new DNSRecord(
                new Domain("example.com"), AddressClass.INTERNET, 42,
                new NSResource(new Domain("ns.example.com")));

            var unexpected_glue_answer = new DNSRecord(
                new Domain("ns2.example.com"), AddressClass.INTERNET, 42,
                new AResource(IPv4Address.Parse("192.168.0.2")));

            var expected_packet = new DNSPacket(
                42, false, QueryType.STANDARD_QUERY, false, false, true, true, ResponseType.NO_ERROR,
                new DNSQuestion[] { expected_question }, new DNSRecord[0], new DNSRecord[] { expected_ns_answer },
                new DNSRecord[] { unexpected_glue_answer });


            Func <EndPoint, DNSQuestion, bool, DNSPacket> gives_direct_answers = (target, question, is_recursive) =>
            {
                Assert.That(target, Is.EqualTo(relay));
                Assert.That(question, Is.EqualTo(expected_question));
                return(expected_packet);
            };

            var resolver = new StubResolver(new NoopCache(), gives_direct_answers);
            var result   = resolver.Resolve(new Domain("example.com"),
                                            ResourceRecordType.HOST_ADDRESS,
                                            AddressClass.INTERNET,
                                            new EndPoint[] { relay });

            var expected_result = new ResolverResult();

            expected_result.answers             = new DNSRecord[0];
            expected_result.aliases             = new DNSRecord[0];
            expected_result.referrals           = new DNSRecord[] { expected_ns_answer };
            expected_result.referral_additional = new DNSRecord[0];

            Assert.That(result, Is.EqualTo(expected_result));
        }
Example #28
0
        private void toolStripButtonDelete_Click(object sender, EventArgs e)
        {
            if (this.dataGridView.SelectedRows.Count == 1 && !this.DeleteRecord.IsBusy)
            {
                DNSRecord record = (DNSRecord)this.dataGridView.SelectedRows[0].DataBoundItem;

                if (!record.editable)
                {
                    MessageBox.Show("This record is not editable", "Dreamhost DNS Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (MessageBox.Show("Are you sure you want to delete the record for " + record.record + "?", "Dreamhost DNS Manager", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    this.toolStripStatusLabel.Text = "Deleting record...";
                    this.DeleteRecord.RunWorkerAsync(record);
                }
            }
        }
Example #29
0
        public AddEdit(DreamhostAPI API, DNSRecord Record)
            : this(API)
        {
            this.IsEdit = true;
            this.Record = Record;

            this.Text = "Edit Record";
            this.textBoxRecord.Text    = this.Record.record;
            this.textBoxComment.Text   = this.Record.comment;
            this.textBoxValue.Text     = this.Record.value;
            this.comboBoxType.Text     = this.Record.type;
            this.textBoxRecord.Enabled = false;
            this.comboBoxType.Enabled  = false;

            this.EditRecord.DoWork             += new DoWorkEventHandler(EditRecord_DoWork);
            this.EditRecord.RunWorkerCompleted += new RunWorkerCompletedEventHandler(EditRecord_RunWorkerCompleted);
        }
Example #30
0
        public void TestQuery()
        {
            var zone         = new DNSZone(start_of_authority, relays);
            var www_a_record = new DNSRecord(
                new Domain("www.example.com"),
                AddressClass.INTERNET,
                42,
                new AResource(IPv4Address.Parse("192.168.0.1")));

            var www_a_record_2 = new DNSRecord(
                new Domain("www.example.com"),
                AddressClass.INTERNET,
                42,
                new AResource(IPv4Address.Parse("192.168.0.2")));

            // Something that matches the class and record type, but not the domain
            var www2_a_record = new DNSRecord(
                new Domain("www2.example.com"),
                AddressClass.INTERNET,
                42,
                new AResource(IPv4Address.Parse("192.168.0.3")));

            // Something that matches the domain and class, but not the record type
            var www_cname_record = new DNSRecord(
                new Domain("www.example.com"),
                AddressClass.INTERNET,
                42,
                new CNAMEResource(new Domain("www2.example.com")));

            zone.Add(www_a_record);
            zone.Add(www_a_record_2);
            zone.Add(www2_a_record);
            zone.Add(www_cname_record);

            var query_result = zone.Query(
                new Domain("www.example.com"),
                ResourceRecordType.HOST_ADDRESS,
                AddressClass.INTERNET);

            var expected = new List <DNSRecord>();

            expected.Add(www_a_record);
            expected.Add(www_a_record_2);
            Assert.That(query_result, Is.EquivalentTo(expected));
        }
 /// <summary>
 /// Create a new DNS host record
 /// </summary>
 /// <param name="record">The record to create</param>
 public void CreateDNSRecord(DNSRecord record)
 {
     _server.CreateDNSRecord(_name, record.ToString());
 }
Example #32
0
 protected DnsRecord ConvertToNative(DNSRecord record, string zoneName)
 {
     string recordName = ConvertRecordNameToInternalFormat(record.Name, zoneName);
     //
     DnsRecord dnsRecord = null;
     switch (record.Type)
     {
         case "A":
             dnsRecord = new DnsRecord
             {
                 RecordName = recordName,
                 RecordType = DnsRecordType.A,
                 RecordData = record.DataFields[0]
             };
             break;
         case "AAAA":
             dnsRecord = new DnsRecord
             {
                 RecordName = recordName,
                 RecordType = DnsRecordType.AAAA,
                 RecordData = record.DataFields[0]
             };
             break;
         case "NS":
             dnsRecord = new DnsRecord
             {
                 RecordName = recordName,
                 RecordType = DnsRecordType.NS,
                 RecordData = record.DataFields[0]
             };
             break;
         case "CNAME":
             dnsRecord = new DnsRecord
             {
                 RecordName = recordName,
                 RecordType = DnsRecordType.CNAME,
                 RecordData = record.DataFields[0]
             };
             break;
         case "MX":
             dnsRecord = new DnsRecord
             {
                 RecordName = recordName,
                 RecordType = DnsRecordType.MX,
                 MxPriority = Convert.ToInt32(record.DataFields[MX_RECORD_PRIORITY]),
                 RecordData = record.DataFields[MX_RECORD_NAMESERVER]
             };
             break;
         case "TXT":
             dnsRecord = new DnsRecord
             {
                 RecordName = recordName,
                 RecordType = DnsRecordType.TXT,
                 RecordData = record.DataFields[0]
             };
             break;
         case "SRV":
             dnsRecord = new DnsRecord
             {
                 RecordName = recordName,
                 RecordType = DnsRecordType.SRV,
                 RecordData = record.DataFields[3],
                 SrvPriority = Convert.ToInt32(record.DataFields[0]),
                 SrvWeight = Convert.ToInt32(record.DataFields[1]),
                 SrvPort = Convert.ToInt32(record.DataFields[2])
             };
             break;
     }
     //
     return dnsRecord;
 }
 /// <summary>
 /// Create a new DNS host record
 /// </summary>
 /// <param name="zone"></param>
 /// <param name="record"></param>
 public void CreateDNSRecord(string zone, DNSRecord record)
 {
     CreateDNSRecord(zone, record.ToString());
 }