BEGIN {use CGI::Carp qw/fatalsToBrowser/} $cwd = $0; $cwd =~ s/\\/\//g; $cwd =~ s/\/poll\.cgi$//ig; if(-e "$cwd/poll_config.cgi") {do("$cwd/poll_config.cgi")} elsif($INPUT{'action'} eq "firstSetup") {secondSetup()} else {firstSetup()} sub firstSetup { $urldir = $this = "http://"."$ENV{'SERVER_NAME'}"."$ENV{'SCRIPT_NAME'}"; $urldir =~ s/\/poll.cgi$//g; $outmail = "$ENV{'SERVER_NAME'}"; $outmail =~ s/^www.//; $outmail = "poll\@$outmail"; if(-e "$cwd/template.html") {$template = "$cwd/template.html"} elsif(-e "$cwd/template.shtml") {$template = "$cwd/template.shtml"} else {$template = ''} print <<"EOC"; Content-type: text/html Poll Administration >> First Time Setup

First Time Setup

It has been determined that this is the first time you have run this script. You must set the basic options for the Poll before you can use it. Please fill in the following settings. The script has tried to fill them in for you, but please verify that they are correct.


Poll password:
Needed to login to administration panel and change settings
Re-type password to confirm:
System path to current directory:
URL to current directory:
Title of your poll:
This will appear when visitors to your site take the poll.
Number of answer choices per poll:
System path to the template file:
If not set, a default will be created
Opening & closing title tags:
Customizing this will change the way the page titles and section titles render
Opening tag:


Closing tag:
Opening & closing main font tags:
Customizing this will change the way the main text in the script renders
Opening tag:


Closing tag:
Opening & closing footnote tags:
Customizing this will change the way the footnotes render
Opening tag:


Closing tag:
Custom table tags:
Here, you can change the way tables render. If you'd like to leave an attribute unset, leave it blank
Border:


Border color:


Background color:


Cellpadding:


Cellspacing:


Cell background color:


Small table width:


Small table alignment:

