mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-24 20:17:32 +08:00
feat: add v2node support
This commit is contained in:
@@ -95,6 +95,8 @@ class UniProxyController extends Controller
|
|||||||
$host = $node->host;
|
$host = $node->host;
|
||||||
|
|
||||||
$baseConfig = [
|
$baseConfig = [
|
||||||
|
'protocol' => $nodeType,
|
||||||
|
'listen_ip' => '0.0.0.0',
|
||||||
'server_port' => (int) $serverPort,
|
'server_port' => (int) $serverPort,
|
||||||
'network' => data_get($protocolSettings, 'network'),
|
'network' => data_get($protocolSettings, 'network'),
|
||||||
'networkSettings' => data_get($protocolSettings, 'network_settings') ?: null,
|
'networkSettings' => data_get($protocolSettings, 'network_settings') ?: null,
|
||||||
@@ -132,6 +134,7 @@ class UniProxyController extends Controller
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
'hysteria' => [
|
'hysteria' => [
|
||||||
|
...$baseConfig,
|
||||||
'server_port' => (int) $serverPort,
|
'server_port' => (int) $serverPort,
|
||||||
'version' => (int) $protocolSettings['version'],
|
'version' => (int) $protocolSettings['version'],
|
||||||
'host' => $host,
|
'host' => $host,
|
||||||
@@ -148,6 +151,7 @@ class UniProxyController extends Controller
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
'tuic' => [
|
'tuic' => [
|
||||||
|
...$baseConfig,
|
||||||
'version' => (int) $protocolSettings['version'],
|
'version' => (int) $protocolSettings['version'],
|
||||||
'server_port' => (int) $serverPort,
|
'server_port' => (int) $serverPort,
|
||||||
'server_name' => $protocolSettings['tls']['server_name'],
|
'server_name' => $protocolSettings['tls']['server_name'],
|
||||||
@@ -157,24 +161,29 @@ class UniProxyController extends Controller
|
|||||||
'heartbeat' => "3s",
|
'heartbeat' => "3s",
|
||||||
],
|
],
|
||||||
'anytls' => [
|
'anytls' => [
|
||||||
|
...$baseConfig,
|
||||||
'server_port' => (int) $serverPort,
|
'server_port' => (int) $serverPort,
|
||||||
'server_name' => $protocolSettings['tls']['server_name'],
|
'server_name' => $protocolSettings['tls']['server_name'],
|
||||||
'padding_scheme' => $protocolSettings['padding_scheme'],
|
'padding_scheme' => $protocolSettings['padding_scheme'],
|
||||||
],
|
],
|
||||||
'socks' => [
|
'socks' => [
|
||||||
|
...$baseConfig,
|
||||||
'server_port' => (int) $serverPort,
|
'server_port' => (int) $serverPort,
|
||||||
],
|
],
|
||||||
'naive' => [
|
'naive' => [
|
||||||
|
...$baseConfig,
|
||||||
'server_port' => (int) $serverPort,
|
'server_port' => (int) $serverPort,
|
||||||
'tls' => (int) $protocolSettings['tls'],
|
'tls' => (int) $protocolSettings['tls'],
|
||||||
'tls_settings' => $protocolSettings['tls_settings']
|
'tls_settings' => $protocolSettings['tls_settings']
|
||||||
],
|
],
|
||||||
'http' => [
|
'http' => [
|
||||||
|
...$baseConfig,
|
||||||
'server_port' => (int) $serverPort,
|
'server_port' => (int) $serverPort,
|
||||||
'tls' => (int) $protocolSettings['tls'],
|
'tls' => (int) $protocolSettings['tls'],
|
||||||
'tls_settings' => $protocolSettings['tls_settings']
|
'tls_settings' => $protocolSettings['tls_settings']
|
||||||
],
|
],
|
||||||
'mieru' => [
|
'mieru' => [
|
||||||
|
...$baseConfig,
|
||||||
'server_port' => (string) $serverPort,
|
'server_port' => (string) $serverPort,
|
||||||
'protocol' => (int) $protocolSettings['protocol'],
|
'protocol' => (int) $protocolSettings['protocol'],
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ class Server
|
|||||||
public function handle(Request $request, Closure $next, ?string $nodeType = null)
|
public function handle(Request $request, Closure $next, ?string $nodeType = null)
|
||||||
{
|
{
|
||||||
$this->validateRequest($request);
|
$this->validateRequest($request);
|
||||||
|
$nodeType = $request->input('node_type', $nodeType);
|
||||||
|
$normalizedNodeType = ServerModel::normalizeType($nodeType);
|
||||||
$serverInfo = ServerService::getServer(
|
$serverInfo = ServerService::getServer(
|
||||||
$request->input('node_id'),
|
$request->input('node_id'),
|
||||||
$request->input('node_type') ?? $nodeType
|
$normalizedNodeType
|
||||||
);
|
);
|
||||||
if (!$serverInfo) {
|
if (!$serverInfo) {
|
||||||
throw new ApiException('Server does not exist');
|
throw new ApiException('Server does not exist');
|
||||||
@@ -43,6 +44,9 @@ class Server
|
|||||||
'node_type' => [
|
'node_type' => [
|
||||||
'nullable',
|
'nullable',
|
||||||
function ($attribute, $value, $fail) use ($request) {
|
function ($attribute, $value, $fail) use ($request) {
|
||||||
|
if ($value === "v2node") {
|
||||||
|
$value = null;
|
||||||
|
}
|
||||||
if (!ServerModel::isValidType($value)) {
|
if (!ServerModel::isValidType($value)) {
|
||||||
$fail("Invalid node type specified");
|
$fail("Invalid node type specified");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -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}";
|
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
|
public function getAvailableStatusAttribute(): int
|
||||||
|
|||||||
@@ -98,10 +98,12 @@ class ServerService
|
|||||||
* @param string $serverType
|
* @param string $serverType
|
||||||
* @return Server|null
|
* @return Server|null
|
||||||
*/
|
*/
|
||||||
public static function getServer($serverId, $serverType)
|
public static function getServer($serverId, ?string $serverType)
|
||||||
{
|
{
|
||||||
return Server::query()
|
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) {
|
->where(function ($query) use ($serverId) {
|
||||||
$query->where('code', $serverId)
|
$query->where('code', $serverId)
|
||||||
->orWhere('id', $serverId);
|
->orWhere('id', $serverId);
|
||||||
|
|||||||
Reference in New Issue
Block a user