#!/usr/bin/perl ##################################### # # # RobPoll v1.1 # # Copyright 1998 by Rob Eisler # # rob@robplanet.com # # http://www.robplanet.com # # # # Last modified on Sept 12, 1998 # # # ##################################### # # Copyright Notice: # Copyright 1998 Robert S. Eisler. All Rights Reserved. # # This code may be used and modified by anyone so long as this header and # copyright information remains intact. By using this code you agree to # indemnify Robert S. Eisler from any liability that might arise from its # use. You must obtain written consent before selling or redistributing # this code. # ##################################### # # The cookie functions used in this script are based on the HTTP # Cookie Library 2.1 by Matt Wright. The copyright information for his # library are at the end of the readme.txt. Check out Matt's Script # Archive: http://www.worldwidemart.com/scripts # ##################################### # declare the variables $polldir = '/data/6/a/6a5d51c2-e2ed-4fec-8484-6cec283eee3e/kiruna-nytt.nu/public_html/poll'; $graph_image = 'http://www.kiruna-nytt.nu/poll/white.jpg'; $cgi = 'http://www.kiruna-nytt.nu/cgi-bin/robpoll.cgi'; $check_cookies = 1; # how to block multi-voting $check_ip = 0; # 1 = use, 0 = don't # the following variable is only for the SSI poll $return_page = 'http://www.kiruna-nytt.nu/index.html'; # the rest are only for the full-page poll $tablecolor = 'lightgrey'; # these colors can be entered as a word like $textcolor = 'black'; # 'black' or an RGB value like '#FFFFFF' $textfont = 'arial'; $textsize = 3; $border = 1; $cellpadding = 2; $cellspacing = 1; $graph_height = 10; $graph_width = 3; # factor for the graph width - the width of # the graph in pixels = percent * graph_width $include_percent = 1; # 1 = include this option, 0 = don't $include_graph = 1; $include_total = 1; ######################################################################### # Don't change anything below here unless you know what you're doing :) # ######################################################################### $use_cgi = 1; read(STDIN, $input, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $input); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s///g; $FORM{$name} = $value; } $ip = $ENV{REMOTE_ADDR}; $ssi = 'false'; $ssi_total = $include_percent + $include_graph + 2; $polldata = "$polldir/data.txt"; $return_page .= "?results"; $Cookie_Exp_Date = 'Sat, 31-Dec-2099 00:00:00 GMT'; $Secure_Cookie = '0'; $Cookie_Path = '/'; @Cookie_Encode_Chars = ('\%', '\+', '\;', '\,', '\=', '\&', '\:\:', '\s'); %Cookie_Encode_Chars = ('\%', '%25', '\+', '%2B', '\;', '%3B', '\,', '%2C', '\=', '%3D', '\&', '%26', '\:\:', '%3A%3A', '\s', '+'); @Cookie_Decode_Chars = ('\+', '\%3A\%3A', '\%26', '\%3D', '\%2C', '\%3B', '\%2B', '\%25'); %Cookie_Decode_Chars = ('\+', ' ', '\%3A\%3A', '::', '\%26', '&', '\%3D', '=', '\%2C', ',', '\%3B', ';', '\%2B', '+', '\%25', '%'); open(FILE, "$polldata") || &file_open_error($polldata); @lines = ; close(FILE); $num = @lines; ($num_questions,$nochop) = split(/``/,$lines[0]); (@num_answers) = split(/``/,$lines[1]); (@q_id) = split(/``/,$lines[2]); (@questions) = split(/``/,$lines[3]); (@answers) = split(/``/,$lines[4]); ($encrypted_password, $nochop) = split(/``/, $lines[5]); $total_answers[0] = 0; for ($a = 1; $a < $num_questions; $a++) { $total_answers[$a] = $total_answers[$a-1] + $num_answers[$a-1]; } $what = $FORM{'what'}; $what = $ENV{'QUERY_STRING'} unless ($what); $ssi = 'true' if ($what eq 'votessi'); &vote if ($what eq 'vote' || $what eq 'votessi'); &results($FORM{'q'}) if ($what eq 'results'); print "Content-type: text/html\n\n"; &start if ($what eq 'start'); &select_q if ($what eq 'select_q'); &admin if ($what eq 'admin'); &add if ($what eq 'add'); &add2 if ($what eq 'add2'); &remove if ($what eq 'remove'); &remove2 if ($what eq 'remove2'); &passwd if ($what eq 'pass'); &setpass if ($what eq 'setpass'); &fatal_error("Error in HTML Form 'what' Variable"); exit; sub start { for ($a = 0; $a < $num_questions; $a++) { &check($a); if ($foundip eq 'Yes') { $voted[$a] = 'Yes'; } else { $voted[$a] = 'No'; } } print "\n"; print "Please Select a Topic\n"; print "\n"; print "\n"; print "
\n"; print "

