mirror of
				https://github.com/bestnite/sub2clash.git
				synced 2025-11-04 04:40:36 +00:00 
			
		
		
		
	Compare commits
	
		
			72 Commits
		
	
	
		
			v0.1.0-alp
			...
			v1.0.3-rc
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						1e8a79c2d2
	
				 | 
					
					
						|||
| 
						
						
							
						
						be656cca57
	
				 | 
					
					
						|||
| 
						
						
							
						
						23a85f573b
	
				 | 
					
					
						|||
| 
						
						
							
						
						fce75baed4
	
				 | 
					
					
						|||
| f5686561f9 | |||
| 83c24170a0 | |||
| 80d91efca4 | |||
| 83a728a415 | |||
| a178d06248 | |||
| 
						 | 
					99d36d93d8 | ||
| 0a9892503d | |||
| ff81d03492 | |||
| 0fa95888cb | |||
| b44703fa0f | |||
| b256c5e809 | |||
| 307c36aa8d | |||
| 06da2e91c2 | |||
| 33d37e631b | |||
| c1012750ff | |||
| 69deed91df | |||
| 6a780a5e27 | |||
| f88ae52a29 | |||
| 0c8bbac2e6 | |||
| c4554d9030 | |||
| 8db2c46bf0 | |||
| 8b3ae45623 | |||
| cdc8ef7e32 | |||
| 
						 | 
					62229fba97 | ||
| b80afd97f1 | |||
| 2a042968d0 | |||
| cdf69ce65f | |||
| 2d8508f390 | |||
| 73616c98a3 | |||
| 44163d30e1 | |||
| a2e97aaa01 | |||
| 4f3c2bb280 | |||
| 1b662de245 | |||
| 4a9297f4a3 | |||
| fcb1358846 | |||
| da9a17201b | |||
| 5b7a94e65c | |||
| b5fcbab1a5 | |||
| 
						 | 
					0b8299f432 | ||
| 
						 | 
					84c5a6e5f4 | ||
| 
						 | 
					06887d91ac | ||
| db00433931 | |||
| 
						 | 
					5b3a12f00d | ||
| d4d7010d8f | |||
| 
						 | 
					2331cd4d18 | ||
| 
						 | 
					88d8653ab5 | ||
| 
						 | 
					cc0b73d7a4 | ||
| b57e4cf49f | |||
| 
						 | 
					cc80e237d6 | ||
| 
						 | 
					fefb4b895a | ||
| 66f214ae10 | |||
| f7dc78aabc | |||
| 6bb2d16e4b | |||
| 98ef93c7bb | |||
| 6e09c44d17 | |||
| 42fd251eb5 | |||
| e504a6cca4 | |||
| 3cfa4bdf24 | |||
| dedbf2bc03 | |||
| 
						 | 
					7158ad467a | ||
| 
						 | 
					fd22cd1499 | ||
| 0946412ea7 | |||
| 98bca0a7ac | |||
| 036907fba4 | |||
| 3e720ec14d | |||
| b73a02bdbf | |||
| 25e47453cb | |||
| 3330412243 | 
@@ -1,7 +0,0 @@
 | 
				
			|||||||
PORT=8011
 | 
					 | 
				
			||||||
META_TEMPLATE=meta_template.json
 | 
					 | 
				
			||||||
CLASH_TEMPLATE=clash_template.json
 | 
					 | 
				
			||||||
REQUEST_RETRY_TIMES=3
 | 
					 | 
				
			||||||
REQUEST_MAX_FILE_SIZE=1048576
 | 
					 | 
				
			||||||
CACHE_EXPIRE=300
 | 
					 | 
				
			||||||
LOG_LEVEL=info
 | 
					 | 
				
			||||||
							
								
								
									
										1
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					* text=auto eol=lf
 | 
				
			||||||
							
								
								
									
										8
									
								
								.github/workflows/docker.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								.github/workflows/docker.yml
									
									
									
									
										vendored
									
									
								
							@@ -18,11 +18,12 @@ jobs:
 | 
				
			|||||||
        with:
 | 
					        with:
 | 
				
			||||||
          images: |
 | 
					          images: |
 | 
				
			||||||
            nite07/sub2clash
 | 
					            nite07/sub2clash
 | 
				
			||||||
            ghcr.io/nitezs/sub2clash
 | 
					            ghcr.io/bestnite/sub2clash
 | 
				
			||||||
          tags: |
 | 
					          tags: |
 | 
				
			||||||
            type=semver,pattern={{version}}
 | 
					            type=semver,pattern={{version}}
 | 
				
			||||||
            type=semver,pattern={{major}}.{{minor}}
 | 
					            type=semver,pattern={{major}}.{{minor}}
 | 
				
			||||||
            type=semver,pattern={{major}}
 | 
					            type=semver,pattern={{major}}
 | 
				
			||||||
 | 
					            type=match,pattern=(alpha|beta|rc),group=1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Set up QEMU
 | 
					      - name: Set up QEMU
 | 
				
			||||||
        uses: docker/setup-qemu-action@v3
 | 
					        uses: docker/setup-qemu-action@v3
 | 
				
			||||||
@@ -44,10 +45,13 @@ jobs:
 | 
				
			|||||||
          password: ${{ secrets.GITHUB_TOKEN }}
 | 
					          password: ${{ secrets.GITHUB_TOKEN }}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Build and push
 | 
					      - name: Build and push
 | 
				
			||||||
        uses: docker/build-push-action@v5
 | 
					        uses: docker/build-push-action@v6
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          build-args: |
 | 
					          build-args: |
 | 
				
			||||||
            "version=${{ github.ref_name }}"
 | 
					            "version=${{ github.ref_name }}"
 | 
				
			||||||
          push: true
 | 
					          push: true
 | 
				
			||||||
          tags: ${{ steps.meta.outputs.tags }}
 | 
					          tags: ${{ steps.meta.outputs.tags }}
 | 
				
			||||||
          labels: ${{ steps.meta.outputs.labels }}
 | 
					          labels: ${{ steps.meta.outputs.labels }}
 | 
				
			||||||
 | 
					          platforms: linux/amd64,linux/arm64,linux/arm/v7
 | 
				
			||||||
 | 
					          file: Containerfile
 | 
				
			||||||
 | 
					          
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										11
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										11
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
								
							@@ -13,13 +13,18 @@ jobs:
 | 
				
			|||||||
    runs-on: ubuntu-latest
 | 
					    runs-on: ubuntu-latest
 | 
				
			||||||
    steps:
 | 
					    steps:
 | 
				
			||||||
      - name: Checkout
 | 
					      - name: Checkout
 | 
				
			||||||
        uses: actions/checkout@v4
 | 
					        uses: actions/checkout@v5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Set up Go
 | 
					      - name: Set up Go
 | 
				
			||||||
        uses: actions/setup-go@v4
 | 
					        uses: actions/setup-go@v5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      - name: Install UPX
 | 
				
			||||||
 | 
					        uses: crazy-max/ghaction-upx@v3
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          install-only: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Run GoReleaser
 | 
					      - name: Run GoReleaser
 | 
				
			||||||
        uses: goreleaser/goreleaser-action@v5
 | 
					        uses: goreleaser/goreleaser-action@v6
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          distribution: goreleaser
 | 
					          distribution: goreleaser
 | 
				
			||||||
          version: latest
 | 
					          version: latest
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,7 +1,11 @@
 | 
				
			|||||||
.idea
 | 
					.idea
 | 
				
			||||||
 | 
					.vscode
 | 
				
			||||||
dist
 | 
					dist
 | 
				
			||||||
subs
 | 
					subs
 | 
				
			||||||
logs
 | 
					logs
 | 
				
			||||||
data
 | 
					data
 | 
				
			||||||
.env
 | 
					.env
 | 
				
			||||||
.vscode/settings.json
 | 
					.vscode/settings.json
 | 
				
			||||||
 | 
					config.yaml
 | 
				
			||||||
 | 
					config.yml
 | 
				
			||||||
 | 
					config.json
 | 
				
			||||||
@@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					version: 2
 | 
				
			||||||
project_name: sub2clash
 | 
					project_name: sub2clash
 | 
				
			||||||
builds:
 | 
					builds:
 | 
				
			||||||
  - env:
 | 
					  - env:
 | 
				
			||||||
@@ -9,19 +10,15 @@ builds:
 | 
				
			|||||||
    goarch:
 | 
					    goarch:
 | 
				
			||||||
      - amd64
 | 
					      - amd64
 | 
				
			||||||
      - arm64
 | 
					      - arm64
 | 
				
			||||||
      - arm
 | 
					 | 
				
			||||||
      - "386"
 | 
					      - "386"
 | 
				
			||||||
    goarm:
 | 
					 | 
				
			||||||
      - "6"
 | 
					 | 
				
			||||||
      - "7"
 | 
					 | 
				
			||||||
    ldflags:
 | 
					    ldflags:
 | 
				
			||||||
      - -s -w -X sub2clash/constant.Version={{ .Version }}
 | 
					      - -s -w -X github.com/bestnite/sub2clash/constant.Version={{ .Version }}
 | 
				
			||||||
    flags:
 | 
					    flags:
 | 
				
			||||||
      - -trimpath
 | 
					      - -trimpath
 | 
				
			||||||
archives:
 | 
					archives:
 | 
				
			||||||
  - format: tar.gz
 | 
					  - formats: ["tar.gz"]
 | 
				
			||||||
    format_overrides:
 | 
					    format_overrides:
 | 
				
			||||||
      - format: zip
 | 
					      - formats: ["zip"]
 | 
				
			||||||
        goos: windows
 | 
					        goos: windows
 | 
				
			||||||
    wrap_in_directory: true
 | 
					    wrap_in_directory: true
 | 
				
			||||||
    files:
 | 
					    files:
 | 
				
			||||||
@@ -30,3 +27,19 @@ archives:
 | 
				
			|||||||
      - templates
 | 
					      - templates
 | 
				
			||||||
release:
 | 
					release:
 | 
				
			||||||
  draft: true
 | 
					  draft: true
 | 
				
			||||||
 | 
					upx:
 | 
				
			||||||
 | 
					  - enabled: true
 | 
				
			||||||
 | 
					    compress: best
 | 
				
			||||||
 | 
					nfpms:
 | 
				
			||||||
 | 
					  - id: sub2clash
 | 
				
			||||||
 | 
					    homepage: https://github.com/bestnite/sub2clash
 | 
				
			||||||
 | 
					    maintainer: Nite <admin@nite07.com>
 | 
				
			||||||
 | 
					    license: "MIT"
 | 
				
			||||||
 | 
					    formats:
 | 
				
			||||||
 | 
					      - apk
 | 
				
			||||||
 | 
					      - deb
 | 
				
			||||||
 | 
					      - rpm
 | 
				
			||||||
 | 
					      - termux.deb
 | 
				
			||||||
 | 
					      - archlinux
 | 
				
			||||||
 | 
					    provides:
 | 
				
			||||||
 | 
					      - sub2clash
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										13
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
								
							@@ -1,13 +0,0 @@
 | 
				
			|||||||
{
 | 
					 | 
				
			||||||
    "configurations": [
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            "name": "Debug",
 | 
					 | 
				
			||||||
            "type": "go",
 | 
					 | 
				
			||||||
            "request": "launch",
 | 
					 | 
				
			||||||
            "mode": "debug",
 | 
					 | 
				
			||||||
            "program": "${workspaceFolder}/main.go",
 | 
					 | 
				
			||||||
            "output": "${workspaceFolder}/dist/main.exe",
 | 
					 | 
				
			||||||
            "buildFlags": "-ldflags '-X sub2clash/constant.Version=dev'"
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    ]
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										47
									
								
								API.md
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								API.md
									
									
									
									
									
								
							@@ -1,47 +0,0 @@
 | 
				
			|||||||
# `GET /clash`, `GET /meta`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
获取 Clash/Clash.Meta 配置链接
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| Query 参数   | 类型   | 是否必须                 | 默认值    | 说明                                                                                                                                                                                                                                      |
 | 
					 | 
				
			||||||
| ------------ | ------ | ------------------------ | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
 | 
					 | 
				
			||||||
| sub          | string | sub/proxy 至少有一项存在 | -         | 订阅链接,可以在链接结尾加上`#名称`,来给订阅中的节点加上统一前缀(可以输入多个,用 `,` 分隔)                                                                                                                                            |
 | 
					 | 
				
			||||||
| proxy        | string | sub/proxy 至少有一项存在 | -         | 节点分享链接(可以输入多个,用 `,` 分隔)                                                                                                                                                                                                 |
 | 
					 | 
				
			||||||
| refresh      | bool   | 否                       | `false`   | 强制刷新配置(默认缓存 5 分钟)                                                                                                                                                                                                           |
 | 
					 | 
				
			||||||
| template     | string | 否                       | -         | 外部模板链接或内部模板名称                                                                                                                                                                                                                |
 | 
					 | 
				
			||||||
| ruleProvider | string | 否                       | -         | 格式 `[Behavior,Url,Group,Prepend,Name],[Behavior,Url,Group,Prepend,Name]...`,其中 `Group` 是该规则集使用的策略组名,`Prepend` 为 bool 类型,如果为 `true` 规则将被添加到规则列表顶部,否则添加到规则列表底部(会调整到 MATCH 规则之前) |
 | 
					 | 
				
			||||||
| rule         | string | 否                       | -         | 格式 `[Rule,Prepend],[Rule,Prepend]...`,其中 `Prepend` 为 bool 类型,如果为 `true` 规则将被添加到规则列表顶部,否则添加到规则列表底部(会调整到 MATCH 规则之前)                                                                         |
 | 
					 | 
				
			||||||
| autoTest     | bool   | 否                       | `false`   | 国家策略组是否自动测速                                                                                                                                                                                                                    |
 | 
					 | 
				
			||||||
| lazy         | bool   | 否                       | `false`   | 自动测速是否启用 lazy                                                                                                                                                                                                                     |
 | 
					 | 
				
			||||||
| sort         | string | 否                       | `nameasc` | 国家策略组排序策略,可选值 `nameasc`、`namedesc`、`sizeasc`、`sizedesc`                                                                                                                                                                   |
 | 
					 | 
				
			||||||
| replace      | string | 否                       | -         | 通过正则表达式重命名节点,格式 `[<ReplaceKey>,<ReplaceTo>],[<ReplaceKey>,<ReplaceTo>]...`                                                                                                                                                 |
 | 
					 | 
				
			||||||
| remove       | string | 否                       | -         | 通过正则表达式删除节点                                                                                                                                                                                                                    |
 | 
					 | 
				
			||||||
| nodeList     | bool   | 否                       | `false`   | 只输出节点                                                                                                                                                                                                                                |
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# `POST /short`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
获取短链,Content-Type 为 `application/json`
 | 
					 | 
				
			||||||
具体参考使用可以参考 [api\templates\index.html](api/static/index.html)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| Body 参数 | 类型   | 是否必须 | 默认值 | 说明                      |
 | 
					 | 
				
			||||||
| --------- | ------ | -------- | ------ | ------------------------- |
 | 
					 | 
				
			||||||
| url       | string | 是       | -      | 需要转换的 Query 参数部分 |
 | 
					 | 
				
			||||||
| password  | string | 否       | -      | 短链密码                  |
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# `GET /s/:hash`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
短链跳转
 | 
					 | 
				
			||||||
`hash` 为动态路由参数,可以通过 `/short` 接口获取
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| Query 参数 | 类型   | 是否必须 | 默认值 | 说明     |
 | 
					 | 
				
			||||||
| ---------- | ------ | -------- | ------ | -------- |
 | 
					 | 
				
			||||||
| password   | string | 否       | -      | 短链密码 |
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# `PUT /short`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
更新短链,Content-Type 为 `application/json`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| Body 参数 | 类型   | 是否必须 | 默认值 | 说明                      |
 | 
					 | 
				
			||||||
| --------- | ------ | -------- | ------ | ------------------------- |
 | 
					 | 
				
			||||||
| url       | string | 是       | -      | 需要转换的 Query 参数部分 |
 | 
					 | 
				
			||||||
| password  | string | 否       | -      | 短链密码                  |
 | 
					 | 
				
			||||||
| hash      | string | 是       | -      | 短链 hash                 |
 | 
					 | 
				
			||||||
@@ -1,10 +1,10 @@
 | 
				
			|||||||
FROM golang:1.21-alpine as builder
 | 
					FROM golang:1.25 as builder
 | 
				
			||||||
LABEL authors="nite07"
 | 
					LABEL authors="nite07"
 | 
				
			||||||
WORKDIR /app
 | 
					WORKDIR /app
 | 
				
			||||||
COPY . .
 | 
					COPY . .
 | 
				
			||||||
RUN go mod download
 | 
					RUN go mod download
 | 
				
			||||||
ARG version
 | 
					ARG version
 | 
				
			||||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w -X sub2clash/constant.Version=${version}" -o sub2clash .
 | 
					RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w -X github.com/bestnite/sub2clash/constant.Version=${version}" -o sub2clash .
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FROM alpine:latest
 | 
					FROM alpine:latest
 | 
				
			||||||
WORKDIR /app
 | 
					WORKDIR /app
 | 
				
			||||||
							
								
								
									
										139
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										139
									
								
								README.md
									
									
									
									
									
								
							@@ -1,14 +1,14 @@
 | 
				
			|||||||
# sub2clash
 | 
					# sub2clash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
将订阅链接转换为 Clash、Clash.Meta 配置  
 | 
					将订阅链接转换为 Clash、Clash.Meta 配置  
 | 
				
			||||||
[预览](https://www.nite07.com/sub)
 | 
					[预览](https://clash.nite07.com/)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 特性
 | 
					## 特性
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- 开箱即用的规则、策略组配置
 | 
					- 开箱即用的规则、策略组配置
 | 
				
			||||||
- 自动根据节点名称按国家划分策略组
 | 
					- 自动根据节点名称按国家划分策略组
 | 
				
			||||||
-   支持多订阅合并
 | 
					- 多订阅合并
 | 
				
			||||||
-   支持添加自定义 Rule Provider、Rule
 | 
					- 自定义 Rule Provider、Rule
 | 
				
			||||||
- 支持多种协议
 | 
					- 支持多种协议
 | 
				
			||||||
  - Shadowsocks
 | 
					  - Shadowsocks
 | 
				
			||||||
  - ShadowsocksR
 | 
					  - ShadowsocksR
 | 
				
			||||||
@@ -17,32 +17,122 @@
 | 
				
			|||||||
  - Trojan
 | 
					  - Trojan
 | 
				
			||||||
  - Hysteria (Clash.Meta)
 | 
					  - Hysteria (Clash.Meta)
 | 
				
			||||||
  - Hysteria2 (Clash.Meta)
 | 
					  - Hysteria2 (Clash.Meta)
 | 
				
			||||||
 | 
					  - Socks5
 | 
				
			||||||
 | 
					  - Anytls (Clash.Meta)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 使用
 | 
					## 使用
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 运行
 | 
					### 部署
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-   [docker compose](./docker-compose.yml)
 | 
					- [docker compose](./compose.yml)
 | 
				
			||||||
-   运行[二进制文件](https://github.com/nitezs/sub2clash/releases/latest)
 | 
					- 运行[二进制文件](https://github.com/bestnite/sub2clash/releases/latest)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 配置
 | 
					### 配置
 | 
				
			||||||
 | 
					
 | 
				
			||||||
可以通过编辑 .env 文件来修改默认配置,docker 直接添加环境变量
 | 
					支持多种配置方式,按优先级排序:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 变量名                | 说明                                           | 默认值                |
 | 
					1. **配置文件**:支持多种格式(YAML、JSON),按以下优先级搜索:
 | 
				
			||||||
| --------------------- | ---------------------------------------------- | --------------------- |
 | 
					   - `config.yaml` / `config.yml`
 | 
				
			||||||
| PORT                  | 端口                                           | `8011`                |
 | 
					   - `config.json`
 | 
				
			||||||
| META_TEMPLATE         | 默认 meta 模板文件名                           | `template_meta.yaml`  |
 | 
					   - `sub2clash.yaml` / `sub2clash.yml`
 | 
				
			||||||
| CLASH_TEMPLATE        | 默认 clash 模板文件名                          | `template_clash.yaml` |
 | 
					   - `sub2clash.json`
 | 
				
			||||||
| REQUEST_RETRY_TIMES   | Get 请求重试次数                               | `3`                   |
 | 
					2. **环境变量**:使用 `SUB2CLASH_` 前缀,例如 `SUB2CLASH_ADDRESS=0.0.0.0:8011`
 | 
				
			||||||
| REQUEST_MAX_FILE_SIZE | Get 请求订阅文件最大大小(byte)               | `1048576`             |
 | 
					3. **默认值**:内置默认配置
 | 
				
			||||||
| CACHE_EXPIRE          | 订阅缓存时间(秒)                             | `300`                 |
 | 
					
 | 
				
			||||||
| LOG_LEVEL             | 日志等级,可选值 `debug`,`info`,`warn`,`error` | `info`                |
 | 
					| 配置项                | 环境变量                        | 说明                                    | 默认值                                                                                               |
 | 
				
			||||||
| SHORT_LINK_LENGTH     | 短链长度                                       | `6`                   |
 | 
					| --------------------- | ------------------------------- | --------------------------------------- | ---------------------------------------------------------------------------------------------------- |
 | 
				
			||||||
 | 
					| address               | SUB2CLASH_ADDRESS               | 服务监听地址                            | `0.0.0.0:8011`                                                                                       |
 | 
				
			||||||
 | 
					| meta_template         | SUB2CLASH_META_TEMPLATE         | 默认 meta 模板 URL                      | `https://raw.githubusercontent.com/bestnite/sub2clash/refs/heads/main/templates/template_meta.yaml`  |
 | 
				
			||||||
 | 
					| clash_template        | SUB2CLASH_CLASH_TEMPLATE        | 默认 clash 模板 URL                     | `https://raw.githubusercontent.com/bestnite/sub2clash/refs/heads/main/templates/template_clash.yaml` |
 | 
				
			||||||
 | 
					| request_retry_times   | SUB2CLASH_REQUEST_RETRY_TIMES   | 请求重试次数                            | `3`                                                                                                  |
 | 
				
			||||||
 | 
					| request_max_file_size | SUB2CLASH_REQUEST_MAX_FILE_SIZE | 请求文件最大大小(byte)                | `1048576`                                                                                            |
 | 
				
			||||||
 | 
					| cache_expire          | SUB2CLASH_CACHE_EXPIRE          | 订阅缓存时间(秒)                      | `300`                                                                                                |
 | 
				
			||||||
 | 
					| log_level             | SUB2CLASH_LOG_LEVEL             | 日志等级:`debug`,`info`,`warn`,`error` | `info`                                                                                               |
 | 
				
			||||||
 | 
					| short_link_length     | SUB2CLASH_SHORT_LINK_LENGTH     | 短链长度                                | `6`                                                                                                  |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### 配置文件示例
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					参考示例文件:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- [config.example.yaml](./config.example.yaml) - YAML 格式
 | 
				
			||||||
 | 
					- [config.example.json](./config.example.json) - JSON 格式
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### API
 | 
					### API
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[API 文档](./API.md)
 | 
					#### `GET /convert/:config`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					获取 Clash/Clash.Meta 配置链接
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					| Path 参数 | 类型   | 说明                                           |
 | 
				
			||||||
 | 
					| --------- | ------ | ---------------------------------------------- |
 | 
				
			||||||
 | 
					| config    | string | Base64 URL Safe 编码后的 JSON 字符串,格式如下 |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					##### `config` JSON 结构
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					| Query 参数         | 类型              | 是否必须                 | 默认值    | 说明                                                                                                     |
 | 
				
			||||||
 | 
					| ------------------ | ----------------- | ------------------------ | --------- | -------------------------------------------------------------------------------------------------------- |
 | 
				
			||||||
 | 
					| clashType          | int               | 是                       | 1         | 配置文件类型 (1: Clash, 2: Clash.Meta)                                                                   |
 | 
				
			||||||
 | 
					| subscriptions      | []string          | sub/proxy 至少有一项存在 | -         | 订阅链接(v2ray 或 clash 格式),可以在链接结尾加上`#名称`,来给订阅中的节点加上统一前缀(可以输入多个) |
 | 
				
			||||||
 | 
					| proxies            | []string          | sub/proxy 至少有一项存在 | -         | 节点分享链接(可以输入多个)                                                                             |
 | 
				
			||||||
 | 
					| refresh            | bool              | 否                       | `false`   | 强制刷新配置(默认缓存 5 分钟)                                                                          |
 | 
				
			||||||
 | 
					| template           | string            | 否                       | -         | 外部模板链接或内部模板名称                                                                               |
 | 
				
			||||||
 | 
					| ruleProviders      | []RuleProvider    | 否                       | -         | 规则                                                                                                     |
 | 
				
			||||||
 | 
					| rules              | []Rule            | 否                       | -         | 规则                                                                                                     |
 | 
				
			||||||
 | 
					| autoTest           | bool              | 否                       | `false`   | 国家策略组是否自动测速                                                                                   |
 | 
				
			||||||
 | 
					| lazy               | bool              | 否                       | `false`   | 自动测速是否启用 lazy                                                                                    |
 | 
				
			||||||
 | 
					| sort               | string            | 否                       | `nameasc` | 国家策略组排序策略,可选值 `nameasc`、`namedesc`、`sizeasc`、`sizedesc`                                  |
 | 
				
			||||||
 | 
					| replace            | map[string]string | 否                       | -         | 通过正则表达式重命名节点                                                                                 |
 | 
				
			||||||
 | 
					| remove             | string            | 否                       | -         | 通过正则表达式删除节点                                                                                   |
 | 
				
			||||||
 | 
					| nodeList           | bool              | 否                       | `false`   | 只输出节点                                                                                               |
 | 
				
			||||||
 | 
					| ignoreCountryGroup | bool              | 否                       | `false`   | 是否忽略国家分组                                                                                         |
 | 
				
			||||||
 | 
					| userAgent          | string            | 否                       | -         | 订阅 user-agent                                                                                          |
 | 
				
			||||||
 | 
					| useUDP             | bool              | 否                       | `false`   | 是否使用 UDP                                                                                             |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					###### `RuleProvider` 结构
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					| 字段     | 类型   | 说明                                                             |
 | 
				
			||||||
 | 
					| -------- | ------ | ---------------------------------------------------------------- |
 | 
				
			||||||
 | 
					| behavior | string | rule-set 的 behavior                                             |
 | 
				
			||||||
 | 
					| url      | string | rule-set 的 url                                                  |
 | 
				
			||||||
 | 
					| group    | string | 该规则集使用的策略组名                                           |
 | 
				
			||||||
 | 
					| prepend  | bool   | 如果为 `true` 规则将被添加到规则列表顶部,否则添加到规则列表底部 |
 | 
				
			||||||
 | 
					| name     | string | 该 rule-provider 的名称,不能重复                                |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					###### `Rule` 结构
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					| 字段    | 类型   | 说明                                                             |
 | 
				
			||||||
 | 
					| ------- | ------ | ---------------------------------------------------------------- |
 | 
				
			||||||
 | 
					| rule    | string | 规则                                                             |
 | 
				
			||||||
 | 
					| prepend | bool   | 如果为 `true` 规则将被添加到规则列表顶部,否则添加到规则列表底部 |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### `POST /short`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					获取短链,Content-Type 为 `application/json`
 | 
				
			||||||
 | 
					具体参考使用可以参考 [api\templates\index.html](api/static/index.html)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					| Body 参数 | 类型   | 是否必须 | 默认值 | 说明                      |
 | 
				
			||||||
 | 
					| --------- | ------ | -------- | ------ | ------------------------- |
 | 
				
			||||||
 | 
					| url       | string | 是       | -      | 需要转换的 Query 参数部分 |
 | 
				
			||||||
 | 
					| password  | string | 否       | -      | 短链密码                  |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### `GET /s/:hash`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					短链跳转
 | 
				
			||||||
 | 
					`hash` 为动态路由参数,可以通过 `/short` 接口获取
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					| Query 参数 | 类型   | 是否必须 | 默认值 | 说明     |
 | 
				
			||||||
 | 
					| ---------- | ------ | -------- | ------ | -------- |
 | 
				
			||||||
 | 
					| password   | string | 否       | -      | 短链密码 |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### `PUT /short`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					更新短链,Content-Type 为 `application/json`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					| Body 参数 | 类型   | 是否必须 | 默认值 | 说明                      |
 | 
				
			||||||
 | 
					| --------- | ------ | -------- | ------ | ------------------------- |
 | 
				
			||||||
 | 
					| url       | string | 是       | -      | 需要转换的 Query 参数部分 |
 | 
				
			||||||
 | 
					| password  | string | 否       | -      | 短链密码                  |
 | 
				
			||||||
 | 
					| hash      | string | 是       | -      | 短链 hash                 |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 模板
 | 
					### 模板
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -57,3 +147,16 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
- [Clash](./templates/template_clash.yaml)
 | 
					- [Clash](./templates/template_clash.yaml)
 | 
				
			||||||
- [Clash.Meta](./templates/template_meta.yaml)
 | 
					- [Clash.Meta](./templates/template_meta.yaml)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 开发
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### 添加新协议支持
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					添加新协议支持需要实现以下组件:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. 在 `parser` 目录下实现协议解析器,用于解析节点链接
 | 
				
			||||||
 | 
					2. 在 `model/proxy` 目录下定义协议结构体
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 贡献者
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[](https://github.com/bestnite/sub2clash/graphs/contributors)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,43 +0,0 @@
 | 
				
			|||||||
package handler
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
	"sub2clash/config"
 | 
					 | 
				
			||||||
	"sub2clash/model"
 | 
					 | 
				
			||||||
	"sub2clash/validator"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
	"gopkg.in/yaml.v3"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func SubmodHandler(c *gin.Context) {
 | 
					 | 
				
			||||||
	// 从请求中获取参数
 | 
					 | 
				
			||||||
	query, err := validator.ParseQuery(c)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.String(http.StatusBadRequest, err.Error())
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	sub, err := BuildSub(model.Clash, query, config.Default.ClashTemplate)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.String(http.StatusInternalServerError, err.Error())
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// 输出
 | 
					 | 
				
			||||||
	if query.NodeListMode {
 | 
					 | 
				
			||||||
		nodelist := model.NodeList{}
 | 
					 | 
				
			||||||
		nodelist.Proxies = sub.Proxies
 | 
					 | 
				
			||||||
		marshal, err := yaml.Marshal(nodelist)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			c.String(http.StatusInternalServerError, "YAML序列化失败: "+err.Error())
 | 
					 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		c.String(http.StatusOK, string(marshal))
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	marshal, err := yaml.Marshal(sub)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.String(http.StatusInternalServerError, "YAML序列化失败: "+err.Error())
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	c.String(http.StatusOK, string(marshal))
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,290 +0,0 @@
 | 
				
			|||||||
package handler
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"crypto/sha256"
 | 
					 | 
				
			||||||
	"encoding/hex"
 | 
					 | 
				
			||||||
	"errors"
 | 
					 | 
				
			||||||
	"net/url"
 | 
					 | 
				
			||||||
	"regexp"
 | 
					 | 
				
			||||||
	"sort"
 | 
					 | 
				
			||||||
	"strconv"
 | 
					 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
	"sub2clash/common"
 | 
					 | 
				
			||||||
	"sub2clash/logger"
 | 
					 | 
				
			||||||
	"sub2clash/model"
 | 
					 | 
				
			||||||
	"sub2clash/parser"
 | 
					 | 
				
			||||||
	"sub2clash/validator"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"go.uber.org/zap"
 | 
					 | 
				
			||||||
	"gopkg.in/yaml.v3"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func BuildSub(clashType model.ClashType, query validator.SubValidator, template string) (
 | 
					 | 
				
			||||||
	*model.Subscription, error,
 | 
					 | 
				
			||||||
) {
 | 
					 | 
				
			||||||
	// 定义变量
 | 
					 | 
				
			||||||
	var temp = &model.Subscription{}
 | 
					 | 
				
			||||||
	var sub = &model.Subscription{}
 | 
					 | 
				
			||||||
	var err error
 | 
					 | 
				
			||||||
	var templateBytes []byte
 | 
					 | 
				
			||||||
	// 加载模板
 | 
					 | 
				
			||||||
	if query.Template != "" {
 | 
					 | 
				
			||||||
		template = query.Template
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if strings.HasPrefix(template, "http") {
 | 
					 | 
				
			||||||
		templateBytes, err = common.LoadSubscription(template, query.Refresh)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			logger.Logger.Debug(
 | 
					 | 
				
			||||||
				"load template failed", zap.String("template", template), zap.Error(err),
 | 
					 | 
				
			||||||
			)
 | 
					 | 
				
			||||||
			return nil, errors.New("加载模板失败: " + err.Error())
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		unescape, err := url.QueryUnescape(template)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return nil, errors.New("加载模板失败: " + err.Error())
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		templateBytes, err = common.LoadTemplate(unescape)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			logger.Logger.Debug(
 | 
					 | 
				
			||||||
				"load template failed", zap.String("template", template), zap.Error(err),
 | 
					 | 
				
			||||||
			)
 | 
					 | 
				
			||||||
			return nil, errors.New("加载模板失败: " + err.Error())
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// 解析模板
 | 
					 | 
				
			||||||
	err = yaml.Unmarshal(templateBytes, &temp)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		logger.Logger.Debug("parse template failed", zap.Error(err))
 | 
					 | 
				
			||||||
		return nil, errors.New("解析模板失败: " + err.Error())
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	var proxyList []model.Proxy
 | 
					 | 
				
			||||||
	// 加载订阅
 | 
					 | 
				
			||||||
	for i := range query.Subs {
 | 
					 | 
				
			||||||
		data, err := common.LoadSubscription(query.Subs[i], query.Refresh)
 | 
					 | 
				
			||||||
		subName := ""
 | 
					 | 
				
			||||||
		if strings.Contains(query.Subs[i], "#") {
 | 
					 | 
				
			||||||
			subName = query.Subs[i][strings.LastIndex(query.Subs[i], "#")+1:]
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			logger.Logger.Debug(
 | 
					 | 
				
			||||||
				"load subscription failed", zap.String("url", query.Subs[i]), zap.Error(err),
 | 
					 | 
				
			||||||
			)
 | 
					 | 
				
			||||||
			return nil, errors.New("加载订阅失败: " + err.Error())
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		// 解析订阅
 | 
					 | 
				
			||||||
		err = yaml.Unmarshal(data, &sub)
 | 
					 | 
				
			||||||
		var newProxies []model.Proxy
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			reg, _ := regexp.Compile("(ssr|ss|vmess|trojan|vless|hysteria|hy2|hysteria2)://")
 | 
					 | 
				
			||||||
			if reg.Match(data) {
 | 
					 | 
				
			||||||
				p := common.ParseProxy(strings.Split(string(data), "\n")...)
 | 
					 | 
				
			||||||
				newProxies = p
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				// 如果无法直接解析,尝试Base64解码
 | 
					 | 
				
			||||||
				base64, err := parser.DecodeBase64(string(data))
 | 
					 | 
				
			||||||
				if err != nil {
 | 
					 | 
				
			||||||
					logger.Logger.Debug(
 | 
					 | 
				
			||||||
						"parse subscription failed", zap.String("url", query.Subs[i]),
 | 
					 | 
				
			||||||
						zap.String("data", string(data)),
 | 
					 | 
				
			||||||
						zap.Error(err),
 | 
					 | 
				
			||||||
					)
 | 
					 | 
				
			||||||
					return nil, errors.New("加载订阅失败: " + err.Error())
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				p := common.ParseProxy(strings.Split(base64, "\n")...)
 | 
					 | 
				
			||||||
				newProxies = p
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			newProxies = sub.Proxies
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if subName != "" {
 | 
					 | 
				
			||||||
			for i := range newProxies {
 | 
					 | 
				
			||||||
				newProxies[i].SubName = subName
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		proxyList = append(proxyList, newProxies...)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// 添加自定义节点
 | 
					 | 
				
			||||||
	if len(query.Proxies) != 0 {
 | 
					 | 
				
			||||||
		proxyList = append(proxyList, common.ParseProxy(query.Proxies...)...)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// 给节点添加订阅名称
 | 
					 | 
				
			||||||
	for i := range proxyList {
 | 
					 | 
				
			||||||
		if proxyList[i].SubName != "" {
 | 
					 | 
				
			||||||
			proxyList[i].Name = strings.TrimSpace(proxyList[i].SubName) + " " + strings.TrimSpace(proxyList[i].Name)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// 去掉配置相同的节点
 | 
					 | 
				
			||||||
	proxies := make(map[string]*model.Proxy)
 | 
					 | 
				
			||||||
	newProxies := make([]model.Proxy, 0, len(proxyList))
 | 
					 | 
				
			||||||
	for i := range proxyList {
 | 
					 | 
				
			||||||
		key := proxyList[i].Server + strconv.Itoa(proxyList[i].Port) + proxyList[i].Type + proxyList[i].UUID + proxyList[i].Password
 | 
					 | 
				
			||||||
		if _, exist := proxies[key]; !exist {
 | 
					 | 
				
			||||||
			proxies[key] = &proxyList[i]
 | 
					 | 
				
			||||||
			newProxies = append(newProxies, proxyList[i])
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	proxyList = newProxies
 | 
					 | 
				
			||||||
	// 删除节点
 | 
					 | 
				
			||||||
	if strings.TrimSpace(query.Remove) != "" {
 | 
					 | 
				
			||||||
		newProxyList := make([]model.Proxy, 0, len(proxyList))
 | 
					 | 
				
			||||||
		for i := range proxyList {
 | 
					 | 
				
			||||||
			removeReg, err := regexp.Compile(query.Remove)
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				logger.Logger.Debug("remove regexp compile failed", zap.Error(err))
 | 
					 | 
				
			||||||
				return nil, errors.New("remove 参数非法: " + err.Error())
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			// 删除匹配到的节点
 | 
					 | 
				
			||||||
			if removeReg.MatchString(proxyList[i].Name) {
 | 
					 | 
				
			||||||
				continue // 如果匹配到要删除的元素,跳过该元素,不添加到新切片中
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			newProxyList = append(newProxyList, proxyList[i]) // 将要保留的元素添加到新切片中
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		proxyList = newProxyList
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// 重命名
 | 
					 | 
				
			||||||
	if len(query.ReplaceKeys) != 0 {
 | 
					 | 
				
			||||||
		// 创建重命名正则表达式
 | 
					 | 
				
			||||||
		replaceRegs := make([]*regexp.Regexp, 0, len(query.ReplaceKeys))
 | 
					 | 
				
			||||||
		for _, v := range query.ReplaceKeys {
 | 
					 | 
				
			||||||
			replaceReg, err := regexp.Compile(v)
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				logger.Logger.Debug("replace regexp compile failed", zap.Error(err))
 | 
					 | 
				
			||||||
				return nil, errors.New("replace 参数非法: " + err.Error())
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			replaceRegs = append(replaceRegs, replaceReg)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		for i := range proxyList {
 | 
					 | 
				
			||||||
			// 重命名匹配到的节点
 | 
					 | 
				
			||||||
			for j, v := range replaceRegs {
 | 
					 | 
				
			||||||
				if v.MatchString(proxyList[i].Name) {
 | 
					 | 
				
			||||||
					proxyList[i].Name = v.ReplaceAllString(
 | 
					 | 
				
			||||||
						proxyList[i].Name, query.ReplaceTo[j],
 | 
					 | 
				
			||||||
					)
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// 重名检测
 | 
					 | 
				
			||||||
	names := make(map[string]int)
 | 
					 | 
				
			||||||
	for i := range proxyList {
 | 
					 | 
				
			||||||
		if _, exist := names[proxyList[i].Name]; exist {
 | 
					 | 
				
			||||||
			names[proxyList[i].Name] = names[proxyList[i].Name] + 1
 | 
					 | 
				
			||||||
			proxyList[i].Name = proxyList[i].Name + " " + strconv.Itoa(names[proxyList[i].Name])
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			names[proxyList[i].Name] = 0
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// trim
 | 
					 | 
				
			||||||
	for i := range proxyList {
 | 
					 | 
				
			||||||
		proxyList[i].Name = strings.TrimSpace(proxyList[i].Name)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// 将新增节点都添加到临时变量 t 中,防止策略组排序错乱
 | 
					 | 
				
			||||||
	var t = &model.Subscription{}
 | 
					 | 
				
			||||||
	common.AddProxy(t, query.AutoTest, query.Lazy, clashType, proxyList...)
 | 
					 | 
				
			||||||
	// 排序策略组
 | 
					 | 
				
			||||||
	switch query.Sort {
 | 
					 | 
				
			||||||
	case "sizeasc":
 | 
					 | 
				
			||||||
		sort.Sort(model.ProxyGroupsSortBySize(t.ProxyGroups))
 | 
					 | 
				
			||||||
	case "sizedesc":
 | 
					 | 
				
			||||||
		sort.Sort(sort.Reverse(model.ProxyGroupsSortBySize(t.ProxyGroups)))
 | 
					 | 
				
			||||||
	case "nameasc":
 | 
					 | 
				
			||||||
		sort.Sort(model.ProxyGroupsSortByName(t.ProxyGroups))
 | 
					 | 
				
			||||||
	case "namedesc":
 | 
					 | 
				
			||||||
		sort.Sort(sort.Reverse(model.ProxyGroupsSortByName(t.ProxyGroups)))
 | 
					 | 
				
			||||||
	default:
 | 
					 | 
				
			||||||
		sort.Sort(model.ProxyGroupsSortByName(t.ProxyGroups))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// 合并新节点和模板
 | 
					 | 
				
			||||||
	MergeSubAndTemplate(temp, t, query.IgnoreCountryGrooup)
 | 
					 | 
				
			||||||
	// 处理自定义规则
 | 
					 | 
				
			||||||
	for _, v := range query.Rules {
 | 
					 | 
				
			||||||
		if v.Prepend {
 | 
					 | 
				
			||||||
			common.PrependRules(temp, v.Rule)
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			common.AppendRules(temp, v.Rule)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// 处理自定义 ruleProvider
 | 
					 | 
				
			||||||
	for _, v := range query.RuleProviders {
 | 
					 | 
				
			||||||
		hash := sha256.Sum224([]byte(v.Url))
 | 
					 | 
				
			||||||
		name := hex.EncodeToString(hash[:])
 | 
					 | 
				
			||||||
		provider := model.RuleProvider{
 | 
					 | 
				
			||||||
			Type:     "http",
 | 
					 | 
				
			||||||
			Behavior: v.Behavior,
 | 
					 | 
				
			||||||
			Url:      v.Url,
 | 
					 | 
				
			||||||
			Path:     "./" + name + ".yaml",
 | 
					 | 
				
			||||||
			Interval: 3600,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if v.Prepend {
 | 
					 | 
				
			||||||
			common.PrependRuleProvider(
 | 
					 | 
				
			||||||
				temp, v.Name, v.Group, provider,
 | 
					 | 
				
			||||||
			)
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			common.AppenddRuleProvider(
 | 
					 | 
				
			||||||
				temp, v.Name, v.Group, provider,
 | 
					 | 
				
			||||||
			)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return temp, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func MergeSubAndTemplate(temp *model.Subscription, sub *model.Subscription, igcg bool) {
 | 
					 | 
				
			||||||
	// 只合并节点、策略组
 | 
					 | 
				
			||||||
	// 统计所有国家策略组名称
 | 
					 | 
				
			||||||
	var countryGroupNames []string
 | 
					 | 
				
			||||||
	for _, proxyGroup := range sub.ProxyGroups {
 | 
					 | 
				
			||||||
		if proxyGroup.IsCountryGrop {
 | 
					 | 
				
			||||||
			countryGroupNames = append(
 | 
					 | 
				
			||||||
				countryGroupNames, proxyGroup.Name,
 | 
					 | 
				
			||||||
			)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	var proxyNames []string
 | 
					 | 
				
			||||||
	for _, proxy := range sub.Proxies {
 | 
					 | 
				
			||||||
		proxyNames = append(proxyNames, proxy.Name)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// 将订阅中的节点添加到模板中
 | 
					 | 
				
			||||||
	temp.Proxies = append(temp.Proxies, sub.Proxies...)
 | 
					 | 
				
			||||||
	// 将订阅中的策略组添加到模板中
 | 
					 | 
				
			||||||
	for i := range temp.ProxyGroups {
 | 
					 | 
				
			||||||
		if temp.ProxyGroups[i].IsCountryGrop {
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		newProxies := make([]string, 0)
 | 
					 | 
				
			||||||
		countryGroupMap := make(map[string]model.ProxyGroup)
 | 
					 | 
				
			||||||
		for _, v := range sub.ProxyGroups {
 | 
					 | 
				
			||||||
			if v.IsCountryGrop {
 | 
					 | 
				
			||||||
				countryGroupMap[v.Name] = v
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		for j := range temp.ProxyGroups[i].Proxies {
 | 
					 | 
				
			||||||
			reg := regexp.MustCompile("<(.*?)>")
 | 
					 | 
				
			||||||
			if reg.Match([]byte(temp.ProxyGroups[i].Proxies[j])) {
 | 
					 | 
				
			||||||
				key := reg.FindStringSubmatch(temp.ProxyGroups[i].Proxies[j])[1]
 | 
					 | 
				
			||||||
				switch key {
 | 
					 | 
				
			||||||
				case "all":
 | 
					 | 
				
			||||||
					newProxies = append(newProxies, proxyNames...)
 | 
					 | 
				
			||||||
				case "countries":
 | 
					 | 
				
			||||||
					if !igcg {
 | 
					 | 
				
			||||||
						newProxies = append(newProxies, countryGroupNames...)
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				default:
 | 
					 | 
				
			||||||
					if !igcg {
 | 
					 | 
				
			||||||
						if len(key) == 2 {
 | 
					 | 
				
			||||||
							newProxies = append(
 | 
					 | 
				
			||||||
								newProxies, countryGroupMap[common.GetContryName(key)].Proxies...,
 | 
					 | 
				
			||||||
							)
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				newProxies = append(newProxies, temp.ProxyGroups[i].Proxies[j])
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		temp.ProxyGroups[i].Proxies = newProxies
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if !igcg {
 | 
					 | 
				
			||||||
		temp.ProxyGroups = append(temp.ProxyGroups, sub.ProxyGroups...)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,44 +0,0 @@
 | 
				
			|||||||
package handler
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	_ "embed"
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
	"sub2clash/config"
 | 
					 | 
				
			||||||
	"sub2clash/model"
 | 
					 | 
				
			||||||
	"sub2clash/validator"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
	"gopkg.in/yaml.v3"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func SubHandler(c *gin.Context) {
 | 
					 | 
				
			||||||
	// 从请求中获取参数
 | 
					 | 
				
			||||||
	query, err := validator.ParseQuery(c)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.String(http.StatusBadRequest, err.Error())
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	sub, err := BuildSub(model.ClashMeta, query, config.Default.MetaTemplate)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.String(http.StatusInternalServerError, err.Error())
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// 输出
 | 
					 | 
				
			||||||
	if query.NodeListMode {
 | 
					 | 
				
			||||||
		nodelist := model.NodeList{}
 | 
					 | 
				
			||||||
		nodelist.Proxies = sub.Proxies
 | 
					 | 
				
			||||||
		marshal, err := yaml.Marshal(nodelist)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			c.String(http.StatusInternalServerError, "YAML序列化失败: "+err.Error())
 | 
					 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		c.String(http.StatusOK, string(marshal))
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	marshal, err := yaml.Marshal(sub)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.String(http.StatusInternalServerError, "YAML序列化失败: "+err.Error())
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	c.String(http.StatusOK, string(marshal))
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,137 +0,0 @@
 | 
				
			|||||||
package handler
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"io"
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
	"strconv"
 | 
					 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
	"time"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"sub2clash/common"
 | 
					 | 
				
			||||||
	"sub2clash/common/database"
 | 
					 | 
				
			||||||
	"sub2clash/config"
 | 
					 | 
				
			||||||
	"sub2clash/model"
 | 
					 | 
				
			||||||
	"sub2clash/validator"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func respondWithError(c *gin.Context, code int, message string) {
 | 
					 | 
				
			||||||
	c.String(code, message)
 | 
					 | 
				
			||||||
	c.Abort()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func GenerateLinkHandler(c *gin.Context) {
 | 
					 | 
				
			||||||
	var params validator.ShortLinkGenValidator
 | 
					 | 
				
			||||||
	if err := c.ShouldBind(¶ms); err != nil {
 | 
					 | 
				
			||||||
		respondWithError(c, http.StatusBadRequest, "参数错误: "+err.Error())
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if strings.TrimSpace(params.Url) == "" {
 | 
					 | 
				
			||||||
		respondWithError(c, http.StatusBadRequest, "URL 不能为空")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	hash, err := generateUniqueHash()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		respondWithError(c, http.StatusInternalServerError, "生成短链接失败")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	shortLink := model.ShortLink{
 | 
					 | 
				
			||||||
		Hash:     hash,
 | 
					 | 
				
			||||||
		Url:      params.Url,
 | 
					 | 
				
			||||||
		Password: params.Password,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if err := database.SaveShortLink(&shortLink); err != nil {
 | 
					 | 
				
			||||||
		respondWithError(c, http.StatusInternalServerError, "数据库错误")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if params.Password != "" {
 | 
					 | 
				
			||||||
		hash += "?password=" + params.Password
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	c.String(http.StatusOK, hash)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func generateUniqueHash() (string, error) {
 | 
					 | 
				
			||||||
	for {
 | 
					 | 
				
			||||||
		hash := common.RandomString(config.Default.ShortLinkLength)
 | 
					 | 
				
			||||||
		exists, err := database.CheckShortLinkHashExists(hash)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return "", err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if !exists {
 | 
					 | 
				
			||||||
			return hash, nil
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func UpdateLinkHandler(c *gin.Context) {
 | 
					 | 
				
			||||||
	var params validator.ShortLinkUpdateValidator
 | 
					 | 
				
			||||||
	if err := c.ShouldBindJSON(¶ms); err != nil {
 | 
					 | 
				
			||||||
		respondWithError(c, http.StatusBadRequest, "参数错误: "+err.Error())
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	shortLink := model.ShortLink{
 | 
					 | 
				
			||||||
		Hash:     params.Hash,
 | 
					 | 
				
			||||||
		Url:      params.Url,
 | 
					 | 
				
			||||||
		Password: params.Password,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if err := database.SaveShortLink(&shortLink); err != nil {
 | 
					 | 
				
			||||||
		respondWithError(c, http.StatusInternalServerError, "数据库错误")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	c.String(http.StatusOK, "短链接更新成功")
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func GetRawConfHandler(c *gin.Context) {
 | 
					 | 
				
			||||||
	// 获取动态路由参数
 | 
					 | 
				
			||||||
	hash := c.Param("hash")
 | 
					 | 
				
			||||||
	password := c.Query("password")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if strings.TrimSpace(hash) == "" {
 | 
					 | 
				
			||||||
		c.String(http.StatusBadRequest, "参数错误")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 查询数据库中的短链接
 | 
					 | 
				
			||||||
	shortLink, err := database.FindShortLinkByHash(hash)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.String(http.StatusNotFound, "未找到短链接或密码错误")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 校验密码
 | 
					 | 
				
			||||||
	if shortLink.Password != "" && shortLink.Password != password {
 | 
					 | 
				
			||||||
		c.String(http.StatusNotFound, "未找到短链接或密码错误")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 更新最后访问时间
 | 
					 | 
				
			||||||
	shortLink.LastRequestTime = time.Now().Unix()
 | 
					 | 
				
			||||||
	err = database.SaveShortLink(shortLink)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		respondWithError(c, http.StatusInternalServerError, "数据库错误")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// 请求短链接指向的URL
 | 
					 | 
				
			||||||
	response, err := http.Get("http://localhost:" + strconv.Itoa(config.Default.Port) + "/" + shortLink.Url)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		respondWithError(c, http.StatusInternalServerError, "请求错误: "+err.Error())
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	defer response.Body.Close()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 读取响应内容
 | 
					 | 
				
			||||||
	all, err := io.ReadAll(response.Body)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		respondWithError(c, http.StatusInternalServerError, "读取错误: "+err.Error())
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 返回响应内容
 | 
					 | 
				
			||||||
	c.String(http.StatusOK, string(all))
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,495 +0,0 @@
 | 
				
			|||||||
function clearExistingValues() {
 | 
					 | 
				
			||||||
  // 清除简单输入框和复选框的值
 | 
					 | 
				
			||||||
  document.getElementById("endpoint").value = "clash";
 | 
					 | 
				
			||||||
  document.getElementById("sub").value = "";
 | 
					 | 
				
			||||||
  document.getElementById("proxy").value = "";
 | 
					 | 
				
			||||||
  document.getElementById("refresh").checked = false;
 | 
					 | 
				
			||||||
  document.getElementById("autoTest").checked = false;
 | 
					 | 
				
			||||||
  document.getElementById("lazy").checked = false;
 | 
					 | 
				
			||||||
  document.getElementById("igcg").checked = false;
 | 
					 | 
				
			||||||
  document.getElementById("template").value = "";
 | 
					 | 
				
			||||||
  document.getElementById("sort").value = "nameasc";
 | 
					 | 
				
			||||||
  document.getElementById("remove").value = "";
 | 
					 | 
				
			||||||
  document.getElementById("apiLink").value = "";
 | 
					 | 
				
			||||||
  document.getElementById("apiShortLink").value = "";
 | 
					 | 
				
			||||||
  document.getElementById("password").value = "";
 | 
					 | 
				
			||||||
  document.getElementById("nodeList").checked = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 清除由 createRuleProvider, createReplace, 和 createRule 创建的所有额外输入组
 | 
					 | 
				
			||||||
  clearInputGroup("ruleProviderGroup");
 | 
					 | 
				
			||||||
  clearInputGroup("replaceGroup");
 | 
					 | 
				
			||||||
  clearInputGroup("ruleGroup");
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function generateURI() {
 | 
					 | 
				
			||||||
  const queryParams = [];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取 API Endpoint
 | 
					 | 
				
			||||||
  const endpoint = document.getElementById("endpoint").value;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取并组合订阅链接
 | 
					 | 
				
			||||||
  let subLines = document
 | 
					 | 
				
			||||||
    .getElementById("sub")
 | 
					 | 
				
			||||||
    .value.split("\n")
 | 
					 | 
				
			||||||
    .filter((line) => line.trim() !== "");
 | 
					 | 
				
			||||||
  let noSub = false;
 | 
					 | 
				
			||||||
  // 去除 subLines 中空元素
 | 
					 | 
				
			||||||
  subLines = subLines.map((item) => {
 | 
					 | 
				
			||||||
    if (item !== "") {
 | 
					 | 
				
			||||||
      return item;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
  if (subLines.length > 0) {
 | 
					 | 
				
			||||||
    queryParams.push(`sub=${encodeURIComponent(subLines.join(","))}`);
 | 
					 | 
				
			||||||
  } else {
 | 
					 | 
				
			||||||
    noSub = true;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取并组合节点分享链接
 | 
					 | 
				
			||||||
  let proxyLines = document
 | 
					 | 
				
			||||||
    .getElementById("proxy")
 | 
					 | 
				
			||||||
    .value.split("\n")
 | 
					 | 
				
			||||||
    .filter((line) => line.trim() !== "");
 | 
					 | 
				
			||||||
  let noProxy = false;
 | 
					 | 
				
			||||||
  // 去除 proxyLines 中空元素
 | 
					 | 
				
			||||||
  proxyLines = proxyLines.map((item) => {
 | 
					 | 
				
			||||||
    if (item !== "") {
 | 
					 | 
				
			||||||
      return item;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
  if (proxyLines.length > 0) {
 | 
					 | 
				
			||||||
    queryParams.push(`proxy=${encodeURIComponent(proxyLines.join(","))}`);
 | 
					 | 
				
			||||||
  } else {
 | 
					 | 
				
			||||||
    noProxy = true;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  if (noSub && noProxy) {
 | 
					 | 
				
			||||||
    // alert("订阅链接和节点分享链接不能同时为空!");
 | 
					 | 
				
			||||||
    return "";
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  // 获取复选框的值
 | 
					 | 
				
			||||||
  const refresh = document.getElementById("refresh").checked;
 | 
					 | 
				
			||||||
  queryParams.push(`refresh=${refresh ? "true" : "false"}`);
 | 
					 | 
				
			||||||
  const autoTest = document.getElementById("autoTest").checked;
 | 
					 | 
				
			||||||
  queryParams.push(`autoTest=${autoTest ? "true" : "false"}`);
 | 
					 | 
				
			||||||
  const lazy = document.getElementById("lazy").checked;
 | 
					 | 
				
			||||||
  queryParams.push(`lazy=${lazy ? "true" : "false"}`);
 | 
					 | 
				
			||||||
  const nodeList = document.getElementById("nodeList").checked;
 | 
					 | 
				
			||||||
  queryParams.push(`nodeList=${nodeList ? "true" : "false"}`);
 | 
					 | 
				
			||||||
  const igcg = document.getElementById("igcg").checked;
 | 
					 | 
				
			||||||
  queryParams.push(`ignoreCountryGroup=${igcg ? "true" : "false"}`);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取模板链接或名称(如果存在)
 | 
					 | 
				
			||||||
  const template = document.getElementById("template").value;
 | 
					 | 
				
			||||||
  if (template.trim() !== "") {
 | 
					 | 
				
			||||||
    queryParams.push(`template=${encodeURIComponent(template)}`);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取Rule Provider和规则
 | 
					 | 
				
			||||||
  const ruleProviders = document.getElementsByName("ruleProvider");
 | 
					 | 
				
			||||||
  const rules = document.getElementsByName("rule");
 | 
					 | 
				
			||||||
  let providers = [];
 | 
					 | 
				
			||||||
  for (let i = 0; i < ruleProviders.length / 5; i++) {
 | 
					 | 
				
			||||||
    let baseIndex = i * 5;
 | 
					 | 
				
			||||||
    let behavior = ruleProviders[baseIndex].value;
 | 
					 | 
				
			||||||
    let url = ruleProviders[baseIndex + 1].value;
 | 
					 | 
				
			||||||
    let group = ruleProviders[baseIndex + 2].value;
 | 
					 | 
				
			||||||
    let prepend = ruleProviders[baseIndex + 3].value;
 | 
					 | 
				
			||||||
    let name = ruleProviders[baseIndex + 4].value;
 | 
					 | 
				
			||||||
    // 是否存在空值
 | 
					 | 
				
			||||||
    if (
 | 
					 | 
				
			||||||
      behavior.trim() === "" ||
 | 
					 | 
				
			||||||
      url.trim() === "" ||
 | 
					 | 
				
			||||||
      group.trim() === "" ||
 | 
					 | 
				
			||||||
      prepend.trim() === "" ||
 | 
					 | 
				
			||||||
      name.trim() === ""
 | 
					 | 
				
			||||||
    ) {
 | 
					 | 
				
			||||||
      // alert("Rule Provider 中存在空值,请检查后重试!");
 | 
					 | 
				
			||||||
      return "";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    providers.push(`[${behavior},${url},${group},${prepend},${name}]`);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  queryParams.push(`ruleProvider=${encodeURIComponent(providers.join(","))}`);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  let ruleList = [];
 | 
					 | 
				
			||||||
  for (let i = 0; i < rules.length / 3; i++) {
 | 
					 | 
				
			||||||
    if (rules[i * 3].value.trim() !== "") {
 | 
					 | 
				
			||||||
      let rule = rules[i * 3].value;
 | 
					 | 
				
			||||||
      let prepend = rules[i * 3 + 1].value;
 | 
					 | 
				
			||||||
      let group = rules[i * 3 + 2].value;
 | 
					 | 
				
			||||||
      // 是否存在空值
 | 
					 | 
				
			||||||
      if (rule.trim() === "" || prepend.trim() === "" || group.trim() === "") {
 | 
					 | 
				
			||||||
        // alert("Rule 中存在空值,请检查后重试!");
 | 
					 | 
				
			||||||
        return "";
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      ruleList.push(`[${rule},${prepend},${group}]`);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  queryParams.push(`rule=${encodeURIComponent(ruleList.join(","))}`);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取排序策略
 | 
					 | 
				
			||||||
  const sort = document.getElementById("sort").value;
 | 
					 | 
				
			||||||
  queryParams.push(`sort=${sort}`);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取删除节点的正则表达式
 | 
					 | 
				
			||||||
  const remove = document.getElementById("remove").value;
 | 
					 | 
				
			||||||
  if (remove.trim() !== "") {
 | 
					 | 
				
			||||||
    queryParams.push(`remove=${encodeURIComponent(remove)}`);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取替换节点名称的正则表达式
 | 
					 | 
				
			||||||
  let replaceList = [];
 | 
					 | 
				
			||||||
  const replaces = document.getElementsByName("replace");
 | 
					 | 
				
			||||||
  for (let i = 0; i < replaces.length / 2; i++) {
 | 
					 | 
				
			||||||
    let replaceStr = `<${replaces[i * 2].value}>`;
 | 
					 | 
				
			||||||
    let replaceTo = `<${replaces[i * 2 + 1].value}>`;
 | 
					 | 
				
			||||||
    if (replaceStr.trim() === "") {
 | 
					 | 
				
			||||||
      // alert("重命名设置中存在空值,请检查后重试!");
 | 
					 | 
				
			||||||
      return "";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    replaceList.push(`[${replaceStr},${replaceTo}]`);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  queryParams.push(`replace=${encodeURIComponent(replaceList.join(","))}`);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  return `${endpoint}?${queryParams.join("&")}`;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 将输入框中的 URL 解析为参数
 | 
					 | 
				
			||||||
async function parseInputURL() {
 | 
					 | 
				
			||||||
  // 获取输入框中的 URL
 | 
					 | 
				
			||||||
  const inputURL = document.getElementById("urlInput").value;
 | 
					 | 
				
			||||||
  // 清除现有的输入框值
 | 
					 | 
				
			||||||
  clearExistingValues();
 | 
					 | 
				
			||||||
  if (!inputURL) {
 | 
					 | 
				
			||||||
    alert("请输入有效的链接!");
 | 
					 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  let url;
 | 
					 | 
				
			||||||
  try {
 | 
					 | 
				
			||||||
    url = new URL(inputURL);
 | 
					 | 
				
			||||||
  } catch (_) {
 | 
					 | 
				
			||||||
    alert("无效的链接!");
 | 
					 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  if (url.pathname.includes("/s/")) {
 | 
					 | 
				
			||||||
    let hash = url.pathname.substring(url.pathname.lastIndexOf("/s/") + 3);
 | 
					 | 
				
			||||||
    let q = new URLSearchParams();
 | 
					 | 
				
			||||||
    let password = url.searchParams.get("password");
 | 
					 | 
				
			||||||
    q.append("hash", hash);
 | 
					 | 
				
			||||||
    q.append("password", password);
 | 
					 | 
				
			||||||
    try {
 | 
					 | 
				
			||||||
      const response = await axios.get("./short?" + q.toString());
 | 
					 | 
				
			||||||
      url = new URL(window.location.href + response.data);
 | 
					 | 
				
			||||||
      document.querySelector("#apiShortLink").value = inputURL;
 | 
					 | 
				
			||||||
      document.querySelector("#password").value = password;
 | 
					 | 
				
			||||||
    } catch (error) {
 | 
					 | 
				
			||||||
      console.log(error);
 | 
					 | 
				
			||||||
      alert("获取短链失败,请检查密码!");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  let params = new URLSearchParams(url.search);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 分配值到对应的输入框
 | 
					 | 
				
			||||||
  const pathSections = url.pathname.split("/");
 | 
					 | 
				
			||||||
  const lastSection = pathSections[pathSections.length - 1];
 | 
					 | 
				
			||||||
  const clientTypeSelect = document.getElementById("endpoint");
 | 
					 | 
				
			||||||
  switch (lastSection.toLowerCase()) {
 | 
					 | 
				
			||||||
    case "meta":
 | 
					 | 
				
			||||||
      clientTypeSelect.value = "meta";
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
    case "clash":
 | 
					 | 
				
			||||||
    default:
 | 
					 | 
				
			||||||
      clientTypeSelect.value = "clash";
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("sub")) {
 | 
					 | 
				
			||||||
    document.getElementById("sub").value = decodeURIComponent(params.get("sub"))
 | 
					 | 
				
			||||||
      .split(",")
 | 
					 | 
				
			||||||
      .join("\n");
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("proxy")) {
 | 
					 | 
				
			||||||
    document.getElementById("proxy").value = decodeURIComponent(
 | 
					 | 
				
			||||||
      params.get("proxy")
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
      .split(",")
 | 
					 | 
				
			||||||
      .join("\n");
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("refresh")) {
 | 
					 | 
				
			||||||
    document.getElementById("refresh").checked =
 | 
					 | 
				
			||||||
      params.get("refresh") === "true";
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("autoTest")) {
 | 
					 | 
				
			||||||
    document.getElementById("autoTest").checked =
 | 
					 | 
				
			||||||
      params.get("autoTest") === "true";
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("lazy")) {
 | 
					 | 
				
			||||||
    document.getElementById("lazy").checked = params.get("lazy") === "true";
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("template")) {
 | 
					 | 
				
			||||||
    document.getElementById("template").value = decodeURIComponent(
 | 
					 | 
				
			||||||
      params.get("template")
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("sort")) {
 | 
					 | 
				
			||||||
    document.getElementById("sort").value = params.get("sort");
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("remove")) {
 | 
					 | 
				
			||||||
    document.getElementById("remove").value = decodeURIComponent(
 | 
					 | 
				
			||||||
      params.get("remove")
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("replace")) {
 | 
					 | 
				
			||||||
    parseAndFillReplaceParams(decodeURIComponent(params.get("replace")));
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("ruleProvider")) {
 | 
					 | 
				
			||||||
    parseAndFillRuleProviderParams(
 | 
					 | 
				
			||||||
      decodeURIComponent(params.get("ruleProvider"))
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("rule")) {
 | 
					 | 
				
			||||||
    parseAndFillRuleParams(decodeURIComponent(params.get("rule")));
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("nodeList")) {
 | 
					 | 
				
			||||||
    document.getElementById("nodeList").checked =
 | 
					 | 
				
			||||||
      params.get("nodeList") === "true";
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function clearInputGroup(groupId) {
 | 
					 | 
				
			||||||
  // 清空第二个之后的child
 | 
					 | 
				
			||||||
  const group = document.getElementById(groupId);
 | 
					 | 
				
			||||||
  while (group.children.length > 2) {
 | 
					 | 
				
			||||||
    group.removeChild(group.lastChild);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function parseAndFillReplaceParams(replaceParams) {
 | 
					 | 
				
			||||||
  const replaceGroup = document.getElementById("replaceGroup");
 | 
					 | 
				
			||||||
  let matches;
 | 
					 | 
				
			||||||
  const regex = /\[(<.*?>),(<.*?>)\]/g;
 | 
					 | 
				
			||||||
  const str = decodeURIComponent(replaceParams);
 | 
					 | 
				
			||||||
  while ((matches = regex.exec(str)) !== null) {
 | 
					 | 
				
			||||||
    const div = createReplace();
 | 
					 | 
				
			||||||
    const original = matches[1].slice(1, -1); // Remove < and >
 | 
					 | 
				
			||||||
    const replacement = matches[2].slice(1, -1); // Remove < and >
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    div.children[0].value = original;
 | 
					 | 
				
			||||||
    div.children[1].value = replacement;
 | 
					 | 
				
			||||||
    replaceGroup.appendChild(div);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function parseAndFillRuleProviderParams(ruleProviderParams) {
 | 
					 | 
				
			||||||
  const ruleProviderGroup = document.getElementById("ruleProviderGroup");
 | 
					 | 
				
			||||||
  let matches;
 | 
					 | 
				
			||||||
  const regex = /\[(.*?),(.*?),(.*?),(.*?),(.*?)\]/g;
 | 
					 | 
				
			||||||
  const str = decodeURIComponent(ruleProviderParams);
 | 
					 | 
				
			||||||
  while ((matches = regex.exec(str)) !== null) {
 | 
					 | 
				
			||||||
    const div = createRuleProvider();
 | 
					 | 
				
			||||||
    div.children[0].value = matches[1];
 | 
					 | 
				
			||||||
    div.children[1].value = matches[2];
 | 
					 | 
				
			||||||
    div.children[2].value = matches[3];
 | 
					 | 
				
			||||||
    div.children[3].value = matches[4];
 | 
					 | 
				
			||||||
    div.children[4].value = matches[5];
 | 
					 | 
				
			||||||
    ruleProviderGroup.appendChild(div);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function parseAndFillRuleParams(ruleParams) {
 | 
					 | 
				
			||||||
  const ruleGroup = document.getElementById("ruleGroup");
 | 
					 | 
				
			||||||
  let matches;
 | 
					 | 
				
			||||||
  const regex = /\[(.*?),(.*?),(.*?)\]/g;
 | 
					 | 
				
			||||||
  const str = decodeURIComponent(ruleParams);
 | 
					 | 
				
			||||||
  while ((matches = regex.exec(str)) !== null) {
 | 
					 | 
				
			||||||
    const div = createRule();
 | 
					 | 
				
			||||||
    div.children[0].value = matches[1];
 | 
					 | 
				
			||||||
    div.children[1].value = matches[2];
 | 
					 | 
				
			||||||
    div.children[2].value = matches[3];
 | 
					 | 
				
			||||||
    ruleGroup.appendChild(div);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
async function copyToClipboard(elem, e) {
 | 
					 | 
				
			||||||
  const apiLinkInput = document.querySelector(`#${elem}`).value;
 | 
					 | 
				
			||||||
  try {
 | 
					 | 
				
			||||||
    await navigator.clipboard.writeText(apiLinkInput);
 | 
					 | 
				
			||||||
    let text = e.textContent;
 | 
					 | 
				
			||||||
    e.addEventListener("mouseout", function () {
 | 
					 | 
				
			||||||
      e.textContent = text;
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    e.textContent = "复制成功";
 | 
					 | 
				
			||||||
  } catch (err) {
 | 
					 | 
				
			||||||
    console.error("复制到剪贴板失败:", err);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function createRuleProvider() {
 | 
					 | 
				
			||||||
  const div = document.createElement("div");
 | 
					 | 
				
			||||||
  div.classList.add("input-group", "mb-2");
 | 
					 | 
				
			||||||
  div.innerHTML = `
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="ruleProvider" placeholder="Behavior">
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="ruleProvider" placeholder="Url">
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="ruleProvider" placeholder="Group">
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="ruleProvider" placeholder="Prepend">
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="ruleProvider" placeholder="Name">
 | 
					 | 
				
			||||||
            <button type="button" class="btn btn-danger" onclick="removeElement(this)">删除</button>
 | 
					 | 
				
			||||||
        `;
 | 
					 | 
				
			||||||
  return div;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function createReplace() {
 | 
					 | 
				
			||||||
  const div = document.createElement("div");
 | 
					 | 
				
			||||||
  div.classList.add("input-group", "mb-2");
 | 
					 | 
				
			||||||
  div.innerHTML = `
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="replace" placeholder="原字符串(正则表达式)">
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="replace" placeholder="替换为(可为空)">
 | 
					 | 
				
			||||||
            <button type="button" class="btn btn-danger" onclick="removeElement(this)">删除</button>
 | 
					 | 
				
			||||||
        `;
 | 
					 | 
				
			||||||
  return div;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function createRule() {
 | 
					 | 
				
			||||||
  const div = document.createElement("div");
 | 
					 | 
				
			||||||
  div.classList.add("input-group", "mb-2");
 | 
					 | 
				
			||||||
  div.innerHTML = `
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="rule" placeholder="Rule">
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="rule" placeholder="Prepend">
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="rule" placeholder="Group">
 | 
					 | 
				
			||||||
            <button type="button" class="btn btn-danger" onclick="removeElement(this)">删除</button>
 | 
					 | 
				
			||||||
        `;
 | 
					 | 
				
			||||||
  return div;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function listenInput() {
 | 
					 | 
				
			||||||
  let selectElements = document.querySelectorAll("select");
 | 
					 | 
				
			||||||
  let inputElements = document.querySelectorAll("input");
 | 
					 | 
				
			||||||
  let textAreaElements = document.querySelectorAll("textarea");
 | 
					 | 
				
			||||||
  inputElements.forEach(function (element) {
 | 
					 | 
				
			||||||
    element.addEventListener("input", function () {
 | 
					 | 
				
			||||||
      generateURL();
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
  textAreaElements.forEach(function (element) {
 | 
					 | 
				
			||||||
    element.addEventListener("input", function () {
 | 
					 | 
				
			||||||
      generateURL();
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
  selectElements.forEach(function (element) {
 | 
					 | 
				
			||||||
    element.addEventListener("change", function () {
 | 
					 | 
				
			||||||
      generateURL();
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function addRuleProvider() {
 | 
					 | 
				
			||||||
  const div = createRuleProvider();
 | 
					 | 
				
			||||||
  document.getElementById("ruleProviderGroup").appendChild(div);
 | 
					 | 
				
			||||||
  listenInput();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function addRule() {
 | 
					 | 
				
			||||||
  const div = createRule();
 | 
					 | 
				
			||||||
  document.getElementById("ruleGroup").appendChild(div);
 | 
					 | 
				
			||||||
  listenInput();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function addReplace() {
 | 
					 | 
				
			||||||
  const div = createReplace();
 | 
					 | 
				
			||||||
  document.getElementById("replaceGroup").appendChild(div);
 | 
					 | 
				
			||||||
  listenInput();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function removeElement(button) {
 | 
					 | 
				
			||||||
  button.parentElement.remove();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function generateURL() {
 | 
					 | 
				
			||||||
  const apiLink = document.getElementById("apiLink");
 | 
					 | 
				
			||||||
  let uri = generateURI();
 | 
					 | 
				
			||||||
  if (uri === "") {
 | 
					 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  apiLink.value = `${window.location.origin}${window.location.pathname}${uri}`;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function generateShortLink() {
 | 
					 | 
				
			||||||
  const apiShortLink = document.getElementById("apiShortLink");
 | 
					 | 
				
			||||||
  const password = document.getElementById("password");
 | 
					 | 
				
			||||||
  let uri = generateURI();
 | 
					 | 
				
			||||||
  if (uri === "") {
 | 
					 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  axios
 | 
					 | 
				
			||||||
    .post(
 | 
					 | 
				
			||||||
      "./short",
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
        url: uri,
 | 
					 | 
				
			||||||
        password: password.value.trim(),
 | 
					 | 
				
			||||||
      },
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
        headers: {
 | 
					 | 
				
			||||||
          "Content-Type": "application/json",
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
    .then((response) => {
 | 
					 | 
				
			||||||
      apiShortLink.value = `${window.location.origin}${window.location.pathname}s/${response.data}`;
 | 
					 | 
				
			||||||
    })
 | 
					 | 
				
			||||||
    .catch((error) => {
 | 
					 | 
				
			||||||
      console.log(error);
 | 
					 | 
				
			||||||
      alert("生成短链失败,请重试!");
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function updateShortLink() {
 | 
					 | 
				
			||||||
  const password = document.getElementById("password");
 | 
					 | 
				
			||||||
  const apiShortLink = document.getElementById("apiShortLink");
 | 
					 | 
				
			||||||
  let hash = apiShortLink.value;
 | 
					 | 
				
			||||||
  if (hash.startsWith("http")) {
 | 
					 | 
				
			||||||
    let u = new URL(hash);
 | 
					 | 
				
			||||||
    hash = u.pathname.substring(u.pathname.lastIndexOf("/s/") + 3);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  if (password.value.trim() === "") {
 | 
					 | 
				
			||||||
    alert("请输入密码!");
 | 
					 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  let uri = generateURI();
 | 
					 | 
				
			||||||
  if (uri === "") {
 | 
					 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  axios
 | 
					 | 
				
			||||||
    .put(
 | 
					 | 
				
			||||||
      "./short",
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
        hash: hash,
 | 
					 | 
				
			||||||
        url: uri,
 | 
					 | 
				
			||||||
        password: password.value.trim(),
 | 
					 | 
				
			||||||
      },
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
        headers: {
 | 
					 | 
				
			||||||
          "Content-Type": "application/json",
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
    .then((response) => {
 | 
					 | 
				
			||||||
      alert("更新短链成功!");
 | 
					 | 
				
			||||||
    })
 | 
					 | 
				
			||||||
    .catch((error) => {
 | 
					 | 
				
			||||||
      console.log(error);
 | 
					 | 
				
			||||||
      alert(error.response.data);
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
listenInput();
 | 
					 | 
				
			||||||
@@ -2,10 +2,10 @@ package database
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"errors"
 | 
					 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"sub2clash/model"
 | 
						"github.com/bestnite/sub2clash/common"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"go.etcd.io/bbolt"
 | 
						"go.etcd.io/bbolt"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -13,19 +13,20 @@ import (
 | 
				
			|||||||
var DB *bbolt.DB
 | 
					var DB *bbolt.DB
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ConnectDB() error {
 | 
					func ConnectDB() error {
 | 
				
			||||||
	// 确保数据目录存在
 | 
					 | 
				
			||||||
	path := filepath.Join("data", "sub2clash.db")
 | 
						path := filepath.Join("data", "sub2clash.db")
 | 
				
			||||||
	// 打开或创建数据库文件
 | 
					
 | 
				
			||||||
	db, err := bbolt.Open(path, 0600, nil)
 | 
						db, err := bbolt.Open(path, 0600, nil)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return common.NewDatabaseConnectError(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	DB = db
 | 
						DB = db
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 确保存储桶存在
 | 
					 | 
				
			||||||
	return db.Update(func(tx *bbolt.Tx) error {
 | 
						return db.Update(func(tx *bbolt.Tx) error {
 | 
				
			||||||
		_, err := tx.CreateBucketIfNotExists([]byte("ShortLinks"))
 | 
							_, err := tx.CreateBucketIfNotExists([]byte("ShortLinks"))
 | 
				
			||||||
		return err
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return common.NewDatabaseConnectError(err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -35,7 +36,7 @@ func FindShortLinkByHash(hash string) (*model.ShortLink, error) {
 | 
				
			|||||||
		b := tx.Bucket([]byte("ShortLinks"))
 | 
							b := tx.Bucket([]byte("ShortLinks"))
 | 
				
			||||||
		v := b.Get([]byte(hash))
 | 
							v := b.Get([]byte(hash))
 | 
				
			||||||
		if v == nil {
 | 
							if v == nil {
 | 
				
			||||||
			return errors.New("ShortLink not found")
 | 
								return common.NewRecordNotFoundError("ShortLink", hash)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return json.Unmarshal(v, &shortLink)
 | 
							return json.Unmarshal(v, &shortLink)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										192
									
								
								common/errors.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										192
									
								
								common/errors.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,192 @@
 | 
				
			|||||||
 | 
					package common
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// CommonError represents a structured error type for the common package
 | 
				
			||||||
 | 
					type CommonError struct {
 | 
				
			||||||
 | 
						Code    ErrorCode
 | 
				
			||||||
 | 
						Message string
 | 
				
			||||||
 | 
						Cause   error
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ErrorCode represents different types of errors
 | 
				
			||||||
 | 
					type ErrorCode string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						// Directory operation errors
 | 
				
			||||||
 | 
						ErrDirCreation ErrorCode = "DIRECTORY_CREATION_FAILED"
 | 
				
			||||||
 | 
						ErrDirAccess   ErrorCode = "DIRECTORY_ACCESS_FAILED"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// File operation errors
 | 
				
			||||||
 | 
						ErrFileNotFound ErrorCode = "FILE_NOT_FOUND"
 | 
				
			||||||
 | 
						ErrFileRead     ErrorCode = "FILE_READ_FAILED"
 | 
				
			||||||
 | 
						ErrFileWrite    ErrorCode = "FILE_WRITE_FAILED"
 | 
				
			||||||
 | 
						ErrFileCreate   ErrorCode = "FILE_CREATE_FAILED"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Network operation errors
 | 
				
			||||||
 | 
						ErrNetworkRequest  ErrorCode = "NETWORK_REQUEST_FAILED"
 | 
				
			||||||
 | 
						ErrNetworkResponse ErrorCode = "NETWORK_RESPONSE_FAILED"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Template and configuration errors
 | 
				
			||||||
 | 
						ErrTemplateLoad  ErrorCode = "TEMPLATE_LOAD_FAILED"
 | 
				
			||||||
 | 
						ErrTemplateParse ErrorCode = "TEMPLATE_PARSE_FAILED"
 | 
				
			||||||
 | 
						ErrConfigInvalid ErrorCode = "CONFIG_INVALID"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Subscription errors
 | 
				
			||||||
 | 
						ErrSubscriptionLoad  ErrorCode = "SUBSCRIPTION_LOAD_FAILED"
 | 
				
			||||||
 | 
						ErrSubscriptionParse ErrorCode = "SUBSCRIPTION_PARSE_FAILED"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Regex errors
 | 
				
			||||||
 | 
						ErrRegexCompile ErrorCode = "REGEX_COMPILE_FAILED"
 | 
				
			||||||
 | 
						ErrRegexInvalid ErrorCode = "REGEX_INVALID"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Database errors
 | 
				
			||||||
 | 
						ErrDatabaseConnect ErrorCode = "DATABASE_CONNECTION_FAILED"
 | 
				
			||||||
 | 
						ErrDatabaseQuery   ErrorCode = "DATABASE_QUERY_FAILED"
 | 
				
			||||||
 | 
						ErrRecordNotFound  ErrorCode = "RECORD_NOT_FOUND"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Validation errors
 | 
				
			||||||
 | 
						ErrValidation   ErrorCode = "VALIDATION_FAILED"
 | 
				
			||||||
 | 
						ErrInvalidInput ErrorCode = "INVALID_INPUT"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Error returns the string representation of the error
 | 
				
			||||||
 | 
					func (e *CommonError) Error() string {
 | 
				
			||||||
 | 
						if e.Cause != nil {
 | 
				
			||||||
 | 
							return fmt.Sprintf("[%s] %s: %v", e.Code, e.Message, e.Cause)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return fmt.Sprintf("[%s] %s", e.Code, e.Message)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Unwrap returns the underlying error
 | 
				
			||||||
 | 
					func (e *CommonError) Unwrap() error {
 | 
				
			||||||
 | 
						return e.Cause
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Is allows error comparison
 | 
				
			||||||
 | 
					func (e *CommonError) Is(target error) bool {
 | 
				
			||||||
 | 
						if t, ok := target.(*CommonError); ok {
 | 
				
			||||||
 | 
							return e.Code == t.Code
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// NewError creates a new CommonError
 | 
				
			||||||
 | 
					func NewError(code ErrorCode, message string, cause error) *CommonError {
 | 
				
			||||||
 | 
						return &CommonError{
 | 
				
			||||||
 | 
							Code:    code,
 | 
				
			||||||
 | 
							Message: message,
 | 
				
			||||||
 | 
							Cause:   cause,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// NewSimpleError creates a new CommonError without a cause
 | 
				
			||||||
 | 
					func NewSimpleError(code ErrorCode, message string) *CommonError {
 | 
				
			||||||
 | 
						return &CommonError{
 | 
				
			||||||
 | 
							Code:    code,
 | 
				
			||||||
 | 
							Message: message,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Convenience constructors for common error types
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Directory errors
 | 
				
			||||||
 | 
					func NewDirCreationError(dirPath string, cause error) *CommonError {
 | 
				
			||||||
 | 
						return NewError(ErrDirCreation, fmt.Sprintf("failed to create directory: %s", dirPath), cause)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewDirAccessError(dirPath string, cause error) *CommonError {
 | 
				
			||||||
 | 
						return NewError(ErrDirAccess, fmt.Sprintf("failed to access directory: %s", dirPath), cause)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// File errors
 | 
				
			||||||
 | 
					func NewFileNotFoundError(filePath string) *CommonError {
 | 
				
			||||||
 | 
						return NewSimpleError(ErrFileNotFound, fmt.Sprintf("file not found: %s", filePath))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewFileReadError(filePath string, cause error) *CommonError {
 | 
				
			||||||
 | 
						return NewError(ErrFileRead, fmt.Sprintf("failed to read file: %s", filePath), cause)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewFileWriteError(filePath string, cause error) *CommonError {
 | 
				
			||||||
 | 
						return NewError(ErrFileWrite, fmt.Sprintf("failed to write file: %s", filePath), cause)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewFileCreateError(filePath string, cause error) *CommonError {
 | 
				
			||||||
 | 
						return NewError(ErrFileCreate, fmt.Sprintf("failed to create file: %s", filePath), cause)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Network errors
 | 
				
			||||||
 | 
					func NewNetworkRequestError(url string, cause error) *CommonError {
 | 
				
			||||||
 | 
						return NewError(ErrNetworkRequest, fmt.Sprintf("network request failed for URL: %s", url), cause)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewNetworkResponseError(message string, cause error) *CommonError {
 | 
				
			||||||
 | 
						return NewError(ErrNetworkResponse, message, cause)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Template errors
 | 
				
			||||||
 | 
					func NewTemplateLoadError(template string, cause error) *CommonError {
 | 
				
			||||||
 | 
						return NewError(ErrTemplateLoad, fmt.Sprintf("failed to load template: %s", template), cause)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewTemplateParseError(data []byte, cause error) *CommonError {
 | 
				
			||||||
 | 
						return NewError(ErrTemplateParse, fmt.Sprintf("failed to parse template: %s", data), cause)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Subscription errors
 | 
				
			||||||
 | 
					func NewSubscriptionLoadError(url string, cause error) *CommonError {
 | 
				
			||||||
 | 
						return NewError(ErrSubscriptionLoad, fmt.Sprintf("failed to load subscription: %s", url), cause)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewSubscriptionParseError(data []byte, cause error) *CommonError {
 | 
				
			||||||
 | 
						return NewError(ErrSubscriptionParse, fmt.Sprintf("failed to parse subscription: %s", string(data)), cause)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Regex errors
 | 
				
			||||||
 | 
					func NewRegexCompileError(pattern string, cause error) *CommonError {
 | 
				
			||||||
 | 
						return NewError(ErrRegexCompile, fmt.Sprintf("failed to compile regex pattern: %s", pattern), cause)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewRegexInvalidError(paramName string, cause error) *CommonError {
 | 
				
			||||||
 | 
						return NewError(ErrRegexInvalid, fmt.Sprintf("invalid regex in parameter: %s", paramName), cause)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Database errors
 | 
				
			||||||
 | 
					func NewDatabaseConnectError(cause error) *CommonError {
 | 
				
			||||||
 | 
						return NewError(ErrDatabaseConnect, "failed to connect to database", cause)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewRecordNotFoundError(recordType string, id string) *CommonError {
 | 
				
			||||||
 | 
						return NewSimpleError(ErrRecordNotFound, fmt.Sprintf("%s not found: %s", recordType, id))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Validation errors
 | 
				
			||||||
 | 
					func NewValidationError(field string, message string) *CommonError {
 | 
				
			||||||
 | 
						return NewSimpleError(ErrValidation, fmt.Sprintf("validation failed for %s: %s", field, message))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewInvalidInputError(paramName string, value string) *CommonError {
 | 
				
			||||||
 | 
						return NewSimpleError(ErrInvalidInput, fmt.Sprintf("invalid input for parameter %s: %s", paramName, value))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// IsErrorCode checks if an error has a specific error code
 | 
				
			||||||
 | 
					func IsErrorCode(err error, code ErrorCode) bool {
 | 
				
			||||||
 | 
						var commonErr *CommonError
 | 
				
			||||||
 | 
						if errors.As(err, &commonErr) {
 | 
				
			||||||
 | 
							return commonErr.Code == code
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetErrorCode extracts the error code from an error
 | 
				
			||||||
 | 
					func GetErrorCode(err error) (ErrorCode, bool) {
 | 
				
			||||||
 | 
						var commonErr *CommonError
 | 
				
			||||||
 | 
						if errors.As(err, &commonErr) {
 | 
				
			||||||
 | 
							return commonErr.Code, true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return "", false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,38 +0,0 @@
 | 
				
			|||||||
package common
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"errors"
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
	"sub2clash/config"
 | 
					 | 
				
			||||||
	"time"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func Get(url string) (resp *http.Response, err error) {
 | 
					 | 
				
			||||||
	retryTimes := config.Default.RequestRetryTimes
 | 
					 | 
				
			||||||
	haveTried := 0
 | 
					 | 
				
			||||||
	retryDelay := time.Second // 延迟1秒再重试
 | 
					 | 
				
			||||||
	for haveTried < retryTimes {
 | 
					 | 
				
			||||||
		client := &http.Client{}
 | 
					 | 
				
			||||||
		//client.Timeout = time.Second * 10
 | 
					 | 
				
			||||||
		req, err := http.NewRequest("GET", url, nil)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			haveTried++
 | 
					 | 
				
			||||||
			time.Sleep(retryDelay)
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		get, err := client.Do(req)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			haveTried++
 | 
					 | 
				
			||||||
			time.Sleep(retryDelay)
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			// 如果文件大小大于设定,直接返回错误
 | 
					 | 
				
			||||||
			if get != nil && get.ContentLength > config.Default.RequestMaxFileSize {
 | 
					 | 
				
			||||||
				return nil, errors.New("文件过大")
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			return get, nil
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil, err
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,7 +1,6 @@
 | 
				
			|||||||
package common
 | 
					package common
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"errors"
 | 
					 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -18,16 +17,13 @@ func MKDir(dir string) error {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func MkEssentialDir() error {
 | 
					func MkEssentialDir() error {
 | 
				
			||||||
	if err := MKDir("subs"); err != nil {
 | 
						if err := MKDir("subs"); err != nil {
 | 
				
			||||||
		return errors.New("create subs dir failed" + err.Error())
 | 
							return NewDirCreationError("subs", err)
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if err := MKDir("templates"); err != nil {
 | 
					 | 
				
			||||||
		return errors.New("create templates dir failed" + err.Error())
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := MKDir("logs"); err != nil {
 | 
						if err := MKDir("logs"); err != nil {
 | 
				
			||||||
		return errors.New("create logs dir failed" + err.Error())
 | 
							return NewDirCreationError("logs", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := MKDir("data"); err != nil {
 | 
						if err := MKDir("data"); err != nil {
 | 
				
			||||||
		return errors.New("create data dir failed" + err.Error())
 | 
							return NewDirCreationError("data", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,16 +2,13 @@ package common
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sub2clash/constant"
 | 
					 | 
				
			||||||
	"sub2clash/logger"
 | 
					 | 
				
			||||||
	"sub2clash/model"
 | 
					 | 
				
			||||||
	"sub2clash/parser"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"go.uber.org/zap"
 | 
						"github.com/bestnite/sub2clash/model"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func GetContryName(countryKey string) string {
 | 
					func GetContryName(countryKey string) string {
 | 
				
			||||||
	// 创建一个切片包含所有的国家映射
 | 
					
 | 
				
			||||||
	countryMaps := []map[string]string{
 | 
						countryMaps := []map[string]string{
 | 
				
			||||||
		model.CountryFlag,
 | 
							model.CountryFlag,
 | 
				
			||||||
		model.CountryChineseName,
 | 
							model.CountryChineseName,
 | 
				
			||||||
@@ -19,11 +16,9 @@ func GetContryName(countryKey string) string {
 | 
				
			|||||||
		model.CountryEnglishName,
 | 
							model.CountryEnglishName,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 对每一个映射进行检查
 | 
					 | 
				
			||||||
	for i, countryMap := range countryMaps {
 | 
						for i, countryMap := range countryMaps {
 | 
				
			||||||
		if i == 2 {
 | 
							if i == 2 {
 | 
				
			||||||
			// 对ISO匹配做特殊处理
 | 
					
 | 
				
			||||||
			// 根据常用分割字符分割字符串
 | 
					 | 
				
			||||||
			splitChars := []string{"-", "_", " "}
 | 
								splitChars := []string{"-", "_", " "}
 | 
				
			||||||
			key := make([]string, 0)
 | 
								key := make([]string, 0)
 | 
				
			||||||
			for _, splitChar := range splitChars {
 | 
								for _, splitChar := range splitChars {
 | 
				
			||||||
@@ -34,9 +29,9 @@ func GetContryName(countryKey string) string {
 | 
				
			|||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			// 对每一个分割后的字符串进行检查
 | 
					
 | 
				
			||||||
			for _, v := range key {
 | 
								for _, v := range key {
 | 
				
			||||||
				// 如果匹配到了国家
 | 
					
 | 
				
			||||||
				if country, ok := countryMap[strings.ToUpper(v)]; ok {
 | 
									if country, ok := countryMap[strings.ToUpper(v)]; ok {
 | 
				
			||||||
					return country
 | 
										return country
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
@@ -53,19 +48,19 @@ func GetContryName(countryKey string) string {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func AddProxy(
 | 
					func AddProxy(
 | 
				
			||||||
	sub *model.Subscription, autotest bool,
 | 
						sub *model.Subscription, autotest bool,
 | 
				
			||||||
	lazy bool, clashType model.ClashType, proxies ...model.Proxy,
 | 
						lazy bool, clashType model.ClashType, proxies ...proxy.Proxy,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
	proxyTypes := model.GetSupportProxyTypes(clashType)
 | 
						proxyTypes := model.GetSupportProxyTypes(clashType)
 | 
				
			||||||
	// 添加节点
 | 
					
 | 
				
			||||||
	for _, proxy := range proxies {
 | 
						for _, proxy := range proxies {
 | 
				
			||||||
		if !proxyTypes[proxy.Type] {
 | 
							if !proxyTypes[proxy.Type] {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		sub.Proxies = append(sub.Proxies, proxy)
 | 
							sub.Proxy = append(sub.Proxy, proxy)
 | 
				
			||||||
		haveProxyGroup := false
 | 
							haveProxyGroup := false
 | 
				
			||||||
		countryName := GetContryName(proxy.Name)
 | 
							countryName := GetContryName(proxy.Name)
 | 
				
			||||||
		for i := range sub.ProxyGroups {
 | 
							for i := range sub.ProxyGroup {
 | 
				
			||||||
			group := &sub.ProxyGroups[i]
 | 
								group := &sub.ProxyGroup[i]
 | 
				
			||||||
			if group.Name == countryName {
 | 
								if group.Name == countryName {
 | 
				
			||||||
				group.Proxies = append(group.Proxies, proxy.Name)
 | 
									group.Proxies = append(group.Proxies, proxy.Name)
 | 
				
			||||||
				group.Size++
 | 
									group.Size++
 | 
				
			||||||
@@ -95,47 +90,7 @@ func AddProxy(
 | 
				
			|||||||
					Size:          1,
 | 
										Size:          1,
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			sub.ProxyGroups = append(sub.ProxyGroups, newGroup)
 | 
								sub.ProxyGroup = append(sub.ProxyGroup, newGroup)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
func ParseProxy(proxies ...string) []model.Proxy {
 | 
					 | 
				
			||||||
	var result []model.Proxy
 | 
					 | 
				
			||||||
	for _, proxy := range proxies {
 | 
					 | 
				
			||||||
		if proxy != "" {
 | 
					 | 
				
			||||||
			var proxyItem model.Proxy
 | 
					 | 
				
			||||||
			var err error
 | 
					 | 
				
			||||||
			// 解析节点
 | 
					 | 
				
			||||||
			if strings.HasPrefix(proxy, constant.ShadowsocksPrefix) {
 | 
					 | 
				
			||||||
				proxyItem, err = parser.ParseShadowsocks(proxy)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if strings.HasPrefix(proxy, constant.TrojanPrefix) {
 | 
					 | 
				
			||||||
				proxyItem, err = parser.ParseTrojan(proxy)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if strings.HasPrefix(proxy, constant.VMessPrefix) {
 | 
					 | 
				
			||||||
				proxyItem, err = parser.ParseVmess(proxy)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if strings.HasPrefix(proxy, constant.VLESSPrefix) {
 | 
					 | 
				
			||||||
				proxyItem, err = parser.ParseVless(proxy)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if strings.HasPrefix(proxy, constant.ShadowsocksRPrefix) {
 | 
					 | 
				
			||||||
				proxyItem, err = parser.ParseShadowsocksR(proxy)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if strings.HasPrefix(proxy, constant.Hysteria2Prefix1) || strings.HasPrefix(proxy, constant.Hysteria2Prefix2) {
 | 
					 | 
				
			||||||
				proxyItem, err = parser.ParseHysteria2(proxy)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if strings.HasPrefix(proxy, constant.HysteriaPrefix) {
 | 
					 | 
				
			||||||
				proxyItem, err = parser.ParseHysteria(proxy)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if err == nil {
 | 
					 | 
				
			||||||
				result = append(result, proxyItem)
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				logger.Logger.Debug(
 | 
					 | 
				
			||||||
					"parse proxy failed", zap.String("proxy", proxy), zap.Error(err),
 | 
					 | 
				
			||||||
				)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return result
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ package common
 | 
				
			|||||||
import "math/rand"
 | 
					import "math/rand"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func RandomString(length int) string {
 | 
					func RandomString(length int) string {
 | 
				
			||||||
	// 生成随机字符串
 | 
					
 | 
				
			||||||
	const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
 | 
						const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
 | 
				
			||||||
	var result []byte
 | 
						var result []byte
 | 
				
			||||||
	for i := 0; i < length; i++ {
 | 
						for i := 0; i < length; i++ {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										12
									
								
								common/request.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								common/request.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					package common
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"resty.dev/v3"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Request(retryTimes int) *resty.Client {
 | 
				
			||||||
 | 
						client := resty.New()
 | 
				
			||||||
 | 
						client.
 | 
				
			||||||
 | 
							SetRetryCount(retryTimes)
 | 
				
			||||||
 | 
						return client
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -3,16 +3,17 @@ package common
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sub2clash/model"
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func PrependRuleProvider(
 | 
					func PrependRuleProvider(
 | 
				
			||||||
	sub *model.Subscription, providerName string, group string, provider model.RuleProvider,
 | 
						sub *model.Subscription, providerName string, group string, provider model.RuleProvider,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
	if sub.RuleProviders == nil {
 | 
						if sub.RuleProvider == nil {
 | 
				
			||||||
		sub.RuleProviders = make(map[string]model.RuleProvider)
 | 
							sub.RuleProvider = make(map[string]model.RuleProvider)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	sub.RuleProviders[providerName] = provider
 | 
						sub.RuleProvider[providerName] = provider
 | 
				
			||||||
	PrependRules(
 | 
						PrependRules(
 | 
				
			||||||
		sub,
 | 
							sub,
 | 
				
			||||||
		fmt.Sprintf("RULE-SET,%s,%s", providerName, group),
 | 
							fmt.Sprintf("RULE-SET,%s,%s", providerName, group),
 | 
				
			||||||
@@ -22,29 +23,29 @@ func PrependRuleProvider(
 | 
				
			|||||||
func AppenddRuleProvider(
 | 
					func AppenddRuleProvider(
 | 
				
			||||||
	sub *model.Subscription, providerName string, group string, provider model.RuleProvider,
 | 
						sub *model.Subscription, providerName string, group string, provider model.RuleProvider,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
	if sub.RuleProviders == nil {
 | 
						if sub.RuleProvider == nil {
 | 
				
			||||||
		sub.RuleProviders = make(map[string]model.RuleProvider)
 | 
							sub.RuleProvider = make(map[string]model.RuleProvider)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	sub.RuleProviders[providerName] = provider
 | 
						sub.RuleProvider[providerName] = provider
 | 
				
			||||||
	AppendRules(sub, fmt.Sprintf("RULE-SET,%s,%s", providerName, group))
 | 
						AppendRules(sub, fmt.Sprintf("RULE-SET,%s,%s", providerName, group))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func PrependRules(sub *model.Subscription, rules ...string) {
 | 
					func PrependRules(sub *model.Subscription, rules ...string) {
 | 
				
			||||||
	if sub.Rules == nil {
 | 
						if sub.Rule == nil {
 | 
				
			||||||
		sub.Rules = make([]string, 0)
 | 
							sub.Rule = make([]string, 0)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	sub.Rules = append(rules, sub.Rules...)
 | 
						sub.Rule = append(rules, sub.Rule...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func AppendRules(sub *model.Subscription, rules ...string) {
 | 
					func AppendRules(sub *model.Subscription, rules ...string) {
 | 
				
			||||||
	if sub.Rules == nil {
 | 
						if sub.Rule == nil {
 | 
				
			||||||
		sub.Rules = make([]string, 0)
 | 
							sub.Rule = make([]string, 0)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	matchRule := sub.Rules[len(sub.Rules)-1]
 | 
						matchRule := sub.Rule[len(sub.Rule)-1]
 | 
				
			||||||
	if strings.Contains(matchRule, "MATCH") {
 | 
						if strings.Contains(matchRule, "MATCH") {
 | 
				
			||||||
		sub.Rules = append(sub.Rules[:len(sub.Rules)-1], rules...)
 | 
							sub.Rule = append(sub.Rule[:len(sub.Rule)-1], rules...)
 | 
				
			||||||
		sub.Rules = append(sub.Rules, matchRule)
 | 
							sub.Rule = append(sub.Rule, matchRule)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	sub.Rules = append(sub.Rules, rules...)
 | 
						sub.Rule = append(sub.Rule, rules...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										339
									
								
								common/sub.go
									
									
									
									
									
								
							
							
						
						
									
										339
									
								
								common/sub.go
									
									
									
									
									
								
							@@ -5,20 +5,31 @@ import (
 | 
				
			|||||||
	"encoding/hex"
 | 
						"encoding/hex"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"net/http"
 | 
						"net/url"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
	"sub2clash/config"
 | 
						"regexp"
 | 
				
			||||||
 | 
						"sort"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/logger"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model"
 | 
				
			||||||
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/parser"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/utils"
 | 
				
			||||||
 | 
						"go.uber.org/zap"
 | 
				
			||||||
 | 
						"gopkg.in/yaml.v3"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var subsDir = "subs"
 | 
					var subsDir = "subs"
 | 
				
			||||||
var fileLock sync.RWMutex
 | 
					var fileLock sync.RWMutex
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func LoadSubscription(url string, refresh bool) ([]byte, error) {
 | 
					func LoadSubscription(url string, refresh bool, userAgent string, cacheExpire int64, retryTimes int) ([]byte, error) {
 | 
				
			||||||
	if refresh {
 | 
						if refresh {
 | 
				
			||||||
		return FetchSubscriptionFromAPI(url)
 | 
							return FetchSubscriptionFromAPI(url, userAgent, retryTimes)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	hash := sha256.Sum224([]byte(url))
 | 
						hash := sha256.Sum224([]byte(url))
 | 
				
			||||||
	fileName := filepath.Join(subsDir, hex.EncodeToString(hash[:]))
 | 
						fileName := filepath.Join(subsDir, hex.EncodeToString(hash[:]))
 | 
				
			||||||
@@ -27,10 +38,10 @@ func LoadSubscription(url string, refresh bool) ([]byte, error) {
 | 
				
			|||||||
		if !os.IsNotExist(err) {
 | 
							if !os.IsNotExist(err) {
 | 
				
			||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return FetchSubscriptionFromAPI(url)
 | 
							return FetchSubscriptionFromAPI(url, userAgent, retryTimes)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	lastGetTime := stat.ModTime().Unix() // 单位是秒
 | 
						lastGetTime := stat.ModTime().Unix()
 | 
				
			||||||
	if lastGetTime+config.Default.CacheExpire > time.Now().Unix() {
 | 
						if lastGetTime+cacheExpire > time.Now().Unix() {
 | 
				
			||||||
		file, err := os.Open(fileName)
 | 
							file, err := os.Open(fileName)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
@@ -48,21 +59,18 @@ func LoadSubscription(url string, refresh bool) ([]byte, error) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		return subContent, nil
 | 
							return subContent, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return FetchSubscriptionFromAPI(url)
 | 
						return FetchSubscriptionFromAPI(url, userAgent, retryTimes)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func FetchSubscriptionFromAPI(url string) ([]byte, error) {
 | 
					func FetchSubscriptionFromAPI(url string, userAgent string, retryTimes int) ([]byte, error) {
 | 
				
			||||||
	hash := sha256.Sum224([]byte(url))
 | 
						hash := sha256.Sum224([]byte(url))
 | 
				
			||||||
	fileName := filepath.Join(subsDir, hex.EncodeToString(hash[:]))
 | 
						fileName := filepath.Join(subsDir, hex.EncodeToString(hash[:]))
 | 
				
			||||||
	resp, err := Get(url)
 | 
						client := Request(retryTimes)
 | 
				
			||||||
 | 
						defer client.Close()
 | 
				
			||||||
 | 
						resp, err := client.R().SetHeader("User-Agent", userAgent).Get(url)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer func(resp *http.Response) {
 | 
					 | 
				
			||||||
		if resp != nil && resp.Body != nil {
 | 
					 | 
				
			||||||
			_ = resp.Body.Close()
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}(resp)
 | 
					 | 
				
			||||||
	data, err := io.ReadAll(resp.Body)
 | 
						data, err := io.ReadAll(resp.Body)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, fmt.Errorf("failed to read response body: %w", err)
 | 
							return nil, fmt.Errorf("failed to read response body: %w", err)
 | 
				
			||||||
@@ -84,3 +92,304 @@ func FetchSubscriptionFromAPI(url string) ([]byte, error) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return data, nil
 | 
						return data, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func BuildSub(clashType model.ClashType, query model.ConvertConfig, template string, cacheExpire int64, retryTimes int) (
 | 
				
			||||||
 | 
						*model.Subscription, error,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
 | 
						var temp = &model.Subscription{}
 | 
				
			||||||
 | 
						var sub = &model.Subscription{}
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
						var templateBytes []byte
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if query.Template != "" {
 | 
				
			||||||
 | 
							template = query.Template
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if strings.HasPrefix(template, "http") {
 | 
				
			||||||
 | 
							templateBytes, err = LoadSubscription(template, query.Refresh, query.UserAgent, cacheExpire, retryTimes)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								logger.Logger.Debug(
 | 
				
			||||||
 | 
									"load template failed", zap.String("template", template), zap.Error(err),
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
								return nil, NewTemplateLoadError(template, err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							unescape, err := url.QueryUnescape(template)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, NewTemplateLoadError(template, err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							templateBytes, err = LoadTemplate(unescape)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								logger.Logger.Debug(
 | 
				
			||||||
 | 
									"load template failed", zap.String("template", template), zap.Error(err),
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
								return nil, NewTemplateLoadError(unescape, err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = yaml.Unmarshal(templateBytes, &temp)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							logger.Logger.Debug("parse template failed", zap.Error(err))
 | 
				
			||||||
 | 
							return nil, NewTemplateParseError(templateBytes, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						var proxyList []P.Proxy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for i := range query.Subs {
 | 
				
			||||||
 | 
							data, err := LoadSubscription(query.Subs[i], query.Refresh, query.UserAgent, cacheExpire, retryTimes)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								logger.Logger.Debug(
 | 
				
			||||||
 | 
									"load subscription failed", zap.String("url", query.Subs[i]), zap.Error(err),
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
								return nil, NewSubscriptionLoadError(query.Subs[i], err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							subName := ""
 | 
				
			||||||
 | 
							if strings.Contains(query.Subs[i], "#") {
 | 
				
			||||||
 | 
								subName = query.Subs[i][strings.LastIndex(query.Subs[i], "#")+1:]
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							err = yaml.Unmarshal(data, &sub)
 | 
				
			||||||
 | 
							var newProxies []P.Proxy
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								reg, err := regexp.Compile("(" + strings.Join(parser.GetAllPrefixes(), "|") + ")://")
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									logger.Logger.Debug("compile regex failed", zap.Error(err))
 | 
				
			||||||
 | 
									return nil, NewRegexInvalidError("prefix", err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if reg.Match(data) {
 | 
				
			||||||
 | 
									p, err := parser.ParseProxies(parser.ParseConfig{UseUDP: query.UseUDP}, strings.Split(string(data), "\n")...)
 | 
				
			||||||
 | 
									if err != nil {
 | 
				
			||||||
 | 
										return nil, err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									newProxies = p
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									base64, err := utils.DecodeBase64(string(data), false)
 | 
				
			||||||
 | 
									if err != nil {
 | 
				
			||||||
 | 
										logger.Logger.Debug(
 | 
				
			||||||
 | 
											"parse subscription failed", zap.String("url", query.Subs[i]),
 | 
				
			||||||
 | 
											zap.String("data", string(data)),
 | 
				
			||||||
 | 
											zap.Error(err),
 | 
				
			||||||
 | 
										)
 | 
				
			||||||
 | 
										return nil, NewSubscriptionParseError(data, err)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									p, err := parser.ParseProxies(parser.ParseConfig{UseUDP: query.UseUDP}, strings.Split(base64, "\n")...)
 | 
				
			||||||
 | 
									if err != nil {
 | 
				
			||||||
 | 
										return nil, err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									newProxies = p
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								newProxies = sub.Proxy
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if subName != "" {
 | 
				
			||||||
 | 
								for i := range newProxies {
 | 
				
			||||||
 | 
									newProxies[i].SubName = subName
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							proxyList = append(proxyList, newProxies...)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(query.Proxies) != 0 {
 | 
				
			||||||
 | 
							p, err := parser.ParseProxies(parser.ParseConfig{UseUDP: query.UseUDP}, query.Proxies...)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							proxyList = append(proxyList, p...)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for i := range proxyList {
 | 
				
			||||||
 | 
							if proxyList[i].SubName != "" {
 | 
				
			||||||
 | 
								proxyList[i].Name = strings.TrimSpace(proxyList[i].SubName) + " " + strings.TrimSpace(proxyList[i].Name)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 去重
 | 
				
			||||||
 | 
						proxies := make(map[string]*P.Proxy)
 | 
				
			||||||
 | 
						newProxies := make([]P.Proxy, 0, len(proxyList))
 | 
				
			||||||
 | 
						for i := range proxyList {
 | 
				
			||||||
 | 
							yamlBytes, err := yaml.Marshal(proxyList[i])
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								logger.Logger.Debug("marshal proxy failed", zap.Error(err))
 | 
				
			||||||
 | 
								return nil, fmt.Errorf("marshal proxy failed: %w", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							key := string(yamlBytes)
 | 
				
			||||||
 | 
							if _, exist := proxies[key]; !exist {
 | 
				
			||||||
 | 
								proxies[key] = &proxyList[i]
 | 
				
			||||||
 | 
								newProxies = append(newProxies, proxyList[i])
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						proxyList = newProxies
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 移除
 | 
				
			||||||
 | 
						if strings.TrimSpace(query.Remove) != "" {
 | 
				
			||||||
 | 
							newProxyList := make([]P.Proxy, 0, len(proxyList))
 | 
				
			||||||
 | 
							for i := range proxyList {
 | 
				
			||||||
 | 
								removeReg, err := regexp.Compile(query.Remove)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									logger.Logger.Debug("remove regexp compile failed", zap.Error(err))
 | 
				
			||||||
 | 
									return nil, NewRegexInvalidError("remove", err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if removeReg.MatchString(proxyList[i].Name) {
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								newProxyList = append(newProxyList, proxyList[i])
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							proxyList = newProxyList
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 替换
 | 
				
			||||||
 | 
						if len(query.Replace) != 0 {
 | 
				
			||||||
 | 
							for k, v := range query.Replace {
 | 
				
			||||||
 | 
								replaceReg, err := regexp.Compile(k)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									logger.Logger.Debug("replace regexp compile failed", zap.Error(err))
 | 
				
			||||||
 | 
									return nil, NewRegexInvalidError("replace", err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								for i := range proxyList {
 | 
				
			||||||
 | 
									if replaceReg.MatchString(proxyList[i].Name) {
 | 
				
			||||||
 | 
										proxyList[i].Name = replaceReg.ReplaceAllString(
 | 
				
			||||||
 | 
											proxyList[i].Name, v,
 | 
				
			||||||
 | 
										)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 重命名有相同名称的节点
 | 
				
			||||||
 | 
						names := make(map[string]int)
 | 
				
			||||||
 | 
						for i := range proxyList {
 | 
				
			||||||
 | 
							if _, exist := names[proxyList[i].Name]; exist {
 | 
				
			||||||
 | 
								names[proxyList[i].Name] = names[proxyList[i].Name] + 1
 | 
				
			||||||
 | 
								proxyList[i].Name = proxyList[i].Name + " " + strconv.Itoa(names[proxyList[i].Name])
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								names[proxyList[i].Name] = 0
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for i := range proxyList {
 | 
				
			||||||
 | 
							proxyList[i].Name = strings.TrimSpace(proxyList[i].Name)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var t = &model.Subscription{}
 | 
				
			||||||
 | 
						AddProxy(t, query.AutoTest, query.Lazy, clashType, proxyList...)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 排序
 | 
				
			||||||
 | 
						switch query.Sort {
 | 
				
			||||||
 | 
						case "sizeasc":
 | 
				
			||||||
 | 
							sort.Sort(model.ProxyGroupsSortBySize(t.ProxyGroup))
 | 
				
			||||||
 | 
						case "sizedesc":
 | 
				
			||||||
 | 
							sort.Sort(sort.Reverse(model.ProxyGroupsSortBySize(t.ProxyGroup)))
 | 
				
			||||||
 | 
						case "nameasc":
 | 
				
			||||||
 | 
							sort.Sort(model.ProxyGroupsSortByName(t.ProxyGroup))
 | 
				
			||||||
 | 
						case "namedesc":
 | 
				
			||||||
 | 
							sort.Sort(sort.Reverse(model.ProxyGroupsSortByName(t.ProxyGroup)))
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							sort.Sort(model.ProxyGroupsSortByName(t.ProxyGroup))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						MergeSubAndTemplate(temp, t, query.IgnoreCountryGrooup)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, v := range query.Rules {
 | 
				
			||||||
 | 
							if v.Prepend {
 | 
				
			||||||
 | 
								PrependRules(temp, v.Rule)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								AppendRules(temp, v.Rule)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, v := range query.RuleProviders {
 | 
				
			||||||
 | 
							hash := sha256.Sum224([]byte(v.Url))
 | 
				
			||||||
 | 
							name := hex.EncodeToString(hash[:])
 | 
				
			||||||
 | 
							provider := model.RuleProvider{
 | 
				
			||||||
 | 
								Type:     "http",
 | 
				
			||||||
 | 
								Behavior: v.Behavior,
 | 
				
			||||||
 | 
								Url:      v.Url,
 | 
				
			||||||
 | 
								Path:     "./" + name + ".yaml",
 | 
				
			||||||
 | 
								Interval: 3600,
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if v.Prepend {
 | 
				
			||||||
 | 
								PrependRuleProvider(
 | 
				
			||||||
 | 
									temp, v.Name, v.Group, provider,
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								AppenddRuleProvider(
 | 
				
			||||||
 | 
									temp, v.Name, v.Group, provider,
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return temp, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func FetchSubscriptionUserInfo(url string, userAgent string, retryTimes int) (string, error) {
 | 
				
			||||||
 | 
						client := Request(retryTimes)
 | 
				
			||||||
 | 
						defer client.Close()
 | 
				
			||||||
 | 
						resp, err := client.R().SetHeader("User-Agent", userAgent).Head(url)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							logger.Logger.Debug("创建 HEAD 请求失败", zap.Error(err))
 | 
				
			||||||
 | 
							return "", NewNetworkRequestError(url, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer resp.Body.Close()
 | 
				
			||||||
 | 
						if userInfo := resp.Header().Get("subscription-userinfo"); userInfo != "" {
 | 
				
			||||||
 | 
							return userInfo, nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						logger.Logger.Debug("subscription-userinfo header not found in response")
 | 
				
			||||||
 | 
						return "", NewNetworkResponseError("subscription-userinfo header not found", nil)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func MergeSubAndTemplate(temp *model.Subscription, sub *model.Subscription, igcg bool) {
 | 
				
			||||||
 | 
						var countryGroupNames []string
 | 
				
			||||||
 | 
						for _, proxyGroup := range sub.ProxyGroup {
 | 
				
			||||||
 | 
							if proxyGroup.IsCountryGrop {
 | 
				
			||||||
 | 
								countryGroupNames = append(
 | 
				
			||||||
 | 
									countryGroupNames, proxyGroup.Name,
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						var proxyNames []string
 | 
				
			||||||
 | 
						for _, proxy := range sub.Proxy {
 | 
				
			||||||
 | 
							proxyNames = append(proxyNames, proxy.Name)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						temp.Proxy = append(temp.Proxy, sub.Proxy...)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for i := range temp.ProxyGroup {
 | 
				
			||||||
 | 
							if temp.ProxyGroup[i].IsCountryGrop {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							newProxies := make([]string, 0)
 | 
				
			||||||
 | 
							countryGroupMap := make(map[string]model.ProxyGroup)
 | 
				
			||||||
 | 
							for _, v := range sub.ProxyGroup {
 | 
				
			||||||
 | 
								if v.IsCountryGrop {
 | 
				
			||||||
 | 
									countryGroupMap[v.Name] = v
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							for j := range temp.ProxyGroup[i].Proxies {
 | 
				
			||||||
 | 
								reg := regexp.MustCompile("<(.*?)>")
 | 
				
			||||||
 | 
								if reg.Match([]byte(temp.ProxyGroup[i].Proxies[j])) {
 | 
				
			||||||
 | 
									key := reg.FindStringSubmatch(temp.ProxyGroup[i].Proxies[j])[1]
 | 
				
			||||||
 | 
									switch key {
 | 
				
			||||||
 | 
									case "all":
 | 
				
			||||||
 | 
										newProxies = append(newProxies, proxyNames...)
 | 
				
			||||||
 | 
									case "countries":
 | 
				
			||||||
 | 
										if !igcg {
 | 
				
			||||||
 | 
											newProxies = append(newProxies, countryGroupNames...)
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									default:
 | 
				
			||||||
 | 
										if !igcg {
 | 
				
			||||||
 | 
											if len(key) == 2 {
 | 
				
			||||||
 | 
												newProxies = append(
 | 
				
			||||||
 | 
													newProxies, countryGroupMap[GetContryName(key)].Proxies...,
 | 
				
			||||||
 | 
												)
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									newProxies = append(newProxies, temp.ProxyGroup[i].Proxies[j])
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							temp.ProxyGroup[i].Proxies = newProxies
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !igcg {
 | 
				
			||||||
 | 
							temp.ProxyGroup = append(temp.ProxyGroup, sub.ProxyGroup...)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,18 +1,29 @@
 | 
				
			|||||||
package common
 | 
					package common
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"errors"
 | 
					 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// LoadTemplate 加载模板
 | 
					const templatesDir = "templates"
 | 
				
			||||||
// templates 模板文件名
 | 
					
 | 
				
			||||||
func LoadTemplate(template string) ([]byte, error) {
 | 
					// LoadTemplate 只读取运行目录下的 templates 目录,防止其他文件内容泄漏
 | 
				
			||||||
	tPath := filepath.Join("templates", template)
 | 
					func LoadTemplate(templateName string) ([]byte, error) {
 | 
				
			||||||
	if _, err := os.Stat(tPath); err == nil {
 | 
						// 清理路径,防止目录遍历攻击
 | 
				
			||||||
		file, err := os.Open(tPath)
 | 
						cleanTemplateName := filepath.Clean(templateName)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 检查是否尝试访问父目录
 | 
				
			||||||
 | 
						if strings.HasPrefix(cleanTemplateName, "..") || strings.Contains(cleanTemplateName, string(filepath.Separator)+".."+string(filepath.Separator)) {
 | 
				
			||||||
 | 
							return nil, NewFileNotFoundError(templateName) // 拒绝包含父目录的路径
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 构建完整路径,确保只从 templates 目录读取
 | 
				
			||||||
 | 
						fullPath := filepath.Join(templatesDir, cleanTemplateName)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if _, err := os.Stat(fullPath); err == nil {
 | 
				
			||||||
 | 
							file, err := os.Open(fullPath)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -27,5 +38,5 @@ func LoadTemplate(template string) ([]byte, error) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		return result, nil
 | 
							return result, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return nil, errors.New("模板文件不存在")
 | 
						return nil, NewFileNotFoundError(templateName)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,39 +0,0 @@
 | 
				
			|||||||
package common
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"os"
 | 
					 | 
				
			||||||
	"path/filepath"
 | 
					 | 
				
			||||||
	"sub2clash/config"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func writeTemplate(path string, template string) error {
 | 
					 | 
				
			||||||
	tPath := filepath.Join(
 | 
					 | 
				
			||||||
		"templates", path,
 | 
					 | 
				
			||||||
	)
 | 
					 | 
				
			||||||
	if _, err := os.Stat(tPath); os.IsNotExist(err) {
 | 
					 | 
				
			||||||
		file, err := os.Create(tPath)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		defer func(file *os.File) {
 | 
					 | 
				
			||||||
			if file != nil {
 | 
					 | 
				
			||||||
				_ = file.Close()
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}(file)
 | 
					 | 
				
			||||||
		_, err = file.WriteString(template)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func WriteDefalutTemplate(templateMeta string, templateClash string) error {
 | 
					 | 
				
			||||||
	if err := writeTemplate(config.Default.MetaTemplate, templateMeta); err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if err := writeTemplate(config.Default.ClashTemplate, templateClash); err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										11
									
								
								compose.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								compose.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					name: sub2clash
 | 
				
			||||||
 | 
					services:
 | 
				
			||||||
 | 
					    sub2clash:
 | 
				
			||||||
 | 
					        restart: unless-stopped
 | 
				
			||||||
 | 
					        image: nite07/sub2clash:latest
 | 
				
			||||||
 | 
					        ports:
 | 
				
			||||||
 | 
					            - "8011:8011"
 | 
				
			||||||
 | 
					        volumes:
 | 
				
			||||||
 | 
					            # - ./logs:/app/logs
 | 
				
			||||||
 | 
					            # - ./templates:/app/templates
 | 
				
			||||||
 | 
					            - ./data:/app/data
 | 
				
			||||||
							
								
								
									
										10
									
								
								config.example.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								config.example.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					    "address": "0.0.0.0:8011",
 | 
				
			||||||
 | 
					    "meta_template": "https://raw.githubusercontent.com/bestnite/sub2clash/refs/heads/main/templates/template_meta.yaml",
 | 
				
			||||||
 | 
					    "clash_template": "https://raw.githubusercontent.com/bestnite/sub2clash/refs/heads/main/templates/template_clash.yaml",
 | 
				
			||||||
 | 
					    "request_retry_times": 3,
 | 
				
			||||||
 | 
					    "request_max_file_size": 1048576,
 | 
				
			||||||
 | 
					    "cache_expire": 300,
 | 
				
			||||||
 | 
					    "log_level": "info",
 | 
				
			||||||
 | 
					    "short_link_length": 6
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										22
									
								
								config.example.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								config.example.yaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					# Sub2Clash 配置文件示例
 | 
				
			||||||
 | 
					# 复制此文件为 config.yaml 并根据需要修改配置
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 服务端口
 | 
				
			||||||
 | 
					address: "0.0.0.0:8011"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 模板配置
 | 
				
			||||||
 | 
					meta_template: "https://raw.githubusercontent.com/bestnite/sub2clash/refs/heads/main/templates/template_meta.yaml"
 | 
				
			||||||
 | 
					clash_template: "https://raw.githubusercontent.com/bestnite/sub2clash/refs/heads/main/templates/template_clash.yaml"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 请求配置
 | 
				
			||||||
 | 
					request_retry_times: 3
 | 
				
			||||||
 | 
					request_max_file_size: 1048576 # 1MB in bytes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 缓存配置 (秒)
 | 
				
			||||||
 | 
					cache_expire: 300 # 5 minutes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 日志级别 (debug, info, warn, error)
 | 
				
			||||||
 | 
					log_level: "info"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 短链接长度
 | 
				
			||||||
 | 
					short_link_length: 6
 | 
				
			||||||
							
								
								
									
										128
									
								
								config/config.go
									
									
									
									
									
								
							
							
						
						
									
										128
									
								
								config/config.go
									
									
									
									
									
								
							@@ -1,90 +1,76 @@
 | 
				
			|||||||
package config
 | 
					package config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"errors"
 | 
						"strings"
 | 
				
			||||||
	"os"
 | 
					 | 
				
			||||||
	"strconv"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/joho/godotenv"
 | 
						"github.com/spf13/viper"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Config struct {
 | 
					type Config struct {
 | 
				
			||||||
	Port               int
 | 
						Address            string `mapstructure:"address"`
 | 
				
			||||||
	MetaTemplate       string
 | 
						MetaTemplate       string `mapstructure:"meta_template"`
 | 
				
			||||||
	ClashTemplate      string
 | 
						ClashTemplate      string `mapstructure:"clash_template"`
 | 
				
			||||||
	RequestRetryTimes  int
 | 
						RequestRetryTimes  int    `mapstructure:"request_retry_times"`
 | 
				
			||||||
	RequestMaxFileSize int64
 | 
						RequestMaxFileSize int64  `mapstructure:"request_max_file_size"`
 | 
				
			||||||
	CacheExpire        int64
 | 
						CacheExpire        int64  `mapstructure:"cache_expire"`
 | 
				
			||||||
	LogLevel           string
 | 
						LogLevel           string `mapstructure:"log_level"`
 | 
				
			||||||
	//BasePath           string
 | 
						ShortLinkLength    int    `mapstructure:"short_link_length"`
 | 
				
			||||||
	ShortLinkLength int
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var Default *Config
 | 
					var GlobalConfig *Config
 | 
				
			||||||
var Dev string
 | 
					var Dev string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func LoadConfig() error {
 | 
					func LoadConfig() error {
 | 
				
			||||||
	Default = &Config{
 | 
						v := viper.New()
 | 
				
			||||||
		MetaTemplate:       "template_meta.yaml",
 | 
					
 | 
				
			||||||
		ClashTemplate:      "template_clash.yaml",
 | 
						// 添加配置文件搜索路径
 | 
				
			||||||
		RequestRetryTimes:  3,
 | 
						v.AddConfigPath(".")
 | 
				
			||||||
		RequestMaxFileSize: 1024 * 1024 * 1,
 | 
						v.AddConfigPath("./config")
 | 
				
			||||||
		Port:               8011,
 | 
						v.AddConfigPath("/etc/sub2clash/")
 | 
				
			||||||
		CacheExpire:        60 * 5,
 | 
					
 | 
				
			||||||
		LogLevel:           "info",
 | 
						// 设置默认值
 | 
				
			||||||
		//BasePath:           "/",
 | 
						setDefaults(v)
 | 
				
			||||||
		ShortLinkLength: 6,
 | 
					
 | 
				
			||||||
 | 
						// 设置环境变量前缀和自动绑定
 | 
				
			||||||
 | 
						v.SetEnvPrefix("SUB2CLASH")
 | 
				
			||||||
 | 
						v.AutomaticEnv()
 | 
				
			||||||
 | 
						v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 尝试按优先级加载不同格式的配置文件
 | 
				
			||||||
 | 
						configLoaded := false
 | 
				
			||||||
 | 
						configNames := []string{"config", "sub2clash"}
 | 
				
			||||||
 | 
						configExts := []string{"yaml", "yml", "json"}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, name := range configNames {
 | 
				
			||||||
 | 
							for _, ext := range configExts {
 | 
				
			||||||
 | 
								v.SetConfigName(name)
 | 
				
			||||||
 | 
								v.SetConfigType(ext)
 | 
				
			||||||
 | 
								if err := v.ReadInConfig(); err == nil {
 | 
				
			||||||
 | 
									configLoaded = true
 | 
				
			||||||
 | 
									break
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
	_ = godotenv.Load()
 | 
					 | 
				
			||||||
	if os.Getenv("PORT") != "" {
 | 
					 | 
				
			||||||
		atoi, err := strconv.Atoi(os.Getenv("PORT"))
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return errors.New("PORT invalid")
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		Default.Port = atoi
 | 
							if configLoaded {
 | 
				
			||||||
 | 
								break
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	if os.Getenv("META_TEMPLATE") != "" {
 | 
					 | 
				
			||||||
		Default.MetaTemplate = os.Getenv("META_TEMPLATE")
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if os.Getenv("CLASH_TEMPLATE") != "" {
 | 
					
 | 
				
			||||||
		Default.ClashTemplate = os.Getenv("CLASH_TEMPLATE")
 | 
						// 将配置解析到结构体
 | 
				
			||||||
	}
 | 
						GlobalConfig = &Config{}
 | 
				
			||||||
	if os.Getenv("REQUEST_RETRY_TIMES") != "" {
 | 
						if err := v.Unmarshal(GlobalConfig); err != nil {
 | 
				
			||||||
		atoi, err := strconv.Atoi(os.Getenv("REQUEST_RETRY_TIMES"))
 | 
							return err
 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return errors.New("REQUEST_RETRY_TIMES invalid")
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		Default.RequestRetryTimes = atoi
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if os.Getenv("REQUEST_MAX_FILE_SIZE") != "" {
 | 
					 | 
				
			||||||
		atoi, err := strconv.Atoi(os.Getenv("REQUEST_MAX_FILE_SIZE"))
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return errors.New("REQUEST_MAX_FILE_SIZE invalid")
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		Default.RequestMaxFileSize = int64(atoi)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if os.Getenv("CACHE_EXPIRE") != "" {
 | 
					 | 
				
			||||||
		atoi, err := strconv.Atoi(os.Getenv("CACHE_EXPIRE"))
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return errors.New("CACHE_EXPIRE invalid")
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		Default.CacheExpire = int64(atoi)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if os.Getenv("LOG_LEVEL") != "" {
 | 
					 | 
				
			||||||
		Default.LogLevel = os.Getenv("LOG_LEVEL")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	//if os.Getenv("BASE_PATH") != "" {
 | 
					 | 
				
			||||||
	//	Default.BasePath = os.Getenv("BASE_PATH")
 | 
					 | 
				
			||||||
	//	if Default.BasePath[len(Default.BasePath)-1] != '/' {
 | 
					 | 
				
			||||||
	//		Default.BasePath += "/"
 | 
					 | 
				
			||||||
	//	}
 | 
					 | 
				
			||||||
	//}
 | 
					 | 
				
			||||||
	if os.Getenv("SHORT_LINK_LENGTH") != "" {
 | 
					 | 
				
			||||||
		atoi, err := strconv.Atoi(os.Getenv("SHORT_LINK_LENGTH"))
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return errors.New("SHORT_LINK_LENGTH invalid")
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		Default.ShortLinkLength = atoi
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func setDefaults(v *viper.Viper) {
 | 
				
			||||||
 | 
						v.SetDefault("address", "0.0.0.0:8011")
 | 
				
			||||||
 | 
						v.SetDefault("meta_template", "https://raw.githubusercontent.com/bestnite/sub2clash/refs/heads/main/templates/template_meta.yaml")
 | 
				
			||||||
 | 
						v.SetDefault("clash_template", "https://raw.githubusercontent.com/bestnite/sub2clash/refs/heads/main/templates/template_clash.yaml")
 | 
				
			||||||
 | 
						v.SetDefault("request_retry_times", 3)
 | 
				
			||||||
 | 
						v.SetDefault("request_max_file_size", 1024*1024*1)
 | 
				
			||||||
 | 
						v.SetDefault("cache_expire", 60*5)
 | 
				
			||||||
 | 
						v.SetDefault("log_level", "info")
 | 
				
			||||||
 | 
						v.SetDefault("short_link_length", 6)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,12 +0,0 @@
 | 
				
			|||||||
package constant
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const (
 | 
					 | 
				
			||||||
	HysteriaPrefix     string = "hysteria://"
 | 
					 | 
				
			||||||
	Hysteria2Prefix1   string = "hysteria2://"
 | 
					 | 
				
			||||||
	Hysteria2Prefix2   string = "hy2://"
 | 
					 | 
				
			||||||
	ShadowsocksPrefix  string = "ss://"
 | 
					 | 
				
			||||||
	ShadowsocksRPrefix string = "ssr://"
 | 
					 | 
				
			||||||
	TrojanPrefix       string = "trojan://"
 | 
					 | 
				
			||||||
	VLESSPrefix        string = "vless://"
 | 
					 | 
				
			||||||
	VMessPrefix        string = "vmess://"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
@@ -1,21 +0,0 @@
 | 
				
			|||||||
version: "3"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
services:
 | 
					 | 
				
			||||||
    sub2clash:
 | 
					 | 
				
			||||||
        container_name: sub2clash
 | 
					 | 
				
			||||||
        restart: unless-stopped
 | 
					 | 
				
			||||||
        image: nite07/sub2clash:latest
 | 
					 | 
				
			||||||
        ports:
 | 
					 | 
				
			||||||
            - "8011:8011"
 | 
					 | 
				
			||||||
        volumes:
 | 
					 | 
				
			||||||
            - ./logs:/app/logs
 | 
					 | 
				
			||||||
            - ./templates:/app/templates
 | 
					 | 
				
			||||||
            - ./data:/app/data
 | 
					 | 
				
			||||||
        # environment:
 | 
					 | 
				
			||||||
        #   - PORT=8011
 | 
					 | 
				
			||||||
        #   - META_TEMPLATE=template_meta.yaml
 | 
					 | 
				
			||||||
        #   - PROXY_TEMPLATE=template_clash.yaml
 | 
					 | 
				
			||||||
        #   - REQUEST_RETRY_TIMES=3
 | 
					 | 
				
			||||||
        #   - REQUEST_MAX_FILE_SIZE=1048576
 | 
					 | 
				
			||||||
        #   - CACHE_EXPIRE=300
 | 
					 | 
				
			||||||
        #   - LOG_LEVEL=info
 | 
					 | 
				
			||||||
							
								
								
									
										131
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										131
									
								
								go.mod
									
									
									
									
									
								
							@@ -1,42 +1,143 @@
 | 
				
			|||||||
module sub2clash
 | 
					module github.com/bestnite/sub2clash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
go 1.21
 | 
					go 1.25
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/gin-gonic/gin v1.9.1
 | 
						github.com/gin-gonic/gin v1.10.1
 | 
				
			||||||
	github.com/joho/godotenv v1.5.1
 | 
						github.com/metacubex/mihomo v1.19.10
 | 
				
			||||||
 | 
						github.com/spf13/viper v1.20.1
 | 
				
			||||||
	go.etcd.io/bbolt v1.3.9
 | 
						go.etcd.io/bbolt v1.3.9
 | 
				
			||||||
	go.uber.org/zap v1.27.0
 | 
						go.uber.org/zap v1.27.0
 | 
				
			||||||
	golang.org/x/text v0.14.0
 | 
						golang.org/x/text v0.22.0
 | 
				
			||||||
	gopkg.in/natefinch/lumberjack.v2 v2.2.1
 | 
						gopkg.in/natefinch/lumberjack.v2 v2.2.1
 | 
				
			||||||
	gopkg.in/yaml.v3 v3.0.1
 | 
						gopkg.in/yaml.v3 v3.0.1
 | 
				
			||||||
 | 
						resty.dev/v3 v3.0.0-beta.3
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/bytedance/sonic v1.11.5 // indirect
 | 
						github.com/3andne/restls-client-go v0.1.6 // indirect
 | 
				
			||||||
 | 
						github.com/RyuaNerin/go-krypto v1.3.0 // indirect
 | 
				
			||||||
 | 
						github.com/Yawning/aez v0.0.0-20211027044916-e49e68abd344 // indirect
 | 
				
			||||||
 | 
						github.com/andybalholm/brotli v1.0.6 // indirect
 | 
				
			||||||
 | 
						github.com/bahlo/generic-list-go v0.2.0 // indirect
 | 
				
			||||||
 | 
						github.com/buger/jsonparser v1.1.1 // indirect
 | 
				
			||||||
 | 
						github.com/bytedance/sonic v1.11.6 // indirect
 | 
				
			||||||
	github.com/bytedance/sonic/loader v0.1.1 // indirect
 | 
						github.com/bytedance/sonic/loader v0.1.1 // indirect
 | 
				
			||||||
	github.com/cloudwego/base64x v0.1.3 // indirect
 | 
						github.com/cloudflare/circl v1.3.7 // indirect
 | 
				
			||||||
 | 
						github.com/cloudwego/base64x v0.1.4 // indirect
 | 
				
			||||||
	github.com/cloudwego/iasm v0.2.0 // indirect
 | 
						github.com/cloudwego/iasm v0.2.0 // indirect
 | 
				
			||||||
 | 
						github.com/coreos/go-iptables v0.8.0 // indirect
 | 
				
			||||||
 | 
						github.com/dlclark/regexp2 v1.11.5 // indirect
 | 
				
			||||||
 | 
						github.com/ebitengine/purego v0.8.3 // indirect
 | 
				
			||||||
 | 
						github.com/enfein/mieru/v3 v3.13.0 // indirect
 | 
				
			||||||
 | 
						github.com/ericlagergren/aegis v0.0.0-20250325060835-cd0defd64358 // indirect
 | 
				
			||||||
 | 
						github.com/ericlagergren/polyval v0.0.0-20220411101811-e25bc10ba391 // indirect
 | 
				
			||||||
 | 
						github.com/ericlagergren/siv v0.0.0-20220507050439-0b757b3aa5f1 // indirect
 | 
				
			||||||
 | 
						github.com/ericlagergren/subtle v0.0.0-20220507045147-890d697da010 // indirect
 | 
				
			||||||
 | 
						github.com/fsnotify/fsnotify v1.9.0 // indirect
 | 
				
			||||||
	github.com/gabriel-vasile/mimetype v1.4.3 // indirect
 | 
						github.com/gabriel-vasile/mimetype v1.4.3 // indirect
 | 
				
			||||||
 | 
						github.com/gaukas/godicttls v0.0.4 // indirect
 | 
				
			||||||
	github.com/gin-contrib/sse v0.1.0 // indirect
 | 
						github.com/gin-contrib/sse v0.1.0 // indirect
 | 
				
			||||||
 | 
						github.com/go-ole/go-ole v1.3.0 // indirect
 | 
				
			||||||
	github.com/go-playground/locales v0.14.1 // indirect
 | 
						github.com/go-playground/locales v0.14.1 // indirect
 | 
				
			||||||
	github.com/go-playground/universal-translator v0.18.1 // indirect
 | 
						github.com/go-playground/universal-translator v0.18.1 // indirect
 | 
				
			||||||
	github.com/go-playground/validator/v10 v10.19.0 // indirect
 | 
						github.com/go-playground/validator/v10 v10.20.0 // indirect
 | 
				
			||||||
 | 
						github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
 | 
				
			||||||
 | 
						github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
 | 
				
			||||||
 | 
						github.com/gobwas/httphead v0.1.0 // indirect
 | 
				
			||||||
 | 
						github.com/gobwas/pool v0.2.1 // indirect
 | 
				
			||||||
 | 
						github.com/gobwas/ws v1.4.0 // indirect
 | 
				
			||||||
	github.com/goccy/go-json v0.10.2 // indirect
 | 
						github.com/goccy/go-json v0.10.2 // indirect
 | 
				
			||||||
 | 
						github.com/gofrs/uuid/v5 v5.3.2 // indirect
 | 
				
			||||||
 | 
						github.com/google/btree v1.1.3 // indirect
 | 
				
			||||||
	github.com/google/go-cmp v0.6.0 // indirect
 | 
						github.com/google/go-cmp v0.6.0 // indirect
 | 
				
			||||||
 | 
						github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
 | 
				
			||||||
 | 
						github.com/hashicorp/yamux v0.1.2 // indirect
 | 
				
			||||||
 | 
						github.com/insomniacslk/dhcp v0.0.0-20250109001534-8abf58130905 // indirect
 | 
				
			||||||
 | 
						github.com/josharian/native v1.1.0 // indirect
 | 
				
			||||||
	github.com/json-iterator/go v1.1.12 // indirect
 | 
						github.com/json-iterator/go v1.1.12 // indirect
 | 
				
			||||||
	github.com/klauspost/cpuid/v2 v2.2.7 // indirect
 | 
						github.com/klauspost/compress v1.17.9 // indirect
 | 
				
			||||||
 | 
						github.com/klauspost/cpuid/v2 v2.2.9 // indirect
 | 
				
			||||||
	github.com/leodido/go-urn v1.4.0 // indirect
 | 
						github.com/leodido/go-urn v1.4.0 // indirect
 | 
				
			||||||
 | 
						github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
 | 
				
			||||||
 | 
						github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 // indirect
 | 
				
			||||||
 | 
						github.com/mailru/easyjson v0.7.7 // indirect
 | 
				
			||||||
	github.com/mattn/go-isatty v0.0.20 // indirect
 | 
						github.com/mattn/go-isatty v0.0.20 // indirect
 | 
				
			||||||
 | 
						github.com/mdlayher/netlink v1.7.2 // indirect
 | 
				
			||||||
 | 
						github.com/mdlayher/socket v0.4.1 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/amneziawg-go v0.0.0-20240922133038-fdf3a4d5a4ab // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/bart v0.20.5 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/bbolt v0.0.0-20240822011022-aed6d4850399 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/chacha v0.1.2 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/fswatch v0.1.1 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/gopacket v1.1.20-0.20230608035415-7e2f98a3e759 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/gvisor v0.0.0-20250324165734-5857f47bd43b // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/nftables v0.0.0-20250503052935-30a69ab87793 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/quic-go v0.52.1-0.20250522021943-aef454b9e639 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/randv2 v0.2.0 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/sing v0.5.3 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/sing-mux v0.3.2 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/sing-quic v0.0.0-20250523120938-f1a248e5ec7f // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/sing-shadowsocks v0.2.10 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/sing-shadowsocks2 v0.2.4 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/sing-tun v0.4.6-0.20250524142129-9d110c0af70c // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/sing-vmess v0.2.2 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/smux v0.0.0-20250503055512-501391591dee // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/tfo-go v0.0.0-20250516165257-e29c16ae41d4 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/utls v1.7.3 // indirect
 | 
				
			||||||
 | 
						github.com/metacubex/wireguard-go v0.0.0-20240922131502-c182e7471181 // indirect
 | 
				
			||||||
 | 
						github.com/miekg/dns v1.1.63 // indirect
 | 
				
			||||||
	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 | 
						github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 | 
				
			||||||
	github.com/modern-go/reflect2 v1.0.2 // indirect
 | 
						github.com/modern-go/reflect2 v1.0.2 // indirect
 | 
				
			||||||
	github.com/pelletier/go-toml/v2 v2.2.1 // indirect
 | 
						github.com/mroth/weightedrand/v2 v2.1.0 // indirect
 | 
				
			||||||
 | 
						github.com/oasisprotocol/deoxysii v0.0.0-20220228165953-2091330c22b7 // indirect
 | 
				
			||||||
 | 
						github.com/onsi/ginkgo/v2 v2.9.5 // indirect
 | 
				
			||||||
 | 
						github.com/openacid/low v0.1.21 // indirect
 | 
				
			||||||
 | 
						github.com/oschwald/maxminddb-golang v1.12.0 // indirect
 | 
				
			||||||
 | 
						github.com/pelletier/go-toml/v2 v2.2.3 // indirect
 | 
				
			||||||
 | 
						github.com/pierrec/lz4/v4 v4.1.14 // indirect
 | 
				
			||||||
 | 
						github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
 | 
				
			||||||
 | 
						github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
 | 
				
			||||||
 | 
						github.com/quic-go/qpack v0.4.0 // indirect
 | 
				
			||||||
 | 
						github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a // indirect
 | 
				
			||||||
 | 
						github.com/sagikazarmark/locafero v0.7.0 // indirect
 | 
				
			||||||
 | 
						github.com/samber/lo v1.50.0 // indirect
 | 
				
			||||||
 | 
						github.com/shirou/gopsutil/v4 v4.25.1 // indirect
 | 
				
			||||||
 | 
						github.com/sina-ghaderi/poly1305 v0.0.0-20220724002748-c5926b03988b // indirect
 | 
				
			||||||
 | 
						github.com/sina-ghaderi/rabaead v0.0.0-20220730151906-ab6e06b96e8c // indirect
 | 
				
			||||||
 | 
						github.com/sina-ghaderi/rabbitio v0.0.0-20220730151941-9ce26f4f872e // indirect
 | 
				
			||||||
 | 
						github.com/sirupsen/logrus v1.9.3 // indirect
 | 
				
			||||||
 | 
						github.com/sourcegraph/conc v0.3.0 // indirect
 | 
				
			||||||
 | 
						github.com/spf13/afero v1.12.0 // indirect
 | 
				
			||||||
 | 
						github.com/spf13/cast v1.7.1 // indirect
 | 
				
			||||||
 | 
						github.com/spf13/pflag v1.0.6 // indirect
 | 
				
			||||||
 | 
						github.com/subosito/gotenv v1.6.0 // indirect
 | 
				
			||||||
 | 
						github.com/tklauser/go-sysconf v0.3.12 // indirect
 | 
				
			||||||
 | 
						github.com/tklauser/numcpus v0.6.1 // indirect
 | 
				
			||||||
	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
 | 
						github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
 | 
				
			||||||
 | 
						github.com/u-root/uio v0.0.0-20230220225925-ffce2a382923 // indirect
 | 
				
			||||||
	github.com/ugorji/go/codec v1.2.12 // indirect
 | 
						github.com/ugorji/go/codec v1.2.12 // indirect
 | 
				
			||||||
 | 
						github.com/vishvananda/netns v0.0.4 // indirect
 | 
				
			||||||
 | 
						github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
 | 
				
			||||||
 | 
						github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
 | 
				
			||||||
 | 
						github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
 | 
				
			||||||
 | 
						github.com/yusufpapurcu/wmi v1.2.4 // indirect
 | 
				
			||||||
 | 
						gitlab.com/go-extension/aes-ccm v0.0.0-20230221065045-e58665ef23c7 // indirect
 | 
				
			||||||
 | 
						gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec // indirect
 | 
				
			||||||
 | 
						go.uber.org/mock v0.4.0 // indirect
 | 
				
			||||||
	go.uber.org/multierr v1.11.0 // indirect
 | 
						go.uber.org/multierr v1.11.0 // indirect
 | 
				
			||||||
	golang.org/x/arch v0.7.0 // indirect
 | 
						go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
 | 
				
			||||||
	golang.org/x/crypto v0.22.0 // indirect
 | 
						golang.org/x/arch v0.8.0 // indirect
 | 
				
			||||||
	golang.org/x/net v0.24.0 // indirect
 | 
						golang.org/x/crypto v0.33.0 // indirect
 | 
				
			||||||
	golang.org/x/sys v0.19.0 // indirect
 | 
						golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect
 | 
				
			||||||
	google.golang.org/protobuf v1.33.0 // indirect
 | 
						golang.org/x/mod v0.20.0 // indirect
 | 
				
			||||||
 | 
						golang.org/x/net v0.35.0 // indirect
 | 
				
			||||||
 | 
						golang.org/x/sync v0.11.0 // indirect
 | 
				
			||||||
 | 
						golang.org/x/sys v0.30.0 // indirect
 | 
				
			||||||
 | 
						golang.org/x/time v0.8.0 // indirect
 | 
				
			||||||
 | 
						golang.org/x/tools v0.24.0 // indirect
 | 
				
			||||||
 | 
						google.golang.org/protobuf v1.36.1 // indirect
 | 
				
			||||||
 | 
						lukechampine.com/blake3 v1.3.0 // indirect
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										338
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										338
									
								
								go.sum
									
									
									
									
									
								
							@@ -1,102 +1,376 @@
 | 
				
			|||||||
github.com/bytedance/sonic v1.11.5 h1:G00FYjjqll5iQ1PYXynbg/hyzqBqavH8Mo9/oTopd9k=
 | 
					github.com/3andne/restls-client-go v0.1.6 h1:tRx/YilqW7iHpgmEL4E1D8dAsuB0tFF3uvncS+B6I08=
 | 
				
			||||||
github.com/bytedance/sonic v1.11.5/go.mod h1:X2PC2giUdj/Cv2lliWFLk6c/DUQok5rViJSemeB0wDw=
 | 
					github.com/3andne/restls-client-go v0.1.6/go.mod h1:iEdTZNt9kzPIxjIGSMScUFSBrUH6bFRNg0BWlP4orEY=
 | 
				
			||||||
github.com/bytedance/sonic/loader v0.1.0/go.mod h1:UmRT+IRTGKz/DAkzcEGzyVqQFJ7H9BqwBO3pm9H/+HY=
 | 
					github.com/RyuaNerin/go-krypto v1.3.0 h1:smavTzSMAx8iuVlGb4pEwl9MD2qicqMzuXR2QWp2/Pg=
 | 
				
			||||||
 | 
					github.com/RyuaNerin/go-krypto v1.3.0/go.mod h1:9R9TU936laAIqAmjcHo/LsaXYOZlymudOAxjaBf62UM=
 | 
				
			||||||
 | 
					github.com/RyuaNerin/testingutil v0.1.0 h1:IYT6JL57RV3U2ml3dLHZsVtPOP6yNK7WUVdzzlpNrss=
 | 
				
			||||||
 | 
					github.com/RyuaNerin/testingutil v0.1.0/go.mod h1:yTqj6Ta/ycHMPJHRyO12Mz3VrvTloWOsy23WOZH19AA=
 | 
				
			||||||
 | 
					github.com/Yawning/aez v0.0.0-20211027044916-e49e68abd344 h1:cDVUiFo+npB0ZASqnw4q90ylaVAbnYyx0JYqK4YcGok=
 | 
				
			||||||
 | 
					github.com/Yawning/aez v0.0.0-20211027044916-e49e68abd344/go.mod h1:9pIqrY6SXNL8vjRQE5Hd/OL5GyK/9MrGUWs87z/eFfk=
 | 
				
			||||||
 | 
					github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
 | 
				
			||||||
 | 
					github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
 | 
				
			||||||
 | 
					github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI=
 | 
				
			||||||
 | 
					github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
 | 
				
			||||||
 | 
					github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
 | 
				
			||||||
 | 
					github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
 | 
				
			||||||
 | 
					github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
 | 
				
			||||||
 | 
					github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
 | 
				
			||||||
 | 
					github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
 | 
				
			||||||
 | 
					github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
 | 
				
			||||||
 | 
					github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
 | 
				
			||||||
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
 | 
					github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
 | 
				
			||||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
 | 
					github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
 | 
				
			||||||
github.com/cloudwego/base64x v0.1.3 h1:b5J/l8xolB7dyDTTmhJP2oTs5LdrjyrUFuNxdfq5hAg=
 | 
					github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
 | 
				
			||||||
github.com/cloudwego/base64x v0.1.3/go.mod h1:1+1K5BUHIQzyapgpF7LwvOGAEDicKtt1umPV+aN8pi8=
 | 
					github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
 | 
				
			||||||
 | 
					github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
 | 
				
			||||||
 | 
					github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
 | 
				
			||||||
 | 
					github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
 | 
				
			||||||
 | 
					github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
 | 
				
			||||||
 | 
					github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
 | 
				
			||||||
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
 | 
					github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
 | 
				
			||||||
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
 | 
					github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
 | 
				
			||||||
 | 
					github.com/coreos/go-iptables v0.8.0 h1:MPc2P89IhuVpLI7ETL/2tx3XZ61VeICZjYqDEgNsPRc=
 | 
				
			||||||
 | 
					github.com/coreos/go-iptables v0.8.0/go.mod h1:Qe8Bv2Xik5FyTXwgIbLAnv2sWSBmvWdFETJConOQ//Q=
 | 
				
			||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
					github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
				
			||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 | 
					github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 | 
				
			||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
					github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
				
			||||||
 | 
					github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
 | 
				
			||||||
 | 
					github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
 | 
				
			||||||
 | 
					github.com/ebitengine/purego v0.8.3 h1:K+0AjQp63JEZTEMZiwsI9g0+hAMNohwUOtY0RPGexmc=
 | 
				
			||||||
 | 
					github.com/ebitengine/purego v0.8.3/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
 | 
				
			||||||
 | 
					github.com/enfein/mieru/v3 v3.13.0 h1:eGyxLGkb+lut9ebmx+BGwLJ5UMbEc/wGIYO0AXEKy98=
 | 
				
			||||||
 | 
					github.com/enfein/mieru/v3 v3.13.0/go.mod h1:zJBUCsi5rxyvHM8fjFf+GLaEl4OEjjBXr1s5F6Qd3hM=
 | 
				
			||||||
 | 
					github.com/ericlagergren/aegis v0.0.0-20250325060835-cd0defd64358 h1:kXYqH/sL8dS/FdoFjr12ePjnLPorPo2FsnrHNuXSDyo=
 | 
				
			||||||
 | 
					github.com/ericlagergren/aegis v0.0.0-20250325060835-cd0defd64358/go.mod h1:hkIFzoiIPZYxdFOOLyDho59b7SrDfo+w3h+yWdlg45I=
 | 
				
			||||||
 | 
					github.com/ericlagergren/polyval v0.0.0-20220411101811-e25bc10ba391 h1:8j2RH289RJplhA6WfdaPqzg1MjH2K8wX5e0uhAxrw2g=
 | 
				
			||||||
 | 
					github.com/ericlagergren/polyval v0.0.0-20220411101811-e25bc10ba391/go.mod h1:K2R7GhgxrlJzHw2qiPWsCZXf/kXEJN9PLnQK73Ll0po=
 | 
				
			||||||
 | 
					github.com/ericlagergren/saferand v0.0.0-20220206064634-960a4dd2bc5c h1:RUzBDdZ+e/HEe2Nh8lYsduiPAZygUfVXJn0Ncj5sHMg=
 | 
				
			||||||
 | 
					github.com/ericlagergren/saferand v0.0.0-20220206064634-960a4dd2bc5c/go.mod h1:ETASDWf/FmEb6Ysrtd1QhjNedUU/ZQxBCRLh60bQ/UI=
 | 
				
			||||||
 | 
					github.com/ericlagergren/siv v0.0.0-20220507050439-0b757b3aa5f1 h1:tlDMEdcPRQKBEz5nGDMvswiajqh7k8ogWRlhRwKy5mY=
 | 
				
			||||||
 | 
					github.com/ericlagergren/siv v0.0.0-20220507050439-0b757b3aa5f1/go.mod h1:4RfsapbGx2j/vU5xC/5/9qB3kn9Awp1YDiEnN43QrJ4=
 | 
				
			||||||
 | 
					github.com/ericlagergren/subtle v0.0.0-20220507045147-890d697da010 h1:fuGucgPk5dN6wzfnxl3D0D3rVLw4v2SbBT9jb4VnxzA=
 | 
				
			||||||
 | 
					github.com/ericlagergren/subtle v0.0.0-20220507045147-890d697da010/go.mod h1:JtBcj7sBuTTRupn7c2bFspMDIObMJsVK8TeUvpShPok=
 | 
				
			||||||
 | 
					github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
 | 
				
			||||||
 | 
					github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
 | 
				
			||||||
 | 
					github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
 | 
				
			||||||
 | 
					github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
 | 
				
			||||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
 | 
					github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
 | 
				
			||||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
 | 
					github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
 | 
				
			||||||
 | 
					github.com/gaukas/godicttls v0.0.4 h1:NlRaXb3J6hAnTmWdsEKb9bcSBD6BvcIjdGdeb0zfXbk=
 | 
				
			||||||
 | 
					github.com/gaukas/godicttls v0.0.4/go.mod h1:l6EenT4TLWgTdwslVb4sEMOCf7Bv0JAK67deKr9/NCI=
 | 
				
			||||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
 | 
					github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
 | 
				
			||||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
 | 
					github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
 | 
				
			||||||
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
 | 
					github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ=
 | 
				
			||||||
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
 | 
					github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
 | 
				
			||||||
 | 
					github.com/go-chi/chi/v5 v5.2.1 h1:KOIHODQj58PmL80G2Eak4WdvUzjSJSm0vG72crDCqb8=
 | 
				
			||||||
 | 
					github.com/go-chi/chi/v5 v5.2.1/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
 | 
				
			||||||
 | 
					github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
 | 
				
			||||||
 | 
					github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0=
 | 
				
			||||||
 | 
					github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
 | 
				
			||||||
 | 
					github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
 | 
				
			||||||
 | 
					github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
 | 
				
			||||||
 | 
					github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
 | 
				
			||||||
 | 
					github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
 | 
				
			||||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
 | 
					github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
 | 
				
			||||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
 | 
					github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
 | 
				
			||||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
 | 
					github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
 | 
				
			||||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
 | 
					github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
 | 
				
			||||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
 | 
					github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
 | 
				
			||||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
 | 
					github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
 | 
				
			||||||
github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4=
 | 
					github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
 | 
				
			||||||
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
 | 
					github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
 | 
				
			||||||
 | 
					github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
 | 
				
			||||||
 | 
					github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
 | 
				
			||||||
 | 
					github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=
 | 
				
			||||||
 | 
					github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
 | 
				
			||||||
 | 
					github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
 | 
				
			||||||
 | 
					github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
 | 
				
			||||||
 | 
					github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
 | 
				
			||||||
 | 
					github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
 | 
				
			||||||
 | 
					github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs=
 | 
				
			||||||
 | 
					github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc=
 | 
				
			||||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
 | 
					github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
 | 
				
			||||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
 | 
					github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
 | 
				
			||||||
 | 
					github.com/gofrs/uuid/v5 v5.3.2 h1:2jfO8j3XgSwlz/wHqemAEugfnTlikAYHhnqQ8Xh4fE0=
 | 
				
			||||||
 | 
					github.com/gofrs/uuid/v5 v5.3.2/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
 | 
				
			||||||
 | 
					github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 | 
				
			||||||
 | 
					github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
 | 
				
			||||||
 | 
					github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
 | 
				
			||||||
 | 
					github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg=
 | 
				
			||||||
 | 
					github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
 | 
				
			||||||
 | 
					github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 | 
				
			||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
 | 
					github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
 | 
				
			||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
 | 
					github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
 | 
				
			||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
 | 
					github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
 | 
				
			||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
 | 
					github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
 | 
				
			||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
 | 
					github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
 | 
				
			||||||
 | 
					github.com/google/tink/go v1.6.1 h1:t7JHqO8Ath2w2ig5vjwQYJzhGEZymedQc90lQXUBa4I=
 | 
				
			||||||
 | 
					github.com/google/tink/go v1.6.1/go.mod h1:IGW53kTgag+st5yPhKKwJ6u2l+SSp5/v9XF7spovjlY=
 | 
				
			||||||
 | 
					github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8=
 | 
				
			||||||
 | 
					github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns=
 | 
				
			||||||
 | 
					github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
 | 
				
			||||||
 | 
					github.com/insomniacslk/dhcp v0.0.0-20250109001534-8abf58130905 h1:q3OEI9RaN/wwcx+qgGo6ZaoJkCiDYe/gjDLfq7lQQF4=
 | 
				
			||||||
 | 
					github.com/insomniacslk/dhcp v0.0.0-20250109001534-8abf58130905/go.mod h1:VvGYjkZoJyKqlmT1yzakUs4mfKMNB0XdODP0+rdml6k=
 | 
				
			||||||
 | 
					github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
 | 
				
			||||||
 | 
					github.com/josharian/native v1.0.1-0.20221213033349-c1e37c09b531/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
 | 
				
			||||||
 | 
					github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
 | 
				
			||||||
 | 
					github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
 | 
				
			||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
 | 
					github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
 | 
				
			||||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
 | 
					github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
 | 
				
			||||||
 | 
					github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
 | 
				
			||||||
 | 
					github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
 | 
				
			||||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
 | 
					github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
 | 
				
			||||||
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
 | 
					github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY=
 | 
				
			||||||
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
 | 
					github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8=
 | 
				
			||||||
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
 | 
					github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
 | 
				
			||||||
 | 
					github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
 | 
				
			||||||
 | 
					github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
 | 
				
			||||||
 | 
					github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
 | 
				
			||||||
 | 
					github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
 | 
				
			||||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
 | 
					github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
 | 
				
			||||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
 | 
					github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
 | 
				
			||||||
 | 
					github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
 | 
				
			||||||
 | 
					github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
 | 
				
			||||||
 | 
					github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 h1:EnfXoSqDfSNJv0VBNqY/88RNnhSGYkrHaO0mmFGbVsc=
 | 
				
			||||||
 | 
					github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40/go.mod h1:vy1vK6wD6j7xX6O6hXe621WabdtNkou2h7uRtTfRMyg=
 | 
				
			||||||
 | 
					github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
 | 
				
			||||||
 | 
					github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
 | 
				
			||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
 | 
					github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
 | 
				
			||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
 | 
					github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
 | 
				
			||||||
 | 
					github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/g=
 | 
				
			||||||
 | 
					github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw=
 | 
				
			||||||
 | 
					github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U=
 | 
				
			||||||
 | 
					github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA=
 | 
				
			||||||
 | 
					github.com/metacubex/amneziawg-go v0.0.0-20240922133038-fdf3a4d5a4ab h1:Chbw+/31UC14YFNr78pESt5Vowlc62zziw05JCUqoL4=
 | 
				
			||||||
 | 
					github.com/metacubex/amneziawg-go v0.0.0-20240922133038-fdf3a4d5a4ab/go.mod h1:xVKK8jC5Sd3hfh7WjmCq+HorehIbrBijaUWmcuKjPcI=
 | 
				
			||||||
 | 
					github.com/metacubex/bart v0.20.5 h1:XkgLZ17QxfxkqKdGsojoM2Zu01mmHyyQSFzt2/calTM=
 | 
				
			||||||
 | 
					github.com/metacubex/bart v0.20.5/go.mod h1:DCcyfP4MC+Zy7sLK7XeGuMw+P5K9mIRsYOBgiE8icsI=
 | 
				
			||||||
 | 
					github.com/metacubex/bbolt v0.0.0-20240822011022-aed6d4850399 h1:oBowHVKZycNtAFbZ6avaCSZJYeme2Nrj+4RpV2cNJig=
 | 
				
			||||||
 | 
					github.com/metacubex/bbolt v0.0.0-20240822011022-aed6d4850399/go.mod h1:4xcieuIK+M4bGQmQYZVqEaIYqjS1ahO4kXG7EmDgEro=
 | 
				
			||||||
 | 
					github.com/metacubex/chacha v0.1.2 h1:QulCq3eVm3TO6+4nVIWJtmSe7BT2GMrgVHuAoqRQnlc=
 | 
				
			||||||
 | 
					github.com/metacubex/chacha v0.1.2/go.mod h1:Djn9bPZxLTXbJFSeyo0/qzEzQI+gUSSzttuzZM75GH8=
 | 
				
			||||||
 | 
					github.com/metacubex/fswatch v0.1.1 h1:jqU7C/v+g0qc2RUFgmAOPoVvfl2BXXUXEumn6oQuxhU=
 | 
				
			||||||
 | 
					github.com/metacubex/fswatch v0.1.1/go.mod h1:czrTT7Zlbz7vWft8RQu9Qqh+JoX+Nnb+UabuyN1YsgI=
 | 
				
			||||||
 | 
					github.com/metacubex/gopacket v1.1.20-0.20230608035415-7e2f98a3e759 h1:cjd4biTvOzK9ubNCCkQ+ldc4YSH/rILn53l/xGBFHHI=
 | 
				
			||||||
 | 
					github.com/metacubex/gopacket v1.1.20-0.20230608035415-7e2f98a3e759/go.mod h1:UHOv2xu+RIgLwpXca7TLrXleEd4oR3sPatW6IF8wU88=
 | 
				
			||||||
 | 
					github.com/metacubex/gvisor v0.0.0-20250324165734-5857f47bd43b h1:RUh4OdVPz/jDrM9MQ2ySuqu2aeBqcA8rtfWUYLZ8RtI=
 | 
				
			||||||
 | 
					github.com/metacubex/gvisor v0.0.0-20250324165734-5857f47bd43b/go.mod h1:8LpS0IJW1VmWzUm3ylb0e2SK5QDm5lO/2qwWLZgRpBU=
 | 
				
			||||||
 | 
					github.com/metacubex/mihomo v1.19.10 h1:GXCOA1rJNfU5qYSvo+UBUFksh61M0tjPfvlZ1OsYtfs=
 | 
				
			||||||
 | 
					github.com/metacubex/mihomo v1.19.10/go.mod h1:ih7BKy1pfqSvPRqaCcuFFK4oNRIFyBotoHX0PbhF7SQ=
 | 
				
			||||||
 | 
					github.com/metacubex/nftables v0.0.0-20250503052935-30a69ab87793 h1:1Qpuy+sU3DmyX9HwI+CrBT/oLNJngvBorR2RbajJcqo=
 | 
				
			||||||
 | 
					github.com/metacubex/nftables v0.0.0-20250503052935-30a69ab87793/go.mod h1:RjRNb4G52yAgfR+Oe/kp9G4PJJ97Fnj89eY1BFO3YyA=
 | 
				
			||||||
 | 
					github.com/metacubex/quic-go v0.52.1-0.20250522021943-aef454b9e639 h1:L+1brQNzBhCCxWlicwfK1TlceemCRmrDE4HmcVHc29w=
 | 
				
			||||||
 | 
					github.com/metacubex/quic-go v0.52.1-0.20250522021943-aef454b9e639/go.mod h1:Kc6h++Q/zf3AxcUCevJhJwgrskJumv+pZdR8g/E/10k=
 | 
				
			||||||
 | 
					github.com/metacubex/randv2 v0.2.0 h1:uP38uBvV2SxYfLj53kuvAjbND4RUDfFJjwr4UigMiLs=
 | 
				
			||||||
 | 
					github.com/metacubex/randv2 v0.2.0/go.mod h1:kFi2SzrQ5WuneuoLLCMkABtiBu6VRrMrWFqSPyj2cxY=
 | 
				
			||||||
 | 
					github.com/metacubex/sing v0.5.2/go.mod h1:ypf0mjwlZm0sKdQSY+yQvmsbWa0hNPtkeqyRMGgoN+w=
 | 
				
			||||||
 | 
					github.com/metacubex/sing v0.5.3 h1:QWdN16WFKMk06x4nzkc8SvZ7y2x+TLQrpkPoHs+WSVM=
 | 
				
			||||||
 | 
					github.com/metacubex/sing v0.5.3/go.mod h1:ypf0mjwlZm0sKdQSY+yQvmsbWa0hNPtkeqyRMGgoN+w=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-mux v0.3.2 h1:nJv52pyRivHcaZJKk2JgxpaVvj1GAXG81scSa9N7ncw=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-mux v0.3.2/go.mod h1:3rt1soewn0O6j89GCLmwAQFsq257u0jf2zQSPhTL3Bw=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-quic v0.0.0-20250523120938-f1a248e5ec7f h1:mP3vIm+9hRFI0C0Vl3pE0NESF/L85FDbuB0tGgUii6I=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-quic v0.0.0-20250523120938-f1a248e5ec7f/go.mod h1:JPTpf7fpnojsSuwRJExhSZSy63pVbp3VM39+zj+sAJM=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-shadowsocks v0.2.10 h1:Pr7LDbjMANIQHl07zWgl1vDuhpsfDQUpZ8cX6DPabfg=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-shadowsocks v0.2.10/go.mod h1:MtRM0ZZjR0kaDOzy9zWSt6/4/UlrnsNBq+1FNAF4vBk=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-shadowsocks2 v0.2.4 h1:Ec0x3hHR7xkld5Z09IGh16wtUUpBb2HgqZ9DExd8Q7s=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-shadowsocks2 v0.2.4/go.mod h1:WP8+S0kqtnSbX1vlIpo5i8Irm/ijZITEPBcZ26B5unY=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2 h1:gXU+MYPm7Wme3/OAY2FFzVq9d9GxPHOqu5AQfg/ddhI=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2/go.mod h1:mbfboaXauKJNIHJYxQRa+NJs4JU9NZfkA+I33dS2+9E=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-tun v0.4.6-0.20250524142129-9d110c0af70c h1:Y6jk7AH5BEg9Dsvczrf/KokYsvxeKSZZlCLHg+hC4ro=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-tun v0.4.6-0.20250524142129-9d110c0af70c/go.mod h1:HDaHDL6onAX2ZGbAGUXKp++PohRdNb7Nzt6zxzhox+U=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-vmess v0.2.2 h1:nG6GIKF1UOGmlzs+BIetdGHkFZ20YqFVIYp5Htqzp+4=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-vmess v0.2.2/go.mod h1:CVDNcdSLVYFgTHQlubr88d8CdqupAUDqLjROos+H9xk=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f h1:Sr/DYKYofKHKc4GF3qkRGNuj6XA6c0eqPgEDN+VAsYU=
 | 
				
			||||||
 | 
					github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f/go.mod h1:jpAkVLPnCpGSfNyVmj6Cq4YbuZsFepm/Dc+9BAOcR80=
 | 
				
			||||||
 | 
					github.com/metacubex/smux v0.0.0-20250503055512-501391591dee h1:lp6hJ+4wCLZu113awp7P6odM2okB5s60HUyF0FMqKmo=
 | 
				
			||||||
 | 
					github.com/metacubex/smux v0.0.0-20250503055512-501391591dee/go.mod h1:4bPD8HWx9jPJ9aE4uadgyN7D1/Wz3KmPy+vale8sKLE=
 | 
				
			||||||
 | 
					github.com/metacubex/tfo-go v0.0.0-20250516165257-e29c16ae41d4 h1:j1VRTiC9JLR4nUbSikx9OGdu/3AgFDqgcLj4GoqyQkc=
 | 
				
			||||||
 | 
					github.com/metacubex/tfo-go v0.0.0-20250516165257-e29c16ae41d4/go.mod h1:l9oLnLoEXyGZ5RVLsh7QCC5XsouTUyKk4F2nLm2DHLw=
 | 
				
			||||||
 | 
					github.com/metacubex/utls v1.7.3 h1:yDcMEWojFh+t8rU9X0HPcZDPAoFze/rIIyssqivzj8A=
 | 
				
			||||||
 | 
					github.com/metacubex/utls v1.7.3/go.mod h1:oknYT0qTOwE4hjPmZOEpzVdefnW7bAdGLvZcqmk4TLU=
 | 
				
			||||||
 | 
					github.com/metacubex/wireguard-go v0.0.0-20240922131502-c182e7471181 h1:hJLQviGySBuaynlCwf/oYgIxbVbGRUIKZCxdya9YrbQ=
 | 
				
			||||||
 | 
					github.com/metacubex/wireguard-go v0.0.0-20240922131502-c182e7471181/go.mod h1:phewKljNYiTVT31Gcif8RiCKnTUOgVWFJjccqYM8s+Y=
 | 
				
			||||||
 | 
					github.com/miekg/dns v1.1.63 h1:8M5aAw6OMZfFXTT7K5V0Eu5YiiL8l7nUAkyN6C9YwaY=
 | 
				
			||||||
 | 
					github.com/miekg/dns v1.1.63/go.mod h1:6NGHfjhpmr5lt3XPLuyfDJi5AXbNIPM9PY6H6sF1Nfs=
 | 
				
			||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
 | 
					github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
 | 
				
			||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
 | 
					github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
 | 
				
			||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
 | 
					github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
 | 
				
			||||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
 | 
					github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
 | 
				
			||||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
 | 
					github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
 | 
				
			||||||
github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg=
 | 
					github.com/mroth/weightedrand/v2 v2.1.0 h1:o1ascnB1CIVzsqlfArQQjeMy1U0NcIbBO5rfd5E/OeU=
 | 
				
			||||||
github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
 | 
					github.com/mroth/weightedrand/v2 v2.1.0/go.mod h1:f2faGsfOGOwc1p94wzHKKZyTpcJUW7OJ/9U4yfiNAOU=
 | 
				
			||||||
 | 
					github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
 | 
				
			||||||
 | 
					github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
 | 
				
			||||||
 | 
					github.com/oasisprotocol/deoxysii v0.0.0-20220228165953-2091330c22b7 h1:1102pQc2SEPp5+xrS26wEaeb26sZy6k9/ZXlZN+eXE4=
 | 
				
			||||||
 | 
					github.com/oasisprotocol/deoxysii v0.0.0-20220228165953-2091330c22b7/go.mod h1:UqoUn6cHESlliMhOnKLWr+CBH+e3bazUPvFj1XZwAjs=
 | 
				
			||||||
 | 
					github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q=
 | 
				
			||||||
 | 
					github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3RonqW57k=
 | 
				
			||||||
 | 
					github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
 | 
				
			||||||
 | 
					github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg=
 | 
				
			||||||
 | 
					github.com/openacid/errors v0.8.1/go.mod h1:GUQEJJOJE3W9skHm8E8Y4phdl2LLEN8iD7c5gcGgdx0=
 | 
				
			||||||
 | 
					github.com/openacid/low v0.1.21 h1:Tr2GNu4N/+rGRYdOsEHOE89cxUIaDViZbVmKz29uKGo=
 | 
				
			||||||
 | 
					github.com/openacid/low v0.1.21/go.mod h1:q+MsKI6Pz2xsCkzV4BLj7NR5M4EX0sGz5AqotpZDVh0=
 | 
				
			||||||
 | 
					github.com/openacid/must v0.1.3/go.mod h1:luPiXCuJlEo3UUFQngVQokV0MPGryeYvtCbQPs3U1+I=
 | 
				
			||||||
 | 
					github.com/openacid/testkeys v0.1.6/go.mod h1:MfA7cACzBpbiwekivj8StqX0WIRmqlMsci1c37CA3Do=
 | 
				
			||||||
 | 
					github.com/oschwald/maxminddb-golang v1.12.0 h1:9FnTOD0YOhP7DGxGsq4glzpGy5+w7pq50AS6wALUMYs=
 | 
				
			||||||
 | 
					github.com/oschwald/maxminddb-golang v1.12.0/go.mod h1:q0Nob5lTCqyQ8WT6FYgS1L7PXKVVbgiymefNwIjPzgY=
 | 
				
			||||||
 | 
					github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
 | 
				
			||||||
 | 
					github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
 | 
				
			||||||
 | 
					github.com/pierrec/lz4/v4 v4.1.14 h1:+fL8AQEZtz/ijeNnpduH0bROTu0O3NZAlPjQxGn8LwE=
 | 
				
			||||||
 | 
					github.com/pierrec/lz4/v4 v4.1.14/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
 | 
				
			||||||
 | 
					github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 | 
				
			||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 | 
					github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 | 
				
			||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 | 
					github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 | 
				
			||||||
 | 
					github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
 | 
				
			||||||
 | 
					github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
 | 
				
			||||||
 | 
					github.com/puzpuzpuz/xsync/v3 v3.5.1 h1:GJYJZwO6IdxN/IKbneznS6yPkVC+c3zyY/j19c++5Fg=
 | 
				
			||||||
 | 
					github.com/puzpuzpuz/xsync/v3 v3.5.1/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
 | 
				
			||||||
 | 
					github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
 | 
				
			||||||
 | 
					github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
 | 
				
			||||||
 | 
					github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
 | 
				
			||||||
 | 
					github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
 | 
				
			||||||
 | 
					github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a h1:ObwtHN2VpqE0ZNjr6sGeT00J8uU7JF4cNUdb44/Duis=
 | 
				
			||||||
 | 
					github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a/go.mod h1:xLnfdiJbSp8rNqYEdIW/6eDO4mVoogml14Bh2hSiFpM=
 | 
				
			||||||
 | 
					github.com/sagikazarmark/locafero v0.7.0 h1:5MqpDsTGNDhY8sGp0Aowyf0qKsPrhewaLSsFaodPcyo=
 | 
				
			||||||
 | 
					github.com/sagikazarmark/locafero v0.7.0/go.mod h1:2za3Cg5rMaTMoG/2Ulr9AwtFaIppKXTRYnozin4aB5k=
 | 
				
			||||||
 | 
					github.com/samber/lo v1.50.0 h1:XrG0xOeHs+4FQ8gJR97zDz5uOFMW7OwFWiFVzqopKgY=
 | 
				
			||||||
 | 
					github.com/samber/lo v1.50.0/go.mod h1:RjZyNk6WSnUFRKK6EyOhsRJMqft3G+pg7dCWHQCWvsc=
 | 
				
			||||||
 | 
					github.com/shirou/gopsutil/v4 v4.25.1 h1:QSWkTc+fu9LTAWfkZwZ6j8MSUk4A2LV7rbH0ZqmLjXs=
 | 
				
			||||||
 | 
					github.com/shirou/gopsutil/v4 v4.25.1/go.mod h1:RoUCUpndaJFtT+2zsZzzmhvbfGoDCJ7nFXKJf8GqJbI=
 | 
				
			||||||
 | 
					github.com/sina-ghaderi/poly1305 v0.0.0-20220724002748-c5926b03988b h1:rXHg9GrUEtWZhEkrykicdND3VPjlVbYiLdX9J7gimS8=
 | 
				
			||||||
 | 
					github.com/sina-ghaderi/poly1305 v0.0.0-20220724002748-c5926b03988b/go.mod h1:X7qrxNQViEaAN9LNZOPl9PfvQtp3V3c7LTo0dvGi0fM=
 | 
				
			||||||
 | 
					github.com/sina-ghaderi/rabaead v0.0.0-20220730151906-ab6e06b96e8c h1:DjKMC30y6yjG3IxDaeAj3PCoRr+IsO+bzyT+Se2m2Hk=
 | 
				
			||||||
 | 
					github.com/sina-ghaderi/rabaead v0.0.0-20220730151906-ab6e06b96e8c/go.mod h1:NV/a66PhhWYVmUMaotlXJ8fIEFB98u+c8l/CQIEFLrU=
 | 
				
			||||||
 | 
					github.com/sina-ghaderi/rabbitio v0.0.0-20220730151941-9ce26f4f872e h1:ur8uMsPIFG3i4Gi093BQITvwH9znsz2VUZmnmwHvpIo=
 | 
				
			||||||
 | 
					github.com/sina-ghaderi/rabbitio v0.0.0-20220730151941-9ce26f4f872e/go.mod h1:+e5fBW3bpPyo+3uLo513gIUblc03egGjMM0+5GKbzK8=
 | 
				
			||||||
 | 
					github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
 | 
				
			||||||
 | 
					github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
 | 
				
			||||||
 | 
					github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
 | 
				
			||||||
 | 
					github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
 | 
				
			||||||
 | 
					github.com/spf13/afero v1.12.0 h1:UcOPyRBYczmFn6yvphxkn9ZEOY65cpwGKb5mL36mrqs=
 | 
				
			||||||
 | 
					github.com/spf13/afero v1.12.0/go.mod h1:ZTlWwG4/ahT8W7T0WQ5uYmjI9duaLQGy3Q2OAl4sk/4=
 | 
				
			||||||
 | 
					github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
 | 
				
			||||||
 | 
					github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
 | 
				
			||||||
 | 
					github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
 | 
				
			||||||
 | 
					github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
 | 
				
			||||||
 | 
					github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4=
 | 
				
			||||||
 | 
					github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4=
 | 
				
			||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 | 
					github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 | 
				
			||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
 | 
					github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
 | 
				
			||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
 | 
					github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
 | 
				
			||||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
 | 
					github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
 | 
				
			||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 | 
					github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 | 
				
			||||||
 | 
					github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
				
			||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
					github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
				
			||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
					github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
				
			||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
 | 
					github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
 | 
				
			||||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
 | 
					github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
 | 
				
			||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
 | 
					github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
 | 
				
			||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
 | 
					 | 
				
			||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
 | 
					github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
 | 
				
			||||||
 | 
					github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
 | 
				
			||||||
 | 
					github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
 | 
				
			||||||
 | 
					github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
 | 
				
			||||||
 | 
					github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
 | 
				
			||||||
 | 
					github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
 | 
				
			||||||
 | 
					github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
 | 
				
			||||||
 | 
					github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
 | 
				
			||||||
 | 
					github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
 | 
				
			||||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
 | 
					github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
 | 
				
			||||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
 | 
					github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
 | 
				
			||||||
 | 
					github.com/u-root/uio v0.0.0-20230220225925-ffce2a382923 h1:tHNk7XK9GkmKUR6Gh8gVBKXc2MVSZ4G/NnWLtzw4gNA=
 | 
				
			||||||
 | 
					github.com/u-root/uio v0.0.0-20230220225925-ffce2a382923/go.mod h1:eLL9Nub3yfAho7qB0MzZizFhTU2QkLeoVsWdHtDW264=
 | 
				
			||||||
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
 | 
					github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
 | 
				
			||||||
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
 | 
					github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
 | 
				
			||||||
 | 
					github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
 | 
				
			||||||
 | 
					github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
 | 
				
			||||||
 | 
					github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
 | 
				
			||||||
 | 
					github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8=
 | 
				
			||||||
 | 
					github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
 | 
				
			||||||
 | 
					github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
 | 
				
			||||||
 | 
					github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
 | 
				
			||||||
 | 
					github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
 | 
				
			||||||
 | 
					github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
 | 
				
			||||||
 | 
					github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
 | 
				
			||||||
 | 
					github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
 | 
				
			||||||
 | 
					github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
 | 
				
			||||||
 | 
					github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
 | 
				
			||||||
 | 
					gitlab.com/go-extension/aes-ccm v0.0.0-20230221065045-e58665ef23c7 h1:UNrDfkQqiEYzdMlNsVvBYOAJWZjdktqFE9tQh5BT2+4=
 | 
				
			||||||
 | 
					gitlab.com/go-extension/aes-ccm v0.0.0-20230221065045-e58665ef23c7/go.mod h1:E+rxHvJG9H6PUdzq9NRG6csuLN3XUx98BfGOVWNYnXs=
 | 
				
			||||||
 | 
					gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec h1:FpfFs4EhNehiVfzQttTuxanPIT43FtkkCFypIod8LHo=
 | 
				
			||||||
 | 
					gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec/go.mod h1:BZ1RAoRPbCxum9Grlv5aeksu2H8BiKehBYooU2LFiOQ=
 | 
				
			||||||
go.etcd.io/bbolt v1.3.9 h1:8x7aARPEXiXbHmtUwAIv7eV2fQFHrLLavdiJ3uzJXoI=
 | 
					go.etcd.io/bbolt v1.3.9 h1:8x7aARPEXiXbHmtUwAIv7eV2fQFHrLLavdiJ3uzJXoI=
 | 
				
			||||||
go.etcd.io/bbolt v1.3.9/go.mod h1:zaO32+Ti0PK1ivdPtgMESzuzL2VPoIG1PCQNvOdo/dE=
 | 
					go.etcd.io/bbolt v1.3.9/go.mod h1:zaO32+Ti0PK1ivdPtgMESzuzL2VPoIG1PCQNvOdo/dE=
 | 
				
			||||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
 | 
					go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
 | 
				
			||||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
 | 
					go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
 | 
				
			||||||
 | 
					go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
 | 
				
			||||||
 | 
					go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
 | 
				
			||||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
 | 
					go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
 | 
				
			||||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
 | 
					go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
 | 
				
			||||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
 | 
					go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
 | 
				
			||||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
 | 
					go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
 | 
				
			||||||
 | 
					go4.org/netipx v0.0.0-20231129151722-fdeea329fbba h1:0b9z3AuHCjxk0x/opv64kcgZLBseWJUpBw5I82+2U4M=
 | 
				
			||||||
 | 
					go4.org/netipx v0.0.0-20231129151722-fdeea329fbba/go.mod h1:PLyyIXexvUFg3Owu6p/WfdlivPbZJsZdgWZlrGope/Y=
 | 
				
			||||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
 | 
					golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
 | 
				
			||||||
golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc=
 | 
					golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
 | 
				
			||||||
golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
 | 
					golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
 | 
				
			||||||
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
 | 
					golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 | 
				
			||||||
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
 | 
					golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 | 
				
			||||||
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
 | 
					golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
 | 
				
			||||||
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
 | 
					golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
 | 
				
			||||||
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
 | 
					golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e h1:I88y4caeGeuDQxgdoFPUq097j7kNfw6uvuiNxUBfcBk=
 | 
				
			||||||
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
 | 
					golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
 | 
				
			||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
 | 
				
			||||||
 | 
					golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
 | 
				
			||||||
 | 
					golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
 | 
				
			||||||
 | 
					golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
 | 
				
			||||||
 | 
					golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 | 
				
			||||||
 | 
					golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 | 
				
			||||||
 | 
					golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
 | 
				
			||||||
 | 
					golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
 | 
				
			||||||
 | 
					golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
				
			||||||
 | 
					golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
 | 
				
			||||||
 | 
					golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20220622161953-175b2fd9d664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
 | 
					golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 | 
					golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
 | 
					golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 | 
				
			||||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
 | 
					golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
 | 
				
			||||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
 | 
					golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 | 
				
			||||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
 | 
					golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
 | 
				
			||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
 | 
					golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
 | 
				
			||||||
 | 
					golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 | 
				
			||||||
 | 
					golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
 | 
				
			||||||
 | 
					golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
 | 
				
			||||||
 | 
					golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
 | 
				
			||||||
 | 
					golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
 | 
				
			||||||
 | 
					golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
 | 
				
			||||||
 | 
					golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
 | 
				
			||||||
 | 
					golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
 | 
				
			||||||
 | 
					golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
				
			||||||
 | 
					golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
				
			||||||
 | 
					google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
 | 
				
			||||||
 | 
					google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
 | 
				
			||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
					gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
				
			||||||
 | 
					gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
 | 
				
			||||||
 | 
					gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
				
			||||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
 | 
					gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
 | 
				
			||||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
 | 
					gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
					gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
					gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
					gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
 | 
					lukechampine.com/blake3 v1.3.0 h1:sJ3XhFINmHSrYCgl958hscfIa3bw8x4DqMP3u1YvoYE=
 | 
				
			||||||
 | 
					lukechampine.com/blake3 v1.3.0/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k=
 | 
				
			||||||
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
 | 
					nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
 | 
				
			||||||
 | 
					resty.dev/v3 v3.0.0-beta.3 h1:3kEwzEgCnnS6Ob4Emlk94t+I/gClyoah7SnNi67lt+E=
 | 
				
			||||||
 | 
					resty.dev/v3 v3.0.0-beta.3/go.mod h1:OgkqiPvTDtOuV4MGZuUDhwOpkY8enjOsjjMzeOHefy4=
 | 
				
			||||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
 | 
					rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										46
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								main.go
									
									
									
									
									
								
							@@ -3,43 +3,32 @@ package main
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	_ "embed"
 | 
						_ "embed"
 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"strconv"
 | 
					
 | 
				
			||||||
	"sub2clash/api"
 | 
						"github.com/bestnite/sub2clash/common"
 | 
				
			||||||
	"sub2clash/common"
 | 
						"github.com/bestnite/sub2clash/common/database"
 | 
				
			||||||
	"sub2clash/common/database"
 | 
						"github.com/bestnite/sub2clash/config"
 | 
				
			||||||
	"sub2clash/config"
 | 
						"github.com/bestnite/sub2clash/logger"
 | 
				
			||||||
	"sub2clash/logger"
 | 
						"github.com/bestnite/sub2clash/server"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
	"go.uber.org/zap"
 | 
						"go.uber.org/zap"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//go:embed templates/template_meta.yaml
 | 
					 | 
				
			||||||
var templateMeta string
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//go:embed templates/template_clash.yaml
 | 
					 | 
				
			||||||
var templateClash string
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
	var err error
 | 
						var err error
 | 
				
			||||||
	// 创建文件夹
 | 
					
 | 
				
			||||||
	err = common.MkEssentialDir()
 | 
						err = common.MkEssentialDir()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Logger.Panic("create essential dir failed", zap.Error(err))
 | 
							logger.Logger.Panic("create essential dir failed", zap.Error(err))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// 加载配置
 | 
					
 | 
				
			||||||
	err = config.LoadConfig()
 | 
						err = config.LoadConfig()
 | 
				
			||||||
	// 初始化日志
 | 
					
 | 
				
			||||||
	logger.InitLogger(config.Default.LogLevel)
 | 
						logger.InitLogger(config.GlobalConfig.LogLevel)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Logger.Panic("load config failed", zap.Error(err))
 | 
							logger.Logger.Panic("load config failed", zap.Error(err))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// 写入默认模板
 | 
					
 | 
				
			||||||
	err = common.WriteDefalutTemplate(templateMeta, templateClash)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		logger.Logger.Panic("write default template failed", zap.Error(err))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// 连接数据库
 | 
					 | 
				
			||||||
	err = database.ConnectDB()
 | 
						err = database.ConnectDB()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Logger.Panic("database connect failed", zap.Error(err))
 | 
							logger.Logger.Panic("database connect failed", zap.Error(err))
 | 
				
			||||||
@@ -48,16 +37,15 @@ func init() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
	// 设置运行模式
 | 
					 | 
				
			||||||
	gin.SetMode(gin.ReleaseMode)
 | 
						gin.SetMode(gin.ReleaseMode)
 | 
				
			||||||
	// 关闭 Gin 的日志输出
 | 
					
 | 
				
			||||||
	gin.DefaultWriter = io.Discard
 | 
						gin.DefaultWriter = io.Discard
 | 
				
			||||||
	// 创建路由
 | 
					
 | 
				
			||||||
	r := gin.Default()
 | 
						r := gin.Default()
 | 
				
			||||||
	// 设置路由
 | 
					
 | 
				
			||||||
	api.SetRoute(r)
 | 
						server.SetRoute(r)
 | 
				
			||||||
	logger.Logger.Info("server is running at http://localhost:" + strconv.Itoa(config.Default.Port))
 | 
						logger.Logger.Info("server is running at " + config.GlobalConfig.Address)
 | 
				
			||||||
	err := r.Run(":" + strconv.Itoa(config.Default.Port))
 | 
						err := r.Run(config.GlobalConfig.Address)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Logger.Error("server running failed", zap.Error(err))
 | 
							logger.Logger.Error("server running failed", zap.Error(err))
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,7 @@
 | 
				
			|||||||
package model
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "github.com/bestnite/sub2clash/parser"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ClashType int
 | 
					type ClashType int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
@@ -8,24 +10,20 @@ const (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func GetSupportProxyTypes(clashType ClashType) map[string]bool {
 | 
					func GetSupportProxyTypes(clashType ClashType) map[string]bool {
 | 
				
			||||||
	if clashType == Clash {
 | 
						supportProxyTypes := make(map[string]bool)
 | 
				
			||||||
		return map[string]bool{
 | 
					
 | 
				
			||||||
			"ss":     true,
 | 
						for _, parser := range parser.GetAllParsers() {
 | 
				
			||||||
			"ssr":    true,
 | 
							switch clashType {
 | 
				
			||||||
			"vmess":  true,
 | 
							case Clash:
 | 
				
			||||||
			"trojan": true,
 | 
								if parser.SupportClash() {
 | 
				
			||||||
 | 
									supportProxyTypes[parser.GetType()] = true
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case ClashMeta:
 | 
				
			||||||
 | 
								if parser.SupportMeta() {
 | 
				
			||||||
 | 
									supportProxyTypes[parser.GetType()] = true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	if clashType == ClashMeta {
 | 
					 | 
				
			||||||
		return map[string]bool{
 | 
					 | 
				
			||||||
			"ss":        true,
 | 
					 | 
				
			||||||
			"ssr":       true,
 | 
					 | 
				
			||||||
			"vmess":     true,
 | 
					 | 
				
			||||||
			"trojan":    true,
 | 
					 | 
				
			||||||
			"vless":     true,
 | 
					 | 
				
			||||||
			"hysteria":  true,
 | 
					 | 
				
			||||||
			"hysteria2": true,
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
					
 | 
				
			||||||
	return nil
 | 
						return supportProxyTypes
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										92
									
								
								model/convert_config.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								model/convert_config.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,92 @@
 | 
				
			|||||||
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/utils"
 | 
				
			||||||
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ConvertConfig struct {
 | 
				
			||||||
 | 
						ClashType           ClashType            `json:"clashType" binding:"required"`
 | 
				
			||||||
 | 
						Subs                []string             `json:"subscriptions" binding:""`
 | 
				
			||||||
 | 
						Proxies             []string             `json:"proxies" binding:""`
 | 
				
			||||||
 | 
						Refresh             bool                 `json:"refresh" binding:""`
 | 
				
			||||||
 | 
						Template            string               `json:"template" binding:""`
 | 
				
			||||||
 | 
						RuleProviders       []RuleProviderStruct `json:"ruleProviders" binding:""`
 | 
				
			||||||
 | 
						Rules               []RuleStruct         `json:"rules" binding:""`
 | 
				
			||||||
 | 
						AutoTest            bool                 `json:"autoTest" binding:""`
 | 
				
			||||||
 | 
						Lazy                bool                 `json:"lazy" binding:""`
 | 
				
			||||||
 | 
						Sort                string               `json:"sort" binding:""`
 | 
				
			||||||
 | 
						Remove              string               `json:"remove" binding:""`
 | 
				
			||||||
 | 
						Replace             map[string]string    `json:"replace" binding:""`
 | 
				
			||||||
 | 
						NodeListMode        bool                 `json:"nodeList" binding:""`
 | 
				
			||||||
 | 
						IgnoreCountryGrooup bool                 `json:"ignoreCountryGroup" binding:""`
 | 
				
			||||||
 | 
						UserAgent           string               `json:"userAgent" binding:""`
 | 
				
			||||||
 | 
						UseUDP              bool                 `json:"useUDP" binding:""`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type RuleProviderStruct struct {
 | 
				
			||||||
 | 
						Behavior string `json:"behavior" binding:""`
 | 
				
			||||||
 | 
						Url      string `json:"url" binding:""`
 | 
				
			||||||
 | 
						Group    string `json:"group" binding:""`
 | 
				
			||||||
 | 
						Prepend  bool   `json:"prepend" binding:""`
 | 
				
			||||||
 | 
						Name     string `json:"name" binding:""`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type RuleStruct struct {
 | 
				
			||||||
 | 
						Rule    string `json:"rule" binding:""`
 | 
				
			||||||
 | 
						Prepend bool   `json:"prepend" binding:""`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ParseConvertQuery(c *gin.Context) (ConvertConfig, error) {
 | 
				
			||||||
 | 
						config := c.Param("config")
 | 
				
			||||||
 | 
						queryBytes, err := utils.DecodeBase64(config, true)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return ConvertConfig{}, errors.New("参数错误: " + err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						var query ConvertConfig
 | 
				
			||||||
 | 
						err = json.Unmarshal([]byte(queryBytes), &query)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return ConvertConfig{}, errors.New("参数错误: " + err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(query.Subs) == 0 && len(query.Proxies) == 0 {
 | 
				
			||||||
 | 
							return ConvertConfig{}, errors.New("参数错误: sub 和 proxy 不能同时为空")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(query.Subs) > 0 {
 | 
				
			||||||
 | 
							for i := range query.Subs {
 | 
				
			||||||
 | 
								if !strings.HasPrefix(query.Subs[i], "http") {
 | 
				
			||||||
 | 
									return ConvertConfig{}, errors.New("参数错误: sub 格式错误")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if _, err := url.ParseRequestURI(query.Subs[i]); err != nil {
 | 
				
			||||||
 | 
									return ConvertConfig{}, errors.New("参数错误: " + err.Error())
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							query.Subs = nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if query.Template != "" {
 | 
				
			||||||
 | 
							if strings.HasPrefix(query.Template, "http") {
 | 
				
			||||||
 | 
								uri, err := url.ParseRequestURI(query.Template)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return ConvertConfig{}, err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								query.Template = uri.String()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(query.RuleProviders) > 0 {
 | 
				
			||||||
 | 
							names := make(map[string]bool)
 | 
				
			||||||
 | 
							for _, ruleProvider := range query.RuleProviders {
 | 
				
			||||||
 | 
								if _, ok := names[ruleProvider.Name]; ok {
 | 
				
			||||||
 | 
									return ConvertConfig{}, errors.New("参数错误: Rule-Provider 名称重复")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								names[ruleProvider.Name] = true
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							query.RuleProviders = nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return query, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,8 +1,5 @@
 | 
				
			|||||||
package model
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// https://zh.wikipedia.org/wiki/%E5%8C%BA%E5%9F%9F%E6%8C%87%E7%A4%BA%E7%AC%A6
 | 
					 | 
				
			||||||
// https://zh.wikipedia.org/zh-sg/ISO_3166-1%E4%BA%8C%E4%BD%8D%E5%AD%97%E6%AF%8D%E4%BB%A3%E7%A0%81
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var CountryEnglishName = map[string]string{
 | 
					var CountryEnglishName = map[string]string{
 | 
				
			||||||
	"Andorra":                        "安道尔(AD)",
 | 
						"Andorra":                        "安道尔(AD)",
 | 
				
			||||||
	"United Arab Emirates":           "阿联酋(AE)",
 | 
						"United Arab Emirates":           "阿联酋(AE)",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,12 +0,0 @@
 | 
				
			|||||||
package model
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Tags []struct {
 | 
					 | 
				
			||||||
	Name       string `json:"name"`
 | 
					 | 
				
			||||||
	ZipballUrl string `json:"zipball_url"`
 | 
					 | 
				
			||||||
	TarballUrl string `json:"tarball_url"`
 | 
					 | 
				
			||||||
	Commit     struct {
 | 
					 | 
				
			||||||
		Sha string `json:"sha"`
 | 
					 | 
				
			||||||
		Url string `json:"url"`
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	NodeId string `json:"node_id"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -9,12 +9,12 @@ type ProxyGroup struct {
 | 
				
			|||||||
	Type                string   `yaml:"type,omitempty"`
 | 
						Type                string   `yaml:"type,omitempty"`
 | 
				
			||||||
	Name                string   `yaml:"name,omitempty"`
 | 
						Name                string   `yaml:"name,omitempty"`
 | 
				
			||||||
	Proxies             []string `yaml:"proxies,omitempty"`
 | 
						Proxies             []string `yaml:"proxies,omitempty"`
 | 
				
			||||||
	IsCountryGrop       bool     `yaml:"-"` // 是否是国家分组
 | 
						IsCountryGrop       bool     `yaml:"-"`
 | 
				
			||||||
	Url                 string   `yaml:"url,omitempty"`
 | 
						Url                 string   `yaml:"url,omitempty"`
 | 
				
			||||||
	Interval            int      `yaml:"interval,omitempty"`
 | 
						Interval            int      `yaml:"interval,omitempty"`
 | 
				
			||||||
	Tolerance           int      `yaml:"tolerance,omitempty"`
 | 
						Tolerance           int      `yaml:"tolerance,omitempty"`
 | 
				
			||||||
	Lazy                bool     `yaml:"lazy"`
 | 
						Lazy                bool     `yaml:"lazy"`
 | 
				
			||||||
	Size                int      `yaml:"-"` // 代理数量
 | 
						Size                int      `yaml:"-"`
 | 
				
			||||||
	DisableUDP          bool     `yaml:"disable-udp,omitempty"`
 | 
						DisableUDP          bool     `yaml:"disable-udp,omitempty"`
 | 
				
			||||||
	Strategy            string   `yaml:"strategy,omitempty"`
 | 
						Strategy            string   `yaml:"strategy,omitempty"`
 | 
				
			||||||
	Icon                string   `yaml:"icon,omitempty"`
 | 
						Icon                string   `yaml:"icon,omitempty"`
 | 
				
			||||||
@@ -42,16 +42,15 @@ func (p ProxyGroupsSortBySize) Len() int {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (p ProxyGroupsSortByName) Less(i, j int) bool {
 | 
					func (p ProxyGroupsSortByName) Less(i, j int) bool {
 | 
				
			||||||
	// 定义一组备选语言:首选英语,其次中文
 | 
					
 | 
				
			||||||
	tags := []language.Tag{
 | 
						tags := []language.Tag{
 | 
				
			||||||
		language.English,
 | 
							language.English,
 | 
				
			||||||
		language.Chinese,
 | 
							language.Chinese,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	matcher := language.NewMatcher(tags)
 | 
						matcher := language.NewMatcher(tags)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 假设我们的请求语言是 "zh"(中文),则使用匹配器找到最佳匹配的语言
 | 
					 | 
				
			||||||
	bestMatch, _, _ := matcher.Match(language.Make("zh"))
 | 
						bestMatch, _, _ := matcher.Match(language.Make("zh"))
 | 
				
			||||||
	// 使用最佳匹配的语言进行排序
 | 
					
 | 
				
			||||||
	c := collate.New(bestMatch)
 | 
						c := collate.New(bestMatch)
 | 
				
			||||||
	return c.CompareString(p[i].Name, p[j].Name) < 0
 | 
						return c.CompareString(p[i].Name, p[j].Name) < 0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,82 +0,0 @@
 | 
				
			|||||||
package model
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type SmuxStruct struct {
 | 
					 | 
				
			||||||
	Enabled bool `yaml:"enable"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Proxy struct {
 | 
					 | 
				
			||||||
	Name                string         `yaml:"name,omitempty"`
 | 
					 | 
				
			||||||
	Server              string         `yaml:"server,omitempty"`
 | 
					 | 
				
			||||||
	Port                int            `yaml:"port,omitempty"`
 | 
					 | 
				
			||||||
	Type                string         `yaml:"type,omitempty"`
 | 
					 | 
				
			||||||
	Cipher              string         `yaml:"cipher,omitempty"`
 | 
					 | 
				
			||||||
	Password            string         `yaml:"password,omitempty"`
 | 
					 | 
				
			||||||
	UDP                 bool           `yaml:"udp,omitempty"`
 | 
					 | 
				
			||||||
	UUID                string         `yaml:"uuid,omitempty"`
 | 
					 | 
				
			||||||
	Network             string         `yaml:"network,omitempty"`
 | 
					 | 
				
			||||||
	Flow                string         `yaml:"flow,omitempty"`
 | 
					 | 
				
			||||||
	TLS                 bool           `yaml:"tls,omitempty"`
 | 
					 | 
				
			||||||
	ClientFingerprint   string         `yaml:"client-fingerprint,omitempty"`
 | 
					 | 
				
			||||||
	Plugin              string         `yaml:"plugin,omitempty"`
 | 
					 | 
				
			||||||
	PluginOpts          map[string]any `yaml:"plugin-opts,omitempty"`
 | 
					 | 
				
			||||||
	Smux                SmuxStruct     `yaml:"smux,omitempty"`
 | 
					 | 
				
			||||||
	Sni                 string         `yaml:"sni,omitempty"`
 | 
					 | 
				
			||||||
	AllowInsecure       bool           `yaml:"allow-insecure,omitempty"`
 | 
					 | 
				
			||||||
	Fingerprint         string         `yaml:"fingerprint,omitempty"`
 | 
					 | 
				
			||||||
	SkipCertVerify      bool           `yaml:"skip-cert-verify,omitempty"`
 | 
					 | 
				
			||||||
	Alpn                []string       `yaml:"alpn,omitempty"`
 | 
					 | 
				
			||||||
	XUDP                bool           `yaml:"xudp,omitempty"`
 | 
					 | 
				
			||||||
	Servername          string         `yaml:"servername,omitempty"`
 | 
					 | 
				
			||||||
	WSOpts              WSOptions      `yaml:"ws-opts,omitempty"`
 | 
					 | 
				
			||||||
	AlterID             int            `yaml:"alterId,omitempty"`
 | 
					 | 
				
			||||||
	GrpcOpts            GrpcOptions    `yaml:"grpc-opts,omitempty"`
 | 
					 | 
				
			||||||
	RealityOpts         RealityOptions `yaml:"reality-opts,omitempty"`
 | 
					 | 
				
			||||||
	Protocol            string         `yaml:"protocol,omitempty"`
 | 
					 | 
				
			||||||
	Obfs                string         `yaml:"obfs,omitempty"`
 | 
					 | 
				
			||||||
	ObfsParam           string         `yaml:"obfs-param,omitempty"`
 | 
					 | 
				
			||||||
	ProtocolParam       string         `yaml:"protocol-param,omitempty"`
 | 
					 | 
				
			||||||
	Remarks             []string       `yaml:"remarks,omitempty"`
 | 
					 | 
				
			||||||
	HTTPOpts            HTTPOptions    `yaml:"http-opts,omitempty"`
 | 
					 | 
				
			||||||
	HTTP2Opts           HTTP2Options   `yaml:"h2-opts,omitempty"`
 | 
					 | 
				
			||||||
	PacketAddr          bool           `yaml:"packet-addr,omitempty"`
 | 
					 | 
				
			||||||
	PacketEncoding      string         `yaml:"packet-encoding,omitempty"`
 | 
					 | 
				
			||||||
	GlobalPadding       bool           `yaml:"global-padding,omitempty"`
 | 
					 | 
				
			||||||
	AuthenticatedLength bool           `yaml:"authenticated-length,omitempty"`
 | 
					 | 
				
			||||||
	UDPOverTCP          bool           `yaml:"udp-over-tcp,omitempty"`
 | 
					 | 
				
			||||||
	UDPOverTCPVersion   int            `yaml:"udp-over-tcp-version,omitempty"`
 | 
					 | 
				
			||||||
	SubName             string         `yaml:"-"`
 | 
					 | 
				
			||||||
	Up                  string         `yaml:"up,omitempty"`
 | 
					 | 
				
			||||||
	Down                string         `yaml:"down,omitempty"`
 | 
					 | 
				
			||||||
	CustomCA            string         `yaml:"ca,omitempty"`
 | 
					 | 
				
			||||||
	CustomCAString      string         `yaml:"ca-str,omitempty"`
 | 
					 | 
				
			||||||
	CWND                int            `yaml:"cwnd,omitempty"`
 | 
					 | 
				
			||||||
	Auth                string         `yaml:"auth,omitempty"`
 | 
					 | 
				
			||||||
	ReceiveWindowConn   int            `yaml:"recv-window-conn,omitempty"`
 | 
					 | 
				
			||||||
	ReceiveWindow       int            `yaml:"recv-window,omitempty"`
 | 
					 | 
				
			||||||
	DisableMTUDiscovery bool           `yaml:"disable-mtu-discovery,omitempty"`
 | 
					 | 
				
			||||||
	FastOpen            bool           `yaml:"fast-open,omitempty"`
 | 
					 | 
				
			||||||
	HopInterval         int            `yaml:"hop-interval,omitempty"`
 | 
					 | 
				
			||||||
	Ports               string         `yaml:"ports,omitempty"`
 | 
					 | 
				
			||||||
	AuthStringOLD       string         `yaml:"auth_str,omitempty"`
 | 
					 | 
				
			||||||
	AuthString          string         `yaml:"auth-str,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p Proxy) MarshalYAML() (interface{}, error) {
 | 
					 | 
				
			||||||
	switch p.Type {
 | 
					 | 
				
			||||||
	case "vmess":
 | 
					 | 
				
			||||||
		return ProxyToVmess(p), nil
 | 
					 | 
				
			||||||
	case "ss":
 | 
					 | 
				
			||||||
		return ProxyToShadowSocks(p), nil
 | 
					 | 
				
			||||||
	case "ssr":
 | 
					 | 
				
			||||||
		return ProxyToShadowSocksR(p), nil
 | 
					 | 
				
			||||||
	case "vless":
 | 
					 | 
				
			||||||
		return ProxyToVless(p), nil
 | 
					 | 
				
			||||||
	case "trojan":
 | 
					 | 
				
			||||||
		return ProxyToTrojan(p), nil
 | 
					 | 
				
			||||||
	case "hysteria":
 | 
					 | 
				
			||||||
		return ProxyToHysteria(p), nil
 | 
					 | 
				
			||||||
	case "hysteria2":
 | 
					 | 
				
			||||||
		return ProxyToHysteria2(p), nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										18
									
								
								model/proxy/anytls.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								model/proxy/anytls.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					package proxy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/anytls.go
 | 
				
			||||||
 | 
					type Anytls struct {
 | 
				
			||||||
 | 
						Server                   string      `yaml:"server"`
 | 
				
			||||||
 | 
						Port                     IntOrString `yaml:"port"`
 | 
				
			||||||
 | 
						Password                 string      `yaml:"password"`
 | 
				
			||||||
 | 
						ALPN                     []string    `yaml:"alpn,omitempty"`
 | 
				
			||||||
 | 
						SNI                      string      `yaml:"sni,omitempty"`
 | 
				
			||||||
 | 
						ECHOpts                  ECHOptions  `yaml:"ech-opts,omitempty"`
 | 
				
			||||||
 | 
						ClientFingerprint        string      `yaml:"client-fingerprint,omitempty"`
 | 
				
			||||||
 | 
						SkipCertVerify           bool        `yaml:"skip-cert-verify,omitempty"`
 | 
				
			||||||
 | 
						Fingerprint              string      `yaml:"fingerprint,omitempty"`
 | 
				
			||||||
 | 
						UDP                      bool        `yaml:"udp,omitempty"`
 | 
				
			||||||
 | 
						IdleSessionCheckInterval int         `yaml:"idle-session-check-interval,omitempty"`
 | 
				
			||||||
 | 
						IdleSessionTimeout       int         `yaml:"idle-session-timeout,omitempty"`
 | 
				
			||||||
 | 
						MinIdleSession           int         `yaml:"min-idle-session,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										29
									
								
								model/proxy/hysteria.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								model/proxy/hysteria.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					package proxy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/hysteria.go
 | 
				
			||||||
 | 
					type Hysteria struct {
 | 
				
			||||||
 | 
						Server              string      `yaml:"server"`
 | 
				
			||||||
 | 
						Port                IntOrString `yaml:"port,omitempty"`
 | 
				
			||||||
 | 
						Ports               string      `yaml:"ports,omitempty"`
 | 
				
			||||||
 | 
						Protocol            string      `yaml:"protocol,omitempty"`
 | 
				
			||||||
 | 
						ObfsProtocol        string      `yaml:"obfs-protocol,omitempty"` // compatible with Stash
 | 
				
			||||||
 | 
						Up                  string      `yaml:"up"`
 | 
				
			||||||
 | 
						UpSpeed             int         `yaml:"up-speed,omitempty"` // compatible with Stash
 | 
				
			||||||
 | 
						Down                string      `yaml:"down"`
 | 
				
			||||||
 | 
						DownSpeed           int         `yaml:"down-speed,omitempty"` // compatible with Stash
 | 
				
			||||||
 | 
						Auth                string      `yaml:"auth,omitempty"`
 | 
				
			||||||
 | 
						AuthString          string      `yaml:"auth-str,omitempty"`
 | 
				
			||||||
 | 
						Obfs                string      `yaml:"obfs,omitempty"`
 | 
				
			||||||
 | 
						SNI                 string      `yaml:"sni,omitempty"`
 | 
				
			||||||
 | 
						ECHOpts             ECHOptions  `yaml:"ech-opts,omitempty"`
 | 
				
			||||||
 | 
						SkipCertVerify      bool        `yaml:"skip-cert-verify,omitempty"`
 | 
				
			||||||
 | 
						Fingerprint         string      `yaml:"fingerprint,omitempty"`
 | 
				
			||||||
 | 
						ALPN                []string    `yaml:"alpn,omitempty"`
 | 
				
			||||||
 | 
						CustomCA            string      `yaml:"ca,omitempty"`
 | 
				
			||||||
 | 
						CustomCAString      string      `yaml:"ca-str,omitempty"`
 | 
				
			||||||
 | 
						ReceiveWindowConn   int         `yaml:"recv-window-conn,omitempty"`
 | 
				
			||||||
 | 
						ReceiveWindow       int         `yaml:"recv-window,omitempty"`
 | 
				
			||||||
 | 
						DisableMTUDiscovery bool        `yaml:"disable-mtu-discovery,omitempty"`
 | 
				
			||||||
 | 
						FastOpen            bool        `yaml:"fast-open,omitempty"`
 | 
				
			||||||
 | 
						HopInterval         int         `yaml:"hop-interval,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										29
									
								
								model/proxy/hysteria2.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								model/proxy/hysteria2.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					package proxy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/hysteria2.go
 | 
				
			||||||
 | 
					type Hysteria2 struct {
 | 
				
			||||||
 | 
						Server         string      `yaml:"server"`
 | 
				
			||||||
 | 
						Port           IntOrString `yaml:"port,omitempty"`
 | 
				
			||||||
 | 
						Ports          string      `yaml:"ports,omitempty"`
 | 
				
			||||||
 | 
						HopInterval    int         `yaml:"hop-interval,omitempty"`
 | 
				
			||||||
 | 
						Up             string      `yaml:"up,omitempty"`
 | 
				
			||||||
 | 
						Down           string      `yaml:"down,omitempty"`
 | 
				
			||||||
 | 
						Password       string      `yaml:"password,omitempty"`
 | 
				
			||||||
 | 
						Obfs           string      `yaml:"obfs,omitempty"`
 | 
				
			||||||
 | 
						ObfsPassword   string      `yaml:"obfs-password,omitempty"`
 | 
				
			||||||
 | 
						SNI            string      `yaml:"sni,omitempty"`
 | 
				
			||||||
 | 
						ECHOpts        ECHOptions  `yaml:"ech-opts,omitempty"`
 | 
				
			||||||
 | 
						SkipCertVerify bool        `yaml:"skip-cert-verify,omitempty"`
 | 
				
			||||||
 | 
						Fingerprint    string      `yaml:"fingerprint,omitempty"`
 | 
				
			||||||
 | 
						ALPN           []string    `yaml:"alpn,omitempty"`
 | 
				
			||||||
 | 
						CustomCA       string      `yaml:"ca,omitempty"`
 | 
				
			||||||
 | 
						CustomCAString string      `yaml:"ca-str,omitempty"`
 | 
				
			||||||
 | 
						CWND           int         `yaml:"cwnd,omitempty"`
 | 
				
			||||||
 | 
						UdpMTU         int         `yaml:"udp-mtu,omitempty"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// quic-go special config
 | 
				
			||||||
 | 
						InitialStreamReceiveWindow     uint64 `yaml:"initial-stream-receive-window,omitempty"`
 | 
				
			||||||
 | 
						MaxStreamReceiveWindow         uint64 `yaml:"max-stream-receive-window,omitempty"`
 | 
				
			||||||
 | 
						InitialConnectionReceiveWindow uint64 `yaml:"initial-connection-receive-window,omitempty"`
 | 
				
			||||||
 | 
						MaxConnectionReceiveWindow     uint64 `yaml:"max-connection-receive-window,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										305
									
								
								model/proxy/proxy.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										305
									
								
								model/proxy/proxy.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,305 @@
 | 
				
			|||||||
 | 
					package proxy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gopkg.in/yaml.v3"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type IntOrString int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (i *IntOrString) UnmarshalYAML(value *yaml.Node) error {
 | 
				
			||||||
 | 
						intVal := 0
 | 
				
			||||||
 | 
						err := yaml.Unmarshal([]byte(value.Value), &intVal)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							*i = IntOrString(intVal)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						strVal := ""
 | 
				
			||||||
 | 
						err = yaml.Unmarshal([]byte(value.Value), &strVal)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							_int, err := strconv.ParseInt(strVal, 10, 64)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								*i = IntOrString(_int)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type HTTPOptions struct {
 | 
				
			||||||
 | 
						Method  string              `yaml:"method,omitempty"`
 | 
				
			||||||
 | 
						Path    []string            `yaml:"path,omitempty"`
 | 
				
			||||||
 | 
						Headers map[string][]string `yaml:"headers,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type HTTP2Options struct {
 | 
				
			||||||
 | 
						Host []string `yaml:"host,omitempty"`
 | 
				
			||||||
 | 
						Path string   `yaml:"path,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type GrpcOptions struct {
 | 
				
			||||||
 | 
						GrpcServiceName string `yaml:"grpc-service-name,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type RealityOptions struct {
 | 
				
			||||||
 | 
						PublicKey string `yaml:"public-key"`
 | 
				
			||||||
 | 
						ShortID   string `yaml:"short-id,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type WSOptions struct {
 | 
				
			||||||
 | 
						Path                string            `yaml:"path,omitempty"`
 | 
				
			||||||
 | 
						Headers             map[string]string `yaml:"headers,omitempty"`
 | 
				
			||||||
 | 
						MaxEarlyData        int               `yaml:"max-early-data,omitempty"`
 | 
				
			||||||
 | 
						EarlyDataHeaderName string            `yaml:"early-data-header-name,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type SmuxStruct struct {
 | 
				
			||||||
 | 
						Enabled bool `yaml:"enable"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type WireGuardPeerOption struct {
 | 
				
			||||||
 | 
						Server       string   `yaml:"server"`
 | 
				
			||||||
 | 
						Port         int      `yaml:"port"`
 | 
				
			||||||
 | 
						PublicKey    string   `yaml:"public-key,omitempty"`
 | 
				
			||||||
 | 
						PreSharedKey string   `yaml:"pre-shared-key,omitempty"`
 | 
				
			||||||
 | 
						Reserved     []uint8  `yaml:"reserved,omitempty"`
 | 
				
			||||||
 | 
						AllowedIPs   []string `yaml:"allowed-ips,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ECHOptions struct {
 | 
				
			||||||
 | 
						Enable bool   `yaml:"enable,omitempty" obfs:"enable,omitempty"`
 | 
				
			||||||
 | 
						Config string `yaml:"config,omitempty" obfs:"config,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Proxy struct {
 | 
				
			||||||
 | 
						Type    string
 | 
				
			||||||
 | 
						Name    string
 | 
				
			||||||
 | 
						SubName string `yaml:"-"`
 | 
				
			||||||
 | 
						Anytls
 | 
				
			||||||
 | 
						Hysteria
 | 
				
			||||||
 | 
						Hysteria2
 | 
				
			||||||
 | 
						ShadowSocks
 | 
				
			||||||
 | 
						ShadowSocksR
 | 
				
			||||||
 | 
						Trojan
 | 
				
			||||||
 | 
						Vless
 | 
				
			||||||
 | 
						Vmess
 | 
				
			||||||
 | 
						Socks
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p Proxy) MarshalYAML() (any, error) {
 | 
				
			||||||
 | 
						switch p.Type {
 | 
				
			||||||
 | 
						case "anytls":
 | 
				
			||||||
 | 
							return struct {
 | 
				
			||||||
 | 
								Type   string `yaml:"type"`
 | 
				
			||||||
 | 
								Name   string `yaml:"name"`
 | 
				
			||||||
 | 
								Anytls `yaml:",inline"`
 | 
				
			||||||
 | 
							}{
 | 
				
			||||||
 | 
								Type:   p.Type,
 | 
				
			||||||
 | 
								Name:   p.Name,
 | 
				
			||||||
 | 
								Anytls: p.Anytls,
 | 
				
			||||||
 | 
							}, nil
 | 
				
			||||||
 | 
						case "hysteria":
 | 
				
			||||||
 | 
							return struct {
 | 
				
			||||||
 | 
								Type     string `yaml:"type"`
 | 
				
			||||||
 | 
								Name     string `yaml:"name"`
 | 
				
			||||||
 | 
								Hysteria `yaml:",inline"`
 | 
				
			||||||
 | 
							}{
 | 
				
			||||||
 | 
								Type:     p.Type,
 | 
				
			||||||
 | 
								Name:     p.Name,
 | 
				
			||||||
 | 
								Hysteria: p.Hysteria,
 | 
				
			||||||
 | 
							}, nil
 | 
				
			||||||
 | 
						case "hysteria2":
 | 
				
			||||||
 | 
							return struct {
 | 
				
			||||||
 | 
								Type      string `yaml:"type"`
 | 
				
			||||||
 | 
								Name      string `yaml:"name"`
 | 
				
			||||||
 | 
								Hysteria2 `yaml:",inline"`
 | 
				
			||||||
 | 
							}{
 | 
				
			||||||
 | 
								Type:      p.Type,
 | 
				
			||||||
 | 
								Name:      p.Name,
 | 
				
			||||||
 | 
								Hysteria2: p.Hysteria2,
 | 
				
			||||||
 | 
							}, nil
 | 
				
			||||||
 | 
						case "ss":
 | 
				
			||||||
 | 
							return struct {
 | 
				
			||||||
 | 
								Type        string `yaml:"type"`
 | 
				
			||||||
 | 
								Name        string `yaml:"name"`
 | 
				
			||||||
 | 
								ShadowSocks `yaml:",inline"`
 | 
				
			||||||
 | 
							}{
 | 
				
			||||||
 | 
								Type:        p.Type,
 | 
				
			||||||
 | 
								Name:        p.Name,
 | 
				
			||||||
 | 
								ShadowSocks: p.ShadowSocks,
 | 
				
			||||||
 | 
							}, nil
 | 
				
			||||||
 | 
						case "ssr":
 | 
				
			||||||
 | 
							return struct {
 | 
				
			||||||
 | 
								Type         string `yaml:"type"`
 | 
				
			||||||
 | 
								Name         string `yaml:"name"`
 | 
				
			||||||
 | 
								ShadowSocksR `yaml:",inline"`
 | 
				
			||||||
 | 
							}{
 | 
				
			||||||
 | 
								Type:         p.Type,
 | 
				
			||||||
 | 
								Name:         p.Name,
 | 
				
			||||||
 | 
								ShadowSocksR: p.ShadowSocksR,
 | 
				
			||||||
 | 
							}, nil
 | 
				
			||||||
 | 
						case "trojan":
 | 
				
			||||||
 | 
							return struct {
 | 
				
			||||||
 | 
								Type   string `yaml:"type"`
 | 
				
			||||||
 | 
								Name   string `yaml:"name"`
 | 
				
			||||||
 | 
								Trojan `yaml:",inline"`
 | 
				
			||||||
 | 
							}{
 | 
				
			||||||
 | 
								Type:   p.Type,
 | 
				
			||||||
 | 
								Name:   p.Name,
 | 
				
			||||||
 | 
								Trojan: p.Trojan,
 | 
				
			||||||
 | 
							}, nil
 | 
				
			||||||
 | 
						case "vless":
 | 
				
			||||||
 | 
							return struct {
 | 
				
			||||||
 | 
								Type  string `yaml:"type"`
 | 
				
			||||||
 | 
								Name  string `yaml:"name"`
 | 
				
			||||||
 | 
								Vless `yaml:",inline"`
 | 
				
			||||||
 | 
							}{
 | 
				
			||||||
 | 
								Type:  p.Type,
 | 
				
			||||||
 | 
								Name:  p.Name,
 | 
				
			||||||
 | 
								Vless: p.Vless,
 | 
				
			||||||
 | 
							}, nil
 | 
				
			||||||
 | 
						case "vmess":
 | 
				
			||||||
 | 
							return struct {
 | 
				
			||||||
 | 
								Type  string `yaml:"type"`
 | 
				
			||||||
 | 
								Name  string `yaml:"name"`
 | 
				
			||||||
 | 
								Vmess `yaml:",inline"`
 | 
				
			||||||
 | 
							}{
 | 
				
			||||||
 | 
								Type:  p.Type,
 | 
				
			||||||
 | 
								Name:  p.Name,
 | 
				
			||||||
 | 
								Vmess: p.Vmess,
 | 
				
			||||||
 | 
							}, nil
 | 
				
			||||||
 | 
						case "socks5":
 | 
				
			||||||
 | 
							return struct {
 | 
				
			||||||
 | 
								Type  string `yaml:"type"`
 | 
				
			||||||
 | 
								Name  string `yaml:"name"`
 | 
				
			||||||
 | 
								Socks `yaml:",inline"`
 | 
				
			||||||
 | 
							}{
 | 
				
			||||||
 | 
								Type:  p.Type,
 | 
				
			||||||
 | 
								Name:  p.Name,
 | 
				
			||||||
 | 
								Socks: p.Socks,
 | 
				
			||||||
 | 
							}, nil
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("unsupported proxy type: %s", p.Type)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *Proxy) UnmarshalYAML(node *yaml.Node) error {
 | 
				
			||||||
 | 
						var temp struct {
 | 
				
			||||||
 | 
							Type string `yaml:"type"`
 | 
				
			||||||
 | 
							Name string `yaml:"name"`
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := node.Decode(&temp); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						p.Type = temp.Type
 | 
				
			||||||
 | 
						p.Name = temp.Name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch temp.Type {
 | 
				
			||||||
 | 
						case "anytls":
 | 
				
			||||||
 | 
							var data struct {
 | 
				
			||||||
 | 
								Type   string `yaml:"type"`
 | 
				
			||||||
 | 
								Name   string `yaml:"name"`
 | 
				
			||||||
 | 
								Anytls `yaml:",inline"`
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err := node.Decode(&data); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							p.Anytls = data.Anytls
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						case "hysteria":
 | 
				
			||||||
 | 
							var data struct {
 | 
				
			||||||
 | 
								Type     string `yaml:"type"`
 | 
				
			||||||
 | 
								Name     string `yaml:"name"`
 | 
				
			||||||
 | 
								Hysteria `yaml:",inline"`
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err := node.Decode(&data); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							p.Hysteria = data.Hysteria
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						case "hysteria2":
 | 
				
			||||||
 | 
							var data struct {
 | 
				
			||||||
 | 
								Type      string `yaml:"type"`
 | 
				
			||||||
 | 
								Name      string `yaml:"name"`
 | 
				
			||||||
 | 
								Hysteria2 `yaml:",inline"`
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err := node.Decode(&data); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							p.Hysteria2 = data.Hysteria2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						case "ss":
 | 
				
			||||||
 | 
							var data struct {
 | 
				
			||||||
 | 
								Type        string `yaml:"type"`
 | 
				
			||||||
 | 
								Name        string `yaml:"name"`
 | 
				
			||||||
 | 
								ShadowSocks `yaml:",inline"`
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err := node.Decode(&data); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							p.ShadowSocks = data.ShadowSocks
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						case "ssr":
 | 
				
			||||||
 | 
							var data struct {
 | 
				
			||||||
 | 
								Type         string `yaml:"type"`
 | 
				
			||||||
 | 
								Name         string `yaml:"name"`
 | 
				
			||||||
 | 
								ShadowSocksR `yaml:",inline"`
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err := node.Decode(&data); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							p.ShadowSocksR = data.ShadowSocksR
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						case "trojan":
 | 
				
			||||||
 | 
							var data struct {
 | 
				
			||||||
 | 
								Type   string `yaml:"type"`
 | 
				
			||||||
 | 
								Name   string `yaml:"name"`
 | 
				
			||||||
 | 
								Trojan `yaml:",inline"`
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err := node.Decode(&data); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							p.Trojan = data.Trojan
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						case "vless":
 | 
				
			||||||
 | 
							var data struct {
 | 
				
			||||||
 | 
								Type  string `yaml:"type"`
 | 
				
			||||||
 | 
								Name  string `yaml:"name"`
 | 
				
			||||||
 | 
								Vless `yaml:",inline"`
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err := node.Decode(&data); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							p.Vless = data.Vless
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						case "vmess":
 | 
				
			||||||
 | 
							var data struct {
 | 
				
			||||||
 | 
								Type  string `yaml:"type"`
 | 
				
			||||||
 | 
								Name  string `yaml:"name"`
 | 
				
			||||||
 | 
								Vmess `yaml:",inline"`
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err := node.Decode(&data); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							p.Vmess = data.Vmess
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						case "socks5":
 | 
				
			||||||
 | 
							var data struct {
 | 
				
			||||||
 | 
								Type  string `yaml:"type"`
 | 
				
			||||||
 | 
								Name  string `yaml:"name"`
 | 
				
			||||||
 | 
								Socks `yaml:",inline"`
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err := node.Decode(&data); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							p.Socks = data.Socks
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return fmt.Errorf("unsupported proxy type: %s", temp.Type)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										15
									
								
								model/proxy/shadowsocks.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								model/proxy/shadowsocks.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					package proxy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/shadowsocks.go
 | 
				
			||||||
 | 
					type ShadowSocks struct {
 | 
				
			||||||
 | 
						Server            string         `yaml:"server"`
 | 
				
			||||||
 | 
						Port              IntOrString    `yaml:"port"`
 | 
				
			||||||
 | 
						Password          string         `yaml:"password"`
 | 
				
			||||||
 | 
						Cipher            string         `yaml:"cipher"`
 | 
				
			||||||
 | 
						UDP               bool           `yaml:"udp,omitempty"`
 | 
				
			||||||
 | 
						Plugin            string         `yaml:"plugin,omitempty"`
 | 
				
			||||||
 | 
						PluginOpts        map[string]any `yaml:"plugin-opts,omitempty"`
 | 
				
			||||||
 | 
						UDPOverTCP        bool           `yaml:"udp-over-tcp,omitempty"`
 | 
				
			||||||
 | 
						UDPOverTCPVersion int            `yaml:"udp-over-tcp-version,omitempty"`
 | 
				
			||||||
 | 
						ClientFingerprint string         `yaml:"client-fingerprint,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										14
									
								
								model/proxy/shadowsocksr.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								model/proxy/shadowsocksr.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					package proxy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/shadowsocksr.go
 | 
				
			||||||
 | 
					type ShadowSocksR struct {
 | 
				
			||||||
 | 
						Server        string      `yaml:"server"`
 | 
				
			||||||
 | 
						Port          IntOrString `yaml:"port"`
 | 
				
			||||||
 | 
						Password      string      `yaml:"password"`
 | 
				
			||||||
 | 
						Cipher        string      `yaml:"cipher"`
 | 
				
			||||||
 | 
						Obfs          string      `yaml:"obfs"`
 | 
				
			||||||
 | 
						ObfsParam     string      `yaml:"obfs-param,omitempty"`
 | 
				
			||||||
 | 
						Protocol      string      `yaml:"protocol"`
 | 
				
			||||||
 | 
						ProtocolParam string      `yaml:"protocol-param,omitempty"`
 | 
				
			||||||
 | 
						UDP           bool        `yaml:"udp,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										13
									
								
								model/proxy/socks.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								model/proxy/socks.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					package proxy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/socks5.go
 | 
				
			||||||
 | 
					type Socks struct {
 | 
				
			||||||
 | 
						Server         string      `yaml:"server"`
 | 
				
			||||||
 | 
						Port           IntOrString `yaml:"port"`
 | 
				
			||||||
 | 
						UserName       string      `yaml:"username,omitempty"`
 | 
				
			||||||
 | 
						Password       string      `yaml:"password,omitempty"`
 | 
				
			||||||
 | 
						TLS            bool        `yaml:"tls,omitempty"`
 | 
				
			||||||
 | 
						UDP            bool        `yaml:"udp,omitempty"`
 | 
				
			||||||
 | 
						SkipCertVerify bool        `yaml:"skip-cert-verify,omitempty"`
 | 
				
			||||||
 | 
						Fingerprint    string      `yaml:"fingerprint,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,10 +1,9 @@
 | 
				
			|||||||
package model
 | 
					package proxy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/trojan.go
 | 
				
			||||||
type Trojan struct {
 | 
					type Trojan struct {
 | 
				
			||||||
	Type              string         `yaml:"type"`
 | 
					 | 
				
			||||||
	Name              string         `yaml:"name"`
 | 
					 | 
				
			||||||
	Server            string         `yaml:"server"`
 | 
						Server            string         `yaml:"server"`
 | 
				
			||||||
	Port              int            `yaml:"port"`
 | 
						Port              IntOrString    `yaml:"port"`
 | 
				
			||||||
	Password          string         `yaml:"password"`
 | 
						Password          string         `yaml:"password"`
 | 
				
			||||||
	ALPN              []string       `yaml:"alpn,omitempty"`
 | 
						ALPN              []string       `yaml:"alpn,omitempty"`
 | 
				
			||||||
	SNI               string         `yaml:"sni,omitempty"`
 | 
						SNI               string         `yaml:"sni,omitempty"`
 | 
				
			||||||
@@ -12,28 +11,16 @@ type Trojan struct {
 | 
				
			|||||||
	Fingerprint       string         `yaml:"fingerprint,omitempty"`
 | 
						Fingerprint       string         `yaml:"fingerprint,omitempty"`
 | 
				
			||||||
	UDP               bool           `yaml:"udp,omitempty"`
 | 
						UDP               bool           `yaml:"udp,omitempty"`
 | 
				
			||||||
	Network           string         `yaml:"network,omitempty"`
 | 
						Network           string         `yaml:"network,omitempty"`
 | 
				
			||||||
 | 
						ECHOpts           ECHOptions     `yaml:"ech-opts,omitempty"`
 | 
				
			||||||
	RealityOpts       RealityOptions `yaml:"reality-opts,omitempty"`
 | 
						RealityOpts       RealityOptions `yaml:"reality-opts,omitempty"`
 | 
				
			||||||
	GrpcOpts          GrpcOptions    `yaml:"grpc-opts,omitempty"`
 | 
						GrpcOpts          GrpcOptions    `yaml:"grpc-opts,omitempty"`
 | 
				
			||||||
	WSOpts            WSOptions      `yaml:"ws-opts,omitempty"`
 | 
						WSOpts            WSOptions      `yaml:"ws-opts,omitempty"`
 | 
				
			||||||
 | 
						SSOpts            TrojanSSOption `yaml:"ss-opts,omitempty"`
 | 
				
			||||||
	ClientFingerprint string         `yaml:"client-fingerprint,omitempty"`
 | 
						ClientFingerprint string         `yaml:"client-fingerprint,omitempty"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ProxyToTrojan(p Proxy) Trojan {
 | 
					type TrojanSSOption struct {
 | 
				
			||||||
	return Trojan{
 | 
						Enabled  bool   `yaml:"enabled,omitempty"`
 | 
				
			||||||
		Type:              "trojan",
 | 
						Method   string `yaml:"method,omitempty"`
 | 
				
			||||||
		Name:              p.Name,
 | 
						Password string `yaml:"password,omitempty"`
 | 
				
			||||||
		Server:            p.Server,
 | 
					 | 
				
			||||||
		Port:              p.Port,
 | 
					 | 
				
			||||||
		Password:          p.Password,
 | 
					 | 
				
			||||||
		ALPN:              p.Alpn,
 | 
					 | 
				
			||||||
		SNI:               p.Sni,
 | 
					 | 
				
			||||||
		SkipCertVerify:    p.SkipCertVerify,
 | 
					 | 
				
			||||||
		Fingerprint:       p.Fingerprint,
 | 
					 | 
				
			||||||
		UDP:               p.UDP,
 | 
					 | 
				
			||||||
		Network:           p.Network,
 | 
					 | 
				
			||||||
		RealityOpts:       p.RealityOpts,
 | 
					 | 
				
			||||||
		GrpcOpts:          p.GrpcOpts,
 | 
					 | 
				
			||||||
		WSOpts:            p.WSOpts,
 | 
					 | 
				
			||||||
		ClientFingerprint: p.ClientFingerprint,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,10 +1,9 @@
 | 
				
			|||||||
package model
 | 
					package proxy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/vless.go
 | 
				
			||||||
type Vless struct {
 | 
					type Vless struct {
 | 
				
			||||||
	Type              string            `yaml:"type"`
 | 
					 | 
				
			||||||
	Name              string            `yaml:"name"`
 | 
					 | 
				
			||||||
	Server            string            `yaml:"server"`
 | 
						Server            string            `yaml:"server"`
 | 
				
			||||||
	Port              int               `yaml:"port"`
 | 
						Port              IntOrString       `yaml:"port"`
 | 
				
			||||||
	UUID              string            `yaml:"uuid"`
 | 
						UUID              string            `yaml:"uuid"`
 | 
				
			||||||
	Flow              string            `yaml:"flow,omitempty"`
 | 
						Flow              string            `yaml:"flow,omitempty"`
 | 
				
			||||||
	TLS               bool              `yaml:"tls,omitempty"`
 | 
						TLS               bool              `yaml:"tls,omitempty"`
 | 
				
			||||||
@@ -14,6 +13,7 @@ type Vless struct {
 | 
				
			|||||||
	XUDP              bool              `yaml:"xudp,omitempty"`
 | 
						XUDP              bool              `yaml:"xudp,omitempty"`
 | 
				
			||||||
	PacketEncoding    string            `yaml:"packet-encoding,omitempty"`
 | 
						PacketEncoding    string            `yaml:"packet-encoding,omitempty"`
 | 
				
			||||||
	Network           string            `yaml:"network,omitempty"`
 | 
						Network           string            `yaml:"network,omitempty"`
 | 
				
			||||||
 | 
						ECHOpts           ECHOptions        `yaml:"ech-opts,omitempty"`
 | 
				
			||||||
	RealityOpts       RealityOptions    `yaml:"reality-opts,omitempty"`
 | 
						RealityOpts       RealityOptions    `yaml:"reality-opts,omitempty"`
 | 
				
			||||||
	HTTPOpts          HTTPOptions       `yaml:"http-opts,omitempty"`
 | 
						HTTPOpts          HTTPOptions       `yaml:"http-opts,omitempty"`
 | 
				
			||||||
	HTTP2Opts         HTTP2Options      `yaml:"h2-opts,omitempty"`
 | 
						HTTP2Opts         HTTP2Options      `yaml:"h2-opts,omitempty"`
 | 
				
			||||||
@@ -26,32 +26,3 @@ type Vless struct {
 | 
				
			|||||||
	ServerName        string            `yaml:"servername,omitempty"`
 | 
						ServerName        string            `yaml:"servername,omitempty"`
 | 
				
			||||||
	ClientFingerprint string            `yaml:"client-fingerprint,omitempty"`
 | 
						ClientFingerprint string            `yaml:"client-fingerprint,omitempty"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
func ProxyToVless(p Proxy) Vless {
 | 
					 | 
				
			||||||
	return Vless{
 | 
					 | 
				
			||||||
		Type:              "vless",
 | 
					 | 
				
			||||||
		Name:              p.Name,
 | 
					 | 
				
			||||||
		Server:            p.Server,
 | 
					 | 
				
			||||||
		Port:              p.Port,
 | 
					 | 
				
			||||||
		UUID:              p.UUID,
 | 
					 | 
				
			||||||
		Flow:              p.Flow,
 | 
					 | 
				
			||||||
		TLS:               p.TLS,
 | 
					 | 
				
			||||||
		ALPN:              p.Alpn,
 | 
					 | 
				
			||||||
		UDP:               p.UDP,
 | 
					 | 
				
			||||||
		PacketAddr:        p.PacketAddr,
 | 
					 | 
				
			||||||
		XUDP:              p.XUDP,
 | 
					 | 
				
			||||||
		PacketEncoding:    p.PacketEncoding,
 | 
					 | 
				
			||||||
		Network:           p.Network,
 | 
					 | 
				
			||||||
		RealityOpts:       p.RealityOpts,
 | 
					 | 
				
			||||||
		HTTPOpts:          p.HTTPOpts,
 | 
					 | 
				
			||||||
		HTTP2Opts:         p.HTTP2Opts,
 | 
					 | 
				
			||||||
		GrpcOpts:          p.GrpcOpts,
 | 
					 | 
				
			||||||
		WSOpts:            p.WSOpts,
 | 
					 | 
				
			||||||
		WSPath:            p.WSOpts.Path,
 | 
					 | 
				
			||||||
		WSHeaders:         p.WSOpts.Headers,
 | 
					 | 
				
			||||||
		SkipCertVerify:    p.SkipCertVerify,
 | 
					 | 
				
			||||||
		Fingerprint:       p.Fingerprint,
 | 
					 | 
				
			||||||
		ServerName:        p.Servername,
 | 
					 | 
				
			||||||
		ClientFingerprint: p.ClientFingerprint,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										29
									
								
								model/proxy/vmess.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								model/proxy/vmess.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					package proxy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/vmess.go
 | 
				
			||||||
 | 
					type Vmess struct {
 | 
				
			||||||
 | 
						Server              string         `yaml:"server"`
 | 
				
			||||||
 | 
						Port                IntOrString    `yaml:"port"`
 | 
				
			||||||
 | 
						UUID                string         `yaml:"uuid"`
 | 
				
			||||||
 | 
						AlterID             IntOrString    `yaml:"alterId"`
 | 
				
			||||||
 | 
						Cipher              string         `yaml:"cipher"`
 | 
				
			||||||
 | 
						UDP                 bool           `yaml:"udp,omitempty"`
 | 
				
			||||||
 | 
						Network             string         `yaml:"network,omitempty"`
 | 
				
			||||||
 | 
						TLS                 bool           `yaml:"tls,omitempty"`
 | 
				
			||||||
 | 
						ALPN                []string       `yaml:"alpn,omitempty"`
 | 
				
			||||||
 | 
						SkipCertVerify      bool           `yaml:"skip-cert-verify,omitempty"`
 | 
				
			||||||
 | 
						Fingerprint         string         `yaml:"fingerprint,omitempty"`
 | 
				
			||||||
 | 
						ServerName          string         `yaml:"servername,omitempty"`
 | 
				
			||||||
 | 
						ECHOpts             ECHOptions     `yaml:"ech-opts,omitempty"`
 | 
				
			||||||
 | 
						RealityOpts         RealityOptions `yaml:"reality-opts,omitempty"`
 | 
				
			||||||
 | 
						HTTPOpts            HTTPOptions    `yaml:"http-opts,omitempty"`
 | 
				
			||||||
 | 
						HTTP2Opts           HTTP2Options   `yaml:"h2-opts,omitempty"`
 | 
				
			||||||
 | 
						GrpcOpts            GrpcOptions    `yaml:"grpc-opts,omitempty"`
 | 
				
			||||||
 | 
						WSOpts              WSOptions      `yaml:"ws-opts,omitempty"`
 | 
				
			||||||
 | 
						PacketAddr          bool           `yaml:"packet-addr,omitempty"`
 | 
				
			||||||
 | 
						XUDP                bool           `yaml:"xudp,omitempty"`
 | 
				
			||||||
 | 
						PacketEncoding      string         `yaml:"packet-encoding,omitempty"`
 | 
				
			||||||
 | 
						GlobalPadding       bool           `yaml:"global-padding,omitempty"`
 | 
				
			||||||
 | 
						AuthenticatedLength bool           `yaml:"authenticated-length,omitempty"`
 | 
				
			||||||
 | 
						ClientFingerprint   string         `yaml:"client-fingerprint,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,58 +0,0 @@
 | 
				
			|||||||
package model
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Hysteria struct {
 | 
					 | 
				
			||||||
	Type                string   `yaml:"type"`
 | 
					 | 
				
			||||||
	Name                string   `yaml:"name"`
 | 
					 | 
				
			||||||
	Server              string   `yaml:"server"`
 | 
					 | 
				
			||||||
	Port                int      `yaml:"port,omitempty"`
 | 
					 | 
				
			||||||
	Ports               string   `yaml:"ports,omitempty"`
 | 
					 | 
				
			||||||
	Protocol            string   `yaml:"protocol,omitempty"`
 | 
					 | 
				
			||||||
	ObfsProtocol        string   `yaml:"obfs-protocol,omitempty"` // compatible with Stash
 | 
					 | 
				
			||||||
	Up                  string   `yaml:"up"`
 | 
					 | 
				
			||||||
	UpSpeed             int      `yaml:"up-speed,omitempty"` // compatible with Stash
 | 
					 | 
				
			||||||
	Down                string   `yaml:"down"`
 | 
					 | 
				
			||||||
	DownSpeed           int      `yaml:"down-speed,omitempty"` // compatible with Stash
 | 
					 | 
				
			||||||
	Auth                string   `yaml:"auth,omitempty"`
 | 
					 | 
				
			||||||
	AuthStringOLD       string   `yaml:"auth_str,omitempty"`
 | 
					 | 
				
			||||||
	AuthString          string   `yaml:"auth-str,omitempty"`
 | 
					 | 
				
			||||||
	Obfs                string   `yaml:"obfs,omitempty"`
 | 
					 | 
				
			||||||
	SNI                 string   `yaml:"sni,omitempty"`
 | 
					 | 
				
			||||||
	SkipCertVerify      bool     `yaml:"skip-cert-verify,omitempty"`
 | 
					 | 
				
			||||||
	Fingerprint         string   `yaml:"fingerprint,omitempty"`
 | 
					 | 
				
			||||||
	ALPN                []string `yaml:"alpn,omitempty"`
 | 
					 | 
				
			||||||
	CustomCA            string   `yaml:"ca,omitempty"`
 | 
					 | 
				
			||||||
	CustomCAString      string   `yaml:"ca-str,omitempty"`
 | 
					 | 
				
			||||||
	ReceiveWindowConn   int      `yaml:"recv-window-conn,omitempty"`
 | 
					 | 
				
			||||||
	ReceiveWindow       int      `yaml:"recv-window,omitempty"`
 | 
					 | 
				
			||||||
	DisableMTUDiscovery bool     `yaml:"disable-mtu-discovery,omitempty"`
 | 
					 | 
				
			||||||
	FastOpen            bool     `yaml:"fast-open,omitempty"`
 | 
					 | 
				
			||||||
	HopInterval         int      `yaml:"hop-interval,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func ProxyToHysteria(p Proxy) Hysteria {
 | 
					 | 
				
			||||||
	return Hysteria{
 | 
					 | 
				
			||||||
		Type:                "hysteria",
 | 
					 | 
				
			||||||
		Name:                p.Name,
 | 
					 | 
				
			||||||
		Server:              p.Server,
 | 
					 | 
				
			||||||
		Port:                p.Port,
 | 
					 | 
				
			||||||
		Ports:               p.Ports,
 | 
					 | 
				
			||||||
		Protocol:            p.Protocol,
 | 
					 | 
				
			||||||
		Up:                  p.Up,
 | 
					 | 
				
			||||||
		Down:                p.Down,
 | 
					 | 
				
			||||||
		Auth:                p.Auth,
 | 
					 | 
				
			||||||
		AuthStringOLD:       p.AuthStringOLD,
 | 
					 | 
				
			||||||
		AuthString:          p.AuthString,
 | 
					 | 
				
			||||||
		Obfs:                p.Obfs,
 | 
					 | 
				
			||||||
		SNI:                 p.Sni,
 | 
					 | 
				
			||||||
		SkipCertVerify:      p.SkipCertVerify,
 | 
					 | 
				
			||||||
		Fingerprint:         p.Fingerprint,
 | 
					 | 
				
			||||||
		ALPN:                p.Alpn,
 | 
					 | 
				
			||||||
		CustomCA:            p.CustomCA,
 | 
					 | 
				
			||||||
		CustomCAString:      p.CustomCAString,
 | 
					 | 
				
			||||||
		ReceiveWindowConn:   p.ReceiveWindowConn,
 | 
					 | 
				
			||||||
		ReceiveWindow:       p.ReceiveWindow,
 | 
					 | 
				
			||||||
		DisableMTUDiscovery: p.DisableMTUDiscovery,
 | 
					 | 
				
			||||||
		FastOpen:            p.FastOpen,
 | 
					 | 
				
			||||||
		HopInterval:         p.HopInterval,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,41 +0,0 @@
 | 
				
			|||||||
package model
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Hysteria2 struct {
 | 
					 | 
				
			||||||
	Type           string   `yaml:"type"`
 | 
					 | 
				
			||||||
	Name           string   `yaml:"name"`
 | 
					 | 
				
			||||||
	Server         string   `yaml:"server"`
 | 
					 | 
				
			||||||
	Port           int      `yaml:"port"`
 | 
					 | 
				
			||||||
	Up             string   `yaml:"up,omitempty"`
 | 
					 | 
				
			||||||
	Down           string   `yaml:"down,omitempty"`
 | 
					 | 
				
			||||||
	Password       string   `yaml:"password,omitempty"`
 | 
					 | 
				
			||||||
	Obfs           string   `yaml:"obfs,omitempty"`
 | 
					 | 
				
			||||||
	ObfsPassword   string   `yaml:"obfs-password,omitempty"`
 | 
					 | 
				
			||||||
	SNI            string   `yaml:"sni,omitempty"`
 | 
					 | 
				
			||||||
	SkipCertVerify bool     `yaml:"skip-cert-verify,omitempty"`
 | 
					 | 
				
			||||||
	Fingerprint    string   `yaml:"fingerprint,omitempty"`
 | 
					 | 
				
			||||||
	ALPN           []string `yaml:"alpn,omitempty"`
 | 
					 | 
				
			||||||
	CustomCA       string   `yaml:"ca,omitempty"`
 | 
					 | 
				
			||||||
	CustomCAString string   `yaml:"ca-str,omitempty"`
 | 
					 | 
				
			||||||
	CWND           int      `yaml:"cwnd,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func ProxyToHysteria2(p Proxy) Hysteria2 {
 | 
					 | 
				
			||||||
	return Hysteria2{
 | 
					 | 
				
			||||||
		Type:           "hysteria2",
 | 
					 | 
				
			||||||
		Name:           p.Name,
 | 
					 | 
				
			||||||
		Server:         p.Server,
 | 
					 | 
				
			||||||
		Port:           p.Port,
 | 
					 | 
				
			||||||
		Up:             p.Up,
 | 
					 | 
				
			||||||
		Down:           p.Down,
 | 
					 | 
				
			||||||
		Password:       p.Password,
 | 
					 | 
				
			||||||
		Obfs:           p.Obfs,
 | 
					 | 
				
			||||||
		ObfsPassword:   p.ObfsParam,
 | 
					 | 
				
			||||||
		SNI:            p.Sni,
 | 
					 | 
				
			||||||
		SkipCertVerify: p.SkipCertVerify,
 | 
					 | 
				
			||||||
		Fingerprint:    p.Fingerprint,
 | 
					 | 
				
			||||||
		ALPN:           p.Alpn,
 | 
					 | 
				
			||||||
		CustomCA:       p.CustomCA,
 | 
					 | 
				
			||||||
		CustomCAString: p.CustomCAString,
 | 
					 | 
				
			||||||
		CWND:           p.CWND,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,33 +0,0 @@
 | 
				
			|||||||
package model
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type ShadowSocks struct {
 | 
					 | 
				
			||||||
	Type              string         `yaml:"type"`
 | 
					 | 
				
			||||||
	Name              string         `yaml:"name"`
 | 
					 | 
				
			||||||
	Server            string         `yaml:"server"`
 | 
					 | 
				
			||||||
	Port              int            `yaml:"port"`
 | 
					 | 
				
			||||||
	Password          string         `yaml:"password"`
 | 
					 | 
				
			||||||
	Cipher            string         `yaml:"cipher"`
 | 
					 | 
				
			||||||
	UDP               bool           `yaml:"udp,omitempty"`
 | 
					 | 
				
			||||||
	Plugin            string         `yaml:"plugin,omitempty"`
 | 
					 | 
				
			||||||
	PluginOpts        map[string]any `yaml:"plugin-opts,omitempty"`
 | 
					 | 
				
			||||||
	UDPOverTCP        bool           `yaml:"udp-over-tcp,omitempty"`
 | 
					 | 
				
			||||||
	UDPOverTCPVersion int            `yaml:"udp-over-tcp-version,omitempty"`
 | 
					 | 
				
			||||||
	ClientFingerprint string         `yaml:"client-fingerprint,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func ProxyToShadowSocks(p Proxy) ShadowSocks {
 | 
					 | 
				
			||||||
	return ShadowSocks{
 | 
					 | 
				
			||||||
		Type:              "ss",
 | 
					 | 
				
			||||||
		Name:              p.Name,
 | 
					 | 
				
			||||||
		Server:            p.Server,
 | 
					 | 
				
			||||||
		Port:              p.Port,
 | 
					 | 
				
			||||||
		Password:          p.Password,
 | 
					 | 
				
			||||||
		Cipher:            p.Cipher,
 | 
					 | 
				
			||||||
		UDP:               p.UDP,
 | 
					 | 
				
			||||||
		Plugin:            p.Plugin,
 | 
					 | 
				
			||||||
		PluginOpts:        p.PluginOpts,
 | 
					 | 
				
			||||||
		UDPOverTCP:        p.UDPOverTCP,
 | 
					 | 
				
			||||||
		UDPOverTCPVersion: p.UDPOverTCPVersion,
 | 
					 | 
				
			||||||
		ClientFingerprint: p.ClientFingerprint,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,31 +0,0 @@
 | 
				
			|||||||
package model
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type ShadowSocksR struct {
 | 
					 | 
				
			||||||
	Type          string `yaml:"type"`
 | 
					 | 
				
			||||||
	Name          string `yaml:"name"`
 | 
					 | 
				
			||||||
	Server        string `yaml:"server"`
 | 
					 | 
				
			||||||
	Port          int    `yaml:"port"`
 | 
					 | 
				
			||||||
	Password      string `yaml:"password"`
 | 
					 | 
				
			||||||
	Cipher        string `yaml:"cipher"`
 | 
					 | 
				
			||||||
	Obfs          string `yaml:"obfs"`
 | 
					 | 
				
			||||||
	ObfsParam     string `yaml:"obfs-param,omitempty"`
 | 
					 | 
				
			||||||
	Protocol      string `yaml:"protocol"`
 | 
					 | 
				
			||||||
	ProtocolParam string `yaml:"protocol-param,omitempty"`
 | 
					 | 
				
			||||||
	UDP           bool   `yaml:"udp,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func ProxyToShadowSocksR(p Proxy) ShadowSocksR {
 | 
					 | 
				
			||||||
	return ShadowSocksR{
 | 
					 | 
				
			||||||
		Type:          "ssr",
 | 
					 | 
				
			||||||
		Name:          p.Name,
 | 
					 | 
				
			||||||
		Server:        p.Server,
 | 
					 | 
				
			||||||
		Port:          p.Port,
 | 
					 | 
				
			||||||
		Password:      p.Password,
 | 
					 | 
				
			||||||
		Cipher:        p.Cipher,
 | 
					 | 
				
			||||||
		Obfs:          p.Obfs,
 | 
					 | 
				
			||||||
		ObfsParam:     p.ObfsParam,
 | 
					 | 
				
			||||||
		Protocol:      p.Protocol,
 | 
					 | 
				
			||||||
		ProtocolParam: p.ProtocolParam,
 | 
					 | 
				
			||||||
		UDP:           p.UDP,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,104 +0,0 @@
 | 
				
			|||||||
package model
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type HTTPOptions struct {
 | 
					 | 
				
			||||||
	Method  string              `yaml:"method,omitempty"`
 | 
					 | 
				
			||||||
	Path    []string            `yaml:"path,omitempty"`
 | 
					 | 
				
			||||||
	Headers map[string][]string `yaml:"headers,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type HTTP2Options struct {
 | 
					 | 
				
			||||||
	Host []string `yaml:"host,omitempty"`
 | 
					 | 
				
			||||||
	Path string   `yaml:"path,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type GrpcOptions struct {
 | 
					 | 
				
			||||||
	GrpcServiceName string `yaml:"grpc-service-name,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type RealityOptions struct {
 | 
					 | 
				
			||||||
	PublicKey string `yaml:"public-key"`
 | 
					 | 
				
			||||||
	ShortID   string `yaml:"short-id,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type WSOptions struct {
 | 
					 | 
				
			||||||
	Path                string            `yaml:"path,omitempty"`
 | 
					 | 
				
			||||||
	Headers             map[string]string `yaml:"headers,omitempty"`
 | 
					 | 
				
			||||||
	MaxEarlyData        int               `yaml:"max-early-data,omitempty"`
 | 
					 | 
				
			||||||
	EarlyDataHeaderName string            `yaml:"early-data-header-name,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type VmessJson struct {
 | 
					 | 
				
			||||||
	V    string      `json:"v"`
 | 
					 | 
				
			||||||
	Ps   string      `json:"ps"`
 | 
					 | 
				
			||||||
	Add  string      `json:"add"`
 | 
					 | 
				
			||||||
	Port interface{} `json:"port"`
 | 
					 | 
				
			||||||
	Id   string      `json:"id"`
 | 
					 | 
				
			||||||
	Aid  interface{} `json:"aid"`
 | 
					 | 
				
			||||||
	Scy  string      `json:"scy"`
 | 
					 | 
				
			||||||
	Net  string      `json:"net"`
 | 
					 | 
				
			||||||
	Type string      `json:"type"`
 | 
					 | 
				
			||||||
	Host string      `json:"host"`
 | 
					 | 
				
			||||||
	Path string      `json:"path"`
 | 
					 | 
				
			||||||
	Tls  string      `json:"tls"`
 | 
					 | 
				
			||||||
	Sni  string      `json:"sni"`
 | 
					 | 
				
			||||||
	Alpn string      `json:"alpn"`
 | 
					 | 
				
			||||||
	Fp   string      `json:"fp"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Vmess struct {
 | 
					 | 
				
			||||||
	Type                string         `yaml:"type"`
 | 
					 | 
				
			||||||
	Name                string         `yaml:"name"`
 | 
					 | 
				
			||||||
	Server              string         `yaml:"server"`
 | 
					 | 
				
			||||||
	Port                int            `yaml:"port"`
 | 
					 | 
				
			||||||
	UUID                string         `yaml:"uuid"`
 | 
					 | 
				
			||||||
	AlterID             int            `yaml:"alterId"`
 | 
					 | 
				
			||||||
	Cipher              string         `yaml:"cipher"`
 | 
					 | 
				
			||||||
	UDP                 bool           `yaml:"udp,omitempty"`
 | 
					 | 
				
			||||||
	Network             string         `yaml:"network,omitempty"`
 | 
					 | 
				
			||||||
	TLS                 bool           `yaml:"tls,omitempty"`
 | 
					 | 
				
			||||||
	ALPN                []string       `yaml:"alpn,omitempty"`
 | 
					 | 
				
			||||||
	SkipCertVerify      bool           `yaml:"skip-cert-verify,omitempty"`
 | 
					 | 
				
			||||||
	Fingerprint         string         `yaml:"fingerprint,omitempty"`
 | 
					 | 
				
			||||||
	ServerName          string         `yaml:"servername,omitempty"`
 | 
					 | 
				
			||||||
	RealityOpts         RealityOptions `yaml:"reality-opts,omitempty"`
 | 
					 | 
				
			||||||
	HTTPOpts            HTTPOptions    `yaml:"http-opts,omitempty"`
 | 
					 | 
				
			||||||
	HTTP2Opts           HTTP2Options   `yaml:"h2-opts,omitempty"`
 | 
					 | 
				
			||||||
	GrpcOpts            GrpcOptions    `yaml:"grpc-opts,omitempty"`
 | 
					 | 
				
			||||||
	WSOpts              WSOptions      `yaml:"ws-opts,omitempty"`
 | 
					 | 
				
			||||||
	PacketAddr          bool           `yaml:"packet-addr,omitempty"`
 | 
					 | 
				
			||||||
	XUDP                bool           `yaml:"xudp,omitempty"`
 | 
					 | 
				
			||||||
	PacketEncoding      string         `yaml:"packet-encoding,omitempty"`
 | 
					 | 
				
			||||||
	GlobalPadding       bool           `yaml:"global-padding,omitempty"`
 | 
					 | 
				
			||||||
	AuthenticatedLength bool           `yaml:"authenticated-length,omitempty"`
 | 
					 | 
				
			||||||
	ClientFingerprint   string         `yaml:"client-fingerprint,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func ProxyToVmess(p Proxy) Vmess {
 | 
					 | 
				
			||||||
	return Vmess{
 | 
					 | 
				
			||||||
		Type:                "vmess",
 | 
					 | 
				
			||||||
		Name:                p.Name,
 | 
					 | 
				
			||||||
		Server:              p.Server,
 | 
					 | 
				
			||||||
		Port:                p.Port,
 | 
					 | 
				
			||||||
		UUID:                p.UUID,
 | 
					 | 
				
			||||||
		AlterID:             p.AlterID,
 | 
					 | 
				
			||||||
		Cipher:              p.Cipher,
 | 
					 | 
				
			||||||
		UDP:                 p.UDP,
 | 
					 | 
				
			||||||
		Network:             p.Network,
 | 
					 | 
				
			||||||
		TLS:                 p.TLS,
 | 
					 | 
				
			||||||
		ALPN:                p.Alpn,
 | 
					 | 
				
			||||||
		SkipCertVerify:      p.SkipCertVerify,
 | 
					 | 
				
			||||||
		Fingerprint:         p.Fingerprint,
 | 
					 | 
				
			||||||
		ServerName:          p.Servername,
 | 
					 | 
				
			||||||
		RealityOpts:         p.RealityOpts,
 | 
					 | 
				
			||||||
		HTTPOpts:            p.HTTPOpts,
 | 
					 | 
				
			||||||
		HTTP2Opts:           p.HTTP2Opts,
 | 
					 | 
				
			||||||
		GrpcOpts:            p.GrpcOpts,
 | 
					 | 
				
			||||||
		WSOpts:              p.WSOpts,
 | 
					 | 
				
			||||||
		PacketAddr:          p.PacketAddr,
 | 
					 | 
				
			||||||
		XUDP:                p.XUDP,
 | 
					 | 
				
			||||||
		PacketEncoding:      p.PacketEncoding,
 | 
					 | 
				
			||||||
		GlobalPadding:       p.GlobalPadding,
 | 
					 | 
				
			||||||
		AuthenticatedLength: p.AuthenticatedLength,
 | 
					 | 
				
			||||||
		ClientFingerprint:   p.ClientFingerprint,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -6,6 +6,7 @@ type RuleProvider struct {
 | 
				
			|||||||
	Url      string `yaml:"url,omitempty"`
 | 
						Url      string `yaml:"url,omitempty"`
 | 
				
			||||||
	Path     string `yaml:"path,omitempty"`
 | 
						Path     string `yaml:"path,omitempty"`
 | 
				
			||||||
	Interval int    `yaml:"interval,omitempty"`
 | 
						Interval int    `yaml:"interval,omitempty"`
 | 
				
			||||||
 | 
						Format string    `yaml:"format,omitempty"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Payload struct {
 | 
					type Payload struct {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										211
									
								
								model/sub.go
									
									
									
									
									
								
							
							
						
						
									
										211
									
								
								model/sub.go
									
									
									
									
									
								
							@@ -1,211 +0,0 @@
 | 
				
			|||||||
package model
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type NodeList struct {
 | 
					 | 
				
			||||||
	Proxies []Proxy `yaml:"proxies,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Subscription struct {
 | 
					 | 
				
			||||||
	Port                  int      `yaml:"port,omitempty" json:"port"`
 | 
					 | 
				
			||||||
	SocksPort             int      `yaml:"socks-port,omitempty" json:"socks-port"`
 | 
					 | 
				
			||||||
	RedirPort             int      `yaml:"redir-port,omitempty" json:"redir-port"`
 | 
					 | 
				
			||||||
	TProxyPort            int      `yaml:"tproxy-port,omitempty" json:"tproxy-port"`
 | 
					 | 
				
			||||||
	MixedPort             int      `yaml:"mixed-port,omitempty" json:"mixed-port"`
 | 
					 | 
				
			||||||
	ShadowSocksConfig     string   `yaml:"ss-config,omitempty"`
 | 
					 | 
				
			||||||
	VmessConfig           string   `yaml:"vmess-config,omitempty"`
 | 
					 | 
				
			||||||
	InboundTfo            bool     `yaml:"inbound-tfo,omitempty"`
 | 
					 | 
				
			||||||
	InboundMPTCP          bool     `yaml:"inbound-mptcp,omitempty"`
 | 
					 | 
				
			||||||
	Authentication        []string `yaml:"authentication,omitempty" json:"authentication"`
 | 
					 | 
				
			||||||
	SkipAuthPrefixes      []string `yaml:"skip-auth-prefixes,omitempty"`
 | 
					 | 
				
			||||||
	LanAllowedIPs         []string `yaml:"lan-allowed-ips,omitempty"`
 | 
					 | 
				
			||||||
	LanDisAllowedIPs      []string `yaml:"lan-disallowed-ips,omitempty"`
 | 
					 | 
				
			||||||
	AllowLan              bool     `yaml:"allow-lan,omitempty" json:"allow-lan"`
 | 
					 | 
				
			||||||
	BindAddress           string   `yaml:"bind-address,omitempty" json:"bind-address"`
 | 
					 | 
				
			||||||
	Mode                  string   `yaml:"mode,omitempty" json:"mode"`
 | 
					 | 
				
			||||||
	UnifiedDelay          bool     `yaml:"unified-delay,omitempty" json:"unified-delay"`
 | 
					 | 
				
			||||||
	LogLevel              string   `yaml:"log-level,omitempty" json:"log-level"`
 | 
					 | 
				
			||||||
	IPv6                  bool     `yaml:"ipv6,omitempty" json:"ipv6"`
 | 
					 | 
				
			||||||
	ExternalController    string   `yaml:"external-controller,omitempty"`
 | 
					 | 
				
			||||||
	ExternalControllerTLS string   `yaml:"external-controller-tls,omitempty"`
 | 
					 | 
				
			||||||
	ExternalUI            string   `yaml:"external-ui,omitempty"`
 | 
					 | 
				
			||||||
	ExternalUIURL         string   `yaml:"external-ui-url,omitempty" json:"external-ui-url"`
 | 
					 | 
				
			||||||
	ExternalUIName        string   `yaml:"external-ui-name,omitempty" json:"external-ui-name"`
 | 
					 | 
				
			||||||
	Secret                string   `yaml:"secret,omitempty"`
 | 
					 | 
				
			||||||
	Interface             string   `yaml:"interface-name,omitempty"`
 | 
					 | 
				
			||||||
	RoutingMark           int      `yaml:"routing-mark,omitempty"`
 | 
					 | 
				
			||||||
	//Tunnels                 []LC.Tunnel       `yaml:"tunnels,omitempty"`
 | 
					 | 
				
			||||||
	GeoAutoUpdate           bool   `yaml:"geo-auto-update,omitempty" json:"geo-auto-update"`
 | 
					 | 
				
			||||||
	GeoUpdateInterval       int    `yaml:"geo-update-interval,omitempty" json:"geo-update-interval"`
 | 
					 | 
				
			||||||
	GeodataMode             bool   `yaml:"geodata-mode,omitempty" json:"geodata-mode"`
 | 
					 | 
				
			||||||
	GeodataLoader           string `yaml:"geodata-loader,omitempty" json:"geodata-loader"`
 | 
					 | 
				
			||||||
	GeositeMatcher          string `yaml:"geosite-matcher,omitempty" json:"geosite-matcher"`
 | 
					 | 
				
			||||||
	TCPConcurrent           bool   `yaml:"tcp-concurrent,omitempty" json:"tcp-concurrent"`
 | 
					 | 
				
			||||||
	FindProcessMode         string `yaml:"find-process-mode,omitempty" json:"find-process-mode"`
 | 
					 | 
				
			||||||
	GlobalClientFingerprint string `yaml:"global-client-fingerprint,omitempty"`
 | 
					 | 
				
			||||||
	GlobalUA                string `yaml:"global-ua,omitempty"`
 | 
					 | 
				
			||||||
	KeepAliveInterval       int    `yaml:"keep-alive-interval,omitempty"`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Sniffer       RawSniffer                `yaml:"sniffer,omitempty" json:"sniffer"`
 | 
					 | 
				
			||||||
	ProxyProvider map[string]map[string]any `yaml:"proxy-providers,omitempty"`
 | 
					 | 
				
			||||||
	RuleProviders map[string]RuleProvider   `yaml:"rule-providers,omitempty"`
 | 
					 | 
				
			||||||
	Hosts         map[string]any            `yaml:"hosts,omitempty" json:"hosts"`
 | 
					 | 
				
			||||||
	NTP           RawNTP                    `yaml:"ntp,omitempty" json:"ntp"`
 | 
					 | 
				
			||||||
	DNS           RawDNS                    `yaml:"dns,omitempty" json:"dns"`
 | 
					 | 
				
			||||||
	Tun           RawTun                    `yaml:"tun,omitempty"`
 | 
					 | 
				
			||||||
	TuicServer    RawTuicServer             `yaml:"tuic-server,omitempty"`
 | 
					 | 
				
			||||||
	EBpf          EBpf                      `yaml:"ebpf,omitempty"`
 | 
					 | 
				
			||||||
	IPTables      IPTables                  `yaml:"iptables,omitempty"`
 | 
					 | 
				
			||||||
	Experimental  Experimental              `yaml:"experimental,omitempty"`
 | 
					 | 
				
			||||||
	Profile       Profile                   `yaml:"profile,omitempty"`
 | 
					 | 
				
			||||||
	GeoXUrl       GeoXUrl                   `yaml:"geox-url,omitempty"`
 | 
					 | 
				
			||||||
	Proxies       []Proxy                   `yaml:"proxies,omitempty"`
 | 
					 | 
				
			||||||
	ProxyGroups   []ProxyGroup              `yaml:"proxy-groups,omitempty"`
 | 
					 | 
				
			||||||
	Rules         []string                  `yaml:"rules,omitempty"`
 | 
					 | 
				
			||||||
	SubRules      map[string][]string       `yaml:"sub-rules,omitempty"`
 | 
					 | 
				
			||||||
	RawTLS        TLS                       `yaml:"tls,omitempty"`
 | 
					 | 
				
			||||||
	Listeners     []map[string]any          `yaml:"listeners,omitempty"`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	ClashForAndroid RawClashForAndroid `yaml:"clash-for-android,omitempty" json:"clash-for-android"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type RawClashForAndroid struct {
 | 
					 | 
				
			||||||
	AppendSystemDNS   bool   `yaml:"append-system-dns,omitempty" json:"append-system-dns"`
 | 
					 | 
				
			||||||
	UiSubtitlePattern string `yaml:"ui-subtitle-pattern,omitempty" json:"ui-subtitle-pattern"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type TLS struct {
 | 
					 | 
				
			||||||
	Certificate     string   `yaml:"certificate,omitempty"`
 | 
					 | 
				
			||||||
	PrivateKey      string   `yaml:"private-key,omitempty"`
 | 
					 | 
				
			||||||
	CustomTrustCert []string `yaml:"custom-certifactes,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type GeoXUrl struct {
 | 
					 | 
				
			||||||
	GeoIp   string `yaml:"geoip,omitempty" json:"geoip"`
 | 
					 | 
				
			||||||
	Mmdb    string `yaml:"mmdb,omitempty" json:"mmdb"`
 | 
					 | 
				
			||||||
	GeoSite string `yaml:"geosite,omitempty" json:"geosite"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Experimental struct {
 | 
					 | 
				
			||||||
	Fingerprints     []string `yaml:"fingerprints,omitempty"`
 | 
					 | 
				
			||||||
	QUICGoDisableGSO bool     `yaml:"quic-go-disable-gso,omitempty"`
 | 
					 | 
				
			||||||
	QUICGoDisableECN bool     `yaml:"quic-go-disable-ecn,omitempty"`
 | 
					 | 
				
			||||||
	IP4PEnable       bool     `yaml:"dialer-ip4p-convert,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Profile struct {
 | 
					 | 
				
			||||||
	StoreSelected bool `yaml:"store-selected,omitempty"`
 | 
					 | 
				
			||||||
	StoreFakeIP   bool `yaml:"store-fake-ip,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type IPTables struct {
 | 
					 | 
				
			||||||
	Enable           bool     `yaml:"enable,omitempty" json:"enable"`
 | 
					 | 
				
			||||||
	InboundInterface string   `yaml:"inbound-interface,omitempty" json:"inbound-interface"`
 | 
					 | 
				
			||||||
	Bypass           []string `yaml:"bypass,omitempty" json:"bypass"`
 | 
					 | 
				
			||||||
	DnsRedirect      bool     `yaml:"dns-redirect,omitempty" json:"dns-redirect"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// EBpf config
 | 
					 | 
				
			||||||
type EBpf struct {
 | 
					 | 
				
			||||||
	RedirectToTun []string `yaml:"redirect-to-tun,omitempty" json:"redirect-to-tun"`
 | 
					 | 
				
			||||||
	AutoRedir     []string `yaml:"auto-redir,omitempty" json:"auto-redir"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type RawSniffer struct {
 | 
					 | 
				
			||||||
	Enable          bool                         `yaml:"enable,omitempty" json:"enable"`
 | 
					 | 
				
			||||||
	OverrideDest    bool                         `yaml:"override-destination,omitempty" json:"override-destination"`
 | 
					 | 
				
			||||||
	Sniffing        []string                     `yaml:"sniffing,omitempty" json:"sniffing"`
 | 
					 | 
				
			||||||
	ForceDomain     []string                     `yaml:"force-domain,omitempty" json:"force-domain"`
 | 
					 | 
				
			||||||
	SkipDomain      []string                     `yaml:"skip-domain,omitempty" json:"skip-domain"`
 | 
					 | 
				
			||||||
	Ports           []string                     `yaml:"port-whitelist,omitempty" json:"port-whitelist"`
 | 
					 | 
				
			||||||
	ForceDnsMapping bool                         `yaml:"force-dns-mapping,omitempty" json:"force-dns-mapping"`
 | 
					 | 
				
			||||||
	ParsePureIp     bool                         `yaml:"parse-pure-ip,omitempty" json:"parse-pure-ip"`
 | 
					 | 
				
			||||||
	Sniff           map[string]RawSniffingConfig `yaml:"sniff,omitempty" json:"sniff"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type RawSniffingConfig struct {
 | 
					 | 
				
			||||||
	Ports        []string `yaml:"ports,omitempty" json:"ports"`
 | 
					 | 
				
			||||||
	OverrideDest *bool    `yaml:"override-destination,omitempty" json:"override-destination"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type RawNTP struct {
 | 
					 | 
				
			||||||
	Enable        bool   `yaml:"enable,omitempty"`
 | 
					 | 
				
			||||||
	Server        string `yaml:"server,omitempty"`
 | 
					 | 
				
			||||||
	ServerPort    int    `yaml:"server-port,omitempty"`
 | 
					 | 
				
			||||||
	Interval      int    `yaml:"interval,omitempty"`
 | 
					 | 
				
			||||||
	DialerProxy   string `yaml:"dialer-proxy,omitempty"`
 | 
					 | 
				
			||||||
	WriteToSystem bool   `yaml:"write-to-system,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type RawDNS struct {
 | 
					 | 
				
			||||||
	Enable            bool              `yaml:"enable,omitempty" json:"enable"`
 | 
					 | 
				
			||||||
	PreferH3          bool              `yaml:"prefer-h3,omitempty" json:"prefer-h3"`
 | 
					 | 
				
			||||||
	IPv6              bool              `yaml:"ipv6,omitempty" json:"ipv6"`
 | 
					 | 
				
			||||||
	IPv6Timeout       uint              `yaml:"ipv6-timeout,omitempty" json:"ipv6-timeout"`
 | 
					 | 
				
			||||||
	UseHosts          bool              `yaml:"use-hosts,omitempty" json:"use-hosts"`
 | 
					 | 
				
			||||||
	NameServer        []string          `yaml:"nameserver,omitempty" json:"nameserver"`
 | 
					 | 
				
			||||||
	Fallback          []string          `yaml:"fallback,omitempty" json:"fallback"`
 | 
					 | 
				
			||||||
	FallbackFilter    RawFallbackFilter `yaml:"fallback-filter,omitempty" json:"fallback-filter"`
 | 
					 | 
				
			||||||
	Listen            string            `yaml:"listen,omitempty" json:"listen"`
 | 
					 | 
				
			||||||
	EnhancedMode      string            `yaml:"enhanced-mode,omitempty" json:"enhanced-mode"`
 | 
					 | 
				
			||||||
	FakeIPRange       string            `yaml:"fake-ip-range,omitempty" json:"fake-ip-range"`
 | 
					 | 
				
			||||||
	FakeIPFilter      []string          `yaml:"fake-ip-filter,omitempty" json:"fake-ip-filter"`
 | 
					 | 
				
			||||||
	DefaultNameserver []string          `yaml:"default-nameserver,omitempty" json:"default-nameserver"`
 | 
					 | 
				
			||||||
	CacheAlgorithm    string            `yaml:"cache-algorithm,omitempty" json:"cache-algorithm"`
 | 
					 | 
				
			||||||
	//NameServerPolicy      *orderedmap.OrderedMap[string, any] `yaml:"nameserver-policy,omitempty" json:"nameserver-policy"`
 | 
					 | 
				
			||||||
	ProxyServerNameserver []string `yaml:"proxy-server-nameserver,omitempty" json:"proxy-server-nameserver"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type RawFallbackFilter struct {
 | 
					 | 
				
			||||||
	GeoIP     bool     `yaml:"geoip,omitempty" json:"geoip"`
 | 
					 | 
				
			||||||
	GeoIPCode string   `yaml:"geoip-code,omitempty" json:"geoip-code"`
 | 
					 | 
				
			||||||
	IPCIDR    []string `yaml:"ipcidr,omitempty" json:"ipcidr"`
 | 
					 | 
				
			||||||
	Domain    []string `yaml:"domain,omitempty" json:"domain"`
 | 
					 | 
				
			||||||
	GeoSite   []string `yaml:"geosite,omitempty" json:"geosite"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type RawTun struct {
 | 
					 | 
				
			||||||
	Enable              bool     `yaml:"enable,omitempty" json:"enable"`
 | 
					 | 
				
			||||||
	Device              string   `yaml:"device,omitempty" json:"device"`
 | 
					 | 
				
			||||||
	Stack               string   `yaml:"stack,omitempty" json:"stack"`
 | 
					 | 
				
			||||||
	DNSHijack           []string `yaml:"dns-hijack,omitempty" json:"dns-hijack"`
 | 
					 | 
				
			||||||
	AutoRoute           bool     `yaml:"auto-route,omitempty" json:"auto-route"`
 | 
					 | 
				
			||||||
	AutoDetectInterface bool     `yaml:"auto-detect-interface,omitempty"`
 | 
					 | 
				
			||||||
	RedirectToTun       []string `yaml:"-,omitempty" json:"-"`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	MTU        uint32 `yaml:"mtu,omitempty" json:"mtu,omitempty"`
 | 
					 | 
				
			||||||
	GSO        bool   `yaml:"gso,omitempty" json:"gso,omitempty"`
 | 
					 | 
				
			||||||
	GSOMaxSize uint32 `yaml:"gso-max-size,omitempty" json:"gso-max-size,omitempty"`
 | 
					 | 
				
			||||||
	//Inet4Address           []netip.Prefix `yaml:"inet4-address,omitempty" json:"inet4_address,omitempty"`
 | 
					 | 
				
			||||||
	Inet6Address             []uint32 `yaml:"inet6-address,omitempty" json:"inet6_address,omitempty"`
 | 
					 | 
				
			||||||
	StrictRoute              bool     `yaml:"strict-route,omitempty" json:"strict_route,omitempty"`
 | 
					 | 
				
			||||||
	Inet4RouteAddress        []uint32 `yaml:"inet4-route-address,omitempty" json:"inet4_route_address,omitempty"`
 | 
					 | 
				
			||||||
	Inet6RouteAddress        []uint32 `yaml:"inet6-route-address,omitempty" json:"inet6_route_address,omitempty"`
 | 
					 | 
				
			||||||
	Inet4RouteExcludeAddress []uint32 `yaml:"inet4-route-exclude-address,omitempty" json:"inet4_route_exclude_address,omitempty"`
 | 
					 | 
				
			||||||
	Inet6RouteExcludeAddress []uint32 `yaml:"inet6-route-exclude-address,omitempty" json:"inet6_route_exclude_address,omitempty"`
 | 
					 | 
				
			||||||
	IncludeInterface         []string `yaml:"include-interface,omitempty" json:"include-interface,omitempty"`
 | 
					 | 
				
			||||||
	ExcludeInterface         []string `yaml:"exclude-interface,omitempty" json:"exclude-interface,omitempty"`
 | 
					 | 
				
			||||||
	IncludeUID               []uint32 `yaml:"include-uid,omitempty" json:"include_uid,omitempty"`
 | 
					 | 
				
			||||||
	IncludeUIDRange          []string `yaml:"include-uid-range,omitempty" json:"include_uid_range,omitempty"`
 | 
					 | 
				
			||||||
	ExcludeUID               []uint32 `yaml:"exclude-uid,omitempty" json:"exclude_uid,omitempty"`
 | 
					 | 
				
			||||||
	ExcludeUIDRange          []string `yaml:"exclude-uid-range,omitempty" json:"exclude_uid_range,omitempty"`
 | 
					 | 
				
			||||||
	IncludeAndroidUser       []int    `yaml:"include-android-user,omitempty" json:"include_android_user,omitempty"`
 | 
					 | 
				
			||||||
	IncludePackage           []string `yaml:"include-package,omitempty" json:"include_package,omitempty"`
 | 
					 | 
				
			||||||
	ExcludePackage           []string `yaml:"exclude-package,omitempty" json:"exclude_package,omitempty"`
 | 
					 | 
				
			||||||
	EndpointIndependentNat   bool     `yaml:"endpoint-independent-nat,omitempty" json:"endpoint_independent_nat,omitempty"`
 | 
					 | 
				
			||||||
	UDPTimeout               int64    `yaml:"udp-timeout,omitempty" json:"udp_timeout,omitempty"`
 | 
					 | 
				
			||||||
	FileDescriptor           int      `yaml:"file-descriptor,omitempty" json:"file-descriptor"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type RawTuicServer struct {
 | 
					 | 
				
			||||||
	Enable                bool              `yaml:"enable,omitempty" json:"enable"`
 | 
					 | 
				
			||||||
	Listen                string            `yaml:"listen,omitempty" json:"listen"`
 | 
					 | 
				
			||||||
	Token                 []string          `yaml:"token,omitempty" json:"token"`
 | 
					 | 
				
			||||||
	Users                 map[string]string `yaml:"users,omitempty" json:"users,omitempty"`
 | 
					 | 
				
			||||||
	Certificate           string            `yaml:"certificate,omitempty" json:"certificate"`
 | 
					 | 
				
			||||||
	PrivateKey            string            `yaml:"private-key,omitempty" json:"private-key"`
 | 
					 | 
				
			||||||
	CongestionController  string            `yaml:"congestion-controller,omitempty" json:"congestion-controller,omitempty"`
 | 
					 | 
				
			||||||
	MaxIdleTime           int               `yaml:"max-idle-time,omitempty" json:"max-idle-time,omitempty"`
 | 
					 | 
				
			||||||
	AuthenticationTimeout int               `yaml:"authentication-timeout,omitempty" json:"authentication-timeout,omitempty"`
 | 
					 | 
				
			||||||
	ALPN                  []string          `yaml:"alpn,omitempty" json:"alpn,omitempty"`
 | 
					 | 
				
			||||||
	MaxUdpRelayPacketSize int               `yaml:"max-udp-relay-packet-size,omitempty" json:"max-udp-relay-packet-size,omitempty"`
 | 
					 | 
				
			||||||
	CWND                  int               `yaml:"cwnd,omitempty" json:"cwnd,omitempty"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										83
									
								
								model/subscription.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								model/subscription.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,83 @@
 | 
				
			|||||||
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"net/netip"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						C "github.com/metacubex/mihomo/config"
 | 
				
			||||||
 | 
						LC "github.com/metacubex/mihomo/listener/config"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type NodeList struct {
 | 
				
			||||||
 | 
						Proxy []proxy.Proxy `yaml:"proxies,omitempty" json:"proxies"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/config/config.go RawConfig
 | 
				
			||||||
 | 
					type Subscription struct {
 | 
				
			||||||
 | 
						Port                    proxy.IntOrString `yaml:"port,omitempty" json:"port"`
 | 
				
			||||||
 | 
						SocksPort               proxy.IntOrString `yaml:"socks-port,omitempty" json:"socks-port"`
 | 
				
			||||||
 | 
						RedirPort               proxy.IntOrString `yaml:"redir-port,omitempty" json:"redir-port"`
 | 
				
			||||||
 | 
						TProxyPort              proxy.IntOrString `yaml:"tproxy-port,omitempty" json:"tproxy-port"`
 | 
				
			||||||
 | 
						MixedPort               proxy.IntOrString `yaml:"mixed-port,omitempty" json:"mixed-port"`
 | 
				
			||||||
 | 
						ShadowSocksConfig       string            `yaml:"ss-config,omitempty" json:"ss-config"`
 | 
				
			||||||
 | 
						VmessConfig             string            `yaml:"vmess-config,omitempty" json:"vmess-config"`
 | 
				
			||||||
 | 
						InboundTfo              bool              `yaml:"inbound-tfo,omitempty" json:"inbound-tfo"`
 | 
				
			||||||
 | 
						InboundMPTCP            bool              `yaml:"inbound-mptcp,omitempty" json:"inbound-mptcp"`
 | 
				
			||||||
 | 
						Authentication          []string          `yaml:"authentication,omitempty" json:"authentication"`
 | 
				
			||||||
 | 
						SkipAuthPrefixes        []netip.Prefix    `yaml:"skip-auth-prefixes,omitempty" json:"skip-auth-prefixes"`
 | 
				
			||||||
 | 
						LanAllowedIPs           []netip.Prefix    `yaml:"lan-allowed-ips,omitempty" json:"lan-allowed-ips"`
 | 
				
			||||||
 | 
						LanDisAllowedIPs        []netip.Prefix    `yaml:"lan-disallowed-ips,omitempty" json:"lan-disallowed-ips"`
 | 
				
			||||||
 | 
						AllowLan                bool              `yaml:"allow-lan,omitempty" json:"allow-lan"`
 | 
				
			||||||
 | 
						BindAddress             string            `yaml:"bind-address,omitempty" json:"bind-address"`
 | 
				
			||||||
 | 
						Mode                    string            `yaml:"mode,omitempty" json:"mode"`
 | 
				
			||||||
 | 
						UnifiedDelay            bool              `yaml:"unified-delay,omitempty" json:"unified-delay"`
 | 
				
			||||||
 | 
						LogLevel                string            `yaml:"log-level,omitempty" json:"log-level"`
 | 
				
			||||||
 | 
						IPv6                    bool              `yaml:"ipv6,omitempty" json:"ipv6"`
 | 
				
			||||||
 | 
						ExternalController      string            `yaml:"external-controller,omitempty" json:"external-controller"`
 | 
				
			||||||
 | 
						ExternalControllerPipe  string            `yaml:"external-controller-pipe,omitempty" json:"external-controller-pipe"`
 | 
				
			||||||
 | 
						ExternalControllerUnix  string            `yaml:"external-controller-unix,omitempty" json:"external-controller-unix"`
 | 
				
			||||||
 | 
						ExternalControllerTLS   string            `yaml:"external-controller-tls,omitempty" json:"external-controller-tls"`
 | 
				
			||||||
 | 
						ExternalControllerCors  C.RawCors         `yaml:"external-controller-cors,omitempty" json:"external-controller-cors"`
 | 
				
			||||||
 | 
						ExternalUI              string            `yaml:"external-ui,omitempty" json:"external-ui"`
 | 
				
			||||||
 | 
						ExternalUIURL           string            `yaml:"external-ui-url,omitempty" json:"external-ui-url"`
 | 
				
			||||||
 | 
						ExternalUIName          string            `yaml:"external-ui-name,omitempty" json:"external-ui-name"`
 | 
				
			||||||
 | 
						ExternalDohServer       string            `yaml:"external-doh-server,omitempty" json:"external-doh-server"`
 | 
				
			||||||
 | 
						Secret                  string            `yaml:"secret,omitempty" json:"secret"`
 | 
				
			||||||
 | 
						Interface               string            `yaml:"interface-name,omitempty" json:"interface-name"`
 | 
				
			||||||
 | 
						RoutingMark             int               `yaml:"routing-mark,omitempty" json:"routing-mark"`
 | 
				
			||||||
 | 
						Tunnels                 []LC.Tunnel       `yaml:"tunnels,omitempty" json:"tunnels"`
 | 
				
			||||||
 | 
						GeoAutoUpdate           bool              `yaml:"geo-auto-update,omitempty" json:"geo-auto-update"`
 | 
				
			||||||
 | 
						GeoUpdateInterval       int               `yaml:"geo-update-interval,omitempty" json:"geo-update-interval"`
 | 
				
			||||||
 | 
						GeodataMode             bool              `yaml:"geodata-mode,omitempty" json:"geodata-mode"`
 | 
				
			||||||
 | 
						GeodataLoader           string            `yaml:"geodata-loader,omitempty" json:"geodata-loader"`
 | 
				
			||||||
 | 
						GeositeMatcher          string            `yaml:"geosite-matcher,omitempty" json:"geosite-matcher"`
 | 
				
			||||||
 | 
						TCPConcurrent           bool              `yaml:"tcp-concurrent,omitempty" json:"tcp-concurrent"`
 | 
				
			||||||
 | 
						FindProcessMode         string            `yaml:"find-process-mode,omitempty" json:"find-process-mode"`
 | 
				
			||||||
 | 
						GlobalClientFingerprint string            `yaml:"global-client-fingerprint,omitempty" json:"global-client-fingerprint"`
 | 
				
			||||||
 | 
						GlobalUA                string            `yaml:"global-ua,omitempty" json:"global-ua"`
 | 
				
			||||||
 | 
						ETagSupport             bool              `yaml:"etag-support,omitempty" json:"etag-support"`
 | 
				
			||||||
 | 
						KeepAliveIdle           int               `yaml:"keep-alive-idle,omitempty" json:"keep-alive-idle"`
 | 
				
			||||||
 | 
						KeepAliveInterval       int               `yaml:"keep-alive-interval,omitempty" json:"keep-alive-interval"`
 | 
				
			||||||
 | 
						DisableKeepAlive        bool              `yaml:"disable-keep-alive,omitempty" json:"disable-keep-alive"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ProxyProvider map[string]map[string]any `yaml:"proxy-providers,omitempty" json:"proxy-providers"`
 | 
				
			||||||
 | 
						RuleProvider  map[string]RuleProvider   `yaml:"rule-providers,omitempty" json:"rule-providers"`
 | 
				
			||||||
 | 
						Proxy         []proxy.Proxy             `yaml:"proxies,omitempty" json:"proxies"`
 | 
				
			||||||
 | 
						ProxyGroup    []ProxyGroup              `yaml:"proxy-groups,omitempty" json:"proxy-groups"`
 | 
				
			||||||
 | 
						Rule          []string                  `yaml:"rules,omitempty" json:"rule"`
 | 
				
			||||||
 | 
						SubRules      map[string][]string       `yaml:"sub-rules,omitempty" json:"sub-rules"`
 | 
				
			||||||
 | 
						Listeners     []map[string]any          `yaml:"listeners,omitempty" json:"listeners"`
 | 
				
			||||||
 | 
						Hosts         map[string]any            `yaml:"hosts,omitempty" json:"hosts"`
 | 
				
			||||||
 | 
						DNS           C.RawDNS                  `yaml:"dns,omitempty" json:"dns"`
 | 
				
			||||||
 | 
						NTP           C.RawNTP                  `yaml:"ntp,omitempty" json:"ntp"`
 | 
				
			||||||
 | 
						Tun           C.RawTun                  `yaml:"tun,omitempty" json:"tun"`
 | 
				
			||||||
 | 
						TuicServer    C.RawTuicServer           `yaml:"tuic-server,omitempty" json:"tuic-server"`
 | 
				
			||||||
 | 
						IPTables      C.RawIPTables             `yaml:"iptables,omitempty" json:"iptables"`
 | 
				
			||||||
 | 
						Experimental  C.RawExperimental         `yaml:"experimental,omitempty" json:"experimental"`
 | 
				
			||||||
 | 
						Profile       C.RawProfile              `yaml:"profile,omitempty" json:"profile"`
 | 
				
			||||||
 | 
						GeoXUrl       C.RawGeoXUrl              `yaml:"geox-url,omitempty" json:"geox-url"`
 | 
				
			||||||
 | 
						Sniffer       C.RawSniffer              `yaml:"sniffer,omitempty" json:"sniffer"`
 | 
				
			||||||
 | 
						TLS           C.RawTLS                  `yaml:"tls,omitempty" json:"tls"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ClashForAndroid C.RawClashForAndroid `yaml:"clash-for-android,omitempty" json:"clash-for-android"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										83
									
								
								parser/anytls.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								parser/anytls.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,83 @@
 | 
				
			|||||||
 | 
					package parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type AnytlsParser struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *AnytlsParser) SupportClash() bool {
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *AnytlsParser) SupportMeta() bool {
 | 
				
			||||||
 | 
						return true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *AnytlsParser) GetPrefixes() []string {
 | 
				
			||||||
 | 
						return []string{"anytls://"}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *AnytlsParser) GetType() string {
 | 
				
			||||||
 | 
						return "anytls"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *AnytlsParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
 | 
				
			||||||
 | 
						if !hasPrefix(proxy, p.GetPrefixes()) {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPrefix, proxy)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						link, err := url.Parse(proxy)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						username := link.User.Username()
 | 
				
			||||||
 | 
						password, exist := link.User.Password()
 | 
				
			||||||
 | 
						if !exist {
 | 
				
			||||||
 | 
							password = username
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						query := link.Query()
 | 
				
			||||||
 | 
						server := link.Hostname()
 | 
				
			||||||
 | 
						if server == "" {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, "missing server host")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						portStr := link.Port()
 | 
				
			||||||
 | 
						if portStr == "" {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, "missing server port")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						port, err := ParsePort(portStr)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPort, err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						insecure, sni := query.Get("insecure"), query.Get("sni")
 | 
				
			||||||
 | 
						insecureBool := insecure == "1"
 | 
				
			||||||
 | 
						remarks := link.Fragment
 | 
				
			||||||
 | 
						if remarks == "" {
 | 
				
			||||||
 | 
							remarks = fmt.Sprintf("%s:%s", server, portStr)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						remarks = strings.TrimSpace(remarks)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result := P.Proxy{
 | 
				
			||||||
 | 
							Type: p.GetType(),
 | 
				
			||||||
 | 
							Name: remarks,
 | 
				
			||||||
 | 
							Anytls: P.Anytls{
 | 
				
			||||||
 | 
								Server:         server,
 | 
				
			||||||
 | 
								Port:           P.IntOrString(port),
 | 
				
			||||||
 | 
								Password:       password,
 | 
				
			||||||
 | 
								SNI:            sni,
 | 
				
			||||||
 | 
								SkipCertVerify: insecureBool,
 | 
				
			||||||
 | 
								UDP:            config.UseUDP,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return result, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func init() {
 | 
				
			||||||
 | 
						RegisterParser(&AnytlsParser{})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,23 +0,0 @@
 | 
				
			|||||||
package parser
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"encoding/base64"
 | 
					 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func DecodeBase64(s string) (string, error) {
 | 
					 | 
				
			||||||
	s = strings.TrimSpace(s)
 | 
					 | 
				
			||||||
	// url safe
 | 
					 | 
				
			||||||
	if strings.Contains(s, "-") || strings.Contains(s, "_") {
 | 
					 | 
				
			||||||
		s = strings.Replace(s, "-", "+", -1)
 | 
					 | 
				
			||||||
		s = strings.Replace(s, "_", "/", -1)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(s)%4 != 0 {
 | 
					 | 
				
			||||||
		s += strings.Repeat("=", 4-len(s)%4)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	decodeStr, err := base64.StdEncoding.DecodeString(s)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return "", err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return string(decodeStr), nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										82
									
								
								parser/common.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								parser/common.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,82 @@
 | 
				
			|||||||
 | 
					package parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"unicode/utf8"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/utils"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func hasPrefix(proxy string, prefixes []string) bool {
 | 
				
			||||||
 | 
						hasPrefix := false
 | 
				
			||||||
 | 
						for _, prefix := range prefixes {
 | 
				
			||||||
 | 
							if strings.HasPrefix(proxy, prefix) {
 | 
				
			||||||
 | 
								hasPrefix = true
 | 
				
			||||||
 | 
								break
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return hasPrefix
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ParsePort(portStr string) (int, error) {
 | 
				
			||||||
 | 
						port, err := strconv.Atoi(portStr)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return 0, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if port < 1 || port > 65535 {
 | 
				
			||||||
 | 
							return 0, errors.New("invaild port range")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return port, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// isLikelyBase64 不严格判断是否是合法的 Base64, 很多分享链接不符合 Base64 规范
 | 
				
			||||||
 | 
					func isLikelyBase64(s string) bool {
 | 
				
			||||||
 | 
						if strings.TrimSpace(s) == "" {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !strings.Contains(strings.TrimSuffix(s, "="), "=") {
 | 
				
			||||||
 | 
							s = strings.TrimSuffix(s, "=")
 | 
				
			||||||
 | 
							chars := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
 | 
				
			||||||
 | 
							for _, c := range s {
 | 
				
			||||||
 | 
								if !strings.ContainsRune(chars, c) {
 | 
				
			||||||
 | 
									return false
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						decoded, err := utils.DecodeBase64(s, true)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !utf8.ValidString(decoded) {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ParseConfig struct {
 | 
				
			||||||
 | 
						UseUDP bool
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ParseProxies(config ParseConfig, proxies ...string) ([]P.Proxy, error) {
 | 
				
			||||||
 | 
						var result []P.Proxy
 | 
				
			||||||
 | 
						for _, proxy := range proxies {
 | 
				
			||||||
 | 
							if proxy != "" {
 | 
				
			||||||
 | 
								var proxyItem P.Proxy
 | 
				
			||||||
 | 
								var err error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								proxyItem, err = ParseProxyWithRegistry(config, proxy)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return nil, err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								result = append(result, proxyItem)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return result, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,11 +1,5 @@
 | 
				
			|||||||
package parser
 | 
					package parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ParseError struct {
 | 
					 | 
				
			||||||
	Type    ParseErrorType
 | 
					 | 
				
			||||||
	Message string
 | 
					 | 
				
			||||||
	Raw     string
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type ParseErrorType string
 | 
					type ParseErrorType string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
@@ -16,9 +10,6 @@ const (
 | 
				
			|||||||
	ErrInvalidBase64     ParseErrorType = "invalid base64"
 | 
						ErrInvalidBase64     ParseErrorType = "invalid base64"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (e *ParseError) Error() string {
 | 
					func (e ParseErrorType) Error() string {
 | 
				
			||||||
	if e.Message != "" {
 | 
						return string(e)
 | 
				
			||||||
		return string(e.Type) + ": " + e.Message + " \"" + e.Raw + "\""
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return string(e.Type)
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,57 +1,59 @@
 | 
				
			|||||||
package parser
 | 
					package parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"net/url"
 | 
						"net/url"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sub2clash/constant"
 | 
					
 | 
				
			||||||
	"sub2clash/model"
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ParseHysteria(proxy string) (model.Proxy, error) {
 | 
					type HysteriaParser struct{}
 | 
				
			||||||
	if !strings.HasPrefix(proxy, constant.HysteriaPrefix) {
 | 
					
 | 
				
			||||||
		return model.Proxy{}, &ParseError{Type: ErrInvalidPrefix, Raw: proxy}
 | 
					func (p *HysteriaParser) SupportClash() bool {
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	proxy = strings.TrimPrefix(proxy, constant.HysteriaPrefix)
 | 
					func (p *HysteriaParser) SupportMeta() bool {
 | 
				
			||||||
	urlParts := strings.SplitN(proxy, "?", 2)
 | 
						return true
 | 
				
			||||||
	if len(urlParts) != 2 {
 | 
					 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrInvalidStruct,
 | 
					 | 
				
			||||||
			Message: "missing character '?' in url",
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	serverInfo := strings.SplitN(urlParts[0], ":", 2)
 | 
					func (p *HysteriaParser) GetPrefixes() []string {
 | 
				
			||||||
	if len(serverInfo) != 2 {
 | 
						return []string{"hysteria://"}
 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrInvalidStruct,
 | 
					 | 
				
			||||||
			Message: "missing server host or port",
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *HysteriaParser) GetType() string {
 | 
				
			||||||
 | 
						return "hysteria"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *HysteriaParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
 | 
				
			||||||
 | 
						if !hasPrefix(proxy, p.GetPrefixes()) {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPrefix, proxy)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						link, err := url.Parse(proxy)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						server := link.Hostname()
 | 
				
			||||||
 | 
						if server == "" {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, "missing server host")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						portStr := link.Port()
 | 
				
			||||||
 | 
						if portStr == "" {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, "missing server port")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	server, portStr := serverInfo[0], serverInfo[1]
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	port, err := ParsePort(portStr)
 | 
						port, err := ParsePort(portStr)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPort, err.Error())
 | 
				
			||||||
			Type:    ErrInvalidPort,
 | 
					 | 
				
			||||||
			Message: err.Error(),
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	params, err := url.ParseQuery(urlParts[1])
 | 
						query := link.Query()
 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrCannotParseParams,
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
			Message: err.Error(),
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	protocol, auth, insecure, upmbps, downmbps, obfs, alpnStr := params.Get("protocol"), params.Get("auth"), params.Get("insecure"), params.Get("upmbps"), params.Get("downmbps"), params.Get("obfs"), params.Get("alpn")
 | 
						protocol, auth, auth_str, insecure, upmbps, downmbps, obfs, alpnStr := query.Get("protocol"), query.Get("auth"), query.Get("auth-str"), query.Get("insecure"), query.Get("upmbps"), query.Get("downmbps"), query.Get("obfs"), query.Get("alpn")
 | 
				
			||||||
	insecureBool, err := strconv.ParseBool(insecure)
 | 
						insecureBool, err := strconv.ParseBool(insecure)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		insecureBool = false
 | 
							insecureBool = false
 | 
				
			||||||
@@ -63,24 +65,31 @@ func ParseHysteria(proxy string) (model.Proxy, error) {
 | 
				
			|||||||
		alpn = strings.Split(alpnStr, ",")
 | 
							alpn = strings.Split(alpnStr, ",")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	remarks := server + ":" + portStr
 | 
						remarks := link.Fragment
 | 
				
			||||||
	if params.Get("remarks") != "" {
 | 
						if remarks == "" {
 | 
				
			||||||
		remarks = params.Get("remarks")
 | 
							remarks = fmt.Sprintf("%s:%s", server, portStr)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						remarks = strings.TrimSpace(remarks)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result := model.Proxy{
 | 
						result := P.Proxy{
 | 
				
			||||||
		Type:           "hysteria",
 | 
							Type: p.GetType(),
 | 
				
			||||||
		Name: remarks,
 | 
							Name: remarks,
 | 
				
			||||||
 | 
							Hysteria: P.Hysteria{
 | 
				
			||||||
			Server:         server,
 | 
								Server:         server,
 | 
				
			||||||
		Port:           port,
 | 
								Port:           P.IntOrString(port),
 | 
				
			||||||
			Up:             upmbps,
 | 
								Up:             upmbps,
 | 
				
			||||||
			Down:           downmbps,
 | 
								Down:           downmbps,
 | 
				
			||||||
			Auth:           auth,
 | 
								Auth:           auth,
 | 
				
			||||||
 | 
								AuthString:     auth_str,
 | 
				
			||||||
			Obfs:           obfs,
 | 
								Obfs:           obfs,
 | 
				
			||||||
		SkipCertVerify: insecure == "1",
 | 
								SkipCertVerify: insecureBool,
 | 
				
			||||||
		Alpn:           alpn,
 | 
								ALPN:           alpn,
 | 
				
			||||||
			Protocol:       protocol,
 | 
								Protocol:       protocol,
 | 
				
			||||||
		AllowInsecure:  insecureBool,
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return result, nil
 | 
						return result, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func init() {
 | 
				
			||||||
 | 
						RegisterParser(&HysteriaParser{})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,89 +1,84 @@
 | 
				
			|||||||
package parser
 | 
					package parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"net/url"
 | 
						"net/url"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sub2clash/constant"
 | 
					
 | 
				
			||||||
	"sub2clash/model"
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ParseHysteria2(proxy string) (model.Proxy, error) {
 | 
					type Hysteria2Parser struct{}
 | 
				
			||||||
	if !strings.HasPrefix(proxy, constant.Hysteria2Prefix1) &&
 | 
					
 | 
				
			||||||
		!strings.HasPrefix(proxy, constant.Hysteria2Prefix2) {
 | 
					func (p *Hysteria2Parser) SupportClash() bool {
 | 
				
			||||||
		return model.Proxy{}, &ParseError{Type: ErrInvalidPrefix, Raw: proxy}
 | 
						return false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	proxy = strings.TrimPrefix(proxy, constant.Hysteria2Prefix1)
 | 
					func (p *Hysteria2Parser) SupportMeta() bool {
 | 
				
			||||||
	proxy = strings.TrimPrefix(proxy, constant.Hysteria2Prefix2)
 | 
						return true
 | 
				
			||||||
	urlParts := strings.SplitN(proxy, "@", 2)
 | 
					 | 
				
			||||||
	if len(urlParts) != 2 {
 | 
					 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrInvalidStruct,
 | 
					 | 
				
			||||||
			Message: "missing character '@' in url",
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	password := urlParts[0]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	serverInfo := strings.SplitN(urlParts[1], "/?", 2)
 | 
					 | 
				
			||||||
	if len(serverInfo) != 2 {
 | 
					 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrInvalidStruct,
 | 
					 | 
				
			||||||
			Message: "missing params in url",
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	paramStr := serverInfo[1]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	serverAndPort := strings.SplitN(serverInfo[0], ":", 2)
 | 
					 | 
				
			||||||
	var server string
 | 
					 | 
				
			||||||
	var portStr string
 | 
					 | 
				
			||||||
	if len(serverAndPort) == 1 {
 | 
					 | 
				
			||||||
		portStr = "443"
 | 
					 | 
				
			||||||
	} else if len(serverAndPort) == 2 {
 | 
					 | 
				
			||||||
		server, portStr = serverAndPort[0], serverAndPort[1]
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrInvalidStruct,
 | 
					 | 
				
			||||||
			Message: "missing server host or port",
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *Hysteria2Parser) GetPrefixes() []string {
 | 
				
			||||||
 | 
						return []string{"hysteria2://", "hy2://"}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *Hysteria2Parser) GetType() string {
 | 
				
			||||||
 | 
						return "hysteria2"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *Hysteria2Parser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
 | 
				
			||||||
 | 
						if !hasPrefix(proxy, p.GetPrefixes()) {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPrefix, proxy)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						link, err := url.Parse(proxy)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						username := link.User.Username()
 | 
				
			||||||
 | 
						password, exist := link.User.Password()
 | 
				
			||||||
 | 
						if !exist {
 | 
				
			||||||
 | 
							password = username
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						query := link.Query()
 | 
				
			||||||
 | 
						server := link.Hostname()
 | 
				
			||||||
 | 
						if server == "" {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, "missing server host")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						portStr := link.Port()
 | 
				
			||||||
 | 
						if portStr == "" {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, "missing server port")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	port, err := ParsePort(portStr)
 | 
						port, err := ParsePort(portStr)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPort, err.Error())
 | 
				
			||||||
			Type:    ErrInvalidPort,
 | 
					 | 
				
			||||||
			Message: err.Error(),
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
						obfs, obfsPassword, insecure, sni := query.Get("obfs"), query.Get("obfs-password"), query.Get("insecure"), query.Get("sni")
 | 
				
			||||||
 | 
					 | 
				
			||||||
	params, err := url.ParseQuery(paramStr)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrCannotParseParams,
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
			Message: err.Error(),
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	remarks, network, obfs, obfsPassword, pinSHA256, insecure, sni := params.Get("name"), params.Get("network"), params.Get("obfs"), params.Get("obfs-password"), params.Get("pinSHA256"), params.Get("insecure"), params.Get("sni")
 | 
					 | 
				
			||||||
	enableTLS := pinSHA256 != ""
 | 
					 | 
				
			||||||
	insecureBool := insecure == "1"
 | 
						insecureBool := insecure == "1"
 | 
				
			||||||
 | 
						remarks := link.Fragment
 | 
				
			||||||
 | 
						if remarks == "" {
 | 
				
			||||||
 | 
							remarks = fmt.Sprintf("%s:%s", server, portStr)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						remarks = strings.TrimSpace(remarks)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result := model.Proxy{
 | 
						result := P.Proxy{
 | 
				
			||||||
		Type:           "hysteria2",
 | 
							Type: p.GetType(),
 | 
				
			||||||
		Name: remarks,
 | 
							Name: remarks,
 | 
				
			||||||
 | 
							Hysteria2: P.Hysteria2{
 | 
				
			||||||
			Server:         server,
 | 
								Server:         server,
 | 
				
			||||||
		Port:           port,
 | 
								Port:           P.IntOrString(port),
 | 
				
			||||||
			Password:       password,
 | 
								Password:       password,
 | 
				
			||||||
			Obfs:           obfs,
 | 
								Obfs:           obfs,
 | 
				
			||||||
		ObfsParam:      obfsPassword,
 | 
								ObfsPassword:   obfsPassword,
 | 
				
			||||||
		Sni:            sni,
 | 
								SNI:            sni,
 | 
				
			||||||
			SkipCertVerify: insecureBool,
 | 
								SkipCertVerify: insecureBool,
 | 
				
			||||||
		TLS:            enableTLS,
 | 
							},
 | 
				
			||||||
		Network:        network,
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return result, nil
 | 
						return result, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func init() {
 | 
				
			||||||
 | 
						RegisterParser(&Hysteria2Parser{})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,18 +0,0 @@
 | 
				
			|||||||
package parser
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"errors"
 | 
					 | 
				
			||||||
	"strconv"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func ParsePort(portStr string) (int, error) {
 | 
					 | 
				
			||||||
	port, err := strconv.Atoi(portStr)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return 0, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if port < 1 || port > 65535 {
 | 
					 | 
				
			||||||
		return 0, errors.New("invaild port range")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return port, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										80
									
								
								parser/registry.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								parser/registry.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,80 @@
 | 
				
			|||||||
 | 
					package parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"sync"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ProxyParser interface {
 | 
				
			||||||
 | 
						Parse(config ParseConfig, proxy string) (P.Proxy, error)
 | 
				
			||||||
 | 
						GetPrefixes() []string
 | 
				
			||||||
 | 
						GetType() string
 | 
				
			||||||
 | 
						SupportClash() bool
 | 
				
			||||||
 | 
						SupportMeta() bool
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type parserRegistry struct {
 | 
				
			||||||
 | 
						mu      sync.RWMutex
 | 
				
			||||||
 | 
						parsers map[string]ProxyParser
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var registry = &parserRegistry{
 | 
				
			||||||
 | 
						parsers: make(map[string]ProxyParser),
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func RegisterParser(parser ProxyParser) {
 | 
				
			||||||
 | 
						registry.mu.Lock()
 | 
				
			||||||
 | 
						defer registry.mu.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, prefix := range parser.GetPrefixes() {
 | 
				
			||||||
 | 
							registry.parsers[prefix] = parser
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetParser(prefix string) (ProxyParser, bool) {
 | 
				
			||||||
 | 
						registry.mu.RLock()
 | 
				
			||||||
 | 
						defer registry.mu.RUnlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						parser, exists := registry.parsers[prefix]
 | 
				
			||||||
 | 
						return parser, exists
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetAllParsers() map[string]ProxyParser {
 | 
				
			||||||
 | 
						registry.mu.RLock()
 | 
				
			||||||
 | 
						defer registry.mu.RUnlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result := make(map[string]ProxyParser)
 | 
				
			||||||
 | 
						for k, v := range registry.parsers {
 | 
				
			||||||
 | 
							result[k] = v
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return result
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetAllPrefixes() []string {
 | 
				
			||||||
 | 
						registry.mu.RLock()
 | 
				
			||||||
 | 
						defer registry.mu.RUnlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						prefixes := make([]string, 0, len(registry.parsers))
 | 
				
			||||||
 | 
						for prefix := range registry.parsers {
 | 
				
			||||||
 | 
							prefixes = append(prefixes, prefix)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return prefixes
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ParseProxyWithRegistry(config ParseConfig, proxy string) (P.Proxy, error) {
 | 
				
			||||||
 | 
						proxy = strings.TrimSpace(proxy)
 | 
				
			||||||
 | 
						if proxy == "" {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, "empty proxy string")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for prefix, parser := range registry.parsers {
 | 
				
			||||||
 | 
							if strings.HasPrefix(proxy, prefix) {
 | 
				
			||||||
 | 
								return parser.Parse(config, proxy)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPrefix, "unsupported protocol")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,91 +1,121 @@
 | 
				
			|||||||
package parser
 | 
					package parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"net/url"
 | 
						"net/url"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sub2clash/constant"
 | 
					
 | 
				
			||||||
	"sub2clash/model"
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/utils"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ParseShadowsocks(proxy string) (model.Proxy, error) {
 | 
					// ShadowsocksParser Shadowsocks协议解析器
 | 
				
			||||||
	if !strings.HasPrefix(proxy, constant.ShadowsocksPrefix) {
 | 
					type ShadowsocksParser struct{}
 | 
				
			||||||
		return model.Proxy{}, &ParseError{Type: ErrInvalidPrefix, Raw: proxy}
 | 
					
 | 
				
			||||||
 | 
					func (p *ShadowsocksParser) SupportClash() bool {
 | 
				
			||||||
 | 
						return true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	proxy = strings.TrimPrefix(proxy, constant.ShadowsocksPrefix)
 | 
					func (p *ShadowsocksParser) SupportMeta() bool {
 | 
				
			||||||
	urlParts := strings.SplitN(proxy, "@", 2)
 | 
						return true
 | 
				
			||||||
	if len(urlParts) != 2 {
 | 
					 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrInvalidStruct,
 | 
					 | 
				
			||||||
			Message: "missing character '@' in url",
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var serverAndPort []string
 | 
					// GetPrefixes 返回支持的协议前缀
 | 
				
			||||||
	if !strings.Contains(urlParts[0], ":") {
 | 
					func (p *ShadowsocksParser) GetPrefixes() []string {
 | 
				
			||||||
		decoded, err := DecodeBase64(urlParts[0])
 | 
						return []string{"ss://"}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetType 返回协议类型
 | 
				
			||||||
 | 
					func (p *ShadowsocksParser) GetType() string {
 | 
				
			||||||
 | 
						return "ss"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Parse 解析Shadowsocks代理
 | 
				
			||||||
 | 
					func (p *ShadowsocksParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
 | 
				
			||||||
 | 
						if !hasPrefix(proxy, p.GetPrefixes()) {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPrefix, proxy)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !strings.Contains(proxy, "@") {
 | 
				
			||||||
 | 
							s := strings.SplitN(proxy, "#", 2)
 | 
				
			||||||
 | 
							for _, prefix := range p.GetPrefixes() {
 | 
				
			||||||
 | 
								if strings.HasPrefix(s[0], prefix) {
 | 
				
			||||||
 | 
									s[0] = strings.TrimPrefix(s[0], prefix)
 | 
				
			||||||
 | 
									break
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							d, err := utils.DecodeBase64(s[0], true)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return model.Proxy{}, &ParseError{
 | 
								return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
				Type:    ErrInvalidStruct,
 | 
							}
 | 
				
			||||||
				Message: "invalid base64 encoded",
 | 
							if len(s) == 2 {
 | 
				
			||||||
				Raw:     proxy,
 | 
								proxy = "ss://" + d + "#" + s[1]
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								proxy = "ss://" + d
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
		urlParts[0] = decoded
 | 
						link, err := url.Parse(proxy)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	credentials := strings.SplitN(urlParts[0], ":", 2)
 | 
					 | 
				
			||||||
	if len(credentials) != 2 {
 | 
					 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrInvalidStruct,
 | 
					 | 
				
			||||||
			Message: "missing server host or port",
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	method, password := credentials[0], credentials[1]
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	serverInfo := strings.SplitN(urlParts[1], "#", 2)
 | 
						server := link.Hostname()
 | 
				
			||||||
	serverAndPort = strings.SplitN(serverInfo[0], ":", 2)
 | 
						if server == "" {
 | 
				
			||||||
	server, portStr := serverAndPort[0], serverAndPort[1]
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, "missing server host")
 | 
				
			||||||
	if len(serverInfo) != 2 {
 | 
					 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrInvalidStruct,
 | 
					 | 
				
			||||||
			Message: "missing server host or port",
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						portStr := link.Port()
 | 
				
			||||||
 | 
						if portStr == "" {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, "missing server port")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	port, err := ParsePort(portStr)
 | 
						port, err := ParsePort(portStr)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
			Type:    ErrInvalidPort,
 | 
					 | 
				
			||||||
			Message: err.Error(),
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var remarks string
 | 
						method := link.User.Username()
 | 
				
			||||||
	if len(serverInfo) == 2 {
 | 
						password, hasPassword := link.User.Password()
 | 
				
			||||||
		unescape, err := url.QueryUnescape(serverInfo[1])
 | 
					
 | 
				
			||||||
		if err != nil {
 | 
						if !hasPassword && isLikelyBase64(method) {
 | 
				
			||||||
			return model.Proxy{}, &ParseError{
 | 
							decodedStr, err := utils.DecodeBase64(method, true)
 | 
				
			||||||
				Type:    ErrInvalidStruct,
 | 
							if err == nil {
 | 
				
			||||||
				Message: "cannot unescape remarks",
 | 
								methodAndPass := strings.SplitN(decodedStr, ":", 2)
 | 
				
			||||||
				Raw:     proxy,
 | 
								if len(methodAndPass) == 2 {
 | 
				
			||||||
			}
 | 
									method = methodAndPass[0]
 | 
				
			||||||
		}
 | 
									password = methodAndPass[1]
 | 
				
			||||||
		remarks = strings.TrimSpace(unescape)
 | 
					 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
		remarks = strings.TrimSpace(server + ":" + portStr)
 | 
									method = decodedStr
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if password != "" && isLikelyBase64(password) {
 | 
				
			||||||
 | 
							password, err = utils.DecodeBase64(password, true)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result := model.Proxy{
 | 
						remarks := link.Fragment
 | 
				
			||||||
		Type:     "ss",
 | 
						if remarks == "" {
 | 
				
			||||||
 | 
							remarks = fmt.Sprintf("%s:%s", server, portStr)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						remarks = strings.TrimSpace(remarks)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result := P.Proxy{
 | 
				
			||||||
 | 
							Type: p.GetType(),
 | 
				
			||||||
 | 
							Name: remarks,
 | 
				
			||||||
 | 
							ShadowSocks: P.ShadowSocks{
 | 
				
			||||||
			Cipher:   method,
 | 
								Cipher:   method,
 | 
				
			||||||
			Password: password,
 | 
								Password: password,
 | 
				
			||||||
			Server:   server,
 | 
								Server:   server,
 | 
				
			||||||
		Port:     port,
 | 
								Port:     P.IntOrString(port),
 | 
				
			||||||
		Name:     remarks,
 | 
								UDP:      config.UseUDP,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	return result, nil
 | 
						return result, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 注册解析器
 | 
				
			||||||
 | 
					func init() {
 | 
				
			||||||
 | 
						RegisterParser(&ShadowsocksParser{})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,40 +1,68 @@
 | 
				
			|||||||
package parser
 | 
					package parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"net/url"
 | 
						"net/url"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sub2clash/constant"
 | 
					
 | 
				
			||||||
	"sub2clash/model"
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/utils"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ParseShadowsocksR(proxy string) (model.Proxy, error) {
 | 
					type ShadowsocksRParser struct{}
 | 
				
			||||||
	if !strings.HasPrefix(proxy, constant.ShadowsocksRPrefix) {
 | 
					
 | 
				
			||||||
		return model.Proxy{}, &ParseError{Type: ErrInvalidPrefix, Raw: proxy}
 | 
					func (p *ShadowsocksRParser) SupportClash() bool {
 | 
				
			||||||
 | 
						return true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	proxy = strings.TrimPrefix(proxy, constant.ShadowsocksRPrefix)
 | 
					func (p *ShadowsocksRParser) SupportMeta() bool {
 | 
				
			||||||
	proxy, err := DecodeBase64(proxy)
 | 
						return true
 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type: ErrInvalidBase64,
 | 
					 | 
				
			||||||
			Raw:  proxy,
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *ShadowsocksRParser) GetPrefixes() []string {
 | 
				
			||||||
 | 
						return []string{"ssr://"}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *ShadowsocksRParser) GetType() string {
 | 
				
			||||||
 | 
						return "ssr"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *ShadowsocksRParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
 | 
				
			||||||
 | 
						if !hasPrefix(proxy, p.GetPrefixes()) {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPrefix, proxy)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, prefix := range p.GetPrefixes() {
 | 
				
			||||||
 | 
							if strings.HasPrefix(proxy, prefix) {
 | 
				
			||||||
 | 
								proxy = strings.TrimPrefix(proxy, prefix)
 | 
				
			||||||
 | 
								break
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						proxy, err := utils.DecodeBase64(proxy, true)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidBase64, err.Error())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	serverInfoAndParams := strings.SplitN(proxy, "/?", 2)
 | 
						serverInfoAndParams := strings.SplitN(proxy, "/?", 2)
 | 
				
			||||||
	parts := strings.Split(serverInfoAndParams[0], ":")
 | 
						if len(serverInfoAndParams) != 2 {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, proxy)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						parts := SplitNRight(serverInfoAndParams[0], ":", 6)
 | 
				
			||||||
 | 
						if len(parts) < 6 {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, proxy)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	server := parts[0]
 | 
						server := parts[0]
 | 
				
			||||||
	protocol := parts[2]
 | 
						protocol := parts[2]
 | 
				
			||||||
	method := parts[3]
 | 
						method := parts[3]
 | 
				
			||||||
	obfs := parts[4]
 | 
						obfs := parts[4]
 | 
				
			||||||
	password := parts[5]
 | 
						password, err := utils.DecodeBase64(parts[5], true)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	port, err := ParsePort(parts[1])
 | 
						port, err := ParsePort(parts[1])
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPort, err.Error())
 | 
				
			||||||
			Type:    ErrInvalidPort,
 | 
					 | 
				
			||||||
			Message: err.Error(),
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var obfsParam string
 | 
						var obfsParam string
 | 
				
			||||||
@@ -43,44 +71,65 @@ func ParseShadowsocksR(proxy string) (model.Proxy, error) {
 | 
				
			|||||||
	if len(serverInfoAndParams) == 2 {
 | 
						if len(serverInfoAndParams) == 2 {
 | 
				
			||||||
		params, err := url.ParseQuery(serverInfoAndParams[1])
 | 
							params, err := url.ParseQuery(serverInfoAndParams[1])
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return model.Proxy{}, &ParseError{
 | 
								return P.Proxy{}, fmt.Errorf("%w: %s", ErrCannotParseParams, err.Error())
 | 
				
			||||||
				Type:    ErrCannotParseParams,
 | 
					 | 
				
			||||||
				Raw:     proxy,
 | 
					 | 
				
			||||||
				Message: err.Error(),
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if params.Get("obfsparam") != "" {
 | 
							if params.Get("obfsparam") != "" {
 | 
				
			||||||
			obfsParam, err = DecodeBase64(params.Get("obfsparam"))
 | 
								obfsParam, err = utils.DecodeBase64(params.Get("obfsparam"), true)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if params.Get("protoparam") != "" {
 | 
							if params.Get("protoparam") != "" {
 | 
				
			||||||
			protoParam, err = DecodeBase64(params.Get("protoparam"))
 | 
								protoParam, err = utils.DecodeBase64(params.Get("protoparam"), true)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if params.Get("remarks") != "" {
 | 
							if params.Get("remarks") != "" {
 | 
				
			||||||
			remarks, err = DecodeBase64(params.Get("remarks"))
 | 
								remarks, err = utils.DecodeBase64(params.Get("remarks"), true)
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			remarks = server + ":" + strconv.Itoa(port)
 | 
								remarks = server + ":" + strconv.Itoa(port)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return model.Proxy{}, &ParseError{
 | 
								return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
				Type:    ErrInvalidStruct,
 | 
					 | 
				
			||||||
				Raw:     proxy,
 | 
					 | 
				
			||||||
				Message: err.Error(),
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result := model.Proxy{
 | 
						result := P.Proxy{
 | 
				
			||||||
 | 
							Type: p.GetType(),
 | 
				
			||||||
		Name: remarks,
 | 
							Name: remarks,
 | 
				
			||||||
		Type:          "ssr",
 | 
							ShadowSocksR: P.ShadowSocksR{
 | 
				
			||||||
			Server:        server,
 | 
								Server:        server,
 | 
				
			||||||
		Port:          port,
 | 
								Port:          P.IntOrString(port),
 | 
				
			||||||
			Protocol:      protocol,
 | 
								Protocol:      protocol,
 | 
				
			||||||
			Cipher:        method,
 | 
								Cipher:        method,
 | 
				
			||||||
			Obfs:          obfs,
 | 
								Obfs:          obfs,
 | 
				
			||||||
			Password:      password,
 | 
								Password:      password,
 | 
				
			||||||
			ObfsParam:     obfsParam,
 | 
								ObfsParam:     obfsParam,
 | 
				
			||||||
			ProtocolParam: protoParam,
 | 
								ProtocolParam: protoParam,
 | 
				
			||||||
 | 
								UDP:           config.UseUDP,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	return result, nil
 | 
						return result, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func init() {
 | 
				
			||||||
 | 
						RegisterParser(&ShadowsocksRParser{})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func SplitNRight(s, sep string, n int) []string {
 | 
				
			||||||
 | 
						if n <= 0 {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if n == 1 {
 | 
				
			||||||
 | 
							return []string{s}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						parts := strings.Split(s, sep)
 | 
				
			||||||
 | 
						if len(parts) <= n {
 | 
				
			||||||
 | 
							return parts
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						result := make([]string, n)
 | 
				
			||||||
 | 
						for i, j := len(parts)-1, 0; i >= 0; i, j = i-1, j+1 {
 | 
				
			||||||
 | 
							if j < n-1 {
 | 
				
			||||||
 | 
								result[n-j-1] = parts[len(parts)-j-1]
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								result[0] = strings.Join(parts[:i+1], sep)
 | 
				
			||||||
 | 
								break
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return result
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										93
									
								
								parser/socks.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								parser/socks.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,93 @@
 | 
				
			|||||||
 | 
					package parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/utils"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type SocksParser struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *SocksParser) SupportClash() bool {
 | 
				
			||||||
 | 
						return true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					func (p *SocksParser) SupportMeta() bool {
 | 
				
			||||||
 | 
						return true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *SocksParser) GetPrefixes() []string {
 | 
				
			||||||
 | 
						return []string{"socks://", "socks5://"}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *SocksParser) GetType() string {
 | 
				
			||||||
 | 
						return "socks5"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *SocksParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
 | 
				
			||||||
 | 
						if !hasPrefix(proxy, p.GetPrefixes()) {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPrefix, proxy)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						link, err := url.Parse(proxy)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						server := link.Hostname()
 | 
				
			||||||
 | 
						if server == "" {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, "missing server host")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						portStr := link.Port()
 | 
				
			||||||
 | 
						if portStr == "" {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, "missing server port")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						port, err := ParsePort(portStr)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPort, err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						remarks := link.Fragment
 | 
				
			||||||
 | 
						if remarks == "" {
 | 
				
			||||||
 | 
							remarks = fmt.Sprintf("%s:%s", server, portStr)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						remarks = strings.TrimSpace(remarks)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var username, password string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						username = link.User.Username()
 | 
				
			||||||
 | 
						password, hasPassword := link.User.Password()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !hasPassword && isLikelyBase64(username) {
 | 
				
			||||||
 | 
							decodedStr, err := utils.DecodeBase64(username, true)
 | 
				
			||||||
 | 
							if err == nil {
 | 
				
			||||||
 | 
								usernameAndPassword := strings.SplitN(decodedStr, ":", 2)
 | 
				
			||||||
 | 
								if len(usernameAndPassword) == 2 {
 | 
				
			||||||
 | 
									username = usernameAndPassword[0]
 | 
				
			||||||
 | 
									password = usernameAndPassword[1]
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									username = decodedStr
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tls, udp := link.Query().Get("tls"), link.Query().Get("udp")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return P.Proxy{
 | 
				
			||||||
 | 
							Type: p.GetType(),
 | 
				
			||||||
 | 
							Name: remarks,
 | 
				
			||||||
 | 
							Socks: P.Socks{
 | 
				
			||||||
 | 
								Server:   server,
 | 
				
			||||||
 | 
								Port:     P.IntOrString(port),
 | 
				
			||||||
 | 
								UserName: username,
 | 
				
			||||||
 | 
								Password: password,
 | 
				
			||||||
 | 
								TLS:      tls == "true",
 | 
				
			||||||
 | 
								UDP:      udp == "true",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func init() {
 | 
				
			||||||
 | 
						RegisterParser(&SocksParser{})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										147
									
								
								parser/trojan.go
									
									
									
									
									
								
							
							
						
						
									
										147
									
								
								parser/trojan.go
									
									
									
									
									
								
							@@ -1,75 +1,74 @@
 | 
				
			|||||||
package parser
 | 
					package parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"net/url"
 | 
						"net/url"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sub2clash/constant"
 | 
					
 | 
				
			||||||
	"sub2clash/model"
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ParseTrojan 解析给定的Trojan代理URL并返回Proxy结构。
 | 
					type TrojanParser struct{}
 | 
				
			||||||
func ParseTrojan(proxy string) (model.Proxy, error) {
 | 
					
 | 
				
			||||||
	if !strings.HasPrefix(proxy, constant.TrojanPrefix) {
 | 
					func (p *TrojanParser) SupportClash() bool {
 | 
				
			||||||
		return model.Proxy{}, &ParseError{Type: ErrInvalidPrefix, Raw: proxy}
 | 
						return true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	proxy = strings.TrimPrefix(proxy, constant.TrojanPrefix)
 | 
					func (p *TrojanParser) SupportMeta() bool {
 | 
				
			||||||
	urlParts := strings.SplitN(proxy, "@", 2)
 | 
						return true
 | 
				
			||||||
	if len(urlParts) != 2 {
 | 
					 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrInvalidStruct,
 | 
					 | 
				
			||||||
			Message: "missing character '@' in url",
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	password := strings.TrimSpace(urlParts[0])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	serverInfo := strings.SplitN(urlParts[1], "#", 2)
 | 
					 | 
				
			||||||
	serverAndPortAndParams := strings.SplitN(serverInfo[0], "?", 2)
 | 
					 | 
				
			||||||
	if len(serverAndPortAndParams) != 2 {
 | 
					 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrInvalidStruct,
 | 
					 | 
				
			||||||
			Message: "missing character '?' in url",
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	serverAndPort := strings.SplitN(serverAndPortAndParams[0], ":", 2)
 | 
					func (p *TrojanParser) GetPrefixes() []string {
 | 
				
			||||||
	if len(serverAndPort) != 2 {
 | 
						return []string{"trojan://"}
 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrInvalidStruct,
 | 
					 | 
				
			||||||
			Message: "missing server host or port",
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	server, portStr := serverAndPort[0], serverAndPort[1]
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	params, err := url.ParseQuery(serverAndPortAndParams[1])
 | 
					func (p *TrojanParser) GetType() string {
 | 
				
			||||||
 | 
						return "trojan"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *TrojanParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
 | 
				
			||||||
 | 
						if !hasPrefix(proxy, p.GetPrefixes()) {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPrefix, proxy)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						link, err := url.Parse(proxy)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
			Type:    ErrCannotParseParams,
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
			Message: err.Error(),
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						password := link.User.Username()
 | 
				
			||||||
 | 
						server := link.Hostname()
 | 
				
			||||||
 | 
						if server == "" {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, "missing server host")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						portStr := link.Port()
 | 
				
			||||||
 | 
						if portStr == "" {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, "missing server port")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	port, err := ParsePort(portStr)
 | 
						port, err := ParsePort(portStr)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPort, err.Error())
 | 
				
			||||||
			Type:    ErrInvalidPort,
 | 
					 | 
				
			||||||
			Message: err.Error(),
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	remarks := ""
 | 
						remarks := link.Fragment
 | 
				
			||||||
	if len(serverInfo) == 2 {
 | 
						if remarks == "" {
 | 
				
			||||||
		remarks, _ = url.QueryUnescape(strings.TrimSpace(serverInfo[1]))
 | 
							remarks = fmt.Sprintf("%s:%s", server, portStr)
 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		remarks = serverAndPort[0]
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						remarks = strings.TrimSpace(remarks)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	network, security, alpnStr, sni, pbk, sid, fp, path, host, serviceName := params.Get("type"), params.Get("security"), params.Get("alpn"), params.Get("sni"), params.Get("pbk"), params.Get("sid"), params.Get("fp"), params.Get("path"), params.Get("host"), params.Get("serviceName")
 | 
						query := link.Query()
 | 
				
			||||||
 | 
						network, security, alpnStr, sni, pbk, sid, fp, path, host, serviceName, udp, insecure := query.Get("type"), query.Get("security"), query.Get("alpn"), query.Get("sni"), query.Get("pbk"), query.Get("sid"), query.Get("fp"), query.Get("path"), query.Get("host"), query.Get("serviceName"), query.Get("udp"), query.Get("allowInsecure")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						insecureBool := insecure == "1"
 | 
				
			||||||
 | 
						result := P.Trojan{
 | 
				
			||||||
 | 
							Server:         server,
 | 
				
			||||||
 | 
							Port:           P.IntOrString(port),
 | 
				
			||||||
 | 
							Password:       password,
 | 
				
			||||||
 | 
							Network:        network,
 | 
				
			||||||
 | 
							UDP:            udp == "true",
 | 
				
			||||||
 | 
							SkipCertVerify: insecureBool,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var alpn []string
 | 
						var alpn []string
 | 
				
			||||||
	if strings.Contains(alpnStr, ",") {
 | 
						if strings.Contains(alpnStr, ",") {
 | 
				
			||||||
@@ -77,38 +76,28 @@ func ParseTrojan(proxy string) (model.Proxy, error) {
 | 
				
			|||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		alpn = nil
 | 
							alpn = nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if len(alpn) > 0 {
 | 
				
			||||||
	// enableUTLS := fp != ""
 | 
							result.ALPN = alpn
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 构建Proxy结构体
 | 
					 | 
				
			||||||
	result := model.Proxy{
 | 
					 | 
				
			||||||
		Type:     "trojan",
 | 
					 | 
				
			||||||
		Server:   server,
 | 
					 | 
				
			||||||
		Port:     port,
 | 
					 | 
				
			||||||
		Password: password,
 | 
					 | 
				
			||||||
		Name:     remarks,
 | 
					 | 
				
			||||||
		Network:  network,
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if security == "xtls" || security == "tls" {
 | 
						if fp != "" {
 | 
				
			||||||
		result.Alpn = alpn
 | 
							result.ClientFingerprint = fp
 | 
				
			||||||
		result.Sni = sni
 | 
						}
 | 
				
			||||||
		result.TLS = true
 | 
					
 | 
				
			||||||
 | 
						if sni != "" {
 | 
				
			||||||
 | 
							result.SNI = sni
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if security == "reality" {
 | 
						if security == "reality" {
 | 
				
			||||||
		result.TLS = true
 | 
							result.RealityOpts = P.RealityOptions{
 | 
				
			||||||
		result.Sni = sni
 | 
					 | 
				
			||||||
		result.RealityOpts = model.RealityOptions{
 | 
					 | 
				
			||||||
			PublicKey: pbk,
 | 
								PublicKey: pbk,
 | 
				
			||||||
			ShortID:   sid,
 | 
								ShortID:   sid,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		result.Fingerprint = fp
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if network == "ws" {
 | 
						if network == "ws" {
 | 
				
			||||||
		result.Network = "ws"
 | 
							result.Network = "ws"
 | 
				
			||||||
		result.WSOpts = model.WSOptions{
 | 
							result.WSOpts = P.WSOptions{
 | 
				
			||||||
			Path: path,
 | 
								Path: path,
 | 
				
			||||||
			Headers: map[string]string{
 | 
								Headers: map[string]string{
 | 
				
			||||||
				"Host": host,
 | 
									"Host": host,
 | 
				
			||||||
@@ -116,19 +105,19 @@ func ParseTrojan(proxy string) (model.Proxy, error) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// if network == "http" {
 | 
					 | 
				
			||||||
	// 	// 未查到相关支持文档
 | 
					 | 
				
			||||||
	// }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// if network == "quic" {
 | 
					 | 
				
			||||||
	// 	// 未查到相关支持文档
 | 
					 | 
				
			||||||
	// }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if network == "grpc" {
 | 
						if network == "grpc" {
 | 
				
			||||||
		result.GrpcOpts = model.GrpcOptions{
 | 
							result.GrpcOpts = P.GrpcOptions{
 | 
				
			||||||
			GrpcServiceName: serviceName,
 | 
								GrpcServiceName: serviceName,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return result, nil
 | 
						return P.Proxy{
 | 
				
			||||||
 | 
							Type:   p.GetType(),
 | 
				
			||||||
 | 
							Name:   remarks,
 | 
				
			||||||
 | 
							Trojan: result,
 | 
				
			||||||
 | 
						}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func init() {
 | 
				
			||||||
 | 
						RegisterParser(&TrojanParser{})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										163
									
								
								parser/vless.go
									
									
									
									
									
								
							
							
						
						
									
										163
									
								
								parser/vless.go
									
									
									
									
									
								
							@@ -1,88 +1,55 @@
 | 
				
			|||||||
package parser
 | 
					package parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"net/url"
 | 
						"net/url"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sub2clash/constant"
 | 
					
 | 
				
			||||||
	"sub2clash/model"
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ParseVless(proxy string) (model.Proxy, error) {
 | 
					type VlessParser struct{}
 | 
				
			||||||
	if !strings.HasPrefix(proxy, constant.VLESSPrefix) {
 | 
					
 | 
				
			||||||
		return model.Proxy{}, &ParseError{Type: ErrInvalidPrefix, Raw: proxy}
 | 
					func (p *VlessParser) SupportClash() bool {
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	urlParts := strings.SplitN(strings.TrimPrefix(proxy, constant.VLESSPrefix), "@", 2)
 | 
					func (p *VlessParser) SupportMeta() bool {
 | 
				
			||||||
	if len(urlParts) != 2 {
 | 
						return true
 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrInvalidStruct,
 | 
					 | 
				
			||||||
			Message: "missing character '@' in url",
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	serverInfo := strings.SplitN(urlParts[1], "#", 2)
 | 
					func (p *VlessParser) GetPrefixes() []string {
 | 
				
			||||||
	serverAndPortAndParams := strings.SplitN(serverInfo[0], "?", 2)
 | 
						return []string{"vless://"}
 | 
				
			||||||
	if len(serverAndPortAndParams) != 2 {
 | 
					 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrInvalidStruct,
 | 
					 | 
				
			||||||
			Message: "missing character '?' in url",
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	serverAndPort := strings.SplitN(serverAndPortAndParams[0], ":", 2)
 | 
					func (p *VlessParser) GetType() string {
 | 
				
			||||||
	if len(serverAndPort) != 2 {
 | 
						return "vless"
 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
			Type:    ErrInvalidStruct,
 | 
					 | 
				
			||||||
			Message: "missing server host or port",
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *VlessParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
 | 
				
			||||||
 | 
						if !hasPrefix(proxy, p.GetPrefixes()) {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPrefix, proxy)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	server, portStr := serverAndPort[0], serverAndPort[1]
 | 
					
 | 
				
			||||||
 | 
						link, err := url.Parse(proxy)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						server := link.Hostname()
 | 
				
			||||||
 | 
						if server == "" {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, "missing server host")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						portStr := link.Port()
 | 
				
			||||||
	port, err := ParsePort(portStr)
 | 
						port, err := ParsePort(portStr)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPort, err.Error())
 | 
				
			||||||
			Type:    ErrInvalidPort,
 | 
					 | 
				
			||||||
			Message: err.Error(),
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	params, err := url.ParseQuery(serverAndPortAndParams[1])
 | 
						query := link.Query()
 | 
				
			||||||
	if err != nil {
 | 
						uuid := link.User.Username()
 | 
				
			||||||
		return model.Proxy{}, &ParseError{
 | 
						flow, security, alpnStr, sni, insecure, fp, pbk, sid, path, host, serviceName, _type, udp := query.Get("flow"), query.Get("security"), query.Get("alpn"), query.Get("sni"), query.Get("allowInsecure"), query.Get("fp"), query.Get("pbk"), query.Get("sid"), query.Get("path"), query.Get("host"), query.Get("serviceName"), query.Get("type"), query.Get("udp")
 | 
				
			||||||
			Type:    ErrCannotParseParams,
 | 
					 | 
				
			||||||
			Raw:     proxy,
 | 
					 | 
				
			||||||
			Message: err.Error(),
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	remarks := ""
 | 
					 | 
				
			||||||
	if len(serverInfo) == 2 {
 | 
					 | 
				
			||||||
		if strings.Contains(serverInfo[1], "|") {
 | 
					 | 
				
			||||||
			remarks = strings.SplitN(serverInfo[1], "|", 2)[1]
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			remarks, err = url.QueryUnescape(serverInfo[1])
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				return model.Proxy{}, &ParseError{
 | 
					 | 
				
			||||||
					Type:    ErrCannotParseParams,
 | 
					 | 
				
			||||||
					Raw:     proxy,
 | 
					 | 
				
			||||||
					Message: err.Error(),
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		remarks, err = url.QueryUnescape(server)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return model.Proxy{}, err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	uuid := strings.TrimSpace(urlParts[0])
 | 
					 | 
				
			||||||
	flow, security, alpnStr, sni, insecure, fp, pbk, sid, path, host, serviceName, _type := params.Get("flow"), params.Get("security"), params.Get("alpn"), params.Get("sni"), params.Get("allowInsecure"), params.Get("fp"), params.Get("pbk"), params.Get("sid"), params.Get("path"), params.Get("host"), params.Get("serviceName"), params.Get("type")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// enableUTLS := fp != ""
 | 
					 | 
				
			||||||
	insecureBool := insecure == "1"
 | 
						insecureBool := insecure == "1"
 | 
				
			||||||
	var alpn []string
 | 
						var alpn []string
 | 
				
			||||||
	if strings.Contains(alpnStr, ",") {
 | 
						if strings.Contains(alpnStr, ",") {
 | 
				
			||||||
@@ -91,26 +58,40 @@ func ParseVless(proxy string) (model.Proxy, error) {
 | 
				
			|||||||
		alpn = nil
 | 
							alpn = nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result := model.Proxy{
 | 
						remarks := link.Fragment
 | 
				
			||||||
		Type:   "vless",
 | 
						if remarks == "" {
 | 
				
			||||||
 | 
							remarks = fmt.Sprintf("%s:%s", server, portStr)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						remarks = strings.TrimSpace(remarks)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result := P.Vless{
 | 
				
			||||||
		Server:         server,
 | 
							Server:         server,
 | 
				
			||||||
		Name:   remarks,
 | 
							Port:           P.IntOrString(port),
 | 
				
			||||||
		Port:   port,
 | 
					 | 
				
			||||||
		UUID:           uuid,
 | 
							UUID:           uuid,
 | 
				
			||||||
		Flow:           flow,
 | 
							Flow:           flow,
 | 
				
			||||||
 | 
							UDP:            udp == "true",
 | 
				
			||||||
 | 
							SkipCertVerify: insecureBool,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(alpn) > 0 {
 | 
				
			||||||
 | 
							result.ALPN = alpn
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if fp != "" {
 | 
				
			||||||
 | 
							result.ClientFingerprint = fp
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if sni != "" {
 | 
				
			||||||
 | 
							result.ServerName = sni
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if security == "tls" {
 | 
						if security == "tls" {
 | 
				
			||||||
		result.TLS = true
 | 
							result.TLS = true
 | 
				
			||||||
		result.Alpn = alpn
 | 
					 | 
				
			||||||
		result.Sni = sni
 | 
					 | 
				
			||||||
		result.AllowInsecure = insecureBool
 | 
					 | 
				
			||||||
		result.Fingerprint = fp
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if security == "reality" {
 | 
						if security == "reality" {
 | 
				
			||||||
		result.TLS = true
 | 
							result.TLS = true
 | 
				
			||||||
		result.RealityOpts = model.RealityOptions{
 | 
							result.RealityOpts = P.RealityOptions{
 | 
				
			||||||
			PublicKey: pbk,
 | 
								PublicKey: pbk,
 | 
				
			||||||
			ShortID:   sid,
 | 
								ShortID:   sid,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -118,7 +99,7 @@ func ParseVless(proxy string) (model.Proxy, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if _type == "ws" {
 | 
						if _type == "ws" {
 | 
				
			||||||
		result.Network = "ws"
 | 
							result.Network = "ws"
 | 
				
			||||||
		result.WSOpts = model.WSOptions{
 | 
							result.WSOpts = P.WSOptions{
 | 
				
			||||||
			Path: path,
 | 
								Path: path,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if host != "" {
 | 
							if host != "" {
 | 
				
			||||||
@@ -127,30 +108,36 @@ func ParseVless(proxy string) (model.Proxy, error) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// if _type == "quic" {
 | 
					 | 
				
			||||||
	// 	// 未查到相关支持文档
 | 
					 | 
				
			||||||
	// }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if _type == "grpc" {
 | 
						if _type == "grpc" {
 | 
				
			||||||
		result.Network = "grpc"
 | 
							result.Network = "grpc"
 | 
				
			||||||
		result.Servername = serviceName
 | 
							result.GrpcOpts = P.GrpcOptions{
 | 
				
			||||||
 | 
								GrpcServiceName: serviceName,
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if _type == "http" {
 | 
						if _type == "http" {
 | 
				
			||||||
 | 
							result.HTTPOpts = P.HTTPOptions{}
 | 
				
			||||||
 | 
							result.HTTPOpts.Headers = map[string][]string{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							result.HTTPOpts.Path = strings.Split(path, ",")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		hosts, err := url.QueryUnescape(host)
 | 
							hosts, err := url.QueryUnescape(host)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return model.Proxy{}, &ParseError{
 | 
								return P.Proxy{}, fmt.Errorf("%w: %s", ErrCannotParseParams, err.Error())
 | 
				
			||||||
				Type:    ErrCannotParseParams,
 | 
					 | 
				
			||||||
				Raw:     proxy,
 | 
					 | 
				
			||||||
				Message: err.Error(),
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		result.Network = "http"
 | 
							result.Network = "http"
 | 
				
			||||||
		result.HTTPOpts = model.HTTPOptions{
 | 
							if hosts != "" {
 | 
				
			||||||
			Headers: map[string][]string{"Host": strings.Split(hosts, ",")},
 | 
								result.HTTPOpts.Headers["host"] = strings.Split(host, ",")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return P.Proxy{
 | 
				
			||||||
 | 
							Type:  p.GetType(),
 | 
				
			||||||
 | 
							Name:  remarks,
 | 
				
			||||||
 | 
							Vless: result,
 | 
				
			||||||
 | 
						}, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return result, nil
 | 
					func init() {
 | 
				
			||||||
 | 
						RegisterParser(&VlessParser{})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										128
									
								
								parser/vmess.go
									
									
									
									
									
								
							
							
						
						
									
										128
									
								
								parser/vmess.go
									
									
									
									
									
								
							@@ -2,28 +2,71 @@ package parser
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"net/url"
 | 
						"net/url"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sub2clash/constant"
 | 
					
 | 
				
			||||||
	"sub2clash/model"
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/utils"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ParseVmess(proxy string) (model.Proxy, error) {
 | 
					type VmessJson struct {
 | 
				
			||||||
	if !strings.HasPrefix(proxy, constant.VMessPrefix) {
 | 
						V    any    `json:"v"`
 | 
				
			||||||
		return model.Proxy{}, &ParseError{Type: ErrInvalidPrefix, Raw: proxy}
 | 
						Ps   string `json:"ps"`
 | 
				
			||||||
 | 
						Add  string `json:"add"`
 | 
				
			||||||
 | 
						Port any    `json:"port"`
 | 
				
			||||||
 | 
						Id   string `json:"id"`
 | 
				
			||||||
 | 
						Aid  any    `json:"aid"`
 | 
				
			||||||
 | 
						Scy  string `json:"scy"`
 | 
				
			||||||
 | 
						Net  string `json:"net"`
 | 
				
			||||||
 | 
						Type string `json:"type"`
 | 
				
			||||||
 | 
						Host string `json:"host"`
 | 
				
			||||||
 | 
						Path string `json:"path"`
 | 
				
			||||||
 | 
						Tls  string `json:"tls"`
 | 
				
			||||||
 | 
						Sni  string `json:"sni"`
 | 
				
			||||||
 | 
						Alpn string `json:"alpn"`
 | 
				
			||||||
 | 
						Fp   string `json:"fp"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	proxy = strings.TrimPrefix(proxy, constant.VMessPrefix)
 | 
					type VmessParser struct{}
 | 
				
			||||||
	base64, err := DecodeBase64(proxy)
 | 
					
 | 
				
			||||||
 | 
					func (p *VmessParser) SupportClash() bool {
 | 
				
			||||||
 | 
						return true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *VmessParser) SupportMeta() bool {
 | 
				
			||||||
 | 
						return true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *VmessParser) GetPrefixes() []string {
 | 
				
			||||||
 | 
						return []string{"vmess://"}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *VmessParser) GetType() string {
 | 
				
			||||||
 | 
						return "vmess"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *VmessParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
 | 
				
			||||||
 | 
						if !hasPrefix(proxy, p.GetPrefixes()) {
 | 
				
			||||||
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPrefix, proxy)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, prefix := range p.GetPrefixes() {
 | 
				
			||||||
 | 
							if strings.HasPrefix(proxy, prefix) {
 | 
				
			||||||
 | 
								proxy = strings.TrimPrefix(proxy, prefix)
 | 
				
			||||||
 | 
								break
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						base64, err := utils.DecodeBase64(proxy, true)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return model.Proxy{}, &ParseError{Type: ErrInvalidBase64, Raw: proxy, Message: err.Error()}
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidBase64, err.Error())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var vmess model.VmessJson
 | 
						var vmess VmessJson
 | 
				
			||||||
	err = json.Unmarshal([]byte(base64), &vmess)
 | 
						err = json.Unmarshal([]byte(base64), &vmess)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return model.Proxy{}, &ParseError{Type: ErrInvalidStruct, Raw: proxy, Message: err.Error()}
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var port int
 | 
						var port int
 | 
				
			||||||
@@ -31,11 +74,7 @@ func ParseVmess(proxy string) (model.Proxy, error) {
 | 
				
			|||||||
	case string:
 | 
						case string:
 | 
				
			||||||
		port, err = ParsePort(vmess.Port.(string))
 | 
							port, err = ParsePort(vmess.Port.(string))
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return model.Proxy{}, &ParseError{
 | 
								return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidPort, err.Error())
 | 
				
			||||||
				Type:    ErrInvalidPort,
 | 
					 | 
				
			||||||
				Message: err.Error(),
 | 
					 | 
				
			||||||
				Raw:     proxy,
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case float64:
 | 
						case float64:
 | 
				
			||||||
		port = int(vmess.Port.(float64))
 | 
							port = int(vmess.Port.(float64))
 | 
				
			||||||
@@ -46,7 +85,7 @@ func ParseVmess(proxy string) (model.Proxy, error) {
 | 
				
			|||||||
	case string:
 | 
						case string:
 | 
				
			||||||
		aid, err = strconv.Atoi(vmess.Aid.(string))
 | 
							aid, err = strconv.Atoi(vmess.Aid.(string))
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return model.Proxy{}, &ParseError{Type: ErrInvalidStruct, Raw: proxy, Message: err.Error()}
 | 
								return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case float64:
 | 
						case float64:
 | 
				
			||||||
		aid = int(vmess.Aid.(float64))
 | 
							aid = int(vmess.Aid.(float64))
 | 
				
			||||||
@@ -61,27 +100,36 @@ func ParseVmess(proxy string) (model.Proxy, error) {
 | 
				
			|||||||
		name = vmess.Ps
 | 
							name = vmess.Ps
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result := model.Proxy{
 | 
					 | 
				
			||||||
		Name:    name,
 | 
					 | 
				
			||||||
		Type:    "vmess",
 | 
					 | 
				
			||||||
		Server:  vmess.Add,
 | 
					 | 
				
			||||||
		Port:    port,
 | 
					 | 
				
			||||||
		UUID:    vmess.Id,
 | 
					 | 
				
			||||||
		AlterID: aid,
 | 
					 | 
				
			||||||
		Cipher:  vmess.Scy,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if vmess.Tls == "tls" {
 | 
					 | 
				
			||||||
	var alpn []string
 | 
						var alpn []string
 | 
				
			||||||
	if strings.Contains(vmess.Alpn, ",") {
 | 
						if strings.Contains(vmess.Alpn, ",") {
 | 
				
			||||||
		alpn = strings.Split(vmess.Alpn, ",")
 | 
							alpn = strings.Split(vmess.Alpn, ",")
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		alpn = nil
 | 
							alpn = nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result := P.Vmess{
 | 
				
			||||||
 | 
							Server:  vmess.Add,
 | 
				
			||||||
 | 
							Port:    P.IntOrString(port),
 | 
				
			||||||
 | 
							UUID:    vmess.Id,
 | 
				
			||||||
 | 
							AlterID: P.IntOrString(aid),
 | 
				
			||||||
 | 
							Cipher:  vmess.Scy,
 | 
				
			||||||
 | 
							UDP:     config.UseUDP,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(alpn) > 0 {
 | 
				
			||||||
 | 
							result.ALPN = alpn
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if vmess.Fp != "" {
 | 
				
			||||||
 | 
							result.ClientFingerprint = vmess.Fp
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if vmess.Sni != "" {
 | 
				
			||||||
 | 
							result.ServerName = vmess.Sni
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if vmess.Tls == "tls" {
 | 
				
			||||||
		result.TLS = true
 | 
							result.TLS = true
 | 
				
			||||||
		result.Fingerprint = vmess.Fp
 | 
					 | 
				
			||||||
		result.Alpn = alpn
 | 
					 | 
				
			||||||
		result.Servername = vmess.Sni
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if vmess.Net == "ws" {
 | 
						if vmess.Net == "ws" {
 | 
				
			||||||
@@ -92,7 +140,7 @@ func ParseVmess(proxy string) (model.Proxy, error) {
 | 
				
			|||||||
			vmess.Host = vmess.Add
 | 
								vmess.Host = vmess.Add
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		result.Network = "ws"
 | 
							result.Network = "ws"
 | 
				
			||||||
		result.WSOpts = model.WSOptions{
 | 
							result.WSOpts = P.WSOptions{
 | 
				
			||||||
			Path: vmess.Path,
 | 
								Path: vmess.Path,
 | 
				
			||||||
			Headers: map[string]string{
 | 
								Headers: map[string]string{
 | 
				
			||||||
				"Host": vmess.Host,
 | 
									"Host": vmess.Host,
 | 
				
			||||||
@@ -100,24 +148,28 @@ func ParseVmess(proxy string) (model.Proxy, error) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// if vmess.Net == "quic" {
 | 
					 | 
				
			||||||
	// 	// 未查到相关支持文档
 | 
					 | 
				
			||||||
	// }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if vmess.Net == "grpc" {
 | 
						if vmess.Net == "grpc" {
 | 
				
			||||||
		result.GrpcOpts = model.GrpcOptions{
 | 
							result.GrpcOpts = P.GrpcOptions{
 | 
				
			||||||
			GrpcServiceName: vmess.Path,
 | 
								GrpcServiceName: vmess.Path,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		result.Network = "grpc"
 | 
							result.Network = "grpc"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if vmess.Net == "h2" {
 | 
						if vmess.Net == "h2" {
 | 
				
			||||||
		result.HTTP2Opts = model.HTTP2Options{
 | 
							result.HTTP2Opts = P.HTTP2Options{
 | 
				
			||||||
			Host: strings.Split(vmess.Host, ","),
 | 
								Host: strings.Split(vmess.Host, ","),
 | 
				
			||||||
			Path: vmess.Path,
 | 
								Path: vmess.Path,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		result.Network = "h2"
 | 
							result.Network = "h2"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return result, nil
 | 
						return P.Proxy{
 | 
				
			||||||
 | 
							Type:  p.GetType(),
 | 
				
			||||||
 | 
							Name:  name,
 | 
				
			||||||
 | 
							Vmess: result,
 | 
				
			||||||
 | 
						}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func init() {
 | 
				
			||||||
 | 
						RegisterParser(&VmessParser{})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										53
									
								
								server/handler/convert.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								server/handler/convert.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
				
			|||||||
 | 
					package handler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						_ "embed"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/common"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/config"
 | 
				
			||||||
 | 
						M "github.com/bestnite/sub2clash/model"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
 | 
						"gopkg.in/yaml.v3"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ConvertHandler(template string) func(c *gin.Context) {
 | 
				
			||||||
 | 
						return func(c *gin.Context) {
 | 
				
			||||||
 | 
							query, err := M.ParseConvertQuery(c)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								c.String(http.StatusBadRequest, err.Error())
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							sub, err := common.BuildSub(query.ClashType, query, template, config.GlobalConfig.CacheExpire, config.GlobalConfig.RequestRetryTimes)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								c.String(http.StatusInternalServerError, err.Error())
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if len(query.Subs) == 1 {
 | 
				
			||||||
 | 
								userInfoHeader, err := common.FetchSubscriptionUserInfo(query.Subs[0], "clash", config.GlobalConfig.RequestRetryTimes)
 | 
				
			||||||
 | 
								if err == nil {
 | 
				
			||||||
 | 
									c.Header("subscription-userinfo", userInfoHeader)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if query.NodeListMode {
 | 
				
			||||||
 | 
								nodelist := M.NodeList{}
 | 
				
			||||||
 | 
								nodelist.Proxy = sub.Proxy
 | 
				
			||||||
 | 
								marshal, err := yaml.Marshal(nodelist)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									c.String(http.StatusInternalServerError, "YAML序列化失败: "+err.Error())
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								c.String(http.StatusOK, string(marshal))
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							marshal, err := yaml.Marshal(sub)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								c.String(http.StatusInternalServerError, "YAML序列化失败: "+err.Error())
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							c.String(http.StatusOK, string(marshal))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										220
									
								
								server/handler/short_link.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										220
									
								
								server/handler/short_link.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,220 @@
 | 
				
			|||||||
 | 
					package handler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/common"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/common/database"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/config"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type shortLinkGenRequset struct {
 | 
				
			||||||
 | 
						Url      string `form:"url" binding:"required"`
 | 
				
			||||||
 | 
						Password string `form:"password"`
 | 
				
			||||||
 | 
						CustomID string `form:"customId"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type shortLinkUpdateRequest struct {
 | 
				
			||||||
 | 
						Hash     string `form:"hash" binding:"required"`
 | 
				
			||||||
 | 
						Url      string `form:"url" binding:"required"`
 | 
				
			||||||
 | 
						Password string `form:"password" binding:"required"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func respondWithError(c *gin.Context, code int, message string) {
 | 
				
			||||||
 | 
						c.String(code, message)
 | 
				
			||||||
 | 
						c.Abort()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GenerateLinkHandler(c *gin.Context) {
 | 
				
			||||||
 | 
						var params shortLinkGenRequset
 | 
				
			||||||
 | 
						if err := c.ShouldBind(¶ms); err != nil {
 | 
				
			||||||
 | 
							respondWithError(c, http.StatusBadRequest, "参数错误: "+err.Error())
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if strings.TrimSpace(params.Url) == "" {
 | 
				
			||||||
 | 
							respondWithError(c, http.StatusBadRequest, "URL 不能为空")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var hash string
 | 
				
			||||||
 | 
						var password string
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if params.CustomID != "" {
 | 
				
			||||||
 | 
							// 检查自定义ID是否已存在
 | 
				
			||||||
 | 
							exists, err := database.CheckShortLinkHashExists(params.CustomID)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								respondWithError(c, http.StatusInternalServerError, "数据库错误")
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if exists {
 | 
				
			||||||
 | 
								respondWithError(c, http.StatusBadRequest, "短链已存在")
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							hash = params.CustomID
 | 
				
			||||||
 | 
							password = params.Password
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							// 自动生成短链ID和密码
 | 
				
			||||||
 | 
							hash, err = generateUniqueHash(config.GlobalConfig.ShortLinkLength)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								respondWithError(c, http.StatusInternalServerError, "生成短链接失败")
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if params.Password == "" {
 | 
				
			||||||
 | 
								password = common.RandomString(8) // 生成8位随机密码
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								password = params.Password
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						shortLink := model.ShortLink{
 | 
				
			||||||
 | 
							Hash:     hash,
 | 
				
			||||||
 | 
							Url:      params.Url,
 | 
				
			||||||
 | 
							Password: password,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := database.SaveShortLink(&shortLink); err != nil {
 | 
				
			||||||
 | 
							respondWithError(c, http.StatusInternalServerError, "数据库错误")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 返回生成的短链ID和密码
 | 
				
			||||||
 | 
						response := map[string]string{
 | 
				
			||||||
 | 
							"hash":     hash,
 | 
				
			||||||
 | 
							"password": password,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						c.JSON(http.StatusOK, response)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func generateUniqueHash(length int) (string, error) {
 | 
				
			||||||
 | 
						for {
 | 
				
			||||||
 | 
							hash := common.RandomString(length)
 | 
				
			||||||
 | 
							exists, err := database.CheckShortLinkHashExists(hash)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return "", err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if !exists {
 | 
				
			||||||
 | 
								return hash, nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func UpdateLinkHandler(c *gin.Context) {
 | 
				
			||||||
 | 
						var params shortLinkUpdateRequest
 | 
				
			||||||
 | 
						if err := c.ShouldBindJSON(¶ms); err != nil {
 | 
				
			||||||
 | 
							respondWithError(c, http.StatusBadRequest, "参数错误: "+err.Error())
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 先获取原有的短链接
 | 
				
			||||||
 | 
						existingLink, err := database.FindShortLinkByHash(params.Hash)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							respondWithError(c, http.StatusNotFound, "未找到短链接")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 验证密码
 | 
				
			||||||
 | 
						if existingLink.Password != params.Password {
 | 
				
			||||||
 | 
							respondWithError(c, http.StatusUnauthorized, "密码错误")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 更新URL,但保持原密码不变
 | 
				
			||||||
 | 
						shortLink := model.ShortLink{
 | 
				
			||||||
 | 
							Hash:     params.Hash,
 | 
				
			||||||
 | 
							Url:      params.Url,
 | 
				
			||||||
 | 
							Password: existingLink.Password, // 保持原密码不变
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := database.SaveShortLink(&shortLink); err != nil {
 | 
				
			||||||
 | 
							respondWithError(c, http.StatusInternalServerError, "数据库错误")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						c.String(http.StatusOK, "短链接更新成功")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetRawConfHandler(c *gin.Context) {
 | 
				
			||||||
 | 
						hash := c.Param("hash")
 | 
				
			||||||
 | 
						password := c.Query("password")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if strings.TrimSpace(hash) == "" {
 | 
				
			||||||
 | 
							c.String(http.StatusBadRequest, "参数错误")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						shortLink, err := database.FindShortLinkByHash(hash)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							c.String(http.StatusNotFound, "未找到短链接或密码错误")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if shortLink.Password != "" && shortLink.Password != password {
 | 
				
			||||||
 | 
							c.String(http.StatusNotFound, "未找到短链接或密码错误")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						shortLink.LastRequestTime = time.Now().Unix()
 | 
				
			||||||
 | 
						err = database.SaveShortLink(shortLink)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							respondWithError(c, http.StatusInternalServerError, "数据库错误")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						scheme := "http"
 | 
				
			||||||
 | 
						if c.Request.TLS != nil {
 | 
				
			||||||
 | 
							scheme = "https"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						host := c.Request.Host
 | 
				
			||||||
 | 
						targetPath := strings.TrimPrefix(shortLink.Url, "/")
 | 
				
			||||||
 | 
						requestURL := fmt.Sprintf("%s://%s/%s", scheme, host, targetPath)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						client := &http.Client{
 | 
				
			||||||
 | 
							Timeout: 30 * time.Second, // 30秒超时
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						response, err := client.Get(requestURL)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							respondWithError(c, http.StatusInternalServerError, "请求错误: "+err.Error())
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer response.Body.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						all, err := io.ReadAll(response.Body)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							respondWithError(c, http.StatusInternalServerError, "读取错误: "+err.Error())
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						c.String(http.StatusOK, string(all))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetRawConfUriHandler(c *gin.Context) {
 | 
				
			||||||
 | 
						hash := c.Query("hash")
 | 
				
			||||||
 | 
						password := c.Query("password")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if strings.TrimSpace(hash) == "" {
 | 
				
			||||||
 | 
							c.String(http.StatusBadRequest, "参数错误")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						shortLink, err := database.FindShortLinkByHash(hash)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							c.String(http.StatusNotFound, "未找到短链接或密码错误")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if shortLink.Password != "" && shortLink.Password != password {
 | 
				
			||||||
 | 
							c.String(http.StatusNotFound, "未找到短链接或密码错误")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						c.String(http.StatusOK, shortLink.Url)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -2,9 +2,10 @@ package middleware
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"sub2clash/logger"
 | 
					 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/logger"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
	"go.uber.org/zap"
 | 
						"go.uber.org/zap"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -1,13 +1,15 @@
 | 
				
			|||||||
package api
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"embed"
 | 
						"embed"
 | 
				
			||||||
	"html/template"
 | 
						"html/template"
 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"sub2clash/api/handler"
 | 
					
 | 
				
			||||||
	"sub2clash/constant"
 | 
						"github.com/bestnite/sub2clash/config"
 | 
				
			||||||
	"sub2clash/middleware"
 | 
						"github.com/bestnite/sub2clash/constant"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/server/handler"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/server/middleware"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -16,9 +18,6 @@ import (
 | 
				
			|||||||
var staticFiles embed.FS
 | 
					var staticFiles embed.FS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func SetRoute(r *gin.Engine) {
 | 
					func SetRoute(r *gin.Engine) {
 | 
				
			||||||
	r.Use(middleware.ZapLogger())
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 使用内嵌的模板文件
 | 
					 | 
				
			||||||
	tpl, err := template.ParseFS(staticFiles, "static/*")
 | 
						tpl, err := template.ParseFS(staticFiles, "static/*")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Fatalf("Error parsing templates: %v", err)
 | 
							log.Fatalf("Error parsing templates: %v", err)
 | 
				
			||||||
@@ -33,9 +32,6 @@ func SetRoute(r *gin.Engine) {
 | 
				
			|||||||
	r.GET(
 | 
						r.GET(
 | 
				
			||||||
		"/", func(c *gin.Context) {
 | 
							"/", func(c *gin.Context) {
 | 
				
			||||||
			version := constant.Version
 | 
								version := constant.Version
 | 
				
			||||||
			if len(constant.Version) > 7 {
 | 
					 | 
				
			||||||
				version = constant.Version[:7]
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			c.HTML(
 | 
								c.HTML(
 | 
				
			||||||
				200, "index.html", gin.H{
 | 
									200, "index.html", gin.H{
 | 
				
			||||||
					"Version": version,
 | 
										"Version": version,
 | 
				
			||||||
@@ -43,9 +39,9 @@ func SetRoute(r *gin.Engine) {
 | 
				
			|||||||
			)
 | 
								)
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	r.GET("/clash", handler.SubmodHandler)
 | 
						r.GET("/convert/:config", middleware.ZapLogger(), handler.ConvertHandler(config.GlobalConfig.ClashTemplate))
 | 
				
			||||||
	r.GET("/meta", handler.SubHandler)
 | 
						r.GET("/s/:hash", middleware.ZapLogger(), handler.GetRawConfHandler)
 | 
				
			||||||
	r.GET("/s/:hash", handler.GetRawConfHandler)
 | 
						r.POST("/short", middleware.ZapLogger(), handler.GenerateLinkHandler)
 | 
				
			||||||
	r.POST("/short", handler.GenerateLinkHandler)
 | 
						r.PUT("/short", middleware.ZapLogger(), handler.UpdateLinkHandler)
 | 
				
			||||||
	r.PUT("/short", handler.UpdateLinkHandler)
 | 
						r.GET("/short", middleware.ZapLogger(), handler.GetRawConfUriHandler)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										3
									
								
								server/static/axios.min.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								server/static/axios.min.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										7
									
								
								server/static/bootstrap.bundle.min.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								server/static/bootstrap.bundle.min.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										6
									
								
								server/static/bootstrap.min.css
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								server/static/bootstrap.min.css
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@@ -1,18 +1,16 @@
 | 
				
			|||||||
<!DOCTYPE html>
 | 
					<!DOCTYPE html>
 | 
				
			||||||
<html lang="zh-CN">
 | 
					<html lang="zh-CN" data-bs-theme="light">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<head>
 | 
					<head>
 | 
				
			||||||
    <meta charset="UTF-8" />
 | 
					    <meta charset="UTF-8" />
 | 
				
			||||||
    <meta content="width=device-width, initial-scale=1.0" name="viewport" />
 | 
					    <meta content="width=device-width, initial-scale=1.0" name="viewport" />
 | 
				
			||||||
    <title>sub2clash</title>
 | 
					    <title>sub2clash</title>
 | 
				
			||||||
    <!-- Bootstrap CSS -->
 | 
					    <!-- Bootstrap CSS -->
 | 
				
			||||||
    <link crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
 | 
					    <link href="./static/bootstrap.min.css" rel="stylesheet" />
 | 
				
			||||||
        integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" rel="stylesheet" />
 | 
					 | 
				
			||||||
    <!-- Bootstrap JS -->
 | 
					    <!-- Bootstrap JS -->
 | 
				
			||||||
    <script crossorigin="anonymous" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
 | 
					    <script src="./static/bootstrap.bundle.min.js"></script>
 | 
				
			||||||
        src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
 | 
					 | 
				
			||||||
    <!-- Axios -->
 | 
					    <!-- Axios -->
 | 
				
			||||||
    <script src="https://cdn.jsdelivr.net/npm/axios@latest/dist/axios.min.js"></script>
 | 
					    <script src="./static/axios.min.js"></script>
 | 
				
			||||||
    <style>
 | 
					    <style>
 | 
				
			||||||
        .container {
 | 
					        .container {
 | 
				
			||||||
            max-width: 800px;
 | 
					            max-width: 800px;
 | 
				
			||||||
@@ -30,15 +28,43 @@
 | 
				
			|||||||
            height: 25px;
 | 
					            height: 25px;
 | 
				
			||||||
            width: 25px;
 | 
					            width: 25px;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* 主题切换按钮样式 */
 | 
				
			||||||
 | 
					        .theme-toggle {
 | 
				
			||||||
 | 
					            position: fixed;
 | 
				
			||||||
 | 
					            top: 20px;
 | 
				
			||||||
 | 
					            right: 20px;
 | 
				
			||||||
 | 
					            z-index: 1000;
 | 
				
			||||||
 | 
					            border: none;
 | 
				
			||||||
 | 
					            border-radius: 50%;
 | 
				
			||||||
 | 
					            width: 50px;
 | 
				
			||||||
 | 
					            height: 50px;
 | 
				
			||||||
 | 
					            font-size: 20px;
 | 
				
			||||||
 | 
					            display: flex;
 | 
				
			||||||
 | 
					            align-items: center;
 | 
				
			||||||
 | 
					            justify-content: center;
 | 
				
			||||||
 | 
					            transition: all 0.3s ease;
 | 
				
			||||||
 | 
					            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        .theme-toggle:hover {
 | 
				
			||||||
 | 
					            transform: scale(1.1);
 | 
				
			||||||
 | 
					            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    </style>
 | 
					    </style>
 | 
				
			||||||
</head>
 | 
					</head>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<body class="bg-light">
 | 
					<body>
 | 
				
			||||||
 | 
					    <!-- 主题切换按钮 -->
 | 
				
			||||||
 | 
					    <button class="theme-toggle btn btn-outline-secondary" onclick="toggleTheme()" title="切换深色/浅色模式">
 | 
				
			||||||
 | 
					        <span id="theme-icon">🌙</span>
 | 
				
			||||||
 | 
					    </button>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <div class="container mt-5">
 | 
					    <div class="container mt-5">
 | 
				
			||||||
        <div class="mb-4">
 | 
					        <div class="mb-4">
 | 
				
			||||||
            <h2>sub2clash</h2>
 | 
					            <h2>sub2clash</h2>
 | 
				
			||||||
            <span class="text-muted fst-italic">通用订阅链接转 Clash(Meta) 配置工具
 | 
					            <span class="text-muted fst-italic">通用订阅链接转 Clash(Meta) 配置工具
 | 
				
			||||||
                <a href="https://github.com/nitezs/sub2clash#clash-meta" target="_blank">使用文档</a></span><br /><span
 | 
					                <a href="https://github.com/bestnite/sub2clash#clash-meta" target="_blank">使用文档</a></span><br /><span
 | 
				
			||||||
                class="text-muted fst-italic">注意:本程序非纯前端程序,输入的订阅将被后端缓存,请确保您信任当前站点</span>
 | 
					                class="text-muted fst-italic">注意:本程序非纯前端程序,输入的订阅将被后端缓存,请确保您信任当前站点</span>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -56,14 +82,14 @@
 | 
				
			|||||||
        <div class="form-group mb-3">
 | 
					        <div class="form-group mb-3">
 | 
				
			||||||
            <label for="endpoint">客户端类型:</label>
 | 
					            <label for="endpoint">客户端类型:</label>
 | 
				
			||||||
            <select class="form-control" id="endpoint" name="endpoint">
 | 
					            <select class="form-control" id="endpoint" name="endpoint">
 | 
				
			||||||
                <option value="clash">Clash</option>
 | 
					                <option value="1">Clash</option>
 | 
				
			||||||
                <option value="meta">Clash.Meta</option>
 | 
					                <option value="2" selected>Clash.Meta</option>
 | 
				
			||||||
            </select>
 | 
					            </select>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <!-- Template -->
 | 
					        <!-- Template -->
 | 
				
			||||||
        <div class="form-group mb-3">
 | 
					        <div class="form-group mb-3">
 | 
				
			||||||
            <label for="template">模板链接或名称:</label>
 | 
					            <label for="template">模板链接或名称:</label>
 | 
				
			||||||
            <input class="form-control" id="template" name="template" placeholder="输入外部模板链接或内部模板名称(可选)" type="text" />
 | 
					            <input class="form-control" id="template" name="template" placeholder="输入模板链接(可选)" type="text" />
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <!-- Subscription Link -->
 | 
					        <!-- Subscription Link -->
 | 
				
			||||||
        <div class="form-group mb-3">
 | 
					        <div class="form-group mb-3">
 | 
				
			||||||
@@ -75,6 +101,12 @@
 | 
				
			|||||||
            <label for="proxy">节点分享链接:</label>
 | 
					            <label for="proxy">节点分享链接:</label>
 | 
				
			||||||
            <textarea class="form-control" id="proxy" name="proxy" placeholder="每行输入一个节点分享链接" rows="5"></textarea>
 | 
					            <textarea class="form-control" id="proxy" name="proxy" placeholder="每行输入一个节点分享链接" rows="5"></textarea>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
 | 
					        <!-- User Agent -->
 | 
				
			||||||
 | 
					        <div class="form-group mb-3">
 | 
				
			||||||
 | 
					            <label for="user-agent">UA 标识:</label>
 | 
				
			||||||
 | 
					            <textarea class="form-control" id="user-agent" name="user-agent"
 | 
				
			||||||
 | 
					                placeholder="用于获取订阅的 http 请求中的 User-Agent 标识(可选)" rows="3"></textarea>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
        <!-- Refresh -->
 | 
					        <!-- Refresh -->
 | 
				
			||||||
        <div class="form-check mb-3">
 | 
					        <div class="form-check mb-3">
 | 
				
			||||||
            <input class="form-check-input" id="refresh" name="refresh" type="checkbox" />
 | 
					            <input class="form-check-input" id="refresh" name="refresh" type="checkbox" />
 | 
				
			||||||
@@ -100,6 +132,11 @@
 | 
				
			|||||||
            <input class="form-check-input" id="igcg" name="igcg" type="checkbox" />
 | 
					            <input class="form-check-input" id="igcg" name="igcg" type="checkbox" />
 | 
				
			||||||
            <label class="form-check-label" for="igcg">不输出国家策略组</label>
 | 
					            <label class="form-check-label" for="igcg">不输出国家策略组</label>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
 | 
					        <!-- Use UDP -->
 | 
				
			||||||
 | 
					        <div class="form-check mb-3">
 | 
				
			||||||
 | 
					            <input class="form-check-input" id="useUDP" name="useUDP" type="checkbox" />
 | 
				
			||||||
 | 
					            <label class="form-check-label" for="useUDP">使用 UDP</label>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
        <!-- Rule Provider -->
 | 
					        <!-- Rule Provider -->
 | 
				
			||||||
        <div class="form-group mb-3" id="ruleProviderGroup">
 | 
					        <div class="form-group mb-3" id="ruleProviderGroup">
 | 
				
			||||||
            <label>Rule Provider:</label>
 | 
					            <label>Rule Provider:</label>
 | 
				
			||||||
@@ -141,35 +178,42 @@
 | 
				
			|||||||
        <div class="form-group mb-5">
 | 
					        <div class="form-group mb-5">
 | 
				
			||||||
            <label for="apiLink">配置链接:</label>
 | 
					            <label for="apiLink">配置链接:</label>
 | 
				
			||||||
            <div class="input-group mb-2">
 | 
					            <div class="input-group mb-2">
 | 
				
			||||||
                <input class="form-control" id="apiLink" type="text" placeholder="链接" />
 | 
					                <input class="form-control" id="apiLink" type="text" placeholder="链接" readonly
 | 
				
			||||||
 | 
					                    style="cursor: not-allowed;" />
 | 
				
			||||||
 | 
					                <button class="btn btn-primary" onclick="generateURL()" type="button">生成配置</button>
 | 
				
			||||||
                <button class="btn btn-primary" onclick="copyToClipboard('apiLink',this)" type="button">
 | 
					                <button class="btn btn-primary" onclick="copyToClipboard('apiLink',this)" type="button">
 | 
				
			||||||
                    复制链接
 | 
					                    复制链接
 | 
				
			||||||
                </button>
 | 
					                </button>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <div class="input-group">
 | 
					            <div class="input-group mb-2">
 | 
				
			||||||
                <input class="form-control" id="apiShortLink" type="text" placeholder="链接" />
 | 
					                <input class="form-control" id="customId" type="text" placeholder="短链ID(可选)" />
 | 
				
			||||||
                <input class="form-control" id="password" type="text" placeholder="密码" />
 | 
					                <input class="form-control" id="password" type="text" placeholder="密码(可选)" />
 | 
				
			||||||
                <button class="btn btn-primary" onclick="generateShortLink()" type="button">
 | 
					                <button class="btn btn-primary" onclick="generateShortLink()" type="button">
 | 
				
			||||||
                    生成短链
 | 
					                    生成短链
 | 
				
			||||||
                </button>
 | 
					                </button>
 | 
				
			||||||
                <button class="btn btn-primary" onclick="updateShortLink()" type="button">
 | 
					 | 
				
			||||||
                    更新短链
 | 
					 | 
				
			||||||
                </button>
 | 
					 | 
				
			||||||
                <button class="btn btn-primary" onclick="copyToClipboard('apiShortLink',this)" type="button">
 | 
					                <button class="btn btn-primary" onclick="copyToClipboard('apiShortLink',this)" type="button">
 | 
				
			||||||
                    复制短链
 | 
					                    复制短链
 | 
				
			||||||
                </button>
 | 
					                </button>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
 | 
					            <div class="input-group">
 | 
				
			||||||
 | 
					                <input class="form-control" id="apiShortLink" type="text" placeholder="短链接" readonly
 | 
				
			||||||
 | 
					                    style="cursor: not-allowed;" />
 | 
				
			||||||
 | 
					                <button class="btn btn-primary" onclick="updateShortLink()" type="button">
 | 
				
			||||||
 | 
					                    更新短链
 | 
				
			||||||
 | 
					                </button>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <!-- footer-->
 | 
					        <!-- footer-->
 | 
				
			||||||
        <footer>
 | 
					        <footer>
 | 
				
			||||||
            <p class="text-center">
 | 
					            <p class="text-center">
 | 
				
			||||||
                Powered by
 | 
					                Powered by
 | 
				
			||||||
                <a class="link-primary" href="https://github.com/nitezs/sub2clash">sub2clash</a>
 | 
					                <a class="link-primary" href="https://github.com/bestnite/sub2clash">sub2clash</a>
 | 
				
			||||||
            </p>
 | 
					            </p>
 | 
				
			||||||
            <p class="text-center">Version {{.Version}}</p>
 | 
					            <p class="text-center">Version {{.Version}}</p>
 | 
				
			||||||
        </footer>
 | 
					        </footer>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
</body>
 | 
					</body>
 | 
				
			||||||
<script src="./static/index.js"></script>
 | 
					<script src="./static/index.js"></script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</html>
 | 
					</html>
 | 
				
			||||||
							
								
								
									
										597
									
								
								server/static/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										597
									
								
								server/static/index.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,597 @@
 | 
				
			|||||||
 | 
					function setInputReadOnly(input, readonly) {
 | 
				
			||||||
 | 
					  if (readonly) {
 | 
				
			||||||
 | 
					    input.readOnly = true;
 | 
				
			||||||
 | 
					    input.style.cursor = 'not-allowed';
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    input.readOnly = false;
 | 
				
			||||||
 | 
					    input.style.cursor = 'auto';
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function clearExistingValues() {
 | 
				
			||||||
 | 
					  // 清除简单输入框和复选框的值
 | 
				
			||||||
 | 
					  document.getElementById("endpoint").value = "clash";
 | 
				
			||||||
 | 
					  document.getElementById("sub").value = "";
 | 
				
			||||||
 | 
					  document.getElementById("proxy").value = "";
 | 
				
			||||||
 | 
					  document.getElementById("refresh").checked = false;
 | 
				
			||||||
 | 
					  document.getElementById("autoTest").checked = false;
 | 
				
			||||||
 | 
					  document.getElementById("lazy").checked = false;
 | 
				
			||||||
 | 
					  document.getElementById("igcg").checked = false;
 | 
				
			||||||
 | 
					  document.getElementById("useUDP").checked = false;
 | 
				
			||||||
 | 
					  document.getElementById("template").value = "";
 | 
				
			||||||
 | 
					  document.getElementById("sort").value = "nameasc";
 | 
				
			||||||
 | 
					  document.getElementById("remove").value = "";
 | 
				
			||||||
 | 
					  document.getElementById("apiLink").value = "";
 | 
				
			||||||
 | 
					  document.getElementById("apiShortLink").value = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 恢复短链ID和密码输入框状态
 | 
				
			||||||
 | 
					  const customIdInput = document.getElementById("customId");
 | 
				
			||||||
 | 
					  const passwordInput = document.getElementById("password");
 | 
				
			||||||
 | 
					  const generateButton = document.querySelector('button[onclick="generateShortLink()"]');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  customIdInput.value = "";
 | 
				
			||||||
 | 
					  setInputReadOnly(customIdInput, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  passwordInput.value = "";
 | 
				
			||||||
 | 
					  setInputReadOnly(passwordInput, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 恢复生成短链按钮状态
 | 
				
			||||||
 | 
					  generateButton.disabled = false;
 | 
				
			||||||
 | 
					  generateButton.classList.remove('btn-secondary');
 | 
				
			||||||
 | 
					  generateButton.classList.add('btn-primary');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  document.getElementById("nodeList").checked = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 清除由 createRuleProvider, createReplace, 和 createRule 创建的所有额外输入组
 | 
				
			||||||
 | 
					  clearInputGroup("ruleProviderGroup");
 | 
				
			||||||
 | 
					  clearInputGroup("replaceGroup");
 | 
				
			||||||
 | 
					  clearInputGroup("ruleGroup");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function generateURI() {
 | 
				
			||||||
 | 
					  const config = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  config.clashType = parseInt(document.getElementById("endpoint").value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let subLines = document
 | 
				
			||||||
 | 
					    .getElementById("sub")
 | 
				
			||||||
 | 
					    .value.split("\n")
 | 
				
			||||||
 | 
					    .filter((line) => line.trim() !== "");
 | 
				
			||||||
 | 
					  if (subLines.length > 0) {
 | 
				
			||||||
 | 
					    config.subscriptions = subLines;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let proxyLines = document
 | 
				
			||||||
 | 
					    .getElementById("proxy")
 | 
				
			||||||
 | 
					    .value.split("\n")
 | 
				
			||||||
 | 
					    .filter((line) => line.trim() !== "");
 | 
				
			||||||
 | 
					  if (proxyLines.length > 0) {
 | 
				
			||||||
 | 
					    config.proxies = proxyLines;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (
 | 
				
			||||||
 | 
					    (config.subscriptions === undefined || config.subscriptions.length === 0) &&
 | 
				
			||||||
 | 
					    (config.proxies === undefined || config.proxies.length === 0)
 | 
				
			||||||
 | 
					  ) {
 | 
				
			||||||
 | 
					    return "";
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  config.userAgent = document.getElementById("user-agent").value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  config.refresh = document.getElementById("refresh").checked;
 | 
				
			||||||
 | 
					  config.autoTest = document.getElementById("autoTest").checked;
 | 
				
			||||||
 | 
					  config.lazy = document.getElementById("lazy").checked;
 | 
				
			||||||
 | 
					  config.nodeList = document.getElementById("nodeList").checked;
 | 
				
			||||||
 | 
					  config.ignoreCountryGroup = document.getElementById("igcg").checked;
 | 
				
			||||||
 | 
					  config.useUDP = document.getElementById("useUDP").checked;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const template = document.getElementById("template").value;
 | 
				
			||||||
 | 
					  if (template.trim() !== "") {
 | 
				
			||||||
 | 
					    config.template = template;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const ruleProvidersElements = document.getElementsByName("ruleProvider");
 | 
				
			||||||
 | 
					  if (ruleProvidersElements.length > 0) {
 | 
				
			||||||
 | 
					    const ruleProviders = [];
 | 
				
			||||||
 | 
					    for (let i = 0; i < ruleProvidersElements.length / 5; i++) {
 | 
				
			||||||
 | 
					      let baseIndex = i * 5;
 | 
				
			||||||
 | 
					      let behavior = ruleProvidersElements[baseIndex].value;
 | 
				
			||||||
 | 
					      let url = ruleProvidersElements[baseIndex + 1].value;
 | 
				
			||||||
 | 
					      let group = ruleProvidersElements[baseIndex + 2].value;
 | 
				
			||||||
 | 
					      let prepend = ruleProvidersElements[baseIndex + 3].value;
 | 
				
			||||||
 | 
					      let name = ruleProvidersElements[baseIndex + 4].value;
 | 
				
			||||||
 | 
					      if (
 | 
				
			||||||
 | 
					        behavior.trim() === "" ||
 | 
				
			||||||
 | 
					        url.trim() === "" ||
 | 
				
			||||||
 | 
					        group.trim() === "" ||
 | 
				
			||||||
 | 
					        prepend.trim() === "" ||
 | 
				
			||||||
 | 
					        name.trim() === ""
 | 
				
			||||||
 | 
					      ) {
 | 
				
			||||||
 | 
					        return "";
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      ruleProviders.push({
 | 
				
			||||||
 | 
					        behavior: behavior,
 | 
				
			||||||
 | 
					        url: url,
 | 
				
			||||||
 | 
					        group: group,
 | 
				
			||||||
 | 
					        prepend: prepend.toLowerCase() === "true",
 | 
				
			||||||
 | 
					        name: name,
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (ruleProviders.length > 0) {
 | 
				
			||||||
 | 
					      config.ruleProviders = ruleProviders;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const rulesElements = document.getElementsByName("rule");
 | 
				
			||||||
 | 
					  if (rulesElements.length > 0) {
 | 
				
			||||||
 | 
					    const rules = [];
 | 
				
			||||||
 | 
					    for (let i = 0; i < rulesElements.length / 2; i++) {
 | 
				
			||||||
 | 
					      if (rulesElements[i * 2].value.trim() !== "") {
 | 
				
			||||||
 | 
					        let rule = rulesElements[i * 2].value;
 | 
				
			||||||
 | 
					        let prepend = rulesElements[i * 2 + 1].value;
 | 
				
			||||||
 | 
					        if (rule.trim() === "" || prepend.trim() === "") {
 | 
				
			||||||
 | 
					          return "";
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        rules.push({
 | 
				
			||||||
 | 
					          rule: rule,
 | 
				
			||||||
 | 
					          prepend: prepend.toLowerCase() === "true",
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (rules.length > 0) {
 | 
				
			||||||
 | 
					      config.rules = rules;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  config.sort = document.getElementById("sort").value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const remove = document.getElementById("remove").value;
 | 
				
			||||||
 | 
					  if (remove.trim() !== "") {
 | 
				
			||||||
 | 
					    config.remove = remove;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const replacesElements = document.getElementsByName("replace");
 | 
				
			||||||
 | 
					  if (replacesElements.length > 0) {
 | 
				
			||||||
 | 
					    const replace = {};
 | 
				
			||||||
 | 
					    for (let i = 0; i < replacesElements.length / 2; i++) {
 | 
				
			||||||
 | 
					      let replaceStr = replacesElements[i * 2].value;
 | 
				
			||||||
 | 
					      let replaceTo = replacesElements[i * 2 + 1].value;
 | 
				
			||||||
 | 
					      if (replaceStr.trim() === "") {
 | 
				
			||||||
 | 
					        return "";
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      replace[replaceStr] = replaceTo;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (Object.keys(replace).length > 0) {
 | 
				
			||||||
 | 
					      config.replace = replace;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const jsonString = JSON.stringify(config);
 | 
				
			||||||
 | 
					  // 解决 btoa 中文报错,使用 TextEncoder 进行 UTF-8 编码再 base64
 | 
				
			||||||
 | 
					  function base64EncodeUnicode(str) {
 | 
				
			||||||
 | 
					    const bytes = new TextEncoder().encode(str);
 | 
				
			||||||
 | 
					    let binary = '';
 | 
				
			||||||
 | 
					    bytes.forEach((b) => binary += String.fromCharCode(b));
 | 
				
			||||||
 | 
					    return btoa(binary);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  const encoded = base64EncodeUnicode(jsonString);
 | 
				
			||||||
 | 
					  const urlSafeBase64 = encoded
 | 
				
			||||||
 | 
					    .replace(/\+/g, "-")
 | 
				
			||||||
 | 
					    .replace(/\//g, "_")
 | 
				
			||||||
 | 
					    .replace(/=/g, "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return `convert/${urlSafeBase64}`;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 将输入框中的 URL 解析为参数
 | 
				
			||||||
 | 
					async function parseInputURL() {
 | 
				
			||||||
 | 
					  // 获取输入框中的 URL
 | 
				
			||||||
 | 
					  const inputURL = document.getElementById("urlInput").value;
 | 
				
			||||||
 | 
					  // 清除现有的输入框值
 | 
				
			||||||
 | 
					  clearExistingValues();
 | 
				
			||||||
 | 
					  if (!inputURL) {
 | 
				
			||||||
 | 
					    alert("请输入有效的链接!");
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let url;
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    url = new URL(inputURL);
 | 
				
			||||||
 | 
					  } catch (_) {
 | 
				
			||||||
 | 
					    alert("无效的链接!");
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (url.pathname.includes("/s/")) {
 | 
				
			||||||
 | 
					    let hash = url.pathname.substring(url.pathname.lastIndexOf("/s/") + 3);
 | 
				
			||||||
 | 
					    let q = new URLSearchParams();
 | 
				
			||||||
 | 
					    let password = url.searchParams.get("password");
 | 
				
			||||||
 | 
					    if (password === null) {
 | 
				
			||||||
 | 
					      alert("仅可解析加密短链");
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    q.append("hash", hash);
 | 
				
			||||||
 | 
					    q.append("password", password);
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      const response = await axios.get("./short?" + q.toString());
 | 
				
			||||||
 | 
					      url = new URL(response.data, window.location.href);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // 回显配置链接
 | 
				
			||||||
 | 
					      const apiLinkInput = document.querySelector("#apiLink");
 | 
				
			||||||
 | 
					      apiLinkInput.value = url.href;
 | 
				
			||||||
 | 
					      setInputReadOnly(apiLinkInput, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // 回显短链相关信息
 | 
				
			||||||
 | 
					      const apiShortLinkInput = document.querySelector("#apiShortLink");
 | 
				
			||||||
 | 
					      apiShortLinkInput.value = inputURL;
 | 
				
			||||||
 | 
					      setInputReadOnly(apiShortLinkInput, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // 设置短链ID和密码,并设置为只读
 | 
				
			||||||
 | 
					      const customIdInput = document.querySelector("#customId");
 | 
				
			||||||
 | 
					      const passwordInput = document.querySelector("#password");
 | 
				
			||||||
 | 
					      const generateButton = document.querySelector('button[onclick="generateShortLink()"]');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      customIdInput.value = hash;
 | 
				
			||||||
 | 
					      setInputReadOnly(customIdInput, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      passwordInput.value = password;
 | 
				
			||||||
 | 
					      setInputReadOnly(passwordInput, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // 禁用生成短链按钮
 | 
				
			||||||
 | 
					      generateButton.disabled = true;
 | 
				
			||||||
 | 
					      generateButton.classList.add('btn-secondary');
 | 
				
			||||||
 | 
					      generateButton.classList.remove('btn-primary');
 | 
				
			||||||
 | 
					    } catch (error) {
 | 
				
			||||||
 | 
					      console.log(error);
 | 
				
			||||||
 | 
					      alert("获取短链失败,请检查密码!");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  const pathSections = url.pathname.split("/");
 | 
				
			||||||
 | 
					  const convertIndex = pathSections.findIndex((s) => s === "convert");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (convertIndex === -1 || convertIndex + 1 >= pathSections.length) {
 | 
				
			||||||
 | 
					    alert("无效的配置链接,请确认链接为新版格式。");
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  const base64Config = pathSections[convertIndex + 1];
 | 
				
			||||||
 | 
					  let config;
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    const regularBase64 = base64Config.replace(/-/g, "+").replace(/_/g, "/");
 | 
				
			||||||
 | 
					    const decodedStr = atob(regularBase64);
 | 
				
			||||||
 | 
					    config = JSON.parse(decodeURIComponent(escape(decodedStr)));
 | 
				
			||||||
 | 
					  } catch (e) {
 | 
				
			||||||
 | 
					    alert("解析配置失败!");
 | 
				
			||||||
 | 
					    console.error(e);
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  document.getElementById("endpoint").value = config.clashType || "1";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (config.subscriptions) {
 | 
				
			||||||
 | 
					    document.getElementById("sub").value = config.subscriptions.join("\n");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (config.proxies) {
 | 
				
			||||||
 | 
					    document.getElementById("proxy").value = config.proxies.join("\n");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (config.refresh) {
 | 
				
			||||||
 | 
					    document.getElementById("refresh").checked = config.refresh;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (config.autoTest) {
 | 
				
			||||||
 | 
					    document.getElementById("autoTest").checked = config.autoTest;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (config.lazy) {
 | 
				
			||||||
 | 
					    document.getElementById("lazy").checked = config.lazy;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (config.template) {
 | 
				
			||||||
 | 
					    document.getElementById("template").value = config.template;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (config.sort) {
 | 
				
			||||||
 | 
					    document.getElementById("sort").value = config.sort;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (config.remove) {
 | 
				
			||||||
 | 
					    document.getElementById("remove").value = config.remove;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (config.userAgent) {
 | 
				
			||||||
 | 
					    document.getElementById("user-agent").value = config.userAgent;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (config.ignoreCountryGroup) {
 | 
				
			||||||
 | 
					    document.getElementById("igcg").checked = config.ignoreCountryGroup;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (config.replace) {
 | 
				
			||||||
 | 
					    const replaceGroup = document.getElementById("replaceGroup");
 | 
				
			||||||
 | 
					    for (const original in config.replace) {
 | 
				
			||||||
 | 
					      const div = createReplace();
 | 
				
			||||||
 | 
					      div.children[0].value = original;
 | 
				
			||||||
 | 
					      div.children[1].value = config.replace[original];
 | 
				
			||||||
 | 
					      replaceGroup.appendChild(div);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (config.ruleProviders) {
 | 
				
			||||||
 | 
					    const ruleProviderGroup = document.getElementById("ruleProviderGroup");
 | 
				
			||||||
 | 
					    for (const p of config.ruleProviders) {
 | 
				
			||||||
 | 
					      const div = createRuleProvider();
 | 
				
			||||||
 | 
					      div.children[0].value = p.behavior;
 | 
				
			||||||
 | 
					      div.children[1].value = p.url;
 | 
				
			||||||
 | 
					      div.children[2].value = p.group;
 | 
				
			||||||
 | 
					      div.children[3].value = p.prepend;
 | 
				
			||||||
 | 
					      div.children[4].value = p.name;
 | 
				
			||||||
 | 
					      ruleProviderGroup.appendChild(div);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (config.rules) {
 | 
				
			||||||
 | 
					    const ruleGroup = document.getElementById("ruleGroup");
 | 
				
			||||||
 | 
					    for (const r of config.rules) {
 | 
				
			||||||
 | 
					      const div = createRule();
 | 
				
			||||||
 | 
					      div.children[0].value = r.rule;
 | 
				
			||||||
 | 
					      div.children[1].value = r.prepend;
 | 
				
			||||||
 | 
					      ruleGroup.appendChild(div);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (config.nodeList) {
 | 
				
			||||||
 | 
					    document.getElementById("nodeList").checked = config.nodeList;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (config.useUDP) {
 | 
				
			||||||
 | 
					    document.getElementById("useUDP").checked = config.useUDP;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function clearInputGroup(groupId) {
 | 
				
			||||||
 | 
					  // 清空第二个之后的child
 | 
				
			||||||
 | 
					  const group = document.getElementById(groupId);
 | 
				
			||||||
 | 
					  while (group.children.length > 2) {
 | 
				
			||||||
 | 
					    group.removeChild(group.lastChild);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async function copyToClipboard(elem, e) {
 | 
				
			||||||
 | 
					  const apiLinkInput = document.querySelector(`#${elem}`).value;
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    await navigator.clipboard.writeText(apiLinkInput);
 | 
				
			||||||
 | 
					    let text = e.textContent;
 | 
				
			||||||
 | 
					    e.addEventListener("mouseout", function () {
 | 
				
			||||||
 | 
					      e.textContent = text;
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    e.textContent = "复制成功";
 | 
				
			||||||
 | 
					  } catch (err) {
 | 
				
			||||||
 | 
					    console.error("复制到剪贴板失败:", err);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function createRuleProvider() {
 | 
				
			||||||
 | 
					  const div = document.createElement("div");
 | 
				
			||||||
 | 
					  div.classList.add("input-group", "mb-2");
 | 
				
			||||||
 | 
					  div.innerHTML = `
 | 
				
			||||||
 | 
					            <input type="text" class="form-control" name="ruleProvider" placeholder="Behavior">
 | 
				
			||||||
 | 
					            <input type="text" class="form-control" name="ruleProvider" placeholder="Url">
 | 
				
			||||||
 | 
					            <input type="text" class="form-control" name="ruleProvider" placeholder="Group">
 | 
				
			||||||
 | 
					            <input type="text" class="form-control" name="ruleProvider" placeholder="Prepend">
 | 
				
			||||||
 | 
					            <input type="text" class="form-control" name="ruleProvider" placeholder="Name">
 | 
				
			||||||
 | 
					            <button type="button" class="btn btn-danger" onclick="removeElement(this)">删除</button>
 | 
				
			||||||
 | 
					        `;
 | 
				
			||||||
 | 
					  return div;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function createReplace() {
 | 
				
			||||||
 | 
					  const div = document.createElement("div");
 | 
				
			||||||
 | 
					  div.classList.add("input-group", "mb-2");
 | 
				
			||||||
 | 
					  div.innerHTML = `
 | 
				
			||||||
 | 
					            <input type="text" class="form-control" name="replace" placeholder="原字符串(正则表达式)">
 | 
				
			||||||
 | 
					            <input type="text" class="form-control" name="replace" placeholder="替换为(可为空)">
 | 
				
			||||||
 | 
					            <button type="button" class="btn btn-danger" onclick="removeElement(this)">删除</button>
 | 
				
			||||||
 | 
					        `;
 | 
				
			||||||
 | 
					  return div;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function createRule() {
 | 
				
			||||||
 | 
					  const div = document.createElement("div");
 | 
				
			||||||
 | 
					  div.classList.add("input-group", "mb-2");
 | 
				
			||||||
 | 
					  div.innerHTML = `
 | 
				
			||||||
 | 
					            <input type="text" class="form-control" name="rule" placeholder="Rule">
 | 
				
			||||||
 | 
					            <input type="text" class="form-control" name="rule" placeholder="Prepend">
 | 
				
			||||||
 | 
					            <button type="button" class="btn btn-danger" onclick="removeElement(this)">删除</button>
 | 
				
			||||||
 | 
					        `;
 | 
				
			||||||
 | 
					  return div;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function listenInput() {
 | 
				
			||||||
 | 
					  let selectElements = document.querySelectorAll("select");
 | 
				
			||||||
 | 
					  let inputElements = document.querySelectorAll("input");
 | 
				
			||||||
 | 
					  let textAreaElements = document.querySelectorAll("textarea");
 | 
				
			||||||
 | 
					  inputElements.forEach(function (element) {
 | 
				
			||||||
 | 
					    element.addEventListener("input", function () {
 | 
				
			||||||
 | 
					      generateURL();
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  textAreaElements.forEach(function (element) {
 | 
				
			||||||
 | 
					    element.addEventListener("input", function () {
 | 
				
			||||||
 | 
					      generateURL();
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  selectElements.forEach(function (element) {
 | 
				
			||||||
 | 
					    element.addEventListener("change", function () {
 | 
				
			||||||
 | 
					      generateURL();
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function addRuleProvider() {
 | 
				
			||||||
 | 
					  const div = createRuleProvider();
 | 
				
			||||||
 | 
					  document.getElementById("ruleProviderGroup").appendChild(div);
 | 
				
			||||||
 | 
					  listenInput();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function addRule() {
 | 
				
			||||||
 | 
					  const div = createRule();
 | 
				
			||||||
 | 
					  document.getElementById("ruleGroup").appendChild(div);
 | 
				
			||||||
 | 
					  listenInput();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function addReplace() {
 | 
				
			||||||
 | 
					  const div = createReplace();
 | 
				
			||||||
 | 
					  document.getElementById("replaceGroup").appendChild(div);
 | 
				
			||||||
 | 
					  listenInput();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function removeElement(button) {
 | 
				
			||||||
 | 
					  button.parentElement.remove();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function generateURL() {
 | 
				
			||||||
 | 
					  const apiLink = document.getElementById("apiLink");
 | 
				
			||||||
 | 
					  let uri = generateURI();
 | 
				
			||||||
 | 
					  if (uri === "") {
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  apiLink.value = `${window.location.origin}${window.location.pathname}${uri}`;
 | 
				
			||||||
 | 
					  setInputReadOnly(apiLink, true);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function generateShortLink() {
 | 
				
			||||||
 | 
					  const apiShortLink = document.getElementById("apiShortLink");
 | 
				
			||||||
 | 
					  const password = document.getElementById("password");
 | 
				
			||||||
 | 
					  const customId = document.getElementById("customId");
 | 
				
			||||||
 | 
					  let uri = generateURI();
 | 
				
			||||||
 | 
					  if (uri === "") {
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  axios
 | 
				
			||||||
 | 
					    .post(
 | 
				
			||||||
 | 
					      "./short",
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        url: uri,
 | 
				
			||||||
 | 
					        password: password.value.trim(),
 | 
				
			||||||
 | 
					        customId: customId.value.trim()
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        headers: {
 | 
				
			||||||
 | 
					          "Content-Type": "application/json",
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    .then((response) => {
 | 
				
			||||||
 | 
					      // 设置返回的短链ID和密码
 | 
				
			||||||
 | 
					      customId.value = response.data.hash;
 | 
				
			||||||
 | 
					      password.value = response.data.password;
 | 
				
			||||||
 | 
					      // 生成完整的短链接
 | 
				
			||||||
 | 
					      const shortLink = `${window.location.origin}${window.location.pathname}s/${response.data.hash}?password=${response.data.password}`;
 | 
				
			||||||
 | 
					      apiShortLink.value = shortLink;
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    .catch((error) => {
 | 
				
			||||||
 | 
					      console.log(error);
 | 
				
			||||||
 | 
					      if (error.response && error.response.data) {
 | 
				
			||||||
 | 
					        alert(error.response.data);
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        alert("生成短链失败,请重试!");
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function updateShortLink() {
 | 
				
			||||||
 | 
					  const password = document.getElementById("password");
 | 
				
			||||||
 | 
					  const apiShortLink = document.getElementById("apiShortLink");
 | 
				
			||||||
 | 
					  let hash = apiShortLink.value;
 | 
				
			||||||
 | 
					  if (hash.startsWith("http")) {
 | 
				
			||||||
 | 
					    let u = new URL(hash);
 | 
				
			||||||
 | 
					    hash = u.pathname.substring(u.pathname.lastIndexOf("/s/") + 3);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (password.value.trim() === "") {
 | 
				
			||||||
 | 
					    alert("请输入原密码进行验证!");
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  let uri = generateURI();
 | 
				
			||||||
 | 
					  if (uri === "") {
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  axios
 | 
				
			||||||
 | 
					    .put(
 | 
				
			||||||
 | 
					      "./short",
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        hash: hash,
 | 
				
			||||||
 | 
					        url: uri,
 | 
				
			||||||
 | 
					        password: password.value.trim(),
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        headers: {
 | 
				
			||||||
 | 
					          "Content-Type": "application/json",
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    .then((response) => {
 | 
				
			||||||
 | 
					      alert(`短链 ${hash} 更新成功!`);
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    .catch((error) => {
 | 
				
			||||||
 | 
					      console.log(error);
 | 
				
			||||||
 | 
					      if (error.response && error.response.status === 401) {
 | 
				
			||||||
 | 
					        alert("密码错误,请输入正确的原密码!");
 | 
				
			||||||
 | 
					      } else if (error.response && error.response.data) {
 | 
				
			||||||
 | 
					        alert(error.response.data);
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        alert("更新短链失败,请重试!");
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 主题切换功能
 | 
				
			||||||
 | 
					function initTheme() {
 | 
				
			||||||
 | 
					  const html = document.querySelector('html');
 | 
				
			||||||
 | 
					  const themeIcon = document.getElementById('theme-icon');
 | 
				
			||||||
 | 
					  let theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 从localStorage获取用户偏好的主题
 | 
				
			||||||
 | 
					  const savedTheme = localStorage.getItem('theme');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (savedTheme) {
 | 
				
			||||||
 | 
					    // 如果用户之前设置过主题,使用保存的主题
 | 
				
			||||||
 | 
					    theme = savedTheme;
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    // 如果没有设置过,检测系统主题偏好
 | 
				
			||||||
 | 
					    const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
 | 
				
			||||||
 | 
					    theme = prefersDark ? 'dark' : 'light';
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 设置主题
 | 
				
			||||||
 | 
					  html.setAttribute('data-bs-theme', theme);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 更新图标
 | 
				
			||||||
 | 
					  if (theme === 'dark') {
 | 
				
			||||||
 | 
					    themeIcon.textContent = '☀️';
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    themeIcon.textContent = '🌙';
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function toggleTheme() {
 | 
				
			||||||
 | 
					  const html = document.querySelector('html');
 | 
				
			||||||
 | 
					  const currentTheme = html.getAttribute('data-bs-theme');
 | 
				
			||||||
 | 
					  // 切换主题
 | 
				
			||||||
 | 
					  const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
 | 
				
			||||||
 | 
					  html.setAttribute('data-bs-theme', newTheme);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 更新图标
 | 
				
			||||||
 | 
					  if (newTheme === 'dark') {
 | 
				
			||||||
 | 
					    themeIcon.textContent = '☀️';
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    themeIcon.textContent = '🌙';
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 保存用户偏好到localStorage
 | 
				
			||||||
 | 
					  localStorage.setItem('theme', newTheme);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					listenInput();
 | 
				
			||||||
 | 
					initTheme();
 | 
				
			||||||
							
								
								
									
										219
									
								
								test/parser/anytls_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										219
									
								
								test/parser/anytls_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,219 @@
 | 
				
			|||||||
 | 
					package test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/parser"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestAnytls_Basic_SimpleLink(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.AnytlsParser{}
 | 
				
			||||||
 | 
						input := "anytls://password123@127.0.0.1:8080#Anytls%20Proxy"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "anytls",
 | 
				
			||||||
 | 
							Name: "Anytls Proxy",
 | 
				
			||||||
 | 
							Anytls: proxy.Anytls{
 | 
				
			||||||
 | 
								Server:         "127.0.0.1",
 | 
				
			||||||
 | 
								Port:           8080,
 | 
				
			||||||
 | 
								Password:       "password123",
 | 
				
			||||||
 | 
								SkipCertVerify: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestAnytls_Basic_WithSNI(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.AnytlsParser{}
 | 
				
			||||||
 | 
						input := "anytls://password123@proxy.example.com:443?sni=proxy.example.com#Anytls%20SNI"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "anytls",
 | 
				
			||||||
 | 
							Name: "Anytls SNI",
 | 
				
			||||||
 | 
							Anytls: proxy.Anytls{
 | 
				
			||||||
 | 
								Server:         "proxy.example.com",
 | 
				
			||||||
 | 
								Port:           443,
 | 
				
			||||||
 | 
								Password:       "password123",
 | 
				
			||||||
 | 
								SNI:            "proxy.example.com",
 | 
				
			||||||
 | 
								SkipCertVerify: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestAnytls_Basic_WithInsecure(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.AnytlsParser{}
 | 
				
			||||||
 | 
						input := "anytls://password123@proxy.example.com:443?insecure=1&sni=proxy.example.com#Anytls%20Insecure"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "anytls",
 | 
				
			||||||
 | 
							Name: "Anytls Insecure",
 | 
				
			||||||
 | 
							Anytls: proxy.Anytls{
 | 
				
			||||||
 | 
								Server:         "proxy.example.com",
 | 
				
			||||||
 | 
								Port:           443,
 | 
				
			||||||
 | 
								Password:       "password123",
 | 
				
			||||||
 | 
								SNI:            "proxy.example.com",
 | 
				
			||||||
 | 
								SkipCertVerify: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestAnytls_Basic_IPv6Address(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.AnytlsParser{}
 | 
				
			||||||
 | 
						input := "anytls://password123@[2001:db8::1]:8080#Anytls%20IPv6"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "anytls",
 | 
				
			||||||
 | 
							Name: "Anytls IPv6",
 | 
				
			||||||
 | 
							Anytls: proxy.Anytls{
 | 
				
			||||||
 | 
								Server:         "2001:db8::1",
 | 
				
			||||||
 | 
								Port:           8080,
 | 
				
			||||||
 | 
								Password:       "password123",
 | 
				
			||||||
 | 
								SkipCertVerify: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestAnytls_Basic_ComplexPassword(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.AnytlsParser{}
 | 
				
			||||||
 | 
						input := "anytls://ComplexPassword!%40%23%24@proxy.example.com:8443?sni=example.com&insecure=1#Anytls%20Full"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "anytls",
 | 
				
			||||||
 | 
							Name: "Anytls Full",
 | 
				
			||||||
 | 
							Anytls: proxy.Anytls{
 | 
				
			||||||
 | 
								Server:         "proxy.example.com",
 | 
				
			||||||
 | 
								Port:           8443,
 | 
				
			||||||
 | 
								Password:       "ComplexPassword!@#$",
 | 
				
			||||||
 | 
								SNI:            "example.com",
 | 
				
			||||||
 | 
								SkipCertVerify: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestAnytls_Basic_NoPassword(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.AnytlsParser{}
 | 
				
			||||||
 | 
						input := "anytls://@127.0.0.1:8080#No%20Password"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "anytls",
 | 
				
			||||||
 | 
							Name: "No Password",
 | 
				
			||||||
 | 
							Anytls: proxy.Anytls{
 | 
				
			||||||
 | 
								Server:         "127.0.0.1",
 | 
				
			||||||
 | 
								Port:           8080,
 | 
				
			||||||
 | 
								Password:       "",
 | 
				
			||||||
 | 
								SkipCertVerify: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestAnytls_Basic_UsernameOnly(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.AnytlsParser{}
 | 
				
			||||||
 | 
						input := "anytls://username@127.0.0.1:8080#Username%20Only"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "anytls",
 | 
				
			||||||
 | 
							Name: "Username Only",
 | 
				
			||||||
 | 
							Anytls: proxy.Anytls{
 | 
				
			||||||
 | 
								Server:         "127.0.0.1",
 | 
				
			||||||
 | 
								Port:           8080,
 | 
				
			||||||
 | 
								Password:       "username",
 | 
				
			||||||
 | 
								SkipCertVerify: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestAnytls_Error_MissingServer(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.AnytlsParser{}
 | 
				
			||||||
 | 
						input := "anytls://password123@:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestAnytls_Error_MissingPort(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.AnytlsParser{}
 | 
				
			||||||
 | 
						input := "anytls://password123@127.0.0.1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestAnytls_Error_InvalidPort(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.AnytlsParser{}
 | 
				
			||||||
 | 
						input := "anytls://password123@127.0.0.1:99999"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestAnytls_Error_InvalidProtocol(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.AnytlsParser{}
 | 
				
			||||||
 | 
						input := "anyssl://example.com:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										198
									
								
								test/parser/hysteria2_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										198
									
								
								test/parser/hysteria2_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,198 @@
 | 
				
			|||||||
 | 
					package test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/parser"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria2_Basic_SimpleLink(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.Hysteria2Parser{}
 | 
				
			||||||
 | 
						input := "hysteria2://password123@127.0.0.1:8080#Hysteria2%20Proxy"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "hysteria2",
 | 
				
			||||||
 | 
							Name: "Hysteria2 Proxy",
 | 
				
			||||||
 | 
							Hysteria2: proxy.Hysteria2{
 | 
				
			||||||
 | 
								Server:         "127.0.0.1",
 | 
				
			||||||
 | 
								Port:           8080,
 | 
				
			||||||
 | 
								Password:       "password123",
 | 
				
			||||||
 | 
								SkipCertVerify: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria2_Basic_AltPrefix(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.Hysteria2Parser{}
 | 
				
			||||||
 | 
						input := "hy2://password123@proxy.example.com:443?insecure=1&sni=proxy.example.com#Hysteria2%20Alt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "hysteria2",
 | 
				
			||||||
 | 
							Name: "Hysteria2 Alt",
 | 
				
			||||||
 | 
							Hysteria2: proxy.Hysteria2{
 | 
				
			||||||
 | 
								Server:         "proxy.example.com",
 | 
				
			||||||
 | 
								Port:           443,
 | 
				
			||||||
 | 
								Password:       "password123",
 | 
				
			||||||
 | 
								SNI:            "proxy.example.com",
 | 
				
			||||||
 | 
								SkipCertVerify: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria2_Basic_WithObfs(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.Hysteria2Parser{}
 | 
				
			||||||
 | 
						input := "hysteria2://password123@127.0.0.1:8080?obfs=salamander&obfs-password=obfs123#Hysteria2%20Obfs"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "hysteria2",
 | 
				
			||||||
 | 
							Name: "Hysteria2 Obfs",
 | 
				
			||||||
 | 
							Hysteria2: proxy.Hysteria2{
 | 
				
			||||||
 | 
								Server:         "127.0.0.1",
 | 
				
			||||||
 | 
								Port:           8080,
 | 
				
			||||||
 | 
								Password:       "password123",
 | 
				
			||||||
 | 
								Obfs:           "salamander",
 | 
				
			||||||
 | 
								ObfsPassword:   "obfs123",
 | 
				
			||||||
 | 
								SkipCertVerify: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria2_Basic_IPv6Address(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.Hysteria2Parser{}
 | 
				
			||||||
 | 
						input := "hysteria2://password123@[2001:db8::1]:8080#Hysteria2%20IPv6"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "hysteria2",
 | 
				
			||||||
 | 
							Name: "Hysteria2 IPv6",
 | 
				
			||||||
 | 
							Hysteria2: proxy.Hysteria2{
 | 
				
			||||||
 | 
								Server:         "2001:db8::1",
 | 
				
			||||||
 | 
								Port:           8080,
 | 
				
			||||||
 | 
								Password:       "password123",
 | 
				
			||||||
 | 
								SkipCertVerify: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria2_Basic_FullConfig(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.Hysteria2Parser{}
 | 
				
			||||||
 | 
						input := "hysteria2://password123@proxy.example.com:443?insecure=1&sni=proxy.example.com&obfs=salamander&obfs-password=obfs123#Hysteria2%20Full"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "hysteria2",
 | 
				
			||||||
 | 
							Name: "Hysteria2 Full",
 | 
				
			||||||
 | 
							Hysteria2: proxy.Hysteria2{
 | 
				
			||||||
 | 
								Server:         "proxy.example.com",
 | 
				
			||||||
 | 
								Port:           443,
 | 
				
			||||||
 | 
								Password:       "password123",
 | 
				
			||||||
 | 
								SNI:            "proxy.example.com",
 | 
				
			||||||
 | 
								Obfs:           "salamander",
 | 
				
			||||||
 | 
								ObfsPassword:   "obfs123",
 | 
				
			||||||
 | 
								SkipCertVerify: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria2_Basic_NoPassword(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.Hysteria2Parser{}
 | 
				
			||||||
 | 
						input := "hysteria2://@127.0.0.1:8080#No%20Password"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "hysteria2",
 | 
				
			||||||
 | 
							Name: "No Password",
 | 
				
			||||||
 | 
							Hysteria2: proxy.Hysteria2{
 | 
				
			||||||
 | 
								Server:         "127.0.0.1",
 | 
				
			||||||
 | 
								Port:           8080,
 | 
				
			||||||
 | 
								Password:       "",
 | 
				
			||||||
 | 
								SkipCertVerify: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria2_Error_MissingServer(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.Hysteria2Parser{}
 | 
				
			||||||
 | 
						input := "hysteria2://password123@:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria2_Error_MissingPort(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.Hysteria2Parser{}
 | 
				
			||||||
 | 
						input := "hysteria2://password123@127.0.0.1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria2_Error_InvalidPort(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.Hysteria2Parser{}
 | 
				
			||||||
 | 
						input := "hysteria2://password123@127.0.0.1:99999"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria2_Error_InvalidProtocol(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.Hysteria2Parser{}
 | 
				
			||||||
 | 
						input := "hysteria://example.com:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										183
									
								
								test/parser/hysteria_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										183
									
								
								test/parser/hysteria_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,183 @@
 | 
				
			|||||||
 | 
					package test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/parser"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria_Basic_SimpleLink(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.HysteriaParser{}
 | 
				
			||||||
 | 
						input := "hysteria://127.0.0.1:8080?protocol=udp&auth=password123&upmbps=100&downmbps=100#Hysteria%20Proxy"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "hysteria",
 | 
				
			||||||
 | 
							Name: "Hysteria Proxy",
 | 
				
			||||||
 | 
							Hysteria: proxy.Hysteria{
 | 
				
			||||||
 | 
								Server:         "127.0.0.1",
 | 
				
			||||||
 | 
								Port:           8080,
 | 
				
			||||||
 | 
								Protocol:       "udp",
 | 
				
			||||||
 | 
								Auth:           "password123",
 | 
				
			||||||
 | 
								Up:             "100",
 | 
				
			||||||
 | 
								Down:           "100",
 | 
				
			||||||
 | 
								SkipCertVerify: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria_Basic_WithAuthString(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.HysteriaParser{}
 | 
				
			||||||
 | 
						input := "hysteria://proxy.example.com:443?protocol=wechat-video&auth-str=myauth&upmbps=50&downmbps=200&insecure=true#Hysteria%20Auth"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "hysteria",
 | 
				
			||||||
 | 
							Name: "Hysteria Auth",
 | 
				
			||||||
 | 
							Hysteria: proxy.Hysteria{
 | 
				
			||||||
 | 
								Server:         "proxy.example.com",
 | 
				
			||||||
 | 
								Port:           443,
 | 
				
			||||||
 | 
								Protocol:       "wechat-video",
 | 
				
			||||||
 | 
								AuthString:     "myauth",
 | 
				
			||||||
 | 
								Up:             "50",
 | 
				
			||||||
 | 
								Down:           "200",
 | 
				
			||||||
 | 
								SkipCertVerify: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria_Basic_WithObfs(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.HysteriaParser{}
 | 
				
			||||||
 | 
						input := "hysteria://127.0.0.1:8080?auth=password123&upmbps=100&downmbps=100&obfs=xplus&alpn=h3#Hysteria%20Obfs"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "hysteria",
 | 
				
			||||||
 | 
							Name: "Hysteria Obfs",
 | 
				
			||||||
 | 
							Hysteria: proxy.Hysteria{
 | 
				
			||||||
 | 
								Server:         "127.0.0.1",
 | 
				
			||||||
 | 
								Port:           8080,
 | 
				
			||||||
 | 
								Auth:           "password123",
 | 
				
			||||||
 | 
								Up:             "100",
 | 
				
			||||||
 | 
								Down:           "100",
 | 
				
			||||||
 | 
								Obfs:           "xplus",
 | 
				
			||||||
 | 
								ALPN:           []string{"h3"},
 | 
				
			||||||
 | 
								SkipCertVerify: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria_Basic_IPv6Address(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.HysteriaParser{}
 | 
				
			||||||
 | 
						input := "hysteria://[2001:db8::1]:8080?auth=password123&upmbps=100&downmbps=100#Hysteria%20IPv6"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "hysteria",
 | 
				
			||||||
 | 
							Name: "Hysteria IPv6",
 | 
				
			||||||
 | 
							Hysteria: proxy.Hysteria{
 | 
				
			||||||
 | 
								Server:         "2001:db8::1",
 | 
				
			||||||
 | 
								Port:           8080,
 | 
				
			||||||
 | 
								Auth:           "password123",
 | 
				
			||||||
 | 
								Up:             "100",
 | 
				
			||||||
 | 
								Down:           "100",
 | 
				
			||||||
 | 
								SkipCertVerify: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria_Basic_MultiALPN(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.HysteriaParser{}
 | 
				
			||||||
 | 
						input := "hysteria://proxy.example.com:443?auth=password123&upmbps=100&downmbps=100&alpn=h3,h2,http/1.1#Hysteria%20Multi%20ALPN"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "hysteria",
 | 
				
			||||||
 | 
							Name: "Hysteria Multi ALPN",
 | 
				
			||||||
 | 
							Hysteria: proxy.Hysteria{
 | 
				
			||||||
 | 
								Server:         "proxy.example.com",
 | 
				
			||||||
 | 
								Port:           443,
 | 
				
			||||||
 | 
								Auth:           "password123",
 | 
				
			||||||
 | 
								Up:             "100",
 | 
				
			||||||
 | 
								Down:           "100",
 | 
				
			||||||
 | 
								ALPN:           []string{"h3", "h2", "http/1.1"},
 | 
				
			||||||
 | 
								SkipCertVerify: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria_Error_MissingServer(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.HysteriaParser{}
 | 
				
			||||||
 | 
						input := "hysteria://:8080?auth=password123"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria_Error_MissingPort(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.HysteriaParser{}
 | 
				
			||||||
 | 
						input := "hysteria://127.0.0.1?auth=password123"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria_Error_InvalidPort(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.HysteriaParser{}
 | 
				
			||||||
 | 
						input := "hysteria://127.0.0.1:99999?auth=password123"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHysteria_Error_InvalidProtocol(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.HysteriaParser{}
 | 
				
			||||||
 | 
						input := "hysteria2://example.com:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										184
									
								
								test/parser/shadowsocks_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										184
									
								
								test/parser/shadowsocks_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,184 @@
 | 
				
			|||||||
 | 
					package test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/parser"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestShadowsocks_Basic_SimpleLink(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.ShadowsocksParser{}
 | 
				
			||||||
 | 
						input := "ss://YWVzLTI1Ni1nY206cGFzc3dvcmQ=@127.0.0.1:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "ss",
 | 
				
			||||||
 | 
							Name: "127.0.0.1:8080",
 | 
				
			||||||
 | 
							ShadowSocks: proxy.ShadowSocks{
 | 
				
			||||||
 | 
								Server:   "127.0.0.1",
 | 
				
			||||||
 | 
								Port:     8080,
 | 
				
			||||||
 | 
								Cipher:   "aes-256-gcm",
 | 
				
			||||||
 | 
								Password: "password",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestShadowsocks_Basic_IPv6Address(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.ShadowsocksParser{}
 | 
				
			||||||
 | 
						input := "ss://YWVzLTI1Ni1nY206cGFzc3dvcmQ=@[2001:db8::1]:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "ss",
 | 
				
			||||||
 | 
							Name: "2001:db8::1:8080",
 | 
				
			||||||
 | 
							ShadowSocks: proxy.ShadowSocks{
 | 
				
			||||||
 | 
								Server:   "2001:db8::1",
 | 
				
			||||||
 | 
								Port:     8080,
 | 
				
			||||||
 | 
								Cipher:   "aes-256-gcm",
 | 
				
			||||||
 | 
								Password: "password",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestShadowsocks_Basic_WithRemark(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.ShadowsocksParser{}
 | 
				
			||||||
 | 
						input := "ss://YWVzLTI1Ni1nY206cGFzc3dvcmQ=@proxy.example.com:8080#My%20SS%20Proxy"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "ss",
 | 
				
			||||||
 | 
							Name: "My SS Proxy",
 | 
				
			||||||
 | 
							ShadowSocks: proxy.ShadowSocks{
 | 
				
			||||||
 | 
								Server:   "proxy.example.com",
 | 
				
			||||||
 | 
								Port:     8080,
 | 
				
			||||||
 | 
								Cipher:   "aes-256-gcm",
 | 
				
			||||||
 | 
								Password: "password",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestShadowsocks_Advanced_Base64FullEncoded(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.ShadowsocksParser{}
 | 
				
			||||||
 | 
						input := "ss://YWVzLTI1Ni1nY206cGFzc3dvcmRAbG9jYWxob3N0OjgwODA=#Local%20SS"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "ss",
 | 
				
			||||||
 | 
							Name: "Local SS",
 | 
				
			||||||
 | 
							ShadowSocks: proxy.ShadowSocks{
 | 
				
			||||||
 | 
								Server:   "localhost",
 | 
				
			||||||
 | 
								Port:     8080,
 | 
				
			||||||
 | 
								Cipher:   "aes-256-gcm",
 | 
				
			||||||
 | 
								Password: "password",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestShadowsocks_Advanced_PlainUserPassword(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.ShadowsocksParser{}
 | 
				
			||||||
 | 
						input := "ss://aes-256-gcm:password@192.168.1.1:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "ss",
 | 
				
			||||||
 | 
							Name: "192.168.1.1:8080",
 | 
				
			||||||
 | 
							ShadowSocks: proxy.ShadowSocks{
 | 
				
			||||||
 | 
								Server:   "192.168.1.1",
 | 
				
			||||||
 | 
								Port:     8080,
 | 
				
			||||||
 | 
								Cipher:   "aes-256-gcm",
 | 
				
			||||||
 | 
								Password: "password",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestShadowsocks_Advanced_ChaCha20Cipher(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.ShadowsocksParser{}
 | 
				
			||||||
 | 
						input := "ss://chacha20-poly1305:mypassword@server.com:443#ChaCha20"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "ss",
 | 
				
			||||||
 | 
							Name: "ChaCha20",
 | 
				
			||||||
 | 
							ShadowSocks: proxy.ShadowSocks{
 | 
				
			||||||
 | 
								Server:   "server.com",
 | 
				
			||||||
 | 
								Port:     443,
 | 
				
			||||||
 | 
								Cipher:   "chacha20-poly1305",
 | 
				
			||||||
 | 
								Password: "mypassword",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 错误处理测试
 | 
				
			||||||
 | 
					func TestShadowsocks_Error_MissingServer(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.ShadowsocksParser{}
 | 
				
			||||||
 | 
						input := "ss://YWVzLTI1Ni1nY206cGFzc3dvcmQ=@:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if !errors.Is(err, parser.ErrInvalidStruct) {
 | 
				
			||||||
 | 
							t.Errorf("Error is not expected: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestShadowsocks_Error_MissingPort(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.ShadowsocksParser{}
 | 
				
			||||||
 | 
						input := "ss://YWVzLTI1Ni1nY206cGFzc3dvcmQ=@127.0.0.1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if !errors.Is(err, parser.ErrInvalidStruct) {
 | 
				
			||||||
 | 
							t.Errorf("Error is not expected: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestShadowsocks_Error_InvalidProtocol(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.ShadowsocksParser{}
 | 
				
			||||||
 | 
						input := "http://example.com:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if !errors.Is(err, parser.ErrInvalidPrefix) {
 | 
				
			||||||
 | 
							t.Errorf("Error is not expected: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										112
									
								
								test/parser/shadowsocksr_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										112
									
								
								test/parser/shadowsocksr_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,112 @@
 | 
				
			|||||||
 | 
					package test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/parser"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestShadowsocksR_Basic_SimpleLink(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.ShadowsocksRParser{}
 | 
				
			||||||
 | 
						input := "ssr://MTI3LjAuMC4xOjQ0MzpvcmlnaW46YWVzLTE5Mi1jZmI6cGxhaW46TVRJek1USXovP2dyb3VwPVpHVm1ZWFZzZEEmcmVtYXJrcz1TRUZJUVE"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "ssr",
 | 
				
			||||||
 | 
							Name: "HAHA",
 | 
				
			||||||
 | 
							ShadowSocksR: proxy.ShadowSocksR{
 | 
				
			||||||
 | 
								Server:        "127.0.0.1",
 | 
				
			||||||
 | 
								Port:          443,
 | 
				
			||||||
 | 
								Cipher:        "aes-192-cfb",
 | 
				
			||||||
 | 
								Password:      "123123",
 | 
				
			||||||
 | 
								ObfsParam:     "",
 | 
				
			||||||
 | 
								Obfs:          "plain",
 | 
				
			||||||
 | 
								Protocol:      "origin",
 | 
				
			||||||
 | 
								ProtocolParam: "",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestShadowsocksR_Basic_WithParams(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.ShadowsocksRParser{}
 | 
				
			||||||
 | 
						input := "ssr://MTI3LjAuMC4xOjQ0MzpvcmlnaW46YWVzLTE5Mi1jZmI6dGxzMS4wX3Nlc3Npb25fYXV0aDpNVEl6TVRJei8/b2Jmc3BhcmFtPWIySm1jeTF3WVhKaGJXVjBaWEkmcHJvdG9wYXJhbT1jSEp2ZEc5allXd3RjR0Z5WVcxbGRHVnkmZ3JvdXA9WkdWbVlYVnNkQSZyZW1hcmtzPVNFRklRUQ"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "ssr",
 | 
				
			||||||
 | 
							Name: "HAHA",
 | 
				
			||||||
 | 
							ShadowSocksR: proxy.ShadowSocksR{
 | 
				
			||||||
 | 
								Server:        "127.0.0.1",
 | 
				
			||||||
 | 
								Port:          443,
 | 
				
			||||||
 | 
								Cipher:        "aes-192-cfb",
 | 
				
			||||||
 | 
								Password:      "123123",
 | 
				
			||||||
 | 
								ObfsParam:     "obfs-parameter",
 | 
				
			||||||
 | 
								Obfs:          "tls1.0_session_auth",
 | 
				
			||||||
 | 
								Protocol:      "origin",
 | 
				
			||||||
 | 
								ProtocolParam: "protocal-parameter",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestShadowsocksR_Basic_IPv6Address(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.ShadowsocksRParser{}
 | 
				
			||||||
 | 
						input := "ssr://WzIwMDE6MGRiODo4NWEzOjAwMDA6MDAwMDo4YTJlOjAzNzA6NzMzNF06NDQzOm9yaWdpbjphZXMtMTkyLWNmYjpwbGFpbjpNVEl6TVRJei8/Z3JvdXA9WkdWbVlYVnNkQSZyZW1hcmtzPVNFRklRUQ"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "ssr",
 | 
				
			||||||
 | 
							Name: "HAHA",
 | 
				
			||||||
 | 
							ShadowSocksR: proxy.ShadowSocksR{
 | 
				
			||||||
 | 
								Server:        "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]",
 | 
				
			||||||
 | 
								Port:          443,
 | 
				
			||||||
 | 
								Cipher:        "aes-192-cfb",
 | 
				
			||||||
 | 
								Password:      "123123",
 | 
				
			||||||
 | 
								ObfsParam:     "",
 | 
				
			||||||
 | 
								Obfs:          "plain",
 | 
				
			||||||
 | 
								Protocol:      "origin",
 | 
				
			||||||
 | 
								ProtocolParam: "",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestShadowsocksR_Error_InvalidBase64(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.ShadowsocksRParser{}
 | 
				
			||||||
 | 
						input := "ssr://invalid_base64"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestShadowsocksR_Error_InvalidProtocol(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.ShadowsocksRParser{}
 | 
				
			||||||
 | 
						input := "ss://example.com:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										168
									
								
								test/parser/socks_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										168
									
								
								test/parser/socks_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,168 @@
 | 
				
			|||||||
 | 
					package test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/parser"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSocks_Basic_SimpleLink(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.SocksParser{}
 | 
				
			||||||
 | 
						input := "socks://user:pass@127.0.0.1:1080#SOCKS%20Proxy"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "socks5",
 | 
				
			||||||
 | 
							Name: "SOCKS Proxy",
 | 
				
			||||||
 | 
							Socks: proxy.Socks{
 | 
				
			||||||
 | 
								Server:   "127.0.0.1",
 | 
				
			||||||
 | 
								Port:     1080,
 | 
				
			||||||
 | 
								UserName: "user",
 | 
				
			||||||
 | 
								Password: "pass",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSocks_Basic_NoAuth(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.SocksParser{}
 | 
				
			||||||
 | 
						input := "socks://127.0.0.1:1080#SOCKS%20No%20Auth"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "socks5",
 | 
				
			||||||
 | 
							Name: "SOCKS No Auth",
 | 
				
			||||||
 | 
							Socks: proxy.Socks{
 | 
				
			||||||
 | 
								Server: "127.0.0.1",
 | 
				
			||||||
 | 
								Port:   1080,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSocks_Basic_IPv6Address(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.SocksParser{}
 | 
				
			||||||
 | 
						input := "socks://user:pass@[2001:db8::1]:1080#SOCKS%20IPv6"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "socks5",
 | 
				
			||||||
 | 
							Name: "SOCKS IPv6",
 | 
				
			||||||
 | 
							Socks: proxy.Socks{
 | 
				
			||||||
 | 
								Server:   "2001:db8::1",
 | 
				
			||||||
 | 
								Port:     1080,
 | 
				
			||||||
 | 
								UserName: "user",
 | 
				
			||||||
 | 
								Password: "pass",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSocks_Basic_WithTLS(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.SocksParser{}
 | 
				
			||||||
 | 
						input := "socks://user:pass@127.0.0.1:1080?tls=true&sni=example.com#SOCKS%20TLS"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "socks5",
 | 
				
			||||||
 | 
							Name: "SOCKS TLS",
 | 
				
			||||||
 | 
							Socks: proxy.Socks{
 | 
				
			||||||
 | 
								Server:   "127.0.0.1",
 | 
				
			||||||
 | 
								Port:     1080,
 | 
				
			||||||
 | 
								UserName: "user",
 | 
				
			||||||
 | 
								Password: "pass",
 | 
				
			||||||
 | 
								TLS:      true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSocks_Basic_WithUDP(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.SocksParser{}
 | 
				
			||||||
 | 
						input := "socks://user:pass@127.0.0.1:1080?udp=true#SOCKS%20UDP"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "socks5",
 | 
				
			||||||
 | 
							Name: "SOCKS UDP",
 | 
				
			||||||
 | 
							Socks: proxy.Socks{
 | 
				
			||||||
 | 
								Server:   "127.0.0.1",
 | 
				
			||||||
 | 
								Port:     1080,
 | 
				
			||||||
 | 
								UserName: "user",
 | 
				
			||||||
 | 
								Password: "pass",
 | 
				
			||||||
 | 
								UDP:      true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSocks_Error_MissingServer(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.SocksParser{}
 | 
				
			||||||
 | 
						input := "socks://user:pass@:1080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSocks_Error_MissingPort(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.SocksParser{}
 | 
				
			||||||
 | 
						input := "socks://user:pass@127.0.0.1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSocks_Error_InvalidPort(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.SocksParser{}
 | 
				
			||||||
 | 
						input := "socks://user:pass@127.0.0.1:99999"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSocks_Error_InvalidProtocol(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.SocksParser{}
 | 
				
			||||||
 | 
						input := "ss://example.com:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										182
									
								
								test/parser/trojan_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										182
									
								
								test/parser/trojan_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,182 @@
 | 
				
			|||||||
 | 
					package test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/parser"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestTrojan_Basic_SimpleLink(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.TrojanParser{}
 | 
				
			||||||
 | 
						input := "trojan://password@127.0.0.1:443#Trojan%20Proxy"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "trojan",
 | 
				
			||||||
 | 
							Name: "Trojan Proxy",
 | 
				
			||||||
 | 
							Trojan: proxy.Trojan{
 | 
				
			||||||
 | 
								Server:   "127.0.0.1",
 | 
				
			||||||
 | 
								Port:     443,
 | 
				
			||||||
 | 
								Password: "password",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestTrojan_Basic_WithTLS(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.TrojanParser{}
 | 
				
			||||||
 | 
						input := "trojan://password@127.0.0.1:443?security=tls&sni=example.com&alpn=h2,http/1.1#Trojan%20TLS"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "trojan",
 | 
				
			||||||
 | 
							Name: "Trojan TLS",
 | 
				
			||||||
 | 
							Trojan: proxy.Trojan{
 | 
				
			||||||
 | 
								Server:   "127.0.0.1",
 | 
				
			||||||
 | 
								Port:     443,
 | 
				
			||||||
 | 
								Password: "password",
 | 
				
			||||||
 | 
								ALPN:     []string{"h2", "http/1.1"},
 | 
				
			||||||
 | 
								SNI:      "example.com",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestTrojan_Basic_WithReality(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.TrojanParser{}
 | 
				
			||||||
 | 
						input := "trojan://password@127.0.0.1:443?security=reality&sni=example.com&pbk=publickey123&sid=shortid123&fp=chrome#Trojan%20Reality"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "trojan",
 | 
				
			||||||
 | 
							Name: "Trojan Reality",
 | 
				
			||||||
 | 
							Trojan: proxy.Trojan{
 | 
				
			||||||
 | 
								Server:   "127.0.0.1",
 | 
				
			||||||
 | 
								Port:     443,
 | 
				
			||||||
 | 
								Password: "password",
 | 
				
			||||||
 | 
								SNI:      "example.com",
 | 
				
			||||||
 | 
								RealityOpts: proxy.RealityOptions{
 | 
				
			||||||
 | 
									PublicKey: "publickey123",
 | 
				
			||||||
 | 
									ShortID:   "shortid123",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								Fingerprint: "chrome",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestTrojan_Basic_WithWebSocket(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.TrojanParser{}
 | 
				
			||||||
 | 
						input := "trojan://password@127.0.0.1:443?type=ws&path=/ws&host=example.com#Trojan%20WS"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "trojan",
 | 
				
			||||||
 | 
							Name: "Trojan WS",
 | 
				
			||||||
 | 
							Trojan: proxy.Trojan{
 | 
				
			||||||
 | 
								Server:   "127.0.0.1",
 | 
				
			||||||
 | 
								Port:     443,
 | 
				
			||||||
 | 
								Password: "password",
 | 
				
			||||||
 | 
								Network:  "ws",
 | 
				
			||||||
 | 
								WSOpts: proxy.WSOptions{
 | 
				
			||||||
 | 
									Path: "/ws",
 | 
				
			||||||
 | 
									Headers: map[string]string{
 | 
				
			||||||
 | 
										"Host": "example.com",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestTrojan_Basic_WithGrpc(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.TrojanParser{}
 | 
				
			||||||
 | 
						input := "trojan://password@127.0.0.1:443?type=grpc&serviceName=grpc_service#Trojan%20gRPC"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "trojan",
 | 
				
			||||||
 | 
							Name: "Trojan gRPC",
 | 
				
			||||||
 | 
							Trojan: proxy.Trojan{
 | 
				
			||||||
 | 
								Server:   "127.0.0.1",
 | 
				
			||||||
 | 
								Port:     443,
 | 
				
			||||||
 | 
								Password: "password",
 | 
				
			||||||
 | 
								Network:  "grpc",
 | 
				
			||||||
 | 
								GrpcOpts: proxy.GrpcOptions{
 | 
				
			||||||
 | 
									GrpcServiceName: "grpc_service",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestTrojan_Error_MissingServer(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.TrojanParser{}
 | 
				
			||||||
 | 
						input := "trojan://password@:443"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestTrojan_Error_MissingPort(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.TrojanParser{}
 | 
				
			||||||
 | 
						input := "trojan://password@127.0.0.1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestTrojan_Error_InvalidPort(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.TrojanParser{}
 | 
				
			||||||
 | 
						input := "trojan://password@127.0.0.1:99999"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestTrojan_Error_InvalidProtocol(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.TrojanParser{}
 | 
				
			||||||
 | 
						input := "ss://example.com:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										24
									
								
								test/parser/utils.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								test/parser/utils.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					package test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"reflect"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"gopkg.in/yaml.v3"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func validateResult(t *testing.T, expected proxy.Proxy, result proxy.Proxy) {
 | 
				
			||||||
 | 
						t.Helper()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if result.Type != expected.Type {
 | 
				
			||||||
 | 
							t.Errorf("Type mismatch: expected %s, got %s", expected.Type, result.Type)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !reflect.DeepEqual(expected, result) {
 | 
				
			||||||
 | 
							expectedYaml, _ := yaml.Marshal(expected)
 | 
				
			||||||
 | 
							resultYaml, _ := yaml.Marshal(result)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							t.Errorf("Structure mismatch: \nexpected:\n %s\ngot:\n %s", string(expectedYaml), string(resultYaml))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										214
									
								
								test/parser/vless_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										214
									
								
								test/parser/vless_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,214 @@
 | 
				
			|||||||
 | 
					package test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/parser"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVless_Basic_SimpleLink(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VlessParser{}
 | 
				
			||||||
 | 
						input := "vless://b831b0c4-33b7-4873-9834-28d66d87d4ce@127.0.0.1:8080#VLESS%20Proxy"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "vless",
 | 
				
			||||||
 | 
							Name: "VLESS Proxy",
 | 
				
			||||||
 | 
							Vless: proxy.Vless{
 | 
				
			||||||
 | 
								Server: "127.0.0.1",
 | 
				
			||||||
 | 
								Port:   8080,
 | 
				
			||||||
 | 
								UUID:   "b831b0c4-33b7-4873-9834-28d66d87d4ce",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVless_Basic_WithTLS(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VlessParser{}
 | 
				
			||||||
 | 
						input := "vless://b831b0c4-33b7-4873-9834-28d66d87d4ce@127.0.0.1:443?security=tls&sni=example.com&alpn=h2,http/1.1#VLESS%20TLS"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "vless",
 | 
				
			||||||
 | 
							Name: "VLESS TLS",
 | 
				
			||||||
 | 
							Vless: proxy.Vless{
 | 
				
			||||||
 | 
								Server:     "127.0.0.1",
 | 
				
			||||||
 | 
								Port:       443,
 | 
				
			||||||
 | 
								UUID:       "b831b0c4-33b7-4873-9834-28d66d87d4ce",
 | 
				
			||||||
 | 
								TLS:        true,
 | 
				
			||||||
 | 
								ALPN:       []string{"h2", "http/1.1"},
 | 
				
			||||||
 | 
								ServerName: "example.com",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVless_Basic_WithReality(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VlessParser{}
 | 
				
			||||||
 | 
						input := "vless://b831b0c4-33b7-4873-9834-28d66d87d4ce@127.0.0.1:443?security=reality&sni=example.com&pbk=publickey123&sid=shortid123&fp=chrome#VLESS%20Reality"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "vless",
 | 
				
			||||||
 | 
							Name: "VLESS Reality",
 | 
				
			||||||
 | 
							Vless: proxy.Vless{
 | 
				
			||||||
 | 
								Server:     "127.0.0.1",
 | 
				
			||||||
 | 
								Port:       443,
 | 
				
			||||||
 | 
								UUID:       "b831b0c4-33b7-4873-9834-28d66d87d4ce",
 | 
				
			||||||
 | 
								TLS:        true,
 | 
				
			||||||
 | 
								ServerName: "example.com",
 | 
				
			||||||
 | 
								RealityOpts: proxy.RealityOptions{
 | 
				
			||||||
 | 
									PublicKey: "publickey123",
 | 
				
			||||||
 | 
									ShortID:   "shortid123",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								Fingerprint: "chrome",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVless_Basic_WithWebSocket(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VlessParser{}
 | 
				
			||||||
 | 
						input := "vless://b831b0c4-33b7-4873-9834-28d66d87d4ce@127.0.0.1:443?type=ws&path=/ws&host=example.com#VLESS%20WS"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "vless",
 | 
				
			||||||
 | 
							Name: "VLESS WS",
 | 
				
			||||||
 | 
							Vless: proxy.Vless{
 | 
				
			||||||
 | 
								Server:  "127.0.0.1",
 | 
				
			||||||
 | 
								Port:    443,
 | 
				
			||||||
 | 
								UUID:    "b831b0c4-33b7-4873-9834-28d66d87d4ce",
 | 
				
			||||||
 | 
								Network: "ws",
 | 
				
			||||||
 | 
								WSOpts: proxy.WSOptions{
 | 
				
			||||||
 | 
									Path: "/ws",
 | 
				
			||||||
 | 
									Headers: map[string]string{
 | 
				
			||||||
 | 
										"Host": "example.com",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVless_Basic_WithGrpc(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VlessParser{}
 | 
				
			||||||
 | 
						input := "vless://b831b0c4-33b7-4873-9834-28d66d87d4ce@127.0.0.1:443?type=grpc&serviceName=grpc_service#VLESS%20gRPC"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "vless",
 | 
				
			||||||
 | 
							Name: "VLESS gRPC",
 | 
				
			||||||
 | 
							Vless: proxy.Vless{
 | 
				
			||||||
 | 
								Server:  "127.0.0.1",
 | 
				
			||||||
 | 
								Port:    443,
 | 
				
			||||||
 | 
								UUID:    "b831b0c4-33b7-4873-9834-28d66d87d4ce",
 | 
				
			||||||
 | 
								Network: "grpc",
 | 
				
			||||||
 | 
								GrpcOpts: proxy.GrpcOptions{
 | 
				
			||||||
 | 
									GrpcServiceName: "grpc_service",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVless_Basic_WithHTTP(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VlessParser{}
 | 
				
			||||||
 | 
						input := "vless://b831b0c4-33b7-4873-9834-28d66d87d4ce@127.0.0.1:443?type=http&path=/path1,/path2&host=host1.com,host2.com#VLESS%20HTTP"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "vless",
 | 
				
			||||||
 | 
							Name: "VLESS HTTP",
 | 
				
			||||||
 | 
							Vless: proxy.Vless{
 | 
				
			||||||
 | 
								Server:  "127.0.0.1",
 | 
				
			||||||
 | 
								Port:    443,
 | 
				
			||||||
 | 
								UUID:    "b831b0c4-33b7-4873-9834-28d66d87d4ce",
 | 
				
			||||||
 | 
								Network: "http",
 | 
				
			||||||
 | 
								HTTPOpts: proxy.HTTPOptions{
 | 
				
			||||||
 | 
									Path: []string{"/path1", "/path2"},
 | 
				
			||||||
 | 
									Headers: map[string][]string{
 | 
				
			||||||
 | 
										"host": {"host1.com", "host2.com"},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVless_Error_MissingServer(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VlessParser{}
 | 
				
			||||||
 | 
						input := "vless://b831b0c4-33b7-4873-9834-28d66d87d4ce@:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVless_Error_MissingPort(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VlessParser{}
 | 
				
			||||||
 | 
						input := "vless://b831b0c4-33b7-4873-9834-28d66d87d4ce@127.0.0.1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVless_Error_InvalidPort(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VlessParser{}
 | 
				
			||||||
 | 
						input := "vless://b831b0c4-33b7-4873-9834-28d66d87d4ce@127.0.0.1:99999"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVless_Error_InvalidProtocol(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VlessParser{}
 | 
				
			||||||
 | 
						input := "ss://example.com:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										232
									
								
								test/parser/vmess_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										232
									
								
								test/parser/vmess_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,232 @@
 | 
				
			|||||||
 | 
					package test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/parser"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVmess_Basic_SimpleLink(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VmessParser{}
 | 
				
			||||||
 | 
						input := "vmess://eyJhZGQiOiIxMjcuMC4wLjEiLCJhaWQiOiIwIiwiaWQiOiIxMjM0NTY3OC05MDEyLTM0NTYtNzg5MC0xMjM0NTY3ODkwMTIiLCJuZXQiOiJ3cyIsInBvcnQiOiI0NDMiLCJwcyI6IkhBSEEiLCJ0bHMiOiJ0bHMiLCJ0eXBlIjoibm9uZSIsInYiOiIyIn0="
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "vmess",
 | 
				
			||||||
 | 
							Name: "HAHA",
 | 
				
			||||||
 | 
							Vmess: proxy.Vmess{
 | 
				
			||||||
 | 
								UUID:    "12345678-9012-3456-7890-123456789012",
 | 
				
			||||||
 | 
								AlterID: 0,
 | 
				
			||||||
 | 
								Cipher:  "auto",
 | 
				
			||||||
 | 
								Server:  "127.0.0.1",
 | 
				
			||||||
 | 
								Port:    443,
 | 
				
			||||||
 | 
								TLS:     true,
 | 
				
			||||||
 | 
								Network: "ws",
 | 
				
			||||||
 | 
								WSOpts: proxy.WSOptions{
 | 
				
			||||||
 | 
									Path: "/",
 | 
				
			||||||
 | 
									Headers: map[string]string{
 | 
				
			||||||
 | 
										"Host": "127.0.0.1",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVmess_Basic_WithPath(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VmessParser{}
 | 
				
			||||||
 | 
						input := "vmess://eyJhZGQiOiIxMjcuMC4wLjEiLCJhaWQiOiIwIiwiaWQiOiIxMjM0NTY3OC05MDEyLTM0NTYtNzg5MC0xMjM0NTY3ODkwMTIiLCJuZXQiOiJ3cyIsInBhdGgiOiIvd3MiLCJwb3J0IjoiNDQzIiwicHMiOiJIQUNLIiwidGxzIjoidGxzIiwidHlwZSI6Im5vbmUiLCJ2IjoiMiJ9"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "vmess",
 | 
				
			||||||
 | 
							Name: "HACK",
 | 
				
			||||||
 | 
							Vmess: proxy.Vmess{
 | 
				
			||||||
 | 
								UUID:    "12345678-9012-3456-7890-123456789012",
 | 
				
			||||||
 | 
								AlterID: 0,
 | 
				
			||||||
 | 
								Cipher:  "auto",
 | 
				
			||||||
 | 
								Server:  "127.0.0.1",
 | 
				
			||||||
 | 
								Port:    443,
 | 
				
			||||||
 | 
								TLS:     true,
 | 
				
			||||||
 | 
								Network: "ws",
 | 
				
			||||||
 | 
								WSOpts: proxy.WSOptions{
 | 
				
			||||||
 | 
									Path: "/ws",
 | 
				
			||||||
 | 
									Headers: map[string]string{
 | 
				
			||||||
 | 
										"Host": "127.0.0.1",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVmess_Basic_WithHost(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VmessParser{}
 | 
				
			||||||
 | 
						input := "vmess://eyJhZGQiOiIxMjcuMC4wLjEiLCJhaWQiOiIwIiwiaG9zdCI6ImV4YW1wbGUuY29tIiwiaWQiOiIxMjM0NTY3OC05MDEyLTM0NTYtNzg5MC0xMjM0NTY3ODkwMTIiLCJuZXQiOiJ3cyIsInBvcnQiOiI0NDMiLCJwcyI6IkhBSEEiLCJ0bHMiOiJ0bHMiLCJ0eXBlIjoibm9uZSIsInYiOiIyIn0="
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "vmess",
 | 
				
			||||||
 | 
							Name: "HAHA",
 | 
				
			||||||
 | 
							Vmess: proxy.Vmess{
 | 
				
			||||||
 | 
								UUID:    "12345678-9012-3456-7890-123456789012",
 | 
				
			||||||
 | 
								AlterID: 0,
 | 
				
			||||||
 | 
								Cipher:  "auto",
 | 
				
			||||||
 | 
								Server:  "127.0.0.1",
 | 
				
			||||||
 | 
								Port:    443,
 | 
				
			||||||
 | 
								TLS:     true,
 | 
				
			||||||
 | 
								Network: "ws",
 | 
				
			||||||
 | 
								WSOpts: proxy.WSOptions{
 | 
				
			||||||
 | 
									Path: "/",
 | 
				
			||||||
 | 
									Headers: map[string]string{
 | 
				
			||||||
 | 
										"Host": "example.com",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVmess_Basic_WithSNI(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VmessParser{}
 | 
				
			||||||
 | 
						input := "vmess://eyJhZGQiOiIxMjcuMC4wLjEiLCJhaWQiOiIwIiwiaWQiOiIxMjM0NTY3OC05MDEyLTM0NTYtNzg5MC0xMjM0NTY3ODkwMTIiLCJuZXQiOiJ3cyIsInBvcnQiOiI0NDMiLCJwcyI6IkhBSEEiLCJzbmkiOiJleGFtcGxlLmNvbSIsInRscyI6InRscyIsInR5cGUiOiJub25lIiwidiI6IjIifQ=="
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "vmess",
 | 
				
			||||||
 | 
							Name: "HAHA",
 | 
				
			||||||
 | 
							Vmess: proxy.Vmess{
 | 
				
			||||||
 | 
								UUID:       "12345678-9012-3456-7890-123456789012",
 | 
				
			||||||
 | 
								AlterID:    0,
 | 
				
			||||||
 | 
								Cipher:     "auto",
 | 
				
			||||||
 | 
								Server:     "127.0.0.1",
 | 
				
			||||||
 | 
								Port:       443,
 | 
				
			||||||
 | 
								TLS:        true,
 | 
				
			||||||
 | 
								Network:    "ws",
 | 
				
			||||||
 | 
								ServerName: "example.com",
 | 
				
			||||||
 | 
								WSOpts: proxy.WSOptions{
 | 
				
			||||||
 | 
									Path: "/",
 | 
				
			||||||
 | 
									Headers: map[string]string{
 | 
				
			||||||
 | 
										"Host": "127.0.0.1",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVmess_Basic_WithAlterID(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VmessParser{}
 | 
				
			||||||
 | 
						input := "vmess://eyJhZGQiOiIxMjcuMC4wLjEiLCJhaWQiOiIxIiwiaWQiOiIxMjM0NTY3OC05MDEyLTM0NTYtNzg5MC0xMjM0NTY3ODkwMTIiLCJuZXQiOiJ3cyIsInBvcnQiOiI0NDMiLCJwcyI6IkhBSEEiLCJ0bHMiOiJ0bHMiLCJ0eXBlIjoibm9uZSIsInYiOiIyIn0="
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "vmess",
 | 
				
			||||||
 | 
							Name: "HAHA",
 | 
				
			||||||
 | 
							Vmess: proxy.Vmess{
 | 
				
			||||||
 | 
								UUID:    "12345678-9012-3456-7890-123456789012",
 | 
				
			||||||
 | 
								AlterID: 1,
 | 
				
			||||||
 | 
								Cipher:  "auto",
 | 
				
			||||||
 | 
								Server:  "127.0.0.1",
 | 
				
			||||||
 | 
								Port:    443,
 | 
				
			||||||
 | 
								TLS:     true,
 | 
				
			||||||
 | 
								Network: "ws",
 | 
				
			||||||
 | 
								WSOpts: proxy.WSOptions{
 | 
				
			||||||
 | 
									Path: "/",
 | 
				
			||||||
 | 
									Headers: map[string]string{
 | 
				
			||||||
 | 
										"Host": "127.0.0.1",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVmess_Basic_GRPC(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VmessParser{}
 | 
				
			||||||
 | 
						input := "vmess://eyJhZGQiOiIxMjcuMC4wLjEiLCJhaWQiOiIwIiwiaWQiOiIxMjM0NTY3OC05MDEyLTM0NTYtNzg5MC0xMjM0NTY3ODkwMTIiLCJuZXQiOiJncnBjIiwicG9ydCI6IjQ0MyIsInBzIjoiSEFIQSIsInRscyI6InRscyIsInR5cGUiOiJub25lIiwidiI6IjIifQ=="
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expected := proxy.Proxy{
 | 
				
			||||||
 | 
							Type: "vmess",
 | 
				
			||||||
 | 
							Name: "HAHA",
 | 
				
			||||||
 | 
							Vmess: proxy.Vmess{
 | 
				
			||||||
 | 
								UUID:     "12345678-9012-3456-7890-123456789012",
 | 
				
			||||||
 | 
								AlterID:  0,
 | 
				
			||||||
 | 
								Cipher:   "auto",
 | 
				
			||||||
 | 
								Server:   "127.0.0.1",
 | 
				
			||||||
 | 
								Port:     443,
 | 
				
			||||||
 | 
								TLS:      true,
 | 
				
			||||||
 | 
								Network:  "grpc",
 | 
				
			||||||
 | 
								GrpcOpts: proxy.GrpcOptions{},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Unexpected error: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateResult(t, expected, result)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVmess_Error_InvalidBase64(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VmessParser{}
 | 
				
			||||||
 | 
						input := "vmess://invalid_base64"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVmess_Error_InvalidJSON(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VmessParser{}
 | 
				
			||||||
 | 
						input := "vmess://eyJpbnZhbGlkIjoianNvbn0="
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestVmess_Error_InvalidProtocol(t *testing.T) {
 | 
				
			||||||
 | 
						p := &parser.VmessParser{}
 | 
				
			||||||
 | 
						input := "ss://example.com:8080"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := p.Parse(parser.ParseConfig{UseUDP: false}, input)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("Expected error but got none")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,22 +0,0 @@
 | 
				
			|||||||
package test
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
	"testing"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func TestParser(t *testing.T) {
 | 
					 | 
				
			||||||
	// res, err := parser.ParseTrojan("trojan://Abse64hhjewrs@test.com:8443?type=ws&path=%2Fx&host=test.com&security=tls&fp=&alpn=http%2F1.1&sni=test.com#test")
 | 
					 | 
				
			||||||
	// if err != nil {
 | 
					 | 
				
			||||||
	// 	t.Log(err.Error())
 | 
					 | 
				
			||||||
	// 	t.Fail()
 | 
					 | 
				
			||||||
	// }
 | 
					 | 
				
			||||||
	// bytes, err := yaml.Marshal(res)
 | 
					 | 
				
			||||||
	// if err != nil {
 | 
					 | 
				
			||||||
	// 	t.Log(err.Error())
 | 
					 | 
				
			||||||
	// 	t.Fail()
 | 
					 | 
				
			||||||
	// }
 | 
					 | 
				
			||||||
	// t.Log(string(bytes))
 | 
					 | 
				
			||||||
	t.Log(strings.SplitN("123456", "/?", 2))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										33
									
								
								test/yaml_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								test/yaml_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					package test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"gopkg.in/yaml.v3"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type testStruct struct {
 | 
				
			||||||
 | 
						A proxy.IntOrString `yaml:"a"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestUnmarshal(t *testing.T) {
 | 
				
			||||||
 | 
						yamlData1 := `a: 123`
 | 
				
			||||||
 | 
						res := testStruct{}
 | 
				
			||||||
 | 
						err := yaml.Unmarshal([]byte(yamlData1), &res)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("failed to unmarshal yaml: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if res.A != 123 {
 | 
				
			||||||
 | 
							t.Errorf("expected 123, but got %v", res.A)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						yamlData2 := `a: "123"`
 | 
				
			||||||
 | 
						err = yaml.Unmarshal([]byte(yamlData2), &res)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("failed to unmarshal yaml: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if res.A != 123 {
 | 
				
			||||||
 | 
							t.Errorf("expected 123, but got %v", res.A)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										31
									
								
								utils/base64.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								utils/base64.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					package utils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/base64"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func DecodeBase64(s string, urlSafe bool) (string, error) {
 | 
				
			||||||
 | 
						s = strings.TrimSpace(s)
 | 
				
			||||||
 | 
						if len(s)%4 != 0 {
 | 
				
			||||||
 | 
							s += strings.Repeat("=", 4-len(s)%4)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						var decodeStr []byte
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
						if urlSafe {
 | 
				
			||||||
 | 
							decodeStr, err = base64.URLEncoding.DecodeString(s)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							decodeStr, err = base64.StdEncoding.DecodeString(s)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return "", err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return string(decodeStr), nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func EncodeBase64(s string, urlSafe bool) string {
 | 
				
			||||||
 | 
						if urlSafe {
 | 
				
			||||||
 | 
							return base64.URLEncoding.EncodeToString([]byte(s))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return base64.StdEncoding.EncodeToString([]byte(s))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,17 +0,0 @@
 | 
				
			|||||||
package validator
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type ShortLinkGenValidator struct {
 | 
					 | 
				
			||||||
	Url      string `form:"url" binding:"required"`
 | 
					 | 
				
			||||||
	Password string `form:"password"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type GetUrlValidator struct {
 | 
					 | 
				
			||||||
	Hash     string `form:"hash" binding:"required"` // Hash: 短链接
 | 
					 | 
				
			||||||
	Password string `form:"password"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type ShortLinkUpdateValidator struct {
 | 
					 | 
				
			||||||
	Hash     string `form:"hash" binding:"required"`
 | 
					 | 
				
			||||||
	Url      string `form:"url" binding:"required"`
 | 
					 | 
				
			||||||
	Password string `form:"password" binding:"required"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										157
									
								
								validator/sub.go
									
									
									
									
									
								
							
							
						
						
									
										157
									
								
								validator/sub.go
									
									
									
									
									
								
							@@ -1,157 +0,0 @@
 | 
				
			|||||||
package validator
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"crypto/sha256"
 | 
					 | 
				
			||||||
	"encoding/hex"
 | 
					 | 
				
			||||||
	"errors"
 | 
					 | 
				
			||||||
	"net/url"
 | 
					 | 
				
			||||||
	"regexp"
 | 
					 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type SubValidator struct {
 | 
					 | 
				
			||||||
	Sub                 string               `form:"sub" binding:""`
 | 
					 | 
				
			||||||
	Subs                []string             `form:"-" binding:""`
 | 
					 | 
				
			||||||
	Proxy               string               `form:"proxy" binding:""`
 | 
					 | 
				
			||||||
	Proxies             []string             `form:"-" binding:""`
 | 
					 | 
				
			||||||
	Refresh             bool                 `form:"refresh,default=false" binding:""`
 | 
					 | 
				
			||||||
	Template            string               `form:"template" binding:""`
 | 
					 | 
				
			||||||
	RuleProvider        string               `form:"ruleProvider" binding:""`
 | 
					 | 
				
			||||||
	RuleProviders       []RuleProviderStruct `form:"-" binding:""`
 | 
					 | 
				
			||||||
	Rule                string               `form:"rule" binding:""`
 | 
					 | 
				
			||||||
	Rules               []RuleStruct         `form:"-" binding:""`
 | 
					 | 
				
			||||||
	AutoTest            bool                 `form:"autoTest,default=false" binding:""`
 | 
					 | 
				
			||||||
	Lazy                bool                 `form:"lazy,default=false" binding:""`
 | 
					 | 
				
			||||||
	Sort                string               `form:"sort" binding:""`
 | 
					 | 
				
			||||||
	Remove              string               `form:"remove" binding:""`
 | 
					 | 
				
			||||||
	Replace             string               `form:"replace" binding:""`
 | 
					 | 
				
			||||||
	ReplaceKeys         []string             `form:"-" binding:""`
 | 
					 | 
				
			||||||
	ReplaceTo           []string             `form:"-" binding:""`
 | 
					 | 
				
			||||||
	NodeListMode        bool                 `form:"nodeList,default=false" binding:""`
 | 
					 | 
				
			||||||
	IgnoreCountryGrooup bool                 `form:"ignoreCountryGroup,default=false" binding:""`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type RuleProviderStruct struct {
 | 
					 | 
				
			||||||
	Behavior string
 | 
					 | 
				
			||||||
	Url      string
 | 
					 | 
				
			||||||
	Group    string
 | 
					 | 
				
			||||||
	Prepend  bool
 | 
					 | 
				
			||||||
	Name     string
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type RuleStruct struct {
 | 
					 | 
				
			||||||
	Rule    string
 | 
					 | 
				
			||||||
	Prepend bool
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func ParseQuery(c *gin.Context) (SubValidator, error) {
 | 
					 | 
				
			||||||
	var query SubValidator
 | 
					 | 
				
			||||||
	if err := c.ShouldBind(&query); err != nil {
 | 
					 | 
				
			||||||
		return SubValidator{}, errors.New("参数错误: " + err.Error())
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if query.Sub == "" && query.Proxy == "" {
 | 
					 | 
				
			||||||
		return SubValidator{}, errors.New("参数错误: sub 和 proxy 不能同时为空")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if query.Sub != "" {
 | 
					 | 
				
			||||||
		query.Subs = strings.Split(query.Sub, ",")
 | 
					 | 
				
			||||||
		for i := range query.Subs {
 | 
					 | 
				
			||||||
			if !strings.HasPrefix(query.Subs[i], "http") {
 | 
					 | 
				
			||||||
				return SubValidator{}, errors.New("参数错误: sub 格式错误")
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if _, err := url.ParseRequestURI(query.Subs[i]); err != nil {
 | 
					 | 
				
			||||||
				return SubValidator{}, errors.New("参数错误: " + err.Error())
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		query.Subs = nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if query.Proxy != "" {
 | 
					 | 
				
			||||||
		query.Proxies = strings.Split(query.Proxy, ",")
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		query.Proxies = nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if query.Template != "" {
 | 
					 | 
				
			||||||
		if strings.HasPrefix(query.Template, "http") {
 | 
					 | 
				
			||||||
			uri, err := url.ParseRequestURI(query.Template)
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				return SubValidator{}, err
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			query.Template = uri.String()
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if query.RuleProvider != "" {
 | 
					 | 
				
			||||||
		reg := regexp.MustCompile(`\[(.*?)\]`)
 | 
					 | 
				
			||||||
		ruleProviders := reg.FindAllStringSubmatch(query.RuleProvider, -1)
 | 
					 | 
				
			||||||
		for i := range ruleProviders {
 | 
					 | 
				
			||||||
			length := len(ruleProviders)
 | 
					 | 
				
			||||||
			parts := strings.Split(ruleProviders[length-i-1][1], ",")
 | 
					 | 
				
			||||||
			if len(parts) < 4 {
 | 
					 | 
				
			||||||
				return SubValidator{}, errors.New("参数错误: ruleProvider 格式错误")
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			u := parts[1]
 | 
					 | 
				
			||||||
			uri, err := url.ParseRequestURI(u)
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				return SubValidator{}, errors.New("参数错误: " + err.Error())
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			u = uri.String()
 | 
					 | 
				
			||||||
			if len(parts) == 4 {
 | 
					 | 
				
			||||||
				hash := sha256.Sum224([]byte(u))
 | 
					 | 
				
			||||||
				parts = append(parts, hex.EncodeToString(hash[:]))
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			query.RuleProviders = append(
 | 
					 | 
				
			||||||
				query.RuleProviders, RuleProviderStruct{
 | 
					 | 
				
			||||||
					Behavior: parts[0],
 | 
					 | 
				
			||||||
					Url:      u,
 | 
					 | 
				
			||||||
					Group:    parts[2],
 | 
					 | 
				
			||||||
					Prepend:  parts[3] == "true",
 | 
					 | 
				
			||||||
					Name:     parts[4],
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		// 校验 Rule-Provider 是否有重名
 | 
					 | 
				
			||||||
		names := make(map[string]bool)
 | 
					 | 
				
			||||||
		for _, ruleProvider := range query.RuleProviders {
 | 
					 | 
				
			||||||
			if _, ok := names[ruleProvider.Name]; ok {
 | 
					 | 
				
			||||||
				return SubValidator{}, errors.New("参数错误: Rule-Provider 名称重复")
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			names[ruleProvider.Name] = true
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		query.RuleProviders = nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if query.Rule != "" {
 | 
					 | 
				
			||||||
		reg := regexp.MustCompile(`\[(.*?)\]`)
 | 
					 | 
				
			||||||
		rules := reg.FindAllStringSubmatch(query.Rule, -1)
 | 
					 | 
				
			||||||
		for i := range rules {
 | 
					 | 
				
			||||||
			length := len(rules)
 | 
					 | 
				
			||||||
			r := rules[length-1-i][1]
 | 
					 | 
				
			||||||
			strings.LastIndex(r, ",")
 | 
					 | 
				
			||||||
			parts := [2]string{}
 | 
					 | 
				
			||||||
			parts[0] = r[:strings.LastIndex(r, ",")]
 | 
					 | 
				
			||||||
			parts[1] = r[strings.LastIndex(r, ",")+1:]
 | 
					 | 
				
			||||||
			query.Rules = append(
 | 
					 | 
				
			||||||
				query.Rules, RuleStruct{
 | 
					 | 
				
			||||||
					Rule:    parts[0],
 | 
					 | 
				
			||||||
					Prepend: parts[1] == "true",
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		query.Rules = nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if strings.TrimSpace(query.Replace) != "" {
 | 
					 | 
				
			||||||
		reg := regexp.MustCompile(`\[<(.*?)>,<(.*?)>\]`)
 | 
					 | 
				
			||||||
		replaces := reg.FindAllStringSubmatch(query.Replace, -1)
 | 
					 | 
				
			||||||
		for i := range replaces {
 | 
					 | 
				
			||||||
			length := len(replaces[i])
 | 
					 | 
				
			||||||
			if length != 3 {
 | 
					 | 
				
			||||||
				return SubValidator{}, errors.New("参数错误: replace 格式错误")
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			query.ReplaceKeys = append(query.ReplaceKeys, replaces[i][1])
 | 
					 | 
				
			||||||
			query.ReplaceTo = append(query.ReplaceTo, replaces[i][2])
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return query, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user