diff --git a/.gitignore b/.gitignore index 2d880df1..06570184 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /app/temp/debug_html/* /app/temp/log/* /app/temp/installed.lock +/app/temp/GeoLite2-Country.mmdb /app/temp/github_release_cache.json /app/version /app/vendor/ diff --git a/app/config.sample.php b/app/config.sample.php index 2fc65108..978b1025 100644 --- a/app/config.sample.php +++ b/app/config.sample.php @@ -31,6 +31,10 @@ // ログイン時にメール認証を有効化するか define("MFA_EMAIL", "0"); +// 国コード(ISO Code)指定でアクセスブロック +//define("USER_BLOCK_COUNTRY_ISO_CODE_CSV", "JP"); +//define("ADMIN_BLOCK_COUNTRY_ISO_CODE_CSV", "JP,US"); + // If you want get error log on display. // define('ERROR_ON_DISPLAY', "1"); // ini_set('display_errors', '1'); diff --git a/app/config_read_from_env.php b/app/config_read_from_env.php index d4303b0e..b339dcb7 100644 --- a/app/config_read_from_env.php +++ b/app/config_read_from_env.php @@ -53,6 +53,10 @@ define("EMERGENCY_PASSWORD_RESET_ENABLE", (string)getenv("FC2_EMERGENCY_PASSWORD_RESET_ENABLE")); define("MFA_EMAIL", (string)getenv("FC2_MFA_EMAIL")); +// 国コード(ISO Code)指定でアクセスブロック +define("USER_BLOCK_COUNTRY_ISO_CODE_CSV", (string)getenv("FC2_USER_BLOCK_COUNTRY_ISO_CODE_CSV")); +define("ADMIN_BLOCK_COUNTRY_ISO_CODE_CSV", (string)getenv("FC2_ADMIN_BLOCK_COUNTRY_ISO_CODE_CSV")); + if (strlen((string)getenv("FC2_GITHUB_REPO")) > 0) { define("GITHUB_REPO", (string)getenv("FC2_GITHUB_REPO")); } diff --git a/app/src/Service/AccessBlock.php b/app/src/Service/AccessBlock.php new file mode 100644 index 00000000..6fc22aac --- /dev/null +++ b/app/src/Service/AccessBlock.php @@ -0,0 +1,96 @@ + 0) { + $this->user_block_country_iso_code_csv = $user_block_country_iso_code_csv; + } elseif (defined("USER_BLOCK_COUNTRY_ISO_CODE_CSV")) { + $this->user_block_country_iso_code_csv = USER_BLOCK_COUNTRY_ISO_CODE_CSV; + } else { + $this->user_block_country_iso_code_csv = ""; + } + + if (strlen($admin_block_country_iso_code_csv) > 0) { + $this->admin_block_country_iso_code_csv = $admin_block_country_iso_code_csv; + } elseif (defined("ADMIN_BLOCK_COUNTRY_ISO_CODE_CSV")) { + $this->admin_block_country_iso_code_csv = ADMIN_BLOCK_COUNTRY_ISO_CODE_CSV; + } else { + $this->admin_block_country_iso_code_csv = ""; + } + + } + + public function isAdminBlockIp(Request $request): bool + { + if (strlen($this->admin_block_country_iso_code_csv) === 0) return false; + /** @noinspection PhpUnhandledExceptionInspection */ // エラーなら、アプリは停止で良い + return $this->isBlockIp($request, $this->admin_block_country_iso_code_csv); + } + + public function isUserBlockIp(Request $request): bool + { + if (strlen($this->user_block_country_iso_code_csv) === 0) return false; + /** @noinspection PhpUnhandledExceptionInspection */ // エラーなら、アプリは停止で良い + return $this->isBlockIp($request, $this->user_block_country_iso_code_csv); + } + + /** + * Check IP address that have to blocked with Read MaxMind Geo ip database. + * @param Request $request + * @param string $block_country_iso_code_csv + * @return bool + * @throws Reader\InvalidDatabaseException + * @throws Exception + */ + public function isBlockIp(Request $request, string $block_country_iso_code_csv): bool + { + if ( + !file_exists(self::MMDB_FILE_PATH) || + !is_file(self::MMDB_FILE_PATH) || + !is_readable(self::MMDB_FILE_PATH) + ) { + // mmdb file notfound. Not to be checking. Done. + return false; + } + + $reader = new Reader(self::MMDB_FILE_PATH); + $result = $reader->get($request->getClientIpAddress()); + $reader->close(); + if ( + !is_array($result) || // If undetermined, Result will be null. + !isset($result['country']) || + !isset($result['country']['iso_code']) + ) { + // Could not detect country information. So allow access. + return false; + } + + $determined_country_iso_code = $result['country']['iso_code']; + + return $this->isContainCsv($determined_country_iso_code, $block_country_iso_code_csv); + } + + private function isContainCsv(string $country_iso_code, string $block_country_iso_code_csv): bool + { + $list = explode(',', $block_country_iso_code_csv); + return in_array($country_iso_code, $list); + } +} diff --git a/app/src/Web/Controller/Admin/AdminController.php b/app/src/Web/Controller/Admin/AdminController.php index 39df4e0f..59fa37b4 100644 --- a/app/src/Web/Controller/Admin/AdminController.php +++ b/app/src/Web/Controller/Admin/AdminController.php @@ -6,6 +6,7 @@ use Fc2blog\App; use Fc2blog\Model\BlogsModel; use Fc2blog\Model\UsersModel; +use Fc2blog\Service\AccessBlock; use Fc2blog\Service\BlogService; use Fc2blog\Web\Controller\Controller; use Fc2blog\Web\Request; @@ -13,10 +14,13 @@ abstract class AdminController extends Controller { - protected function beforeFilter(Request $request) + protected function beforeFilter(Request $request): string { // 親のフィルター呼び出し - parent::beforeFilter($request); + $template_path = parent::beforeFilter($request); + if (strlen($template_path) > 0) { + return $template_path; + } // install.lockファイルがなければインストーラーへ if (!$this->isInstalled() && ( @@ -26,6 +30,11 @@ protected function beforeFilter(Request $request) $this->redirect($request, ['controller' => 'Common', 'action' => 'install']); } + // IPアドレスからアクセス元の国を推定してのブロック + if ((new AccessBlock())->isAdminBlockIp($request)) { + return $this->error403(); + } + if (!$this->isLogin()) { // 未ログイン時でもアクセス許可するパターンリスト $allows = array( @@ -40,7 +49,7 @@ protected function beforeFilter(Request $request) if (!isset($allows[$controller_name]) || !in_array($action_name, $allows[$controller_name])) { $this->redirect($request, array('controller' => 'Session', 'action' => 'login')); } - return; + return ""; } if (!$this->isSelectedBlog()) { @@ -57,7 +66,7 @@ protected function beforeFilter(Request $request) $this->setWarnMessage(__('Please select a blog')); $this->redirect($request, ['controller' => 'Blogs', 'action' => 'index']); } - return; + return ""; } // ログイン中でかつブログ選択中の場合ブログ情報を取得し時間設定を行う @@ -65,6 +74,8 @@ protected function beforeFilter(Request $request) if (is_array($blog) && isset($blog['timezone'])) { date_default_timezone_set($blog['timezone']); } + + return ""; } /** diff --git a/app/src/Web/Controller/Controller.php b/app/src/Web/Controller/Controller.php index d027e086..96d6bde5 100644 --- a/app/src/Web/Controller/Controller.php +++ b/app/src/Web/Controller/Controller.php @@ -53,7 +53,10 @@ public function execute($method): void */ public function prepare(string $method): string { - $this->beforeFilter($this->request); + $template_path = $this->beforeFilter($this->request); + if (strlen($template_path) > 0) { + return $template_path; + } $this->resolvedMethod = $method; @@ -130,8 +133,9 @@ protected function isInvalidAjaxRequest(Request $request): bool return false; } - protected function beforeFilter(Request $request) + protected function beforeFilter(Request $request): string { + return ""; } public function set(string $key, $value) diff --git a/app/src/Web/Controller/User/EntriesController.php b/app/src/Web/Controller/User/EntriesController.php index fba7fb1d..699a00c9 100644 --- a/app/src/Web/Controller/User/EntriesController.php +++ b/app/src/Web/Controller/User/EntriesController.php @@ -27,10 +27,14 @@ class EntriesController extends UserController /** * 記事系統の前処理 * @param Request $request + * @return string */ - protected function beforeFilter(Request $request): void + protected function beforeFilter(Request $request): string { - parent::beforeFilter($request); + $template_path = parent::beforeFilter($request); + if (strlen($template_path) > 0) { + return $template_path; + } // ブログID指定があるかチェック $blog_id = $request->getBlogId(); @@ -76,6 +80,8 @@ protected function beforeFilter(Request $request): void $entries_model = new EntriesModel(); $entries_model->updateReservation($blog_id); $entries_model->updateLimited($blog_id); + + return ""; } /** diff --git a/app/src/Web/Controller/User/UserController.php b/app/src/Web/Controller/User/UserController.php index 76282e12..b766ec72 100644 --- a/app/src/Web/Controller/User/UserController.php +++ b/app/src/Web/Controller/User/UserController.php @@ -4,6 +4,7 @@ namespace Fc2blog\Web\Controller\User; use Fc2blog\Model\BlogsModel; +use Fc2blog\Service\AccessBlock; use Fc2blog\Web\Controller\Controller; use Fc2blog\Web\Fc2BlogTemplate; use Fc2blog\Web\Request; @@ -12,6 +13,22 @@ abstract class UserController extends Controller { + protected function beforeFilter(Request $request): string + { + // 親のフィルター呼び出し + $template_path = parent::beforeFilter($request); + if (strlen($template_path) > 0) { + return $template_path; + } + + // IPアドレスからアクセス元の国を推定してのブロック + if ((new AccessBlock())->isUserBlockIp($request)) { + return $this->error403(); + } + + return ""; + } + /** * 管理画面ログイン中のブログIDを取得する */ @@ -80,9 +97,6 @@ protected static function getEntryPasswordKey(string $blog_id, int $entry_id): s */ protected function renderByFc2Template(Request $request, string $template_file_path): string { - if (is_null($template_file_path)) { - throw new InvalidArgumentException("undefined template"); - } if (!is_file($template_file_path)) { throw new InvalidArgumentException("missing template"); } @@ -94,7 +108,6 @@ protected function renderByFc2Template(Request $request, string $template_file_p // テンプレートをレンダリングして返す ob_start(); - /** @noinspection PhpIncludeInspection */ include($template_file_path); return ob_get_clean(); } diff --git a/app/src/Web/Request.php b/app/src/Web/Request.php index 8bdd107a..b76d3313 100644 --- a/app/src/Web/Request.php +++ b/app/src/Web/Request.php @@ -103,6 +103,17 @@ public function getReferer(): string return $this->server['HTTP_REFERER'] ?? ''; } + /** + * アクセスIPアドレスを返却 取得できなかった場合は空文字を返却 + * @return string + */ + public function getClientIpAddress(): string + { + // TODO support X_FORWARDED_FOR and other. + // TODO どの環境変数を「信用するか」を設定する項目が必要 + return $this->server['REMOTE_ADDR'] ?? ''; + } + public function getPath() { return $this->path; diff --git a/composer.json b/composer.json index acc2bd49..a53b25f4 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "nikic/php-parser": "^4.10", "tuupola/base62": "^2.1", "mibe/feedwriter": "^1.1", - "swiftmailer/swiftmailer": "^6.0" + "swiftmailer/swiftmailer": "^6.0", + "maxmind-db/reader": "~1.0" }, "config": { "vendor-dir": "app/vendor" diff --git a/composer.lock b/composer.lock index f2e2adef..4aa5977c 100644 --- a/composer.lock +++ b/composer.lock @@ -1,20 +1,20 @@ { - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "7092a6218e8fae2d6b62166c9b79c9ee", - "packages": [ - { - "name": "doctrine/lexer", - "version": "1.2.1", - "source": { - "type": "git", - "url": "https://github.com/doctrine/lexer.git", - "reference": "e864bbf5904cb8f5bb334f99209b48018522f042" - }, - "dist": { + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "86bb9f7b06596fa4f257587efda5223e", + "packages": [ + { + "name": "doctrine/lexer", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "e864bbf5904cb8f5bb334f99209b48018522f042" + }, + "dist": { "type": "zip", "url": "https://api.github.com/repos/doctrine/lexer/zipball/e864bbf5904cb8f5bb334f99209b48018522f042", "reference": "e864bbf5904cb8f5bb334f99209b48018522f042", @@ -295,26 +295,91 @@ "funding": [ { "url": "https://github.com/frankdejonge", - "type": "github" + "type": "github" }, - { - "url": "https://tidelift.com/funding/github/packagist/league/flysystem", - "type": "tidelift" - } + { + "url": "https://tidelift.com/funding/github/packagist/league/flysystem", + "type": "tidelift" + } ], - "time": "2021-01-18T20:58:21+00:00" + "time": "2021-01-18T20:58:21+00:00" }, + { + "name": "maxmind-db/reader", + "version": "v1.10.1", + "source": { + "type": "git", + "url": "https://github.com/maxmind/MaxMind-DB-Reader-php.git", + "reference": "569bd44d97d30a4ec12c7793a33004a76d4caf18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/569bd44d97d30a4ec12c7793a33004a76d4caf18", + "reference": "569bd44d97d30a4ec12c7793a33004a76d4caf18", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "conflict": { + "ext-maxminddb": "<1.10.1,>=2.0.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "*", + "php-coveralls/php-coveralls": "^2.1", + "phpstan/phpstan": "*", + "phpunit/phpcov": ">=6.0.0", + "phpunit/phpunit": ">=8.0.0,<10.0.0", + "squizlabs/php_codesniffer": "3.*" + }, + "suggest": { + "ext-bcmath": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder", + "ext-gmp": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder", + "ext-maxminddb": "A C-based database decoder that provides significantly faster lookups" + }, + "type": "library", + "autoload": { + "psr-4": { + "MaxMind\\Db\\": "src/MaxMind/Db" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ { - "name": "mibe/feedwriter", - "version": "v1.1.1", - "source": { - "type": "git", - "url": "https://github.com/mibe/FeedWriter.git", - "reference": "f4cc748ad8700e36663f08cfeebe7fd39b00eea2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/mibe/FeedWriter/zipball/f4cc748ad8700e36663f08cfeebe7fd39b00eea2", + "name": "Gregory J. Oschwald", + "email": "goschwald@maxmind.com", + "homepage": "https://www.maxmind.com/" + } + ], + "description": "MaxMind DB Reader API", + "homepage": "https://github.com/maxmind/MaxMind-DB-Reader-php", + "keywords": [ + "database", + "geoip", + "geoip2", + "geolocation", + "maxmind" + ], + "support": { + "issues": "https://github.com/maxmind/MaxMind-DB-Reader-php/issues", + "source": "https://github.com/maxmind/MaxMind-DB-Reader-php/tree/v1.10.1" + }, + "time": "2021-04-14T17:49:35+00:00" + }, + { + "name": "mibe/feedwriter", + "version": "v1.1.1", + "source": { + "type": "git", + "url": "https://github.com/mibe/FeedWriter.git", + "reference": "f4cc748ad8700e36663f08cfeebe7fd39b00eea2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mibe/FeedWriter/zipball/f4cc748ad8700e36663f08cfeebe7fd39b00eea2", "reference": "f4cc748ad8700e36663f08cfeebe7fd39b00eea2", "shasum": "" }, @@ -407,16 +472,16 @@ }, { "name": "monolog/monolog", - "version": "2.3.0", + "version": "2.3.2", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "df991fd88693ab703aa403413d83e15f688dae33" + "reference": "71312564759a7db5b789296369c1a264efc43aad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/df991fd88693ab703aa403413d83e15f688dae33", - "reference": "df991fd88693ab703aa403413d83e15f688dae33", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/71312564759a7db5b789296369c1a264efc43aad", + "reference": "71312564759a7db5b789296369c1a264efc43aad", "shasum": "" }, "require": { @@ -487,7 +552,7 @@ ], "support": { "issues": "https://github.com/Seldaek/monolog/issues", - "source": "https://github.com/Seldaek/monolog/tree/2.3.0" + "source": "https://github.com/Seldaek/monolog/tree/2.3.2" }, "funding": [ { @@ -499,20 +564,20 @@ "type": "tidelift" } ], - "time": "2021-07-05T11:34:13+00:00" + "time": "2021-07-23T07:42:52+00:00" }, { "name": "nikic/php-parser", - "version": "v4.11.0", + "version": "v4.12.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "fe14cf3672a149364fb66dfe11bf6549af899f94" + "reference": "6608f01670c3cc5079e18c1dab1104e002579143" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/fe14cf3672a149364fb66dfe11bf6549af899f94", - "reference": "fe14cf3672a149364fb66dfe11bf6549af899f94", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6608f01670c3cc5079e18c1dab1104e002579143", + "reference": "6608f01670c3cc5079e18c1dab1104e002579143", "shasum": "" }, "require": { @@ -553,9 +618,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.11.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.12.0" }, - "time": "2021-07-03T13:36:55+00:00" + "time": "2021-07-21T10:44:31+00:00" }, { "name": "psr/log", @@ -1014,16 +1079,16 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.23.0", + "version": "v1.23.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "2df51500adbaebdc4c38dea4c89a2e131c45c8a1" + "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/2df51500adbaebdc4c38dea4c89a2e131c45c8a1", - "reference": "2df51500adbaebdc4c38dea4c89a2e131c45c8a1", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9174a3d80210dca8daa7f31fec659150bbeabfc6", + "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6", "shasum": "" }, "require": { @@ -1074,7 +1139,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.23.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.23.1" }, "funding": [ { @@ -1090,7 +1155,7 @@ "type": "tidelift" } ], - "time": "2021-05-27T09:27:20+00:00" + "time": "2021-05-27T12:26:48+00:00" }, { "name": "symfony/polyfill-php72", @@ -1558,16 +1623,16 @@ }, { "name": "phar-io/manifest", - "version": "2.0.1", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133" + "reference": "97803eca37d319dfa7826cc2437fc020857acb53" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", - "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", + "reference": "97803eca37d319dfa7826cc2437fc020857acb53", "shasum": "" }, "require": { @@ -1612,9 +1677,9 @@ "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", "support": { "issues": "https://github.com/phar-io/manifest/issues", - "source": "https://github.com/phar-io/manifest/tree/master" + "source": "https://github.com/phar-io/manifest/tree/2.0.3" }, - "time": "2020-06-27T14:33:11+00:00" + "time": "2021-07-20T11:28:43+00:00" }, { "name": "phar-io/version", @@ -2212,16 +2277,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.6", + "version": "9.5.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "fb9b8333f14e3dce976a60ef6a7e05c7c7ed8bfb" + "reference": "191768ccd5c85513b4068bdbe99bb6390c7d54fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fb9b8333f14e3dce976a60ef6a7e05c7c7ed8bfb", - "reference": "fb9b8333f14e3dce976a60ef6a7e05c7c7ed8bfb", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/191768ccd5c85513b4068bdbe99bb6390c7d54fb", + "reference": "191768ccd5c85513b4068bdbe99bb6390c7d54fb", "shasum": "" }, "require": { @@ -2233,7 +2298,7 @@ "ext-xml": "*", "ext-xmlwriter": "*", "myclabs/deep-copy": "^1.10.1", - "phar-io/manifest": "^2.0.1", + "phar-io/manifest": "^2.0.3", "phar-io/version": "^3.0.2", "php": ">=7.3", "phpspec/prophecy": "^1.12.1", @@ -2299,7 +2364,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.6" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.8" }, "funding": [ { @@ -2311,7 +2376,7 @@ "type": "github" } ], - "time": "2021-06-23T05:14:38+00:00" + "time": "2021-07-31T15:17:34+00:00" }, { "name": "psr/container", @@ -2363,20 +2428,21 @@ }, { "name": "ramsey/collection", - "version": "1.1.3", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/ramsey/collection.git", - "reference": "28a5c4ab2f5111db6a60b2b4ec84057e0f43b9c1" + "reference": "eaca1dc1054ddd10cbd83c1461907bee6fb528fa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/collection/zipball/28a5c4ab2f5111db6a60b2b4ec84057e0f43b9c1", - "reference": "28a5c4ab2f5111db6a60b2b4ec84057e0f43b9c1", + "url": "https://api.github.com/repos/ramsey/collection/zipball/eaca1dc1054ddd10cbd83c1461907bee6fb528fa", + "reference": "eaca1dc1054ddd10cbd83c1461907bee6fb528fa", "shasum": "" }, "require": { - "php": "^7.2 || ^8" + "php": "^7.3 || ^8", + "symfony/polyfill-php81": "^1.23" }, "require-dev": { "captainhook/captainhook": "^5.3", @@ -2386,6 +2452,7 @@ "hamcrest/hamcrest-php": "^2", "jangregor/phpstan-prophecy": "^0.8", "mockery/mockery": "^1.3", + "phpspec/prophecy-phpunit": "^2.0", "phpstan/extension-installer": "^1", "phpstan/phpstan": "^0.12.32", "phpstan/phpstan-mockery": "^0.12.5", @@ -2413,7 +2480,7 @@ "homepage": "https://benramsey.com" } ], - "description": "A PHP 7.2+ library for representing and manipulating collections.", + "description": "A PHP library for representing and manipulating collections.", "keywords": [ "array", "collection", @@ -2424,7 +2491,7 @@ ], "support": { "issues": "https://github.com/ramsey/collection/issues", - "source": "https://github.com/ramsey/collection/tree/1.1.3" + "source": "https://github.com/ramsey/collection/tree/1.2.1" }, "funding": [ { @@ -2436,20 +2503,20 @@ "type": "tidelift" } ], - "time": "2021-01-21T17:40:04+00:00" + "time": "2021-08-06T03:41:06+00:00" }, { "name": "ramsey/uuid", - "version": "4.1.1", + "version": "4.2.0", "source": { "type": "git", "url": "https://github.com/ramsey/uuid.git", - "reference": "cd4032040a750077205918c86049aa0f43d22947" + "reference": "7231612a5221f5524d3575bebdce20eeef8547a1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/uuid/zipball/cd4032040a750077205918c86049aa0f43d22947", - "reference": "cd4032040a750077205918c86049aa0f43d22947", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/7231612a5221f5524d3575bebdce20eeef8547a1", + "reference": "7231612a5221f5524d3575bebdce20eeef8547a1", "shasum": "" }, "require": { @@ -2463,26 +2530,26 @@ "rhumsaa/uuid": "self.version" }, "require-dev": { - "codeception/aspect-mock": "^3", - "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7.0", + "captainhook/captainhook": "^5.10", + "captainhook/plugin-composer": "^5.3", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", "doctrine/annotations": "^1.8", - "goaop/framework": "^2", + "ergebnis/composer-normalize": "^2.15", "mockery/mockery": "^1.3", "moontoast/math": "^1.1", "paragonie/random-lib": "^2", + "php-mock/php-mock": "^2.2", "php-mock/php-mock-mockery": "^1.3", - "php-mock/php-mock-phpunit": "^2.5", "php-parallel-lint/php-parallel-lint": "^1.1", - "phpbench/phpbench": "^0.17.1", + "phpbench/phpbench": "^1.0", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^0.12", "phpstan/phpstan-mockery": "^0.12", "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^8.5", - "psy/psysh": "^0.10.0", - "slevomat/coding-standard": "^6.0", + "phpunit/phpunit": "^8.5 || ^9", + "slevomat/coding-standard": "^7.0", "squizlabs/php_codesniffer": "^3.5", - "vimeo/psalm": "3.9.4" + "vimeo/psalm": "^4.9" }, "suggest": { "ext-bcmath": "Enables faster math with arbitrary-precision integers using BCMath.", @@ -2495,7 +2562,10 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.x-dev" + "dev-main": "4.x-dev" + }, + "captainhook": { + "force-install": true } }, "autoload": { @@ -2511,7 +2581,6 @@ "MIT" ], "description": "A PHP library for generating and working with universally unique identifiers (UUIDs).", - "homepage": "https://github.com/ramsey/uuid", "keywords": [ "guid", "identifier", @@ -2519,16 +2588,19 @@ ], "support": { "issues": "https://github.com/ramsey/uuid/issues", - "rss": "https://github.com/ramsey/uuid/releases.atom", - "source": "https://github.com/ramsey/uuid" + "source": "https://github.com/ramsey/uuid/tree/4.2.0" }, "funding": [ { "url": "https://github.com/ramsey", "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/ramsey/uuid", + "type": "tidelift" } ], - "time": "2020-08-18T17:17:46+00:00" + "time": "2021-08-06T22:30:43+00:00" }, { "name": "sebastian/cli-parser", @@ -3632,18 +3704,97 @@ ], "time": "2021-03-23T23:28:01+00:00" }, + { + "name": "symfony/polyfill-php81", + "version": "v1.23.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php81.git", + "reference": "e66119f3de95efc359483f810c4c3e6436279436" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/e66119f3de95efc359483f810c4c3e6436279436", + "reference": "e66119f3de95efc359483f810c4c3e6436279436", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php81\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php81/tree/v1.23.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-05-21T13:25:03+00:00" + }, { "name": "theseer/tokenizer", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "75a63c33a8577608444246075ea0af0d052e452a" + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/75a63c33a8577608444246075ea0af0d052e452a", - "reference": "75a63c33a8577608444246075ea0af0d052e452a", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", "shasum": "" }, "require": { @@ -3672,7 +3823,7 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "support": { "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/master" + "source": "https://github.com/theseer/tokenizer/tree/1.2.1" }, "funding": [ { @@ -3680,7 +3831,7 @@ "type": "github" } ], - "time": "2020-07-12T23:59:07+00:00" + "time": "2021-07-28T10:34:58+00:00" }, { "name": "uzulla/pseudo_sendmail", diff --git a/tests/App/Service/AccessBlockTest.php b/tests/App/Service/AccessBlockTest.php new file mode 100644 index 00000000..d03be00a --- /dev/null +++ b/tests/App/Service/AccessBlockTest.php @@ -0,0 +1,39 @@ +markTestSkipped(); + return; + } + + $jp_ip_address = "133.0.0.1"; // Some JP address https://www.nic.ad.jp/ja/dns/jp-addr-block.html + $r = new Request(null, null, null, null, null, null, [ + 'REMOTE_ADDR' => $jp_ip_address + ]); + + $ab = new AccessBlock("JP"); + $this->assertTrue($ab->isUserBlockIp($r)); + + $ab = new AccessBlock("JP,US"); + $this->assertTrue($ab->isUserBlockIp($r)); + + $ab = new AccessBlock("US,JP"); + $this->assertTrue($ab->isUserBlockIp($r)); + + $ab = new AccessBlock("US"); + $this->assertFalse($ab->isUserBlockIp($r)); + + $ab = new AccessBlock(); + $this->assertFalse($ab->isUserBlockIp($r)); + } +}