Månadens fråga - juni, 2016

\n"; print "\n"; for ($a = 1; $a <= $num_questions; $a++) { print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; } else { print "Du har redan röstat!.\n"; print "\n"; } print "\n"; } print "
Fråga $a$questions[$a-1]
\n"; $b = $a - 1; if ($voted[$a-1] eq 'No') { print "Du har inte röstat ännu!.

\n"; print "\n"; print "\n"; print "\n"; print "

\n"; print "\n"; print "\n"; print "

\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "
Till Admin-sidan

\n"; print "Rob's Perl


\n"; print "
\n"; exit; } sub select_q { $q = $FORM{'q'}; $voted = $FORM{'voted'}; &check($q-1); &results($q-1) if ($voted eq 'Yes' || $foundip eq 'Yes'); print "\n"; print "$questions[$q-1]\n"; print "\n"; print "\n"; print "
\n"; print "
\n"; print "

$questions[$q-1]

\n"; print "\n"; for ($b = $total_answers[$q-1]; $b < $total_answers[$q-1]+$num_answers[$q-1]; $b++) { $c = $b-$total_answers[$q-1] + 1; print "\n"; print "\n"; print "\n"; } print "
$answers[$b]
\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "
\n"; exit; } sub vote { $q = $FORM{'q'}; $q--; if ($FORM{'response'}) { $v = $FORM{'response'}; $v--; &check($q); &results($q) if ($foundip eq 'Yes' && $ssi eq 'false'); &ssi_results($q) if ($foundip eq 'Yes' && $ssi eq 'true'); if ($check_ip) { open(FILE, ">>$polldir/ip$q_id[$q]\.txt") || &file_open_error("ip$q_id[$q]\.txt"); print FILE "\n$ip``x\n"; close(FILE); } if ($check_cookies) { $set_me = ''; for ($f = 0; $f < @answered - 1; $f++) { $set_me .= ",$answered[$f]"; } $set_me .= ",$q_id[$q]"; $set_me .= ",xx"; &SetCookies('questions',$set_me); } open(FILE, "$polldir/q$q_id[$q]\.txt") || &file_open_error("q$q_id[$q]\.txt"); @lines = ; close(FILE); @numbers = split(/``/, $lines[0]); $numbers[$v]++; open(FILE, ">$polldir/q$q_id[$q]\.txt") || &file_open_error("q$q_id[$q]\.txt"); for ($a = 0; $a < $num_answers[$q]; $a++) { print FILE "$numbers[$a]"; print FILE "``"; } print FILE "x"; close(FILE); &results($q) if ($ssi eq 'false'); &ssi_results; } else { print "Content-type: text/html\n\n"; &fatal_error("No Response Selected"); } exit; } sub results { print "Content-type: text/html\n\n"; local($qu) = @_; open(FILE, "$polldir/q$q_id[$qu]\.txt") || &file_open_error("q$q_id[$qu]\.txt"); @lines = ; close(FILE); @values = split(/``/, $lines[0]); $nv = @values; $total = 0; for ($a = 0; $a < $nv; $a++) { $total += $values[$a]; } for ($a = 0; $a < $nv; $a++) { if ($values[$a] > 0) { $values_p[$a] = sprintf("%.2f", ($values[$a]/$total) * 100); } else { $values_p[$a] = 0; } $values_g[$a] = int($graph_width*$values_p[$a])+1; } print "\n"; print "Results\n"; print "\n"; print "\n"; print "
\n"; print "

$questions[$qu]

\n"; print "\n"; print "\n"; print "\n"; print "\n"; if ($include_percent == 1) { print "\n"; } if ($include_graph == 1) { print "\n"; } print "\n"; $c = 0; for ($b = $total_answers[$qu]; $b < $total_answers[$qu]+$num_answers[$qu]; $b++) { print "\n"; print "\n"; print "\n"; if ($include_percent == 1) { print "\n"; } if ($include_graph == 1) { print "\n"; } $c++; } if ($include_total == 1) { print "\n"; print "\n"; print "\n"; if ($include_percent == 1) { print "\n"; } if ($include_graph == 1) { print "\n"; } } print "\n"; print "
SvarsalternativRösterProcentDiagram som visar andel av röster
$answers[$b]$values[$c]$values_p[$c] %
Totalt$total100.00 %..
\n"; print "
\n"; print "\n"; print "\n"; print "
\n"; print "
\n"; exit; } sub ssi_results { print "HTTP/1.0 302 Temporary Redirection\r\n" if $ENV{PERLXS} eq "PerlIS"; print "Content-type: text/html\n"; print ("Location: $return_page\n\n"); exit; } sub check { local($qu) = @_; $foundip = 'No'; if ($check_cookies) { if (&GetCookies('questions')) { (@answered) = split(/,/,$Cookies{'questions'}); for ($f = 0; $f < @answered - 1; $f++) { $foundip = 'Yes' if ($answered[$f] == $q_id[$qu]); } } } if ($check_ip) { open(FILE, "$polldir/ip$q_id[$qu]\.txt") || &file_open_error("ip$q_id[$qu]\.txt"); @lines = ; close(FILE); $numip = @lines; $voted[$a] = 'No'; for ($b = 0; $b < $numip; $b++) { ($check_ip,$nochop) = split(/``/,$lines[$b]); if ($check_ip eq $ip) { $foundip = 'Yes'; $b = $numip; } } } } sub admin { print "\n"; print "RobPoll Admin\n"; print "\n"; print "\n"; print "
\n"; print "

Admin

\n"; print "
\n"; print "\n"; print "\n"; print "

\n"; print "

\n"; print "\n"; print "\n"; print "

\n"; print "

\n"; print "\n"; print "\n"; print "

\n"; print "Rob's Place\n"; print "

\n"; exit; } sub add { print "\n"; print "Add a New Question\n"; print "\n"; print "\n"; print "
\n"; print "

Skapa ny fråga

\n"; print "
\n"; print "Password:\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; for ($a = 0; $a < 20; $a++) { $aa = $a + 1; print "\n"; print "\n"; } print "
\n"; print "Skapa ny fråga:
\n"; print "
\n"; print "Antal alternativ för fråga:\n"; print "\n"; print "
\n"; print "Antal alternativ för fråga:
$aa
\n"; print "\n"; print "\n"; print "
\n"; print "
\n"; print "
\n"; exit; } sub add2 { $new_q = $FORM{'question'}; $num_r = $FORM{'num_responses'}; &badpass if ($encrypted_password ne crypt($FORM{'pass'}, substr($encrypted_password, 0, 2))); for ($a = 0; $a < $num_r; $a++) { if ($FORM{"r$a"}) { $r[$a] = $FORM{"r$a"}; } else { $b = $a+1; &fatal_error("Response Number $b Not Entered"); } } open(NUMBER,"$polldir/num.txt") || &file_open_error("num.txt"); $num = ; close(NUMBER); if ($num == 99999) { $num = "1"; } else { $num++; } open(NUM,">$polldir/num.txt") || &file_open_error("num.txt"); print NUM "$num"; close(NUM); $num_questions++; open (FILE, ">$polldir/data.txt") || &file_open_error("data.txt"); print FILE "$num_questions``x\n"; for ($a = 0; $a < $num_questions-1; $a++) { print FILE "$num_answers[$a]"; print FILE "``"; } print FILE "$num_r"; print FILE "``x\n"; for ($a = 0; $a < $num_questions-1; $a++) { print FILE "$q_id[$a]"; print FILE "``"; } print FILE "$num"; print FILE "``x\n"; for ($a = 0; $a < $num_questions-1; $a++) { print FILE "$questions[$a]"; print FILE "``"; } print FILE "$new_q"; print FILE "``x\n"; $total_a = @answers; for ($a = 0; $a < $total_a-1; $a++) { print FILE "$answers[$a]"; print FILE "``"; } for ($a = 0; $a < $num_r; $a++) { print FILE "$r[$a]"; print FILE "``"; } print FILE "x\n"; print FILE "$encrypted_password"; print FILE "``x\n"; close(FILE); open(FILE, ">$polldir/q$num\.txt") || &file_open_error("q$num\.txt"); for ($a = 0; $a < $num_r; $a++) { print FILE "0``"; } print FILE "x"; close(FILE); open(FILE, ">$polldir/ip$num\.txt") || &file_open_error("ip$num\.txt"); print FILE "zzz.zzz.zzz.zzz``x\n"; close(FILE); print "\n"; print "Finished\n"; print "\n"; print "\n"; print "
\n"; print "

