Skip to content

Commit

Permalink
Fix coding style.
Browse files Browse the repository at this point in the history
  • Loading branch information
terrylinooo committed Jun 15, 2023
1 parent 9b487d7 commit 4021d66
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 79 deletions.
42 changes: 19 additions & 23 deletions config.php
Expand Up @@ -6,7 +6,7 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*
* Notice: This file is a sample file for configuration.
*/

Expand Down Expand Up @@ -118,7 +118,7 @@
| Filters
|--------------------------------------------------------------------------
|
| Filters are the soft rule-sets to detect bad-behavior requests then we
| Filters are the soft rule-sets to detect bad-behavior requests then we
| can "temporarily" ban them. (Unbannend by solving CAPTCHA by themselves.)
|
*/
Expand Down Expand Up @@ -171,7 +171,7 @@
| Components
|--------------------------------------------------------------------------
|
| Components are the hard rule-sets to detect bad-behavior requests then we
| Components are the hard rule-sets to detect bad-behavior requests then we
| can "permanently" ban them. (No CAPTCHA shows.)
|
| Each component provides its public APIs for further control.
Expand Down Expand Up @@ -237,8 +237,8 @@
'image' => [
'enable' => false,
'config' => [
'type' => 'alnum', // // alnum, alpha, numeric
'length' => 4
'type' => 'alnum', // // alnum, alpha, numeric
'length' => 4,
],
],
],
Expand All @@ -254,17 +254,17 @@

'ip_variable_source' => [
'REMOTE_ADDR' => true,
'HTTP_CF_CONNECTING_IP' => false,
'HTTP_X_FORWARDED_FOR' => false,
'HTTP_X_FORWARDED_HOST' => false
'HTTP_CF_CONNECTING_IP' => false,
'HTTP_X_FORWARDED_FOR' => false,
'HTTP_X_FORWARDED_HOST' => false,
],

/*
|--------------------------------------------------------------------------
| Online Session Limit
|--------------------------------------------------------------------------
|
| When the Online user count has reached the limit, other users not in the
| When the Online user count has reached the limit, other users not in the
| queue have to line up!
|
*/
Expand Down Expand Up @@ -329,7 +329,7 @@
'config' => [
'attacks' => 10,
'handler' => [
'type' => 'shieldon' // shieldon, iptable, utw (Ubuntu firewall).
'type' => 'shieldon', // shieldon, iptable, utw (Ubuntu firewall).
],
],
],
Expand Down Expand Up @@ -516,7 +516,7 @@
'recipients' => [
'user1@email.com',
'user2@email.com',
]
],
],
'confirm_test' => false,
],
Expand All @@ -542,7 +542,7 @@
'recipients' => [
'user1@email.com',
'user2@email.com',
]
],
],
'confirm_test' => false,
],
Expand All @@ -554,7 +554,7 @@
'recipients' => [
'user1@email.com',
'user2@email.com',
]
],
],
'confirm_test' => false,
],
Expand All @@ -571,7 +571,7 @@
'recipients' => [
'user1@email.com',
'user2@email.com',
]
],
],
'confirm_test' => false,
],
Expand All @@ -584,22 +584,18 @@
*/

'events' => [

'failed_attempts_in_a_row' => [

'data_circle' => [
'enable' => true,
'messenger' => true,
'buffer' => 10,
],

'system_firewall' => [
'enable' => true,
'messenger' => true,
'buffer' => 10,
]
]

],
],
],

/*
Expand All @@ -625,13 +621,13 @@
'enable' => false,
'config' => [
'watching_folder' => '',
]
],
],

'ip6tables' => [
'enable' => false,
'config' => [
'watching_folder' => '',
]
],
],
];
];
53 changes: 24 additions & 29 deletions src/Firewall/Firewall/SetupTrait.php
Expand Up @@ -84,15 +84,15 @@ abstract public function setConfig(string $field, $value): void;
abstract public function add(MiddlewareInterface $middleware): void;

/**
* Are database tables created?
* Are database tables created?
*
* @return bool
*/
abstract protected function hasCheckpoint(): bool;

/**
* Are database tables created?
*
*
* @param bool $create Is create the checkpoint file, or not.
*
* @return void
Expand All @@ -111,7 +111,8 @@ public function setupDriver(): void
$driverSetting = $this->getOption($driverType, 'drivers');

if (isset($driverSetting['directory_path'])) {
$driverSetting['directory_path'] = $driverSetting['directory_path'] ?: $this->directory . '/data_driver_' . $driverType;
$driverSetting['directory_path'] = $driverSetting['directory_path'] ?:
$this->directory . '/data_driver_' . $driverType;
}

$driverInstance = DriverFactory::getInstance($driverType, $driverSetting);
Expand Down Expand Up @@ -209,7 +210,7 @@ protected function setupFilters(): void

/**
* Components
*
*
* (1) Ip
* (2) Rdns
* (3) Header
Expand Down Expand Up @@ -249,7 +250,7 @@ protected function setupComponents(): void

/**
* Captcha modules.
*
*
* (1) Google ReCaptcha
* (2) Simple image captcha.
*
Expand All @@ -267,13 +268,12 @@ protected function setupCaptchas(): void

// Initialize messenger instances from the factory/
if (CaptchaFactory::check($setting)) {

$this->kernel->setCaptcha(
CaptchaFactory::getInstance(
// The ID of the captcha module in the configuration.
$captcha,
$captcha,
// The settings of the captcha module in the configuration.
$setting
$setting
)
);
}
Expand Down Expand Up @@ -302,7 +302,7 @@ protected function setupLogger(): void

/**
* Apply the denied list and the allowed list to Ip Component.
*
*
* @return void
*/
protected function setupAndApplyComponentIpManager(): void
Expand All @@ -313,11 +313,11 @@ protected function setupAndApplyComponentIpManager(): void
$deniedList = [];

