Merge pull request #345 from wloot/buildvmess

clean up buildvmess()
This commit is contained in:
tokumeikoi 2020-12-05 17:16:41 +08:00 committed by GitHub
commit 1ca9899437
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 78 additions and 75 deletions

View File

@ -29,22 +29,28 @@ class Clash
$array['alterId'] = $server['alter_id']; $array['alterId'] = $server['alter_id'];
$array['cipher'] = 'auto'; $array['cipher'] = 'auto';
$array['udp'] = true; $array['udp'] = true;
if ($server['tls']) { if ($server['tls']) {
$tlsSettings = json_decode($server['tlsSettings'], true);
$array['tls'] = true; $array['tls'] = true;
if (!empty($tlsSettings['allowInsecure'])) $array['skip-cert-verify'] = ($tlsSettings['allowInsecure'] ? true : false ); if ($server['tlsSettings']) {
if (!empty($tlsSettings['serverName'])) $array['servername'] = $tlsSettings['serverName']; $tlsSettings = json_decode($server['tlsSettings'], true);
} if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
if ($server['network'] == 'ws') { $array['skip-cert-verify'] = ($tlsSettings['allowInsecure'] ? true : false);
$array['network'] = $server['network']; if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
if ($server['networkSettings']) { $array['servername'] = $tlsSettings['serverName'];
$wsSettings = json_decode($server['networkSettings'], true);
if (isset($wsSettings['path'])) $array['ws-path'] = $wsSettings['path'];
if (isset($wsSettings['headers']['Host'])) $array['ws-headers'] = [
'Host' => $wsSettings['headers']['Host']
];
} }
} }
if ($server['network'] === 'ws') {
$array['network'] = 'ws';
if ($server['networkSettings']) {
$wsSettings = json_decode($server['networkSettings'], true);
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
$array['ws-path'] = $wsSettings['path'];
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
$array['ws-headers'] = ['Host' => $wsSettings['headers']['Host']];
}
}
return $array; return $array;
} }
@ -58,7 +64,7 @@ class Clash
$array['password'] = $password; $array['password'] = $password;
$array['udp'] = true; $array['udp'] = true;
if (!empty($server['server_name'])) $array['sni'] = $server['server_name']; if (!empty($server['server_name'])) $array['sni'] = $server['server_name'];
if (!empty($server['allow_insecure'])) $array['skip-cert-verify'] = ($server['allow_insecure'] ? true : false ); if (!empty($server['allow_insecure'])) $array['skip-cert-verify'] = ($server['allow_insecure'] ? true : false);
return $array; return $array;
} }
} }

View File

@ -31,34 +31,33 @@ class QuantumultX
'udp-relay=true', 'udp-relay=true',
"tag={$server['name']}" "tag={$server['name']}"
]; ];
if ($server['network'] === 'tcp') {
if ($server['tls']) { if ($server['tls']) {
$tlsSettings = json_decode($server['tlsSettings'], true); if ($server['network'] === 'tcp') {
array_push($config, 'obfs=over-tls'); array_push($config, 'obfs=over-tls');
if (isset($tlsSettings['allowInsecure'])) { } else {
// Tips: allowInsecure=false = tls-verification=true array_push($config, 'obfs=wss');
array_push($config, $tlsSettings['allowInsecure'] ? 'tls-verification=false' : 'tls-verification=true');
}
if (!empty($tlsSettings['serverName'])) {
array_push($config, "obfs-host={$tlsSettings['serverName']}");
}
} }
} else if ($server['network'] === 'ws') {
array_push($config, 'obfs=ws');
} }
if ($server['network'] === 'ws') { if ($server['tls']) {
if ($server['tls']) { if ($server['tlsSettings']) {
$tlsSettings = json_decode($server['tlsSettings'], true); $tlsSettings = json_decode($server['tlsSettings'], true);
array_push($config, 'obfs=wss'); if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
if (isset($tlsSettings['allowInsecure'])) { array_push($config, 'tls-verification=' . $tlsSettings['allowInsecure'] ? 'false' : 'true');
array_push($config, $tlsSettings['allowInsecure'] ? 'tls-verification=false' : 'tls-verification=true'); if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
} array_push($config, "sni={$tlsSettings['serverName']}");
} else {
array_push($config, 'obfs=ws');
} }
}
if ($server['network'] === 'ws') {
if ($server['networkSettings']) { if ($server['networkSettings']) {
$wsSettings = json_decode($server['networkSettings'], true); $wsSettings = json_decode($server['networkSettings'], true);
if (isset($wsSettings['path'])) array_push($config, "obfs-uri={$wsSettings['path']}"); if (isset($wsSettings['path']) && !empty($wsSettings['path']))
if (isset($wsSettings['headers']['Host'])) array_push($config, "obfs-host={$wsSettings['headers']['Host']}"); array_push($config, "obfs-uri={$wsSettings['path']}");
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
array_push($config, "obfs-host={$wsSettings['headers']['Host']}");
} }
} }

View File

