Skip to content

Commit e04ea28

Browse files
authored
Merge pull request #2 from crowdsecurity/current-features
release preparation
2 parents fa6b1e6 + ebba53e commit e04ea28

File tree

13 files changed

+92
-53
lines changed

13 files changed

+92
-53
lines changed

.github/workflows/build_package.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

crowdsec.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44
Plugin URI: https://www.crowdsec.net/
55
Description: Safer Together. Protect your WordPress application with CrowdSec.
66
Tags: security, firewall, malware scanner, two factor authentication, captcha, waf, web app firewall, mfa, 2fa
7-
Version 0.0.1
7+
Version 0.1.0
88
Author: CrowdSec
99
Author URI: https://www.crowdsec.net/
1010
Github: https://github.com/crowdsecurity/cs-wordpress-blocker
1111
License: MIT
1212
Requires PHP: 7.2
13-
Stable tag: 0.0.1
13+
Stable tag: 0.1.0
1414
Text Domain: crowdsec-wp
1515
*/
1616

17-
// TODO P2 check WP minimum compatible version + add a tag: "Requires at least: X.Y"
18-
// TODO P2 check WP maximum compatible version + add a tag: "Tested up to: 4.8"
19-
2017

2118
session_start();
2219
require_once __DIR__ . '/vendor/autoload.php';

