Shieldon\Firewall\Kernel
$ip
)string
$ip -
Single IP address.void
Ban an IP address.
Example:
$kernel->ban('33.125.12.87');
string
Return current URL. This method equals $_SERVER['REQUEST_URI']
.
Example:
echo $kernel->getCurrentUrl();
$type
)string
$type ""
managed | config | demovoid
Tell Shieldon what type the Shieldon is managed by. This setting only influences the Firewall Panel.
Example:
$kernel->managedBy('demo');
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();
$key
, $closure
)string
$key -
The identification name of the closure.Closure
$closure -
The closure function.void
Set a closure function.
Example:
$kernel->setClosure('www_authenticate', function() use ($authHandler, $authenticateList) {
$authHandler->set($authenticateList);
$authHandler->check();
});
$uriPath
)string
$uriPath -
The path component of a URI.void
Set a URL you want them excluded them from protection.
Example:
$kernel->exclude('/firewall/panel');
$urls
)array
$urls -
The collection of URLs.void
Set the URLs you want them excluded them from protection.
Example:
$list = [
'/example/1',
'/wp-login.php',
];
$kernel->setExcludedUrls($list);
$logger
)ActionLogger
$logger -
Record action logs for users.void
Set an action log logger.
Example:
$kernel->setLogger(
new \Shieldon\Firewall\Log\ActionLogger(
BOOTSTRAP_DIR . '/../tmp/shieldon'
)
);
$key
, $value
)string
$key -
The key name for the property.mixed
$value -
The value of the key.void
Example:
$kernel->setProperty('time_unit_quota', [
's' => 4,
'm' => 20,
'h' => 60,
'd' => 240,
]);
The explanation of settings you cand find here.
$settings
)array
$settings -
The settings.void
Example:
$kernel->setProperties($settings);
$bool
)bool
$bool -
Set true to enble strict mode, false to disable it overwise.void
Example:
$kernel->setStrict(true);
$ip
)string
$ip -
An IP address.void
Unban an IP address.
Example:
$kernel->unban('33.33.33.33');
Shieldon\Firewall\Kernel\CaptchaTrait
$instance
)CaptchaInterface
$instance -
The Captcha instance.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',
])
);
bool
Return the result from Captchas.
true
: Captcha is solved successfully, false
overwise.
Example:
$result = $this->captchaResponsse();
void
Disable all Captcha modules. This method is for unit testing purpose.
Shieldon\Firewall\Kernel\ComponentTrait
$instance
)ComponentProvider
$instance -
The component instance.void
Set a commponent.
Example:
$kernel->setComponent(
new \Shieldon\Firewall\Component\UserAgent()
);
string
$name -
The component's class name.void
| ComponentProvider
Get a component instance from component's container.
Example:
$useragent = $kernel->getComponent('UserAgent');
void
Disable all components even they have been set up ready.
Example:
$kernel->disableComponents();
Shieldon\Firewall\Kernel\DriverTrait
$driver
)DriverProvider
$driver -
Query data from the driver you choose.void
Example:
$dbLocation = APPPATH . 'cache/shieldon.sqlite3';
$pdoInstance = new \PDO('sqlite:' . $dbLocation);
$kernel->setDriver(
new \Shieldon\Firewall\Driver\SqliteDriver($pdoInstance)
);
$channel
)string
$channel -
Specify a channel.void
Example:
$kernel->setChannel('web_project');
void
Disable building database automatically.
Example:
$kernel->disableDbBuilder();
Shieldon\Firewall\Kernel\FilterTrait
$settings
)array
$settings -
Filter settings.void
$kernel->setFilters([
'session' => true,
'cookie' => true,
'referer' => true,
'frequency' => true,
]);
$filterName
, $value
)string
$filterName -
The filter's name.bool
$value -
True for enabling the filter, overwise.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.
void
Disable all filters even they have been set up ready.
$kernel->disableFilters();
Shieldon\Firewall\IpTrait
$ip
)string
$ip -
An IP address.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);
string
Get current set IP.
Example:
$ip = $kernel->getIp();
$rdns
)string
$rdns -
Reserve DNS record for that IP address.void
Set a RDNS record for the check.
Example:
$kernel->setRdns('localhost');
string
Get IP resolved hostname.
$rdns = $kernel->getRdns();
Shieldon\Firewall\Kernel\MessengerTrait
$instance
)MessengerInterface
$instance -
The messenger instance.void
Example:
$apiKey = '981441296:AAGCcgv_NETMdWQCBTaMOk_yoMfax5EV7YQ';
$channel = '@your_channel';
$telegramMessenger = new \Messenger\Telegram($apiKey, $channel);
$kernel->setMessenger($telegramMessenger);
Shieldon\Firewall\Kernel\TemplateTrait
$settings
)array
$settings -
The dialog UI settings.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);
ResponseInterface
Respond the result.
Example:
$response = $kernel->respond();
$directory
)array
$directory -
The directory in where the template files are placed.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);
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
$count
, $period
, $unique
)int
$count 1000
The amount of online users. If reached, users will be in queue.int
$period 300
The period of time allows users browsing. (unit: second)bool
$unique false
Allow only one session per IP address.void
Limt online sessions.
Example:
$kernel->limitSession(100, 300);
int
Get online people count. If enable limitSession.
Example:
$count = $kernel->getSessionCount();