@chenpu17/tcpmapping 2.1.1 → 2.4.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,108 @@
1
+ # Changelog
2
+
3
+ ## v2.4.1
4
+
5
+ ### 新增
6
+
7
+ - CLI 支持 `-p, --port <port>` 与 `-H, --host <host>` 选项,可直接指定 WebUI 端口和监听地址:
8
+ - `tcpmapping start --host 0.0.0.0 --port 5000` 直接对外提供服务;
9
+ - 选项对 `start`、`restart`、`status`、`init` 生效;
10
+ - 优先级:命令行选项 > 环境变量 > `config.json`。
11
+ - 监听 `0.0.0.0` 时,启动输出会列出 `localhost` 与本机局域网 IPv4 访问地址。
12
+ - 新增 `--listen` 作为 `--host` 的别名,便于记忆。
13
+
14
+ ### 修复
15
+
16
+ - 使用 `WEBUI_PORT` / `WEBUI_HOST` 启动时,CLI 输出的 WebUI 地址未反映环境变量,导致提示端口与实际监听端口不一致。
17
+ - `init --host/--port` 现在会将指定值写入生成的 `config.json`。
18
+
19
+ ## v2.4.0
20
+
21
+ ### 新增
22
+
23
+ - WebUI 新增「服务资源」面板,实时展示服务进程自身的资源占用:
24
+ - CPU 使用率(按核心数归一化为整机占比)与核心数;
25
+ - 进程内存占用(RSS)、占系统内存比例与 V8 堆用量;
26
+ - 实时上行 / 下行速率与进程启动以来的累计流量;
27
+ - 最近采样时间与顶部实时指示点。
28
+ - `GET /api/status` 新增 `resources` 字段,包含 `cpuPercent`、`cpuCount`、`memory`、`traffic` 与 `sampledAt`。
29
+
30
+ ### 改进
31
+
32
+ - 进程累计流量独立于映射统计,删除映射后仍可看到服务整体流量。
33
+ - 资源面板随界面语言与主题切换,移动端自动堆叠为单列布局,进度条提供 `progressbar` 无障碍语义。
34
+ - 系统状态卡片的累计流量改为上行 / 下行整行换行,避免窄卡片中「B」单位单独折行。
35
+
36
+ ## v2.3.0
37
+
38
+ ### 新增
39
+
40
+ - WebUI 支持中文 / English 切换,语言偏好保存在浏览器本地,静态与动态文案同步切换。
41
+ - 深色 / 浅色主题切换,首次访问跟随系统偏好,之后记住用户选择。
42
+ - API 提示信息支持 `X-Language` / `Accept-Language`,英文界面下返回英文错误提示。
43
+ - 登录页新增密码显示/隐藏按钮。
44
+ - 标记连接的实际监听地址,IPv6 地址统一显示为 `[addr]:port`。
45
+
46
+ ### 改进
47
+
48
+ - 重新设计 WebUI:统一颜色、圆角、阴影设计变量,半透明吸顶导航、图标化统计卡片。
49
+ - 表格、状态徽章、按钮、连接卡片、空状态与弹窗全面美化,支持深色模式。
50
+ - 操作反馈由 `alert` 改为轻量 Toast 提示。
51
+ - 移动端布局优化,表单与连接信息自适应换行。
52
+ - 最近连接记录支持按映射筛选,并随界面语言转换关闭原因。
53
+ - 辅助文字对比度提升至 WCAG AA,表头、空状态、占位符在明暗主题下更清晰。
54
+ - 表格中的地址与端口不再从中间折行;内联 favicon,消除 `/favicon.ico` 404。
55
+ - `Accept-Language` 按首选语言解析,语言切换后历史关闭原因立即重新获取。
56
+
57
+ ## v2.2.0
58
+
59
+ ### 新增
60
+
61
+ - WebUI 支持编辑已有映射(修改名称、监听地址/端口、目标地址/端口)。
62
+ - 每个映射展示累计连接数、累计上下行流量,以及当前活跃连接流量。
63
+ - 连接监控展示连接持续时间,并记录客户端实际连接的本地地址。
64
+ - 新增最近连接记录(`GET /api/connections/history`),保存已关闭连接的源地址、目的地址、起止时间、持续时长、流量和关闭原因,WebUI 可按映射筛选查看。
65
+ - 连接关闭日志包含持续时长与双向流量,便于审计。
66
+ - 映射列表、连接状态和系统状态每 5 秒自动刷新,页面隐藏时自动暂停。
67
+ - `timeouts.connect` / `timeouts.idle` 配置项,支持自定义连接与空闲超时(`idle: 0` 可禁用)。
68
+ - `WEBUI_PORT`、`WEBUI_HOST`、`SESSION_SECRET` 环境变量支持。
69
+ - `npm test` 冒烟测试,覆盖登录、映射增删改、TCP 转发与统计。
70
+
71
+ ### 修复与改进
72
+
73
+ - **安全**:移除 `admin/admin123` 默认凭据,未配置密码时 WebUI 不再启动。
74
+ - **安全**:登录成功后重新生成会话 ID,防止会话固定攻击。
75
+ - **安全**:Cookie 增加 `HttpOnly`、`SameSite=Lax`,并支持自定义会话超时。
76
+ - **安全**:增加跨站请求来源校验与安全响应头(CSP、X-Frame-Options、nosniff)。
77
+ - **安全**:会话密钥迁移到 `~/.tcpmapping/.session-secret`,权限 0600。
78
+ - **安全**:`auth-config.json` 使用原子写入并设置为 0600。
79
+ - **安全**:WebUI 默认只监听 `127.0.0.1`(可在 config.json 中修改)。
80
+ - **稳定性**:配置写入改为原子操作,避免异常退出导致配置损坏。
81
+ - **稳定性**:映射启动失败(如端口被占用)时不再显示为"运行中"。
82
+ - **稳定性**:停止映射会主动断开该映射下的所有活跃连接。
83
+ - **稳定性**:优雅关闭会关闭 HTTP 服务与所有转发连接。
84
+ - **性能**:TCP 转发使用 `pipe` 处理背压,避免慢速对端导致内存无限增长。
85
+ - **性能**:启用 TCP_NODELAY 与 KeepAlive,降低转发延迟并检测死连接。
86
+ - **体验**:编辑映射名称或目标地址时无需重启监听,已有连接不会被中断。
87
+ - **协议**:支持 TCP 半关闭(half-close)。
88
+ - **兼容**:CLI 停止服务不再依赖 `sleep` 命令,日志跟踪兼容 Windows。
89
+ - **兼容**:CLI 使用当前 Node.js 可执行文件启动服务。
90
+ - **UI**:修复 XSS 风险(映射名称等字段统一转义)。
91
+ - **UI**:登录状态失效时自动跳转登录页;修复登录页回车可能重复提交的问题。
92
+ - **UI**:新增监听地址输入项,可配置映射只监听指定网卡。
93
+
94
+ ## v2.1.1
95
+
96
+ - 修复 Windows 下密码输入显示问题。
97
+
98
+ ## v2.1.0
99
+
100
+ - 配置持久化与双语 README。
101
+
102
+ ## v2.0.0
103
+
104
+ - 支持 CLI 工具,发布 npm 包 `@chenpu17/tcpmapping`。
105
+
106
+ ## v1.0.0
107
+
108
+ - TCP 端口转发服务器,支持 WebUI 管理与实时连接监控。
package/README.md CHANGED
@@ -10,9 +10,12 @@ TCP端口转发服务器,支持WebUI管理界面和实时连接监控。
10
10
 
