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
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";
<_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'}
| $fopenView Poll$fclose | $fopenAdministration Panel$fclose | $fopenView Results$fclose | $fopenView Code$fclose |