mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-03-29 16:01:43 +01:00
Auto block abusers
This commit is contained in:
parent
2493eb7c3e
commit
e2e6bf0d0c
39
src/php/cloudflare.php
Normal file
39
src/php/cloudflare.php
Normal 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"]));
|
||||
}
|
||||
?>
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user