From 1527b9f8568190daf7ecd6189fdbbe44cfdbcec2 Mon Sep 17 00:00:00 2001 From: mercury Date: Wed, 4 Dec 2024 00:08:32 +0400 Subject: [PATCH] added rule-set for clash --- app/bot.php | 40 ++++++++++++++++++++++++++++++++++++---- config/clash.json | 2 ++ config/sing.json | 10 +++++----- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/app/bot.php b/app/bot.php index 003d991..03d5d7e 100644 --- a/app/bot.php +++ b/app/bot.php @@ -5811,13 +5811,17 @@ DNS-over-HTTPS with IP: $data[] = [ [ - 'text' => 'xray', + 'text' => $this->i18n('v2ray'), 'web_app' => ['url' => "https://{$domain}/pac?h=$hash&t=s&s={$c['id']}"], ], [ - 'text' => 'sing-box', + 'text' => $this->i18n('singbox'), 'web_app' => ['url' => "https://{$domain}/pac?h=$hash&t=si&s={$c['id']}"], ], + [ + 'text' => $this->i18n('clash'), + 'web_app' => ['url' => "https://{$domain}/pac?h=$hash&t=cl&s={$c['id']}"], + ], ]; $data[] = [ [ @@ -6134,6 +6138,7 @@ DNS-over-HTTPS with IP: } break; case 'cl': + $c = $this->clashRuleSet($c); if (!empty($c['rules'])) { $c['rules'] = $this->clashRules($c['rules']); } @@ -6150,6 +6155,33 @@ DNS-over-HTTPS with IP: echo json_encode($c); } + public function clashRuleSet($c) + { + $p = $this->getPacConf(); + if (!empty($p['rulessetlist']) && $c['add-rule-providers']) { + foreach ($p['rulessetlist'] as $k => $v) { + if (!empty($v)) { + [$type, $time, $url] = explode(':', $k, 3); + if (preg_match('~\.mrs$~', $url)) { + $c['rule-providers'][$type] = [ + 'type' => 'http', + 'url' => $url, + 'interval' => $time, + ]; + array_unshift($c['rules'], [ + 'RULE-SET', $url, strtoupper($type) + ]); + } + } + } + } + unset($c['add-rule-providers']); + if (empty($c['rule-providers'])) { + unset($c['rule-providers']); + } + return $c; + } + public function clashRules($rules) { foreach ($rules as $v) { @@ -6160,7 +6192,7 @@ DNS-over-HTTPS with IP: } } } else { - $tmp[] = "{$v['type']}, {$v['action']}"; + $tmp[] = implode(', ', $v); } } return $tmp; @@ -6184,7 +6216,7 @@ DNS-over-HTTPS with IP: foreach ($p['rulessetlist'] as $k => $v) { if (!empty($v)) { [$type, $time, $url] = explode(':', $k, 3); - if (!empty($route['rules'][$t[$type]])) { + if (preg_match('~\.srs$~', $url) && !empty($route['rules'][$t[$type]])) { $route['rule_set'][] = [ "tag" => $k, "type" => "remote", diff --git a/config/clash.json b/config/clash.json index 3180382..63ea5f0 100644 --- a/config/clash.json +++ b/config/clash.json @@ -90,6 +90,8 @@ ] } ], + "add-rule-providers": true, + "rule-providers": {}, "rules": [ { "type": "DOMAIN-SUFFIX", diff --git a/config/sing.json b/config/sing.json index f4e53fd..ebc80fe 100644 --- a/config/sing.json +++ b/config/sing.json @@ -115,7 +115,7 @@ "createruleset": [ { "name": "pac", - "interval": "15s", + "interval": "30s", "rules": [ { "domain_suffix": "~pac~" @@ -130,7 +130,7 @@ "createruleset": [ { "name": "package", - "interval": "15s", + "interval": "30s", "rules": [ { "package_name": "~package~" @@ -145,7 +145,7 @@ "createruleset": [ { "name": "process", - "interval": "15s", + "interval": "30s", "rules": [ { "process_name": "~process~" @@ -160,7 +160,7 @@ "createruleset": [ { "name": "block", - "interval": "15s", + "interval": "30s", "rules": [ { "domain_suffix": "~block~" @@ -175,7 +175,7 @@ "createruleset": [ { "name": "warp", - "interval": "15s", + "interval": "30s", "rules": [ { "domain_suffix": "~warp~"