Exemple #1
0
 /// <remarks/>
 public void DeleteZoneRecordAsync(string zoneName, DnsRecord record, object userState)
 {
     if ((this.DeleteZoneRecordOperationCompleted == null))
     {
         this.DeleteZoneRecordOperationCompleted = new System.Threading.SendOrPostCallback(this.OnDeleteZoneRecordOperationCompleted);
     }
     this.InvokeAsync("DeleteZoneRecord", new object[] {
         zoneName,
         record
     }, this.DeleteZoneRecordOperationCompleted, userState);
 }
Exemple #2
0
        public override void AddZoneRecord(string zoneName, DnsRecord record)
        {
            try
            {
                string name = record.RecordName;
                if (String.IsNullOrEmpty(name))
                {
                    name = ".";
                }

                if (record.RecordType == DnsRecordType.A)
                {
                    ps.Add_DnsServerResourceRecordA(zoneName, name, record.RecordData);
                }
                else if (record.RecordType == DnsRecordType.AAAA)
                {
                    ps.Add_DnsServerResourceRecordAAAA(zoneName, name, record.RecordData);
                }
                else if (record.RecordType == DnsRecordType.CNAME)
                {
                    ps.Add_DnsServerResourceRecordCName(zoneName, name, record.RecordData);
                }
                else if (record.RecordType == DnsRecordType.MX)
                {
                    ps.Add_DnsServerResourceRecordMX(zoneName, name, record.RecordData, (ushort)record.MxPriority);
                }
                else if (record.RecordType == DnsRecordType.NS)
                {
                    ps.Add_DnsServerResourceRecordNS(zoneName, name, record.RecordData);
                }
                else if (record.RecordType == DnsRecordType.TXT)
                {
                    ps.Add_DnsServerResourceRecordTXT(zoneName, name, record.RecordData);
                }
                else if (record.RecordType == DnsRecordType.SRV)
                {
                    ps.Add_DnsServerResourceRecordSRV(zoneName, name, record.RecordData, (ushort)record.SrvPort, (ushort)record.SrvPriority, (ushort)record.SrvWeight);
                }
                else if (record.RecordType == DnsRecordType.CAA)
                {
                    ps.Add_DnsServerResourceRecordCAA(zoneName, name, record.RecordData);
                }
                else
                {
                    throw new Exception("Unknown record type");
                }
            }
            catch (Exception ex)
            {
                // log exception
                Log.WriteError(ex);
            }
        }
Exemple #3
0
        private static DomainRecord ConvertToDomainRecord(DnsRecord dnsRecord, string zoneName)
        {
            DomainRecord domainRecord = new DomainRecord();

            domainRecord.Data       = dnsRecord.RecordData;
            domainRecord.DomainName = zoneName;
            domainRecord.Priority   = dnsRecord.MxPriority;
            domainRecord.RecordType = dnsRecord.RecordType.ToString();
            domainRecord.HostName   = dnsRecord.RecordName;

            return(domainRecord);
        }
Exemple #4
0
 public virtual void DeleteZoneRecord(string zoneName, DnsRecord record)
 {
     try
     {
         string rrType;
         if (!RecordTypes.rrTypeFromRecord.TryGetValue(record.RecordType, out rrType))
         {
             throw new Exception("Unknown record type");
         }
         ps.Remove_DnsServerResourceRecord(zoneName, record);
     }
     catch (Exception ex)
     {
         // log exception
         Log.WriteError(ex);
     }
 }
Exemple #5
0
        public virtual void DeleteZoneRecord(string zoneName, DnsRecord record)
        {
            try
            {
                if (record.RecordType == DnsRecordType.A || record.RecordType == DnsRecordType.AAAA || record.RecordType == DnsRecordType.CNAME)
                {
                    record.RecordName = CorrectRecordName(zoneName, record.RecordName);
                }

                // delete record
                DeleteRecord(zoneName, record.RecordType, record.RecordName, record.RecordData);
            }
            catch (Exception ex)
            {
                // log exception
                Log.WriteError(ex);
            }
        }
Exemple #6
0
 public virtual void AddZoneRecord(string zoneName, DnsRecord record)
 {
     try
     {
         if (record.RecordType == DnsRecordType.A)
         {
             AddARecord(zoneName, record.RecordName, record.RecordData);
         }
         else if (record.RecordType == DnsRecordType.AAAA)
         {
             AddAAAARecord(zoneName, record.RecordName, record.RecordData);
         }
         else if (record.RecordType == DnsRecordType.CNAME)
         {
             AddCNameRecord(zoneName, record.RecordName, record.RecordData);
         }
         else if (record.RecordType == DnsRecordType.MX)
         {
             AddMXRecord(zoneName, record.RecordName, record.RecordData, record.MxPriority);
         }
         else if (record.RecordType == DnsRecordType.NS)
         {
             AddNsRecord(zoneName, record.RecordName, record.RecordData);
         }
         else if (record.RecordType == DnsRecordType.TXT)
         {
             AddTxtRecord(zoneName, record.RecordName, record.RecordData);
         }
     }
     catch (Exception ex)
     {
         // log exception
         Log.WriteError(
             String.Format(
                 "Simple DNS: Unable to create record (Name '{0}', Data '{1}', Text '{2}') to zone '{3}'"
                 , record.RecordName
                 , record.RecordData
                 , record.RecordText
                 , zoneName
                 )
             , ex
             );
     }
 }
Exemple #7
0
        public void AddZoneRecord(string zoneName, DnsRecord record)
        {
            if (string.IsNullOrEmpty(zoneName))
            {
                throw new ArgumentNullException("zoneName");
            }

            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            DomainRecord rec = ConvertToDomainRecord(record, zoneName);
            DnsResult    res = proxy.AddRecord(Login, Password, rec);

            if (res.Status != Success)
            {
                throw new Exception(string.Format("Could not add zone record. Error code {0}. {1}", res.Status, res.Description));
            }
        }
Exemple #8
0
        private static DnsRecord ConvertToDnsRecord(DomainRecord record)
        {
            DnsRecord dnsRecord = new DnsRecord();

            dnsRecord.RecordName = record.HostName;
            dnsRecord.MxPriority = record.Priority;
            dnsRecord.RecordData = record.Data;

            switch (record.RecordType)
            {
            case "A":
                dnsRecord.RecordType = DnsRecordType.A;
                break;

            case "AAAA":
                dnsRecord.RecordType = DnsRecordType.AAAA;
                break;

            case "MX":
                dnsRecord.RecordType = DnsRecordType.MX;
                break;

            case "CNAME":
                dnsRecord.RecordType = DnsRecordType.CNAME;
                break;

            case "NS":
                dnsRecord.RecordType = DnsRecordType.NS;
                break;

            case "SOA":
                dnsRecord.RecordType = DnsRecordType.SOA;
                break;

            case "TXT":
                dnsRecord.RecordType = DnsRecordType.TXT;
                break;
            }

            return(dnsRecord);
        }
Exemple #9
0
 public override void DeleteZoneRecord(string zoneName, DnsRecord record)
 {
     if (ZoneExists(zoneName))
     {
         string m_strRecordName = ConvertRecordNameToSDNSFormat(record.RecordName, zoneName);
         //
         Connection cn      = SetupProviderConnection();
         DNSZone    dnsZone = cn.GetZone(zoneName);
         //
         List <string> m_strRecordData = new List <string>();
         String        m_strRecordType = String.Empty;
         // build record data
         SupportedDnsRecords[record.RecordType](zoneName, ref m_strRecordType, record, m_strRecordData);
         //
         dnsZone.Records.Remove(m_strRecordName, m_strRecordType, m_strRecordData.ToArray());
         //
         cn.UpdateZone(dnsZone, false);
         //
         UpdateSoaRecord(zoneName);
     }
 }
