summaryrefslogtreecommitdiffstats
path: root/src/main.lib/Plugins/ValidationPlugins/Dns/Manual/Manual.cs
blob: c584efb4f1f499b08b52df6c5160d62e4bccb082 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using PKISharp.WACS.Clients.DNS;
using PKISharp.WACS.Services;
using System.Threading.Tasks;

namespace PKISharp.WACS.Plugins.ValidationPlugins.Dns
{
    internal class Manual : DnsValidation<Manual>
    {
        private readonly IInputService _input;
        private readonly string _identifier;

        public Manual(
            LookupClientProvider dnsClient, 
            ILogService log, 
            IInputService input,
            ISettingsService settings,
            string identifier) 
            : base(dnsClient, log, settings)
        {
            // Usually it's a big no-no to rely on user input in validation plugin
            // because this should be able to run unattended. This plugin is for testing
            // only and therefor we will allow it. Future versions might be more advanced,
            // e.g. shoot an email to an admin and complete the order later.
            _input = input;
            _identifier = identifier;
        }

        public override async Task<bool> CreateRecord(string recordName, string token)
        {
            _input.CreateSpace();
            _input.Show("Domain", _identifier);
            _input.Show("Record", recordName);
            _input.Show("Type", "TXT");
            _input.Show("Content", $"\"{token}\"");
            _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())
                {
                    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;
                    }
                }
            }
        }

        public override Task DeleteRecord(string recordName, string token)
        {
            _input.CreateSpace();
            _input.Show("Domain", _identifier);
            _input.Show("Record", recordName);
            _input.Show("Type", "TXT");
            _input.Show("Content", $"\"{token}\"");
            _input.Wait("Please press <Enter> after you've deleted the record");
            return Task.CompletedTask;
        }
    }
}