Created
January 7, 2016 11:52
-
-
Save Grenlandias/abe26adeec323e738fd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?if ($_REQUEST['code']){ | |
define('START_TIME', time()); // засекаем время старта | |
define('CODE', str_replace("\r\n","\n",$_REQUEST['code'])); // строка поиска | |
define('START_PATH', dirname(__FILE__)); // стартовая папка для поиска | |
define('LOG',START_PATH.'/filelist.txt'); // файл с результатами | |
if ($_REQUEST['break_point']) | |
define('SKIP_PATH',$_REQUEST['break_point']); // промежуточный путь | |
else | |
@unlink(LOG); // первый раз, удалим файл со старыми результатами | |
Search(START_PATH); | |
if (defined('BREAK_POINT')) | |
{ | |
?><form method=post id=postform> | |
<input type=hidden name=go value=y> | |
<input type=hidden name=code value="<?=htmlspecialchars(CODE)?>"> | |
<input type=hidden name=break_point value="<?=htmlspecialchars(BREAK_POINT)?>"> | |
</form> | |
Идёт поиск...<br> | |
Текущий файл: <i><?=htmlspecialchars(BREAK_POINT)?></i> | |
<script>window.setTimeout("document.getElementById('postform').submit()",500);</script><? // таймаут чтобы браузер показал текст | |
die(); | |
} | |
$iframe = "<iframe src=filelist.txt width=100% height=600></iframe>"; | |
} | |
else | |
$iframe = ''; | |
?> | |
<form method=post> | |
<textarea name=code cols=80 rows=10><?=htmlspecialchars($_REQUEST['code'])?></textarea> | |
<br><input type=submit name=go value="GO!"></form><? | |
if (file_exists(LOG)) | |
echo $iframe; | |
function Search($path) | |
{ | |
if (time() - START_TIME > 10) | |
{ | |
if (!defined('BREAK_POINT')) | |
define('BREAK_POINT', $path); | |
return; | |
} | |
if (defined('SKIP_PATH') && !defined('FOUND')) // проверим, годится ли текущий путь | |
{ | |
# /bitrix/components/bitrix/forum/message | |
# /bitrix/components/alpha - годится | |
# /bitrix/components/alpha/beta - не годится | |
if (0!==strpos(SKIP_PATH, dirname($path))) // отбрасываем имя или идём ниже | |
return; | |
if (SKIP_PATH==$path) // путь найден, продолжаем искать текст | |
define('FOUND',true); | |
} | |
if (is_dir($path)) // dir | |
{ | |
$dir = opendir($path); | |
while($item = readdir($dir)) | |
{ | |
if ($item == '.' || $item == '..') | |
continue; | |
Search($path.'/'.$item); | |
} | |
closedir($dir); | |
} | |
else // file | |
{ | |
if ((!defined('SKIP_PATH') || defined('FOUND')) && substr($path,-4) == '.php') | |
{ | |
$str = file_get_contents($path); | |
$str = str_replace("\r\n","\n",$str); | |
if (false !== strpos($str,CODE)) | |
Mark($path); | |
} | |
} | |
} | |
function Mark($file) | |
{ | |
static $res; | |
if (!$res) | |
$res = fopen(LOG,'ab'); | |
if (!$res) | |
die('no permissions'); | |
fwrite($res,substr($file,strlen(START_PATH))."\n"); | |
}?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment