#!/usr/bin/perl # # posServer CGI for the ZazaMap applet. # Copyright (C) 2001 Brian Rudy (brudyNO@SPAMpraecogito.com) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # # Requires: poslib.pl # CGI::Request # CGI::LogCarp # # ## Revision History ## # 0.35 9-20-2002 # Quick update for mod_perl support. # # 0.34 6-24-2002 # Added support for isvotingenabled(). # # 0.33 12-8-2001 # Added goal voting enable/disable (voting only allowed from uberclients). # # 0.32 9-8-2001 # Cleaned up debugging messages to make more Apache/client friendly. # # 0.31 8-15-2001 # Added support for basic vote listing for debugging. # # 0.30 8-14-2001 # Replaced simple CGI form parsing with CGI::Request. Initial support # for sendgoal. Added test mode switch. Added shared goal retreival # from poslib with popgoals(). # # 0.22 8-10-2001 # Initial poslib support with poppos(), now it really works! # # 0.21 8-2-2001 # Added info URL to goals (x,y,name,URL,,) # # 0.20 7-30-2001 # Basic goal point support (x,y,name,,) # # 0.10 7-24-2001 # First working version. Random position generation for testing. # require "/home/brudy/posServer/poslib.pl"; use CGI::Request; use CGI::LogCarp qw(:STDLOG); use Apache::Constants ':common'; # Simple interface: (combines SendHeaders, new and import_names) # my $req = GetRequest($pkg); # Full Interface: my $req = new CGI::Request; # fetch and parse request # Prepare log stream #open(LOG,">>/var/log/httpd/posServer_log") open(LOG,">>/home/brudy/posServer/log/posServer_log") or die "Unable to open posServer_log: $!\n"; logmsgout \*LOG; # Setup data (goals) if ($req->param('setup') eq 'yes') { my @appletgoals = popgoals(); for $j (0 .. $#appletgoals) { print join(",",$appletgoals[$j]{Appletx}, $appletgoals[$j]{Applety}, $appletgoals[$j]{Name}, $appletgoals[$j]{URL}) . ",,\n"; } } # Position if ($req->param('getpos') eq 'yes') { my ($x,$y,$theta) = poppos(); printf("%.0f,", $x); printf("%.0f,", $y); printf("%.0f,,\n", $theta); } # Goal request if ($req->param('sendgoal') ne '') { my $clientip = $req->cgi->var("REMOTE_ADDR"); if ($clientip eq '') { # Bad client request. Discourage potential hackers... print "Go away!\n"; logmsg "Received vote for goal " . $req->param('sendgoal') . " from an invalid IP!\n" } else { if ((isvotingenabled()) || (isuberclient($clientip))) { my @appletgoals = popgoals(); my $goalreq = $req->param('sendgoal'); if (($goalreq >= 0) && ($goalreq <= $#appletgoals)) { votegoal($goalreq, $clientip); print "Registered vote for number " . $goalreq . ", " . $appletgoals[$goalreq]{Name} . ".\n"; } else { print "Sorry " . $clientip . " that goal is not available.\n"; logmsg "$clientip voted for an invalid goal ($goalreq).\n"; } } else { print "Sorry " . $clientip . ", voting is disabled.\n"; logmsg "$clientip voted, but voting is disabled.\n"; } } } # print out formatted list of clients and the goals they voted on if ($req->param('printvotes') ne '') { my $clientip = $req->cgi->var("REMOTE_ADDR"); if (isuberclient($clientip)) { print "
\n"; #tallyvotes(); print "
\n"; printvotes(); print "<\/pre>\n"; } else { print "Sorry, $clientip you are not allowed to view the vote table.\n"; } }