v2board/app/Utils/Surfboard.php

67 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace App\Utils;
class Surfboard
{
public static function buildShadowsocks($password, $server)
{
$config = [
2020-11-15 17:10:32 +08:00
"{$server['name']}=custom",
"{$server['host']}",
"{$server['port']}",
"{$server['cipher']}",
"{$password}",
'https://raw.githubusercontent.com/Hackl0us/proxy-tool-backup/master/SSEncrypt.module',
'tfo=true',
'udp-relay=true'
];
$config = array_filter($config);
$uri = implode(',', $config);
$uri .= "\r\n";
return $uri;
}
public static function buildVmess($uuid, $server)
{
$config = [
2020-11-15 17:10:32 +08:00
"{$server['name']}=vmess",
"{$server['host']}",
"{$server['port']}",
"username={$uuid}",
'tfo=true',
'udp-relay=true'
];
2020-11-15 17:10:32 +08:00
if ($server['network'] === 'tcp') {
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');
}
}
}
2020-11-15 17:10:32 +08:00
if ($server['network'] === 'ws') {
array_push($config, 'ws=true');
2020-11-15 17:10:32 +08:00
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');
}
}
2020-11-15 17:10:32 +08:00
if ($server['networkSettings']) {
$wsSettings = json_decode($server['networkSettings'], true);
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']}");
}
}
$uri = implode(',', $config);
$uri .= "\r\n";
return $uri;
}
}