Skip to content

Commit

Permalink
Merge branch 'release/v0.2.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mobula9 committed Dec 8, 2020
2 parents 23fa07b + c740b3d commit 5723811
Show file tree
Hide file tree
Showing 35 changed files with 745 additions and 1,895 deletions.
36 changes: 16 additions & 20 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Tests
name: tests

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

jobs:

Expand All @@ -12,8 +11,7 @@ jobs:

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

services:
redis:
Expand All @@ -24,6 +22,14 @@ jobs:
image: memcached:1.6.5
ports:
- 11211:11211
crowdsec:
image: crowdsecurity/crowdsec:v1.0.0
ports:
- 8080:8080
env:
DISABLE_AGENT: true
options: >-
--name crowdsec
steps:
- name: Checkout
Expand All @@ -32,30 +38,20 @@ jobs:
# In this step, this action saves a list of existing images,
# the cache is created without them in the post run.
# It also restores the cache if it exists.
- uses: satackey/[email protected].8
- uses: satackey/[email protected].10
# Ignore the failure of a step and avoid terminating the job.
continue-on-error: true

- name: Checkout Crowdsec
uses: actions/checkout@v2
with:
repository: crowdsecurity/crowdsec
ref: v1.0.0-rc4
path: ./var/.tmp-crowdsec

- name: Build Crowdsec 1.0.0 (RC4) Docker image
run: docker build -t crowdsec:v1.0.0-rc4 ./var/.tmp-crowdsec

- name: Run the crowdsec container
run: docker run -d --name crowdsec -p 8080:8080 -e "DISABLE_AGENT=true" crowdsec:v1.0.0-rc4

- name: Add a bouncer to run phpunit tests
run: docker exec crowdsec cscli bouncers add bouncer-php-library -o raw > .bouncer-key

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

- name: Install libmemcached
if: matrix.php == '8.0' # required only for php 8 as mentioned here: https://github.com/shivammathur/setup-php/issues/354
run: sudo apt-get install libmemcached-dev -y

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand Down
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
# Systems
.DS_Store

# App
/var/
.bouncer-key
#Tools
super-linter.log
.phpdoc
TODO.md
.php_cs.cache

# App
/var/
.bouncer-key
93 changes: 62 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,76 @@

<p align="center">
<img src="https://raw.githubusercontent.com/crowdsecurity/crowdsec/master/docs/assets/images/crowdsec_logo.png" alt="CrowdSec" title="CrowdSec" width="200" height="120"/>
</p>

# PHP Bouncer Library

The official PHP client for the CrowdSec APIs (LAPI or CAPI).
> The official PHP bouncer library for the CrowdSec LAPI/CAPI
<p align="center">
<img src="https://img.shields.io/github/workflow/status/crowdsecurity/php-cs-bouncer/tests/main">
<img src="https://img.shields.io/github/license/crowdsecurity/php-cs-bouncer">
<img src="https://img.shields.io/github/v/release/crowdsecurity/php-cs-bouncer?include_prereleases">
</p>

<p align="center">
:books: <a href="https://doc.crowdsec.net">Documentation</a>
:diamond_shape_with_a_dot_inside: <a href="https://hub.crowdsec.net">Hub</a>
:speech_balloon: <a href="https://discourse.crowdsec.net">Discourse Forum</a>
:speech_balloon: <a href="https://gitter.im/crowdsec-project/community?utm_source=share-link&utm_medium=link&utm_campaign=share-link">Gitter Chat</a>
</p>

> This library allows you to create CrowdSec bouncers for PHP applications or frameworks like e-commerce, blog or other exposed applications.
This client helps to create CrowdSec bouncers for PHP applications or frameworks (e-commerce, blog, other apps...).
## Features

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

View `docs/getting-started.md` to learn how to include this library in your project.
### Installing CrowdSec Bouncer library

The recommended way to install CrowdSec Bouncer library is through [Composer](https://getcomposer.org/).

```bash
composer require crowdsec/bouncer
```

```php

/* To get a token: "cscli bouncers add <name-of-your-php-bouncer> */
$apiToken = 'YOUR_TOKEN';

/* Select the best cache adapter for your needs (Memcached, Redis, PhpFiles, ...) */
$cacheAdapter = new Symfony\Component\Cache\Adapter\PhpFilesAdapter();

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

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

- https://thephp.website/en/issue/php-docker-quick-setup/
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.

# Licence
## Future
- Retrieve cache items with pagination
- Release 1.0.0 version
- Direct CAPI support
- Support more cache systems (Apcu, Couchbase, Doctrine, Pdo)
- Publish load tests (compare performances)
- Report Code coverage
- Setup Xdebug environment with Docker

MIT License. Details in the `./LICENSE` file.
## Licence

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

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

Code:
- [x] Docker dev environment (Dockerized Crowdsec, Redis, Memcached, PHP)
- [x] Continuous Integration (CI, includes Integration Tests and Super Linter)
- [x] Integration tests (with TDD)
- [x] Documented (Static documentation, PHP Doc)
- [ ] Continuous Delivery (CD)
- [ ] Load tests (compare performances)
- [ ] Report Code coverage
- [ ] Setup Xdebug environment
[MIT License](https://github.com/crowdsecurity/php-cs-bouncer/blob/main/LICENSE)
48 changes: 31 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
{
"name": "crowdsec/bouncer-php-library",
"description": "The official PHP client for the CrowdSec LAPI/CAPI",
"name": "crowdsec/bouncer",
"description": "The official PHP bouncer library for the CrowdSec LAPI/CAPI",
"type": "library",
"license": "MIT License",
"license": "MIT",
"minimum-stability": "stable",
"keywords": [
"security",
"crowdsec",
"waf",
"middleware",
"http",
"blocker",
"bouncer",
"captcha",
"geoip",
"ip",
"ip range"
],
"autoload": {
"psr-4": {
"CrowdSecBouncer\\": "src/"
}
},
"require-dev": {
"symfony/var-dumper": "^5.1",
"predis/predis": "^1.1",
"phpstan/phpstan": "^0.12.58",
"bramus/monolog-colored-line-formatter": "^3.0",
"friendsofphp/php-cs-fixer": "^2.16",
"phpunit/phpunit": "^8.5"
},
"authors": [
{
"name": "Lucas Cherifi",
"email": "[email protected]"
}
],
"require": {
"symfony/config": "^5.1",
"symfony/cache": "^5.1",
"php": "^7.2 || ^8.0",
"symfony/config": "^5.2",
"symfony/cache": "^5.2",
"monolog/monolog": "^2.1"
},
"scripts": {
"lintfix":"vendor/bin/php-cs-fixer fix --verbose --show-progress=estimating --config=.php_cs ./src",
"phpstan":"vendor/bin/phpstan analyse"
"require-dev": {
"predis/predis": "^1.1",
"bramus/monolog-colored-line-formatter": "^3.0",
"symfony/var-dumper": "^5.2",
"phpunit/phpunit": "8.5.13"
}
}
}
Loading

0 comments on commit 5723811

Please sign in to comment.