Advertisement
D3vBl4ck

Untitled

Jul 29th, 2019
20,374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.07 KB | None | 0 0
  1. <?php
  2.  
  3.   $crlf=chr(13).chr(10);
  4.   $itime=3;  //Minimum number of seconds between one-visitor visits
  5.   $imaxvisit=45;  //Maximum visits in $itime x $imaxvisits seconds
  6.   $ipenalty=1;  //Minutes for waitting
  7.   $iplogdir="./system/engine_logs/ProtectionLogs/";
  8.   $iplogfile="AttackersIPs.Log";
  9.  
  10.   //Warning Messages:
  11.   $message1='<br><font size="4" color="orange">Server under heavy bandwidth or being DDoS attacked!</font><br>';
  12.   $message2='Please wait ... ';
  13.   $message3=' seconds and try again to enter page.<br>';
  14.   $message4= '<b>Website has been attacked from this IP address: '.$_SERVER["REMOTE_ADDR"].'</b><br>';
  15.   $message5= '<font size="1">Keep in mind that page spamming is flood</font><br>';
  16. //---------------------- End of Initialization ---------------------------------------  
  17.  
  18.   //Get file time:
  19.   $ipfile=substr(md5($_SERVER["REMOTE_ADDR"]),-3);  // -3 means 4096 possible files
  20.   $oldtime=0;
  21.   if (file_exists($iplogdir.$ipfile)) $oldtime=filemtime($iplogdir.$ipfile);
  22.  
  23.   //Update times:
  24.   $time=time();
  25.   if ($oldtime<$time) $oldtime=$time;
  26.   $newtime=$oldtime+$itime;
  27.  
  28.   //     Check human or bot:
  29.   if ($newtime>=$time+$itime*$imaxvisit)
  30.   {
  31.     //     To block visitor:
  32.     touch($iplogdir.$ipfile,$time+$itime*($imaxvisit-1)+$ipenalty);
  33.     header("HTTP/1.0 503 Service Temporarily Unavailable");
  34.     header("Connection: close");
  35.     header("Content-Type: text/html");
  36.     echo '<html><head><title>Server DDoS Protection</title></head><body><p align="center"><strong>'
  37.           .$message1.'</strong>';
  38.     echo $message2.$ipenalty.$message3.$message4.$message5.'</p></body></html>'.$crlf;
  39.     //     logging:
  40.     $fp=@fopen($iplogdir.$iplogfile,"a"); chmod($iplogdir.$iplogfile, 0777);
  41.     if ($fp!==FALSE)
  42.     {
  43.       $useragent='<unknown user agent>';
  44.       if (isset($_SERVER["HTTP_USER_AGENT"])) $useragent=$_SERVER["HTTP_USER_AGENT"];
  45.       @fputs($fp,$_SERVER["REMOTE_ADDR"].' on '.date("D, d M Y, H:i:s").' as '.$useragent.$crlf);
  46.     }
  47.     @fclose($fp);
  48.     exit();
  49.  
  50.   }
  51.  
  52.   //Modify file time:
  53.   touch($iplogdir.$ipfile,$newtime);
  54.  
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement