Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @ This file is created by http://DeZender.Net
- * @ deZender (PHP5 Decoder for ionCube Encoder)
- *
- * @ Version : 3.0.8.0
- * @ Author : DeZender
- * @ Release on : 25.09.2017
- * @ Official site : http://DeZender.Net
- *
- */
- class AntiFlood
- {
- const OPTION_COUNTER_RESET_SECONDS = 'COUNTER_RESET_SECONDS';
- const OPTION_BAN_REMOVE_SECONDS = 'BAN_REMOVE_SECONDS';
- const OPTION_MAX_REQUESTS = 'MAX_REQUESTS';
- const OPTION_DATA_PATH = 'DATA_PATH';
- private $options = null;
- private $ip = null;
- public function __construct($overrideOptions = array( ))
- {
- $this->options = array_merge( array(
- self::OPTION_COUNTER_RESET_SECONDS => 2,
- self::OPTION_MAX_REQUESTS => 5,
- self::OPTION_BAN_REMOVE_SECONDS => 60,
- self::OPTION_DATA_PATH => '/tmp/antiflood_' . str_replace( array(
- 'www.',
- '.'
- ), array(
- '',
- '_'
- ), $_SERVER['SERVER_NAME'] )
- ), $overrideOptions );
- @mkdir( $this->options[self::OPTION_DATA_PATH] );
- $this->ip = $_SERVER['REMOTE_ADDR'];
- }
- public function isBanned()
- {
- $controlLockFile = $this->options[self::OPTION_DATA_PATH] . '/' . str_replace( '.', '_', $this->ip );
- if (file_exists( $controlLockFile )) {
- if ($this->options[self::OPTION_BAN_REMOVE_SECONDS] < (time( ) - filemtime( $controlLockFile ))) {
- unlink( $controlLockFile );
- }
- else {
- touch( $controlLockFile );
- return true;
- }
- }
- $controlFile = $this->options[self::OPTION_DATA_PATH] . '/ctrl';
- $control = array( );
- if (file_exists( $controlFile )) {
- $fh = fopen( $controlFile, 'r' );
- $fileContentsArr = ((0 < filesize( $controlFile ) ? json_decode( fread( $fh, filesize( $controlFile ) ), true ) : array( )));
- $control = array_merge( $control, $fileContentsArr );
- fclose( $fh );
- }
- if (isset( $control[$this->ip] )) {
- if ((time( ) - $control[$this->ip]['t']) < $this->options[self::OPTION_COUNTER_RESET_SECONDS]) {
- ++$control[$this->ip]['c'];
- }
- else {
- $control[$this->ip]['c'] = 1;
- }
- }
- else {
- $control[$this->ip]['c'] = 1;
- }
- $control[$this->ip]['t'] = time( );
- if ($this->options[self::OPTION_MAX_REQUESTS] < $control[$this->ip]['c']) {
- $fh = fopen( $controlLockFile, 'w' );
- fwrite( $fh, '' );
- fclose( $fh );
- }
- $fh = fopen( $controlFile, 'w' );
- .................................................................
- ..................................
- ............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement