pureslaves now work too
This commit is contained in:
71
DDNS.pm
71
DDNS.pm
@ -5,7 +5,7 @@ use warnings;
|
||||
use Net::DNS;
|
||||
use File::Temp qw/tempfile/;
|
||||
|
||||
our $VERSION = '0.1';
|
||||
our $VERSION = '0.2';
|
||||
|
||||
sub new {
|
||||
my $me = shift;
|
||||
@ -17,10 +17,20 @@ sub new {
|
||||
}, $me;
|
||||
}
|
||||
|
||||
sub _fqdn {
|
||||
my ($dom) = @_;
|
||||
sub _validateTypeOrDie {
|
||||
my ($t) = @_;
|
||||
|
||||
return $dom . "_vhosts.private.invalid.";
|
||||
die "Invalid type"
|
||||
unless ($t =~ /^_(vhosts|hostedservers|pureslave|custom)$/);
|
||||
}
|
||||
|
||||
sub _fqdn {
|
||||
my ($dom, $type) = @_;
|
||||
$type ||= '_vhosts';
|
||||
|
||||
_validateTypeOrDie($type);
|
||||
|
||||
return $dom . "$type.private.invalid.";
|
||||
}
|
||||
|
||||
sub _validateOrDie {
|
||||
@ -36,7 +46,7 @@ sub _lookupOrDie {
|
||||
my ($dom) = @_;
|
||||
|
||||
_validateOrDie($dom);
|
||||
my $fqdn = _fqdn($dom);
|
||||
my $fqdn = _fqdn($dom, '_vhosts');
|
||||
|
||||
my $res = Net::DNS::Resolver->new;
|
||||
my $query = $res->query($fqdn, "TXT");
|
||||
@ -77,29 +87,11 @@ sub __docmd {
|
||||
unlink $filename;
|
||||
}
|
||||
|
||||
# Add a new vhost domain by adding a DDNS record that the slaves will notice.
|
||||
sub addvhost {
|
||||
my ($this, $dom, $master) = @_;
|
||||
|
||||
_validateOrDie($dom);
|
||||
my $fqdn = _fqdn($dom);
|
||||
sub _gethosts {
|
||||
my ($this, $type) = @_;
|
||||
|
||||
$this->__docmd("update add $fqdn 60 TXT $master");
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
sub delvhost {
|
||||
my ($this, $dom) = @_;
|
||||
|
||||
_lookupOrDie($dom);
|
||||
my $fqdn = _fqdn($dom);
|
||||
|
||||
$this->__docmd("update delete $fqdn TXT");
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
sub getvhosts {
|
||||
my ($this) = @_;
|
||||
_validateTypeOrDie($type);
|
||||
|
||||
my $fh;
|
||||
open($fh, "dig -t AXFR \@127.0.0.1 private.invalid. |")
|
||||
@ -108,7 +100,7 @@ sub getvhosts {
|
||||
my @vh;
|
||||
|
||||
while (<$fh>) {
|
||||
if (/^(\S+)._vhosts.private.invalid.\s+\d+\s+IN\s+TXT\s+\"(.+)\"$/) {
|
||||
if (/^(\S+).$type.private.invalid.\s+\d+\s+IN\s+TXT\s+\"(.+)\"$/) {
|
||||
push (@vh, { zone => $1,
|
||||
master => $2 });
|
||||
}
|
||||
@ -117,6 +109,31 @@ sub getvhosts {
|
||||
return @vh;
|
||||
}
|
||||
|
||||
sub add {
|
||||
my ($this, $dom, $master, $type) = @_;
|
||||
_validateOrDie($dom);
|
||||
my $fqdn = _fqdn($dom, $type);
|
||||
|
||||
$this->__docmd("update add $fqdn 60 TXT $master");
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
sub del {
|
||||
my ($this, $dom, $type) = @_;
|
||||
|
||||
_lookupOrDie($dom);
|
||||
my $fqdn = _fqdn($dom, $type);
|
||||
|
||||
$this->__docmd("update delete $fqdn TXT");
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
sub get {
|
||||
my ($this, $type) = @_;
|
||||
|
||||
return $this->_gethosts($type);
|
||||
}
|
||||
|
||||
sub cleanup {
|
||||
my ($this) = @_;
|
||||
# Merge the .jnl file in with the domain file
|
||||
|
||||
Reference in New Issue
Block a user