💾 Archived View for kvothe.one › dev › scripts › cgi_input.pl captured on 2020-09-24 at 00:49:14.

View Raw

More Information

-=-=-=-=-=-=-

#!/usr/bin/env perl
use strict;
use warnings;
use URI::Escape;

#--[OpenBSD specific code.]-----------------------------------------
use OpenBSD::Pledge;
use OpenBSD::Unveil;

# unveil(2) at least one directory to enable file whitelisting.
# In this case, we are unveiling a dir with no permissions.
# args: path,          permissions.
unveil( '/var/gemini', '' );

# finalize the unveil(2) list.
unveil();

# pledge(2) to only use stdio system calls.
pledge('stdio');
#--[OpenBSD specific code.]-----------------------------------------

my $input = $ENV{QUERY_STRING};

if ( defined $input && length $input ) {
    # We have a CGI query!

    # First, unescape it.
    $input = uri_unescape($input);

    # Send a plain geminitext response header (20).
    print "20 text/gemini; lang=en\r\n";

    # Handle the user input.
    print "# repeatbot 3000.\r\n";
    print "What you said: '$input'\r\n";
    print "What you said, but uppercase: '" . uc($input) . "'\r\n";
} else {
    # We don't have a CGI query.
    # Let's ask for input with an input gemini response header (10).
    print "10 What would you like to say to repeatbot 3000?\r\n";
}