#!/usr/local/bin/perl -w use CGI qw(:all); use CGI::Carp; my $c = param('c'); # container my $invalid; if (defined $c) { $c = cleanContainer($c); $invalid = validate($c); } if (! defined($c) || defined($invalid)) { print header(); print << "%%";

Google Earth Container Tracker

Container number
%% print "

$invalid

" if (defined($invalid)); print << '%%';

At this point, the demo is only known to work with these containers:

Other input is likely to cause it to fail in mysterious ways, because this is just a prototype.

The files that make this thing work are here. You can also see the README without unpacking the zip file. These files are placed in the public domain, and may be used by anyone as a basis of any future project. Jeff R. Allen, June 8, 2006. %% exit; } print header(-type => 'application/vnd.google-earth.kml+xml', '-Content-disposition' => 'attachment; filename=track.kml' ); # make the new URL by editing out current one my $me = self_url(); $me =~ s/(index.cgi)?\?/track.cgi?/; print << "%%" Tracking container $c 1 $me onInterval 86404 onRequest %% ; # make sure it is not undef, # then uppercase it, # then remove all things which are not numbers and letters. sub cleanContainer { my($c) = $_[0] || ''; $c = uc($c); $c =~ s/[^A-Z0-9]//; return $c; } # already cleaned, so guaranteed to be close to right format # not undef, num/let only. sub validate { my($c) = @_; if (length($c) != 11) { return "Container numbers should be exactly 11 characters long." } if ($c !~ /^[A-Z]{4}.......$/) { return "Container numbers should start with exactly 4 letters." } if ($c !~ /^....[0-9]{7}$/) { return "Container numbers should end with exactly 7 numbers." } # no errors, yay return undef; }