@ -20,23 +20,32 @@ class Shadowrocket
{ {
$userinfo = base64_encode('auto:' . $uuid . '@' . $server['host'] . ':' . $server['port']); $userinfo = base64_encode('auto:' . $uuid . '@' . $server['host'] . ':' . $server['port']);
$config = [ $config = [
'tfo' => 1,
'remark' => $server['name'], 'remark' => $server['name'],
'alterId' => $server['alter_id'] 'alterId' => $server['alter_id']
]; ];
if ($server['tls']) { if ($server['tls']) {
$tlsSettings = json_decode($server['tlsSettings'], true);
$config['tls'] = 1; $config['tls'] = 1;
if (isset($tlsSettings['serverName'])) $config['peer'] = $tlsSettings['serverName']; if ($server['tlsSettings']) {
if (isset($tlsSettings['allowInsecure'])) $config['allowInsecure'] = 1; $tlsSettings = json_decode($server['tlsSettings'], true);
if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
$config['allowInsecure'] = (int)$tlsSettings['allowInsecure'];
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
$config['peer'] = $tlsSettings['serverName'];
}
} }
if ($server['network'] === 'ws') { if ($server['network'] === 'ws') {
$wsSettings = json_decode($server['networkSettings'], true);
$config['obfs'] = "websocket"; $config['obfs'] = "websocket";
if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path']; if ($server['networkSettings']) {
if (isset($wsSettings['headers']['Host'])) $config['obfsParam'] = $wsSettings['headers']['Host']; $wsSettings = json_decode($server['networkSettings'], true);
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
$config['path'] = $wsSettings['path'];
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
$config['obfsParam'] = $wsSettings['headers']['Host'];
}
} }
$query = http_build_query($config, null, '&', PHP_QUERY_RFC3986); $query = http_build_query($config, '', '&', PHP_QUERY_RFC3986);
$uri = "vmess://{$userinfo}?{$query}&tfo=1"; $uri = "vmess://{$userinfo}?{$query}";
$uri .= "\r\n"; $uri .= "\r\n";
return $uri; return $uri;
} }

View File

@ -33,29 +33,25 @@ class Surfboard
'tfo=true', 'tfo=true',
'udp-relay=true' 'udp-relay=true'
]; ];
if ($server['network'] === 'tcp') {
if ($server['tls']) { if ($server['tls']) {
array_push($config, 'tls=true');
if ($server['tlsSettings']) {
$tlsSettings = json_decode($server['tlsSettings'], true); $tlsSettings = json_decode($server['tlsSettings'], true);
array_push($config, $server['tls'] ? 'tls=true' : 'tls=false'); if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
if (!empty($tlsSettings['allowInsecure'])) { array_push($config, 'skip-cert-verify=' . $tlsSettings['allowInsecure'] ? 'true' : 'false');
array_push($config, $tlsSettings['allowInsecure'] ? 'skip-cert-verify=true' : 'skip-cert-verify=false'); if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
} array_push($config, "sni={$tlsSettings['serverName']}");
} }
} }
if ($server['network'] === 'ws') { if ($server['network'] === 'ws') {
array_push($config, 'ws=true'); array_push($config, 'ws=true');
if ($server['tls']) {
$tlsSettings = json_decode($server['tlsSettings'], true);
array_push($config, $server['tls'] ? 'tls=true' : 'tls=false');
if (!empty($tlsSettings['allowInsecure'])) {
array_push($config, $tlsSettings['allowInsecure'] ? 'skip-cert-verify=true' : 'skip-cert-verify=false');
}
}
if ($server['networkSettings']) { if ($server['networkSettings']) {
$wsSettings = json_decode($server['networkSettings'], true); $wsSettings = json_decode($server['networkSettings'], true);
if (isset($wsSettings['path'])) array_push($config, "ws-path={$wsSettings['path']}"); if (isset($wsSettings['path']) && !empty($wsSettings['path']))
if (isset($wsSettings['headers']['Host'])) array_push($config, "ws-headers=host:{$wsSettings['headers']['Host']}"); array_push($config, "ws-path={$wsSettings['path']}");
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
array_push($config, "ws-headers=Host:{$wsSettings['headers']['Host']}");
} }
} }

View File

@ -32,32 +32,25 @@ class Surge
'tfo=true', 'tfo=true',
'udp-relay=true' 'udp-relay=true'
]; ];
if ($server['network'] === 'tcp') {
if ($server['tls']) { if ($server['tls']) {
array_push($config, 'tls=true');
if ($server['tlsSettings']) {
$tlsSettings = json_decode($server['tlsSettings'], true); $tlsSettings = json_decode($server['tlsSettings'], true);
array_push($config, $server['tls'] ? 'tls=true' : 'tls=false'); if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
if (!empty($tlsSettings['allowInsecure'])) { array_push($config, 'skip-cert-verify=' . $tlsSettings['allowInsecure'] ? 'true' : 'false');
array_push($config, $tlsSettings['allowInsecure'] ? 'skip-cert-verify=true' : 'skip-cert-verify=false'); if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
}
if (!empty($tlsSettings['serverName'])) {
array_push($config, "sni={$tlsSettings['serverName']}"); array_push($config, "sni={$tlsSettings['serverName']}");
}
} }
} }
if ($server['network'] === 'ws') { if ($server['network'] === 'ws') {
array_push($config, 'ws=true'); array_push($config, 'ws=true');
if ($server['tls']) {
$tlsSettings = json_decode($server['tlsSettings'], true);
array_push($config, $server['tls'] ? 'tls=true' : 'tls=false');
if (!empty($tlsSettings['allowInsecure'])) {
array_push($config, $tlsSettings['allowInsecure'] ? 'skip-cert-verify=true' : 'skip-cert-verify=false');
}
}
if ($server['networkSettings']) { if ($server['networkSettings']) {
$wsSettings = json_decode($server['networkSettings'], true); $wsSettings = json_decode($server['networkSettings'], true);
if (isset($wsSettings['path'])) array_push($config, "ws-path={$wsSettings['path']}"); if (isset($wsSettings['path']) && !empty($wsSettings['path']))
if (isset($wsSettings['headers']['Host'])) array_push($config, "ws-headers=host:{$wsSettings['headers']['Host']}"); array_push($config, "ws-path={$wsSettings['path']}");
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
array_push($config, "ws-headers=Host:{$wsSettings['headers']['Host']}");
} }
} }