Advertisement
Guest User

Untitled

a guest
Apr 18th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP5 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 3.0.8.0
  8. * @ Author : DeZender
  9. * @ Release on : 25.09.2017
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. class AntiFlood
  15. {
  16. const OPTION_COUNTER_RESET_SECONDS = 'COUNTER_RESET_SECONDS';
  17. const OPTION_BAN_REMOVE_SECONDS = 'BAN_REMOVE_SECONDS';
  18. const OPTION_MAX_REQUESTS = 'MAX_REQUESTS';
  19. const OPTION_DATA_PATH = 'DATA_PATH';
  20.  
  21. private $options = null;
  22. private $ip = null;
  23.  
  24. public function __construct($overrideOptions = array( ))
  25. {
  26. $this->options = array_merge( array(
  27. self::OPTION_COUNTER_RESET_SECONDS => 2,
  28. self::OPTION_MAX_REQUESTS => 5,
  29. self::OPTION_BAN_REMOVE_SECONDS => 60,
  30. self::OPTION_DATA_PATH => '/tmp/antiflood_' . str_replace( array(
  31. 'www.',
  32. '.'
  33. ), array(
  34. '',
  35. '_'
  36. ), $_SERVER['SERVER_NAME'] )
  37. ), $overrideOptions );
  38. @mkdir( $this->options[self::OPTION_DATA_PATH] );
  39. $this->ip = $_SERVER['REMOTE_ADDR'];
  40. }
  41.  
  42. public function isBanned()
  43. {
  44. $controlLockFile = $this->options[self::OPTION_DATA_PATH] . '/' . str_replace( '.', '_', $this->ip );
  45.  
  46. if (file_exists( $controlLockFile )) {
  47. if ($this->options[self::OPTION_BAN_REMOVE_SECONDS] < (time( ) - filemtime( $controlLockFile ))) {
  48. unlink( $controlLockFile );
  49. }
  50. else {
  51. touch( $controlLockFile );
  52. return true;
  53. }
  54. }
  55.  
  56. $controlFile = $this->options[self::OPTION_DATA_PATH] . '/ctrl';
  57. $control = array( );
  58.  
  59. if (file_exists( $controlFile )) {
  60. $fh = fopen( $controlFile, 'r' );
  61. $fileContentsArr = ((0 < filesize( $controlFile ) ? json_decode( fread( $fh, filesize( $controlFile ) ), true ) : array( )));
  62. $control = array_merge( $control, $fileContentsArr );
  63. fclose( $fh );
  64. }
  65.  
  66. if (isset( $control[$this->ip] )) {
  67. if ((time( ) - $control[$this->ip]['t']) < $this->options[self::OPTION_COUNTER_RESET_SECONDS]) {
  68. ++$control[$this->ip]['c'];
  69. }
  70. else {
  71. $control[$this->ip]['c'] = 1;
  72. }
  73. }
  74. else {
  75. $control[$this->ip]['c'] = 1;
  76. }
  77.  
  78. $control[$this->ip]['t'] = time( );
  79.  
  80. if ($this->options[self::OPTION_MAX_REQUESTS] < $control[$this->ip]['c']) {
  81. $fh = fopen( $controlLockFile, 'w' );
  82. fwrite( $fh, '' );
  83. fclose( $fh );
  84. }
  85.  
  86. $fh = fopen( $controlFile, 'w' );
  87. .................................................................
  88. ..................................
  89. ............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement