#!/usr/bin/perl
$| = 1;
require '/NOC1/hnagashi/script/www/CONFIG';
@pairs = split(/&/, <>);
#-----BACK COLOR CONFIGURATION ------
srand(time()^($$ +($$ <<15)));
$BGCOLOR=$BGC[int(rand(4))];
&get_str;
&header;
#print $ms;
#print "-------------------------------";
if($regist eq $write_pass){ ®ist_get; exit;};
if($regist ne ""){ ®ist_form; exit;};
# if($str1 eq ""){ print "String1 is NULL. Terminate This Program!\n"; exit;}
if($str1 eq ""){ &footer; exit;}
if($str2 eq ""){ if($and eq "and"){ $and="or"; }}
sub regist_get{
$ms=$ms."
".$link_name."
".
$link_url."
";
print $ms;
open(L1,"> ".$pdir."1"); print L1 $link_url; close L1;
open(L2,"> ".$pdir."link_name"); print L2 $link_name; close L2;
jcode'convert(*link_name,'euc');
open(L2,"> ".$pdir."link_name.euc"); print L2 $link_name; close L2;
}
sub regist_form{
open(L1,$pdir."link_name");
while(){ $l1=$l1.$_;}
close L1;
open(L2,$pdir."1");
while(){ $l2=$l2.$_;}
close L2;
if($regist eq $cfg_pass){
$ms=$ms."
".
"";
print $ms;
}
}
#-------------------------------
# STEP1 1st serch and "AND"
# STEP2 "OR"
# STEP3 Print POINT in file
#-------------------------------
$num=0; &step1; &step2;
#$sub=$sub."------".$infile."------";
&step3;
# print "$infile\n Number = $num\n";
# if($num ne 0){$ms=$ms.$num." Article Found!!\n";}
&footer;
#--------------------------------------------------------
sub footer{
if($num !=0){$ms=$ms."".$num." Article Found!!\n
";
}else{
if($str1.$str2.$str3 ne ""){
$ms=$ms."\n
";
}
}
# $ms=$ms."
";
&step_new;
$ms=$ms."".$where."
".$cred;
# jcode'convert(*ms,'euc');
jcode'convert(*ms,'sjis');
print $ms;
}
sub header{
$ms=$ms."Content-type: text/html\n\n".
"SEARCH".
"".
"SEARCH
".
"";
if($str1 ne ""){
$ms=$ms."[$str1]".
" $and [$str2]".
" $and2 [$str3]\n searching...";
}
}
sub step3{
open(MD,$cgi_dir."/m3");
while(){
($no,$class,$comp,$url)=split(/,/,$_);
# ($no,$class,$url)=split(/,/,$_);
$url_data[$no]=$class.",".$url;
# print "\n$no,$class,$url";
}
close MD;
open(LK,$cgi_dir."/link_name");
while(){
($no,$name)=split(/,/,$_);
$link_name[$no]=$name;
# print "\n$no,$class,$url";
}
close LK;
@fname=split(/,/,$infile);
for($i=0;$i<@fname;$i++){
($class,$url)=split(/,/,$url_data[$fname[$i]]);
$link=$link_name[$class]; jcode'convert(*link,'sjis');
$ms=$ms."\n". #"No.$fname[$i] | ".
"$link | ".
"$url |
";
}
}
sub step1{
$data1="grep -i -l $str1 $dir/*";
print "<<<<<<<<<<<<<<<<<<<$data1 >>>>>>>>>>>>>>>>>>>>>>";
while($file2=<`$data1`>){ $dum1=$dum1.$file2.",";}
$dum1=~s /$dir\///g; $_=$dum1;
#--------str2 serach----------
if($str2 ne ""){
$data2="grep -i -l $str2 $dir/*";
$dum2="";
while($file2=<`$data2`>){
$file2=~s /$dir\///g;
# print $file2." ";
if($and eq "or"){
if(!/$file2/){ $dum2=$dum2.$file2.",";}
}else{
if(/$file2/){ $dum2=$dum2.$file2.","; }
}
}
if($and eq "or"){ $infile=$dum2.$_; }else{ $infile=$dum2; }
}else{ $infile=$dum1;}
#--------str3 serach----------
$_=$infile; $dum1=$infile;
if($str3 ne ""){
$data2="grep -i -l $str3 $dir/*";
$dum2="";
while($file2=<`$data2`>){
$file2=~s /$dir\///g;
# print $file2." ";
if($and2 eq "or"){
if(!/$file2/){ $dum2=$dum2.$file2.",";}
}else{
if(/$file2/){ $dum2=$dum2.$file2.","; }
}
}
if($and2 eq "or"){ $infile=$dum2.$_; }else{ $infile=$dum2; }
}else{ $infile=$dum1;}
#---------search OK------
# print "-->>>".$infile."\n";
@n=split(/,/,$infile);
$num=@n;
}
sub step2{
}
sub step1_old{
#----------- 1st STEP
$data1="grep -i -l $str1 $dir/*";
while($file=<`$data1`>){
# $ms=$ms."$file
\n";
$flag=1;
if($and eq "and"){
$flag=0;
$comp="grep -i -l $str2 $file"; $com="";
while(<`$comp`>){
if(/$file/){ $flag=1;}
}
}
if($flag == 1){
$file=~s /$dir\///;
$infile=$infile."$file,"; $num++;
}
}
}
sub step2_old{
#----------- 2nd STEP
if($and ne "and"){
if($str2 ne ""){
$_=$infile;
$data1="grep -i -l $str2 $dir/*";
while($file=<`$data1`>){
$file=~s /$dir\///;
if(!/$file/){ $infile=$infile."$file,"; $num++;}
}
}
}
}
#--------------------------------
sub get_str {
# WWW Clientから渡された引数の展開
foreach $pair (@pairs) {
($name,$value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# &jcode'convert(*value,'euc');
$FORM{$name} = $value;
}
# 引数の表示
for (keys %FORM) {
# print "$_, $FORM{$_}
\n";
}
# 個々の引数の格納
$str1 = $FORM{'str1'};
$str2 = $FORM{'str2'};
$str3 = $FORM{'str3'};
$and = $FORM{'and'};
$and2 = $FORM{'and2'};
$regist = $FORM{'regist'};
$link_url = $FORM{'link_url'};
$link_name = $FORM{'link_name'};
# $str1="drg";
# $str2="pps";
# $str3="pps";
# $and="or";
# $and2="and";
&jcode'h2z_sjis(*str1);
&jcode'h2z_sjis(*str2);
&jcode'h2z_sjis(*str3);
&jcode'convert(*str1,'jis');
&jcode'tr(*str1,'0123456789','0123456789');
&jcode'tr(*str1,'abcdefghijklmnopqrstuvwxyz!@#$%^&*','abcdefghijklmnopqrstuvwxyz!@#$%^&*');
&jcode'tr(*str1,'ABCDEFGHIJKLMNOPQRSTUVWXYZ<>?/;”()「」{}|+=−_〜','ABCDEFGHIJKLMNOPQRSTUVWXYZ<>?/;"()[]{}|+=-_~');
&jcode'convert(*str1,'sjis');
&jcode'convert(*str2,'jis');
&jcode'tr(*str2,'0123456789','0123456789');
&jcode'tr(*str2,'abcdefghijklmnopqrstuvwxyz!@#$%^&*','abcdefghijklmnopqrstuvwxyz!@#$%^&*');
&jcode'tr(*str2,'ABCDEFGHIJKLMNOPQRSTUVWXYZ<>?/;”()「」{}|+=−_〜','ABCDEFGHIJKLMNOPQRSTUVWXYZ<>?/;"()[]{}|+=-_~');
&jcode'convert(*str2,'sjis');
&jcode'convert(*str3,'jis');
&jcode'tr(*str3,'0123456789','0123456789');
&jcode'tr(*str3,'abcdefghijklmnopqrstuvwxyz!@#$%^&*','abcdefghijklmnopqrstuvwxyz!@#$%^&*');
&jcode'tr(*str3,'ABCDEFGHIJKLMNOPQRSTUVWXYZ<>?/;”()「」{}|+=−_〜','ABCDEFGHIJKLMNOPQRSTUVWXYZ<>?/;"()[]{}|+=-_~');
&jcode'convert(*str3,'sjis');
$sstr1=$str1; &jcode'convert(*sstr1,'euc');
$sstr2=$str2; &jcode'convert(*sstr2,'euc');
$sstr3=$str3; &jcode'convert(*sstr3,'euc');
$log=$ENV{REMOTE_ADDR}."(". $ENV{REMOTE_HOST}.")".
" --->[ ".$sstr1." ] ".$and." [ ".$sstr2." ] ".$and2." [ ".$sstr3." ]\n";
open(SEC,">> ".$pdir."log"); print SEC $log; close SEC;
}
#---------------------------------
sub step_new{
if($and eq "or"){ $andsub="and"; }else{ $and="and";$andsub="or";}
if($and2 eq "or"){$andsub2="and"; }else{$and2="and"; $andsub2="or";}
$inform = <<"EOF";
EOF
#
open(SS,$pdir."mes.1");
while(){ $sub=$sub.$_; }
$sub=~s//