From 459fba6b86375e67c48fc08b0762e7e3e0061123 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis <roman25052006.kelesh@gmail.com> Date: Wed, 8 May 2024 22:13:30 +0700 Subject: [PATCH] =?UTF-8?q?Show=20client=20country=20in=20seeders=20/=20le?= =?UTF-8?q?echers=20list=20=F0=9F=8C=8D=20(#1478)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Show client country in seeders / leechers list * Update functions.php * Update functions.php * Update functions.php * Updated * Update displaying_torrent.php * Update functions.php * Update viewtopic_torrent.tpl * Update viewtopic_torrent.tpl * Update functions.php * Update functions.php * Update functions.php * Update functions.php * Update config.php * Updated * Updated * Updated * Updated * Update update_geolite_db.php * Update update_geolite_db.php * Updated * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Updated * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Updated * Update viewtopic_torrent.tpl * Updated * Update composer.lock * Update defines.php * Updated * Update init_bb.php * Update CHANGELOG.md --- .gitignore | 4 +- CHANGELOG.md | 1 + common.php | 20 + composer.json | 10 +- composer.lock | 359 ++++++++++++++---- filelist.php | 2 +- install/sql/mysql.sql | 5 +- library/attach_mod/displaying_torrent.php | 3 +- library/config.php | 1 + library/defines.php | 14 + .../includes/cron/jobs/board_maintenance.php | 2 +- library/includes/cron/jobs/cache_gc.php | 2 +- library/includes/cron/jobs/demo_mode.php | 2 +- .../includes/cron/jobs/update_geolite_db.php | 81 ++++ .../datastore/build_check_updates.php | 2 +- library/includes/functions.php | 27 ++ library/includes/init_bb.php | 4 +- library/language/source/main.php | 2 + src/Helpers/IsHelper.php | 11 + .../templates/default/viewtopic_torrent.tpl | 12 +- 20 files changed, 475 insertions(+), 89 deletions(-) create mode 100644 library/includes/cron/jobs/update_geolite_db.php diff --git a/.gitignore b/.gitignore index da122430a..8f425eb05 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,6 @@ data/uploads internal_data/atom internal_data/cache internal_data/log -internal_data/updater.ver sitemap internal_data/triggers library/config.local.php @@ -33,6 +32,9 @@ Desktop.ini $RECYCLE.BIN/ *.lnk *.bat +*.ver +*.mmdb +*.mmdb.old ### OSX ### .DS_Store diff --git a/CHANGELOG.md b/CHANGELOG.md index 09a413cda..b59cbe4e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Some enhancements [\#1445](https://github.com/torrentpier/torrentpier/pull/1445) ([belomaxorka](https://github.com/belomaxorka)) - Guests can view polls [\#1464](https://github.com/torrentpier/torrentpier/pull/1464) ([belomaxorka](https://github.com/belomaxorka)) - Improved app debug [\#1438](https://github.com/torrentpier/torrentpier/pull/1438) ([belomaxorka](https://github.com/belomaxorka)) +- Show client country in seeders / leechers list 🌍 [\#1478](https://github.com/torrentpier/torrentpier/pull/1478) ([belomaxorka](https://github.com/belomaxorka)) - Some enhancements for flags [\#1470](https://github.com/torrentpier/torrentpier/pull/1470), [\#1471](https://github.com/torrentpier/torrentpier/pull/1471) ([belomaxorka](https://github.com/belomaxorka)) - Fixed quote selection for smiles [\#1457](https://github.com/torrentpier/torrentpier/pull/1457) ([belomaxorka](https://github.com/belomaxorka)) - Demo mode: Allow registering torrents by default [\#1440](https://github.com/torrentpier/torrentpier/pull/1440) ([belomaxorka](https://github.com/belomaxorka)) diff --git a/common.php b/common.php index 920678fbb..9ba5ba0d3 100644 --- a/common.php +++ b/common.php @@ -172,6 +172,26 @@ switch ($bb_cfg['datastore_type']) { $datastore = new TorrentPier\Legacy\Datastore\File($bb_cfg['cache']['db_dir'] . 'datastore/', $bb_cfg['cache']['prefix']); } +if (CHECK_REQIREMENTS['status'] && !CACHE('bb_cache')->get('system_req')) { + // [1] Check PHP Version + if (!\TorrentPier\Helpers\IsHelper::isPHP(CHECK_REQIREMENTS['php_min_version'])) { + die("TorrentPier requires PHP version " . CHECK_REQIREMENTS['php_min_version'] . "+ Your PHP version " . PHP_VERSION); + } + + // [2] Check installed PHP Extensions on server + $data = []; + foreach (CHECK_REQIREMENTS['ext_list'] as $ext) { + if (!extension_loaded($ext)) { + $data[] = '<code style="background:#222;color:#00e01f;padding:2px 6px;border-radius:3px;">' . $ext . '</code>'; + } + } + if (!empty($data)) { + die(sprintf("TorrentPier requires %s extension(s) installed on server", implode(', ', $data))); + } + + CACHE('bb_cache')->set('system_req', true); +} + // Functions function utime() { diff --git a/composer.json b/composer.json index 2e678e70c..e8ca6db7e 100644 --- a/composer.json +++ b/composer.json @@ -37,21 +37,13 @@ }, "require": { "php": "^8.1", - "ext-bcmath": "*", - "ext-ctype": "*", - "ext-curl": "*", - "ext-intl": "*", - "ext-json": "*", - "ext-mbstring": "*", - "ext-mysqli": "*", - "ext-xml": "*", - "ext-xmlwriter": "*", "arokettu/bencode": "^4.1.0", "arokettu/torrent-file": "^5.2.1", "bugsnag/bugsnag": "^v3.29.1", "claviska/simpleimage": "^4.0", "egulias/email-validator": "^4.0.1", "filp/whoops": "^2.15", + "geoip2/geoip2": "^3.0", "gigablah/sphinxphp": "2.0.8", "google/recaptcha": "^1.3", "jacklul/monolog-telegram": "^3.1", diff --git a/composer.lock b/composer.lock index cc55f55d2..91b2886b5 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": "0d3ba700ad5fce7abfc08815599a39b3", + "content-hash": "3fb022a8706a580cdc67b5c4cdd52e8e", "packages": [ { "name": "arokettu/bencode", @@ -389,28 +389,28 @@ }, { "name": "composer/ca-bundle", - "version": "1.4.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/composer/ca-bundle.git", - "reference": "b66d11b7479109ab547f9405b97205640b17d385" + "reference": "0c5ccfcfea312b5c5a190a21ac5cef93f74baf99" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/ca-bundle/zipball/b66d11b7479109ab547f9405b97205640b17d385", - "reference": "b66d11b7479109ab547f9405b97205640b17d385", + "url": "https://api.github.com/repos/composer/ca-bundle/zipball/0c5ccfcfea312b5c5a190a21ac5cef93f74baf99", + "reference": "0c5ccfcfea312b5c5a190a21ac5cef93f74baf99", "shasum": "" }, "require": { "ext-openssl": "*", "ext-pcre": "*", - "php": "^5.3.2 || ^7.0 || ^8.0" + "php": "^7.2 || ^8.0" }, "require-dev": { - "phpstan/phpstan": "^0.12.55", + "phpstan/phpstan": "^1.10", "psr/log": "^1.0", "symfony/phpunit-bridge": "^4.2 || ^5", - "symfony/process": "^2.5 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0" + "symfony/process": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "type": "library", "extra": { @@ -445,7 +445,7 @@ "support": { "irc": "irc://irc.freenode.org/composer", "issues": "https://github.com/composer/ca-bundle/issues", - "source": "https://github.com/composer/ca-bundle/tree/1.4.0" + "source": "https://github.com/composer/ca-bundle/tree/1.5.0" }, "funding": [ { @@ -461,7 +461,7 @@ "type": "tidelift" } ], - "time": "2023-12-18T12:05:55+00:00" + "time": "2024-03-15T14:00:32+00:00" }, { "name": "doctrine/lexer", @@ -678,6 +678,64 @@ ], "time": "2023-11-03T12:00:00+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": "gigablah/sphinxphp", "version": "2.0.8", @@ -1418,6 +1476,122 @@ }, "time": "2016-10-23T20:08:46+00:00" }, + { + "name": "maxmind-db/reader", + "version": "v1.11.1", + "source": { + "type": "git", + "url": "https://github.com/maxmind/MaxMind-DB-Reader-php.git", + "reference": "1e66f73ffcf25e17c7a910a1317e9720a95497c7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/1e66f73ffcf25e17c7a910a1317e9720a95497c7", + "reference": "1e66f73ffcf25e17c7a910a1317e9720a95497c7", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "conflict": { + "ext-maxminddb": "<1.11.1,>=2.0.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.*", + "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": "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.11.1" + }, + "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.6.0", @@ -2112,16 +2286,16 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v3.4.0", + "version": "v3.5.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", "shasum": "" }, "require": { @@ -2130,7 +2304,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.4-dev" + "dev-main": "3.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -2159,7 +2333,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.4.0" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.0" }, "funding": [ { @@ -2175,7 +2349,7 @@ "type": "tidelift" } ], - "time": "2023-05-23T14:45:45+00:00" + "time": "2024-04-18T09:32:20+00:00" }, { "name": "symfony/event-dispatcher", @@ -2259,16 +2433,16 @@ }, { "name": "symfony/event-dispatcher-contracts", - "version": "v3.4.2", + "version": "v3.5.0", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher-contracts.git", - "reference": "4e64b49bf370ade88e567de29465762e316e4224" + "reference": "8f93aec25d41b72493c6ddff14e916177c9efc50" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/4e64b49bf370ade88e567de29465762e316e4224", - "reference": "4e64b49bf370ade88e567de29465762e316e4224", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/8f93aec25d41b72493c6ddff14e916177c9efc50", + "reference": "8f93aec25d41b72493c6ddff14e916177c9efc50", "shasum": "" }, "require": { @@ -2278,7 +2452,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.4-dev" + "dev-main": "3.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -2315,7 +2489,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.4.2" + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.5.0" }, "funding": [ { @@ -2331,26 +2505,27 @@ "type": "tidelift" } ], - "time": "2024-01-23T14:51:35+00:00" + "time": "2024-04-18T09:32:20+00:00" }, { "name": "symfony/filesystem", - "version": "v6.4.3", + "version": "v6.4.7", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "7f3b1755eb49297a0827a7575d5d2b2fd11cc9fb" + "reference": "78dde75f8f6dbbca4ec436a4b0087f7af02076d4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/7f3b1755eb49297a0827a7575d5d2b2fd11cc9fb", - "reference": "7f3b1755eb49297a0827a7575d5d2b2fd11cc9fb", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/78dde75f8f6dbbca4ec436a4b0087f7af02076d4", + "reference": "78dde75f8f6dbbca4ec436a4b0087f7af02076d4", "shasum": "" }, "require": { "php": ">=8.1", "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-mbstring": "~1.8" + "symfony/polyfill-mbstring": "~1.8", + "symfony/process": "^5.4|^6.4" }, "type": "library", "autoload": { @@ -2378,7 +2553,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v6.4.3" + "source": "https://github.com/symfony/filesystem/tree/v6.4.7" }, "funding": [ { @@ -2394,20 +2569,20 @@ "type": "tidelift" } ], - "time": "2024-01-23T14:51:35+00:00" + "time": "2024-04-18T09:22:46+00:00" }, { "name": "symfony/finder", - "version": "v6.4.0", + "version": "v6.4.7", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "11d736e97f116ac375a81f96e662911a34cd50ce" + "reference": "511c48990be17358c23bf45c5d71ab85d40fb764" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/11d736e97f116ac375a81f96e662911a34cd50ce", - "reference": "11d736e97f116ac375a81f96e662911a34cd50ce", + "url": "https://api.github.com/repos/symfony/finder/zipball/511c48990be17358c23bf45c5d71ab85d40fb764", + "reference": "511c48990be17358c23bf45c5d71ab85d40fb764", "shasum": "" }, "require": { @@ -2442,7 +2617,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v6.4.0" + "source": "https://github.com/symfony/finder/tree/v6.4.7" }, "funding": [ { @@ -2458,7 +2633,7 @@ "type": "tidelift" } ], - "time": "2023-10-31T17:30:12+00:00" + "time": "2024-04-23T10:36:43+00:00" }, { "name": "symfony/mailer", @@ -2627,16 +2802,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb" + "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", - "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ef4d7e442ca910c4764bce785146269b30cb5fc4", + "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4", "shasum": "" }, "require": { @@ -2650,9 +2825,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -2689,7 +2861,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.29.0" }, "funding": [ { @@ -2705,7 +2877,7 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-intl-idn", @@ -3106,22 +3278,84 @@ "time": "2024-01-29T20:11:03+00:00" }, { - "name": "symfony/service-contracts", - "version": "v3.4.2", + "name": "symfony/process", + "version": "v6.4.7", "source": { "type": "git", - "url": "https://github.com/symfony/service-contracts.git", - "reference": "11bbf19a0fb7b36345861e85c5768844c552906e" + "url": "https://github.com/symfony/process.git", + "reference": "cdb1c81c145fd5aa9b0038bab694035020943381" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/11bbf19a0fb7b36345861e85c5768844c552906e", - "reference": "11bbf19a0fb7b36345861e85c5768844c552906e", + "url": "https://api.github.com/repos/symfony/process/zipball/cdb1c81c145fd5aa9b0038bab694035020943381", + "reference": "cdb1c81c145fd5aa9b0038bab694035020943381", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Executes commands in sub-processes", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/process/tree/v6.4.7" + }, + "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": "2024-04-18T09:22:46+00:00" + }, + { + "name": "symfony/service-contracts", + "version": "v3.5.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/service-contracts.git", + "reference": "bd1d9e59a81d8fa4acdcea3f617c581f7475a80f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/bd1d9e59a81d8fa4acdcea3f617c581f7475a80f", + "reference": "bd1d9e59a81d8fa4acdcea3f617c581f7475a80f", "shasum": "" }, "require": { "php": ">=8.1", - "psr/container": "^1.1|^2.0" + "psr/container": "^1.1|^2.0", + "symfony/deprecation-contracts": "^2.5|^3" }, "conflict": { "ext-psr": "<1.1|>=2" @@ -3129,7 +3363,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.4-dev" + "dev-main": "3.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -3169,7 +3403,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.4.2" + "source": "https://github.com/symfony/service-contracts/tree/v3.5.0" }, "funding": [ { @@ -3185,7 +3419,7 @@ "type": "tidelift" } ], - "time": "2023-12-19T21:51:00+00:00" + "time": "2024-04-18T09:32:20+00:00" }, { "name": "vlucas/phpdotenv", @@ -3365,17 +3599,8 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^8.1", - "ext-bcmath": "*", - "ext-ctype": "*", - "ext-curl": "*", - "ext-intl": "*", - "ext-json": "*", - "ext-mbstring": "*", - "ext-mysqli": "*", - "ext-xml": "*", - "ext-xmlwriter": "*" + "php": "^8.1" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/filelist.php b/filelist.php index bbd30b7f1..b9aa39426 100644 --- a/filelist.php +++ b/filelist.php @@ -90,7 +90,7 @@ foreach ($files as $file) { $data = [ 'name' => !empty($t_name = $torrent->getName()) ? htmlCHR(substr($t_name, 0, 255)) : 'undefined', 'client' => !empty($creator = $torrent->getCreatedBy()) ? htmlCHR(substr($creator, 0, 20)) : 'unknown client', - 'date' => (!empty($dt = $torrent->getCreationDate()) && is_numeric($creation_date = $dt->getTimestamp())) ? date('d-M-Y H:i (e)', $creation_date) : 'unknown', + 'date' => (!empty($dt = $torrent->getCreationDate()) && is_numeric($creation_date = $dt->getTimestamp())) ? date('d-M-Y H:i (e)', $creation_date) : $lang['UNKNOWN'], 'size' => humn_size($row['size'], 2), 'file_count' => iterator_count($files), 'site_url' => FULL_URL, diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index 0b26ed5c2..ed6e7d497 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -506,7 +506,7 @@ VALUES ('allow_autologin', '1'), ('birthday_check_day', '7'), ('bt_add_auth_key', '1'), ('bt_allow_spmode_change', '1'), - ('bt_announce_url', ''), + ('bt_announce_url', 'https://localhost/bt/announce.php'), ('bt_disable_dht', '0'), ('bt_check_announce_url', '0'), ('bt_del_addit_ann_urls', '1'), @@ -654,6 +654,9 @@ VALUES ('1', 'Attach maintenance', 'attach_maintenance.php', 'daily', '', '05:00 '0', '0', '0'), ('1', 'Demo mode', 'demo_mode.php', 'daily', '', '05:00:00', '255', '', '', '', '1', 'demo_mode_cron', '1', '1', + '0'), + ('1', 'Update GeoLite DB', 'update_geolite_db.php', 'daily', '', '05:00:00', '255', '', '', '', '1', + 'update_geolite_db', '1', '1', '0'); -- ---------------------------- diff --git a/library/attach_mod/displaying_torrent.php b/library/attach_mod/displaying_torrent.php index e21badca0..ae7dab672 100644 --- a/library/attach_mod/displaying_torrent.php +++ b/library/attach_mod/displaying_torrent.php @@ -447,7 +447,8 @@ if ($tor_reged && $tor_info) { $template->assign_block_vars("$x_full.$x_row", [ 'ROW_BGR' => $row_bgr, 'NAME' => ($peer['update_time']) ? $name : "<s>$name</s>", - 'PEER_ID' => isset($peer['peer_id']) ? get_user_torrent_client($peer['peer_id']) : 'unknown', + 'PEER_ID' => isset($peer['peer_id']) ? get_user_torrent_client($peer['peer_id']) : $lang['UNKNOWN'], + 'COUNTRY' => render_flag(countryByIP($ip, $port), false), 'COMPL_PRC' => $compl_perc, 'UP_TOTAL' => ($max_up_id[$x] == $pid) ? "<b>$up_tot</b>" : $up_tot, 'DOWN_TOTAL' => ($max_down_id[$x] == $pid) ? "<b>$down_tot</b>" : $down_tot, diff --git a/library/config.php b/library/config.php index 9a26e20c4..be224e1c5 100644 --- a/library/config.php +++ b/library/config.php @@ -78,6 +78,7 @@ $bb_cfg['cache'] = [ 'bb_cap_sid' => ['filecache', []], 'bb_login_err' => ['filecache', []], 'bb_poll_data' => ['filecache', []], + 'bb_ip2countries' => ['filecache', []], ], ]; diff --git a/library/defines.php b/library/defines.php index a54b8438d..72df2a587 100644 --- a/library/defines.php +++ b/library/defines.php @@ -32,6 +32,20 @@ define('TEMPLATES_DIR', BB_PATH . '/styles/templates'); define('APP_NAME', 'TorrentPier'); define('UPDATER_URL', 'https://api.github.com/repos/torrentpier/torrentpier/releases/latest'); define('UPDATER_FILE', INT_DATA_DIR . '/updater.ver'); +define('CHECK_REQIREMENTS', [ + 'status' => true, + 'php_min_version' => '8.1.0', + 'ext_list' => [ + 'json', + 'curl', + 'mysqli', + 'bcmath', + 'mbstring', + 'intl', + 'xml', + 'xmlwriter', + ], +]); // Templates define('ADMIN_TPL_DIR', TEMPLATES_DIR . '/admin/'); diff --git a/library/includes/cron/jobs/board_maintenance.php b/library/includes/cron/jobs/board_maintenance.php index 2736600ca..b89cc4904 100644 --- a/library/includes/cron/jobs/board_maintenance.php +++ b/library/includes/cron/jobs/board_maintenance.php @@ -50,7 +50,7 @@ if ($posts_days = (int)$bb_cfg['posts_cache_days_keep']) { } // Autofill announcer url -if (empty($bb_cfg['bt_announce_url'])) { +if (empty($bb_cfg['bt_announce_url']) || ($bb_cfg['bt_announce_url'] === 'https://localhost/bt/announce.php')) { bb_update_config(['bt_announce_url' => FULL_URL . 'bt/announce.php']); } diff --git a/library/includes/cron/jobs/cache_gc.php b/library/includes/cron/jobs/cache_gc.php index 752aa0307..549d8447f 100644 --- a/library/includes/cron/jobs/cache_gc.php +++ b/library/includes/cron/jobs/cache_gc.php @@ -16,6 +16,6 @@ global $cron_runtime_log; foreach ($bb_cfg['cache']['engines'] as $cache_name => $cache_val) { if (method_exists(CACHE($cache_name), 'gc')) { $changes = CACHE($cache_name)->gc(); - $cron_runtime_log = date('Y-m-d H:i:s') . " -- " . str_pad("$cache_name ", 25, '-', STR_PAD_RIGHT) . " del: $changes\n"; + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- " . str_pad("$cache_name ", 25, '-', STR_PAD_RIGHT) . " del: $changes\n"; } } diff --git a/library/includes/cron/jobs/demo_mode.php b/library/includes/cron/jobs/demo_mode.php index eb61b0563..46113a2d7 100644 --- a/library/includes/cron/jobs/demo_mode.php +++ b/library/includes/cron/jobs/demo_mode.php @@ -37,7 +37,7 @@ foreach (file($dump_path) as $line) { $temp_line .= $line; if (str_ends_with(trim($line), ';')) { if (!DB()->query($temp_line)) { - $cron_runtime_log = date('Y-m-d H:i:s') . " -- Error performing query: " . $temp_line . " | " . DB()->sql_error()['message'] . "\n"; + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- Error performing query: " . $temp_line . " | " . DB()->sql_error()['message'] . "\n"; } $temp_line = ''; } diff --git a/library/includes/cron/jobs/update_geolite_db.php b/library/includes/cron/jobs/update_geolite_db.php new file mode 100644 index 000000000..7399c28f2 --- /dev/null +++ b/library/includes/cron/jobs/update_geolite_db.php @@ -0,0 +1,81 @@ +<?php +/** + * TorrentPier – Bull-powered BitTorrent tracker engine + * + * @copyright Copyright (c) 2005-2024 TorrentPier (https://torrentpier.com) + * @link https://github.com/torrentpier/torrentpier for the canonical source repository + * @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License + */ + +if (!defined('BB_ROOT')) { + die(basename(__FILE__)); +} + +set_time_limit(600); + +global $cron_runtime_log; + +$save_path = INT_DATA_DIR . '/GeoLite2-City.mmdb'; +$old_file_path = INT_DATA_DIR . '/GeoLite2-City.mmdb.old'; +$repo_link = 'https://api.github.com/repos/P3TERX/GeoLite.mmdb/releases/latest'; + +if (is_file($old_file_path) && unlink($old_file_path)) { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- Old GeoLite file successfully removed (First step)\n"; +} + +if (is_file($save_path)) { + if (rename($save_path, $old_file_path)) { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- Successfully created old GeoLite file\n"; + } else { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot create old GeoLite file\n"; + } +} else { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot find GeoLite file (It's okay)\n"; +} + +$context = stream_context_create(['http' => ['header' => 'User-Agent: ' . APP_NAME]]); +$repo_content = file_get_contents($repo_link, context: $context); + +$json_response = false; +if ($repo_content !== false) { + $json_response = json_decode(utf8_encode($repo_content), true); + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- Successfully connected to: " . $repo_link . "\n"; +} else { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot access to: " . $repo_link . "\n"; +} + +if (is_array($json_response) && !empty($json_response)) { + $download_link = $json_response['assets'][1]['browser_download_url']; + $file_date = $json_response['name'] ?? ''; + if (!empty($download_link)) { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- Link to download is valid: " . $download_link . "\n"; + $get_file = file_get_contents($download_link); + if ($get_file !== false) { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- GeoLite file obtained\n"; + file_put_contents($save_path, $get_file); // Save new GeoLite file! + if (is_file($save_path)) { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- GeoLite file successfully saved ($file_date)\n"; + if (is_file($old_file_path) && unlink($old_file_path)) { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- Old GeoLite file successfully removed (Second step)\n"; + } + } else { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- Reverting all changes...\n"; + if (is_file($old_file_path)) { + if (rename($old_file_path, $save_path)) { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- Successfully reverted\n"; + } else { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot revert changes, because cannot rename old file\n"; + } + } else { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot revert changes, old file not found\n"; + } + } + } else { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- GeoLite file not obtained\n"; + } + } else { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot find link to download\n"; + } +} else { + $cron_runtime_log .= date('Y-m-d H:i:s') . " -- Invalid response from server: " . $json_response . "\n"; +} diff --git a/library/includes/datastore/build_check_updates.php b/library/includes/datastore/build_check_updates.php index 3693447e6..ff3638b6d 100644 --- a/library/includes/datastore/build_check_updates.php +++ b/library/includes/datastore/build_check_updates.php @@ -15,7 +15,7 @@ global $bb_cfg; $data = []; -$context = stream_context_create(['http' => ['header' => 'User-Agent: TorrentPier Updater. With love!']]); +$context = stream_context_create(['http' => ['header' => 'User-Agent: ' . APP_NAME]]); $updater_content = file_get_contents(UPDATER_URL, context: $context); $json_response = false; diff --git a/library/includes/functions.php b/library/includes/functions.php index 62363af17..9da7fd870 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -2165,3 +2165,30 @@ function readUpdaterFile(): array|bool return false; } + +/** + * Show country ISO Code by user IP address + * + * @param string $ipAddress + * @param int $port + * @return mixed|string|null + */ +function countryByIP(string $ipAddress, int $port = 1111): mixed +{ + global $lang; + + if (!$data = CACHE('bb_ip2countries')->get($ipAddress . '_' . $port)) { + $cityDbReader = new \GeoIp2\Database\Reader(INT_DATA_DIR . '/GeoLite2-City.mmdb'); + try { + $record = $cityDbReader->city($ipAddress); + $data = $record->country->isoCode; + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { + $data = $lang['UNKNOWN']; + } catch (\MaxMind\Db\Reader\InvalidDatabaseException $e) { + bb_die($e->getMessage()); + } + CACHE('bb_ip2countries')->set($ipAddress . '_' . $port, $data, 1200); + } + + return $data; +} diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index 40a8aafef..4fe5ca47f 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -394,15 +394,15 @@ require_once INC_DIR . '/functions.php'; $bb_cfg = array_merge(bb_get_config(BB_CONFIG), $bb_cfg); $log_action = new TorrentPier\Legacy\LogAction(); +$wordCensor = new TorrentPier\Censor(); $html = new TorrentPier\Legacy\Common\Html(); $user = new TorrentPier\Legacy\Common\User(); $userdata =& $user->data; /** - * Word censor + * Check for updates */ -$wordCensor = new \TorrentPier\Censor(); /** * Cron diff --git a/library/language/source/main.php b/library/language/source/main.php index 4f30f0860..c5dab8d21 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -61,6 +61,7 @@ $lang['DISABLED'] = 'Disabled'; $lang['ERROR'] = 'Error'; $lang['SELECT_ACTION'] = 'Select action'; $lang['CLEAR'] = 'Clear'; +$lang['UNKNOWN'] = 'Unknown'; $lang['NEXT_PAGE'] = 'Next'; $lang['PREVIOUS_PAGE'] = 'Previous'; @@ -978,6 +979,7 @@ $lang['DATETIME']['NOV'] = 'Nov'; $lang['DATETIME']['DEC'] = 'Dec'; // Country selector +$lang['COUNTRY'] = 'Country'; $lang['COUNTRIES'] = [ 0 => 'No select', 'AD' => 'Andorra', diff --git a/src/Helpers/IsHelper.php b/src/Helpers/IsHelper.php index 87cd3ecb8..ec10f387f 100644 --- a/src/Helpers/IsHelper.php +++ b/src/Helpers/IsHelper.php @@ -15,6 +15,17 @@ namespace TorrentPier\Helpers; */ class IsHelper { + /** + * Determines if the current version of PHP is equal to or greater than the supplied value + * + * @param string $version + * @return bool TRUE if the current version is $version or higher + */ + public static function isPHP(string $version): bool + { + return version_compare(PHP_VERSION, $version, '>='); + } + /** * Return true if server have SSL * diff --git a/styles/templates/default/viewtopic_torrent.tpl b/styles/templates/default/viewtopic_torrent.tpl index 9d29a36ba..86a19d0e0 100644 --- a/styles/templates/default/viewtopic_torrent.tpl +++ b/styles/templates/default/viewtopic_torrent.tpl @@ -151,12 +151,13 @@ ajax.callback.callseed = function (data) { <th class="{sorter: 'digit'}"><b class="tbs-text">{L_DL_UL_SPEED}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th> <th class="{sorter: 'digit'}"><b class="tbs-text">{L_DL_DL_SPEED}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th> <!-- BEGIN iphead --> - <th class="{sorter: 'digit'}"><b class="tbs-text">{L_IP_ADDRESS}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th> + <th class="{sorter: false}"><b class="tbs-text">{L_IP_ADDRESS}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th> <!-- END iphead --> <!-- BEGIN porthead --> <th class="{sorter: 'digit'}"><b class="tbs-text">{L_DL_PORT}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th> <!-- END porthead --> <th class="{sorter: false}"><b class="tbs-text">{L_DL_CLIENT}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th> + <th class="{sorter: false}"><b class="tbs-text">{L_COUNTRY}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th> </tr> </thead> <!-- BEGIN srow --> @@ -174,6 +175,7 @@ ajax.callback.callseed = function (data) { <td>{sfull.srow.port.PORT}</td> <!-- END port --> <td>{sfull.srow.PEER_ID}</td> + <td>{sfull.srow.COUNTRY}</td> </tr> <!-- END srow --> </table> @@ -202,12 +204,13 @@ ajax.callback.callseed = function (data) { <th class="{sorter: 'digit'}"><b class="tbs-text">{L_DL_UL_SPEED}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th> <th class="{sorter: 'digit'}"><b class="tbs-text">{L_DL_DL_SPEED}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th> <!-- BEGIN iphead --> - <th class="{sorter: 'digit'}"><b class="tbs-text">{L_IP_ADDRESS}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th> + <th class="{sorter: false}"><b class="tbs-text">{L_IP_ADDRESS}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th> <!-- END iphead --> <!-- BEGIN porthead --> <th class="{sorter: 'digit'}"><b class="tbs-text">{L_DL_PORT}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th> <!-- END porthead --> <th class="{sorter: false}"><b class="tbs-text">{L_DL_CLIENT}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th> + <th class="{sorter: false}"><b class="tbs-text">{L_COUNTRY}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th> </tr> </thead> <!-- BEGIN lrow --> @@ -225,6 +228,7 @@ ajax.callback.callseed = function (data) { <td>{lfull.lrow.port.PORT}</td> <!-- END port --> <td>{lfull.lrow.PEER_ID}</td> + <td>{lfull.lrow.COUNTRY}</td> </tr> <!-- END lrow --> </table> @@ -234,7 +238,9 @@ ajax.callback.callseed = function (data) { </table> <!-- END lfull --> - <div class="med tCenter mrg_4 warnColor1">{L_DL_INFO}</div> + <div class="med tCenter mrg_4 warnColor1">{L_DL_INFO}</div> + <hr> + <div class="med tCenter mrg_4">This DL-list includes GeoLite2 data created by MaxMind, available from <a target="_blank" href="https://www.maxmind.com">https://www.maxmind.com</a>.</div> </div><!--/full_details--> <!-- ENDIF / PEER_EXIST -->