EOC exit; } sub secondSetup { unless($INPUT{'pw'} eq $INPUT{'pw_c'}) {die("Password ($INPUT{'pw'}) & confirmation password ($INPUT{'pw_c'}) did not match.")} unless($INPUT{'n_a'} =~ /^(\d+)$/) {die("Number of answers per poll ($INPUT{'n_a'}) must be a number.")} my $z = chr(0); # I did this instead of \0 just to be safe if($INPUT{'pw'} eq '' || $INPUT{'pw'} =~ /$z|\n|\r|\t|\f|\\/) {die("Password was an empty string or contained invalid characters. (It cannot include null characters, newlines, backslashes, form feeds, or tabs)")} $INPUT{'path'} =~ s/\\/\//g; $INPUT{'template'} =~ s/\\/\//g; if($INPUT{'path'} =~ /\/$/) {$INPUT{'path'} =~ s/\/$//} if($INPUT{'url'} =~ /\/$/) {$INPUT{'url'} =~ s/\/$//} @fields = ('pw','path','url','s_title','template','border','bordercolor','bgcolor','cpadding','cspacing','tdbg','width','align'); foreach $i (@fields) {$INPUT{$i} =~ s/'/\\'/g} undef @fields; %fields = ( 'topen' => 'Opening title text formatting', 'tclose' => 'Closing title text formatting', 'fopen' => 'Opening text formatting', 'fclose' => 'Closing text formatting', 'sopen' => 'Opening footnote formatting', 'sclose' => 'Closing footnote formatting' ); foreach $i (keys(%fields)) { if($INPUT{$i} =~ /'/) { die("'$fields{$i}' field cannot contain single quotations"); } } undef %fields; unless(defined($INPUT{'border'}) || $INPUT{'border'} ne '') { $INPUT{'border'} = '_DEFAULT_'; } unless(defined($INPUT{'bordercolor'}) || $INPUT{'bordercolor'} ne '') { $INPUT{'bordercolor'} = '_DEFAULT_'; } unless(defined($INPUT{'bgcolor'}) || $INPUT{'bgcolor'} ne '') { $INPUT{'bgcolor'} = '_DEFAULT_'; } unless(defined($INPUT{'cpadding'}) || $INPUT{'cpadding'} ne '') { $INPUT{'cpadding'} = '_DEFAULT_'; } unless(defined($INPUT{'cspacing'}) || $INPUT{'cspacing'} ne '') { $INPUT{'cspacing'} = '_DEFAULT_'; } unless(defined($INPUT{'tdbg'}) || $INPUT{'tdbg'} ne '') { $INPUT{'tdbg'} = '_DEFAULT_'; } unless(defined($INPUT{'width'}) || $INPUT{'width'} ne '') { $INPUT{'width'} = '_DEFAULT_'; } unless(defined($INPUT{'align'}) || $INPUT{'align'} ne '') { $INPUT{'align'} = '_DEFAULT_'; } if(! defined($INPUT{'template'}) || $INPUT{'template'} eq '') { $INPUT{'template'} = "$INPUT{'path'}/template.shtml"; } if(! (-e "$INPUT{'template'}")) { open(NEWTEMPLATE,">$INPUT{'template'}"); print NEWTEMPLATE <<"EOC"; <_Title_>

<_Name_>


<_Content_>


<_Menu_> EOC close(NEWTEMPLATE); } open(CONFIGWRITE,">$cwd/poll_config.cgi"); print CONFIGWRITE <<"EOC"; ################################################################################## ## Poll Configuration File # Note: Generated file...Manual editing not recommended! # Poll password \$pw = '$INPUT{'pw'}'; # Full system path to current directory \$path = '$INPUT{'pw'}'; # Absolute URL of current directory \$url = '$INPUT{'url'}'; # Title of your site's poll \$s_title = '$INPUT{'s_title'}'; # Number of answer choices per poll \$n_a = $INPUT{'n_a'}; # Full system path to the HTML template file \$template = '$INPUT{'template'}'; # Custom title opening tag \$topen = '$INPUT{'topen'}'; # Custom title closing tag \$tclose = '$INPUT{'tclose'}'; # Custom text opening tag \$fopen = '$INPUT{'fopen'}'; # Custom text closing tag \$fclose = '$INPUT{'fclose'}'; # Custom footnote opening tag \$sopen = '$INPUT{'sopen'}'; # Custom footnote closing tag \$sclose = '$INPUT{'sclose'}'; # Table border width \$border = '$INPUT{'border'}'; # Table border color \$bordercolor = '$INPUT{'bordercolor'}'; # Table background color \$bgcolor = '$INPUT{'bgcolor'}'; # Table cellpadding \$cpadding = '$INPUT{'cpadding'}'; # Table cellspacing \$cspacing = '$INPUT{'cspacing'}'; # Table cell background \$tdbg = '$INPUT{'tdbg'}'; if(\$tdbg ne "_DEFAULT_") {\$td = " bgcolor=\$tdbg"} else {\$td = ''} # Miniature poll width \$width = '$INPUT{'width'}'; # Miniature poll alignment \$align = '$INPUT{'align'}'; # All this is just for formatting purposes \$table = ''; if(\$border ne "_DEFAULT_") {\$table .= " border=\$border"} if(\$bordercolor ne "_DEFAULT_") {\$table .= " bordercolor=\$bordercolor"} if(\$bgcolor ne "_DEFAULT_") {\$table .= " bgcolor=\$bgcolor"} if(\$cpadding ne "_DEFAULT_") {\$table .= " cellpadding=\$cpadding"} if(\$cspacing ne "_DEFAULT_") {\$table .= " cellspacing=\$cspacing"} \$table .= ' width=100%'; \$wtable = ''; if(\$border ne "_DEFAULT_") {\$wtable .= " border=\$border"} if(\$bordercolor ne "_DEFAULT_") {\$wtable .= " bordercolor=\$bordercolor"} if(\$bgcolor ne "_DEFAULT_") {\$wtable .= " bgcolor=\$bgcolor"} if(\$cpadding ne "_DEFAULT_") {\$wtable .= " cellpadding=\$cpadding"} if(\$cspacing ne "_DEFAULT_") {\$wtable .= " cellspacing=\$cspacing"} if(\$width ne "_DEFAULT_") {\$wtable .= "width=\$width"} 1; EOC close(CONFIGWRITE); unless(-e "$INPUT{'path'}/archives" && -d "$INPUT{'path'}/archives") { `mkdir $INPUT{'path'}/archives`; if(! (-e "$INPUT{'path'}/archives")) {die("Archives directory could not be made in $INPUT{'path'}")} } my $key = crypt("Copyright © 2001, Evan Kaufman","EK"); $content = <<"EOC";
$INPUT{'sopen'}Sort by Question$INPUT{'sclose'}

EOC open(ARCHLIST,">$INPUT{'path'}/archives/index.shtml"); print ARCHLIST displayAs("$s_title Archived Polls >> Sorted by Date",$content,0,1); close(ARCHLIST); $content = <<"EOC";
$INPUT{'sopen'}Sort by Date$INPUT{'sclose'} EOC open(ARCHLISTB,">$INPUT{'path'}/archives/index2.shtml"); print ARCHLIST displayAs("$s_title Archived Polls >> Sorted by Question",$content,0,1); close(ARCHLISTB); print "Location: $url/poll.cgi?action=login\n\n"; } sub login { displayAs("Poll Administration >> Login","$_[0]\n
\n\nPassword: \n
",0,0); } sub displayAs { my($title,$content,$admin,$tostring) = @_; unless($title ne '' && defined($title)) {$title = $s_title} if($admin != 1) {$admin = 0} my($html,$i,$menu); if($admin) { $menu = <<"EOC";

$fopenView Poll$fclose $fopenAdministration Panel$fclose $fopenView Results$fclose $fopenView Code$fclose EOC } open(TEMPLATE, $template); @template =