#!/usr/bin/perl # # info2www - Gateway between GNU Info nodes and WWW $id = '$Id: info2www,v 1.2.2.9 1996/07/02 08:44:12 lmdrsm Exp $ '; # # This is a script conforming to the CGI - Common Gateway Interface # # Author: Roar Smith (lmdrsm@lmd.ericsson.se) # # Copyright: This program is in the Public Domain. # # The original code (most of &info2html) was written by # Eelco van Asperen (evas@cs.few.eur.nl). # # TODO: # ----- # * Present a list of choices when there is no exact match for the requested # Info file but multiple non-exact matches exist. # # * Use Tag Table to find possible file and offset. # # #----------------- CONFIGURATION ----------------------------------------------- # # # DEBUG should be set if you want to debug what's happening. # $DEBUG = 0; # # DEBUG_PREFIX is prepended to each debug string. # DEBUG_POSTFIX is appended to each debug string. # DEBUG_HTMLIFY should be set if you want to HTML'ify the debug output, # this shouldn't be necessary within comments, but your mileage may vary. # $DEBUG_PREFIX = ""; # Alternative suggestion: "\n" $DEBUG_HTMLIFY = 0; # Alternative suggestion: 1 # # INFOPATH is the path of direcories in which to search for Info node files. # @INFOPATH = ( "/usr/info", "/usr/local/info" ); # # ALLOWPATH specifies whether info files may be specified with path-names # outside of those directories included in INFOPATH . # It is a possible security hole to set this variable to a true value, # because *any* file on the system could then be accessed through this gateway. $ALLOWPATH = 0; # # ALLOWRELPATH specifies whether info files may be specified with # relativ path-names below the directories included in INFOPATH . $ALLOWRELPATH = 1; # # ALTERNATIVE is a map of alternatives - look for the alternative if the node # itself isn't found. # The key (first entry) is the node filename, the value (second entry) is the # alternative. Both are basenames (i.e. no path!) with no capital letters. # Note that the keys *must* be unique! # %ALTERNATIVE = ( 'emacs', 'lemacs', 'g++', 'gcc', 'c++', 'gcc', 'gunzip', 'gzip', 'zcat' , 'gzip', 'elisp', 'lispref', 'features', 'bash' # Really easy to guess this huh! ); # # Set the PATH so that the ZCAT and GZCAT programs can be found # $ENV{'PATH'} .= "/bin:/usr/bin"; # # ZCAT is the program to use for reading compressed files (*.Z) # GZCAT is the program to use for reading gzip'ped files (*.gz) # Both are arrays to be used in an exec() call, with the first element # being the program (absolute path, or something to be found in PATH) # and any additional elements being options. # # Set either of these to () if you don't want it used. # @ZCAT = ("zcat"); @GZCAT = ("gunzip", "-c"); # # URL of the icons used for indicating references and stuff: # $INFO_ICON - Icon at the top left of each document # $UP_ICON - Icon used in an "Up:" hyperlink at the top # $NEXT_ICON - Icon used in a "Next:" hyperlink at the top # $PREV_ICON - Icon used in a "Prev:" hyperlink at the top # $MENU_ICON - Icon used in front of each menu label # $ALIGN - How to aling the icons # # Set these to "" if you don't want them used. # $INFO_ICON = "/images/infodoc.jpg"; $UP_ICON = "/images/up.gif"; $NEXT_ICON = "/images/next.gif"; $PREV_ICON = "/images/prev.gif"; $MENU_ICON = "/images/menu.gif"; $ALIGN = "BOTTOM"; # # URL for documentation on info2www # # Set this to "" if you don't want it used. # $DOCREF = "/doc/info2www/info2www.html"; # # $INPUTFORM specifies whether to have an input form for going to an Info node. # # Set this to 0 if you don't want it used. # $INPUTFORM = 1; # # CACHE is the dbm(3) or ndbm(3) file for caching lookup information. # Set this to "" if you don't want it used. # The effective user of this script should have write permissions to # the directory in which the dbm files reside, or at least to the files # $CACHE.dir , $CACHE.pag and $CACHE.lock. # $CACHE = "/var/tmp/info2www_cache"; # # Set this to true if you want to lock the lookup-cache dbm(3) files # while updating lookup information. If flock(2) doesn't work on your # system, then set this to false. # You can get a tiny performance increase by unsetting this variable, # but at the cost of risking damage to the dbm files, which could happen # if you get simultaneous update attempts since there is no builtin locking # in dbm - at least not in SunOS 4.x ! # $CACHE_LOCKING = 1; # # These are the defines for file-locking with flock(2) # $LOCK_SH = 1; $LOCK_EX = 2; $LOCK_NB = 4; $LOCK_UN = 8; # #----------------- CONFIGURATION END ------------------------------------------- #----------------- MAIN -------------------------------------------------------- # print "Content-type: text/html\n\n"; # Mime header for NCSA httpd $DEBUG = 1 if (defined $ENV{'DEBUG'}); $DEBUG && &Debug($id); $pg = $0; $pg =~ s,^.*/([^/]*)$,$1,; ($version, $date) = ($id =~ m@,v\s+([0-9.]+)\s+([0-9/]+)@); %CACHE = (); %INPUT = (); $CACHE_OPENED = 0; $NFILES = 0; @INFOPATH = grep(-d, @INFOPATH); # Only search existing directories $SCRIPT_NAME = $ENV{'SCRIPT_NAME'}; $SERVER_NAME = $ENV{'SERVER_NAME'}; $QUERY_STRING = $ENV{'QUERY_STRING'}; $REQUEST_METHOD = $ENV{'REQUEST_METHOD'}; $PREFIX = $SCRIPT_NAME . "?"; # prefix for HREF= entries $DEBUG && &Debug("QUERY_STRING: $QUERY_STRING") if (defined $QUERY_STRING); $DEBUG && &Debug('ARGV: "', join('", "', @ARGV), '"') if @ARGV; if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $request, $ENV{'CONTENT_LENGTH'}); $DEBUG && &Debug("POST: $request"); } elsif ($ENV{'REQUEST_METHOD'} eq "GET" ) { if ($QUERY_STRING) { $request = $QUERY_STRING; } } if ($request) { # The argument string is encoded in %XX format and must be decoded, but not # until split up into key=value pairs: file=gcc&node=Invoking%20GCC if ($request =~ /=/) { # Form created key=value pairs %request = &UrlDecode(split(/[&=]/, $request)); if (!defined $request{'debug'}) { # Do nothing } elsif ($request{'debug'} =~ /^Y(es)?$|^On$|^True$/i) { $DEBUG = 1; &Debug("debug=$request{'debug'}\nDEBUG enabled!"); &Debug($id); &Debug("QUERY_STRING: $QUERY_STRING") if (defined $QUERY_STRING); &Debug('ARGV: "', join('", "', @ARGV), '"') if @ARGV; } elsif ($request{'debug'} =~ /N(o)?$|^Off$|^False$|^$/i) { $DEBUG && &Debug("debug=$request{'debug'}\nIgnored!"); } else { $DEBUG = 1; &Debug("debug=$request{'debug'}\nSay what???\nDEBUG enabled!"); &Debug($id); &Debug("QUERY_STRING: $QUERY_STRING") if (defined $QUERY_STRING); &Debug('ARGV: "', join('", "', @ARGV), '"') if @ARGV; } if ($nodename = ($request{'query'} || $request{'isindex'})) { if ($nodename !~ /^\(/ && $request{'file'}) { $nodename = "(".$request{'file'}.")".$nodename; } } elsif ($request{'file'}) { $nodename = "(".$request{'file'}.")".$request{'node'}; } else { $nodename = "(dir)"; } } else { # Simple request for a node $nodename = &UrlDecode($request); } } elsif (@ARGV) { # The argument string is already decoded, bet special characters are # backslash escaped: \(gcc\)Invoking\ GCC ($nodename = join('+', @ARGV)) =~ s/\\(\W)/$1/g;; } else { $nodename = "(dir)"; } $nodename = "(dir)" unless $nodename; $nodename = "(".$nodename unless ($nodename =~ /^\(/); $nodename = $nodename.")" unless ($nodename =~ /\)/); $DEBUG && &Debug("Nodename: $nodename\n"); &info2html($nodename); if ($DOCREF) { print "