Skip to content

Commit

Permalink
support fragment feature
Browse files Browse the repository at this point in the history
  • Loading branch information
nobody committed Dec 31, 2024
1 parent 633b3e9 commit f6f1cfb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
* `PROXY` (可留空)反代 CF 网页的服务器,逗号分隔,每次随机抽取一个,格式:`a.com, b.com, ...`
* `LOG_LEVEL` 日志级别,可选值:`debug`, `info`, `error`, `none`
* `TIME_ZONE` 日志时间戳的时区,中国填 `8`
* `WS_PATH` ws 协议的访问路径,例如:`/ws`,留空表示关闭这个功能
* `XHTTP_PATH` xhttp 协议的访问路径,例如:`/xhttp`,留空表示关闭这个功能
* `XPADDING_RANGE` xhttp 协议回复头中 X-Padding 的长度范围,例如:`100-1000` 或者 `10`,填 `0` 表示关闭这个功能
* `WS_PATH` ws 协议的访问路径,例如:`/ws`,留空表示关闭这个功能
* `DOH_QUERY_PATH` DoH 服务的访问路径,例如:`/doh-query`,留空表示关闭这个功能
* `UPSTREAM_DOH` 上游 DoH 服务器,例如:`https://dns.google/dns-query`,注意不要填 Cloudflare 的 DNS
* `IP_QUERY_PATH` 查询客户 IP 信息功能的访问路径,例如: `/ip-query/?key=123456`,留空表示关闭这个功能,后面那个 key 相当于密码

这些配置项也可以在 workers 的环境变量界面中配置。环境变量的优先级更高。

一切顺利的话,访问 `https://sub.your-website.com` 会看到 `Hello world!`
访问 `https://sub.your-website.com/(XHTTP_PATH)/?uuid=(YOUR-UUID)` 得到 xhttp 客户端的 `config.json`,把 `(XHTTP_PATH)` 改为 `(WS_PATH)` 得到 ws 的配置。
访问 `https://sub.your-website.com/(WS_PATH)/?fragment=true&uuid=(YOUR-UUID)` 得到 WebSocket 协议的客户端 `config.json`,把 `(WS_PATH)` 改为 `(XHTTP_PATH)` 得到 xhttp 协议的配置。修改 `fragment=false` 得到关闭分片功能的配置。

#### 注意事项
* 网站测速结果是错的,这个脚本很慢,不要有太高的期望
Expand Down
4 changes: 2 additions & 2 deletions docs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ There are some configurations at the top of the source code.
* `PROXY` (optional) Reverse proxies for websites using Cloudflare CDN. Random pick one for every connection. Format: `a.com, b.com, ...`
* `LOG_LEVEL` debug, info, error, none
* `TIME_ZONE` Timestamp time zone of logs. e.g. Argentina is `-3`
* `WS_PATH` URL path for ws transport. e.g. `/ws`. Leave it empty to disable this feature.
* `XHTTP_PATH` URL path for xhttp transport. e.g. `/xhttp`. Leave it empty to disable this feature.
* `XPADDING_RANGE` Length range of X-Padding response header. e.g. `100-1000`, `10`, Set to `0` to disable this feature.
* `WS_PATH` URL path for ws transport. e.g. `/ws`. Leave it empty to disable this feature.
* `DOH_QUERY_PATH` URL path for DNS over HTTP(S) feature. e.g. `/doh-query`. Leave it empty to disable this feature.
* `UPSTREAM_DOH` e.g. `https://dns.google/dns-query`. Do not use Cloudflare DNS.
* `IP_QUERY_PATH` URL path for querying client IP information feature. e.g. `/ip-query/?key=123456`. Leave it empty to disable this feature. The following `key` parameter is used for authentication.

You can setup those configurations in worker's enviroment variables config panel too. Env-vars have higher priority.

If every thing goes right, you would see a `Hello world!` when accessing `https://sub.your-website.com/`.
Visit `https://sub.your-website.com/(XHTTP_PATH)/?uuid=(YOUR-UUID)` to get a `client-config.json` with xhttp transport. Replace `(XHTTP_PATH)` with `(WS_PATH)` to get a config with ws transport.
Visit `https://sub.your-website.com/(WS_PATH)/?fragment=true&uuid=(YOUR-UUID)` to get a `client-config.json` with WebSocket transport. Replace `(WS_PATH)` with `(XHTTP_PATH)` to get a config with xhttp transport. Set `fragemnt` to `false` to get a config without fragment settings.

#### Notice
* This script is slow, do not expect too much.
Expand Down
4 changes: 4 additions & 0 deletions docs/update-log.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### 发布记录

#### v1.0.1 (尚未发布)
* 支持指定多个 Cloudflare 反向代理
* 生成的配置添加分片(fragment)选项

#### v1.0.0 (2024-12)
* WebSocket 协议
* XHTTP 协议
Expand Down
17 changes: 17 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,23 @@ function create_config(ctype, url, uuid) {
return null
}

if (url.searchParams.get('fragment') === 'true') {
config['outbounds'][0]['proxySettings'] = {
tag: 'direct',
transportLayer: true,
}
config['outbounds'].push({
tag: 'direct',
protocol: 'freedom',
settings: {
fragment: {
packets: 'tlshello',
length: '100-200',
interval: '10-20',
},
},
})
}
stream['network'] = ctype
return config
}
Expand Down

0 comments on commit f6f1cfb

Please sign in to comment.