mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-22 02:47:27 +08:00
Detect if IP is SeedBox
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
class SeedBoxYesException extends NexusException
|
||||
{
|
||||
private int $id;
|
||||
|
||||
public function __construct($id)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
namespace App\Filament\Resources\System\SeedBoxRecordResource\Pages;
|
||||
|
||||
use App\Exceptions\SeedBoxYesException;
|
||||
use App\Filament\PageList;
|
||||
use App\Filament\Resources\System\SeedBoxRecordResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Forms;
|
||||
|
||||
class ListSeedBoxRecords extends PageList
|
||||
{
|
||||
@@ -15,6 +16,24 @@ class ListSeedBoxRecords extends PageList
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
Actions\Action::make('check')
|
||||
->label(__('admin.resources.seed_box_record.check_modal_btn'))
|
||||
->form([
|
||||
Forms\Components\TextInput::make('ip')->required()->label('IP'),
|
||||
Forms\Components\TextInput::make('uid')->required()->label('UID'),
|
||||
])
|
||||
->modalHeading(__('admin.resources.seed_box_record.check_modal_header'))
|
||||
->action(function ($data) {
|
||||
try {
|
||||
isIPSeedBox($data['ip'], $data['uid'], true, true);
|
||||
$this->notify('success', nexus_trans("seed-box.is_seed_box_no"));
|
||||
} catch (SeedBoxYesException $exception) {
|
||||
$this->notify('danger', nexus_trans("seed-box.is_seed_box_yes", ['id' => $exception->getId()]));
|
||||
} catch (\Throwable $throwable) {
|
||||
do_log($throwable->getMessage() . $throwable->getTraceAsString(), "error");
|
||||
$this->notify('danger', $throwable->getMessage());
|
||||
}
|
||||
})
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.14');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-11-08');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-11-22');
|
||||
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||
|
||||
@@ -857,7 +857,7 @@ function do_action($name, ...$args)
|
||||
return $hook->doAction(...func_get_args());
|
||||
}
|
||||
|
||||
function isIPSeedBoxFromASN($ip): bool
|
||||
function isIPSeedBoxFromASN($ip, $exceptionWhenYes = false): bool
|
||||
{
|
||||
try {
|
||||
static $reader;
|
||||
@@ -875,14 +875,18 @@ function isIPSeedBoxFromASN($ip): bool
|
||||
return false;
|
||||
}
|
||||
$row = \Nexus\Database\NexusDB::getOne("seed_box_records", "asn = $asn", "id");
|
||||
return !empty($row);
|
||||
} catch (\Throwable $throwable) {
|
||||
do_log("ip: $ip, error: " . $throwable->getMessage(), "error");
|
||||
return false;
|
||||
}
|
||||
$result = !empty($row);
|
||||
if ($result && $exceptionWhenYes) {
|
||||
throw new \App\Exceptions\SeedBoxYesException($row['id']);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function isIPSeedBox($ip, $uid, $withoutCache = false): bool
|
||||
function isIPSeedBox($ip, $uid, $withoutCache = false, $exceptionWhenYes = false): bool
|
||||
{
|
||||
$key = "nexus_is_ip_seed_box:ip:$ip:uid:$uid";
|
||||
$cacheData = \Nexus\Database\NexusDB::cache_get($key);
|
||||
@@ -891,7 +895,7 @@ function isIPSeedBox($ip, $uid, $withoutCache = false): bool
|
||||
return (bool)$cacheData;
|
||||
}
|
||||
//check from asn
|
||||
$res = isIPSeedBoxFromASN($ip);
|
||||
$res = isIPSeedBoxFromASN($ip, $exceptionWhenYes);
|
||||
if (!empty($res)) {
|
||||
\Nexus\Database\NexusDB::cache_put($key, 1, 300);
|
||||
do_log("$key, get result from asn, true");
|
||||
@@ -920,6 +924,9 @@ function isIPSeedBox($ip, $uid, $withoutCache = false): bool
|
||||
if (!empty($res)) {
|
||||
\Nexus\Database\NexusDB::cache_put($key, 1, 300);
|
||||
do_log("$key, get result from admin, true");
|
||||
if ($exceptionWhenYes) {
|
||||
throw new \App\Exceptions\SeedBoxYesException($res[0]['id']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if ($uid !== null) {
|
||||
@@ -931,6 +938,9 @@ function isIPSeedBox($ip, $uid, $withoutCache = false): bool
|
||||
if (!empty($res)) {
|
||||
\Nexus\Database\NexusDB::cache_put($key, 1, 300);
|
||||
do_log("$key, get result from user, true");
|
||||
if ($exceptionWhenYes) {
|
||||
throw new \App\Exceptions\SeedBoxYesException($res[0]['id']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1313,3 +1323,13 @@ function convertNamespaceToSnake(string $str): string
|
||||
{
|
||||
return str_replace(["\\", "::"], ["_", "."], $str);
|
||||
}
|
||||
|
||||
function get_user_locale(int $uid): string
|
||||
{
|
||||
$sql = "select language.site_lang_folder from useers inner join language on users.lang = language.id where users.id = $uid limit 1";
|
||||
$result = \Nexus\Database\NexusDB::select($sql);
|
||||
if (empty($result) || empty($result['site_lang_folder'])) {
|
||||
return "en";
|
||||
}
|
||||
return \App\Http\Middleware\Locale::$languageMaps[$result['site_lang_folder']] ?? 'en';
|
||||
}
|
||||
|
||||
@@ -118,6 +118,8 @@ return [
|
||||
],
|
||||
'seed_box_record' => [
|
||||
'toggle_status' => 'Change status',
|
||||
'check_modal_btn' => 'Check',
|
||||
'check_modal_header' => 'Detect if IP is SeedBox',
|
||||
],
|
||||
'tag' => [
|
||||
'detach_torrents' => 'Detach all torrents',
|
||||
|
||||
@@ -14,4 +14,6 @@ return [
|
||||
'subject' => 'SeedBox record status changed',
|
||||
'body' => 'The status of your SeedBox record with ID :id was changed by :operator from :old_status to :new_status. Reason: :reason',
|
||||
],
|
||||
'is_seed_box_yes' => 'This IP is SeedBox, identified by the record with ID :id',
|
||||
'is_seed_box_no' => 'This IP is not SeedBox',
|
||||
];
|
||||
|
||||
@@ -116,6 +116,8 @@ return [
|
||||
],
|
||||
'seed_box_record' => [
|
||||
'toggle_status' => '更改状态',
|
||||
'check_modal_btn' => '检测',
|
||||
'check_modal_header' => '检测 IP 是否为 SeedBox',
|
||||
],
|
||||
'tag' => [
|
||||
'detach_torrents' => '分离所有种子',
|
||||
|
||||
@@ -14,4 +14,6 @@ return [
|
||||
'subject' => 'SeedBox 记录状态变更',
|
||||
'body' => '你的 ID 为 :id 的 SeedBox 记录状态被 :operator 由 :old_status 变更为 :new_status。原因::reason',
|
||||
],
|
||||
'is_seed_box_yes' => '此 IP 是 SeedBox, 由 ID 为 :id 的记录确定',
|
||||
'is_seed_box_no' => '此 IP 不是 SeedBox',
|
||||
];
|
||||
|
||||
@@ -118,6 +118,8 @@ return [
|
||||
],
|
||||
'seed_box_record' => [
|
||||
'toggle_status' => '更改狀態',
|
||||
'check_modal_btn' => '檢測',
|
||||
'check_modal_header' => '檢測 IP 是否為 SeedBox',
|
||||
],
|
||||
'tag' => [
|
||||
'detach_torrents' => '分離所有種子',
|
||||
|
||||
@@ -14,4 +14,6 @@ return [
|
||||
'subject' => 'SeedBox 記錄狀態變更',
|
||||
'body' => '你的 ID 為 :id 的 SeedBox 記錄狀態被 :operator 由 :old_status 變更為 :new_status。原因::reason',
|
||||
],
|
||||
'is_seed_box_yes' => '此 IP 是 SeedBox, 由 ID 為 :id 的記錄確定',
|
||||
'is_seed_box_no' => '此 IP 不是 SeedBox',
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user