mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
[admin] agent allow&deny
This commit is contained in:
@@ -4,18 +4,47 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\AgentAllowResource;
|
||||
use App\Models\AgentAllow;
|
||||
use App\Repositories\AgentAllowRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class AgentAllowController extends Controller
|
||||
{
|
||||
private $repository;
|
||||
|
||||
public function __construct(AgentAllowRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
private function getRules(): array
|
||||
{
|
||||
return [
|
||||
'family' => 'required|string',
|
||||
'start_name' => 'required|string',
|
||||
|
||||
'peer_id_pattern' => 'required|string',
|
||||
'peer_id_match_num' => 'required|numeric',
|
||||
'peer_id_matchtype' => ['required', Rule::in(array_keys(AgentAllow::$matchTypes))],
|
||||
'peer_id_start' => 'required|string',
|
||||
|
||||
'agent_pattern' => 'required|string',
|
||||
'agent_match_num' => 'required|numeric',
|
||||
'agent_matchtype' => ['required', Rule::in(array_keys(AgentAllow::$matchTypes))],
|
||||
'agent_start' => 'required|string',
|
||||
|
||||
'exception' => ['required', Rule::in(['yes', 'no'])],
|
||||
'allowhttps' => ['required', Rule::in(['yes', 'no'])],
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function index()
|
||||
public function index(Request $request)
|
||||
{
|
||||
$result = AgentAllow::query()->orderBy('id', 'desc')->paginate();
|
||||
$result = $this->repository->getList($request->all());
|
||||
$resource = AgentAllowResource::collection($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
@@ -28,7 +57,10 @@ class AgentAllowController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
$request->validate($this->getRules());
|
||||
$result = $this->repository->store($request->all());
|
||||
$resource = new AgentAllowResource($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,8 +85,8 @@ class AgentAllowController extends Controller
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$result = AgentAllow::query()->findOrFail($id);
|
||||
$result->update($request->all());
|
||||
$request->validate($this->getRules());
|
||||
$result = $this->repository->update($request->all(), $id);
|
||||
$resource = new AgentAllowResource($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
@@ -67,8 +99,24 @@ class AgentAllowController extends Controller
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$result = AgentAllow::query()->findOrFail($id);
|
||||
$deleted = $result->delete();
|
||||
return $this->success([$deleted]);
|
||||
$result = $this->repository->delete($id);
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
$result = AgentAllow::query()->orderBy('id', 'desc')->get();
|
||||
$resource = AgentAllowResource::collection($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
public function check(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'peer_id' => 'required|string',
|
||||
'agent' => 'required|string',
|
||||
]);
|
||||
$result = $this->repository->checkClient($request->peer_id, $request->agent, true);
|
||||
return $this->success($result->toArray(), sprintf("Congratulations! the client is allowed by ID: %s", $result->id));
|
||||
}
|
||||
}
|
||||
|
||||
96
app/Http/Controllers/AgentDenyController.php
Normal file
96
app/Http/Controllers/AgentDenyController.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\AgentDenyResource;
|
||||
use App\Models\AgentDeny;
|
||||
use App\Repositories\AgentDenyRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class AgentDenyController extends Controller
|
||||
{
|
||||
private $repository;
|
||||
|
||||
public function __construct(AgentDenyRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
private function getRules(): array
|
||||
{
|
||||
return [
|
||||
'family_id' => 'required|numeric',
|
||||
'name' => 'required|string',
|
||||
'peer_id' => 'required|string',
|
||||
'agent' => 'required|string',
|
||||
'comment' => 'required|string',
|
||||
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$result = $this->repository->getList($request->all());
|
||||
$resource = AgentDenyResource::collection($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate($this->getRules());
|
||||
$result = $this->repository->store($request->all());
|
||||
$resource = new AgentDenyResource($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return array
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$result = AgentDeny::query()->findOrFail($id);
|
||||
$resource = new AgentDenyResource($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return array
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$request->validate($this->getRules());
|
||||
$result = $this->repository->update($request->all(), $id);
|
||||
$resource = new AgentDenyResource($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return array
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$result = $this->repository->delete($id);
|
||||
return $this->success($result);
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ class Kernel extends HttpKernel
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
// \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
27
app/Http/Resources/AgentDenyResource.php
Normal file
27
app/Http/Resources/AgentDenyResource.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AgentDenyResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'family_id' => $this->family_id,
|
||||
'agent' => $this->agent,
|
||||
'peer_id' => $this->peer_id,
|
||||
'comment' => $this->comment,
|
||||
'name' => $this->name,
|
||||
'family' => new AgentAllowResource($this->whenLoaded('family'))
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user