分享
 
 
 

CGI搜索本站

王朝other·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

源代码:

#!/usr/bin/perl

#search.pl 2.02

#

#A simple script to search .html pages in a directory.

#written by webjx.com <web@webjx.com>

#June 10, 2004

#

#Please do not redistribute this script.

#

#Feel free to modify it as you wish, but if you do make any modifications, please

#submit them to me and I will give you credit in this section of the script.

#

#Thanks.

#

# DISCLAIMER: I AM IN NO WAY RESPONSIBLE FOR ANY DAMAGE THIS SCRIPT MAY CAUSE

#Configuration

#

#

# The base directory(absolute path) which contains all of the subdirectories you wish

# to search

#

# NOTICE HAS A TRAILING SLASH

#

#

# The url of a images

#

#

# The url onto which the subdirectories in @path are appended.

#

# Notice that INCLUDES THE TRAILING SLASH.

#

# For Example:

#

# If is /ROOT/LOCAL/USERS/ represented by =

http://yourhost.here/users/

# then JDOE's home directory would be /ROOT/LOCAL/USERS/JDOE/ and the link to all pages

# found in his directory which match the search string would be generated as

#http://yourhost.here/JDOE/page.html.

#

# The script simply assumes that the directory

# structure of your system matches the URL mapping of your server software.

# It just appends the user's home directory to .

#

#

# If user's home directories are called by,

# http://yourhost.here/~jdoe/ , for example, set it to '~';

# Pages containing the search string will be displayed with the "~" in place.

#

#

# If users have public_html as their home directories change this line to

#

# ='public_html/';

#

# the script will search /public_html/directory/path/

# rather than /directory/path/

#

#

# The extension for files to search(html or htm--Don't include the period)

#

#@filetypes

# Types of files that the script should search through(extensions).

#

#

# Valid URLs(HTTP Referers) that can search your site. For example, if your

# site ishttp://www.yoursite.com/you/and you want only your pages to have access

# to the script and search your directories, you could set

# to http://www.yoursite.com/you/ because all of your pages would have that part

# in common. If their in different directories, that will differ but the

#http://www.yoursite.com/you/will always be there in the HTTP referer.

#

#

# The name of the person who owns the site that the script will be used on

#

#

# The above person's email address.

#########

= '/home/httpd/';

=

http://linux.cqi.com.cn/~elvis/flame.gif';

='~'; #either '' or '~'

='public_html/'; #either '' or 'public_html/'

@filetypes=('html','txt','htm','shtml');

@valid=('linux.cqi.com.cn/~elvis/');

='Elvis Tam';

='elvis@126.com';

#########

#check if logon matches Referer URL

if({'HTTP_REFERER'} !~ /\/{ 'logon' }/)

{

print "Content-type: text/html\n\n";

print "<html>\n<title>错误</title>\n";

print "<body bgcolor=\"\#ffffff\" text=\"\#000000\">\n\n";

print "错误的username. 你只被允许搜索 <b>你自已的</b> 页面.\n";

print "</ul>\n<center><hr width=50%></center>\n</html>";

exit 0;

}

foreach (@valid)

