update: server

This commit is contained in:
Tokumeikoi 2020-11-15 17:10:32 +08:00
parent b4212e7af4
commit 592b751e2c
8 changed files with 174 additions and 176 deletions

View File

@ -31,16 +31,16 @@ class AppController extends Controller
foreach ($servers as $item) { foreach ($servers as $item) {
if ($item['type'] === 'shadowsocks') { if ($item['type'] === 'shadowsocks') {
array_push($proxy, Clash::buildShadowsocks($user->uuid, $item)); array_push($proxy, Clash::buildShadowsocks($user['uuid'], $item));
array_push($proxies, $item->name); array_push($proxies, $item['name']);
} }
if ($item['type'] === 'v2ray') { if ($item['type'] === 'v2ray') {
array_push($proxy, Clash::buildVmess($user->uuid, $item)); array_push($proxy, Clash::buildVmess($user['uuid'], $item));
array_push($proxies, $item->name); array_push($proxies, $item['name']);
} }
if ($item['type'] === 'trojan') { if ($item['type'] === 'trojan') {
array_push($proxy, Clash::buildTrojan($user->uuid, $item)); array_push($proxy, Clash::buildTrojan($user['uuid'], $item));
array_push($proxies, $item->name); array_push($proxies, $item['name']);
} }
} }

View File

