2014-05-08 00:45:12 +02:00
|
|
|
use v5.14;
|
|
|
|
package app::zone::nsdc_interface;
|
|
|
|
use Moose;
|
|
|
|
|
|
|
|
has [ qw/data/ ] => qw/is ro required 1/;
|
|
|
|
|
|
|
|
# on suppose que tout est déjà mis à jour dans le fichier
|
2014-05-08 14:35:06 +02:00
|
|
|
sub reload_sec {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
$self->_reload_conf();
|
|
|
|
|
|
|
|
system('ssh -p ' . $self->data->sshportsec . ' '
|
|
|
|
. $self->data->sshusersec . '@' . $self->data->sshhostsec
|
2014-05-08 17:44:55 +02:00
|
|
|
. ' "sudo nsdc rebuild 2>/dev/null 1>/dev/null && sudo nsdc restart 2>/dev/null 1>/dev/null "');
|
2014-05-08 00:45:12 +02:00
|
|
|
}
|
|
|
|
|
2014-05-08 14:35:06 +02:00
|
|
|
sub _reload_conf {
|
|
|
|
my ($self) = @_;
|
2014-05-08 00:45:12 +02:00
|
|
|
|
|
|
|
# get the file
|
|
|
|
# modify the file
|
|
|
|
# push the file
|
|
|
|
my $f = "/tmp/nsd.conf";
|
|
|
|
|
|
|
|
_scp_get($self->data->sshusersec
|
|
|
|
, $self->data->sshhostsec
|
|
|
|
, $self->data->sshportsec
|
|
|
|
, "/etc/nsd3/nsd.conf"
|
|
|
|
, $f);
|
|
|
|
|
|
|
|
my %slavedzones = $self->data->get_all_domains();
|
|
|
|
|
|
|
|
my $data = read_file($f);
|
|
|
|
my $debut = "## BEGIN_GENERATED";
|
2014-05-08 14:35:06 +02:00
|
|
|
my $nouveau = '';
|
2014-05-08 00:45:12 +02:00
|
|
|
|
|
|
|
for(keys %slavedzones) {
|
2014-05-08 14:35:06 +02:00
|
|
|
$nouveau .= "zone:\n\n\tname: \"$_\"\n"
|
|
|
|
. "\tzonefile: \"slave/$_\"\n\n";
|
2014-05-08 00:45:12 +02:00
|
|
|
|
|
|
|
# allow notify & request xfr, v4 & v6
|
|
|
|
$nouveau .=
|
2014-05-08 00:50:31 +02:00
|
|
|
"\tallow-notify: " . $self->data->nsmasterv4 . ' ' . $self->data->dnsslavekey . "\n"
|
2014-05-08 14:35:06 +02:00
|
|
|
. "\trequest-xfr: " . $self->data->nsmasterv4 . ' ' . $self->data->dnsslavekey . "\n\n";
|
2014-05-08 00:45:12 +02:00
|
|
|
|
|
|
|
$nouveau .=
|
2014-05-08 00:50:31 +02:00
|
|
|
"\tallow-notify: " . $self->data->nsmasterv6. ' ' . $self->data->dnsslavekey . "\n"
|
|
|
|
. "\trequest-xfr: " . $self->data->nsmasterv6. ' ' . $self->data->dnsslavekey . "\n\n";
|
2014-05-08 00:45:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$data =~ s/$debut.*/$debut\n$nouveau/gsm;
|
|
|
|
|
|
|
|
write_file($f, $data);
|
|
|
|
|
|
|
|
_scp_put($self->data->sshusersec
|
|
|
|
, $self->data->sshhostsec
|
|
|
|
, $self->data->sshportsec
|
|
|
|
, $f
|
|
|
|
, "/etc/nsd3/");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub _scp_get {
|
2014-05-08 14:18:26 +02:00
|
|
|
my ($user, $host, $port, $src, $dest) = @_;
|
2014-05-08 00:45:12 +02:00
|
|
|
|
|
|
|
my $co = $user . '@' . $host . ':' . $port;
|
|
|
|
my $ssh = Net::OpenSSH->new($co);
|
|
|
|
$ssh->scp_get($src, $dest) or die "scp failed: " . $ssh->error;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub _scp_put {
|
2014-05-08 14:18:26 +02:00
|
|
|
my ($user, $host, $port, $src, $dest) = @_;
|
2014-05-08 00:45:12 +02:00
|
|
|
|
|
|
|
my $co = $user . '@' . $host . ':' . $port;
|
|
|
|
my $ssh = Net::OpenSSH->new($co);
|
|
|
|
$ssh->scp_put($src, $dest) or die "scp failed: " . $ssh->error;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub reconfig {
|
|
|
|
my ($self, $zname) = @_;
|
2014-05-08 14:35:06 +02:00
|
|
|
die "not implemented";
|
|
|
|
#system("nsdc reconfig 2>/dev/null 1>/dev/null");
|
2014-05-08 00:45:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub delzone {
|
2014-05-08 14:35:06 +02:00
|
|
|
my ($self) = @_;
|
|
|
|
die "not implemented";
|
|
|
|
#system("nsdc delzone $zname 2>/dev/null 1>/dev/null");
|
2014-05-08 00:45:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub read_file {
|
|
|
|
my ($filename) = @_;
|
|
|
|
|
|
|
|
open my $entree, '<:encoding(UTF-8)', $filename or
|
|
|
|
die "Impossible d'ouvrir '$filename' en lecture : $!";
|
|
|
|
local $/ = undef;
|
|
|
|
my $tout = <$entree>;
|
|
|
|
close $entree;
|
|
|
|
|
|
|
|
return $tout;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub write_file {
|
|
|
|
my ($filename, $data) = @_;
|
|
|
|
|
|
|
|
open my $sortie, '>:encoding(UTF-8)', $filename or die "Impossible d'ouvrir '$filename' en écriture : $!";
|
|
|
|
print $sortie $data;
|
|
|
|
close $sortie;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|