#!/usr/bin/perl -w # # mapselect CGI for the ZazaMap applet, poslib and the web control # interface. Used to select the map and starting position for the # robot when in Phase III/IV mode. # # Copyright (C) 2003 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 # LWP::Simple; # Image::Magick; # LWP::Simple; # # ## Revision History ## # 0.01 10-10-2003 # First working version. # require "/home/brudy/posServer/poslib.pl"; #use Config::IniFiles; # this is loaded through poslib.pl use CGI::Request; use CGI::LogCarp qw(:STDLOG); use Apache::Constants ':common'; use Image::Magick; use LWP::Simple; # Full Interface: my $req = new CGI::Request; # fetch and parse request my $clientip = $req->cgi->var("REMOTE_ADDR"); my $clientpath = $req->cgi->var("HTTP_REFERER"); my $tlmap_dir = "/home/brudy/posServer/maps"; my $html_dir = "/var/www/html/mapselect"; my $bee_bin_dir = "/home/brudy/bee/bin"; #my $robot_image = "/home/brudy/public_html/zaza/java/images/robot.gif"; #my $robot_image = "/home/brudy/public_html/zaza/java/images/robot3.png"; my $robot_image = "/home/brudy/public_html/zaza/java/images/robot4.png"; print "\n"; if (!poslib::isuberclient($clientip)) { # This IP is not an uberclient, let's see if they have authenticated if (($clientpath =~ m/brudy\/internal\//) || ($clientpath =~ m/cgi-bin\/zaza-control/) || ($clientpath =~ m/cgi-bin\/mapselect/)) { # It's ok, they have authenticated } else { print"
Sorry " . $clientip . ", you are not allowed to select maps.<\/pre><\/html>\n";
die "$clientip attempted to use the mapselect CGI!\n";
}
}
if ($req->param('set_map') eq '') {
# create the map selection window
# dump header info
print<
mapselect
Select Map
HEADER
# index directories
opendir(DIR, $tlmap_dir) || die "Can't open top level map directory!";
my @directories = grep { !/^\./ && !/params/ && -d "$tlmap_dir/$_" } readdir(DIR);
closedir(DIR);
# clear out anything left over from the last run
system("rm $html_dir/*_map.gif");
my $firsttime = 1;
foreach $directory (@directories) {
# Open the ini file for this map
my $inifile = new Config::IniFiles( -file => "$tlmap_dir/$directory/mapselect.ini");
# Skip any map that isn't enabled
if ($inifile->val( 'Map', 'Enabled') =~ m/yes|1/i) {
if (!-e "$tlmap_dir/$directory/map_image/map.gif") {
# create images if needed
create_applet_image("$tlmap_dir/$directory");
}
# copy images to web accessable location
system("cp $tlmap_dir/$directory/map_image/map.gif $html_dir/$directory" . "_map.gif");
# dump table HTML for this map
if (!$firsttime) {
print "
\n";
}
print "