{

if({'HTTP_REFERER'} =~ //)

{

="yes";

}

}

if( eq "")

{

if( ne "yes")

{

print "Content-type: text/html\n\n";

print "<title>请 离 开</title>";

print "<body bgcolor=\"\#ffffff\" text=\"\#000000\">";

print "你试图在地址窗口输入脚本的URL ";

print "或使用不合法的表单来访问它,两者都是不允许的.";

print "</html>\n";

exit 0;

}

}

##########

#Get form data

########

if( ne "")

{

@bern=('search1','search','type','insensitive','user','','paths','basedir;guestbook');

%formdata=@bern;

}

else

{

&get_form_data;

}

######

#Check search string to see if it's worth searching for.

########

if ({'search1'} eq "" | {'search1'} =~ /^ /)

{

print "Content-type: text/html\n\n";

print "<title>Error!</title>";

print "<body bgcolor=\"\#ffffff\" text=\"\#000000\">";

if ({'search1'} eq "")

{

print "你并没有输入任何字符.";

}

else

{

print "你输入的字符前面有空格.";

}

print '<p>';

print '请按"后退"的按钮回去再尝试.';

print "请联系系统管理员<a href=\"mailto:\"></a> ";

print "如果你需要进一步的援助.<p><br>";

print "</html>";

exit 0;

}

#############

#Make array of directories to search.

############

else

{

= {'logon'};

= {'baseurl'};

if({'paths'} =~ /\;/)

{

@temppaths=split("\;",{'paths'});

foreach (@temppaths)

{

if( eq "basedir")

{

push(@paths,"basedir");

}

else

{

push(@paths,"/"); #put a slash onto the end of the directory name

}

}

}

else

{

push(@paths,"basedir");

}

=0;

#@paths is an array containing the directories to search.(with trailing slashes)

#if user wants to search the base directory, the array also contains "basedir"

print "Content-type: text/html\n\n";

print "<title>搜索结果</title>\n";

print "<body bgcolor=\"\#ffffff\" text=\"\#000000\">\n";

print "<h1>搜索结果</h1>\n";

print "<p>\n";

print "你输入的关键字 <b>{'search1'}</b> 在本站的搜索结果如下\n";

print "<p>\n";

print "<hr><br>\n";

#Get list of all files of specified types

#in the specified directories.

foreach (@paths)

{

foreach (@filetypes)

{

if ( eq "") #if being used to search

{

if( ne "basedir")

{

opendir(DIR,".") || &error("");

}

else

{

opendir(DIR,".") || &error("");

}

}

else #if being used by a regular user

{

if( ne "basedir")

{

opendir(DIR,"/.") || &error("/");

}

else

{

opendir(DIR,"/.") || &error("/");

}

}

@nb=grep(/\.$/,readdir(DIR));

foreach (@nb)

{

if( eq "") #superuser

{

if( ne "basedir")

{

push(@names,"");

push(@URLS,"","");

}

else

{

push(@names,"");

push(@URLS,"","");

}

}

else #regular user

{

if( ne "basedir")

{

push(@names,"/");

push(@URLS,"/","");

}

else

{

push(@names,"/");

push(@URLS,"/","");

}

}

}

close(DIR);

}#go to the next file in the directory

}#go to the next directory and do it again.

#@URLS contains "file location","file url"

#@names contains "file location","file location2"...

#Make @URLs associative so we can call up the URL just by using

#the value int @names as the key.

%URLS = @URLS;

=@names;

= + ;

#Now you have a list of the eligible files in the all of the directories.

#Search each of them for the desired string. If you find it, remember

#the path and the name of the file and extract the title.

foreach (@names) #for each .html file in the array @names, do the following

{

="nothing";

open (HTML,"") || &error("");

@contents=<HTML>; #Read the contents into an array

close (HTML); #so that you can work with it and close it.

=join('',@contents);

=0; #Will be used to count no. of occurrences

if({'type'} eq "insensitive") #If search type is "case insenstitive"

{

++ while =~ /{'search1'}/gi;

if( != 0)

{

++;

}

}

else #if search type is "case-sensitive"

{

++ while =~ /{'search1'}/g;

if( != 0)

{

++;

}

}

if ( != 0) #if search string is found, print link to the page

{

if( =~ /htm.?$/i)

{

if ( =~ /title/)

{

@a=split(/title\>/,);

chop ;

chop ;

=;

}

elsif ( =~ /TITLE/)

{

@a=split(/TITLE\>/,);

chop ;

chop ;

=;

}

else

{

='NO TITLE';

}

}

else

{

='NO TITLE';

}

#print the HTML for the file

print "<br><img src=\"\" alt=\"[\*]\"><a href=\"{}\"></a>\( 处\)\n";

}

}#Go to the next file in the list.

if ( eq "0")

{

print "<center>没有发现任何包含关键字为 <b>{'search1'}</b> 的文件.</center>\n";

}

print "<hr><br>\n";

print "<p><b>被搜索的文件数:</b> \n";

print "<br><b>搜索类型:</b> case-{'type'}\n";

print "<br><br><center>\n本程式由 <a href=\"http://oh.yeah.net/\">Oh Yeah Net</a>编制<br></center>\n";

print "</html>\n";

}

exit 0;

################

#Subroutines

######

sub get_form_data{

@pairs=split(/\&/,{'QUERY_STRING'});

foreach (@pairs)

{

(,) = split(/\=/,);

=~ s/\+/ /g;

=~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

=~ s/~!/ ~!/g;

=~ s/\+/ /g;

=~ s/\r//g;

push (@formdata,);

push (@formdata,);

}

%formdata=@formdata;

return %formdata;

[1] [2] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有