#!/usr/bin/perl -w ######################################################## #Program: perlMan #Programmer: ZiaTioN #Requires: Linux/Unix/BSD/MAC # perl # CGI.pm # # Description: # This application was designed to be a web interface # for the Linux/Unix/BSD/MAC man, perldoc and info pages. # Most the appearance is controlled by the CSS settings # in the tag. # # Copyright: # Copyright (C) 2005 - * ziation AT perlskripts.com # # This program is free software and can be redistrubuted # and/or modified under the terms of the GNU General Public # License the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # Additional requirements I have for redistrobution or editing # is that this header must remain intact. # # Disclaimer: # This application comes free of any warranty or guarantee. # If for some crazy reason this application does any damage # to your system the author of this application (me) can # not be held responsible. # # Note: # Inspiration for this application came from a program # called phpMan (http://sourceforge.net/projects/phpunixman/). # It is very similar in look and functionality to this # program. I came across the program and decided to write # my own in perl. This is NOT a perl port of that php # application. ######################################################## use strict; use CGI qw(:standard); ######################################################## # Gather and filter URL parameters my $param = CleanParam(param('param')); my $mode = CleanParam(param('mode')); my $section = CleanParam(param('section')); $mode = 'man' unless $mode; ######################################################## # Some initial checking to make sure things are in order my $mWidth = 132; my @path = reverse(split(/\//, $0)); my $app = $path[0]; if ($mode !~ /man|perldoc|info|copyright|apropos|source/) { showHeader(); print "Invalid mode type!\n"; showFooter(); exit(0); } ######################################################## # This is more or less the driver to the application if ($mode eq 'man') { showHeader(); showMan($param); showFooter(); exit(0); } if ($mode eq 'perldoc') { showHeader(); showPerldoc($param); showFooter(); exit(0) } if ($mode eq 'info') { showHeader(); showInfo($param); showFooter(); exit(0); } if ($mode eq 'apropos') { showHeader(); showApropos($param); showFooter(); exit(0); } if ($mode eq 'source') { showHeader(); showSource(); showFooter(); exit(0); } copyright() if ($mode eq 'copyright'); ######################################################## # HTML building section # Print HTML header sub showHeader { my @modes = qw(man perldoc info apropos); my $input; for (@modes) { if ($_ eq $mode) { $input .= qq~ $_\n~; } else { $input .= qq~ $_\n~; } } print "Content-type: text/html; charset=ISO-8859-1\n\n"; print qq~ perlMan
perlMan -- Web Interface For Man Pages
Command: $input
View Source -- View License

~;
}

#Print HTML body
sub showMan {
   my $param = shift;

   my $intro;
   unless ($param) {
      $intro .= qq~1) General Commands intro(1)
~; $intro .= qq~2) System Calls intro(2)
~; $intro .= qq~3) Subroutines intro(3)
~; $intro .= qq~4) Special Files intro(4)
~; $intro .= qq~5) File Formats intro(5)
~; $intro .= qq~6) Games intro(6)
~; $intro .= qq~7) Macros and Conventions intro(7)
~; $intro .= qq~8) Maintenance Commands intro(8)
~; $intro .= qq~9) Kernel Interface intro(9)
~; $intro .= qq~n) New Commands
~; print $intro; return; } # Method to obtain data without spawning a shell open(MODE, "-|") || exec("MANWIDTH=$mWidth $mode $section $param"); if () { print ParseData($_) while (); } else { print qq!$param: Nothing Appropriate!; } close(MODE); } sub showPerldoc { my $param = shift; my $cmd = $mode; $cmd = 'apropos' unless ($param); $param = 'perl' unless ($param); # Method to obtain data without spawning a shell open(MODE, "-|") || exec("$cmd $param"); if () { print ParseData($_) while (); } else { print qq!$param: Nothing Appropriate!; } close(MODE); } sub showInfo { my $param = shift; # Method to obtain data without spawning a shell open(MODE, "-|") || exec("$mode $param"); if () { print ParseData($_) while (); } else { print qq!$param: Nothing Appropriate!; } close(MODE); } sub showApropos { my $param = shift; my $cmd = $mode; unless ($param) { $cmd = 'man'; $param = 'apropos'; } # Method to obtain data without spawning a shell open(MODE, "-|") || exec("$cmd $param"); if () { print ParseData($_) while (); } else { print qq!$param: Nothing Appropriate!; } close(MODE); } sub showSource { open(APP, "<", $0) || print "Error: $!\n", return; print ParseData($_) while (); close(APP); } # Print HTML footer sub showFooter { print qq~

Author: ZiaTioN Home Page: $1";}else{$obj = $1} "$obj"|eg; } unless ($mode eq 'info') { $Tmp =~ s|([\w:\-]+)(\s*)(\()(\w+)(\))|$1$2$3$4$5|g; $Tmp =~ s|\[([\w:\-]+)\](\s*)(\()(\w+)(\))|\[$1\]$2$3$4$5|g; } else { $Tmp =~ s|\((\w+)\)|\($1\)|g; } $Tmp =~ s|(\s+)($param)(\s+)|$1$2$3|g if ($param); $Tmp =~ s|(\w+\:\:[\w\:]+)|$1|g; $Tmp =~ s|(([\w\-\.]+)\@([\w\-]+)([\w\-\.]+))|$1|g; $Tmp =~ s|(\w+:\/\/[\/\w\-_\.]+)|$1|g; return $Tmp; } sub Trim { my @tr = @_; return unless @_; for (@tr) { s!^\s+!!; s!\s+$!!; } return wantarray ? @tr : $tr[0]; } # End of filtering routines ######################################################## # +--------------------------------------------------------------------------------+ # | GNU GENERAL PUBLIC LICENSE Version 2 | # | http://www.gnu.org/licenses/gpl.txt | # +--------------------------------------------------------------------------------+ sub copyright { # Print HTML header showHeader(); print qq~GNU GENERAL PUBLIC LICENSE Version 2~; showFooter(); exit(0); }