perl ve cgi

Burak Demircan (burak.demircan@mbturk.mercedes-benz.com)
Mon, 03 Aug 1998 17:52:38 +0000


selam,
daha once de sorundan bahsettim fakat hala cozum bulamadim
webten
search.cgi yi calistirinca
---
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, root@wizard.mbturk.mercedes-benz.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

---
seklinde bir hata aliyorum
dosyaya erisememe gibi birsey soz konsu degil cunku haklari 755
zaten erisemediginde farkli bir hata veriyor

web server logu ise soyle

---- [Mon Aug 3 20:48:00 1998] [error] (2)No such file or directory: exec of /usr/local/apache/share/cgi-bin/search.cgi failed [Mon Aug 3 20:48:00 1998] [error] Premature end of script headers: /usr/local/apache/share/cgi-bin/search.cgi ---- ama dosya orada yok demesine rahmen ve script in icerigi de asagidaki gibi (perl gercekten ilk satirdaki yerde ve script icinde gecen dosyalar da bahsi gecen yerlerde yani onlarda da sorun yok)

birisi yardim ederse sevinirim delirtti beni bu perl saygi hormet

#!/usr/bin/perl

# ---------------------------------------------------------------------- # # search.cgi # # search engine script that can be set to search an entire site, but # exclude named directories, files, or files of a certain pattern. # # CGI Magic April 10th 1997 # # version 1.01 # # CHMOD this script 755 # # this script is an adaption of the work of Gunther Brznieks, and adds # various pretty bits plus the ability to run a single search engine # and setup script from one place on the site, accessing it from # individual html forms, each of which can "hide" local unwanted files # from view. # # as always, this script is given to you free to use for whatever purpose # you wish, with the request that you email us at # # users@spells.com # # to let us know the url where you are using it, so we may learn from your # adaptions. By using this script you absolve the authors and their agents # from all liability for any damage actual or consequential that may arise # from its use. # # ----------------------------------------------------------------------

# --- set the path to the library files

$lib = ".";

# --- require cgi-lib.pl

require "$lib/cgi-lib.pl";

# --- require the setup file

require "$lib/search.setup";

# --- define the default self-reference to this script

if ($search_script eq "") { $search_script = "search.cgi"; }

# --- get the essential cgi header from cgi-lib.pl

print &PrintHeader;

# --- use cgi-lib.pl to read and parse the incoming data

&ReadParse;

# --- set variables to incoming data values

$keywords = $in{'keywords'}; $exact_match = $in{'exact_match'}; $hidden_files = $in{'hidden_files'}; $user = $in{'user'}; $html_url = $in{'html_url'};

# --- the complete list of files that are NOT to be displayed in a search # --- is created by joining $hidden_files (data input) and $banned_files # --- as listed in the setup script

$unwanted_files = ($hidden_files . "|" . $banned_files);

# --- create an array called @unwanted_files by splitting incoming # --- keywords at the | delimiter

@unwanted_files = split(/\|+/,$unwanted_files);

# --- create an array called @keyword_list by splitting incoming # --- keywords at the word boundaries (\s+ splits on whitespace)

@keyword_list = split(/\s+/,$keywords);

# --- look at the incoming keywords, and if there are none, then output # --- a message telling the user that they must input one or more keywords

if ($keywords eq "") { &PrintNoKeywordMessage($user);

# --- exit the program to wait for a valid search form to be posted back

exit; }

# --- otherwise, if $keywords has keyword data, begin the search # --- for matching keywords. Use search.setup routines to print out the html

&PrintHeaderHTML($user);

# --- starting from $root_web_path, the search script looks down the whole # --- directory structure, parsing html files to find keywords, and also # --- to extract the page title for display if required.

# --- now set up some initial variables. @dirs is used as a placeholder to # --- make it possible to return up the directory tree when all branches # --- have been searched. $cur_dir is the current directory that we are # --- in, and is referenced to the @dirs array. Directory handles are # --- straight ASCII, made up from 'DIR'+$cur_dir.

$number_of_hits = 0; $cur_dir = 0; @dirs = ($root_web_path); opendir("DIR$cur_dir", $dirs[$cur_dir]);

$end_of_all_files = 0;

while (!($end_of_all_files)) {

# --- begin searching down to the next file level. If there are no more # --- files, then set $end_of_all_files to 1 to end the search process.

while (1) {

$filename = &GetNextEntry("DIR$cur_dir", $dirs[$cur_dir]); $fullpath = "$dirs[$cur_dir]/$filename";

# --- First situation: no more files, but still some directory paths to # --- check, so continue

if (!($filename) && $cur_dir > 0) { closedir("DIR$cur_dir"); $cur_dir--; next; }

# --- Second situation: no more files and no more directories, so end search

if (!($filename)) { closedir("DIR$cur_dir"); $end_of_all_files = 1; last; }

# --- Third situation: the file is a directory, so continue down through it # --- checking -d for directory, -r for read permission and -x for execute # --- permission

if (-d $fullpath) { if (-r $fullpath && -x $fullpath) { $cur_dir++; $dirs[$cur_dir] = $fullpath; opendir("DIR$cur_dir", $dirs[$cur_dir]); next; } else {

# --- otherwise if there are no read or execute permissions we continue down

next; } }

# --- Fourth situation: check to see whether the file is listed in the # --- unwanted file list. If it is, ignore it.

$unwanted_file = 0;

foreach (@unwanted_files) { if ($fullpath =~ /$_/) { $unwanted_file = 1; } }

if ($unwanted_file) { next; }

# --- Fifth situation: if we drop through to here, we have found a file # --- to search. Check that it is readable (-r).

if (-r $fullpath) { last; }

# --- and this is the end of the While (1) loop.

}

# --- now find the keywords we are looking for

if (!($end_of_all_files)) {

# --- make an array @not_found_words which contains the keywords from # --- @keyword_list. If @not_found_words is empty, then all keywords # --- have been found.

@not_found_words = @keyword_list; $are_we_in_head = 0;

open(SEARCHFILE, $fullpath);

$headline = "";

while(<SEARCHFILE>) { $line = $_; $headline .= $line if ($are_we_in_head == 0); $are_we_in_head = 1

if (($line =~ m!</head>!i) || ($line =~ m!</title>!i));

&FindKeywords($exact_match, $line, *not_found_words);

} # End of SEARCHFILE

close (SEARCHFILE);

if (@not_found_words < 1) {

# --- get the <title></title> information

$headline =~ s/\n/ /g; $headline =~ m!<title>(.*)</title>!i; $title = $1;

if ($title eq "") { $title = "This Page Has No Title"; }

$fullpath =~ s!$root_web_path/!!;

&PrintBodyHTML($fullpath, $title);

$number_of_hits++;

} } }

# --- if there are no keywords found, print appropriate message

if ($number_of_hits == 0) { &PrintNoHitsBodyHTML; }

# --- and print the page footer including the number of hits

&PrintFooterHTML($number_of_hits, $html_url);

# --- subroutine to find the keywords --------------------------------- sub FindKeywords { local($exact_match, $line, *not_found_words) = @_; local($x, $match_word);

if ($exact_match eq "on") { for ($x = @not_found_words; $x > 0; $x--) {

# --- \b matches on a word boundary $match_word = $not_found_words[$x - 1];

if ($line =~ /\b$match_word\b/i) { splice(@not_found_words,$x - 1, 1); } } } else {

for ($x = @not_found_words; $x > 0; $x--) { $match_word = $not_found_words[$x - 1];

if ($line =~ /$match_word/i) { splice(@not_found_words,$x - 1, 1); } } }

}

# --- subroutine to get the next entry -------------------------------- sub GetNextEntry { local($dirhandle, $directory) = @_;

while ($filename = readdir($dirhandle)) { if (($filename =~ /htm.?/i) || (!($filename =~ /^\.\.?$/) && -d "$directory/$filename")) { last; } }

# --- filename will be true if it is a directory or a filename

$filename;

}

# ---------------------------------------------------------------------