Exemple #10
0
        protected void PDNSDeleteZoneRecord(string zoneName, DnsRecord record, bool isNeedToUpdateSOA)
        {
            string recordName = zoneName;

            if (!String.IsNullOrEmpty(record.RecordName))
            {
                recordName = string.Format("{0}.{1}", record.RecordName, recordName);
            }

            RemoveRecord(
                recordName
                , ConvertDnsRecordTypeToString(record.RecordType)
                , record.RecordData
                , record.MxPriority
                );

            if (isNeedToUpdateSOA)
            {
                PDNSUpdateSoaRecord(zoneName);
            }
        }
Exemple #11
0
        public void DeleteZoneRecord(string zoneName, DnsRecord record)
        {
            //Null checking
            if (string.IsNullOrWhiteSpace(zoneName))
            {
                throw new ArgumentNullException(nameof(zoneName));
            }
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            //Declare content to be patched
            var content = new List <ZoneRecordsDeleteRequest>
            {
                //Convert record into delete request
                new ZoneRecordsDeleteRequest(record.ToZoneRecordsResponse(MinimumTTL, zoneName))
            };

            //Call API to PATCH record
            ApiPatch($"zones/{zoneName}/records", content.ToJson());
        }
Exemple #12
0
 public virtual void AddZoneRecord(string zoneName, DnsRecord record)
 {
     try
     {
         if (record.RecordType == DnsRecordType.A)
         {
             AddARecord(zoneName, record.RecordName, record.RecordData);
         }
         else if (record.RecordType == DnsRecordType.AAAA)
         {
             AddAAAARecord(zoneName, record.RecordName, record.RecordData);
         }
         else if (record.RecordType == DnsRecordType.CNAME)
         {
             AddCNameRecord(zoneName, record.RecordName, record.RecordData);
         }
         else if (record.RecordType == DnsRecordType.MX)
         {
             AddMXRecord(zoneName, record.RecordName, record.RecordData, record.MxPriority);
         }
         else if (record.RecordType == DnsRecordType.NS)
         {
             AddNsRecord(zoneName, record.RecordName, record.RecordData);
         }
         else if (record.RecordType == DnsRecordType.TXT)
         {
             AddTxtRecord(zoneName, record.RecordName, record.RecordData);
         }
         else if (record.RecordType == DnsRecordType.SRV)
         {
             AddSrvRecord(zoneName, record.RecordName, record.RecordData, record.SrvPriority, record.SrvWeight, record.SrvPort);
         }
     }
     catch (Exception ex)
     {
         // log exception
         Log.WriteError(ex);
     }
 }
Exemple #13
0
 public virtual void DeleteZoneRecord(string zoneName, DnsRecord record)
 {
     try
     {
         if (record.RecordType == DnsRecordType.A)
         {
             DeleteARecord(zoneName, record.RecordName, record.RecordData);
         }
         else if (record.RecordType == DnsRecordType.AAAA)
         {
             DeleteAAAARecord(zoneName, record.RecordName, record.RecordData);
         }
         else if (record.RecordType == DnsRecordType.CNAME)
         {
             DeleteCNameRecord(zoneName, record.RecordName, record.RecordData);
         }
         else if (record.RecordType == DnsRecordType.MX)
         {
             DeleteMXRecord(zoneName, record.RecordName, record.RecordData);
         }
         else if (record.RecordType == DnsRecordType.NS)
         {
             DeleteNsRecord(zoneName, record.RecordName, record.RecordData);
         }
         else if (record.RecordType == DnsRecordType.TXT)
         {
             DeleteTxtRecord(zoneName, record.RecordName, record.RecordData);
         }
         else if (record.RecordType == DnsRecordType.SRV)
         {
             DeleteSrvRecord(zoneName, record.RecordName, record.RecordData);
         }
     }
     catch (Exception ex)
     {
         // log exception
         Log.WriteError(ex);
     }
 }
