#!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); ####################################################################################### # # Site File Finder V1.0 # ©2002, Jim Melanson # # Requirements: UNIX Server, Perl5+ # Created: February 5th, 2002 # Author: Jim Melanson # Contact: www.perlservices.net # Phone: 1-877-751-5900, ext. 920 # Fax: 1-208-694-1613 # E-Mail: info@perlservices.net # ####################################################################################### # # INSTRUCTIONS # # 1.) Make sure the path to Perl at the top of the script is correct. # # 2.) Place this script on your server, make sure you FTP it in ASCII mode # and not Binary mode. Make sure you place the script in an executable # directory # # 3.) Call the script by entering the full URL to it in your browsers address bar # # This script does one thing and it does it very well. It will only run on a # UNIX server. If it runs on any other platform, please let us know. # # We do not accept support requests for this script, it does not require any # support. All you need to do is make sure the path to Perl is correct, you # FTP it in ASCII mode and not Binary mode, that you CHMOD it 755 and that the # directory and parent directories it resides in are CHMOD 755. # ####################################################################################### # # Edit nothing below this line # ####################################################################################### #Set the primary path $FORM{search_in} = $ENV{'DOCUMENT_ROOT'}; &Parse; $ScriptURL = qq~http://$ENV{'SERVER_NAME'}$ENV{'SCRIPT_NAME'}~; my($fselected, $dselected, $aselected); if($FORM{finding} =~ /^f/) {$fselected = qq~ selected~} elsif($FORM{finding} =~ /^d/) {$dselected = qq~ selected~} else {$aselected = qq~ selected~} print "Pragma: no-cache\nContent-type: text/html\n\n"; print qq~Perl Services - Site File Lister
Perl Services - Site File Finder
$ENV{'SERVER_NAME'}

Finding:
Look in and below:
(Abs-path only)
Containing:
(No spaces)
File Extension: (Only if file searching)



~; if($FORM{action} eq 'process_search') { #Initialize the hashes. Yeah, yeah, expensive I know but that are part of the beauty and power of Perl dammit! my(%dirs, %dirs2beread, %dirs2bexfer, %files2bexfer); #Add the primary path to the hash of all directories $dirs{$FORM{search_in}} = 1; #Add the primary path to the list of directories to be parsed $dirs2beread{$FORM{search_in}} = 1; #Initialize to true the var which will tell the loop when to exit my $read_dirs = 1; #Start the loop while($read_dirs) { #Get a list of all the currently held directory paths not yet parsed my @dirkeys = sort keys %dirs2beread; #Shift the first directory from this list my $this_dir = shift(@dirkeys); #Remove this first directory from the hash so that it will not be in the list during #the next iteration through the loop delete $dirs2beread{$this_dir}; #Now get a list of everyting in this directory my @new = &readit($this_dir); #Now step through each every item that is in the directory currently being examined foreach(@new) { if(-d $_) { #If the item is a directory, add it to the hash of directories to be parsed #and add it to the list of direcotries to be created on remote server $dirs{$_} = 1; $dirs2beread{$_} = 1; } else { #If the item is a binary file, add it to the hash of binary files to be xfer'd $files2bexfer{$_} = 1; } } my @checkloop = keys %dirs2beread; unless((-d $checkloop[0]) && ($checkloop[0] =~ /[a-zA-Z1-9]/)) { $read_dirs = 0; } } #Print out the counts print qq~
Results of Search

~; #Finally, search everything if($FORM{finding} =~ /(d|a)/) { print "Directories Matching Search Request:



\n"; } if($FORM{finding} =~ /(f|a)/) { print "Files Matching Search Request:



\n"; } } print qq~


Perl Services - Site File Finder

© 2002, Perl Services

~; sub readit { my $path = shift; opendir(READ, $path); my @temp = readdir(READ); closedir READ; my @temp2; foreach(@temp) { unless(($_ eq '.') || ($_ eq '..')) { push(@temp2, "$path/$_"); } } return(@temp2); } sub Parse { my($name, $value, $buffer, $pair, $hold, @pairs); read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $name =~ s/\n//g; $name =~ s/\r//g; $value =~ s/\n//g; $value =~ s/\r//g; #This section checks the value portion (user input) of #all name/value pairs. $value =~ s/(<[^>]*>)//g; #Remove this tag to permit HTML tags $value =~ s/\|//g; $value =~ s///g; $value =~ s/\s-\w.+//g; $value =~ s/\0//g; $value =~ s/\|//g; $value =~ s/\\//g; $value =~ s/system\(.+//g; $value =~ s/grep//g; $value =~ s/\srm\s//g; $value =~ s/\srf\s//g; $value =~ s/\.\.([\/\:]|$)//g; $value =~ s/< *((SCRIPT)|(APPLET)|(EMBED))[^>]+>//ig; #This section checks the value portion (from element name) of #all name/value pairs. This was included to prevent any nasty #surprises from those who would hijack you forms! $name =~ s/(<[^>]*>)//g; $name =~ s///g; $name =~ s/\s-\w.+//g; $name =~ s/\0//g; $name =~ s/\|//g; $name =~ s/\\//g; $name =~ s/system\(.+//g; $name =~ s/grep//g; $name =~ s/\srm\s//g; $name =~ s/\srf\s//g; $name =~ s/\.\.([\/\:]|$)//g; $name =~ s/< *((SCRIPT)|(APPLET)|(EMBED))[^>]+>//ig; $FORM{$name} = $value; } }