mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-13 07:59:20 +00:00
97 lines
2.7 KiB
PHP
97 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Components\Client;
|
|
|
|
/*
|
|
* 本文件依据
|
|
* https://github.com/Dreamacro/clash/tree/master/adapter/outbound
|
|
* https://github.com/Dreamacro/clash/wiki/Configuration#all-configuration-options
|
|
* https://lancellc.gitbook.io/clash/clash-config-file/proxies/config-a-shadowsocks-proxy
|
|
*
|
|
*/
|
|
|
|
class Clash
|
|
{
|
|
public static function buildShadowsocks($server)
|
|
{
|
|
return [
|
|
'name' => $server['name'],
|
|
'type' => 'ss',
|
|
'server' => $server['host'],
|
|
'port' => $server['port'],
|
|
'password' => $server['passwd'],
|
|
'cipher' => $server['method'],
|
|
'udp' => $server['udp'],
|
|
];
|
|
}
|
|
|
|
public static function buildShadowsocksr($server)
|
|
{
|
|
return [
|
|
'name' => $server['name'],
|
|
'type' => 'ssr',
|
|
'server' => $server['host'],
|
|
'port' => $server['port'],
|
|
'password' => $server['passwd'],
|
|
'cipher' => $server['method'],
|
|
'obfs' => $server['obfs'],
|
|
'obfs-param' => $server['obfs_param'],
|
|
'protocol' => $server['protocol'],
|
|
'protocol-param' => $server['protocol_param'],
|
|
'udp' => $server['udp'],
|
|
];
|
|
}
|
|
|
|
public static function buildVmess($server)
|
|
{
|
|
$array = [
|
|
'name' => $server['name'],
|
|
'type' => 'vmess',
|
|
'server' => $server['host'],
|
|
'port' => $server['port'],
|
|
'uuid' => $server['uuid'],
|
|
'alterId' => $server['v2_alter_id'],
|
|
'cipher' => $server['method'],
|
|
'udp' => $server['udp'],
|
|
];
|
|
|
|
if ($server['v2_tls']) {
|
|
$array['tls'] = true;
|
|
$array['servername'] = $server['v2_host'];
|
|
}
|
|
$array['network'] = $server['v2_net'];
|
|
|
|
if ($server['v2_net'] === 'ws') {
|
|
$array['ws-opts'] = [];
|
|
$array['ws-opts']['path'] = $server['v2_path'];
|
|
if ($server['v2_host']) {
|
|
$array['ws-opts']['headers'] = ['Host' => $server['v2_host']];
|
|
}
|
|
$array['ws-path'] = $server['v2_path'];
|
|
if ($server['v2_host']) {
|
|
$array['ws-headers'] = ['Host' => $server['v2_host']];
|
|
}
|
|
}
|
|
|
|
return $array;
|
|
}
|
|
|
|
public static function buildTrojan($server)
|
|
{
|
|
$array = [
|
|
'name' => $server['name'],
|
|
'type' => 'trojan',
|
|
'server' => $server['host'],
|
|
'port' => $server['port'],
|
|
'password' => $server['passwd'],
|
|
'udp' => $server['udp'],
|
|
];
|
|
|
|
if (! empty($server['sni'])) {
|
|
$array['sni'] = $server['sni'];
|
|
}
|
|
|
|
return $array;
|
|
}
|
|
}
|