Compare commits
5 Commits
1519c653aa
...
v1.0-rc1
Author | SHA1 | Date | |
---|---|---|---|
4427f42e63 | |||
401db7bda8 | |||
dc1a90014a | |||
07dc0d75c5 | |||
965c94a223 |
@ -2,3 +2,6 @@ FROM alpine
|
|||||||
# docker build -t fooflington/mythic-beasts-dns .
|
# docker build -t fooflington/mythic-beasts-dns .
|
||||||
LABEL maintainer="Matthew Slowe <foo@mafoo.org.uk>"
|
LABEL maintainer="Matthew Slowe <foo@mafoo.org.uk>"
|
||||||
RUN apk --no-cache add perl perl-yaml perl-lwp-protocol-https perl-json perl-uri perl-yaml-tiny perl-www-form-urlencoded
|
RUN apk --no-cache add perl perl-yaml perl-lwp-protocol-https perl-json perl-uri perl-yaml-tiny perl-www-form-urlencoded
|
||||||
|
|
||||||
|
COPY manage-dns.pl /docker-entry-point.pl
|
||||||
|
ENTRYPOINT ["perl", "/docker-entry-point.pl"]
|
40
manage-dns.pl
Normal file → Executable file
40
manage-dns.pl
Normal file → Executable file
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env perl -w
|
#!/usr/bin/perl
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
use warnings;
|
||||||
use LWP::UserAgent;
|
use LWP::UserAgent;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
@ -32,12 +33,12 @@ sub _notice {
|
|||||||
my %supported_types = (
|
my %supported_types = (
|
||||||
A => "yes",
|
A => "yes",
|
||||||
AAAA => "yes",
|
AAAA => "yes",
|
||||||
CAA => "not yet implemented",
|
CAA => "yes",
|
||||||
CNAME => "yes",
|
CNAME => "yes",
|
||||||
DNAME => "not yet implemented",
|
DNAME => "yes",
|
||||||
MX => "yes",
|
MX => "yes",
|
||||||
NS => "yes",
|
NS => "yes",
|
||||||
PTR => "not yet implemented",
|
PTR => "yes",
|
||||||
SSHFP => "not yet implemented",
|
SSHFP => "not yet implemented",
|
||||||
SRV => "yes",
|
SRV => "yes",
|
||||||
TLSA => "not yet implemented",
|
TLSA => "not yet implemented",
|
||||||
@ -119,6 +120,19 @@ sub format_record($$$$) {
|
|||||||
my ($pri, $data) = split(/\s+/, $value);
|
my ($pri, $data) = split(/\s+/, $value);
|
||||||
$record->{mx_priority} = $pri;
|
$record->{mx_priority} = $pri;
|
||||||
$record->{data} = $data;
|
$record->{data} = $data;
|
||||||
|
} elsif ($type eq 'SRV') {
|
||||||
|
# pri weight port data
|
||||||
|
my ($pri, $weight, $port, $data) = split(/\s+/, $value);
|
||||||
|
$record->{srv_priority} = $pri;
|
||||||
|
$record->{srv_weight} = $weight;
|
||||||
|
$record->{srv_port} = $port;
|
||||||
|
$record->{data} = $data;
|
||||||
|
} elsif ($type eq 'CAA') {
|
||||||
|
my ($flags, $property, $data) = split(/\s+/, $value);
|
||||||
|
$record->{caa_flags} = $flags;
|
||||||
|
$record->{caa_property} = $property;
|
||||||
|
$record->{caa_tag} = $property;
|
||||||
|
$record->{data} = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $record;
|
return $record;
|
||||||
@ -128,6 +142,19 @@ sub reformat_data($$) {
|
|||||||
my ($type, $data) = @_;
|
my ($type, $data) = @_;
|
||||||
if($type eq 'MX') {
|
if($type eq 'MX') {
|
||||||
return sprintf('%d %s', $data->{mx_priority}, $data->{data});
|
return sprintf('%d %s', $data->{mx_priority}, $data->{data});
|
||||||
|
} elsif($type eq 'SRV') {
|
||||||
|
return sprintf('%d %d %d %s',
|
||||||
|
$data->{srv_priority},
|
||||||
|
$data->{srv_weight},
|
||||||
|
$data->{srv_port},
|
||||||
|
$data->{data}
|
||||||
|
);
|
||||||
|
} elsif($type eq 'CAA') {
|
||||||
|
return sprintf('%d %s %s',
|
||||||
|
$data->{caa_flags},
|
||||||
|
$data->{caa_property} || $data->{caa_tag},
|
||||||
|
$data->{data}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data->{data};
|
return $data->{data};
|
||||||
@ -136,7 +163,8 @@ sub reformat_data($$) {
|
|||||||
sub check_and_update_record($$$$$) {
|
sub check_and_update_record($$$$$) {
|
||||||
my ($zone, $data, $type, $host, $value) = @_;
|
my ($zone, $data, $type, $host, $value) = @_;
|
||||||
if(my $err = is_unsupported($type)) {
|
if(my $err = is_unsupported($type)) {
|
||||||
die ("Unable to process $host $type: $err");
|
warn ("WARNING: Unable to process $host $type: $err");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# _info("Considering %s %s %s", $host, $type, $value);
|
# _info("Considering %s %s %s", $host, $type, $value);
|
||||||
@ -161,6 +189,7 @@ sub check_and_update_record($$$$$) {
|
|||||||
# Create new record
|
# Create new record
|
||||||
my $new = format_record($zone, $type, $host, $value);
|
my $new = format_record($zone, $type, $host, $value);
|
||||||
_notice("Created new record: %s %s %s", $host, $type, $value);
|
_notice("Created new record: %s %s %s", $host, $type, $value);
|
||||||
|
_debug($new);
|
||||||
my $res = $ua->post(
|
my $res = $ua->post(
|
||||||
$url,
|
$url,
|
||||||
"Content-Type" => "application/json",
|
"Content-Type" => "application/json",
|
||||||
@ -215,6 +244,7 @@ foreach my $z (keys %{$in->[0]->{zones}}) {
|
|||||||
unless (defined $seen{$record}) {
|
unless (defined $seen{$record}) {
|
||||||
# _info("Considering %s %s", $record->{host}, $record->{type});
|
# _info("Considering %s %s", $record->{host}, $record->{type});
|
||||||
my $skip;
|
my $skip;
|
||||||
|
$skip = 1 if is_unsupported($record->{type});
|
||||||
if ($in->[0]->{ignore}->{$z}->{$record->{host}}) {
|
if ($in->[0]->{ignore}->{$z}->{$record->{host}}) {
|
||||||
# check if type is specified
|
# check if type is specified
|
||||||
if(keys %{$in->[0]->{ignore}->{$z}->{$record->{host}}}) {
|
if(keys %{$in->[0]->{ignore}->{$z}->{$record->{host}}}) {
|
||||||
|
Reference in New Issue
Block a user