forked from ZaphodB/powerdns-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatchall.pl
executable file
·66 lines (64 loc) · 1.63 KB
/
catchall.pl
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
#!/usr/bin/perl -w
# PowerDNS Coprocess backend
# in pdns.conf use:
# launch=pipe
# pipe-command=/path/to/catchall.pl
# pipe-timeout=1000
# pipe-abi-version=2
use strict;
use warnings;
$|=1; # no buffering
my $webserverip="4.3.2.1";
my $nameserver="ns1.example.com";
my $hostmaster="hostmaster.example.com";
my $line=<>;
chomp($line);
unless($line eq "HELO\t2") {
print "FAIL\n";
<>;
exit;
}
print "OK Catchall fireing up!\n"; # print our banner
my @last_query=();
my ($type,$qname,$qclass,$qtype,$id,$ip,$lip);
LINE: while(<>)
{
chomp();
my @arr=split(/\t/);
if((defined $arr[0])&&($arr[0] eq "PING")) {
print "LOG Catchall is still alife!\n";
print "END\n";
next LINE;
}
if((defined $arr[0])&&($arr[0] eq "AXFR")) {
print "END\n";
next LINE;
}
if((@arr)&&(@arr<7)) {
print "LOG PowerDNS sent too few arguments, wrong ABI Version 1 in config?\n";
print "FAIL\n";
next LINE;
}
($type,$qname,$qclass,$qtype,$id,$ip,$lip)=@arr;
if((defined $type)&&(defined $qname)&&(defined $qclass)&&(defined $qtype)&&(defined $id)&&(defined $ip)&&(defined $lip)) {
} else {
print "FAIL\n";
next LINE;
}
if($type ne "Q") {
print "END\n";
next LINE;
}
if((defined $type)&&(defined $qname)&&(defined $qclass)&&(defined $qtype)&&(defined $id)&&(defined $ip)&&(defined $lip)) {
if(($qtype eq "SOA")||($qtype eq "ANY")) {
print "DATA $qname $qclass SOA 3600 -1 $nameserver $hostmaster 2008080300 1800 3600 604800 3600\n";
}
if(($qtype eq "A")||($qtype eq "ANY")) {
print "DATA $qname IN A 3600 1 $webserverip\n";
}
} else {
print "LOG ERROR - some parts are missing - this should not happen!\n";
}
print "END\n";
next LINE;
}