2020-06-13 18:33:42 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Utils;
|
|
|
|
|
|
|
|
|
|
|
|
class Surge
|
|
|
|
{
|
2020-10-04 22:55:40 +08:00
|
|
|
public static function buildShadowsocks($password, $server)
|
|
|
|
{
|
|
|
|
$config = [
|
|
|
|
"{$server->name}=ss",
|
|
|
|
"{$server->host}",
|
|
|
|
"{$server->port}",
|
|
|
|
"encrypt-method={$server->cipher}",
|
|
|
|
"password={$password}",
|
2020-10-09 21:47:36 +08:00
|
|
|
'tfo=true',
|
|
|
|
'udp-relay=true'
|
2020-10-04 22:55:40 +08:00
|
|
|
];
|
|
|
|
$config = array_filter($config);
|
|
|
|
$uri = implode(',', $config);
|
|
|
|
$uri .= "\r\n";
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
|
2020-06-13 18:33:42 +08:00
|
|
|
public static function buildVmess($uuid, $server)
|
|
|
|
{
|
2020-10-09 21:47:36 +08:00
|
|
|
$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}");
|
|
|
|
}
|
2020-06-13 18:33:42 +08:00
|
|
|
}
|
|
|
|
}
|
2020-10-09 21:47:36 +08:00
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
2020-06-13 18:33:42 +08:00
|
|
|
if ($server->networkSettings) {
|
|
|
|
$wsSettings = json_decode($server->networkSettings);
|
2020-10-09 21:47:36 +08:00
|
|
|
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}");
|
2020-06-13 18:33:42 +08:00
|
|
|
}
|
|
|
|
}
|
2020-10-09 21:47:36 +08:00
|
|
|
|
|
|
|
$uri = implode(',', $config);
|
|
|
|
$uri .= "\r\n";
|
|
|
|
return $uri;
|
2020-06-13 18:33:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function buildTrojan($password, $server)
|
|
|
|
{
|
2020-07-01 18:31:44 +08:00
|
|
|
$config = [
|
|
|
|
"{$server->name}=trojan",
|
|
|
|
"{$server->host}",
|
|
|
|
"{$server->port}",
|
|
|
|
"password={$password}",
|
2020-07-01 18:32:41 +08:00
|
|
|
$server->server_name ? "sni={$server->server_name}" : "",
|
2020-10-09 21:47:36 +08:00
|
|
|
'tfo=true',
|
|
|
|
'udp-relay=true'
|
2020-07-01 18:31:44 +08:00
|
|
|
];
|
2020-10-09 21:47:36 +08:00
|
|
|
if (!empty($server->allow_insecure)) {
|
|
|
|
array_push($config, $server->allow_insecure ? 'skip-cert-verify=true' : 'skip-cert-verify=false');
|
|
|
|
}
|
2020-07-01 18:31:44 +08:00
|
|
|
$config = array_filter($config);
|
2020-07-28 16:11:27 +08:00
|
|
|
$uri = implode(',', $config);
|
2020-06-13 18:33:42 +08:00
|
|
|
$uri .= "\r\n";
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
}
|