#!/usr/bin/perl
###############################################################
# Gambrinus Mug Add Recipe Version 1.0 #
# Copyright 1996 Karl Lutzen lutzen@alpha.rollanet.org #
# Created 12/7/96 #
###############################################################
# COPYRIGHT NOTICE #
# Copyright 1996 Karl F. Lutzen All Rights Reserved. #
# #
###############################################################
# Define Variables
$basedir = "/WWW/gambmug"; #NO TRAILING "/" on directories!!!
$baseurl = "http://alpha.rollanet.org/gambmug";
$cgi_url = "http://alpha.rollanet.org/cgi-bin/gambmug";
$recdir = "recs";
$tocdir = "toc";
$serialfile = "serial.txt";
$datafile = "data.txt";
$countfile="count.html";
$gmindex="gm_index_include.html";
$ext = "html";
$date_command = "/bin/date";
$title = "Gambrinus' Mug";
$subtitle = "The Brewery's Recipe Exchange";
#Return line in recipes.
$RecReturn="Back to previous Table of Contents";
$IndexFlag = "REC_ADDED.flg";
# Done
###########################################################################
###########################################################################
#
# Sequence of entry to this script.
#
# A call contains 2 arguments, the category for the recipe to
# be added, and the mode, either GET a submission form or POST a recipe
#
##################################################
##################################################
# Main.
#
# read our initialization file to get category info as that is common to all
&Init;
# parse out command line and all environment data
&UnWebify;
# Decide if we send out form or process data ($Mode=GET or POST)
if ($Mode eq "GET") {
&SendForm;
} elsif ($Mode eq "POST") {
&PostRecipe;
} # any other entry means Karl screwed up in writing and we simply exit
#Main Done
##################################################
# Init subroutine. Read in our data file so
# we know what categories are valid.
#
# We support hierarchal data. see data file for info.
# Two parts. We recurse calling load_entry...
sub Init {
open(D,"<$basedir/$datafile") || die $!;
$root='';
&load_entry('',$root,1);
}
sub load_entry{
local($parent,$root,$idx) = @_;
local($name,$pos);
while () {
last if /}/;
next if /^#/;
next unless /(\w.*\w)/;
$name =$1;
$pos=$root.$idx++;
$Category{$pos}=$name;
if (/{/) {
&load_entry($name,$pos."_",1);
}
}
}
##################################################
# UnWebify subroutine. Read all our command line
# and environment into an associative array (if POST).
sub UnWebify {
# Get the input
($Cat,$Mode)=split(/&/,$ENV{'QUERY_STRING'});
if ($Mode eq "POST") {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s///g;
$FORM{$name} = $value;
}
}
}
##################################################
# SendForm subroutine. Send out a recipe submission
# form based on our command line options.
sub SendForm {
print "Content-type: text/html\n\n";
print "$title: $Category{$Cat}\n";
print "\n";
print "