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']);