add uploadspeed + downloadspeed +isp

This commit is contained in:
xiaomlove
2022-07-30 15:06:51 +08:00
parent 8a4f4a77cb
commit 1ed68b6058
28 changed files with 477 additions and 64 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ class Test extends Command
// $ipObj = IPBlock::create($ip); // $ipObj = IPBlock::create($ip);
// $ipObj = IP::create($ip); // $ipObj = IP::create($ip);
// $r = $ipObj->getVersion(); // $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'); // $r = get_ip_location_from_geoip('116.30.133.129');
dd($r); dd($r);
} }
+36
View File
@@ -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 () { ->action(function () {
$userRep = new UserRepository(); $userRep = new UserRepository();
try { 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->notify('success', 'Success!');
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id); $this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
} catch (\Exception $exception) { } catch (\Exception $exception) {
+2 -2
View File
@@ -49,8 +49,8 @@ class Locale
public static function getLocaleFromCookie() public static function getLocaleFromCookie()
{ {
if (IN_NEXUS) { if (IN_NEXUS) {
$lang = get_langfolder_cookie(); $lang = IN_TRACKER ? null : get_langfolder_cookie();
$log = "IN_NEXUS, get_langfolder_cookie(): $lang"; $log = "IN_NEXUS, get_langfolder_cookie() or IN_TRACKER use null: $lang";
} else { } else {
$lang = Cookie::get('c_lang_folder'); $lang = Cookie::get('c_lang_folder');
$log = "Cookie::get(): $lang"; $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:*");
}
}
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace App\Models;
class DownloadSpeed extends NexusModel
{
protected $table = 'downloadspeed';
protected $fillable = ['name'];
}
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace App\Models;
class Isp extends NexusModel
{
protected $table = 'isp';
protected $fillable = ['name'];
}
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace App\Models;
class UploadSpeed extends NexusModel
{
protected $table = 'uploadspeed';
protected $fillable = ['name'];
}
+5
View File
@@ -2,7 +2,9 @@
namespace App\Providers; namespace App\Providers;
use App\Events\SeedBoxRecordUpdated;
use App\Events\TorrentUpdated; use App\Events\TorrentUpdated;
use App\Listeners\RemoveSeedBoxRecordCache;
use App\Listeners\SyncTorrentToEs; use App\Listeners\SyncTorrentToEs;
use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
@@ -23,6 +25,9 @@ class EventServiceProvider extends ServiceProvider
TorrentUpdated::class => [ TorrentUpdated::class => [
SyncTorrentToEs::class, SyncTorrentToEs::class,
], ],
SeedBoxRecordUpdated::class => [
RemoveSeedBoxRecordCache::class,
],
]; ];
/** /**
+5 -2
View File
@@ -39,10 +39,13 @@ class BaseRepository
/** /**
* @param $user * @param $user
* @param null $fields * @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) { if ($user instanceof User) {
return $user; return $user;
} }
+3 -1
View File
@@ -1,6 +1,7 @@
<?php <?php
namespace App\Repositories; namespace App\Repositories;
use App\Events\SeedBoxRecordUpdated;
use App\Exceptions\InsufficientPermissionException; use App\Exceptions\InsufficientPermissionException;
use App\Models\Message; use App\Models\Message;
use App\Models\Poll; use App\Models\Poll;
@@ -140,7 +141,8 @@ class SeedBoxRepository extends BaseRepository
private function clearCache() private function clearCache()
{ {
NexusDB::redis()->del("nexus_is_ip_seed_box"); return true;
// SeedBoxRecordUpdated::dispatch();
} }
+1 -1
View File
@@ -590,7 +590,7 @@ class TrackerRepository extends BaseRepository
$notSeedBoxMaxSpeedMbps = Setting::get('seed_box.not_seed_box_max_speed'); $notSeedBoxMaxSpeedMbps = Setting::get('seed_box.not_seed_box_max_speed');
do_log("upSpeedMbps: $upSpeedMbps, notSeedBoxMaxSpeedMbps: $notSeedBoxMaxSpeedMbps"); do_log("upSpeedMbps: $upSpeedMbps, notSeedBoxMaxSpeedMbps: $notSeedBoxMaxSpeedMbps");
if ($upSpeedMbps > $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'); do_log("user: {$user->id} downloading privileges have been disabled! (over speed)", 'error');
throw new TrackerException("Your downloading privileges have been disabled! (over speed)"); throw new TrackerException("Your downloading privileges have been disabled! (over speed)");
} }
+27 -10
View File
@@ -174,6 +174,7 @@ class UserRepository extends BaseRepository
UserBanLog::query()->insert($banLog); UserBanLog::query()->insert($banLog);
}); });
do_log("user: $uid, $modCommentText"); do_log("user: $uid, $modCommentText");
$this->clearCache($targetUser);
return true; 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); $modCommentText = sprintf("%s - Enable by %s, reason: %s", now()->format('Y-m-d'), $operator->username, $reason);
$targetUser->updateWithModComment($update, $modCommentText); $targetUser->updateWithModComment($update, $modCommentText);
do_log("user: $uid, $modCommentText, update: " . nexus_json_encode($update)); do_log("user: $uid, $modCommentText, update: " . nexus_json_encode($update));
$this->clearCache($targetUser);
return true; return true;
} }
@@ -289,16 +291,16 @@ class UserRepository extends BaseRepository
} }
Message::query()->insert($message); Message::query()->insert($message);
}); });
$this->clearCache($targetUser);
return true; return true;
} }
public function removeLeechWarn($operator, $uid): bool public function removeLeechWarn($operator, $uid): bool
{ {
$operator = $this->getUser($operator); $operator = $this->getUser($operator);
$classRequire = Setting::get('authority.prfmanage');
$user = User::query()->findOrFail($uid, User::$commonFields); $user = User::query()->findOrFail($uid, User::$commonFields);
$this->checkPermission($operator, $user); $this->checkPermission($operator, $user);
NexusDB::cache_del('user_'.$uid.'_content'); $this->clearCache($user);
$user->leechwarn = 'no'; $user->leechwarn = 'no';
$user->leechwarnuntil = null; $user->leechwarnuntil = null;
return $user->save(); return $user->save();
@@ -311,33 +313,42 @@ class UserRepository extends BaseRepository
} }
$user = User::query()->findOrFail($uid, User::$commonFields); $user = User::query()->findOrFail($uid, User::$commonFields);
$this->checkPermission($operator, $user); $this->checkPermission($operator, $user);
$this->clearCache($user);
$user->two_step_secret = ''; $user->two_step_secret = '';
return $user->save(); 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); $operator = $this->getUser($operator);
$this->checkPermission($operator, $targetUser); $operatorUsername = 'System';
if ($operator) {
$operatorUsername = $operator->username;
$this->checkPermission($operator, $targetUser);
}
$message = [ $message = [
'added' => now(), 'added' => now(),
'receiver' => $targetUser->id, 'receiver' => $targetUser->id,
]; ];
if ($targetUser->downloadpos == 'yes') { if ($status == 'no') {
$update = ['downloadpos' => '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['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 { } else {
$update = ['downloadpos' => 'yes']; $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['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) { return NexusDB::transaction(function () use ($targetUser, $update, $modComment, $message) {
Message::add($message); Message::add($message);
$this->clearCache($targetUser);
return $targetUser->updateWithModComment($update, $modComment); 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');
}
} }
+21 -21
View File
@@ -14,75 +14,75 @@ class AdminpanelTableSeeder extends Seeder
*/ */
public function run() public function run()
{ {
\DB::table('adminpanel')->delete(); \DB::table('adminpanel')->delete();
\DB::table('adminpanel')->insert(array ( \DB::table('adminpanel')->insert(array (
0 => 0 =>
array ( array (
'id' => 1, 'id' => 1,
'name' => 'Add user', 'name' => 'Add user',
'url' => 'adduser.php', 'url' => 'adduser.php',
'info' => 'Create new user account', 'info' => 'Create new user account',
), ),
1 => 1 =>
array ( array (
'id' => 3, 'id' => 3,
'name' => 'Reset Users Password', 'name' => 'Reset Users Password',
'url' => 'reset.php', 'url' => 'reset.php',
'info' => 'Rest lost Passwords', 'info' => 'Rest lost Passwords',
), ),
2 => 2 =>
array ( array (
'id' => 4, 'id' => 4,
'name' => 'Mass PM', 'name' => 'Mass PM',
'url' => 'staffmess.php', 'url' => 'staffmess.php',
'info' => 'Send PM to all users', 'info' => 'Send PM to all users',
), ),
3 => 3 =>
array ( array (
'id' => 6, 'id' => 6,
'name' => 'Poll overview', 'name' => 'Poll overview',
'url' => 'polloverview.php', 'url' => 'polloverview.php',
'info' => 'View poll votes', 'info' => 'View poll votes',
), ),
4 => 4 =>
array ( array (
'id' => 7, 'id' => 7,
'name' => 'Warned users', 'name' => 'Warned users',
'url' => 'warned.php', 'url' => 'warned.php',
'info' => 'See all warned users on tracker', 'info' => 'See all warned users on tracker',
), ),
5 => // 5 =>
array ( // array (
'id' => 8, // 'id' => 8,
'name' => 'FreeLeech', // 'name' => 'FreeLeech',
'url' => 'freeleech.php', // 'url' => 'freeleech.php',
'info' => 'Set ALL Torrents At Special State.', // 'info' => 'Set ALL Torrents At Special State.',
), // ),
6 => 6 =>
array ( array (
'id' => 9, 'id' => 9,
'name' => 'FAQ Management', 'name' => 'FAQ Management',
'url' => 'faqmanage.php', 'url' => 'faqmanage.php',
'info' => 'Edit/Add/Delete FAQ Page', 'info' => 'Edit/Add/Delete FAQ Page',
), ),
7 => 7 =>
array ( array (
'id' => 10, 'id' => 10,
'name' => 'Rules Management', 'name' => 'Rules Management',
'url' => 'modrules.php', 'url' => 'modrules.php',
'info' => 'Edit/Add/Delete RULES Page', 'info' => 'Edit/Add/Delete RULES Page',
), ),
8 => 8 =>
array ( array (
'id' => 11, 'id' => 11,
'name' => 'Category Manage', 'name' => 'Category Manage',
'url' => 'catmanage.php', 'url' => 'catmanage.php',
'info' => 'Manage torrents categories at your site', 'info' => 'Manage torrents categories at your site',
), ),
9 => 9 =>
array ( array (
'id' => 12, 'id' => 12,
'name' => 'Custom Field Manage', 'name' => 'Custom Field Manage',
@@ -90,7 +90,7 @@ class AdminpanelTableSeeder extends Seeder
'info' => 'Manage custom fields', 'info' => 'Manage custom fields',
), ),
)); ));
} }
} }
+2 -2
View File
@@ -1,7 +1,7 @@
<?php <?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.7.19'); defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.7.19');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-07-25'); defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-07-30');
defined('IN_TRACKER') || define('IN_TRACKER', true); defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP"); defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org"); defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
defined('NEXUSWIKIURL') || define("NEXUSWIKIURL","https://doc.nexusphp.org"); defined('NEXUSWIKIURL') || define("NEXUSWIKIURL","https://doc.nexusphp.org");
+17 -16
View File
@@ -3,18 +3,19 @@
function get_global_sp_state() function get_global_sp_state()
{ {
static $global_promotion_state; static $global_promotion_state;
$cacheKey = 'global_promotion_state';
if (!$global_promotion_state) { if (!$global_promotion_state) {
if (!$global_promotion_state = \Nexus\Database\NexusDB::cache_get('global_promotion_state')){ $row = \Nexus\Database\NexusDB::remember($cacheKey, 600, function () use ($cacheKey) {
$row = \Nexus\Database\NexusDB::getOne('torrents_state', 1); $row = \Nexus\Database\NexusDB::getOne('torrents_state', 1);
if (isset($row['deadline']) && $row['deadline'] < date('Y-m-d H:i:s')) { \Nexus\Database\NexusDB::cache_put($cacheKey . '_deadline', $row['deadline'], 600);
//expired return $row;
$global_promotion_state = \App\Models\Torrent::PROMOTION_NORMAL; });
} else { if (isset($row['deadline']) && $row['deadline'] < date('Y-m-d H:i:s')) {
$global_promotion_state = $row["global_sp_state"]; //expired
} $global_promotion_state = \App\Models\Torrent::PROMOTION_NORMAL;
\Nexus\Database\NexusDB::cache_put('global_promotion_state', $global_promotion_state, 600); } else {
\Nexus\Database\NexusDB::cache_put('global_promotion_state_deadline', $row['deadline'], 600); $global_promotion_state = $row["global_sp_state"];
} }
} }
return $global_promotion_state; return $global_promotion_state;
} }
@@ -769,8 +770,8 @@ function isIPSeedBox($ip, $uid = null, $withoutCache = false): bool
{ {
$key = "nexus_is_ip_seed_box:ip:$ip:uid:$uid"; $key = "nexus_is_ip_seed_box:ip:$ip:uid:$uid";
$cacheData = \Nexus\Database\NexusDB::cache_get($key); $cacheData = \Nexus\Database\NexusDB::cache_get($key);
if (in_array($cacheData, [0, 1], true) && !$withoutCache) { if (in_array($cacheData, [0, 1, '0', '1'], true) && !$withoutCache) {
do_log("$key, get result from cache: $cacheData"); do_log("$key, get result from cache: $cacheData(" . gettype($cacheData) . ")");
return (bool)$cacheData; return (bool)$cacheData;
} }
$ipObject = \PhpIP\IP::create($ip); $ipObject = \PhpIP\IP::create($ip);
@@ -782,7 +783,7 @@ function isIPSeedBox($ip, $uid = null, $withoutCache = false): bool
); );
$res = \Nexus\Database\NexusDB::select($checkSeedBoxAdminSql); $res = \Nexus\Database\NexusDB::select($checkSeedBoxAdminSql);
if (!empty($res)) { if (!empty($res)) {
\Nexus\Database\NexusDB::cache_put($key, 1); \Nexus\Database\NexusDB::cache_put($key, 1, 300);
do_log("$key, get result from admin, true"); do_log("$key, get result from admin, true");
return true; return true;
} }
@@ -793,12 +794,12 @@ function isIPSeedBox($ip, $uid = null, $withoutCache = false): bool
); );
$res = \Nexus\Database\NexusDB::select($checkSeedBoxUserSql); $res = \Nexus\Database\NexusDB::select($checkSeedBoxUserSql);
if (!empty($res)) { if (!empty($res)) {
\Nexus\Database\NexusDB::cache_put($key, 1); \Nexus\Database\NexusDB::cache_put($key, 1, 300);
do_log("$key, get result from user, true"); do_log("$key, get result from user, true");
return true; return true;
} }
} }
\Nexus\Database\NexusDB::cache_put($key, 0); \Nexus\Database\NexusDB::cache_put($key, 0, 300);
do_log("$key, no result, false"); do_log("$key, no result, false");
return false; return false;
} }
+18
View File
@@ -371,6 +371,24 @@ class NexusDB
} }
} }
public static function cache_del_by_pattern($pattern)
{
$redis = self::redis();
$it = NULL;
do {
// Scan for some keys
$arr_keys = $redis->scan($it, $pattern);
// Redis may return empty results, so protect against that
if ($arr_keys !== FALSE) {
foreach($arr_keys as $str_key) {
do_log("[SCAN_KEY] $str_key");
self::cache_del($str_key);
}
}
} while ($it > 0);
}
/** /**
* @return mixed|\Redis|null * @return mixed|\Redis|null
*/ */
+1 -1
View File
@@ -358,7 +358,7 @@ else // continue an existing session
$upSpeedMbps = number_format(($trueupthis / $self['announcetime'] / 1024 / 1024) * 8); $upSpeedMbps = number_format(($trueupthis / $self['announcetime'] / 1024 / 1024) * 8);
do_log("notSeedBoxMaxSpeedMbps: $notSeedBoxMaxSpeedMbps, upSpeedMbps: $upSpeedMbps"); do_log("notSeedBoxMaxSpeedMbps: $notSeedBoxMaxSpeedMbps, upSpeedMbps: $upSpeedMbps");
if ($isSeedBoxRuleEnabled && !($az['class'] >= \App\Models\User::CLASS_VIP || $isDonor) && !$isIPSeedBox && $upSpeedMbps > $notSeedBoxMaxSpeedMbps) { if ($isSeedBoxRuleEnabled && !($az['class'] >= \App\Models\User::CLASS_VIP || $isDonor) && !$isIPSeedBox && $upSpeedMbps > $notSeedBoxMaxSpeedMbps) {
sql_query("update users set downloadpos = 'no' where id = $userid"); (new \App\Repositories\UserRepository())->updateDownloadPrivileges(null, $userid, 'no');
do_log("user: $userid downloading privileges have been disabled! (over speed)", 'error'); do_log("user: $userid downloading privileges have been disabled! (over speed)", 'error');
err("Your downloading privileges have been disabled! (over speed)"); err("Your downloading privileges have been disabled! (over speed)");
} }
+2 -2
View File
@@ -13,10 +13,10 @@ return [
'download_disable' => [ 'download_disable' => [
'subject' => 'Download permission cancellation', 'subject' => 'Download permission cancellation',
'body' => 'Administrator: :operator has revoked your download privileges, possibly due to low sharing rates or misbehavior.', 'body' => 'Your download privileges has revoked, possibly due to low sharing rates or misbehavior. By: :operator',
], ],
'download_enable' => [ 'download_enable' => [
'subject' => 'Download permission restored', 'subject' => 'Download permission restored',
'body' => 'Administrator: :operator restored your download privileges, you can now download torrents.', 'body' => 'Your download privileges restored, you can now download torrents. By: :operator',
], ],
]; ];
+3
View File
@@ -18,6 +18,9 @@ return [
'roles_list' => '角色', 'roles_list' => '角色',
'ability_list' => '权限', 'ability_list' => '权限',
'seed_box_records' => 'SeedBox', 'seed_box_records' => 'SeedBox',
'upload_speed' => '上行带宽',
'download_speed' => '下行带宽',
'isp' => 'ISP',
], ],
'resources' => [ 'resources' => [
'agent_allow' => [ 'agent_allow' => [
+2 -2
View File
@@ -13,10 +13,10 @@ return [
'download_disable' => [ 'download_disable' => [
'subject' => '下载权限取消', 'subject' => '下载权限取消',
'body' => '管理员::operator 取消了你的下载权限,可能的原因是过低的分享率或行为不当。', 'body' => '你的下载权限被取消,可能的原因是过低的分享率或行为不当。By: :operator',
], ],
'download_enable' => [ 'download_enable' => [
'subject' => '下载权限恢复', 'subject' => '下载权限恢复',
'body' => '管理员::operator 恢复了你的下载权限,你现在可以下载种子。', 'body' => '你的下载权限恢复,你现在可以下载种子。By: :operator',
], ],
]; ];
+2 -2
View File
@@ -12,10 +12,10 @@ return [
'field_value_change_message_subject' => ':field 改變', 'field_value_change_message_subject' => ':field 改變',
'download_disable' => [ 'download_disable' => [
'subject' => '下載權限取消', 'subject' => '下載權限取消',
'body' => '管理員::operator 取消了你的下載權限,可能的原因是過低的分享率或行為不當。', 'body' => '你的下載權限被取消,可能的原因是過低的分享率或行為不當。By: :operator',
], ],
'download_enable' => [ 'download_enable' => [
'subject' => '下載權限恢復', 'subject' => '下載權限恢復',
'body' => '管理員::operator 恢復了你的下載權限,你現在可以下載種子。', 'body' => '你的下載權限恢復,你現在可以下載種子。By: :operator',
], ],
]; ];