mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
add uploadspeed + downloadspeed +isp
This commit is contained in:
@@ -88,7 +88,7 @@ class Test extends Command
|
||||
// $ipObj = IPBlock::create($ip);
|
||||
// $ipObj = IP::create($ip);
|
||||
// $r = $ipObj->getVersion();
|
||||
$r = get_ip_location('116.30.133.129');
|
||||
$r = isIPSeedBox('116.30.133.129', 1);
|
||||
// $r = get_ip_location_from_geoip('116.30.133.129');
|
||||
dd($r);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SeedBoxRecordUpdated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return \Illuminate\Broadcasting\Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\System;
|
||||
|
||||
use App\Filament\Resources\System\DownloadSpeedResource\Pages;
|
||||
use App\Filament\Resources\System\DownloadSpeedResource\RelationManagers;
|
||||
use App\Models\DownloadSpeed;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Tables;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class DownloadSpeedResource extends Resource
|
||||
{
|
||||
protected static ?string $model = DownloadSpeed::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-download';
|
||||
|
||||
protected static ?string $navigationGroup = 'System';
|
||||
|
||||
protected static ?int $navigationSort = 6;
|
||||
|
||||
protected static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.sidebar.download_speed');
|
||||
}
|
||||
|
||||
public static function getBreadcrumb(): string
|
||||
{
|
||||
return self::getNavigationLabel();
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')->label(__('label.name'))
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id'),
|
||||
Tables\Columns\TextColumn::make('name')->label(__('label.name')),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ManageDownloadSpeeds::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\System\DownloadSpeedResource\Pages;
|
||||
|
||||
use App\Filament\Resources\System\DownloadSpeedResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
|
||||
class ManageDownloadSpeeds extends ManageRecords
|
||||
{
|
||||
protected static string $resource = DownloadSpeedResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\System;
|
||||
|
||||
use App\Filament\Resources\System\IspResource\Pages;
|
||||
use App\Filament\Resources\System\IspResource\RelationManagers;
|
||||
use App\Models\Isp;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Tables;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class IspResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Isp::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-globe-alt';
|
||||
|
||||
protected static ?string $navigationGroup = 'System';
|
||||
|
||||
protected static ?int $navigationSort = 7;
|
||||
|
||||
protected static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.sidebar.isp');
|
||||
}
|
||||
|
||||
public static function getBreadcrumb(): string
|
||||
{
|
||||
return self::getNavigationLabel();
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')->label(__('label.name'))
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id'),
|
||||
Tables\Columns\TextColumn::make('name')->label(__('label.name')),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ManageIsps::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\System\IspResource\Pages;
|
||||
|
||||
use App\Filament\Resources\System\IspResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
|
||||
class ManageIsps extends ManageRecords
|
||||
{
|
||||
protected static string $resource = IspResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\System;
|
||||
|
||||
use App\Filament\Resources\System\UploadSpeedResource\Pages;
|
||||
use App\Filament\Resources\System\UploadSpeedResource\RelationManagers;
|
||||
use App\Models\UploadSpeed;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Tables;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class UploadSpeedResource extends Resource
|
||||
{
|
||||
protected static ?string $model = UploadSpeed::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-upload';
|
||||
|
||||
protected static ?string $navigationGroup = 'System';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
protected static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.sidebar.upload_speed');
|
||||
}
|
||||
|
||||
public static function getBreadcrumb(): string
|
||||
{
|
||||
return self::getNavigationLabel();
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')->label(__('label.name'))
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id'),
|
||||
Tables\Columns\TextColumn::make('name')->label(__('label.name')),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ManageUploadSpeeds::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\System\UploadSpeedResource\Pages;
|
||||
|
||||
use App\Filament\Resources\System\UploadSpeedResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
|
||||
class ManageUploadSpeeds extends ManageRecords
|
||||
{
|
||||
protected static string $resource = UploadSpeedResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -243,7 +243,7 @@ class UserProfile extends Page
|
||||
->action(function () {
|
||||
$userRep = new UserRepository();
|
||||
try {
|
||||
$userRep->toggleDownloadPrivileges(Auth::user(), $this->record->id);
|
||||
$userRep->updateDownloadPrivileges(Auth::user(), $this->record->id, $this->record->downloadpos == 'yes' ? 'no' : 'yes');
|
||||
$this->notify('success', 'Success!');
|
||||
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
|
||||
} catch (\Exception $exception) {
|
||||
|
||||
@@ -49,8 +49,8 @@ class Locale
|
||||
public static function getLocaleFromCookie()
|
||||
{
|
||||
if (IN_NEXUS) {
|
||||
$lang = get_langfolder_cookie();
|
||||
$log = "IN_NEXUS, get_langfolder_cookie(): $lang";
|
||||
$lang = IN_TRACKER ? null : get_langfolder_cookie();
|
||||
$log = "IN_NEXUS, get_langfolder_cookie() or IN_TRACKER use null: $lang";
|
||||
} else {
|
||||
$lang = Cookie::get('c_lang_folder');
|
||||
$log = "Cookie::get(): $lang";
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class RemoveSeedBoxRecordCache implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
NexusDB::cache_del_by_pattern("nexus_is_ip_seed_box:ip:*");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class DownloadSpeed extends NexusModel
|
||||
{
|
||||
protected $table = 'downloadspeed';
|
||||
|
||||
protected $fillable = ['name'];
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class Isp extends NexusModel
|
||||
{
|
||||
protected $table = 'isp';
|
||||
|
||||
protected $fillable = ['name'];
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class UploadSpeed extends NexusModel
|
||||
{
|
||||
protected $table = 'uploadspeed';
|
||||
|
||||
protected $fillable = ['name'];
|
||||
}
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Events\SeedBoxRecordUpdated;
|
||||
use App\Events\TorrentUpdated;
|
||||
use App\Listeners\RemoveSeedBoxRecordCache;
|
||||
use App\Listeners\SyncTorrentToEs;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
@@ -23,6 +25,9 @@ class EventServiceProvider extends ServiceProvider
|
||||
TorrentUpdated::class => [
|
||||
SyncTorrentToEs::class,
|
||||
],
|
||||
SeedBoxRecordUpdated::class => [
|
||||
RemoveSeedBoxRecordCache::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,10 +39,13 @@ class BaseRepository
|
||||
/**
|
||||
* @param $user
|
||||
* @param null $fields
|
||||
* @return User
|
||||
* @return User|null
|
||||
*/
|
||||
protected function getUser($user, $fields = null): User
|
||||
protected function getUser($user, $fields = null): User|null
|
||||
{
|
||||
if ($user === null) {
|
||||
return null;
|
||||
}
|
||||
if ($user instanceof User) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Events\SeedBoxRecordUpdated;
|
||||
use App\Exceptions\InsufficientPermissionException;
|
||||
use App\Models\Message;
|
||||
use App\Models\Poll;
|
||||
@@ -140,7 +141,8 @@ class SeedBoxRepository extends BaseRepository
|
||||
|
||||
private function clearCache()
|
||||
{
|
||||
NexusDB::redis()->del("nexus_is_ip_seed_box");
|
||||
return true;
|
||||
// SeedBoxRecordUpdated::dispatch();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -590,7 +590,7 @@ class TrackerRepository extends BaseRepository
|
||||
$notSeedBoxMaxSpeedMbps = Setting::get('seed_box.not_seed_box_max_speed');
|
||||
do_log("upSpeedMbps: $upSpeedMbps, notSeedBoxMaxSpeedMbps: $notSeedBoxMaxSpeedMbps");
|
||||
if ($upSpeedMbps > $notSeedBoxMaxSpeedMbps) {
|
||||
$user->update(['downloadpos' => 'no']);
|
||||
(new \App\Repositories\UserRepository())->updateDownloadPrivileges(null, $user, '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)");
|
||||
}
|
||||
|
||||
@@ -174,6 +174,7 @@ class UserRepository extends BaseRepository
|
||||
UserBanLog::query()->insert($banLog);
|
||||
});
|
||||
do_log("user: $uid, $modCommentText");
|
||||
$this->clearCache($targetUser);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -199,6 +200,7 @@ class UserRepository extends BaseRepository
|
||||
$modCommentText = sprintf("%s - Enable by %s, reason: %s", now()->format('Y-m-d'), $operator->username, $reason);
|
||||
$targetUser->updateWithModComment($update, $modCommentText);
|
||||
do_log("user: $uid, $modCommentText, update: " . nexus_json_encode($update));
|
||||
$this->clearCache($targetUser);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -289,16 +291,16 @@ class UserRepository extends BaseRepository
|
||||
}
|
||||
Message::query()->insert($message);
|
||||
});
|
||||
$this->clearCache($targetUser);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function removeLeechWarn($operator, $uid): bool
|
||||
{
|
||||
$operator = $this->getUser($operator);
|
||||
$classRequire = Setting::get('authority.prfmanage');
|
||||
$user = User::query()->findOrFail($uid, User::$commonFields);
|
||||
$this->checkPermission($operator, $user);
|
||||
NexusDB::cache_del('user_'.$uid.'_content');
|
||||
$this->clearCache($user);
|
||||
$user->leechwarn = 'no';
|
||||
$user->leechwarnuntil = null;
|
||||
return $user->save();
|
||||
@@ -311,33 +313,42 @@ class UserRepository extends BaseRepository
|
||||
}
|
||||
$user = User::query()->findOrFail($uid, User::$commonFields);
|
||||
$this->checkPermission($operator, $user);
|
||||
$this->clearCache($user);
|
||||
$user->two_step_secret = '';
|
||||
return $user->save();
|
||||
}
|
||||
|
||||
|
||||
public function toggleDownloadPrivileges($operator, $id)
|
||||
public function updateDownloadPrivileges($operator, $user, $status)
|
||||
{
|
||||
$targetUser = User::query()->findOrFail($id, User::$commonFields);
|
||||
if (!in_array($status, ['yes', 'no'])) {
|
||||
throw new \InvalidArgumentException("Invalid status: $status");
|
||||
}
|
||||
$targetUser = $this->getUser($user);
|
||||
$operator = $this->getUser($operator);
|
||||
$this->checkPermission($operator, $targetUser);
|
||||
$operatorUsername = 'System';
|
||||
if ($operator) {
|
||||
$operatorUsername = $operator->username;
|
||||
$this->checkPermission($operator, $targetUser);
|
||||
}
|
||||
$message = [
|
||||
'added' => now(),
|
||||
'receiver' => $targetUser->id,
|
||||
];
|
||||
if ($targetUser->downloadpos == 'yes') {
|
||||
if ($status == 'no') {
|
||||
$update = ['downloadpos' => 'no'];
|
||||
$modComment = date('Y-m-d') . " - Download disable by " . $operator->username;
|
||||
$modComment = date('Y-m-d') . " - Download disable by " . $operatorUsername;
|
||||
$message['subject'] = nexus_trans('message.download_disable.subject', [], $targetUser->locale);
|
||||
$message['msg'] = nexus_trans('message.download_disable.body', ['operator' => $operator->username], $targetUser->locale);
|
||||
$message['msg'] = nexus_trans('message.download_disable.body', ['operator' => $operatorUsername], $targetUser->locale);
|
||||
} else {
|
||||
$update = ['downloadpos' => 'yes'];
|
||||
$modComment = date('Y-m-d') . " - Download enable by " . $operator->username;
|
||||
$modComment = date('Y-m-d') . " - Download enable by " . $operatorUsername;
|
||||
$message['subject'] = nexus_trans('message.download_enable.subject', [], $targetUser->locale);
|
||||
$message['msg'] = nexus_trans('message.download_enable.body', ['operator' => $operator->username], $targetUser->locale);
|
||||
$message['msg'] = nexus_trans('message.download_enable.body', ['operator' => $operatorUsername], $targetUser->locale);
|
||||
}
|
||||
return NexusDB::transaction(function () use ($targetUser, $update, $modComment, $message) {
|
||||
Message::add($message);
|
||||
$this->clearCache($targetUser);
|
||||
return $targetUser->updateWithModComment($update, $modComment);
|
||||
});
|
||||
}
|
||||
@@ -352,6 +363,12 @@ class UserRepository extends BaseRepository
|
||||
}
|
||||
}
|
||||
|
||||
private function clearCache(User $user)
|
||||
{
|
||||
\Nexus\Database\NexusDB::cache_del("user_{$user->id}_content");
|
||||
\Nexus\Database\NexusDB::cache_del('user_passkey_'.$user->passkey.'_content');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user