mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
finish seed box basic
This commit is contained in:
@@ -85,8 +85,11 @@ class Test extends Command
|
||||
{
|
||||
$ip = '116.30.133.129';
|
||||
// $ip = '240e:3a1:680c:bb11:211:32ff:fe2c:a603';
|
||||
$ipObj = IPBlock::create($ip);
|
||||
$r = $ipObj->getFirstIp();
|
||||
// $ipObj = IPBlock::create($ip);
|
||||
// $ipObj = IP::create($ip);
|
||||
// $r = $ipObj->getVersion();
|
||||
$r = get_ip_location('116.30.133.129');
|
||||
// $r = get_ip_location_from_geoip('116.30.133.129');
|
||||
dd($r);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace App\Filament\Resources\System;
|
||||
use App\Filament\Resources\System\SeedBoxRecordResource\Pages;
|
||||
use App\Filament\Resources\System\SeedBoxRecordResource\RelationManagers;
|
||||
use App\Models\SeedBoxRecord;
|
||||
use App\Repositories\SeedBoxRepository;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Resource;
|
||||
@@ -12,6 +14,7 @@ use Filament\Resources\Table;
|
||||
use Filament\Tables;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\See;
|
||||
|
||||
class SeedBoxRecordResource extends Resource
|
||||
{
|
||||
@@ -25,7 +28,7 @@ class SeedBoxRecordResource extends Resource
|
||||
|
||||
protected static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.sidebar.seedbox_records');
|
||||
return __('admin.sidebar.seed_box_records');
|
||||
}
|
||||
|
||||
public static function getBreadcrumb(): string
|
||||
@@ -37,11 +40,11 @@ class SeedBoxRecordResource extends Resource
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('operator')->label(__('label.seedbox_record.operator')),
|
||||
Forms\Components\TextInput::make('bandwidth')->label(__('label.seedbox_record.bandwidth'))->integer(),
|
||||
Forms\Components\TextInput::make('ip_begin')->label(__('label.seedbox_record.ip_begin')),
|
||||
Forms\Components\TextInput::make('ip_end')->label(__('label.seedbox_record.ip_end')),
|
||||
Forms\Components\TextInput::make('ip')->label(__('label.seedbox_record.ip'))->helperText(__('label.seedbox_record.ip_help')),
|
||||
Forms\Components\TextInput::make('operator')->label(__('label.seed_box_record.operator')),
|
||||
Forms\Components\TextInput::make('bandwidth')->label(__('label.seed_box_record.bandwidth'))->integer(),
|
||||
Forms\Components\TextInput::make('ip_begin')->label(__('label.seed_box_record.ip_begin')),
|
||||
Forms\Components\TextInput::make('ip_end')->label(__('label.seed_box_record.ip_end')),
|
||||
Forms\Components\TextInput::make('ip')->label(__('label.seed_box_record.ip'))->helperText(__('label.seed_box_record.ip_help')),
|
||||
Forms\Components\Textarea::make('comment')->label(__('label.comment')),
|
||||
])->columns(1);
|
||||
}
|
||||
@@ -51,18 +54,45 @@ class SeedBoxRecordResource extends Resource
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id'),
|
||||
Tables\Columns\TextColumn::make('typeText')->label(__('label.seedbox_record.type')),
|
||||
Tables\Columns\TextColumn::make('user.username')->label(__('label.username')),
|
||||
Tables\Columns\TextColumn::make('operation')->label(__('label.seedbox_record.operator')),
|
||||
Tables\Columns\TextColumn::make('bandwidth')->label(__('label.seedbox_record.bandwidth')),
|
||||
Tables\Columns\TextColumn::make('ip')->label(__('label.seedbox_record.ip'))->formatStateUsing(fn ($record) => $record->ip ?: sprintf('%s ~ %s', $record->ip_begin, $record->ip_end)),
|
||||
Tables\Columns\TextColumn::make('typeText')->label(__('label.seed_box_record.type')),
|
||||
Tables\Columns\TextColumn::make('user.username')->label(__('label.username'))->searchable(),
|
||||
Tables\Columns\TextColumn::make('operator')->label(__('label.seed_box_record.operator'))->searchable(),
|
||||
Tables\Columns\TextColumn::make('bandwidth')->label(__('label.seed_box_record.bandwidth')),
|
||||
Tables\Columns\TextColumn::make('ip')
|
||||
->label(__('label.seed_box_record.ip'))
|
||||
->searchable()
|
||||
->formatStateUsing(fn ($record) => $record->ip ?: sprintf('%s ~ %s', $record->ip_begin, $record->ip_end)),
|
||||
Tables\Columns\TextColumn::make('comment')->label(__('label.comment')),
|
||||
Tables\Columns\BadgeColumn::make('status')
|
||||
->colors([
|
||||
'success' => SeedBoxRecord::STATUS_ALLOWED,
|
||||
'warning' => SeedBoxRecord::STATUS_UNAUDITED,
|
||||
'danger' => SeedBoxRecord::STATUS_DENIED,
|
||||
])
|
||||
->formatStateUsing(fn ($record) => $record->statusText)
|
||||
->label(__('label.seed_box_record.status')),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
Tables\Filters\SelectFilter::make('type')->options(SeedBoxRecord::listTypes('text'))->label(__('label.seed_box_record.type')),
|
||||
Tables\Filters\SelectFilter::make('status')->options(SeedBoxRecord::listStatus('text'))->label(__('label.seed_box_record.status')),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\Action::make('audit')
|
||||
->label(__('admin.resources.seed_box_record.toggle_status'))
|
||||
->form([
|
||||
Forms\Components\Radio::make('status')->options(SeedBoxRecord::listStatus('text'))
|
||||
->inline()->label(__('label.seed_box_record.status'))->required()
|
||||
])
|
||||
->action(function (SeedBoxRecord $record, array $data) {
|
||||
$rep = new SeedBoxRepository();
|
||||
try {
|
||||
$rep->updateStatus($record, $data['status']);
|
||||
} catch (\Exception $exception) {
|
||||
Filament::notify('danger', class_basename($exception));
|
||||
}
|
||||
})
|
||||
,
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
|
||||
@@ -13,23 +13,28 @@ class CreateSeedBoxRecord extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SeedBoxRecordResource::class;
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
public function create(bool $another = false): void
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
$data['uid'] = auth()->id();
|
||||
$data['type'] = SeedBoxRecord::TYPE_ADMIN;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function handleRecordCreation(array $data): Model
|
||||
{
|
||||
$seedBoxRep = new SeedBoxRepository();
|
||||
$data['status'] = SeedBoxRecord::STATUS_ALLOWED;
|
||||
$rep = new SeedBoxRepository();
|
||||
try {
|
||||
return $seedBoxRep->store($data);
|
||||
$this->record = $rep->store($data);
|
||||
$this->notify('success', $this->getCreatedNotificationMessage());
|
||||
if ($another) {
|
||||
// Ensure that the form record is anonymized so that relationships aren't loaded.
|
||||
$this->form->model($this->record::class);
|
||||
$this->record = null;
|
||||
|
||||
$this->fillForm();
|
||||
|
||||
return;
|
||||
}
|
||||
$this->redirect($this->getResource()::getUrl('index'));
|
||||
} catch (\Exception $exception) {
|
||||
//this wont work...
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Filament\Resources\System\SeedBoxRecordResource\Pages;
|
||||
|
||||
use App\Filament\Resources\System\SeedBoxRecordResource;
|
||||
use App\Repositories\SeedBoxRepository;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
@@ -16,4 +17,17 @@ class EditSeedBoxRecord extends EditRecord
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
public function save(bool $shouldRedirect = true): void
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
$rep = new SeedBoxRepository();
|
||||
try {
|
||||
$this->record = $rep->update($data, $this->record->id);
|
||||
$this->notify('success', $this->getSavedNotificationMessage());
|
||||
$this->redirect($this->getResource()::getUrl('index'));
|
||||
} catch (\Exception $exception) {
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
])->columns(2),
|
||||
Forms\Components\Tabs\Tab::make(__('label.setting.backup.tab_header'))
|
||||
->schema([
|
||||
Forms\Components\Radio::make('backup.enabled')->options(self::$yesOrNo)->inline(true)->label(__('label.setting.backup.enabled'))->helperText(__('label.setting.backup.enabled_help')),
|
||||
Forms\Components\Radio::make('backup.enabled')->options(self::$yesOrNo)->inline(true)->label(__('label.enabled'))->helperText(__('label.setting.backup.enabled_help')),
|
||||
Forms\Components\Radio::make('backup.frequency')->options(['daily' => 'daily', 'hourly' => 'hourly'])->inline(true)->label(__('label.setting.backup.frequency'))->helperText(__('label.setting.backup.frequency_help')),
|
||||
Forms\Components\Select::make('backup.hour')->options(range(0, 23))->label(__('label.setting.backup.hour'))->helperText(__('label.setting.backup.hour_help')),
|
||||
Forms\Components\Select::make('backup.minute')->options(range(0, 59))->label(__('label.setting.backup.minute'))->helperText(__('label.setting.backup.minute_help')),
|
||||
@@ -63,6 +63,13 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
Forms\Components\Radio::make('backup.via_ftp')->options(self::$yesOrNo)->inline(true)->label(__('label.setting.backup.via_ftp'))->helperText(__('label.setting.backup.via_ftp_help')),
|
||||
Forms\Components\Radio::make('backup.via_sftp')->options(self::$yesOrNo)->inline(true)->label(__('label.setting.backup.via_sftp'))->helperText(__('label.setting.backup.via_sftp_help')),
|
||||
])->columns(2),
|
||||
Forms\Components\Tabs\Tab::make(__('label.setting.seed_box.tab_header'))
|
||||
->schema([
|
||||
Forms\Components\Radio::make('seed_box.enabled')->options(self::$yesOrNo)->inline(true)->label(__('label.enabled'))->helperText(__('label.setting.seed_box.enabled_help')),
|
||||
Forms\Components\TextInput::make('seed_box.not_seed_box_max_speed')->label(__('label.setting.seed_box.not_seed_box_max_speed'))->helperText(__('label.setting.seed_box.not_seed_box_max_speed_help'))->integer(),
|
||||
Forms\Components\Radio::make('seed_box.no_promotion')->options(self::$yesOrNo)->inline(true)->label(__('label.setting.seed_box.no_promotion'))->helperText(__('label.setting.seed_box.no_promotion_help')),
|
||||
Forms\Components\TextInput::make('seed_box.max_uploaded')->label(__('label.setting.seed_box.max_uploaded'))->helperText(__('label.setting.seed_box.max_uploaded_help'))->integer(),
|
||||
])->columns(2),
|
||||
])
|
||||
];
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class Message extends NexusModel
|
||||
{
|
||||
protected $table = 'messages';
|
||||
@@ -24,4 +26,11 @@ class Message extends NexusModel
|
||||
return $this->belongsTo(User::class, 'receiver');
|
||||
}
|
||||
|
||||
public static function add(array $data): bool
|
||||
{
|
||||
NexusDB::cache_del('user_'.$data["receiver"].'_inbox_count');
|
||||
NexusDB::cache_del('user_'.$data["receiver"].'_unread_message_count');
|
||||
return self::query()->insert($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,22 +6,68 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class SeedBoxRecord extends NexusModel
|
||||
{
|
||||
protected $table = 'seedbox_records';
|
||||
|
||||
protected $fillable = ['type', 'uid', 'operator', 'bandwidth', 'ip', 'ip_begin', 'ip_end', 'ip_begin_numeric', 'ip_end_numeric', 'comment'];
|
||||
protected $fillable = ['type', 'uid', 'status', 'operator', 'bandwidth', 'ip', 'ip_begin', 'ip_end', 'ip_begin_numeric', 'ip_end_numeric', 'comment', 'version'];
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
const TYPE_USER = 1;
|
||||
const TYPE_ADMIN = 2;
|
||||
|
||||
public static array $types = [
|
||||
self::TYPE_USER => ['text' => 'User'],
|
||||
self::TYPE_ADMIN => ['text' => 'Administrator'],
|
||||
];
|
||||
|
||||
const STATUS_UNAUDITED = 0;
|
||||
const STATUS_ALLOWED = 1;
|
||||
const STATUS_DENIED = 2;
|
||||
|
||||
public static array $status = [
|
||||
self::STATUS_UNAUDITED => ['text' => 'Unaudited'],
|
||||
self::STATUS_ALLOWED => ['text' => 'Allowed'],
|
||||
self::STATUS_DENIED => ['text' => 'Denied'],
|
||||
];
|
||||
|
||||
protected function typeText(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn($value, $attributes) => __("seedbox.type_text." . $attributes['type'])
|
||||
get: fn($value, $attributes) => nexus_trans("seed-box.type_text." . $attributes['type'])
|
||||
);
|
||||
}
|
||||
|
||||
protected function statusText(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn($value, $attributes) => nexus_trans("seed-box.status_text." . $attributes['status'])
|
||||
);
|
||||
}
|
||||
|
||||
public static function listTypes($key = null): array
|
||||
{
|
||||
$result = self::$types;
|
||||
$keyValues = [];
|
||||
foreach ($result as $type => &$info) {
|
||||
$info['text'] = nexus_trans("seed-box.type_text.$type");
|
||||
if ($key !== null) {
|
||||
$keyValues[$type] = $info[$key];
|
||||
}
|
||||
}
|
||||
return $key === null ? $result : $keyValues;
|
||||
}
|
||||
|
||||
public static function listStatus($key = null): array
|
||||
{
|
||||
$result = self::$status;
|
||||
$keyValues = [];
|
||||
foreach ($result as $status => &$info) {
|
||||
$info['text'] = nexus_trans("seed-box.status_text.$status");
|
||||
if ($key !== null) {
|
||||
$keyValues[$status] = $info[$key];
|
||||
}
|
||||
}
|
||||
return $key === null ? $result : $keyValues;
|
||||
}
|
||||
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'uid');
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
<?php
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Exceptions\InsufficientPermissionException;
|
||||
use App\Models\Message;
|
||||
use App\Models\Poll;
|
||||
use App\Models\SeedBoxRecord;
|
||||
use App\Models\Torrent;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Nexus\Database\NexusDB;
|
||||
use PhpIP\IP;
|
||||
use PhpIP\IPBlock;
|
||||
|
||||
@@ -20,35 +24,66 @@ class SeedBoxRepository extends BaseRepository
|
||||
return $query->paginate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function store(array $params)
|
||||
{
|
||||
$params = $this->formatParams($params);
|
||||
$seedBoxRecord = SeedBoxRecord::query()->create($params);
|
||||
$this->clearCache();
|
||||
return $seedBoxRecord;
|
||||
}
|
||||
|
||||
private function formatParams(array $params): array
|
||||
{
|
||||
if (!empty($params['ip']) && empty($params['ip_begin']) && empty($params['ip_end'])) {
|
||||
if (str_contains($params['ip'], '/')) {
|
||||
try {
|
||||
$ipBlock = IPBlock::create($params['ip']);
|
||||
$params['ip_begin_numeric'] = $ipBlock->getFirstIp()->numeric();
|
||||
$params['ip_end_numeric'] = $ipBlock->getLastIp()->numeric();
|
||||
} else {
|
||||
$ip = IP::create($params['ip']);
|
||||
$params['ip_begin_numeric'] = $ip->numeric();
|
||||
$params['ip_end_numeric'] = $ip->numeric();
|
||||
$params['version'] = $ipBlock->getVersion();
|
||||
} catch (\Exception $exception) {
|
||||
do_log("[NOT_IP_BLOCK], {$params['ip']}" . $exception->getMessage());
|
||||
}
|
||||
if (empty($params['version'])) {
|
||||
try {
|
||||
$ip = IP::create($params['ip']);
|
||||
$params['ip_begin_numeric'] = $ip->numeric();
|
||||
$params['ip_end_numeric'] = $ip->numeric();
|
||||
$params['version'] = $ip->getVersion();
|
||||
} catch (\Exception $exception) {
|
||||
do_log("[NOT_IP], {$params['ip']}" . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
if (empty($params['version'])) {
|
||||
throw new \InvalidArgumentException("Invalid IPBlock or IP: " . $params['ip']);
|
||||
}
|
||||
|
||||
} elseif (empty($params['ip']) && !empty($params['ip_begin']) && !empty($params['ip_end'])) {
|
||||
$ipBegin = IP::create($params['ip_begin']);
|
||||
$params['ip_begin_numeric'] = $ipBegin->numeric();
|
||||
|
||||
$ipEnd = IP::create($params['ip_end']);
|
||||
$params['ip_end_numeric'] = $ipEnd->numeric();
|
||||
if ($ipBegin->getVersion() != $ipEnd->getVersion()) {
|
||||
throw new \InvalidArgumentException("ip_begin/ip_end must be the same version");
|
||||
}
|
||||
$params['version'] = $ipEnd->getVersion();
|
||||
} else {
|
||||
throw new \InvalidArgumentException("Require ip or ip_begin + ip_end");
|
||||
}
|
||||
|
||||
return SeedBoxRecord::query()->create($params);
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function update(array $params, $id)
|
||||
{
|
||||
$model = Poll::query()->findOrFail($id);
|
||||
$model = SeedBoxRecord::query()->findOrFail($id);
|
||||
$params = $this->formatParams($params);
|
||||
$model->update($params);
|
||||
$this->clearCache();
|
||||
return $model;
|
||||
}
|
||||
|
||||
@@ -60,7 +95,54 @@ class SeedBoxRepository extends BaseRepository
|
||||
|
||||
public function delete($id, $uid)
|
||||
{
|
||||
$this->clearCache();
|
||||
return SeedBoxRecord::query()->whereIn('id', Arr::wrap($id))->where('uid', $uid)->delete();
|
||||
}
|
||||
|
||||
public function updateStatus(SeedBoxRecord $seedBoxRecord, $status): bool
|
||||
{
|
||||
if (Auth::user()->class < User::CLASS_ADMINISTRATOR) {
|
||||
throw new InsufficientPermissionException();
|
||||
}
|
||||
if (!isset(SeedBoxRecord::$status[$status])) {
|
||||
throw new \InvalidArgumentException("Invalid status: $status");
|
||||
}
|
||||
if ($seedBoxRecord->status == $status) {
|
||||
return true;
|
||||
}
|
||||
$message = [
|
||||
'receiver' => $seedBoxRecord->uid,
|
||||
'subject' => nexus_trans('seed-box.status_change_message.subject'),
|
||||
'msg' => nexus_trans('seed-box.status_change_message.body', [
|
||||
'id' => $seedBoxRecord->id,
|
||||
'operator' => Auth::user()->username,
|
||||
'old_status' => $seedBoxRecord->statusText,
|
||||
'new_status' => nexus_trans('seed-box.status_text.' . $status),
|
||||
]),
|
||||
'added' => now()
|
||||
];
|
||||
return NexusDB::transaction(function () use ($seedBoxRecord, $status, $message) {
|
||||
$seedBoxRecord->status = $status;
|
||||
$seedBoxRecord->save();
|
||||
$this->clearCache();
|
||||
return Message::add($message);
|
||||
});
|
||||
}
|
||||
|
||||
public function renderIcon($ip, $uid): string
|
||||
{
|
||||
$result = '';
|
||||
if ((isIPV4($ip) || isIPV6($ip)) && get_setting('seed_box.enabled') == 'yes' && isIPSeedBox($ip, $uid)) {
|
||||
$result = '<img src="pic/misc/seed-box.png" style="vertical-align: bottom; height: 16px; margin-left: 4px" title="SeedBox" />';
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function clearCache()
|
||||
{
|
||||
NexusDB::redis()->del("nexus_is_ip_seed_box");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -88,16 +88,23 @@ class TrackerRepository extends BaseRepository
|
||||
} elseif ($isReAnnounce == self::ANNOUNCE_FIRST) {
|
||||
$this->checkMinInterval($peerSelf, $queries);
|
||||
}
|
||||
|
||||
$snatch = Snatch::query()
|
||||
->where('torrentid', $torrent->id)
|
||||
->where('userid', $user->id)
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
/**
|
||||
* Note: Must get before update peer!
|
||||
*/
|
||||
$dataTraffic = $this->getDataTraffic($torrent, $queries, $user, $peerSelf);
|
||||
$dataTraffic = $this->getDataTraffic($torrent, $queries, $user, $peerSelf, $snatch);
|
||||
|
||||
/**
|
||||
* Note: Only check in old session
|
||||
*/
|
||||
if ($peerSelf->exists) {
|
||||
$this->checkCheater($torrent, $dataTraffic, $user, $peerSelf);
|
||||
$this->checkCheater($torrent, $queries, $dataTraffic, $user, $peerSelf);
|
||||
$this->checkSeedBox($torrent, $queries, $dataTraffic, $user, $peerSelf);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +120,7 @@ class TrackerRepository extends BaseRepository
|
||||
/**
|
||||
* Note: Must update snatch first, otherwise peer `last_action` already change
|
||||
*/
|
||||
$snatch = $this->updateSnatch($peerSelf, $queries, $dataTraffic);
|
||||
$snatch = $this->updateSnatch($peerSelf, $queries, $dataTraffic, $snatch);
|
||||
if ($queries['event'] == 'completed') {
|
||||
$this->handleHitAndRun($user, $torrent, $snatch);
|
||||
}
|
||||
@@ -420,6 +427,7 @@ class TrackerRepository extends BaseRepository
|
||||
if ($user->class >= User::CLASS_VIP) {
|
||||
return;
|
||||
}
|
||||
|
||||
$gigs = $user->downloaded / (1024*1024*1024);
|
||||
if ($gigs < 10) {
|
||||
return;
|
||||
@@ -485,7 +493,7 @@ class TrackerRepository extends BaseRepository
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkCheater(Torrent $torrent, $dataTraffic, User $user, Peer $peer)
|
||||
protected function checkCheater(Torrent $torrent, $queries, $dataTraffic, User $user, Peer $peer)
|
||||
{
|
||||
$settingSecurity = Setting::get('security');
|
||||
$level = $settingSecurity['cheaterdet'];
|
||||
@@ -560,6 +568,33 @@ class TrackerRepository extends BaseRepository
|
||||
|
||||
}
|
||||
|
||||
private function checkSeedBox(Torrent $torrent, $queries, $dataTraffic, User $user, Peer $peer)
|
||||
{
|
||||
if ($user->class >= User::CLASS_VIP || $user->isDonating()) {
|
||||
return;
|
||||
}
|
||||
$isSeedBoxRuleEnabled = Setting::get('seed_box.enabled') == 'yes';
|
||||
if (!$isSeedBoxRuleEnabled) {
|
||||
return;
|
||||
}
|
||||
$isIPSeedBox = isIPSeedBox($queries['ip'], $user->id);
|
||||
if ($isIPSeedBox) {
|
||||
return;
|
||||
}
|
||||
if (!$peer->isValidDate('last_action')) {
|
||||
//no last action
|
||||
return;
|
||||
}
|
||||
$duration = Carbon::now()->diffInSeconds($peer->last_action);
|
||||
$upSpeedMbps = ($dataTraffic['uploaded_increment'] / $duration) * 8;
|
||||
$notSeedBoxMaxSpeedMbps = Setting::get('seed_box.not_seed_box_max_speed');
|
||||
if ($upSpeedMbps > $notSeedBoxMaxSpeedMbps) {
|
||||
$user->update(['downloadpos' => 'no']);
|
||||
do_log("user: {$user->id} downloading privileges have been disabled! (over speed)", 'error');
|
||||
throw new TrackerException("Your downloading privileges have been disabled! (over speed)");
|
||||
}
|
||||
}
|
||||
|
||||
private function createOrUpdateCheater(Torrent $torrent, User $user, array $createData)
|
||||
{
|
||||
$existsCheater = Cheater::query()
|
||||
@@ -671,7 +706,7 @@ class TrackerRepository extends BaseRepository
|
||||
return $real_annnounce_interval;
|
||||
}
|
||||
|
||||
private function getDataTraffic(Torrent $torrent, $queries, User $user, Peer $peer): array
|
||||
private function getDataTraffic(Torrent $torrent, $queries, User $user, Peer $peer, $snatch): array
|
||||
{
|
||||
$log = sprintf(
|
||||
"torrent: %s, user: %s, peer: %s, queriesUploaded: %s, queriesDownloaded: %s",
|
||||
@@ -720,12 +755,32 @@ class TrackerRepository extends BaseRepository
|
||||
$downRatio = 0;
|
||||
$log .= ", [PEER_NOT_EXISTS], realUploaded: $realUploaded, realDownloaded: $realDownloaded, upRatio: $upRatio, downRatio: $downRatio";
|
||||
}
|
||||
$uploadedIncrementForUser = $realUploaded * $upRatio;
|
||||
$downloadedIncrementForUser = $realDownloaded * $downRatio;
|
||||
|
||||
/**
|
||||
* check seed box rule
|
||||
*/
|
||||
$isSeedBoxRuleEnabled = Setting::get('seed_box.enabled') == 'yes';
|
||||
if ($isSeedBoxRuleEnabled) {
|
||||
$isIPSeedBox = isIPSeedBox($queries['ip'], $user->id);
|
||||
if ($isIPSeedBox) {
|
||||
$uploadedIncrementForUser = $realUploaded;
|
||||
$downloadedIncrementForUser = $realDownloaded;
|
||||
$log .= ", isIPSeedBox, increment for user = real";
|
||||
$maxUploadedTimes = Setting::get('seed_box.max_uploaded');
|
||||
if ($snatch && $snatch->uploaded >= $torrent->size * $maxUploadedTimes) {
|
||||
$log .= ", uploaded >= torrentSize * times($maxUploadedTimes), uploadedIncrementForUser = 0";
|
||||
$uploadedIncrementForUser = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
'uploaded_increment' => $realUploaded,
|
||||
'uploaded_increment_for_user' => $realUploaded * $upRatio,
|
||||
'uploaded_increment_for_user' => $uploadedIncrementForUser,
|
||||
'downloaded_increment' => $realDownloaded,
|
||||
'downloaded_increment_for_user' => $realDownloaded * $downRatio,
|
||||
'downloaded_increment_for_user' => $downloadedIncrementForUser,
|
||||
];
|
||||
do_log("$log, result: " . json_encode($result), 'info');
|
||||
return $result;
|
||||
@@ -938,15 +993,10 @@ class TrackerRepository extends BaseRepository
|
||||
* @param $queries
|
||||
* @param $dataTraffic
|
||||
*/
|
||||
private function updateSnatch(Peer $peer, $queries, $dataTraffic)
|
||||
private function updateSnatch(Peer $peer, $queries, $dataTraffic, $snatch)
|
||||
{
|
||||
$nowStr = Carbon::now()->toDateTimeString();
|
||||
|
||||
$snatch = Snatch::query()
|
||||
->where('torrentid', $peer->torrent)
|
||||
->where('userid', $peer->userid)
|
||||
->first();
|
||||
|
||||
//torrentid, userid, ip, port, uploaded, downloaded, to_go, ,seedtime, leechtime, last_action, startdat, completedat, finished
|
||||
if (!$snatch) {
|
||||
$snatch = new Snatch();
|
||||
|
||||
Reference in New Issue
Block a user