home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2007 April / PCpro_2007_04.ISO / files / dsl / NVinst.exe / Scripts / HTTP / DefaultHost / NetSearch / index.php < prev    next >
Encoding:
PHP Script  |  2007-02-10  |  7.1 KB  |  184 lines

  1. <?php
  2.     setlocale(LC_ALL,"ru_RU.CP1251");
  3.     $VERSION="1.4";
  4.         $DIR="..\\..\\..\\";//─Φ≡σΩ≥ε≡Φ , πΣσ φα⌡εΣ ≥±  Γ±σ φ≤µφ√σ ⌠αΘδ√, \NetView\Scripts
  5.     $FLISTNAME_ONLINE=$DIR."Online.Searcher_HTTP_State.FileList.txt";
  6.         $FLISTNAME_ALL=$DIR."All.Searcher_HTTP_State.FileList.txt";
  7.     $FCNTNAME=$DIR."counter.txt";
  8.     $FLOGNAME=$DIR."log.txt";
  9.     $SIZEUNIT=1000000;
  10.     $query=""; $type=""; $mode=""; $minsize=""; $maxsize=""; $hosts="";$online="";
  11.     $minsizestr=""; $maxsizestr=""; $invtitle=""; $modestr="";
  12.     if (isset($_GET['query'])) $query=$_GET['query'];
  13.     if (isset($_GET['type'])) $type=$_GET['type'];
  14.     if (isset($_GET['mode'])) $mode=$_GET['mode'];
  15.     if (isset($_GET['minsize'])) $minsize=$_GET['minsize'];
  16.     if (isset($_GET['maxsize'])) $maxsize=$_GET['maxsize'];
  17.     if (isset($_GET['hosts'])) $hosts=$_GET['hosts'];
  18.         if (isset($_GET['online'])) $online=$_GET['online'];
  19.     $querystr=str_replace("\\\"","\"",$query);
  20.         $types[0]="";$types[1]="";$types[2]="";
  21.     switch ($type){
  22.         case "files": $types[1]="selected"; break;
  23.         case "dirs": $types[2]="selected"; break;
  24.         default: $types[0]="selected"; break;
  25.     }
  26.     $cntstr=file($FCNTNAME);
  27.     $counter=$cntstr[0];
  28.     if ($mode=="invisible"){
  29.         $invtitle=" (±Ω≡√≥√Θ ≡σµΦ∞)";
  30.         $modestr="?mode=invisible";
  31.     }
  32.     else
  33.         if (isset($_GET['query'])) $counter++;
  34.     if ($minsize>0) $minsizestr=$minsize;
  35.     if ($maxsize>0) $maxsizestr=$maxsize;
  36.  
  37. function num_format($num){
  38.     return number_format($num,0,',',' ');
  39. }
  40.  
  41. function query_parse($query){            //╧≡σΣΓα≡Φ≥σδⁿφα  εß≡αßε≥Ωα τα∩≡ε±α
  42.     $regexp=preg_quote($query);            //╧≡σεß≡ατεΓαφΦσ Ω ≡σπ≤δ ≡φε∞≤ Γ√≡αµσφΦ■
  43.     $regexp=str_replace("\\\\\"","",$regexp);
  44.     $regexp=str_replace("/","",$regexp);
  45.     $regexp=str_replace("\\*",".*",$regexp);
  46.     $regexp=str_replace(" ",".*",$regexp);
  47.     while (substr($regexp,0,2)==".*")    //╙ΣαδσφΦσ φστφα≈α∙Φ⌡ * Φ ∩≡εßσδεΓ Γ φα≈αδσ Φ Ωεφ÷σ τα∩≡ε±α
  48.         $regexp=substr($regexp,2);
  49.     while (substr($regexp,strlen($regexp)-2)==".*")
  50.         $regexp=substr($regexp,0,strlen($regexp)-2);
  51.     return "/".$regexp."/i";
  52. }
  53.  
  54. function name_highlight($str,$matches){    //┬√ΣσδσφΦσ ÷Γσ≥ε∞ ±εΓ∩αΓ°σΘ ≈α±≥Φ
  55.     $pos=$matches[0][1];
  56.     $matchlen=strlen($matches[0][0]);
  57.     return substr($str,0,$pos)."<font color='green'>".$matches[0][0]."</font>".substr($str,$pos+$matchlen);
  58. }
  59. ?>
  60. <head>
  61.     <title>╧εΦ±ΩεΓα  ±Φ±≥σ∞α ╠√φΣσΩ±<?php print $invtitle;?></title>
  62.     <link rel='stylesheet' type='text/css' href='styles.css'>
  63. </head>
  64. <html>
  65.  
  66. <form action='' method='get' align='center'>
  67. <?php
  68.     if ($mode=="invisible")
  69.         print "<input type=hidden name='mode' value='invisible'>";
  70. ?>
  71.     <table cellpadding=0 cellspacing=0 align='center'>
  72.     <tr><td width=130 valign='center'><img src='logo.gif'>
  73.  
  74.     <td><table cellpadding=0>
  75.     <tr><td><input type=text name='query' size=40 value='<?php print $querystr;?>'>
  76.     <td><select name='type'>
  77. <?php
  78.     print "<option value='both' $types[0]>╘αΘδ√ Φ ΣΦ≡σΩ≥ε≡ΦΦ</option>";
  79.     print "<option value='files' $types[1]>╘αΘδ√</option>";
  80.     print "<option value='dirs' $types[2]>─Φ≡σΩ≥ε≡ΦΦ</option>";
  81. ?>
  82.     </select>
  83.     <input type=submit value='═αΘ≥Φ!'>
  84.     <tr><td><font class='itext'>╨ατ∞σ≡:</font>
  85.     ε≥ <input type=text name='minsize' size=5 value='<?php print $minsizestr;?>'>
  86.     Σε <input type=text name='maxsize' size=5 value='<?php print $maxsizestr;?>'> ╠┴
  87.     <td>
  88.  
  89. <p style="text-indent: 0; word-spacing: 0; line-height: 100%; margin: 0"><input type="checkbox" name="online" value="on"<?php if ($online=="on") print "checked";?>>╥εδⁿΩε ΓΩδ■≈σφφ√σ Ωε∞∩ⁿ■≥σ≡√
  90.  
  91.         <p style="text-indent: 0; word-spacing: 0; line-height: 100%; margin: 0"><font class='itext'>╩ε∞∩ⁿ■≥σ≡:</font><input type=text name='hosts' size=15 value='<?php print $hosts;?>'>
  92.     </table>
  93.  
  94.     </table>
  95. </form>
  96.  
  97. <table cellpadding=0 cellspacing=0 width='100%'>
  98. <tr>
  99. <td class='smalltext' align='left' width='20%'><b><a href='../'>─≡≤πΦσ ±σ≡ΓΦ±√</a></b>
  100. <td class='smalltext' align='center' width='20%'><a href='help.php<?php print $modestr;?>'>╩αΩ ≡αßε≥ασ≥ ∩εΦ±Ω?</a>
  101. <td class='smalltext' align='center' width='30%'>╬ß≡αßε≥αφε <a href='stats.php<?php print $modestr;?>'>τα∩≡ε±εΓ</a>: <b><?php print $counter;?></b>
  102. <td class='smalltext' align='right' width='30%'><i><b>╠√φΣσΩc <?php print $VERSION;?></b> (±) <a href='mailto:artus@mail.ru'>AlexeyPetrov</a>, 2004</i>
  103. </table>
  104.  
  105. <?php
  106.     if (!isset($_GET['query'])) exit();
  107. ?>
  108. <hr>
  109. <table align='center' border=1 cellpadding=1 cellspacing=0 width='100%'>
  110.     <tr class='caption'><td>#<td>╧≤≥ⁿ<td>╚∞ <td width=75>╨ατ∞σ≡<td width=90>╧≡εΓσ≡σφ
  111. <?php
  112.     list($microtime,$time)=explode(" ",microtime());
  113.  
  114.     $regquery=query_parse($query);
  115.     $reghosts=query_parse($hosts);
  116.     if ($online=="on")$fdata=fopen($FLISTNAME_ONLINE,"r");
  117.                  else $fdata=fopen($FLISTNAME_ALL,"r");
  118.  
  119.     $basesize=0;
  120.     for ($num=0,$resnum=0; ($str=fgets($fdata))!=FALSE; $num++){
  121.         list($hostip,$hostname,$path,$name,$size,$ident,$found,$confirm)=explode("|",$str);
  122.         if ($size!=-1) $basesize+=$size;
  123.         //╧≡εΓσ≡Ωα φα ±εε≥Γσ≥±≥ΓΦσ τα∩≡ε±≤ Φ∞σφΦ/∩α≡α∞σ≥≡εΓ ⌠αΘδα/ΣΦ≡σΩ≥ε≡ΦΦ
  124.         if (!preg_match($regquery,$name,$qmatches,PREG_OFFSET_CAPTURE)) continue;
  125.         if ($size==-1){
  126.             if ($type=="files") continue;
  127.             $class="boldrow";
  128.             $sizestr="─Φ≡σΩ≥ε≡Φ ";
  129.             $targetstr="target='_blank'";
  130.         }
  131.         else{
  132.             if ($type=="dirs" || $size<$minsize*$SIZEUNIT || $maxsize>0 && $size>$maxsize*$SIZEUNIT) continue;
  133.             $class="row";
  134.             $sizestr=num_format($size);
  135.             $targetstr="";
  136.         }
  137.  
  138.         //╧≡εΓσ≡Ωα φα ±εε≥Γσ≥±≥ΓΦσ τα∩≡ε±≤ Φ∞σφΦ/αΣ≡σ±α Ωε∞∩ⁿ■≥σ≡α
  139.         if (preg_match($reghosts,$hostip,$hipmatches,PREG_OFFSET_CAPTURE))
  140.             $hostnamestr=name_highlight($hostip,$hipmatches);
  141.         else
  142.             if (preg_match($reghosts,$hostname,$hnmatches,PREG_OFFSET_CAPTURE))
  143.                 $hostnamestr=name_highlight($hostname,$hnmatches);
  144.             else continue;
  145.         if (substr($path,0,2)=="\\\\") $path="file:".str_replace("\\","/",$path);
  146.         $pathstr=str_replace($hostip,$hostnamestr,$path);
  147.  
  148.         $namestr=name_highlight($name,$qmatches);
  149.         $resnum++;
  150.         print "<tr class='$class'>";
  151.         print "<td>$resnum ";
  152.         print "<td><a href='$path' target='_blank'>$pathstr</a>";
  153.         print "<td><a href='$path$name' $targetstr>$namestr</a>";
  154.         print "<td>$sizestr";
  155.         print "<td align='center'>$confirm";
  156.     }
  157.     print "</table>";
  158.     fclose($fdata);
  159.  
  160.     list($end_microtime,$end_time)=explode(" ",microtime());
  161.     $duration = (float)$end_time - (float)$time + (float)$end_microtime - (float)$microtime;
  162.     $numstr=num_format($num);
  163.     $basesizestr=num_format($basesize/$SIZEUNIT);
  164.     print "<table width='100%'><tr class='smalltext'>";
  165.     printf ("<td width='50%%' align='center'>┬≡σ∞  Γ√∩εδφσφΦ : <b>%.2f ±σΩ.</b>",$duration);
  166.     print "<td width='50%' align='center'>╩εδΦ≈σ±≥Γε ⌠αΘδεΓ Γ ßατσ: <b>$numstr (<i>$basesizestr ╠┴</i>)</b>";
  167.     print "</table>";
  168.  
  169.     //╟α∩Φ±ⁿ τα∩≡ε±α Γ δεπ-⌠αΘδ ∩≡Φ "εß√≈φε∞" ≡σµΦ∞σ ∩εΦ±Ωα
  170.     if ($mode!="invisible"){
  171.         $fcounter=fopen($FCNTNAME,"w");
  172.         fputs($fcounter,$counter);
  173.         fclose($fcounter);
  174.  
  175.         $flog=fopen($FLOGNAME,"a");
  176.         $date=date("Y-m-d H:i:s");
  177.         $ip=getenv("REMOTE_ADDR");;
  178.         $host=gethostbyaddr($ip);
  179.         $logstr=sprintf("%d|%s|%s|%s|%s|%s|%d|%d|%s|%d|%.2f|%d|%d\n",$counter,$date,$ip,$host,$querystr,$type,$minsize,$maxsize,$hosts,$resnum,$duration,$num,$basesize/$SIZEUNIT);
  180.         fputs($flog,$logstr);
  181.         fclose($flog);
  182.     }
  183. ?>
  184.