Skip to content

Commit 1f2eb75

Browse files
committed
Merge branch 'hotfix/v0.3.1' into develop
2 parents 34dfe76 + e81ddf9 commit 1f2eb75

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

README.md

+8-13
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
:speech_balloon: <a href="https://gitter.im/crowdsec-project/community?utm_source=share-link&utm_medium=link&utm_campaign=share-link">Gitter Chat</a>
2020
</p>
2121

22-
> This library allows you to create CrowdSec bouncers for PHP applications or frameworks like e-commerce, blog or other exposed applications.
22+
This library allows you to create CrowdSec bouncers for PHP applications or frameworks like e-commerce, blog or other exposed applications.
2323

2424
## Features
2525

2626
- ✅ Fast API client
27-
- ✅ LAPI Support (CAPI not supported yet)
27+
- ✅ LAPI Support ([CAPI not supported yet](https://github.com/crowdsecurity/php-cs-bouncer#future))
2828
- ✅ Built-in support for the most known cache systems like Redis, Memcached, PhpFiles
2929
-**Live mode** or **Stream mode**
3030
- ✅ Events logged using monolog
@@ -33,14 +33,14 @@
3333
- ✅ Clear and prune the cache
3434
## Getting started
3535

36-
### Installing CrowdSec Bouncer library
37-
3836
The recommended way to install CrowdSec Bouncer library is through [Composer](https://getcomposer.org/).
3937

4038
```bash
4139
composer require crowdsec/bouncer
4240
```
4341

42+
In your PHP project, just add these lines to verify an IP:
43+
4444
```php
4545

4646
/* To get a bouncer api key: "cscli bouncers add <name-of-your-php-bouncer> */
@@ -55,21 +55,16 @@ $bouncer->configure(['api_key'=> $bouncerApiKey], $cacheAdapter);
5555
$remediation = $bouncer->getRemediationForIp($blockedIp);// Return "ban", "captcha" or "bypass"
5656
```
5757

58-
View [`docs/getting-started.md`](https://github.com/crowdsecurity/php-cs-bouncer/blob/main/docs/complete-guide.md) to learn how to include this library in your project in minutes.
58+
View [`docs/complete-guide.md`](https://github.com/crowdsecurity/php-cs-bouncer/blob/main/docs/complete-guide.md) to learn how to include this library in your project in minutes.
5959

6060
## Future
61-
- Retrieve cache items with pagination
62-
- Release 1.0.0 version
63-
- Direct CAPI support
64-
- Support more cache systems (Apcu, Couchbase, Doctrine, Pdo)
61+
- Retrieve decisions stored in cache using pagination
62+
- Direct CAPI support (no LAPI required)
63+
- Support more cache systems (Apcu, Couchbase, Doctrine -SQL or MongoDB-, Pdo...)
6564
- Publish load tests (compare performances)
6665
- Report Code coverage
6766
- Setup Xdebug environment with Docker
6867

6968
## Licence
7069

7170
[MIT License](https://github.com/crowdsecurity/php-cs-bouncer/blob/main/LICENSE)
72-
73-
## Licence
74-
75-
[MIT License](https://github.com/crowdsecurity/php-cs-bouncer/blob/main/LICENSE)

docs/complete-guide.md

+20-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# CrowdSec PHP Bouncer
1+
# The complete guide
2+
3+
Discover the CrowdSec Bouncer Library for PHP.
24

35
Here is the complete guide to learning how to use the [Bouncer CrowdSec library developed in PHP](https://github.com/crowdsecurity/php-cs-bouncer).
46

@@ -46,7 +48,7 @@ Also create a `docker-compose.yml` file containing two instances, the **PHP CLI*
4648
```yml
4749
version: "3"
4850
services:
49-
php:
51+
app:
5052
build:
5153
context: .
5254
dockerfile: ./Dockerfile
@@ -75,15 +77,15 @@ echo "BOUNCER_KEY=`docker-compose exec crowdsec /usr/local/bin/cscli bouncers ad
7577
Init the `composer.json` and download the `crowdsec/bouncer` library (just wait a short moment for the first docker image build)
7678

7779
```bash
78-
docker-compose run php composer init --no-interaction --require crowdsec/bouncer:^0
79-
docker-compose run php composer install
80+
docker-compose run app composer init --no-interaction --require crowdsec/bouncer:^0
81+
docker-compose run app composer install
8082
```
8183

82-
## Now let's try your first IP verification!
84+
## Now let's verify your first IP!
8385

8486
Now that the setup is done, you'll enjoy making your first IP verification!
8587

86-
For that, create a short `check-ip.php` script:
88+
For that, create this short `check-ip.php` script:
8789

8890
```php
8991
<?php
@@ -124,7 +126,7 @@ echo "\nResult: $remediation\n\n"; // "ban", "captcha" or "bypass"
124126
Now run the php script:
125127

126128
```bash
127-
docker-compose run php php check-ip.php 1.2.3.4
129+
docker-compose run app php check-ip.php 1.2.3.4
128130
```
129131

130132
Congrats! You successfully obtain remediation about the requested IP from LAPI.
@@ -137,30 +139,30 @@ Let's now add a new decision in CrowdSec, for example we will ban the 2.3.4.5/30
137139
docker-compose exec crowdsec /usr/local/bin/cscli decisions add --range 2.3.4.5/30 --duration 4h --type ban
138140
```
139141

140-
If now, you run the php script against the `2.3.4.5` IP:
142+
Now, if you run the php script against the `2.3.4.5` IP:
141143

142144
```bash
143-
docker-compose run php php check-ip.php 2.3.4.5
145+
docker-compose run app php check-ip.php 2.3.4.5
144146
```
145147

146148
LAPI will advise you to ban this IP as it's within the 2.3.4.5/30 range.
147149

148150
## The cache system
149151

150-
If you script this script twice, LAPI will not be called, the cache system will relay the information.
152+
If you run this script twice, LAPI will not be called, the cache system will relay the information.
151153

152154
Let's try to stop the `crowdsec` container and re-run the script with the "bad" IP:
153155

154156
```bash
155157
docker-compose stop crowdsec
156-
docker-compose run php php check-ip.php 2.3.4.5
158+
docker-compose run app php check-ip.php 2.3.4.5
157159
```
158160

159161
For this IP, the cache system will never ask LAPI anymore for the duration of the decision.
160162

161163
Note: By default, a "bypass" decision is stored in the cache for 10 min. You can change this duration while instantiating the library.
162164

163-
Don't forget to start the crowdsec before continuing :-)
165+
Don't forget to restart the crowdsec container before continuing :-)
164166

165167
```bash
166168
docker-compose start crowdsec
@@ -224,7 +226,7 @@ $cacheAdapter = new RedisAdapter(RedisAdapter::createConnection('redis://redis:6
224226
...
225227
```
226228

227-
Or, if `Memcached` is more adapter to your needs than `Redis`:
229+
Or, if `Memcached` is more adapted than `Redis` to your needs:
228230

229231
```php
230232
<?php
@@ -244,7 +246,7 @@ $cacheAdapter = new MemcachedAdapter(MemcachedAdapter::createConnection('memcach
244246
You will still be able to verify IPs, but the cache system will be extremely efficient!
245247

246248
```bash
247-
docker-compose run php php check-ip.php 2.3.4.5
249+
docker-compose run app php check-ip.php 2.3.4.5
248250
```
249251

250252
Congrats! Now you use a very efficient cache layer!
@@ -253,7 +255,7 @@ Congrats! Now you use a very efficient cache layer!
253255
254256
## Cap remediation level
255257

256-
For some websites, it's a critical action to ban access to users (ex: e-commerce). In some case, we prefer to let user access to the website, even if CrowdSec says "ban it!".
258+
In some cases, it's a critical action to ban access to users (ex: e-commerce). We prefer to let user access to the website, even if CrowdSec says "ban it!".
257259

258260
Fortunately, this library allows you to cap the remediation to a certain level.
259261

@@ -271,7 +273,7 @@ $bouncer->configure([
271273
Now if you call one more time:
272274

273275
```bash
274-
docker-compose run php php check-ip.php 2.3.4.5
276+
docker-compose run app php check-ip.php 2.3.4.5
275277
```
276278

277279
The library will cap the value to `captcha` level.
@@ -394,7 +396,7 @@ echo "Cache successfully refreshed.\n";
394396
> Don't forget to use the same cache system as the one you used in the **check-ip.php** script.
395397
396398
```bash
397-
docker-compose run php php refresh-cache.php
399+
docker-compose run app php refresh-cache.php
398400
```
399401

400402
Now you can request as much remediation as you need without never overloading LAPI! Pretty nice!
@@ -403,7 +405,7 @@ Let's try to stop the `crowdsec` container and re-run the script with the "bad"
403405

404406
```bash
405407
docker-compose stop crowdsec
406-
docker-compose run php php check-ip.php 2.3.4.5
408+
docker-compose run app php check-ip.php 2.3.4.5
407409
```
408410

409411
> Even if CrowdSec LAPI is down, your bouncer can get the correct information.

0 commit comments

Comments
 (0)