#!/usr/bin/perl use warnings; use strict; use CGI; use POSIX qw(ceil); print 'Content-Type: text/html',"\n\n"; # print the content-type of our doc! # Create neccesary directory. mkdir("polldatabase") if (not -e 'polldatabase'); ; my $cgi = new CGI; # Create our CGI object! # where to store the votes. my $database = 'polldatabase/operatingsystems.txt'; # where to store a list of IP's that voted, this should be deleted when starting a new vote. my $lastip = 'polldatabase/lastip.txt'; # Read value passed to script. my ($poll) = $cgi->param('poll'); =for vuln open(LASTIP, '<', $lastip); my @ips = ; close(LASTIP); foreach my $ip (@ips) { chomp($ip); if($ENV{'REMOTE_ADDR'} eq $ip && $poll ne 'SHOWRESULT') { print ' :. Denlab

Sorry, you cant vote twice!

You will be redirected to the poll results in 3 seconds. '; exit(0); } } =cut # The format of the database, create the database file. if(not -e $database) { open(DB,'>',$database); print DB 'WINDOWS:0 LINUX:0 BSD:0 MACOSX:0 OTHER:0'; close(DB); } # Store the vote open(ADDVOTE,'<',$database); my @votes = ; close(ADDVOTE); # This piece of code reads the votes, and then adds to the neccesary entry. for(my $i = 0; $i <= $#votes;$i++) { my ($entry,$value) = split(/:/,$votes[$i],2); $value++; # add to the vote by 1. $votes[$i] =~ s/$poll:\d*/$poll:$value/; # regex to add the new vote to the database. } # print the new votes to the database. open(ADDTODB, '>',$database); print ADDTODB @votes; close(ADDTODB); # $total holds the total number of votes, @entries holds the entries, and @poll holds the votes. my ($total); my (@entries,@poll); foreach my $castvote (@votes) { my ($entry,$number) = split(/:/,$castvote,2); # split the db entry into category/vote. $total += $number; # add the vote to the total. push(@entries,$entry); # add $entry to @entries. push(@poll,$number); # add $number to @poll . } # The next section of code just prints the HTML. print ' :. denlab - online denlab servers
'; print '
Poll results
Poll Results - votes ',$total,' '; # loop through $entries and print the results to the html document. my $percent; for(my $i = 0;$i <= $#entries;$i++) { print "",'"; } print '
$entries[$i]  ',$percent = ceil($poll[$i] / $total * 100),"%
'; print '
'; print ' '; open(IPLAST, '>>', $lastip) or die("$!"); print IPLAST $ENV{'REMOTE_ADDR'},"\n"; close(IPLAST);