|
<? Php
If ($ _ POST ['submit '] = 'start '){
$ Total = 0; // total number of files
$ Dangerous = array (); // dangerous File
$ Dangerous_content =$ _ POST ["sstr"];
$ Find_path = $ _ POST ["searchpath"];
$ Shortname = $ _ POST ["shortname"];
Echo "<! DOCTYPE html PUBLIC '-// W3C // dtd xhtml 1.0 Transitional // en' 'HTTP: // www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> ";
Echo "
Echo "
Echo "<meta http-equiv = 'content-type' Content = 'text/html; charset = UTF-8 '/> ";
Echo "
Echo "<body> ";
$ Begin_time = date ("U ");
// $ Dangerous_content = "xiaoliang, Root_GP, Root_CSS, c99sh_updateurl, c99sh_sourcesurl, 640684770 ";
VisitFile ($ find_path, $ shortname );
$ End_time = date ("U ");
Foreach ($ dangerous as $ d ){
Echo $ d. "<br/> ";
}
Echo "total number of files:". $ total. "dangerous files:". count ($ dangerous). "total time". ($ end_time-$ begin_time). "seconds ";
Echo "</body> ";
Echo "
// If (! Empty ($ dangerous )){
// Foreach ($ dangerous as $ dan ){
// Echo "[error]". $ dan. "<br/> ";
//}
//}
Exit ();
}
Function visitFile ($ path, $ ext ){
Global $ total;
Global $ dangerous_content;
$ Fdir = dir ($ path );
// Echo "Handle:". $ d-> handle. "<br> ";
// Echo "Path:". $ fdir-> path. "<br> ";
Set_time_limit (24*60*60 );
While ($ entry = $ fdir-> read ())! = False ){
$ PathSub = $ path. "\". $ entry;
If ($ entry! = '.' & $ Entry! = '..'){
If (is_dir ($ pathSub )){
VisitFile ($ pathSub, $ ext );
} Else {
$ Exten = explode ('.', $ entry );
$ Exten = array_reverse ($ exten); // returns the reverse order of the preceding array.
// Foreach ()
$ Shortnames = explode ('|', $ ext );
Foreach ($ shortnames as $ sn ){
If (! Empty ($ exten) & $ sn =$ exten [0]) {
$ Total = $ total + 1;
// Echo "Start analysis file:". $ path. "/". $ entry. "<br> ";
$ Content = file_get_contents ($ path. "/". $ entry); // High Performance
$ Content = strtolower ($ content); // convert all to lowercase letters
$ Dangerous_content = strtolower ($ dangerous_content); // convert all to lower case
IsExists ($ dangerous_content, $ path. "/". $ entry, $ content); // This method is too memory-consuming. I hope some experts can solve this problem.
}
}
// Sleep (1 );
}
}
}
$ Fdir-> close ();
}
Function isExists ($ str, $ filename, $ content ){
Global $ dangerous;
// Sleep (1 );
Set_time_limit (10 );
$ Arr = explode (',', $ str );
$ Signature = "signature :";
If (! Empty ($ arr )){
// $ Content = file_get_contents ($ filename); // This has good performance.
$ Content = strtolower ($ content); // convert all to lowercase letters
$ Error_count = 0;
Foreach ($ arr as $ ){
If (trim ($ )! = ""){
If (strpos ($ content, $ )){
$ Error_count = $ error_count + 1;
$ Signature. = $ ."";
}
}
}
If ($ error_count> 0 ){
// $ Dangerous [] = $ filename;
$ Dangerous [] = "[error]". $ error_count. "". $ signature. "". $ filename;
// Echo "[error]". $ error_count. "". $ signature. "". $ filename. "<br/> ";
} Else {
// Echo "[OK]". $ filename. "<br/> ";
}
}
}
?>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> Query files in batches </title>
<Style type = "text/css">
Body {
Background: # FFFFFF;
Color: #000;
Font-size: 12px;
}
# Top {
Text-align: center;
}
H1, p, form {
Margin: 0;
Padding: 0;
}
H1 {font-size; 14px;
}
</Style>
</Head>
<Body>
<Div id = "top">
<H1> batch search program
<Div> This program can scan all the files in the specified directory and perform <strong> Content Search </strong>. <Br/>
When the number of files is very large, this operation occupies server resources. Make sure that the script time-out period can be changed. Otherwise, the operation may fail. </Div>
</Div>
<Form action = "<? = $ _ SERVER ['script _ name']?> "Name =" form1"
Target = "stafrm" method = "post">
<Table width = "95%" border = "0" align = "center" cellpadding = "3"
Cellspacing = "1" bgcolor = "#666666">
<Tr>
<Td width = "10%" bgcolor = "# FFFFFF"> <strong> & nbsp; Start root path: </strong> </td>
<Td width = "90%" bgcolor = "# FFFFFF"> <input name = "searchpath" type = "text"
Id = "searchpath" value = "D:/" size = "20"/> click to indicate the current directory. Do not add/at the end. </td>
</Tr>
<Tr>
<Td bgcolor = "# FFFFFF"> <strong> & nbsp; File Extension: </strong> </td>
<Td bgcolor = "# FFFFFF"> <input name = "shortname" type = "text"
Id = "shortname" size = "20" value = "htm | html | shtml | php"/> separate multiple values with | </td>
</Tr>
<Tr id = "rpct">
<Td height = "64" colspan = "2" bgcolor = "# FFFFFF">
<Table width = "100%" border = "0" cellspacing = "1" cellpadding = "1">
<Tr bgcolor = "# EDFCE2">
<Td colspan = "4"> <strong> content search options: </strong> <input type = "checkbox"
Name = "isreg" value = "1"/> use regular expressions </td>
</Tr>
<Tr>
<Td colspan = "4"> by default, the search content class uses string search, or you can use a regular expression (check required ). "If this parameter is left blank, the system deletes the" search content ".
<Br/> com, system, exec, eval, escapeshell, cmd, passthru, base64_decode, gzuncompress
</Td>
</Tr>
<Tr>
<Td width = "10%"> & nbsp; search content: </td>
<Td width = "36%" colspan = "3"> <textarea name = "sstr" id = "sstr"
Style = "width: 90%; height: 45px"> Xiao Liang, Root_GP, Root_CSS, c99sh_updateurl, c99sh_sourcesurl, 640684770, hx_dealdir, while (1) </textarea> </td>
</Tr>
</Table>
</Td>
</Tr>
<Tr>
<Td colspan = "2" height = "20" align = "center" bgcolor = "# E2F5BC"> <input
Type = "submit" name = "Submit" value = "" class = "inputbut"/> </td>
</Tr>
</Table>
</Form>
<Table width = "95%" border = "0" align = "center" cellpadding = "3"
Cellspacing = "1" bgcolor = "#666666">
<Tr bgcolor = "# FFFFFF">
<Td id = "mtd">
<Div id = 'magrou' style = 'width: 100%; height: 100; '> <iframe name = "stafrm"
Frameborder = "0" id = "stafrm" width = "100%" height = "100%"> </iframe> </div>
<Script type = "text/javascript">
Document. all. DV. style. pixelHeight = screen. height-450;
</Script> </td>
</Tr>
</Table>
</Body>
</Html> |