├── _worker.js.zip ├── .github └── workflows │ └── zip_flows.yml ├── .gitignore ├── README.md ├── LICENSE └── _worker.js /_worker.js.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amclubs/am-cf-auto-trojan/HEAD/_worker.js.zip -------------------------------------------------------------------------------- /.github/workflows/zip_flows.yml: -------------------------------------------------------------------------------- 1 | name: zip_flows # 工作流程的名称 2 | 3 | on: 4 | workflow_dispatch: # 手动触发 5 | push: 6 | paths: 7 | - '_worker.js' # 当 _worker.js 文件发生变动时触发 8 | 9 | permissions: 10 | contents: write 11 | 12 | jobs: 13 | package-and-commit: 14 | runs-on: ubuntu-latest # 运行环境,这里使用最新版本的 Ubuntu 15 | steps: 16 | - name: Checkout Repository # 检出代码 17 | uses: actions/checkout@v2 18 | 19 | - name: Zip the worker file # 将 _worker.js 文件打包成 worker.js.zip 20 | run: zip _worker.js.zip _worker.js 21 | 22 | - name: Commit and push the packaged file # 提交并推送打包后的文件 23 | uses: EndBug/add-and-commit@v7 24 | with: 25 | add: '_worker.js.zip' 26 | message: 'Automatically package and commit _worker.js.zip' 27 | author_name: github-actions[bot] 28 | author_email: actions[bot]@users.noreply.github.com 29 | token: ${{ secrets.GH_TOKEN }} 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | .DS_Store 26 | 27 | # nyc test coverage 28 | .nyc_output 29 | 30 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 31 | .grunt 32 | 33 | # Bower dependency directory (https://bower.io/) 34 | bower_components 35 | 36 | # node-waf configuration 37 | .lock-wscript 38 | 39 | # Compiled binary addons (https://nodejs.org/api/addons.html) 40 | build/Release 41 | 42 | # Dependency directories 43 | node_modules/ 44 | jspm_packages/ 45 | 46 | # Snowpack dependency directory (https://snowpack.dev/) 47 | web_modules/ 48 | 49 | # TypeScript cache 50 | *.tsbuildinfo 51 | 52 | # Optional npm cache directory 53 | .npm 54 | 55 | # Optional eslint cache 56 | .eslintcache 57 | 58 | # Optional stylelint cache 59 | .stylelintcache 60 | 61 | # Microbundle cache 62 | .rpt2_cache/ 63 | .rts2_cache_cjs/ 64 | .rts2_cache_es/ 65 | .rts2_cache_umd/ 66 | 67 | # Optional REPL history 68 | .node_repl_history 69 | 70 | # Output of 'npm pack' 71 | *.tgz 72 | 73 | # Yarn Integrity file 74 | .yarn-integrity 75 | 76 | # dotenv environment variable files 77 | .env 78 | .env.development.local 79 | .env.test.local 80 | .env.production.local 81 | .env.local 82 | 83 | # parcel-bundler cache (https://parceljs.org/) 84 | .cache 85 | .parcel-cache 86 | 87 | # Next.js build output 88 | .next 89 | out 90 | 91 | # Nuxt.js build / generate output 92 | .nuxt 93 | dist 94 | 95 | # Gatsby files 96 | .cache/ 97 | # Comment in the public line in if your project uses Gatsby and not Next.js 98 | # https://nextjs.org/blog/next-9-1#public-directory-support 99 | # public 100 | 101 | # vuepress build output 102 | .vuepress/dist 103 | 104 | # vuepress v2.x temp and cache directory 105 | .temp 106 | .cache 107 | 108 | # Docusaurus cache and generated files 109 | .docusaurus 110 | 111 | # Serverless directories 112 | .serverless/ 113 | 114 | # FuseBox cache 115 | .fusebox/ 116 | 117 | # DynamoDB Local files 118 | .dynamodb/ 119 | 120 | # TernJS port file 121 | .tern-port 122 | 123 | # Stores VSCode versions used for testing VSCode extensions 124 | .vscode-test 125 | 126 | # yarn v2 127 | .yarn/cache 128 | .yarn/unplugged 129 | .yarn/build-state.yml 130 | .yarn/install-state.gz 131 | .pnp.* 132 | 133 | .DS_Store 134 | .vscode 135 | package-lock.json 136 | yarn.lock 137 | 138 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [am-cf-auto-trojan](https://github.com/amclubs/am-cf-auto-trojan) 2 | 这是基于CF平台的脚本,部署Trojan配置信息转换为订阅内容。可以快速生成优先节点信息。 3 | 4 | # 5 | ▶️ **新人[YouTube](https://youtube.com/@am_clubs?sub_confirmation=1)** 需要您的支持,请务必帮我**点赞**、**关注**、**打开小铃铛**,***十分感谢!!!*** ✅ 6 |
🎁请 **follow** 我的[GitHub](https://github.com/amclubs)、给我所有项目一个 **Star** 星星(拜托了)!你的支持是我不断前进的动力! 💖 7 |
✅**解锁更多技能** [加入TG群【am_clubs】](https://t.me/am_clubs)、[YouTube频道【@am_clubs】](https://youtube.com/@am_clubs?sub_confirmation=1)、[【博客(国内)】](https://amclubss.com)、[【博客(国际)】](https://amclubs.blogspot.com) 8 |
✅点击观看教程[CLoudflare免费节点](https://www.youtube.com/playlist?list=PLGVQi7TjHKXbrY0Pk8gm3T7m8MZ-InquF) | [VPS搭建节点](https://www.youtube.com/playlist?list=PLGVQi7TjHKXaVlrHP9Du61CaEThYCQaiY) | [获取免费域名](https://www.youtube.com/playlist?list=PLGVQi7TjHKXZGODTvB8DEervrmHANQ1AR) | [免费VPN](https://www.youtube.com/playlist?list=PLGVQi7TjHKXY7V2JF-ShRSVwGANlZULdk) | [IPTV源](https://www.youtube.com/playlist?list=PLGVQi7TjHKXbkozDYVsDRJhbnNaEOC76w) | [Mac和Win工具](https://www.youtube.com/playlist?list=PLGVQi7TjHKXYBWu65yP8E08HxAu9LbCWm) | [AI分享](https://www.youtube.com/playlist?list=PLGVQi7TjHKXaodkM-mS-2Nwggwc5wRjqY) 9 | 10 | ## Workers 部署方法 11 | 1. 部署 Cloudflare Worker: 12 | - 在 Cloudflare Worker 控制台中创建一个新的 Worker。 13 | - 将 [_worker.js](https://github.com/amclubs/am-cf-auto-trojan/blob/main/_worker.js) 的内容粘贴到 Worker 编辑器中。 14 | 2. 访问订阅内容: 15 | - 访问 `https://[YOUR-WORKERS-URL]/[UUID]` 即可获取订阅内容。 16 | - 例如 `https://vless.google.workers.dev/90cd4a77-141a-43c9-991b-08263cfe9c10` 就是你的通用自适应订阅地址(Quantumult X、Clash、singbox、小火箭、v2rayN、v2rayU、surge、PassWall、SSR+、Karing等)。 17 | - 例如 `https://vless.google.workers.dev/90cd4a77-141a-43c9-991b-08263cfe9c10?base64` Base64订阅格式,适用PassWall,SSR+等。 18 | - 例如 `https://vless.google.workers.dev/90cd4a77-141a-43c9-991b-08263cfe9c10?clash` Clash订阅格式,适用OpenClash等。 19 | - 例如 `https://vless.google.workers.dev/90cd4a77-141a-43c9-991b-08263cfe9c10?singbox` singbox订阅格式,适用singbox等。 20 | 21 | 3. 给 workers绑定 自定义域: 22 | - 在 workers控制台的 `触发器`选项卡,下方点击 `添加自定义域`。 23 | - 填入你已转入 CloudFlare 域名解析服务的次级域名,例如:`vless.google.com`后 点击`添加自定义域`,等待证书生效即可。 24 | 25 | 26 | 27 | ## Pages 上传 部署方法 **最佳推荐!!!** 28 | 1. 部署 Cloudflare Pages: 29 | - 下载 [_worker.js.zip](https://raw.githubusercontent.com/amclubs/am-cf-auto-trojan/main/_worker.js.zip) 文件,并点上 Star !!! 30 | - 在 Cloudflare Pages 控制台中选择 `上传资产`后,为你的项目取名后点击 `创建项目`,然后上传你下载好的 [_worker.js.zip](https://raw.githubusercontent.com/amclubs/am-cf-auto-trojan/main/_worker.js.zip) 文件后点击 `部署站点`。 31 | - 部署完成后点击 `继续处理站点` 后,选择 `设置` > `环境变量` > **制作**为生产环境定义变量 > `添加变量`。 32 | 变量名称填写**UUID**,值则为你的UUID,后点击 `保存`即可。 33 | - 返回 `部署` 选项卡,在右下角点击 `创建新部署` 后,重新上传 [_worker.js.zip](https://raw.githubusercontent.com/amclubs/am-cf-auto-trojan/main/_worker.js.zip) 文件后点击 `保存并部署` 即可。 34 | 2. 访问订阅内容: 35 | - 访问 `https://[YOUR-WORKERS-URL]/[UUID]` 即可获取订阅内容。 36 | - 例如 `https://vless.google.workers.dev/90cd4a77-141a-43c9-991b-08263cfe9c10` 就是你的通用自适应订阅地址(Quantumult X、Clash、singbox、小火箭、v2rayN、v2rayU、surge、PassWall、SSR+、Karing等)。 37 | - 例如 `https://vless.google.workers.dev/90cd4a77-141a-43c9-991b-08263cfe9c10?base64` Base64订阅格式,适用PassWall,SSR+等。 38 | - 例如 `https://vless.google.workers.dev/90cd4a77-141a-43c9-991b-08263cfe9c10?clash` Clash订阅格式,适用OpenClash等。 39 | - 例如 `https://vless.google.workers.dev/90cd4a77-141a-43c9-991b-08263cfe9c10?singbox` singbox订阅格式,适用singbox等。 40 | 41 | 3. 给 Pages绑定 CNAME自定义域: 42 | - 在 Pages控制台的 `自定义域`选项卡,下方点击 `设置自定义域`。 43 | - 填入你的自定义次级域名,注意不要使用你的根域名,例如: 44 | 您分配到的域名是 `google.com`,则添加自定义域填入 `vless.google.com`即可; 45 | - 按照 Cloudflare 的要求将返回你的域名DNS服务商,添加 该自定义域 `vless`的 CNAME记录 `vless.google.pages.dev` 后,点击 `激活域`即可。 46 | 47 | 48 | 49 | ## Pages GitHub 部署方法 50 | 1. 部署 Cloudflare Pages: 51 | - 在 Github 上先 Fork 本项目,并点上 Star !!! 52 | - 在 Cloudflare Pages 控制台中选择 `连接到 Git`后,选中 `am-cf-auto-trojan`项目后点击 `开始设置`。 53 | - 在 `设置构建和部署`页面下方,选择 `环境变量(高级)`后并 `添加变量` 54 | 变量名称填写**UUID**,值则为你的UUID,后点击 `保存并部署`即可。 55 | 56 | 2. 访问订阅内容: 57 | - 访问 `https://[YOUR-WORKERS-URL]/[UUID]` 即可获取订阅内容。 58 | - 例如 `https://vless.google.workers.dev/90cd4a77-141a-43c9-991b-08263cfe9c10` 就是你的通用自适应订阅地址(Quantumult X、Clash、singbox、小火箭、v2rayN、v2rayU、surge、PassWall、SSR+、Karing等)。 59 | - 例如 `https://vless.google.workers.dev/90cd4a77-141a-43c9-991b-08263cfe9c10?base64` Base64订阅格式,适用PassWall,SSR+等。 60 | - 例如 `https://vless.google.workers.dev/90cd4a77-141a-43c9-991b-08263cfe9c10?clash` Clash订阅格式,适用OpenClash等。 61 | - 例如 `https://vless.google.workers.dev/90cd4a77-141a-43c9-991b-08263cfe9c10?singbox` singbox订阅格式,适用singbox等。 62 | 63 | 3. 给 Pages绑定 CNAME自定义域: 64 | - 在 Pages控制台的 `自定义域`选项卡,下方点击 `设置自定义域`。 65 | - 填入你的自定义次级域名,注意不要使用你的根域名,例如: 66 | 您分配到的域名是 `google.com`,则添加自定义域填入 `vless.google.com`即可; 67 | - 按照 Cloudflare 的要求将返回你的域名DNS服务商,添加 该自定义域 `vless`的 CNAME记录 `vless.google.pages.dev` 后,点击 `激活域`即可。 68 | 69 | 70 | 71 | 72 | 73 | ## 变量说明 74 | | 变量名 | 示例 | 必填 | 备注 | YT | 75 | |-----|-----|-----|-----|-----| 76 | | TOKEN | auto |✅| 快速订阅内置节点的订阅路径地址 /auto (支持多元素, 元素之间使用,作间隔) | | 77 | | HOST | page-us-17m.pages.dev |❌| 快速订阅内置节点的伪装域名 | | 78 | | PASSWORD | amclubs |❌| 快速订阅内置节点的密码 | | 79 | | DNS_RESOLVER_URL | https://cloudflare-dns.com/dns-query |❌| DNS解析获取作用,小白勿用 | | 80 | | IP_LOCAL | `icook.hk:2053#官方优选域名` |❌| 本地优选域名/优选IP(支持多元素之间`,`或 换行 作间隔) | | 81 | | IP_URL_TXT | [https://raw.github.../ipv4.txt](https://raw.githubusercontent.com/amclubs/am-cf-auto-trojan/main/ipv4.txt) |❌| 优选ipv4、ipv6、域名、API地址(支持多个之间`,`或 换行 作间隔) |[Video](https://youtu.be/dzxezRV1v-o) | 82 | | IP_URL_CSV | [https://raw.github.../ipv4.csv](https://raw.githubusercontent.com/amclubs/am-cf-auto-trojan/main/ipv4.csv) |❌| 优选ipv4/6的IP测速结果(支持多元素, 元素之间使用`,`作间隔) |[Video](https://youtu.be/vX3U3FuuTT8)| 83 | | NO_TLS | true/false |❌| 默认false,是否开启TLS系列端口,只有workers部署才可以使非用TLS系列端口 | | 84 | | SL | 5 |❌| `CSV`文件里的测速结果满足速度下限 || 85 | | SUB_CONFIG | [https://raw.github.../ACL4SSR_Online_Mini.ini](https://raw.githubusercontent.com/amclubs/ACL4SSR/main/Clash/config/ACL4SSR_Online_Full_MultiMode.ini) |❌| clash、singbox等 订阅转换配置文件 || 86 | | SUB_CONVERTER | https://url.v1.mk |❌| clash、singbox等 订阅转换后端的api地址 || 87 | | SUB_NAME | @AM_CLUB |❌ | 订阅名称 || 88 | | TG_TOKEN | 68941456:XXXXXXX0qExVUDAXXXqWXgBA |❌| 发送TG通知的机器人token || 89 | | TG_ID | 6946912345 |❌ | 接收TG通知的账户数字ID || 90 | 91 | 92 | # 93 |
94 |
[点击展开] 赞赏支持 ~🧧 95 | *我非常感谢您的赞赏和支持,它们将极大地激励我继续创新,持续产生有价值的工作。* 96 | 97 | - **USDT-TRC20:** `TWTxUyay6QJN3K4fs4kvJTT8Zfa2mWTwDD` 98 | - **TRX-TRC20:** `TWTxUyay6QJN3K4fs4kvJTT8Zfa2mWTwDD` 99 | 100 |
101 |
102 | TRC10/TRC20扫码支付 103 |
104 |
105 |
106 | 107 | # 108 | 免责声明: 109 | - 1、该项目设计和开发仅供学习、研究和安全测试目的。请于下载后 24 小时内删除, 不得用作任何商业用途, 文字、数据及图片均有所属版权, 如转载须注明来源。 110 | - 2、使用本程序必循遵守部署服务器所在地区的法律、所在国家和用户所在国家的法律法规。对任何人或团体使用该项目时产生的任何后果由使用者承担。 111 | - 3、作者不对使用该项目可能引起的任何直接或间接损害负责。作者保留随时更新免责声明的权利,且不另行通知。 112 | 113 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /_worker.js: -------------------------------------------------------------------------------- 1 | /** 2 | * YouTube Channel: https://youtube.com/@AM_CLUB 3 | * GitHub Repository: https://github.com/amclubs 4 | * Telegram Group: https://t.me/AM_CLUBS 5 | * Personal Blog: https://am.809098.xyz 6 | */ 7 | 8 | // @ts-ignore 9 | import { connect } from 'cloudflare:sockets'; 10 | 11 | // Generate your own UUID using the following command in PowerShell: 12 | // Powershell -NoExit -Command "[guid]::NewGuid()" 13 | let userID = 'auto'; 14 | 15 | // https://cloudflare-dns.com/dns-query or https://dns.google/dns-query 16 | // DNS-over-HTTPS URL 17 | let dohURL = 'https://sky.rethinkdns.com/1:-Pf_____9_8A_AMAIgE8kMABVDDmKOHTAKg='; 18 | 19 | // Preferred address API interface 20 | let ipUrlTxt = [ 21 | 'https://raw.githubusercontent.com/amclubs/am-cf-tunnel/main/ipv4.txt', 22 | // 'https://raw.githubusercontent.com/amclubs/am-cf-tunnel/main/ipv6.txt' 23 | ]; 24 | let ipUrlCsv = [ 25 | // 'https://raw.githubusercontent.com/amclubs/am-cf-tunnel/main/ipv4.csv' 26 | ]; 27 | // Preferred addresses with optional TLS subscription 28 | let ipLocal = [ 29 | 'icook.hk#t.me/AM_CLUBS 加入频道解锁更多优选节点', 30 | 'visa.cn:443#youtube.com/@AM_CLUB 订阅频道获取更多教程' 31 | // 'cloudflare.cfgo.cc:443#关注YouTube频道@AM_CLUB' 32 | ]; 33 | let noTLS = 'false'; 34 | let sl = 5; 35 | 36 | // let tagName = 'amclubs'; 37 | let subUpdateTime = 6; // Subscription update time in hours 38 | let timestamp = 4102329600000; // Timestamp for the end date (2099-12-31) 39 | let total = 99 * 1125899906842624; // PB (perhaps referring to bandwidth or total entries) 40 | let download = Math.floor(Math.random() * 1099511627776); 41 | let upload = download; 42 | 43 | // Regex pattern to match IP addresses and ports 44 | // let regex = /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[.*\]):?(\d+)?#?(.*)?$/; 45 | 46 | // Network protocol type 47 | let network = 'ws'; // WebSocket 48 | 49 | // Fake UUID and hostname for configuration generation 50 | let fakeUserID; 51 | let fakeHostName; 52 | 53 | // Subscription and conversion details 54 | let subProtocol = 'https'; 55 | let subConverter = 'url.v1.mk'; // Subscription conversion backend using Sheep's function 56 | let subConfig = "https://raw.githubusercontent.com/amclubs/ACL4SSR/main/Clash/config/ACL4SSR_Online_Full_MultiMode.ini"; // Subscription profile 57 | let fileName = 'youtube.com/@am_club'; 58 | let isBase64 = true; 59 | 60 | let botToken = ''; 61 | let chatID = ''; 62 | 63 | 64 | 65 | export default { 66 | /** 67 | * @param {import("@cloudflare/workers-types").Request} request 68 | * @param {{UUID: string, DNS_RESOLVER_URL: string, NODE_ID: int, API_HOST: string, API_TOKEN: string}} env 69 | * @returns {Promise} 70 | */ 71 | async fetch(request, env) { 72 | try { 73 | // Destructure environment variables for clarity 74 | const { 75 | TOKEN, 76 | HOST, 77 | PASSWORD, 78 | DNS_RESOLVER_URL, 79 | IP_LOCAL, 80 | IP_URL_TXT, 81 | IP_URL_CSV, 82 | NO_TLS, 83 | SL, 84 | SUB_CONFIG, 85 | SUB_CONVERTER, 86 | SUB_NAME, 87 | TG_TOKEN, 88 | TG_ID 89 | 90 | } = env; 91 | 92 | userID = (TOKEN || userID).toLowerCase(); 93 | 94 | const url = new URL(request.url); 95 | dohURL = (DNS_RESOLVER_URL || dohURL); 96 | 97 | if (IP_LOCAL) { 98 | ipLocal = await addIpText(IP_LOCAL); 99 | } 100 | if (IP_URL_TXT) { 101 | ipUrlTxt = await addIpText(IP_URL_TXT); 102 | } 103 | if (IP_URL_CSV) { 104 | ipUrlCsv = await addIpText(IP_URL_CSV); 105 | } 106 | 107 | noTLS = (NO_TLS || noTLS); 108 | sl = (SL || sl); 109 | subConfig = (SUB_CONFIG || subConfig); 110 | subConverter = (SUB_CONVERTER || subConverter); 111 | fileName = (SUB_NAME || subConverter); 112 | botToken = (TG_TOKEN || botToken); 113 | chatID = (TG_ID || chatID); 114 | 115 | // Unified protocol for handling subconverters 116 | const [subProtocol, subConverterWithoutProtocol] = (subConverter.startsWith("http://") || subConverter.startsWith("https://")) 117 | ? subConverter.split("://") 118 | : [undefined, subConverter]; 119 | subConverter = subConverterWithoutProtocol; 120 | 121 | //const uuid = url.searchParams.get('uuid')?.toLowerCase() || 'null'; 122 | const ua = request.headers.get('User-Agent') || 'null'; 123 | const userAgent = ua.toLowerCase(); 124 | const host = (url.searchParams.get('host') || HOST || request.headers.get('Host')); 125 | const password = (url.searchParams.get('password') || PASSWORD || userID); 126 | 127 | // Calculate expiry and upload/download limits 128 | const expire = Math.floor(timestamp / 1000); 129 | 130 | fakeUserID = await getFakeUserID(userID); 131 | fakeHostName = fakeUserID.slice(6, 9) + "." + fakeUserID.slice(13, 19); 132 | console.log(`userID: ${userID}`); 133 | console.log(`fakeUserID: ${fakeUserID}`); 134 | // Handle routes based on the path 135 | switch (url.pathname.toLowerCase()) { 136 | case '/': { 137 | // Serve the nginx disguise page 138 | return new Response(await nginx(), { 139 | headers: { 140 | 'Content-Type': 'text/html; charset=UTF-8', 141 | 'referer': 'https://www.google.com/search?q=am.809098.xyz', 142 | }, 143 | }); 144 | } 145 | 146 | case `/${fakeUserID}`: { 147 | // Disguise UUID node generation 148 | const fakeConfig = await getTROJANConfig(userID, host, 'CF-FAKE-UA', url); 149 | return new Response(fakeConfig, { status: 200 }); 150 | } 151 | 152 | case `/${userID}`: { 153 | // Handle real UUID requests and get node info 154 | await sendMessage( 155 | `#获取订阅 ${fileName}`, 156 | request.headers.get('CF-Connecting-IP'), 157 | `UA: ${userAgent}\n域名: ${url.hostname}\n入口: ${url.pathname + url.search}` 158 | ); 159 | 160 | const trojanConfig = await getTROJANConfig(password, host, userAgent, url); 161 | const isMozilla = userAgent.includes('mozilla'); 162 | 163 | // Prepare common headers 164 | const commonHeaders = { 165 | "Content-Type": isMozilla ? "text/html;charset=utf-8" : "text/plain;charset=utf-8", 166 | "Profile-Update-Interval": `${subUpdateTime}`, 167 | "Subscription-Userinfo": `upload=${upload}; download=${download}; total=${total}; expire=${expire}`, 168 | }; 169 | 170 | // Add download headers if not a Mozilla browser 171 | if (!isMozilla) { 172 | commonHeaders["Content-Disposition"] = `attachment; filename=${fileName}; filename*=utf-8''${encodeURIComponent(fileName)}`; 173 | } 174 | 175 | return new Response(trojanConfig, { 176 | status: 200, 177 | headers: commonHeaders, 178 | }); 179 | } 180 | 181 | default: { 182 | // Serve the default nginx disguise page 183 | return new Response(await nginx(), { 184 | headers: { 185 | 'Content-Type': 'text/html; charset=UTF-8', 186 | 'referer': 'https://www.google.com/search?q=am.809098.xyz', 187 | }, 188 | }); 189 | } 190 | } 191 | } catch (err) { 192 | // Log error for debugging purposes 193 | console.error('Error processing request:', err); 194 | return new Response(`Error: ${err.message}`, { status: 500 }); 195 | } 196 | }, 197 | }; 198 | 199 | 200 | /** ---------------------Tools------------------------------ */ 201 | 202 | export async function hashHex_f(string) { 203 | const encoder = new TextEncoder(); 204 | const data = encoder.encode(string); 205 | const hashBuffer = await crypto.subtle.digest('SHA-256', data); 206 | const hashArray = Array.from(new Uint8Array(hashBuffer)); 207 | const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join(''); 208 | return hashHex; 209 | } 210 | 211 | const byteToHex = []; 212 | for (let i = 0; i < 256; ++i) { 213 | byteToHex.push((i + 256).toString(16).slice(1)); 214 | } 215 | 216 | async function getFakeUserID(userID) { 217 | const date = new Date().toISOString().split('T')[0]; 218 | const rawString = `${userID}-${date}`; 219 | 220 | const hashBuffer = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(rawString)); 221 | const hashArray = Array.from(new Uint8Array(hashBuffer)).map(b => ('00' + b.toString(16)).slice(-2)).join(''); 222 | 223 | return `${hashArray.substring(0, 8)}-${hashArray.substring(8, 12)}-${hashArray.substring(12, 16)}-${hashArray.substring(16, 20)}-${hashArray.substring(20, 32)}`; 224 | } 225 | 226 | function revertFakeInfo(content, userID, hostName) { 227 | //console.log(`revertFakeInfo-->: isBase64 ${isBase64} \n content: ${content}`); 228 | if (isBase64) { 229 | content = atob(content);//Base64 decrypt 230 | } 231 | content = content.replace(new RegExp(fakeUserID, 'g'), userID).replace(new RegExp(fakeHostName, 'g'), hostName); 232 | if (isBase64) { 233 | content = btoa(content);//Base64 encryption 234 | } 235 | return content; 236 | } 237 | 238 | async function addIpText(envAdd) { 239 | var addText = envAdd.replace(/[ |"'\r\n]+/g, ',').replace(/,+/g, ','); 240 | //console.log(addText); 241 | if (addText.charAt(0) == ',') { 242 | addText = addText.slice(1); 243 | } 244 | if (addText.charAt(addText.length - 1) == ',') { 245 | addText = addText.slice(0, addText.length - 1); 246 | } 247 | const add = addText.split(','); 248 | // console.log(add); 249 | return add; 250 | } 251 | 252 | 253 | /** ---------------------Get data------------------------------ */ 254 | 255 | let subParams = ['sub', 'base64', 'b64', 'clash', 'singbox', 'sb']; 256 | /** 257 | * @param {string} userID 258 | * @param {string | null} host 259 | * @param {string} userAgent 260 | * @param {string} _url 261 | * @returns {Promise} 262 | */ 263 | async function getTROJANConfig(userID, host, userAgent, _url) { 264 | // console.log(`------------getTROJANConfig------------------`); 265 | // console.log(`userID: ${userID} \n host: ${host} \n userAgent: ${userAgent} \n _url: ${_url}`); 266 | 267 | userAgent = userAgent.toLowerCase(); 268 | 269 | // Get node information 270 | fakeHostName = getFakeHostName(host); 271 | const ipUrlTxtAndCsv = await getIpUrlTxtAndCsv(noTLS); 272 | 273 | // console.log(`txt: ${ipUrlTxtAndCsv.txt} \n csv: ${ipUrlTxtAndCsv.csv}`); 274 | let content = await getSubscribeNode(userAgent, _url, host, fakeHostName, fakeUserID, noTLS, ipUrlTxtAndCsv.txt, ipUrlTxtAndCsv.csv); 275 | 276 | return _url.pathname === `/${fakeUserID}` ? content : revertFakeInfo(content, userID, host); 277 | 278 | } 279 | 280 | 281 | function getFakeHostName(host) { 282 | if (host.includes(".pages.dev")) { 283 | return `${fakeHostName}.pages.dev`; 284 | } else if (host.includes(".workers.dev") || host.includes("notls") || noTLS === 'true') { 285 | return `${fakeHostName}.workers.dev`; 286 | } 287 | return `${fakeHostName}.xyz`; 288 | } 289 | 290 | async function getIpUrlTxtAndCsv(noTLS) { 291 | if (noTLS === 'true') { 292 | return { 293 | txt: await getIpUrlTxt(ipUrlTxt), 294 | csv: await getIpUrlCsv('FALSE') 295 | }; 296 | } 297 | return { 298 | txt: await getIpUrlTxt(ipUrlTxt), 299 | csv: await getIpUrlCsv('TRUE') 300 | }; 301 | } 302 | 303 | async function getIpUrlTxt(ipUrlTxts) { 304 | if (!ipUrlTxts || ipUrlTxts.length === 0) { 305 | return []; 306 | } 307 | 308 | let ipTxt = ""; 309 | 310 | // Create an AbortController object to control the cancellation of fetch requests 311 | const controller = new AbortController(); 312 | 313 | // Set a timeout to trigger the cancellation of all requests after 2 seconds 314 | const timeout = setTimeout(() => { 315 | controller.abort(); // Cancel all requests 316 | }, 2000); 317 | 318 | try { 319 | // Use Promise.allSettled to wait for all API requests to complete, regardless of success or failure 320 | // Iterate over the api array and send a fetch request to each API URL 321 | const responses = await Promise.allSettled(ipUrlTxts.map(apiUrl => fetch(apiUrl, { 322 | method: 'GET', 323 | headers: { 324 | 'Accept': 'text/html,application/xhtml+xml,application/xml;', 325 | 'User-Agent': 'amclubs/am-cf-tunnel' 326 | }, 327 | signal: controller.signal // Attach the AbortController's signal to the fetch request to allow cancellation when needed 328 | }).then(response => response.ok ? response.text() : Promise.reject()))); 329 | 330 | // Iterate through all the responses 331 | for (const response of responses) { 332 | // Check if the request was fulfilled successfully 333 | if (response.status === 'fulfilled') { 334 | // Get the response content 335 | const content = await response.value; 336 | ipTxt += content + '\n'; 337 | } 338 | } 339 | } catch (error) { 340 | console.error(error); 341 | } finally { 342 | // Clear the timeout regardless of success or failure 343 | clearTimeout(timeout); 344 | } 345 | 346 | // Process the result using addIpText function 347 | const newIpTxt = await addIpText(ipTxt); 348 | // console.log(`ipUrlTxts: ${ipUrlTxts} \n ipTxt: ${ipTxt} \n newIpTxt: ${newIpTxt} `); 349 | 350 | // Return the processed result 351 | return newIpTxt; 352 | } 353 | 354 | async function getIpUrlCsv(tls) { 355 | // Check if the CSV URLs are valid 356 | if (!ipUrlCsv || ipUrlCsv.length === 0) { 357 | return []; 358 | } 359 | 360 | const newAddressesCsv = []; 361 | 362 | // Fetch and process all CSVs concurrently 363 | const fetchCsvPromises = ipUrlCsv.map(async (csvUrl) => { 364 | try { 365 | const response = await fetch(csvUrl); 366 | 367 | // Ensure the response is successful 368 | if (!response.ok) { 369 | console.error('Error fetching CSV:', response.status, response.statusText); 370 | return; 371 | } 372 | 373 | // Parse the CSV content and split it into lines 374 | const text = await response.text(); 375 | const lines = text.includes('\r\n') ? text.split('\r\n') : text.split('\n'); 376 | 377 | // Ensure we have a non-empty CSV 378 | if (lines.length < 2) { 379 | console.error('CSV file is empty or has no data rows'); 380 | return; 381 | } 382 | 383 | // Extract the header and get required field indexes 384 | const header = lines[0].trim().split(','); 385 | const tlsIndex = header.indexOf('TLS'); 386 | const ipAddressIndex = 0; // Assuming the first column is IP address 387 | const portIndex = 1; // Assuming the second column is port 388 | const dataCenterIndex = tlsIndex + 1; // Data center assumed to be right after TLS 389 | const speedIndex = header.length - 1; // Last column for speed 390 | 391 | // If the required fields are missing, skip this CSV 392 | if (tlsIndex === -1) { 393 | console.error('CSV file missing required TLS field'); 394 | return; 395 | } 396 | 397 | // Process the data rows 398 | for (let i = 1; i < lines.length; i++) { 399 | const columns = lines[i].trim().split(','); 400 | 401 | // Skip empty or malformed rows 402 | if (columns.length < header.length) { 403 | continue; 404 | } 405 | 406 | // Check if TLS matches and speed is greater than sl 407 | const tlsValue = columns[tlsIndex].toUpperCase(); 408 | const speedValue = parseFloat(columns[speedIndex]); 409 | 410 | if (tlsValue === tls && speedValue > sl) { 411 | const ipAddress = columns[ipAddressIndex]; 412 | const port = columns[portIndex]; 413 | const dataCenter = columns[dataCenterIndex]; 414 | newAddressesCsv.push(`${ipAddress}:${port}#${dataCenter}`); 415 | } 416 | } 417 | } catch (error) { 418 | console.error('Error processing CSV URL:', csvUrl, error); 419 | } 420 | }); 421 | 422 | // Wait for all CSVs to be processed 423 | await Promise.all(fetchCsvPromises); 424 | 425 | return newAddressesCsv; 426 | } 427 | 428 | const protocolTypeBase64 = 'dHJvamFu'; 429 | /** 430 | * Get node configuration information 431 | * @param {*} uuid 432 | * @param {*} host 433 | * @param {*} address 434 | * @param {*} port 435 | * @param {*} remarks 436 | * @returns 437 | */ 438 | function getConfigLink(uuid, host, address, port, remarks) { 439 | const protocolType = atob(protocolTypeBase64); 440 | 441 | const encryption = 'none'; 442 | let path = '/?ed=2560'; 443 | const fingerprint = 'randomized'; 444 | let tls = ['tls', true]; 445 | if (host.includes('.workers.dev') || host.includes('pages.dev')) { 446 | path = `/${host}${path}`; 447 | remarks += ' 请通过绑定自定义域名订阅!'; 448 | } 449 | 450 | const v2ray = getV2rayLink({ protocolType, host, uuid, address, port, remarks, encryption, path, fingerprint, tls }); 451 | const clash = getClashLink(protocolType, host, address, port, uuid, path, tls, fingerprint); 452 | 453 | return [v2ray, clash]; 454 | } 455 | 456 | /** 457 | * Get vless information 458 | * @param {*} param0 459 | * @returns 460 | */ 461 | function getV2rayLink({ protocolType, host, uuid, address, port, remarks, encryption, path, fingerprint, tls }) { 462 | let sniAndFp = `&sni=${host}&fp=${fingerprint}`; 463 | if (portSet_http.has(parseInt(port))) { 464 | tls = ['', false]; 465 | sniAndFp = ''; 466 | } 467 | 468 | const v2rayLink = `${protocolType}://${uuid}@${address}:${port}?encryption=${encryption}&security=${tls[0]}&type=${network}&host=${host}&path=${encodeURIComponent(path)}${sniAndFp}#${encodeURIComponent(remarks)}`; 469 | return v2rayLink; 470 | } 471 | 472 | /** 473 | * getClashLink 474 | * @param {*} protocolType 475 | * @param {*} host 476 | * @param {*} address 477 | * @param {*} port 478 | * @param {*} uuid 479 | * @param {*} path 480 | * @param {*} tls 481 | * @param {*} fingerprint 482 | * @returns 483 | */ 484 | function getClashLink(protocolType, host, address, port, uuid, path, tls, fingerprint) { 485 | return `- {type: ${protocolType}, name: ${host}, server: ${address}, port: ${port}, password: ${uuid}, network: ${network}, tls: ${tls[1]}, udp: false, sni: ${host}, client-fingerprint: ${fingerprint}, skip-cert-verify: true, ws-opts: {path: ${path}, headers: {Host: ${host}}}}`; 486 | 487 | // return ` 488 | // - type: ${protocolType} 489 | // name: ${host} 490 | // server: ${address} 491 | // port: ${port} 492 | // uuid: ${uuid} 493 | // network: ${network} 494 | // tls: ${tls[1]} 495 | // udp: false 496 | // sni: ${host} 497 | // client-fingerprint: ${fingerprint} 498 | // ws-opts: 499 | // path: "${path}" 500 | // headers: 501 | // host: ${host} 502 | // `; 503 | } 504 | 505 | 506 | let portSet_http = new Set([80, 8080, 8880, 2052, 2086, 2095, 2082]); 507 | let portSet_https = new Set([443, 8443, 2053, 2096, 2087, 2083]); 508 | /** 509 | * 510 | * @param {*} host 511 | * @param {*} uuid 512 | * @param {*} noTLS 513 | * @param {*} ipUrlTxt 514 | * @param {*} ipUrlCsv 515 | * @returns 516 | */ 517 | async function getSubscribeNode(userAgent, _url, host, fakeHostName, fakeUserID, noTLS, ipUrlTxt, ipUrlCsv) { 518 | // Use Set object to remove duplicates 519 | const uniqueIpTxt = [...new Set([...ipLocal, ...ipUrlTxt, ...ipUrlCsv])]; 520 | let responseBody = splitNodeData(uniqueIpTxt, noTLS, fakeHostName, fakeUserID, userAgent); 521 | // console.log(`getSubscribeNode---> responseBody: ${responseBody} `); 522 | 523 | if (!userAgent.includes(('CF-FAKE-UA').toLowerCase())) { 524 | 525 | let url = `https://${host}/${fakeUserID}`; 526 | 527 | if (isClashCondition(userAgent, _url)) { 528 | isBase64 = false; 529 | url = createSubConverterUrl('clash', url, subConfig, subConverter, subProtocol); 530 | } else if (isSingboxCondition(userAgent, _url)) { 531 | isBase64 = false; 532 | url = createSubConverterUrl('singbox', url, subConfig, subConverter, subProtocol); 533 | } else { 534 | return responseBody; 535 | } 536 | const response = await fetch(url, { 537 | headers: { 538 | 'User-Agent': `${userAgent} am-cf-tunnel/amclubs` 539 | } 540 | }); 541 | responseBody = await response.text(); 542 | //console.log(`getSubscribeNode---> url: ${url} `); 543 | } 544 | 545 | return responseBody; 546 | } 547 | 548 | function createSubConverterUrl(target, url, subConfig, subConverter, subProtocol) { 549 | return `${subProtocol}://${subConverter}/sub?target=${target}&url=${encodeURIComponent(url)}&insert=false&config=${encodeURIComponent(subConfig)}&emoji=true&list=false&tfo=false&scv=true&fdn=false&sort=false&new_name=true`; 550 | } 551 | 552 | function isClashCondition(userAgent, _url) { 553 | return (userAgent.includes('clash') && !userAgent.includes('nekobox')) || (_url.searchParams.has('clash') && !userAgent.includes('subConverter')); 554 | } 555 | 556 | function isSingboxCondition(userAgent, _url) { 557 | return userAgent.includes('sing-box') || userAgent.includes('singbox') || ((_url.searchParams.has('singbox') || _url.searchParams.has('sb')) && !userAgent.includes('subConverter')); 558 | } 559 | 560 | /** 561 | * 562 | * @param {*} uniqueIpTxt 563 | * @param {*} noTLS 564 | * @param {*} host 565 | * @param {*} uuid 566 | * @returns 567 | */ 568 | function splitNodeData(uniqueIpTxt, noTLS, host, uuid, userAgent) { 569 | // Regex to match IPv4 and IPv6 570 | const regex = /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[.*\]):?(\d+)?#?(.*)?$/; 571 | 572 | // Region codes mapped to corresponding emojis 573 | const regionMap = { 574 | 'SG': '🇸🇬 SG', 575 | 'HK': '🇭🇰 HK', 576 | 'KR': '🇰🇷 KR', 577 | 'JP': '🇯🇵 JP', 578 | 'GB': '🇬🇧 GB', 579 | 'US': '🇺🇸 US', 580 | 'TW': '🇼🇸 TW', 581 | 'CF': '📶 CF' 582 | }; 583 | 584 | const responseBody = uniqueIpTxt.map(ipTxt => { 585 | let address = ipTxt; 586 | let port = "443"; 587 | let remarks = ""; 588 | 589 | const match = address.match(regex); 590 | if (match) { 591 | address = match[1]; 592 | port = match[2] || port; 593 | remarks = match[3] || address; 594 | } else { 595 | let ip, newPort, extra; 596 | 597 | if (ipTxt.includes(':') && ipTxt.includes('#')) { 598 | [ip, newPort, extra] = ipTxt.split(/[:#]/); 599 | } else if (ipTxt.includes(':')) { 600 | [ip, newPort] = ipTxt.split(':'); 601 | } else if (ipTxt.includes('#')) { 602 | [ip, extra] = ipTxt.split('#'); 603 | } else { 604 | ip = ipTxt; 605 | } 606 | 607 | address = ip; 608 | port = newPort || port; 609 | remarks = extra || address; 610 | 611 | // console.log(`splitNodeData---> ip: ${ip} \n extra: ${extra} \n port: ${port}`); 612 | } 613 | 614 | // Replace region code with corresponding emoji 615 | remarks = regionMap[remarks] || remarks; 616 | 617 | // Check if TLS is disabled and if the port is in the allowed set 618 | if (noTLS !== 'true' && portSet_http.has(parseInt(port))) { 619 | return null; // Skip this iteration 620 | } 621 | 622 | const [v2ray, clash] = getConfigLink(uuid, host, address, port, remarks); 623 | return v2ray; 624 | }).filter(Boolean).join('\n'); 625 | 626 | let base64Response = responseBody; 627 | return btoa(base64Response); 628 | } 629 | 630 | 631 | /** ---------------------Get CF data------------------------------ */ 632 | 633 | const API_URL = 'http://ip-api.com/json/'; 634 | const TELEGRAM_API_URL = 'https://api.telegram.org/bot'; 635 | /** 636 | * Send message to Telegram channel 637 | * @param {string} type 638 | * @param {string} ip I 639 | * @param {string} [add_data=""] 640 | */ 641 | async function sendMessage(type, ip, add_data = "") { 642 | if (botToken && chatID) { 643 | try { 644 | const ipResponse = await fetch(`${API_URL}${ip}?lang=zh-CN`); 645 | let msg = `${type}\nIP: ${ip}\n${add_data}`; 646 | 647 | if (ipResponse.ok) { 648 | const ipInfo = await ipResponse.json(); 649 | msg = `${type}\nIP: ${ip}\n国家: ${ipInfo.country}\n城市: ${ipInfo.city}\n组织: ${ipInfo.org}\nASN: ${ipInfo.as}\n${add_data}`; 650 | } else { 651 | console.error(`Failed to fetch IP info. Status: ${ipResponse.status}`); 652 | } 653 | 654 | const telegramUrl = `${TELEGRAM_API_URL}${botToken}/sendMessage`; 655 | const params = new URLSearchParams({ 656 | chat_id: chatID, 657 | parse_mode: 'HTML', 658 | text: msg 659 | }); 660 | 661 | await fetch(`${telegramUrl}?${params.toString()}`, { 662 | method: 'GET', 663 | headers: { 664 | 'Accept': 'text/html,application/xhtml+xml,application/xml', 665 | 'Accept-Encoding': 'gzip, deflate, br', 666 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36' 667 | } 668 | }); 669 | 670 | } catch (error) { 671 | console.error('Error sending message:', error); 672 | } 673 | } else { 674 | console.warn('botToken or chatID is missing.'); 675 | } 676 | } 677 | 678 | 679 | /** -------------------Home page-------------------------------- */ 680 | async function nginx() { 681 | const text = ` 682 | 683 | 684 | 685 | Welcome to nginx! 686 | 693 | 694 | 695 |

Welcome to nginx!

696 |

If you see this page, the nginx web server is successfully installed and 697 | working. Further configuration is required.

698 | 699 |

For online documentation and support please refer to 700 | nginx.org.
701 | Commercial support is available at 702 | nginx.com.

703 | 704 |

Thank you for using nginx.

705 | 706 | 707 | ` 708 | return text; 709 | } --------------------------------------------------------------------------------