mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-24 12:07:28 +08:00
feat: Add TUIC protocol support and fix user filtering/export issues
This commit is contained in:
@@ -48,7 +48,7 @@ class ClashMeta implements ProtocolInterface
|
||||
$config = Yaml::parse($template);
|
||||
$proxy = [];
|
||||
$proxies = [];
|
||||
|
||||
|
||||
foreach ($servers as $item) {
|
||||
$protocol_settings = $item['protocol_settings'];
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
@@ -74,6 +74,10 @@ class ClashMeta implements ProtocolInterface
|
||||
array_push($proxy, self::buildHysteria($user['uuid'], $item, $user));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'tuic') {
|
||||
array_push($proxy, self::buildTuic($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
}
|
||||
|
||||
$config['proxies'] = array_merge($config['proxies'] ? $config['proxies'] : [], $proxy);
|
||||
@@ -332,6 +336,39 @@ class ClashMeta implements ProtocolInterface
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function buildTuic($password, $server)
|
||||
{
|
||||
$protocol_settings = data_get($server, 'protocol_settings', []);
|
||||
$array = [
|
||||
'name' => $server['name'],
|
||||
'type' => 'tuic',
|
||||
'server' => $server['host'],
|
||||
'port' => $server['port'],
|
||||
'udp' => true,
|
||||
];
|
||||
|
||||
if (data_get($protocol_settings, 'version') === 4) {
|
||||
$array['token'] = $password;
|
||||
} else {
|
||||
$array['uuid'] = $password;
|
||||
$array['password'] = $password;
|
||||
}
|
||||
|
||||
$array['skip-cert-verify'] = (bool) data_get($protocol_settings, 'tls.allow_insecure', false);
|
||||
if ($serverName = data_get($protocol_settings, 'tls.server_name')) {
|
||||
$array['sni'] = $serverName;
|
||||
}
|
||||
|
||||
if ($alpn = data_get($protocol_settings, 'alpn')) {
|
||||
$array['alpn'] = $alpn;
|
||||
}
|
||||
|
||||
$array['congestion-controller'] = data_get($protocol_settings, 'congestion_control', 'cubic');
|
||||
$array['udp-relay-mode'] = data_get($protocol_settings, 'udp_relay_mode', 'native');
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
private function isMatch($exp, $str)
|
||||
{
|
||||
return @preg_match($exp, $str);
|
||||
|
||||
@@ -80,6 +80,10 @@ class SingBox implements ProtocolInterface
|
||||
$hysteriaConfig = $this->buildHysteria($this->user['uuid'], $item);
|
||||
$proxies[] = $hysteriaConfig;
|
||||
}
|
||||
if ($item['type'] === 'tuic') {
|
||||
$tuicConfig = $this->buildTuic($this->user['uuid'], $item);
|
||||
$proxies[] = $tuicConfig;
|
||||
}
|
||||
}
|
||||
foreach ($outbounds as &$outbound) {
|
||||
if (in_array($outbound['type'], ['urltest', 'selector'])) {
|
||||
@@ -324,4 +328,37 @@ class SingBox implements ProtocolInterface
|
||||
$versionConfig
|
||||
);
|
||||
}
|
||||
|
||||
protected function buildTuic($password, $server): array
|
||||
{
|
||||
$protocol_settings = data_get($server, 'protocol_settings', []);
|
||||
$array = [
|
||||
'type' => 'tuic',
|
||||
'tag' => $server['name'],
|
||||
'server' => $server['host'],
|
||||
'server_port' => $server['port'],
|
||||
'congestion_control' => data_get($protocol_settings, 'congestion_control', 'cubic'),
|
||||
'udp_relay_mode' => data_get($protocol_settings, 'udp_relay_mode', 'native'),
|
||||
'zero_rtt_handshake' => true,
|
||||
'heartbeat' => '10s',
|
||||
'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;
|
||||
}
|
||||
|
||||
if (data_get($protocol_settings, 'version') === 4) {
|
||||
$array['token'] = $password;
|
||||
} else {
|
||||
$array['uuid'] = $password;
|
||||
$array['password'] = $password;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user