11
11
  - **TCP Port Forwarding** - Forward TCP traffic to backend servers | TCP端口转发
12
12
  - **Multiple Mappings** - Manage multiple forwarding rules simultaneously | 多端口映射
13
- - **WebUI Management** - Modern web interface for real-time monitoring | WebUI管理界面
14
- - **Connection Monitoring** - Real-time connection count and traffic statistics | 实时连接监控
15
- - **Secure Authentication** - bcrypt password hashing, login protection | 安全认证
13
+ - **WebUI Management** - Add, edit, start, stop and delete mappings in real time | WebUI管理界面
14
+ - **Bilingual & Themes** - Simplified Chinese / English UI, dark and light themes | 中英文界面与深色模式
15
+ - **Connection Monitoring** - Live connection details, per-mapping cumulative traffic and a searchable history of closed connections | 实时连接、累计流量与已关闭连接记录
16
+ - **Service Resources** - Live CPU, memory and traffic usage of the forwarding process itself | 服务进程自身的 CPU、内存与实时流量
17
+ - **Robust Forwarding** - Backpressure handling, TCP half-close support and idle timeouts | 背压控制、半关闭与空闲超时
18
+ - **Secure by Default** - bcrypt hashing, login lockout, session hardening, no default password | 默认安全
16
19
 
17
20
  ---
18
21
 
@@ -28,6 +31,14 @@ tcpmapping init # Create config file | 创建配置文件
28
31
  tcpmapping start # Start server | 启动服务