@ -62,13 +62,13 @@ class ClientController extends Controller
foreach ($servers as $item) { foreach ($servers as $item) {
if ($item['type'] === 'v2ray') { if ($item['type'] === 'v2ray') {
$str = ''; $str = '';
$str .= $item->name . '= vmess, ' . $item->host . ', ' . $item->port . ', chacha20-ietf-poly1305, "' . $user->uuid . '", over-tls=' . ($item->tls ? "true" : "false") . ', certificate=0, group=' . config('v2board.app_name', 'V2Board'); $str .= $item['name'] . '= vmess, ' . $item['host'] . ', ' . $item['port'] . ', chacha20-ietf-poly1305, "' . $user['uuid'] . '", over-tls=' . ($item['tls'] ? "true" : "false") . ', certificate=0, group=' . config('v2board.app_name', 'V2Board');
if ($item->network === 'ws') { if ($item['network'] === 'ws') {
$str .= ', obfs=ws'; $str .= ', obfs=ws';
if ($item->networkSettings) { if ($item['networkSettings']) {
$wsSettings = json_decode($item->networkSettings); $wsSettings = json_decode($item['networkSettings']);
if (isset($wsSettings->path)) $str .= ', obfs-path="' . $wsSettings->path . '"'; if (isset($wsSettings['path'])) $str .= ', obfs-path="' . $wsSettings['path'] . '"';
if (isset($wsSettings->headers->Host)) $str .= ', obfs-header="Host:' . $wsSettings->headers->Host . '"'; if (isset($wsSettings['headers']['Host'])) $str .= ', obfs-header="Host:' . $wsSettings['headers']['Host'] . '"';
} }
} }
$uri .= "vmess://" . base64_encode($str) . "\r\n"; $uri .= "vmess://" . base64_encode($str) . "\r\n";
@ -88,13 +88,13 @@ class ClientController extends Controller
$uri .= "STATUS=🚀↑:{$upload}GB,↓:{$download}GB,TOT:{$totalTraffic}GB💡Expires:{$expiredDate}\r\n"; $uri .= "STATUS=🚀↑:{$upload}GB,↓:{$download}GB,TOT:{$totalTraffic}GB💡Expires:{$expiredDate}\r\n";
foreach ($servers as $item) { foreach ($servers as $item) {
if ($item['type'] === 'shadowsocks') { if ($item['type'] === 'shadowsocks') {
$uri .= Shadowrocket::buildShadowsocks($user->uuid, $item); $uri .= Shadowrocket::buildShadowsocks($user['uuid'], $item);
} }
if ($item['type'] === 'v2ray') { if ($item['type'] === 'v2ray') {
$uri .= Shadowrocket::buildVmess($user->uuid, $item); $uri .= Shadowrocket::buildVmess($user['uuid'], $item);
} }
if ($item['type'] === 'trojan') { if ($item['type'] === 'trojan') {
$uri .= Shadowrocket::buildTrojan($user->uuid, $item); $uri .= Shadowrocket::buildTrojan($user['uuid'], $item);
} }
} }
return base64_encode($uri); return base64_encode($uri);
@ -106,13 +106,13 @@ class ClientController extends Controller
header("subscription-userinfo: upload={$user->u}; download={$user->d}; total={$user->transfer_enable}; expire={$user->expired_at}"); header("subscription-userinfo: upload={$user->u}; download={$user->d}; total={$user->transfer_enable}; expire={$user->expired_at}");
foreach ($servers as $item) { foreach ($servers as $item) {
if ($item['type'] === 'shadowsocks') { if ($item['type'] === 'shadowsocks') {
$uri .= QuantumultX::buildShadowsocks($user->uuid, $item); $uri .= QuantumultX::buildShadowsocks($user['uuid'], $item);
} }
if ($item['type'] === 'v2ray') { if ($item['type'] === 'v2ray') {
$uri .= QuantumultX::buildVmess($user->uuid, $item); $uri .= QuantumultX::buildVmess($user['uuid'], $item);
} }
if ($item['type'] === 'trojan') { if ($item['type'] === 'trojan') {
$uri .= QuantumultX::buildTrojan($user->uuid, $item); $uri .= QuantumultX::buildTrojan($user['uuid'], $item);
} }
} }
return base64_encode($uri); return base64_encode($uri);
@ -143,21 +143,21 @@ class ClientController extends Controller
foreach ($servers as $item) { foreach ($servers as $item) {
if ($item['type'] === 'shadowsocks') { if ($item['type'] === 'shadowsocks') {
// [Proxy] // [Proxy]
$proxies .= Surge::buildShadowsocks($user->uuid, $item); $proxies .= Surge::buildShadowsocks($user['uuid'], $item);
// [Proxy Group] // [Proxy Group]
$proxyGroup .= $item->name . ', '; $proxyGroup .= $item['name'] . ', ';
} }
if ($item['type'] === 'v2ray') { if ($item['type'] === 'v2ray') {
// [Proxy] // [Proxy]
$proxies .= Surge::buildVmess($user->uuid, $item); $proxies .= Surge::buildVmess($user['uuid'], $item);
// [Proxy Group] // [Proxy Group]
$proxyGroup .= $item->name . ', '; $proxyGroup .= $item['name'] . ', ';
} }
if ($item['type'] === 'trojan') { if ($item['type'] === 'trojan') {
// [Proxy] // [Proxy]
$proxies .= Surge::buildTrojan($user->uuid, $item); $proxies .= Surge::buildTrojan($user['uuid'], $item);
// [Proxy Group] // [Proxy Group]
$proxyGroup .= $item->name . ', '; $proxyGroup .= $item['name'] . ', ';
} }
} }
@ -186,15 +186,15 @@ class ClientController extends Controller
foreach ($servers as $item) { foreach ($servers as $item) {
if ($item['type'] === 'shadowsocks') { if ($item['type'] === 'shadowsocks') {
// [Proxy] // [Proxy]
$proxies .= Surfboard::buildShadowsocks($user->uuid, $item); $proxies .= Surfboard::buildShadowsocks($user['uuid'], $item);
// [Proxy Group] // [Proxy Group]
$proxyGroup .= $item->name . ', '; $proxyGroup .= $item['name'] . ', ';
} }
if ($item['type'] === 'v2ray') { if ($item['type'] === 'v2ray') {
// [Proxy] // [Proxy]
$proxies .= Surfboard::buildVmess($user->uuid, $item); $proxies .= Surfboard::buildVmess($user['uuid'], $item);
// [Proxy Group] // [Proxy Group]
$proxyGroup .= $item->name . ', '; $proxyGroup .= $item['name'] . ', ';
} }
} }
@ -229,16 +229,16 @@ class ClientController extends Controller
foreach ($servers as $item) { foreach ($servers as $item) {
if ($item['type'] === 'shadowsocks') { if ($item['type'] === 'shadowsocks') {
array_push($proxy, Clash::buildShadowsocks($user->uuid, $item)); array_push($proxy, Clash::buildShadowsocks($user['uuid'], $item));
array_push($proxies, $item->name); array_push($proxies, $item['name']);
} }
if ($item['type'] === 'v2ray') { if ($item['type'] === 'v2ray') {
array_push($proxy, Clash::buildVmess($user->uuid, $item)); array_push($proxy, Clash::buildVmess($user['uuid'], $item));
array_push($proxies, $item->name); array_push($proxies, $item['name']);
} }
if ($item['type'] === 'trojan') { if ($item['type'] === 'trojan') {
array_push($proxy, Clash::buildTrojan($user->uuid, $item)); array_push($proxy, Clash::buildTrojan($user['uuid'], $item));
array_push($proxies, $item->name); array_push($proxies, $item['name']);
} }
} }

View File

@ -8,11 +8,11 @@ class Clash
public static function buildShadowsocks($uuid, $server) public static function buildShadowsocks($uuid, $server)
{ {
$array = []; $array = [];
$array['name'] = $server->name; $array['name'] = $server['name'];
$array['type'] = 'ss'; $array['type'] = 'ss';
$array['server'] = $server->host; $array['server'] = $server['host'];
$array['port'] = $server->port; $array['port'] = $server['port'];
$array['cipher'] = $server->cipher; $array['cipher'] = $server['cipher'];
$array['password'] = $uuid; $array['password'] = $uuid;
$array['udp'] = true; $array['udp'] = true;
return $array; return $array;
@ -21,27 +21,27 @@ class Clash
public static function buildVmess($uuid, $server) public static function buildVmess($uuid, $server)
{ {
$array = []; $array = [];
$array['name'] = $server->name; $array['name'] = $server['name'];
$array['type'] = 'vmess'; $array['type'] = 'vmess';
$array['server'] = $server->host; $array['server'] = $server['host'];
$array['port'] = $server->port; $array['port'] = $server['port'];
$array['uuid'] = $uuid; $array['uuid'] = $uuid;
$array['alterId'] = 2; $array['alterId'] = 2;
$array['cipher'] = 'auto'; $array['cipher'] = 'auto';
$array['udp'] = true; $array['udp'] = true;
if ($server->tls) { if ($server['tls']) {
$tlsSettings = json_decode($server->tlsSettings); $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 (!empty($tlsSettings['allowInsecure'])) $array['skip-cert-verify'] = ($tlsSettings['allowInsecure'] ? true : false );
if (!empty($tlsSettings->serverName)) $array['servername'] = $tlsSettings->serverName; if (!empty($tlsSettings['serverName'])) $array['servername'] = $tlsSettings['serverName'];
} }
if ($server->network == 'ws') { if ($server['network'] == 'ws') {
$array['network'] = $server->network; $array['network'] = $server['network'];
if ($server->networkSettings) { if ($server['networkSettings']) {
$wsSettings = json_decode($server->networkSettings); $wsSettings = json_decode($server['networkSettings'], true);
if (isset($wsSettings->path)) $array['ws-path'] = $wsSettings->path; if (isset($wsSettings['path'])) $array['ws-path'] = $wsSettings['path'];
if (isset($wsSettings->headers->Host)) $array['ws-headers'] = [ if (isset($wsSettings['headers']['Host'])) $array['ws-headers'] = [
'Host' => $wsSettings->headers->Host 'Host' => $wsSettings['headers']['Host']
]; ];
} }
} }
@ -51,14 +51,14 @@ class Clash
public static function buildTrojan($password, $server) public static function buildTrojan($password, $server)
{ {
$array = []; $array = [];
$array['name'] = $server->name; $array['name'] = $server['name'];
$array['type'] = 'trojan'; $array['type'] = 'trojan';
$array['server'] = $server->host; $array['server'] = $server['host'];
$array['port'] = $server->port; $array['port'] = $server['port'];
$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

@ -8,12 +8,12 @@ class QuantumultX
public static function buildShadowsocks($password, $server) public static function buildShadowsocks($password, $server)
{ {
$config = [ $config = [
"shadowsocks={$server->host}:{$server->port}", "shadowsocks={$server['host']}:{$server['port']}",
"method={$server->cipher}", "method={$server['cipher']}",
"password={$password}", "password={$password}",
'fast-open=true', 'fast-open=true',
'udp-relay=true', 'udp-relay=true',
"tag={$server->name}" "tag={$server['name']}"
]; ];
$config = array_filter($config); $config = array_filter($config);
$uri = implode(',', $config); $uri = implode(',', $config);
@ -24,41 +24,41 @@ class QuantumultX
public static function buildVmess($uuid, $server) public static function buildVmess($uuid, $server)
{ {
$config = [ $config = [
"vmess={$server->host}:{$server->port}", "vmess={$server['host']}:{$server['port']}",
'method=chacha20-poly1305', 'method=chacha20-poly1305',
"password={$uuid}", "password={$uuid}",
'fast-open=true', 'fast-open=true',
'udp-relay=true', 'udp-relay=true',
"tag={$server->name}" "tag={$server['name']}"
]; ];
if ($server->network === 'tcp') { if ($server['network'] === 'tcp') {
if ($server->tls) { if ($server['tls']) {
$tlsSettings = json_decode($server->tlsSettings); $tlsSettings = json_decode($server['tlsSettings'], true);
array_push($config, 'obfs=over-tls'); array_push($config, 'obfs=over-tls');
if (isset($tlsSettings->allowInsecure)) { if (isset($tlsSettings['allowInsecure'])) {
// Tips: allowInsecure=false = tls-verification=true // Tips: allowInsecure=false = tls-verification=true
array_push($config, $tlsSettings->allowInsecure ? 'tls-verification=false' : 'tls-verification=true'); array_push($config, $tlsSettings['allowInsecure'] ? 'tls-verification=false' : 'tls-verification=true');
} }
if (!empty($tlsSettings->serverName)) { if (!empty($tlsSettings['serverName'])) {
array_push($config, "obfs-host={$tlsSettings->serverName}"); array_push($config, "obfs-host={$tlsSettings['serverName']}");
} }
} }
} }
if ($server->network === 'ws') { if ($server['network'] === 'ws') {
if ($server->tls) { if ($server['tls']) {
$tlsSettings = json_decode($server->tlsSettings); $tlsSettings = json_decode($server['tlsSettings'], true);
array_push($config, 'obfs=wss'); array_push($config, 'obfs=wss');
if (isset($tlsSettings->allowInsecure)) { if (isset($tlsSettings['allowInsecure'])) {
array_push($config, $tlsSettings->allowInsecure ? 'tls-verification=false' : 'tls-verification=true'); array_push($config, $tlsSettings['allowInsecure'] ? 'tls-verification=false' : 'tls-verification=true');
} }
} else { } else {
array_push($config, 'obfs=ws'); array_push($config, 'obfs=ws');
} }
if ($server->networkSettings) { if ($server['networkSettings']) {
$wsSettings = json_decode($server->networkSettings); $wsSettings = json_decode($server['networkSettings'], true);
if (isset($wsSettings->path)) array_push($config, "obfs-uri={$wsSettings->path}"); if (isset($wsSettings['path'])) array_push($config, "obfs-uri={$wsSettings['path']}");
if (isset($wsSettings->headers->Host)) array_push($config, "obfs-host={$wsSettings->headers->Host}"); if (isset($wsSettings['headers']['Host'])) array_push($config, "obfs-host={$wsSettings['headers']['Host']}");
} }
} }
@ -70,15 +70,15 @@ class QuantumultX
public static function buildTrojan($password, $server) public static function buildTrojan($password, $server)
{ {
$config = [ $config = [
"trojan={$server->host}:{$server->port}", "trojan={$server['host']}:{$server['port']}",
"password={$password}", "password={$password}",
'over-tls=true', 'over-tls=true',
$server->server_name ? "tls-host={$server->server_name}" : "", $server['server_name'] ? "tls-host={$server['server_name']}" : "",
// Tips: allowInsecure=false = tls-verification=true // Tips: allowInsecure=false = tls-verification=true
$server->allow_insecure ? 'tls-verification=false' : 'tls-verification=true', $server['allow_insecure'] ? 'tls-verification=false' : 'tls-verification=true',
'fast-open=true', 'fast-open=true',
'udp-relay=true', 'udp-relay=true',
"tag={$server->name}" "tag={$server['name']}"
]; ];
$config = array_filter($config); $config = array_filter($config);
$uri = implode(',', $config); $uri = implode(',', $config);

View File

@ -7,32 +7,32 @@ class Shadowrocket
{ {
public static function buildShadowsocks($password, $server) public static function buildShadowsocks($password, $server)
{ {
$name = rawurlencode($server->name); $name = rawurlencode($server['name']);
$str = str_replace( $str = str_replace(
['+', '/', '='], ['+', '/', '='],
['-', '_', ''], ['-', '_', ''],
base64_encode("{$server->cipher}:{$password}") base64_encode("{$server['cipher']}:{$password}")
); );
return "ss://{$str}@{$server->host}:{$server->port}#{$name}\r\n"; return "ss://{$str}@{$server['host']}:{$server['port']}#{$name}\r\n";
} }
public static function buildVmess($uuid, $server) public static function buildVmess($uuid, $server)
{ {
$userinfo = base64_encode('auto:' . $uuid . '@' . $server->host . ':' . $server->port); $userinfo = base64_encode('auto:' . $uuid . '@' . $server['host'] . ':' . $server['port']);
$config = [ $config = [
'remark' => $server->name 'remark' => $server['name']
]; ];
if ($server->tls) { if ($server['tls']) {
$tlsSettings = json_decode($server->tlsSettings); $tlsSettings = json_decode($server['tlsSettings'], true);
$config['tls'] = 1; $config['tls'] = 1;
if (isset($tlsSettings->serverName)) $config['peer'] = $tlsSettings->serverName; if (isset($tlsSettings['serverName'])) $config['peer'] = $tlsSettings['serverName'];
if (isset($tlsSettings->allowInsecure)) $config['allowInsecure'] = 1; if (isset($tlsSettings['allowInsecure'])) $config['allowInsecure'] = 1;
} }
if ($server->network === 'ws') { if ($server['network'] === 'ws') {
$wsSettings = json_decode($server->networkSettings); $wsSettings = json_decode($server['networkSettings'], true);
$config['obfs'] = "websocket"; $config['obfs'] = "websocket";
if (isset($wsSettings->path)) $config['path'] = $wsSettings->path; if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path'];
if (isset($wsSettings->headers->Host)) $config['obfsParam'] = $wsSettings->headers->Host; if (isset($wsSettings['headers']['Host'])) $config['obfsParam'] = $wsSettings['headers']['Host'];
} }
$query = http_build_query($config, null, '&', PHP_QUERY_RFC3986); $query = http_build_query($config, null, '&', PHP_QUERY_RFC3986);
$uri = "vmess://{$userinfo}?{$query}&tfo=1"; $uri = "vmess://{$userinfo}?{$query}&tfo=1";
@ -42,12 +42,12 @@ class Shadowrocket
public static function buildTrojan($password, $server) public static function buildTrojan($password, $server)
{ {
$name = rawurlencode($server->name); $name = rawurlencode($server['name']);
$query = http_build_query([ $query = http_build_query([
'allowInsecure' => $server->allow_insecure, 'allowInsecure' => $server['allow_insecure'],
'peer' => $server->server_name 'peer' => $server['server_name']
]); ]);
$uri = "trojan://{$password}@{$server->host}:{$server->port}?{$query}&tfo=1#{$name}"; $uri = "trojan://{$password}@{$server['host']}:{$server['port']}?{$query}&tfo=1#{$name}";
$uri .= "\r\n"; $uri .= "\r\n";
return $uri; return $uri;
} }

View File

@ -8,10 +8,10 @@ class Surfboard
public static function buildShadowsocks($password, $server) public static function buildShadowsocks($password, $server)
{ {
$config = [ $config = [
"{$server->name}=custom", "{$server['name']}=custom",
"{$server->host}", "{$server['host']}",
"{$server->port}", "{$server['port']}",
"{$server->cipher}", "{$server['cipher']}",
"{$password}", "{$password}",
'https://raw.githubusercontent.com/Hackl0us/proxy-tool-backup/master/SSEncrypt.module', 'https://raw.githubusercontent.com/Hackl0us/proxy-tool-backup/master/SSEncrypt.module',
'tfo=true', 'tfo=true',
@ -26,36 +26,36 @@ class Surfboard
public static function buildVmess($uuid, $server) public static function buildVmess($uuid, $server)
{ {
$config = [ $config = [
"{$server->name}=vmess", "{$server['name']}=vmess",
"{$server->host}", "{$server['host']}",
"{$server->port}", "{$server['port']}",
"username={$uuid}", "username={$uuid}",
'tfo=true', 'tfo=true',
'udp-relay=true' 'udp-relay=true'
]; ];
if ($server->network === 'tcp') { if ($server['network'] === 'tcp') {
if ($server->tls) { if ($server['tls']) {
$tlsSettings = json_decode($server->tlsSettings); $tlsSettings = json_decode($server['tlsSettings'], true);
array_push($config, $server->tls ? 'tls=true' : 'tls=false'); array_push($config, $server['tls'] ? 'tls=true' : 'tls=false');
if (!empty($tlsSettings->allowInsecure)) { if (!empty($tlsSettings['allowInsecure'])) {
array_push($config, $tlsSettings->allowInsecure ? 'skip-cert-verify=true' : 'skip-cert-verify=false'); array_push($config, $tlsSettings['allowInsecure'] ? 'skip-cert-verify=true' : 'skip-cert-verify=false');
} }
} }
} }
if ($server->network === 'ws') { if ($server['network'] === 'ws') {
array_push($config, 'ws=true'); array_push($config, 'ws=true');
if ($server->tls) { if ($server['tls']) {
$tlsSettings = json_decode($server->tlsSettings); $tlsSettings = json_decode($server['tlsSettings'], true);
array_push($config, $server->tls ? 'tls=true' : 'tls=false'); array_push($config, $server['tls'] ? 'tls=true' : 'tls=false');
if (!empty($tlsSettings->allowInsecure)) { if (!empty($tlsSettings['allowInsecure'])) {
array_push($config, $tlsSettings->allowInsecure ? 'skip-cert-verify=true' : 'skip-cert-verify=false'); array_push($config, $tlsSettings['allowInsecure'] ? 'skip-cert-verify=true' : 'skip-cert-verify=false');
} }
} }
if ($server->networkSettings) { if ($server['networkSettings']) {
$wsSettings = json_decode($server->networkSettings); $wsSettings = json_decode($server['networkSettings'], true);
if (isset($wsSettings->path)) array_push($config, "ws-path={$wsSettings->path}"); 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}"); if (isset($wsSettings['headers']['Host'])) array_push($config, "ws-headers=host:{$wsSettings['headers']['Host']}");
} }
} }

View File

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

View File

@ -2,56 +2,54 @@
namespace App\Utils; namespace App\Utils;
use App\Models\Server; use App\Models\Server;
use App\Models\ServerShadowsocks;
use App\Models\ServerTrojan;
use App\Models\User; use App\Models\User;
class URLSchemes class URLSchemes
{ {
public static function buildShadowsocks(ServerShadowsocks $server, User $user) public static function buildShadowsocks($server, User $user)
{ {
$name = rawurlencode($server->name); $name = rawurlencode($server['name']);
$str = str_replace( $str = str_replace(
['+', '/', '='], ['+', '/', '='],
['-', '_', ''], ['-', '_', ''],
base64_encode("{$server->cipher}:{$user->uuid}") base64_encode("{$server['cipher']}:{$user['uuid']}")
); );
return "ss://{$str}@{$server->host}:{$server->port}#{$name}\r\n"; return "ss://{$str}@{$server['host']}:{$server['port']}#{$name}\r\n";
} }
public static function buildVmess(Server $server, User $user) public static function buildVmess($server, User $user)
{ {
$config = [ $config = [
"v" => "2", "v" => "2",
"ps" => $server->name, "ps" => $server['name'],
"add" => $server->host, "add" => $server['host'],
"port" => $server->port, "port" => $server['port'],
"id" => $user->uuid, "id" => $user['uuid'],
"aid" => "2", "aid" => "2",
"net" => $server->network, "net" => $server['network'],
"type" => "none", "type" => "none",
"host" => "", "host" => "",
"path" => "", "path" => "",
"tls" => $server->tls ? "tls" : "" "tls" => $server['tls'] ? "tls" : ""
]; ];
if ((string)$server->network === 'ws') { if ((string)$server['network'] === 'ws') {
$wsSettings = json_decode($server->networkSettings); $wsSettings = json_decode($server['networkSettings'], true);
if (isset($wsSettings->path)) $config['path'] = $wsSettings->path; if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path'];
if (isset($wsSettings->headers->Host)) $config['host'] = $wsSettings->headers->Host; if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host'];
} }
return "vmess://" . base64_encode(json_encode($config)) . "\r\n"; return "vmess://" . base64_encode(json_encode($config)) . "\r\n";
} }
public static function buildTrojan(ServerTrojan $server, User $user) public static function buildTrojan($server, User $user)
{ {
$name = rawurlencode($server->name); $name = rawurlencode($server['name']);
$query = http_build_query([ $query = http_build_query([
'allowInsecure' => $server->allow_insecure, 'allowInsecure' => $server['allow_insecure'],
'peer' => $server->server_name, 'peer' => $server['server_name'],
'sni' => $server->server_name 'sni' => $server['server_name']
]); ]);
$uri = "trojan://{$user->uuid}@{$server->host}:{$server->port}?{$query}#{$name}"; $uri = "trojan://{$user['uuid']}@{$server['host']}:{$server['port']}?{$query}#{$name}";
$uri .= "\r\n"; $uri .= "\r\n";
return $uri; return $uri;
} }