forked from jbjonesjr/letsencrypt-manual-hook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manual_hook.rb
executable file
·57 lines (47 loc) · 1.35 KB
/
manual_hook.rb
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
#!/usr/bin/env ruby
require 'resolv'
def setup_dns(domain, txt_challenge)
resolved = false;
singleLoop = false;
dns = Resolv::DNS.new;
acme_domain = "_acme-challenge."+domain;
puts "Checking for pre-existing TXT record for the domain: \'#{acme_domain}\'."
until resolved
dns.each_resource(acme_domain, Resolv::DNS::Resource::IN::TXT) { |resp|
if resp.strings[0] == txt_challenge
puts "Found #{resp.strings[0]}. match."
resolved = true;
else
puts "Found #{resp.strings[0]}. no match."
end
}
if !resolved
if !singleLoop
puts "Create TXT record for the domain: \'#{acme_domain}\'. TXT record:"
puts "\'#{txt_challenge}\'"
puts "Press enter when DNS has been updated..."
$stdin.readline()
singleLoop = true
end
puts "Didn't find a match for #{txt_challenge}";
puts "Waiting to retry...";
sleep 30;
end
end
end
def delete_dns(domain, txt_challenge)
puts "Challenge complete. Leave TXT record in place to allow easier future refreshes."
end
if __FILE__ == $0
hook_stage = ARGV[0]
domain = ARGV[1]
txt_challenge = ARGV[3]
# puts hook_stage
# puts domain
# puts txt_challenge
if hook_stage == "deploy_challenge"
setup_dns(domain, txt_challenge)
elsif hook_stage == "clean_challenge"
delete_dns(domain, txt_challenge)
end
end