File: backend-v3.pl

package info (click to toggle)
pdns 5.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 10,824 kB
  • sloc: cpp: 101,247; sh: 5,616; makefile: 2,318; sql: 860; ansic: 675; python: 635; yacc: 245; perl: 161; lex: 131
file content (68 lines) | stat: -rwxr-xr-x 2,057 bytes parent folder | download
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
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/perl -w
# sample PowerDNS Coprocess backend with edns-client-subnet support
#

use strict;


$|=1;					# no buffering

my $line=<>;
chomp($line);

unless($line eq "HELO\t3" ) {
	print "FAIL\n";
	print STDERR "Received unexpected '$line', wrong ABI version?\n";
	<>;
	exit;
}
print "OK	Sample backend firing up\n";	# print our banner

while(<>)
{
	print STDERR "$$ Received: $_";
	chomp();
	my @arr=split(/\t/);
	if(@arr < 8) {
		print "LOG	PowerDNS sent unparseable line\n";
		print "FAIL\n";
		next;
	}

	my ($type,$qname,$qclass,$qtype,$id,$ip,$localip,$ednsip)=split(/\t/);
	my $bits=21;
	my $auth = 1;

	if(($qtype eq "SOA" || $qtype eq "ANY") && $qname eq "example.com") {
		print STDERR "$$ Sent SOA records\n";
		print "DATA	$bits	$auth	$qname	$qclass	SOA	3600	-1	ahu.example.com ns1.example.com 2008080300 1800 3600 604800 3600\n";
	}
	if(($qtype eq "NS" || $qtype eq "ANY") && $qname eq "example.com") {
		print STDERR "$$ Sent NS records\n";
		print "DATA	$bits	$auth	$qname	$qclass	NS	3600	-1	ns1.example.com\n";
		print "DATA	$bits	$auth	$qname	$qclass	NS	3600	-1	ns2.example.com\n";
	}
	if(($qtype eq "TXT" || $qtype eq "ANY") && $qname eq "example.com") {
		print STDERR "$$ Sent TXT records\n";
		print "DATA	$bits	$auth	$qname	$qclass	TXT	3600	-1	\"hallo allemaal!\"\n";
	}
	if(($qtype eq "A" || $qtype eq "ANY") && $qname eq "webserver.example.com") {
		print STDERR "$$ Sent A records\n";
		print "DATA	$bits	$auth	$qname	$qclass	A	3600	-1	1.2.3.4\n";
		print "DATA	$bits	$auth	$qname	$qclass	A	3600	-1	1.2.3.5\n";
		print "DATA	$bits	$auth	$qname	$qclass	A	3600	-1	1.2.3.6\n";
	}
	if(($qtype eq "CNAME" || $qtype eq "ANY") && $qname eq "www.example.com") {
		print STDERR "$$ Sent CNAME records\n";
		print "DATA	$bits	$auth	$qname	$qclass	CNAME	3600	-1	webserver.example.com\n";
	}
	if(($qtype eq "MX" || $qtype eq "ANY") && $qname eq "example.com") {
		print STDERR "$$ Sent MX records\n";
		print "DATA	$bits	$auth	$qname	$qclass	MX	3600	-1	25	smtp.powerdns.com\n";
	}


	print STDERR "$$ End of data\n";
	print "END\n";
}