-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanual_hook.rb
66 lines (56 loc) · 1.88 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
58
59
60
61
62
63
64
65
66
#!/usr/bin/env ruby
require 'resolv'
require 'tempfile'
def setup_dns(domain, txt_challenge)
dns = Resolv::DNS.new;
acme_domain = "_acme-challenge."+domain;
# Create nsupdate_create tempfile
nsupdate_create = Tempfile.new('nsupdate_create')
nsupdate_create.puts("server ns1.geilerserver.com")
nsupdate_create.puts("zone geilerserver.com")
nsupdate_create.puts("update add #{acme_domain} 60 TXT #{txt_challenge}")
nsupdate_create.puts("send")
nsupdate_create.close
# Execute nsupdate
dnskey = 'geilerserver.com.key:"MVptZHq85/irKhnJI+vxm4B6UX1T7NGw0IH2HhvUTBlDE7MVDOutK74E md9lTzmts6ux87uFtEPqVLABo3fkcA=="'
%x( /usr/bin/nsupdate -y #{dnskey} -v #{nsupdate_create.path})
nsupdate_create.unlink
resolved = false;
until resolved
dns.each_resource(acme_domain, Resolv::DNS::Resource::IN::TXT) { |resp|
if resp.strings[0] == txt_challenge
resolved = true;
end
}
if !resolved
sleep 10;
end
end
end
def delete_dns(domain, txt_challenge)
acme_domain = "_acme-challenge."+domain;
# Create nsupdate_delete tempfile
nsupdate_delete = Tempfile.new('nsupdate_delete')
nsupdate_delete.puts("server ns1.geilerserver.com")
nsupdate_delete.puts("zone geilerserver.com")
nsupdate_delete.puts("update delete #{acme_domain} 60 TXT #{txt_challenge}")
nsupdate_delete.puts("send")
nsupdate_delete.close
# Execute nsupdate
dnskey = 'geilerserver.com.key:"MVptZHq85/irKhnJI+vxm4B6UX1T7NGw0IH2HhvUTBlDE7MVDOutK74E md9lTzmts6ux87uFtEPqVLABo3fkcA=="'
%x( /usr/bin/nsupdate -y #{dnskey} -v #{nsupdate_delete.path})
nsupdate_delete.unlink
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