Obsolete
/
dnsmanagerv1
Archived
3
0
Fork 0

Moved function to delete an entry to app::app

master
Julien Simonet 2014-01-26 17:27:04 +01:00
parent 59cf727e28
commit e18f8a1a3a
2 changed files with 252 additions and 235 deletions

View File

@ -168,4 +168,71 @@ sub new_tmp {
$ze->new_tmp();
}
sub delete_entry {
my ($self, $login, $domain, $entryToDelete) = @_;
my $name = $entryToDelete->{'name'};
my $type = $entryToDelete->{'type'};
my $ttl = $entryToDelete->{'ttl'};
my $host = $entryToDelete->{'host'};
my $zone = $self->get_domain($login , $domain);
my $dump = $zone->dump;
my $record;
my $found = 0;
given( lc $type )
{
when ('a')
{
$record = $zone->a;
$found = 1;
}
when ('aaaa')
{
$record = $zone->aaaa;
$found = 1;
}
when ('cname')
{
$record = $zone->cname;
$found = 1;
}
when ('ns')
{
$record = $zone->ns;
$found = 1;
}
when ('mx')
{
$record = $zone->mx;
$found = 1;
}
when ('ptr')
{
$record = $zone->ptr;
$found = 1;
}
}
if( $found )
{
foreach my $i ( 0 .. scalar @{$record}-1 )
{
delete $record->[$i]
if( $record->[$i]->{'name'} eq $name &&
$record->[$i]->{'host'} eq $host &&
$record->[$i]->{'ttl'} == $ttl );
}
}
$self->update_domain( $login, $zone, $domain );
}
1;

View File

@ -363,74 +363,23 @@ prefix '/domain' => sub {
else {
# Load :domain and search for corresponding data
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'));
my $dump = $zone->dump;
my $record;
my $found = false;
given( lc param('type') )
$app->delete_entry( session('login'),
param('domain'),
{
when ('a')
{
$record = $zone->a;
$found = true;
}
when ('aaaa')
{
$record = $zone->aaaa;
$found = true;
}
when ('cname')
{
$record = $zone->cname;
$found = true;
}
when ('ns')
{
$record = $zone->ns;
$found = true;
}
when ('mx')
{
$record = $zone->mx;
$found = true;
}
when ('ptr')
{
$record = $zone->ptr;
$found = true;
}
}
if( $found )
{
foreach my $i ( 0 .. scalar @{$record}-1 )
{
if( $record->[$i]->{'name'} eq param('name') &&
$record->[$i]->{'host'} eq param('host') &&
$record->[$i]->{'ttl'} == param('ttl') )
{
delete $record->[$i];
}
}
}
$app->update_domain( session('login'), $zone, param('domain') );
}
type => param('type'),
name => param('name'),
host => param('host'),
ttl => param('ttl')
});
redirect '/domain/details/'. param('domain');
}
};
};
any ['get', 'post'] => '/admin' => sub {
any ['get', 'post'] => '/admin' => sub {
unless( session('login') )
{
@ -460,6 +409,8 @@ any ['get', 'post'] => '/admin' => sub {
, allusers => { %allusers } };
}
}
};
};
prefix '/user' => sub {
@ -663,5 +614,4 @@ prefix '/user' => sub {
redirect '/home';
};
};