3
0

Add entries modification.

Allows to change an entry details (name, host, ttl and mx priority).
This commit is contained in:
Julien Simonet 2014-01-26 20:21:39 +01:00
parent e18f8a1a3a
commit cd0afa37b3
3 changed files with 113 additions and 27 deletions

View File

@ -168,14 +168,23 @@ sub new_tmp {
$ze->new_tmp(); $ze->new_tmp();
} }
sub delete_entry { sub _mod_entry {
my ($self, $login, $domain, $entryToDelete) = @_; my ($self, $login, $domain, $entryToDelete, $action, $newEntry) = @_;
my $name = $entryToDelete->{'name'}; my $name = $entryToDelete->{'name'};
my $type = $entryToDelete->{'type'}; my $type = $entryToDelete->{'type'};
my $ttl = $entryToDelete->{'ttl'}; my $ttl = $entryToDelete->{'ttl'};
my $host = $entryToDelete->{'host'}; 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 $zone = $self->get_domain($login , $domain);
my $dump = $zone->dump; my $dump = $zone->dump;
@ -222,17 +231,45 @@ sub delete_entry {
foreach my $i ( 0 .. scalar @{$record}-1 ) foreach my $i ( 0 .. scalar @{$record}-1 )
{ {
delete $record->[$i] if( $action eq 'del' )
{
delete $record->[$i]
if( $record->[$i]->{'name'} eq $name && if( $record->[$i]->{'name'} eq $name &&
$record->[$i]->{'host'} eq $host && $record->[$i]->{'host'} eq $host &&
$record->[$i]->{'ttl'} == $ttl ); $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 ); $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; 1;

View File

@ -245,8 +245,8 @@ prefix '/domain' => sub {
else else
{ {
my $app = initco(); my $app = initco();
my ($auth_ok, $user, $isadmin) = $app->auth(param('login'), # my ($auth_ok, $user, $isadmin) = $app->auth(param('login'),
param('password') ); # param('password') );
my $zone = $app->get_domain(session('login') , param('domain')); 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<Domaine non renseigné.>;
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 { any ['get', 'post'] => '/admin' => sub {
unless( session('login') ) unless( session('login') )

View File

@ -26,66 +26,84 @@
<% FOREACH address in ns %> <% FOREACH address in ns %>
<tr> <tr>
<td><% address.name %></td> <form action='/domain/mod/<%domain%>/<%address.name%>/NS/<%address.host%>/<%address.ttl%>'>
<td><input type='text' name='newname' class="form-control" value='<% address.name %>'></input></td>
<td><% address.class %></td> <td><% address.class %></td>
<td>NS</td> <td>NS</td>
<td><% address.host %></td> <td><input type='text' name='newhost' class="form-control" value='<% address.host %>'/></td>
<td><% address.ttl %></td> <td><input type='number' name='newttl' class="form-control" value='<% address.ttl %>'/></td>
<td><input type='submit' id='submit' class="btn btn-success btn-xs" value='✔' />
</form>
<td><button type="button" class="btn btn-primary btn-danger btn-xs" onclick="location.href='http://'+location.host+'/domain/del/<% domain %>/<% address.name %>/NS/<% address.host %>/<% address.ttl %>';">✘</button></td> <td><button type="button" class="btn btn-primary btn-danger btn-xs" onclick="location.href='http://'+location.host+'/domain/del/<% domain %>/<% address.name %>/NS/<% address.host %>/<% address.ttl %>';">✘</button></td>
</tr> </tr>
<% END %> <% END %>
<% FOREACH address in a %> <% FOREACH address in a %>
<tr> <tr>
<td><% address.name %></td> <form action='/domain/mod/<%domain%>/<%address.name%>/A/<%address.host%>/<%address.ttl%>'>
<td><input type='text' name='newname' class="form-control" value='<% address.name %>'/></td>
<td><% address.class %></td> <td><% address.class %></td>
<td>A</td> <td>A</td>
<td><% address.host %></td> <td><input type='text' name='newhost' class="form-control" value='<% address.host %>'/></td>
<td><% address.ttl %></td> <td><input type='number' name='newttl' class="form-control" value='<% address.ttl %>'/></td>
<td><input type='submit' id='submit' class="btn btn-success btn-xs" value='✔' />
</form>
<td><button type="button" class="btn btn-primary btn-danger btn-xs" onclick="location.href='http://'+location.host+'/domain/del/<% domain %>/<% address.name %>/A/<% address.host %>/<% address.ttl %>';">✘</button></td> <td><button type="button" class="btn btn-primary btn-danger btn-xs" onclick="location.href='http://'+location.host+'/domain/del/<% domain %>/<% address.name %>/A/<% address.host %>/<% address.ttl %>';">✘</button></td>
</tr> </tr>
<% END %> <% END %>
<% FOREACH address in aaaa %> <% FOREACH address in aaaa %>
<tr> <tr>
<td><% address.name %></td> <form action='/domain/mod/<%domain%>/<%address.name%>/AAAA/<%address.host%>/<%address.ttl%>'>
<td><input type='text' name='newname' class="form-control" value='<% address.name %>'/></td>
<td><% address.class %></td> <td><% address.class %></td>
<td>AAAA</td> <td>AAAA</td>
<td><% address.host %></td> <td><input type='text' name='newhost' class="form-control" value='<% address.host %>'/></td>
<td><% address.ttl %></td> <td><input type='number' name='newttl' class="form-control" value='<% address.ttl %>'/></td>
<td><input type='submit' id='submit' class="btn btn-success btn-xs" value='✔' />
</form>
<td><button type="button" class="btn btn-primary btn-danger btn-xs" onclick="location.href='http://'+location.host+'/domain/del/<% domain %>/<% address.name %>/AAAA/<% address.host %>/<% address.ttl %>';">✘</button></td> <td><button type="button" class="btn btn-primary btn-danger btn-xs" onclick="location.href='http://'+location.host+'/domain/del/<% domain %>/<% address.name %>/AAAA/<% address.host %>/<% address.ttl %>';">✘</button></td>
</tr> </tr>
<% END %> <% END %>
<% FOREACH address in cname %> <% FOREACH address in cname %>
<tr> <tr>
<td><% address.name %></td> <form action='/domain/mod/<%domain%>/<%address.name%>/CNAME/<%address.host%>/<%address.ttl%>'>
<td><input type='text' name='newname' class="form-control" value='<% address.name %>'/></td>
<td><% address.class %></td> <td><% address.class %></td>
<td>CNAME</td> <td>CNAME</td>
<td><% address.host %></td> <td><input type='text' name='newhost' class="form-control" value='<% address.host %>'/></td>
<td><% address.ttl %></td> <td><input type='number' name='newttl' class="form-control" value='<% address.ttl %>'/></td>
<td><input type='submit' id='submit' class="btn btn-success btn-xs" value='✔' />
</form>
<td><button type="button" class="btn btn-primary btn-danger btn-xs" onclick="location.href='http://'+location.host+'/domain/del/<% domain %>/<% address.name %>/CNAME/<% address.host %>/<% address.ttl %>';">✘</button></td> <td><button type="button" class="btn btn-primary btn-danger btn-xs" onclick="location.href='http://'+location.host+'/domain/del/<% domain %>/<% address.name %>/CNAME/<% address.host %>/<% address.ttl %>';">✘</button></td>
</tr> </tr>
<% END %> <% END %>
<% FOREACH address in ptr %> <% FOREACH address in ptr %>
<tr> <tr>
<td><% address.name %></td> <form action='/domain/mod/<%domain%>/<%address.name%>/PTR/<%address.host%>/<%address.ttl%>'>
<td><input type='text' name='newname' class="form-control" value='<% address.name %>'/></td>
<td><% address.class %></td> <td><% address.class %></td>
<td>PTR</td> <td>PTR</td>
<td><% address.host %></td> <td><input type='text' name='newhost' class="form-control" value='<% address.host %>'/></td>
<td><% address.ttl %></td> <td><input type='number' name='newttl' class="form-control" value='<% address.ttl %>'/></td>
<td><input type='submit' id='submit' class="btn btn-success btn-xs" value='✔' />
</form>
<td><button type="button" class="btn btn-primary btn-danger btn-xs" onclick="location.href='http://'+location.host+'/domain/del/<% domain %>/<% address.name %>/PTR/<% address.host %>/<% address.ttl %>';">✘</button></td> <td><button type="button" class="btn btn-primary btn-danger btn-xs" onclick="location.href='http://'+location.host+'/domain/del/<% domain %>/<% address.name %>/PTR/<% address.host %>/<% address.ttl %>';">✘</button></td>
</tr> </tr>
<% END %> <% END %>
<% FOREACH address in mx %> <% FOREACH address in mx %>
<tr> <tr>
<td><% address.name %></td> <form action='/domain/mod/<%domain%>/<%address.name%>/MX/<%address.host%>/<%address.ttl%>'>
<td><input type='text' name='newname' class="form-control" value='<% address.name %>'/></td>
<td><% address.class %></td> <td><% address.class %></td>
<td>MX</td> <td>MX</td>
<td><% address.host %> (<% address.priority %>)</td> <td><input type='text' name='newhost' class="form-control" value='<% address.host %>'/><input type='number' name='newpriority' class="form-control" value='<%address.priority%>'/></td>
<td><% address.ttl %></td> <td><input type='number' name='newttl' class="form-control" value='<% address.ttl %>'/></td>
<td><input type='submit' id='submit' class="btn btn-success btn-xs" value='✔' />
</form>
<td><button type="button" class="btn btn-primary btn-danger btn-xs" onclick="location.href='http://'+location.host+'/domain/del/<% domain %>/<% address.name %>/MX/<% address.host %>/<% address.ttl %>';">✘</button></td> <td><button type="button" class="btn btn-primary btn-danger btn-xs" onclick="location.href='http://'+location.host+'/domain/del/<% domain %>/<% address.name %>/MX/<% address.host %>/<% address.ttl %>';">✘</button></td>
</tr> </tr>
<% END %> <% END %>