Exemple #14
0
        public override DnsRecord[] GetZoneRecords(string zoneName)
        {
            List <DnsRecord> dnsRecords = new List <DnsRecord>();

            if (ZoneExists(zoneName))
            {
                Connection cn = SetupProviderConnection();
                //
                DNSZone dnsZone = cn.GetZone(zoneName);
                //
                foreach (DNSRecord record in dnsZone.Records)
                {
                    DnsRecord zoneRecord = ConvertToNative(record, zoneName);
                    if (zoneRecord != null && zoneRecord.RecordType != DnsRecordType.SOA &&
                        zoneRecord.RecordType != DnsRecordType.Other)
                    {
                        dnsRecords.Add(zoneRecord);
                    }
                }
            }

            return(dnsRecords.ToArray());
        }
Exemple #15
0
        public DnsRecord[] GetZoneRecords(string zoneName)
        {
            if (string.IsNullOrEmpty(zoneName))
            {
                throw new ArgumentNullException("zoneName");
            }

            DomainResult res = proxy.ListDomain(Login, Password, zoneName);

            if (res.Result.Status != Success)
            {
                throw new Exception(string.Format("Could not get zone records. Error code {0}. {1}", res.Result.Status, res.Result.Description));
            }

            List <DnsRecord> retRecords = new List <DnsRecord>(res.Record.Length);

            foreach (DomainRecord record in res.Record)
            {
                DnsRecord tempRecord = ConvertToDnsRecord(record);
                retRecords.Add(tempRecord);
            }
            return(retRecords.ToArray());
        }
Exemple #16
0
        public virtual void AddPrimaryZone(string zoneName, string[] secondaryServers)
        {
            // CREATE PRIMARY DNS ZONE
            List <DnsRecord> records = new List <DnsRecord>();

            // add "Zone transfers" record
            if (secondaryServers != null && secondaryServers.Length != 0)
            {
                DnsRecord zt = new DnsRecord();
                zt.RecordType = DnsRecordType.Other;
                zt.RecordName = "";
                if (secondaryServers.Length == 1 &&
                    secondaryServers[0] == "*")
                {
                    zt.RecordText = ";$AllowZT *";
                }
                else
                {
                    zt.RecordText = ";$AllowZT " + String.Join(" ", secondaryServers);
                }

                records.Add(zt);
            }

            // add SOA record
            DnsSOARecord soa = new DnsSOARecord();

            soa.RecordType      = DnsRecordType.SOA;
            soa.RecordName      = "";
            soa.PrimaryNsServer = System.Net.Dns.GetHostEntry("LocalHost").HostName;
            soa.PrimaryPerson   = "hostmaster";          //"hostmaster." + zoneName;
            records.Add(soa);

            // add DNS zone
            UpdateZone(zoneName, records);
        }
Exemple #17
0
        public void AddZoneRecord(string zoneName, DnsRecord record)
        {
            //Null checking
            if (string.IsNullOrWhiteSpace(zoneName))
            {
                throw new ArgumentNullException(nameof(zoneName));
            }
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            //Declare content to be Patched
            var content = new List <ZoneRecordsResponse>
            {
                //Add DnsRecord to it
                record.ToZoneRecordsResponse(MinimumTTL, zoneName)
            };

            Log.WriteInfo("AddZoneRecord content: {0}", content.ToJson());

            //Call API to PATCH record
            ApiPatch($"zones/{zoneName}/records", content.ToJson());
        }
Exemple #18
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);
        }
