mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
update laravel + filament & improve agent deny
This commit is contained in:
@@ -9,4 +9,9 @@ use Filament\Resources\Pages\CreateRecord;
|
||||
class CreateAgentAllow extends CreateRecord
|
||||
{
|
||||
protected static string $resource = AgentAllowResource::class;
|
||||
|
||||
public function afterCreate()
|
||||
{
|
||||
clear_agent_allow_deny_cache();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,4 +16,9 @@ class EditAgentAllow extends EditRecord
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
public function afterSave()
|
||||
{
|
||||
clear_agent_allow_deny_cache();
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -20,10 +20,10 @@ class DeniesRelationManager extends RelationManager
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')->required()->maxLength(255),
|
||||
Forms\Components\TextInput::make('peer_id')->required()->maxLength(255),
|
||||
Forms\Components\TextInput::make('agent')->required()->maxLength(255),
|
||||
Forms\Components\Textarea::make('comment'),
|
||||
Forms\Components\TextInput::make('name')->required()->maxLength(255)->label(__('label.name')),
|
||||
Forms\Components\TextInput::make('peer_id')->required()->maxLength(255)->label(__('label.agent_deny.peer_id')),
|
||||
Forms\Components\TextInput::make('agent')->required()->maxLength(255)->label(__('label.agent_deny.agent')),
|
||||
Forms\Components\Textarea::make('comment')->label(__('label.comment')),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ class DeniesRelationManager extends RelationManager
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name'),
|
||||
Tables\Columns\TextColumn::make('peer_id'),
|
||||
Tables\Columns\TextColumn::make('agent'),
|
||||
Tables\Columns\TextColumn::make('name')->label(__('label.name')),
|
||||
Tables\Columns\TextColumn::make('peer_id')->label(__('label.agent_deny.peer_id')),
|
||||
Tables\Columns\TextColumn::make('agent')->label(__('label.agent_deny.agent')),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
|
||||
@@ -9,4 +9,9 @@ use Filament\Resources\Pages\CreateRecord;
|
||||
class CreateAgentDeny extends CreateRecord
|
||||
{
|
||||
protected static string $resource = AgentDenyResource::class;
|
||||
|
||||
public function afterCreate()
|
||||
{
|
||||
clear_agent_allow_deny_cache();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,4 +16,9 @@ class EditAgentDeny extends EditRecord
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
public function afterSave()
|
||||
{
|
||||
clear_agent_allow_deny_cache();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Repositories;
|
||||
use App\Exceptions\ClientNotAllowedException;
|
||||
use App\Models\AgentAllow;
|
||||
use App\Models\AgentDeny;
|
||||
use Illuminate\Support\Collection;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class AgentAllowRepository extends BaseRepository
|
||||
@@ -73,7 +74,7 @@ class AgentAllowRepository extends BaseRepository
|
||||
public function checkClient($peerId, $agent, $debug = false)
|
||||
{
|
||||
//check from high version to low version, if high version allow, stop!
|
||||
$allows = NexusDB::remember("all_agent_allows", 600, function () {
|
||||
$allows = NexusDB::remember("all_agent_allows", 3600, function () {
|
||||
return AgentAllow::query()
|
||||
->orderBy('peer_id_start', 'desc')
|
||||
->orderBy('agent_start', 'desc')
|
||||
@@ -189,7 +190,11 @@ class AgentAllowRepository extends BaseRepository
|
||||
|
||||
private function checkIsDenied($peerId, $agent, $familyId)
|
||||
{
|
||||
$agentDenies = AgentDeny::query()->where('family_id', $familyId)->get();
|
||||
/** @var Collection $allDenies */
|
||||
$allDenies = NexusDB::remember("all_agent_denies", 3600, function () {
|
||||
return AgentDeny::query()->get()->groupBy('family_id');
|
||||
});
|
||||
$agentDenies = $allDenies->get($familyId, []);
|
||||
foreach ($agentDenies as $agentDeny) {
|
||||
if ($agentDeny->agent == $agent && preg_match("/^" . $agentDeny->peer_id . "/", $peerId)) {
|
||||
return $agentDeny;
|
||||
|
||||
Reference in New Issue
Block a user