diff --git a/app/Http/Controllers/V1/Server/UniProxyController.php b/app/Http/Controllers/V1/Server/UniProxyController.php index 01a45d2..b31489d 100644 --- a/app/Http/Controllers/V1/Server/UniProxyController.php +++ b/app/Http/Controllers/V1/Server/UniProxyController.php @@ -95,6 +95,8 @@ class UniProxyController extends Controller $host = $node->host; $baseConfig = [ + 'protocol' => $nodeType, + 'listen_ip' => '0.0.0.0', 'server_port' => (int) $serverPort, 'network' => data_get($protocolSettings, 'network'), 'networkSettings' => data_get($protocolSettings, 'network_settings') ?: null, @@ -132,6 +134,7 @@ class UniProxyController extends Controller } ], 'hysteria' => [ + ...$baseConfig, 'server_port' => (int) $serverPort, 'version' => (int) $protocolSettings['version'], 'host' => $host, @@ -148,6 +151,7 @@ class UniProxyController extends Controller } ], 'tuic' => [ + ...$baseConfig, 'version' => (int) $protocolSettings['version'], 'server_port' => (int) $serverPort, 'server_name' => $protocolSettings['tls']['server_name'], @@ -157,24 +161,29 @@ class UniProxyController extends Controller 'heartbeat' => "3s", ], 'anytls' => [ + ...$baseConfig, 'server_port' => (int) $serverPort, 'server_name' => $protocolSettings['tls']['server_name'], 'padding_scheme' => $protocolSettings['padding_scheme'], ], 'socks' => [ + ...$baseConfig, 'server_port' => (int) $serverPort, ], 'naive' => [ + ...$baseConfig, 'server_port' => (int) $serverPort, 'tls' => (int) $protocolSettings['tls'], 'tls_settings' => $protocolSettings['tls_settings'] ], 'http' => [ + ...$baseConfig, 'server_port' => (int) $serverPort, 'tls' => (int) $protocolSettings['tls'], 'tls_settings' => $protocolSettings['tls_settings'] ], 'mieru' => [ + ...$baseConfig, 'server_port' => (string) $serverPort, 'protocol' => (int) $protocolSettings['protocol'], ], diff --git a/app/Http/Middleware/Server.php b/app/Http/Middleware/Server.php index 8053411..15dd494 100644 --- a/app/Http/Middleware/Server.php +++ b/app/Http/Middleware/Server.php @@ -14,10 +14,11 @@ class Server public function handle(Request $request, Closure $next, ?string $nodeType = null) { $this->validateRequest($request); - + $nodeType = $request->input('node_type', $nodeType); + $normalizedNodeType = ServerModel::normalizeType($nodeType); $serverInfo = ServerService::getServer( $request->input('node_id'), - $request->input('node_type') ?? $nodeType + $normalizedNodeType ); if (!$serverInfo) { throw new ApiException('Server does not exist'); @@ -43,6 +44,9 @@ class Server 'node_type' => [ 'nullable', function ($attribute, $value, $fail) use ($request) { + if ($value === "v2node") { + $value = null; + } if (!ServerModel::isValidType($value)) { $fail("Invalid node type specified"); return; diff --git a/app/Http/Routes/V2/ServerRoute.php b/app/Http/Routes/V2/ServerRoute.php new file mode 100644 index 0000000..db6c31f --- /dev/null +++ b/app/Http/Routes/V2/ServerRoute.php @@ -0,0 +1,26 @@ +group([ + 'prefix' => 'server', + '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']); + $route->get('alivelist', [UniProxyController::class, 'alivelist']); + $route->post('status', [UniProxyController::class, 'status']); + }); + } +} diff --git a/app/Models/Server.php b/app/Models/Server.php index dcbaf44..5b3b930 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -317,14 +317,14 @@ class Server extends Model return "{$serverKey}:{$userKey}"; } - public static function normalizeType(string $type): string + public static function normalizeType(?string $type): string | null { - return strtolower(self::TYPE_ALIASES[$type] ?? $type); + return $type ? strtolower(self::TYPE_ALIASES[$type] ?? $type) : null; } - - public static function isValidType(string $type): bool + + public static function isValidType(?string $type): bool { - return in_array(self::normalizeType($type), self::VALID_TYPES, true); + return $type ? in_array(self::normalizeType($type), self::VALID_TYPES, true) : true; } public function getAvailableStatusAttribute(): int diff --git a/app/Services/ServerService.php b/app/Services/ServerService.php index 058934c..30a883d 100644 --- a/app/Services/ServerService.php +++ b/app/Services/ServerService.php @@ -98,10 +98,12 @@ class ServerService * @param string $serverType * @return Server|null */ - public static function getServer($serverId, $serverType) + public static function getServer($serverId, ?string $serverType) { return Server::query() - ->where('type', Server::normalizeType($serverType)) + ->when($serverType, function ($query) use ($serverType) { + $query->where('type', Server::normalizeType($serverType)); + }) ->where(function ($query) use ($serverId) { $query->where('code', $serverId) ->orWhere('id', $serverId);