Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 56 lines (47 sloc) 1.456 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#!/usr/bin/env 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 =~ /([\w|\d|-|\*]+)\.somedomain\.com$/
    short_name = $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 == 'A' || qtype == 'ANY'
      address = if short_name =~ /^[a-m]/
        "192.1.1.1"
      elsif short_name =~ /^[n-z]/
        "192.1.1.2"
      else
        "80.10.1.40"
      end
      $stderr.write "#{$$} Sent address #{address} for #{short_name}\n"
      $stdout.write "DATA\t#{qname}\t#{qclass}\tA\t3600\t-1\t#{address}\n"
    end
  end

  $stderr.write "#{$$} End of data\n"
  $stdout.write "END\n"
end
Something went wrong with that request. Please try again.