/// <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); }
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; }
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); }
protected void PDNSAddZoneRecord(string zoneName, DnsRecord record, bool isNeedToUpdateSOA) { string domainId = GetDomainId(zoneName); if (domainId == string.Empty) { throw new ArgumentOutOfRangeException("DomainId not found. Zone does not exist."); } string recordType = ConvertDnsRecordTypeToString(record.RecordType); string ttl = GetDefaultRecordTTL(record.RecordType); //NS record if (record.RecordType == DnsRecordType.NS) { if (string.IsNullOrEmpty(record.RecordName)) { record.RecordName = zoneName; } } //widen record name for Power DNS if (!string.IsNullOrEmpty(record.RecordName)) { if (!record.RecordName.Contains(zoneName)) { record.RecordName = string.Format("{0}.{1}", record.RecordName, zoneName); } } else { record.RecordName = zoneName; } AddRecord( domainId , record.RecordName , record.RecordData , recordType , ttl , record.MxPriority.ToString() ); if (isNeedToUpdateSOA) { PDNSUpdateSoaRecord(zoneName); } }
//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; } } 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()); }
public virtual 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 { throw new Exception("Unknown record type"); } } catch (Exception ex) { // log exception Log.WriteError(ex); } }
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); } }
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); } }
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 ); } }
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)); } }
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); }
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); } }
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); } }
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.SrvPriority, record.SrvWeight, record.SrvPort, record.RecordData); } } catch (Exception ex) { // log exception Log.WriteError(ex); } }
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); } }
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()); }
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()); }
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); }
static void BuildRecordData_TXTRecord(string zoneName, ref string type, DnsRecord record, List<string> data) { type = "TXT"; data.Add(record.RecordData); }
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); }
static void BuildRecordData_MXRecord(string zoneName, ref string type, DnsRecord record, List<string> data) { type = "MX"; data.Add(record.MxPriority.ToString()); data.Add(record.RecordData); }
/// <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); }
/// <remarks/> public void DeleteZoneRecordAsync(string zoneName, DnsRecord record) { this.DeleteZoneRecordAsync(zoneName, record, null); }
public static int AddZone(int packageId, int serviceId, string zoneName, bool addPackageItem, bool ignoreGlobalDNSRecords) { // get DNS provider DNSServer dns = GetDNSServer(serviceId); // Ensure zoneName is in ascii before saving to database zoneName = GetAsciiZoneName(zoneName); // check if zone already exists if (dns.ZoneExists(zoneName)) return BusinessErrorCodes.ERROR_DNS_ZONE_EXISTS; // TaskManager.StartTask("DNS_ZONE", "ADD", zoneName); // int zoneItemId = default(int); // try { // get secondary DNS services StringDictionary primSettings = ServerController.GetServiceSettings(serviceId); string[] primaryIPAddresses = GetExternalIPAddressesFromString(primSettings["ListeningIPAddresses"]); List<string> secondaryIPAddresses = new List<string>(); List<int> secondaryServiceIds = new List<int>(); string strSecondaryServices = primSettings["SecondaryDNSServices"]; if (!String.IsNullOrEmpty(strSecondaryServices)) { string[] secondaryServices = strSecondaryServices.Split(','); foreach (string strSecondaryId in secondaryServices) { int secondaryId = Utils.ParseInt(strSecondaryId, 0); if (secondaryId == 0) continue; secondaryServiceIds.Add(secondaryId); StringDictionary secondarySettings = ServerController.GetServiceSettings(secondaryId); // add secondary IPs to the master array secondaryIPAddresses.AddRange( GetExternalIPAddressesFromString(secondarySettings["ListeningIPAddresses"])); } } // add "Allow zone transfers" string allowTransfers = primSettings["AllowZoneTransfers"]; if (!String.IsNullOrEmpty(allowTransfers)) { string[] ips = Utils.ParseDelimitedString(allowTransfers, '\n', ' ', ',', ';'); foreach (string ip in ips) { if (!secondaryIPAddresses.Contains(ip)) secondaryIPAddresses.Add(ip); } } // add primary zone dns.AddPrimaryZone(zoneName, secondaryIPAddresses.ToArray()); // get DNS zone records List<GlobalDnsRecord> records = ServerController.GetDnsRecordsTotal(packageId); // get name servers PackageSettings packageSettings = PackageController.GetPackageSettings(packageId, PackageSettings.NAME_SERVERS); string[] nameServers = new string[] { }; if (!String.IsNullOrEmpty(packageSettings["NameServers"])) nameServers = packageSettings["NameServers"].Split(';'); // build records list List<DnsRecord> zoneRecords = new List<DnsRecord>(); string primaryNameServer = "ns." + zoneName; if (nameServers.Length > 0) primaryNameServer = nameServers[0]; // update SOA record string hostmaster = primSettings["ResponsiblePerson"]; if (String.IsNullOrEmpty(hostmaster)) { hostmaster = "hostmaster." + zoneName; } else { hostmaster = Utils.ReplaceStringVariable(hostmaster, "domain_name", zoneName); } dns.UpdateSoaRecord(zoneName, "", primaryNameServer, hostmaster); // add name servers foreach (string nameServer in nameServers) { DnsRecord ns = new DnsRecord(); ns.RecordType = DnsRecordType.NS; ns.RecordName = ""; ns.RecordData = nameServer; zoneRecords.Add(ns); } if (!ignoreGlobalDNSRecords) { // add all other records zoneRecords.AddRange(BuildDnsResourceRecords(records, "", zoneName, "")); } // add zone records dns.AddZoneRecords(zoneName, zoneRecords.ToArray()); // add secondary zones foreach (int secondaryId in secondaryServiceIds) { try { // add secondary zone DNSServer secDns = GetDNSServer(secondaryId); secDns.AddSecondaryZone(zoneName, primaryIPAddresses); RegisterZoneItems(packageId, secondaryId, zoneName, false); } catch (Exception ex) { TaskManager.WriteError(ex, "Error adding secondary zone (service ID = " + secondaryId + ")"); } } if (!addPackageItem) return 0; // add service item zoneItemId = RegisterZoneItems(packageId, serviceId, zoneName, true); // TaskManager.ItemId = zoneItemId; } catch (Exception ex) { TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } // return zoneItemId; }
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); } //Debug.WriteLine(zfLine); } return(records); }
//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; } 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(); }
public static int AddDnsZoneRecord(int domainId, string recordName, DnsRecordType recordType, string recordData, int mxPriority) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) return accountCheck; // load domain info DomainInfo domain = GetDomain(domainId); // check package int packageCheck = SecurityContext.CheckPackage(domain.PackageId, DemandPackage.IsActive); if (packageCheck < 0) return packageCheck; // get DNS service DnsZone zoneItem = (DnsZone)PackageController.GetPackageItem(domain.ZoneItemId); if(zoneItem == null) return 0; // place log record TaskManager.StartTask("DNS_ZONE", "ADD_RECORD", domain.DomainName); TaskManager.ItemId = domain.ZoneItemId; try { // check if record already exists if (GetDnsZoneRecord(domainId, recordName, recordType, recordData) != null) return 0; DNSServer dns = new DNSServer(); ServiceProviderProxy.Init(dns, zoneItem.ServiceId); DnsRecord record = new DnsRecord(); record.RecordType = recordType; record.RecordName = recordName; record.RecordData = recordData; record.MxPriority = mxPriority; dns.AddZoneRecord(zoneItem.Name, record); return 0; } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
/// <remarks/> public void AddZoneRecordAsync(string zoneName, DnsRecord record) { this.AddZoneRecordAsync(zoneName, record, null); }
public void DeleteZoneRecords(string zoneName, DnsRecord[] records) { try { Log.WriteStart("'{0}' DeleteZoneRecords", ProviderSettings.ProviderName); DnsProvider.DeleteZoneRecords(zoneName, records); Log.WriteEnd("'{0}' DeleteZoneRecords", ProviderSettings.ProviderName); } catch (Exception ex) { Log.WriteError(String.Format("'{0}' DeleteZoneRecords", ProviderSettings.ProviderName), ex); throw; } }
public void AddZoneRecord(string zoneName, DnsRecord record) { try { Log.WriteStart("'{0}' AddZoneRecord", ProviderSettings.ProviderName); DnsProvider.AddZoneRecord(zoneName, record); Log.WriteEnd("'{0}' AddZoneRecord", ProviderSettings.ProviderName); } catch (Exception ex) { Log.WriteError(String.Format("'{0}' AddZoneRecord", ProviderSettings.ProviderName), ex); throw; } }
/// <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); }
static void BuildRecordData_SRVRecord(string zoneName, ref string type, DnsRecord record, List<string> data) { type = "SRV"; data.Add(Convert.ToString(record.SrvPriority)); data.Add(Convert.ToString(record.SrvWeight)); data.Add(Convert.ToString(record.SrvPort)); data.Add(record.RecordData); }
protected void PDNSAddZoneRecord(string zoneName, DnsRecord record, bool isNeedToUpdateSOA) { string domainId = GetDomainId(zoneName); if (domainId == string.Empty) throw new ArgumentOutOfRangeException("DomainId not found. Zone does not exist."); string recordType = ConvertDnsRecordTypeToString(record.RecordType); string ttl = GetDefaultRecordTTL(record.RecordType); //NS record if (record.RecordType == DnsRecordType.NS) { if (string.IsNullOrEmpty(record.RecordName)) record.RecordName = zoneName; } //widen record name for Power DNS if (!string.IsNullOrEmpty(record.RecordName)) { if (!record.RecordName.Contains(zoneName)) { record.RecordName = string.Format("{0}.{1}", record.RecordName, zoneName); } } else { record.RecordName = zoneName; } AddRecord( domainId , record.RecordName , record.RecordData , recordType , ttl , record.MxPriority.ToString() ); if (isNeedToUpdateSOA) { PDNSUpdateSoaRecord(zoneName); } }
public static List<DnsRecord> BuildDnsResourceRecords(List<GlobalDnsRecord> records, string hostName, string domainName, string serviceIP) { List<DnsRecord> zoneRecords = new List<DnsRecord>(); foreach (GlobalDnsRecord record in records) { domainName = GetAsciiZoneName(domainName); DnsRecord rr = new DnsRecord(); rr.RecordType = (DnsRecordType)Enum.Parse(typeof(DnsRecordType), record.RecordType, true); rr.RecordName = Utils.ReplaceStringVariable(record.RecordName, "host_name", hostName, true); if (record.RecordType == "A" || record.RecordType == "AAAA") { // If the service IP address and the DNS records external address are empty / null SimpleDNS will fail to properly create the zone record if (String.IsNullOrEmpty(serviceIP) && String.IsNullOrEmpty(record.ExternalIP) && String.IsNullOrEmpty(record.RecordData)) continue; rr.RecordData = String.IsNullOrEmpty(record.RecordData) ? record.ExternalIP : record.RecordData; rr.RecordData = Utils.ReplaceStringVariable(rr.RecordData, "ip", string.IsNullOrEmpty(serviceIP) ? record.ExternalIP : serviceIP); rr.RecordData = Utils.ReplaceStringVariable(rr.RecordData, "domain_name", string.IsNullOrEmpty(domainName) ? string.Empty : domainName); if (String.IsNullOrEmpty(rr.RecordData) && !String.IsNullOrEmpty(serviceIP)) rr.RecordData = serviceIP; } else if (record.RecordType == "SRV") { rr.SrvPriority = record.SrvPriority; rr.SrvWeight = record.SrvWeight; rr.SrvPort = record.SrvPort; rr.RecordText = record.RecordData; rr.RecordData = record.RecordData; } else { rr.RecordData = record.RecordData; } // substitute variables rr.RecordData = Utils.ReplaceStringVariable(rr.RecordData, "domain_name", domainName); // add MX priority if (record.RecordType == "MX") rr.MxPriority = record.MxPriority; if (!String.IsNullOrEmpty(rr.RecordData)) { if (rr.RecordName != "[host_name]") zoneRecords.Add(rr); } } return zoneRecords; }
/// <remarks/> public System.IAsyncResult BeginAddZoneRecord(string zoneName, DnsRecord record, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("AddZoneRecord", new object[] { zoneName, record}, callback, asyncState); }
/// <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()); }
/// <remarks/> public void AddZoneRecordAsync(string zoneName, DnsRecord record, object userState) { if ((this.AddZoneRecordOperationCompleted == null)) { this.AddZoneRecordOperationCompleted = new System.Threading.SendOrPostCallback(this.OnAddZoneRecordOperationCompleted); } this.InvokeAsync("AddZoneRecord", new object[] { zoneName, record}, this.AddZoneRecordOperationCompleted, userState); }
static void BuildRecordData_TXTRecord(string zoneName, ref string type, DnsRecord record, List <string> data) { type = "TXT"; data.Add(record.RecordData); }
public void DeleteZoneRecords(string zoneName, DnsRecord[] records) { this.Invoke("DeleteZoneRecords", new object[] { zoneName, records}); }
public void DeleteZoneRecords(string zoneName, DnsRecord[] records) { foreach (DnsRecord record in records) { PDNSDeleteZoneRecord(zoneName, record, false); } PDNSUpdateSoaRecord(zoneName); }
/// <remarks/> public void DeleteZoneRecordsAsync(string zoneName, DnsRecord[] records) { this.DeleteZoneRecordsAsync(zoneName, records, null); }
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); }
public override void AddZoneRecords(string zoneName, DnsRecord[] records) { // load zone Connection cn = SetupProviderConnection(); DNSZone dnsZone = cn.GetZone(zoneName); // add zone records foreach (DnsRecord record in records) { if (!SupportedDnsRecords.ContainsKey(record.RecordType)) continue; string m_strRecordName = ConvertRecordNameToSDNSFormat(record.RecordName, 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); // skip if already added if (dnsZone.Records.Contains(m_strRecordName, m_strRecordType, m_strRecordData.ToArray())) continue; // add records dnsZone.Records.Add(m_strRecordName, m_strRecordType, m_strRecordData.ToArray()); } // update zone cn.UpdateZone(dnsZone, false); // update SOA UpdateSoaRecord(zoneName); }
public void DeleteZoneRecord(string zoneName, DnsRecord record) { this.Invoke("DeleteZoneRecord", new object[] { zoneName, record}); }
public override void AddZoneRecord(string zoneName, DnsRecord record) { if (ZoneExists(zoneName)) { // if (SupportedDnsRecords.ContainsKey(record.RecordType)) { 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); // skip if already added if (dnsZone.Records.Contains(m_strRecordName, m_strRecordType, m_strRecordData.ToArray())) return; // dnsZone.Records.Add(m_strRecordName, m_strRecordType, m_strRecordData.ToArray()); // cn.UpdateZone(dnsZone, false); // UpdateSoaRecord(zoneName); } } }
/// <remarks/> public void AddZoneRecordsAsync(string zoneName, DnsRecord[] records) { this.AddZoneRecordsAsync(zoneName, records, null); }
public override void DeleteZoneRecords(string zoneName, DnsRecord[] records) { // load zone Connection cn = SetupProviderConnection(); DNSZone dnsZone = cn.GetZone(zoneName); foreach (DnsRecord record in records) { if (ZoneExists(zoneName)) { string m_strRecordName = ConvertRecordNameToSDNSFormat(record.RecordName, 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()); } } // update zone cn.UpdateZone(dnsZone, false); // update SOA UpdateSoaRecord(zoneName); }
/// <remarks/> public System.IAsyncResult BeginDeleteZoneRecords(string zoneName, DnsRecord[] records, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("DeleteZoneRecords", new object[] { zoneName, records}, callback, asyncState); }
public static List<DnsRecord> BuildDnsResourceRecords(List<GlobalDnsRecord> records, string domainName, string serviceIP) { List<DnsRecord> zoneRecords = new List<DnsRecord>(); foreach (GlobalDnsRecord record in records) { DnsRecord rr = new DnsRecord(); rr.RecordType = (DnsRecordType)Enum.Parse(typeof(DnsRecordType), record.RecordType, true); rr.RecordName = record.RecordName; if (record.RecordType == "A") { rr.RecordData = String.IsNullOrEmpty(record.RecordData) ? record.ExternalIP : record.RecordData; rr.RecordData = Utils.ReplaceStringVariable(rr.RecordData, "ip", record.ExternalIP); if (String.IsNullOrEmpty(rr.RecordData) && !String.IsNullOrEmpty(serviceIP)) rr.RecordData = serviceIP; } else { rr.RecordData = record.RecordData; } // substitute variables rr.RecordData = Utils.ReplaceStringVariable(rr.RecordData, "domain_name", domainName); // add MX priority if (record.RecordType == "MX") rr.MxPriority = record.MxPriority; if (!String.IsNullOrEmpty(rr.RecordData)) zoneRecords.Add(rr); } return zoneRecords; }
/// <remarks/> public void DeleteZoneRecordsAsync(string zoneName, DnsRecord[] records, object userState) { if ((this.DeleteZoneRecordsOperationCompleted == null)) { this.DeleteZoneRecordsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnDeleteZoneRecordsOperationCompleted); } this.InvokeAsync("DeleteZoneRecords", new object[] { zoneName, records}, this.DeleteZoneRecordsOperationCompleted, userState); }
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; }