update laravel + filament & improve agent deny

This commit is contained in:
xiaomlove
2023-03-06 14:53:18 +08:00
parent e59cb7911c
commit a0e7ba12ae
13 changed files with 787 additions and 615 deletions
@@ -9,4 +9,9 @@ use Filament\Resources\Pages\CreateRecord;
class CreateAgentAllow extends CreateRecord class CreateAgentAllow extends CreateRecord
{ {
protected static string $resource = AgentAllowResource::class; 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(), Actions\DeleteAction::make(),
]; ];
} }
public function afterSave()
{
clear_agent_allow_deny_cache();
}
} }
@@ -20,10 +20,10 @@ class DeniesRelationManager extends RelationManager
{ {
return $form return $form
->schema([ ->schema([
Forms\Components\TextInput::make('name')->required()->maxLength(255), Forms\Components\TextInput::make('name')->required()->maxLength(255)->label(__('label.name')),
Forms\Components\TextInput::make('peer_id')->required()->maxLength(255), Forms\Components\TextInput::make('peer_id')->required()->maxLength(255)->label(__('label.agent_deny.peer_id')),
Forms\Components\TextInput::make('agent')->required()->maxLength(255), Forms\Components\TextInput::make('agent')->required()->maxLength(255)->label(__('label.agent_deny.agent')),
Forms\Components\Textarea::make('comment'), Forms\Components\Textarea::make('comment')->label(__('label.comment')),
]); ]);
} }
@@ -31,9 +31,9 @@ class DeniesRelationManager extends RelationManager
{ {
return $table return $table
->columns([ ->columns([
Tables\Columns\TextColumn::make('name'), Tables\Columns\TextColumn::make('name')->label(__('label.name')),
Tables\Columns\TextColumn::make('peer_id'), Tables\Columns\TextColumn::make('peer_id')->label(__('label.agent_deny.peer_id')),
Tables\Columns\TextColumn::make('agent'), Tables\Columns\TextColumn::make('agent')->label(__('label.agent_deny.agent')),
]) ])
->filters([ ->filters([
// //
@@ -9,4 +9,9 @@ use Filament\Resources\Pages\CreateRecord;
class CreateAgentDeny extends CreateRecord class CreateAgentDeny extends CreateRecord
{ {
protected static string $resource = AgentDenyResource::class; 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(), Actions\DeleteAction::make(),
]; ];
} }
public function afterSave()
{
clear_agent_allow_deny_cache();
}
} }
+7 -2
View File
@@ -4,6 +4,7 @@ namespace App\Repositories;
use App\Exceptions\ClientNotAllowedException; use App\Exceptions\ClientNotAllowedException;
use App\Models\AgentAllow; use App\Models\AgentAllow;
use App\Models\AgentDeny; use App\Models\AgentDeny;
use Illuminate\Support\Collection;
use Nexus\Database\NexusDB; use Nexus\Database\NexusDB;
class AgentAllowRepository extends BaseRepository class AgentAllowRepository extends BaseRepository
@@ -73,7 +74,7 @@ class AgentAllowRepository extends BaseRepository
public function checkClient($peerId, $agent, $debug = false) public function checkClient($peerId, $agent, $debug = false)
{ {
//check from high version to low version, if high version allow, stop! //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() return AgentAllow::query()
->orderBy('peer_id_start', 'desc') ->orderBy('peer_id_start', 'desc')
->orderBy('agent_start', 'desc') ->orderBy('agent_start', 'desc')
@@ -189,7 +190,11 @@ class AgentAllowRepository extends BaseRepository
private function checkIsDenied($peerId, $agent, $familyId) 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) { foreach ($agentDenies as $agentDeny) {
if ($agentDeny->agent == $agent && preg_match("/^" . $agentDeny->peer_id . "/", $peerId)) { if ($agentDeny->agent == $agent && preg_match("/^" . $agentDeny->peer_id . "/", $peerId)) {
return $agentDeny; return $agentDeny;
+2 -2
View File
@@ -35,13 +35,13 @@
"ext-zend-opcache": "*", "ext-zend-opcache": "*",
"doctrine/dbal": "^3.1", "doctrine/dbal": "^3.1",
"elasticsearch/elasticsearch": "^7.16", "elasticsearch/elasticsearch": "^7.16",
"filament/filament": "2.16.52", "filament/filament": "2.17.14",
"flowframe/laravel-trend": "^0.1.1", "flowframe/laravel-trend": "^0.1.1",
"fruitcake/laravel-cors": "^2.0", "fruitcake/laravel-cors": "^2.0",
"geoip2/geoip2": "~2.0", "geoip2/geoip2": "~2.0",
"hashids/hashids": "^4.1", "hashids/hashids": "^4.1",
"imdbphp/imdbphp": "^7.0", "imdbphp/imdbphp": "^7.0",
"laravel/framework": "9.41.0", "laravel/framework": "9.52.4",
"laravel/octane": "^1.2", "laravel/octane": "^1.2",
"laravel/sanctum": "^2.10", "laravel/sanctum": "^2.10",
"laravel/tinker": "^2.5", "laravel/tinker": "^2.5",
Generated
+740 -600
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0'); defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-03-05'); defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-03-06');
defined('IN_TRACKER') || define('IN_TRACKER', false); 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");
+7
View File
@@ -1063,6 +1063,13 @@ function clear_inbox_count_cache($uid)
} }
} }
function clear_agent_allow_deny_cache()
{
do_log("clear_agent_allow_deny_cache");
\Nexus\Database\NexusDB::cache_del("all_agent_allows");
\Nexus\Database\NexusDB::cache_del("all_agent_denies");
}
function user_can($permission, $fail = false, $uid = 0): bool function user_can($permission, $fail = false, $uid = 0): bool
{ {
+1 -1
View File
@@ -211,7 +211,7 @@ return [
], ],
'agent_deny' => [ 'agent_deny' => [
'label' => 'Agent deny', 'label' => 'Agent deny',
'peer_id' => 'Peer ID', 'peer_id' => 'Peer ID starts',
'agent' => 'Agent', 'agent' => 'Agent',
], ],
'claim' => [ 'claim' => [
+1 -1
View File
@@ -213,7 +213,7 @@ return [
], ],
'agent_deny' => [ 'agent_deny' => [
'label' => '拒绝客戶端', 'label' => '拒绝客戶端',
'peer_id' => 'Peer ID', 'peer_id' => 'Peer ID 起始',
'agent' => 'Agent', 'agent' => 'Agent',
], ],
'claim' => [ 'claim' => [
+1 -1
View File
@@ -210,7 +210,7 @@ return [
], ],
'agent_deny' => [ 'agent_deny' => [
'label' => '拒絕客戶端', 'label' => '拒絕客戶端',
'peer_id' => 'Peer ID', 'peer_id' => 'Peer ID 超始',
'agent' => 'Agent', 'agent' => 'Agent',
], ],
'claim' => [ 'claim' => [