Now we can add automatic the challenge record
8741d71076920204b63fc46da893e4238cbe0c42
3 files changed
MijnHost/CheckAllHelper.csMijnHost/Program.csMijnHost/Properties/launchSettings.json
diff --git a/MijnHost/CheckAllHelper.cs b/MijnHost/CheckAllHelper.cs
new file mode 100644
index 0000000..c620e9b
--- /dev/null
+++ b/MijnHost/CheckAllHelper.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace MijnHost;
+
+public class CheckAllHelper
+{
+ public static async Task CheckAlAsync(DnsApiClient client)
+ {
+ DnsResponse<DnsDomains> dnsResponse = await client.GetDomainsAsync();
+ foreach (DnsDomain dom in dnsResponse.Data.Domains)
+ {
+ DnsResponse<DnsRecords> dnsRecords = await client.GetDomainRecordsAsync(dom.Domain);
+
+ DnsRecord? challenge = dnsRecords.Data.Records.FirstOrDefault(x => x.Name.StartsWith("_acme-challenge"));
+ if (challenge != null)
+ {
+ Console.WriteLine($"{challenge.Name} -> {challenge.Value}");
+ }
+ else
+ {
+ DnsApiResponse? result = await client.PatchDnsRecordAsync(
+ dom.Domain, new DnsRecord($"_acme-challenge", "CNAME", $"{dom.Domain}.acme.certservice.nl.", 60));
+ if(result.Status == 200)
+ {
+ Console.WriteLine($"Added _acme-challenge for {dom.Domain}");
+ }
+ else
+ {
+ Console.WriteLine($"Failed to add _acme-challenge for {dom.Domain}: {result.StatusDescription}");
+ }
+ }
+ }
+ }
+}
diff --git a/MijnHost/Program.cs b/MijnHost/Program.cs
index c3112f9..24a6c48 100644
--- a/MijnHost/Program.cs
+++ b/MijnHost/Program.cs
@@ -8,6 +8,8 @@ if(args.Length < 1)
Console.WriteLine("\t--list");
Console.WriteLine("\t--records example.com");
Console.WriteLine("\t--challenge example.com 12345");
+ Console.WriteLine("\t--cname example.com example.com.acme.certservice.nl.");
+ Console.WriteLine("\t--checkall");
Environment.Exit(1);
}
@@ -25,6 +27,9 @@ try
using var client = new DnsApiClient(apiKey, userAgent);
+ DnsApiResponse? result = null;
+ string domain, value;
+
switch (args[0])
{
case "--list":
@@ -43,11 +48,20 @@ try
}
break;
case "--challenge":
- string domain = args[1];
- string value = args[2];
- var result = await client.PatchDnsRecordAsync(domain, new DnsRecord($"_acme-challenge", "TXT", value, 60));
+ domain = args[1];
+ value = args[2];
+ result = await client.PatchDnsRecordAsync(domain, new DnsRecord($"_acme-challenge", "TXT", value, 60));
+ Console.WriteLine($"Success: {result.Status} - {result.StatusDescription}");
+ break;
+ case "--cname":
+ domain = args[1];
+ value = args[2];
+ result = await client.PatchDnsRecordAsync(domain, new DnsRecord($"_acme-challenge", "CNAME", value, 60));
Console.WriteLine($"Success: {result.Status} - {result.StatusDescription}");
break;
+ case "--checkall":
+ await CheckAllHelper.CheckAlAsync(client);
+ break;
default:
Console.WriteLine("Onbekende opdracht.");
break;
diff --git a/MijnHost/Properties/launchSettings.json b/MijnHost/Properties/launchSettings.json
index 45f28ed..b0ef53a 100644
--- a/MijnHost/Properties/launchSettings.json
+++ b/MijnHost/Properties/launchSettings.json
@@ -2,7 +2,7 @@
"profiles": {
"MijnHost": {
"commandName": "Project",
- "commandLineArgs": "--records lingerieke.nl"
+ "commandLineArgs": "--checkall"
}
}
}
\ No newline at end of file