Merge pull request #323 from NekoCareLab/master

Fixed trojan and polished Vmess/VLESS for General.php and Clash/Meta.php
This commit is contained in:
Xboard 2025-01-16 18:48:15 +08:00 committed by GitHub
commit d7b88d7b5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 68 additions and 53 deletions

View File

@ -170,16 +170,17 @@ class Clash implements ProtocolInterface
break;
case 'ws':
$array['network'] = 'ws';
$array['ws-opts']['path'] = data_get($protocol_settings, 'network_settings.path', '/');
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
if ($path = data_get($protocol_settings, 'network_settings.path'))
$array['ws-opts']['path'] = $path;
if ($host = data_get($protocol_settings, 'network_settings.headers.Host'))
$array['ws-opts']['headers'] = ['Host' => $host];
}
break;
case 'grpc':
$array['network'] = 'grpc';
$array['grpc-opts'] = [
'grpc-service-name' => data_get($protocol_settings, 'network_settings.serviceName')
];
if ($serviceName = data_get($protocol_settings, 'network_settings.serviceName'))
$array['grpc-opts']['grpc-service-name'] = $serviceName;
break;
default:
break;
}
return $array;
@ -206,16 +207,15 @@ class Clash implements ProtocolInterface
break;
case 'ws':
$array['network'] = 'ws';
$array['ws-opts']['path'] = data_get($protocol_settings, 'network_settings.path', '/');
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
if ($path = data_get($protocol_settings, 'network_settings.path'))
$array['ws-opts']['path'] = $path;
if ($host = data_get($protocol_settings, 'network_settings.headers.Host'))
$array['ws-opts']['headers'] = ['Host' => $host];
}
break;
case 'grpc':
$array['network'] = 'grpc';
$array['grpc-opts'] = [
'grpc-service-name' => data_get($protocol_settings, 'network_settings.serviceName')
];
if ($serviceName = data_get($protocol_settings, 'network_settings.serviceName'))
$array['grpc-opts']['grpc-service-name'] = $serviceName;
break;
default:
$array['network'] = 'tcp';
@ -234,6 +234,6 @@ class Clash implements ProtocolInterface
if (empty($exp)) {
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;
case 'ws':
$array['network'] = 'ws';
$array['ws-opts'] = [
'path' => data_get($protocol_settings, 'network_settings.path'),
'headers' => ['Host' => data_get($protocol_settings, 'network_settings.headers.Host', $server['host'])]
];
if ($path = data_get($protocol_settings, 'network_settings.path'))
$array['ws-opts']['path'] = $path;
if ($host = data_get($protocol_settings, 'network_settings.headers.Host'))
$array['ws-opts']['headers'] = ['Host' => $host];
break;
case 'grpc':
$array['network'] = 'grpc';
$array['grpc-opts'] = [
'grpc-service-name' => data_get($protocol_settings, 'network_settings.serviceName')
];
if ($serviceName = data_get($protocol_settings, 'network_settings.serviceName'))
$array['grpc-opts']['grpc-service-name'] = $serviceName;
break;
default:
break;
@ -226,23 +225,15 @@ class ClashMeta implements ProtocolInterface
switch (data_get($protocol_settings, 'network')) {
case 'ws':
$array['network'] = 'ws';
$array['ws-opts']['path'] = data_get($protocol_settings, 'network_settings.path', '/');
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
if ($path = data_get($protocol_settings, 'network_settings.path'))
$array['ws-opts']['path'] = $path;
if ($host = data_get($protocol_settings, 'network_settings.headers.Host'))
$array['ws-opts']['headers'] = ['Host' => $host];
}
break;
case 'grpc':
$array['network'] = 'grpc';
$array['grpc-opts'] = [
'grpc-service-name' => data_get($protocol_settings, 'network_settings.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')
];
if ($serviceName = data_get($protocol_settings, 'network_settings.serviceName'))
$array['grpc-opts']['grpc-service-name'] = $serviceName;
break;
default:
break;
@ -268,20 +259,23 @@ class ClashMeta implements ProtocolInterface
}
switch (data_get($protocol_settings, 'network')) {
case 'grpc':
$array['network'] = 'grpc';
$array['grpc-opts'] = [
'grpc-service-name' => data_get($protocol_settings, 'network_settings.serviceName')
];
case 'tcp':
$array['network'] = 'tcp';
break;
case 'ws':
$array['network'] = 'ws';
$array['ws-opts']['path'] = data_get($protocol_settings, 'network_settings.path', '/');
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
if ($path = data_get($protocol_settings, 'network_settings.path'))
$array['ws-opts']['path'] = $path;
if ($host = data_get($protocol_settings, 'network_settings.headers.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;
default:
$array['network'] = 'tcp';
break;
}

View File

@ -92,14 +92,15 @@ class General implements ProtocolInterface
break;
case 'ws':
$config['type'] = 'ws';
$config['path'] = data_get($protocol_settings, 'network_settings.path');
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
if ($path = data_get($protocol_settings, 'network_settings.path'))
$config['path'] = $path;
if ($host = data_get($protocol_settings, 'network_settings.headers.Host'))
$config['host'] = $host;
}
break;
case 'grpc':
$config['type'] = 'grpc';
$config['path'] = data_get($protocol_settings, 'network_settings.serviceName');
if ($path = data_get($protocol_settings, 'network_settings.serviceName'))
$config['path'] = $path;
break;
default:
break;
@ -144,20 +145,23 @@ class General implements ProtocolInterface
// 处理传输协议
switch ($server['protocol_settings']['network']) {
case 'ws':
$config['path'] = data_get($protocol_settings, 'network_settings.path');
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
if ($path = data_get($protocol_settings, 'network_settings.path'))
$config['path'] = $path;
if ($host = data_get($protocol_settings, 'network_settings.headers.Host'))
$config['host'] = $host;
}
break;
case 'grpc':
$config['serviceName'] = data_get($protocol_settings, 'network_settings.serviceName');
if ($path = data_get($protocol_settings, 'network_settings.serviceName'))
$config['path'] = $path;
break;
case 'kcp':
$config['path'] = data_get($protocol_settings, 'network_settings.seed');
if ($path = data_get($protocol_settings, 'network_settings.seed'))
$config['path'] = $path;
$config['type'] = data_get($protocol_settings, 'network_settings.header.type', 'none');
break;
case 'httpupgrade':
$config['path'] = data_get($protocol_settings, 'network_settings.path');
if ($path = data_get($protocol_settings, 'network_settings.path'))
$config['path'] = $path;
$config['host'] = data_get($protocol_settings, 'network_settings.host', $server['host']);
break;
case 'xhttp':
@ -179,12 +183,29 @@ class General implements ProtocolInterface
{
$protocol_settings = $server['protocol_settings'];
$name = rawurlencode($server['name']);
$array = [];
$array = [];
$array['allowInsecure'] = $protocol_settings['allow_insecure'];
if ($serverName = data_get($protocol_settings, 'server_name')) {
$array['peer'] = $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);
$uri = "trojan://{$password}@{$server['host']}:{$server['port']}?{$query}#{$name}";
$uri .= "\r\n";
@ -209,7 +230,7 @@ class General implements ProtocolInterface
$params['obfs'] = 'salamander';
$params['obfs-password'] = data_get($protocol_settings, 'obfs.password');
}
if(isset($server['ports'])){
if (isset($server['ports'])) {
$params['mport'] = $server['ports'];
}