-
Notifications
You must be signed in to change notification settings - Fork 99
Kernel APIs
Shieldon\Firewall\Kernel
- ban
- getCurrentUrl
- managedBy
- run
- setClosure
- exclude
- setExcludedUrls
- setLogger
- setProperty
- setProperties
- setStrict
- unban
-
param
string
$ip-
Single IP address. -
return
void
Ban an IP address.
Example:
$kernel->ban('33.125.12.87');
-
return
string
Return current URL. This method equals $_SERVER['REQUEST_URI']
.
Example:
echo $kernel->getCurrentUrl();
-
param
string
$type""
managed | config | demo -
return
void
Tell Shieldon what type the Shieldon is managed by. This setting only influences the Firewall Panel.
Example:
$kernel->managedBy('demo');
-
return
int
Run the checking process.
Reponse code:
constant | value | reason |
---|---|---|
RESPONSE_DENY |
0 | Banned permanently. |
RESPONSE_ALLOW |
1 | Passed. |
RESPONSE_TEMPORARILY_DENY |
2 | Banned temporarily and can be unbaned by solving Captcha. |
RESPONSE_LIMIT |
3 | Stopped due to reaching online session limit. |
Example:
$result = $kernel->run();
-
param
string
$key-
The identification name of the closure. -
param
Closure
$closure-
The closure function. -
return
void
Set a closure function.
Example:
$kernel->setClosure('www_authenticate', function() use ($authHandler, $authenticateList) {
$authHandler->set($authenticateList);
$authHandler->check();
});
-
param
string
$uriPath-
The path component of a URI. -
return
void
Set a URL you want them excluded them from protection.
Example:
$kernel->exclude('/firewall/panel');
-
param
array
$urls-
The collection of URLs. -
return
void
Set the URLs you want them excluded them from protection.
Example:
$list = [
'/example/1',
'/wp-login.php',
];
$kernel->setExcludedUrls($list);
-
param
ActionLogger
$logger-
Record action logs for users. -
return
void
Set an action log logger.
Example:
$kernel->setLogger(
new \Shieldon\Firewall\Log\ActionLogger(
BOOTSTRAP_DIR . '/../tmp/shieldon'
)
);
-
param
string
$key-
The key name for the property. -
param
mixed
$value-
The value of the key. -
return
void
Example:
$kernel->setProperty('time_unit_quota', [
's' => 4,
'm' => 20,
'h' => 60,
'd' => 240,
]);
The explanation of settings you cand find here.
-
param
array
$settings-
The settings. -
return
void
Example:
$kernel->setProperties($settings);
-
param
bool
$bool-
Set true to enble strict mode, false to disable it overwise. -
return
void
Example:
$kernel->setStrict(true);
-
param
string
$ip-
An IP address. -
return
void
Unban an IP address.
Example:
$kernel->unban('33.33.33.33');
Shieldon\Firewall\Kernel\CaptchaTrait
- setCaptcha
- captchaResponse
- disableCaptcha
-
param
CaptchaInterface
$instance-
The Captcha instance. -
return
void
Set a captcha. For deatiled usages, please see Captcha section.
$kernel->setCaptcha(
new \Shieldon\Firewall\Captcha\Recaptcha([
'key' => '6LfkOaUUAAAAAH-AlTz3hRQ25SK8kZKb2hDRSwz9',
'secret' => '6LfkOaUUAAAAAJddZ6k-1j4hZC1rOqYZ9gLm0WQh',
'version' => 'v2',
'lang' => 'en',
])
);
-
return
bool
Return the result from Captchas.
true
: Captcha is solved successfully, false
overwise.
Example:
$result = $this->captchaResponsse();
-
return
void
Disable all Captcha modules. This method is for unit testing purpose.
Shieldon\Firewall\Kernel\ComponentTrait
- setComponent
- getComponent
- disableComponents
-
param
ComponentProvider
$instance-
The component instance. -
return
void
Set a commponent.
Example:
$kernel->setComponent(
new \Shieldon\Firewall\Component\UserAgent()
);
-
param
string
$name-
The component's class name. -
return
void
|ComponentProvider
Get a component instance from component's container.
Example:
$useragent = $kernel->getComponent('UserAgent');
-
return
void
Disable all components even they have been set up ready.
Example:
$kernel->disableComponents();
Shieldon\Firewall\Kernel\DriverTrait
- setDriver
- setChannel
- disableDbBuilder
-
param
DriverProvider
$driver-
Query data from the driver you choose. -
return
void
Example:
$dbLocation = APPPATH . 'cache/shieldon.sqlite3';
$pdoInstance = new \PDO('sqlite:' . $dbLocation);
$kernel->setDriver(
new \Shieldon\Firewall\Driver\SqliteDriver($pdoInstance)
);
-
param
string
$channel-
Specify a channel. -
return
void
Example:
$kernel->setChannel('web_project');
-
return
void
Disable building database automatically.
Example:
$kernel->disableDbBuilder();
Shieldon\Firewall\Kernel\FilterTrait
- setFilters
- setFilter
- disableFilters
-
param
array
$settings-
Filter settings. -
return
void
$kernel->setFilters([
'session' => true,
'cookie' => true,
'referer' => true,
'frequency' => true,
]);
-
param
string
$filterName-
The filter's name. -
param
bool
$value-
True for enabling the filter, overwise. -
return
void
Example:
$kernel->setFilter('session', false);
$kernel->setFilter('cookie', false);
$kernel->setFilter('referer', true);
$kernel->setFilter('frequency', false);
Default settings:
key | type | value | description |
---|---|---|---|
session | bool | true | Check session created by Shieldon session driver. |
cookie | bool | false | Check cookie generated by JavaScript. |
referer | bool | true | Check HTTP_REFERER
|
frequency | bool | true | Check time_unit_quota setting. |
The Cookie filter is false
by default, because you have to output the JavaScript snippet to your web pages. The snippet created by getJavascript()
will generate cookie by JavaScript.
Check out getJavascript()
for usage.
-
return
void
Disable all filters even they have been set up ready.
$kernel->disableFilters();
Shieldon\Firewall\IpTrait
- setIp
- getIp
- setRdns
- getRdns
-
param
string
$ip-
An IP address. -
return
void
Set an IP address.
Example:
// Here is an example, cature real vistor IP from CloudFlare.
$realIp = $_SERVER['HTTP_CF_CONNECTING_IP'];
// If you use a CDN serive on your website,
// make sure to cature the real vistor IP, overwise users will get banned.
$kernel->setIp($realIp);
-
return
string
Get current set IP.
Example:
$ip = $kernel->getIp();
-
param
string
$rdns-
Reserve DNS record for that IP address. -
return
void
Set a RDNS record for the check.
Example:
$kernel->setRdns('localhost');
-
return
string
Get IP resolved hostname.
$rdns = $kernel->getRdns();
Shieldon\Firewall\Kernel\MessengerTrait
- setMessenger
-
param
MessengerInterface
$instance-
The messenger instance. -
return
void
Example:
$apiKey = '981441296:AAGCcgv_NETMdWQCBTaMOk_yoMfax5EV7YQ';
$channel = '@your_channel';
$telegramMessenger = new \Messenger\Telegram($apiKey, $channel);
$kernel->setMessenger($telegramMessenger);
Shieldon\Firewall\Kernel\TemplateTrait
- setDialog
- respond
- setTemplateDirectory
- getJavascript
-
param
array
$settings-
The dialog UI settings. -
return
void
Customize the dialog UI.
Example:
$settings = [
'lang' => 'en',
'background_image' => '',
'bg_color' => '#ffffff',
'header_bg_color' => '#212531',
'header_color' => '#ffffff',
'shadow_opacity' => '0.2',
];
$kernel->setDialog($settings);
-
return
ResponseInterface
Respond the result.
Example:
$response = $kernel->respond();
-
param
array
$directory-
The directory in where the template files are placed. -
return
void
Set the frontend template directory. You can copy those files to a dictionary, and modify them for customizing the look of dialogs.
Example:
$kernel->setTemplateDirectory(YOUR_DIRECTORY_PATH);
-
return
string
Print a JavaScript snippet in your webpages.
This snippet generate cookie on client's browser,then we check the cookie to identify the client is a rebot or not.
// Output this variable in your page template.
$jsCode = $kernel->getJavascript();
Shieldon\Firewall\Kernel\SessionTrait
- limitSession
- getSessionCount
-
param
int
$count1000
The amount of online users. If reached, users will be in queue. -
param
int
$period300
The period of time allows users browsing. (unit: second) -
param
bool
$uniquefalse
Allow only one session per IP address. -
return
void
Limt online sessions.
Example:
$kernel->limitSession(100, 300);
-
return
int
Get online people count. If enable limitSession.
Example:
$count = $kernel->getSessionCount();
- Author: Terry L. from Taiwan.
- Website: shieldon.io
- GitHub repository: github.com/terrylinooo/shieldon
- WordPress plugin: wordpress.org/plugins/wp-shieldon/
Docs: Laravel, Symfony, CodeIgniter, CakePHP, Yii, Zend, Slim, Fat-Free, Fuel, PHPixie