#!/usr/bin/perl # #$Id: WebRman,v 1.2 1997/10/26 19:54:56 root Exp root $ # ################################################################################ # # # WebRman v1.1 - the CGI interface to RosettaMan # # # ################################################################################ # Written by Olivier Bourquin , inspired by # # rman.pl by Alexander Gagin and # # http-rman by Fredrik Lundh . # # # # Many many thanks to Thomas A. Phelps (phelps@ACM.org) for # # his magnificent RosettaMan. # # RosettaMan is available at # # ftp://ftp.cs.berkeley.edu/ucb/people/phelps/tcltk/rman.tar.Z # # # # NOTE: Version 3.0 of rman or higher is required!!! # # # # Copyright (C) 1997-2000 Olivier Bourquin # # All Rights Reserved. # # # # Here some word of advise... # # # # PERMISSION IS GRANTED TO DISTRIBUTE THIS SOFTWARE FREELY, WITH THE # # EXCEPTION THAT ONE MAY NOT CHARGE FOR IT OR INCLUDE IT WITH SOFTWARE # # WHICH IS SOLD. Permission to use, copy, modify, and distribute this # # software and its documentation for educational, research, internal # # corporate and non-profit purposes, without fee, and without a written # # agreement is hereby granted for all cases that do not conflict with # # the restriction in the first sentence of this paragraph, provided that # # the above copyright notice, this paragraph, and the following three # # paragraphs appear in all copies. # # # # Permission to incorporate this software into commercial products may # # be obtained from the author Olivier Bourquin . # # # # IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, # # SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF # # THIS SOFTWARE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF # # SUCH DAMAGE. # # # # THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED # # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # # PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE # # AUTHOR HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, # # ENHANCEMENTS, OR MODIFICATIONS. # # # # # ################################################################################ # # # Configurable section - Change the values below... # # # ################################################################################ # URL of the background picture desired $background="/images/help-back.jpg"; # Name of the person to be contacted $webmaster='the webmaster'; # and his/her mail address $webmail='webmaster@oli.isoe.ch'; # path to the 'man' program $man='/usr/bin/man'; # colon separated list of paths to man directories $manpath='/usr/man:/usr/X11R6/man:/usr/local/man:/usr/openwin/man'; # path to RosettaMan program. $rman='/usr/bin/rman'; # footpage of every produced html document $footpage='
Look up another man page
Back to Gromit\'s Help Page
Back to Gromit\'s Homepage
Send a mail to the Webmaster '; # $form defines what the query form should look like. # The form must have three fields: # "topic" : text field where the topic searched is entered # "section" : possibles man sections, and "all" # "keyword" : check box allowing "apropos" (man -k) # # Check the action as well (method=GET and action=URL to the program)! $form='

WebRman - THE Gateway to Manual pages

Enter a command:
choose a manual-section:
or search only for keyword
(section will be ignored then)

... and ...

'; ################################################################################ # # # End of configation # # # # from here on, I am on my own... $tail=$footpage . '
WebRman © 1997-2000, Olivier Bourquin
RosettaMan © 1993-1996, Thomas A. Phelps
'; $script=$ENV{'SCRIPT_NAME'}; &parse_form; $topic=$FORM{'topic'}; $section=$FORM{'section'}; $keyword=$FORM{'keyword'}; if( $ENV{'QUERY_STRING'} eq "" ){ &print_header("Entry-form"); print $form; print $tail; exit; } &return_error(500,"No topic!","Please enter what you're looking for...") unless (($topic) ne ""); if ($keyword eq "on"){ &search_keyword; } else { &show_page; } ################################################################################ # sub to return the man -k sub search_keyword { open(MANK,"$man -M $manpath -k $topic |") || &return_error (500,"System error", "Can't open pipe $man -M $manpath -k $topic |: $!\n"); read(MANK,$x,100); &return_error(500,"Nothing found", "Nothing could be found for $topic.") if ($x =~ /nothing appro/i); &print_header("Keyword search results for $topic"); print "

Keyword search results for $topic

\n"; print "\n"; while() { if ($_=~/^(.+) \((\S+)\)\s+\- (.+)$/) { print ""; print ""; print "\n"; } } print "
"; print ""; print "$1 ($2)    -    $3
\n"; print $tail; exit; } ################################################################################ # sub to return the manual page sub show_page { $|=1; $section="" if ($section eq "all"); open(MAN,"$man -M $manpath $section $topic |") || &return_error (500,"System error", "Can't open pipe $man -M $manpath -k $topic |: $!\n"); read( MAN,$x,100); if ($x=~ /^no manu/i){ &return_error(500,"Man page not found", "The manual page of $topic ($section) doesn't exist!"); } print "Content-type: text/html\n\n"; open (RMAN,"| $rman -f html -b -r \"$script?topic=%s\§ion=%s\" -l \"$topic ($section) Manual Page\"") || &return_error (500,"System error", "Can't open pipe | $rman : $!\n"); my $err=0; while (){ print RMAN $_; } close MAN; close RMAN; print $tail; } ################################################################################ # Sub to parse the form data sub parse_form { if ($ENV{'REQUEST_METHOD'} eq 'GET') { # Split the name-value pairs @pairs = split(/&/, $ENV{'QUERY_STRING'}); } else { &return_error (500, "Server Error", "Server uses unsupported method"); } foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # If they try to include server side includes, erase them, so they # arent a security risk if the html gets returned. $value =~ s///g; $FORM{$name} = $value; } } ################################################################################ # Sub that returns the header sub print_header { local ($title,$nocache) = @_; print "Content-type: text/html\n\n"; print "\n"; print "WebRman - $title\n"; print ""; } ################################################################################ # Sub to return nice errors sub return_error { local ($status, $keyword, $message) = @_; print "Content-type: text/html\n"; print "Status: ", $status, " ", $keyword, "\n\n"; print <<"End_of_Error"; WebRman - Error

$keyword

$message

Please contact $webmaster for more information. End_of_Error print $tail; exit -1; }