class PowerDNS::Pipe
DnsPipe is an abstraction of the Powerdns pipe backend protocol. doc.powerdns.com/backends-detail.html
It's dead simple to use, see the README for examples
Written by John Leach <john@johnleach.co.uk>
Attributes
err[R]
input[R]
output[R]
version_range[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/powerdns_pipe.rb 51 def initialize(options = {}) 52 options = { 53 :input => STDIN, 54 :output => STDOUT, 55 :err => STDERR, 56 :version_range => 1..2, 57 :banner => "Ruby PowerDNS::Pipe" 58 }.merge options 59 60 @input = options[:input] 61 @output = options[:output] 62 @err = options[:err] 63 @version_range = options[:version_range] 64 @banner = options[:banner] 65 end
Public Instance Methods
run!(&query_processor)
click to toggle source
# File lib/powerdns_pipe.rb 67 def run!(&query_processor) 68 while (line = input.readline) do 69 process_line line, query_processor 70 end 71 rescue EOFError 72 err.write "EOF, terminating loop\n" 73 end
Private Instance Methods
process_helo(q, query_processor)
click to toggle source
# File lib/powerdns_pipe.rb 90 def process_helo(q, query_processor) 91 if version_range === (q.name.to_i rescue -1) 92 respond "OK", banner 93 else 94 respond "FAIL", banner 95 end 96 end
process_line(line, query_processor)
click to toggle source
# File lib/powerdns_pipe.rb 78 def process_line(line, query_processor) 79 q = Question.new *line.chomp.split("\t") 80 qtypes = { 81 "HELO" => :process_helo, 82 "Q" => :process_query, 83 "AXFR" => :process_query, 84 "PING" => :process_ping 85 } 86 87 self.send(qtypes.fetch(q.tag, :process_unknown), q, query_processor) 88 end
process_ping(q, query_processor)
click to toggle source
# File lib/powerdns_pipe.rb 115 def process_ping(q, query_processor) 116 respond "END" 117 end
process_query(q, query_processor)
click to toggle source
# File lib/powerdns_pipe.rb 98 def process_query(q, query_processor) 99 answer = Answer.new(self, q) 100 begin 101 answer.instance_eval &query_processor 102 respond "END" 103 rescue StandardError => e 104 respond "LOG", "Error: #{e.class}: #{e.message}" 105 respond "FAIL" 106 end 107 108 end
process_unknown(q, query_processor)
click to toggle source
# File lib/powerdns_pipe.rb 110 def process_unknown(q, query_processor) 111 respond "LOG", "Unknown Question received: #{q}" 112 respond "FAIL" 113 end
respond(*args)
click to toggle source
# File lib/powerdns_pipe.rb 119 def respond(*args) 120 output.write(args.join("\t") + "\n") 121 output.flush 122 end