@ystemsrx/cfshare 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Sixteen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,337 @@
1
+ <h1 align="center">☁️ CFShare</h1>
2
+
3
+ <p align="center">
4
+ Securely share local files and services to the public internet via Cloudflare Tunnel
5
+ </p>
6
+
7
+ <p align="center">
8
+ <img src="https://img.shields.io/badge/Platform-macOS_|_Linux_|_Windows_(WSL2)-9cf?style=flat-square" alt="Platform">
9
+ <img src="https://img.shields.io/badge/Node-≥22-339933?style=flat-square&logo=node.js&logoColor=white" alt="Node">
10
+ <img src="https://img.shields.io/badge/OpenClaw-≥2026.1.29-E86D37?style=flat-square" alt="OpenClaw">
11
+ <img src="https://img.shields.io/badge/License-MIT-97CA00?style=flat-square" alt="MIT">
12
+ </p>
13
+
14
+ <p align="center">
15
+ <a href="./README.zh.md">简体中文</a>
16
+ &nbsp;|&nbsp;
17
+ <strong>English</strong>
18
+ </p>
19
+
20
+ ---
21
+
22
+ ## 📖 What Is This?
23
+
24
+ **CFShare** is a community plugin for [OpenClaw](https://github.com/openclaw/openclaw) that enables your AI assistant to:
25
+
26
+ - 🔗 **Expose a local port** as a temporary public HTTPS link (`https://*.trycloudflare.com`) with one command
27
+ - 📁 **Share files/directories** — automatically spins up a local static server + tunnel so recipients can browse/download/preview via a link (encryption supported)
28
+ - 🔒 **Built-in security** — Token/Basic auth, rate limiting, port blacklist, exclusion rules
29
+ - ⏱️ **Auto-expiry cleanup** — tunnels are automatically closed and temp files deleted when the TTL expires
30
+
31
+ > [!NOTE]
32
+ > **No Cloudflare account required.** CFShare uses [Cloudflare Quick Tunnel](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/do-more-with-tunnels/trycloudflare/) (`trycloudflare.com`), which is completely free and works out of the box.
33
+
34
+ ---
35
+
36
+ ## 🏗️ How It Works
37
+
38
+ ```mermaid
39
+ flowchart LR
40
+ subgraph LOCAL["Your Machine"]
41
+ A["Local Service / Files"]
42
+ B["[Optional] Reverse Proxy<br/>(Auth + Rate Limit)"]
43
+ C["cloudflared tunnel"]
44
+
45
+ A --> B
46
+ B --> C
47
+ end
48
+
49
+ C ==>|Cloudflare Quick Tunnel| D["https://xxx.trycloudflare.com"]
50
+ E["Recipient's Browser"] --> D
51
+ ```
52
+
53
+ Internally, CFShare handles: path validation → copy files to a temp directory → start a read-only static server → mount auth/rate-limit reverse proxy → launch `cloudflared` tunnel → schedule expiry cleanup. All you need to do is tell the AI "what you want to share" and it takes care of the rest.
54
+
55
+ ---
56
+
57
+ ## 🚀 Installation
58
+
59
+ ### Step 1: Make Sure OpenClaw Is Installed
60
+
61
+ If you haven't installed OpenClaw yet, do so first:
62
+
63
+ ```bash
64
+ # Install OpenClaw (requires Node.js ≥ 22)
65
+ npm install -g openclaw@latest
66
+
67
+ # Run the onboarding wizard
68
+ openclaw onboard --install-daemon
69
+ ```
70
+
71
+ > [!TIP]
72
+ > Not sure about your Node.js version? Run `node -v` to check. [nvm](https://github.com/nvm-sh/nvm) is recommended for managing versions.
73
+
74
+ ---
75
+
76
+ ### Step 2: Install `cloudflared`
77
+
78
+ CFShare relies on Cloudflare's `cloudflared` CLI to create tunnels.
79
+
80
+ <details>
81
+ <summary><b>🍎 macOS</b></summary>
82
+
83
+ ```bash
84
+ brew install cloudflare/cloudflare/cloudflared
85
+ ```
86
+
87
+ </details>
88
+
89
+ <details>
90
+ <summary><b>🐧 Linux (Debian / Ubuntu)</b></summary>
91
+
92
+ ```bash
93
+ curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
94
+ echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflared.list
95
+ sudo apt-get update && sudo apt-get install cloudflared
96
+ ```
97
+
98
+ </details>
99
+
100
+ <details>
101
+ <summary><b>🪟 Windows (inside WSL2)</b></summary>
102
+
103
+ ```bash
104
+ # Inside WSL2:
105
+ curl -fsSL https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/local/bin/cloudflared
106
+ chmod +x /usr/local/bin/cloudflared
107
+ ```
108
+
109
+ Or install natively via PowerShell / CMD with winget:
110
+
111
+ ```powershell
112
+ winget install --id Cloudflare.cloudflared
113
+ ```
114
+
115
+ </details>
116
+
117
+ **Or simply ask the Agent to install it for you.**
118
+
119
+ Verify the installation:
120
+
121
+ ```bash
122
+ cloudflared --version
123
+ # Output should be similar to: cloudflared version 2025.x.x
124
+ ```
125
+
126
+ > [!IMPORTANT]
127
+ > You only need to install `cloudflared` — there is **no need** to run `cloudflared tunnel login`. Quick Tunnel requires no account authentication.
128
+
129
+ ---
130
+
131
+ ### Step 3: Install the CFShare Plugin
132
+
133
+ **Option A — Install from npm (recommended):**
134
+
135
+ ```bash
136
+ openclaw plugins install @ystemsrx/cfshare
137
+ ```
138
+
139
+ **Option B — Install from a local directory (for development):**
140
+
141
+ If you've already cloned the repository:
142
+
143
+ ```bash
144
+ # Install dependencies first
145
+ cd /path/to/cfshare
146
+ npm install
147
+
148
+ # Link to OpenClaw (dev mode, no file copying)
149
+ openclaw plugins install -l .
150
+ ```
151
+
152
+ ---
153
+
154
+ ### Step 4: Enable the Plugin and Restart the Gateway
155
+
156
+ ```bash
157
+ # Enable the plugin
158
+ openclaw plugins enable cfshare
159
+
160
+ # Restart the Gateway to load the plugin
161
+ openclaw gateway restart
162
+ ```
163
+
164
+ > [!NOTE]
165
+ > If you're running in daemon mode (`--install-daemon`), you can also restart via `openclaw restart`.
166
+
167
+ ---
168
+
169
+ ## ⚙️ Configuration (Optional)
170
+
171
+ CFShare works out of the box. The defaults below suit most use cases. To customize, edit `~/.openclaw/openclaw.json`:
172
+
173
+ ```json5
174
+ {
175
+ plugins: {
176
+ entries: {
177
+ cfshare: {
178
+ enabled: true,
179
+ config: {
180
+ // Custom configuration (all fields are optional)
181
+ },
182
+ },
183
+ },
184
+ },
185
+ }
186
+ ```
187
+
188
+ ### Configuration Reference
189
+
190
+ | Option | Default | Description |
191
+ | :------------------------- | :-------------------- | :--------------------------------------- |
192
+ | `cloudflaredPath` | `"cloudflared"` | Path or command name for `cloudflared` |
193
+ | `stateDir` | `~/.openclaw/cfshare` | Directory for state file storage |
194
+ | `defaultTtlSeconds` | `3600` (1 hour) | Default tunnel time-to-live |
195
+ | `maxTtlSeconds` | `86400` (24 hours) | Maximum TTL cap |
196
+ | `defaultExposePortAccess` | `"token"` | Default auth mode for port exposure |
197
+ | `defaultExposeFilesAccess` | `"none"` | Default auth mode for file sharing |
198
+ | `blockedPorts` | `[22, 2375, 2376]` | Ports blocked from exposure (SSH/Docker) |
199
+ | `rateLimit.enabled` | `true` | Whether rate limiting is enabled |
200
+ | `rateLimit.maxRequests` | `240` | Max requests per window |
201
+ | `rateLimit.windowMs` | `60000` (1 minute) | Rate limit window in milliseconds |
202
+
203
+ > [!TIP]
204
+ > **Auth mode reference:**
205
+ >
206
+ > - `"token"` — A token is required to access the link (suitable for port exposure)
207
+ > - `"basic"` — HTTP Basic authentication (username/password)
208
+ > - `"none"` — No authentication, anyone can access (suitable for temporary file sharing)
209
+
210
+ ---
211
+
212
+ ## 💬 Usage Examples
213
+
214
+ Once installed, just speak naturally to your AI assistant — it will automatically invoke the appropriate CFShare tools:
215
+
216
+ ### Get AI-Processed Files
217
+
218
+ > _"Rename all files under `/mnt/data/students/` to `{index}_{name}.{ext}` format, then bundle them up and give me a download link."_
219
+
220
+ The Agent will automatically call `expose_files` and return a public link along with its expiration time.
221
+
222
+ ### Share Your Creations
223
+
224
+ > _"Build a 3D interactive solar system model with Vue 3 + Vite, then share it with my friend via a link."_
225
+
226
+ > _"Run this project for me and send me the link to access it."_
227
+
228
+ The Agent will create and run the project, then use `expose_port` to create a tunnel so anyone can access it through a link.
229
+
230
+ ### Share a Directory (with File Browser) — preview images/videos/text in-browser, or download (encryption supported)
231
+
232
+ > _"Share the directory `~/Pictures/vacation` with encryption."_
233
+
234
+ The Agent will use `expose_files` in `preview` mode to create a share page with a file browser. A valid token is required to access it.
235
+
236
+ ### View Active Shares
237
+
238
+ > _"What links do I have active right now?"_
239
+
240
+ ### Stop Sharing
241
+
242
+ > _"Shut down all active share links."_
243
+
244
+ ---
245
+
246
+ ## 🧰 Tool Overview
247
+
248
+ CFShare registers the following tools for the AI:
249
+
250
+ | Tool | Purpose |
251
+ | :-------------- | :------------------------------------------------ |
252
+ | `env_check` | Check if `cloudflared` is available & view policy |
253
+ | `expose_port` | Expose a local port to the public internet |
254
+ | `expose_files` | Share files/directories (auto static server) |
255
+ | `exposure_list` | List all active sessions |
256
+ | `exposure_get` | Get details for a specific session |
257
+ | `exposure_stop` | Stop and clean up specific or all sessions |
258
+ | `exposure_logs` | View session logs |
259
+ | `maintenance` | TTL guardian / garbage collection / policy refresh |
260
+ | `audit_query` | Query audit logs |
261
+ | `audit_export` | Export audit logs to a file |
262
+
263
+ ---
264
+
265
+ ## 🔐 Security Design
266
+
267
+ <table>
268
+ <tr><td>🛡️</td><td><b>Secure by Default</b></td><td>Port exposure defaults to token auth + reverse proxy protection</td></tr>
269
+ <tr><td>🚫</td><td><b>Port Blacklist</b></td><td>SSH (22) and Docker Daemon (2375/2376) are blocked by default</td></tr>
270
+ <tr><td>⏳</td><td><b>Auto Expiry</b></td><td>Sessions automatically close tunnels and delete temp files upon expiration</td></tr>
271
+ <tr><td>📊</td><td><b>Rate Limiting</b></td><td>Per-IP sliding window rate limiting (default: 240 req/min)</td></tr>
272
+ <tr><td>📝</td><td><b>Audit Logging</b></td><td>All operations are logged to a local JSONL file</td></tr>
273
+ <tr><td>🙈</td><td><b>File Exclusion</b></td><td>Automatically excludes <code>.git/</code>, <code>.openclaw/</code>, and respects <code>.gitignore</code> rules</td></tr>
274
+ </table>
275
+
276
+ ---
277
+
278
+ ## ❓ FAQ
279
+
280
+ <details>
281
+ <summary><b>Q: Do I need a paid Cloudflare account?</b></summary>
282
+
283
+ No. CFShare uses Cloudflare Quick Tunnel (`trycloudflare.com`), which is completely free and requires no account registration.
284
+
285
+ </details>
286
+
287
+ <details>
288
+ <summary><b>Q: How long do links last?</b></summary>
289
+
290
+ By default, 1 hour. This can be adjusted via configuration or specified per share (up to 7 days). Links are automatically destroyed upon expiry.
291
+
292
+ </details>
293
+
294
+ <details>
295
+ <summary><b>Q: What if cloudflared is not found?</b></summary>
296
+
297
+ 1. Confirm `cloudflared` is installed: `cloudflared --version`
298
+ 2. If it's installed in a location not in your `PATH`, specify the full path in the config:
299
+
300
+ ```json5
301
+ {
302
+ plugins: {
303
+ entries: {
304
+ cfshare: {
305
+ config: { cloudflaredPath: "/usr/local/bin/cloudflared" },
306
+ },
307
+ },
308
+ },
309
+ }
310
+ ```
311
+
312
+ </details>
313
+
314
+ <details>
315
+ <summary><b>Q: Can I use it directly on Windows?</b></summary>
316
+
317
+ OpenClaw officially strongly recommends using WSL2 on Windows. CFShare follows the same guidance — please use it within a WSL2 environment.
318
+
319
+ </details>
320
+
321
+ <details>
322
+ <summary><b>Q: How do I verify the plugin installed correctly?</b></summary>
323
+
324
+ ```bash
325
+ openclaw plugins list
326
+ # You should see cfshare listed as enabled
327
+ ```
328
+
329
+ Then tell the AI _"Run the cfshare environment check"_ — it will call `env_check` and return detailed status information.
330
+
331
+ </details>
332
+
333
+ ---
334
+
335
+ ## 📄 License
336
+
337
+ MIT © [ystemsrx](https://github.com/ystemsrx)
package/README.zh.md ADDED
@@ -0,0 +1,337 @@
1
+ <h1 align="center">☁️ CFShare</h1>
2
+
3
+ <p align="center">
4
+ 通过 Cloudflare 隧道安全地将本地文件与服务分享到公网
5
+ </p>
6
+
7
+ <p align="center">
8
+ <img src="https://img.shields.io/badge/平台-macOS_|_Linux_|_Windows_(WSL2)-9cf?style=flat-square" alt="平台">
9
+ <img src="https://img.shields.io/badge/Node-≥22-339933?style=flat-square&logo=node.js&logoColor=white" alt="Node">
10
+ <img src="https://img.shields.io/badge/OpenClaw-≥2026.1.29-E86D37?style=flat-square" alt="OpenClaw">
11
+ <img src="https://img.shields.io/badge/许可-MIT-97CA00?style=flat-square" alt="MIT">
12
+ </p>
13
+
14
+ <p align="center">
15
+ <strong>简体中文</strong>
16
+ &nbsp;|&nbsp;
17
+ <a href="./README.md">English</a>
18
+ </p>
19
+
20
+ ---
21
+
22
+ ## 📖 这是什么?
23
+
24
+ **CFShare** 是 [OpenClaw](https://github.com/openclaw/openclaw) 的社区插件,让你的 AI 助手能够:
25
+
26
+ - 🔗 **一键将本地端口**暴露为临时公网 HTTPS 链接(`https://*.trycloudflare.com`)
27
+ - 📁 **分享文件/目录**——自动起本地静态服务器 + 隧道,对方打开链接即可浏览/下载/预览(支持加密)
28
+ - 🔒 **内置安全策略**——Token/Basic 认证、速率限制、端口黑名单、排除规则
29
+ - ⏱️ **自动过期清理**——TTL 到期自动关闭隧道并删除临时文件
30
+
31
+ > [!NOTE]
32
+ > **无需 Cloudflare 账号**。CFShare 使用的是 [Cloudflare Quick Tunnel](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/do-more-with-tunnels/trycloudflare/)(`trycloudflare.com`),完全免费、即开即用。
33
+
34
+ ---
35
+
36
+ ## 🏗️ 工作原理
37
+
38
+ ```mermaid
39
+ flowchart LR
40
+ subgraph LOCAL["你的电脑"]
41
+ A["本地服务 / 文件"]
42
+ B["[可选] 反向代理<br/>(认证 + 限流)"]
43
+ C["cloudflared tunnel"]
44
+
45
+ A --> B
46
+ B --> C
47
+ end
48
+
49
+ C ==>|Cloudflare Quick Tunnel| D["https://xxx.trycloudflare.com"]
50
+ E["对方浏览器"] --> D
51
+ ```
52
+
53
+ CFShare 在内部完成:路径校验 → 文件复制到临时目录 → 启动只读静态服务器 → 挂载认证/限流反代 → 开启 `cloudflared` 隧道 → 设置过期回收。你只需告诉 AI “我要分享什么”,它会帮你完成剩下的工作。
54
+
55
+ ---
56
+
57
+ ## 🚀 安装步骤
58
+
59
+ ### 第一步:确保已安装 OpenClaw
60
+
61
+ 如果你还没有安装 OpenClaw,请先完成安装:
62
+
63
+ ```bash
64
+ # 安装 OpenClaw(需要 Node.js ≥ 22)
65
+ npm install -g openclaw@latest
66
+
67
+ # 运行初始化向导
68
+ openclaw onboard --install-daemon
69
+ ```
70
+
71
+ > [!TIP]
72
+ > 如果你不确定 Node.js 版本,运行 `node -v` 检查。推荐使用 [nvm](https://github.com/nvm-sh/nvm) 管理版本。
73
+
74
+ ---
75
+
76
+ ### 第二步:安装 `cloudflared`
77
+
78
+ CFShare 依赖 Cloudflare 的 `cloudflared` 命令行工具来创建隧道。
79
+
80
+ <details>
81
+ <summary><b>🍎 macOS</b></summary>
82
+
83
+ ```bash
84
+ brew install cloudflare/cloudflare/cloudflared
85
+ ```
86
+
87
+ </details>
88
+
89
+ <details>
90
+ <summary><b>🐧 Linux(Debian / Ubuntu)</b></summary>
91
+
92
+ ```bash
93
+ curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
94
+ echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflared.list
95
+ sudo apt-get update && sudo apt-get install cloudflared
96
+ ```
97
+
98
+ </details>
99
+
100
+ <details>
101
+ <summary><b>🪟 Windows(WSL2 内操作)</b></summary>
102
+
103
+ ```bash
104
+ # 在 WSL2 中:
105
+ curl -fsSL https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/local/bin/cloudflared
106
+ chmod +x /usr/local/bin/cloudflared
107
+ ```
108
+
109
+ 或在 Windows 原生 PowerShell / CMD 中使用 winget:
110
+
111
+ ```powershell
112
+ winget install --id Cloudflare.cloudflared
113
+ ```
114
+
115
+ </details>
116
+
117
+ **或者直接告诉 Agent 让他帮你安装**
118
+
119
+ 安装后验证:
120
+
121
+ ```bash
122
+ cloudflared --version
123
+ # 输出类似: cloudflared version 2025.x.x
124
+ ```
125
+
126
+ > [!IMPORTANT]
127
+ > 只需安装 `cloudflared`,**不需要**运行 `cloudflared tunnel login`。Quick Tunnel 无需账号认证。
128
+
129
+ ---
130
+
131
+ ### 第三步:安装 CFShare 插件
132
+
133
+ **方式 A — 从 npm 安装(推荐):**
134
+
135
+ ```bash
136
+ openclaw plugins install @ystemsrx/cfshare
137
+ ```
138
+
139
+ **方式 B — 从本地目录安装(适用于开发):**
140
+
141
+ 如果你已经克隆了仓库:
142
+
143
+ ```bash
144
+ # 先安装依赖
145
+ cd /path/to/cfshare
146
+ npm install
147
+
148
+ # 链接到 OpenClaw(开发模式,不复制文件)
149
+ openclaw plugins install -l .
150
+ ```
151
+
152
+ ---
153
+
154
+ ### 第四步:启用插件并重启 Gateway
155
+
156
+ ```bash
157
+ # 启用插件
158
+ openclaw plugins enable cfshare
159
+
160
+ # 重启 Gateway 使插件生效
161
+ openclaw gateway restart
162
+ ```
163
+
164
+ > [!NOTE]
165
+ > 如果你使用守护进程模式(`--install-daemon`),也可以通过 `openclaw restart` 重启。
166
+
167
+ ---
168
+
169
+ ## ⚙️ 配置(可选)
170
+
171
+ CFShare 开箱即用,以下默认配置适合绝大多数场景。如需调整,编辑 `~/.openclaw/openclaw.json`:
172
+
173
+ ```json5
174
+ {
175
+ plugins: {
176
+ entries: {
177
+ cfshare: {
178
+ enabled: true,
179
+ config: {
180
+ // 自定义配置(以下皆为可选项)
181
+ },
182
+ },
183
+ },
184
+ },
185
+ }
186
+ ```
187
+
188
+ ### 可配置项速查
189
+
190
+ | 配置项 | 默认值 | 说明 |
191
+ | :------------------------- | :-------------------- | :----------------------------- |
192
+ | `cloudflaredPath` | `"cloudflared"` | `cloudflared` 的路径或名称 |
193
+ | `stateDir` | `~/.openclaw/cfshare` | 状态文件存储目录 |
194
+ | `defaultTtlSeconds` | `3600`(1 小时) | 默认隧道存活时间 |
195
+ | `maxTtlSeconds` | `86400`(24 小时) | 最大 TTL 上限 |
196
+ | `defaultExposePortAccess` | `"token"` | 端口暴露默认认证模式 |
197
+ | `defaultExposeFilesAccess` | `"none"` | 文件分享默认认证模式 |
198
+ | `blockedPorts` | `[22, 2375, 2376]` | 禁止暴露的端口(SSH / Docker) |
199
+ | `rateLimit.enabled` | `true` | 是否启用速率限制 |
200
+ | `rateLimit.maxRequests` | `240` | 每窗口期最大请求数 |
201
+ | `rateLimit.windowMs` | `60000`(1 分钟) | 速率限制窗口(毫秒) |
202
+
203
+ > [!TIP]
204
+ > **认证模式说明:**
205
+ >
206
+ > - `"token"` — 访问链接需要带 Token(适合暴露端口)
207
+ > - `"basic"` — HTTP Basic 认证(用户名/密码)
208
+ > - `"none"` — 无认证,任何人都可访问(适合临时分享文件)
209
+
210
+ ---
211
+
212
+ ## 💬 使用示例
213
+
214
+ 安装完成后,你可以直接对 AI 助手说自然语言,它会自动调用 CFShare 工具:
215
+
216
+ ### 获取 AI 处理好的文件
217
+
218
+ > _按照 `{index}_{name}.{ext}` 的格式整理 `/mnt/data/students/` 下所有文件名,最后打包发我下载链接_
219
+
220
+ Agent 会自动执行 `expose_files`,返回一个公网链接和过期时间。
221
+
222
+ ### 分享你的作品
223
+
224
+ > _"用 Vue3+Vite 框架完成3D交互式太阳系模型,然后用链接分享给我朋友"_
225
+
226
+ >_"帮我运行这个项目,最后把链接发我访问"_
227
+
228
+ Agent 会创建项目并运行,然后通过 `expose_port` 创建隧道,让任何人都能通过一个链接访问。
229
+
230
+ ### 分享目录(带文件浏览器),可以在浏览器中预览图片/视频/文本等,也可以下载(支持加密)
231
+
232
+ > _"加密分享目录 `~/Pictures/vacation`"_
233
+
234
+ Agent 会用 `expose_files` 的 `preview` 模式创建带文件浏览器的分享页面,你需要拥有有效的 Token 才能访问。
235
+
236
+ ### 查看活跃分享
237
+
238
+ > _"我现在有哪些正在分享的链接?"_
239
+
240
+ ### 停止分享
241
+
242
+ > _"关掉所有正在分享的链接"_
243
+
244
+ ---
245
+
246
+ ## 🧰 工具一览
247
+
248
+ CFShare 为 AI 注册了以下工具:
249
+
250
+ | 工具 | 作用 |
251
+ | :-------------- | :------------------------------------ |
252
+ | `env_check` | 检查 `cloudflared` 是否可用及当前策略 |
253
+ | `expose_port` | 暴露本地端口到公网 |
254
+ | `expose_files` | 分享文件/目录(自动起静态服务器) |
255
+ | `exposure_list` | 列出所有活跃会话 |
256
+ | `exposure_get` | 获取指定会话详情 |
257
+ | `exposure_stop` | 停止并清理指定/全部会话 |
258
+ | `exposure_logs` | 查看会话日志 |
259
+ | `maintenance` | TTL 守护 / 垃圾回收 / 策略更新 |
260
+ | `audit_query` | 查询审计日志 |
261
+ | `audit_export` | 导出审计日志到文件 |
262
+
263
+ ---
264
+
265
+ ## 🔐 安全设计
266
+
267
+ <table>
268
+ <tr><td>🛡️</td><td><b>默认安全</b></td><td>端口暴露默认开启 Token 认证 + 反向代理保护</td></tr>
269
+ <tr><td>🚫</td><td><b>端口黑名单</b></td><td>SSH (22)、Docker Daemon (2375/2376) 默认禁止暴露</td></tr>
270
+ <tr><td>⏳</td><td><b>自动过期</b></td><td>会话到期自动关闭隧道并删除临时文件</td></tr>
271
+ <tr><td>📊</td><td><b>速率限制</b></td><td>Per-IP 滑动窗口限流(默认 240 次/分钟)</td></tr>
272
+ <tr><td>📝</td><td><b>审计日志</b></td><td>所有操作记录到本地 JSONL 文件</td></tr>
273
+ <tr><td>🙈</td><td><b>文件排除</b></td><td>自动排除 <code>.git/</code>、<code>.openclaw/</code>,并遵守 <code>.gitignore</code> 规则</td></tr>
274
+ </table>
275
+
276
+ ---
277
+
278
+ ## ❓ 常见问题
279
+
280
+ <details>
281
+ <summary><b>Q: 需要 Cloudflare 付费账号吗?</b></summary>
282
+
283
+ 不需要。CFShare 使用 Cloudflare Quick Tunnel(`trycloudflare.com`),完全免费,无需注册账号。
284
+
285
+ </details>
286
+
287
+ <details>
288
+ <summary><b>Q: 链接有效期多长?</b></summary>
289
+
290
+ 默认 1 小时,可通过配置或每次分享时指定(最长 7 天)。到期后自动销毁。
291
+
292
+ </details>
293
+
294
+ <details>
295
+ <summary><b>Q: cloudflared 提示找不到怎么办?</b></summary>
296
+
297
+ 1. 确认 `cloudflared` 已安装:`cloudflared --version`
298
+ 2. 如果安装位置不在 `PATH` 中,在配置里指定完整路径:
299
+
300
+ ```json5
301
+ {
302
+ plugins: {
303
+ entries: {
304
+ cfshare: {
305
+ config: { cloudflaredPath: "/usr/local/bin/cloudflared" },
306
+ },
307
+ },
308
+ },
309
+ }
310
+ ```
311
+
312
+ </details>
313
+
314
+ <details>
315
+ <summary><b>Q: 可以在 Windows 上直接用吗?</b></summary>
316
+
317
+ OpenClaw 官方强烈推荐在 Windows 上使用 WSL2。CFShare 同样遵循此建议,请在 WSL2 环境中使用。
318
+
319
+ </details>
320
+
321
+ <details>
322
+ <summary><b>Q: 如何验证插件是否安装成功?</b></summary>
323
+
324
+ ```bash
325
+ openclaw plugins list
326
+ # 应该能看到 cfshare 处于 enabled 状态
327
+ ```
328
+
329
+ 然后对 AI 说 _"运行 cfshare 环境检查"_,它会调用 `env_check` 并返回详细状态。
330
+
331
+ </details>
332
+
333
+ ---
334
+
335
+ ## 📄 许可
336
+
337
+ MIT © [ystemsrx](https://github.com/ystemsrx)