From c2b08c2627ae498b63385f5d8036f67193203c01 Mon Sep 17 00:00:00 2001 From: xboard Date: Fri, 12 Apr 2024 17:34:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=90=8E=E5=AF=BC=E8=87=B4=E8=8A=82=E7=82=B9=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E4=BA=A4=E4=BA=92api=E4=B8=8D=E5=8F=AF=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Middleware/Server.php | 5 +++-- app/Http/Routes/V1/ServerRoute.php | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/Http/Middleware/Server.php b/app/Http/Middleware/Server.php index dbb99cc..57d10ab 100644 --- a/app/Http/Middleware/Server.php +++ b/app/Http/Middleware/Server.php @@ -16,7 +16,7 @@ class Server * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse */ - public function handle(Request $request, Closure $next) + public function handle(Request $request, Closure $next, $node_type = null) { // alias $aliasTypes = [ @@ -27,6 +27,7 @@ class Server 'token' => ['required', 'string', 'in:' . admin_setting('server_token')], 'node_id' => 'required', 'node_type' => [ + 'nullable', 'regex:/^(?i)(hysteria|hysteria2|vless|trojan|vmess|v2ray|tuic|shadowsocks|shadowsocks-plugin)$/', function ($attribute, $value, $fail) use ($aliasTypes, $request) { $request->merge([$attribute => strtolower(isset ($aliasTypes[$value]) ? $aliasTypes[$value] : $value)]); @@ -36,7 +37,7 @@ class Server 'token.in' => 'Token is error!', 'node_type.regex' => 'node_type is error!' ]); - $nodeInfo = ServerService::getServer($request->input('node_id'), $request->input('node_type')); + $nodeInfo = ServerService::getServer($request->input('node_id'), $request->input('node_type') ?? $node_type); if (!$nodeInfo) throw new ApiException('server is not exist!'); $request->merge(['node_info' => $nodeInfo]); diff --git a/app/Http/Routes/V1/ServerRoute.php b/app/Http/Routes/V1/ServerRoute.php index 33eb7d3..77070b3 100644 --- a/app/Http/Routes/V1/ServerRoute.php +++ b/app/Http/Routes/V1/ServerRoute.php @@ -13,24 +13,35 @@ class ServerRoute { $router->group([ 'prefix' => 'server', - 'middleware' => 'server' ], function ($router) { - $router->prefix('UniProxy')->group(function ($route) { + $router->group([ + 'prefix' => 'UniProxy', + 'middleware' => 'server' + ] ,function ($route) { $route->get('config', [UniProxyController::class, 'config']); $route->get('user', [UniProxyController::class, 'user']); $route->post('push', [UniProxyController::class, 'push']); $route->post('alive', [UniProxyController::class, 'alive']); }); - $router->prefix('Deepbwork')->group(function ($route) { + $router->group([ + 'prefix' => 'Deepbwork', + 'middleware' => 'server:vmess' + ], function ($route) { $route->get('config', [DeepbworkController::class, 'config']); $route->get('user', [DeepbworkController::class, 'user']); $route->post('submit', [DeepbworkController::class, 'submit']); }); - $router->prefix('ShadowsocksTidalab')->group(function ($route) { + $router->group([ + 'prefix' => 'ShadowsocksTidalab', + 'middleware' => 'server:shadowsocks' + ], function ($route) { $route->get('user', [ShadowsocksTidalabController::class, 'user']); $route->post('submit', [ShadowsocksTidalabController::class, 'submit']); }); - $router->prefix('TrojanTidalab')->group(function ($route) { + $router->group([ + 'prefix' => 'TrojanTidalab', + 'middleware' => 'server:trojan' + ], function ($route) { $route->get('config', [TrojanTidalabController::class, 'config']); $route->get('user', [TrojanTidalabController::class, 'user']); $route->post('submit', [TrojanTidalabController::class, 'submit']);