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); }
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); } }
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); } } }
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]); } }
public override void AddSecondaryZone(string zoneName, string[] masterServers) { Connection cn = SetupProviderConnection(); IPAddress ipAddress = System.Net.Dns.GetHostEntry(masterServers[0]).AddressList[0]; DNSZone dnsZone = cn.CreateZone(zoneName, masterServers[0], "hostmaster"); dnsZone.PrimaryIP = ipAddress.ToString(); cn.UpdateZone(dnsZone, false); }
public override bool ZoneExists(string zoneName) { try { Connection cn = SetupProviderConnection(); // DNSZone dnsZone = cn.GetZone(zoneName); // return(true); } catch (WebException ex) { Log.WriteWarning(ex.ToString()); return(false); } }
public override void DeleteZoneRecord(string zoneName, DnsRecord record) { if (ZoneExists(zoneName)) { Log.WriteInfo("SimpleDNS6 Removing Zone: {0}", 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); } }
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 override void AddPrimaryZone(string zoneName, string[] secondaryServers) { Connection cn = SetupProviderConnection(); // CREATE PRIMARY DNS ZONE string primaryNameServer = System.Net.Dns.GetHostEntry("LocalHost").HostName; DNSZone zoneObj = cn.CreateZone(zoneName, primaryNameServer, "hostmaster"); zoneObj.Comments = String.Concat("Created with SolidCP DNS API at ", DateTime.Now); // Setup zone data transfer if (secondaryServers != null && secondaryServers.Length != 0) { if (secondaryServers.Length == 1 && secondaryServers[0] == "*") { zoneObj.AllowZoneTransfer = "*"; } else { zoneObj.AllowZoneTransfer = String.Join(" ", secondaryServers); } } // Update SOA record DNSRecord soaRecord = zoneObj.Records[0]; soaRecord.DataFields[SOA_PRIMARY_NAME_SERVER] = CorrectSOARecord(zoneName, primaryNameServer); soaRecord.DataFields[SOA_RESPONSIBLE_PERSON] = CorrectSOARecord(zoneName, "hostmaster"); // Issue new serial number for the zone soaRecord.DataFields[SOA_SERIAL_NUMBER] = UpdateSerialNumber(null); 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(); // Publish updates are made cn.UpdateZone(zoneObj, false); }
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 static IEnumerable <DNSZone> Get_DomainDNSZone(Args_Get_DomainDNSZone args = null) { if (args == null) { args = new Args_Get_DomainDNSZone(); } var SearcherArguments = new Args_Get_DomainSearcher { LDAPFilter = @"(objectClass=dnsZone)", Domain = args.Domain, Server = args.Server, Properties = args.Properties, ResultPageSize = args.ResultPageSize, ServerTimeLimit = args.ServerTimeLimit, Credential = args.Credential }; var DNSSearcher1 = GetDomainSearcher.Get_DomainSearcher(SearcherArguments); SearchResult[] Results = null; List <DNSZone> Outs = null; if (DNSSearcher1 != null) { if (args.FindOne) { Results = new SearchResult[] { DNSSearcher1.FindOne() }; } else { var items = DNSSearcher1.FindAll(); if (items != null) { Results = new SearchResult[items.Count]; items.CopyTo(Results, 0); } } if (Results != null) { foreach (var result in Results) { var Out = new DNSZone(ConvertLDAPProperty.Convert_LDAPProperty(result.Properties)); Outs.Add(Out); } } DNSSearcher1.Dispose(); } SearcherArguments.SearchBasePrefix = @"CN=MicrosoftDNS,DC=DomainDnsZones"; var DNSSearcher2 = GetDomainSearcher.Get_DomainSearcher(SearcherArguments); if (DNSSearcher2 != null) { try { if (args.FindOne) { Results = new SearchResult[] { DNSSearcher2.FindOne() }; } else { var items = DNSSearcher2.FindAll(); if (items != null) { Results = new SearchResult[items.Count]; items.CopyTo(Results, 0); } } if (Results != null) { foreach (var result in Results) { var Out = new DNSZone(ConvertLDAPProperty.Convert_LDAPProperty(result.Properties)); Outs.Add(Out); } } } catch { Logger.Write_Verbose(@"[Get-DomainDNSZone] Error accessing 'CN=MicrosoftDNS,DC=DomainDnsZones'"); } DNSSearcher2.Dispose(); } return(Outs); }