Auto block abusers

This commit is contained in:
Kieran 2018-04-02 03:16:33 +08:00
parent 2493eb7c3e
commit e2e6bf0d0c
3 changed files with 52 additions and 2 deletions

39
src/php/cloudflare.php Normal file
View File

@ -0,0 +1,39 @@
<?php
function AddFirewallRule($ip) {
$post = array(
'mode' => 'challenge',
'configuration' => array(
'target' => 'ip',
'value' => $ip
),
'notes' => 'void.cat auto block'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.cloudflare.com/client/v4/zones/' . _CLOUDFLARE_ZONE . '/firewall/access_rules/rules');
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'X-Auth-Email: ' . _CLOUDFLARE_API_EMAIL,
'X-Auth-Key: ' . _CLOUDFLARE_API_KEY
));
$result = curl_exec ($ch);
curl_close ($ch);
$cfr = json_decode($result, true);
if($cfr['success'] == True){
$discord_data = array("content" => "[IP BLOCKED] " . $ip);
include_once("discord.php");
}
return $cfr;
}
if(isset($_GET["ip"])) {
include_once("config.php");
var_dump(AddFirewallRule($_GET["ip"]));
}
?>

View File

@ -20,6 +20,11 @@
define('_UA_NO_VIEW', array("YandexBot/3.0", "Googlebot/2.1", "Yahoo! Slurp"));
define('_VIRUSTOTAL_KEY', 'API_KEY');
/* CLOUDFLARE SETTINGS */
define('_CLOUDFLARE_API_EMAIL', 'me@me.com');
define('_CLOUDFLARE_API_KEY', 'API_KEY');
define('_CLOUDFLARE_ZONE', 'ZONE_ID');
/* CAPTCHA SETTINGS */
define('_DL_CAPTCHA', 10);
define('_CAPTCHA_DL_EXPIRE', 86400);

View File

@ -7,8 +7,9 @@
GAPageView($redis);
$ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
$hash = substr($_SERVER["REQUEST_URI"], 1);
$hashKey = $_SERVER['REMOTE_ADDR'] . ':' . $hash;
$hashKey = $ip . ':' . $hash;
$refr = isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : False;
if($refr != False){
@ -56,7 +57,12 @@
$dlCounter = $redis->get($hashKey);
if($dlCounter != FALSE) {
if($dlCounter >= _DL_CAPTCHA * 2){
http_response_code(444); //for tracking abuse
$cfbk = 'VC:CF:BLOCK';
if(_CLOUDFLARE_API_KEY != 'API_KEY' && $redis->sIsMember($cfbk, $ip) == False){
$redis->sadd($cfbk, $ip);
include_once('cloudflare.php');
AddFirewallRule($ip);
}
exit();
}else if($dlCounter >= _DL_CAPTCHA){
//redirect for captcha check