#!c:/Perl/bin/perl ## HOST: intranet #!/usr/bin/perl ## HOST: 1dollarhosting #!/usr/local/bin/perl ## HOST: verio # define script defaults (change these to suit your needs) my %defaults = ( path => "", debug => "", ); # define script properties (don't change these) my %script = ( name => "frankenpage", version => "1.02", release => "Final", author => "Sean Shrum", email => "sean\@shrum.net", created => "2001.03.22", modified => "2002.03.23", status => "open source", distribute => "http://www.shrum.net/programming", ); # define script error messages (don't change these) my %errors = ( header => "$script{'name'} v. $script{'version'} [ $script{'release'} ] by $script{'author'} ( $script{'email'} ) - $script{'status'}\n\n", nopath => "No PATH parameter was specified.\n", badpath => "Unable to open the specified PATH.\n", badsource => "Unable to open the specified FILE.\n", ); ################################################################################ # # WHAT DOES THIS SCRIPT DO? # Reads a directory of files and builds a form that allows you to specify what # to include/omit in the final result. Upon submitting, the script pulls the # files you selected in the order your chose and builds the page. # # WHY ARE THE NOTES DOWN HERE? # Typically, you open up a script and this section is the first thing you # see. Not with my scripts. Why? Well, it makes it easier to parse the # script file for various important items, things like the version #, # release, status, etc. As a result, I moved this section below them in # the event that I write something like "..this version contains...", my # parsing scripts don't get the two confused. This is really for my own # reasons. Once you have d/l'ed the script, feel free to move this section # where ever you like. # # WHERE ARE THE SCRIPT REQUIREMENTS, INPUT, OUTPUT, FAQs, ETC.? # To reduce the amount of redundant write up that I have to do, # all info pertaining to the use of this script has been centralized. # on my website. Go to www.shrum.net/programming and do a search # on the script name for the latest source and white paper discussion # Use these resources first if you need any information. # # SUPPORT AND LEGAL ISSUES: # See http://www.shrum.net/programming/legal for information. # ################################################################################ # to access REMOTE files use LWP::Simple; # to handle parameter passing use CGI; # to display more meaningful error messages to the browser use CGI::Carp qw(fatalsToBrowser); # check if the DOCUMENT_ROOT environment variable is defined my $rootPath = "$ENV{'DOCUMENT_ROOT'}/" || ""; # get the parameters; 1st from the ARGV array or the QUERY_STRING if (@ARGV) { $input = new CGI ( join "&" => @ARGV ); } else { $input = new CGI; } # check for input; if no parameters are supplied, redirect to technical white paper unless ( $input->param() ) { print $input->redirect( $script{'distribute'} . '/redirects/' . $script{'name'} . '.shtml' ); exit; } # set defaults for parameters omitted by user for ( keys %defaults ) { $input->param(-name=>$_,-value=>$defaults{$_}) unless $input->param($_); } # check for required parameters if ( ! defined $input->param('path') ) { die $errors{'header'} . $errors{'nopath'}; } # see if this is part of a SSI call, if not print out the HTML header print $input->header unless @ARGV; ################################################################################ # for debugging if ( $input->param('debug') ) { print "

Retrieving file list..."; } # open the user specified directory opendir (DIR, $rootPath . $input->param('path')) or die $errors{'header'} . $errors{'badpath'}; # fill the array with all the filenames in the specified PATH #@files = grep { !/^\./ && -f } map {$rootPath . $input->param('path') . "/" . $_ } readdir DIR; @files = readdir DIR; # close the directory closedir(DIR); # sort the array @files = sort @files; # get the number of files $num_files = $#files + 1; # for debugging if ( $input->param('debug') ) { print $num_files . " found."; } # initalize $page my $page = ""; # see if we are building the final resume if ( $input->param('s1') ne "" ) { # for debugging if ( $input->param('debug') ) { print "


Building PAGE...

"; } # for debugging if ( $input->param('debug') ) { print "

...adding section "; } # loop through each possible iteration foreach ( @files ) { # increment the count $count++; # for debugging if ( $input->param('debug') ) { print $count . ","; } # see if the user selected a entry $skey = "s" . $count; if ( $input->param($skey) ne "" ) { # retrieve the defined file $section = &get_data( $rootPath . $input->param('path') . "/" . $input->param($skey) ); # see if the user requested a HR be inserted above this section $ckey = "c" . $count; if ( $input->param($ckey) ) { $break = "


"; } else { $break = ""; } # add the result to the page $page = $page . $break . $section; } } } else { # for debugging if ( $input->param('debug') ) { print "

Building FORM...

"; } # build the section_template $page = "

Welcome to Frankenpage

The on-the-fly-slap-it-together web page construction Script.

Looks like you'll be building a page from the contents of " . $input->param('path') . "."; # make the script call itself again $page = $page . "

"; # for debugging if ( $input->param('debug') ) { print "

...adding section "; } # create a combobox for each file (in case the user wants everything). foreach ( @files ) { # increment the count $count++; # for debugging if ( $input->param('debug') ) { print $count . ","; } # start off the section $section = "

" . $count . ". Break before this section with hortizontal rule"; # add the section to the page $page = $page . $section; } # for debugging if ( $input->param('debug') ) { print "

"; } # add a submit button and cap off the FORM tag $page = $page . "

param('path'). "\">

"; } # for debugging if ( $input->param('debug') ) { print "

Printing...

"; } # display page print $page; # quit exit; ######################################## sub get_data ( $source ) { # pass the arguments to localized variables my $source = $_[0]; # make sure that the source is defined if ( $source ) { # for debugging if ( $input->param('debug') ) { print "

...openning locally hosted file: $source

"; } # open the local file open ( DATA, $source ) or die $errors{'header'} . $errors{'badsource'} . "\n\nSource: $source"; local($/) = undef; # place the raw contents of the file into a variable $data = ; # close the file close (DATA); } # return the results return $data; }