Skip to content

Instantly share code, notes, and snippets.

@jimbocoder
Created February 10, 2013 20:08
Show Gist options
  • Save jimbocoder/4750880 to your computer and use it in GitHub Desktop.
Save jimbocoder/4750880 to your computer and use it in GitHub Desktop.
powerdns pipe backend to do unorthodox wildcard A records, with a little mc hammer
#!/usr/bin/perl -w
#
# Jim's evil wildcard dns backend for front gate tickets
#
use strict;
$|=1; # pump a little bit and let em know it's goin on (no output buffering)
my $line=<>;
chomp($line);
unless($line eq "HELO\t3" ) {
print "FAIL\n";
print STDERR "Received unexpected '$line', make sure to use ABI protocol version 3\n";
<>;
exit; # Not legit, must quit
}
print "OK FGT webdev-server wildcard backend firing up\n"; # STOP! banner time
while(<>) # Now why would I ever stop doing this
{
print STDERR "$$ Received: $_";
chomp();
my @arr=split(/\t/);
if(@arr < 8) {
print "LOG PowerDNS sent unparseable line\n"; # others makin' records that just don't hit
print "FAIL\n";
next; # CANT TOUCH THIS
}
my ($type,$qname,$qclass,$qtype,$id,$ip,$localip,$ednsip)=split(/\t/);
my $bits=21;
my $auth = 1;
if(($qtype eq "SOA" || $qtype eq "ANY")) {
if ( $qname =~ /frontgatetickets\.com\.?$/ ) {
print STDERR "$$ Sent SOA records\n";
print "DATA $bits $auth $qname $qclass SOA 3600 -1 tech.frontgatetickets.com ns1.frontgatetickets.com 2008080300 1800 3600 604800 3600\n";
} elsif ( $qname =~ /fgt\.com\.?$/ ) {
print STDERR "$$ Sent SOA records\n";
print "DATA $bits $auth $qname $qclass SOA 3600 -1 tech.fgt.com ns1.fgt.com 2008080300 1800 3600 604800 3600\n";
}
}
if(($qtype eq "A" || $qtype eq "ANY")) {
#if ( $qname =~ /(?:jim|patrick)\.dev\..*\.(?:fgt|frontgatetickets)\.com/ ) {
if ( $qname =~ /.*\.dev\..*\.frontgatetickets\.com/ ) {
print STDERR "$$ Sent A records\n";
print "DATA $bits $auth $qname $qclass A 3600 -1 6.6.6.6\n";
} else {
print STDERR "$$ NO match\n";
}
}
print "END\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment