Esempio n. 1
0
 public override async Task DeleteRecord(DnsValidationRecord record)
 {
     try
     {
         var domain     = _domainParser.GetRegisterableDomain(record.Authority.Domain);
         var recordName = RelativeRecordName(domain, record.Authority.Domain);
         await _dnsService.DeleteDnsEntry(
             domain,
             new DnsEntry()
         {
             Content = record.Value,
             Name    = recordName,
             Type    = "TXT"
         });
     }
     catch (Exception ex)
     {
         _log.Warning($"Error deleting TXT record: {ex.Message}");
     }
 }
Esempio n. 2
0
        public override async Task DeleteRecord(DnsValidationRecord record)
        {
            try
            {
                var(_, zone) = SplitDomain(record.Authority.Domain);
                if (_recordId == null)
                {
                    _log.Warning("Not deleting DNS records on DigitalOcean because of missing record id.");
                    return;
                }

                await _doClient.DomainRecords.Delete(zone, _recordId.Value);

                _log.Information("Successfully deleted DNS record on DigitalOcean.");
            }
            catch (Exception ex)
            {
                _log.Error(ex, "Failed to delete DNS record on DigitalOcean.");
            }
        }
Esempio n. 3
0
        public override async Task DeleteRecord(DnsValidationRecord record)
        {
            if (!_recordsMap.ContainsKey(record.Authority.Domain))
            {
                _log.Warning($"No record with name {record.Authority.Domain} was created");
                return;
            }

            _log.Information("Deleting LuaDNS verification record");

            using var client = GetClient();
            var created = _recordsMap[record.Authority.Domain];
            var response = await client.DeleteAsync(new Uri(_LuaDnsApiEndpoint, $"zones/{created.ZoneId}/records/{created.Id}"));
            if (!response.IsSuccessStatusCode)
            {
                _log.Warning("Failed to delete DNS verification record");
                return;
            }

            _ = _recordsMap.Remove(record.Authority.Domain);
        }
Esempio n. 4
0
        public override async Task DeleteRecord(DnsValidationRecord record)
        {
            var recordName    = record.Authority.Domain;
            var token         = record.Value;
            var hostedZoneIds = await GetHostedZoneIds(recordName);

            if (hostedZoneIds == null)
            {
                return;
            }
            _log.Information($"Deleting TXT record {recordName} with value {token}");
            var deleteTasks = hostedZoneIds.Select(hostedZoneId =>
                                                   _route53Client.ChangeResourceRecordSetsAsync(
                                                       new ChangeResourceRecordSetsRequest(hostedZoneId,
                                                                                           new ChangeBatch(new List <Change> {
                new Change(
                    ChangeAction.DELETE,
                    CreateResourceRecordSet(recordName, token))
            }))));

            _ = await Task.WhenAll(deleteTasks);
        }
Esempio n. 5
0
        public override async Task <bool> CreateRecord(DnsValidationRecord record)
        {
            try
            {
                var(name, zone) = SplitDomain(record.Authority.Domain);
                var createdRecord = await _doClient.DomainRecords.Create(zone, new DomainRecord
                {
                    Type = "TXT",
                    Name = name,
                    Data = record.Value,
                    Ttl  = 300
                });

                _recordId = createdRecord.Id;
                return(true);
            }
            catch (Exception ex)
            {
                _log.Error(ex, "Failed to create DNS record on DigitalOcean.");
                return(false);
            }
        }
Esempio n. 6
0
        public override async Task <bool> CreateRecord(DnsValidationRecord record)
        {
            var ctx  = GetContext();
            var zone = await GetHostedZone(ctx, record.Authority.Domain).ConfigureAwait(false);

            if (zone == null)
            {
                _log.Error("The zone could not be found using the Cloudflare API, thus creating a DNS validation record is impossible. " +
                           $"Please note you need to use an API Token, not the Global API Key. The token needs the permissions Zone.Zone:Read and Zone.DNS:Edit. Regarding " +
                           $"Zone:Read it is important, that this token has access to all zones in your account (Zone Resources > Include > All zones) because we need to " +
                           $"list your zones. Read the docs carefully for instructions.");
                return(false);
            }

            var dns = ctx.Zone(zone).Dns;

            _ = await dns.Create(DnsRecordType.TXT, record.Authority.Domain, record.Value)
                .CallAsync(_hc)
                .ConfigureAwait(false);

            return(true);
        }
