From 9edbaf49cae470278a597db5fd0c30d539cf4711 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Fri, 25 Feb 2022 18:09:31 +0800 Subject: [PATCH] [admin] agent allow&deny --- admin/src/App.vue | 14 +- admin/src/router/index.js | 20 ++ admin/src/styles/common.scss | 1 + admin/src/utils/api.js | 32 ++- admin/src/utils/index.js | 2 + admin/src/utils/table.js | 2 +- admin/src/views/agent-allow/dialog-check.vue | 78 ++++++ admin/src/views/agent-allow/form.vue | 198 +++++++++++++- admin/src/views/agent-allow/index.vue | 197 +++++++++++++- admin/src/views/agent-deny/form.vue | 133 ++++++++++ admin/src/views/agent-deny/index.vue | 181 +++++++++++++ admin/src/views/user/index.vue | 29 ++- app/Console/Commands/Test.php | 7 +- app/Http/Controllers/AgentAllowController.php | 64 ++++- app/Http/Controllers/AgentDenyController.php | 96 +++++++ app/Http/Kernel.php | 2 +- app/Http/Resources/AgentDenyResource.php | 27 ++ app/Models/AgentAllow.php | 17 +- app/Models/AgentDeny.php | 17 ++ app/Repositories/AgentAllowRepository.php | 243 ++++++++++++++++++ app/Repositories/AgentDenyRepository.php | 43 ++++ app/Repositories/UserRepository.php | 9 + ...dd_id_to_agent_allowed_exception_table.php | 32 +++ include/globalfunctions.php | 1 + routes/api.php | 3 + 25 files changed, 1420 insertions(+), 28 deletions(-) create mode 100644 admin/src/views/agent-allow/dialog-check.vue create mode 100644 admin/src/views/agent-deny/form.vue create mode 100644 admin/src/views/agent-deny/index.vue create mode 100644 app/Http/Controllers/AgentDenyController.php create mode 100644 app/Http/Resources/AgentDenyResource.php create mode 100644 app/Models/AgentDeny.php create mode 100644 app/Repositories/AgentAllowRepository.php create mode 100644 app/Repositories/AgentDenyRepository.php create mode 100644 database/migrations/2022_02_25_021356_add_id_to_agent_allowed_exception_table.php diff --git a/admin/src/App.vue b/admin/src/App.vue index 6463911c..1308c27d 100644 --- a/admin/src/App.vue +++ b/admin/src/App.vue @@ -26,12 +26,20 @@ + + + Allow + + + Deny + + + - - - Exam diff --git a/admin/src/router/index.js b/admin/src/router/index.js index a8bb045f..36338f5e 100644 --- a/admin/src/router/index.js +++ b/admin/src/router/index.js @@ -64,6 +64,26 @@ const router = createRouter({ name: 'medal-form', component: () => import('../views/medal/form.vue') }, + { + path: '/agent-allow', + name: 'agent-allow', + component: () => import('../views/agent-allow/index.vue') + }, + { + path: '/agent-allow-form', + name: 'agent-allow-form', + component: () => import('../views/agent-allow/form.vue') + }, + { + path: '/agent-deny', + name: 'agent-deny', + component: () => import('../views/agent-deny/index.vue') + }, + { + path: '/agent-deny-form', + name: 'agent-deny-form', + component: () => import('../views/agent-deny/form.vue') + }, { path: '/setting', name: 'setting', diff --git a/admin/src/styles/common.scss b/admin/src/styles/common.scss index 68a1a61c..de017124 100644 --- a/admin/src/styles/common.scss +++ b/admin/src/styles/common.scss @@ -1,6 +1,7 @@ .nexus-table-header { display: flex; justify-content: space-between; + align-items: center; } .nexus-help-text { color: #aaa; diff --git a/admin/src/utils/api.js b/admin/src/utils/api.js index 525fa3bd..845c2abc 100644 --- a/admin/src/utils/api.js +++ b/admin/src/utils/api.js @@ -7,22 +7,44 @@ const api = { logout: (params = {}) => { return axios.post('logout'); }, - listAllowAgent: (params = {}) => { + listAgentAllow: (params = {}) => { return axios.get('agent-allows', {params: params}); }, - storeAllowAgent: (params = {}) => { + listAllAgentAllow: (params = {}) => { + return axios.get('all-agent-allows', {params: params}); + }, + storeAgentAllow: (params = {}) => { return axios.post('agent-allows', params); }, - updateAllowAgent: (id, params = {}) => { + updateAgentAllow: (id, params = {}) => { return axios.put('agent-allows/' + id, params); }, - getAllowAgent: (id) => { + getAgentAllow: (id) => { return axios.get('agent-allows/' + id); }, - deleteAllowAgent: (id) => { + deleteAgentAllow: (id) => { return axios.delete('agent-allows/' + id); }, + listAgentDeny: (params = {}) => { + return axios.get('agent-denies', {params: params}); + }, + storeAgentDeny: (params = {}) => { + return axios.post('agent-denies', params); + }, + updateAgentDeny: (id, params = {}) => { + return axios.put('agent-denies/' + id, params); + }, + getAgentDeny: (id) => { + return axios.get('agent-denies/' + id); + }, + deleteAgentDeny: (id) => { + return axios.delete('agent-denies/' + id); + }, + checkAgent: (params = {}) => { + return axios.post('agent-check', params); + }, + listUser: (params = {}) => { return axios.get('users', {params: params}); }, diff --git a/admin/src/utils/index.js b/admin/src/utils/index.js index bdaf6fa8..102ce29b 100644 --- a/admin/src/utils/index.js +++ b/admin/src/utils/index.js @@ -40,6 +40,8 @@ export const pathMap = { account: '修改账户', 'agent-allow': 'Agent allow', 'agent-allow-form': 'Agent allow form', + 'agent-deny': 'Agent deny', + 'agent-deny-form': 'Agent deny form', 'user': 'User', 'user-form': 'User form', 'user-detail': 'User detail', diff --git a/admin/src/utils/table.js b/admin/src/utils/table.js index a381fece..f9316307 100644 --- a/admin/src/utils/table.js +++ b/admin/src/utils/table.js @@ -6,7 +6,7 @@ const useTable = () => { query: { page: 1, sort_field: 'id', - sort_type: 'desc' + sort_type: 'desc', }, tableData: [], multipleSelection: [], diff --git a/admin/src/views/agent-allow/dialog-check.vue b/admin/src/views/agent-allow/dialog-check.vue new file mode 100644 index 00000000..80d697d3 --- /dev/null +++ b/admin/src/views/agent-allow/dialog-check.vue @@ -0,0 +1,78 @@ + + + diff --git a/admin/src/views/agent-allow/form.vue b/admin/src/views/agent-allow/form.vue index 45587e56..d38e5129 100644 --- a/admin/src/views/agent-allow/form.vue +++ b/admin/src/views/agent-allow/form.vue @@ -1,3 +1,199 @@ + + + + diff --git a/admin/src/views/agent-allow/index.vue b/admin/src/views/agent-allow/index.vue index b714668f..779fe02e 100644 --- a/admin/src/views/agent-allow/index.vue +++ b/admin/src/views/agent-allow/index.vue @@ -1,3 +1,198 @@ + + + + diff --git a/admin/src/views/agent-deny/form.vue b/admin/src/views/agent-deny/form.vue new file mode 100644 index 00000000..c1e82787 --- /dev/null +++ b/admin/src/views/agent-deny/form.vue @@ -0,0 +1,133 @@ + + + + + diff --git a/admin/src/views/agent-deny/index.vue b/admin/src/views/agent-deny/index.vue new file mode 100644 index 00000000..7b9cc09d --- /dev/null +++ b/admin/src/views/agent-deny/index.vue @@ -0,0 +1,181 @@ + + + + + diff --git a/admin/src/views/user/index.vue b/admin/src/views/user/index.vue index 541e28c7..7d082a77 100644 --- a/admin/src/views/user/index.vue +++ b/admin/src/views/user/index.vue @@ -3,10 +3,24 @@ @@ -26,7 +40,7 @@ @@ -157,6 +171,12 @@ export default { fetchTableData() } + const handleReset = () => { + state.query.id = ''; + state.query.username = ''; + state.query.email = ''; + } + const handleDetail = (id) => { router.push({ name: 'user-detail', @@ -187,7 +207,8 @@ export default { handleSortChange, formatColumnClass, formatColumnUploaded, - formatColumnDownloaded + formatColumnDownloaded, + handleReset } } } diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 95120ad8..b8ef129a 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -11,6 +11,7 @@ use App\Models\Medal; use App\Models\SearchBox; use App\Models\Snatch; use App\Models\User; +use App\Repositories\AgentAllowRepository; use App\Repositories\ExamRepository; use App\Repositories\HitAndRunRepository; use App\Repositories\SearchBoxRepository; @@ -58,8 +59,10 @@ class Test extends Command */ public function handle() { - $rep = new HitAndRunRepository(); - $r = $rep->cronjobUpdateStatus(); + $peerId = '-TR2920-9bqp8iu7v9se'; + $agent = 'Transmission/2.92'; + $rep = new AgentAllowRepository(); + $r = $rep->checkClient($peerId, $agent, true); dd($r); } diff --git a/app/Http/Controllers/AgentAllowController.php b/app/Http/Controllers/AgentAllowController.php index 805002b9..9cb1831d 100644 --- a/app/Http/Controllers/AgentAllowController.php +++ b/app/Http/Controllers/AgentAllowController.php @@ -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)); } } diff --git a/app/Http/Controllers/AgentDenyController.php b/app/Http/Controllers/AgentDenyController.php new file mode 100644 index 00000000..dadf7fbf --- /dev/null +++ b/app/Http/Controllers/AgentDenyController.php @@ -0,0 +1,96 @@ +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); + } +} diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index fa9c0029..1c5407f3 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -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, ]; /** diff --git a/app/Http/Resources/AgentDenyResource.php b/app/Http/Resources/AgentDenyResource.php new file mode 100644 index 00000000..0f53a254 --- /dev/null +++ b/app/Http/Resources/AgentDenyResource.php @@ -0,0 +1,27 @@ + $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')) + ]; + } +} diff --git a/app/Models/AgentAllow.php b/app/Models/AgentAllow.php index d9979592..c87ac0fd 100644 --- a/app/Models/AgentAllow.php +++ b/app/Models/AgentAllow.php @@ -6,11 +6,24 @@ class AgentAllow extends NexusModel { protected $table = 'agent_allowed_family'; - public $timestamps = true; - protected $fillable = [ 'family', 'start_name', 'exception', 'allowhttps', 'comment', 'peer_id_pattern', 'peer_id_match_num', 'peer_id_matchtype', 'peer_id_start', 'agent_pattern', 'agent_match_num', 'agent_matchtype', 'agent_start', ]; + + const MATCH_TYPE_DEC = 'dec'; + const MATCH_TYPE_HEX = 'hex'; + + public static $matchTypes = [ + self::MATCH_TYPE_DEC => 'dec', + self::MATCH_TYPE_HEX => 'hex', + ]; + + public function denies(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(AgentDeny::class, 'family_id'); + } + + } diff --git a/app/Models/AgentDeny.php b/app/Models/AgentDeny.php new file mode 100644 index 00000000..2d5ca5b3 --- /dev/null +++ b/app/Models/AgentDeny.php @@ -0,0 +1,17 @@ +belongsTo(AgentAllow::class, 'family_id'); + } +} diff --git a/app/Repositories/AgentAllowRepository.php b/app/Repositories/AgentAllowRepository.php new file mode 100644 index 00000000..3a928261 --- /dev/null +++ b/app/Repositories/AgentAllowRepository.php @@ -0,0 +1,243 @@ +where('family', 'like', "%{$params['family']}%"); + } + list($sortField, $sortType) = $this->getSortFieldAndType($params); + $query->orderBy($sortField, $sortType); + return $query->paginate(); + } + + public function store(array $params) + { + $this->getPatternMatches($params['peer_id_pattern'], $params['peer_id_start'], $params['peer_id_match_num']); + $this->getPatternMatches($params['agent_pattern'], $params['agent_start'], $params['agent_match_num']); + $model = AgentAllow::query()->create($params); + return $model; + } + + public function update(array $params, $id) + { + $this->getPatternMatches($params['peer_id_pattern'], $params['peer_id_start'], $params['peer_id_match_num']); + $this->getPatternMatches($params['agent_pattern'], $params['agent_start'], $params['agent_match_num']); + $model = AgentAllow::query()->findOrFail($id); + $model->update($params); + return $model; + } + + public function getDetail($id) + { + $model = AgentAllow::query()->findOrFail($id); + return $model; + } + + public function delete($id) + { + $model = AgentAllow::query()->findOrFail($id); + $model->denies()->delete(); + $result = $model->delete(); + return $result; + } + + public function getPatternMatches($pattern, $start, $matchNum) + { + if (!preg_match($pattern, $start, $matches)) { + throw new NexusException(sprintf('pattern: %s can not match start: %s', $pattern, $start)); + } + $matchCount = count($matches) - 1; + if ($matchNum > $matchCount) { + throw new NexusException("pattern: $pattern match start: $start got matches count: $matchCount, but require $matchNum."); + } + return array_slice($matches, 1, $matchNum); + } + + public function checkClient($peerId, $agent, $debug = false) + { + //check from high version to low version, if high version allow, stop! + $allows = AgentAllow::query() + ->orderBy('peer_id_start', 'desc') + ->orderBy('agent_start', 'desc') + ->get(); + $agentAllowPassed = null; + $versionTooLowStr = ''; + foreach ($allows as $agentAllow) { + $agentAllowId = $agentAllow->id; + $isPeerIdAllowed = $isAgentAllowed = $isPeerIdTooLow = $isAgentTooLow = false; + //check peer_id + if ($agentAllow->peer_id_pattern == '') { + $isPeerIdAllowed = true; + } else { + $pattern = $agentAllow->peer_id_pattern; + $start = $agentAllow->peer_id_start; + $matchType = $agentAllow->peer_id_matchtype; + $matchNum = $agentAllow->peer_id_match_num; + try { + $peerIdResult = $this->isAllowed($pattern, $start, $matchNum, $matchType, $peerId, $debug); + if ($debug) { + do_log( + "agentAllowId: $agentAllowId, peerIdResult: $peerIdResult, with parameters: " + . nexus_json_encode(compact('pattern', 'start', 'matchNum', 'matchType', 'peerId')) + ); + } + } catch (\Exception $exception) { + do_log("agent allow: {$agentAllow->id} check peer_id error: " . $exception->getMessage(), 'error'); + throw new NexusException("regular expression err for peer_id: " . $start . ", please ask sysop to fix this"); + } + if ($peerIdResult == 1) { + $isPeerIdAllowed = true; + } + if ($peerIdResult == 2) { + $isPeerIdTooLow = true; + } + } + + //check agent + if ($agentAllow->agent_pattern == '') { + $isAgentAllowed = true; + } else { + $pattern = $agentAllow->agent_pattern; + $start = $agentAllow->agent_start; + $matchType = $agentAllow->agent_matchtype; + $matchNum = $agentAllow->agent_match_num; + try { + $agentResult = $this->isAllowed($pattern, $start, $matchNum, $matchType, $agent, $debug); + if ($debug) { + do_log( + "agentAllowId: $agentAllowId, agentResult: $agentResult, with parameters: " + . nexus_json_encode(compact('pattern', 'start', 'matchNum', 'matchType', 'agent')) + ); + } + } catch (\Exception $exception) { + do_log("agent allow: {$agentAllow->id} check agent error: " . $exception->getMessage(), 'error'); + throw new NexusException("regular expression err for agent: " . $start . ", please ask sysop to fix this"); + } + if ($agentResult == 1) { + $isAgentAllowed = true; + } + if ($agentResult == 2) { + $isAgentTooLow = true; + } + } + + //both OK, passed, client is allowed + if ($isPeerIdAllowed && $isAgentAllowed) { + $agentAllowPassed = $agentAllow; + break; + } + if ($isPeerIdTooLow && $isAgentTooLow) { + $versionTooLowStr = "Your " . $agentAllow->family . " 's version is too low, please update it after " . $agentAllow->start_name; + } + } + + if ($versionTooLowStr) { + throw new NexusException($versionTooLowStr); + } + + if (!$agentAllowPassed) { + throw new NexusException("Banned Client, Please goto " . getSchemeAndHttpHost() . "/faq.php#id29 for a list of acceptable clients"); + } + + if ($debug) { + do_log("agentAllowPassed: " . $agentAllowPassed->toJson()); + } + + // check if exclude + if ($agentAllowPassed->exception == 'yes') { + $agentDeny = $this->checkIsDenied($peerId, $agent, $agentAllowPassed->id); + if ($agentDeny) { + if ($debug) { + do_log("agentDeny: " . $agentDeny->toJson()); + } + throw new NexusException(sprintf( + "[%s-%s]Client: %s is banned due to: %s", + $agentAllowPassed->id, $agentDeny->id, $agentDeny->name, $agentDeny->comment + )); + } + } + if (isHttps() && $agentAllowPassed->allowhttps != 'yes') { + throw new NexusException(sprintf( + "[%s]This client does not support https well, Please goto %s/faq.php#id29 for a list of proper clients", + $agentAllowPassed->id, getSchemeAndHttpHost() + )); + } + + return $agentAllowPassed; + + } + + private function checkIsDenied($peerId, $agent, $familyId) + { + $agentDenies = AgentDeny::query()->where('family_id', $familyId)->get(); + foreach ($agentDenies as $agentDeny) { + if ($agentDeny->agent == $agent && preg_match("/^" . $agentDeny->peer_id . "/", $peerId)) { + return $agentDeny; + } + } + } + + /** + * check peer_id or agent is allowed + * + * 0: not allowed + * 1: allowed + * 2: version too low + * + * @param $pattern + * @param $start + * @param $matchNum + * @param $matchType + * @param $value + * @param bool $debug + * @return int + * @throws NexusException + */ + private function isAllowed($pattern, $start, $matchNum, $matchType, $value, $debug = false): int + { + $matchBench = $this->getPatternMatches($pattern, $start, $matchNum); + if ($debug) { + do_log("matchBench: " . nexus_json_encode($matchBench)); + } + if (!preg_match($pattern, $value, $matchTarget)) { + return 0; + } + if ($matchNum <= 0) { + return 1; + } + $matchTarget = array_slice($matchTarget, 1); + if ($debug) { + do_log("matchTarget: " . nexus_json_encode($matchTarget)); + } + for ($i = 0; $i < $matchNum; $i++) { + if (!isset($matchBench[$i]) || !isset($matchTarget[$i])) { + break; + } + if ($matchType == 'dec') { + $matchBench[$i] = intval($matchBench[$i]); + $matchTarget[$i] = intval($matchTarget[$i]); + } elseif ($matchType == 'hex') { + $matchBench[$i] = hexdec($matchBench[$i]); + $matchTarget[$i] = hexdec($matchTarget[$i]); + } else { + throw new NexusException(sprintf("Invalid match type: %s", $matchType)); + } + if ($matchTarget[$i] > $matchBench[$i]) { + return 1; + } elseif ($matchTarget[$i] < $matchBench[$i]) { + return 2; + } + } + return 0; + + } + +} diff --git a/app/Repositories/AgentDenyRepository.php b/app/Repositories/AgentDenyRepository.php new file mode 100644 index 00000000..4e574d18 --- /dev/null +++ b/app/Repositories/AgentDenyRepository.php @@ -0,0 +1,43 @@ +with(['family']); + if (!empty($params['family_id'])) { + $query->where('family_id', $params['family_id']); + } + $query->orderBy('family_id', 'desc'); + return $query->paginate(); + } + + public function store(array $params) + { + $model = AgentDeny::query()->create($params); + return $model; + } + + public function update(array $params, $id) + { + $model = AgentDeny::query()->findOrFail($id); + $model->update($params); + return $model; + } + + public function getDetail($id) + { + $model = AgentDeny::query()->findOrFail($id); + return $model; + } + + public function delete($id) + { + $model = AgentDeny::query()->findOrFail($id); + $result = $model->delete(); + return $result; + } +} diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 3a56010b..04664276 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -16,6 +16,15 @@ class UserRepository extends BaseRepository public function getList(array $params) { $query = User::query(); + if (!empty($params['id'])) { + $query->where('id', $params['id']); + } + if (!empty($params['username'])) { + $query->where('username', 'like',"%{$params['username']}%"); + } + if (!empty($params['email'])) { + $query->where('email', 'like',"%{$params['email']}%"); + } list($sortField, $sortType) = $this->getSortFieldAndType($params); $query->orderBy($sortField, $sortType); return $query->paginate(); diff --git a/database/migrations/2022_02_25_021356_add_id_to_agent_allowed_exception_table.php b/database/migrations/2022_02_25_021356_add_id_to_agent_allowed_exception_table.php new file mode 100644 index 00000000..b11aba3a --- /dev/null +++ b/database/migrations/2022_02_25_021356_add_id_to_agent_allowed_exception_table.php @@ -0,0 +1,32 @@ +increments('id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('agent_allowed_exception', function (Blueprint $table) { + $table->dropColumn('id'); + }); + } +} diff --git a/include/globalfunctions.php b/include/globalfunctions.php index c51e463e..71cb21f8 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -511,6 +511,7 @@ function api(...$args) 'msg' => (string)$msg, 'data' => $data, 'time' => (float)number_format(microtime(true) - $start, 3), + 'request_id' => REQUEST_ID, ]; } diff --git a/routes/api.php b/routes/api.php index a0fe149d..55050f7e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -36,6 +36,9 @@ Route::group(['middleware' => ['auth:sanctum', 'locale']], function () { Route::group(['middleware' => ['admin']], function () { Route::resource('agent-allows', \App\Http\Controllers\AgentAllowController::class); + Route::get('all-agent-allows', [\App\Http\Controllers\AgentAllowController::class, 'all']); + Route::post('agent-check', [\App\Http\Controllers\AgentAllowController::class, 'check']); + Route::resource('agent-denies', \App\Http\Controllers\AgentDenyController::class); Route::resource('users', \App\Http\Controllers\UserController::class); Route::get('user-base', [\App\Http\Controllers\UserController::class, 'base']);