Skip to content

Commit 5723811

Browse files
committed
Merge branch 'release/v0.2.0' into main
2 parents 23fa07b + c740b3d commit 5723811

35 files changed

+745
-1895
lines changed

.github/workflows/tests.yml

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
name: Tests
1+
name: tests
22

33
on:
4-
pull_request:
5-
# push: TODO P3 No tests on push because it causes an unresolved bug (no space left on device). This Smell a race condition.
4+
push:
65

76
jobs:
87

@@ -12,8 +11,7 @@ jobs:
1211

1312
strategy:
1413
matrix:
15-
php: ['7.2', '7.3', '7.4']
16-
# TODO P2 PHP 8 Compatibility: Fix: Error: Class "Memcached" not found (https://github.com/crowdsecurity/php-cs-bouncer/runs/1491476055?check_suite_focus=true)
14+
php: ['7.2', '7.3', '7.4', '8.0']
1715

1816
services:
1917
redis:
@@ -24,6 +22,14 @@ jobs:
2422
image: memcached:1.6.5
2523
ports:
2624
- 11211:11211
25+
crowdsec:
26+
image: crowdsecurity/crowdsec:v1.0.0
27+
ports:
28+
- 8080:8080
29+
env:
30+
DISABLE_AGENT: true
31+
options: >-
32+
--name crowdsec
2733
2834
steps:
2935
- name: Checkout
@@ -32,30 +38,20 @@ jobs:
3238
# In this step, this action saves a list of existing images,
3339
# the cache is created without them in the post run.
3440
# It also restores the cache if it exists.
35-
- uses: satackey/action-docker-layer-caching@v0.0.8
41+
- uses: satackey/action-docker-layer-caching@v0.0.10
3642
# Ignore the failure of a step and avoid terminating the job.
3743
continue-on-error: true
3844

39-
- name: Checkout Crowdsec
40-
uses: actions/checkout@v2
41-
with:
42-
repository: crowdsecurity/crowdsec
43-
ref: v1.0.0-rc4
44-
path: ./var/.tmp-crowdsec
45-
46-
- name: Build Crowdsec 1.0.0 (RC4) Docker image
47-
run: docker build -t crowdsec:v1.0.0-rc4 ./var/.tmp-crowdsec
48-
49-
- name: Run the crowdsec container
50-
run: docker run -d --name crowdsec -p 8080:8080 -e "DISABLE_AGENT=true" crowdsec:v1.0.0-rc4
51-
5245
- name: Add a bouncer to run phpunit tests
5346
run: docker exec crowdsec cscli bouncers add bouncer-php-library -o raw > .bouncer-key
5447

55-
# TODO P2 Move values to env vars
5648
- name: Add a machine to pilot crowdsec state
5749
run: docker exec crowdsec cscli machines add PhpUnitTestMachine --password PhpUnitTestMachinePassword
5850

51+
- name: Install libmemcached
52+
if: matrix.php == '8.0' # required only for php 8 as mentioned here: https://github.com/shivammathur/setup-php/issues/354
53+
run: sudo apt-get install libmemcached-dev -y
54+
5955
- name: Setup PHP
6056
uses: shivammathur/setup-php@v2
6157
with:

.gitignore

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
# Systems
55
.DS_Store
66

7-
# App
8-
/var/
9-
.bouncer-key
7+
#Tools
8+
super-linter.log
109
.phpdoc
11-
TODO.md
1210
.php_cs.cache
11+
12+
# App
13+
/var/
14+
.bouncer-key

README.md

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,76 @@
1+
2+
<p align="center">
3+
<img src="https://raw.githubusercontent.com/crowdsecurity/crowdsec/master/docs/assets/images/crowdsec_logo.png" alt="CrowdSec" title="CrowdSec" width="200" height="120"/>
4+
</p>
5+
16
# PHP Bouncer Library
27

3-
The official PHP client for the CrowdSec APIs (LAPI or CAPI).
8+
> The official PHP bouncer library for the CrowdSec LAPI/CAPI
9+
10+
<p align="center">
11+
<img src="https://img.shields.io/github/workflow/status/crowdsecurity/php-cs-bouncer/tests/main">
12+
<img src="https://img.shields.io/github/license/crowdsecurity/php-cs-bouncer">
13+
<img src="https://img.shields.io/github/v/release/crowdsecurity/php-cs-bouncer?include_prereleases">
14+
</p>
15+
16+
<p align="center">
17+
:books: <a href="https://doc.crowdsec.net">Documentation</a>
18+
:diamond_shape_with_a_dot_inside: <a href="https://hub.crowdsec.net">Hub</a>
19+
:speech_balloon: <a href="https://discourse.crowdsec.net">Discourse Forum</a>
20+
:speech_balloon: <a href="https://gitter.im/crowdsec-project/community?utm_source=share-link&utm_medium=link&utm_campaign=share-link">Gitter Chat</a>
21+
</p>
22+
23+
> This library allows you to create CrowdSec bouncers for PHP applications or frameworks like e-commerce, blog or other exposed applications.
424
5-
This client helps to create CrowdSec bouncers for PHP applications or frameworks (e-commerce, blog, other apps...).
25+
## Features
626

27+
- ✅ Fast API client
28+
- ✅ LAPI Support (CAPI not supported yet)
29+
- ✅ Built-in support for the most known cache systems like Redis, Memcached, PhpFiles
30+
-**Live mode** or **Stream mode**
31+
- ✅ Events logged using monolog
32+
- ✅ Large PHP matrix compatibility: 7.2.x, 7.3.x, 7.4.x and 8.0.x
33+
- ✅ Cap remediation level (ex: for sensitives websites: ban will be capped to captcha)
34+
- ✅ Clear and prune the cache
735
## Getting started
836

9-
View `docs/getting-started.md` to learn how to include this library in your project.
37+
### Installing CrowdSec Bouncer library
38+
39+
The recommended way to install CrowdSec Bouncer library is through [Composer](https://getcomposer.org/).
40+
41+
```bash
42+
composer require crowdsec/bouncer
43+
```
44+
45+
```php
46+
47+
/* To get a token: "cscli bouncers add <name-of-your-php-bouncer> */
48+
$apiToken = 'YOUR_TOKEN';
49+
50+
/* Select the best cache adapter for your needs (Memcached, Redis, PhpFiles, ...) */
51+
$cacheAdapter = new Symfony\Component\Cache\Adapter\PhpFilesAdapter();
1052

11-
You will find the full documenation here: (...) TODO P2
53+
$bouncer = new CrowdSecBouncer\Bouncer();
54+
$bouncer->configure(['api_token'=> $apiToken], $cacheAdapter);
1255

13-
# Sources
56+
$remediation = $bouncer->getRemediationForIp($blockedIp);// Return "ban", "captcha" or "bypass"
57+
```
1458

15-
- https://thephp.website/en/issue/php-docker-quick-setup/
59+
View [`docs/getting-started.md`](https://github.com/crowdsecurity/php-cs-bouncer/blob/main/docs/getting-started.rst) to learn how to include this library in your project in minutes.
1660

17-
# Licence
61+
## Future
62+
- Retrieve cache items with pagination
63+
- Release 1.0.0 version
64+
- Direct CAPI support
65+
- Support more cache systems (Apcu, Couchbase, Doctrine, Pdo)
66+
- Publish load tests (compare performances)
67+
- Report Code coverage
68+
- Setup Xdebug environment with Docker
1869

19-
MIT License. Details in the `./LICENSE` file.
70+
## Licence
2071

21-
# TODO
72+
[MIT License](https://github.com/crowdsecurity/php-cs-bouncer/blob/main/LICENSE)
2273

23-
Features:
24-
- [x] Fast API client
25-
- [x] LAPI Support
26-
- [x] Built-in support for the most known cache systems: Redis, Memcached, PhpFiles
27-
- [x] Live mode
28-
- [x] Stream mode
29-
- [x] Log events using monolog
30-
- [ ] Cap remediation level (ex: for sensitives websites: ban will be capped to captcha)
31-
- [ ] PHP 7.x+8.x compatibility (currenly only PHP 7.2+)
32-
- [ ] Retrieve cache items with pagination
33-
- [ ] Direct CAPI support
34-
- [ ] Release 1.0.0 version
35-
- [ ] Support more cache systems (Apcu, Couchbase, Doctrine, Pdo)
74+
## Licence
3675

37-
Code:
38-
- [x] Docker dev environment (Dockerized Crowdsec, Redis, Memcached, PHP)
39-
- [x] Continuous Integration (CI, includes Integration Tests and Super Linter)
40-
- [x] Integration tests (with TDD)
41-
- [x] Documented (Static documentation, PHP Doc)
42-
- [ ] Continuous Delivery (CD)
43-
- [ ] Load tests (compare performances)
44-
- [ ] Report Code coverage
45-
- [ ] Setup Xdebug environment
76+
[MIT License](https://github.com/crowdsecurity/php-cs-bouncer/blob/main/LICENSE)

composer.json

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
{
2-
"name": "crowdsec/bouncer-php-library",
3-
"description": "The official PHP client for the CrowdSec LAPI/CAPI",
2+
"name": "crowdsec/bouncer",
3+
"description": "The official PHP bouncer library for the CrowdSec LAPI/CAPI",
44
"type": "library",
5-
"license": "MIT License",
5+
"license": "MIT",
66
"minimum-stability": "stable",
7+
"keywords": [
8+
"security",
9+
"crowdsec",
10+
"waf",
11+
"middleware",
12+
"http",
13+
"blocker",
14+
"bouncer",
15+
"captcha",
16+
"geoip",
17+
"ip",
18+
"ip range"
19+
],
720
"autoload": {
821
"psr-4": {
922
"CrowdSecBouncer\\": "src/"
1023
}
1124
},
12-
"require-dev": {
13-
"symfony/var-dumper": "^5.1",
14-
"predis/predis": "^1.1",
15-
"phpstan/phpstan": "^0.12.58",
16-
"bramus/monolog-colored-line-formatter": "^3.0",
17-
"friendsofphp/php-cs-fixer": "^2.16",
18-
"phpunit/phpunit": "^8.5"
19-
},
25+
"authors": [
26+
{
27+
"name": "Lucas Cherifi",
28+
"email": "lucas@crowdsec.net"
29+
}
30+
],
2031
"require": {
21-
"symfony/config": "^5.1",
22-
"symfony/cache": "^5.1",
32+
"php": "^7.2 || ^8.0",
33+
"symfony/config": "^5.2",
34+
"symfony/cache": "^5.2",
2335
"monolog/monolog": "^2.1"
2436
},
25-
"scripts": {
26-
"lintfix":"vendor/bin/php-cs-fixer fix --verbose --show-progress=estimating --config=.php_cs ./src",
27-
"phpstan":"vendor/bin/phpstan analyse"
37+
"require-dev": {
38+
"predis/predis": "^1.1",
39+
"bramus/monolog-colored-line-formatter": "^3.0",
40+
"symfony/var-dumper": "^5.2",
41+
"phpunit/phpunit": "8.5.13"
2842
}
29-
}
43+
}

0 commit comments

Comments
 (0)