diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 1819a456..e63191f9 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -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); } diff --git a/app/Events/SeedBoxRecordUpdated.php b/app/Events/SeedBoxRecordUpdated.php new file mode 100644 index 00000000..3b384982 --- /dev/null +++ b/app/Events/SeedBoxRecordUpdated.php @@ -0,0 +1,36 @@ +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('/'), + ]; + } +} diff --git a/app/Filament/Resources/System/DownloadSpeedResource/Pages/ManageDownloadSpeeds.php b/app/Filament/Resources/System/DownloadSpeedResource/Pages/ManageDownloadSpeeds.php new file mode 100644 index 00000000..646a679a --- /dev/null +++ b/app/Filament/Resources/System/DownloadSpeedResource/Pages/ManageDownloadSpeeds.php @@ -0,0 +1,19 @@ +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('/'), + ]; + } +} diff --git a/app/Filament/Resources/System/IspResource/Pages/ManageIsps.php b/app/Filament/Resources/System/IspResource/Pages/ManageIsps.php new file mode 100644 index 00000000..5d3cb199 --- /dev/null +++ b/app/Filament/Resources/System/IspResource/Pages/ManageIsps.php @@ -0,0 +1,19 @@ +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('/'), + ]; + } +} diff --git a/app/Filament/Resources/System/UploadSpeedResource/Pages/ManageUploadSpeeds.php b/app/Filament/Resources/System/UploadSpeedResource/Pages/ManageUploadSpeeds.php new file mode 100644 index 00000000..58a2d268 --- /dev/null +++ b/app/Filament/Resources/System/UploadSpeedResource/Pages/ManageUploadSpeeds.php @@ -0,0 +1,19 @@ +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) { diff --git a/app/Http/Middleware/Locale.php b/app/Http/Middleware/Locale.php index 8e60891e..756cecd6 100644 --- a/app/Http/Middleware/Locale.php +++ b/app/Http/Middleware/Locale.php @@ -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"; diff --git a/app/Listeners/RemoveSeedBoxRecordCache.php b/app/Listeners/RemoveSeedBoxRecordCache.php new file mode 100644 index 00000000..597f309d --- /dev/null +++ b/app/Listeners/RemoveSeedBoxRecordCache.php @@ -0,0 +1,31 @@ + [ SyncTorrentToEs::class, ], + SeedBoxRecordUpdated::class => [ + RemoveSeedBoxRecordCache::class, + ], ]; /** diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 04d8ba36..5771074f 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -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; } diff --git a/app/Repositories/SeedBoxRepository.php b/app/Repositories/SeedBoxRepository.php index 1f8e2b0f..ba7f6e5b 100644 --- a/app/Repositories/SeedBoxRepository.php +++ b/app/Repositories/SeedBoxRepository.php @@ -1,6 +1,7 @@ del("nexus_is_ip_seed_box"); + return true; +// SeedBoxRecordUpdated::dispatch(); } diff --git a/app/Repositories/TrackerRepository.php b/app/Repositories/TrackerRepository.php index 65d001bf..593565b1 100644 --- a/app/Repositories/TrackerRepository.php +++ b/app/Repositories/TrackerRepository.php @@ -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)"); } diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index c7f0d22a..e15357aa 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -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'); + } + } diff --git a/database/seeders/AdminpanelTableSeeder.php b/database/seeders/AdminpanelTableSeeder.php index e4fe73c1..0608434e 100644 --- a/database/seeders/AdminpanelTableSeeder.php +++ b/database/seeders/AdminpanelTableSeeder.php @@ -14,75 +14,75 @@ class AdminpanelTableSeeder extends Seeder */ public function run() { - + \DB::table('adminpanel')->delete(); - + \DB::table('adminpanel')->insert(array ( - 0 => + 0 => array ( 'id' => 1, 'name' => 'Add user', 'url' => 'adduser.php', 'info' => 'Create new user account', ), - 1 => + 1 => array ( 'id' => 3, 'name' => 'Reset Users Password', 'url' => 'reset.php', 'info' => 'Rest lost Passwords', ), - 2 => + 2 => array ( 'id' => 4, 'name' => 'Mass PM', 'url' => 'staffmess.php', 'info' => 'Send PM to all users', ), - 3 => + 3 => array ( 'id' => 6, 'name' => 'Poll overview', 'url' => 'polloverview.php', 'info' => 'View poll votes', ), - 4 => + 4 => array ( 'id' => 7, 'name' => 'Warned users', 'url' => 'warned.php', 'info' => 'See all warned users on tracker', ), - 5 => - array ( - 'id' => 8, - 'name' => 'FreeLeech', - 'url' => 'freeleech.php', - 'info' => 'Set ALL Torrents At Special State.', - ), - 6 => +// 5 => +// array ( +// 'id' => 8, +// 'name' => 'FreeLeech', +// 'url' => 'freeleech.php', +// 'info' => 'Set ALL Torrents At Special State.', +// ), + 6 => array ( 'id' => 9, 'name' => 'FAQ Management', 'url' => 'faqmanage.php', 'info' => 'Edit/Add/Delete FAQ Page', ), - 7 => + 7 => array ( 'id' => 10, 'name' => 'Rules Management', 'url' => 'modrules.php', 'info' => 'Edit/Add/Delete RULES Page', ), - 8 => + 8 => array ( 'id' => 11, 'name' => 'Category Manage', 'url' => 'catmanage.php', 'info' => 'Manage torrents categories at your site', ), - 9 => + 9 => array ( 'id' => 12, 'name' => 'Custom Field Manage', @@ -90,7 +90,7 @@ class AdminpanelTableSeeder extends Seeder 'info' => 'Manage custom fields', ), )); - - + + } -} \ No newline at end of file +} diff --git a/include/constants.php b/include/constants.php index f75f578d..65d36753 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,7 +1,7 @@ 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 */ diff --git a/public/announce.php b/public/announce.php index 134c2923..bd58cf6d 100644 --- a/public/announce.php +++ b/public/announce.php @@ -358,7 +358,7 @@ else // continue an existing session $upSpeedMbps = number_format(($trueupthis / $self['announcetime'] / 1024 / 1024) * 8); do_log("notSeedBoxMaxSpeedMbps: $notSeedBoxMaxSpeedMbps, upSpeedMbps: $upSpeedMbps"); 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'); err("Your downloading privileges have been disabled! (over speed)"); } diff --git a/resources/lang/en/message.php b/resources/lang/en/message.php index 8ff8e25c..c9fb81d4 100644 --- a/resources/lang/en/message.php +++ b/resources/lang/en/message.php @@ -13,10 +13,10 @@ return [ 'download_disable' => [ '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' => [ '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', ], ]; diff --git a/resources/lang/zh_CN/admin.php b/resources/lang/zh_CN/admin.php index 2a4a4494..6d3693a5 100644 --- a/resources/lang/zh_CN/admin.php +++ b/resources/lang/zh_CN/admin.php @@ -18,6 +18,9 @@ return [ 'roles_list' => '角色', 'ability_list' => '权限', 'seed_box_records' => 'SeedBox', + 'upload_speed' => '上行带宽', + 'download_speed' => '下行带宽', + 'isp' => 'ISP', ], 'resources' => [ 'agent_allow' => [ diff --git a/resources/lang/zh_CN/message.php b/resources/lang/zh_CN/message.php index b290a6c9..30ff49e6 100644 --- a/resources/lang/zh_CN/message.php +++ b/resources/lang/zh_CN/message.php @@ -13,10 +13,10 @@ return [ 'download_disable' => [ 'subject' => '下载权限取消', - 'body' => '管理员::operator 取消了你的下载权限,可能的原因是过低的分享率或行为不当。', + 'body' => '你的下载权限被取消,可能的原因是过低的分享率或行为不当。By: :operator', ], 'download_enable' => [ 'subject' => '下载权限恢复', - 'body' => '管理员::operator 恢复了你的下载权限,你现在可以下载种子。', + 'body' => '你的下载权限恢复,你现在可以下载种子。By: :operator', ], ]; diff --git a/resources/lang/zh_TW/message.php b/resources/lang/zh_TW/message.php index 0457e864..b2978f75 100644 --- a/resources/lang/zh_TW/message.php +++ b/resources/lang/zh_TW/message.php @@ -12,10 +12,10 @@ return [ 'field_value_change_message_subject' => ':field 改變', 'download_disable' => [ 'subject' => '下載權限取消', - 'body' => '管理員::operator 取消了你的下載權限,可能的原因是過低的分享率或行為不當。', + 'body' => '你的下載權限被取消,可能的原因是過低的分享率或行為不當。By: :operator', ], 'download_enable' => [ 'subject' => '下載權限恢復', - 'body' => '管理員::operator 恢復了你的下載權限,你現在可以下載種子。', + 'body' => '你的下載權限恢復,你現在可以下載種子。By: :operator', ], ];