Anteprima: differenze tra le versioni

(Creata pagina con '<pre> <?php // TODO: verificare se il percorso di partenza esiste ////////////////////////////////////////////////////////////////////////////////////// MAIN $NL = "\r\n"...')
 
Nessun oggetto della modifica
Riga 1: Riga 1:
<pre>
<pre>
<?php


[root@calipso_nolfi tifone]# php /tmp/3.php
./iubar-put-crmcall.php => SHA1: 87d312730ebc5732717519a44adb43750eb29975 MD5: b25b80e36e5687c378d9c3670c3aab36
./put-crmcall.php => SHA1: 725a580317e488d43e94ef2b2ac579758e93be5b MD5: add5469f324f0583cea81f3aabcba1dd
./class2.php => SHA1: 4f6c546ebbd4af7ecea487666f8c6bc3efa4db9e MD5: f47c07e7ef8d1ad4e029db1ecc30cb80
./get-oper.php => SHA1: 725a580317e488d43e94ef2b2ac579758e93be5b MD5: add5469f324f0583cea81f3aabcba1dd
./class1.php => SHA1: 9aaff085878862f90262d16f0eb2d1cfb18e2a27 MD5: ef6215a59cea6b7febb361c87c196e86


// TODO: verificare se il percorso di partenza esiste




////////////////////////////////////////////////////////////////////////////////////// MAIN


$NL = "\r\n";
[root@calipso_nolfi tifone]# ls -la
//Put here the directory you want to search for. Put / if you want to search your entire domain
totale 628
$dir = './';
drwxr-xr-x 3 root root  4096  2 lug 16:37 .
drwxr-xr-x 4 root root  4096  8 giu 12:52 ..
-rwxrwxrwx 1 root root  3610 29 apr 14:21 algoritmi.lib
-rwxrwxrwx 1 root root 196935 29 apr 14:21 class1.lib
-rwxrwxr-x 1 root root  14430  8 giu 10:50 class1.php
-rwxrwxrwx 1 root root  57631 29 apr 14:21 class2.lib
-rwxrwxr-x 1 root root  12986  8 giu 10:50 class2.php
-rwxrwxrwx 1 root root  1691 18 lug 08:04 config.inc
-rwxrwxrwx 1 root root    171  8 giu 13:19 get-oper
-rwxrwxrwx 1 root root  74462 29 apr 14:21 get-oper.lib
-rwxrwxr-x 1 root root  26755  8 giu 10:51 get-oper.php
-rwxrwxr-x 1 root root    454  9 giu 17:30 iubar-put-crmcall.php
-rwxr-xr-x 1 root root    300  9 giu 17:26 iubar-start-calls
-rw------- 1 root root  3143  3 lug 16:59 iubar-test.php
drwxrwxrwx 2 root root  4096  2 lug 12:26 log
-rwxrwxrwx 1 root root    173 29 apr 12:44 put-call
-rwxrwxrwx 1 root root 121172 29 apr 14:21 put-call.lib
-rwxrwxrwx 1 root root    158 29 apr 12:45 put-crmcall
-rwxrwxrwx 1 root root  18094 29 apr 14:21 put-crmcall.lib
-rwxrwxr-x 1 root root  26755  8 giu 10:51 put-crmcall.php
-rwxrwxrwx 1 root root  1085 29 apr 12:28 put-reg
-rwxrwxrwx 1 root root    218 29 apr 12:37 start-calls


