mirror of
https://github.com/v2board/v2board.git
synced 2024-11-14 07:29:13 +08:00
1acf64db44
Signed-off-by: Beta Soft <betaxab@gmail.com>
64 lines
2.0 KiB
PHP
64 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Utils;
|
|
|
|
|
|
class Surge
|
|
{
|
|
public static function buildShadowsocks($password, $server)
|
|
{
|
|
$config = [
|
|
"{$server->name}=ss",
|
|
"{$server->host}",
|
|
"{$server->port}",
|
|
"encrypt-method={$server->cipher}",
|
|
"password={$password}",
|
|
"tfo=true",
|
|
"udp-relay=true"
|
|
];
|
|
$config = array_filter($config);
|
|
$uri = implode(',', $config);
|
|
$uri .= "\r\n";
|
|
return $uri;
|
|
}
|
|
|
|
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");
|
|
}
|
|
}
|
|
if ($server->network == 'ws') {
|
|
$proxies .= ', ws=true';
|
|
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;
|
|
}
|
|
}
|
|
$proxies .= "\r\n";
|
|
return $proxies;
|
|
}
|
|
|
|
public static function buildTrojan($password, $server)
|
|
{
|
|
$config = [
|
|
"{$server->name}=trojan",
|
|
"{$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"
|
|
];
|
|
$config = array_filter($config);
|
|
$uri = implode(',', $config);
|
|
$uri .= "\r\n";
|
|
return $uri;
|
|
}
|
|
}
|