From b8e39824b54eae516975a6aaabaebd96f3aa700f Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Fri, 7 Jul 2023 18:22:18 +0200 Subject: [PATCH] Added cloudflare enable option --- Moonlight/App/Services/DomainService.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Moonlight/App/Services/DomainService.cs b/Moonlight/App/Services/DomainService.cs index c56855f..7eb0a0b 100644 --- a/Moonlight/App/Services/DomainService.cs +++ b/Moonlight/App/Services/DomainService.cs @@ -20,6 +20,7 @@ namespace Moonlight.App.Services; public class DomainService { private readonly DomainRepository DomainRepository; + private readonly ConfigService ConfigService; private readonly SharedDomainRepository SharedDomainRepository; private readonly CloudFlareClient Client; private readonly string AccountId; @@ -29,6 +30,7 @@ public class DomainService DomainRepository domainRepository, SharedDomainRepository sharedDomainRepository) { + ConfigService = configService; DomainRepository = domainRepository; SharedDomainRepository = sharedDomainRepository; @@ -48,6 +50,9 @@ public class DomainService public Task Create(string domain, SharedDomain sharedDomain, User user) { + if (!ConfigService.Get().Moonlight.Domains.Enable) + throw new DisplayException("This operation is disabled"); + if (DomainRepository.Get().Where(x => x.SharedDomain.Id == sharedDomain.Id).Any(x => x.Name == domain)) throw new DisplayException("A domain with this name does already exist for this shared domain"); @@ -63,6 +68,9 @@ public class DomainService public Task Delete(Domain domain) { + if (!ConfigService.Get().Moonlight.Domains.Enable) + throw new DisplayException("This operation is disabled"); + DomainRepository.Delete(domain); return Task.CompletedTask; @@ -71,6 +79,9 @@ public class DomainService public async Task GetAvailableDomains() // This method returns all available domains which are not added as a shared domain { + if (!ConfigService.Get().Moonlight.Domains.Enable) + return Array.Empty(); + var domains = GetData( await Client.Zones.GetAsync(new() { @@ -93,6 +104,9 @@ public class DomainService public async Task GetDnsRecords(Domain d) { + if (!ConfigService.Get().Moonlight.Domains.Enable) + return Array.Empty(); + var domain = EnsureData(d); var records = new List(); @@ -166,6 +180,9 @@ public class DomainService public async Task AddDnsRecord(Domain d, DnsRecord dnsRecord) { + if (!ConfigService.Get().Moonlight.Domains.Enable) + throw new DisplayException("This operation is disabled"); + var domain = EnsureData(d); var rname = $"{domain.Name}.{domain.SharedDomain.Name}"; @@ -225,6 +242,9 @@ public class DomainService public async Task UpdateDnsRecord(Domain d, DnsRecord dnsRecord) { + if (!ConfigService.Get().Moonlight.Domains.Enable) + throw new DisplayException("This operation is disabled"); + var domain = EnsureData(d); var rname = $"{domain.Name}.{domain.SharedDomain.Name}"; @@ -255,6 +275,9 @@ public class DomainService public async Task DeleteDnsRecord(Domain d, DnsRecord dnsRecord) { + if (!ConfigService.Get().Moonlight.Domains.Enable) + throw new DisplayException("This operation is disabled"); + var domain = EnsureData(d); GetData(