mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-14 02:50:52 +08:00
feat: add v2node support
This commit is contained in:
@@ -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'],
|
||||
],
|
||||
|
||||
@@ -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;
|
||||
|
||||
26
app/Http/Routes/V2/ServerRoute.php
Normal file
26
app/Http/Routes/V2/ServerRoute.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace App\Http\Routes\V2;
|
||||
|
||||
use App\Http\Controllers\V1\Server\ShadowsocksTidalabController;
|
||||
use App\Http\Controllers\V1\Server\TrojanTidalabController;
|
||||
use App\Http\Controllers\V1\Server\UniProxyController;
|
||||
use Illuminate\Contracts\Routing\Registrar;
|
||||
|
||||
class ServerRoute
|
||||
{
|
||||
public function map(Registrar $router)
|
||||
{
|
||||
|
||||
$router->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']);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user