Exemple #19
0
        private List <DnsRecord> ParseZoneFileToArrayList(string zoneName, string zf)
        {
            List <DnsRecord> records = new List <DnsRecord>();
            StringReader     reader  = new StringReader(zf);
            string           zfLine  = null;

            DnsSOARecord soa = null;

            while ((zfLine = reader.ReadLine()) != null)
            {
                //string line = Regex.Replace(zfLine, "\\s+", " ").Trim();

                string[] columns = zfLine.Split('\t');

                string recordName  = "";
                string recordTTL   = "";
                string recordType  = "";
                string recordData  = "";
                string recordData2 = "";

                recordName = columns[0];
                if (columns.Length > 1)
                {
                    recordTTL = columns[1];
                }
                if (columns.Length > 2)
                {
                    recordType = columns[2];
                }
                if (columns.Length > 3)
                {
                    recordData = columns[3];
                }
                if (columns.Length > 4)
                {
                    recordData2 = columns[4].Trim();
                }

                if (recordType == "IN SOA")
                {
                    string[] dataColumns = recordData.Split(' ');

                    // parse SOA record
                    soa                 = new DnsSOARecord();
                    soa.RecordType      = DnsRecordType.SOA;
                    soa.RecordName      = "";
                    soa.PrimaryNsServer = RemoveTrailingDot(dataColumns[0]);
                    soa.PrimaryPerson   = RemoveTrailingDot(dataColumns[1]);
                    soa.RecordText      = zfLine;
                    if (dataColumns[2] != "(")
                    {
                        soa.SerialNumber = dataColumns[2];
                    }

                    // add to the collection
                    records.Add(soa);
                }
                else if (recordData2.IndexOf("; Serial number") != -1)
                {
                    string[] dataColumns = recordData2.Split(' ');

                    // append soa serial number
                    soa.SerialNumber = dataColumns[0];
                }
                else if (recordType == "NS")                 // NS record with empty host
                {
                    DnsRecord r = new DnsRecord();
                    r.RecordType = DnsRecordType.NS;
                    r.RecordName = CorrectRecordName(zoneName, recordName);
                    r.RecordData = CorrectRecordData(zoneName, recordData);
                    r.RecordText = zfLine;
                    records.Add(r);
                }
                else if (recordType == "A")                 // A record
                {
                    DnsRecord r = new DnsRecord();
                    r.RecordType = DnsRecordType.A;
                    r.RecordName = CorrectRecordName(zoneName, recordName);
                    r.RecordData = recordData;
                    r.RecordText = zfLine;
                    records.Add(r);
                }
                else if (recordType == "AAAA")                 // A record
                {
                    DnsRecord r = new DnsRecord();
                    r.RecordType = DnsRecordType.AAAA;
                    r.RecordName = CorrectRecordName(zoneName, recordName);
                    r.RecordData = recordData;
                    r.RecordText = zfLine;
                    records.Add(r);
                }
                else if (recordType == "CNAME")                 // CNAME record
                {
                    DnsRecord r = new DnsRecord();
                    r.RecordType = DnsRecordType.CNAME;
                    r.RecordName = CorrectRecordName(zoneName, recordName);
                    r.RecordData = CorrectRecordData(zoneName, recordData);
                    r.RecordText = zfLine;
                    records.Add(r);
                }
                else if (recordType == "MX")                 // MX record
                {
                    string[] dataColumns = recordData.Split(' ');

                    DnsRecord r = new DnsRecord();
                    r.RecordType = DnsRecordType.MX;
                    r.RecordName = CorrectRecordName(zoneName, recordName);
                    r.MxPriority = Int32.Parse(dataColumns[0]);
                    r.RecordData = CorrectRecordData(zoneName, dataColumns[1]);
                    r.RecordText = zfLine;
                    records.Add(r);
                }
                else if (recordType == "TXT")                 // TXT record
                {
                    DnsRecord r = new DnsRecord();
                    r.RecordType = DnsRecordType.TXT;
                    r.RecordName = CorrectRecordName(zoneName, recordName);
                    r.RecordData = recordData.Substring(1, recordData.Length - 2);
                    r.RecordText = zfLine;
                    records.Add(r);
                }
                else if (recordType == "SRV")                 // SRV record
                {
                    string[] dataColumns = recordData.Split(' ');

                    DnsRecord r = new DnsRecord();
                    r.RecordType  = DnsRecordType.SRV;
                    r.RecordName  = CorrectRecordName(zoneName, recordName);
                    r.SrvPriority = Int32.Parse(dataColumns[0]);
                    r.SrvWeight   = Int32.Parse(dataColumns[1]);
                    r.SrvPort     = Int32.Parse(dataColumns[2]);
                    r.RecordData  = CorrectRecordData(zoneName, dataColumns[3]);
                    r.RecordText  = zfLine;
                    records.Add(r);
                }

                //Debug.WriteLine(zfLine);
            }
            return(records);
        }
