2015-01-03 16:55:03 +00:00
|
|
|
#!/usr/bin/env ruby
|
2015-01-30 08:08:18 +00:00
|
|
|
require "netaddr"
|
|
|
|
require_relative "lib/lxc"
|
2015-01-03 16:55:03 +00:00
|
|
|
|
2015-01-30 08:08:18 +00:00
|
|
|
def update_hetzner_rdns6(user, password, domain, network)
|
|
|
|
api = Lxc::Hetzner.new(user, password)
|
2015-01-03 16:55:03 +00:00
|
|
|
rdns = api.get("/rdns")
|
|
|
|
records = {}
|
|
|
|
rdns.each do |val|
|
|
|
|
rec = val["rdns"]
|
|
|
|
cidr = NetAddr::CIDR.create(rec["ip"])
|
|
|
|
next if cidr.version == 4
|
|
|
|
records[cidr.ip] = rec["ptr"]
|
|
|
|
end
|
2015-01-30 08:08:18 +00:00
|
|
|
network.each do |host, data|
|
2015-01-03 16:55:03 +00:00
|
|
|
cidr = data["ipv6"]
|
|
|
|
next if cidr.nil?
|
|
|
|
ipv6 = NetAddr::CIDR.create(cidr).ip
|
2015-01-30 08:08:18 +00:00
|
|
|
hostname = data["rdns6"] || "#{host}.#{domain}"
|
2015-01-03 16:55:03 +00:00
|
|
|
ptr = records.delete(ipv6)
|
|
|
|
if ptr.nil? or ptr != hostname
|
|
|
|
api.post("/rdns/#{ipv6}", ptr: hostname)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
records.each do |ip, ptr|
|
|
|
|
api.delete("/rnds/#{ip}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-30 08:08:18 +00:00
|
|
|
credentials = File.read(Lxc::CONFIG_ROOT.join("hetzner.key"))
|
2015-01-03 16:55:03 +00:00
|
|
|
user, password = credentials.split(":")
|
2015-01-30 08:08:18 +00:00
|
|
|
registry = Lxc::Registry.new
|
|
|
|
registry.data["zone"] ||= {}
|
|
|
|
domain = registry.data["zone"]["domain"]
|
|
|
|
update_hetzner_rdns6(user, password, domain, registry.data["network"] || {})
|