2017-07-14 19:29:52 +02:00
|
|
|
package cyberman;
|
2017-07-16 18:13:15 +02:00
|
|
|
|
2017-07-14 19:29:52 +02:00
|
|
|
use Dancer2;
|
2017-07-15 20:24:05 +02:00
|
|
|
use Dancer2::Plugin::Database;
|
2017-07-14 19:29:52 +02:00
|
|
|
|
2017-07-17 09:55:50 +02:00
|
|
|
use cyberman::Domains;
|
|
|
|
use cyberman::Auth;
|
2017-07-17 15:25:45 +02:00
|
|
|
use cyberman::Account;
|
2017-07-17 09:55:50 +02:00
|
|
|
use cyberman::Helper;
|
2017-07-17 14:25:35 +02:00
|
|
|
use cyberman::API;
|
2017-08-11 22:28:32 +02:00
|
|
|
use cyberman::Records;
|
2017-08-19 16:03:54 +02:00
|
|
|
use cyberman::Forgot;
|
2017-09-09 00:27:05 +02:00
|
|
|
use cyberman::Admin;
|
2017-07-15 20:24:05 +02:00
|
|
|
|
2017-07-17 09:55:50 +02:00
|
|
|
# Index route, hook and helper functions for authentication
|
2017-07-15 20:24:05 +02:00
|
|
|
|
|
|
|
sub get_auth {
|
2017-08-20 00:45:25 +02:00
|
|
|
my $uid = shift;
|
|
|
|
my $token = shift;
|
2017-07-15 20:24:05 +02:00
|
|
|
|
2017-08-20 00:45:25 +02:00
|
|
|
my $result = database->quick_select("session", {"uid" => $uid, "token" => $token});
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
return $uid;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-15 20:24:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hook 'before' => sub {
|
2017-08-20 00:45:25 +02:00
|
|
|
sub cookieval {
|
|
|
|
my $name = shift;
|
|
|
|
my $cookie = cookie($name);
|
|
|
|
if ($cookie) {
|
|
|
|
return $cookie->value;
|
|
|
|
} else {
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my $uid = cookieval("id");
|
|
|
|
my $token = cookieval("token");
|
|
|
|
my $auth = 0;
|
2017-08-21 19:44:40 +02:00
|
|
|
my $user;
|
2017-08-20 00:45:25 +02:00
|
|
|
if ($uid && $token) {
|
|
|
|
$auth = get_auth($uid, $token);
|
2017-08-21 19:44:40 +02:00
|
|
|
$user = database->quick_select(
|
2017-08-20 00:45:25 +02:00
|
|
|
"user",
|
|
|
|
{
|
|
|
|
"id" => $uid,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2017-07-15 20:24:05 +02:00
|
|
|
|
2017-08-20 00:45:25 +02:00
|
|
|
var auth => $auth;
|
2017-08-21 19:44:40 +02:00
|
|
|
var email => $user->{"email"};
|
2017-09-09 00:27:05 +02:00
|
|
|
var admin => $user->{"admin"};
|
2017-08-20 00:45:25 +02:00
|
|
|
var config => config();
|
2017-08-21 19:44:40 +02:00
|
|
|
|
2017-09-14 18:15:02 +02:00
|
|
|
if ($user->{"admin"}) {
|
|
|
|
my $zone_check = database->quick_lookup(
|
|
|
|
"cyberman",
|
|
|
|
{},
|
|
|
|
"zonecheckstatus",
|
|
|
|
);
|
|
|
|
if ($zone_check != 0) {
|
|
|
|
var zone_check_alert => 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-21 20:00:13 +02:00
|
|
|
if ($user->{"stylesheet"} && grep {$_ eq $user->{"stylesheet"}} @{ config->{"stylesheets"}->{"available"} }) {
|
2017-08-21 19:44:40 +02:00
|
|
|
var stylesheet => $user->{"stylesheet"};
|
|
|
|
} else {
|
|
|
|
var stylesheet => config->{"stylesheets"}->{"default"};
|
|
|
|
}
|
2017-07-15 20:24:05 +02:00
|
|
|
};
|
2017-07-14 19:29:52 +02:00
|
|
|
|
2017-07-15 23:08:11 +02:00
|
|
|
get qr{^/(index)?$} => sub {
|
2017-08-20 00:45:25 +02:00
|
|
|
if (!vars->{auth}) {
|
|
|
|
return template 'index';
|
|
|
|
}
|
2017-07-16 18:13:15 +02:00
|
|
|
|
2017-08-20 00:45:25 +02:00
|
|
|
template 'redir' => {
|
|
|
|
"redir" => "domains",
|
|
|
|
};
|
2017-07-15 20:24:05 +02:00
|
|
|
};
|
|
|
|
|
2017-07-14 19:29:52 +02:00
|
|
|
true;
|