Last active
September 13, 2023 01:03
-
-
Save afresh1/1027d4bcfd6e5586292cb2c18da28fcb to your computer and use it in GitHub Desktop.
mwl posted a script on his blog (https://mwl.io/archives/23082) that seems to indicate that he actually runs it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.16; | |
use warnings; | |
#manages the narcissistic bibliography MIB | |
#deploy as: | |
#rocommunity megadweeb 0.0.0.0/0 1.3.6.1.4.1.55030 | |
#rocommunity6 megadweeb 0::/0 1.3.6.1.4.1.55030 | |
#pass_persist .1.3.6.1.4.1.55030.1.1.1 /usr/local/scripts/persistwp.pl | |
my $DEBUG = 0; | |
#open STDERR, '>', '/tmp/agent.log' or die $!; | |
#STDERR->autoflush(1); | |
#say STDERR "$_: $ENV{$_}" for sort keys %ENV; | |
my $place = ".1.3.6.1.4.1.55030.1.1.1"; # TWP mwlbooks OID | |
#$place = ".1.3.6.1.3.1"; #experimental OID for testing | |
$| = 1; #flush buffer after every print | |
#save the PID file | |
my $PIDFILE = "/var/run/pass_persist.pid"; | |
if ( open my $fh, ">$PIDFILE" ) { | |
print $fh "$$\n"; | |
close $fh; | |
} | |
else { | |
say STDERR "Unable to open PIDFILE $PIDFILE for writing"; | |
} | |
#the data, FSM help us | |
my @columns = ( | |
#column 0: invalid OID | |
undef, | |
#column 1: the row index, no key needed | |
{ type => 'integer' }, | |
#column 2: the titles, where all goes bad | |
{ key => 'title', type => 'string' }, | |
#column 3, year | |
{ key => 'year', type => 'integer' }, | |
#column 4, type of book/genre | |
# 1 = fiction, 2 = nonfiction | |
{ key => 'genre', type => 'integer' }, | |
#column 5, length | |
# 1 = full length, 2 = novella, 3 = story, 4 = anthology appearance | |
{ key => 'length', type => 'integer' }, | |
); | |
my @books = ( | |
undef, # Can't use 0 as an OID | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'Gatecrasher', | |
'year' => 1992, | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'Believe it or Else!', | |
'year' => 1993 | |
}, | |
{ 'genre' => 1, | |
'length' => 2, | |
'title' => | |
'SLUGS: The Satanic, Loathsome, Unholy Game System (as Greg Donner)', | |
'year' => 1994 | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'Gatecrasher 2nd edition', | |
'year' => 1995 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Women who Run with the Werewolves', | |
'year' => 1995 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'Absolute BSD', | |
'year' => 2002 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'Absolute OpenBSD', | |
'year' => 2003 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'Cisco Routers for the Desperate', | |
'year' => 2004 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'PGP & GPG', | |
'year' => 2006 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'Absolute FreeBSD, 2nd edition', | |
'year' => 2007 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'Cisco Routers for the Desperate, 2nd edition', | |
'year' => 2009 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'Network Flow Analysis', | |
'year' => 2010 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Horror Library volume 2', | |
'year' => 2010 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Opening the Eye', | |
'year' => 2011 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Breaking the Circle', | |
'year' => 2011 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'SSH Mastery', | |
'year' => 2012 | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'Vicious Redemption: Five Dark Fantasies', | |
'year' => 2012 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'DNSSEC Mastery', | |
'year' => 2013 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'Sudo Mastery', | |
'year' => 2013 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'Absolute OpenBSD, 2nd ed', | |
'year' => 2013 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'No More Lonesome Blue Rings', | |
'year' => 2013 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Sticky Supersaturation', | |
'year' => 2013 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Lavender', | |
'year' => 2013 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Pax Canina', | |
'year' => 2013 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Wednesday\'s Seagulls', | |
'year' => 2013 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'FreeBSD Mastery: Storage Essentials', | |
'year' => 2014 | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'Immortal Clay', | |
'year' => 2014 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Waking Up Yesterday', | |
'year' => 2014 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Calling Control', | |
'year' => 2014 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Moonlight\'s Apples', | |
'year' => 2014 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'Networking for Systems Administrators', | |
'year' => 2015 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'Tarsnap Mastery', | |
'year' => 2015 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'FreeBSD Mastery: ZFS', | |
'year' => 2015 | |
}, | |
{ 'genre' => 1, | |
'length' => 2, | |
'title' => 'Forever Falls', | |
'year' => 2015 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Spilled Mirovar (Prohibition Orcs 1)', | |
'year' => 2015 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Whisker Line', | |
'year' => 2015 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Wifi and Romex', | |
'year' => 2015 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'PAM Mastery', | |
'year' => 2016 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'FreeBSD Mastery: Advanced ZFS', | |
'year' => 2016 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'FreeBSD Mastery: Advanced ZedFS', | |
'year' => 2016 | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'Kipuka Blues (Immortal Clay #2)', | |
'year' => 2016 | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'Hydrogen Sleets', | |
'year' => 2016 | |
}, | |
{ 'genre' => 1, | |
'length' => 2, | |
'title' => 'Drowned Mirovar (Prohibition Orcs #2)', | |
'year' => 2016 | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'Butterfly Stomp Waltz (Beaks #1)', | |
'year' => 2016 | |
}, | |
{ 'genre' => 1, | |
'length' => 2, | |
'title' => 'Earthquake Kitten Kiss (Beaks spin-off)', | |
'year' => 2016 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Butterfly Stomp (Beaks #0)', | |
'year' => 2016 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Forced to Talk, Like, With Your Mouth', | |
'year' => 2016 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'FreeBSD Mastery: Specialty Filesystems', | |
'year' => 2016 | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'git commit murder', | |
'year' => 2017 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'savaged by systemd', | |
'year' => 2017 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'Httpd and Relayd Mastery', | |
'year' => 2017 | |
}, | |
{ 'genre' => 2, | |
'length' => 2, | |
'title' => 'Ed Mastery', | |
'year' => 2018 | |
}, | |
{ 'genre' => 2, | |
'length' => 2, | |
'title' => 'Ed Mastery, Manly McManface Edition', | |
'year' => 2018 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'SSH Mastery, 2nd edition', | |
'year' => 2018 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'Absolute FreeBSD, 3rd edition', | |
'year' => 2018 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Bedazzled by Blockchain', | |
'year' => 2018 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Face Less', | |
'year' => 2018 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Boundary Shock: Tuesday After Next', | |
'year' => 2018 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Boundary Shock: Robots, Androids, Cyborgs, Oh My!', | |
'year' => 2018 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'Sudo Mastery, 2nd edition', | |
'year' => 2019 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'FreeBSD Mastery: Jails', | |
'year' => 2019 | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'Terrapin Sky Tango (Beaks #2)', | |
'year' => 2019 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Winner Breaks All', | |
'year' => 2019 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Boundary Shock: Apocalypse Descending', | |
'year' => 2019 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Fiction River: Superstitious', | |
'year' => 2019 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Snot-Nosed Aliens', | |
'year' => 2019 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'An Interpretation of Moles', | |
'year' => 2019 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'SNMP Mastery', | |
'year' => 2020 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Boundary Shock: Alien Dreams', | |
'year' => 2020 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'The Networknomicon', | |
'year' => 2020 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'Cash Flow for Creators', | |
'year' => 2020 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Boundary Shock: What Might Have Been', | |
'year' => 2020 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Face The Strange', | |
'year' => 2020 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Bloody Christmas', | |
'year' => 2020 | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'Drinking Heavy Water', | |
'year' => 2020 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Final Gift', | |
'year' => 2020 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Woolen Torment', | |
'year' => 2020 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Drums with Delusions of Godhood', | |
'year' => 2020 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Uncollected Anthology: Deities', | |
'year' => 2020 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Drag Air Through Fire', | |
'year' => 2021 | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'Aidan Redding Against the Universes', | |
'year' => 2021 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Fiction River: Chances', | |
'year' => 2021 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Fiction River: Dark and Deadly Passions', | |
'year' => 2021 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'TLS Mastery', | |
'year' => 2021 | |
}, | |
{ 'genre' => 2, | |
'length' => 2, | |
'title' => 'Only Footnotes', | |
'year' => 2021 | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'git sync murder', | |
'year' => 2021 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'The Holiday Spectacular #2', | |
'year' => 2021 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Boundary Shock: Wandering Monsters', | |
'year' => 2021 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Fantastic Christmas', | |
'year' => 2021 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Mysterious Christmas', | |
'year' => 2021 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => 'Witness November', | |
'year' => 2021 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'Domesticate Your Badgers', | |
'year' => 2022 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'DNSSEC Mastery, 2nd edition', | |
'year' => 2022 | |
}, | |
{ 'genre' => 2, | |
'length' => 2, | |
'title' => | |
'Letters from ed(1): The FreeBSD Journal Letters column, years 1-3', | |
'year' => 2022 | |
}, | |
{ 'genre' => 1, | |
'length' => 4, | |
'title' => 'Fiction River: Broken Dreams', | |
'year' => 2022 | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'Prohibition Orcs', | |
'year' => 2022 | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'Frozen Talons', | |
'year' => 2022 | |
}, | |
{ 'genre' => 2, | |
'length' => 1, | |
'title' => 'OpenBSD Mastery: Filesystems', | |
'year' => 2023 | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'Devotion and Corrosion', | |
'year' => 2023 | |
}, | |
{ 'genre' => 1, | |
'length' => 3, | |
'title' => | |
'The Rats\' Man\'s Lackey and the Half Gallon of Christmas Miracle', | |
'year' => 2023 | |
}, | |
{ 'genre' => 1, | |
'length' => 2, | |
'title' => 'The Rats\' Man\'s Lackey and the Delphi Taco', | |
'year' => 2023 | |
}, | |
{ 'genre' => 1, | |
'length' => 1, | |
'title' => 'Apocalypse Moi', | |
'year' => 2023 | |
} | |
); | |
while (<>) { | |
if (m!^PING!) { | |
say "PONG"; | |
next; | |
} | |
say STDERR "\n========" if $DEBUG; | |
my $command = $_; | |
chomp($command); | |
say STDERR "Command is $command" if $DEBUG; | |
unless ( $command eq "get" or $command eq "getnext" ) { | |
say STDERR "not a valid command, die die die" if $DEBUG; | |
say "NONE"; | |
next; | |
} | |
my $inoid = <>; | |
chomp($inoid); | |
say STDERR "raw OID is $inoid" if $DEBUG; | |
#sanity check, parsing | |
#is this our MIB? | |
unless ( $inoid =~ s/\Q$place// ) { | |
say STDERR "not our OID, die die die" if $DEBUG; | |
say "NONE"; | |
next; | |
} | |
if ($DEBUG) { | |
say STDERR "our OID!"; | |
say STDERR "converted to $inoid"; | |
} | |
#make parseable | |
unless ( $inoid =~ /^ | |
(?:\. (?<column_id>[0-9]+) )? | |
(?:\. (?<book_id> [0-9]+) )? | |
(?<detrius> (?:\.[0-9]+)* ) | |
$/x ) { | |
say STDERR "not a valid OID, die die die" if $DEBUG; | |
say "NONE"; | |
next; | |
} | |
my ( $column_id, $book_id, $detritus ) | |
= @+{qw< column_id book_id detritus >}; | |
if ($DEBUG) { | |
no warnings 'uninitialized'; | |
say STDERR "Column is $column_id"; | |
say STDERR "Row is $book_id"; | |
say STDERR "Detritus is $detritus"; | |
} | |
#if $detritus exists: not valid, reject on GET | |
if ( $command eq "get" and $detritus ) { | |
say "NONE"; | |
next; | |
} | |
if ( $command eq "getnext" ) { | |
#next OID will be: | |
#$place.$column_id.$book_id++ | |
$book_id++; | |
if ( $book_id > $#books ) { | |
$column_id++; | |
$book_id = 1; | |
} | |
elsif ( !$column_id or $column_id == 0 ) { | |
$column_id = 1; | |
} | |
say STDERR "Next is $column_id.$book_id" if $DEBUG; | |
} | |
# GET requests - check for valid instance | |
my $book = $books[$book_id // 0]; | |
my $column = $columns[$column_id // 0]; | |
unless ( $book and $column ) { | |
say STDERR "Row or column is not valid DIE DIE DIE" if $DEBUG; | |
say "NONE"; | |
next; | |
} | |
say STDERR "Both column and row are valid" if $DEBUG; | |
my $returnoid = $place . '.' . $column_id . '.' . $book_id; | |
say STDERR "returnoid is $returnoid" if $DEBUG; | |
#no matter what, we print the returned OID | |
say STDERR "Script output is:" if $DEBUG; | |
say STDERR "$returnoid\\n$column->{type}\\n" | |
. ( $column->{key} ? $book->{ $column->{key} } : $book_id ) | |
if $DEBUG; | |
say $returnoid; | |
say $column->{type}; | |
# The column without a key is the index column | |
say $column->{key} ? $book->{ $column->{key} } : $book_id; | |
} #end of program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment