diff --git a/README.md b/README.md index 4267a584c..6cfddd448 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,6 @@ FOSSBilling is open source software and is released under the Apache v2.0 licens This product includes the following third party work: -- GeoLite2 data created by MaxMind, available from [https://www.maxmind.com](https://www.maxmind.com). - Open Source Iconography by [Pictogrammers](https://pictogrammers.com/) licensed under the [Pictogrammers Free License](https://pictogrammers.com/docs/general/license/). ## Links diff --git a/composer.json b/composer.json index b96dab6e9..918886b6e 100644 --- a/composer.json +++ b/composer.json @@ -19,16 +19,15 @@ "require": { "php": ">=8.1", "ext-curl": "*", + "ext-intl": "*", "ext-mbstring": "*", "ext-pdo": "*", "ext-zlib": "*", - "ext-intl": "*", "antcms/antloader": "^2.0.2", "dompdf/dompdf": "^3.0.0", "egulias/email-validator": "^4.0", "filp/whoops": "^2.14", "gabordemooij/redbean": "^5.7", - "geoip2/geoip2": "^3.0.0", "io-developer/php-whois": "^4.1", "lcharette/webpack-encore-twig": "^1.2.0", "league/commonmark": "^2.3", @@ -36,6 +35,7 @@ "liborm85/composer-vendor-cleaner": "^1.7", "mattketmo/email-checker": "^2.2", "maximebf/debugbar": "^1.19", + "maxmind-db/reader": "^1.11", "monolog/monolog": "^3.5", "nelexa/zip": "^4.0.2", "phpmyadmin/motranslator": "^5.3.0", @@ -104,4 +104,4 @@ ] } } -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index aed0d4531..e0f7d46a4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a664af7f8c7e427f7ecf242dae4447fb", + "content-hash": "665cf4b8351ac5313e10c5252fad0c0a", "packages": [ { "name": "antcms/antloader", @@ -113,82 +113,6 @@ ], "time": "2023-11-29T23:19:16+00:00" }, - { - "name": "composer/ca-bundle", - "version": "1.5.2", - "source": { - "type": "git", - "url": "https://github.com/composer/ca-bundle.git", - "reference": "48a792895a2b7a6ee65dd5442c299d7b835b6137" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/ca-bundle/zipball/48a792895a2b7a6ee65dd5442c299d7b835b6137", - "reference": "48a792895a2b7a6ee65dd5442c299d7b835b6137", - "shasum": "" - }, - "require": { - "ext-openssl": "*", - "ext-pcre": "*", - "php": "^7.2 || ^8.0" - }, - "require-dev": { - "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^8 || ^9", - "psr/log": "^1.0 || ^2.0 || ^3.0", - "symfony/process": "^4.0 || ^5.0 || ^6.0 || ^7.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Composer\\CaBundle\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be" - } - ], - "description": "Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.", - "keywords": [ - "cabundle", - "cacert", - "certificate", - "ssl", - "tls" - ], - "support": { - "irc": "irc://irc.freenode.org/composer", - "issues": "https://github.com/composer/ca-bundle/issues", - "source": "https://github.com/composer/ca-bundle/tree/1.5.2" - }, - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], - "time": "2024-09-25T07:49:53+00:00" - }, { "name": "composer/class-map-generator", "version": "1.4.0", @@ -831,64 +755,6 @@ }, "time": "2023-03-17T22:39:19+00:00" }, - { - "name": "geoip2/geoip2", - "version": "v3.0.0", - "source": { - "type": "git", - "url": "https://github.com/maxmind/GeoIP2-php.git", - "reference": "1a802ce9356cdd1c6b681c030fd9563750e11e6a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/maxmind/GeoIP2-php/zipball/1a802ce9356cdd1c6b681c030fd9563750e11e6a", - "reference": "1a802ce9356cdd1c6b681c030fd9563750e11e6a", - "shasum": "" - }, - "require": { - "ext-json": "*", - "maxmind-db/reader": "^1.11.1", - "maxmind/web-service-common": "~0.8", - "php": ">=8.1" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "3.*", - "phpstan/phpstan": "*", - "phpunit/phpunit": "^10.0", - "squizlabs/php_codesniffer": "3.*" - }, - "type": "library", - "autoload": { - "psr-4": { - "GeoIp2\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Gregory J. Oschwald", - "email": "goschwald@maxmind.com", - "homepage": "https://www.maxmind.com/" - } - ], - "description": "MaxMind GeoIP2 PHP API", - "homepage": "https://github.com/maxmind/GeoIP2-php", - "keywords": [ - "IP", - "geoip", - "geoip2", - "geolocation", - "maxmind" - ], - "support": { - "issues": "https://github.com/maxmind/GeoIP2-php/issues", - "source": "https://github.com/maxmind/GeoIP2-php/tree/v3.0.0" - }, - "time": "2023-12-04T17:16:34+00:00" - }, { "name": "guzzlehttp/psr7", "version": "2.7.0", @@ -1788,57 +1654,6 @@ }, "time": "2023-12-02T00:09:23+00:00" }, - { - "name": "maxmind/web-service-common", - "version": "v0.9.0", - "source": { - "type": "git", - "url": "https://github.com/maxmind/web-service-common-php.git", - "reference": "4dc5a3e8df38aea4ca3b1096cee3a038094e9b53" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/maxmind/web-service-common-php/zipball/4dc5a3e8df38aea4ca3b1096cee3a038094e9b53", - "reference": "4dc5a3e8df38aea4ca3b1096cee3a038094e9b53", - "shasum": "" - }, - "require": { - "composer/ca-bundle": "^1.0.3", - "ext-curl": "*", - "ext-json": "*", - "php": ">=7.2" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "3.*", - "phpstan/phpstan": "*", - "phpunit/phpunit": "^8.0 || ^9.0", - "squizlabs/php_codesniffer": "3.*" - }, - "type": "library", - "autoload": { - "psr-4": { - "MaxMind\\Exception\\": "src/Exception", - "MaxMind\\WebService\\": "src/WebService" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Gregory Oschwald", - "email": "goschwald@maxmind.com" - } - ], - "description": "Internal MaxMind Web Service API", - "homepage": "https://github.com/maxmind/web-service-common-php", - "support": { - "issues": "https://github.com/maxmind/web-service-common-php/issues", - "source": "https://github.com/maxmind/web-service-common-php/tree/v0.9.0" - }, - "time": "2022-03-28T17:43:20+00:00" - }, { "name": "monolog/monolog", "version": "3.7.0", @@ -8927,17 +8742,17 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { "php": ">=8.1", "ext-curl": "*", + "ext-intl": "*", "ext-mbstring": "*", "ext-pdo": "*", - "ext-zlib": "*", - "ext-intl": "*" + "ext-zlib": "*" }, - "platform-dev": {}, + "platform-dev": [], "plugin-api-version": "2.6.0" } diff --git a/cspell.json b/cspell.json index b87a03238..35386cf2d 100644 --- a/cspell.json +++ b/cspell.json @@ -398,7 +398,9 @@ "evenodd", "Retryable", "FAILONERROR", - "releasenotes" + "releasenotes", + "Prins", + "iplookup" ], "ignorePaths": [ "tests-legacy/**", @@ -414,7 +416,7 @@ "phpunit.xml.dist", "phpunit-live.xml", "bin/**", - "src/library/GeoLite2-Country.mmdb", + "*.mmdb", "cspell.json", "package.json", "src/library/Registrar/**", diff --git a/src/di.php b/src/di.php index 6ed34f586..d9d3e7b82 100644 --- a/src/di.php +++ b/src/di.php @@ -709,14 +709,14 @@ $di['license_server'] = function () use ($di) { /* * @param void * - * @return \GeoIp2\Database\Reader + * @return \FOSSBilling\GeoIP\Reader */ -$di['geoip'] = fn (): \GeoIp2\Database\Reader => new GeoIp2\Database\Reader(PATH_LIBRARY . '/GeoLite2-Country.mmdb'); +$di['geoip'] = fn (): FOSSBilling\GeoIP\Reader => new FOSSBilling\GeoIP\Reader(PATH_LIBRARY . '/FOSSBilling/GeoIP/Databases/CC0-Country.mmdb'); /* * @param void * - * @return \Box_Password + * @return \FOSSBilling\PasswordManager */ $di['password'] = fn (): \FOSSBilling\PasswordManager => new FOSSBilling\PasswordManager(); diff --git a/src/install/sql/content.sql b/src/install/sql/content.sql index ee43ed3ca..e8c4ce196 100644 --- a/src/install/sql/content.sql +++ b/src/install/sql/content.sql @@ -315,7 +315,7 @@ LOCK TABLES `setting` WRITE; INSERT INTO `setting` (`id`, `param`, `value`, `public`, `category`, `hash`, `created_at`, `updated_at`) VALUES - (1,'last_patch','42',0,NULL,NULL,'2024-01-04 12:00:00','2024-01-04 12:00:00'), + (1,'last_patch','43',0,NULL,NULL,'2024-01-04 12:00:00','2024-01-04 12:00:00'), (2,'company_name','Company Name',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (3,'company_email','company@email.com',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (4,'company_signature','FOSSBilling.org - Client Management, Invoicing and Support Software',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), diff --git a/src/install/sql/content_test.sql b/src/install/sql/content_test.sql index 83bcf4676..121d5caed 100755 --- a/src/install/sql/content_test.sql +++ b/src/install/sql/content_test.sql @@ -480,7 +480,7 @@ LOCK TABLES `setting` WRITE; INSERT INTO `setting` (`id`, `param`, `value`, `public`, `category`, `hash`, `created_at`, `updated_at`) VALUES - (1,'last_patch','42',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), + (1,'last_patch','43',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (2,'company_name','FOSSBilling demo',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (3,'company_email','demo@fossbilling.org',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (4,'company_signature','FOSSBilling.org - Client Management, Invoicing and Support Software',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), diff --git a/src/library/Box/TwigExtensions.php b/src/library/Box/TwigExtensions.php index 639f359ca..990f88006 100644 --- a/src/library/Box/TwigExtensions.php +++ b/src/library/Box/TwigExtensions.php @@ -69,6 +69,8 @@ class Box_TwigExtensions extends AbstractExtension implements InjectionAwareInte 'money_convert' => new TwigFilter('money_convert', $this->twig_money_convert(...), ['needs_environment' => true, 'is_safe' => ['html']]), 'money_convert_without_currency' => new TwigFilter('money_convert_without_currency', $this->money_convert_without_currency(...), ['needs_environment' => true, 'is_safe' => ['html']]), + 'iplookup' => new TwigFilter('iplookup', $this->ipLookupLink(...), ['is_safe' => ['html']]), + // We override these default twig filters so we can explicitly disable it from calling certain functions that may leak data or allow commands to be executed on the system. 'filter' => new TwigFilter('filter', $this->filteredFilter(...)), 'map' => new TwigFilter('map', $this->filteredMap(...)), @@ -96,7 +98,7 @@ class Box_TwigExtensions extends AbstractExtension implements InjectionAwareInte try { $record = $this->di['geoip']->country($value); - return $record->country->name; + return $record->name; } catch (Exception) { return ''; } @@ -366,4 +368,15 @@ class Box_TwigExtensions extends AbstractExtension implements InjectionAwareInte return $array; } + + public function ipLookupLink(?string $ip) + { + if ($ip === null || $ip === '') { + return ''; + } + + $link = $this->di['url']->adminLink('security/iplookup', ['ip' => $ip]); + + return "{$ip}"; + } } diff --git a/src/library/FOSSBilling/GeoIP/ASN.php b/src/library/FOSSBilling/GeoIP/ASN.php new file mode 100644 index 000000000..6b6aaf7df --- /dev/null +++ b/src/library/FOSSBilling/GeoIP/ASN.php @@ -0,0 +1,37 @@ +asnNumber = $asnRecord['autonomous_system_number']; + $this->asnOrg = $asnRecord['autonomous_system_organization']; + } + + public function jsonSerialize(): array + { + return [ + 'asnNumber' => $this->asnNumber, + 'asnOrg' => $this->asnOrg, + ]; + } +} diff --git a/src/library/FOSSBilling/GeoIP/Country.php b/src/library/FOSSBilling/GeoIP/Country.php new file mode 100644 index 000000000..6d379de4f --- /dev/null +++ b/src/library/FOSSBilling/GeoIP/Country.php @@ -0,0 +1,61 @@ +name = $country->getNameInLanguage($language); + $this->flag = $country->getFlagEmoji(); + + foreach ($country->getCurrenciesAlpha3() as $currency) { + $currencies[] = $currency->value; + } + + $this->currencies = $currencies ?? []; + } + + public function jsonSerialize(): array + { + return [ + 'name' => $this->name, + 'flag' => $this->flag, + 'currencies' => $this->currencies, + ]; + } +} diff --git a/src/library/FOSSBilling/GeoIP/Databases/CC0-Country.mmdb b/src/library/FOSSBilling/GeoIP/Databases/CC0-Country.mmdb new file mode 100644 index 000000000..bddcba4c6 Binary files /dev/null and b/src/library/FOSSBilling/GeoIP/Databases/CC0-Country.mmdb differ diff --git a/src/library/FOSSBilling/GeoIP/Databases/PDDL-ASN.mmdb b/src/library/FOSSBilling/GeoIP/Databases/PDDL-ASN.mmdb new file mode 100644 index 000000000..419084e44 Binary files /dev/null and b/src/library/FOSSBilling/GeoIP/Databases/PDDL-ASN.mmdb differ diff --git a/src/library/FOSSBilling/GeoIP/IncompleteRecord.php b/src/library/FOSSBilling/GeoIP/IncompleteRecord.php new file mode 100644 index 000000000..07c2dfa31 --- /dev/null +++ b/src/library/FOSSBilling/GeoIP/IncompleteRecord.php @@ -0,0 +1,17 @@ +reader = new MaxMindReader($database); + + if ($locale === null) { + $locale = i18n::getActiveLocale(); + } + + $this->language = StandardsHelper::getLanguageObject(false, $locale); + } + + /** + * Retrieves the record for the IP address. + * + * @param string $ipAddress the IP address to look up + * + * @return array the record for the IP address + * + * @throws \InvalidArgumentException if something other than a single IP address is passed to the method + * @throws InvalidDatabaseException if the database is invalid or there is an error reading from it + */ + public function get(string $ipAddress) + { + return $this->reader->get($ipAddress); + } + + /** + * Retrieves the country for an IP address. + * + * @param string $ipAddress the IP address to look up + * + * @return Country A country object for the associated record + * + * @throws IncompleteRecord if the record for the given IP address does not contain the needed information + * @throws \InvalidArgumentException if something other than a single IP address is passed to the method + * @throws InvalidDatabaseException if the database is invalid or there is an error reading from it + */ + public function country(string $ipAddress): Country + { + $record = $this->get($ipAddress); + + return new Country($record['country'] ?? [], $this->language); + } + + /** + * Returns the ASN information for an IP address. + * + * @param string $ipAddress the IP address to look up + * + * @return ASN the ASN object for the associated record + * + * @throws IncompleteRecord if the record for the given IP address does not contain the needed information + * @throws \InvalidArgumentException if something other than a single IP address is passed to the method + * @throws InvalidDatabaseException if the database is invalid or there is an error reading from it + */ + public function asn(string $ipAddress): ASN + { + $record = $this->get($ipAddress); + + return new ASN($record); + } +} diff --git a/src/library/FOSSBilling/StandardsHelper.php b/src/library/FOSSBilling/StandardsHelper.php new file mode 100644 index 000000000..9745723a5 --- /dev/null +++ b/src/library/FOSSBilling/StandardsHelper.php @@ -0,0 +1,41 @@ +setConfig($config); }, + 43 => function (): void { + $fileActions = [ + PATH_LIBRARY . DIRECTORY_SEPARATOR . 'GeoLite2-Country.mmdb' => 'unlink', + ]; + $this->executeFileActions($fileActions); + }, ]; ksort($patches, SORT_NATURAL); diff --git a/src/library/GeoLite2-Country.mmdb b/src/library/GeoLite2-Country.mmdb deleted file mode 100644 index 9544b0952..000000000 Binary files a/src/library/GeoLite2-Country.mmdb and /dev/null differ diff --git a/src/modules/Activity/html_admin/mod_activity_index.html.twig b/src/modules/Activity/html_admin/mod_activity_index.html.twig index 364041047..abba33b1e 100644 --- a/src/modules/Activity/html_admin/mod_activity_index.html.twig +++ b/src/modules/Activity/html_admin/mod_activity_index.html.twig @@ -58,7 +58,7 @@ {% endif %}
| {{ 'IP Address'|trans }} | +{{ 'Country'|trans }} | +ASN # | +{{ 'ASN Organization'|trans }} | +
|---|---|---|---|
| {{ record.ip.address }} ({{ record.ip.type }}) | +{{ record.country.flag }} {{ record.country.name }} | +{{ record.asn.asnNumber }} | +{{ record.asn.asnOrg }} | +