Exemple #20
0
 /// <remarks/>
 public void AddZoneRecordAsync(string zoneName, DnsRecord record)
 {
     this.AddZoneRecordAsync(zoneName, record, null);
 }
Exemple #21
0
 /// <summary>
 /// Adds zone record into Power DNS database
 /// </summary>
 /// <param name="zoneName">Domain name in Power DNS database.</param>
 /// <param name="record">Record in Power DNS database</param>
 public void AddZoneRecord(string zoneName, DnsRecord record)
 {
     PDNSAddZoneRecord(zoneName, record, true);
 }
Exemple #22
0
 /// <summary>
 /// Delete zone record from Power DNS database.
 /// </summary>
 /// <param name="zoneName">Domain name from Power DNS database</param>
 /// <param name="record">Record from Power DNS database</param>
 public void DeleteZoneRecord(string zoneName, DnsRecord record)
 {
     PDNSDeleteZoneRecord(zoneName, record, true);
 }
Exemple #23
0
 static void BuildRecordData_TXTRecord(string zoneName, ref string type,
                                       DnsRecord record, List <string> data)
 {
     type = "TXT";
     data.Add(record.RecordData);
 }
Exemple #24
0
        /// <summary>
        /// Supports managed resources disposal
        /// </summary>
        /// <param name="zoneName"></param>
        /// <returns></returns>

        public virtual DnsRecord[] GetZoneRecords(string zoneName)
        {
            //using (ManagementObjectCollection rrs = wmi.ExecuteQuery(
            //	String.Format("SELECT * FROM MicrosoftDNS_ResourceRecord WHERE DomainName='{0}'", zoneName)))
            //ManagementObjectCollection rrs = GetWmiObjects("MicrosoftDNS_ResourceRecord", "DomainName='{0}'",zoneName);

            ManagementObjectCollection rrsA = wmi.GetWmiObjects("MicrosoftDNS_AType", "DomainName='{0}'", zoneName);

            ManagementObjectCollection rrsAAAA = wmi.GetWmiObjects("MicrosoftDNS_AAAAType", "DomainName='{0}'", zoneName);

            ManagementObjectCollection rrsCNAME = wmi.GetWmiObjects("MicrosoftDNS_CNAMEType", "DomainName='{0}'", zoneName);

            ManagementObjectCollection rrsMX = wmi.GetWmiObjects("MicrosoftDNS_MXType", "DomainName='{0}'", zoneName);

            ManagementObjectCollection rrsNS = wmi.GetWmiObjects("MicrosoftDNS_NSType", "DomainName='{0}'", zoneName);

            ManagementObjectCollection rrsTXT = wmi.GetWmiObjects("MicrosoftDNS_TXTType", "DomainName='{0}'", zoneName);

            ManagementObjectCollection rrsSRV = wmi.GetWmiObjects("MicrosoftDNS_SRVType", "DomainName='{0}'", zoneName);

            ManagementObjectCollection rrsSRV_tcp = wmi.GetWmiObjects("MicrosoftDNS_SRVType", "DomainName='_tcp.{0}'", zoneName);

            ManagementObjectCollection rrsSRV_udp = wmi.GetWmiObjects("MicrosoftDNS_SRVType", "DomainName='_udp.{0}'", zoneName);

            ManagementObjectCollection rrsSRV_tls = wmi.GetWmiObjects("MicrosoftDNS_SRVType", "DomainName='_tls.{0}'", zoneName);

            List <DnsRecord> records = new List <DnsRecord>();
            DnsRecord        record  = new DnsRecord();

            foreach (ManagementObject rr in rrsA)
            {
                record            = new DnsRecord();
                record.RecordType = DnsRecordType.A;
                record.RecordName = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.RecordData = (string)rr.Properties["RecordData"].Value;
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsAAAA)
            {
                record            = new DnsRecord();
                record.RecordType = DnsRecordType.AAAA;
                record.RecordName = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.RecordData = (string)rr.Properties["RecordData"].Value;
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsCNAME)
            {
                record            = new DnsRecord();
                record.RecordType = DnsRecordType.CNAME;
                record.RecordName = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.RecordData = RemoveTrailingDot((string)rr.Properties["RecordData"].Value);
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsMX)
            {
                record            = new DnsRecord();
                record.RecordType = DnsRecordType.MX;
                record.RecordName = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.RecordData = RemoveTrailingDot((string)rr.Properties["MailExchange"].Value);
                record.MxPriority = Convert.ToInt32(rr.Properties["Preference"].Value);
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsNS)
            {
                record            = new DnsRecord();
                record.RecordType = DnsRecordType.NS;
                record.RecordName = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.RecordData = RemoveTrailingDot((string)rr.Properties["NSHost"].Value);
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsTXT)
            {
                record            = new DnsRecord();
                record.RecordType = DnsRecordType.TXT;
                record.RecordName = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                string text = (string)rr.Properties["RecordData"].Value;
                record.RecordData = text.Substring(1, text.Length - 2);
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsSRV)
            {
                record             = new DnsRecord();
                record.RecordType  = DnsRecordType.SRV;
                record.RecordName  = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.SrvPriority = Convert.ToInt32(rr.Properties["Priority"].Value);
                record.SrvWeight   = Convert.ToInt32(rr.Properties["Weight"].Value);
                record.SrvPort     = Convert.ToInt32(rr.Properties["Port"].Value);
                record.RecordData  = RemoveTrailingDot((string)rr.Properties["SRVDomainName"].Value);
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsSRV_tcp)
            {
                record             = new DnsRecord();
                record.RecordType  = DnsRecordType.SRV;
                record.RecordName  = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.SrvPriority = Convert.ToInt32(rr.Properties["Priority"].Value);
                record.SrvWeight   = Convert.ToInt32(rr.Properties["Weight"].Value);
                record.SrvPort     = Convert.ToInt32(rr.Properties["Port"].Value);
                record.RecordData  = RemoveTrailingDot((string)rr.Properties["SRVDomainName"].Value);
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsSRV_udp)
            {
                record             = new DnsRecord();
                record.RecordType  = DnsRecordType.SRV;
                record.RecordName  = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.SrvPriority = Convert.ToInt32(rr.Properties["Priority"].Value);
                record.SrvWeight   = Convert.ToInt32(rr.Properties["Weight"].Value);
                record.SrvPort     = Convert.ToInt32(rr.Properties["Port"].Value);
                record.RecordData  = RemoveTrailingDot((string)rr.Properties["SRVDomainName"].Value);
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsSRV_tls)
            {
                record             = new DnsRecord();
                record.RecordType  = DnsRecordType.SRV;
                record.RecordName  = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.SrvPriority = Convert.ToInt32(rr.Properties["Priority"].Value);
                record.SrvWeight   = Convert.ToInt32(rr.Properties["Weight"].Value);
                record.SrvPort     = Convert.ToInt32(rr.Properties["Port"].Value);
                record.RecordData  = RemoveTrailingDot((string)rr.Properties["SRVDomainName"].Value);
                records.Add(record);
            }



            return(records.ToArray());
        }
