Skip to content

Commit b09d9e9

Browse files
Merge pull request #80 from julienloizelet/feature/update-geoloc-and-cache-configs
Feature/update geoloc and cache configs
2 parents 3d2156c + 4797c86 commit b09d9e9

File tree

7 files changed

+22
-10
lines changed

7 files changed

+22
-10
lines changed

.github/dependabot.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ updates:
55
schedule:
66
interval: monthly
77
open-pull-requests-limit: 10
8+
ignore:
9+
- dependency-name: phpunit/phpunit

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77

8+
9+
## [0.20.0] - 2022-03-31
10+
11+
### Changed
12+
- Require a minimum of 1 for `clean_ip_cache_duration` and `bad_ip_cache_duration` settings
13+
- Do not use session for geolocation if `save_in_session` setting is not true.
14+
815
## [0.19.0] - 2022-03-24
916

1017
### Added

docs/INSTALLATION_GUIDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
## Requirements
2626

2727
- PHP >= 7.2
28+
- required php extensions : `ext-curl`, `ext-gd`
2829

2930
## Installation
3031

src/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ public function getConfigTreeBuilder(): TreeBuilder
6969
->scalarNode('redis_dsn')->end()
7070
->scalarNode('memcached_dsn')->end()
7171
->integerNode('clean_ip_cache_duration')
72-
->defaultValue(Constants::CACHE_EXPIRATION_FOR_CLEAN_IP)
72+
->min(1)->defaultValue(Constants::CACHE_EXPIRATION_FOR_CLEAN_IP)
7373
->end()
7474
->integerNode('bad_ip_cache_duration')
75-
->defaultValue(Constants::CACHE_EXPIRATION_FOR_BAD_IP)
75+
->min(1)->defaultValue(Constants::CACHE_EXPIRATION_FOR_BAD_IP)
7676
->end()
7777
// Geolocation
7878
->arrayNode('geolocation')

src/Constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Constants
2020
public const DEFAULT_LAPI_URL = 'http://localhost:8080';
2121

2222
/** @var string The last version of this library */
23-
public const VERSION = 'v0.19.0';
23+
public const VERSION = 'v0.20.0';
2424

2525
/** @var string The user agent used to send request to LAPI */
2626
public const BASE_USER_AGENT = 'PHP CrowdSec Bouncer/'.self::VERSION;

src/Geolocation.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,16 @@ public function getCountryResult(array $geolocConfig, string $ip): array
7676
{
7777
$result = $this->resultTemplate;
7878
$saveInSession = !empty($geolocConfig['save_in_session']);
79-
if ($country = Session::getSessionVariable('crowdsec_geolocation_country')) {
80-
$result['country'] = $country;
79+
if ($saveInSession) {
80+
if ($country = Session::getSessionVariable('crowdsec_geolocation_country')) {
81+
$result['country'] = $country;
8182

82-
return $result;
83-
} elseif ($notFoundError = Session::getSessionVariable('crowdsec_geolocation_not_found')) {
84-
$result['not_found'] = $notFoundError;
83+
return $result;
84+
} elseif ($notFoundError = Session::getSessionVariable('crowdsec_geolocation_not_found')) {
85+
$result['not_found'] = $notFoundError;
8586

86-
return $result;
87+
return $result;
88+
}
8789
}
8890
if (Constants::GEOLOCATION_TYPE_MAXMIND === $geolocConfig['type']) {
8991
$configPath = $geolocConfig[Constants::GEOLOCATION_TYPE_MAXMIND];

src/StandaloneBounce.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class StandaloneBounce extends AbstractBounce implements IBounce
3030
/**
3131
* @var string
3232
*/
33-
const SESSION_NAME = 'crowdsec';
33+
public const SESSION_NAME = 'crowdsec';
3434

3535
/**
3636
* Initialize the bouncer.

0 commit comments

Comments
 (0)