3
0

remplacement par un simple scalaire (pointeur)

This commit is contained in:
Philippe Pittoli 2014-05-08 14:08:06 +02:00
parent e73e7c00fb
commit 6d4cc2e0ca
2 changed files with 22 additions and 27 deletions

View File

@ -89,12 +89,7 @@ sub _get_zone_edit {
return app::zone::edit->new( return app::zone::edit->new(
zname => $domain zname => $domain
, dnsapp => $self->dnsapp , data => $self );
, dnsappsec => $self->dnsappsec
, zdir => $self->zdir
, host => $self->sshhost
, user => $self->sshuser
, port => $self->sshport );
} }
# return yes or no # return yes or no

View File

@ -11,12 +11,12 @@ use app::zone::interface;
package app::zone::edit; package app::zone::edit;
use Moose; use Moose;
has [ qw/dnsapp dnsappsec zname zdir host user port/ ] => qw/is ro required 1/; has [ qw/zname data/ ] => qw/is ro required 1/;
sub get { sub get {
my ($self) = @_; my ($self) = @_;
my $dest = '/tmp/' . $self->zname; my $dest = '/tmp/' . $self->zname;
my $file = $self->zdir.'/'.$self->zname; my $file = $self->data->zdir.'/'.$self->zname;
$self->_scp_get($file, $dest); $self->_scp_get($file, $dest);
DNS::ZoneParse->new($dest, $self->zname); DNS::ZoneParse->new($dest, $self->zname);
@ -32,7 +32,7 @@ sub get {
sub addzone { sub addzone {
my ($self) = @_; my ($self) = @_;
my $tpl = $self->zdir."/tpl.zone"; my $tpl = $self->data->zdir."/tpl.zone";
my $tmpfile = '/tmp/'.$self->zname; my $tmpfile = '/tmp/'.$self->zname;
$self->_scp_get($tpl, $tmpfile); # get the template $self->_scp_get($tpl, $tmpfile); # get the template
@ -47,19 +47,19 @@ sub addzone {
print $newzone $zonefile->output(); print $newzone $zonefile->output();
close $newzone; close $newzone;
my $file = $self->zdir.'/'.$self->zname; my $file = $self->data->zdir.'/'.$self->zname;
$self->_scp_put($tmpfile, $file); # put the final zone on the server $self->_scp_put($tmpfile, $file); # put the final zone on the server
unlink($tmpfile); # del the temporary file unlink($tmpfile); # del the temporary file
# add new zone on the primary ns # add new zone on the primary ns
my $prim = app::zone::interface->new() my $prim = app::zone::interface->new()
->get_interface($self->dnsapp); ->get_interface($self->data->dnsapp, $self->data);
$prim->addzone($self->zdir, $self->zname); $prim->addzone($self->data->zdir, $self->zname);
# add new zone on the secondary ns # add new zone on the secondary ns
my $sec = app::zone::interface->new() my $sec = app::zone::interface->new()
->get_interface($self->dnsappsec); ->get_interface($self->data->dnsappsec, $self->data);
$sec->addzone_sec($self->zdir, $self->zname); $sec->addzone_sec($self->data->zdir, $self->zname);
return $zonefile; return $zonefile;
} }
@ -83,12 +83,12 @@ sub update {
print $newzone $zonefile->output(); print $newzone $zonefile->output();
close $newzone; close $newzone;
my $file = $self->zdir.'/'.$self->zname; my $file = $self->data->zdir.'/'.$self->zname;
$self->_scp_put($tmpfile, $file); # put the final zone on the server $self->_scp_put($tmpfile, $file); # put the final zone on the server
unlink($tmpfile); # del the temporary file unlink($tmpfile); # del the temporary file
my $prim = app::zone::interface->new() my $prim = app::zone::interface->new()
->get_interface($self->dnsapp); ->get_interface($self->data->dnsapp, $self->data);
$prim->reload($self->zname); $prim->reload($self->zname);
1; 1;
} }
@ -125,7 +125,7 @@ sub update_raw {
sub new_tmp { sub new_tmp {
my ($self) = @_; my ($self) = @_;
my $tpl = $self->zdir."/tpl.zone"; my $tpl = $self->data->zdir."/tpl.zone";
my $file = '/tmp/'.$self->zname; my $file = '/tmp/'.$self->zname;
$self->_scp($tpl, $file); $self->_scp($tpl, $file);
@ -148,7 +148,7 @@ sub _cp {
sub _scp_put { sub _scp_put {
my ($self, $src, $dest) = @_; my ($self, $src, $dest) = @_;
my $co = $self->user . '@' . $self->host . ':' . $self->port; my $co = $self->data->sshuser . '@' . $self->data->sshhost . ':' . $self->data->sshport;
my $ssh = Net::OpenSSH->new($co); my $ssh = Net::OpenSSH->new($co);
$ssh->scp_put($src, $dest) or die "scp failed: " . $ssh->error; $ssh->scp_put($src, $dest) or die "scp failed: " . $ssh->error;
} }
@ -156,7 +156,7 @@ sub _scp_put {
sub _scp_get { sub _scp_get {
my ($self, $src, $dest) = @_; my ($self, $src, $dest) = @_;
my $co = $self->user . '@' . $self->host . ':' . $self->port; my $co = $self->data->sshuser . '@' . $self->data->sshhost . ':' . $self->data->sshport;
my $ssh = Net::OpenSSH->new($co); my $ssh = Net::OpenSSH->new($co);
$ssh->scp_get($src, $dest) or die "scp failed: " . $ssh->error; $ssh->scp_get($src, $dest) or die "scp failed: " . $ssh->error;
} }
@ -172,18 +172,18 @@ sub _sed {
sub del { sub del {
my ($self) = @_; my ($self) = @_;
my $prim = app::zone::interface->new() my $prim = app::zone::interface->new()
->get_interface($self->dnsapp); ->get_interface($self->data->dnsapp, $self->data);
$prim->delzone($self->zdir, $self->zname); $prim->delzone($self->data->zdir, $self->zname);
$prim->reconfig(); $prim->reconfig();
my $sec = app::zone::interface->new() my $sec = app::zone::interface->new()
->get_interface($self->dnsappsec); ->get_interface($self->data->dnsappsec, $self->data);
$sec->delzone($self->zdir, $self->zname); $sec->delzone($self->data->zdir, $self->zname);
$sec->reload($self->zdir, $self->zname); $sec->reload($self->data->zdir, $self->zname);
my $file = $self->zdir.'/'.$self->zname; my $file = $self->data->zdir.'/'.$self->zname;
my $host = $self->host; my $host = $self->data->sshhost;
my $user = $self->user; my $user = $self->data->sshuser;
my $cmd = "rm $file"; my $cmd = "rm $file";
Net::SSH::sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!"; Net::SSH::sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!";