Implement session cookie

This commit is contained in:
swagg boi 2021-03-12 23:22:50 -05:00
parent f2c8b04d88
commit 3fecb71e1e
3 changed files with 39 additions and 17 deletions

3
.gitignore vendored
View file

@ -42,3 +42,6 @@ inc/
/.mmCreds.xml
/.msg.bans
/.name.bans
# Conf file
/www-swagg.conf

View file

@ -7,14 +7,12 @@
<link rel="stylesheet" type="text/css" href="/css/swagg.css">
</head>
<body>
<!-- Import jQuery -->
<script src="/js/jquery.js"></script>
<script src="/js/jquery.cookie.js"></script>
<!-- Soundtrack -->
<!-- <embed> doesn't work anymore SAD
<embed src="/misc/Smashmouth_-_All_Star.mid" width="100%" height="60">-->
<audio id="soundtrack" src="/Music/Smashmouth-All-Star.mp3" preload="auto">
</audio>
<% unless (session('banner') eq 'seen') { %>
<!-- "GDPR" banner -->
<div id="gdpr">
<b>Notice:</b> This site uses kickass MIDI technology instead of cookies.
@ -27,22 +25,15 @@
<script>
function closeIt() {
document.getElementById("gdpr").style.display = "none";
if ($.cookie("banner")) {
return;
} else {
document.cookie = "banner=seen";
}
document.cookie = "banner=seen; max-age=300;";
}
function playIt() {
document.getElementById("soundtrack").play();
closeIt();
}
if ($.cookie("banner") === "seen") {
closeIt();
}
</script>
<% } %>
<!-- Bonzi buddy -->
<div id="bonzi">
<img alt="a purple gorilla" src="/Pictures/Bonzi_Buddy.png">
@ -63,10 +54,15 @@
</div>
<div class="outer">
<center>
<a href="/">Home <img alt="american flag" src="/Pictures/patriotic45.gif" height="16"></a> -
<a href="/">Home <img alt="american flag" src="/Pictures/patriotic45.gif"
height="16"></a> -
<a href="/me">Me <img alt="BSOD" src="/Pictures/bluscrn.gif"
height="16"></a> -
<a href="/news">News <img alt="update" src="/Pictures/updat4.gif"></a><br>
<a href="/news">News <img alt="update" src="/Pictures/updat4.gif"></a> -
<a href="https://blog.swagg.net">Web Log <img alt="book"
src="/Pictures/Simple_book.gif"
height="18">
</a><br>
<br>
</center>
<hr>
@ -78,7 +74,7 @@
<p>
<i>contact:</i>
<a href="mailto:swaggboi@slackware.uk">swaggboi@slackware.uk</a> -
<a href="https://eattherich.club/@swaggboi">Mastodon (@swaggboi)</a> -
<a href="https://eattherich.club/@swaggboi">Social (@swaggboi)</a> -
<a href="https://steamcommunity.com/id/danielbowling">Steam</a> -
<a href="https://chat.swagg.net">Chat (Mattermost)</a>
</p>

View file

@ -8,16 +8,33 @@ use Regexp::Common qw{net};
use Digest::SHA qw{sha1_hex};
use Number::Format qw{format_number};
## Let's set some things up first ##
plugin 'Config';
# CGI scripts
plugin CGI => ['/cgi-bin/guest' => './cgi-bin/guest_mm.cgi'];
plugin CGI => ['/cgi-bin/whoami' => './cgi-bin/whoami.cgi' ];
# Handle the GDPR non-compliance banner via session cookie
helper swaggSession => sub {
my ($c) = @_;
if ($c->cookie('banner') eq 'seen') {
$c->session->{banner} = 'seen' unless $c->session->{banner}
}
};
## Begin routes ##
# The main landing page; pass in the output of the fortune command
get '/' => sub {
my ($c) = @_;
my $count = format_number time; # Grab epoch and add commas
my $fortune = `/usr/games/fortune` || `fortune` || "huh??\n";
$c->swaggSession();
$c->stash(
count => $count,
fortune => $fortune
@ -38,7 +55,7 @@ get '/ula6' => sub {
# Check the MAC
$mac = ($c->param('macaddr')) ? lc $c->param('macaddr') : '';
if ($mac =~ /$RE{'net'}{'MAC'}/) {
if ($mac =~ /$RE{net}{MAC}/) {
# Local vars for this bit
my (
$binfield,
@ -75,6 +92,8 @@ get '/ula6' => sub {
$ula6 = $uniqueid . ':/48';
}
$c->swaggSession();
$c->render(ula6 => $ula6);
};
@ -83,8 +102,12 @@ get '/:route' => sub {
my ($c) = @_;
my $route = $c->stash('route');
$c->swaggSession();
$c->render(template => $route);
};
# Send it
## Send it ##
app->secrets(app->config->{secrets}) || die $!;
app->start();