#!/usr/bin/perl
# ungeek.cgi -*- Perl -*-
#
# Copyright (C) 1997, Bradley M. Kuhn
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Please request a copy of the GNU General Public License from the author, or
# download a copy from http://www.gnu.org/copyleft/gpl.html
# Alternatively, you can obtain a copy by writing to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# Program : Bradley M. Kuhn's CGI Package
# File : Ungeek - decode a geek code
#
# Written : Bradley M. Kuhn
# By http://www.ebb.org/bkuhn
#
#
# TODO:
# Make it work for more than one geek code at a time
# Add support so that I can just give a URL
#
# $Source: /home/Site/www.ebb.org/CVS/web-public/cgi-bin/ungeek.cgi,v $
# $Revision: 1.1.1.1 $
# $Date: 1998/09/06 02:59:15 $
#
# $Log: ungeek.cgi,v $
# Revision 1.1.1.1 1998/09/06 02:59:15 bkuhn
# Imported cgi-bin
#
# Revision 0.10 1998/08/13 13:57:36 bkuhn
# -- added license information
#
# Revision 0.9 1997/10/08 02:51:39 bkuhn
# -- added url for Ungeek location.
#
# Revision 0.8 1997/10/08 02:50:45 bkuhn
# -- changed some messages
#
# Revision 0.7 1997/10/08 02:47:22 bkuhn
# -- fixed location of other .pl script
#
# Revision 0.6 1997/10/08 02:35:06 bkuhn
# -- changed the error message a bit...
#
# Revision 0.5 1996/07/31 02:35:20 bkuhn
# -- fixed location of perl
#
# Revision 0.4 1996/05/20 04:46:34 bkuhn
# -- made headers make more sense
#
# Revision 0.3 1996/05/20 04:40:40 bkuhn
# -- made decrypt decode
#
# Revision 0.2 1996/05/20 04:24:35 bkuhn
# -- minor changes
#
# Revision 0.1 1996/05/20 02:59:19 bkuhn
# # initial version
#
use warnings;
use strict;
use POSIX qw(tmpnam);
# $UNGEEK_SCRIPT is the full path name of Pete Williams ungeek script
my $UNGEEK_SCRIPT = "/var/www/hidden-bin/ungeek.pl";
# $UNGEEK_OPTS is any options to be passed with $UNGEEK_SCRIPT
my $UNGEEK_OPTS = "";
# $GEEK_FORM is the URL of the form to display to the user
my $GEEK_FORM = "http://www.ebb.org/ungeek";
# $SCRIPT_OWNER_EMAIL is the email address of the script owner
my $SCRIPT_OWNER_EMAIL = "geekcode\@ebb.org";
# $TEMP_FILE is a temporary file that can be written to and is unique to
# the process
my $TEMP_FILE = POSIX::tmpnam();
###############################################################################
# CONFIGURABLE PARAMETERS ARE ABOVE THIS LINE
my $requestMethod = $ENV{'REQUEST_METHOD'};
my $queryString = $ENV{'QUERY_STRING'};
my $contentLength = $ENV{'CONTENT_LENGTH'};
if ($requestMethod eq "GET") {
if ( (! defined($queryString)) && ($queryString eq "") ) {
print "Location: $GEEK_FORM", "\n\n";
} else {
my $formData =
ParseFormData($requestMethod, $queryString, $contentLength);
&ExecuteDecode($formData->{geekCode});
}
} elsif ($requestMethod eq "POST") {
my $formData = ParseFormData($requestMethod,
$queryString, $contentLength);
&ExecuteDecode($formData->{geekCode});
} else {
&HtmlErrorMessage(500, "Server Error", "Server uses unsupported method.");
}
exit 0;
###############################################################################
sub ExecuteDecode ($) {
my($geekCodeString) = @_;
my($haveSome, $seenOtherStuff);
%ENV = ();
open(TEMP, ">$TEMP_FILE") || &HtmlErrorMessage(500, "Server Error",
"Fatal error");
print "Content-type: text/html\n\n";
print TEMP "$geekCodeString\n";
close(TEMP);
print <Requested Decoded Geek Code
Decoded Geek Code
END_OF_PAGE_TOP
open(GEEK_CODE, "$UNGEEK_SCRIPT $UNGEEK_OPTS < $TEMP_FILE |") ||
&HtmlErrorMessage(500, "Server Error", "Fatal ungeek script error");
$haveSome = $seenOtherStuff = 0;
while (my $line = ) {
chomp $line;
$haveSome = 1;
# ignore ====== lines, until the last one
next if ( (! $seenOtherStuff) && ($line =~ /^=+/) );
$seenOtherStuff = 1;
if ($line =~ /^\s*\-+ (.+) \-+\s*$/) {
print "
$1
\n";
} elsif ($line =~ /^=+/) {
last;
} else {
print "$line\n";
}
}
if (! $haveSome) {
print " Unable to find a geek code in the text you gave me.",
" The mostly likely reason for this is that one of your geek code",
" characters was not valid. Make sure your geek code complies\n",
" exactly with Geek ",
"Code ",
"",
"Version 3.12.\n ",
"In addition, you must have at least 2 sequential valid geek codes ",
"within in your code. Thus, for example, 'GCS' alone is not valid.\n";
} else {
# print out the actual geek code block at the end
print "\n
\n";
while () {
print $_;
}
print "
\n";
}
close(GEEK_CODE);
unlink($TEMP_FILE);
print <
This Geek Code was automatically
decoded by a script written by Bradley M.
Kuhn.
If you enjoyed this decocder, please make a donation
to help Bradley pay for the cost of bandwidth of the Geek Code Decoder:
Please, report any decoding problems to the author of the decoding script:
Bradley M. Kuhn $SCRIPT_OWNER_EMAIL
but he rarely has time to work on it anymore or even fix bugs.