foreach ($ipList as $ip) {
if (empty($ip))
if (empty($ip)) {
continue;
}

if (0 === strpos($this->kernel->getCurrentUrl(), empty($ip['url']) ? '/' : $ip['url']) ) {

if (0 === strpos($this->kernel->getCurrentUrl(), empty($ip['url']) ? '/' : $ip['url'])) {
if ('allow' === $ip['rule']) {
$allowedList[] = $ip['ip'];
}
Expand All @@ -328,10 +328,10 @@ protected function setupAndApplyComponentIpManager(): void
}
}

/** @scrutinizer ignore-call */
// @scrutinizer ignore-call
$this->kernel->component['Ip']->setAllowedItems($allowedList);

/** @scrutinizer ignore-call */
// @scrutinizer ignore-call
$this->kernel->component['Ip']->setDeniedItems($deniedList);
}

Expand All @@ -355,7 +355,6 @@ protected function setupIpSource(): void
$ip = $serverParams[$key];

if (empty($ip)) {

// @codeCoverageIgnoreStart
throw new RuntimeException(
'IP source is not set correctly.'
Expand All @@ -378,8 +377,8 @@ protected function setupDenyTooManyAttempts(): void
$this->kernel->setProperty(
'deny_attempt_enable',
[
'data_circle' => $setting['data_circle']['enable'], // false
'system_firewall' => $setting['system_firewall']['enable'], // false
'data_circle' => $setting['data_circle']['enable'], // false
'system_firewall' => $setting['system_firewall']['enable'], // false
]
);

Expand All @@ -397,12 +396,12 @@ protected function setupDenyTooManyAttempts(): void
$this->kernel->setProperty(
'record_attempt_detection_period',
$recordAttempt['detection_period'] // 5
);
);

$this->kernel->setProperty(
'reset_attempt_counter',
$recordAttempt['time_to_reset'] // 1800
);
);
}

/**
Expand Down Expand Up @@ -430,7 +429,6 @@ protected function setupLimitSession(): void
$sessionLimitSetting = $this->getOption('online_session_limit');

if ($sessionLimitSetting['enable']) {

$onlineUsers = $sessionLimitSetting['config']['count']; // default: 100
$alivePeriod = $sessionLimitSetting['config']['period']; // default: 300
$isUniqueIp = $sessionLimitSetting['config']['unique_only']; // false
Expand All @@ -445,17 +443,16 @@ protected function setupLimitSession(): void
*
* @return void
*/
protected function setupCronJob(): void
protected function setupCronJob(): void
{
$cronjobSetting = $this->getOption('reset_circle', 'cronjob');

if ($cronjobSetting['enable']) {

$nowTime = time();

$lastResetTime = $cronjobSetting['config']['last_update'];

if (!empty($lastResetTime) ) {
if (!empty($lastResetTime)) {
$lastResetTime = strtotime($lastResetTime);
} else {
// @codeCoverageIgnoreStart
Expand All @@ -466,7 +463,6 @@ protected function setupCronJob(): void
}

if (($nowTime - $lastResetTime) > $cronjobSetting['config']['period']) {

$updateResetTime = date('Y-m-d 00:00:00');

// Update new reset time.
Expand All @@ -478,7 +474,7 @@ protected function setupCronJob(): void
$this->updateConfig();

// Remove all logs.
/** @scrutinizer ignore-call */
// @scrutinizer ignore-call
$this->kernel->driver->rebuild();
}
}
Expand Down Expand Up @@ -523,9 +519,8 @@ protected function setupPageAuthentication(): void
*/
protected function setupDialogUserInterface()
{
Event::AddListener('session_init', function() {
Event::AddListener('session_init', function () {
$ui = $this->getOption('dialog_ui');

if (!empty($ui)) {
get_session_instance()->set('shieldon_ui_lang', $ui['lang']);
$this->kernel->setDialog($this->getOption('dialog_ui'));
Expand All @@ -535,8 +530,8 @@ protected function setupDialogUserInterface()
$dialogInfo = $this->getOption('dialog_info_disclosure');

$this->kernel->setProperty('display_online_info', $dialogInfo['online_user_amount']);
$this->kernel->setProperty('display_user_info', $dialogInfo['user_inforamtion']);
$this->kernel->setProperty('display_http_code', $dialogInfo['http_status_code']);
$this->kernel->setProperty('display_user_info', $dialogInfo['user_inforamtion']);
$this->kernel->setProperty('display_http_code', $dialogInfo['http_status_code']);
$this->kernel->setProperty('display_reason_code', $dialogInfo['reason_code']);
$this->kernel->setProperty('display_reason_text', $dialogInfo['reason_text']);
}
Expand Down

0 comments on commit 4021d66

Please sign in to comment.