Esempio n. 7
0
        public override async Task DeleteRecord(DnsValidationRecord record)
        {
            var recordName = record.Authority.Domain;
            var zone       = await GetManagedZone(_options.ProjectId, recordName);

            if (zone == null)
            {
                _log.Warning("Could not find zone '{0}' in project '{1}'", recordName, _options.ProjectId);
                return;
            }

            try
            {
                _ = await _client.DeleteTxtRecord(_options.ProjectId, zone, recordName);

                _log.Debug("Deleted TXT record");
            }
            catch (Exception ex)
            {
                _log.Warning("Error deleting TXT record, {0}", ex.Message);
                return;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Create record in Azure DNS
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public override async Task <bool> CreateRecord(DnsValidationRecord record)
        {
            var zone = await GetHostedZone(record.Authority.Domain);

            if (zone == null)
            {
                return(false);
            }
            // Create or update record set parameters
            var txtRecord = new TxtRecord(new[] { record.Value });

            if (!_recordSets.ContainsKey(zone))
            {
                _recordSets.Add(zone, new Dictionary <string, RecordSet?>());
            }
            var zoneRecords = _recordSets[zone];
            var relativeKey = RelativeRecordName(zone, record.Authority.Domain);

            if (!zoneRecords.ContainsKey(relativeKey))
            {
                zoneRecords.Add(
                    relativeKey,
                    new RecordSet
                {
                    TTL        = 0,
                    TxtRecords = new List <TxtRecord> {
                        txtRecord
                    }
                });
            }
            else if (zoneRecords[relativeKey] != null)
            {
                zoneRecords[relativeKey] !.TxtRecords.Add(txtRecord);
            }
            return(true);
        }
Esempio n. 9
0
        public override async Task<bool> CreateRecord(DnsValidationRecord record)
        {
            _log.Information("Creating LuaDNS verification record");

            using var client = GetClient();
            var response = await client.GetAsync(new Uri(_LuaDnsApiEndpoint, "zones"));
            if (!response.IsSuccessStatusCode)
            {
                _log.Error("Failed to get DNS zones list for account. Aborting.");
                return false;
            }

            var payload = await response.Content.ReadAsStringAsync();
            var zones = JsonSerializer.Deserialize<ZoneData[]>(payload);
            var targetZone = FindBestMatch(zones.ToDictionary(x => x.Name), record.Authority.Domain);
            if (targetZone == null)
            {
                _log.Error("No matching zone found in LuaDNS account. Aborting");
                return false;
            }

            var newRecord = new RecordData { Name = $"{record.Authority.Domain}.", Type = "TXT", Content = record.Value, TTL = 300 };
            payload = JsonSerializer.Serialize(newRecord);

            response = await client.PostAsync(new Uri(_LuaDnsApiEndpoint, $"zones/{targetZone.Id}/records"), new StringContent(payload, Encoding.UTF8, "application/json"));
            if (!response.IsSuccessStatusCode)
            {
                _log.Error("Failed to create DNS verification record");
                return false;
            }

            payload = await response.Content.ReadAsStringAsync();
            newRecord = JsonSerializer.Deserialize<RecordData>(payload);
            _recordsMap[record.Authority.Domain] = newRecord;
            return true;
        }
Esempio n. 10
0
        public override async Task <bool> CreateRecord(DnsValidationRecord record)
        {
            _input.CreateSpace();
            _input.Show("Domain", record.Context.Identifier);
            _input.Show("Record", record.Authority.Domain);
            _input.Show("Type", "TXT");
            _input.Show("Content", $"\"{record.Value}\"");
            _input.Show("Note", "Some DNS managers add quotes automatically. A single set is needed.");
            if (!await _input.Wait("Please press <Enter> after you've created and verified the record"))
            {
                _log.Warning("User aborted");
                return(false);
            }

            // Pre-pre-validate, allowing the manual user to correct mistakes
            while (true)
            {
                if (await PreValidate(record))
                {
                    return(true);
                }
                else
                {
                    var retry = await _input.PromptYesNo(
                        "The correct record is not yet found by the local resolver. " +
                        "Check your configuration and/or wait for the name servers to " +
                        "synchronize and press <Enter> to try again. Answer 'N' to " +
                        "try ACME validation anyway.", true);

                    if (!retry)
                    {
                        return(false);
                    }
                }
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Create validation record
 /// </summary>
 /// <param name="recordName">Name of the record</param>
 /// <param name="token">Contents of the record</param>
 public abstract Task <bool> CreateRecord(DnsValidationRecord record);
Esempio n. 12
0
 /// <summary>
 /// Delete validation record
 /// </summary>
 /// <param name="recordName">Name of the record</param>
 public abstract Task DeleteRecord(DnsValidationRecord record);
Esempio n. 13
0
 public override Task DeleteRecord(DnsValidationRecord record) => Task.CompletedTask;
Esempio n. 14
0
        /// <summary>
        /// Send API call to the acme-dns server
        /// </summary>
        /// <param name="recordName"></param>
        /// <param name="token"></param>
        public override async Task <bool> CreateRecord(DnsValidationRecord record)
        {
            var client = new AcmeDnsClient(_dnsClient, _proxy, _log, _settings, _input, new Uri(_options.BaseUri));

            return(await client.Update(record.Context.Identifier, record.Value));
        }