2021-02-27 05:39:40 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
2021-03-05 21:01:18 +00:00
|
|
|
# Daniel Bowling <swaggboi@slackware.uk>
|
|
|
|
# Mar 2021
|
|
|
|
|
2021-02-27 05:39:40 +00:00
|
|
|
use Mojolicious::Lite;
|
2021-03-05 21:01:18 +00:00
|
|
|
use Regexp::Common qw{net};
|
|
|
|
use Digest::SHA qw{sha1_hex};
|
2021-02-27 05:39:40 +00:00
|
|
|
|
2021-03-05 21:01:18 +00:00
|
|
|
# The main landing page; pass in the output of the fortune command
|
2021-02-27 05:39:40 +00:00
|
|
|
get '/' => sub {
|
2021-02-28 07:27:38 +00:00
|
|
|
my ($c) = @_;
|
2021-03-05 21:01:18 +00:00
|
|
|
my $fortune = `fortune` || "huh?? no fortune for u\n";
|
2021-02-27 06:14:38 +00:00
|
|
|
|
2021-03-05 21:01:18 +00:00
|
|
|
$c->render(fortune => $fortune);
|
2021-02-27 05:39:40 +00:00
|
|
|
} => 'index';
|
|
|
|
|
2021-03-05 21:01:18 +00:00
|
|
|
# Deprecation of IE page
|
2021-02-28 06:33:35 +00:00
|
|
|
get '/die';
|
2021-02-27 06:24:34 +00:00
|
|
|
|
2021-02-28 06:33:35 +00:00
|
|
|
get '/me';
|
2021-02-27 06:24:34 +00:00
|
|
|
|
2021-02-28 06:33:35 +00:00
|
|
|
get '/news';
|
2021-02-27 06:24:34 +00:00
|
|
|
|
2021-03-05 21:01:18 +00: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
|
|
|
|
get '/ula6' => sub {
|
|
|
|
my ($c) = @_;
|
|
|
|
my $mac = lc $c->param('macaddr'); # Lower-case plz
|
|
|
|
my $ula6;
|
|
|
|
|
|
|
|
# Check the MAC
|
|
|
|
if ($mac =~ /$RE{net}{MAC}/) {
|
|
|
|
# Local vars for this bit
|
|
|
|
my (
|
|
|
|
$binfield,
|
|
|
|
$decfield,
|
|
|
|
$digesty,
|
|
|
|
$epoch,
|
|
|
|
@fields,
|
|
|
|
$fulleui,
|
|
|
|
$halfone,
|
|
|
|
$halftwo,
|
|
|
|
$hexfield,
|
|
|
|
$uniqueid
|
|
|
|
);
|
|
|
|
|
|
|
|
# EUI64
|
|
|
|
@fields = split(/:/, $mac);
|
|
|
|
$halfone = $fields[0] . $fields[1] . $fields[2] . "ff";
|
|
|
|
$halftwo = "fe" . $fields[3] . $fields[4] . $fields[5];
|
|
|
|
$binfield = sprintf "%b", hex $fields[0];
|
|
|
|
$decfield = sprintf "%d", hex $fields[0];
|
|
|
|
$decfield = ($binfield =~ m/1[01]$/) ? $decfield - 2 : $decfield + 2;
|
|
|
|
$binfield = sprintf "%b", int $decfield;
|
|
|
|
$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);
|
|
|
|
($uniqueid = "fd" . substr $digesty, -10) =~ s/(.{1,4})/$1:/gs;
|
|
|
|
|
|
|
|
# Set the ULA
|
|
|
|
$ula6 = $uniqueid . ':/48';
|
|
|
|
}
|
|
|
|
|
|
|
|
$c->render(ula6 => $ula6);
|
|
|
|
};
|
|
|
|
|
|
|
|
# Send it
|
2021-02-27 05:39:40 +00:00
|
|
|
app->start();
|