Fixed trojan and polished Vmess/VLESS for General.php and Clash/Meta.php

This commit is contained in:
NekoCareLab 2025-01-16 15:26:19 +08:00
parent e0e76a22ea
commit bc16656371
No known key found for this signature in database
3 changed files with 52 additions and 41 deletions

View File

@ -170,16 +170,17 @@ class Clash implements ProtocolInterface
break; break;
case 'ws': case 'ws':
$array['network'] = 'ws'; $array['network'] = 'ws';
$array['ws-opts']['path'] = data_get($protocol_settings, 'network_settings.path', '/'); if ($path = data_get($protocol_settings, 'network_settings.path'))
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) { $array['ws-opts']['path'] = $path;
if ($host = data_get($protocol_settings, 'network_settings.headers.Host'))
$array['ws-opts']['headers'] = ['Host' => $host]; $array['ws-opts']['headers'] = ['Host' => $host];
}
break; break;
case 'grpc': case 'grpc':
$array['network'] = 'grpc'; $array['network'] = 'grpc';
$array['grpc-opts'] = [ if ($serviceName = data_get($protocol_settings, 'network_settings.serviceName'))
'grpc-service-name' => data_get($protocol_settings, 'network_settings.serviceName') $array['grpc-opts']['grpc-service-name'] = $serviceName;
]; break;
default:
break; break;
} }
return $array; return $array;
@ -206,16 +207,15 @@ class Clash implements ProtocolInterface
break; break;
case 'ws': case 'ws':
$array['network'] = 'ws'; $array['network'] = 'ws';
$array['ws-opts']['path'] = data_get($protocol_settings, 'network_settings.path', '/'); if ($path = data_get($protocol_settings, 'network_settings.path'))
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) { $array['ws-opts']['path'] = $path;
if ($host = data_get($protocol_settings, 'network_settings.headers.Host'))
$array['ws-opts']['headers'] = ['Host' => $host]; $array['ws-opts']['headers'] = ['Host' => $host];
}
break; break;
case 'grpc': case 'grpc':
$array['network'] = 'grpc'; $array['network'] = 'grpc';
$array['grpc-opts'] = [ if ($serviceName = data_get($protocol_settings, 'network_settings.serviceName'))
'grpc-service-name' => data_get($protocol_settings, 'network_settings.serviceName') $array['grpc-opts']['grpc-service-name'] = $serviceName;
];
break; break;
default: default:
$array['network'] = 'tcp'; $array['network'] = 'tcp';
@ -234,6 +234,6 @@ class Clash implements ProtocolInterface
if (empty($exp)) { if (empty($exp)) {
return false; return false;
} }
return @preg_match((string)$exp, '') !== false; return @preg_match((string) $exp, '') !== false;
} }
} }

View File

@ -167,16 +167,15 @@ class ClashMeta implements ProtocolInterface
break; break;
case 'ws': case 'ws':
$array['network'] = 'ws'; $array['network'] = 'ws';
$array['ws-opts'] = [ if ($path = data_get($protocol_settings, 'network_settings.path'))
'path' => data_get($protocol_settings, 'network_settings.path'), $array['ws-opts']['path'] = $path;
'headers' => ['Host' => data_get($protocol_settings, 'network_settings.headers.Host', $server['host'])] if ($host = data_get($protocol_settings, 'network_settings.headers.Host'))
]; $array['ws-opts']['headers'] = ['Host' => $host];
break; break;
case 'grpc': case 'grpc':
$array['network'] = 'grpc'; $array['network'] = 'grpc';
$array['grpc-opts'] = [ if ($serviceName = data_get($protocol_settings, 'network_settings.serviceName'))
'grpc-service-name' => data_get($protocol_settings, 'network_settings.serviceName') $array['grpc-opts']['grpc-service-name'] = $serviceName;
];
break; break;
default: default:
break; break;
@ -226,23 +225,15 @@ class ClashMeta implements ProtocolInterface
switch (data_get($protocol_settings, 'network')) { switch (data_get($protocol_settings, 'network')) {
case 'ws': case 'ws':
$array['network'] = 'ws'; $array['network'] = 'ws';
$array['ws-opts']['path'] = data_get($protocol_settings, 'network_settings.path', '/'); if ($path = data_get($protocol_settings, 'network_settings.path'))
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) { $array['ws-opts']['path'] = $path;
if ($host = data_get($protocol_settings, 'network_settings.headers.Host'))
$array['ws-opts']['headers'] = ['Host' => $host]; $array['ws-opts']['headers'] = ['Host' => $host];
}
break; break;
case 'grpc': case 'grpc':
$array['network'] = 'grpc'; $array['network'] = 'grpc';
$array['grpc-opts'] = [ if ($serviceName = data_get($protocol_settings, 'network_settings.serviceName'))
'grpc-service-name' => data_get($protocol_settings, 'network_settings.serviceName') $array['grpc-opts']['grpc-service-name'] = $serviceName;
];
break;
case 'h2':
$array['network'] = 'h2';
$array['h2-opts'] = [
'path' => data_get($protocol_settings, 'network_settings.path', '/'),
'host' => data_get($protocol_settings, 'network_settings.host')
];
break; break;
default: default:
break; break;
@ -268,20 +259,23 @@ class ClashMeta implements ProtocolInterface
} }
switch (data_get($protocol_settings, 'network')) { switch (data_get($protocol_settings, 'network')) {
case 'grpc': case 'tcp':
$array['network'] = 'grpc'; $array['network'] = 'tcp';
$array['grpc-opts'] = [
'grpc-service-name' => data_get($protocol_settings, 'network_settings.serviceName')
];
break; break;
case 'ws': case 'ws':
$array['network'] = 'ws'; $array['network'] = 'ws';
$array['ws-opts']['path'] = data_get($protocol_settings, 'network_settings.path', '/'); if ($path = data_get($protocol_settings, 'network_settings.path'))
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) { $array['ws-opts']['path'] = $path;
if ($host = data_get($protocol_settings, 'network_settings.headers.Host'))
$array['ws-opts']['headers'] = ['Host' => $host]; $array['ws-opts']['headers'] = ['Host' => $host];
} break;
case 'grpc':
$array['network'] = 'grpc';
if ($serviceName = data_get($protocol_settings, 'network_settings.serviceName'))
$array['grpc-opts']['grpc-service-name'] = $serviceName;
break; break;
default: default:
$array['network'] = 'tcp';
break; break;
} }

View File

@ -189,6 +189,23 @@ class General implements ProtocolInterface
$array['peer'] = $serverName; $array['peer'] = $serverName;
$array['sni'] = $serverName; $array['sni'] = $serverName;
} }
switch ($server['protocol_settings']['network']) {
case 'ws':
$array['type'] = 'ws';
if ($path = data_get($protocol_settings, 'network_settings.path'))
$array['path'] = $path;
if ($host = data_get($protocol_settings, 'network_settings.headers.Host'))
$array['host'] = $host;
break;
case 'grpc':
// Follow V2rayN family standards
$array['type'] = 'grpc';
if ($serviceName = data_get($protocol_settings, 'network_settings.serviceName'))
$array['serviceName'] = $serviceName;
break;
default:
break;
}
$query = http_build_query($array); $query = http_build_query($array);
$uri = "trojan://{$password}@{$server['host']}:{$server['port']}?{$query}#{$name}"; $uri = "trojan://{$password}@{$server['host']}:{$server['port']}?{$query}#{$name}";
$uri .= "\r\n"; $uri .= "\r\n";