docs/contribute.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,29 @@ docker-compose down
8080
docker images | grep wordpress-bouncer_web # to get the container id
8181
docker rmi 145c1ed0e4df
8282
CS_WORDPRESS_BOUNCER_PHP_VERSION=7.2 docker-compose up -d --build --force-recreate
83+
```
84+
85+
#### New feature
86+
87+
```bash
88+
git checkout -b <branch-name>
89+
git commit # as much as necessary.
90+
91+
# Rename branch if necessary
92+
git branch -m <new-name>
93+
git push origin :<old-name> && git push origin <new-name>
94+
95+
# Create PR
96+
gh pr create --fill
97+
```
98+
99+
After the merge, don't forget to delete to branch.
100+
101+
#### New release
102+
103+
```bash
104+
git checkout main && git pull
105+
git describe --tags `git rev-list --tags --max-count=1` # to verify what is the current tag
106+
export NEW_GIT_VERSION_WITHOUT_V_PREFIX= #...X.X.X
107+
./scripts/publish-release.sh
83108
```

inc/admin/advanced-settings.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ function adminAdvancedSettings()
5555
addFieldSelect('crowdsec_cache_system', 'Technology', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_cache', function ($input) {
5656
if (!in_array($input, [CROWDSEC_CACHE_SYSTEM_PHPFS, CROWDSEC_CACHE_SYSTEM_REDIS, CROWDSEC_CACHE_SYSTEM_MEMCACHED])) {
5757
$input = CROWDSEC_CACHE_SYSTEM_PHPFS;
58-
// TODO P3 throw error
58+
add_settings_error("Technology", "crowdsec_error", "Technology: Incorrect cache technology selected.");
5959
}
6060

61-
// TODO P1 big bug: fatal error when changing techno without dsn already set at previous state. Quick fix: Add error if no dsn and ask to set dsn then save then select techno.
62-
6361
$bouncer = getBouncerInstance();
6462
$bouncer->clearCache();
6563
$message = __('Cache system changed. Previous cache data has been cleared.');
@@ -86,13 +84,11 @@ function adminAdvancedSettings()
8684

8785
// Field "crowdsec_redis_dsn"
8886
addFieldString('crowdsec_redis_dsn', 'Redis DSN<br>(if applicable)', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_cache', function ($input) {
89-
// TODO P2 check if it's a valid DSN
9087
return $input;
9188
}, '<p>Fill in this field only if you have chosen the Redis cache.<br>Example of DSN: redis://localhost:6379.', 'redis://...', '');
9289

9390
// Field "crowdsec_memcached_dsn"
9491
addFieldString('crowdsec_memcached_dsn', 'Memcached DSN<br>(if applicable)', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_cache', function ($input) {
95-
// TODO P2 check if it's a valid DSN
9692
return $input;
9793
}, '<p>Fill in this field only if you have chosen the Memcached cache.<br>Example of DSN: memcached://localhost:11211.', 'memcached://...', '');
9894

@@ -127,11 +123,21 @@ function adminAdvancedSettings()
127123
foreach (Constants::ORDERED_REMEDIATIONS as $remediation) {
128124
$choice[$remediation] = $remediation;
129125
}
130-
addFieldSelect('crowdsec_fallback_remediation', 'Fallback to', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_cache', function ($input) {
126+
addFieldSelect('crowdsec_fallback_remediation', 'Fallback to', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_remediations', function ($input) {
131127
if (!in_array($input, Constants::ORDERED_REMEDIATIONS)) {
132128
$input = CROWDSEC_BOUNCING_LEVEL_DISABLED;
133-
// TODO P3 throw error
129+
add_settings_error("Fallback to", "crowdsec_error", "Fallback to: Incorrect Fallback selected.");
134130
}
135131
return $input;
136132
}, '<p>Which remediation to apply when CrowdSec advises unhandled remediation.</p>', $choice);
133+
134+
// Field "crowdsec_hide_mentions"
135+
addFieldCheckbox('crowdsec_hide_mentions', 'Hide CrowdSec mentions', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_remediations', function () {
136+
// Stream mode just activated.
137+
scheduleBlocklistRefresh();
138+
}, function () {
139+
// Stream mode just deactivated.
140+
unscheduleBlocklistRefresh();
141+
}, '
142+
<p>Enable if you want to hide CrowdSec mentions on the Ban and Captcha pages</p>');
137143
}

inc/admin/init.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ function clearBouncerCacheInAdminPage()
2424

2525
AdminNotice::displaySuccess($message);
2626

27-
// TODO P3 i18n the whole lib https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/
2827
} catch (WordpressCrowdSecBouncerException $e) {
2928
getCrowdSecLoggerInstance()->error(null, [
3029
'type' => 'WP_EXCEPTION_WHILE_CLEARING_CACHE',

inc/admin/settings.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ function adminSettings()
1515

1616
// Field "crowdsec_api_url"
1717
addFieldString('crowdsec_api_url', 'LAPI URL', 'crowdsec_plugin_settings', 'crowdsec_settings', 'crowdsec_admin_connection', function ($input) {
18-
// P2 TODO ping API to see if it's available if not: add_settings_error("LAPI URL", "crowdsec_error", "LAPI URL " . $input . " is not reachable.");
1918
return $input;
2019
}, '<p>If the CrowdSec Agent is installed on this server, you will set this field to http://localhost:8080.</p>', 'Your LAPI URL', '');
2120

2221

2322
// Field "crowdsec_api_key"
2423
addFieldString('crowdsec_api_key', 'Bouncer API key', 'crowdsec_plugin_settings', 'crowdsec_settings', 'crowdsec_admin_connection', function ($input) {
25-
// TODO check api key format / ping api if not: add_settings_error("LAPI URL", "crowdsec_error", "LAPI URL " . $input . " is not reachable.");
2624
return $input;
2725
}, '<p>Generated with the cscli command, ex: <em>cscli bouncers add wordpress-bouncer</em></p>', 'Your bouncer key', 'width: 280px;', 'text');
2826

@@ -43,7 +41,7 @@ function adminSettings()
4341
CROWDSEC_BOUNCING_LEVEL_PARANOID
4442
])) {
4543
$input = CROWDSEC_BOUNCING_LEVEL_DISABLED;
46-
// TODO P3 throw error
44+
add_settings_error("Bouncing level", "crowdsec_error", "Bouncing level: Incorrect bouncing level selected.");
4745
}
4846
return $input;
4947
}, '<p>
@@ -52,13 +50,13 @@ function adminSettings()
5250
<li><strong>Bouncing disabled</strong>: No ban or Captcha display to users. The road is free, even for attackers.</li>
5351
<li><strong>Flex bouncing</strong>: Display Captcha only, even if CrowdSec advises to ban the IP.</li>
5452
<li><strong>Normal bouncing</strong>: Follow CrowdSec advice (Ban or Captcha).</li>
55-
<li><strong>Paranoid mode</strong>: Ban IPs when there are in the CrowdSec database, even if CrowdSec advises to display a Captcha.</li>
53+
<!--<li><strong>Paranoid mode</strong>: Ban IPs when there are in the CrowdSec database, even if CrowdSec advises to display a Captcha.</li>-->
5654
</ul>
5755
</p>', [
5856
CROWDSEC_BOUNCING_LEVEL_DISABLED => '🚫 Bouncing disabled',
5957
CROWDSEC_BOUNCING_LEVEL_FLEX => '😎 Flex bouncing',
6058
CROWDSEC_BOUNCING_LEVEL_NORMAL => '🛡️ Normal bouncing',
61-
CROWDSEC_BOUNCING_LEVEL_PARANOID => '🕵️ Paranoid mode',
59+
//CROWDSEC_BOUNCING_LEVEL_PARANOID => '🕵️ Paranoid mode',
6260
]);
6361

6462

inc/bounce-current-ip.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ function bounceCurrentIp()
1111
function displayCaptchaWall()
1212
{
1313
header('HTTP/1.0 401 Unauthorized');
14-
echo Bouncer::getCaptchaHtmlTemplate($_SESSION["crowdsec_captcha_resolution_failed"], $_SESSION['crowdsec_captcha_inline_image'], '');
14+
echo Bouncer::getCaptchaHtmlTemplate($_SESSION["crowdsec_captcha_resolution_failed"], $_SESSION['crowdsec_captcha_inline_image'], '', !get_option('crowdsec_hide_mentions'));
1515
die();
1616
}
1717

1818
function handleBanRemediation()
1919
{
2020
header('HTTP/1.0 403 Forbidden');
21-
echo Bouncer::getAccessForbiddenHtmlTemplate();
21+
echo Bouncer::getAccessForbiddenHtmlTemplate(!get_option('crowdsec_hide_mentions'));
2222
die();
2323
}
2424

@@ -128,7 +128,7 @@ function handleRemediation(string $remediation, string $ip)
128128
$remediation = $bouncer->getRemediationForIp($ip);
129129
handleRemediation($remediation, $ip);
130130
} catch (WordpressCrowdSecBouncerException $e) {
131-
// TODO log error for debug mode only.
131+
132132
}
133133
}
134134
}

inc/bouncer-instance.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ function getCacheAdapterInstance(string $forcedCacheSystem = null): AbstractAdap
5757
$redisDsn = esc_attr(get_option('crowdsec_redis_dsn'));
5858
if (empty($redisDsn)) {
5959
throw new WordpressCrowdSecBouncerException('Redis selected but no DSN provided.');
60-
// TODO P2 fix: when redis is selected and the dsn is filled at the same moment, this error is thrown or it should not be.
6160
}
6261
return new RedisAdapter(RedisAdapter::createConnection($redisDsn));
6362
}
@@ -101,7 +100,6 @@ function getBouncerInstance(string $forcedCacheSystem = null): Bouncer
101100
break;
102101
case CROWDSEC_BOUNCING_LEVEL_PARANOID:
103102
$maxRemediationLevel = Constants::REMEDIATION_BAN;
104-
// TODO P2 add "minimum remediation" feature in lib + set it to ban in this case
105103
break;
106104
default:
107105
throw new Exception("Unknown $bouncingLevel");
@@ -110,13 +108,12 @@ function getBouncerInstance(string $forcedCacheSystem = null): Bouncer
110108
$logger = getCrowdSecLoggerInstance();
111109

112110
// Instanciate the bouncer
113-
$bouncer = new Bouncer($logger);
114111
$cacheAdapter = getCacheAdapterInstance($forcedCacheSystem);
112+
$bouncer = new Bouncer($cacheAdapter, $logger);
115113
$bouncer->configure([
116114
'api_key' => $apiKey,
117115
'api_url' => $apiUrl,
118116
'api_user_agent' => CROWDSEC_BOUNCER_USER_AGENT,
119-
//'api_timeout' => null // TODO P3 make a advanced settings
120117
'live_mode' => !$isStreamMode,
121118
'max_remediation_level' => $maxRemediationLevel,
122119
'fallback_remediation' => $fallbackRemediation,

inc/constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
define('CROWDSEC_CAPTCHA_TECHNOLOGY_LOCAL', "local");
1616
define('CROWDSEC_CAPTCHA_TECHNOLOGY_RECAPTCHA', "recaptcha");
1717

18-
define('CROWDSEC_BOUNCER_USER_AGENT', "Wordpress CrowdSec Bouncer/0.0.1");// TODO P1 SET THE CORRECT VERSION ON BUILD
18+
define('CROWDSEC_BOUNCER_USER_AGENT', "Wordpress CrowdSec Bouncer/v0.1.0");

inc/plugin-setup.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ function activate_crowdsec_plugin()
2828
update_option("crowdsec_clean_ip_cache_duration", Constants::CACHE_EXPIRATION_FOR_CLEAN_IP);
2929
update_option("crowdsec_bad_ip_cache_duration", Constants::CACHE_EXPIRATION_FOR_BAD_IP);
3030
update_option("crowdsec_fallback_remediation", Constants::REMEDIATION_CAPTCHA);
31+
32+
update_option("crowdsec_hide_mentions", false);
3133
}
3234

3335

@@ -67,4 +69,6 @@ function deactivate_crowdsec_plugin()
6769
delete_option("crowdsec_clean_ip_cache_duration");
6870
delete_option("crowdsec_bad_ip_cache_duration");
6971
delete_option("crowdsec_fallback_remediation");
72+
73+
delete_option("crowdsec_hide_mentions");
7074
}

0 commit comments

Comments
 (0)