Exemple #25
0
 /// <remarks/>
 public void DeleteZoneRecordAsync(string zoneName, DnsRecord record)
 {
     this.DeleteZoneRecordAsync(zoneName, record, null);
 }
Exemple #26
0
        //TESTED: partially
        /// <summary>
        /// The caller of this method is not waiting for SOA records. Assuming this, one should return all records except SOA.
        /// </summary>
        /// <param name="zoneName">Corresponds to the Domain name in the Power DNS domains table.</param>
        /// <returns>All DnsRecords except of SOA type.</returns>
        public DnsRecord[] GetZoneRecords(string zoneName)
        {
            List <DnsRecord> records = new List <DnsRecord>();

            try
            {
                string domainId = GetDomainId(zoneName);
                if (string.IsNullOrEmpty(domainId))
                {
                    throw new ArgumentOutOfRangeException("Power DNS zone '{0}' does not exist.");
                }

                MySqlParameter DomainId = new MySqlParameter("?DomainId", MySqlDbType.Int32);
                DomainId.Value = domainId;

                IDataReader reader = ExecuteReader(
                    "SELECT * FROM records WHERE domain_id = ?DomainId AND type != 'SOA'"
                    , DomainId
                    );

                while (reader.Read())
                {
                    DnsRecord record = new DnsRecord();

                    record.RecordData = reader["content"].ToString();
                    record.RecordName = CorrectHost(zoneName, reader["name"].ToString());
                    record.RecordType = ConvertStringToDnsRecordType(reader["type"].ToString());

                    int mxPriority = 0;
                    if (!string.IsNullOrEmpty(reader["prio"].ToString()))
                    {
                        if (Int32.TryParse(reader["prio"].ToString(), out mxPriority))
                        {
                            record.MxPriority  = mxPriority;
                            record.SrvPriority = mxPriority;
                        }
                    }
                    if (record.RecordType == DnsRecordType.SRV)
                    {
                        string[] srvparts = record.RecordData.Split(' ');
                        if (srvparts.Length == 3)
                        {
                            int SrvWeight = 0;
                            if (Int32.TryParse(srvparts[0], out SrvWeight))
                            {
                                record.SrvWeight = SrvWeight;
                            }

                            int SrvPort = 0;
                            if (Int32.TryParse(srvparts[1], out SrvPort))
                            {
                                record.SrvPort = SrvPort;
                            }
                            record.RecordData = srvparts[2];
                        }
                    }
                    records.Add(record);
                }

                reader.Close();
            }
            catch (Exception ex)
            {
                Log.WriteError(String.Format("Error getting records for '{0}' Power DNS zone", zoneName), ex);
            }

            return(records.ToArray());
        }
