pdns-remotebackend 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +8 -1
- data/contrib/example.rb +1 -1
- data/lib/pdns/remotebackend/version.rb +1 -1
- data/lib/pdns/remotebackend.rb +124 -4
- metadata +12 -12
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Pdns/Remotebackend
|
2
2
|
|
3
|
-
This is a helper for PowerDNS remotebackend. It lets you create a backend with less hassle.
|
3
|
+
This is a helper for PowerDNS remotebackend. It lets you create a backend with less hassle. Also supports pipe backend.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -47,6 +47,13 @@ To start a pipe or unix server, do
|
|
47
47
|
Pdns::Remotebackend::Pipe.new(MyHandlerClass).run
|
48
48
|
Pdns::Remotebackend::Unix(MyHandlerClass, { :path => "/path/to/socket"} ).run
|
49
49
|
|
50
|
+
To use it with PowerDNS pipe backend, use
|
51
|
+
|
52
|
+
Pdns::Remotebackend::Pipe.new(MyHandlerClass, { :abi => :pipe }).run
|
53
|
+
Pdns::Remotebackend::Unix(MyHandlerClass, { :path => "/path/to/socket", :abi => :pipe } ).run
|
54
|
+
|
55
|
+
In this mode, it supports do\_lookup and do\_list.
|
56
|
+
|
50
57
|
## Reference
|
51
58
|
|
52
59
|
In addition to stubs for remotebackend, the Pdns::Remotebackend::Handler has following helpers for making records
|
data/contrib/example.rb
CHANGED
@@ -86,7 +86,7 @@ Coefficient: 5lP9IFknvFgaXKCs8MproehHSFhFTWac4557HIn03KrnlGOKDcY6DC/vgu1e42bEZ4J
|
|
86
86
|
]
|
87
87
|
elsif args["qname"] == "example.com" and args["qtype"].downcase == "any"
|
88
88
|
@result = [
|
89
|
-
record("
|
89
|
+
record("example.com", "SOA", "sns.dns.icann.org noc.dns.icann.org 2013012485 7200 3600 1209600 3600"),
|
90
90
|
record("example.com", "NS", "sns.dns.icann.org"),
|
91
91
|
record_prio("example.com", "MX", "test.example.com",10)
|
92
92
|
]
|
data/lib/pdns/remotebackend.rb
CHANGED
@@ -142,11 +142,123 @@ module Pdns
|
|
142
142
|
@options = options
|
143
143
|
end
|
144
144
|
|
145
|
+
# Reads one line at a time from pipebackend, and calls approriate method
|
146
|
+
#
|
147
|
+
# @param [Socket] reader Socket to read from
|
148
|
+
# @param [Socket] writer Socket to write to
|
149
|
+
def mainloop3(reader,writer)
|
150
|
+
h = @handler.new
|
151
|
+
state = :init
|
152
|
+
abi = 1
|
153
|
+
last_soa_name = nil
|
154
|
+
|
155
|
+
reader.each_line do |line|
|
156
|
+
h.log = []
|
157
|
+
h.result = false
|
158
|
+
|
159
|
+
# cannot continue anymore
|
160
|
+
if state == :fail
|
161
|
+
next
|
162
|
+
end
|
163
|
+
|
164
|
+
input = {}
|
165
|
+
line = line.strip
|
166
|
+
if (state == :init)
|
167
|
+
if line.match "HELO[ \t]*([0-9])"
|
168
|
+
abi = $2.to_i
|
169
|
+
# synthesize empty init
|
170
|
+
h.do_initialize(input)
|
171
|
+
|
172
|
+
if h.result == false
|
173
|
+
state = :fail
|
174
|
+
h.log.each do |l|
|
175
|
+
writer.puts "LOG\t#{l}"
|
176
|
+
end
|
177
|
+
writer.puts "FAIL"
|
178
|
+
else
|
179
|
+
writer.puts "OK\tPowerDNS ruby remotebackend version #{Pdns::Remotebackend::VERSION} initialized"
|
180
|
+
state = :main
|
181
|
+
end
|
182
|
+
else
|
183
|
+
writer.puts "FAIL"
|
184
|
+
state = :fail
|
185
|
+
end
|
186
|
+
next
|
187
|
+
end
|
188
|
+
|
189
|
+
# parse input
|
190
|
+
query = line.split /[\t ]+/
|
191
|
+
input["method"] = query[0]
|
192
|
+
if input["method"] == "Q"
|
193
|
+
input["method"] = "lookup"
|
194
|
+
input["parameters"] = {
|
195
|
+
"qname" => query[1], "qclass" => query[2],
|
196
|
+
"qtype" => query[3], "domain_id" => query[4].to_i,
|
197
|
+
"zone_id" => query[4].to_i, "remote" => query[5]
|
198
|
+
}
|
199
|
+
if abi > 1
|
200
|
+
input["parameters"]["local"] = query[6]
|
201
|
+
end
|
202
|
+
if abi > 2
|
203
|
+
input["parameters"]["edns-subnet"] = query[7]
|
204
|
+
end
|
205
|
+
if input["parameters"]["qtype"] == "SOA"
|
206
|
+
last_soa_name = input["parameters"]["qname"]
|
207
|
+
end
|
208
|
+
elsif input["method"] == "AXFR"
|
209
|
+
input["method"] = "list"
|
210
|
+
input["parameters"] = { "zonename" => last_soa_name, "domain_id" => line[1].to_i }
|
211
|
+
else
|
212
|
+
writer.puts "FAIL"
|
213
|
+
next
|
214
|
+
end
|
215
|
+
|
216
|
+
method = "do_#{input["method"]}"
|
217
|
+
# try to call
|
218
|
+
if h.respond_to?(method.to_sym) == true
|
219
|
+
h.send(method, input["parameters"])
|
220
|
+
else
|
221
|
+
writer.puts "FAIL"
|
222
|
+
next
|
223
|
+
end
|
224
|
+
|
225
|
+
if (h.result != false)
|
226
|
+
h.result.each do |r|
|
227
|
+
if r.has_key? :scopemask == false
|
228
|
+
r[:scopemask] = 0
|
229
|
+
end
|
230
|
+
if r.has_key?(:domain_id) == false
|
231
|
+
r[:domain_id] = input["parameters"]["domain_id"]
|
232
|
+
end
|
233
|
+
|
234
|
+
# fix content to contain prio if needed
|
235
|
+
if ["MX", "SRV", "NAPTR"].include? r[:qtype].upcase
|
236
|
+
if r.has_key?("prio")
|
237
|
+
r[:content] = "#{r[:prio].to_i} #{r[:content]}"
|
238
|
+
else
|
239
|
+
r[:content] = "0 #{r[:content]}"
|
240
|
+
end
|
241
|
+
end
|
242
|
+
if (abi < 3)
|
243
|
+
writer.puts "DATA\t#{r[:qname]}\tIN\t#{r[:qtype]}\t#{r[:ttl]}\t#{r[:domain_id]}\t#{r[:content]}"
|
244
|
+
else
|
245
|
+
writer.puts "DATA\t#{r[:scopemask]}\t#{r[:auth]}\t#{r[:qname]}\tIN\t#{r[:qtype]}\t#{r[:ttl]}\t#{r[:domain_id]}\t#{r[:content]}"
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
h.log.each do |l|
|
251
|
+
writer.puts "LOG\t#{l}"
|
252
|
+
end
|
253
|
+
writer.puts "END"
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
145
257
|
# Reads one line at a time from remotebackend, and calls approriate method
|
146
258
|
#
|
147
|
-
# @param [Socket] reader Socket to read from
|
259
|
+
# @param [Socket] reader Socket to read from
|
148
260
|
# @param [Socket] writer Socket to write to
|
149
|
-
def
|
261
|
+
def mainloop4(reader,writer)
|
150
262
|
h = @handler.new
|
151
263
|
|
152
264
|
reader.each_line do |line|
|
@@ -178,7 +290,11 @@ module Pdns
|
|
178
290
|
def run
|
179
291
|
begin
|
180
292
|
STDOUT.sync=true
|
181
|
-
|
293
|
+
if (@options.has_key? :abi and @options[:abi].to_sym == :pipe)
|
294
|
+
mainloop3 STDIN,STDOUT
|
295
|
+
else
|
296
|
+
mainloop4 STDIN,STDOUT
|
297
|
+
end
|
182
298
|
rescue SystemExit, Interrupt
|
183
299
|
end
|
184
300
|
end
|
@@ -190,7 +306,11 @@ module Pdns
|
|
190
306
|
begin
|
191
307
|
Socket.unix_server_loop(@path) do |sock, client_addrinfo|
|
192
308
|
begin
|
193
|
-
|
309
|
+
if (@options.has_key? :abi and @options[:abi].to_sym == :pipe)
|
310
|
+
mainloop3 sock,sock
|
311
|
+
else
|
312
|
+
mainloop4 sock,sock
|
313
|
+
end
|
194
314
|
ensure
|
195
315
|
sock.close
|
196
316
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdns-remotebackend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &7027560 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *7027560
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &7027140 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *7027140
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: yard
|
38
|
-
requirement: &
|
38
|
+
requirement: &7026720 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *7026720
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: redcarpet
|
49
|
-
requirement: &
|
49
|
+
requirement: &7075660 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *7075660
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: json
|
60
|
-
requirement: &
|
60
|
+
requirement: &7075240 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *7075240
|
69
69
|
description: This gem provides a base class and helpers for writing remotebackend
|
70
70
|
servers for pipe/unix/. It is intended to make using remotebackend easier. For http
|
71
71
|
support, see pdns-remotebackend-http.
|