From 529130953bd6d3cb8a8185b30e7951e64fa4eee6 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sat, 25 Jan 2014 14:08:01 +0100 Subject: [PATCH] =?UTF-8?q?formulaire=20++,=20debug=20MX,=20securit=C3=A9?= =?UTF-8?q?=20concernant=20les=20entr=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/zone/edit.pm | 10 ++- www/lib/DNSManager.pm | 140 +++++++++++++++++++++++------------------- www/views/details.tt | 72 +++++++++++++++++----- 3 files changed, 141 insertions(+), 81 deletions(-) diff --git a/app/zone/edit.pm b/app/zone/edit.pm index 434a4ab..dd20c91 100644 --- a/app/zone/edit.pm +++ b/app/zone/edit.pm @@ -77,6 +77,7 @@ sub update { sub update_raw { my ($self, $zonetext) = @_; + my $zonefile; my $file = '/tmp/'.$self->zname; # write the updated zone file to disk @@ -85,10 +86,17 @@ sub update_raw { print $newzone $zonetext; close $newzone; - my $zonefile = DNS::ZoneParse->new($file, $self->zname); + eval { $zonefile = DNS::ZoneParse->new($file, $self->zname); }; + + if( $@ ) { + unlink($file); + 0; + } + unlink($file); $self->update($zonefile); + 1; } # sera utile plus tard, pour l'interface diff --git a/www/lib/DNSManager.pm b/www/lib/DNSManager.pm index c0f61cf..fef11e9 100644 --- a/www/lib/DNSManager.pm +++ b/www/lib/DNSManager.pm @@ -136,14 +136,14 @@ prefix '/domain' => sub { my ($auth_ok, $user, $isadmin) = $app->auth(param('login'), param('password') ); - $app->update_domain_raw(session('login') + my $success = $app->update_domain_raw(session('login') , param('zoneupdated') , param('domain')); redirect '/domain/details/' . param('domain'); - } + } - }; + }; any ['post', 'get'] => '/update/:domain' => sub { unless( session('login') && param('domain') ) @@ -152,75 +152,87 @@ prefix '/domain' => sub { } else { - my $type = param('type'); - my $name = param('name'); - my $value = param('value'); - my $ttl = param('ttl'); + my $type = param('type'); + my $name = param('name'); + my $value = param('value'); + my $ttl = param('ttl'); + my $priority = param('priority'); - my $app = initco(); - my ($auth_ok, $user, $isadmin) = $app->auth(param('login'), - param('password') ); - my $zone = $app->get_domain( session('login') , param('domain') ); - given( $type ) - { + my $app = initco(); + my ($auth_ok, $user, $isadmin) = $app->auth(param('login'), + param('password') ); + my $zone = $app->get_domain( session('login') , param('domain') ); + given( $type ) + { - when ('A') { my $a=$zone->a(); - push( @$a, {name => $name, - class => "IN", - host => $value, - ttl => $ttl, - ORIGIN => $zone->origin} ); - } + when ('A') { + my $a = $zone->a(); + push( @$a, {name => $name + , class => "IN" + , host => $value + , ttl => $ttl + , ORIGIN => $zone->origin} ); + } - when ('AAAA') { my $aaaa=$zone->aaaa; - push(@$aaaa, {name => $name, - class => "IN", - host => $value, - ttl => $ttl, - ORIGIN => $zone->origin} ); - } + when ('AAAA') { + my $aaaa = $zone->aaaa; + push(@$aaaa, {name => $name + , class => "IN" + , host => $value + , ttl => $ttl + , ORIGIN => $zone->origin} ); + } - when ('CNAME') { my $cname=$zone->cname; - push(@$cname, - {name => $name, - class => "IN", - host => $value, - ttl => $ttl, - ORIGIN => $zone->origin} ); - } + when ('CNAME') { + my $cname = $zone->cname; + push(@$cname, + {name => $name + , class => "IN" + , host => $value + , ttl => $ttl + , ORIGIN => $zone->origin} ); + } - when ('MX') { my $ptr=$zone->ptr; - push(@$ptr, {name => $name, - class => "IN", - host => $value, - ttl => $ttl, - ORIGIN => $zone->origin} ); - } + when ('MX') { + my $mx = $zone->mx; + push(@$mx, { name => $name + , class => "IN" + , host => $value + , priority => $priority + , ttl => $ttl + , ORIGIN => $zone->origin} ); + } - when ('PTR') { my $ptr=$zone->ptr; - push(@$ptr, {name => $name, - class => "IN", - host => $value, - ttl => $ttl, - ORIGIN => $zone->origin} ); - } + when ('PTR') { + my $ptr = $zone->ptr; + push(@$ptr, {name => $name + , class => "IN" + , host => $value + , ttl => $ttl + , ORIGIN => $zone->origin} ); + } - when ('NS') { my $ns=$zone->ns; - push(@$ns, {name => $name, - class => "IN", - host => $value, - ttl => $ttl, - ORIGIN => $zone->origin} ); - } + when ('NS') { + my $ns = $zone->ns; + push(@$ns, {name => $name + , class => "IN" + , host => $value + , ttl => $ttl + , ORIGIN => $zone->origin} ); + } - } - $zone->new_serial(); - my $cfg = new Config::Simple(dirname(__FILE__).'/../conf/config.ini'); - my $ed = app::zone::edit->new(zdir=>$cfg->param('zones_path'), zname => param('domain')); - $ed->update($zone); - redirect '/domain/details/'.param('domain'); - } - }; + } + + $zone->new_serial(); + my $cfg = new Config::Simple(dirname(__FILE__).'/../conf/config.ini'); + my $ed = app::zone::edit->new(zdir=>$cfg->param('zones_path') + , zname => param('domain')); + + $ed->update($zone); + redirect '/domain/details/'.param('domain'); + + } + }; get '/details/:domain' => sub { diff --git a/www/views/details.tt b/www/views/details.tt index 72c7a7f..7545714 100644 --- a/www/views/details.tt +++ b/www/views/details.tt @@ -87,25 +87,65 @@ -

- Ajouter un enregistrement :
-
+
+ - - +
+ Ajout d'un enregistrement + +
+ +
+ +
+
+ +
+ +
+ + +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+
+ +
+
+ +
+
+ +
- - - - <% END %>