From b646f113787a54c244c4756498ef822217cd269c Mon Sep 17 00:00:00 2001
From: swaggboi
Date: Fri, 5 Mar 2021 16:01:18 -0500
Subject: [PATCH] Implemented /ula6 route and template; new layout for iframes
---
templates/index.html.ep | 2 +-
templates/layouts/swagg-iframe.html.ep | 11 +++++
templates/ula6.html.ep | 12 +++++
www-swagg.pl | 67 ++++++++++++++++++++++++--
4 files changed, 88 insertions(+), 4 deletions(-)
create mode 100644 templates/layouts/swagg-iframe.html.ep
create mode 100644 templates/ula6.html.ep
diff --git a/templates/index.html.ep b/templates/index.html.ep
index 1bef109..9507d3c 100644
--- a/templates/index.html.ep
+++ b/templates/index.html.ep
@@ -59,7 +59,7 @@
give it one. Maybe some wayward network nerd standing up an IPv6 lab
will find this useful :)
-
+
Limit of 1,208,925,819,614,629,174,706,176 ULA addresses per
customer.
diff --git a/templates/layouts/swagg-iframe.html.ep b/templates/layouts/swagg-iframe.html.ep
new file mode 100644
index 0000000..1a3f555
--- /dev/null
+++ b/templates/layouts/swagg-iframe.html.ep
@@ -0,0 +1,11 @@
+
+
+
+
+ <%= title %>
+
+
+
+<%= content %>
+
+
diff --git a/templates/ula6.html.ep b/templates/ula6.html.ep
new file mode 100644
index 0000000..53933a6
--- /dev/null
+++ b/templates/ula6.html.ep
@@ -0,0 +1,12 @@
+% title 'Swagg::Net ULA Tool';
+% layout 'swagg-iframe';
+<% if ($ula6) { %>
+
+<% } else { %>
+
+<% } %>
diff --git a/www-swagg.pl b/www-swagg.pl
index 4432ceb..6c2aadd 100755
--- a/www-swagg.pl
+++ b/www-swagg.pl
@@ -1,18 +1,79 @@
#!/usr/bin/env perl
-use Mojolicious::Lite;
+# Daniel Bowling
+# Mar 2021
+use Mojolicious::Lite;
+use Regexp::Common qw{net};
+use Digest::SHA qw{sha1_hex};
+
+# The main landing page; pass in the output of the fortune command
get '/' => sub {
my ($c) = @_;
- my $fortune = `fortune` || "huh??\n";
+ my $fortune = `fortune` || "huh?? no fortune for u\n";
- $c->render(fortune => $fortune)
+ $c->render(fortune => $fortune);
} => 'index';
+# Deprecation of IE page
get '/die';
get '/me';
get '/news';
+# 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
app->start();