Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (42 sloc) 1.35 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
$stderr.write "Less than 6 args received.\n"
$stdout.write "END\n"
next;
end
type,qname,qclass,qtype,id,ip = line.split(/\t/)
#$stderr.write("qname: #{qname}\n")
if qname =~ /^(staging\.[\w|\d|-|\*]+\.somedomain\.com)$/
dn = $1
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 == 'CNAME' || qtype == 'ANY'
$stderr.write "#{$$} Sent staging address for #{dn}\n"
$stdout.write "DATA\t#{qname}\t#{qclass}\tCNAME\t3600\t-1\tstaging.somedomain.com\n"
end
elsif qname =~ /([\w|\d|-|\*]+)\.somedomain\.com$/
# like example 2
end
$stderr.write "#{$$} End of data\n"
$stdout.write "END\n"
end
Jump to Line
Something went wrong with that request. Please try again.