comparison mod_dnsupdate/mod_dnsupdate.lua @ 4896:54fa2116bbf3

mod_dnsupdate: Add a --remove option to delete all SRV records
author Kim Alvefur <zash@zash.se>
date Thu, 17 Feb 2022 01:59:24 +0100
parents 28f6322fad50
children 429be658c0bb
comparison
equal deleted inserted replaced
4895:2542fd80cd15 4896:54fa2116bbf3
40 out:write("\t-p --primary\tprimary DNS name server\n"); 40 out:write("\t-p --primary\tprimary DNS name server\n");
41 out:write("\t-t --target\ttarget hostname for SRV\n"); 41 out:write("\t-t --target\ttarget hostname for SRV\n");
42 out:write("\t-l --ttl\tTTL to use\n"); 42 out:write("\t-l --ttl\tTTL to use\n");
43 out:write("\t--each\tremove and replace individual SRV records\n"); 43 out:write("\t--each\tremove and replace individual SRV records\n");
44 out:write("\t--reset\tremove and replace all SRV records\n"); 44 out:write("\t--reset\tremove and replace all SRV records\n");
45 out:write("\t--remove\tremove all SRV records\n");
45 return opts and opts.help and 0 or 1; 46 return opts and opts.help and 0 or 1;
46 end 47 end
47 48
48 local vhost = nameprep(arg[1]); -- TODO loop over arg[]? 49 local vhost = nameprep(arg[1]); -- TODO loop over arg[]?
49 if not vhost then 50 if not vhost then
101 print("ttl " .. tostring(opts.ttl or 60 * 60)); 102 print("ttl " .. tostring(opts.ttl or 60 * 60));
102 103
103 for _, service in ipairs(services) do 104 for _, service in ipairs(services) do
104 local ports = set.new(configured_ports[service]); 105 local ports = set.new(configured_ports[service]);
105 local records = (async.wait_for(existing_srv[service])); 106 local records = (async.wait_for(existing_srv[service]));
106 if opts.reset then 107 if opts.remove or opts.reset then
107 print(("del _%s._tcp.%s IN SRV"):format(service, ihost)); 108 print(("del _%s._tcp.%s IN SRV"):format(service, ihost));
108 else 109 else
109 for _, rr in ipairs(records) do 110 for _, rr in ipairs(records) do
110 if ports:contains(rr.srv.port) and target == nameprep(rr.srv.target):gsub("%.$", "") then 111 if ports:contains(rr.srv.port) and target == nameprep(rr.srv.target):gsub("%.$", "") then
111 ports:remove(rr.srv.port) 112 ports:remove(rr.srv.port)
115 else 116 else
116 print(("del _%s._tcp.%s IN SRV %s"):format(service, ihost, rr)); 117 print(("del _%s._tcp.%s IN SRV %s"):format(service, ihost, rr));
117 end 118 end
118 end 119 end
119 end 120 end
120 for port in ports do print(("add _%s._tcp.%s IN SRV 1 1 %d %s"):format(service, ihost, port, target)); end 121 if not opts.remove then
122 for port in ports do print(("add _%s._tcp.%s IN SRV 1 1 %d %s"):format(service, ihost, port, target)); end
123 end
121 end 124 end
122 125
123 print("show"); 126 print("show");
124 print("send"); 127 print("send");
125 print("answer"); 128 print("answer");