29
32
  ```
30
33
 
34
+ To allow remote access on port 5000 | 如需对外提供 5000 端口访问:
35
+
36
+ ```bash
37
+ tcpmapping setup-password
38
+ tcpmapping init --host 0.0.0.0 --port 5000
39
+ tcpmapping start --host 0.0.0.0 --port 5000
40
+ ```
41
+
31
42
  ### Local Install | 本地安装
32
43
 
33
44
  ```bash
@@ -53,6 +64,23 @@ npm start
53
64
  | `tcpmapping setup-password` | Set admin password | 设置管理员密码 |
54
65
  | `tcpmapping init` | Create config file | 创建配置文件 |
55
66
 
67
+ ### CLI Options | 命令行选项
68
+
69
+ | Option | Description |
70
+ |--------|-------------|
71
+ | `-p, --port <port>` | WebUI port (default: 9999) | WebUI端口(默认9999) |
72
+ | `-H, --host <host>` | Listen address (default: 127.0.0.1, use 0.0.0.0 for remote access) | 监听地址(默认127.0.0.1,远程访问用0.0.0.0) |
73
+
74
+ Options apply to `start`, `restart`, `status` and `init`, and take precedence over environment variables and `config.json`.
75
+
76
+ 选项对 `start`、`restart`、`status`、`init` 生效,优先级高于环境变量和 `config.json`。
77
+
78
+ ```bash
79
+ tcpmapping start --host 0.0.0.0 --port 5000 # Public access on port 5000 | 对外监听 5000
80
+ tcpmapping status --port 5000 # Check that instance | 查看该实例状态
81
+ tcpmapping restart --port 5000 # Restart with the same port | 以该端口重启
82
+ ```
83
+
56
84
  ---
57
85
 
58
86
  ## WebUI
@@ -61,8 +89,29 @@ After starting, visit **http://localhost:9999**
61
89
 
62
90
  启动后访问 **http://localhost:9999**
63
91
 
92
+ ### Screenshots | 界面预览
93
+
94
+ ![管理面板 · 中文浅色 | Dashboard · Chinese light](docs/screenshots/dashboard-zh-light.webp)
95
+
96
+ | English · Dark | Mobile · 中文 |
97
+ |:---:|:---:|
98
+ | ![English dark dashboard](docs/screenshots/dashboard-en-dark.webp) | ![移动端资源面板](docs/screenshots/dashboard-mobile-zh.webp) |
99
+
100
+ <details>
101
+ <summary>Login page | 登录页</summary>
102
+
103
+ ![登录页](docs/screenshots/login-zh-light.webp)
104
+
105
+ </details>
106
+
107
+ > Screenshots use demo data from an isolated instance | 截图使用独立演示实例的数据
108
+
64
109
  Default username | 默认用户名: `admin`
65
110
 
111
+ > For security, the WebUI listens on `127.0.0.1` by default. To access it from another machine, start with `--host 0.0.0.0` (or set `webui.host` in `config.json`) and restrict access with a firewall.
112
+ >
113
+ > 出于安全考虑,WebUI 默认只监听 `127.0.0.1`。如需远程访问,请使用 `--host 0.0.0.0` 启动(或修改 `config.json` 中的 `webui.host`),并通过防火墙限制访问来源。公网部署请务必设置强密码,建议使用 HTTPS 反向代理。
114
+
66
115
  ---
67
116
 
68
117
  ## Configuration | 配置
@@ -87,11 +136,16 @@ Config file location (priority order) | 配置文件位置(优先级):
87
136
  "target": { "host": "db.example.com", "port": 3306 }
88
137
  }
89
138
  ],
90
- "webui": { "port": 9999 },
91
- "logging": { "level": "info" }
139
+ "webui": { "enabled": true, "host": "127.0.0.1", "port": 9999 },
140
+ "logging": { "enabled": true, "level": "info" },
141
+ "timeouts": { "connect": 30000, "idle": 300000 }
92
142
  }
