Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 50 lines (41 sloc) 1.29 KB
#!/usr/local/bin/ruby
# PowerDNS Coprocess backend
require 'rubygems'
require 'sequel'
DB = Sequel.open 'postgres://postgres:postgres@localhost/powerdns'
$stdin.sync = true
$stdout.sync = true
line = $stdin.gets.chomp
unless line == "HELO\t1"
$stdout.write "FAIL\n"
$stderr.write "Recevied '#{line}'\n"
exit
end
$stdout.write "OK custom backend firing up\n" # print our banner
while(line = $stdin.gets)
$stderr.write "#{$$} Received: #{line}\n"
line.chomp!
arr = line.split(/\t/)
if arr.length < 6
$stdout.write "END\n"
next;
end
type,qname,qclass,qtype,id,ip = line.split(/\t/)
if qname =~ /([\w|\d|-|\*]+)\.somedomain\.com$/
short_name = $1
record = DB[:users].filter(:login => short_name).first
if record
if qtype == 'NS' || qtype == 'ANY'
$stderr.write "#{$$} Sent NS records\n"
$stdout.write "DATA\t#{qname}\t#{qclass}\tNS\t3600\t-1\tns1.somedomain.com\n"
$stdout.write "DATA\t#{qname}\t#{qclass}\tNS\t3600\t-1\tns2.somedomain.com\n"
end
if qtype == 'A' || qtype == 'ANY'
$stderr.write "#{$$} Sent address #{record[:host]} for #{short_name}\n"
$stdout.write "DATA\t#{qname}\t#{qclass}\tA\t3600\t-1\t#{record[:host]}\n"
end
end
end
$stderr.write "#{$$} End of data\n"
$stdout.write "END\n"
end
Something went wrong with that request. Please try again.