block-proxy 0.1.10 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/commit/skill.md +40 -0
- package/.claude/skills/commit/skill.md +34 -26
- package/CLAUDE.md +83 -23
- package/README.md +41 -46
- package/build/index.html +1 -2
- package/config.json +54 -2
- package/hack-of-anyproxy/lib/requestHandler.js +1 -1
- package/package.json +4 -3
- package/proxy/fs.js +29 -2
- package/proxy/proxy.js +51 -3
- package/server/express.js +1 -0
- package/skills-lock.json +11 -0
- package/socks5/server.js +2 -2
- package/build/static/css/main.098e0e65.css +0 -2
- package/build/static/css/main.098e0e65.css.map +0 -1
- package/build/static/js/main.e8a52b27.js +0 -3
- package/build/static/js/main.e8a52b27.js.LICENSE.txt +0 -49
- package/build/static/js/main.e8a52b27.js.map +0 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "commit"
|
|
3
|
+
description: "Analyze git changes, stage as needed, generate a Conventional Commit message, and create a commit."
|
|
4
|
+
argument-hint: "[optional commit intent]"
|
|
5
|
+
user-invocable: true
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Skill: Smart Git Commit
|
|
9
|
+
|
|
10
|
+
Use this skill when the user runs `/commit` or asks to commit changes.
|
|
11
|
+
|
|
12
|
+
## Instructions
|
|
13
|
+
|
|
14
|
+
1. **Analyze Context**:
|
|
15
|
+
- Run `git status` to identify modified, added, or deleted files.
|
|
16
|
+
- Run `git diff` to inspect changes in unstaged files.
|
|
17
|
+
- Run `git diff --cached` to inspect changes in staged files.
|
|
18
|
+
|
|
19
|
+
2. **Stage Changes**:
|
|
20
|
+
- If there are unstaged changes, run `git add -A` to stage all changes unless the user explicitly requested a partial commit.
|
|
21
|
+
|
|
22
|
+
3. **Generate Commit Message**:
|
|
23
|
+
- Analyze diffs to understand the intent of changes.
|
|
24
|
+
- Draft a message following **Conventional Commits**:
|
|
25
|
+
```
|
|
26
|
+
<type>(<scope>): <description>
|
|
27
|
+
|
|
28
|
+
[optional body]
|
|
29
|
+
```
|
|
30
|
+
- **Type 使用英文**: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`。
|
|
31
|
+
- Scope 为可选,应反映受影响的功能区域。
|
|
32
|
+
- **标题示例格式**: `feat(world): WorldStore/RegionCache 架构与 runtime chunk streaming`
|
|
33
|
+
- **正文尽量使用中文编写**,描述具体变更细节和原因。
|
|
34
|
+
|
|
35
|
+
4. **Execute Commit**:
|
|
36
|
+
- Run `git commit -m "generated_message"`.
|
|
37
|
+
- If a body is needed, use multiple `-m` flags.
|
|
38
|
+
|
|
39
|
+
5. **Report**:
|
|
40
|
+
- Inform the user of the commit message used and commit result.
|
|
@@ -1,32 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "commit"
|
|
3
|
+
description: "Analyze git changes, stage as needed, generate a Conventional Commit message, and create a commit."
|
|
4
|
+
argument-hint: "[optional commit intent]"
|
|
5
|
+
user-invocable: true
|
|
6
|
+
---
|
|
7
|
+
|
|
1
8
|
# Skill: Smart Git Commit
|
|
2
9
|
|
|
3
10
|
Use this skill when the user runs `/commit` or asks to commit changes.
|
|
4
11
|
|
|
5
12
|
## Instructions
|
|
6
13
|
|
|
7
|
-
1.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
2.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
3.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
14
|
+
1. **Analyze Context**:
|
|
15
|
+
- Run `git status` to identify modified, added, or deleted files.
|
|
16
|
+
- Run `git diff` to inspect changes in unstaged files.
|
|
17
|
+
- Run `git diff --cached` to inspect changes in staged files.
|
|
18
|
+
|
|
19
|
+
2. **Stage Changes**:
|
|
20
|
+
- If there are unstaged changes, run `git add -A` to stage all changes unless the user explicitly requested a partial commit.
|
|
21
|
+
|
|
22
|
+
3. **Generate Commit Message**:
|
|
23
|
+
- Analyze diffs to understand the intent of changes.
|
|
24
|
+
- Draft a message following **Conventional Commits**:
|
|
25
|
+
```
|
|
26
|
+
<type>(<scope>): <description>
|
|
27
|
+
|
|
28
|
+
[optional body]
|
|
29
|
+
```
|
|
30
|
+
- **Type 使用英文**: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`。
|
|
31
|
+
- Scope 为可选,应反映受影响的功能区域。
|
|
32
|
+
- **标题示例格式**: `feat(world): WorldStore/RegionCache 架构与 runtime chunk streaming`
|
|
33
|
+
- **正文尽量使用中文编写**,描述具体变更细节和原因。
|
|
34
|
+
|
|
35
|
+
4. **Execute Commit**:
|
|
36
|
+
- Run `git commit -m "generated_message"`.
|
|
37
|
+
- If a body is needed, use multiple `-m` flags.
|
|
38
|
+
|
|
39
|
+
5. **Report**:
|
|
40
|
+
- Inform the user of the commit message used and commit result.
|
package/CLAUDE.md
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
# CLAUDE.md
|
|
2
2
|
|
|
3
|
-
This file provides guidance to Claude Code (claude.ai/code) when working with
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with this repository.
|
|
4
4
|
|
|
5
5
|
## Common Commands
|
|
6
6
|
|
|
7
7
|
### Development
|
|
8
|
+
- `pnpm i` – Install dependencies (pnpm is the preferred package manager)
|
|
8
9
|
- `npm run dev` – Start development mode with BLOCK_PROXY_DEV=1 (starts all services)
|
|
9
10
|
- `npm run craco` – Start React development server with CRACO (port 3000)
|
|
10
11
|
- `npm run start` / `npm run express` – Start backend + proxy server for production
|
|
11
12
|
- `npm run proxy` – Start proxy only (no admin interface)
|
|
12
13
|
- `npm run socks5` – Start SOCKS5 server only
|
|
14
|
+
- `npm run cp` – Print start banner (used internally by other scripts)
|
|
15
|
+
|
|
16
|
+
### Code Analysis
|
|
17
|
+
- `npm test` – Run React tests (currently limited, based on CRA defaults)
|
|
18
|
+
|
|
19
|
+
### Utilities
|
|
20
|
+
- `npm run rm_bkconfig` – Remove backup config file
|
|
13
21
|
|
|
14
22
|
### Build & Deployment
|
|
15
23
|
- `npm run build` – Build React frontend
|
|
@@ -19,7 +27,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
|
|
19
27
|
- `npm run eject` – Eject from Create React App (irreversible)
|
|
20
28
|
|
|
21
29
|
### Global CLI
|
|
22
|
-
- `block-proxy` – Start the proxy system (auto-restart on failure)
|
|
30
|
+
- `block-proxy` – Start the proxy system (auto-restart on failure, max 10000 times)
|
|
23
31
|
- `block-proxy -c rule.js` – Start with external MITM rule configuration
|
|
24
32
|
|
|
25
33
|
## Architecture Overview
|
|
@@ -29,35 +37,51 @@ Block-Proxy is a MITM-based proxy filtering tool designed for parental control a
|
|
|
29
37
|
### Core Components
|
|
30
38
|
|
|
31
39
|
1. **Proxy Engine** (`/proxy/`)
|
|
32
|
-
- `proxy.js` – Main AnyProxy integration with MITM logic
|
|
33
|
-
- `mitm
|
|
34
|
-
- `
|
|
35
|
-
- `
|
|
40
|
+
- `proxy.js` – Main AnyProxy integration with MITM logic, request/response filtering
|
|
41
|
+
- `mitm/rule.js` – MITM rule definitions (YouTube ads, Youdao Dictionary, etc.)
|
|
42
|
+
- `mitm/youtube/` – YouTube ad-blocking response modifiers
|
|
43
|
+
- `mitm/ydcd/` – Youdao Dictionary VIP modifier
|
|
44
|
+
- `mitm/persistentStore.js` – Presistent store for MITM state (you can read along)
|
|
45
|
+
- `mitm/uaFilter.js` – User-Agent based filtering
|
|
46
|
+
- `scan.js` – Network scanning for device discovery (every 2 hours via ARP)
|
|
47
|
+
- `fs.js` – Configuration file management (read/write/backup)
|
|
48
|
+
- `attacker.js` – Request blocking logic
|
|
49
|
+
- `domain.js` – Host pattern matching
|
|
50
|
+
- `operator.js` – Proxy control operations (restart, etc.)
|
|
51
|
+
- `http.js` – HTTP client utilities
|
|
52
|
+
- `wanip.js` – WAN IP detection
|
|
53
|
+
- `monitor.js` – Proxy monitoring interface
|
|
36
54
|
|
|
37
55
|
2. **SOCKS5 Proxy** (`/socks5/`)
|
|
38
|
-
- `server.js` – SOCKS5 over TLS implementation (port 8002)
|
|
56
|
+
- `server.js` – SOCKS5 over TLS implementation (port 8002), forwards to AnyProxy
|
|
39
57
|
- `start.js` – SOCKS5 server entry point
|
|
40
58
|
|
|
41
59
|
3. **Backend Server** (`/server/`)
|
|
42
60
|
- `express.js` – Express.js API server for admin interface (port 8004)
|
|
43
|
-
- `start.js` – Main server entry point (decides whether to start admin UI)
|
|
61
|
+
- `start.js` – Main server entry point (decides whether to start admin UI based on config)
|
|
62
|
+
- `util.js` – Shared utilities
|
|
44
63
|
|
|
45
64
|
4. **React Frontend** (`/src/`)
|
|
46
65
|
- `App.js` – Admin interface for managing blocking rules
|
|
47
66
|
- Built with Create React App, configured via CRACO
|
|
48
67
|
|
|
49
68
|
5. **CLI Interface** (`/bin/`)
|
|
50
|
-
- `start.js` – Global CLI entry point with auto-restart capabilities and config cleanup
|
|
69
|
+
- `start.js` – Global CLI entry point with auto-restart capabilities (max 10000 restarts) and config cleanup on exit
|
|
70
|
+
|
|
71
|
+
6. **AnyProxy Fork** (`/hack-of-anyproxy/`)
|
|
72
|
+
- Modified AnyProxy request handler with custom TLS handling, IPv6 normalization, and UA-based filtering
|
|
73
|
+
- Patched into `@bachi/anyproxy` package at runtime
|
|
51
74
|
|
|
52
|
-
|
|
53
|
-
- Runtime configuration: ports, blocked hosts, authentication
|
|
75
|
+
7. **Configuration** (`config.json`)
|
|
76
|
+
- Runtime configuration: ports, blocked hosts, authentication, device list
|
|
54
77
|
- Auto-saved from admin interface
|
|
78
|
+
- Key fields: `block_hosts[]`, `proxy_port`, `socks5_port`, `enable_express`, `enable_socks5`, `devices[]`, `auth_username`, `auth_password`
|
|
55
79
|
|
|
56
80
|
### Port Configuration
|
|
57
|
-
- `8001` – HTTP proxy port (mandatory)
|
|
81
|
+
- `8001` – HTTP proxy port (mandatory, AnyProxy)
|
|
58
82
|
- `8002` – SOCKS5 over TLS port (optional)
|
|
59
83
|
- `8003` – AnyProxy monitoring interface (optional)
|
|
60
|
-
- `8004` – Admin configuration interface (optional)
|
|
84
|
+
- `8004` – Admin configuration interface (optional, Express)
|
|
61
85
|
- `3000` – React development server (dev only)
|
|
62
86
|
|
|
63
87
|
### Entry Points
|
|
@@ -65,50 +89,86 @@ Block-Proxy is a MITM-based proxy filtering tool designed for parental control a
|
|
|
65
89
|
- **Proxy-only**: `proxy/start.js` → `proxy/proxy.js`
|
|
66
90
|
- **Development**: `npm run dev` → starts everything with dev flag
|
|
67
91
|
|
|
92
|
+
### Request Flow
|
|
93
|
+
```
|
|
94
|
+
Client → HTTP Proxy (8001) → AnyProxy → MITM Rules → Target Server
|
|
95
|
+
→ SOCKS5 (8002) → TLS → AnyProxy → MITM Rules → Target Server
|
|
96
|
+
```
|
|
97
|
+
|
|
68
98
|
## Key Patterns
|
|
69
99
|
|
|
70
100
|
### MITM Rule System
|
|
71
101
|
- Host-based blocking with regex pattern matching
|
|
72
102
|
- Time-based restrictions (start/end times, weekdays)
|
|
73
|
-
- MAC address targeting for device-specific rules
|
|
103
|
+
- MAC address targeting for device-specific rules (HTTP proxy only)
|
|
74
104
|
- YouTube ad blocking with predefined regex patterns
|
|
75
105
|
- Custom rule injection via external `rule.js` configuration
|
|
106
|
+
- Two rule types: `beforeSendRequest` and `beforeSendResponse`
|
|
107
|
+
- Built-in rules: YouTube ad removal, Youdao Dictionary VIP unlock
|
|
108
|
+
|
|
109
|
+
**Adding Custom MITM Rules:**
|
|
110
|
+
1. Edit `proxy/mitm/rule.js` for built-in rules, or
|
|
111
|
+
2. Create external rule file and start with `block-proxy -c rule.js`
|
|
112
|
+
3. Rule structure: `{ type, host, regexp, callback }` where callback receives `(url, request, response)`
|
|
113
|
+
4. See `example/rule.js` for reference
|
|
76
114
|
|
|
77
115
|
### Configuration Management
|
|
78
116
|
- Configuration stored in `config.json` at runtime
|
|
79
|
-
- Supports external rule files via `-c` flag
|
|
80
|
-
- Network device scanning every 2 hours (stored in `config.json`)
|
|
117
|
+
- Supports external rule files via `-c` flag (global config via `_fs.setGlobalConfigFile()`)
|
|
118
|
+
- Network device scanning every 2 hours (stored in `config.json` as `devices[]`)
|
|
81
119
|
- Auto-clears global config file on exit/restart
|
|
120
|
+
- Backup config: `config_backup.json` (removed on build)
|
|
121
|
+
|
|
122
|
+
### Block Host Rule Structure
|
|
123
|
+
```javascript
|
|
124
|
+
{
|
|
125
|
+
"filter_host": "example.com", // Host pattern
|
|
126
|
+
"filter_match_rule": "^https?://...", // URL regex (optional)
|
|
127
|
+
"filter_start_time": "00:00", // Start time
|
|
128
|
+
"filter_end_time": "23:59", // End time
|
|
129
|
+
"filter_weekday": [1,2,3,4,5,6,7], // 1=Monday, 7=Sunday
|
|
130
|
+
"filter_mac": "AA:BB:CC:DD:EE:FF" // Target device (optional)
|
|
131
|
+
}
|
|
132
|
+
```
|
|
82
133
|
|
|
83
134
|
### Deployment Patterns
|
|
84
135
|
- Designed for OpenWRT router deployment with host networking (`--network=host`)
|
|
85
136
|
- Docker container with volume mounting for configuration
|
|
86
137
|
- Multi-architecture support (ARM/X86)
|
|
87
|
-
- Auto-restart on failure with config cleanup
|
|
138
|
+
- Auto-restart on failure with config cleanup (3 second delay, max 10000 restarts)
|
|
88
139
|
- Production vs. development modes controlled by `BLOCK_PROXY_DEV` env var
|
|
89
140
|
|
|
90
141
|
### Development Workflow
|
|
91
142
|
1. **Development**: `npm run dev` starts proxy + admin UI + SOCKS5 (if enabled)
|
|
92
|
-
2. **
|
|
93
|
-
3. **
|
|
94
|
-
4. **
|
|
143
|
+
2. **Frontend Development**: `npm run craco` starts React dev server (port 3000) with API proxy to backend (port 8003)
|
|
144
|
+
3. **Testing**: Proxy-only mode with `npm run proxy`
|
|
145
|
+
4. **Building**: `npm run build` compiles React frontend to `/build/`
|
|
146
|
+
5. **Docker**: Separate commands for x86 and ARM architectures
|
|
95
147
|
|
|
96
148
|
### Dependencies
|
|
149
|
+
**Note:** Due to the `@bachi/anyproxy` fork being incompatible with newer Node.js versions, it is bundled as a `devDependency`. Most runtime dependencies are in `devDependencies`:
|
|
97
150
|
- `@bachi/anyproxy` – Modified AnyProxy fork for MITM
|
|
98
151
|
- `express` – Backend API server
|
|
99
152
|
- `react`, `react-dom` – Frontend framework
|
|
100
153
|
- `commander` – CLI argument parsing
|
|
101
154
|
- `axios` – HTTP client for API calls
|
|
102
155
|
- `qrcode` – Certificate QR code generation for MITM setup
|
|
156
|
+
- `ping` – Network ping utility
|
|
157
|
+
- `http-proxy-agent`, `https-proxy-agent` – Upstream proxy support
|
|
158
|
+
- `@craco/craco` – CRA configuration override
|
|
103
159
|
|
|
104
160
|
## Important Notes
|
|
105
161
|
- SOCKS5 proxy does not support MAC address targeting (only HTTP proxy does)
|
|
106
162
|
- Clients must install AnyProxy certificate for HTTPS MITM inspection
|
|
107
|
-
- Service needs network scanning permissions (best deployed on OpenWRT gateway)
|
|
163
|
+
- Service needs network scanning permissions (best deployed on OpenWRT gateway, uses `arp -a`)
|
|
108
164
|
- Admin interface allows real-time rule management with proxy restart
|
|
109
165
|
- Docker builds use Chinese npm registry (registry.npmmirror.com) by default
|
|
166
|
+
- iOS Safari has security restriction: proxy with auth cannot be same as gateway IP
|
|
167
|
+
- Network device table refreshes every 2 hours; new devices may need manual refresh
|
|
168
|
+
- HTTP keep-alive enabled with max 100 sockets for performance
|
|
110
169
|
|
|
111
170
|
# Project Rules & Skills
|
|
112
171
|
|
|
113
|
-
- **
|
|
114
|
-
|
|
172
|
+
- **Local Skills**: 实时遵循 `.claude/skills/*/skill.md` 中的指令。可用技能: `commit`, `pcap-analyse`
|
|
173
|
+
- **CLI入口**: 全局命令 `block-proxy` 注册在 `bin/start.js`,通过 `npm i -g` 安装后可直接调用
|
|
174
|
+
- **config.json** 是运行时配置文件(非源码),由 `proxy/fs.js` 管理读写和备份,不在 git 中追踪变更
|
package/README.md
CHANGED
|
@@ -7,17 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
> **Block-Proxy**
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Socks5/http 代理工具,支持 MITM 和二次开发
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
用在家庭网关,限制小朋友上网用。特性:
|
|
13
13
|
|
|
14
|
-
- HTTP 代理
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
- url 正则拦截
|
|
18
|
-
- 指定拦截Mac地址
|
|
19
|
-
- 设定日期和时间段
|
|
20
|
-
- 顺便过滤广告
|
|
14
|
+
- HTTP 代理 + Socks5 over TLS 代理
|
|
15
|
+
- 域名拦截、url 正则、Mac 地址拦截
|
|
16
|
+
- 设定日期和时间段、顺便过滤广告
|
|
21
17
|
|
|
22
18
|
### 1)使用方法
|
|
23
19
|
|
|
@@ -49,7 +45,35 @@ block-proxy -c rule.js
|
|
|
49
45
|
- Arm 架构 → <a href="http://yui.cool:7001/public/downloads/block-proxy/arm/block-proxy.tar" target=_blank>block-proxy-arm.tar</a>
|
|
50
46
|
- X86 架构 → <a href="http://yui.cool:7001/public/downloads/block-proxy/x86/block-proxy-x86.tar" target=_blank>block-proxy-x86.tar</a>
|
|
51
47
|
2. 导入:`docker load < block-proxy.tar`
|
|
52
|
-
3.
|
|
48
|
+
3. 启动:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
docker run --init -d --restart=unless-stopped \
|
|
52
|
+
-e TZ=Asia/Shanghai --network=host \
|
|
53
|
+
--user=root \
|
|
54
|
+
--log-driver local \
|
|
55
|
+
--log-opt max-size=10m \
|
|
56
|
+
--log-opt max-file=3 \
|
|
57
|
+
--cpus="5" \
|
|
58
|
+
--memory 400m \
|
|
59
|
+
-v "$(pwd)/":/app/config \
|
|
60
|
+
--name block-proxy block-proxy
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
其中挂载目录 `$(pws)/` 下的 `rule.js` 是需要额外挂载的配置文件,可留空。
|
|
64
|
+
|
|
65
|
+
> block-proxy 可以配置只启动 proxy 不启动后台面板,首次启动后访问 http://代理IP:8001 根据提示操作。
|
|
66
|
+
|
|
67
|
+
网关里为了方便获取子网机器 ip 和 mac 地址,docker 容器需要和宿主机共享同一个网络,同时指定时区。
|
|
68
|
+
|
|
69
|
+
如果是在 Window/Mac 中,需要手动指定端口绑定(不推荐):
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
docker run --init -d --restart=unless-stopped --user=root \
|
|
73
|
+
-v "$(pwd)/":/app/config \
|
|
74
|
+
-e TZ=Asia/Shanghai -p 8001:8001 -p 8002:8002 -p 8003:8003 \
|
|
75
|
+
--name block-proxy block-proxy
|
|
76
|
+
```
|
|
53
77
|
|
|
54
78
|
### 2)端口配置
|
|
55
79
|
|
|
@@ -84,42 +108,14 @@ block-proxy -c rule.js
|
|
|
84
108
|
|
|
85
109
|
> 要是打包 docker 空间不够就执行 `docker system prune -a --volumes`
|
|
86
110
|
|
|
87
|
-
拷贝 tar 到 openwrt
|
|
88
|
-
|
|
89
|
-
```
|
|
90
|
-
docker run --init -d --restart=unless-stopped \
|
|
91
|
-
-e TZ=Asia/Shanghai --network=host \
|
|
92
|
-
--user=root \
|
|
93
|
-
--log-driver local \
|
|
94
|
-
--log-opt max-size=10m \
|
|
95
|
-
--log-opt max-file=3 \
|
|
96
|
-
--cpus="5" \
|
|
97
|
-
--memory 400m \
|
|
98
|
-
-v "$(pwd)/":/app/config \
|
|
99
|
-
--name block-proxy block-proxy
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
其中挂载目录 `$(pws)/` 下的 `rule.js` 是需要额外挂载的配置文件,可留空。
|
|
103
|
-
|
|
104
|
-
> block-proxy 可以配置只启动 proxy 不启动后台面板,首次启动后访问 http://代理IP:8001 根据提示操作。
|
|
105
|
-
|
|
106
|
-
网关里为了方便获取子网机器 ip 和 mac 地址,docker 容器需要和宿主机共享同一个网络,同时指定时区。
|
|
107
|
-
|
|
108
|
-
如果是在 Window/Mac 中,需要手动指定端口绑定(不推荐):
|
|
109
|
-
|
|
110
|
-
```
|
|
111
|
-
docker run --init -d --restart=unless-stopped --user=root \
|
|
112
|
-
-v "$(pwd)/":/app/config \
|
|
113
|
-
-e TZ=Asia/Shanghai -p 8001:8001 -p 8002:8002 -p 8003:8003 \
|
|
114
|
-
--name block-proxy block-proxy
|
|
115
|
-
```
|
|
116
|
-
|
|
111
|
+
拷贝 tar 到 openwrt 后启动容器:参照上文 Docker部署。
|
|
117
112
|
|
|
118
113
|
### 5)配置说明
|
|
119
114
|
|
|
120
115
|
#### ① 代理端口
|
|
121
116
|
|
|
122
|
-
|
|
117
|
+
- 8001:HTTP 代理
|
|
118
|
+
- 8002:socks5 over TLS
|
|
123
119
|
|
|
124
120
|
⚠️ Socks5 代理不支持对 Mac 地址的定向拦截,Mac 地址的拦截只对局域网内的 HTTP 代理绑定生效。建议局域网绑定 http 代理,公网绑定 Socks5 代理。
|
|
125
121
|
|
|
@@ -136,10 +132,10 @@ docker run --init -d --restart=unless-stopped --user=root \
|
|
|
136
132
|
|
|
137
133
|
#### ③ 设备配置
|
|
138
134
|
|
|
139
|
-
1.
|
|
140
|
-
2.
|
|
135
|
+
1. 证书设置:进入后台配置,扫码安装证书,在手机设置中安装该证书,同时配置完全信任:设置→通用→关于本机→证书信任设置→打开对AnyProxy的完全信任
|
|
136
|
+
2. 代理设置:iPhone/iPad 为例:设置 → 无线局域网 → 点击当前网络 → HTTP代理/配置代理,设置服务器和端口。
|
|
141
137
|
|
|
142
|
-
|
|
138
|
+
如果要通过 mac 地址拦截小朋友上网,小朋友的设备里把 Mac 固定下来:
|
|
143
139
|
|
|
144
140
|
<img width="350" alt="image" src="https://github.com/user-attachments/assets/f9bfab89-7194-4a72-b1ae-5cca27911bc9" />
|
|
145
141
|
|
|
@@ -162,7 +158,7 @@ ip6tables -I forwarding_rule -m mac --mac-source D2:9E:8D:1B:F1:4E -j REJECT
|
|
|
162
158
|
1. MITM 基于 AnyProxy 的规则实现,客户端设备必须要安装 AnyProxy 的证书。
|
|
163
159
|
2. 服务需要根据 ip 反查 mac 地址,需要代理服务工作在对子网有扫描权限的节点,最好是部署在 openwrt 网关,可以`arp -a`看下是否可以扫描完全。
|
|
164
160
|
3. 服务会自动更新路由表,每 2 个小时更新一次,对于新入网的设备,最好在后台手动刷新并重启代理,以免拦截规则不能立即生效。
|
|
165
|
-
4. 所有规则都在 HTTP 代理中生效,Socks5 是指向 AnyProxy
|
|
161
|
+
4. 所有规则都在 HTTP 代理中生效,Socks5 on tls 是指向 AnyProxy 的反向代理,内网 Mac 地址的拦截只对直接绑定 HTTP 代理的情况生效。
|
|
166
162
|
|
|
167
163
|
#### Youtube 去广告
|
|
168
164
|
|
|
@@ -172,7 +168,6 @@ ip6tables -I forwarding_rule -m mac --mac-source D2:9E:8D:1B:F1:4E -j REJECT
|
|
|
172
168
|
- *youtube.com*:`^https?:\/\/s\.youtube\.com\/api\/stats\/qoe\?adcontext`
|
|
173
169
|
- *youtube.com*:`^https?:\/\/(www|s)\.youtube\.com\/api\/stats\/ads`
|
|
174
170
|
- *googlevideo.com*:`^https?:\/\/[\w-]+\.googlevideo\.com\/(?!(dclk_video_ads|videoplayback\?)).+&oad`
|
|
175
|
-
- <del>*youtubei.googleapis.com*:`\/youtubei\/v1\/notification_registration\/get_settings`</del>
|
|
176
171
|
|
|
177
172
|
另外两条规则在这里:<https://github.com/jayli/block-proxy/blob/main/proxy/mitm/rule.js>(手工添加上面四条规则就够了)
|
|
178
173
|
|
package/build/index.html
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.2247fb80.js"></script><link href="/static/css/main.8bfa3d5f.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
|
2
|
-
|
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.2247fb80.js"></script><link href="/static/css/main.8bfa3d5f.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
package/config.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"network_scanning_status": "
|
|
2
|
+
"network_scanning_status": "1",
|
|
3
3
|
"progress_time_stamp": "1766571511705",
|
|
4
4
|
"block_hosts": [
|
|
5
5
|
{
|
|
@@ -145,6 +145,58 @@
|
|
|
145
145
|
{
|
|
146
146
|
"ip": "192.168.124.1",
|
|
147
147
|
"mac": "FA:27:3C:E5:31:5F"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"ip": "192.168.124.2",
|
|
151
|
+
"mac": "7C:DE:78:A9:83:A0"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"ip": "192.168.124.6",
|
|
155
|
+
"mac": "0:DD:B6:EB:26:5C"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"ip": "192.168.124.10",
|
|
159
|
+
"mac": "FA:27:3C:E5:31:5F"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"ip": "192.168.124.34",
|
|
163
|
+
"mac": "D6:A0:61:69:67:F6"
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"ip": "192.168.124.37",
|
|
167
|
+
"mac": "DE:1E:87:ED:17:8B"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"ip": "192.168.124.49",
|
|
171
|
+
"mac": "62:A1:CC:42:55:E4"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"ip": "192.168.124.107",
|
|
175
|
+
"mac": "6:26:EA:5A:9E:6C"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"ip": "192.168.124.111",
|
|
179
|
+
"mac": "74:3F:C2:67:74:98"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"ip": "192.168.124.125",
|
|
183
|
+
"mac": "14:C0:50:14:6E:A5"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"ip": "192.168.124.128",
|
|
187
|
+
"mac": "48:F3:F3:CA:1D:E"
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"ip": "192.168.124.200",
|
|
191
|
+
"mac": "54:52:84:95:DF:5E"
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"ip": "192.168.124.240",
|
|
195
|
+
"mac": "F4:6B:8C:90:29:5"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"ip": "192.168.124.251",
|
|
199
|
+
"mac": "6E:FB:18:4D:9C:3E"
|
|
148
200
|
}
|
|
149
201
|
]
|
|
150
|
-
}
|
|
202
|
+
}
|
|
@@ -496,7 +496,7 @@ function getUserReqHandler(userRule, recorder) {
|
|
|
496
496
|
if (userRule.responseRules && matchResponseRule(userRule.responseRules, userConfig)) {
|
|
497
497
|
var _chunkSizeThreshold = chunkSizeThreshold;
|
|
498
498
|
} else {
|
|
499
|
-
var _chunkSizeThreshold =
|
|
499
|
+
var _chunkSizeThreshold = 64 * 1024; // 64K
|
|
500
500
|
}
|
|
501
501
|
if (userConfig.response) {
|
|
502
502
|
// user-assigned local response
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "block-proxy",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "Small-scale network mitm proxy filter",
|
|
5
5
|
"bin": {
|
|
6
6
|
"block-proxy": "bin/start.js"
|
|
@@ -17,20 +17,21 @@
|
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"cp": "echo '----- program start -----'",
|
|
20
|
+
"rm_bkconfig": "rm ./config_backup.json",
|
|
20
21
|
"craco": "craco start",
|
|
21
22
|
"dev": "BLOCK_PROXY_DEV=1 npm run express",
|
|
22
23
|
"start": "npm run express",
|
|
23
24
|
"socks5": "node ./socks5/start.js",
|
|
24
25
|
"express": "npm run cp && node ./server/start.js",
|
|
25
26
|
"proxy": "npm run cp && node ./proxy/start.js",
|
|
26
|
-
"build": "react-scripts build",
|
|
27
|
+
"build": "npm run rm_bkconfig && react-scripts build",
|
|
27
28
|
"docker:build": "npm run build && docker build -t block-proxy .",
|
|
28
29
|
"docker:build_arm": "npm run build && docker buildx build --platform linux/arm64/v8 -t block-proxy .",
|
|
29
30
|
"test": "react-scripts test",
|
|
30
31
|
"eject": "react-scripts eject"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
|
-
"@bachi/anyproxy": "^0.1.
|
|
34
|
+
"@bachi/anyproxy": "^0.1.5",
|
|
34
35
|
"@craco/craco": "^7.1.0",
|
|
35
36
|
"axios": "^1.13.2",
|
|
36
37
|
"commander": "^14.0.2",
|
package/proxy/fs.js
CHANGED
|
@@ -4,6 +4,7 @@ const path = require('path');
|
|
|
4
4
|
|
|
5
5
|
const configPath = path.join(__dirname, '../config.json');
|
|
6
6
|
const CONFIG_FILE_PATH = configPath;
|
|
7
|
+
const BACKUP_FILE_PATH = path.join(__dirname, '../config_backup.json');
|
|
7
8
|
|
|
8
9
|
// 传入的是对象
|
|
9
10
|
async function writeConfig(newData) {
|
|
@@ -16,20 +17,45 @@ async function writeConfig(newData) {
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
async function backupConfig(newData) {
|
|
21
|
+
try {
|
|
22
|
+
await fs.writeFile(BACKUP_FILE_PATH, JSON.stringify(newData, null, 2), 'utf8');
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.error('Error writing backup config file:', error.message);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
19
28
|
// 示例:读取配置
|
|
20
29
|
// 返回的是对象
|
|
21
30
|
async function readConfig() {
|
|
22
31
|
try {
|
|
23
32
|
const data = await fs.readFile(CONFIG_FILE_PATH, 'utf8');
|
|
24
33
|
const config = JSON.parse(data);
|
|
34
|
+
|
|
35
|
+
// 第一次运行:如果备份不存在,则生成一个
|
|
36
|
+
try {
|
|
37
|
+
await fs.access(BACKUP_FILE_PATH);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
await backupConfig(config);
|
|
40
|
+
}
|
|
41
|
+
|
|
25
42
|
return config;
|
|
26
43
|
} catch (error) {
|
|
27
44
|
if (error.code === 'ENOENT') {
|
|
28
45
|
console.error('Config file does not exist.');
|
|
29
46
|
return {}; // 或返回一个默认配置对象
|
|
30
47
|
} else if (error instanceof SyntaxError) {
|
|
31
|
-
console.error('Error parsing config file JSON:', error.message);
|
|
32
|
-
|
|
48
|
+
console.error('Error parsing config file JSON, attempting to restore from backup:', error.message);
|
|
49
|
+
try {
|
|
50
|
+
const backupData = await fs.readFile(BACKUP_FILE_PATH, 'utf8');
|
|
51
|
+
const config = JSON.parse(backupData);
|
|
52
|
+
// 自动恢复主配置文件
|
|
53
|
+
await writeConfig(config);
|
|
54
|
+
return config;
|
|
55
|
+
} catch (backupError) {
|
|
56
|
+
console.error('Backup file also failed:', backupError.message);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
33
59
|
} else {
|
|
34
60
|
console.error('Error reading config file:', error.message);
|
|
35
61
|
throw error;
|
|
@@ -63,6 +89,7 @@ async function clearGlobalConfigFile() {
|
|
|
63
89
|
module.exports = {
|
|
64
90
|
writeConfig,
|
|
65
91
|
readConfig,
|
|
92
|
+
backupConfig,
|
|
66
93
|
setGlobalConfigFile,
|
|
67
94
|
getGlobalConfigFile,
|
|
68
95
|
clearGlobalConfigFile
|