Clash优化

This commit is contained in:
lxf 2026-07-17 18:22:36 +08:00
parent a53a7a3e8e
commit 412fb62a31
2 changed files with 80 additions and 44 deletions

View File

@ -34,33 +34,47 @@ class Clash extends Protocol
}
$proxy = [];
$proxies = [];
$proxiesOther = array();
$proxiesOther = [];
foreach ($servers as $item) {
if ($item['type'] === 'shadowsocks') {
array_push($proxy, self::buildShadowsocks($user['uuid'], $item));
array_push($proxies, $item['name']);
}
if ($item['type'] === 'v2ray') {
array_push($proxy, self::buildVmess($user['uuid'], $item));
array_push($proxies, $item['name']);
}
if ($item['type'] === 'trojan') {
array_push($proxy, self::buildTrojan($user['uuid'], $item));
array_push($proxies, $item['name']);
}
if(!is_null($item['tags'])){
$isGroups = false;
if (!empty($item['tags'])) {
foreach ($item['tags'] as $tag) {
if(strpos($tag, "node:") === 0){
$nodearr = explode(":", $tag);
if(array_key_exists($nodearr[1], $proxiesOther)){
array_push($proxiesOther[$nodearr[1]], $item['name']);
}else{
$proxiesOther[$nodearr[1]] = [$item['name']];
if (strpos($tag, 'node:') === 0) {
$group = substr($tag, 5);
if ($group !== '') {
$proxiesOther[$group][] = $item['name'];
if (strpos($item['name'], $group) !== false) {
$isGroups = true;
}
}
}
}
}
switch ($item['type']) {
case 'shadowsocks':
$proxy[] = self::buildShadowsocks($user['uuid'], $item);
break;
case 'v2ray':
$proxy[] = self::buildVmess($user['uuid'], $item);
break;
case 'trojan':
$proxy[] = self::buildTrojan($user['uuid'], $item);
break;
default:
continue 2;
}
if (!$isGroups) {
$proxies[] = $item['name'];
}
}
$proxiesOther0 = $config['proxy-groups'][0]['proxies'];
$config['proxy-groups'][0]['proxies']=array();
$config['proxies'] = array_merge($config['proxies'] ?: [], $proxy);
foreach ($config['proxy-groups'] as $k => $v) {
if (!is_array($config['proxy-groups'][$k]['proxies'])) {
@ -74,11 +88,17 @@ class Clash extends Protocol
}
}
foreach ($proxiesOther as $k => $v) {
$vo = ['name' => $k, 'type' => 'fallback','proxies' => $v,'url' => "http://www.gstatic.com/generate_204",'interval' => 600];
array_push($config['proxy-groups'], $vo);
array_push($config['proxy-groups'][0]['proxies'],$k);
array_push($proxiesOther0,$k);
}
$config['proxy-groups'][0]['proxies'] = array_merge($proxiesOther0,$config['proxy-groups'][0]['proxies']);
// Force the current subscription domain to be a direct rule
$subsDomain = $_SERVER['SERVER_NAME'];
$subsDomainRule = "DOMAIN,{$subsDomain},DIRECT";
array_unshift($config['rules'], $subsDomainRule);
// Force the current subscription domain to be a direct rule
$subsDomain = $_SERVER['SERVER_NAME'];
$subsDomainRule = "DOMAIN,{$subsDomain},DIRECT";

View File

@ -24,33 +24,47 @@ class Mozilla extends Protocol
$config = Yaml::parseFile($defaultConfig);
$proxy = [];
$proxies = [];
$proxiesOther = array();
$proxiesOther = [];
foreach ($servers as $item) {
if ($item['type'] === 'shadowsocks') {
array_push($proxy, self::buildShadowsocks($user['uuid'], $item));
array_push($proxies, $item['name']);
}
if ($item['type'] === 'v2ray') {
array_push($proxy, self::buildVmess($user['uuid'], $item));
array_push($proxies, $item['name']);
}
if ($item['type'] === 'trojan') {
array_push($proxy, self::buildTrojan($user['uuid'], $item));
array_push($proxies, $item['name']);
}
if(!is_null($item['tags'])){
$isGroups = false;
if (!empty($item['tags'])) {
foreach ($item['tags'] as $tag) {
if(strpos($tag, "node:") === 0){
$nodearr = explode(":", $tag);
if(array_key_exists($nodearr[1], $proxiesOther)){
array_push($proxiesOther[$nodearr[1]], $item['name']);
}else{
$proxiesOther[$nodearr[1]] = [$item['name']];
if (strpos($tag, 'node:') === 0) {
$group = substr($tag, 5);
if ($group !== '') {
$proxiesOther[$group][] = $item['name'];
if (strpos($item['name'], $group) !== false) {
$isGroups = true;
}
}
}
}
}
switch ($item['type']) {
case 'shadowsocks':
$proxy[] = self::buildShadowsocks($user['uuid'], $item);
break;
case 'v2ray':
$proxy[] = self::buildVmess($user['uuid'], $item);
break;
case 'trojan':
$proxy[] = self::buildTrojan($user['uuid'], $item);
break;
default:
continue 2;
}
if (!$isGroups) {
$proxies[] = $item['name'];
}
}
$proxiesOther0 = $config['proxy-groups'][0]['proxies'];
$config['proxy-groups'][0]['proxies']=array();
$config['proxies'] = array_merge($config['proxies'] ?: [], $proxy);
foreach ($config['proxy-groups'] as $k => $v) {
if (!is_array($config['proxy-groups'][$k]['proxies'])) {
@ -64,11 +78,13 @@ class Mozilla extends Protocol
}
}
foreach ($proxiesOther as $k => $v) {
$vo = ['name' => $k, 'type' => 'fallback','proxies' => $v,'url' => "http://www.gstatic.com/generate_204",'interval' => 600];
array_push($config['proxy-groups'], $vo);
array_push($config['proxy-groups'][0]['proxies'],$k);
array_push($proxiesOther0,$k);
}
$config['proxy-groups'][0]['proxies'] = array_merge($proxiesOther0,$config['proxy-groups'][0]['proxies']);
// Force the current subscription domain to be a direct rule
$subsDomain = $_SERVER['SERVER_NAME'];
$subsDomainRule = "DOMAIN,{$subsDomain},DIRECT";