Clash优化
This commit is contained in:
parent
a53a7a3e8e
commit
412fb62a31
|
|
@ -34,33 +34,47 @@ class Clash extends Protocol
|
||||||
}
|
}
|
||||||
$proxy = [];
|
$proxy = [];
|
||||||
$proxies = [];
|
$proxies = [];
|
||||||
$proxiesOther = array();
|
$proxiesOther = [];
|
||||||
|
|
||||||
foreach ($servers as $item) {
|
foreach ($servers as $item) {
|
||||||
if ($item['type'] === 'shadowsocks') {
|
$isGroups = false;
|
||||||
array_push($proxy, self::buildShadowsocks($user['uuid'], $item));
|
if (!empty($item['tags'])) {
|
||||||
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'])){
|
|
||||||
foreach ($item['tags'] as $tag) {
|
foreach ($item['tags'] as $tag) {
|
||||||
if(strpos($tag, "node:") === 0){
|
if (strpos($tag, 'node:') === 0) {
|
||||||
$nodearr = explode(":", $tag);
|
$group = substr($tag, 5);
|
||||||
if(array_key_exists($nodearr[1], $proxiesOther)){
|
if ($group !== '') {
|
||||||
array_push($proxiesOther[$nodearr[1]], $item['name']);
|
$proxiesOther[$group][] = $item['name'];
|
||||||
}else{
|
if (strpos($item['name'], $group) !== false) {
|
||||||
$proxiesOther[$nodearr[1]] = [$item['name']];
|
$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);
|
$config['proxies'] = array_merge($config['proxies'] ?: [], $proxy);
|
||||||
foreach ($config['proxy-groups'] as $k => $v) {
|
foreach ($config['proxy-groups'] as $k => $v) {
|
||||||
if (!is_array($config['proxy-groups'][$k]['proxies'])) {
|
if (!is_array($config['proxy-groups'][$k]['proxies'])) {
|
||||||
|
|
@ -74,11 +88,17 @@ class Clash extends Protocol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach ($proxiesOther as $k => $v) {
|
foreach ($proxiesOther as $k => $v) {
|
||||||
$vo = ['name' => $k, 'type' => 'fallback','proxies' => $v,'url' => "http://www.gstatic.com/generate_204",'interval' => 600];
|
$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'], $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
|
// Force the current subscription domain to be a direct rule
|
||||||
$subsDomain = $_SERVER['SERVER_NAME'];
|
$subsDomain = $_SERVER['SERVER_NAME'];
|
||||||
$subsDomainRule = "DOMAIN,{$subsDomain},DIRECT";
|
$subsDomainRule = "DOMAIN,{$subsDomain},DIRECT";
|
||||||
|
|
|
||||||
|
|
@ -24,33 +24,47 @@ class Mozilla extends Protocol
|
||||||
$config = Yaml::parseFile($defaultConfig);
|
$config = Yaml::parseFile($defaultConfig);
|
||||||
$proxy = [];
|
$proxy = [];
|
||||||
$proxies = [];
|
$proxies = [];
|
||||||
$proxiesOther = array();
|
$proxiesOther = [];
|
||||||
|
|
||||||
foreach ($servers as $item) {
|
foreach ($servers as $item) {
|
||||||
if ($item['type'] === 'shadowsocks') {
|
$isGroups = false;
|
||||||
array_push($proxy, self::buildShadowsocks($user['uuid'], $item));
|
if (!empty($item['tags'])) {
|
||||||
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'])){
|
|
||||||
foreach ($item['tags'] as $tag) {
|
foreach ($item['tags'] as $tag) {
|
||||||
if(strpos($tag, "node:") === 0){
|
if (strpos($tag, 'node:') === 0) {
|
||||||
$nodearr = explode(":", $tag);
|
$group = substr($tag, 5);
|
||||||
if(array_key_exists($nodearr[1], $proxiesOther)){
|
if ($group !== '') {
|
||||||
array_push($proxiesOther[$nodearr[1]], $item['name']);
|
$proxiesOther[$group][] = $item['name'];
|
||||||
}else{
|
if (strpos($item['name'], $group) !== false) {
|
||||||
$proxiesOther[$nodearr[1]] = [$item['name']];
|
$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);
|
$config['proxies'] = array_merge($config['proxies'] ?: [], $proxy);
|
||||||
foreach ($config['proxy-groups'] as $k => $v) {
|
foreach ($config['proxy-groups'] as $k => $v) {
|
||||||
if (!is_array($config['proxy-groups'][$k]['proxies'])) {
|
if (!is_array($config['proxy-groups'][$k]['proxies'])) {
|
||||||
|
|
@ -64,11 +78,13 @@ class Mozilla extends Protocol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach ($proxiesOther as $k => $v) {
|
foreach ($proxiesOther as $k => $v) {
|
||||||
$vo = ['name' => $k, 'type' => 'fallback','proxies' => $v,'url' => "http://www.gstatic.com/generate_204",'interval' => 600];
|
$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'], $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
|
// Force the current subscription domain to be a direct rule
|
||||||
$subsDomain = $_SERVER['SERVER_NAME'];
|
$subsDomain = $_SERVER['SERVER_NAME'];
|
||||||
$subsDomainRule = "DOMAIN,{$subsDomain},DIRECT";
|
$subsDomainRule = "DOMAIN,{$subsDomain},DIRECT";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue