Obsolete
/
dnsmanagerv1
Archived
3
0
Fork 0

Merge branch 'features/modEntry' into debug

master
Julien Simonet 2014-01-26 20:54:15 +01:00
commit e24bad43f6
3 changed files with 358 additions and 255 deletions

View File

@ -168,4 +168,108 @@ sub new_tmp {
$ze->new_tmp();
}
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 $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;
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 )
{
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;

View File

@ -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'));
@ -363,305 +363,286 @@ 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') )
{
when ('a')
$app->delete_entry( session('login'),
param('domain'),
{
$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;
}
}
type => param('type'),
name => param('name'),
host => param('host'),
ttl => param('ttl')
});
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') );
redirect '/domain/details/'. param('domain');
}
};
redirect '/domain/details/'. param('domain');
}
};
get '/mod/:domain/:name/:type/:host/:ttl' => sub {
any ['get', 'post'] => '/admin' => sub {
unless( session('login') )
{
redirect '/';
}
else
{
my $app = initco();
my ($auth_ok, $user, $isadmin) = $app->auth(session('login'),
session('password') );
unless ( $auth_ok && $isadmin ) {
redirect '/ ';
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') );
my %alldomains = $app->get_all_domains;
my %allusers = $app->get_all_users;
my ($success, @domains) = $app->get_domains( session('login') );
$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') )
{
redirect '/';
}
else
{
my $app = initco();
my ($auth_ok, $user, $isadmin) = $app->auth(session('login'),
session('password') );
unless ( $auth_ok && $isadmin ) {
redirect '/ ';
}
else {
my %alldomains = $app->get_all_domains;
my %allusers = $app->get_all_users;
my ($success, @domains) = $app->get_domains( session('login') );
template administration => {
login => session('login')
, admin => session('admin')
, errmsg => get_errmsg
, domains => [ @domains ]
, alldomains => { %alldomains }
, allusers => { %allusers } };
}
}
};
template administration => {
login => session('login')
, admin => session('admin')
, errmsg => get_errmsg
, domains => [ @domains ]
, alldomains => { %alldomains }
, allusers => { %allusers } };
}
}
};
prefix '/user' => sub {
get '/logout' => sub {
session->destroy;
redirect '/';
};
get '/logout' => sub {
session->destroy;
redirect '/';
};
post '/add/' => sub {
post '/add/' => sub {
if ( param('login') && param('password') )
{
if ( param('login') && param('password') )
{
my $app = initco();
my ($success) = $app->register_user(param('login')
, param('password'));
my $app = initco();
my ($success) = $app->register_user(param('login')
, param('password'));
if($success) {
session login => param('login');
session password => param('password');
redirect '/home';
}
else {
session errmsg => q/Ce pseudo est déjà pris./;
redirect '/user/subscribe';
}
if($success) {
session login => param('login');
session password => param('password');
redirect '/home';
}
else {
session errmsg => q/Ce pseudo est déjà pris./;
redirect '/user/subscribe';
}
}
else {
session errmsg => q/login ou password non renseignés/;
redirect '/user/subscribe';
}
}
else {
session errmsg => q/login ou password non renseignés/;
redirect '/user/subscribe';
}
};
};
get '/subscribe' => sub {
get '/subscribe' => sub {
if( defined session('login') )
{
redirect '/home';
}
else {
if( defined session('login') )
{
redirect '/home';
}
else {
template subscribe => {
errmsg => get_errmsg
};
}
template subscribe => {
errmsg => get_errmsg
};
}
};
};
get '/unsetadmin/:user' => sub {
get '/unsetadmin/:user' => sub {
unless( defined param('user') )
{
unless( defined param('user') )
{
# TODO ajouter une erreur à afficher
session errmsg => "L'administrateur n'est pas défini." ;
redirect request->referer;
# TODO ajouter une erreur à afficher
session errmsg => "L'administrateur n'est pas défini." ;
redirect request->referer;
}
elsif(! defined session('login') )
{
}
elsif(! defined session('login') )
{
session errmsg => "Vous n'êtes pas connecté." ;
redirect '/';
session errmsg => "Vous n'êtes pas connecté." ;
redirect '/';
}
else {
}
else {
my $app = initco();
my $app = initco();
my ($auth_ok, $user, $isadmin) = $app->auth(session('login'),
session('password') );
my ($auth_ok, $user, $isadmin) = $app->auth(session('login'),
session('password') );
if ( $auth_ok && $isadmin ) {
$app->set_admin(param('user'), 0);
}
else {
session errmsg => q/Vous n'êtes pas administrateur./;
}
if ( $auth_ok && $isadmin ) {
$app->set_admin(param('user'), 0);
}
else {
session errmsg => q/Vous n'êtes pas administrateur./;
}
if( request->referer =~ "/admin" ) {
redirect request->referer;
}
else {
redirect '/';
}
if( request->referer =~ "/admin" ) {
redirect request->referer;
}
else {
redirect '/';
}
}
}
};
};
get '/setadmin/:user' => sub {
get '/setadmin/:user' => sub {
unless( defined param('user') )
{
unless( defined param('user') )
{
# TODO ajouter une erreur à afficher
session errmsg => "L'utilisateur n'est pas défini." ;
redirect request->referer;
# TODO ajouter une erreur à afficher
session errmsg => "L'utilisateur n'est pas défini." ;
redirect request->referer;
}
elsif(! defined session('login') )
{
}
elsif(! defined session('login') )
{
session errmsg => "Vous n'êtes pas connecté." ;
redirect '/';
session errmsg => "Vous n'êtes pas connecté." ;
redirect '/';
}
else {
}
else {
my $app = initco();
my $app = initco();
my ($auth_ok, $user, $isadmin) = $app->auth(session('login'),
session('password') );
my ($auth_ok, $user, $isadmin) = $app->auth(session('login'),
session('password') );
if ( $auth_ok && $isadmin ) {
$app->set_admin(param('user'), 1);
}
if ( $auth_ok && $isadmin ) {
$app->set_admin(param('user'), 1);
}
if( request->referer =~ "/admin" ) {
redirect request->referer;
}
else {
redirect '/';
}
if( request->referer =~ "/admin" ) {
redirect request->referer;
}
else {
redirect '/';
}
}
}
};
};
get '/del/:user' => sub {
get '/del/:user' => sub {
if(defined param 'user') {
if(defined param 'user') {
my $app = initco();
my $app = initco();
my ($auth_ok, $user, $isadmin) = $app->auth(session('login'),
session('password') );
my ($auth_ok, $user, $isadmin) = $app->auth(session('login'),
session('password') );
if ( $auth_ok && $isadmin || session('login') eq param('user')) {
unless ( $app->delete_user(param('user'))) {
session errmsg => "L'utilisateur "
. param 'user'
. " n'a pas pu être supprimé.";
}
}
}
else {
session errmsg => q{Le nom d'utilisateur n'est pas renseigné.};
}
if ( $auth_ok && $isadmin || session('login') eq param('user')) {
unless ( $app->delete_user(param('user'))) {
session errmsg => "L'utilisateur "
. param 'user'
. " n'a pas pu être supprimé.";
}
}
}
else {
session errmsg => q{Le nom d'utilisateur n'est pas renseigné.};
}
if( defined request->referer) {
redirect request->referer;
}
else {
redirect '/';
}
if( defined request->referer) {
redirect request->referer;
}
else {
redirect '/';
}
};
};
post '/login' => sub {
post '/login' => sub {
# Check if user is already logged
unless ( session('login') )
{
# Check user login and password
if ( param('login') && param('password') )
{
# Check if user is already logged
unless ( session('login') )
{
# Check user login and password
if ( param('login') && param('password') )
{
my $app = initco();
my ($auth_ok, $user, $isadmin) = $app->auth(param('login'),
param('password') );
my $app = initco();
my ($auth_ok, $user, $isadmin) = $app->auth(param('login'),
param('password') );
if( $auth_ok )
{
if( $auth_ok )
{
session login => param('login');
# TODO : change password storage…
session password => param('password');
session user => freeze( $user );
session admin => $isadmin;
session login => param('login');
# TODO : change password storage…
session password => param('password');
session user => freeze( $user );
session admin => $isadmin;
if( $isadmin ) {
redirect '/admin';
return;
}
if( $isadmin ) {
redirect '/admin';
return;
}
}
else
{
}
else
{
session errmsg => q<Impossible de se connecter (login ou mot de passe incorrect).>;
redirect '/';
session errmsg => q<Impossible de se connecter (login ou mot de passe incorrect).>;
redirect '/';
}
}
}
}
}
}
redirect '/home';
};
redirect '/home';
};
};

View File

@ -26,66 +26,84 @@
<% FOREACH address in ns %>
<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>NS</td>
<td><% address.host %></td>
<td><% address.ttl %></td>
<td><input type='text' name='newhost' class="form-control" value='<% address.host %>'/></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>
</tr>
<% END %>
<% FOREACH address in a %>
<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>A</td>
<td><% address.host %></td>
<td><% address.ttl %></td>
<td><input type='text' name='newhost' class="form-control" value='<% address.host %>'/></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>
</tr>
<% END %>
<% FOREACH address in aaaa %>
<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>AAAA</td>
<td><% address.host %></td>
<td><% address.ttl %></td>
<td><input type='text' name='newhost' class="form-control" value='<% address.host %>'/></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>
</tr>
<% END %>
<% FOREACH address in cname %>
<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>CNAME</td>
<td><% address.host %></td>
<td><% address.ttl %></td>
<td><input type='text' name='newhost' class="form-control" value='<% address.host %>'/></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>
</tr>
<% END %>
<% FOREACH address in ptr %>
<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>PTR</td>
<td><% address.host %></td>
<td><% address.ttl %></td>
<td><input type='text' name='newhost' class="form-control" value='<% address.host %>'/></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>
</tr>
<% END %>
<% FOREACH address in mx %>
<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>MX</td>
<td><% address.host %> (<% address.priority %>)</td>
<td><% address.ttl %></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><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>
</tr>
<% END %>