freinir / zakarum
The package is designed to block unwanted traffic
Requires
- php: >=7.2.0
- sypex/geo: ^0.3.2
README
About
Zakarum is a protection layer that helps prevent unwanted access to your website from bots and automated traffic.
The protection is based on a set of rules that analyze incoming requests.
You can configure the built-in rules or add your own custom rules to extend the behavior.
The system is modular and rule-based, which allows flexible protection strategies depending on your project needs.
Installation
Install the package via Composer
`composer require freinir/ad-wizard`
Basic usage
Call the main class at any convenient place during your application initialization.
The protection system has a modular structure based on rules that must implement the RuleInterface.
If a request violates at least one rule, the user will be presented with a CAPTCHA challenge (ReCaptcha by default).
After successfully passing the CAPTCHA, a secret hash is stored in the client's cookies for 1 hour (the cookie lifetime is configurable).
$captcha = new Recaptcha('secretKey', 'publicKey');
$cookie = new CookieService('cookie_secret_salt', 3600, 'cookie_name');
$context = RequestContext::fromGlobals();
$guard = new Guard($context, $captcha, $cookie);
$ipList = (new IpCollectorDataProvider([
['127.0.0.1'],
(new GoogleIpDataProvider()) // optional
]))->getIpList();
$guard->inWhiteList($ipList);
$guard->checkRule((new RefererRule()), $context);
$guard->checkRule((new LanguageRule()), $context);
$badUserAgentRule = new UserAgentRule(['dotbot', '', '']);
$guard->checkRule($badUserAgentRule, $context);
$allowCountriesRule = new GeoIpRule(
["AU", "BY"],
__DIR__ . '/geoData/SxGeo.dat'
);
$guard->checkRule($allowCountriesRule, $context);