mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-14 18:48:21 -07:00
feat(freeipapi): Added ability to use own API token (#1901)
* feat(freeipapi): Added ability to use own API token * Updated * Update displaying_torrent.php * Update usercp_register.tpl * Update register.php
This commit is contained in:
parent
a4793f6ce1
commit
513e3065d3
7 changed files with 50 additions and 21 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue