Saturday, September 7, 2024

PHP Ban IP to Cloudflare API Script

Usage:
Run the script periodically using a cron job (Linux) or Task Scheduler (Windows) to handle blocking and removal of expired blocks.

Ensure paths to logs and other configurations are updated to reflect your actual setup.

<?php
// Cloudflare API settings
$apiKey = "your_cloudflare_api_key"; // Global API Key
$authEmail = "your_cloudflare_email"; // Cloudflare account email
$zoneID = "your_zone_id"; // Zone ID
$logPath = "C:pathtoaccess.log"; // Path to Apache access log
$blockLogPath = "C:pathtoblock.log"; // Path to log block actions
$blockRemoveLogPath = "C:pathtoblock_remove.log"; // Path to log block removal actions
$threshold = 10; // Number of 404s to trigger a block
$timeWindowMinutes = 10; // Time window in minutes for analysis
$blockDurationHours = 1; // Duration to block IP in hours

// Current timestamp minus time window (in seconds)
$timeWindow = time() - ($timeWindowMinutes * 60);

// Function to log messages to a file
function logMessage($message, $logFilePath) {
    $timestamp = date('Y-m-d H:i:s');
    file_put_contents($logFilePath, "[$timestamp] $message" . PHP_EOL, FILE_APPEND);
}
[Read more...]

Subscribe

  • RSS Atom

ອອນລາຍ: 2 | ມື້ນີ້: 10 | ວານນີ້: 25 | ທິດນີ້: 90 | ເດືອນນີ້: 869 | ປີນີ້: 11829 | ລວມ: 78932