#
# Who I should reply as.
-$me="autodns\@earth.li";
+$me = "autodns\@earth.li";
# Who replies should be CCed to.
-$ccreply="noodles\@earth.li";
+$ccreply = "noodles\@earth.li";
# Where to look for zones we're already hosting.
-@cfgfiles=("/etc/bind/named.conf",
+@cfgfiles = ("/etc/bind/named.conf",
"/etc/bind/named.secondary.conf");
# The file we should add/delete domains from.
-$conffile="/etc/bind/named.secondary.conf";
+$conffile = "/etc/bind/named.secondary.conf";
# The file that contains details of the authorized users.
-$usersfile="/etc/bind/autodns.users";
+$usersfile = "/etc/bind/autodns.users";
# Base file name to for list of users domains.
-$domainlistroot="/etc/bind/domains.";
+$domainlistroot = "/etc/bind/domains.";
# The lockfile we use to ensure we have exclusive access to the
# $domainlistroot$user files and $conffile.
-$lockfile="/etc/bind/autodns.lck";
+$lockfile = "/etc/bind/autodns.lck";
# The command to reload the nameserver domains list.
-$reload_command="sudo ndc reconfig 2>&1";
+$reload_command = "sudo ndc reconfig 2>&1";
# When we consider a signature to have expired and so to be rejected.
# Intended to help prevent reply attacks. Value is in seconds and the
use IPC::Open3;
use MIME::Parser;
-$ENV{'PATH'}="/usr/local/bin:/usr/bin:/bin:/usr/sbin";
+$ENV{'PATH'} = "/usr/local/bin:/usr/bin:/bin:/usr/sbin";
my ($from, $subject, $gpguser, $gpggood, $priv);
my ($user, $server, $inprocess, $delcount, $addcount);
use vars qw($me $ccreply $conffile $domainlistroot @cfgfiles $usersfile
$lockfile $reload_command $expiry $zonefiledir);
-$VERSION="0.0.8";
+$VERSION = "0.0.8";
#
# Load our config
close(LOCKFILE);
unlink($lockfile);
-# die $message;
exit;
}
foreach (<CONFIGFILE>) {
if (/^([^#.]+):$gpguser:(\d+):(.+)$/) {
- $user=$1;
- $privilege=$2;
- $server=$3;
+ $user = $1;
+ $privilege = $2;
+ $server = $3;
chomp $user;
chomp $privilege;
chomp $server;
if ($user !~ /^.+$/) {
close(CONFIGFILE);
- fatalerror("Error in user configuration file: Can't get username.\n");
+ fatalerror("Error in user configuration ".
+ "file: Can't get username.\n");
}
if ($server !~ /^(\d{1,3}\.){3}\d{1,3}$/) {
$server =~ s/\d\.]//g;
close(CONFIGFILE);
- fatalerror("Error in user configuration file: Invalid primary server IP address ($server)\n");
+ fatalerror("Error in user configuration ".
+ "file: Invalid primary server IP ".
+ "address ($server)\n");
exit;
}
}
close(USERFILE);
}
-$delcount=$addcount=$inprocess=0;
+$delcount = $addcount = $inprocess = 0;
# Read in the mail from stdin.
-@MAIL=<>;
+@MAIL = <>;
$subject = "Reply from AutoDNS";
# Now lets try to find out who it's from.
foreach (@MAIL) {
if (/^$/) { last; }
- if (/^From: (.*)/i) { $from=$1; chomp $from;}
- if (/^Subject:\s+(re:)?(.*)$/i) { $subject="Re: ".$2 if ($2);}
+ if (/^From: (.*)/i) { $from = $1; chomp $from;}
+ if (/^Subject:\s+(re:)?(.*)$/i) { $subject = "Re: ".$2 if ($2);}
}
if ((! defined($from)) || $from =~ /^$/ ) {
die "From address is mailer-daemon, ignoring.";
}
-if (! defined($subject)) { $subject="Reply from AutoDNS"; };
+if (! defined($subject)) { $subject = "Reply from AutoDNS"; };
# We've got a from address. Start a reply.
#
# Make sure locale is set to C so we get messages in English as we expect.
#
-$ENV{'LC_ALL'}="C";
+$ENV{'LC_ALL'} = "C";
if ($entity->parts) {
# MIME
my ($got_sig, $got_text) = (0, 0);
- my ($sig_name,$sig_fh,$text_name,$text_fh);
- ($sig_fh, $sig_name) = tempfile();
- ($text_fh, $text_name) = tempfile();
+ my ($sig_fh, $sig_name) = tempfile();
+ my ($text_fh, $text_name) = tempfile();
foreach my $subent ($entity->parts) {
if ($subent->effective_type eq "text/plain") {
close GPGIN;
- @GPGERROR=<GPGERR>;
- my @GPGOUTPUT=<GPGOUT>;
+ @GPGERROR = <GPGERR>;
+ my @GPGOUTPUT = <GPGOUT>;
close GPGERR;
close GPGOUT;
waitpid $pid, 0;
close GPGIN;
# And grab what it has to say.
- @GPGERROR=<GPGERR>;
- @COMMANDS=<GPGOUT>;
+ @GPGERROR = <GPGERR>;
+ @COMMANDS = <GPGOUT>;
@COMMANDS = split /\n/,$entity->bodyhandle->as_string;
close GPGERR;
close GPGOUT;
chomp;
if (/Signature made (.*) using.*ID (.*)$/) {
$sigtime = str2time($1);
- $gpguser=$2;
+ $gpguser = $2;
} elsif (/error/) {
$gpggood = 0;
print REPLY "Some errors ocurred\n";
# Empty line, so ignore it.
#
} elsif (/^END$/) {
- $inprocess=0;
+ $inprocess = 0;
} elsif (/^BEGIN$/) {
- $inprocess=1;
+ $inprocess = 1;
} elsif ($inprocess && /^ADD\s+(.*)$/) {
$domain = $1;
$domain =~ tr/[A-Z]/[a-z]/;
if (! valid_domain($domain)) {
$domain =~ s/[-a-z0-9.]//g;
- print REPLY "Invalid character(s) in domain name: $domain\n";
+ print REPLY "Invalid character(s) in domain name:",
+ " $domain\n";
} elsif (defined($zones{$domain}) && $zones{$domain}) {
print REPLY "We already secondary $domain\n";
} else {
print REPLY "Adding domain $domain\n";
- $zones{$domain}=1;
+ $zones{$domain} = 1;
my $df = $domain;
$df =~ tr,/,:,;
$domain =~ tr/[A-Z]/[a-z]/;
if (!valid_domain($domain)) {
$domain =~ s/[-a-z0-9.]//g;
- print REPLY "Invalid character(s) in domain name: $domain\n";
+ print REPLY "Invalid character(s) in domain name:",
+ " $domain\n";
} elsif (!defined($zones{$domain}) || !$zones{$domain}) {
print REPLY "$domain does not exist!\n";
} else {
print REPLY "Deleting domain $domain\n";
- my (@newcfg,$found);
+ my (@newcfg, $found);
open (DOMAINLIST, "<$domainlistroot$user") or
- fatalerror("Couldn't open file $domainlistroot$user for reading: $!.\n");
+ fatalerror("Couldn't open file ".
+ $domainlistroot.$user.
+ " for reading: $!.\n");
my @cfg = <DOMAINLIST>;
close(DOMAINLIST);
@newcfg = grep { ! /^$domain$/ } @cfg;
if (scalar @cfg == scalar @newcfg) {
- print REPLY "Didn't find $domain in $domainlistroot$user!\n";
- print REPLY "You are only allowed to delete your own domains that exist.\n";
+ print REPLY "Didn't find $domain in ",
+ "$domainlistroot$user!\n";
+ print REPLY "You are only allowed to delete",
+ " your own domains that exist.\n";
next;
}
open (DOMAINLIST, ">$domainlistroot$user") or
- fatalerror("Couldn't open file $domainlistroot$user for writing: $!.\n");
+ fatalerror("Couldn't open file ".
+ $domainlistroot.$user.
+ " for writing: $!.\n");
print DOMAINLIST @newcfg;
close DOMAINLIST;
- $found=0;
- @newcfg=();
+ $found = 0;
+ @newcfg = ();
open (DOMAINSFILE, "<$conffile") or
- fatalerror("Couldn't open file $conffile for reading: $!\n");
+ fatalerror("Couldn't open file $conffile for".
+ " reading: $!\n");
{
local $/ = ''; # eat whole paragraphs
while (<DOMAINSFILE>) {
unless (/^\s*zone\s+"$domain"/) {
push @newcfg, $_;
} else {
- $found=1;
+ $found = 1;
if ($newcfg[-1] =~ /^###/) {
# remove comment and \n
pop @newcfg;
} # end of paragraph eating
if (!$found) {
- print REPLY "Didn't find $domain in $conffile!\n";
+ print REPLY "Didn't find $domain in",
+ " $conffile!\n";
next;
}
open (DOMAINSFILE, ">$conffile") or
- fatalerror("Couldn't open $conffile for writing: $!\n");
+ fatalerror("Couldn't open $conffile for".
+ " writing: $!\n");
print DOMAINSFILE @newcfg;
close DOMAINSFILE;
$delcount++;
close GPGIN;
# And grab what it has to say.
- @GPGERROR=<GPGERR>;
- my @GPGOUTPUT=<GPGOUT>;
+ @GPGERROR = <GPGERR>;
+ my @GPGOUTPUT = <GPGOUT>;
close GPGERR;
close GPGOUT;
waitpid $pid, 0;
print REPLY "ADDUSER parameter error.\n";
}
} elsif ($inprocess && /^HELP$/) {
- print REPLY "In order to use the service, you will need to send GPG signed\n";
- print REPLY "messages.\n\n";
- print REPLY "The format of the text in these messages is important, as they represent\n";
- print REPLY "commands to autodns. Commands are formatted one per line, and enclosed\n";
- print REPLY "by \"BEGIN\" and \"END\" commands (without the quotes).\n";
- print REPLY "Current valid commands are:\n";
- print REPLY "BEGIN - begin processing.\n";
- print REPLY "END - end processing.\n";
- print REPLY "HELP - display this message.\n";
- print REPLY "LIST - show all the zones currently held by you.\n";
- print REPLY "ADD <domain> - adds the domain <domain> for processing.\n";
- print REPLY "DEL <domain> - removes the domain <domain> if you own it.\n";
+ print REPLY <<EOF;
+In order to use the service, you will need to send GPG signed messages.
+The format of the text in these messages is important, as they represent
+commands to autodns. Commands are formatted one per line, and enclosed
+by "BEGIN" and "END" commands (without the quotes).
+
+Current valid commands are:
+
+BEGIN - begin processing.
+END - end processing.
+HELP - display this message.
+LIST - show all the zones currently held by you.
+ADD <domain> - adds the domain <domain> for processing.
+DEL <domain> - removes the domain <domain> if you own it.
+EOF
if (($priv & 1) == 1) {
print REPLY "MASTER <ip address> - set the nameserver".
" we should slave off for subsequent ADD\ncommands.\n";