From 95763327196cbcae3797c1640f4160edd62f1fe2 Mon Sep 17 00:00:00 2001 From: mtak3 Date: Fri, 14 Feb 2020 04:02:02 +0000 Subject: [PATCH 1/7] update for cake-4.x --- .editorconfig | 16 ++++++++++++++++ .gitignore | 3 +++ composer.json | 8 ++++---- src/Controller/Component/IpFilterComponent.php | 2 +- .../Component/IpFilterComponentTest.php | 6 +++--- tests/bootstrap.php | 2 -- 6 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitignore diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..bd0ddd7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +; This file is for unifying the coding style for different editors and IDEs. +; More information at http://editorconfig.org + +root = false + +[*] +indent_style = space +indent_size = 4 +charset = "utf-8" +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d7e132 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +vendor/ +composer.lock +.phpunit.result.cache diff --git a/composer.json b/composer.json index 2b8db40..d6a7125 100644 --- a/composer.json +++ b/composer.json @@ -1,15 +1,15 @@ { "name": "tyrellsys/cakephp3-ip-filter", - "description": "restrict access by ip address for CakePHP3", + "description": "restrict access by ip address for CakePHP4", "type": "cakephp-plugin", "require": { - "php": ">=5.6", - "cakephp/cakephp": "~3.6", + "php": ">=7.2", + "cakephp/cakephp": "^4.0", "jalle19/php-whitelist-check": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^5.7|^6.0" + "phpunit/phpunit": "^8.5" }, "autoload": { "psr-4": { diff --git a/src/Controller/Component/IpFilterComponent.php b/src/Controller/Component/IpFilterComponent.php index 2de8761..c7af7be 100644 --- a/src/Controller/Component/IpFilterComponent.php +++ b/src/Controller/Component/IpFilterComponent.php @@ -30,7 +30,7 @@ public function check($ip = null) { $checker = new Check(); if (is_null($ip)) { - $request = clone $this->request; + $request = clone $this->getController()->getRequest(); $request->trustProxy = filter_var($this->getConfig('trustProxy', true), FILTER_VALIDATE_BOOLEAN); $ip = $request->clientIP(); } diff --git a/tests/TestCase/Controller/Component/IpFilterComponentTest.php b/tests/TestCase/Controller/Component/IpFilterComponentTest.php index 0dd6e72..0a61b5a 100644 --- a/tests/TestCase/Controller/Component/IpFilterComponentTest.php +++ b/tests/TestCase/Controller/Component/IpFilterComponentTest.php @@ -27,7 +27,7 @@ class IpFilterComponentTest extends TestCase * * @return void */ - public function setUp() + public function setUp(): void { parent::setUp(); $this->_oSERVER = $_SERVER; @@ -53,7 +53,7 @@ public function setUp() * * @return void */ - public function tearDown() + public function tearDown(): void { parent::tearDown(); @@ -121,11 +121,11 @@ public function testCheckNoTrustProxy($ip) /** * test checkOrFail method - * @expectedException \Cake\Http\Exception\ForbiddenException * @return void */ public function testCheckOrFail() { + $this->expectException(\Cake\Http\Exception\ForbiddenException::class); $this->Controller->IpFilter->checkOrFail('127.0.0.1'); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3834ac3..5952f20 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -21,6 +21,4 @@ require $root . '/vendor/autoload.php'; -require $root . '/config/bootstrap.php'; - $_SERVER['PHP_SELF'] = '/'; From 4aa2c8d5b278acf36698174275c5259910ab9baa Mon Sep 17 00:00:00 2001 From: mtak3 Date: Fri, 14 Feb 2020 04:03:41 +0000 Subject: [PATCH 2/7] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 871a9df..471f130 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # cakephp3-ip-filter -restrict access by ip address for CakePHP3 Component +restrict access by ip address for CakePHP4 Component ## Installation From d9658d6105e3590e307edc99935037c035cab574 Mon Sep 17 00:00:00 2001 From: mtak3 Date: Thu, 20 Aug 2020 04:41:19 +0000 Subject: [PATCH 3/7] change package xrstf/ip-utils has gone. https://bitbucket.org/xrstf/ip-utils https://bitbucket.org/blog/sunsetting-mercurial-support-in-bitbucket --- composer remove jalle19/php-whitelist-check composer require wikimedia/ip-set --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d6a7125..80cc6ab 100644 --- a/composer.json +++ b/composer.json @@ -1,4 +1,3 @@ - { "name": "tyrellsys/cakephp3-ip-filter", "description": "restrict access by ip address for CakePHP4", @@ -6,7 +5,7 @@ "require": { "php": ">=7.2", "cakephp/cakephp": "^4.0", - "jalle19/php-whitelist-check": "^1.0" + "wikimedia/ip-set": "^2.1" }, "require-dev": { "phpunit/phpunit": "^8.5" From fa8dd6e59e354bd7885f606671a40f73b607c44c Mon Sep 17 00:00:00 2001 From: mtak3 Date: Thu, 20 Aug 2020 04:42:56 +0000 Subject: [PATCH 4/7] update IpFilterComponent.php --- src/Controller/Component/IpFilterComponent.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Controller/Component/IpFilterComponent.php b/src/Controller/Component/IpFilterComponent.php index c7af7be..15793d8 100644 --- a/src/Controller/Component/IpFilterComponent.php +++ b/src/Controller/Component/IpFilterComponent.php @@ -4,7 +4,7 @@ use Cake\Controller\Component; use Cake\Controller\ComponentRegistry; use Cake\Http\Exception\ForbiddenException; -use Whitelist\Check; +use Wikimedia\IPSet; /** * IpFilter component @@ -28,7 +28,6 @@ class IpFilterComponent extends Component */ public function check($ip = null) { - $checker = new Check(); if (is_null($ip)) { $request = clone $this->getController()->getRequest(); $request->trustProxy = filter_var($this->getConfig('trustProxy', true), FILTER_VALIDATE_BOOLEAN); @@ -40,9 +39,9 @@ public function check($ip = null) $whitelist = explode(",", $whitelist); } - $checker->whitelist($whitelist); + $ipset = new IpSet($whitelist); - return $checker->check($ip); + return $ipset->match($ip); } /** From 7481d1f068b1aadc230edf23d3d7ee2d480ac8df Mon Sep 17 00:00:00 2001 From: mtak3 Date: Thu, 20 Aug 2020 04:57:28 +0000 Subject: [PATCH 5/7] fixup unittest config --- tests/bootstrap.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5952f20..8a107ce 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -19,6 +19,10 @@ $root = $findRoot(__FILE__); unset($findRoot); +require_once 'vendor/cakephp/cakephp/src/basics.php'; + require $root . '/vendor/autoload.php'; $_SERVER['PHP_SELF'] = '/'; + +error_reporting(E_ALL); From 95c4e6c5b4abef161a780f7ead8e680e297ea6be Mon Sep 17 00:00:00 2001 From: mtak3 Date: Thu, 20 Aug 2020 05:47:32 +0000 Subject: [PATCH 6/7] fixup class name --- src/Controller/Component/IpFilterComponent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/Component/IpFilterComponent.php b/src/Controller/Component/IpFilterComponent.php index 15793d8..bda7ad6 100644 --- a/src/Controller/Component/IpFilterComponent.php +++ b/src/Controller/Component/IpFilterComponent.php @@ -39,7 +39,7 @@ public function check($ip = null) $whitelist = explode(",", $whitelist); } - $ipset = new IpSet($whitelist); + $ipset = new IPSet($whitelist); return $ipset->match($ip); } From a9021b74e10971ee07a449cfa1e1a9d7526391ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TS=5F=E7=80=A7=E6=BE=A4=20=E5=85=85=E6=B5=A9=EF=BC=88Takiz?= =?UTF-8?q?awa=20Mitsuhiro=EF=BC=89?= Date: Mon, 17 Nov 2025 17:26:15 +0900 Subject: [PATCH 7/7] Update dependencies in composer.json Replaced wikimedia/ip-set with wikimedia/ip-utils --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 80cc6ab..f5e7735 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "require": { "php": ">=7.2", "cakephp/cakephp": "^4.0", - "wikimedia/ip-set": "^2.1" + "wikimedia/ip-utils": "5.0.0" }, "require-dev": { "phpunit/phpunit": "^8.5"