93
143
  ```
94
144
 
145
+ For remote WebUI access, set `webui.host` to `"0.0.0.0"` and protect the port with a firewall.
146
+
147
+ 如需远程访问 WebUI,请将 `webui.host` 设为 `"0.0.0.0"`,并使用防火墙保护该端口。
148
+
95
149
  ### Config Options | 配置项
96
150
 
97
151
  | Option | Description |
@@ -101,8 +155,26 @@ Config file location (priority order) | 配置文件位置(优先级):
101
155
  | `mappings[].listen.port` | Listen port | 监听端口 |
102
156
  | `mappings[].target.host` | Target host IP or domain | 目标主机 |
103
157
  | `mappings[].target.port` | Target port | 目标端口 |
158
+ | `webui.enabled` | Enable the WebUI (default: true) | 是否启用 WebUI |
159
+ | `webui.host` | WebUI bind address (default: 127.0.0.1) | WebUI监听地址 |
104
160
  | `webui.port` | WebUI port (default: 9999) | WebUI端口 |
161
+ | `logging.enabled` | Enable logging (default: true) | 是否输出日志 |
105
162
  | `logging.level` | Log level: debug/info/warn/error | 日志级别 |
163
+ | `timeouts.connect` | Target connect timeout in ms (default: 30000) | 连接超时(毫秒) |
164
+ | `timeouts.idle` | Idle timeout in ms, 0 disables (default: 300000) | 空闲超时(毫秒,0为禁用) |
165
+
166
+ ### Environment Variables | 环境变量
167
+
168
+ | Variable | Description |
169
+ |----------|-------------|
170
+ | `TCPMAPPING_DATA_DIR` | Override the data directory | 覆盖数据目录 |
171
+ | `WEBUI_PORT` | Override the WebUI port | 覆盖WebUI端口 |
172
+ | `WEBUI_HOST` | Override the WebUI bind address | 覆盖WebUI监听地址 |
173
+ | `SESSION_SECRET` | Override the session secret | 覆盖会话密钥 |
174
+
175
+ Priority | 优先级: CLI options > environment variables > `config.json` default.
176
+
177
+ 优先级:命令行选项 > 环境变量 > `config.json` 默认值。
106
178
 
107
179
  ---
108
180
 
@@ -114,6 +186,7 @@ User configuration is stored in `~/.tcpmapping/`:
114
186
 
115
187
  - `config.json` - Port mapping configuration | 端口映射配置
116
188
  - `auth-config.json` - Authentication configuration | 认证配置
189
+ - `.session-secret` - Session signing secret (0600) | 会话签名密钥(0600)
117
190
  - `tcpmapping.log` - Log file | 日志文件
118
191
  - `tcpmapping.pid` - PID file | PID文件
119
192
 
@@ -125,10 +198,15 @@ User configuration is stored in `~/.tcpmapping/`:
125
198
 
126
199
  ## Security | 安全特性
127
200
 
128
- - **Strong Password Policy** - 8+ chars, uppercase, lowercase, numbers | 强密码策略
201
+ - **No Default Password** - The WebUI will not start until `setup-password` is run | 无默认密码
202
+ - **Strong Password Policy** - Length, character classes and expiry are configurable | 可配置的强密码策略
129
203
  - **Login Protection** - Lock after 5 failed attempts for 30 minutes | 登录保护
130
- - **Session Timeout** - 24 hours auto expiration | 会话超时
131
- - **Password Encryption** - bcrypt with 12 rounds | bcrypt加密
204
+ - **Session Hardening** - Session ID regeneration on login, HttpOnly + SameSite cookies | 会话加固
205
+ - **CSRF Protection** - Cross-origin state-changing requests are rejected | 跨站请求防护
206
+ - **Security Headers** - CSP, X-Frame-Options, nosniff and no-store API responses | 安全响应头
207
+ - **Localhost by Default** - The WebUI listens on 127.0.0.1 unless configured otherwise | 默认仅本机访问
208
+ - **Atomic Config Writes** - Configuration files are written atomically | 配置原子写入
209
+ - **Password Encryption** - bcrypt hashing | bcrypt加密
132
210
 
133
211
  ---
134
212
 
@@ -174,9 +252,34 @@ tcpmapping status
174
252
 
175
253
  ### Port already in use? | 端口被占用?
176
254
 
177
- Edit `webui.port` or `mappings[].listen.port` in config.json.
255
+ Start with another port, or edit `webui.port` / `mappings[].listen.port` in config.json.
256
+
257
+ 使用 `--port` 指定其他端口启动,或修改 config.json 中的 `webui.port` / `mappings[].listen.port`。
258
+
259
+ ```bash
260
+ tcpmapping restart --port 8080
261
+ ```
262
+
263
+ ---
264
+
265
+ ## Development | 开发
266
+
267
+ Run the smoke test (starts an isolated server, verifies login, CRUD, TCP forwarding and statistics):
268
+
269
+ 运行冒烟测试(启动独立实例,验证登录、映射增删改、TCP 转发与统计):
270
+
271
+ ```bash
272
+ npm install
273
+ npm test
274
+ ```
275
+
276
+ ---
277
+
278
+ ## Changelog | 更新日志
279
+
280
+ See [CHANGELOG.md](CHANGELOG.md) for details.
178
281
 
179
- 修改 config.json 中的 `webui.port` 或 `mappings[].listen.port`。
282
+ 详见 [CHANGELOG.md](CHANGELOG.md)。
180
283
 
181
284
  ---
182
285