Följande information lämnades

\n"; print "\n"; print "\n"; print "\n"; print "
$new_q
\n"; for ($a = 0; $a < $num_r; $a++) { print "$r[$a]
\n"; } print "
\n"; print "
\n"; print "\n"; print "\n"; print "
\n"; print "
\n"; exit; } sub remove { &remove_last if ($num_questions < 2); print "\n"; print "Remove a Question\n"; print "\n"; print "\n"; print "
\n"; print "

Ta bort en fråga

\n"; print "
\n"; print "Password:\n"; print "\n"; print "\n"; for ($a = 0; $a < $num_questions; $a++) { print "\n"; print "\n"; print "\n"; print "\n"; } print "\n"; print "
$questions[$a]
\n"; print "\n"; print "
\n"; print "
\n"; print "
\n"; exit; } sub remove2 { &remove_last if ($num_questions < 2); &badpass if ($encrypted_password ne crypt($FORM{'pass'}, substr($encrypted_password, 0, 2))); $question = $FORM{'q'}; open (FILE, ">$polldir/data.txt") || &file_open_error("data.txt"); $tempxxx = $num_questions - 1; print FILE "$tempxxx"; print FILE "``x\n"; for ($a = 0; $a < $question; $a++) { print FILE "$num_answers[$a]"; print FILE "``"; } for ($a = $question+1; $a < $num_questions; $a++) { print FILE "$num_answers[$a]"; print FILE "``"; } print FILE "x\n"; for ($a = 0; $a < $question; $a++) { print FILE "$q_id[$a]"; print FILE "``"; } for ($a = $question+1; $a < $num_questions; $a++) { print FILE "$q_id[$a]"; print FILE "``"; } print FILE "x\n"; for ($a = 0; $a < $question; $a++) { print FILE "$questions[$a]"; print FILE "``"; } for ($a = $question+1; $a < $num_questions; $a++) { print FILE "$questions[$a]"; print FILE "``"; } print FILE "x\n"; for ($a = 0; $a < $total_answers[$question]; $a++) { print FILE "$answers[$a]"; print FILE "``"; } $na = @answers; for ($a = $total_answers[$question] + $num_answers[$question]; $a < $na-1; $a++) { print FILE "$answers[$a]"; print FILE "``"; } print FILE "x\n"; print FILE "$encrypted_password"; print FILE "``x\n"; close(FILE); &del_file("$polldir/q$q_id[$question]\.txt"); &del_file("$polldir/ip$q_id[$question]\.txt"); print "\n"; print "Finished\n"; print "\n"; print "\n"; print "
\n"; print "

\"$questions[$question]\" togs bort

\n"; print "
\n"; print "\n"; print "\n"; print "
\n"; print "
\n"; print "
"; exit; } sub passwd { print "\n"; print "Change Password\n"; print "\n"; print "\n"; print "
\n"; print "

Byt lösenord

\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
Password:
New Password:
Retype Password:
\n"; print "\n"; print "\n"; print "
\n"; print "
\n"; print "
\n"; exit; } sub setpass { &badpass if ($encrypted_password ne crypt($FORM{'pass'}, substr($encrypted_password, 0, 2))); &fatal_error("The Two New Password Fields Don't Match") if ($FORM{'newpass1'} ne $FORM{'newpass2'}); &fatal_error("No New Password Entered") if ($FORM{'newpass1'} eq ""); $write_pass = crypt($FORM{'newpass1'}, substr($encrypted_password, 0, 2)); open (FILE, ">$polldir/data.txt") || &file_open_error("data.txt"); print FILE "$num_questions``x\n"; for ($a = 0; $a < $num_questions; $a++) { print FILE "$num_answers[$a]"; print FILE "``"; } print FILE "x\n"; for ($a = 0; $a < $num_questions; $a++) { print FILE "$q_id[$a]"; print FILE "``"; } print FILE "x\n"; for ($a = 0; $a < $num_questions; $a++) { print FILE "$questions[$a]"; print FILE "``"; } print FILE "x\n"; $total_a = @answers; for ($a = 0; $a < $total_a-1; $a++) { print FILE "$answers[$a]"; print FILE "``"; } print FILE "x\n"; print FILE "$write_pass"; print FILE "``x\n"; close(FILE); print "\n"; print "Finished\n"; print "\n"; print "\n"; print "
\n"; print "

Lösenordet har ändrats

\n"; print "
\n"; print "\n"; print "\n"; print "

\n"; print "Tillbaka till frågemenyn\n"; print "
\n"; print "
"; exit; } sub GetCookies { local(@ReturnCookies) = @_; local($cookie_flag) = 0; local($cookie,$value); if ($ENV{'HTTP_COOKIE'}) { if ($ReturnCookies[0] ne '') { foreach (split(/; /,$ENV{'HTTP_COOKIE'})) { ($cookie,$value) = split(/=/); foreach $char (@Cookie_Decode_Chars) { $cookie =~ s/$char/$Cookie_Decode_Chars{$char}/g; $value =~ s/$char/$Cookie_Decode_Chars{$char}/g; } foreach $ReturnCookie (@ReturnCookies) { if ($ReturnCookie eq $cookie) { $Cookies{$cookie} = $value; $cookie_flag = "1"; } } } } else { foreach (split(/; /,$ENV{'HTTP_COOKIE'})) { ($cookie,$value) = split(/=/); foreach $char (@Cookie_Decode_Chars) { $cookie =~ s/$char/$Cookie_Decode_Chars{$char}/g; $value =~ s/$char/$Cookie_Decode_Chars{$char}/g; } $Cookies{$cookie} = $value; } $cookie_flag = 1; } } return $cookie_flag; } sub SetCookieExpDate { if ($_[0] =~ /^\w{3}\,\s\d{2}\-\w{3}-\d{4}\s\d{2}\:\d{2}\:\d{2}\sGMT$/ || $_[0] eq '') { $Cookie_Exp_Date = $_[0]; return 1; } else { return 0; } } sub SetCookiePath { $Cookie_Path = $_[0]; } sub SetCookies { local(@cookies) = @_; local($cookie,$value,$char); while( ($cookie,$value) = @cookies ) { foreach $char (@Cookie_Encode_Chars) { $cookie =~ s/$char/$Cookie_Encode_Chars{$char}/g; $value =~ s/$char/$Cookie_Encode_Chars{$char}/g; } print 'Set-Cookie: ' . $cookie . '=' . $value . ';'; if ($Cookie_Exp_Date) { print ' expires=' . $Cookie_Exp_Date . ';'; } if ($Cookie_Path) { print ' path=' . $Cookie_Path . ';'; } if ($Cookie_Domain) { print ' domain=' . $Cookie_Domain . ';'; } if ($Secure_Cookie) { print ' secure'; } print "\n"; shift(@cookies); shift(@cookies); } } sub del_file { local($filename) = @_; unlink("$filename") if (-e $filename); } sub remove_last { &fatal_error("Can't Remove Last Question"); exit; } sub badpass { &fatal_error("Invalid Password"); exit; } sub file_open_error { local($err) = @_; &fatal_error("Can't Open $err"); exit; } sub fatal_error { local($e) = @_; print "\n"; print " RobPoll Fatal Error \n"; print "\n"; print "
\n"; print "

RobRing Fatal Error

\n"; print "
\n"; print "RobPoll experienced an unrecoverable error. The error seems\n"; print "to be:

\n"; print "$e

\n\n"; print "If this error continues, you should contact the administrator.

\n"; print "Back\n"; print "

\n"; print "
"; print "
\n"; exit; }