am i stupid or grep? :-)
find /data/www/ -type f -name *.php -exec grep -l -i -n -F "<?" '{}' ; lists any file which contains "<?" under the path /data/www/
find /data/www/ -type f -name *.php -exec grep -l -i -n -F "<?\n" '{}' ; is expected to find any file with "<?" followed directly by a linebreak but that does not work and if someone finds google empty it was me :-(
On Tue, 2013-05-07 at 19:41 +0200, Reindl Harald wrote:
am i stupid or grep? :-)
Well I know you aren't grep ...
find /data/www/ -type f -name *.php -exec grep -l -i -n -F "<?" '{}' ; lists any file which contains "<?" under the path /data/www/
find /data/www/ -type f -name *.php -exec grep -l -i -n -F "<?\n" '{}' ; is expected to find any file with "<?" followed directly by a linebreak but that does not work and if someone finds google empty it was me :-(
Not sure if "\n" is allowed, but why not use $ for end of line as in most regular expressions?
poc
On Wed, May 08, 2013 at 11:23:34PM -0430, Patrick O'Callaghan wrote:
On Tue, 2013-05-07 at 19:41 +0200, Reindl Harald wrote:
find /data/www/ -type f -name *.php -exec grep -l -i -n -F "<?\n" '{}' ; is expected to find any file with "<?" followed directly by a linebreak but that does not work and if someone finds google empty it was me :-(
Not sure if "\n" is allowed, but why not use $ for end of line as in most regular expressions?
Reindl is using fgrep (implied by the -F flag), so I would think \n is interpreted literally. I would agree with your suggestion to use
$ grep -E "<?$"
Another recommendation would be to use -print0 and pipe to xargs -0. Using the -exec flag for something like this might be significantly less efficient.
Am 09.05.2013 05:53, schrieb Patrick O'Callaghan:
On Tue, 2013-05-07 at 19:41 +0200, Reindl Harald wrote:
find /data/www/ -type f -name *.php -exec grep -l -i -n -F "<?" '{}' ; lists any file which contains "<?" under the path /data/www/
find /data/www/ -type f -name *.php -exec grep -l -i -n -F "<?\n" '{}' ; is expected to find any file with "<?" followed directly by a linebreak but that does not work and if someone finds google empty it was me :-(
Not sure if "\n" is allowed, but why not use $ for end of line as in most regular expressions?
because it does not work and i have no idea how to "mask" the LF for grep
[harry@srv-rhsoft:~]$ find /mnt/data/www/ -type f -name *.php -exec grep -l -i -n -F "<?$" '{}' ; [harry@srv-rhsoft:~]$
as you see nothing found
[harry@srv-rhsoft:~]$ cat /mnt/data/www/short-open.php <? echo 'TEST'; ?>
as you see there is at least one file
On 05/09/13 21:05, Reindl Harald wrote:
Am 09.05.2013 05:53, schrieb Patrick O'Callaghan:
On Tue, 2013-05-07 at 19:41 +0200, Reindl Harald wrote:
find /data/www/ -type f -name *.php -exec grep -l -i -n -F "<?" '{}' ; lists any file which contains "<?" under the path /data/www/
find /data/www/ -type f -name *.php -exec grep -l -i -n -F "<?\n" '{}' ; is expected to find any file with "<?" followed directly by a linebreak but that does not work and if someone finds google empty it was me :-(
Not sure if "\n" is allowed, but why not use $ for end of line as in most regular expressions?
because it does not work and i have no idea how to "mask" the LF for grep
[harry@srv-rhsoft:~]$ find /mnt/data/www/ -type f -name *.php -exec grep -l -i -n -F "<?$" '{}' ; [harry@srv-rhsoft:~]$
as you see nothing found
[harry@srv-rhsoft:~]$ cat /mnt/data/www/short-open.php
<? echo 'TEST'; ?>
as you see there is at least one file
-G seems to work.... Got a splitting headache, so not thinking of the implications....
[egreshko@meimei try]$ cat one.php <? echo 'TEST'; ?> [egreshko@meimei try]$ cat two.php <?xxxx echo 'TEST'; ?>xxxx
[egreshko@meimei try]$ find /tmp/try -type f -name *.php -exec grep -l -i -n -G "<?$" '{}' ; /tmp/try/one.php
[egreshko@meimei try]$ find /tmp/try -type f -name *.php -exec grep -l -i -n -G "<?$" '{}' ; /tmp/try/one.php
-- The only thing worse than a poorly asked question is a cryptic answer.
So you want all the <? but not the <?php, <?xml, <?= in text files?
grep -r "<?" * | grep -v "Binary file" | grep -v "<?php" | grep -v "<?xml" | grep -v "<?="
Hi Reindl,
On Thu, May 09, 2013 at 03:05:01PM +0200, Reindl Harald wrote:
because it does not work and i have no idea how to "mask" the LF for grep
[harry@srv-rhsoft:~]$ find /mnt/data/www/ -type f -name *.php -exec grep -l -i -n -F "<?$" '{}' ;
Did you look at my response earlier?
http://mid.gmane.org/20130509123904.GC6637@kuru.dyndns-at-home.com
Hope this helps,
Am 10.05.2013 01:52, schrieb David Beveridge:
[egreshko@meimei try]$ find /tmp/try -type f -name *.php -exec grep -l -i -n -G "<?$" '{}' ; /tmp/try/one.php
The only thing worse than a poorly asked question is a cryptic answer.
So you want all the <? but not the <?php, <?xml, <?= in text files?
grep -r "<?" * | grep -v "Binary file" | grep -v "<?php" | grep -v "<?xml" | grep -v "<?="
i finally solved it with a php-script itself using a years ago written PHP-SPL-wrapper for recursive listing of files started in the dir the php-cli-script is living
relevant is <? followed by space, LF, CR, TAB to catch also files with windows or OSX line-breaks
you must not list here files containing value="<?=(int)$id?>" because this short echo-variant is starting with PHP 5.4 always supported and no longer in context with "short_open_tag" from php.ini
well, i found 7 files out of some thousand written in the last 10 years :-)
script and 3 test-files below __________________________________________________________________________________
#!/usr/bin/php <?php if(PHP_SAPI != 'cli') { exit('Forbidden'); } require('global.inc.php'); $fs = new rh_filesystem(); $liste = $fs->ListFilesRecursive(/**$path*/__DIR__, /**$details*/false, /**$excludes*/array()); foreach($liste as $file) { if($file != __FILE__ && strtolower(pathinfo($file, PATHINFO_EXTENSION)) == 'php' && is_readable($file)) { $content = file_get_contents($file); if(strpos($content, '<? ') !== false || strpos($content, "<?\r") !== false || strpos($content, "<?\n") !== false || strpos($content, "<?\t") !== false) { echo $file . MY_LE; flush(); } } } ?>
__________________________________________________________________________________
$fs->ListFilesRecursive() is basically this:
$spl_objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); try { foreach($spl_objects as $filename=>$spl_object) { if(!$spl_object->isDir()) { if(DIRECTORY_SEPARATOR === "\") { $filename = str_replace(DIRECTORY_SEPARATOR, '/', $filename); } if(substr($filename, 0, 2) === './') { $filename = substr($filename, 2); } if(empty($pattern) || !preg_match($pattern, $filename)) { if(!$ignore_svn || strpos($filename, '/.svn') === false) { $enumerate_list[] = $filename; } } } } } catch(UnexpectedValueException $e) { error_log('Directory "' . $path . '" contained a directory we can not recurse into'); return false; } sort($enumerate_list);
__________________________________________________________________________________
[harry@srv-rhsoft:/www]$ cat test-short-open-1.php <? echo 'TEST'; ?> __________________________________________________________________________________
[harry@srv-rhsoft:/www]$ cat test-short-open-2.php <?php echo 'TEST'; ?> <form action="<? echo "TEST"?>"></form> __________________________________________________________________________________
[harry@srv-rhsoft:/www]$ cat test-short-open-3.php <? echo 'TEST'; ?> <td> <? echo 'TEST'; ?> </td> __________________________________________________________________________________