#! /usr/local/bin/perl ################################################################################ $VERSION = "survey.pl v1.1"; # Apr 06-96 Dale Bewley # v.9 01-23-96, v1.0 02-23-96, v1.01 03-18-96, v1.02 03-26-96 #------------------------------------------------------------------------------# # This script and others found at http://www.bewley.net/perl/ # # Survey. Gathers comments on any number of pages using one standard # survey or a unique survey for each page. # Designed to be inobtrusive, it knows the page a user referenced it # from and will return them to that page once they submit the form. # # Copyright (C) 1996 Dale Bewley # # 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. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # Changes in this ver: # see http://www.bewley.net/perl/survey.html for up to date docs. # # Todo: # o Read survey from external URL to make more portable? # o Add file locking. # o Need to work on output format. Particularly if using external surveys # Currently output is hard coded. This is next on the list. # # Notes: # Since I am avoiding open ended input (allowing check boxes only) # there are no checks for malicious input yet. # # If you would like to modify this to work with your site start by # running survey.pl and saving the form that it outputs for you. # # survey.pl > survey.html # # The names in the form are hard coded in survey.pl as is the form of # course. Modify the form to your needs and make sure you don't break # any variables in survey.pl. You will also have to work on the output # format if you change the survey. It is modeled closely after the # hard coded survey below. # # See the comments in printSurvey for notes on creating your # survey form. # ############################################################################## #- User Configurable Variables ----------------------------------------------# $SURVEY_FORM = "/sparcus/users/dbewley/www/survey.html";#default survey $OUTFILE = "/home/stu/d/dbewley/www/sparcus/survey-out.html";#default output #- Survey Mappings ----------------------------------------------------------# # # I'm trying to decide on a format that will be easy to configure for even a # perl novice. Entries are of the format # "partial URL|/path/to/survey/form.html", # The quotes and the comma is necessary. No spaces around the | character. # An entry should be continuous and not span lines! # The URL is passed into a regex so make it SPECIFIC if you have similar URLs # @SURVEY_MAP=( "dbewley/perl|/sparcus/users/dbewley/www/survey.html", "dbewley/test|/sparcus/users/dbewley/www/survey.html", "engr/entrance|/sparcus/users/dbewley/www/entrance-survey.html", "dbewley/work/test|/sparcus/users/dbewley/www/test-survey.html", ); #----------------------------------------------------------------------------# #- Main Program -------------------------------------------------------------# ($sec, $min, $hour, $mday, $mon, $year) = localtime($^T); $mon++; &determineSurveyForm; # what survey will user take? &getInput; # what did user have to say? #(&oldPrintSurvey && exit) if (!%FORM); # this will use hard coded survey (&printSurvey && exit) if (!%FORM); # user didn't say anything yet &oldLogSurvey; # IF we made it this far we have a completed survey. write log #&logSurvey; # IF we made it this far we have a completed survey. write log #- Determine Which Survey to Print ------------------------------------------# sub determineSurveyForm { # use @SURVEY_MAP to pick associated survey for accessed URL. foreach (@SURVEY_MAP) { ($url, $survey_form) = split(/\|/,$_); $SURVEYS{$url}=$survey_form; } foreach $url (keys %SURVEYS) { # assuming referer is passed! ($ENV{'HTTP_REFERER'} =~ /$url/)&&($SURVEY_FORM=$SURVEYS{$url}); } # return $SURVEY_FORM; # this default is set in user config variables } #- Get Input ----------------------------------------------------------------# sub getInput { # assumes method=post read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } } #- Print survey results to file ---------------------------------------------# sub logSurvey { # yet to write this. this will eliminate hard coding in oldLogSurvey # and finally enable you to use this program with an arbitrary survey, # theoretically. :) } #- Print survey results to file ---------------------------------------------# sub oldLogSurvey { # may output to different format at some time # print survey results to a file. open (RESULTS, ">>$OUTFILE") || die "Content-type: text/html\n\nCan't open $OUTFILE.\n"; # Output now goes to $OUTFILE local($oldfh) = select(RESULTS); if ($ENV{'HTTP_REFERER'}) { print "

Commenting from:", " $FORM{'httpReferer'}
\n"; } else { print "User agent, $ENV{'HTTP_USER_AGENT'},", " did not report referring page.
\n"; } print "User host IP: $ENV{'REMOTE_ADDR'}
\n"; print "Browser: ", "$ENV{'HTTP_USER_AGENT'}
\n" if $ENV{'HTTP_REFERER'}; printf ("Time: %02d/%02d/%02d %02d:%02d:%02d
\n", $mday, $mon, $year, $hour, $min, $sec); if ($FORM{'pageWasHelpful'} =~ /yes/i) { print "

Page was helpful.
\n"; } else { print "

Page was not helpful.
\n"; } if ($FORM{'foundIt'} =~ /yes/i) { print "I did find what I was looking for.
\n"; } else { print "I did not find what I was looking for.
\n"; } print "\n"; print "\n"; print "\n\n
\n
\n"; print "
I liked:\n"; print "
The scripts.\n" if ($FORM{'likedScripts'}); print "
The documentation.\n" if ($FORM{'likedDocumentation'}); print "
The graphics.\n" if ($FORM{'likedGraphics'}); print "
The navigation.\n" if ($FORM{'likedNavigation'}); print "
\n
You can improve:\n"; print "
The scripts.\n" if ($FORM{'improveScripts'}); print "
The documentation.\n" if ($FORM{'improveDocumentation'}); print "
The graphics.\n" if ($FORM{'improveGraphics'}); print "
The navigation.\n" if ($FORM{'improveNavigation'}); print "\n"; print "
\n"; print "


\n"; close RESULTS; select($oldfh); # Output now goes to browser # send user back to calling page. print "Content-type: text/html\n"; print "Location: $FORM{'httpReferer'}\n"; print "\n"; print "

Return to: $FORM{'httpReferer'}\n\n"; } #- Print External Survey Form -----------------------------------------------# sub printSurvey { # got $SURVEY_FORM from determineSurveyForm print "Content-type: text/html\n\n"; open (SURVEY, "<$SURVEY_FORM") || die "Can't open $SURVEY_FORM for input. Stopped,"; while () { # The string HTTP_REFERER in your survey.html will be replaced # by the page survey.pl was accessed from. # # You definitely need this exact line in your survey.html: # # You may want this line in your survey.html: # Commenting from: HTTP_REFERER
$_ =~ s/HTTP_REFERER/$ENV{'HTTP_REFERER'}/o; print; } return "1"; } #- Print Survey Form --------------------------------------------------------# sub oldPrintSurvey { # I'm leaving this hard coded survey as documentation on how to set # yours up. You will want to create your own survey and describe it # in @SURVEY_MAP print "Content-type: text/html\n\n"; print < Dale Bewley's Five Second Survey

Dale Bewley's Five Second Survey


Commenting from: $ENV{'HTTP_REFERER'}

Did you find this page helpful?
yes no

Did you find what you were looking for?
yes no

What did you like?
Scripts
Documentation
Graphics
Ease of Navigation

What can I improve?
Scripts
Documentation
Graphics
Ease of Navigation


If you have more specific comments please email me.
Original: 22 January 1996 Dale Bewley
Updated: 26 March 1996 Dale Bewley
Comments: dale\@bewley.net

URL: http://www.bewley.net/cgi-bin/survey.pl
EOF_FORM }