From 18ceb51f4e5dd22c80370866479334e5811a99b2 Mon Sep 17 00:00:00 2001 From: mercury Date: Tue, 10 Dec 2024 16:28:36 +0400 Subject: [PATCH] mihomo: rules -> rule-providers update core's --- app/bot.php | 58 +++++++++++++++++++++++++++++++++++++-- config/clash.json | 54 ++++++++++++++++++++---------------- docker-compose.yml | 4 +-- dockerfile/php.dockerfile | 23 ++++++++-------- 4 files changed, 100 insertions(+), 39 deletions(-) diff --git a/app/bot.php b/app/bot.php index 50c4626..57637d8 100644 --- a/app/bot.php +++ b/app/bot.php @@ -6138,7 +6138,8 @@ DNS-over-HTTPS with IP: } break; case 'cl': - $c = $this->clashRuleSet($c); + $c = $this->createClashRuleSet($c, $uid, $domain); + $c = $this->addClashRuleSet($c); if (!empty($c['rules'])) { $c['rules'] = $this->clashRules($c['rules']); if (count($c['rules']) == 1) { @@ -6158,7 +6159,60 @@ DNS-over-HTTPS with IP: echo json_encode($c); } - public function clashRuleSet($c) + public function createClashRuleSet($c, $uid, $domain) + { + $scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https'; + $hash = substr(md5($this->key), 0, 8); + if (!empty($c['rule-providers'])) { + foreach ($c['rule-providers'] as $k => $v) { + if (array_key_exists('list', $v)) { + if (!empty($_GET['r']) && $k == $_GET['r']) { + header("Content-Disposition: attachment; filename=$k.yaml"); + header('Content-Type: text/yaml'); + switch ($v['behavior']) { + case 'domain': + echo yaml_emit(['payload' => array_map(fn($e) => "+.$e", $v['list'])]); + break; + + default: + echo yaml_emit(['payload' => array_map(fn($e) => "PROCESS-NAME,$e", $v['list'])]); + break; + } + exit; + } + $c['rule-providers'][$k] = [ + 'type' => 'http', + 'url' => "$scheme://{$domain}/pac/" . base64_encode(serialize([ + 'h' => $hash, + 't' => 'cl', + 's' => $uid, + 'r' => $k, + ])), + 'interval' => $v['interval'], + 'behavior' => $v['behavior'], + 'format' => 'yaml', + ]; + switch ($v['action']) { + case 'reject': + case 'REJECT': + array_unshift($c['rules'], [ + 'RULE-SET', $k, strtoupper($v['action']) + ]); + break; + + default: + array_splice($c['rules'], count($c['rules']) - 1, 0, [[ + 'RULE-SET', $k, strtoupper($v['action']) + ]]); + break; + } + } + } + } + return $c; + } + + public function addClashRuleSet($c) { $p = $this->getPacConf(); if (!empty($p['rulessetlist']) && $c['add-rule-providers']) { diff --git a/config/clash.json b/config/clash.json index 63ea5f0..08cfd9e 100644 --- a/config/clash.json +++ b/config/clash.json @@ -6,7 +6,7 @@ "find-process-mode": "strict", "global-client-fingerprint": "chrome", "mode": "rule", - "log-level": "debug", + "log-level": "info", "ipv6": false, "keep-alive-interval": 30, "unified-delay": false, @@ -91,33 +91,39 @@ } ], "add-rule-providers": true, - "rule-providers": {}, - "rules": [ - { - "type": "DOMAIN-SUFFIX", + "rule-providers": { + "block": { "list": "~block~", - "action": "REJECT" + "interval": 30, + "action": "REJECT", + "behavior": "domain" }, - { - "type": "PROCESS-NAME", - "list": "~process~", - "action": "PROXY" - }, - { - "type": "PROCESS-NAME", - "list": "~package~", - "action": "PROXY" - }, - { - "type": "DOMAIN-SUFFIX", - "list": "~warp~", - "action": "PROXY" - }, - { - "type": "DOMAIN-SUFFIX", + "pac": { "list": "~pac~", - "action": "PROXY" + "interval": 30, + "action": "PROXY", + "behavior": "domain" }, + "warp": { + "list": "~warp~", + "interval": 30, + "action": "PROXY", + "behavior": "domain" + }, + "package": { + "list": "~package~", + "interval": 30, + "action": "PROXY", + "behavior": "classical" + }, + "process": { + "list": "~process~", + "interval": 30, + "action": "PROXY", + "behavior": "classical" + } + }, + "rules": [ { "type": "MATCH", "action": "DIRECT" diff --git a/docker-compose.yml b/docker-compose.yml index 8b737d2..34d9760 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -96,7 +96,7 @@ services: ipv4_address: 10.10.1.2 logging: *default-logging php: - image: mercurykd/vpnbot-php:1.6 + image: mercurykd/vpnbot-php:1.7 build: dockerfile: dockerfile/php.dockerfile args: @@ -405,7 +405,7 @@ services: ipv4_address: 10.10.0.8 logging: *default-logging xr: - image: mercurykd/vpnbot-xr:1.3 + image: mercurykd/vpnbot-xr:1.4 build: dockerfile: dockerfile/xray.dockerfile args: diff --git a/dockerfile/php.dockerfile b/dockerfile/php.dockerfile index 895c2d1..ef231a4 100644 --- a/dockerfile/php.dockerfile +++ b/dockerfile/php.dockerfile @@ -22,16 +22,17 @@ RUN apk add --no-cache --update php81 \ curl \ git \ py3-qt5 \ - && wget https://github.com/ameshkov/dnslookup/releases/download/v1.9.1/dnslookup-linux-amd64-v1.9.1.tar.gz \ - && tar -xf dnslookup-linux-amd64-v1.9.1.tar.gz \ + && mkdir /root/.ssh \ + && wget https://github.com/ameshkov/dnslookup/releases/download/v1.11.1/dnslookup-linux-amd64-v1.11.1.tar.gz \ + && tar -xf dnslookup-linux-amd64-v1.11.1.tar.gz \ && mv linux-amd64/dnslookup /usr/bin \ - && rm dnslookup-linux-amd64-v1.9.1.tar.gz \ + && rm dnslookup-linux-amd64-v1.11.1.tar.gz \ && rm -rf /linux-amd64 \ - && wget https://github.com/SagerNet/sing-box/releases/download/v1.8.11/sing-box-1.8.11-linux-amd64.tar.gz \ - && tar -xf sing-box-1.8.11-linux-amd64.tar.gz \ - && mv sing-box-1.8.11-linux-amd64/sing-box /usr/bin \ - && rm sing-box-1.8.11-linux-amd64.tar.gz \ - && rm -rf /sing-box-1.8.11-linux-amd64 -RUN apk add openssh \ - && mkdir /root/.ssh - ENV ENV="/root/.ashrc" + && wget https://github.com/SagerNet/sing-box/releases/download/v1.10.3/sing-box-1.10.3-linux-amd64.tar.gz \ + && tar -xf sing-box-1.10.3-linux-amd64.tar.gz \ + && mv sing-box-1.10.3-linux-amd64/sing-box /usr/bin \ + && rm sing-box-1.10.3-linux-amd64.tar.gz \ + && rm -rf /sing-box-1.10.3-linux-amd64 \ + && wget https://github.com/MetaCubeX/mihomo/releases/download/v1.18.10/mihomo-linux-amd64-v1.18.10.gz \ + && gunzip mihomo-linux-amd64-v1.18.10.gz \ + && mv mihomo-linux-amd64-v1.18.10 /usr/bin/mihomo \ No newline at end of file