Merge pull request #344 from betaxab/p1

subscription: add shadowsocks SIP008 subscription support
This commit is contained in:
tokumeikoi 2020-11-27 01:48:50 +08:00 committed by GitHub
commit 5f0e62f43c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -50,6 +50,9 @@ class ClientController extends Controller
if (strpos($flag, 'shadowrocket') !== false) {
die($this->shadowrocket($user, $servers));
}
if (strpos($flag, 'shadowsocks') !== false) {
die($this->shaodowsocksSIP008($user, $servers));
}
}
die($this->origin($user, $servers));
}
@ -135,6 +138,25 @@ class ClientController extends Controller
return base64_encode($uri);
}
private function shaodowsocksSIP008($user, $servers = [])
{
$configs = [];
$subs = [];
$subs['servers'] = [];
foreach ($servers as $item) {
if ($item['type'] === 'shadowsocks') {
array_push($configs, URLSchemes::buildShadowsocksSIP008($item, $user));
}
}
$subs['version'] = 1;
$subs['remark'] = config('v2board.app_name', 'V2Board');
$subs['servers'] = array_merge($subs['servers'] ? $subs['servers'] : [], $configs);
return json_encode($subs, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
}
private function surge($user, $servers = [])
{
$proxies = '';

View File

@ -17,6 +17,18 @@ class URLSchemes
return "ss://{$str}@{$server['host']}:{$server['port']}#{$name}\r\n";
}
public static function buildShadowsocksSIP008($server, User $user)
{
$config = [
"id" => $server['id'],
"remark" => $server['name'],
"server" => $server['host'],
"server_port" => $server['port'],
"password" => $user['uuid'],
"method" => $server['cipher']
];
return $config;
}
public static function buildVmess($server, User $user)
{