added validation and runtime detection of addition to a second group
This commit is contained in:
28
DDNS.pm
28
DDNS.pm
@ -4,6 +4,9 @@ use strict;
|
||||
use warnings;
|
||||
use Net::DNS;
|
||||
use File::Temp qw/tempfile/;
|
||||
use Memoize;
|
||||
|
||||
memoize('_gethosts');
|
||||
|
||||
our $VERSION = '0.2';
|
||||
|
||||
@ -21,7 +24,7 @@ sub _validateTypeOrDie {
|
||||
my ($t) = @_;
|
||||
|
||||
die "Invalid type"
|
||||
unless ($t =~ /^_(vhosts|hostedservers|pureslave|custom)$/);
|
||||
unless ($t =~ /^_(vhosts|pureslave|custom)$/);
|
||||
}
|
||||
|
||||
sub _fqdn {
|
||||
@ -121,11 +124,34 @@ sub _gethosts {
|
||||
return @vh;
|
||||
}
|
||||
|
||||
# Find the type of domin that $dom is. If we don't find it, return
|
||||
# undef. (The domain $dom ends in a dot; the DNS info we find won't;
|
||||
# hence the concat of the extra "." after the lc.)
|
||||
sub type {
|
||||
my ($this, $dom) = @_;
|
||||
|
||||
_validateOrDie($dom);
|
||||
|
||||
my @vh = $this->get();
|
||||
foreach my $i (@vh) {
|
||||
if (lc($i->{zone})."." eq lc($dom)) {
|
||||
return $i->{type};
|
||||
}
|
||||
}
|
||||
|
||||
# Didn't find it.
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub add {
|
||||
my ($this, $dom, $master, $type) = @_;
|
||||
_validateOrDie($dom);
|
||||
my $fqdn = _fqdn($dom, $type);
|
||||
|
||||
if (my $type = $this->type($dom)) {
|
||||
die "Domain $dom already exists [of type $type]";
|
||||
}
|
||||
|
||||
$this->__docmd("update add $fqdn 60 TXT $master");
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user