#!/usr/bin/perl # # webxref.cgi - web interface to run webxref # # Written by Earl Fogel, March 1996 # using the cgi-lib.pl library # # March 1998 - updated to use webxref version 4 # Jan-Feb 1999 - added depth, group, user options # - added basepath and baseurl require "common.pl"; require "cgi-lib.pl"; $| = 1; # un-buffered output (required if we do an exec) $ENV{'PATH'} = '/bin:/usr/bin'; $virtual = 0; # show fields to check virtual hosts MAIN: { # Read in all the variables set by the form if (&ReadParse(*in) || defined($ARGV[0])) { &ProcessForm; } else { &PrintForm; } } sub ProcessForm { $in{query} = $ARGV[0] if defined($ARGV[0]); $in{depth} = 0 unless $in{depth} > 0; # CgiDie("Sorry, you must type in a valid URL.") # unless $in{query} =~ /\S/; $query = purify($in{query}); if ($in{baseurl}) { $baseurl = purify($in{baseurl}); } else { $baseurl = "http://$ENV{SERVER_NAME}/"; } if ($in{basepath}) { $basepath = purify($in{basepath}); } else { $basepath = $ENV{DOCUMENT_ROOT}; } CgiDie("Can't find base directory ($basepath) for $baseurl") unless -d $basepath; print &PrintHeader; # if it's not a url, assume it's a local file if ($query !~ m#://#i) { $query =~ s#^/www##; $query = "/$query" if ($query !~ m#^/#i); $query = "$baseurl$query"; } # We can only handle local files if ($query !~ s#^$baseurl/##i) { CgiDie("Sorry, I can only check files on $ENV{SERVER_NAME}\n"); } $args = ""; $args .= "-long " if $in{long}; $args .= "-verbose -verbose " if $in{progress}; $args .= "-dots " unless $in{progress} || $in{dots}; $args .= "-nohttp " unless $in{http}; $args .= "-fluff " if $in{orphans}; $args .= "-group " unless $in{group}; $args .= "-user " unless $in{user}; $args .= "-depth $in{depth} " if defined $in{depth}; $args .= "-islocal $baseurl "; $args .= "-timeout $in{timeout} " if $in{timeout}; $args .= "-debug " if $in{debug}; $args .= "-html "; $args .= "'$query'"; print "cd $basepath; /var/www/bin/webxref4 $args
\n" if $in{debug}; system "cd $basepath; /var/www/bin/webxref4 $args 2>&1" || CgiDie("webxref4 $args failed: $?"); } sub PrintForm { print &PrintHeader; print_header("Check Links on $ENV{SERVER_NAME}"); print <<"EOF"; This form uses webxref to check links on web pages on $ENV{SERVER_NAME}.
Enter the URL to your file in the following field (relative to http://$ENV{SERVER_NAME}/).
EOF print_footer(); }