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
 
(Una versione intermedia di uno stesso utente non è mostrata)
Riga 1: Riga 1:
<pre>
<pre>
<?php




// TODO: verificare se il percorso di partenza esiste
rwxrwxrwx. 3 root root  4096 29 apr 12:40 .
drwxr-xr-x. 3 root root  4096 29 apr 12:33 ..
-rwxrwxrwx  1 root root  4858 29 apr 12:38 algoritmi.lib
-rwxrwxrwx  1 root root 312276 29 apr 12:38 class1.lib
-rwxrwxrwx  1 root root  98170 29 apr 12:38 class2.lib
-rwxrwxrwx. 1 root root  1831 25 giu 13:01 config.inc
-rwxrwxrwx  1 root root    137 29 apr 12:43 get-oper
-rwxrwxrwx  1 root root  93470 29 apr 12:38 get-oper.lib
drwxrwxrwx. 2 root root  4096 25 giu 13:49 log
-rwxrwxrwx  1 root root    173 29 apr 12:43 put-call
-rwxrwxrwx  1 root root 165451 29 apr 12:38 put-call.lib
-rwxrwxrwx  1 root root    158 29 apr 12:44 put-crmcall
-rwxrwxrwx  1 root root  20612 29 apr 12:38 put-crmcall.lib
-rwxrwxrwx  1 root root  1085 29 apr 12:28 put-reg
-rwxrwxrwx  1 root root    218 29 apr 12:37 start-calls
[root@calipso-kennedy tifone]# php /tmp/1.php
./put-crmcall => SHA1: 5d09b94c7a7e7628310af0ad0da18f9e30c23455 MD5: bb11bf852f270593ea3bdee73e684e7f
./class2.lib => SHA1: 11f5550592cfaf18e162aaa83241ebd7227bd258 MD5: 62ed8fcdae090fcb7a3ea957f901a398
./algoritmi.lib => SHA1: bb2235e5756394754a5b4648d4f94d18fbb43bee MD5: ca6934c45d86dbeaf306411344a731a3
./get-oper => SHA1: 83a243c40649fb71704bc7f37adcf7fd7a05c0a5 MD5: 70c886fe5eb7aa3cb503d23c1f75d3d5
./get-oper.lib => SHA1: e42ea12ba3565966e124430118c002aadf03226a MD5: d127b1c27079fe0674a71ddb0847182e
./class1.lib => SHA1: c330bc548a55b56f90c9171925affe6e0c555d1a MD5: af77346bc3650d5b23e552b32401fa98
./config.inc => SHA1: 0ab80c38cafbd9b0f80b3ffee748e89ea50bbf10 MD5: 33db1d635da4cab54d812a19819b9215
./start-calls => SHA1: e9ae108fe08a7625c2eb270d17306a035e2100e0 MD5: be49c6694d4908ff4837dccbeb0f0efb
./put-call.lib => SHA1: a32e7c48e75cadcc64eb5a00c4933e93d0c2927f MD5: c290c373f6986d0659bad0a65dc1f024
./put-reg => SHA1: 6b40e8ddeba6fb5996dc46589b8e0ff04ade8b73 MD5: 22fdd6df58c4357e4d541db057d78963
./put-crmcall.lib => SHA1: eb2e479becfb3193af62de027cc11716173eabc6 MD5: 8c7ca4e4fdd99447dc16f7cc874df8ff
./put-call => SHA1: 329b9c009250dac742b267574d3c2c44d8bd7460 MD5: bb3e59c2d1c664b81bf9d1fcc6dc68bd
array size is 12
[root@calipso-kennedy tifone]#




////////////////////////////////////////////////////////////////////////////////////// MAIN
$NL = "\r\n";
//Put here the directory you want to search for. Put / if you want to search your entire domain
$dir = './';
//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 attuale delle 11:46, 23 lug 2013



rwxrwxrwx. 3 root root   4096 29 apr 12:40 .
drwxr-xr-x. 3 root root   4096 29 apr 12:33 ..
-rwxrwxrwx  1 root root   4858 29 apr 12:38 algoritmi.lib
-rwxrwxrwx  1 root root 312276 29 apr 12:38 class1.lib
-rwxrwxrwx  1 root root  98170 29 apr 12:38 class2.lib
-rwxrwxrwx. 1 root root   1831 25 giu 13:01 config.inc
-rwxrwxrwx  1 root root    137 29 apr 12:43 get-oper
-rwxrwxrwx  1 root root  93470 29 apr 12:38 get-oper.lib
drwxrwxrwx. 2 root root   4096 25 giu 13:49 log
-rwxrwxrwx  1 root root    173 29 apr 12:43 put-call
-rwxrwxrwx  1 root root 165451 29 apr 12:38 put-call.lib
-rwxrwxrwx  1 root root    158 29 apr 12:44 put-crmcall
-rwxrwxrwx  1 root root  20612 29 apr 12:38 put-crmcall.lib
-rwxrwxrwx  1 root root   1085 29 apr 12:28 put-reg
-rwxrwxrwx  1 root root    218 29 apr 12:37 start-calls
[root@calipso-kennedy tifone]# php /tmp/1.php
./put-crmcall => SHA1: 5d09b94c7a7e7628310af0ad0da18f9e30c23455 MD5: bb11bf852f270593ea3bdee73e684e7f
./class2.lib => SHA1: 11f5550592cfaf18e162aaa83241ebd7227bd258 MD5: 62ed8fcdae090fcb7a3ea957f901a398
./algoritmi.lib => SHA1: bb2235e5756394754a5b4648d4f94d18fbb43bee MD5: ca6934c45d86dbeaf306411344a731a3
./get-oper => SHA1: 83a243c40649fb71704bc7f37adcf7fd7a05c0a5 MD5: 70c886fe5eb7aa3cb503d23c1f75d3d5
./get-oper.lib => SHA1: e42ea12ba3565966e124430118c002aadf03226a MD5: d127b1c27079fe0674a71ddb0847182e
./class1.lib => SHA1: c330bc548a55b56f90c9171925affe6e0c555d1a MD5: af77346bc3650d5b23e552b32401fa98
./config.inc => SHA1: 0ab80c38cafbd9b0f80b3ffee748e89ea50bbf10 MD5: 33db1d635da4cab54d812a19819b9215
./start-calls => SHA1: e9ae108fe08a7625c2eb270d17306a035e2100e0 MD5: be49c6694d4908ff4837dccbeb0f0efb
./put-call.lib => SHA1: a32e7c48e75cadcc64eb5a00c4933e93d0c2927f MD5: c290c373f6986d0659bad0a65dc1f024
./put-reg => SHA1: 6b40e8ddeba6fb5996dc46589b8e0ff04ade8b73 MD5: 22fdd6df58c4357e4d541db057d78963
./put-crmcall.lib => SHA1: eb2e479becfb3193af62de027cc11716173eabc6 MD5: 8c7ca4e4fdd99447dc16f7cc874df8ff
./put-call => SHA1: 329b9c009250dac742b267574d3c2c44d8bd7460 MD5: bb3e59c2d1c664b81bf9d1fcc6dc68bd
array size is 12
[root@calipso-kennedy tifone]#