public static function getActiveBansTable() { if (isset(static::$_activeBans)) { return static::$_activeBans; } if (static::$_activeBans = Cache::fetch('bans')) { return static::$_activeBans; } static::$_activeBans = ['ips' => [], 'keys' => []]; foreach (Ban::getAllByWhere('ExpirationDate IS NULL OR ExpirationDate > CURRENT_TIMESTAMP') as $Ban) { if ($Ban->IP) { static::$_activeBans['ips'][] = long2ip($Ban->IP); } elseif ($Ban->KeyID) { static::$_activeBans['keys'][] = $Ban->KeyID; } } Cache::store('bans', static::$_activeBans, static::$tableCachePeriod); return static::$_activeBans; }
<?php namespace Gatekeeper; use Gatekeeper\Bans\Ban; $Key = $_EVENT['request']->getKey(); if ($Key && Ban::isKeyBanned($Key)) { \JSON::error('Your API key is currently banned from using this service', 403); }
<?php namespace Gatekeeper; use Gatekeeper\Bans\Ban; if (Ban::isIPAddressBanned($_SERVER['REMOTE_ADDR'])) { header('HTTP/1.1 403 Forbidden'); \JSON::error('Your IP address is currently banned from using this service'); }