|
@@ -13,8 +13,8 @@ class Surge
|
|
|
"{$server->port}",
|
|
|
"encrypt-method={$server->cipher}",
|
|
|
"password={$password}",
|
|
|
- "tfo=true",
|
|
|
- "udp-relay=true"
|
|
|
+ 'tfo=true',
|
|
|
+ 'udp-relay=true'
|
|
|
];
|
|
|
$config = array_filter($config);
|
|
|
$uri = implode(',', $config);
|
|
@@ -24,24 +24,46 @@ class Surge
|
|
|
|
|
|
public static function buildVmess($uuid, $server)
|
|
|
{
|
|
|
- $proxies = $server->name . ' = vmess, ' . $server->host . ', ' . $server->port . ', username=' . $uuid . ', tfo=true';
|
|
|
- if ($server->tls) {
|
|
|
- $tlsSettings = json_decode($server->tlsSettings);
|
|
|
- $proxies .= ', tls=' . ($server->tls ? "true" : "false");
|
|
|
- if (isset($tlsSettings->allowInsecure)) {
|
|
|
- $proxies .= ', skip-cert-verify=' . ($tlsSettings->allowInsecure ? "true" : "false");
|
|
|
+ $config = [
|
|
|
+ "{$server->name}=vmess",
|
|
|
+ "{$server->host}",
|
|
|
+ "{$server->port}",
|
|
|
+ "username={$uuid}",
|
|
|
+ 'tfo=true',
|
|
|
+ 'udp-relay=true'
|
|
|
+ ];
|
|
|
+ if ($server->network === 'tcp') {
|
|
|
+ if ($server->tls) {
|
|
|
+ $tlsSettings = json_decode($server->tlsSettings);
|
|
|
+ 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 (!empty($tlsSettings->serverName)) {
|
|
|
+ array_push($config, "sni={$tlsSettings->serverName}");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- if ($server->network == 'ws') {
|
|
|
- $proxies .= ', ws=true';
|
|
|
+
|
|
|
+ if ($server->network === 'ws') {
|
|
|
+ array_push($config, 'ws=true');
|
|
|
+ if ($server->tls) {
|
|
|
+ $tlsSettings = json_decode($server->tlsSettings);
|
|
|
+ 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) {
|
|
|
$wsSettings = json_decode($server->networkSettings);
|
|
|
- if (isset($wsSettings->path)) $proxies .= ', ws-path=' . $wsSettings->path;
|
|
|
- if (isset($wsSettings->headers->Host)) $proxies .= ', ws-headers=host:' . $wsSettings->headers->Host;
|
|
|
+ if (isset($wsSettings->path)) array_push($config, "ws-path={$wsSettings->path}");
|
|
|
+ if (isset($wsSettings->headers->Host)) array_push($config, "ws-headers=host:{$wsSettings->headers->Host}");
|
|
|
}
|
|
|
}
|
|
|
- $proxies .= "\r\n";
|
|
|
- return $proxies;
|
|
|
+
|
|
|
+ $uri = implode(',', $config);
|
|
|
+ $uri .= "\r\n";
|
|
|
+ return $uri;
|
|
|
}
|
|
|
|
|
|
public static function buildTrojan($password, $server)
|
|
@@ -51,10 +73,13 @@ class Surge
|
|
|
"{$server->host}",
|
|
|
"{$server->port}",
|
|
|
"password={$password}",
|
|
|
- $server->allow_insecure ? 'skip-cert-verify=true' : 'skip-cert-verify=false',
|
|
|
$server->server_name ? "sni={$server->server_name}" : "",
|
|
|
- "tfo=true"
|
|
|
+ 'tfo=true',
|
|
|
+ 'udp-relay=true'
|
|
|
];
|
|
|
+ if (!empty($server->allow_insecure)) {
|
|
|
+ array_push($config, $server->allow_insecure ? 'skip-cert-verify=true' : 'skip-cert-verify=false');
|
|
|
+ }
|
|
|
$config = array_filter($config);
|
|
|
$uri = implode(',', $config);
|
|
|
$uri .= "\r\n";
|