mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-28 14:57:22 +08:00
add anytls support
This commit is contained in:
@@ -80,6 +80,10 @@ class ClashMeta implements ProtocolInterface
|
||||
array_push($proxy, self::buildTuic($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'anytls'){
|
||||
array_push($proxy, self::buildAnyTLS($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'socks') {
|
||||
array_push($proxy, self::buildSocks5($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
@@ -391,6 +395,24 @@ class ClashMeta implements ProtocolInterface
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function buildAnyTLS($password, $server)
|
||||
{
|
||||
|
||||
$protocol_settings = data_get($server, 'protocol_settings', []);
|
||||
$array = [
|
||||
'name' => $server['name'],
|
||||
'type' => 'anytls',
|
||||
'server' => $server['host'],
|
||||
'port' => $server['port'],
|
||||
'password' => $password,
|
||||
'udp' => true,
|
||||
];
|
||||
$array['skip-cert-verify'] = (bool) data_get($protocol_settings, 'tls.allow_insecure', false);
|
||||
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function buildMieru($password, $server)
|
||||
{
|
||||
$protocol_settings = data_get($server, 'protocol_settings', []);
|
||||
|
||||
@@ -51,6 +51,12 @@ class Shadowrocket implements ProtocolInterface
|
||||
if ($item['type'] === 'hysteria') {
|
||||
$uri .= self::buildHysteria($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'tuic') {
|
||||
$uri.= self::buildTuic($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'anytls') {
|
||||
$uri.= self::buildAnyTLS($user['uuid'], $item);
|
||||
}
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
@@ -276,4 +282,38 @@ class Shadowrocket implements ProtocolInterface
|
||||
}
|
||||
return $uri;
|
||||
}
|
||||
public static function buildTuic($password, $server)
|
||||
{
|
||||
$protocol_settings = $server['protocol_settings'];
|
||||
$name = rawurlencode($server['name']);
|
||||
$params = [
|
||||
'alpn' => data_get($protocol_settings, 'alpn'),
|
||||
'sni' => data_get($protocol_settings, 'tls.server_name'),
|
||||
'insecure' => data_get($protocol_settings, 'tls.allow_insecure')
|
||||
];
|
||||
if (data_get($protocol_settings, 'version') === 4) {
|
||||
$params['token'] = $password;
|
||||
}else{
|
||||
$params['uuid'] = $password;
|
||||
$params['password'] = $password;
|
||||
}
|
||||
$query = http_build_query($params);
|
||||
$uri = "tuic://{$server['host']}:{$server['port']}?{$query}#{$name}";
|
||||
$uri.= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public static function buildAnyTLS($password, $server)
|
||||
{
|
||||
$protocol_settings = $server['protocol_settings'];
|
||||
$name = rawurlencode($server['name']);
|
||||
$params = [
|
||||
'sni' => data_get($protocol_settings, 'tls.server_name'),
|
||||
'insecure' => data_get($protocol_settings, 'tls.allow_insecure')
|
||||
];
|
||||
$query = http_build_query($params);
|
||||
$uri = "anytls://{$password}@{$server['host']}:{$server['port']}?{$query}#{$name}";
|
||||
$uri.= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,10 @@ class SingBox implements ProtocolInterface
|
||||
$tuicConfig = $this->buildTuic($this->user['uuid'], $item);
|
||||
$proxies[] = $tuicConfig;
|
||||
}
|
||||
if ($item['type'] === 'anytls') {
|
||||
$anytlsConfig = $this->buildAnyTLS($this->user['uuid'], $item);
|
||||
$proxies[] = $anytlsConfig;
|
||||
}
|
||||
if ($item['type'] === 'socks') {
|
||||
$socksConfig = $this->buildSocks($this->user['uuid'], $item);
|
||||
$proxies[] = $socksConfig;
|
||||
@@ -372,6 +376,29 @@ class SingBox implements ProtocolInterface
|
||||
return $array;
|
||||
}
|
||||
|
||||
protected function buildAnyTLS($password, $server): array
|
||||
{
|
||||
$protocol_settings = data_get($server, 'protocol_settings', []);
|
||||
$array = [
|
||||
'type' => 'anytls',
|
||||
'tag' => $server['name'],
|
||||
'server' => $server['host'],
|
||||
'password' => $password,
|
||||
'server_port' => $server['port'],
|
||||
'tls' => [
|
||||
'enabled' => true,
|
||||
'insecure' => (bool) data_get($protocol_settings, 'tls.allow_insecure', false),
|
||||
'alpn' => data_get($protocol_settings, 'alpn', ['h3']),
|
||||
]
|
||||
];
|
||||
|
||||
if ($serverName = data_get($protocol_settings, 'tls.server_name')) {
|
||||
$array['tls']['server_name'] = $serverName;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
protected function buildSocks($password, $server): array
|
||||
{
|
||||
$protocol_settings = data_get($server, 'protocol_settings', []);
|
||||
|
||||
+22
-1
@@ -76,6 +76,10 @@ class Stash implements ProtocolInterface
|
||||
array_push($proxy, self::buildTuic($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'anytls') {
|
||||
array_push($proxy, self::buildAnyTLS($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'socks') {
|
||||
array_push($proxy, self::buildSocks5($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
@@ -213,7 +217,7 @@ class Stash implements ProtocolInterface
|
||||
break;
|
||||
case 2:
|
||||
$array['tls'] = true;
|
||||
$array['reality-opts']= [
|
||||
$array['reality-opts'] = [
|
||||
'public-key' => data_get($protocol_settings, 'reality_settings.public_key'),
|
||||
'short-id' => data_get($protocol_settings, 'reality_settings.short_id')
|
||||
];
|
||||
@@ -333,6 +337,23 @@ class Stash implements ProtocolInterface
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function buildAnyTLS($password, $server)
|
||||
{
|
||||
$protocol_settings = $server['protocol_settings'];
|
||||
$array = [
|
||||
'name' => $server['name'],
|
||||
'type' => 'anytls',
|
||||
'server' => $server['host'],
|
||||
'port' => $server['port'],
|
||||
'password' => $password,
|
||||
'sni' => data_get($protocol_settings, 'tls_settings.server_name'),
|
||||
'skip-cert-verify' => (bool) data_get($protocol_settings, 'tls_settings.allow_insecure', false),
|
||||
'udp' => true,
|
||||
];
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function buildSocks5($password, $server)
|
||||
{
|
||||
$protocol_settings = $server['protocol_settings'];
|
||||
|
||||
Reference in New Issue
Block a user