#!/usr/bin/perl -Tw # #NAME # findget - CGI sanity test # #SYNOPSIS # http://host.dom.ain:port/CGI/findget/path/info?some&args=values... # #DESCRIPTION # This is a CGI script that looks for certain hosts in the client info, # and sends them a message. It also prints out a dump of all its HTML # form fields, and its environment. # # This program really is a sort of prototype and sanity test. # #OPTIONS # #FILES # #BUGS # #SEE ALSO # #AUTHOR John Chambers $| = 1; use strict; my($e, $n, @names, $query, $v, @vals); my($botname, $hms, $msg, $UA, $ymd); #push @INC, '.'; #require "sendsubs.pm"; use CGI; use CGI::Carp 'fatalsToBrowser'; use diagnostics; print "Content-type: text/html\n\n"; print "$0\n"; print "
$0
\n"; print "
Here are our form elements:\n"; $query = new CGI; @names = $query->param(); print "
\n"; for $n (sort @names) { if (@vals = $query->param($n)) { for $v (@vals) {print "
$n
\"$v\"\n"} } elsif ($v = $query->param($n)) { print "
$n
\"$v\"\n"; } else { print "
$n
(NO VALUE)\n"; } } print "
\n"; print "
Here are our environment variables:\n"; print "
\n"; for $e (sort keys %ENV) { $v = $ENV{$e}; print "
$e
$v\n"; } print "
\n"; # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Check for known bots, and reject their request if they've asked for a tune # # match. But we don't discriminate against them here; we just announce that # # we think they're a bot. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # if ($UA = $query->param('HTTP_USER_AGENT')) { if ($UA =~ /([-\w]*Google\w*|Yahoo. \w*)/) { $botname = $1; my($ss,$mm,$hh,$DD,$MM,$CY) = gmtime(time); $CY += 1900; $ymd = sprintf("%d-%02d-%02d",$CY,1+$MM,$DD); # CCYY-MM-DD $hms = sprintf("%02d:%02d:%02d",$hh,$mm,$ss); # HH:MM:SS $msg = "[$ymd $hms] $$ $0: Request from \"$botname\" bot."; print STDERR "$msg\n"; # Tell the errlog about it print "$msg\n"; # Tell the client about it } } print "
\n";