Skip to content

Commit

Permalink
Fix for preview domain when DNS server supports setting TTL. Fixes re…
Browse files Browse the repository at this point in the history
…cords added with 0 TTL.

[PowerDNS][MsDNS2016][SimpleDNS Plus 9.x]
  • Loading branch information
FuseCP-TRobinson committed Dec 11, 2024
1 parent 95eb20a commit b34c4f9
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public static int AddZone(int packageId, int serviceId, string zoneName, bool ad
ns.RecordType = DnsRecordType.NS;
ns.RecordName = "";
ns.RecordData = nameServer;
ns.RecordTTL = Convert.ToInt32(primSettings["recorddefaultttl"]);

zoneRecords.Add(ns);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2299,13 +2299,16 @@ public static DomainInfo GetDomain(int domainId, bool withLog = true)
// get domain by ID
DomainInfo domain = GetDomainItem(domainId);

//get default TTL
StringDictionary settings = GetServiceSettings(domain.ZoneServiceID);
domain.RecordDefaultTTL = Convert.ToInt32(settings["RecordDefaultTTL"]);
if (domain.RecordDefaultTTL == 0) domain.RecordDefaultTTL = 86400;
domain.RecordMinimumTTL = Convert.ToInt32(settings["RecordMinimumTTL"]);
if (domain.RecordMinimumTTL == 0) domain.RecordMinimumTTL = 3600;
domain.MinimumTTL = Convert.ToInt32(settings["MinimumTTL"]);
//get default TTL
if (domainId > 0)
{
StringDictionary settings = GetServiceSettings(domain.ZoneServiceID);
domain.RecordDefaultTTL = Convert.ToInt32(settings["RecordDefaultTTL"]);
if (domain.RecordDefaultTTL == 0) domain.RecordDefaultTTL = 86400;
domain.RecordMinimumTTL = Convert.ToInt32(settings["RecordMinimumTTL"]);
if (domain.RecordMinimumTTL == 0) domain.RecordMinimumTTL = 3600;
domain.MinimumTTL = Convert.ToInt32(settings["MinimumTTL"]);
}

// return
return GetDomain(domain, withLog);
Expand Down
11 changes: 11 additions & 0 deletions SolidCP/Sources/SolidCP.Providers.DNS.MsDNS/MsDNS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ protected bool AdMode
{
get { return ProviderSettings.GetBool("AdMode"); }
}

public int DNSRecordDefaultTTL
{
get { return ProviderSettings.GetInt("RecordDefaultTTL"); }
}

public int DNSRecordMinimumTTL
{
get { return ProviderSettings.GetInt("RecordMinimumTTL"); }
}

#endregion

private WmiHelper wmi = null;
Expand Down
11 changes: 11 additions & 0 deletions SolidCP/Sources/SolidCP.Providers.DNS.MsDNS2012/MsDNS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ protected bool AdMode
{
get { return ProviderSettings.GetBool( "AdMode" ); }
}

public int DNSRecordDefaultTTL
{
get { return ProviderSettings.GetInt("RecordDefaultTTL"); }
}

public int DNSRecordMinimumTTL
{
get { return ProviderSettings.GetInt("RecordMinimumTTL"); }
}

#endregion

private PowerShellHelper ps = null;
Expand Down
3 changes: 3 additions & 0 deletions SolidCP/Sources/SolidCP.Providers.DNS.MsDNS2016/MsDNS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public override void AddZoneRecord(string zoneName, DnsRecord record)
if (String.IsNullOrEmpty(name))
name = ".";

if (record.RecordTTL == 0)
record.RecordTTL = DNSRecordDefaultTTL;

if (record.RecordType == DnsRecordType.A)
ps.Add_DnsServerResourceRecordA(zoneName, name, record.RecordData, TimeSpan.FromSeconds(record.RecordTTL));
else if (record.RecordType == DnsRecordType.AAAA)
Expand Down
17 changes: 17 additions & 0 deletions SolidCP/Sources/SolidCP.Providers.DNS.PowerDNS/PowerDNS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public class PowerDNS : HostingServiceProviderBase, IDnsServer
const string ExpireLimit = "ExpireLimit";
const string MinimumTTL = "MinimumTTL";

//Record Settings
const string RecordDefaultTTL = "RecordDefaultTTL";
const string RecordMinimumTTL = "RecordMinimumTTL";

//name servers
const string NameServers = "NameServers";

Expand Down Expand Up @@ -168,6 +172,16 @@ public string DbPassword
get { return ProviderSettings[PDNSDbPassword]; }
}

public string DNSRecordDefaultTTL
{
get { return ProviderSettings[RecordDefaultTTL]; }
}

public string DNSRecordMinimumTTL
{
get { return ProviderSettings[RecordMinimumTTL]; }
}

#endregion

#region IDnsServer Members
Expand Down Expand Up @@ -567,6 +581,9 @@ protected void PDNSAddZoneRecord(string zoneName, DnsRecord record, bool isNeedT
record.RecordName = zoneName;
}

if (record.RecordTTL == 0)
record.RecordTTL = Convert.ToInt32(DNSRecordDefaultTTL);

AddRecord(
domainId
, record.RecordName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ public void AddZoneRecord(string zoneName, DnsRecord record)
if (record == null)
throw new ArgumentNullException(nameof(record));

if (record.RecordTTL == 0)
record.RecordTTL = RecordDefaultTTL;

//Declare content to be Patched
var content = new List<ZoneRecordsResponse>
{
Expand All @@ -535,6 +538,12 @@ public void AddZoneRecords(string zoneName, DnsRecord[] records)
if (records.Length == 0 || records[0] == null)
return;

foreach (DnsRecord record in records)
{
if (record.RecordTTL == 0)
record.RecordTTL = RecordDefaultTTL;
}

//Declare content to be patched
var content = records.Select(record => record.ToZoneRecordsResponse(zoneName)).ToList();

Expand Down

0 comments on commit b34c4f9

Please sign in to comment.