home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/tclsh
-
- # tcltest.tcl: bot implementation in Tcl
-
- # ----------------------------------------------------------
-
- # Decode CGI/1.1 parameters, args, and environment variables
- # from tcl-cgi2.tcl
- #
- # Rewrite by dl@hplyot.obspm.fr - v2.2 - May 24th 1995
- # based on robert.bagwill@nist.gov's version
- #
- # news and latest version shall on http://hplyot.obspm.fr/~dl/wwwtools.html
- #
- # no warranty, no rights reserved
- #
-
- # ----------------------------------------------------------
-
- set envvars {SERVER_SOFTWARE SERVER_NAME GATEWAY_INTERFACE SERVER_PROTOCOL SERVER_PORT REQUEST_METHOD PATH_INFO PATH_TRANSLATED SCRIPT_NAME QUERY_STRING REMOTE_HOST REMOTE_ADDR REMOTE_USER AUTH_TYPE CONTENT_TYPE CONTENT_LENGTH HTTP_ACCEPT HTTP_REFERER HTTP_USER_AGENT}
-
- # ----------------------------------------------------------
-
- #
- # UnCgi Translation hack, in Tcl, v1.5 5/1995 by dl@hplyot.obspm.fr
- #
- proc uncgi {buf} {
- # ncsa httpd (at least) \ quotes some chars, including \ so :
- regsub -all {\\(.)} $buf {\1} buf ;
- regsub -all {\\} $buf {\\\\} buf ;
- regsub -all { } $buf {\ } buf ;
- regsub -all {\+} $buf {\ } buf ;
- regsub -all {\$} $buf {\$} buf ;
- regsub -all \n $buf {\n} buf ;
- regsub -all {;} $buf {\;} buf ;
- regsub -all {\[} $buf {\[} buf ;
- regsub -all \" $buf \\\" buf ;
- # the next one can probably be skipped as the first char is prolly not
- # an \{, but, hey who knows... lets be safe...
- regsub ^\{ $buf \\\{ buf ;
- # I think everything has been escaped, now the real work :
- regsub -all -nocase {%([a-fA-F0-9][a-fA-F0-9])} $buf {[format %c 0x\1]} buf
- # And now lets replace all those escaped back, along with excuting of
- # the format :
- eval return \"$buf\"
- # now everything is in buf, but translated, nice trick no ?
- }
-
- # ----------------------------------------------------------
-
- # returns in the 'cgi' array all the parameters sent to the script
- # through 'message' (each array cell is a list (ie if only one value
- # is expected through 'test' variable, use [lindex $cgi(test) 0] to get it)).
-
- proc parse_cgi_message {message} {
- global cgi;
- set cgi() "";
- foreach pair [split $message &] {
- set plst [split $pair =];
- set name [uncgi [lindex $plst 0]];
- set val [uncgi [lindex $plst 1]];
- lappend cgi($name) $val;
- }
- }
-
- # ----------------------------------------------------------
-
- # get the params, depending of method :
- if {[string compare $env(REQUEST_METHOD) "POST"]==0} {
- set message [read stdin $env(CONTENT_LENGTH)];
- } else {
- set message $env(QUERY_STRING)
- }
- parse_cgi_message $message;
-
- # Show our attributes
-
- puts "<UL>"
- puts "<LI><B>Bot Attributes</B>"
- foreach var [array names cgi] {
- puts "<LI><I>$var</I>: $cgi($var)";
- }
- puts "<LI><B>Environment Variables</B>"
- foreach var $envvars {
- if {[info exists env($var)]} {
- puts "<LI><I>$var</I>: $env($var)"
- }
- }
- puts "</UL>"
-
-
-