fileMonitor.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /*
  3. -------------------------------------------------
  4. File Name: fileMonitor
  5. Description :
  6. Author : CoolCat
  7. date: 2019/1/3
  8. -------------------------------------------------
  9. Change Activity:
  10. 2019/1/3:
  11. -------------------------------------------------
  12. */
  13. class FileMonitor
  14. {
  15. private $dir;
  16. private $i=0;
  17. private $files = [];
  18. private $filesize = [];
  19. public function __construct($argv)
  20. {
  21. $this->dir = $this->getparam($argv);
  22. $this->getfiles($this->dir);
  23. print "[+] total:".count($this->files[$this->i])."\n\r";
  24. $this->i++;
  25. while(true)
  26. {
  27. $this->getfiles($this->dir);
  28. if(isset($this->files[$this->i-1]) && ((count($this->files[$this->i])>count($this->files[$this->i-1]))))
  29. {
  30. print "[+] total:".count($this->files[$this->i])."\n\r";
  31. print "[*] addfile: ".implode('|',array_diff($this->files[$this->i],$this->files[$this->i-1]))."\n\r";
  32. }
  33. if(isset($this->files[$this->i-1]) && ((count($this->files[$this->i])<count($this->files[$this->i-1]))))
  34. {
  35. print "[+] total:".count($this->files[$this->i])."\n\r";
  36. print "[*] deletefile: ".implode('|',array_diff($this->files[$this->i-1],$this->files[$this->i]))."\n\r";
  37. }
  38. if(isset($this->filesize[$this->i-1]))
  39. {
  40. array_map(function($v,$val,$key){
  41. if($v != $val)
  42. {
  43. print "[*] updatefile:{$key}\n\r";
  44. }
  45. },$this->filesize[$this->i-1],$this->filesize[$this->i],array_keys($this->filesize[$this->i]));
  46. }
  47. $this->i++;
  48. if($this->i>=30)
  49. {
  50. $this->files = [];
  51. $this->filesize = [];
  52. $this->i = 0;
  53. }
  54. }
  55. }
  56. private function getparam($argv)
  57. {
  58. foreach($argv as $key=>$val)
  59. {
  60. if($val == "--dir")
  61. {
  62. return is_dir($argv[$key+1])?$argv[$key+1]:exit("[-] directory does not exist!");
  63. }
  64. }
  65. }
  66. private function getfiles($dir)
  67. {
  68. if(is_dir($dir))
  69. {
  70. $d = scandir($dir);
  71. foreach($d as $v)
  72. {
  73. if($v != '.' && $v != '..')
  74. {
  75. if(is_dir("{$dir}/{$v}"))
  76. {
  77. $this->getfiles("{$dir}/{$v}");
  78. }
  79. else
  80. {
  81. $this->files[$this->i][] = "{$dir}/{$v}";
  82. $this->filesize[$this->i]["{$dir}/{$v}"] = filesize("{$dir}/{$v}");
  83. }
  84. }
  85. }
  86. }
  87. else
  88. {
  89. $this->files[$this->i][] = $dir;
  90. $this->filesize[$this->i][$dir] = filesize($dir);
  91. }
  92. }
  93. }
  94. print "
  95. _____________
  96. < FileMonitor >
  97. -------------
  98. /\_)o<
  99. | |
  100. | O . O |
  101. \_____/
  102. By CoolCat
  103. ";
  104. new FileMonitor($argv);
  105. ?>