From cd0afa37b3bd52b2d549aa8b9e84063482935fc6 Mon Sep 17 00:00:00 2001 From: Julien Simonet Date: Sun, 26 Jan 2014 20:21:39 +0100 Subject: [PATCH] Add entries modification. Allows to change an entry details (name, host, ttl and mx priority). --- app/app.pm | 51 ++++++++++++++++++++++++++++++++++------ www/lib/DNSManager.pm | 35 ++++++++++++++++++++++++++-- www/views/details.tt | 54 ++++++++++++++++++++++++++++--------------- 3 files changed, 113 insertions(+), 27 deletions(-) diff --git a/app/app.pm b/app/app.pm index cfe7167..85756f0 100644 --- a/app/app.pm +++ b/app/app.pm @@ -168,14 +168,23 @@ sub new_tmp { $ze->new_tmp(); } -sub delete_entry { - my ($self, $login, $domain, $entryToDelete) = @_; +sub _mod_entry { + my ($self, $login, $domain, $entryToDelete, $action, $newEntry) = @_; - my $name = $entryToDelete->{'name'}; - my $type = $entryToDelete->{'type'}; - my $ttl = $entryToDelete->{'ttl'}; - my $host = $entryToDelete->{'host'}; + my $name = $entryToDelete->{'name'}; + my $type = $entryToDelete->{'type'}; + my $ttl = $entryToDelete->{'ttl'}; + my $host = $entryToDelete->{'host'}; + my $priority = $entryToDelete->{'priority'}; + my $new_name = $newEntry->{'newname'}; + my $new_type = $newEntry->{'newtype'}; + my $new_ttl = $newEntry->{'newttl'}; + my $new_host = $newEntry->{'newhost'}; + my $new_priority = $newEntry->{'newpriority'}; + + # say "in _mod_entry : $action"; + # say "in _mod_entry : $new_name"; my $zone = $self->get_domain($login , $domain); my $dump = $zone->dump; @@ -222,17 +231,45 @@ sub delete_entry { foreach my $i ( 0 .. scalar @{$record}-1 ) { - delete $record->[$i] + if( $action eq 'del' ) + { + delete $record->[$i] if( $record->[$i]->{'name'} eq $name && $record->[$i]->{'host'} eq $host && $record->[$i]->{'ttl'} == $ttl ); + } + if ( $action eq 'mod' ) + { + if( $record->[$i]->{'name'} eq $name && + $record->[$i]->{'host'} eq $host && + $record->[$i]->{'ttl'} == $ttl ) + { + $record->[$i]->{'name'} = $new_name; + $record->[$i]->{'host'} = $new_host; + $record->[$i]->{'ttl'} = $new_ttl; + if( defined $new_priority ) + { + $record->[$i]->{'priority'} = $new_priority + } + } + } } } $self->update_domain( $login, $zone, $domain ); +} + +sub delete_entry { + my ($self, $login, $domain, $entryToDelete) = @_; + $self->_mod_entry( $login, $domain, $entryToDelete, 'del' ); +} + +sub modify_entry { + my ($self, $login, $domain, $entryToDelete, $newEntry) = @_; + $self->_mod_entry( $login, $domain, $entryToDelete, 'mod', $newEntry ); } 1; diff --git a/www/lib/DNSManager.pm b/www/lib/DNSManager.pm index be655f0..cc422ae 100644 --- a/www/lib/DNSManager.pm +++ b/www/lib/DNSManager.pm @@ -245,8 +245,8 @@ prefix '/domain' => sub { else { my $app = initco(); - my ($auth_ok, $user, $isadmin) = $app->auth(param('login'), - param('password') ); + # my ($auth_ok, $user, $isadmin) = $app->auth(param('login'), + # param('password') ); my $zone = $app->get_domain(session('login') , param('domain')); @@ -379,6 +379,37 @@ prefix '/domain' => sub { } }; + get '/mod/:domain/:name/:type/:host/:ttl' => sub { + + unless( session( 'user' ) and defined param('domain') ) { + session errmsg => q; + redirect get_route; + } + else { + # Load :domain and search for corresponding data + my $app = initco(); + # my ($auth_ok, $user, $isadmin) = $app->auth(param('login'), + # param('password') ); + + $app->modify_entry( session('login'), + param('domain'), + { + type => param('type'), + name => param('name'), + host => param('host'), + ttl => param('ttl') + }, + { + newtype => param('newtype'), + newname => param('newname'), + newhost => param('newhost'), + newttl => param('newttl'), + newpriority => param('newpriority') + }); + + redirect '/domain/details/'. param('domain'); + } + }; any ['get', 'post'] => '/admin' => sub { unless( session('login') ) diff --git a/www/views/details.tt b/www/views/details.tt index 58caf7e..1a248d4 100644 --- a/www/views/details.tt +++ b/www/views/details.tt @@ -26,66 +26,84 @@ <% FOREACH address in ns %> - <% address.name %> +
+ <% address.class %> NS - <% address.host %> - <% address.ttl %> + + + +
<% END %> <% FOREACH address in a %> - <% address.name %> +
+ <% address.class %> A - <% address.host %> - <% address.ttl %> + + + +
<% END %> <% FOREACH address in aaaa %> - <% address.name %> +
+ <% address.class %> AAAA - <% address.host %> - <% address.ttl %> + + + +
<% END %> <% FOREACH address in cname %> - <% address.name %> +
+ <% address.class %> CNAME - <% address.host %> - <% address.ttl %> + + + +
<% END %> <% FOREACH address in ptr %> - <% address.name %> +
+ <% address.class %> PTR - <% address.host %> - <% address.ttl %> + + + +
<% END %> <% FOREACH address in mx %> - <% address.name %> +
+ <% address.class %> MX - <% address.host %> (<% address.priority %>) - <% address.ttl %> + + + +
<% END %>