//Put the date you want to compare with in the format of:  YYYY-mm-dd hh:mm:ss
$comparedatestr = "2013-04-25 00:00:00";
$comparedate = strtotime($comparedatestr);
//I run the function here to start the search.
$exts = array();
$exts[] = "log";
$array = directory_tree(null, $dir, $comparedate, $exts);
echo "array size is " . count($array) . $NL;
////////////////////////////////////////////////////////////////////////////////////// FUNCTIONS
//This is the function which is doing the search...
function directory_tree($array=array(), $address, $comparedate, $exts=array(), $newline="\r\n", $dir_sep="/"){
  @$dir = opendir($address);
  if($dir){
        while($entry = readdir($dir)){
                $address = formatDir($address);
                $fullpath = $address . $dir_sep . $entry;
                if(is_dir($fullpath) && ($entry != ".." && $entry != ".")){
                        $array = directory_tree($array, $fullpath, $comparedate, $exts, $newline, $dir_sep);
                } else {
                  if($entry != ".." && $entry != ".") {
                    $last_modified = filemtime($fullpath);
                    $last_modified_str= date("Y-m-d h:i:s", $last_modified);
                    $ok = true;
                    if(count($exts)>0){
                                $ext = pathinfo($fullpath, PATHINFO_EXTENSION);
                                // echo "ext: " . $ext;
                                $ok = in_array($ext, $exts);
                    }
                    if($ok){
                                if($comparedate < $last_modified)  {
                                  echo $fullpath . ' => ' . $last_modified_str . $newline;
                                  $array[$fullpath] = $last_modified;
                                }
                    }
                }
            }
      }
}
return $array;
}
function formatDir($string){
//if(substr($string, -1) == '/') {
//    $string = substr($string, 0, -1)
//}
//Another (probably better) option would be using rtrim() - this one removes all trailing slashes:
$string = rtrim($string, '/');
  return $string;
}
function mostRecentModifiedFileTime($dirName, $doRecursive) {
    $d = dir($dirName);
    $lastModified = 0;
    while($entry = $d->read()) {
        if ($entry != "." && $entry != "..") {
            if (!is_dir($dirName."/".$entry)) {
                $currentModified = filemtime($dirName."/".$entry);
            } else if ($doRecursive && is_dir($dirName."/".$entry)) {
                $currentModified = mostRecentModifiedFileTime($dirName."/".$entry,true);
            }
            if ($currentModified > $lastModified){
                $lastModified = $currentModified;
            }
        }
    }
    $d->close();
    return $lastModified;
}
?>
</pre>
<?php
// TODO: verificare se il percorso di partenza esiste
////////////////////////////////////////////////////////////////////////////////////// MAIN
$NL = "\r\n";
//Put here the directory you want to search for. Put / if you want to search your entire domain
$dir='./';
//I run the function here to start the search.
$exts = array();
// $exts[] = "log";
$array = directory_tree(null, $dir, $exts);
echo "array size is " . count($array) . $NL;
////////////////////////////////////////////////////////////////////////////////////// FUNCTIONS
//This is the function which is doing the search...
function directory_tree($array=array(), $address, $exts=array(), $newline="\r\n", $dir_sep="/"){
  @$dir = opendir($address);
  if($dir){
        while($entry = readdir($dir)){
                $address = formatDir($address);
                $fullpath = $address . $dir_sep . $entry;
                if(is_dir($fullpath) && ($entry != ".." && $entry != ".")){
                        $array = directory_tree($array, $fullpath, $exts, $newline, $dir_sep);
                } else {
                  if($entry != ".." && $entry != ".") {
                    $ok = true;
                    if(count($exts)>0){
                                $ext = pathinfo($fullpath, PATHINFO_EXTENSION);
                                // echo "ext: " . $ext;
                                $ok = in_array($ext, $exts);
                    }
                    if($ok){
  $sha1 = get_sha1_file($fullpath);
  $md5 = get_md5_file($fullpath);
                                  echo $fullpath . ' => ' . "SHA1: " . $sha1 . " MD5: " . $md5 . $newline;
                                  $array[$fullpath] = array($sha1, $md5);
                    }
                }
            }
      }
}
return $array;
}
function formatDir($string){
//if(substr($string, -1) == '/') {
//    $string = substr($string, 0, -1)
//}
//Another (probably better) option would be using rtrim() - this one removes all trailing slashes:
$string = rtrim($string, '/');
  return $string;
}
function get_sha1_file($file) {
  if(is_null($file) || !file_exists($file)) {
return trigger_error('File is null or does not exists');
  }
  return sha1_file($file);
}
function get_md5_file($file) {
  if(is_null($file) || !file_exists($file)) {
return trigger_error('File is null or does not exists');
  }
  return md5_file($file);
}
?>
<pre>




</pre>
</pre>

Versione delle 10:00, 23 lug 2013


[root@calipso_nolfi tifone]# php /tmp/3.php
./iubar-put-crmcall.php => SHA1: 87d312730ebc5732717519a44adb43750eb29975 MD5: b25b80e36e5687c378d9c3670c3aab36
./put-crmcall.php => SHA1: 725a580317e488d43e94ef2b2ac579758e93be5b MD5: add5469f324f0583cea81f3aabcba1dd
./class2.php => SHA1: 4f6c546ebbd4af7ecea487666f8c6bc3efa4db9e MD5: f47c07e7ef8d1ad4e029db1ecc30cb80
./get-oper.php => SHA1: 725a580317e488d43e94ef2b2ac579758e93be5b MD5: add5469f324f0583cea81f3aabcba1dd
./class1.php => SHA1: 9aaff085878862f90262d16f0eb2d1cfb18e2a27 MD5: ef6215a59cea6b7febb361c87c196e86




[root@calipso_nolfi tifone]# ls -la
totale 628
drwxr-xr-x 3 root root   4096  2 lug 16:37 .
drwxr-xr-x 4 root root   4096  8 giu 12:52 ..
-rwxrwxrwx 1 root root   3610 29 apr 14:21 algoritmi.lib
-rwxrwxrwx 1 root root 196935 29 apr 14:21 class1.lib
-rwxrwxr-x 1 root root  14430  8 giu 10:50 class1.php
-rwxrwxrwx 1 root root  57631 29 apr 14:21 class2.lib
-rwxrwxr-x 1 root root  12986  8 giu 10:50 class2.php
-rwxrwxrwx 1 root root   1691 18 lug 08:04 config.inc
-rwxrwxrwx 1 root root    171  8 giu 13:19 get-oper
-rwxrwxrwx 1 root root  74462 29 apr 14:21 get-oper.lib
-rwxrwxr-x 1 root root  26755  8 giu 10:51 get-oper.php
-rwxrwxr-x 1 root root    454  9 giu 17:30 iubar-put-crmcall.php
-rwxr-xr-x 1 root root    300  9 giu 17:26 iubar-start-calls
-rw------- 1 root root   3143  3 lug 16:59 iubar-test.php
drwxrwxrwx 2 root root   4096  2 lug 12:26 log
-rwxrwxrwx 1 root root    173 29 apr 12:44 put-call
-rwxrwxrwx 1 root root 121172 29 apr 14:21 put-call.lib
-rwxrwxrwx 1 root root    158 29 apr 12:45 put-crmcall
-rwxrwxrwx 1 root root  18094 29 apr 14:21 put-crmcall.lib
-rwxrwxr-x 1 root root  26755  8 giu 10:51 put-crmcall.php
-rwxrwxrwx 1 root root   1085 29 apr 12:28 put-reg
-rwxrwxrwx 1 root root    218 29 apr 12:37 start-calls