#!/usr/bin/perl
####################################################################
# Script: | Poll It #
# Version: | 2.05 #
# By: | Jason Berry (i2 Services, Inc. / CGI World) #
# Contact: | jason@cgi-world.com #
# WWWeb: | http://www.cgi-world.com #
# Copyright: | Jason Berry (CGI World of i2 Services, Inc.) #
# Released | August 09, 1998 #
####################################################################
# By using this software, you have agreed to the license #
# agreement packaged with this program. #
# #
####################################################################
# Variables:
#
#
$admin_password = "mayajed1";
# Password you would like to use for entering the administration
# area located at: ScriptName.cgi?load=login
$image_url = "http://www.e-souks.com/polls/pollit_files/image.gif";
# URL to the 'image.gif' that was packaged with this script. Upload
# that GIF Image to your website & enter the URL to it above.
$vote_text = "Enregistrez mon vote!";
# Text that is shown on the submit button when casting your vote.
# Note:
##################################################################
# If you're looking to use an image in one of the variables
# below, input the IMAGE tag inside of the quotes as:
# <-- Placing backslashes (\)
# before the extra quotes inside a quote.
###########################################################
$last_poll_text = "
Revenez bientot...";
# Message listed when a poll is not available.
#
#
#
# (We do not support this script if you edit below this line )
################################################################
#
#
%in = &ReadForm;
if ($0=~m#^(.*)(\\|/)#) { $cgidir = $1; }
else { $cgidir = `pwd`; chomp $cgidir; }
$script_url = $ENV{'SCRIPT_NAME'};
$data_dir = "$cgidir/pollit_files";
$poll_options = "$data_dir/poll_options.txt";
$last_poll_options = "$data_dir/last_poll_options.txt";
$poll_info = "$data_dir/poll_info.txt";
$last_poll_info = "$data_dir/last_poll_info.txt";
$ips_file = "$data_dir/ips.txt";
$last_file = "$data_dir/last_poll.txt";
$lockdir = "$data_dir/filelock";
# Administration Area:
###############################################################
if($admin_password eq "$entered_password") {
print "Content-Type: text/html\n\n";
# Add New Voting Option:
#########################################################
if($action eq "add_option" && $add_option) {
open(COPTIONS,"<$poll_options");
@coptions = To remove an added option mark its checkbox
next to it, then press " };
if(!$show_new_options) { $show_new_options = "No NEW Options Currently..." };
print &Template("$data_dir/_admin_create_poll.html");
exit;
}
# Show Main Menu:
#########################################################
else {
&Template("$data_dir/_admin_menu.html");
open(POLLINFO,"<$poll_info");
while(";
$show_results .= &Cell('poll_results');
}
}
if(!$show_results) { $show_results = "There are currently no results for your current poll" };
if(!$poll_title) { undef($show_results) };
print &Template("$data_dir/_admin_menu.html");
}
exit;
}
# Administration Login:
###############################################################
if($load =~ /login|admin/i || $entered_password && $entered_password ne "$admin_password") {
print "Content-Type: text/html\n\n";
&Template("$data_dir/_admin_login.html");
print &Template("$data_dir/_admin_login.html");
exit;
}
# Show Last Poll Results:
###############################################################
if($load =~ /^lastpoll/i) {
print "Content-Type: text/html\n\n";
&Template("$data_dir/_last_poll.html");
open(POLLINFO,"<$last_poll_info");
while(
";
$show_results .= &Cell('poll_results');
}
}
$show_results .= &Cell('total_votes');
print &Template("$data_dir/_last_poll.html");
exit;
}
# Show Poll:
###############################################################
if(!$ENV{'QUERY_STRING'}) {
open(IPS,"<$ips_file");
@ips =
";
$show_results .= &Cell('poll_results');
}
}
$show_results .= &Cell('total_votes');
if($show_results_after > $total) {
undef($show_results);
$show_results = "$results_not_available";
}
}
# Show Voting Options:
#####################################
if(!$voted) {
foreach$p_option(@poll_options) {
($votes_received,$option_id,$poll_option) = split(/=/,$p_option);
if($option_id ne "total") {
$display_options .= &Cell("show_options");
}
}
if(!$display_options) {
$display_options = "$poll_not_available" ;
$poll_title = "No Poll Currently Available...";
}
}
if($display_options) { $submit = "
" };
open(LASTPOLL,"<$last_poll_options");
@last_poll =
";
}
print &Template("$data_dir/_poll.html",'html');
}
# Send Poll to Last Poll: #
###############################################################
# Usage : &last_poll #
# #
###############################################################
sub last_poll {
open(CPOLLOPTIONS,"<$poll_options");
@cpoptions =
\nTemplate : No file was specified
\n"; }
elsif (!-e "$_[0]") { return "
\nTemplate : File '$_[0]' does not exist
\n"; }
else {
open(FILE, "<$_[0]") || return "
\nTemplate : Could open $_[0]
\n";
while (
\nCell : No cell was specified
\n"; }
elsif (!$CELL) { return "
\nCell : Cell '$_[0]' is not defined
\n"; }
else { $CELL =~ s/\$(\w+)\$/${$1}/g; } # translate $scalars$
return $CELL;
}
# Parse Form: #
###############################################################
# Usage : %in = &ReadForm; #
# #
###############################################################
sub ReadForm {
my($max) = $_[1]; # Max Input Size
my($name,$value,$pair,@pairs,$buffer,%hash); # localize variables
# Check input size if max input size is defined
if ($max && ($ENV{'CONTENT_LENGTH'}||length $ENV{'QUERY_STRING'}) > $max) {
die("ReadForm : Input exceeds max input limit of $max bytes\n");
}
# Read GET or POST form into $buffer
if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }
elsif ($ENV{'REQUEST_METHOD'} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; }
@pairs = split(/&/, $buffer); # Split into name/value pairs
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair); # split into $name and $value
$value =~ tr/+/ /; # replace "+" with " "
$value =~ s/%([A-F0-9]{2})/pack("C", hex($1))/egi; # replace %hex with char
if($name eq "add_option" && $value) {
push(@added_options,$value);
}
if($name eq "remove_new") {
push(@removes,$value);
}
if($name ne "admin_password") {
$$name = $value;
}
}
return %hash;
}
# File Locking: #
###############################################################
# Usage : &FileLock("$lockdir"); #
# : &FileUnlock("$lockdir"); #
# #
###############################################################
sub FileLock {
my($i); # sleep counter
while (!mkdir($_[0],0777)) { # if there already is a lock
sleep 1; # sleep for 1 sec and try again
if (++$i>60) { die("File_Lock : Can't create filelock : $!\n"); }
}
}
sub FileUnlock {
rmdir($_[0]); # remove file lock dir
}
####################################################################