HI,
ich hab hier eine Suchmaschine bei der man die "Base Dir" über das Formular angeben muss. Da kann dann aber jeder diese einsehen. Kann ich das auch in dem Script selbst festlegen?
Und über das Formular kommt das dazu:
<input type="hidden" name="base" value="/home/etc/">
Kann mir da vielleicht jemand helfen, dass so umzuschreiben, dass die Variable im Script selbst drin ist?
Danke!!!
ich hab hier eine Suchmaschine bei der man die "Base Dir" über das Formular angeben muss. Da kann dann aber jeder diese einsehen. Kann ich das auch in dem Script selbst festlegen?
Code:
#!/usr/bin/perl
my($version) = "1.1m";
my($incSub);
#############################################################################
# jasearch.pl - Simple search script - Version 1.1a - Released 18/02/97
#
# requires 4 paramaters from form
#
# 'sv' = search value
# 'base' = base directory to search
# 'rbase' = returned base
#
# optionals
#
# 'background' = gif to display as background
# 'text' = text colour
# 'link' = colour of links
# 'alink' = colour of active link
# 'vlink' = colour of visited links
# 'bgcolor' = colour of background
# 'log' = log file
#
# base = /home/jason & rbase = [url]http://www.ufbs.co.uk[/url]
#
# /home/jason/jason.html would be [url]http://www.ufbs.co.uk/jason.html[/url]
#
# This script is Copyright 1997 Jason Anthony, [email]janthony@ufbs.co.uk[/email]
#############################################################################
&readForm;
if (lc($FORM{'mode'}) eq 'help') {
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>Search Help</TITLE></HEAD>\n";
print "<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\" LINK=\"#FF0000\" ALINK=\"#00FF00\" VLINK=\"#0000FF\">\n";
print "<CENTER><H2>Search Help</H2></CENTER><P>\n";
print "The default search is to select any pages which include any of the search keywords you enter. You can overide this behaviour by ";
print "preceding the keywords with special characters.<P>\n";
print "<UL>\n";
print "<LI>If the keyword starts with <STRONG>+</STRONG> then that keyword must appear in the page.\n";
print "<LI>If the keyword starts with <STRONG>-</STRONG> then that keyword must not exist on the page.\n";
print "<LI>If you want to match an exact string include "quotation" marks around the keywords that make up that string.\n";
print "</UL><P>\n";
print "<STRONG>Examples:</STRONG>\n";
print "<UL>\n";
print "<LI>To search for stars in the sky you could use <EM>+stars -movie</EM> this would select pages that include the word stars but not those pages that contain the word movie.";
print "<LI>To search for movie stars you could use <EM>+movie +stars</EM> as this search would only include pages with both keywords.";
print "<LI>To search for a name you could use <EM>"John Smith"</EM> as this would require the exact string to be present.";
print "</UL>\n";
print "<P>\n";
print "<HR><CENTER>\n";
print "Press BACK to return to previous page.\n";
print "</CENTER><HR>\n";
print "<P>For more information email <A HREF=\"mailto:jason\@ufbs.co.uk\">jason\@ufbs.co.uk</A>\n";
print "<BR>This page is © 1999 Jason Anthony\n";
print "</BODY></HTML>\n";
exit;
}
$listdirs = 0;
if ($FORM{'dirs'} ne "") {
@directories = split(/;/,$FORM{'dirs'});
$listdir = 1;
$FORM{'subdir'} = "no";
}
$excdirs = 0;
if ($FORM{'excdirs'} ne "") {
@excpaths = split(/;/,$FORM{'excdirs'});
$excdirs = 1;
}
$incSub = 1;
if (lc($FORM{'subdir'}) eq "no") { $incSub = 0; }
&printHtmlTop;
if ($listdir > 0) {
foreach $dir (@directories) {
&checkFiles($FORM{'base'}."$dir");
}
} else {
&checkFiles($FORM{'base'});
}
&printHtmlBottom;
sub printHtmlTop {
# prints top part of html file, upto the list of files.....
if ($FORM{'log'} ne "") { doLog(); }
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>Search Results</TITLE></HEAD>\n";
print "<BODY";
$body = "";
if ($FORM{'background'} ne "") { $body = "$body BACKGROUND=\"$FORM{'background'}\" "; }
if ($FORM{'bgcolor'} ne "") { $body = "$body BGCOLOR=\"$FORM{'bgcolor'}\" "; }
if ($FORM{'text'} ne "") { $body = "$body TEXT=\"$FORM{'text'}\" "; }
if ($FORM{'link'} ne "") { $body = "$body LINK=\"$FORM{'link'}\" "; }
if ($FORM{'alink'} ne "") { $body = "$body ALINK=\"$FORM{'alink'}\" "; }
if ($FORM{'vlink'} ne "") { $body = "$body VLINK=\"$FORM{'vlink'}\" "; }
if ($body eq "") { $body = " BGCOLOR=\"#FFFFFF\""; }
print "$body>\n";
print "<CENTER><FONT SIZE=\"6\"><STRONG>Search Results</STRONG></FONT></CENTER><HR><P>\n";
&printFormCode;
print "<P>Results are not returned in any specific order:<P>\n";
print "<DL>\n";
}
sub printHtmlBottom {
# prints last part of html file after list of files....
print "</DL>\n";
if ($numberreturned == 0) {
print "<H2>Sorry no matches found!</H2>\n";
} else {
print "<P>Found $numberreturned match";
if (!($numberreturned == 1)) { print "es"; };
print "\n";
}
print "<P><HR><CENTER>jasearch.pl V$version<BR>© Copyright ";
print "<A HREF=\"http://www.ufbs.co.uk/jason/\">Jason Anthony</A> 1997.</CENTER>\n";
print "</BODY>\n</HTML>\n";
}
sub readForm {
# reads data pairs from form
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if ($buffer eq "") { $buffer = $ENV{'QUERY_STRING'}; }
@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;
$FORM{lc($name)} = $value;
if (lc($name) eq 'sv') {
$input = $value;
}
}
$FORM{'sv'} =~ s!\*!!ge;
$FORM{'sv'} =~ s!\?!!ge;
$input =~ s!\?!!ge;
$input =~ s!\*!!ge;
# extract terms from $FORM{'sv'}
while ($input =~ m/\+"(.+?)"/ig) {
if($1 ne "") { push(@sereqd,$1); }
}
$input =~ s/\+"(.+?)"//se;
while ($input =~ m/\-"(.+?)"/ig) {
if ($1 ne "") { push(@senotr,$1); }
}
$input =~ s/\-"(.+?)"//se;
while ($input =~ m/"(.+?)"/ig) {
if ($1 ne "") { push(@seany,$1); }
}
$input =~ s/"(.+?)"//se;
@sv = split( / /,$input);
foreach $sv (@sv) {
if ($sv ne "") {
if (substr($sv,0,1) eq '+') {
push(@sereqd,substr($sv,1));
} elsif (substr($sv,0,1) eq '-') {
push(@senotr,substr($sv,1));
} else {
push(@seany,$sv);
}
}
}
$reqd = @sereqd;
$notr = @senotr;
my($numberreturned) = 0;
}
sub checkFiles {
# read files in directory, passed as first paramater
my($path) = shift;
my($fullFilename);
my(@files);
my(@lines);
my($line);
my($title);
opendir(ROOT,$path);
@files = readdir(ROOT);
closedir(ROOT);
foreach (@files) {
next if /^\.|\.\.$/;
if ($_ =~ m/_vti_cnf/i) { next; }
$fullFilename = "$path/$_";
if (-d $fullFilename) {
if ($incSub > 0) {
$ok2dosub = 1;
if ($excdirs > 0) {
$tmp = $fullFilename;
$tmp =~ s/$FORM{'base'}//;
foreach $tpath (@excpaths) {
if ($tmp eq $tpath) { $ok2dosub = 0; }
}
}
if ($ok2dosub > 0) { checkFiles($fullFilename); }
}
next;
}
if ($fullFilename =~ m/\.htm/i || $fullFilename =~ m/\.sht/i) {
open(FILE, $fullFilename);
@lines = <FILE>;
close(FILE);
$line = join(' ',@lines);
$line =~ s/\n//g;
$title = "No Title";
if($line =~ m!<title>(.+)</title>!i) {
$title = $1;
};
if ($reqd > 0) {
$found = 1;
foreach $se (@sereqd) {
if ($line !~ m/$se/i) { $found = 0; }
}
} else {
$found = 0;
foreach $se (@seany) {
if ($line =~ m/$se/i) { $found = 1; }
}
}
if ($notr > 0) {
foreach $se (@senotr) {
if ($line =~ m/$se/i) { $found = 0;}
}
}
if ($line =~ m!NOSEARCH!i) {
$found = 0;
}
if ($found == 1 ) {
$meta="";
if ($line =~ m!<meta\s*name="description"\s*content="(.+?)">!i) {
$meta = $1;
}
if ($line =~ m!<meta\s*content="(.+?)"\s*name="description">!i) {
$meta = $1;
}
$namereq = '';
$foundfirst = 0;
foreach $line (@lines) {
if ($line =~ m/\<a name=/i) {
if ($foundfirst < 1) {
if($line =~ m!<a\s*name="(.+)"!i) {
$namereq = $1;
};
}
}
foreach $se (@search) {
if ($line =~ m/$se/i) {
$foundfirst = 1;
}
}
}
$tmp = $fullFilename;
$tmp =~ s/$FORM{'base'}//;
$tmp = "$FORM{'rbase'}$tmp";
if ($namereq ne "") { $tmp = $tmp . "#$namereq"};
$numberreturned++;
print "<DT><STRONG>$numberreturned.</STRONG> <a href=\"$tmp\">$title</a></DT>\n";
if ($meta ne "") {
@meta = split(' ',$meta);
$meta = "";
for($n=0;$n<24;$n++) {
$meta = $meta . @meta[$n] . " ";
}
while( substr($meta,0,1) eq " ") { $meta = substr($meta,1); }
while( substr($meta,-1) eq " ") { $meta = substr($meta,0,-1); }
print "<DD>$meta ...</DD>\n";
}
print "<P>\n";
}
}
}
}
sub doLog {
#write details of use to log file
my($site);
$site = $ENV{'REMOTE_HOST'};
if ($site eq "") { $site = $ENV{'REMOTE_ADDR'}; }
if (!(-e "$FORM{'log'}" )) {
open( OUTFILE,">$FORM{'log'}") or return;
print OUTFILE "\"searh value\",\"search type\",\"time\",\"remote site\"\n";
close(OUTFILE);
}
open( OUTFILE,">>$FORM{'log'}") or return;
print OUTFILE "\"$FORM{'sv'}\",\"$FORM{'type'}\",\"" . localtime() . "\",\"$site\"\n";
close( OUTFILE );
}
sub printFormCode {
print "<FORM METHOD=\"post\" ACTION=\"$ENV{'SCRIPT_NAME'}\">\n";
print "<INPUT TYPE=\"hidden\" NAME=\"base\" VALUE=\"$FORM{'base'}\">\n";
print "<INPUT TYPE=\"hidden\" NAME=\"rbase\" VALUE=\"$FORM{'rbase'}\">\n";
if ($FORM{'background'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"background\" VALUE=\"$FORM{'background'}\">\n"; }
if ($FORM{'bgcolor'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"bgcolor\" VALUE=\"$FORM{'bgcolor'}\">\n"; }
if ($FORM{'text'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"text\" VALUE=\"$FORM{'text'}\">\n"; }
if ($FORM{'link'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"link\" VALUE=\"$FORM{'link'}\">\n"; }
if ($FORM{'alink'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"alink\" VALUE=\"$FORM{'alink'}\">\n"; }
if ($FORM{'vlink'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"vlink\" VALUE=\"$FORM{'vlink'}\">\n"; }
if ($FORM{'log'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"log\" VALUE=\"$FORM{'log'}\">\n"; }
if ($FORM{'dirs'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"dirs\" VALUE=\"$FORM{'dirs'}\">\n"; }
if ($FORM{'excdirs'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"excdirs\" VALUE=\"$FORM{'excdirs'}\">\n"; }
if ($FORM{'subdir'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"subdir\" VALUE=\"$FORM{'subdir'}\">\n"; }
print "Search for ";
print "<INPUT TYPE=\"text\" NAME=\"sv\" VALUE=\"$FORM{'sv'}\">\n";
print "<INPUT TYPE=\"submit\" VALUE=\"Search\">\n";
print "<INPUT TYPE=\"reset\" VALUE=\"Reset\">\n";
print "<SMALL><A HREF=\"$ENV{'SCRIPT_NAME'}?mode=help\">help</A></SMALL>\n";
print "</FORM>\n";
}
Und über das Formular kommt das dazu:
<input type="hidden" name="base" value="/home/etc/">
Kann mir da vielleicht jemand helfen, dass so umzuschreiben, dass die Variable im Script selbst drin ist?
Danke!!!