2021-02-27 00:39:40 -05:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
2021-03-05 16:01:18 -05:00
|
|
|
# Daniel Bowling <swaggboi@slackware.uk>
|
|
|
|
# Mar 2021
|
|
|
|
|
2021-02-27 00:39:40 -05:00
|
|
|
use Mojolicious::Lite;
|
2021-03-05 16:01:18 -05:00
|
|
|
use Regexp::Common qw{net};
|
|
|
|
use Digest::SHA qw{sha1_hex};
|
2021-03-06 17:20:56 -05:00
|
|
|
use Number::Format qw{format_number};
|
2021-02-27 00:39:40 -05:00
|
|
|
|
2021-03-12 23:22:50 -05:00
|
|
|
plugin 'Config';
|
|
|
|
|
2021-03-12 20:07:57 -05:00
|
|
|
# CGI scripts
|
2021-06-03 23:56:51 -04:00
|
|
|
plugin CGI => ['/cgi-bin/guest.cgi', './cgi-bin/guest_mm.cgi'];
|
|
|
|
plugin CGI => ['/cgi-bin/whoami.cgi', './cgi-bin/whoami.cgi'];
|
2021-03-07 20:44:58 -05:00
|
|
|
|
2021-03-13 02:21:16 -05:00
|
|
|
# Handle the session
|
2021-03-13 02:15:04 -05:00
|
|
|
under sub {
|
2021-03-29 15:02:41 -04:00
|
|
|
my ($c) = @_;
|
|
|
|
my $sessionLife = 604800;
|
2021-03-12 23:22:50 -05:00
|
|
|
|
|
|
|
if ($c->cookie('banner') eq 'seen') {
|
2021-03-29 13:51:37 -04:00
|
|
|
# Set session for a week
|
2021-03-29 15:02:41 -04:00
|
|
|
$c->session(expiration => $sessionLife, banner => 'seen');
|
2021-03-29 13:51:37 -04:00
|
|
|
# Kill plain-text cookie
|
|
|
|
$c->cookie(banner => 'seen', {expires => 1});
|
2021-03-12 23:22:50 -05:00
|
|
|
}
|
|
|
|
|
2021-03-29 15:02:41 -04:00
|
|
|
# Pass in the expiration for plain-text cookie
|
|
|
|
$c->stash(sessionLife => $sessionLife);
|
|
|
|
|
2021-04-20 13:11:32 -04:00
|
|
|
# Opt out of Google FLoC
|
|
|
|
# https://paramdeo.com/blog/opting-your-website-out-of-googles-floc-network
|
|
|
|
$c->res->headers->header('Permissions-Policy', 'interest-cohort=()');
|
|
|
|
|
2021-03-13 02:25:06 -05:00
|
|
|
1;
|
2021-03-13 02:15:04 -05:00
|
|
|
};
|
2021-03-12 23:22:50 -05:00
|
|
|
|
2021-03-13 02:15:04 -05:00
|
|
|
# The main landing page; index.html
|
2021-05-31 00:57:39 -04:00
|
|
|
get '/', sub {
|
2021-02-28 02:27:38 -05:00
|
|
|
my ($c) = @_;
|
2021-03-07 20:55:34 -05:00
|
|
|
my $count = format_number time; # Grab epoch and add commas
|
2021-03-06 20:24:16 -05:00
|
|
|
my $fortune = `/usr/games/fortune` || `fortune` || "huh??\n";
|
2021-03-06 17:20:56 -05:00
|
|
|
|
2021-03-09 21:31:15 -05:00
|
|
|
$c->stash(
|
2021-03-06 17:20:56 -05:00
|
|
|
count => $count,
|
|
|
|
fortune => $fortune
|
|
|
|
);
|
|
|
|
|
2021-03-09 21:31:15 -05:00
|
|
|
$c->render();
|
2021-05-31 00:57:39 -04:00
|
|
|
}, 'index';
|
2021-02-27 00:39:40 -05:00
|
|
|
|
2021-03-05 16:01:18 -05:00
|
|
|
# Process mac address to ula6 ala the ol' ula6.cgi script:
|
|
|
|
# - Current time of day in 64-bit NTP format
|
|
|
|
# - Obtain EUI64
|
|
|
|
# - Cat first with second
|
|
|
|
# - Compute SHA-1 of third and use least significant 40 bits
|
|
|
|
# TODO: This ancient code could certainly be cleaned up
|
2021-05-31 00:57:39 -04:00
|
|
|
get '/ula6', sub {
|
2021-03-07 20:57:42 -05:00
|
|
|
my ($c) = @_;
|
2021-03-07 20:44:58 -05:00
|
|
|
my ($mac, $ula6);
|
2021-03-05 16:01:18 -05:00
|
|
|
|
|
|
|
# Check the MAC
|
2021-04-15 21:52:41 -04:00
|
|
|
$mac = $c->param('macaddr') ? lc $c->param('macaddr') : '';
|
2021-03-12 23:22:50 -05:00
|
|
|
if ($mac =~ /$RE{net}{MAC}/) {
|
2021-03-05 16:01:18 -05:00
|
|
|
# Local vars for this bit
|
|
|
|
my (
|
|
|
|
$binfield,
|
|
|
|
$decfield,
|
|
|
|
$digesty,
|
|
|
|
$epoch,
|
|
|
|
@fields,
|
|
|
|
$fulleui,
|
|
|
|
$halfone,
|
|
|
|
$halftwo,
|
|
|
|
$hexfield,
|
|
|
|
$uniqueid
|
|
|
|
);
|
|
|
|
|
|
|
|
# EUI64
|
|
|
|
@fields = split(/:/, $mac);
|
2021-04-15 21:52:41 -04:00
|
|
|
$halftwo = "fe" . $fields[3] . $fields[4] . $fields[5];
|
2021-03-05 16:01:18 -05:00
|
|
|
$binfield = sprintf "%b", hex $fields[0];
|
|
|
|
$decfield = sprintf "%d", hex $fields[0];
|
2021-03-05 22:31:48 -05:00
|
|
|
$decfield = ($binfield =~ /1[01]$/) ? $decfield - 2 : $decfield + 2;
|
2021-03-05 16:01:18 -05:00
|
|
|
$hexfield = sprintf "%x", int $decfield;
|
|
|
|
$halfone = $hexfield . $fields[1] . $fields[2] . "ff";
|
|
|
|
$fulleui = $halfone . $halftwo;
|
|
|
|
|
|
|
|
# Current time of day
|
|
|
|
$epoch = time() + 2208988800;
|
|
|
|
|
|
|
|
# Cat with the time
|
|
|
|
$digesty = sha1_hex($epoch . $fulleui);
|
2021-04-15 22:21:43 -04:00
|
|
|
($uniqueid = "fd" . substr $digesty, -10) =~ s/(.{4})/$1:/g;
|
2021-03-05 16:01:18 -05:00
|
|
|
|
|
|
|
# Set the ULA
|
|
|
|
$ula6 = $uniqueid . ':/48';
|
|
|
|
}
|
|
|
|
|
|
|
|
$c->render(ula6 => $ula6);
|
|
|
|
};
|
|
|
|
|
2022-01-05 21:44:58 -05:00
|
|
|
# Reset session cookie
|
|
|
|
get '/reset', sub {
|
|
|
|
my ($c) = @_;
|
|
|
|
|
|
|
|
$c->session(expires => 1);
|
|
|
|
$c->redirect_to('index');
|
|
|
|
};
|
|
|
|
|
2021-03-13 02:15:04 -05:00
|
|
|
# Default route
|
2021-05-31 00:57:39 -04:00
|
|
|
get '/:route', [route => [qw{die me news portal}]], sub {
|
2021-03-13 23:26:17 -05:00
|
|
|
my ($c) = @_;
|
2021-03-12 20:07:57 -05:00
|
|
|
|
2021-03-13 02:19:51 -05:00
|
|
|
$c->render(template => $c->stash('route'));
|
2021-03-12 20:07:57 -05:00
|
|
|
};
|
|
|
|
|
2021-03-13 02:15:04 -05:00
|
|
|
# Send it
|
2021-03-12 23:22:50 -05:00
|
|
|
app->secrets(app->config->{secrets}) || die $!;
|
2021-02-27 00:39:40 -05:00
|
|
|
app->start();
|