Added additional dns error handling
This commit is contained in:
parent
daba4cba04
commit
daeb4dd5b9
1 changed files with 56 additions and 45 deletions
|
@ -182,59 +182,70 @@ public class DomainService
|
||||||
{
|
{
|
||||||
if (!ConfigService.Get().Moonlight.Domains.Enable)
|
if (!ConfigService.Get().Moonlight.Domains.Enable)
|
||||||
throw new DisplayException("This operation is disabled");
|
throw new DisplayException("This operation is disabled");
|
||||||
|
|
||||||
var domain = EnsureData(d);
|
|
||||||
|
|
||||||
var rname = $"{domain.Name}.{domain.SharedDomain.Name}";
|
try
|
||||||
var dname = $".{rname}";
|
|
||||||
|
|
||||||
if (dnsRecord.Type == DnsRecordType.Srv)
|
|
||||||
{
|
{
|
||||||
var parts = dnsRecord.Name.Split(".");
|
var domain = EnsureData(d);
|
||||||
|
|
||||||
Protocol protocol = Protocol.Tcp;
|
var rname = $"{domain.Name}.{domain.SharedDomain.Name}";
|
||||||
|
var dname = $".{rname}";
|
||||||
|
|
||||||
if (parts[1].Contains("udp"))
|
if (dnsRecord.Type == DnsRecordType.Srv)
|
||||||
protocol = Protocol.Udp;
|
|
||||||
|
|
||||||
var valueParts = dnsRecord.Content.Split(" ");
|
|
||||||
|
|
||||||
var nameWithoutProt = dnsRecord.Name.Replace($"{parts[0]}.{parts[1]}.", "");
|
|
||||||
nameWithoutProt = nameWithoutProt.Replace($"{parts[0]}.{parts[1]}", "");
|
|
||||||
var name = nameWithoutProt == "" ? rname : nameWithoutProt + dname;
|
|
||||||
|
|
||||||
var srv = new NewDnsRecord<Srv>()
|
|
||||||
{
|
{
|
||||||
Type = dnsRecord.Type,
|
var parts = dnsRecord.Name.Split(".");
|
||||||
Data = new()
|
|
||||||
|
Protocol protocol = Protocol.Tcp;
|
||||||
|
|
||||||
|
if (parts[1].Contains("udp"))
|
||||||
|
protocol = Protocol.Udp;
|
||||||
|
|
||||||
|
var valueParts = dnsRecord.Content.Split(" ");
|
||||||
|
|
||||||
|
var nameWithoutProt = dnsRecord.Name.Replace($"{parts[0]}.{parts[1]}.", "");
|
||||||
|
nameWithoutProt = nameWithoutProt.Replace($"{parts[0]}.{parts[1]}", "");
|
||||||
|
var name = nameWithoutProt == "" ? rname : nameWithoutProt + dname;
|
||||||
|
|
||||||
|
var srv = new NewDnsRecord<Srv>()
|
||||||
{
|
{
|
||||||
Service = parts[0],
|
Type = dnsRecord.Type,
|
||||||
Protocol = protocol,
|
Data = new()
|
||||||
Name = name,
|
{
|
||||||
Weight = int.Parse(valueParts[0]),
|
Service = parts[0],
|
||||||
Port = int.Parse(valueParts[1]),
|
Protocol = protocol,
|
||||||
Target = valueParts[2],
|
Name = name,
|
||||||
Priority = dnsRecord.Priority
|
Weight = int.Parse(valueParts[0]),
|
||||||
},
|
Port = int.Parse(valueParts[1]),
|
||||||
Proxied = dnsRecord.Proxied,
|
Target = valueParts[2],
|
||||||
Ttl = dnsRecord.Ttl,
|
Priority = dnsRecord.Priority
|
||||||
};
|
},
|
||||||
|
Proxied = dnsRecord.Proxied,
|
||||||
|
Ttl = dnsRecord.Ttl,
|
||||||
|
};
|
||||||
|
|
||||||
GetData(await Client.Zones.DnsRecords.AddAsync(d.SharedDomain.CloudflareId, srv));
|
GetData(await Client.Zones.DnsRecords.AddAsync(d.SharedDomain.CloudflareId, srv));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
var name = string.IsNullOrEmpty(dnsRecord.Name) ? rname : dnsRecord.Name + dname;
|
|
||||||
|
|
||||||
GetData(await Client.Zones.DnsRecords.AddAsync(d.SharedDomain.CloudflareId, new NewDnsRecord()
|
|
||||||
{
|
{
|
||||||
Type = dnsRecord.Type,
|
var name = string.IsNullOrEmpty(dnsRecord.Name) ? rname : dnsRecord.Name + dname;
|
||||||
Priority = dnsRecord.Priority,
|
|
||||||
Content = dnsRecord.Content,
|
GetData(await Client.Zones.DnsRecords.AddAsync(d.SharedDomain.CloudflareId, new NewDnsRecord()
|
||||||
Proxied = dnsRecord.Proxied,
|
{
|
||||||
Ttl = dnsRecord.Ttl,
|
Type = dnsRecord.Type,
|
||||||
Name = name
|
Priority = dnsRecord.Priority,
|
||||||
}));
|
Content = dnsRecord.Content,
|
||||||
|
Proxied = dnsRecord.Proxied,
|
||||||
|
Ttl = dnsRecord.Ttl,
|
||||||
|
Name = name
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (OverflowException)
|
||||||
|
{
|
||||||
|
throw new DisplayException("Invalid dns record values");
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
throw new DisplayException("Invalid dns record values");
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: AuditLog
|
//TODO: AuditLog
|
||||||
|
|
Loading…
Reference in a new issue