Skip to content

Commit

Permalink
Merge pull request #120 from julienloizelet/feat/timeout-config
Browse files Browse the repository at this point in the history
Feat/timeout config
  • Loading branch information
julienloizelet authored Dec 22, 2022
2 parents 31a4d9b + 8f02e1d commit 4485617
Show file tree
Hide file tree
Showing 31 changed files with 83 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/end-to-end-auto-prepend-test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

- name: Install DDEV
env:
DDEV_VERSION: v1.21.1
DDEV_VERSION: v1.21.4
run: |
# @see https://ddev.readthedocs.io/en/stable/#installationupgrade-script-linux-and-macos-armarm64-and-amd64-architectures
sudo apt-get -qq update
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/end-to-end-test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

- name: Install DDEV
env:
DDEV_VERSION: v1.21.1
DDEV_VERSION: v1.21.4
run: |
# @see https://ddev.readthedocs.io/en/stable/#installationupgrade-script-linux-and-macos-armarm64-and-amd64-architectures
sudo apt-get -qq update
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ jobs:
fi
- name: Create Tag ${{ github.event.inputs.tag_name }}
uses: actions/github-script@v3
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
script: |
github.git.createRef({
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/${{ github.event.inputs.tag_name }}",
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [1.11.0](https://github.com/crowdsecurity/cs-wordpress-bouncer/releases/tag/v1.11.0) - 2022-12-22
[_Compare with previous release_](https://github.com/crowdsecurity/cs-wordpress-bouncer/compare/v1.10.0...v1.11.0)

### Added
- Add LAPI request timeout setting (default to 120 seconds)
---

## [1.10.0](https://github.com/crowdsecurity/cs-wordpress-bouncer/releases/tag/v1.10.0) - 2022-12-01
[_Compare with previous release_](https://github.com/crowdsecurity/cs-wordpress-bouncer/compare/v1.9.0...v1.10.0)
### Changed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
},
"require": {
"crowdsec/bouncer": "0.34.0",
"crowdsec/bouncer": "0.35.0",
"symfony/polyfill-mbstring": "1.20.0",
"symfony/service-contracts": "2.4.1"
},
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crowdsec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://github.com/crowdsecurity/cs-wordpress-bouncer
* Description: Safer Together. Protect your WordPress application with CrowdSec.
* Tags: crowdsec-bouncer, wordpress, security, firewall, captcha, ip-scanner, ip-blocker, ip-blocking, ip-address, ip-database, ip-range-check, crowdsec, ban-hosts, ban-management, anti-hacking, hacker-protection, captcha-image, captcha-generator, captcha-generation, captcha-service
* Version: 1.10.0
* Version: 1.11.0
* Author: CrowdSec
* Author URI: https://www.crowdsec.net/
* Github: https://github.com/crowdsecurity/cs-wordpress-blocker
Expand All @@ -13,7 +13,7 @@
* Requires PHP: 7.2
* Requires at least: 4.9
* Tested up to: 6.1
* Stable tag: 1.10.0
* Stable tag: 1.11.0
* Text Domain: crowdsec-wp
* First release: 2021.
*/
Expand Down
12 changes: 2 additions & 10 deletions docs/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,8 @@ __We will suppose here that you want to install WordPress 5.9. Please change "5.

#### DDEV installation

This project is fully compatible with DDEV 1.21.1, and it is recommended to use this specific version.
For the DDEV installation, please follow the [official instructions](https://ddev.readthedocs.io/en/stable/#installation).
On a Linux distribution, you can run:
```
sudo apt-get -qq update
sudo apt-get -qq -y install libnss3-tools
curl -LO https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh
bash install_ddev.sh v1.21.1
rm install_ddev.sh
```
This project is fully compatible with DDEV 1.21.4, and it is recommended to use this specific version.
For the DDEV installation, please follow the [official instructions](https://ddev.readthedocs.io/en/stable/users/install/ddev-installation/).

### Prepare DDEV WordPress environment

Expand Down
9 changes: 9 additions & 0 deletions docs/USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,19 @@ By default, `file_get_contents` method is used to call Local API. This method re
Here, you can choose to use `cURL` requests instead. Beware that in this case, you need to have php `cURL` extension
installed and enabled on your system.


***

`Connection details → Local API request timeout`

By default, the maximum allowed time to perform a Local API request is 120 seconds. You can change this setting here.
If you set a negative value, request timeout will be unlimited.

![Connection details](images/screenshots/config-bouncing.jpg)

***


`Bouncing → Bouncing level`

Choose if you want to apply CrowdSec directives (`Normal bouncing`) or be more permissive (`Flex bouncing`).
Expand Down
Binary file modified docs/images/screenshots/config-connection-details.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion inc/Bounce.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getBouncerInstance(array $settings): Bouncer
'api_url' => $this->escape($this->getStringSettings('crowdsec_api_url')),
'use_curl' => $this->getBoolSettings('crowdsec_use_curl'),
'api_user_agent' => Constants::CROWDSEC_BOUNCER_USER_AGENT,
'api_timeout' => Constants::API_TIMEOUT,
'api_timeout' => $this->getIntegerSettings('crowdsec_api_timeout')?:Constants::API_TIMEOUT,
// Debug
'debug_mode' => $this->getBoolSettings('crowdsec_debug_mode'),
'disable_prod_log' => $this->getBoolSettings('crowdsec_disable_prod_log'),
Expand Down
2 changes: 1 addition & 1 deletion inc/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Constants extends LibConstants
public const CROWDSEC_DEBUG_LOG_PATH = __DIR__ . '/../logs/debug.log';
public const CROWDSEC_CACHE_PATH = __DIR__ . '/../.cache';
public const CROWDSEC_CONFIG_PATH = __DIR__ . '/standalone-settings.php';
public const CROWDSEC_BOUNCER_USER_AGENT = 'WordPress CrowdSec Bouncer/v1.10.0';
public const CROWDSEC_BOUNCER_USER_AGENT = 'WordPress CrowdSec Bouncer/v1.11.0';
public const CROWDSEC_BOUNCER_GEOLOCATION_DIR = __DIR__ . '/../geolocation';
public const CROWDSEC_BOUNCER_TLS_DIR = __DIR__ . '/../tls';

Expand Down
13 changes: 13 additions & 0 deletions inc/admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ function adminSettings()
'crowdsec_settings', 'crowdsec_admin_connection', function () {}, function () {}, '<p>If checked, calls to Local API will be done with <i>cURL</i> (be sure to have <i>cURL</i> enabled on your system before enabling).
<br>If not checked, calls are done with <i>file_get_contents</i> method (<i>allow_url_fopen</i> is required for this).</p>');

// Field "timeout"
addFieldString('crowdsec_api_timeout', 'Local API request timeout', 'crowdsec_plugin_settings', 'crowdsec_settings',
'crowdsec_admin_connection', function ($input) {
if ((int) $input === 0) {
add_settings_error('Local API timeout', 'crowdsec_error', 'Local API timeout: Must be different than 0.');

return Constants::API_TIMEOUT;
}

return (int) $input !== 0 ? (int) $input : Constants::API_TIMEOUT ;
}, ' seconds. <p>Maximum execution time (in seconds) for a Local API request.<br> Set a negative value (e.g. -1) to allow unlimited request timeout.<br>Default to ' . Constants::API_TIMEOUT .'.',
Constants::API_TIMEOUT, 'width: 115px;', 'number');

/************************************
** Section "Bouncing refinements" **
***********************************/
Expand Down
2 changes: 1 addition & 1 deletion inc/bouncer-instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function getDatabaseSettings(): array
'api_url' => esc_attr(get_option('crowdsec_api_url')),
'use_curl' => !empty(get_option('crowdsec_use_curl')),
'api_user_agent' => Constants::CROWDSEC_BOUNCER_USER_AGENT,
'api_timeout' => Constants::API_TIMEOUT,
'api_timeout' => (int)get_option('crowdsec_api_timeout') ?:Constants::API_TIMEOUT,
// Debug
'debug_mode' => !empty(get_option('crowdsec_debug_mode')),
'log_directory_path' => Constants::CROWDSEC_LOG_BASE_PATH,
Expand Down
1 change: 1 addition & 0 deletions inc/options-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function getCrowdSecOptionsConfig()
['name' => 'crowdsec_tls_ca_cert_path', 'default' => '', 'autoInit' => true],
['name' => 'crowdsec_api_key', 'default' => '', 'autoInit' => true],
['name' => 'crowdsec_use_curl', 'default' => '', 'autoInit' => true],
['name' => 'crowdsec_api_timeout', 'default' => Constants::API_TIMEOUT, 'autoInit' => true],
['name' => 'crowdsec_bouncing_level', 'default' => Constants::BOUNCING_LEVEL_DISABLED, 'autoInit' => true],
['name' => 'crowdsec_public_website_only', 'default' => 'on', 'autoInit' => true],
['name' => 'crowdsec_stream_mode', 'default' => '', 'autoInit' => true],
Expand Down
2 changes: 1 addition & 1 deletion inc/templates/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function updateTlsDisplay () {
?>
</form>
<h2><?php echo __("Test your settings");?></h2>
<p><?php echo __("Here you can check if your saved settings are correct.");?></p>
<p><?php echo __("Here you can check if your <b>saved</b> settings are correct.");?></p>
<p><?php echo __("Click the 'Test bouncing' button and the bouncer will try to get the remediation for the following IP:");?></p>
<form action="admin-post.php" method="post" id="crowdsec_action_test_connection">
<input type="hidden" name="action" value="crowdsec_test_connection"/>
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://crowdsec.net/
Tags: crowdsec-bouncer, wordpress, security, firewall, captcha, ip-scanner, ip-blocker, ip-blocking, ip-address, ip-database, ip-range-check, crowdsec, ban-hosts, ban-management, anti-hacking, hacker-protection, captcha-image, captcha-generator, captcha-generation, captcha-service
Requires at least: 4.9
Tested up to: 6.1
Stable tag: 1.10.0
Stable tag: 1.11.0
Requires PHP: 7.2
License: MIT
License URI: https://opensource.org/licenses/MIT
Expand Down Expand Up @@ -44,6 +44,10 @@ This WordPress plugin is a "bouncer", which purpose is to block detected attacks

== Changelog ==

= 1.11 (2022-12-22) =

- Add LAPI request timeout setting

= 1.10 (2022-12-01) =

- Modify ban and captcha walls templating for W3C validity
Expand Down
2 changes: 0 additions & 2 deletions tests/e2e-ddev/__tests__/1-activate-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const {
} = require("../utils/constants");

const {
waitForNavigation,
goToAdmin,
onLoginPageLoginAsAdmin,
wait,
Expand All @@ -32,7 +31,6 @@ describe(`Setup CrowdSec plugin`, () => {
await page.click('[aria-label="Activate CrowdSec"]');
}

await waitForNavigation;
await expect(page).toHaveText("#message", "Plugin activated.");
});
});
3 changes: 0 additions & 3 deletions tests/e2e-ddev/__tests__/4-live-mode-cache.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-undef */
const {
wait,
waitForNavigation,
goToAdmin,
onAdminGoToAdvancedPage,
onAdminSaveSettings,
Expand Down Expand Up @@ -29,7 +28,6 @@ describe(`Run in Live mode`, () => {
await goToAdmin();
await onAdminGoToAdvancedPage();
await page.click("#crowdsec_prune_cache");
await waitForNavigation;

await expect(page).toHaveText(
"#wpbody-content > div.wrap > div.notice.notice-success",
Expand All @@ -56,7 +54,6 @@ describe(`Run in Live mode`, () => {
await dialog.accept();
});
await page.click("#crowdsec_clear_cache");
await waitForNavigation;

await expect(page).toHaveText(
"#wpbody-content > div.wrap > div.notice.notice-success",
Expand Down
3 changes: 0 additions & 3 deletions tests/e2e-ddev/__tests__/5-stream-mode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable no-undef */
const {
waitForNavigation,
goToAdmin,
onAdminGoToAdvancedPage,
onAdminGoToSettingsPage,
Expand Down Expand Up @@ -49,7 +48,6 @@ describe(`Run in Stream mode`, () => {
await goToAdmin();
await onAdminGoToAdvancedPage();
await page.click("#crowdsec_refresh_cache");
await waitForNavigation;

await expect(page).toHaveText(
"#wpbody-content > div.wrap > div.notice.notice-success",
Expand Down Expand Up @@ -80,7 +78,6 @@ describe(`Run in Stream mode`, () => {
await goToAdmin();
await onAdminGoToAdvancedPage();
await page.click("#crowdsec_refresh_cache");
await waitForNavigation;

await expect(page).toHaveText(
"#wpbody-content > div.wrap > div.notice.notice-success",
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e-ddev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"jest-playwright-preset": "^1.4.3",
"jest-runner": "^26.6.3",
"lodash": "^4.17.21",
"playwright-chromium": "^1.26.1",
"playwright-chromium": "1.28.1",
"ws": "^7.4.6"
}
}
14 changes: 3 additions & 11 deletions tests/e2e-ddev/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,19 @@ const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

jest.setTimeout(TIMEOUT);

const waitForNavigation = page.waitForNavigation();

const goToAdmin = async () => {
await page.goto(ADMIN_URL);
await waitForNavigation;
};

const goToPublicPage = async () => {
await page.goto(`${BASE_URL}`);
await waitForNavigation;
};

const onAdminGoToSettingsPage = async () => {
// CrowdSec Menu
await page.click(
"#adminmenuwrap > #adminmenu > #toplevel_page_crowdsec_plugin > .wp-has-submenu > .wp-menu-name",
);
await waitForNavigation;
};

const onAdminGoToAdvancedPage = async () => {
Expand All @@ -42,7 +37,6 @@ const onAdminGoToAdvancedPage = async () => {
await page.click(
"#toplevel_page_crowdsec_plugin > ul > li:nth-child(4) > a",
);
await waitForNavigation;
await wait(1000);
await expect(page).toMatchTitle(/Advanced/);
};
Expand All @@ -53,23 +47,23 @@ const onAdminGoToThemePage = async () => {
await page.click(
"#toplevel_page_crowdsec_plugin > ul > li:nth-child(3) > a",
);
await waitForNavigation;
await wait(1000);

await expect(page).toMatchTitle(/Theme customization/);
};

const onLoginPageLoginAsAdmin = async () => {
await wait(2000);
await page.fill("#user_login", ADMIN_LOGIN);
await wait(2000);
await page.fill("#user_pass", ADMIN_PASSWORD);
await wait(2000);
await page.waitForSelector("#wp-submit");
await page.click("#wp-submit");
await waitForNavigation;
};

const onAdminSaveSettings = async (check = true) => {
await page.click("[type=submit]");
await waitForNavigation;

if (check) {
await expect(page).toHaveText(
Expand Down Expand Up @@ -201,7 +195,6 @@ const removeAllDecisions = async () => {

const onCaptchaPageRefreshCaptchaImage = async () => {
await page.click("#refresh_link");
await waitForNavigation;
};

const forceCronRun = async () => {
Expand Down Expand Up @@ -251,7 +244,6 @@ const setDefaultConfig = async () => {
module.exports = {
addDecision,
wait,
waitForNavigation,
goToAdmin,
goToPublicPage,
onAdminGoToSettingsPage,
Expand Down
Loading

0 comments on commit 4485617

Please sign in to comment.