Project

General

Profile

Download (1.56 KB) Statistics
| Branch: | Tag: | Revision:
bba6b24b Ohad Levy
class SmartProxy
80f8a61f Sam Kottler
def dns_setup(opts)
7e72434b Dominic Cleal
raise "Smart Proxy is not configured to support DNS" unless SETTINGS.dns
case SETTINGS.dns_provider
when "nsupdate"
require 'proxy/dns/nsupdate'
1242cab2 Povilas Daukintis
@server = Proxy::DNS::Nsupdate.new(opts.merge(
:server => SETTINGS.dns_server,
:ttl => SETTINGS.dns_ttl
))
7e72434b Dominic Cleal
when "nsupdate_gss"
require 'proxy/dns/nsupdate_gss'
@server = Proxy::DNS::NsupdateGSS.new(opts.merge(
:server => SETTINGS.dns_server,
1242cab2 Povilas Daukintis
:ttl => SETTINGS.dns_ttl,
7e72434b Dominic Cleal
:tsig_keytab => SETTINGS.dns_tsig_keytab,
:tsig_principal => SETTINGS.dns_tsig_principal
))
d3509e63 Lukas Zapletal
when "virsh"
require 'proxy/dns/virsh'
@server = Proxy::DNS::Virsh.new(opts.merge(
:virsh_network => SETTINGS.virsh_network
))
7e72434b Dominic Cleal
else
log_halt 400, "Unrecognized or missing DNS provider: #{SETTINGS.dns_provider || "MISSING"}"
end
rescue => e
log_halt 400, e
2b9164ca Ohad Levy
end

bba6b24b Ohad Levy
post "/dns/" do
fqdn = params[:fqdn]
2b9164ca Ohad Levy
value = params[:value]
bba6b24b Ohad Levy
type = params[:type]
begin
80f8a61f Sam Kottler
dns_setup({:fqdn => fqdn, :value => value, :type => type})
4a767d09 Paul Kelly
@server.create
b1b32f74 Paul Kelly
rescue Proxy::DNS::Collision => e
fcc0d38b Ohad Levy
log_halt 409, e
bba6b24b Ohad Levy
rescue Exception => e
fcc0d38b Ohad Levy
log_halt 400, e
bba6b24b Ohad Levy
end
2b9164ca Ohad Levy
end
bba6b24b Ohad Levy
delete "/dns/:value" do
case params[:value]
986157bd Nils Caspar
when /\.(in-addr|ip6)\.arpa$/
bba6b24b Ohad Levy
type = "PTR"
value = params[:value]
else
fqdn = params[:value]
end
begin
80f8a61f Sam Kottler
dns_setup({:fqdn => fqdn, :value => value, :type => type})
4a767d09 Paul Kelly
@server.remove
bba6b24b Ohad Levy
rescue => e
fcc0d38b Ohad Levy
log_halt 400, e
bba6b24b Ohad Levy
end
2b9164ca Ohad Levy
end
end