Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. // Report all errors
  2. error_reporting(E_ALL);
  3. ini_set('display_errors','On');
  4.  
  5. // Set memory limit and time out period
  6. ini_set('memory_limit','64M');
  7. set_time_limit(600);
  8.  
  9. // Scan hash strings for files
  10.  
  11. if ($_GET['action'] == 'scan') {
  12.     $filemd5 = array();
  13.     getdir(dirname(__FILE__));
  14.    
  15.     include_once(dirname(__FILE__).'/filehashes.php');
  16.  
  17.     $fh = fopen("scanresults.txt", 'w');
  18.  
  19.     foreach ($filemd5 as $file) {
  20.         if (empty($filehashes[$file[0]])) {
  21.             fwrite($fh, "F: ".$file[0]."\r\n");
  22.         } else
  23.  
  24.         if ($filehashes[$file[0]] != $file[1]) {
  25.             fwrite($fh, "M: ".$file[0]."\r\n");
  26.         }
  27.     }
  28.  
  29.     fclose($fh);
  30.  
  31. }
  32.  
  33. // Generate hash strings for files
  34.  
  35. if ($_GET['action'] == 'generate') {
  36.     $filemd5 = array();
  37.     getdir(dirname(__FILE__));
  38.  
  39.     $fh = fopen("filehashes.php", 'w') or die("can't open file");
  40.     fwrite($fh, '<?php $filehashes = array('."\r\n");
  41.  
  42.     foreach ($filemd5 as $file) {
  43.         fwrite($fh, "'".$file[0]."' => '".$file[1]."',\r\n");
  44.     }
  45.  
  46.     fwrite($fh, '); ?>');
  47.     fclose($fh);
  48. }
  49.  
  50. // Recursively read directory
  51.  
  52. function getdir( $path, $level = 0 ){
  53.     global $filemd5;
  54.     $ignore = array('.','..');
  55.     $dh = @opendir( $path );
  56.      
  57.     while( false !== ( $file = readdir( $dh ) ) ){
  58.         if( !in_array( $file, $ignore ) ){
  59.             $spaces = str_repeat( '-', ( $level * 4 ) );
  60.             if( is_dir( "$path/$file" ) ){
  61.                 getdir( "$path/$file", ($level+1) );
  62.             } else {
  63.                 $filemd5[] = array(str_replace(dirname(__FILE__).'/','',"$path/$file"),md5_file("$path/$file"));
  64.             }
  65.         }
  66.     }
  67.     closedir( $dh );
  68. }
  69.  
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement