2015-10-13 19:06:37 +02:00
|
|
|
package MyWeb::App;
|
|
|
|
|
|
|
|
use v5.14;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2016-01-21 20:52:59 +01:00
|
|
|
use utf8;
|
|
|
|
use open qw/:std :utf8/;
|
2015-10-13 19:06:37 +02:00
|
|
|
|
|
|
|
use Dancer2;
|
|
|
|
use Dancer2::Plugin::Deferred;
|
|
|
|
use File::Basename;
|
|
|
|
#use Storable qw( freeze thaw );
|
|
|
|
#$Storable::Deparse = true;
|
|
|
|
#$Storable::Eval=true;
|
|
|
|
|
|
|
|
use YAML::XS;
|
|
|
|
use configuration ':all';
|
|
|
|
use util ':all';
|
2016-01-13 04:11:46 +01:00
|
|
|
|
2015-10-13 19:06:37 +02:00
|
|
|
use rt::root ':all';
|
|
|
|
use rt::domain ':all';
|
|
|
|
use rt::user ':all';
|
|
|
|
use rt::admin ':all';
|
2016-01-13 04:11:46 +01:00
|
|
|
|
|
|
|
use rt::rootfake ':all';
|
|
|
|
use rt::domainfake ':all';
|
|
|
|
use rt::userfake ':all';
|
|
|
|
use rt::adminfake ':all';
|
2015-10-13 19:06:37 +02:00
|
|
|
use app;
|
|
|
|
|
2016-01-13 04:11:46 +01:00
|
|
|
our $isviewtest = is_view_test(get_cfg());
|
|
|
|
|
2015-10-13 19:06:37 +02:00
|
|
|
our $VERSION = '0.1';
|
|
|
|
|
2016-01-19 05:26:54 +01:00
|
|
|
get '/info' => sub {
|
|
|
|
my $str = "This is : " . config->{appname} . "<br>";
|
|
|
|
$str .= "environment : " . config->{environment} . "<br>";
|
|
|
|
};
|
|
|
|
|
2015-10-13 19:06:37 +02:00
|
|
|
sub what_is_next {
|
|
|
|
my ($res) = @_;
|
|
|
|
|
|
|
|
if($$res{sessiondestroy}) {
|
|
|
|
app->destroy_session;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(keys %{$$res{deferred}}) {
|
|
|
|
deferred $_ => $$res{deferred}{$_};
|
|
|
|
}
|
|
|
|
|
|
|
|
for(keys %{$$res{addsession}}) {
|
2015-12-28 01:29:24 +01:00
|
|
|
say "ajout de la session $_ : $$res{addsession}{$_}";
|
2015-10-13 19:06:37 +02:00
|
|
|
session $_ => $$res{addsession}{$_};
|
|
|
|
}
|
|
|
|
|
|
|
|
for(keys %{$$res{delsession}}) {
|
|
|
|
session $_ => undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(exists $$res{route}) {
|
|
|
|
redirect $$res{route};
|
|
|
|
}
|
|
|
|
elsif(exists $$res{template}) {
|
|
|
|
template $$res{template} => $$res{params};
|
|
|
|
} else {
|
|
|
|
redirect '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_param {
|
|
|
|
my $param_values;
|
|
|
|
for(@_) {
|
|
|
|
$$param_values{$_} = param "$_";
|
|
|
|
}
|
|
|
|
$param_values;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_request {
|
|
|
|
my $request_values;
|
|
|
|
for(@_) {
|
|
|
|
if(/^address$/) { $$request_values{$_} = request->address; }
|
|
|
|
elsif(/^referer$/) { $$request_values{$_} = request->referer; }
|
|
|
|
}
|
|
|
|
$request_values;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_session {
|
|
|
|
my $session_values;
|
|
|
|
for(@_) {
|
|
|
|
$$session_values{$_} = session "$_";
|
|
|
|
}
|
|
|
|
$session_values;
|
|
|
|
}
|
|
|
|
|
|
|
|
get '/' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_root_fake if $isviewtest;
|
2015-10-13 19:06:37 +02:00
|
|
|
what_is_next rt_root
|
|
|
|
get_session( qw/login passwd/ );
|
|
|
|
};
|
|
|
|
|
|
|
|
prefix '/domain' => sub {
|
|
|
|
|
2015-12-21 09:39:50 +01:00
|
|
|
post '/updateraw/:domain' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_dom_updateraw_fake
|
|
|
|
"" , "" , get_request( qw/address referer/ )
|
|
|
|
if $isviewtest;
|
2015-10-13 19:06:37 +02:00
|
|
|
what_is_next rt_dom_updateraw
|
|
|
|
get_session( qw/login passwd/ )
|
|
|
|
, get_param( qw/domain zoneupdated/)
|
|
|
|
, get_request( qw/address referer/ );
|
|
|
|
};
|
|
|
|
|
2015-12-21 09:39:50 +01:00
|
|
|
post '/update/:domain' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_dom_add_entry_fake
|
|
|
|
"" , "", get_request( qw/referer/ )
|
|
|
|
if $isviewtest;
|
2015-12-22 17:50:26 +01:00
|
|
|
what_is_next rt_dom_add_entry
|
2015-10-13 19:06:37 +02:00
|
|
|
get_session( qw/login passwd/ )
|
2015-12-22 17:50:26 +01:00
|
|
|
, get_param( qw/domain type name ttl priority weight port rdata/ )
|
|
|
|
, get_request( qw/referer/ );
|
2015-10-13 19:06:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
get '/details/:domain' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_dom_details_fake ""
|
|
|
|
, get_param( qw/expert/ )
|
|
|
|
, get_request( qw/address referer/ ) if $isviewtest;
|
2015-10-13 19:06:37 +02:00
|
|
|
what_is_next rt_dom_details
|
|
|
|
get_session( qw/login passwd/ )
|
|
|
|
, get_param( qw/domain expert/ )
|
|
|
|
, get_request( qw/address referer/ );
|
|
|
|
};
|
|
|
|
|
|
|
|
post '/add/' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_dom_add_fake if $isviewtest;
|
2015-10-13 19:06:37 +02:00
|
|
|
what_is_next rt_dom_add
|
|
|
|
get_session( qw/login passwd/ )
|
|
|
|
, get_param( qw/domain tld/ );
|
|
|
|
};
|
|
|
|
|
|
|
|
get '/del/:domain' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_dom_del_fake
|
|
|
|
"" , "", get_request( qw/address referer/ )
|
|
|
|
if $isviewtest;
|
2015-10-13 19:06:37 +02:00
|
|
|
what_is_next rt_dom_del
|
|
|
|
get_session( qw/login passwd/ )
|
|
|
|
, get_param( qw/domain/ )
|
|
|
|
, get_request( qw/address referer/ );
|
|
|
|
};
|
|
|
|
|
2015-12-22 17:50:26 +01:00
|
|
|
get '/del/:domain/:name/:ttl/:type/:priority/:rdata' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_dom_del_entry_fake
|
|
|
|
"" , "", get_request( qw/address referer/ )
|
|
|
|
if $isviewtest;
|
2015-12-22 17:50:26 +01:00
|
|
|
what_is_next rt_dom_del_entry
|
|
|
|
get_session( qw/login passwd/ )
|
|
|
|
, get_param( qw/domain name ttl type priority rdata/ )
|
|
|
|
, get_request( qw/address referer/ );
|
|
|
|
};
|
|
|
|
|
|
|
|
get '/del/:domain/:name/:ttl/:type/:priority/:weight/:port/:rdata' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_dom_del_entry_fake
|
|
|
|
"" , "", get_request( qw/address referer/ )
|
|
|
|
if $isviewtest;
|
2015-12-22 17:50:26 +01:00
|
|
|
what_is_next rt_dom_del_entry
|
|
|
|
get_session( qw/login passwd/ )
|
|
|
|
, get_param( qw/domain name ttl type priority weight port rdata/ )
|
|
|
|
, get_request( qw/address referer/ );
|
|
|
|
};
|
|
|
|
|
2015-12-21 09:39:50 +01:00
|
|
|
get '/del/:domain/:name/:ttl/:type/:rdata' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_dom_del_entry_fake
|
|
|
|
"" , "", get_request( qw/address referer/ )
|
|
|
|
if $isviewtest;
|
2015-10-13 19:06:37 +02:00
|
|
|
what_is_next rt_dom_del_entry
|
|
|
|
get_session( qw/login passwd/ )
|
2015-12-21 09:39:50 +01:00
|
|
|
, get_param( qw/domain name type ttl rdata/ )
|
2015-10-13 19:06:37 +02:00
|
|
|
, get_request( qw/address referer/ );
|
|
|
|
};
|
|
|
|
|
2015-12-21 09:39:50 +01:00
|
|
|
post '/mod/:domain' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_dom_mod_entry_fake
|
|
|
|
"" , "", get_request( qw/address referer/ )
|
|
|
|
if $isviewtest;
|
2015-10-13 19:06:37 +02:00
|
|
|
what_is_next rt_dom_mod_entry
|
|
|
|
get_session( qw/login passwd/ )
|
2015-12-22 17:50:26 +01:00
|
|
|
, get_param( qw/domain type
|
|
|
|
oldpriority oldname oldttl oldrdata oldweight oldport
|
|
|
|
newpriority newname newttl newrdata newweight newport/ )
|
2015-10-13 19:06:37 +02:00
|
|
|
, get_request( qw/address referer/ );
|
|
|
|
};
|
|
|
|
|
2015-12-22 22:31:14 +01:00
|
|
|
get '/cliup/:login/:pass/:domain/:name/:type/:rdata' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_dom_cli_autoupdate_fake if $isviewtest;
|
2015-12-22 22:31:14 +01:00
|
|
|
what_is_next rt_dom_cli_autoupdate
|
|
|
|
get_session( qw// )
|
|
|
|
, get_param( qw/login pass domain name type rdata/ );
|
|
|
|
};
|
|
|
|
|
2015-12-21 09:39:50 +01:00
|
|
|
get '/cli/:login/:pass/:domain/:name/:type/:rdata/:ttl/:ip' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_dom_cli_mod_entry_fake if $isviewtest;
|
2015-10-13 19:06:37 +02:00
|
|
|
what_is_next rt_dom_cli_mod_entry
|
2015-12-22 22:31:14 +01:00
|
|
|
get_session( qw// )
|
|
|
|
, get_param( qw/login pass domain name type rdata ttl ip/ );
|
2015-10-13 19:06:37 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
any ['get', 'post'] => '/admin' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_admin_fake if $isviewtest;
|
2015-10-13 19:06:37 +02:00
|
|
|
what_is_next rt_admin
|
|
|
|
get_session( qw/login passwd/ );
|
|
|
|
};
|
|
|
|
|
|
|
|
prefix '/user' => sub {
|
|
|
|
|
|
|
|
get '/home' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_user_home_fake if $isviewtest;
|
2015-10-13 19:06:37 +02:00
|
|
|
what_is_next rt_user_home
|
|
|
|
get_session( qw/login passwd/ )
|
|
|
|
, get_param( qw// )
|
|
|
|
, get_request( qw// );
|
|
|
|
};
|
|
|
|
|
|
|
|
get '/logout' => sub {
|
|
|
|
app->destroy_session;
|
|
|
|
redirect '/';
|
|
|
|
};
|
|
|
|
|
|
|
|
get '/del/:user' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_user_del_fake
|
|
|
|
"" , "", get_request( qw/address referer/ )
|
|
|
|
if $isviewtest;
|
2015-10-13 19:06:37 +02:00
|
|
|
what_is_next rt_user_del
|
|
|
|
get_session( qw/login passwd/ )
|
|
|
|
, get_param( qw/user/ )
|
|
|
|
, get_request( qw/referer/ );
|
|
|
|
};
|
|
|
|
|
|
|
|
# add a user => registration
|
|
|
|
post '/add/' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_user_add_fake if $isviewtest;
|
2015-10-13 19:06:37 +02:00
|
|
|
what_is_next rt_user_add
|
|
|
|
get_session( qw// )
|
|
|
|
, get_param( qw/login password password2/ )
|
|
|
|
, get_request( qw// );
|
|
|
|
};
|
|
|
|
|
|
|
|
get '/subscribe' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_user_subscribe_fake if $isviewtest;
|
2015-10-13 19:06:37 +02:00
|
|
|
what_is_next rt_user_subscribe
|
|
|
|
get_session( qw/login/ );
|
|
|
|
};
|
|
|
|
|
2015-12-28 01:29:24 +01:00
|
|
|
post '/changepasswd' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_user_changepasswd_fake if $isviewtest;
|
2015-12-28 01:29:24 +01:00
|
|
|
what_is_next rt_user_changepasswd
|
|
|
|
get_session( qw/login/ )
|
|
|
|
, get_param( qw/password/ );
|
|
|
|
};
|
|
|
|
|
2015-10-13 19:06:37 +02:00
|
|
|
get '/toggleadmin/:user' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_user_toggleadmin_fake
|
|
|
|
"" , "", get_request( qw/referer/ )
|
|
|
|
if $isviewtest;
|
2015-10-13 19:06:37 +02:00
|
|
|
what_is_next rt_user_toggleadmin
|
|
|
|
get_session( qw/login passwd/ )
|
|
|
|
, get_param( qw/user/ )
|
|
|
|
, get_request( qw/referer/ );
|
|
|
|
};
|
|
|
|
|
|
|
|
post '/login' => sub {
|
2016-01-13 04:11:46 +01:00
|
|
|
return what_is_next rt_user_login_fake
|
|
|
|
"" , "", get_request( qw/referer/ )
|
|
|
|
if $isviewtest;
|
2015-10-13 19:06:37 +02:00
|
|
|
what_is_next rt_user_login
|
|
|
|
get_session( qw/login/ )
|
|
|
|
, get_param( qw/login password/ )
|
|
|
|
, get_request( qw/referer/ );
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
true;
|