Exemple #27
0
        public static void Remove_DnsServerResourceRecord(this PowerShellHelper ps, string zoneName, DnsRecord record)
        {
            string type;

            if (!RecordTypes.rrTypeFromRecord.TryGetValue(record.RecordType, out type))
            {
                throw new Exception("Unknown record type");
            }

            string Name = record.RecordName;

            if (String.IsNullOrEmpty(Name))
            {
                Name = "@";
            }

            var cmd = new Command("Get-DnsServerResourceRecord");

            cmd.addParam("ZoneName", zoneName);
            cmd.addParam("Name", Name);
            cmd.addParam("RRType", type);
            Collection <PSObject> resourceRecords = ps.RunPipeline(cmd);

            object inputObject = null;

            foreach (PSObject resourceRecord in resourceRecords)
            {
                DnsRecord dnsResourceRecord = resourceRecord.asDnsRecord(zoneName);

                bool found = false;

                switch (dnsResourceRecord.RecordType)
                {
                case DnsRecordType.A:
                case DnsRecordType.AAAA:
                case DnsRecordType.CNAME:
                case DnsRecordType.NS:
                case DnsRecordType.TXT:
                    found = dnsResourceRecord.RecordData == record.RecordData;
                    break;

                case DnsRecordType.SOA:
                    found = true;
                    break;

                case DnsRecordType.MX:
                    found = (dnsResourceRecord.RecordData == record.RecordData) && (dnsResourceRecord.MxPriority == record.MxPriority);
                    break;

                case DnsRecordType.SRV:
                    found = (dnsResourceRecord.RecordData == record.RecordData) &&
                            (dnsResourceRecord.SrvPriority == record.SrvPriority) &&
                            (dnsResourceRecord.SrvWeight == record.SrvWeight) &&
                            (dnsResourceRecord.SrvPort == record.SrvPort);
                    break;
                }

                if (found)
                {
                    inputObject = resourceRecord;
                    break;
                }
            }

            cmd = new Command("Remove-DnsServerResourceRecord");
            cmd.addParam("ZoneName", zoneName);
            cmd.addParam("InputObject", inputObject);

            cmd.addParam("Force");
            ps.RunPipeline(cmd);
        }