mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +08:00
Announce Log
This commit is contained in:
@@ -98,3 +98,10 @@ FORCE_SCHEME=
|
||||
|
||||
CROWDIN_ACCESS_TOKEN=
|
||||
CROWDIN_PROJECT_ID=
|
||||
|
||||
CLICKHOUSE_HOST=
|
||||
CLICKHOUSE_HTTP_PORT=
|
||||
CLICKHOUSE_TCP_PORT=
|
||||
CLICKHOUSE_USER=
|
||||
CLICKHOUSE_PASSWORD=
|
||||
CLICKHOUSE_DATABASE=
|
||||
|
||||
26
app/Enums/AnnounceEventEnum.php
Normal file
26
app/Enums/AnnounceEventEnum.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use function PHPUnit\Framework\matches;
|
||||
|
||||
enum AnnounceEventEnum: string
|
||||
{
|
||||
case STARTED = "started";
|
||||
case STOPPED = "stopped";
|
||||
case PAUSED = "paused";
|
||||
case COMPLETED = "completed";
|
||||
case NONE = "none";
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::STARTED => nexus_trans("announce_log.events.started"),
|
||||
self::STOPPED => nexus_trans("announce_log.events.stopped"),
|
||||
self::PAUSED => nexus_trans("announce_log.events.paused"),
|
||||
self::COMPLETED => nexus_trans("announce_log.events.completed"),
|
||||
self::NONE => nexus_trans("announce_log.events.none"),
|
||||
default => '',
|
||||
};
|
||||
}
|
||||
}
|
||||
35
app/Filament/Pages/AnnounceMonitor.php
Normal file
35
app/Filament/Pages/AnnounceMonitor.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Filament\Widgets\AnnounceMonitor\MaxUploadedUser;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class AnnounceMonitor extends \Filament\Pages\Dashboard
|
||||
{
|
||||
protected ?string $maxContentWidth = 'full';
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-archive-box';
|
||||
|
||||
protected static string $routePath = 'announce-monitor';
|
||||
|
||||
protected static ?string $navigationGroup = 'Torrent';
|
||||
|
||||
protected static ?int $navigationSort = 15;
|
||||
|
||||
public function getTitle(): string|Htmlable
|
||||
{
|
||||
return self::getNavigationLabel();
|
||||
}
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.sidebar.announce_monitor');
|
||||
}
|
||||
|
||||
public function getWidgets(): array
|
||||
{
|
||||
return [
|
||||
MaxUploadedUser::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
198
app/Filament/Resources/Torrent/AnnounceLogResource.php
Normal file
198
app/Filament/Resources/Torrent/AnnounceLogResource.php
Normal file
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Torrent;
|
||||
|
||||
use App\Filament\Resources\Torrent\AnnounceLogResource\Pages;
|
||||
use App\Filament\Resources\Torrent\AnnounceLogResource\RelationManagers;
|
||||
use App\Models\AnnounceLog;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Infolists;
|
||||
use Filament\Infolists\Infolist;
|
||||
|
||||
class AnnounceLogResource extends Resource
|
||||
{
|
||||
protected static ?string $model = AnnounceLog::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Torrent';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.sidebar.announce_logs');
|
||||
}
|
||||
|
||||
public static function getBreadcrumb(): string
|
||||
{
|
||||
return self::getNavigationLabel();
|
||||
}
|
||||
|
||||
public static function infolist(Infolist $infolist): Infolist
|
||||
{
|
||||
return $infolist
|
||||
->schema([
|
||||
Infolists\Components\TextEntry::make('timestamp')->label(__('announce-log.timestamp')),
|
||||
Infolists\Components\TextEntry::make('request_id')->label(__('announce-log.request_id'))->copyable(),
|
||||
Infolists\Components\TextEntry::make('user_id')->label(__('announce-log.user_id'))->copyable(),
|
||||
|
||||
|
||||
Infolists\Components\TextEntry::make('torrent_id')->label(__('announce-log.torrent_id'))->copyable(),
|
||||
Infolists\Components\TextEntry::make('torrent_size')->label(__('announce-log.torrent_size'))->formatStateUsing(fn($state) => mksize($state)),
|
||||
Infolists\Components\TextEntry::make('peer_id')->label(__('announce-log.peer_id'))->copyable(),
|
||||
|
||||
Infolists\Components\TextEntry::make('announce_time')->label(__('announce-log.announce_time'))->copyable(),
|
||||
Infolists\Components\TextEntry::make('seeder_count')->label(__('announce-log.seeder_count')),
|
||||
Infolists\Components\TextEntry::make('leecher_count')->label(__('announce-log.leecher_count')),
|
||||
|
||||
Infolists\Components\TextEntry::make('uploaded_offset')->label(__('announce-log.uploaded_offset'))->formatStateUsing(fn($state) => mksize($state)),
|
||||
Infolists\Components\TextEntry::make('uploaded_total')->label(__('announce-log.uploaded_total'))->formatStateUsing(fn($state) => mksize($state)),
|
||||
Infolists\Components\TextEntry::make('uploaded_increment')->label(__('announce-log.uploaded_increment'))->formatStateUsing(fn($state) => mksize($state)),
|
||||
|
||||
Infolists\Components\TextEntry::make('downloaded_offset')->label(__('announce-log.downloaded_offset'))->formatStateUsing(fn($state) => mksize($state)),
|
||||
Infolists\Components\TextEntry::make('downloaded_total')->label(__('announce-log.downloaded_total'))->formatStateUsing(fn($state) => mksize($state)),
|
||||
Infolists\Components\TextEntry::make('downloaded_increment')->label(__('announce-log.downloaded_increment'))->formatStateUsing(fn($state) => mksize($state)),
|
||||
|
||||
Infolists\Components\TextEntry::make('left')->label(__('announce-log.left'))->formatStateUsing(fn($state) => mksize($state)),
|
||||
Infolists\Components\TextEntry::make('port')->label(__('announce-log.port')),
|
||||
Infolists\Components\TextEntry::make('agent')->label(__('announce-log.agent')),
|
||||
|
||||
Infolists\Components\TextEntry::make('started')->label(__('announce-log.started')),
|
||||
Infolists\Components\TextEntry::make('last_action')->label(__('announce-log.last_action')),
|
||||
Infolists\Components\TextEntry::make('prev_action')->label(__('announce-log.prev_action')),
|
||||
|
||||
|
||||
Infolists\Components\TextEntry::make('scheme')->label(__('announce-log.scheme')),
|
||||
Infolists\Components\TextEntry::make('host')->label(__('announce-log.host')),
|
||||
Infolists\Components\TextEntry::make('path')->label(__('announce-log.path')),
|
||||
Infolists\Components\TextEntry::make('ip')->label(__('announce-log.ip'))->copyable(),
|
||||
Infolists\Components\TextEntry::make('ipv4')->label(__('announce-log.ipv4'))->copyable(),
|
||||
Infolists\Components\TextEntry::make('ipv6')->label(__('announce-log.ipv6'))->copyable(),
|
||||
Infolists\Components\TextEntry::make('continent')->label(__('announce-log.continent')),
|
||||
Infolists\Components\TextEntry::make('country')->label(__('announce-log.country')),
|
||||
Infolists\Components\TextEntry::make('city')->label(__('announce-log.city')),
|
||||
|
||||
Infolists\Components\TextEntry::make('event')->label(__('announce-log.event')),
|
||||
Infolists\Components\TextEntry::make('passkey')->label(__('announce-log.passkey'))->copyable(),
|
||||
Infolists\Components\TextEntry::make('client_select')->label(__('announce-log.client_select')),
|
||||
])->columns(3);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('timestamp')->label(__('announce-log.timestamp'))->sortable(),
|
||||
Tables\Columns\TextColumn::make('user_id')->label(__('announce-log.user_id')),
|
||||
Tables\Columns\TextColumn::make('torrent_id')->label(__('announce-log.torrent_id')),
|
||||
Tables\Columns\TextColumn::make('peer_id')->label(__('announce-log.peer_id')),
|
||||
Tables\Columns\TextColumn::make('torrent_size')
|
||||
->label(__('announce-log.torrent_size'))
|
||||
->formatStateUsing(fn ($state): string => mksize($state))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('uploaded_total')
|
||||
->label(__('announce-log.uploaded_total'))
|
||||
->formatStateUsing(fn ($state): string => mksize($state))
|
||||
->sortable()
|
||||
,
|
||||
Tables\Columns\TextColumn::make('uploaded_increment')
|
||||
->label(__('announce-log.uploaded_increment'))
|
||||
->formatStateUsing(fn ($state): string => mksize($state))
|
||||
->sortable()
|
||||
,
|
||||
Tables\Columns\TextColumn::make('downloaded_total')
|
||||
->label(__('announce-log.downloaded_total'))
|
||||
->formatStateUsing(fn ($state): string => mksize($state))
|
||||
->sortable()
|
||||
,
|
||||
Tables\Columns\TextColumn::make('downloaded_increment')
|
||||
->label(__('announce-log.downloaded_increment'))
|
||||
->formatStateUsing(fn ($state): string => mksize($state))
|
||||
->sortable()
|
||||
,
|
||||
Tables\Columns\TextColumn::make('left')
|
||||
->label(__('announce-log.left'))
|
||||
->formatStateUsing(fn ($state): string => mksize($state))
|
||||
->sortable()
|
||||
,
|
||||
Tables\Columns\TextColumn::make('announce_time')
|
||||
->label(__('announce-log.announce_time'))
|
||||
->sortable()
|
||||
,
|
||||
Tables\Columns\TextColumn::make('event')->label(__('announce-log.event')),
|
||||
Tables\Columns\TextColumn::make('ip')->label('IP'),
|
||||
// Tables\Columns\TextColumn::make('agent')->label(__('announce-log.agent')),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\Filter::make('user_id')
|
||||
->form([
|
||||
Forms\Components\TextInput::make('user_id')
|
||||
->label(__('announce-log.user_id'))
|
||||
->numeric()
|
||||
,
|
||||
])
|
||||
,
|
||||
Tables\Filters\Filter::make('torrent_id')
|
||||
->form([
|
||||
Forms\Components\TextInput::make('torrent_id')
|
||||
->label(__('announce-log.torrent_id'))
|
||||
->numeric()
|
||||
,
|
||||
])
|
||||
,
|
||||
Tables\Filters\Filter::make('peer_id')
|
||||
->form([
|
||||
Forms\Components\TextInput::make('peer_id')
|
||||
->label(__('announce-log.peer_id'))
|
||||
,
|
||||
])
|
||||
,
|
||||
Tables\Filters\Filter::make('ip')
|
||||
->form([
|
||||
Forms\Components\TextInput::make('ip')
|
||||
->label('IP')
|
||||
,
|
||||
])
|
||||
,
|
||||
Tables\Filters\Filter::make('event')
|
||||
->form([
|
||||
Forms\Components\Select::make('event')
|
||||
->label(__('announce-log.event'))
|
||||
->options(AnnounceLog::listEvents())
|
||||
,
|
||||
])
|
||||
,
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
// Tables\Actions\BulkActionGroup::make([
|
||||
// Tables\Actions\DeleteBulkAction::make(),
|
||||
// ]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListAnnounceLogs::route('/'),
|
||||
// 'create' => Pages\CreateAnnounceLog::route('/create'),
|
||||
// 'edit' => Pages\EditAnnounceLog::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Torrent\AnnounceLogResource\Pages;
|
||||
|
||||
use App\Filament\Resources\Torrent\AnnounceLogResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateAnnounceLog extends CreateRecord
|
||||
{
|
||||
protected static string $resource = AnnounceLogResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Torrent\AnnounceLogResource\Pages;
|
||||
|
||||
use App\Filament\Resources\Torrent\AnnounceLogResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditAnnounceLog extends EditRecord
|
||||
{
|
||||
protected static string $resource = AnnounceLogResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Torrent\AnnounceLogResource\Pages;
|
||||
|
||||
use App\Filament\PageListSingle;
|
||||
use App\Filament\Resources\Torrent\AnnounceLogResource;
|
||||
use App\Models\AnnounceLog;
|
||||
use App\Repositories\AnnounceLogRepository;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Contracts\Pagination\CursorPaginator;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
class ListAnnounceLogs extends PageListSingle
|
||||
{
|
||||
protected static string $resource = AnnounceLogResource::class;
|
||||
|
||||
public function getTableRecords(): Collection|Paginator|CursorPaginator
|
||||
{
|
||||
$filterableColumns = ['user_id', 'torrent_id', 'peer_id', 'ip', 'event'];
|
||||
$sortableColumns = ['timestamp', 'uploaded_total', 'uploaded_increment', 'downloaded_total', 'downloaded_increment', 'left', 'announce_time'];
|
||||
$sortableDirections = ['asc', 'desc'];
|
||||
$request = request();
|
||||
// dd($request->all());
|
||||
$filters = [];
|
||||
foreach ($request->get('tableFilters', []) as $field => $values) {
|
||||
if (!in_array($field, $filterableColumns)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($values as $k => $v) {
|
||||
if (in_array($k, $filterableColumns)) {
|
||||
$filters[$field] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
$page = $request->get('page', 1);
|
||||
$perPage = $request->get('per_page', 10);
|
||||
$sortColumn = null;
|
||||
$sortDirection = null;
|
||||
$sortColumnFromQuery = $request->get("tableSortColumn");
|
||||
$sortDirectionFromQuery = $request->get("tableSortDirection");
|
||||
if (in_array($sortColumnFromQuery, $sortableColumns)) {
|
||||
$sortColumn = $sortColumnFromQuery;
|
||||
}
|
||||
if (in_array($sortDirectionFromQuery, $sortableDirections)) {
|
||||
$sortDirection = $sortDirectionFromQuery;
|
||||
}
|
||||
|
||||
$sorts = [];
|
||||
foreach ($request->input('components', []) as $component) {
|
||||
$snapshot = json_decode($component['snapshot'], true);
|
||||
// do_log("snapshot: " . $component['snapshot']);
|
||||
if (isset($snapshot['data']['tableRecordsPerPage'])) {
|
||||
$perPage = $snapshot['data']['tableRecordsPerPage'];
|
||||
}
|
||||
if (isset($snapshot['data']['tableSortColumn']) && in_array($snapshot['data']['tableSortColumn'], $sortableColumns)) {
|
||||
$sortColumn = $snapshot['data']['tableSortColumn'];
|
||||
}
|
||||
if (isset($snapshot['data']['tableSortDirection']) && in_array($snapshot['data']['tableSortDirection'], $sortableDirections)) {
|
||||
$sortDirection = $snapshot['data']['tableSortDirection'];
|
||||
}
|
||||
if ($sortColumn && $sortDirection) {
|
||||
$sorts[$sortColumn] = $sortDirection;
|
||||
}
|
||||
if (isset($snapshot['data']['paginators'])) {
|
||||
foreach ($snapshot['data']['paginators'] as $paginator) {
|
||||
if (isset($paginator['page'])) {
|
||||
$page = $paginator['page'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($snapshot['data']['tableFilters'])) {
|
||||
// dd($snapshot['data']['tableFilters']);
|
||||
foreach ($snapshot['data']['tableFilters'] as $filterItems) {
|
||||
foreach ($filterItems as $field => $items) {
|
||||
if (!in_array($field, $filterableColumns) || !is_array($items)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($items as $values) {
|
||||
if (!is_array($values)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($values as $subField => $value) {
|
||||
if ($field == $subField && $value !== null) {
|
||||
$filters[$field] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// do_log("updates: " . json_encode($component['updates'] ?? []));
|
||||
if (isset($component['updates']['tableRecordsPerPage'])) {
|
||||
$perPage = $component['updates']['tableRecordsPerPage'];
|
||||
}
|
||||
// do_log("calls: " . json_encode($component['calls'] ?? []));
|
||||
if (isset($component['calls'])) {
|
||||
foreach ($component['calls'] as $call) {
|
||||
if ($call['method'] == "gotoPage") {
|
||||
$page = $call['params'][0];
|
||||
}
|
||||
if ($call['method'] == "sortTable") {
|
||||
if (!in_array($call['params'][0], $sortableColumns)) {
|
||||
continue;
|
||||
}
|
||||
$sortColumn = $call['params'][0];
|
||||
if (!isset($sorts[$sortColumn])) {
|
||||
$sortDirection = "asc";
|
||||
} elseif ($sorts[$sortColumn] == "asc") {
|
||||
$sortDirection = "desc";
|
||||
} elseif ($sorts[$sortColumn] == "desc") {
|
||||
$sortDirection = null;
|
||||
}
|
||||
}
|
||||
if ($call['method'] == "resetTableFiltersForm") {
|
||||
$filters = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($filterableColumns as $field) {
|
||||
if (isset($component['updates']["tableFilters.$field.$field"])) {
|
||||
$filters[$field] = $component['updates']["tableFilters.$field.$field"];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$rep = new AnnounceLogRepository();
|
||||
$result = $rep->listAll($filters, $page, $perPage, $sortColumn, $sortDirection);
|
||||
|
||||
// 转换数据格式以适配 Filament 表格
|
||||
$items = [];
|
||||
foreach ($result['data'] as $announceLog) {
|
||||
$model = new AnnounceLog($announceLog);
|
||||
$items[] = $model;
|
||||
}
|
||||
return new LengthAwarePaginator($items, $result['total'], $perPage, $page);
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
// Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function resolveTableRecord(?string $key): ?Model
|
||||
{
|
||||
$rep = new AnnounceLogRepository();
|
||||
return $rep->getById($key);
|
||||
}
|
||||
}
|
||||
49
app/Filament/Widgets/AnnounceMonitor/MaxUploadedUser.php
Normal file
49
app/Filament/Widgets/AnnounceMonitor/MaxUploadedUser.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets\AnnounceMonitor;
|
||||
|
||||
use App\Models\AnnounceLog;
|
||||
use App\Repositories\AnnounceLogRepository;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
use Illuminate\Contracts\Pagination\CursorPaginator;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class MaxUploadedUser extends BaseWidget
|
||||
{
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitle("ssss")
|
||||
->heading(fn () => __('announce-monitor.max_uploaded_user', ['interval' => ' 1 ' . __('nexus.time_units.hour')]))
|
||||
->query(AnnounceLog::query())
|
||||
->defaultPaginationPageOption(null)
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('user_id')
|
||||
->label(__('announce-log.user_id'))
|
||||
->formatStateUsing(fn ($state) => username_for_admin($state))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('uploaded_total')
|
||||
->label(__('announce-log.uploaded_total'))
|
||||
->formatStateUsing(fn ($state) => mksize($state))
|
||||
,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getTableRecords(): Collection|Paginator|CursorPaginator
|
||||
{
|
||||
$rep = new AnnounceLogRepository();
|
||||
$list = $rep->listMaxUploadedUser(1);
|
||||
$items = [];
|
||||
foreach ($list as $index => $item) {
|
||||
$record = new AnnounceLog($item);
|
||||
$record->request_id = $index;
|
||||
$items[] = $record;
|
||||
}
|
||||
return new Collection($items);
|
||||
}
|
||||
|
||||
}
|
||||
91
app/Models/AnnounceLog.php
Normal file
91
app/Models/AnnounceLog.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\AnnounceEventEnum;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class AnnounceLog extends NexusModel
|
||||
{
|
||||
protected $fillable = [
|
||||
'timestamp', 'user_id', 'passkey', 'torrent_id', 'info_hash', 'torrent_size', 'event', 'peer_id',
|
||||
'uploaded_total', 'uploaded_increment', 'uploaded_offset',
|
||||
'downloaded_total', 'downloaded_increment', 'downloaded_offset',
|
||||
'announce_time', 'ip', 'ipv4', 'ipv6', 'port', 'agent', 'left', 'started', 'prev_action', 'last_action',
|
||||
'client_select', 'seeder_count', 'leecher_count', 'scheme', 'host', 'path',
|
||||
'continent', 'country', 'city', 'request_id'
|
||||
];
|
||||
|
||||
protected $table = null;
|
||||
protected $primaryKey = "request_id";
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
protected function timestamp(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
set: function (?string $value) {
|
||||
return $this->toLocaleTime($value, "Y-m-d H:i:s.u");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
protected function started(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
set: function (?string $value) {
|
||||
return $this->toLocaleTime($value);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
protected function prevAction(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
set: function (?string $value) {
|
||||
return $this->toLocaleTime($value);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
protected function lastAction(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
set: function (string $value) {
|
||||
return $this->toLocaleTime($value);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
private function toLocaleTime(?string $time, string $format = "Y-m-d H:i:s"): ?string
|
||||
{
|
||||
static $fromTimezone;
|
||||
static $toTimezone;
|
||||
if ($fromTimezone == null) {
|
||||
$fromTimezone = new DateTimeZone('UTC');
|
||||
}
|
||||
if ($toTimezone == null) {
|
||||
$toTimezone = new DateTimeZone(config('app.timezone'));
|
||||
}
|
||||
if (empty($time)) {
|
||||
return $time;
|
||||
}
|
||||
// 创建 DateTime 对象
|
||||
$date = DateTime::createFromFormat($format, $time, $fromTimezone);
|
||||
// 转换时区
|
||||
$date->setTimezone($toTimezone);
|
||||
// 输出转换后的时间
|
||||
return $date->format($format);
|
||||
}
|
||||
|
||||
public static function listEvents(): array
|
||||
{
|
||||
$result = [];
|
||||
foreach (AnnounceEventEnum::cases() as $event) {
|
||||
$result[$event->value] = $event->value;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -258,5 +258,10 @@ class Setting extends NexusModel
|
||||
return (int)self::get("backup.retention_count");
|
||||
}
|
||||
|
||||
public static function getIsRecordAnnounceLog(): bool
|
||||
{
|
||||
return self::get('security.record_announce_logs') == 'yes';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
77
app/Repositories/AnnounceLogRepository.php
Normal file
77
app/Repositories/AnnounceLogRepository.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\AnnounceLog;
|
||||
use ClickHouseDB\Client;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class AnnounceLogRepository extends BaseRepository
|
||||
{
|
||||
const TABLE = 'announce_logs';
|
||||
|
||||
public function listAll(array $filters, int $page, int $perPage, ?string $sortColumn, ?string $sortDirection)
|
||||
{
|
||||
$beginTimestamp = microtime(true);
|
||||
$totalAlias = "total";
|
||||
$offset = ($page - 1) * $perPage;
|
||||
$client = $this->getClient();
|
||||
$bindFields = $bindValues = [];
|
||||
foreach ($filters as $key => $value) {
|
||||
$bindFields[] = "$key = :$key";
|
||||
if ($key == "event" && $value == "none") {
|
||||
$value = "";
|
||||
}
|
||||
$bindValues[$key] = $value;
|
||||
}
|
||||
$selectPrefix = sprintf("select * from %s", self::TABLE);
|
||||
$countPrefix = sprintf("select count(*) as %s from %s", $totalAlias, self::TABLE);
|
||||
$whereStr = "";
|
||||
if (count($bindFields) > 0) {
|
||||
$whereStr = " where " . implode(" and ", $bindFields);
|
||||
}
|
||||
$selectSql = sprintf(
|
||||
"%s %s order by %s %s limit %d offset %d",
|
||||
$selectPrefix, $whereStr, $sortColumn ?: "timestamp", $sortDirection ?: "desc", $perPage, $offset
|
||||
);
|
||||
$countSql = sprintf("%s %s", $countPrefix, $whereStr);
|
||||
$data = $client->select($selectSql, $bindValues);
|
||||
$total = $client->select($countSql, $bindValues)->rows()[0][$totalAlias] ?? 0;
|
||||
do_log(sprintf(
|
||||
"[REQUEST_CLICKHOUSE], filters: %s, page: %s, perPage: %s, sortColumn: %s, sortDirection: %s, selectSql: %s, binds: %s, costTime: %.3f sec.",
|
||||
json_encode($filters), $page, $perPage, $sortColumn, $sortDirection, $selectSql, json_encode($bindValues), microtime(true) - $beginTimestamp
|
||||
));
|
||||
return [
|
||||
'data' => $data->rows(),
|
||||
'total' => (int)$total,
|
||||
'page' => $page,
|
||||
'perPage' => $perPage,
|
||||
];
|
||||
}
|
||||
|
||||
private function getClient(): Client
|
||||
{
|
||||
return app(Client::class);
|
||||
}
|
||||
|
||||
public function getById(?string $id): ?AnnounceLog
|
||||
{
|
||||
if (empty($id)) {
|
||||
return null;
|
||||
}
|
||||
$sql = sprintf("select * from %s where request_id = :id limit 1", self::TABLE);
|
||||
$statement = $this->getClient()->select($sql, ['id' => $id]);
|
||||
$arr = $statement->fetchOne();
|
||||
return $arr ? new AnnounceLog($arr) : null;
|
||||
}
|
||||
|
||||
public function listMaxUploadedUser(int $hours)
|
||||
{
|
||||
$sql = sprintf(
|
||||
"select user_id, sum(uploaded_increment) as uploaded_total from %s where timestamp >= now() - INTERVAL %d HOUR group by user_id order by uploaded_total desc limit 5",
|
||||
self::TABLE, $hours
|
||||
);
|
||||
$data = $this->getClient()->select($sql);
|
||||
return $data->rows();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -128,7 +128,7 @@ class SeedBoxRepository extends BaseRepository
|
||||
return SeedBoxRecord::query()->whereIn('id', Arr::wrap($id))->where('uid', $uid)->delete();
|
||||
}
|
||||
|
||||
public function updateStatus(SeedBoxRecord $seedBoxRecord, $status, $reason = ''): bool
|
||||
public function updateStatus(SeedBoxRecord $seedBoxRecord, $status, $reason = '')
|
||||
{
|
||||
if (Auth::user()->class < User::CLASS_ADMINISTRATOR) {
|
||||
throw new InsufficientPermissionException();
|
||||
|
||||
@@ -31,11 +31,12 @@
|
||||
"ext-pcntl": "*",
|
||||
"ext-posix": "*",
|
||||
"ext-redis": "*",
|
||||
"ext-sqlite3": "*",
|
||||
"ext-xml": "*",
|
||||
"ext-zend-opcache": "*",
|
||||
"ext-zip": "*",
|
||||
"ext-sqlite3": "*",
|
||||
"calebporzio/sushi": "^2.5",
|
||||
"cybercog/laravel-clickhouse": "dev-master",
|
||||
"elasticsearch/elasticsearch": "^7.16",
|
||||
"filament/filament": "^3.3",
|
||||
"flowframe/laravel-trend": "^0.4",
|
||||
|
||||
144
composer.lock
generated
144
composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "784dd3fb3491bc979f55e3014d9010ae",
|
||||
"content-hash": "785a13847b46eeebda6401298b89855f",
|
||||
"packages": [
|
||||
{
|
||||
"name": "anourvalar/eloquent-serialize",
|
||||
@@ -481,6 +481,84 @@
|
||||
],
|
||||
"time": "2025-03-06T14:30:56+00:00"
|
||||
},
|
||||
{
|
||||
"name": "cybercog/laravel-clickhouse",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cybercog/laravel-clickhouse.git",
|
||||
"reference": "ba90e0916ab0b7af594fa6c3874de9091afbd923"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/cybercog/laravel-clickhouse/zipball/ba90e0916ab0b7af594fa6c3874de9091afbd923",
|
||||
"reference": "ba90e0916ab0b7af594fa6c3874de9091afbd923",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/console": "^8.0|^9.0|^10.1.3|^11.0|^12.0",
|
||||
"illuminate/contracts": "^8.0|^9.0|^10.1.3|^11.0|^12.0",
|
||||
"illuminate/filesystem": "^8.0|^9.0|^10.1.3|^11.0|^12.0",
|
||||
"illuminate/support": "^8.0|^9.0|^10.1.3|^11.0|^12.0",
|
||||
"php": "^7.4|^8.0",
|
||||
"smi2/phpclickhouse": "^1.5.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"orchestra/testbench": "^7.0|^8.0|^9.0|^10.0",
|
||||
"phpunit/phpunit": "^9.6|^10.5|^11.5"
|
||||
},
|
||||
"default-branch": true,
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Cog\\Laravel\\Clickhouse\\ClickhouseServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Cog\\Laravel\\Clickhouse\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Anton Komarev",
|
||||
"email": "anton@komarev.com",
|
||||
"homepage": "https://komarev.com",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "ClickHouse migrations for Laravel",
|
||||
"homepage": "https://komarev.com/sources/laravel-clickhouse",
|
||||
"keywords": [
|
||||
"clickhouse",
|
||||
"cog",
|
||||
"cybercog",
|
||||
"database",
|
||||
"db",
|
||||
"laravel",
|
||||
"migration"
|
||||
],
|
||||
"support": {
|
||||
"docs": "https://github.com/cybercog/laravel-clickhouse",
|
||||
"email": "open@cybercog.su",
|
||||
"issues": "https://github.com/cybercog/laravel-clickhouse/issues",
|
||||
"source": "https://github.com/cybercog/laravel-clickhouse",
|
||||
"wiki": "https://github.com/cybercog/laravel-clickhouse/wiki"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://paypal.me/antonkomarev",
|
||||
"type": "custom"
|
||||
}
|
||||
],
|
||||
"time": "2025-06-16T07:24:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "danharrin/date-format-converter",
|
||||
"version": "v0.3.1",
|
||||
@@ -6863,6 +6941,65 @@
|
||||
],
|
||||
"time": "2025-02-25T09:09:36+00:00"
|
||||
},
|
||||
{
|
||||
"name": "smi2/phpclickhouse",
|
||||
"version": "1.6.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/smi2/phpClickHouse.git",
|
||||
"reference": "f79dfb798df96185beff90891efda997b01eb51b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/smi2/phpClickHouse/zipball/f79dfb798df96185beff90891efda997b01eb51b",
|
||||
"reference": "f79dfb798df96185beff90891efda997b01eb51b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"php": "^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/coding-standard": "^8.2",
|
||||
"phpstan/phpstan": "^0.12",
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"sebastian/comparator": "^4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"ClickHouseDB\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Igor Strykhar",
|
||||
"email": "isublimity@gmail.com",
|
||||
"homepage": "https://github.com/isublimity"
|
||||
}
|
||||
],
|
||||
"description": "PHP ClickHouse Client",
|
||||
"homepage": "https://github.com/smi2/phpClickHouse",
|
||||
"keywords": [
|
||||
"clickhouse",
|
||||
"client",
|
||||
"curl",
|
||||
"driver",
|
||||
"http",
|
||||
"http client",
|
||||
"php"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/smi2/phpClickHouse/issues",
|
||||
"source": "https://github.com/smi2/phpClickHouse/tree/1.6.0"
|
||||
},
|
||||
"time": "2025-01-15T07:04:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "spatie/color",
|
||||
"version": "1.8.0",
|
||||
@@ -12867,6 +13004,7 @@
|
||||
"aliases": [],
|
||||
"minimum-stability": "dev",
|
||||
"stability-flags": {
|
||||
"cybercog/laravel-clickhouse": 20,
|
||||
"phpgangsta/googleauthenticator": 20
|
||||
},
|
||||
"prefer-stable": true,
|
||||
@@ -12884,10 +13022,10 @@
|
||||
"ext-pcntl": "*",
|
||||
"ext-posix": "*",
|
||||
"ext-redis": "*",
|
||||
"ext-sqlite3": "*",
|
||||
"ext-xml": "*",
|
||||
"ext-zend-opcache": "*",
|
||||
"ext-zip": "*",
|
||||
"ext-sqlite3": "*"
|
||||
"ext-zip": "*"
|
||||
},
|
||||
"platform-dev": {},
|
||||
"plugin-api-version": "2.6.0"
|
||||
|
||||
48
config/clickhouse.php
Normal file
48
config/clickhouse.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Laravel ClickHouse.
|
||||
*
|
||||
* (c) Anton Komarev <anton@komarev.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ClickHouse Client Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you can configure a connection to connect to the ClickHouse
|
||||
| database and specify additional configuration options.
|
||||
|
|
||||
*/
|
||||
|
||||
'connection' => [
|
||||
'host' => env('CLICKHOUSE_HOST', 'localhost'),
|
||||
'port' => env('CLICKHOUSE_HTTP_PORT', 8123),
|
||||
'username' => env('CLICKHOUSE_USER', 'default'),
|
||||
'password' => env('CLICKHOUSE_PASSWORD', ''),
|
||||
'options' => [
|
||||
'database' => env('CLICKHOUSE_DATABASE', 'default'),
|
||||
'timeout' => 1,
|
||||
'connectTimeOut' => 2,
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ClickHouse Migration Settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
'migrations' => [
|
||||
'table' => env('CLICKHOUSE_MIGRATION_TABLE', 'migrations'),
|
||||
'path' => database_path('clickhouse-migrations'),
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Cog\Laravel\Clickhouse\Migration\AbstractClickhouseMigration;
|
||||
|
||||
return new class extends AbstractClickhouseMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->clickhouseClient->write(
|
||||
<<<SQL
|
||||
CREATE TABLE announce_logs
|
||||
(
|
||||
timestamp DateTime64(6),
|
||||
user_id UInt32,
|
||||
passkey String,
|
||||
torrent_id UInt32,
|
||||
torrent_size UInt64,
|
||||
info_hash FixedString(20),
|
||||
event LowCardinality(String),
|
||||
peer_id String,
|
||||
uploaded_total Float64,
|
||||
uploaded_offset Float64,
|
||||
uploaded_increment Float64,
|
||||
downloaded_total Float64,
|
||||
downloaded_offset Float64,
|
||||
downloaded_increment Float64,
|
||||
announce_time UInt32,
|
||||
ip String,
|
||||
ipv4 String,
|
||||
ipv6 String,
|
||||
port UInt16,
|
||||
agent LowCardinality(String),
|
||||
left UInt64,
|
||||
started Nullable(DateTime),
|
||||
prev_action Nullable(DateTime),
|
||||
last_action Nullable(DateTime),
|
||||
client_select UInt32,
|
||||
seeder_count UInt32,
|
||||
leecher_count UInt32,
|
||||
scheme LowCardinality(String),
|
||||
host LowCardinality(String),
|
||||
path LowCardinality(String),
|
||||
continent LowCardinality(String),
|
||||
country LowCardinality(String),
|
||||
city LowCardinality(String),
|
||||
request_id String
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
PARTITION BY toYYYYMMDD(timestamp)
|
||||
ORDER BY (user_id, torrent_id, peer_id, timestamp)
|
||||
TTL toDateTime(timestamp) + INTERVAL 90 DAY
|
||||
SETTINGS index_granularity = 8192;
|
||||
SQL
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.5');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-06-22');
|
||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.7');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-06-29');
|
||||
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||
|
||||
@@ -149,15 +149,16 @@ function print_attachment($dlkey, $enableimage = true, $imageresizer = true)
|
||||
if ($row['isimage'] == 1)
|
||||
{
|
||||
if ($enableimage){
|
||||
// if ($row['thumb'] == 1){
|
||||
// $url = $httpdirectory_attachment."/".$row['location'].".thumb.jpg";
|
||||
// $url = $httpdirectory_attachment."/".$row['location'];
|
||||
// }
|
||||
// else{
|
||||
// $url = $httpdirectory_attachment."/".$row['location'];
|
||||
// }
|
||||
$driver = $row['driver'] ?? 'local';
|
||||
$url = \Nexus\Attachment\Storage::getDriver($driver)->getImageUrl($row['location']);
|
||||
if ($driver == "local") {
|
||||
if ($row['thumb'] == 1){
|
||||
$url = $httpdirectory_attachment."/".$row['location'].".thumb.jpg";
|
||||
} else {
|
||||
$url = $httpdirectory_attachment."/".$row['location'];
|
||||
}
|
||||
} else {
|
||||
$url = \Nexus\Attachment\Storage::getDriver($driver)->getImageUrl($row['location']);
|
||||
}
|
||||
do_log(sprintf("driver: %s, location: %s, url: %s", $driver, $row['location'], $url));
|
||||
if($imageresizer == true)
|
||||
$onclick = " onclick=\"Previewurl('".$url."')\"";
|
||||
@@ -1993,6 +1994,7 @@ function userlogin() {
|
||||
|
||||
$oldip = $row['ip'];
|
||||
$row['ip'] = $ip;
|
||||
$row['seedbonus'] = floatval($row['seedbonus']);
|
||||
$GLOBALS["CURUSER"] = $row;
|
||||
if (isset($_GET['clearcache']) && $_GET['clearcache'] && get_user_class() >= UC_MODERATOR) {
|
||||
$Cache->setClearCache(1);
|
||||
@@ -5816,27 +5818,14 @@ function can_access_torrent($torrent, $uid)
|
||||
|
||||
function get_ip_location_from_geoip($ip): bool|array
|
||||
{
|
||||
$database = nexus_env('GEOIP2_DATABASE');
|
||||
if (empty($database)) {
|
||||
do_log("no geoip2 database.");
|
||||
return false;
|
||||
}
|
||||
if (!is_readable($database)) {
|
||||
do_log("geoip2 database: $database is not readable.");
|
||||
return false;
|
||||
}
|
||||
static $reader;
|
||||
if (is_null($reader)) {
|
||||
$reader = new \GeoIp2\Database\Reader($database);
|
||||
}
|
||||
$lang = get_langfolder_cookie();
|
||||
$langMap = [
|
||||
'chs' => 'zh-CN',
|
||||
'cht' => 'zh-CN',
|
||||
'en' => 'en',
|
||||
];
|
||||
$locale = $langMap[$lang] ?? $lang;
|
||||
$locationInfo = \Nexus\Database\NexusDB::remember("locations_{$ip}", 3600, function () use ($locale, $ip, $reader) {
|
||||
$locationInfo = \Nexus\Database\NexusDB::remember("locations_{$ip}", 3600, function () use ($ip) {
|
||||
$lang = get_langfolder_cookie();
|
||||
$langMap = [
|
||||
'chs' => 'zh-CN',
|
||||
'cht' => 'zh-CN',
|
||||
'en' => 'en',
|
||||
];
|
||||
$locale = $langMap[$lang] ?? $lang;
|
||||
$info = [
|
||||
'ip' => $ip,
|
||||
'version' => '',
|
||||
@@ -5846,9 +5835,20 @@ function get_ip_location_from_geoip($ip): bool|array
|
||||
'city_en' => '',
|
||||
];
|
||||
try {
|
||||
$database = nexus_env('GEOIP2_DATABASE');
|
||||
if (empty($database)) {
|
||||
do_log("no geoip2 database.");
|
||||
return false;
|
||||
}
|
||||
if (!is_readable($database)) {
|
||||
do_log("geoip2 database: $database is not readable.");
|
||||
return false;
|
||||
}
|
||||
$reader = new \GeoIp2\Database\Reader($database);
|
||||
$record = $reader->city($ip);
|
||||
$countryName = $record->country->names[$locale] ?? $record->country->names['en'] ?? '';
|
||||
$cityName = $record->city->names[$locale] ?? $record->city->names['en'] ?? '';
|
||||
$continentName = $record->continent->names[$locale] ?? $record->continent->names['en'] ?? '';
|
||||
if (isIPV4($ip)) {
|
||||
$info['version'] = 4;
|
||||
} elseif (isIPV6($ip)) {
|
||||
@@ -5858,13 +5858,17 @@ function get_ip_location_from_geoip($ip): bool|array
|
||||
$info['country_en'] = $record->country->names['en'] ?? '';
|
||||
$info['city'] = $cityName;
|
||||
$info['city_en'] = $record->city->names['en'] ?? '';
|
||||
|
||||
$info['continent'] = $continentName;
|
||||
$info['continent_en'] = $record->continent->names['en'] ?? '';
|
||||
} catch (\Exception $exception) {
|
||||
do_log($exception->getMessage() . $exception->getTraceAsString(), 'error');
|
||||
}
|
||||
return $info;
|
||||
});
|
||||
do_log("ip: $ip, locale: $locale, result: " . nexus_json_encode($locationInfo));
|
||||
do_log("ip: $ip, result: " . nexus_json_encode($locationInfo));
|
||||
if ($locationInfo === false) {
|
||||
return false;
|
||||
}
|
||||
$name = sprintf('%s[v%s]', $locationInfo['city'] ? ($locationInfo['city'] . "·" . $locationInfo['country']) : $locationInfo['country'], $locationInfo['version']);
|
||||
return [
|
||||
'name' => $name,
|
||||
@@ -5876,6 +5880,7 @@ function get_ip_location_from_geoip($ip): bool|array
|
||||
'ip_version' => $locationInfo['version'],
|
||||
'country_en' => $locationInfo['country_en'],
|
||||
'city_en' => $locationInfo['city_en'],
|
||||
'continent_en' => $locationInfo['continent_en'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -816,6 +816,8 @@ $lang_settings = array
|
||||
'text_use_challenge_response_authentication_note' => '如果启用,登录时将不传输明文密码,建议启用。未来版本会删除此配置且启用此功能。',
|
||||
'row_complain_enabled' => '启用申诉',
|
||||
'row_complain_enabled_note' => '默认: "yes"',
|
||||
'row_record_announce_logs' => '记录汇报日志',
|
||||
'text_record_announce_logs_note' => '要启用,请先安装并启动 ClickHouse,并在 .env 文件中添加配置',
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
@@ -378,7 +378,12 @@ class Update extends Install
|
||||
]);
|
||||
NexusDB::cache_del("nexus_plugin_store_all");
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.9.7
|
||||
*/
|
||||
if (env("CLICKHOUSE_HOST")) {
|
||||
Artisan::call("clickhouse:migrate");
|
||||
}
|
||||
}
|
||||
|
||||
public function runExtraMigrate()
|
||||
|
||||
@@ -20,12 +20,12 @@ class TechnicalInformation
|
||||
$result = [];
|
||||
$parentKey = "";
|
||||
foreach ($arr as $key => $value) {
|
||||
$value = trim($value);
|
||||
$value = $this->trim($value);
|
||||
if (empty($value)) {
|
||||
continue;
|
||||
}
|
||||
$rowKeyValue = explode(':', $value);
|
||||
$rowKeyValue = array_filter(array_map('trim', $rowKeyValue));
|
||||
$rowKeyValue = array_filter(array_map([$this, 'trim'], $rowKeyValue));
|
||||
if (count($rowKeyValue) == 1) {
|
||||
$parentKey = $rowKeyValue[0];
|
||||
} elseif (count($rowKeyValue) == 2) {
|
||||
@@ -39,6 +39,11 @@ class TechnicalInformation
|
||||
|
||||
}
|
||||
|
||||
private function trim(string $value): string
|
||||
{
|
||||
return trim($value, " \n\r\t\v\0\u{A0}");
|
||||
}
|
||||
|
||||
public function getRuntime()
|
||||
{
|
||||
return $this->mediaInfoArr['General']['Duration'] ?? '';
|
||||
|
||||
@@ -64,6 +64,19 @@ if (!$useChallengeResponseAuthentication) {
|
||||
<tr><td class="rowhead"><?php echo $lang_login['rowhead_two_step_code']?></td><td class="rowfollow" align="left"><input type="text" name="two_step_code" placeholder="<?php echo $lang_login['two_step_code_tooltip'] ?>" style="width: 180px; border: 1px solid gray"/></td></tr>
|
||||
<?php
|
||||
show_image_code ();
|
||||
//\Nexus\Nexus::js("https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit&onload=onloadTurnstileCallback", "footer", true);
|
||||
//echo sprintf('<tr><td colspan="2"><div id="example-container"></div></td></tr>');
|
||||
//$script = <<<JS
|
||||
//window.onloadTurnstileCallback = function () {
|
||||
// turnstile.render("#example-container", {
|
||||
// sitekey: "0x4AAAAAABcl4hBpOruc_7NH",
|
||||
// callback: function (token) {
|
||||
// console.log(`Challenge Success: ` + token);
|
||||
// },
|
||||
// });
|
||||
//};
|
||||
//JS;
|
||||
//\Nexus\Nexus::js($script, "footer", false);
|
||||
if ($securelogin == "yes")
|
||||
$sec = "checked=\"checked\" disabled=\"disabled\"";
|
||||
elseif ($securelogin == "no")
|
||||
@@ -83,9 +96,10 @@ elseif ($securetracker == "op")
|
||||
<!--<tr><td class="rowhead">--><?php //echo $lang_login['text_restrict_ip']?><!--</td><td class="rowfollow" align="left"><input class="checkbox" type="checkbox" name="securelogin" value="yes" />--><?php //echo $lang_login['checkbox_restrict_ip']?><!--</td></tr>-->
|
||||
<!--<tr><td class="rowhead">--><?php //echo $lang_login['text_ssl']?><!--</td><td class="rowfollow" align="left"><input class="checkbox" type="checkbox" name="ssl" value="yes" --><?php //echo $sec?><!-- />--><?php //echo $lang_login['checkbox_ssl']?><!--<br /><input class="checkbox" type="checkbox" name="trackerssl" value="yes" --><?php //echo $sectra?><!-- />--><?php //echo $lang_login['checkbox_ssl_tracker']?><!--</td></tr>-->
|
||||
<tr><td class="toolbox" colspan="2" align="right"><input id="submit-btn" type="button" value="<?php echo $lang_login['button_login']?>" class="btn" /> <input type="reset" value="<?php echo $lang_login['button_reset']?>" class="btn" /></td></tr>
|
||||
<tr><td colspan="2"><div class="cf-turnstile" data-sitekey="0x4AAAAAABiU8qHu0dBVuioD"></div></td></tr>
|
||||
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js"></script>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
if (isset($returnto)) {
|
||||
print("<input type=\"hidden\" name=\"returnto\" value=\"" . htmlspecialchars($returnto) . "\" />\n");
|
||||
}
|
||||
|
||||
@@ -369,6 +369,7 @@ for ($i=0; $i < count($allBonus); $i++)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
$bonusarrray['points'] = floatval($bonusarray['points']);
|
||||
|
||||
print("<tr>");
|
||||
print("<form action=\"?action=exchange\" method=\"post\">");
|
||||
|
||||
@@ -199,7 +199,7 @@ elseif ($action == 'savesettings_security') // save security
|
||||
$validConfig = array(
|
||||
'securelogin', 'securetracker', 'https_announce_url','iv','maxip','maxloginattempts','changeemail','cheaterdet','nodetect',
|
||||
'guest_visit_type', 'guest_visit_value_static_page', 'guest_visit_value_custom_content', 'guest_visit_value_redirect',
|
||||
'login_type', 'login_secret_lifetime', 'use_challenge_response_authentication'
|
||||
'login_type', 'login_secret_lifetime', 'use_challenge_response_authentication', 'record_announce_logs'
|
||||
);
|
||||
GetVar($validConfig);
|
||||
$SECURITY = [];
|
||||
@@ -368,7 +368,8 @@ elseif ($action == 'securitysettings') //security settings
|
||||
print("<tbody>");
|
||||
print ("<form method='post' action='".$_SERVER["SCRIPT_NAME"]."' name='securitysettings_form'><input type='hidden' name='action' value='savesettings_security'>");
|
||||
tr($lang_settings['row_enable_ssl'],"<input type='radio' name='securelogin'" . ($SECURITY["securelogin"] == "yes" ? " checked" : "") . " value='yes'> ".$lang_settings['text_yes']. " <input type='radio' name='securelogin'" . ($SECURITY["securelogin"] == "no" ? " checked" : "") . " value='no'> ".$lang_settings['text_no']. " <input type='radio' name='securelogin'" . ($SECURITY["securelogin"] == "op" ? " checked" : "") . " value='op'> ".$lang_settings['text_optional']."<br />".$lang_settings['text_ssl_note'], 1);
|
||||
tr($lang_settings['row_enable_ssl_tracker'],"<input type='radio' name='securetracker'" . ($SECURITY["securetracker"] == "yes" ? " checked" : "") . " value='yes'> ".$lang_settings['text_yes']. " <input type='radio' name='securetracker'" . ($SECURITY["securetracker"] == "no" ? " checked" : "") . " value='no'> ".$lang_settings['text_no']. " <input type='radio' name='securetracker'" . ($SECURITY["securetracker"] == "op" ? " checked" : "") . " value='op'> ".$lang_settings['text_optional']."<br />".$lang_settings['text_ssl_note'], 1);
|
||||
// tr($lang_settings['row_enable_ssl_tracker'],"<input type='radio' name='securetracker'" . ($SECURITY["securetracker"] == "yes" ? " checked" : "") . " value='yes'> ".$lang_settings['text_yes']. " <input type='radio' name='securetracker'" . ($SECURITY["securetracker"] == "no" ? " checked" : "") . " value='no'> ".$lang_settings['text_no']. " <input type='radio' name='securetracker'" . ($SECURITY["securetracker"] == "op" ? " checked" : "") . " value='op'> ".$lang_settings['text_optional']."<br />".$lang_settings['text_ssl_note'], 1);
|
||||
tr($lang_settings['row_record_announce_logs'],"<input type='radio' name='record_announce_logs'" . ($SECURITY["record_announce_logs"] == "yes" ? " checked" : "") . " value='yes'> ".$lang_settings['text_yes']. " <input type='radio' name='record_announce_logs'" . ($SECURITY["record_announce_logs"] == "no" ? " checked" : "") . " value='no'> ".$lang_settings['text_no']."<br />".$lang_settings['text_record_announce_logs_note'], 1);
|
||||
// tr($lang_settings['row_https_announce_url'],"<input type='text' style=\"width: 300px\" name=https_announce_url value='".($SECURITY["https_announce_url"] ? $SECURITY["https_announce_url"] : "")."'> ".$lang_settings['text_https_announce_url_note'] . $_SERVER["HTTP_HOST"]."/announce.php", 1);
|
||||
yesorno($lang_settings['row_enable_image_verification'], 'iv', $SECURITY["iv"], $lang_settings['text_image_verification_note']);
|
||||
yesorno($lang_settings['row_allow_email_change'], 'changeemail', $SECURITY["changeemail"], $lang_settings['text_email_change_note']);
|
||||
|
||||
@@ -46,6 +46,8 @@ return [
|
||||
'user_modify_logs' => '修改记录',
|
||||
'message_templates' => '消息模板',
|
||||
'tracker_url' => 'Tracker URL',
|
||||
'announce_logs' => '汇报记录',
|
||||
'announce_monitor' => '汇报监控',
|
||||
],
|
||||
'resources' => [
|
||||
'agent_allow' => [
|
||||
|
||||
47
resources/lang/zh_CN/announce-log.php
Normal file
47
resources/lang/zh_CN/announce-log.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'timestamp' => '汇报时间',
|
||||
'request_id' => '请求 ID',
|
||||
'uploaded_total' => '累计上传量',
|
||||
'uploaded_increment' => '上传增量',
|
||||
'uploaded_offset' => '上传起始量',
|
||||
'downloaded_total' => '累计下载量',
|
||||
'downloaded_increment' => '下载增量',
|
||||
'downloaded_offset' => '下载起始量',
|
||||
'left' => '剩余量',
|
||||
'seeder' => '做种',
|
||||
'leecher' => '下载',
|
||||
'announce_time' => '时间间隔',
|
||||
'agent' => '客户端',
|
||||
'user_id' => '用户 ID',
|
||||
'passkey' => '用户 Passkey',
|
||||
'torrent_id' => '种子 ID',
|
||||
'peer_id' => 'Peer ID',
|
||||
'event' => '事件',
|
||||
'ip' => 'IP',
|
||||
'ipv4' => 'IPV4',
|
||||
'ipv6' => 'IPV6',
|
||||
'port' => '端口',
|
||||
'started' => '开始时间',
|
||||
'prev_action' => '上次汇报',
|
||||
'last_action' => '最近汇报',
|
||||
'seeder_count' => '做种数',
|
||||
'leecher_count' => '下载数',
|
||||
'scheme' => '汇报协议',
|
||||
'host' => '汇报主机',
|
||||
'path' => '汇报路径',
|
||||
'continent' => '洲',
|
||||
'country' => '国家',
|
||||
'city' => '城市',
|
||||
'show_client_error' => '是否客户端错误',
|
||||
'client_select' => '客户端 ID',
|
||||
'torrent_size' => '种子体积',
|
||||
'events' => [
|
||||
'started' => '开始',
|
||||
'stopped' => '停止',
|
||||
'paused' => '暂停',
|
||||
'completed' => '完成',
|
||||
'none' => '无',
|
||||
],
|
||||
];
|
||||
5
resources/lang/zh_CN/announce-monitor.php
Normal file
5
resources/lang/zh_CN/announce-monitor.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'max_uploaded_user' => '最近:interval最多上传',
|
||||
];
|
||||
@@ -7,6 +7,7 @@ return [
|
||||
'user_not_exists' => '(无此帐户)',
|
||||
'time_units' => [
|
||||
'week' => '周',
|
||||
'hour' => '小时',
|
||||
],
|
||||
'select_all' => '全选',
|
||||
'unselect_all' => '全不选',
|
||||
|
||||
@@ -48,6 +48,8 @@ return [
|
||||
'user_modify_logs' => '修改記錄',
|
||||
'message_templates' => '消息模板',
|
||||
'tracker_url' => 'Tracker URL',
|
||||
'announce_logs' => '匯報記錄',
|
||||
'announce_monitor' => '匯報監控',
|
||||
],
|
||||
'resources' => [
|
||||
'agent_allow' => [
|
||||
|
||||
47
resources/lang/zh_TW/announce-log.php
Normal file
47
resources/lang/zh_TW/announce-log.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'timestamp' => '匯報時間',
|
||||
'request_id' => '請求 ID',
|
||||
'uploaded_total' => '累計上傳量',
|
||||
'uploaded_increment' => '上傳增量',
|
||||
'uploaded_offset' => '上傳起始量',
|
||||
'downloaded_total' => '累計下載量',
|
||||
'downloaded_increment' => '下載增量',
|
||||
'downloaded_offset' => '下載起始量',
|
||||
'left' => '剩餘量',
|
||||
'seeder' => '做種',
|
||||
'leecher' => '下載',
|
||||
'announce_time' => '時間間隔',
|
||||
'agent' => '客戶端',
|
||||
'user_id' => '用戶 ID',
|
||||
'passkey' => '用戶 Passkey',
|
||||
'torrent_id' => '種子 ID',
|
||||
'peer_id' => 'Peer ID',
|
||||
'event' => '事件',
|
||||
'ip' => 'IP',
|
||||
'ipv4' => 'IPV4',
|
||||
'ipv6' => 'IPV6',
|
||||
'port' => '端口',
|
||||
'started' => '開始時間',
|
||||
'prev_action' => '上次匯報',
|
||||
'last_action' => '最近匯報',
|
||||
'seeder_count' => '做種數',
|
||||
'leecher_count' => '下載數',
|
||||
'scheme' => '匯報協議',
|
||||
'host' => '匯報主機',
|
||||
'path' => '匯報路徑',
|
||||
'continent' => '洲',
|
||||
'country' => '國家',
|
||||
'city' => '城市',
|
||||
'show_client_error' => '是否客戶端錯誤',
|
||||
'client_select' => '客戶端 ID',
|
||||
'torrent_size' => '種子體積',
|
||||
'events' => [
|
||||
'started' => '開始',
|
||||
'stopped' => '停止',
|
||||
'paused' => '暫停',
|
||||
'completed' => '完成',
|
||||
'none' => '無',
|
||||
],
|
||||
];
|
||||
5
resources/lang/zh_TW/announce-monitor.php
Normal file
5
resources/lang/zh_TW/announce-monitor.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'max_uploaded_user' => '最近:interval最多上傳',
|
||||
];
|
||||
Reference in New Issue
Block a user