Skip to content

Commit 8338134

Browse files
Merge pull request #103 from julienloizelet/feat/test-connexion-button
Feat/test connexion button
2 parents ac3d3f0 + e35214b commit 8338134

File tree

10 files changed

+64
-6
lines changed

10 files changed

+64
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
8+
## [1.6.0] - 2022-06-30
9+
10+
### Added
11+
- Add "Test bouncing" action in settings view
12+
713
## [1.5.1] - 2022-06-24
814

915
### Added

crowdsec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin URI: https://github.com/crowdsecurity/cs-wordpress-bouncer
55
* Description: Safer Together. Protect your WordPress application with CrowdSec.
66
* 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
7-
* Version: 1.5.1
7+
* Version: 1.6.0
88
* Author: CrowdSec
99
* Author URI: https://www.crowdsec.net/
1010
* Github: https://github.com/crowdsecurity/cs-wordpress-blocker
@@ -13,7 +13,7 @@
1313
* Requires PHP: 7.2
1414
* Requires at least: 4.9
1515
* Tested up to: 6.0
16-
* Stable tag: 1.5.1
16+
* Stable tag: 1.6.0
1717
* Text Domain: crowdsec-wp
1818
* First release: 2021.
1919
*/

docs/USER_GUIDE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ mode makes it possible to never ban an IP but only to offer a Captcha, in the wo
9696

9797
If enabled, the admin is not bounced.
9898

99+
***
100+
101+
`Test your settings`
102+
103+
Click the "Test bouncing" button and the configured bouncer will try to get the remediation (bypass, captcha or ban)
104+
for
105+
the IP entered in the text field. By default, tested IP is the current detected remote IP.
106+
107+
This test allows you to know if your connection, bouncing and cache settings are correct.
108+
109+
99110
***
100111

101112

18.4 KB
Loading

inc/admin/init.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,27 @@ function pruneBouncerCacheInAdminPage()
104104
}
105105
}
106106

107+
function testBouncerConnexionInAdminPage($ip)
108+
{
109+
try {
110+
$settings = getDatabaseSettings();
111+
$bouncer = getBouncerInstance($settings);
112+
$remediation = $bouncer->getRemediationForIp($ip);
113+
$message = __("Bouncing has been successfully tested for IP: $ip. Result is: $remediation.");
114+
115+
AdminNotice::displaySuccess($message);
116+
} catch (BouncerException $e) {
117+
getCrowdSecLoggerInstance()->error('', [
118+
'type' => 'WP_EXCEPTION_WHILE_TESTING_CONNECTION',
119+
'message' => $e->getMessage(),
120+
'code' => $e->getCode(),
121+
'file' => $e->getFile(),
122+
'line' => $e->getLine(),
123+
]);
124+
AdminNotice::displayError('Technical error while testing bouncer connection: '.$e->getMessage());
125+
}
126+
}
127+
107128
// ACTIONS
108129
add_action('admin_post_crowdsec_clear_cache', function () {
109130
if (
@@ -132,6 +153,16 @@ function pruneBouncerCacheInAdminPage()
132153
header("Location: {$_SERVER['HTTP_REFERER']}");
133154
exit(0);
134155
});
156+
add_action('admin_post_crowdsec_test_connection', function () {
157+
if (
158+
!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'crowdsec_test_connection')) {
159+
die('This link expired.');
160+
}
161+
$ip = isset($_POST['crowdsec_test_connection_ip']) ? $_POST['crowdsec_test_connection_ip'] : $_SERVER['REMOTE_ADDR'];
162+
testBouncerConnexionInAdminPage($ip);
163+
header("Location: {$_SERVER['HTTP_REFERER']}");
164+
exit(0);
165+
});
135166

136167
// THEME
137168
add_action('admin_enqueue_scripts', function () {

inc/admin/settings.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ function adminSettings()
2525
/************************************
2626
** Section "Bouncing refinements" **
2727
***********************************/
28-
2928
add_settings_section('crowdsec_admin_boucing', 'Bouncing', function () {
3029
echo 'Refine bouncing according to your needs.';
3130
}, 'crowdsec_settings');

inc/constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ function crowdsecDefineConstants(string $crowdsecRandomLogFolder)
88
define('CROWDSEC_DEBUG_LOG_PATH', __DIR__."/../logs/$crowdsecRandomLogFolder/debug.log");
99
define('CROWDSEC_CACHE_PATH', __DIR__.'/../.cache');
1010
define('CROWDSEC_CONFIG_PATH', __DIR__.'/standalone-settings.php');
11-
define('CROWDSEC_BOUNCER_USER_AGENT', 'WordPress CrowdSec Bouncer/v1.5.1');
11+
define('CROWDSEC_BOUNCER_USER_AGENT', 'WordPress CrowdSec Bouncer/v1.6.0');
1212
}
1313
}

inc/templates/settings.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212
submit_button();
1313
?>
1414
</form>
15+
<h2><?php echo __("Test your settings");?></h2>
16+
<p><?php echo __("Here you can check if your saved settings are correct.");?></p>
17+
<p><?php echo __("Click the 'Test bouncing' button and the bouncer will try to get the remediation for the following IP:");?></p>
18+
<form action="admin-post.php" method="post" id="crowdsec_action_test_connection">
19+
<input type="hidden" name="action" value="crowdsec_test_connection"/>
20+
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce('crowdsec_test_connection'); ?>"/>
21+
<input type="text" name="crowdsec_test_connection_ip" value="<?php echo $_SERVER['REMOTE_ADDR'];?>"/>
22+
<?php
23+
submit_button('Test bouncing', 'secondary');
24+
?>
25+
</form>
1526
<p>
1627
Feel free to ask any questions about this plugin, make your suggestions or raise issues on the <a href="https://wordpress.org/support/plugin/crowdsec/">plugin support page</a> or directly on <a href="https://github.com/crowdsecurity/cs-wordpress-bouncer/issues/new">Github</a>.
1728
</p>

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://crowdsec.net/
44
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
55
Requires at least: 4.9
66
Tested up to: 6.0
7-
Stable tag: 1.5.1
7+
Stable tag: 1.6.0
88
Requires PHP: 7.2
99
License: MIT
1010
License URI: https://opensource.org/licenses/MIT

tests/e2e-ddev/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"jest-playwright-preset": "^1.4.3",
2424
"jest-runner": "^26.6.3",
2525
"lodash": "^4.17.21",
26-
"playwright-chromium": "^1.7.1",
26+
"playwright-chromium": "1.22.2",
2727
"soap": "^0.42.0",
2828
"ws": "^7.4.6"
2929
}

0 commit comments

Comments
 (0)