From 4c2ea5896bcab47078d73dd71e83e59df6fe9175 Mon Sep 17 00:00:00 2001 From: nite07 Date: Wed, 13 Mar 2024 00:11:34 +0800 Subject: [PATCH 1/2] add: version cmd add: dockerfile --- .github/workflows/docker.yaml | 66 +++++++++++++++++++++++++++++++ .github/workflows/goreleaser.yaml | 2 +- .goreleaser.yaml | 2 +- Dockerfile | 17 ++++++++ LICENSE.txt | 21 ++++++++++ cmd/root.go | 7 +++- cmd/version.go | 20 ++++++++++ main.go | 7 ++++ 8 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/docker.yaml create mode 100644 Dockerfile create mode 100644 LICENSE.txt create mode 100644 cmd/version.go diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..dcdc273 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,66 @@ +name: Build and Push Docker + +on: + push: + branches: + - dev + tags: + - "*" + workflow_dispatch: + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_PASSWORD }} + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ secrets.DOCKER_HUB_USERNAME }}/sub2sing-box + ghcr.io/${{ github.repository }} + + - name: Prepare tags and build args + id: prep + run: | + if [[ "${{ github.event_name }}" == 'workflow_dispatch' ]]; then + VERSION="${{ github.sha }}" + fi + if [[ "$GITHUB_REF" == 'refs/heads/dev' ]]; then + VERSION="${{ github.sha }}" + fi + if [[ "$GITHUB_REF" == 'refs/tags/'* ]]; then + VERSION=$TAG_NAME + fi + echo "version=${VERSION}" >> $GITHUB_ENV + + - name: Set up Docker buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push Docker image to GHCR and Docker Hub + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + build-args: version=${{ steps.prep.outputs.version }} + push: true + platforms: linux/amd64,linux/arm,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/goreleaser.yaml b/.github/workflows/goreleaser.yaml index 8bca9ef..1f97cec 100644 --- a/.github/workflows/goreleaser.yaml +++ b/.github/workflows/goreleaser.yaml @@ -1,4 +1,4 @@ -name: build +name: Build and Release on: push: diff --git a/.goreleaser.yaml b/.goreleaser.yaml index f5af655..651f1c6 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -12,7 +12,7 @@ builds: - arm - "386" ldflags: - - -s -w + - -s -w -X sub2sing-box/main.Version={{ .Version }} no_unique_dist_dir: true binary: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}" archives: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8feabff --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM golang:1.21 as builder +LABEL authors="nite07" + +WORKDIR /app + +COPY . . +RUN go mod download + +ARG version + +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X sub2clash/config.Version=${version}" -o sub2sing-box main.go + +FROM alpine:latest + +COPY --from=builder /app/sub2sing-box /app/sub2sing-box + +ENTRYPOINT ["/app/sub2sing-box","server"] diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..83509c3 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Nite07 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/cmd/root.go b/cmd/root.go index a62c8db..6d8c1e7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,8 +1,11 @@ package cmd -import "github.com/spf13/cobra" +import ( + "github.com/spf13/cobra" +) var RootCmd = &cobra.Command{} -func init() { +func SetVersion(version string) { + RootCmd.Version = version } diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..2bb8dc2 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,20 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print version", + Long: "Print version", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("version: " + RootCmd.Version) + }, +} + +func init() { + RootCmd.AddCommand(versionCmd) +} diff --git a/main.go b/main.go index 408dbce..98cf883 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,13 @@ import ( "sub2sing-box/cmd" ) +var Version string + +func init() { + Version = "dev" + cmd.SetVersion(Version) +} + func main() { if err := cmd.RootCmd.Execute(); err != nil { fmt.Println(err) From c3ed3929001011c5a2fc115ec4719fdf04a37e6f Mon Sep 17 00:00:00 2001 From: nite07 Date: Wed, 13 Mar 2024 02:02:17 +0800 Subject: [PATCH 2/2] update: readme, template --- .github/workflows/docker.yaml | 6 +- .goreleaser.yaml | 2 + Readme.md | 23 +- api/server.go | 2 +- template/tun-fakeip-with-dns-leaks.json | 247 +++++++++++++++++++ template/tun-fakeip-without-dns-leaks.json | 266 +++++++++++++++++++++ template/tun-fakeip.json | 234 ------------------ template/tun-with-dns-leaks.json | 233 ++++++++++++++++++ template/tun-without-dns-leaks.json | 252 +++++++++++++++++++ 9 files changed, 1024 insertions(+), 241 deletions(-) create mode 100644 template/tun-fakeip-with-dns-leaks.json create mode 100644 template/tun-fakeip-without-dns-leaks.json delete mode 100644 template/tun-fakeip.json create mode 100644 template/tun-with-dns-leaks.json create mode 100644 template/tun-without-dns-leaks.json diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index dcdc273..cf204b6 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -37,7 +37,7 @@ jobs: ${{ secrets.DOCKER_HUB_USERNAME }}/sub2sing-box ghcr.io/${{ github.repository }} - - name: Prepare tags and build args + - name: Prepare args id: prep run: | if [[ "${{ github.event_name }}" == 'workflow_dispatch' ]]; then @@ -49,7 +49,7 @@ jobs: if [[ "$GITHUB_REF" == 'refs/tags/'* ]]; then VERSION=$TAG_NAME fi - echo "version=${VERSION}" >> $GITHUB_ENV + echo "version=$VERSION" >> $GITHUB_ENV - name: Set up Docker buildx uses: docker/setup-buildx-action@v3 @@ -59,7 +59,7 @@ jobs: with: context: . file: ./Dockerfile - build-args: version=${{ steps.prep.outputs.version }} + build-args: version=${{ env.version }} push: true platforms: linux/amd64,linux/arm,linux/arm64 tags: ${{ steps.meta.outputs.tags }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 651f1c6..aec47d1 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -13,6 +13,8 @@ builds: - "386" ldflags: - -s -w -X sub2sing-box/main.Version={{ .Version }} + flags: + - -trimpath no_unique_dist_dir: true binary: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}" archives: diff --git a/Readme.md b/Readme.md index bbc9ff5..f47a1b1 100644 --- a/Readme.md +++ b/Readme.md @@ -40,9 +40,22 @@ Flags: - `data`: Base64 编码的 JSON 字符串,包含以下字段: - `subscription`: []string - `proxy`: []string - - `delete`: string - - `rename`: string - - `template`: string + - `delete`: string 可选 + - `rename`: string 可选 + - `template`: map[string]string 可选 + +示例 +``` +{ + "subscription": ["url1", "url2"], + "proxy": ["p1", "p2"], + "delete": "reg", + "template": "t", + "rename": { + "text": "replaceTo" + } +} +``` ## Template @@ -56,3 +69,7 @@ Template 中使用 `` 指明节点插入位置,例如 "interrupt_exist_connections": true }, ``` + +## Docker + +`docker run -p 8080:8080 nite07/sub2sing-box` \ No newline at end of file diff --git a/api/server.go b/api/server.go index 224e464..4324f85 100644 --- a/api/server.go +++ b/api/server.go @@ -14,7 +14,7 @@ func RunServer(port uint16) { r.GET("/convert", handler.Convert) - fmt.Println("Server is running on port ", port) + fmt.Println("Server is running on port", port) err := r.Run(":" + strconv.Itoa(int(port))) if err != nil { fmt.Println("Run server failed: ", err) diff --git a/template/tun-fakeip-with-dns-leaks.json b/template/tun-fakeip-with-dns-leaks.json new file mode 100644 index 0000000..2d2b205 --- /dev/null +++ b/template/tun-fakeip-with-dns-leaks.json @@ -0,0 +1,247 @@ +{ + "log": { + "level": "info", + "timestamp": true + }, + "dns": { + "servers": [ + { + "tag": "google", + "address": "tls://8.8.8.8" + }, + { + "tag": "local", + "address": "https://223.5.5.5/dns-query", + "detour": "direct" + }, + { + "tag": "remote", + "address": "fakeip" + } + ], + "rules": [ + { + "outbound": "any", + "server": "local" + }, + { + "clash_mode": "Direct", + "server": "local" + }, + { + "clash_mode": "Global", + "server": "google" + }, + { + "rule_set": "geosite-geolocation-cn", + "server": "local" + }, + { + "query_type": ["A", "AAAA"], + "server": "remote" + } + ], + "fakeip": { + "enabled": true, + "inet4_range": "198.18.0.0/15", + "inet6_range": "fc00::/18" + }, + "independent_cache": true + }, + "route": { + "rule_set": [ + { + "tag": "geosite-geolocation-cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-geolocation-cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-geolocation-!cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-geolocation-!cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geoip-cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geoip/rule-set/geoip-cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-category-ads-all", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-ads-all.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-microsoft", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-microsoft.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-bilibili", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-bilibili.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-bahamut", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-bahamut.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-category-games@cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-games@cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-category-games", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-games.srs", + "download_detour": "节点选择" + } + ], + "rules": [ + { + "type": "logical", + "mode": "or", + "rules": [ + { + "protocol": "dns" + }, + { + "port": 53 + } + ], + "outbound": "dns-out" + }, + { + "ip_is_private": true, + "outbound": "direct" + }, + { + "rule_set": ["geoip-cn", "geosite-geolocation-cn"], + "outbound": "direct" + }, + { + "rule_set": "geosite-category-ads-all", + "outbound": "Ads" + }, + { + "rule_set": "geosite-microsoft", + "outbound": "Microsoft" + }, + { + "rule_set": "geosite-bilibili", + "outbound": "Bilibili" + }, + { + "rule_set": "geosite-category-games@cn", + "outbound": "Games(中国)" + }, + { + "rule_set": "geosite-category-games", + "outbound": "Games(全球)" + }, + { + "rule_set": "geosite-bahamut", + "outbound": "Bahamut" + } + ], + "final": "节点选择", + "auto_detect_interface": true + }, + "inbounds": [ + { + "type": "tun", + "inet4_address": "172.19.0.1/30", + "inet6_address": "fdfe:dcba:9876::1/126", + "auto_route": true, + "strict_route": true, + "sniff": true, + "sniff_override_destination": false + } + ], + "outbounds": [ + { + "type": "selector", + "tag": "节点选择", + "outbounds": ["", "direct"], + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Ads", + "outbounds": ["direct", "block"], + "default": "block", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Microsoft", + "outbounds": ["节点选择", "", "direct"], + "default": "节点选择", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Bilibili", + "outbounds": ["节点选择", "", "direct"], + "default": "direct", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Games(全球)", + "outbounds": ["节点选择", "", "direct"], + "default": "节点选择", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Games(中国)", + "outbounds": ["节点选择", "", "direct"], + "default": "direct", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Bahamut", + "outbounds": ["节点选择", "", "direct"], + "default": "节点选择", + "interrupt_exist_connections": true + }, + { + "type": "direct", + "tag": "direct" + }, + { + "type": "block", + "tag": "block" + }, + { + "type": "dns", + "tag": "dns-out" + } + ], + "experimental": { + "clash_api": { + "external_controller": "127.0.0.1:9090", + "external_ui": "./ui", + "external_ui_download_detour": "节点选择" + } + } +} diff --git a/template/tun-fakeip-without-dns-leaks.json b/template/tun-fakeip-without-dns-leaks.json new file mode 100644 index 0000000..a09fad2 --- /dev/null +++ b/template/tun-fakeip-without-dns-leaks.json @@ -0,0 +1,266 @@ +{ + "log": { + "level": "info", + "timestamp": true + }, + "dns": { + "servers": [ + { + "tag": "google", + "address": "tls://8.8.8.8" + }, + { + "tag": "local", + "address": "https://223.5.5.5/dns-query", + "detour": "direct" + }, + { + "tag": "remote", + "address": "fakeip" + } + ], + "rules": [ + { + "outbound": "any", + "server": "local" + }, + { + "clash_mode": "Direct", + "server": "local" + }, + { + "clash_mode": "Global", + "server": "google" + }, + { + "rule_set": "geosite-geolocation-cn", + "server": "local" + }, + { + "type": "logical", + "mode": "and", + "rules": [ + { + "rule_set": "geosite-geolocation-!cn" + }, + { + "rule_set": "geoip-cn" + } + ], + "server": "google", + "client_subnet": "114.114.114.114" + }, + { + "query_type": ["A", "AAAA"], + "server": "remote" + } + ], + "fakeip": { + "enabled": true, + "inet4_range": "198.18.0.0/15", + "inet6_range": "fc00::/18" + }, + "independent_cache": true + }, + "route": { + "rule_set": [ + { + "tag": "geosite-geolocation-cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-geolocation-cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-geolocation-!cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-geolocation-!cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geoip-cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geoip/rule-set/geoip-cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-category-ads-all", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-ads-all.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-microsoft", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-microsoft.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-bilibili", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-bilibili.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-bahamut", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-bahamut.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-category-games@cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-games@cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-category-games", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-games.srs", + "download_detour": "节点选择" + } + ], + "rules": [ + { + "type": "logical", + "mode": "or", + "rules": [ + { + "protocol": "dns" + }, + { + "port": 53 + } + ], + "outbound": "dns-out" + }, + { + "ip_is_private": true, + "outbound": "direct" + }, + { + "rule_set": ["geoip-cn", "geosite-geolocation-cn"], + "outbound": "direct" + }, + { + "rule_set": "geosite-category-ads-all", + "outbound": "Ads" + }, + { + "rule_set": "geosite-microsoft", + "outbound": "Microsoft" + }, + { + "rule_set": "geosite-bilibili", + "outbound": "Bilibili" + }, + { + "rule_set": "geosite-category-games@cn", + "outbound": "Games(中国)" + }, + { + "rule_set": "geosite-category-games", + "outbound": "Games(全球)" + }, + { + "rule_set": "geosite-bahamut", + "outbound": "Bahamut" + } + ], + "final": "节点选择", + "auto_detect_interface": true + }, + "inbounds": [ + { + "type": "tun", + "inet4_address": "172.19.0.1/30", + "inet6_address": "fdfe:dcba:9876::1/126", + "auto_route": true, + "strict_route": true, + "sniff": true, + "sniff_override_destination": false + } + ], + "outbounds": [ + { + "type": "selector", + "tag": "节点选择", + "outbounds": ["", "direct"], + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Ads", + "outbounds": ["direct", "block"], + "default": "block", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Microsoft", + "outbounds": ["节点选择", "", "direct"], + "default": "节点选择", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Bilibili", + "outbounds": ["节点选择", "", "direct"], + "default": "direct", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Games(全球)", + "outbounds": ["节点选择", "", "direct"], + "default": "节点选择", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Games(中国)", + "outbounds": ["节点选择", "", "direct"], + "default": "direct", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Bahamut", + "outbounds": ["节点选择", "", "direct"], + "default": "节点选择", + "interrupt_exist_connections": true + }, + { + "type": "direct", + "tag": "direct" + }, + { + "type": "block", + "tag": "block" + }, + { + "type": "dns", + "tag": "dns-out" + } + ], + "experimental": { + "cache_file": { + "enabled": true, + "store_rdrc": true + }, + "clash_api": { + "default_mode": "Enhanced", + "external_controller": "127.0.0.1:9090", + "external_ui": "./ui", + "external_ui_download_detour": "节点选择" + } + } +} diff --git a/template/tun-fakeip.json b/template/tun-fakeip.json deleted file mode 100644 index 6747693..0000000 --- a/template/tun-fakeip.json +++ /dev/null @@ -1,234 +0,0 @@ -{ - "log": { - "level": "info", - "timestamp": true - }, - "dns": { - "servers": [ - { - "tag": "google", - "address": "tls://8.8.8.8" - }, - { - "tag": "local", - "address": "https://223.5.5.5/dns-query", - "detour": "direct" - }, - { - "tag": "remote", - "address": "fakeip" - } - ], - "rules": [ - { - "outbound": "any", - "server": "local" - }, - { - "query_type": ["A", "AAAA"], - "server": "remote" - } - ], - "fakeip": { - "enabled": true, - "inet4_range": "198.18.0.0/15", - "inet6_range": "fc00::/18" - }, - "independent_cache": true - }, - "route": { - "rule_set": [ - { - "tag": "geosite-geolocation-cn", - "type": "remote", - "format": "binary", - "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-geolocation-cn.srs", - "download_detour": "节点选择" - }, - { - "tag": "geoip-cn", - "type": "remote", - "format": "binary", - "url": "https://raw.githubusercontent.com/SagerNet/sing-geoip/rule-set/geoip-cn.srs", - "download_detour": "节点选择" - }, - { - "tag": "geosite-category-ads-all", - "type": "remote", - "format": "binary", - "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-ads-all.srs", - "download_detour": "节点选择" - }, - { - "tag": "geosite-microsoft", - "type": "remote", - "format": "binary", - "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-microsoft.srs", - "download_detour": "节点选择" - }, - { - "tag": "geosite-bilibili", - "type": "remote", - "format": "binary", - "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-bilibili.srs", - "download_detour": "节点选择" - }, - { - "tag": "geosite-bahamut", - "type": "remote", - "format": "binary", - "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-bahamut.srs", - "download_detour": "节点选择" - }, - { - "tag": "geosite-category-games@cn", - "type": "remote", - "format": "binary", - "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-games@cn.srs", - "download_detour": "节点选择" - }, - { - "tag": "geosite-category-games", - "type": "remote", - "format": "binary", - "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-games.srs", - "download_detour": "节点选择" - } - ], - "rules": [ - { - "type": "logical", - "mode": "or", - "rules": [ - { - "protocol": "dns" - }, - { - "port": 53 - } - ], - "outbound": "dns-out" - }, - { - "protocol": "dns", - "outbound": "dns-out" - }, - { - "ip_is_private": true, - "outbound": "direct" - }, - { - "rule_set": ["geoip-cn", "geosite-geolocation-cn"], - "outbound": "direct" - }, - { - "rule_set": "geosite-category-ads-all", - "outbound": "Ads" - }, - { - "rule_set": "geosite-microsoft", - "outbound": "Microsoft" - }, - { - "rule_set": "geosite-bilibili", - "outbound": "Bilibili" - }, - { - "rule_set": "geosite-category-games@cn", - "outbound": "Games(中国)" - }, - { - "rule_set": "geosite-category-games", - "outbound": "Games(全球)" - }, - { - "rule_set": "geosite-bahamut", - "outbound": "Bahamut" - } - ], - "final": "节点选择", - "auto_detect_interface": true - }, - "inbounds": [ - { - "type": "tun", - "inet4_address": "172.19.0.1/30", - "inet6_address": "fdfe:dcba:9876::1/126", - "auto_route": true, - "strict_route": true - } - ], - "outbounds": [ - { - "type": "selector", - "tag": "节点选择", - "outbounds": ["", "direct"], - "interrupt_exist_connections": true - }, - { - "type": "selector", - "tag": "Ads", - "outbounds": ["direct", "block"], - "default": "block", - "interrupt_exist_connections": true - }, - { - "type": "selector", - "tag": "Microsoft", - "outbounds": ["节点选择", "", "direct"], - "default": "节点选择", - "interrupt_exist_connections": true - }, - { - "type": "selector", - "tag": "Bilibili", - "outbounds": ["节点选择", "", "direct"], - "default": "direct", - "interrupt_exist_connections": true - }, - { - "type": "selector", - "tag": "Games(全球)", - "outbounds": ["节点选择", "", "direct"], - "default": "节点选择", - "interrupt_exist_connections": true - }, - { - "type": "selector", - "tag": "Games(中国)", - "outbounds": ["节点选择", "", "direct"], - "default": "direct", - "interrupt_exist_connections": true - }, - { - "type": "selector", - "tag": "Bahamut", - "outbounds": ["节点选择", "", "direct"], - "default": "节点选择", - "interrupt_exist_connections": true - }, - { - "type": "direct", - "tag": "direct" - }, - { - "type": "block", - "tag": "block" - }, - { - "type": "dns", - "tag": "dns-out" - } - ], - "experimental": { - "cache_file": { - "enabled": true, - "path": "cache.db" - }, - "clash_api": { - "external_controller": "127.0.0.1:9090", - "external_ui": "./ui", - "external_ui_download_detour": "节点选择" - } - } -} diff --git a/template/tun-with-dns-leaks.json b/template/tun-with-dns-leaks.json new file mode 100644 index 0000000..3db9a90 --- /dev/null +++ b/template/tun-with-dns-leaks.json @@ -0,0 +1,233 @@ +{ + "log": { + "level": "info", + "timestamp": true + }, + "dns": { + "servers": [ + { + "tag": "google", + "address": "tls://8.8.8.8" + }, + { + "tag": "local", + "address": "https://223.5.5.5/dns-query", + "detour": "direct" + } + ], + "rules": [ + { + "outbound": "any", + "server": "local" + }, + { + "clash_mode": "Direct", + "server": "local" + }, + { + "clash_mode": "Global", + "server": "google" + }, + { + "rule_set": "geosite-geolocation-cn", + "server": "local" + } + ] + }, + "route": { + "rule_set": [ + { + "tag": "geosite-geolocation-cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-geolocation-cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-geolocation-!cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-geolocation-!cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geoip-cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geoip/rule-set/geoip-cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-category-ads-all", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-ads-all.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-microsoft", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-microsoft.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-bilibili", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-bilibili.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-bahamut", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-bahamut.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-category-games@cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-games@cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-category-games", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-games.srs", + "download_detour": "节点选择" + } + ], + "rules": [ + { + "type": "logical", + "mode": "or", + "rules": [ + { + "protocol": "dns" + }, + { + "port": 53 + } + ], + "outbound": "dns-out" + }, + { + "ip_is_private": true, + "outbound": "direct" + }, + { + "rule_set": ["geoip-cn", "geosite-geolocation-cn"], + "outbound": "direct" + }, + { + "rule_set": "geosite-category-ads-all", + "outbound": "Ads" + }, + { + "rule_set": "geosite-microsoft", + "outbound": "Microsoft" + }, + { + "rule_set": "geosite-bilibili", + "outbound": "Bilibili" + }, + { + "rule_set": "geosite-category-games@cn", + "outbound": "Games(中国)" + }, + { + "rule_set": "geosite-category-games", + "outbound": "Games(全球)" + }, + { + "rule_set": "geosite-bahamut", + "outbound": "Bahamut" + } + ], + "final": "节点选择", + "auto_detect_interface": true + }, + "inbounds": [ + { + "type": "tun", + "inet4_address": "172.19.0.1/30", + "inet6_address": "fdfe:dcba:9876::1/126", + "auto_route": true, + "strict_route": false, + "sniff": true, + "sniff_override_destination": false + } + ], + "outbounds": [ + { + "type": "selector", + "tag": "节点选择", + "outbounds": ["", "direct"], + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Ads", + "outbounds": ["direct", "block"], + "default": "block", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Microsoft", + "outbounds": ["节点选择", "", "direct"], + "default": "节点选择", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Bilibili", + "outbounds": ["节点选择", "", "direct"], + "default": "direct", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Games(全球)", + "outbounds": ["节点选择", "", "direct"], + "default": "节点选择", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Games(中国)", + "outbounds": ["节点选择", "", "direct"], + "default": "direct", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Bahamut", + "outbounds": ["节点选择", "", "direct"], + "default": "节点选择", + "interrupt_exist_connections": true + }, + { + "type": "direct", + "tag": "direct" + }, + { + "type": "block", + "tag": "block" + }, + { + "type": "dns", + "tag": "dns-out" + } + ], + "experimental": { + "clash_api": { + "external_controller": "127.0.0.1:9090", + "external_ui": "./ui", + "external_ui_download_detour": "节点选择" + } + } +} diff --git a/template/tun-without-dns-leaks.json b/template/tun-without-dns-leaks.json new file mode 100644 index 0000000..7236340 --- /dev/null +++ b/template/tun-without-dns-leaks.json @@ -0,0 +1,252 @@ +{ + "log": { + "level": "info", + "timestamp": true + }, + "dns": { + "servers": [ + { + "tag": "google", + "address": "tls://8.8.8.8" + }, + { + "tag": "local", + "address": "https://223.5.5.5/dns-query", + "detour": "direct" + } + ], + "rules": [ + { + "outbound": "any", + "server": "local" + }, + { + "clash_mode": "Direct", + "server": "local" + }, + { + "clash_mode": "Global", + "server": "google" + }, + { + "rule_set": "geosite-geolocation-cn", + "server": "local" + }, + { + "type": "logical", + "mode": "and", + "rules": [ + { + "rule_set": "geosite-geolocation-!cn" + }, + { + "rule_set": "geoip-cn" + } + ], + "server": "google", + "client_subnet": "114.114.114.114" + } + ] + }, + "route": { + "rule_set": [ + { + "tag": "geosite-geolocation-cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-geolocation-cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-geolocation-!cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-geolocation-!cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geoip-cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geoip/rule-set/geoip-cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-category-ads-all", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-ads-all.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-microsoft", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-microsoft.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-bilibili", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-bilibili.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-bahamut", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-bahamut.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-category-games@cn", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-games@cn.srs", + "download_detour": "节点选择" + }, + { + "tag": "geosite-category-games", + "type": "remote", + "format": "binary", + "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-games.srs", + "download_detour": "节点选择" + } + ], + "rules": [ + { + "type": "logical", + "mode": "or", + "rules": [ + { + "protocol": "dns" + }, + { + "port": 53 + } + ], + "outbound": "dns-out" + }, + { + "ip_is_private": true, + "outbound": "direct" + }, + { + "rule_set": ["geoip-cn", "geosite-geolocation-cn"], + "outbound": "direct" + }, + { + "rule_set": "geosite-category-ads-all", + "outbound": "Ads" + }, + { + "rule_set": "geosite-microsoft", + "outbound": "Microsoft" + }, + { + "rule_set": "geosite-bilibili", + "outbound": "Bilibili" + }, + { + "rule_set": "geosite-category-games@cn", + "outbound": "Games(中国)" + }, + { + "rule_set": "geosite-category-games", + "outbound": "Games(全球)" + }, + { + "rule_set": "geosite-bahamut", + "outbound": "Bahamut" + } + ], + "final": "节点选择", + "auto_detect_interface": true + }, + "inbounds": [ + { + "type": "tun", + "inet4_address": "172.19.0.1/30", + "inet6_address": "fdfe:dcba:9876::1/126", + "auto_route": true, + "strict_route": false, + "sniff": true, + "sniff_override_destination": false + } + ], + "outbounds": [ + { + "type": "selector", + "tag": "节点选择", + "outbounds": ["", "direct"], + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Ads", + "outbounds": ["direct", "block"], + "default": "block", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Microsoft", + "outbounds": ["节点选择", "", "direct"], + "default": "节点选择", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Bilibili", + "outbounds": ["节点选择", "", "direct"], + "default": "direct", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Games(全球)", + "outbounds": ["节点选择", "", "direct"], + "default": "节点选择", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Games(中国)", + "outbounds": ["节点选择", "", "direct"], + "default": "direct", + "interrupt_exist_connections": true + }, + { + "type": "selector", + "tag": "Bahamut", + "outbounds": ["节点选择", "", "direct"], + "default": "节点选择", + "interrupt_exist_connections": true + }, + { + "type": "direct", + "tag": "direct" + }, + { + "type": "block", + "tag": "block" + }, + { + "type": "dns", + "tag": "dns-out" + } + ], + "experimental": { + "cache_file": { + "enabled": true, + "store_rdrc": true + }, + "clash_api": { + "default_mode": "Enhanced", + "external_controller": "127.0.0.1:9090", + "external_ui": "./ui", + "external_ui_download_detour": "节点选择" + } + } +}