Merge branch 'master' into misc-Minor-improvements

This commit is contained in:
Roman Kelesidis 2025-05-05 18:59:55 +03:00 committed by GitHub
commit 1fa9691c04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 66 additions and 31 deletions

View file

@ -6,15 +6,19 @@
### 🚀 Features
- *(admin_smilies)* Added confirmation on smilie deleting ([#1895](https://github.com/torrentpier/torrentpier/pull/1895)) - ([b51820e](https://github.com/torrentpier/torrentpier/commit/b51820e1861044143321fcde5239c22abc3de984))
- Added ability to hide peer country in peer list ([#1891](https://github.com/torrentpier/torrentpier/pull/1891)) - ([2555ebc](https://github.com/torrentpier/torrentpier/commit/2555ebce4717f871922495e48cbca9e22da78bd5))
- Added ability to hide BitTorrent client in peers list ([#1890](https://github.com/torrentpier/torrentpier/pull/1890)) - ([f5d65b8](https://github.com/torrentpier/torrentpier/commit/f5d65b8911c5e864f000348a6d1aefbb4c09c2b4))
### 🐛 Bug Fixes
- Incorrect rounding in execution time counter ([#1899](https://github.com/torrentpier/torrentpier/pull/1899)) - ([781b724](https://github.com/torrentpier/torrentpier/commit/781b7240c41ddd141cfb057480c10d9cee30e6d7))
- `Undefined array key "smile"` when are no smilies ([#1896](https://github.com/torrentpier/torrentpier/pull/1896)) - ([36d3992](https://github.com/torrentpier/torrentpier/commit/36d399220e2c16a582e1e400df0002c164f5ec3b))
- Peer country flag not shown in peers list ([#1894](https://github.com/torrentpier/torrentpier/pull/1894)) - ([8edba72](https://github.com/torrentpier/torrentpier/commit/8edba72f09f037225ede058cf09c830b1a01e78f))
### ⚙️ Miscellaneous
- Minor improvements ([#1897](https://github.com/torrentpier/torrentpier/pull/1897)) - ([14086a0](https://github.com/torrentpier/torrentpier/commit/14086a0ed6181a0ff4496ee2e56f4fb70bfe18d5))
- Minor improvements ([#1893](https://github.com/torrentpier/torrentpier/pull/1893)) - ([90ece5c](https://github.com/torrentpier/torrentpier/commit/90ece5c7621789f170246b2898841b347e264674))
- Minor improvements ([#1892](https://github.com/torrentpier/torrentpier/pull/1892)) - ([1e5b93d](https://github.com/torrentpier/torrentpier/commit/1e5b93d2c072c5c35feef7567b3fcdb4b3597935))

View file

@ -73,7 +73,7 @@
"symfony/event-dispatcher": "^6.4",
"symfony/mime": "^6.4",
"symfony/mailer": "^6.4",
"symfony/polyfill": "v1.31.0",
"symfony/polyfill": "v1.32.0",
"vlucas/phpdotenv": "^5.5"
},
"require-dev": {

20
composer.lock generated
View file

@ -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": "291864741a4c19d097861853d529836c",
"content-hash": "2acad3dafd9fd57bc8c26303df22dd15",
"packages": [
{
"name": "arokettu/bencode",
@ -3310,16 +3310,16 @@
},
{
"name": "symfony/polyfill",
"version": "v1.31.0",
"version": "v1.32.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill.git",
"reference": "c5ce28b35b2784b7b508aaa4447a6c3e39041e50"
"reference": "c4ee386e95ccdbea59cea802ea776d806319d506"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill/zipball/c5ce28b35b2784b7b508aaa4447a6c3e39041e50",
"reference": "c5ce28b35b2784b7b508aaa4447a6c3e39041e50",
"url": "https://api.github.com/repos/symfony/polyfill/zipball/c4ee386e95ccdbea59cea802ea776d806319d506",
"reference": "c4ee386e95ccdbea59cea802ea776d806319d506",
"shasum": ""
},
"require": {
@ -3342,6 +3342,7 @@
"symfony/polyfill-php82": "self.version",
"symfony/polyfill-php83": "self.version",
"symfony/polyfill-php84": "self.version",
"symfony/polyfill-php85": "self.version",
"symfony/polyfill-util": "self.version",
"symfony/polyfill-uuid": "self.version"
},
@ -3372,6 +3373,7 @@
"src/Intl/Icu/Resources/stubs",
"src/Intl/MessageFormatter/Resources/stubs",
"src/Intl/Normalizer/Resources/stubs",
"src/Php85/Resources/stubs",
"src/Php84/Resources/stubs",
"src/Php83/Resources/stubs",
"src/Php82/Resources/stubs",
@ -3405,7 +3407,7 @@
],
"support": {
"issues": "https://github.com/symfony/polyfill/issues",
"source": "https://github.com/symfony/polyfill/tree/v1.31.0"
"source": "https://github.com/symfony/polyfill/tree/v1.32.0"
},
"funding": [
{
@ -3421,7 +3423,7 @@
"type": "tidelift"
}
],
"time": "2024-09-09T12:16:23+00:00"
"time": "2025-05-02T09:40:28+00:00"
},
{
"name": "symfony/service-contracts",
@ -3743,6 +3745,6 @@
"platform": {
"php": ">=8.1"
},
"platform-dev": {},
"plugin-api-version": "2.6.0"
"platform-dev": [],
"plugin-api-version": "2.3.0"
}

View file

@ -463,10 +463,12 @@ if ($tor_reged && $tor_info) {
}
$peerCountry = $lang['UNKNOWN'];
if (IS_AM || $peer['user_id'] == $userdata['user_id'] || !bf($peer['user_opt'], 'user_opt', 'user_hide_peer_country')) {
if ($infoByIP = infoByIP((!empty($peer['ipv6']) ? $peer['ipv6'] : $peer['ip']), $peer['port'])) {
if (!empty($infoByIP['countryCode'])) {
$peerCountry = render_flag($infoByIP['countryCode'], false);
if ($bb_cfg['ip2country_settings']['enabled']) {
if (IS_AM || $peer['user_id'] == $userdata['user_id'] || !bf($peer['user_opt'], 'user_opt', 'user_hide_peer_country')) {
if ($infoByIP = infoByIP((!empty($peer['ipv6']) ? $peer['ipv6'] : $peer['ip']), $peer['port'])) {
if (!empty($infoByIP['countryCode'])) {
$peerCountry = render_flag($infoByIP['countryCode'], false);
}
}
}
}

View file

@ -144,6 +144,14 @@ $bb_cfg['torr_server'] = [
'disable_for_guest' => true
];
// FreeIPAPI settings
$bb_cfg['ip2country_settings'] = [
// Documentation: https://docs.freeipapi.com/
'enabled' => true,
'endpoint' => 'https://freeipapi.com/api/json/',
'api_token' => '', // not required for basic usage
];
// FAQ url help link
$bb_cfg['how_to_download_url_help'] = 'viewtopic.php?t=1'; // How to download?
$bb_cfg['what_is_torrent_url_help'] = 'viewtopic.php?t=2'; // What is a torrent?

View file

@ -35,9 +35,6 @@ define('UPDATER_URL', 'https://api.github.com/repos/torrentpier/torrentpier/rele
define('UPDATER_FILE', INT_DATA_DIR . '/updater.json');
define('COOKIE_DBG', 'bb_dbg');
// TODO: Move in another section
define('API_IP_URL', 'https://freeipapi.com/api/json/');
// Templates
define('ADMIN_TPL_DIR', TEMPLATES_DIR . '/admin/');
define('XS_USE_ISSET', '1');

View file

@ -2186,20 +2186,40 @@ function readUpdaterFile(): array|bool
*/
function infoByIP(string $ipAddress, int $port = 0): array
{
global $bb_cfg;
if (!$bb_cfg['ip2country_settings']['enabled']) {
return [];
}
$ipAddress = \TorrentPier\Helpers\IPHelper::long2ip_extended($ipAddress);
$cacheName = hash('xxh128', ($ipAddress . '_' . $port));
if (!$data = CACHE('bb_ip2countries')->get($cacheName)) {
$data = [];
$response = file_get_contents(API_IP_URL . $ipAddress);
$json = json_decode($response, true);
if (is_array($json) && !empty($json)) {
$data = [
'ipVersion' => $json['ipVersion'],
'countryCode' => $json['countryCode'],
'continent' => $json['continent'],
'continentCode' => $json['continentCode']
$contextOptions = [];
if (!empty($bb_cfg['ip2country_settings']['api_token'])) {
$contextOptions['http'] = [
'header' => "Authorization: Bearer " . $bb_cfg['ip2country_settings']['api_token'] . "\r\n"
];
CACHE('bb_ip2countries')->set($cacheName, $data, 1200);
}
$context = stream_context_create($contextOptions);
$response = file_get_contents($bb_cfg['ip2country_settings']['endpoint'] . $ipAddress, context: $context);
if ($response !== false) {
$json = json_decode($response, true);
if (is_array($json) && !empty($json)) {
$data = [
'ipVersion' => $json['ipVersion'],
'countryCode' => $json['countryCode'],
'continent' => $json['continent'],
'continentCode' => $json['continentCode']
];
CACHE('bb_ip2countries')->set($cacheName, $data, 1200);
}
}
}

View file

@ -366,7 +366,7 @@ foreach ($profile_fields as $field => $can_edit) {
'user_callseed' => $reg_mode ? true : true,
'user_retracker' => $reg_mode ? true : true,
'user_hide_torrent_client' => $reg_mode ? true : true,
'user_hide_peer_country' => $reg_mode ? true : true,
'user_hide_peer_country' => $reg_mode ? true : $bb_cfg['ip2country_settings']['enabled'],
];
foreach ($update_user_opt as $opt => $can_change_opt) {

View file

@ -326,6 +326,7 @@
<label><input type="radio" name="user_hide_torrent_client" value="0" <!-- IF not USER_HIDE_TORRENT_CLIENT -->checked<!-- ENDIF --> />{L_NO}</label>
</td>
</tr>
<!-- IF $bb_cfg['ip2country_settings']['enabled'] -->
<tr>
<td class="prof-title">{L_HIDE_PEER_COUNTRY_NAME}:</td>
<td>
@ -333,6 +334,7 @@
<label><input type="radio" name="user_hide_peer_country" value="0" <!-- IF not USER_HIDE_PEER_COUNTRY -->checked<!-- ENDIF --> />{L_NO}</label>
</td>
</tr>
<!-- ENDIF -->
<tr>
<th colspan="2">{L_AVATAR_PANEL}</th>
</tr>

View file

@ -155,7 +155,7 @@ ajax.callback.callseed = function (data) {
<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>
<!-- IF $bb_cfg['ip2country_settings']['enabled'] --><th class="{sorter: false}"><b class="tbs-text">{L_COUNTRY}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th><!-- ENDIF -->
</tr>
</thead>
<!-- BEGIN srow -->
@ -173,7 +173,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>
<!-- IF $bb_cfg['ip2country_settings']['enabled'] --><td>{sfull.srow.COUNTRY}</td><!-- ENDIF -->
</tr>
<!-- END srow -->
</table>
@ -208,7 +208,7 @@ ajax.callback.callseed = function (data) {
<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>
<!-- IF $bb_cfg['ip2country_settings']['enabled'] --><th class="{sorter: false}"><b class="tbs-text">{L_COUNTRY}</b><img width="75" class="spacer" src="{SPACER}" alt="" /></th><!-- ENDIF -->
</tr>
</thead>
<!-- BEGIN lrow -->
@ -226,7 +226,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>
<!-- IF $bb_cfg['ip2country_settings']['enabled'] --><td>{lfull.lrow.COUNTRY}</td><!-- ENDIF -->
</tr>
<!-- END lrow -->
</table>