From e94224b6f29c1dedee572a583f632231a41bb0ad Mon Sep 17 00:00:00 2001 From: karchnu Date: Wed, 14 Oct 2015 00:50:23 +0200 Subject: [PATCH] =?UTF-8?q?modifications=20de=20derni=C3=A8re=20minute,=20?= =?UTF-8?q?mise=20en=20prod=20r=C3=A9ussie=20\o/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/app.pm | 4 ++++ lib/configuration.pm | 10 ++++++++++ lib/interface/bind9.pm | 41 +++++++++++++++++++++++++---------------- lib/interface/nsd3.pm | 32 +++++++++++++++++++------------- 4 files changed, 58 insertions(+), 29 deletions(-) diff --git a/lib/app.pm b/lib/app.pm index 6c92133..6da87b4 100644 --- a/lib/app.pm +++ b/lib/app.pm @@ -4,6 +4,7 @@ use Moo; use db; use zone; +use configuration ':all'; has db => ( is => 'rw', builder => '_void'); @@ -16,6 +17,9 @@ sub BUILD { my ($self) = @_; $$self{db} = db->new(data => $self); + my $tmpdir = get_tmpdir_from_uri($$self{tmpdir}); + -f $tmpdir || qx/mkdir -p $tmpdir/; + my $db = $$self{database}; unless(exists $$db{sgbd} && exists $$db{name} && exists $$db{host} && exists $$db{port} diff --git a/lib/configuration.pm b/lib/configuration.pm index 337fd45..e462048 100644 --- a/lib/configuration.pm +++ b/lib/configuration.pm @@ -16,6 +16,7 @@ get_v6_from_cfg get_host_from_cfg get_user_from_cfg get_port_from_cfg +get_tmpdir_from_uri /; # bundle of exports (tags) @@ -30,6 +31,7 @@ get_v6_from_cfg get_host_from_cfg get_user_from_cfg get_port_from_cfg +get_tmpdir_from_uri /] ); sub is_conf_file { @@ -102,6 +104,14 @@ sub get_v4_from_cfg { $$cfg{domain}{v4} // get_v4_from_name($$cfg{domain}{name}) } +sub get_tmpdir_from_uri { + my $tmpdir = shift; + unless($tmpdir) { + die 'There is no tmpdir'; + } + URI->new($tmpdir)->path; +} + sub get_zonedir_from_cfg { my $cfg = shift; unless($$cfg{zonedir}) { diff --git a/lib/interface/bind9.pm b/lib/interface/bind9.pm index f07b0ea..e252a62 100644 --- a/lib/interface/bind9.pm +++ b/lib/interface/bind9.pm @@ -9,16 +9,20 @@ has [ qw/mycfg tmpdir primarydnsserver secondarydnsserver/ ] => qw/is ro require sub reload { my ($self, $domain) = @_; - my $cmd = "rndc reload $domain "; + my $cmd = "rndc reload $domain"; + qx/$cmd/; + $cmd = "rndc notify $domain"; + qx/$cmd/; - my $user = get_user_from_cfg($$self{mycfg}); - my $host = get_host_from_cfg($$self{mycfg}); - my $port = get_port_from_cfg($$self{mycfg}); + #my $cmd = "rndc reload $domain "; + #my $user = get_user_from_cfg($$self{mycfg}); + #my $host = get_host_from_cfg($$self{mycfg}); + #my $port = get_port_from_cfg($$self{mycfg}); - remotecmd $user, $host, $port, $cmd; + #remotecmd $user, $host, $port, $cmd; - $cmd = "rndc notify $domain "; - remotecmd $user, $host, $port, $cmd; + #$cmd = "rndc notify $domain "; + #remotecmd $user, $host, $port, $cmd; } sub primary_addzone { @@ -44,11 +48,14 @@ sub primary_addzone { $cmd .= " }; notify yes; };\""; } - my $user = get_user_from_cfg($$self{mycfg}); - my $host = get_host_from_cfg($$self{mycfg}); - my $port = get_port_from_cfg($$self{mycfg}); + # if remote rndc + #my $user = get_user_from_cfg($$self{mycfg}); + #my $host = get_host_from_cfg($$self{mycfg}); + #my $port = get_port_from_cfg($$self{mycfg}); - remotecmd $user, $host, $port, $cmd; + #remotecmd $user, $host, $port, $cmd; + + qx/$cmd/; } sub reconfig { @@ -56,17 +63,19 @@ sub reconfig { my $cmd = "rndc reconfig "; - my $user = get_user_from_cfg($$self{mycfg}); - my $host = get_host_from_cfg($$self{mycfg}); - my $port = get_port_from_cfg($$self{mycfg}); + #my $user = get_user_from_cfg($$self{mycfg}); + #my $host = get_host_from_cfg($$self{mycfg}); + #my $port = get_port_from_cfg($$self{mycfg}); - remotecmd $user, $host, $port, $cmd; + #remotecmd $user, $host, $port, $cmd; + + qx/$cmd/; } sub delzone { my ($self, $domain) = @_; - my $cmd = "rndc delzone $domain "; + my $cmd = "sudo rndc delzone $domain "; my $user = get_user_from_cfg($$self{mycfg}); my $host = get_host_from_cfg($$self{mycfg}); diff --git a/lib/interface/nsd3.pm b/lib/interface/nsd3.pm index e9fa60f..8941aa9 100644 --- a/lib/interface/nsd3.pm +++ b/lib/interface/nsd3.pm @@ -15,8 +15,7 @@ sub reload_sec { $self->_reload_conf($slavedzones); - my $cmd = "sudo nsdc rebuild && " - . " sudo nsdc restart "; + my $cmd = "sudo nsdc rebuild && sudo nsdc restart && sudo nsdc patch "; my $user = get_user_from_cfg($$self{mycfg}); my $host = get_host_from_cfg($$self{mycfg}); @@ -42,28 +41,36 @@ sub _reload_conf { copycat $remote, $f; my $data = read_file $f; + + # if it's the first time we get the configuration, fresh start + $data .= "\n## BEGIN_GENERATED" if( $data !~ /BEGIN_GENERATED/); + + my $v4 = get_v4_from_cfg($$self{primarydnsserver}); + my $v6 = get_v6_from_cfg($$self{primarydnsserver}); + my $debut = "## BEGIN_GENERATED"; + my $nouveau = ''; my $dnsslavekey = get_dnsslavekey_from_cfg($$self{primarydnsserver}); for(@{$slavedzones}) { - $nouveau .= "zone:\n\n\tname: \"$_\"\n" - . "\tzonefile: \"slave/$_\"\n\n"; + $nouveau .= "zone:\n\tname: \"$$_{domain}\"\n" + . "\tzonefile: \"slave/$$_{domain}\"\n"; - my $v4 = get_v4_from_cfg($$self{primarydnsserver}); - my $v6 = get_v6_from_cfg($$self{primarydnsserver}); + say "domain : $$_{domain}"; if($v4) { # allow notify & request xfr, v4 & v6 - $nouveau .= "\tallow-notify: $v4 $dnsslavekey \n" - . "\trequest-xfr: $v4 $dnsslavekey \n\n"; + $nouveau .= "\tallow-notify: $v4 \"$dnsslavekey\" \n" + . "\trequest-xfr: $v4 \"$dnsslavekey\" \n"; } if($v6) { - $nouveau .= "\tallow-notify: $v6 $dnsslavekey \n" - . "\trequest-xfr: $v6 $dnsslavekey \n\n"; + $nouveau .= "\tallow-notify: $v6 \"$dnsslavekey\" \n" + . "\trequest-xfr: $v6 \"$dnsslavekey\" \n"; } + $nouveau .= "\n"; } $data =~ s/$debut.*/$debut\n$nouveau/gsm; @@ -71,10 +78,9 @@ sub _reload_conf { write_file $f, $data; copycat $f, $remote; - my $cmd = "sudo nsdc patch && " - . " sudo rm /var/nsd3/ixfr.db"; + my $cmd = "sudo nsdc patch && sudo rm /var/nsd3/ixfr.db"; - remotecmd $user, $host, $port, $cmd; + remotecmd $user, $host, $port, $cmd } sub reconfig {