From d354c5e988d2f44d6a1b2e3efc00b82d2f9ff21f Mon Sep 17 00:00:00 2001 From: SukkaW Date: Fri, 7 Feb 2025 17:52:36 +0800 Subject: [PATCH] Chore: maintainance --- Build/build-apple-cdn.ts | 2 +- Build/build-cdn-download-conf.ts | 2 +- Build/build-chn-cidr.ts | 2 +- Build/build-cloudmounter-rules.ts | 2 +- Build/build-common.ts | 3 +- ...c-direct-lan-ruleset-dns-mapping-module.ts | 2 +- Build/build-microsoft-cdn.ts | 2 +- Build/build-reject-domainset.ts | 2 +- Build/build-reject-ip-list.ts | 3 +- Build/build-speedtest-domainset.ts | 2 +- Build/build-stream-service.ts | 2 +- Build/build-telegram-cidr.ts | 2 +- Build/lib/create-file.ts | 113 +- Build/lib/rules/base.ts | 108 -- Dist/Build/_get-lum-apex-domains.cjs | 2 + Dist/Build/_get-lum-apex-domains2.cjs | 28 + Dist/Build/build-apple-cdn.cjs | 2 + Dist/Build/build-apple-cdn2.cjs | 44 + Dist/Build/build-cdn-download-conf.cjs | 2 + Dist/Build/build-cdn-download-conf2.cjs | 86 ++ Dist/Build/build-chn-cidr.cjs | 2 + Dist/Build/build-chn-cidr2.cjs | 77 ++ Dist/Build/build-cloudmounter-rules.cjs | 2 + Dist/Build/build-cloudmounter-rules2.cjs | 36 + Dist/Build/build-common.cjs | 2 + Dist/Build/build-common2.cjs | 161 +++ Dist/Build/build-deprecate-files.cjs | 2 + Dist/Build/build-deprecate-files2.cjs | 67 + ...-direct-lan-ruleset-dns-mapping-module.cjs | 2 + ...direct-lan-ruleset-dns-mapping-module2.cjs | 305 +++++ .../Build/build-internal-reverse-chn-cidr.cjs | 2 + .../build-internal-reverse-chn-cidr2.cjs | 77 ++ Dist/Build/build-microsoft-cdn.cjs | 2 + Dist/Build/build-microsoft-cdn2.cjs | 84 ++ Dist/Build/build-public.cjs | 2 + Dist/Build/build-public2.cjs | 158 +++ Dist/Build/build-reject-domainset.cjs | 2 + Dist/Build/build-reject-domainset2.cjs | 141 ++ Dist/Build/build-reject-ip-list.cjs | 2 + Dist/Build/build-reject-ip-list2.cjs | 96 ++ Dist/Build/build-sgmodule-always-realip.cjs | 2 + Dist/Build/build-sgmodule-always-realip2.cjs | 136 ++ Dist/Build/build-sgmodule-redirect.cjs | 2 + Dist/Build/build-sgmodule-redirect2.cjs | 508 ++++++++ Dist/Build/build-speedtest-domainset.cjs | 2 + Dist/Build/build-speedtest-domainset2.cjs | 113 ++ Dist/Build/build-sspanel-appprofile.cjs | 2 + Dist/Build/build-sspanel-appprofile2.cjs | 217 ++++ Dist/Build/build-stream-service.cjs | 2 + Dist/Build/build-stream-service2.cjs | 48 + Dist/Build/build-telegram-cidr.cjs | 2 + Dist/Build/build-telegram-cidr2.cjs | 69 + Dist/Build/constants/cidr.cjs | 92 ++ Dist/Build/constants/description.cjs | 34 + Dist/Build/constants/dir.cjs | 71 + Dist/Build/constants/domains.cjs | 148 +++ Dist/Build/constants/loose-tldts-opt.cjs | 47 + Dist/Build/constants/reject-data-source.cjs | 584 +++++++++ Dist/Build/download-mock-assets.cjs | 2 + Dist/Build/download-mock-assets2.cjs | 58 + Dist/Build/download-previous-build.cjs | 2 + Dist/Build/download-previous-build2.cjs | 99 ++ Dist/Build/index.cjs | 2 + Dist/Build/index2.cjs | 107 ++ Dist/Build/lib/append-array-in-place.cjs | 46 + Dist/Build/lib/cache-filesystem.cjs | 134 ++ Dist/Build/lib/create-file.cjs | 114 ++ Dist/Build/lib/fetch-assets.cjs | 81 ++ Dist/Build/lib/fetch-retry.cjs | 235 ++++ Dist/Build/lib/fetch-text-by-line.cjs | 79 ++ Dist/Build/lib/fs-memo.cjs | 89 ++ Dist/Build/lib/get-phishing-domains.cjs | 376 ++++++ Dist/Build/lib/is-domain-alive.cjs | 396 ++++++ Dist/Build/lib/memo-promise.cjs | 35 + Dist/Build/lib/misc.cjs | 122 ++ Dist/Build/lib/normalize-domain.cjs | 79 ++ Dist/Build/lib/parse-dnsmasq.cjs | 44 + Dist/Build/lib/parse-filter/domainlists.cjs | 71 + Dist/Build/lib/parse-filter/filters.cjs | 372 ++++++ Dist/Build/lib/parse-filter/hosts.cjs | 66 + Dist/Build/lib/parse-filter/shared.cjs | 52 + Dist/Build/lib/process-line.cjs | 79 ++ Dist/Build/lib/rules/base.cjs | 469 +++++++ Dist/Build/lib/rules/domainset.cjs | 47 + Dist/Build/lib/rules/ip.cjs | 34 + Dist/Build/lib/rules/ruleset.cjs | 59 + Dist/Build/lib/text-line-transform-stream.cjs | 65 + Dist/Build/lib/tree-dir.cjs | 75 ++ Dist/Build/lib/trie.cjs | 540 ++++++++ .../lib/writing-strategy/adguardhome.cjs | 113 ++ Dist/Build/lib/writing-strategy/base.cjs | 63 + Dist/Build/lib/writing-strategy/clash.cjs | 172 +++ Dist/Build/lib/writing-strategy/singbox.cjs | 121 ++ Dist/Build/lib/writing-strategy/surge.cjs | 246 ++++ Dist/Build/trace/index.cjs | 182 +++ Dist/Build/trim-source.cjs | 2 + Dist/Build/trim-source2.cjs | 47 + Dist/Build/validate-domain-alive.cjs | 2 + Dist/Build/validate-domain-alive2.cjs | 94 ++ Dist/Build/validate-domestic.cjs | 2 + Dist/Build/validate-domestic2.cjs | 81 ++ Dist/Build/validate-gfwlist.cjs | 2 + Dist/Build/validate-gfwlist2.cjs | 153 +++ Dist/Build/validate-global-tld.cjs | 2 + Dist/Build/validate-global-tld2.cjs | 53 + Dist/Build/validate-hash-collision-test.cjs | 2 + Dist/Build/validate-hash-collision-test2.cjs | 54 + Dist/Build/validate-reject-stats.cjs | 2 + Dist/Build/validate-reject-stats2.cjs | 42 + Dist/Source/ip/badboy_asn.cjs | 50 + Dist/Source/non_ip/cloudmounter.cjs | 39 + Dist/Source/non_ip/direct.cjs | 147 +++ Dist/Source/non_ip/domestic.cjs | 437 +++++++ Dist/Source/stream.cjs | 858 ++++++++++++ Dist/_get-lum-apex-domains.cjs | 29 + Dist/_virtual/_commonjsHelpers.cjs | 3 + Dist/_virtual/_get-lum-apex-domains.cjs | 1 + Dist/_virtual/adguardhome.cjs | 1 + Dist/_virtual/append-array-in-place.cjs | 1 + Dist/_virtual/badboy_asn.cjs | 1 + Dist/_virtual/base.cjs | 1 + Dist/_virtual/base2.cjs | 1 + Dist/_virtual/build-apple-cdn.cjs | 1 + Dist/_virtual/build-cdn-download-conf.cjs | 1 + Dist/_virtual/build-chn-cidr.cjs | 1 + Dist/_virtual/build-cloudmounter-rules.cjs | 1 + Dist/_virtual/build-common.cjs | 1 + Dist/_virtual/build-deprecate-files.cjs | 1 + ...-direct-lan-ruleset-dns-mapping-module.cjs | 1 + .../build-internal-reverse-chn-cidr.cjs | 1 + Dist/_virtual/build-microsoft-cdn.cjs | 1 + Dist/_virtual/build-public.cjs | 1 + Dist/_virtual/build-reject-domainset.cjs | 1 + Dist/_virtual/build-reject-ip-list.cjs | 1 + .../_virtual/build-sgmodule-always-realip.cjs | 1 + Dist/_virtual/build-sgmodule-redirect.cjs | 1 + Dist/_virtual/build-speedtest-domainset.cjs | 1 + Dist/_virtual/build-sspanel-appprofile.cjs | 1 + Dist/_virtual/build-stream-service.cjs | 1 + Dist/_virtual/build-telegram-cidr.cjs | 1 + Dist/_virtual/cache-filesystem.cjs | 1 + Dist/_virtual/cidr.cjs | 1 + Dist/_virtual/clash.cjs | 1 + Dist/_virtual/cloudmounter.cjs | 1 + Dist/_virtual/create-file.cjs | 1 + Dist/_virtual/description.cjs | 1 + Dist/_virtual/dir.cjs | 1 + Dist/_virtual/direct.cjs | 1 + Dist/_virtual/domainlists.cjs | 1 + Dist/_virtual/domains.cjs | 1 + Dist/_virtual/domainset.cjs | 1 + Dist/_virtual/domestic.cjs | 1 + Dist/_virtual/download-mock-assets.cjs | 1 + Dist/_virtual/download-previous-build.cjs | 1 + Dist/_virtual/fetch-assets.cjs | 1 + Dist/_virtual/fetch-retry.cjs | 1 + Dist/_virtual/fetch-text-by-line.cjs | 1 + Dist/_virtual/filters.cjs | 1 + Dist/_virtual/fs-memo.cjs | 1 + Dist/_virtual/get-phishing-domains.cjs | 1 + Dist/_virtual/hosts.cjs | 1 + Dist/_virtual/index.cjs | 1 + Dist/_virtual/index2.cjs | 1 + Dist/_virtual/ip.cjs | 1 + Dist/_virtual/is-domain-alive.cjs | 1 + Dist/_virtual/loose-tldts-opt.cjs | 1 + Dist/_virtual/memo-promise.cjs | 1 + Dist/_virtual/misc.cjs | 1 + Dist/_virtual/normalize-domain.cjs | 1 + Dist/_virtual/parse-dnsmasq.cjs | 1 + Dist/_virtual/process-line.cjs | 1 + Dist/_virtual/reject-data-source.cjs | 1 + Dist/_virtual/ruleset.cjs | 1 + Dist/_virtual/shared.cjs | 1 + Dist/_virtual/singbox.cjs | 1 + Dist/_virtual/stream.cjs | 1 + Dist/_virtual/surge.cjs | 1 + Dist/_virtual/text-line-transform-stream.cjs | 1 + Dist/_virtual/tree-dir.cjs | 1 + Dist/_virtual/trie.cjs | 1 + Dist/_virtual/trim-source.cjs | 1 + Dist/_virtual/validate-domain-alive.cjs | 1 + Dist/_virtual/validate-domestic.cjs | 1 + Dist/_virtual/validate-gfwlist.cjs | 1 + Dist/_virtual/validate-global-tld.cjs | 1 + .../_virtual/validate-hash-collision-test.cjs | 1 + Dist/_virtual/validate-reject-stats.cjs | 1 + Dist/build-apple-cdn.cjs | 2 + Dist/build-cdn-download-conf.cjs | 2 + Dist/build-chn-cidr.cjs | 2 + Dist/build-cloudmounter-rules.cjs | 2 + Dist/build-common.cjs | 2 + Dist/build-deprecate-files.cjs | 2 + ...-direct-lan-ruleset-dns-mapping-module.cjs | 2 + Dist/build-internal-reverse-chn-cidr.cjs | 2 + Dist/build-microsoft-cdn.cjs | 2 + Dist/build-public.cjs | 2 + Dist/build-reject-domainset.cjs | 2 + Dist/build-reject-ip-list.cjs | 2 + Dist/build-sgmodule-always-realip.cjs | 2 + Dist/build-sgmodule-redirect.cjs | 2 + Dist/build-speedtest-domainset.cjs | 2 + Dist/build-sspanel-appprofile.cjs | 2 + Dist/build-stream-service.cjs | 2 + Dist/build-telegram-cidr.cjs | 2 + Dist/chunks/base.C13YY5P3.cjs | 1145 +++++++++++++++++ Dist/chunks/build-apple-cdn.CNsnkTO_.cjs | 45 + .../build-cdn-download-conf.Dj0KZ2lm.cjs | 86 ++ Dist/chunks/build-chn-cidr.BjyqKcvm.cjs | 201 +++ .../build-cloudmounter-rules.RMp-w3JV.cjs | 74 ++ Dist/chunks/build-common.DBhs-fKR.cjs | 161 +++ .../chunks/build-deprecate-files.BeL0QUfk.cjs | 67 + ...an-ruleset-dns-mapping-module.T1tgVza_.cjs | 887 +++++++++++++ ...ild-internal-reverse-chn-cidr.C6CBihfs.cjs | 77 ++ Dist/chunks/build-microsoft-cdn.CCw86frc.cjs | 84 ++ Dist/chunks/build-public.8-AWnl05.cjs | 232 ++++ .../build-reject-domainset.BCoJGSBE.cjs | 1073 +++++++++++++++ Dist/chunks/build-reject-ip-list.D6Cjv0d8.cjs | 145 +++ .../build-sgmodule-always-realip.CuBgClIT.cjs | 136 ++ .../build-sgmodule-redirect.iquVSpqW.cjs | 508 ++++++++ .../build-speedtest-domainset.D2jYMvWN.cjs | 113 ++ .../build-sspanel-appprofile.DbsFXAyN.cjs | 217 ++++ Dist/chunks/build-stream-service.BKBKJK6i.cjs | 48 + Dist/chunks/build-telegram-cidr.05NmRbUx.cjs | 69 + Dist/chunks/create-file.loOMbJEN.cjs | 114 ++ Dist/chunks/domainset.CSQfKAtf.cjs | 159 +++ Dist/chunks/download-mock-assets.Dk5F6scb.cjs | 58 + .../download-previous-build.-XKJmEYz.cjs | 99 ++ Dist/chunks/fetch-assets.aqw2YOi8.cjs | 81 ++ Dist/chunks/fetch-retry.D06uBUaW.cjs | 307 +++++ Dist/chunks/fetch-text-by-line.YY5b5610.cjs | 221 ++++ Dist/chunks/fs-memo.Dw823m02.cjs | 222 ++++ Dist/chunks/index.B8Uk9n3v.cjs | 182 +++ Dist/chunks/loose-tldts-opt.DLUpGXpj.cjs | 47 + Dist/chunks/memo-promise.BbOsVeGo.cjs | 35 + Dist/chunks/misc.BpcQjda1.cjs | 122 ++ Dist/chunks/normalize-domain.Cfz4j8eP.cjs | 79 ++ Dist/chunks/parse-dnsmasq.CiH7YJVY.cjs | 44 + Dist/chunks/reject-data-source.DaKwvNlG.cjs | 584 +++++++++ Dist/chunks/ruleset.iYH0XOC1.cjs | 59 + Dist/chunks/stream.C9eZuk9f.cjs | 858 ++++++++++++ Dist/chunks/trie.Vu1FNyv-.cjs | 540 ++++++++ Dist/download-mock-assets.cjs | 2 + Dist/download-previous-build.cjs | 2 + Dist/index.cjs | 108 ++ Dist/trim-source.cjs | 48 + Dist/validate-domain-alive.cjs | 490 +++++++ Dist/validate-domestic.cjs | 82 ++ Dist/validate-gfwlist.cjs | 154 +++ Dist/validate-global-tld.cjs | 201 +++ Dist/validate-hash-collision-test.cjs | 55 + Dist/validate-reject-stats.cjs | 43 + 252 files changed, 21086 insertions(+), 124 deletions(-) create mode 100644 Dist/Build/_get-lum-apex-domains.cjs create mode 100644 Dist/Build/_get-lum-apex-domains2.cjs create mode 100644 Dist/Build/build-apple-cdn.cjs create mode 100644 Dist/Build/build-apple-cdn2.cjs create mode 100644 Dist/Build/build-cdn-download-conf.cjs create mode 100644 Dist/Build/build-cdn-download-conf2.cjs create mode 100644 Dist/Build/build-chn-cidr.cjs create mode 100644 Dist/Build/build-chn-cidr2.cjs create mode 100644 Dist/Build/build-cloudmounter-rules.cjs create mode 100644 Dist/Build/build-cloudmounter-rules2.cjs create mode 100644 Dist/Build/build-common.cjs create mode 100644 Dist/Build/build-common2.cjs create mode 100644 Dist/Build/build-deprecate-files.cjs create mode 100644 Dist/Build/build-deprecate-files2.cjs create mode 100644 Dist/Build/build-domestic-direct-lan-ruleset-dns-mapping-module.cjs create mode 100644 Dist/Build/build-domestic-direct-lan-ruleset-dns-mapping-module2.cjs create mode 100644 Dist/Build/build-internal-reverse-chn-cidr.cjs create mode 100644 Dist/Build/build-internal-reverse-chn-cidr2.cjs create mode 100644 Dist/Build/build-microsoft-cdn.cjs create mode 100644 Dist/Build/build-microsoft-cdn2.cjs create mode 100644 Dist/Build/build-public.cjs create mode 100644 Dist/Build/build-public2.cjs create mode 100644 Dist/Build/build-reject-domainset.cjs create mode 100644 Dist/Build/build-reject-domainset2.cjs create mode 100644 Dist/Build/build-reject-ip-list.cjs create mode 100644 Dist/Build/build-reject-ip-list2.cjs create mode 100644 Dist/Build/build-sgmodule-always-realip.cjs create mode 100644 Dist/Build/build-sgmodule-always-realip2.cjs create mode 100644 Dist/Build/build-sgmodule-redirect.cjs create mode 100644 Dist/Build/build-sgmodule-redirect2.cjs create mode 100644 Dist/Build/build-speedtest-domainset.cjs create mode 100644 Dist/Build/build-speedtest-domainset2.cjs create mode 100644 Dist/Build/build-sspanel-appprofile.cjs create mode 100644 Dist/Build/build-sspanel-appprofile2.cjs create mode 100644 Dist/Build/build-stream-service.cjs create mode 100644 Dist/Build/build-stream-service2.cjs create mode 100644 Dist/Build/build-telegram-cidr.cjs create mode 100644 Dist/Build/build-telegram-cidr2.cjs create mode 100644 Dist/Build/constants/cidr.cjs create mode 100644 Dist/Build/constants/description.cjs create mode 100644 Dist/Build/constants/dir.cjs create mode 100644 Dist/Build/constants/domains.cjs create mode 100644 Dist/Build/constants/loose-tldts-opt.cjs create mode 100644 Dist/Build/constants/reject-data-source.cjs create mode 100644 Dist/Build/download-mock-assets.cjs create mode 100644 Dist/Build/download-mock-assets2.cjs create mode 100644 Dist/Build/download-previous-build.cjs create mode 100644 Dist/Build/download-previous-build2.cjs create mode 100644 Dist/Build/index.cjs create mode 100644 Dist/Build/index2.cjs create mode 100644 Dist/Build/lib/append-array-in-place.cjs create mode 100644 Dist/Build/lib/cache-filesystem.cjs create mode 100644 Dist/Build/lib/create-file.cjs create mode 100644 Dist/Build/lib/fetch-assets.cjs create mode 100644 Dist/Build/lib/fetch-retry.cjs create mode 100644 Dist/Build/lib/fetch-text-by-line.cjs create mode 100644 Dist/Build/lib/fs-memo.cjs create mode 100644 Dist/Build/lib/get-phishing-domains.cjs create mode 100644 Dist/Build/lib/is-domain-alive.cjs create mode 100644 Dist/Build/lib/memo-promise.cjs create mode 100644 Dist/Build/lib/misc.cjs create mode 100644 Dist/Build/lib/normalize-domain.cjs create mode 100644 Dist/Build/lib/parse-dnsmasq.cjs create mode 100644 Dist/Build/lib/parse-filter/domainlists.cjs create mode 100644 Dist/Build/lib/parse-filter/filters.cjs create mode 100644 Dist/Build/lib/parse-filter/hosts.cjs create mode 100644 Dist/Build/lib/parse-filter/shared.cjs create mode 100644 Dist/Build/lib/process-line.cjs create mode 100644 Dist/Build/lib/rules/base.cjs create mode 100644 Dist/Build/lib/rules/domainset.cjs create mode 100644 Dist/Build/lib/rules/ip.cjs create mode 100644 Dist/Build/lib/rules/ruleset.cjs create mode 100644 Dist/Build/lib/text-line-transform-stream.cjs create mode 100644 Dist/Build/lib/tree-dir.cjs create mode 100644 Dist/Build/lib/trie.cjs create mode 100644 Dist/Build/lib/writing-strategy/adguardhome.cjs create mode 100644 Dist/Build/lib/writing-strategy/base.cjs create mode 100644 Dist/Build/lib/writing-strategy/clash.cjs create mode 100644 Dist/Build/lib/writing-strategy/singbox.cjs create mode 100644 Dist/Build/lib/writing-strategy/surge.cjs create mode 100644 Dist/Build/trace/index.cjs create mode 100644 Dist/Build/trim-source.cjs create mode 100644 Dist/Build/trim-source2.cjs create mode 100644 Dist/Build/validate-domain-alive.cjs create mode 100644 Dist/Build/validate-domain-alive2.cjs create mode 100644 Dist/Build/validate-domestic.cjs create mode 100644 Dist/Build/validate-domestic2.cjs create mode 100644 Dist/Build/validate-gfwlist.cjs create mode 100644 Dist/Build/validate-gfwlist2.cjs create mode 100644 Dist/Build/validate-global-tld.cjs create mode 100644 Dist/Build/validate-global-tld2.cjs create mode 100644 Dist/Build/validate-hash-collision-test.cjs create mode 100644 Dist/Build/validate-hash-collision-test2.cjs create mode 100644 Dist/Build/validate-reject-stats.cjs create mode 100644 Dist/Build/validate-reject-stats2.cjs create mode 100644 Dist/Source/ip/badboy_asn.cjs create mode 100644 Dist/Source/non_ip/cloudmounter.cjs create mode 100644 Dist/Source/non_ip/direct.cjs create mode 100644 Dist/Source/non_ip/domestic.cjs create mode 100644 Dist/Source/stream.cjs create mode 100644 Dist/_get-lum-apex-domains.cjs create mode 100644 Dist/_virtual/_commonjsHelpers.cjs create mode 100644 Dist/_virtual/_get-lum-apex-domains.cjs create mode 100644 Dist/_virtual/adguardhome.cjs create mode 100644 Dist/_virtual/append-array-in-place.cjs create mode 100644 Dist/_virtual/badboy_asn.cjs create mode 100644 Dist/_virtual/base.cjs create mode 100644 Dist/_virtual/base2.cjs create mode 100644 Dist/_virtual/build-apple-cdn.cjs create mode 100644 Dist/_virtual/build-cdn-download-conf.cjs create mode 100644 Dist/_virtual/build-chn-cidr.cjs create mode 100644 Dist/_virtual/build-cloudmounter-rules.cjs create mode 100644 Dist/_virtual/build-common.cjs create mode 100644 Dist/_virtual/build-deprecate-files.cjs create mode 100644 Dist/_virtual/build-domestic-direct-lan-ruleset-dns-mapping-module.cjs create mode 100644 Dist/_virtual/build-internal-reverse-chn-cidr.cjs create mode 100644 Dist/_virtual/build-microsoft-cdn.cjs create mode 100644 Dist/_virtual/build-public.cjs create mode 100644 Dist/_virtual/build-reject-domainset.cjs create mode 100644 Dist/_virtual/build-reject-ip-list.cjs create mode 100644 Dist/_virtual/build-sgmodule-always-realip.cjs create mode 100644 Dist/_virtual/build-sgmodule-redirect.cjs create mode 100644 Dist/_virtual/build-speedtest-domainset.cjs create mode 100644 Dist/_virtual/build-sspanel-appprofile.cjs create mode 100644 Dist/_virtual/build-stream-service.cjs create mode 100644 Dist/_virtual/build-telegram-cidr.cjs create mode 100644 Dist/_virtual/cache-filesystem.cjs create mode 100644 Dist/_virtual/cidr.cjs create mode 100644 Dist/_virtual/clash.cjs create mode 100644 Dist/_virtual/cloudmounter.cjs create mode 100644 Dist/_virtual/create-file.cjs create mode 100644 Dist/_virtual/description.cjs create mode 100644 Dist/_virtual/dir.cjs create mode 100644 Dist/_virtual/direct.cjs create mode 100644 Dist/_virtual/domainlists.cjs create mode 100644 Dist/_virtual/domains.cjs create mode 100644 Dist/_virtual/domainset.cjs create mode 100644 Dist/_virtual/domestic.cjs create mode 100644 Dist/_virtual/download-mock-assets.cjs create mode 100644 Dist/_virtual/download-previous-build.cjs create mode 100644 Dist/_virtual/fetch-assets.cjs create mode 100644 Dist/_virtual/fetch-retry.cjs create mode 100644 Dist/_virtual/fetch-text-by-line.cjs create mode 100644 Dist/_virtual/filters.cjs create mode 100644 Dist/_virtual/fs-memo.cjs create mode 100644 Dist/_virtual/get-phishing-domains.cjs create mode 100644 Dist/_virtual/hosts.cjs create mode 100644 Dist/_virtual/index.cjs create mode 100644 Dist/_virtual/index2.cjs create mode 100644 Dist/_virtual/ip.cjs create mode 100644 Dist/_virtual/is-domain-alive.cjs create mode 100644 Dist/_virtual/loose-tldts-opt.cjs create mode 100644 Dist/_virtual/memo-promise.cjs create mode 100644 Dist/_virtual/misc.cjs create mode 100644 Dist/_virtual/normalize-domain.cjs create mode 100644 Dist/_virtual/parse-dnsmasq.cjs create mode 100644 Dist/_virtual/process-line.cjs create mode 100644 Dist/_virtual/reject-data-source.cjs create mode 100644 Dist/_virtual/ruleset.cjs create mode 100644 Dist/_virtual/shared.cjs create mode 100644 Dist/_virtual/singbox.cjs create mode 100644 Dist/_virtual/stream.cjs create mode 100644 Dist/_virtual/surge.cjs create mode 100644 Dist/_virtual/text-line-transform-stream.cjs create mode 100644 Dist/_virtual/tree-dir.cjs create mode 100644 Dist/_virtual/trie.cjs create mode 100644 Dist/_virtual/trim-source.cjs create mode 100644 Dist/_virtual/validate-domain-alive.cjs create mode 100644 Dist/_virtual/validate-domestic.cjs create mode 100644 Dist/_virtual/validate-gfwlist.cjs create mode 100644 Dist/_virtual/validate-global-tld.cjs create mode 100644 Dist/_virtual/validate-hash-collision-test.cjs create mode 100644 Dist/_virtual/validate-reject-stats.cjs create mode 100644 Dist/build-apple-cdn.cjs create mode 100644 Dist/build-cdn-download-conf.cjs create mode 100644 Dist/build-chn-cidr.cjs create mode 100644 Dist/build-cloudmounter-rules.cjs create mode 100644 Dist/build-common.cjs create mode 100644 Dist/build-deprecate-files.cjs create mode 100644 Dist/build-domestic-direct-lan-ruleset-dns-mapping-module.cjs create mode 100644 Dist/build-internal-reverse-chn-cidr.cjs create mode 100644 Dist/build-microsoft-cdn.cjs create mode 100644 Dist/build-public.cjs create mode 100644 Dist/build-reject-domainset.cjs create mode 100644 Dist/build-reject-ip-list.cjs create mode 100644 Dist/build-sgmodule-always-realip.cjs create mode 100644 Dist/build-sgmodule-redirect.cjs create mode 100644 Dist/build-speedtest-domainset.cjs create mode 100644 Dist/build-sspanel-appprofile.cjs create mode 100644 Dist/build-stream-service.cjs create mode 100644 Dist/build-telegram-cidr.cjs create mode 100644 Dist/chunks/base.C13YY5P3.cjs create mode 100644 Dist/chunks/build-apple-cdn.CNsnkTO_.cjs create mode 100644 Dist/chunks/build-cdn-download-conf.Dj0KZ2lm.cjs create mode 100644 Dist/chunks/build-chn-cidr.BjyqKcvm.cjs create mode 100644 Dist/chunks/build-cloudmounter-rules.RMp-w3JV.cjs create mode 100644 Dist/chunks/build-common.DBhs-fKR.cjs create mode 100644 Dist/chunks/build-deprecate-files.BeL0QUfk.cjs create mode 100644 Dist/chunks/build-domestic-direct-lan-ruleset-dns-mapping-module.T1tgVza_.cjs create mode 100644 Dist/chunks/build-internal-reverse-chn-cidr.C6CBihfs.cjs create mode 100644 Dist/chunks/build-microsoft-cdn.CCw86frc.cjs create mode 100644 Dist/chunks/build-public.8-AWnl05.cjs create mode 100644 Dist/chunks/build-reject-domainset.BCoJGSBE.cjs create mode 100644 Dist/chunks/build-reject-ip-list.D6Cjv0d8.cjs create mode 100644 Dist/chunks/build-sgmodule-always-realip.CuBgClIT.cjs create mode 100644 Dist/chunks/build-sgmodule-redirect.iquVSpqW.cjs create mode 100644 Dist/chunks/build-speedtest-domainset.D2jYMvWN.cjs create mode 100644 Dist/chunks/build-sspanel-appprofile.DbsFXAyN.cjs create mode 100644 Dist/chunks/build-stream-service.BKBKJK6i.cjs create mode 100644 Dist/chunks/build-telegram-cidr.05NmRbUx.cjs create mode 100644 Dist/chunks/create-file.loOMbJEN.cjs create mode 100644 Dist/chunks/domainset.CSQfKAtf.cjs create mode 100644 Dist/chunks/download-mock-assets.Dk5F6scb.cjs create mode 100644 Dist/chunks/download-previous-build.-XKJmEYz.cjs create mode 100644 Dist/chunks/fetch-assets.aqw2YOi8.cjs create mode 100644 Dist/chunks/fetch-retry.D06uBUaW.cjs create mode 100644 Dist/chunks/fetch-text-by-line.YY5b5610.cjs create mode 100644 Dist/chunks/fs-memo.Dw823m02.cjs create mode 100644 Dist/chunks/index.B8Uk9n3v.cjs create mode 100644 Dist/chunks/loose-tldts-opt.DLUpGXpj.cjs create mode 100644 Dist/chunks/memo-promise.BbOsVeGo.cjs create mode 100644 Dist/chunks/misc.BpcQjda1.cjs create mode 100644 Dist/chunks/normalize-domain.Cfz4j8eP.cjs create mode 100644 Dist/chunks/parse-dnsmasq.CiH7YJVY.cjs create mode 100644 Dist/chunks/reject-data-source.DaKwvNlG.cjs create mode 100644 Dist/chunks/ruleset.iYH0XOC1.cjs create mode 100644 Dist/chunks/stream.C9eZuk9f.cjs create mode 100644 Dist/chunks/trie.Vu1FNyv-.cjs create mode 100644 Dist/download-mock-assets.cjs create mode 100644 Dist/download-previous-build.cjs create mode 100644 Dist/index.cjs create mode 100644 Dist/trim-source.cjs create mode 100644 Dist/validate-domain-alive.cjs create mode 100644 Dist/validate-domestic.cjs create mode 100644 Dist/validate-gfwlist.cjs create mode 100644 Dist/validate-global-tld.cjs create mode 100644 Dist/validate-hash-collision-test.cjs create mode 100644 Dist/validate-reject-stats.cjs diff --git a/Build/build-apple-cdn.ts b/Build/build-apple-cdn.ts index e9d30a96..c9710e1c 100644 --- a/Build/build-apple-cdn.ts +++ b/Build/build-apple-cdn.ts @@ -2,7 +2,7 @@ import { parseFelixDnsmasqFromResp } from './lib/parse-dnsmasq'; import { task } from './trace'; import { SHARED_DESCRIPTION } from './constants/description'; import { createMemoizedPromise } from './lib/memo-promise'; -import { DomainsetOutput } from './lib/create-file'; +import { DomainsetOutput } from './lib/rules/domainset'; import { $$fetch } from './lib/fetch-retry'; export const getAppleCdnDomainsPromise = createMemoizedPromise(() => $$fetch('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf').then(parseFelixDnsmasqFromResp)); diff --git a/Build/build-cdn-download-conf.ts b/Build/build-cdn-download-conf.ts index 7f407f4e..21d945f5 100644 --- a/Build/build-cdn-download-conf.ts +++ b/Build/build-cdn-download-conf.ts @@ -5,7 +5,7 @@ import { task } from './trace'; import { SHARED_DESCRIPTION } from './constants/description'; import { appendArrayInPlace } from './lib/append-array-in-place'; import { SOURCE_DIR } from './constants/dir'; -import { DomainsetOutput } from './lib/create-file'; +import { DomainsetOutput } from './lib/rules/domainset'; import { CRASHLYTICS_WHITELIST } from './constants/reject-data-source'; import { appendSetElementsToArray } from 'foxts/append-set-elements-to-array'; diff --git a/Build/build-chn-cidr.ts b/Build/build-chn-cidr.ts index e75465b2..b0b3d5b8 100644 --- a/Build/build-chn-cidr.ts +++ b/Build/build-chn-cidr.ts @@ -5,7 +5,7 @@ import { contains as containsCidr, exclude as excludeCidr } from 'fast-cidr-tool import { createMemoizedPromise } from './lib/memo-promise'; import { CN_CIDR_MISSING_IN_CHNROUTE, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } from './constants/cidr'; import { appendArrayInPlace } from './lib/append-array-in-place'; -import { IPListOutput } from './lib/create-file'; +import { IPListOutput } from './lib/rules/ip'; import { cachedOnlyFail } from './lib/fs-memo'; import { createFileDescription } from './constants/description'; diff --git a/Build/build-cloudmounter-rules.ts b/Build/build-cloudmounter-rules.ts index a60b718f..5650473c 100644 --- a/Build/build-cloudmounter-rules.ts +++ b/Build/build-cloudmounter-rules.ts @@ -1,7 +1,7 @@ import { DOMAINS, PROCESS_NAMES } from '../Source/non_ip/cloudmounter'; import { SHARED_DESCRIPTION } from './constants/description'; import { task } from './trace'; -import { RulesetOutput } from './lib/create-file'; +import { RulesetOutput } from './lib/rules/ruleset'; export const buildCloudMounterRules = task(require.main === module, __filename)(async (span) => { // AND,((SRC-IP,192.168.1.110), (DOMAIN, example.com)) diff --git a/Build/build-common.ts b/Build/build-common.ts index 96abfdf4..37475fe7 100644 --- a/Build/build-common.ts +++ b/Build/build-common.ts @@ -9,7 +9,8 @@ import { SHARED_DESCRIPTION } from './constants/description'; import { fdir as Fdir } from 'fdir'; import { appendArrayInPlace } from './lib/append-array-in-place'; import { SOURCE_DIR } from './constants/dir'; -import { DomainsetOutput, RulesetOutput } from './lib/create-file'; +import { DomainsetOutput } from './lib/rules/domainset'; +import { RulesetOutput } from './lib/rules/ruleset'; const MAGIC_COMMAND_SKIP = '# $ custom_build_script'; const MAGIC_COMMAND_TITLE = '# $ meta_title '; diff --git a/Build/build-domestic-direct-lan-ruleset-dns-mapping-module.ts b/Build/build-domestic-direct-lan-ruleset-dns-mapping-module.ts index 8119e43f..7f3f88ee 100644 --- a/Build/build-domestic-direct-lan-ruleset-dns-mapping-module.ts +++ b/Build/build-domestic-direct-lan-ruleset-dns-mapping-module.ts @@ -11,7 +11,7 @@ import { createMemoizedPromise } from './lib/memo-promise'; import * as yaml from 'yaml'; import { appendArrayInPlace } from './lib/append-array-in-place'; import { OUTPUT_INTERNAL_DIR, OUTPUT_MODULES_DIR, OUTPUT_MODULES_RULES_DIR, SOURCE_DIR } from './constants/dir'; -import { RulesetOutput } from './lib/create-file'; +import { RulesetOutput } from './lib/rules/ruleset'; import { SurgeOnlyRulesetOutput } from './lib/rules/ruleset'; export function createGetDnsMappingRule(allowWildcard: boolean) { diff --git a/Build/build-microsoft-cdn.ts b/Build/build-microsoft-cdn.ts index 64e1b6f5..2139a1ce 100644 --- a/Build/build-microsoft-cdn.ts +++ b/Build/build-microsoft-cdn.ts @@ -4,7 +4,7 @@ import { HostnameSmolTrie } from './lib/trie'; import { SHARED_DESCRIPTION } from './constants/description'; import { createMemoizedPromise } from './lib/memo-promise'; import { extractDomainsFromFelixDnsmasq } from './lib/parse-dnsmasq'; -import { RulesetOutput } from './lib/create-file'; +import { RulesetOutput } from './lib/rules/ruleset'; import { appendArrayInPlace } from './lib/append-array-in-place'; const PROBE_DOMAINS = ['.microsoft.com', '.windows.net', '.windows.com', '.windowsupdate.com', '.windowssearch.com', '.office.net']; diff --git a/Build/build-reject-domainset.ts b/Build/build-reject-domainset.ts index c2b13636..9f5d98e3 100644 --- a/Build/build-reject-domainset.ts +++ b/Build/build-reject-domainset.ts @@ -17,7 +17,7 @@ import { getPhishingDomains } from './lib/get-phishing-domains'; import { addArrayElementsToSet } from 'foxts/add-array-elements-to-set'; import { OUTPUT_INTERNAL_DIR, SOURCE_DIR } from './constants/dir'; -import { DomainsetOutput } from './lib/create-file'; +import { DomainsetOutput } from './lib/rules/domainset'; import { foundDebugDomain } from './lib/parse-filter/shared'; import { AdGuardHomeOutput } from './lib/rules/domainset'; diff --git a/Build/build-reject-ip-list.ts b/Build/build-reject-ip-list.ts index a09a8222..e72e7593 100644 --- a/Build/build-reject-ip-list.ts +++ b/Build/build-reject-ip-list.ts @@ -3,12 +3,13 @@ import path from 'node:path'; import { createReadlineInterfaceFromResponse, readFileIntoProcessedArray } from './lib/fetch-text-by-line'; import { task } from './trace'; import { SHARED_DESCRIPTION } from './constants/description'; -import { compareAndWriteFile, RulesetOutput } from './lib/create-file'; +import { compareAndWriteFile } from './lib/create-file'; import { OUTPUT_INTERNAL_DIR, SOURCE_DIR } from './constants/dir'; import { $$fetch } from './lib/fetch-retry'; import { fetchAssets } from './lib/fetch-assets'; import { fastIpVersion } from './lib/misc'; import { AUGUST_ASN, HUIZE_ASN } from '../Source/ip/badboy_asn'; +import { RulesetOutput } from './lib/rules/ruleset'; const BOGUS_NXDOMAIN_URL = 'https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/bogus-nxdomain.china.conf'; const getBogusNxDomainIPsPromise: Promise<[ipv4: string[], ipv6: string[]]> = $$fetch(BOGUS_NXDOMAIN_URL).then(async (resp) => { diff --git a/Build/build-speedtest-domainset.ts b/Build/build-speedtest-domainset.ts index 1dd0b532..a1a3d6c4 100644 --- a/Build/build-speedtest-domainset.ts +++ b/Build/build-speedtest-domainset.ts @@ -5,7 +5,7 @@ import { task } from './trace'; import { SHARED_DESCRIPTION } from './constants/description'; import { readFileIntoProcessedArray } from './lib/fetch-text-by-line'; -import { DomainsetOutput } from './lib/create-file'; +import { DomainsetOutput } from './lib/rules/domainset'; import { OUTPUT_SURGE_DIR, SOURCE_DIR } from './constants/dir'; import { newQueue } from '@henrygd/queue'; import { $$fetch } from './lib/fetch-retry'; diff --git a/Build/build-stream-service.ts b/Build/build-stream-service.ts index a008ca1d..f8b7fab2 100644 --- a/Build/build-stream-service.ts +++ b/Build/build-stream-service.ts @@ -4,7 +4,7 @@ import { task } from './trace'; import { ALL, NORTH_AMERICA, EU, HK, TW, JP, KR } from '../Source/stream'; import { SHARED_DESCRIPTION } from './constants/description'; -import { RulesetOutput } from './lib/create-file'; +import { RulesetOutput } from './lib/rules/ruleset'; function createRulesetForStreamService( span: Span, diff --git a/Build/build-telegram-cidr.ts b/Build/build-telegram-cidr.ts index 7dbb561d..875d5573 100644 --- a/Build/build-telegram-cidr.ts +++ b/Build/build-telegram-cidr.ts @@ -3,7 +3,7 @@ import { createReadlineInterfaceFromResponse } from './lib/fetch-text-by-line'; import { task } from './trace'; import { SHARED_DESCRIPTION } from './constants/description'; import { createMemoizedPromise } from './lib/memo-promise'; -import { RulesetOutput } from './lib/create-file'; +import { RulesetOutput } from './lib/rules/ruleset'; import { $$fetch } from './lib/fetch-retry'; import { fastIpVersion } from './lib/misc'; diff --git a/Build/lib/create-file.ts b/Build/lib/create-file.ts index a42c92c9..8fda87b3 100644 --- a/Build/lib/create-file.ts +++ b/Build/lib/create-file.ts @@ -1,4 +1,109 @@ -export { DomainsetOutput } from './rules/domainset'; -export { IPListOutput } from './rules/ip'; -export { RulesetOutput } from './rules/ruleset'; -export { fileEqual, compareAndWriteFile } from './rules/base'; +import { asyncWriteToStream } from 'foxts/async-write-to-stream'; +import { fastStringArrayJoin } from 'foxts/fast-string-array-join'; +import fs from 'node:fs'; +import picocolors from 'picocolors'; +import type { Span } from '../trace'; +import { readFileByLine } from './fetch-text-by-line'; +import { writeFile } from './misc'; + +export async function fileEqual(linesA: string[], source: AsyncIterable | Iterable): Promise { + if (linesA.length === 0) { + return false; + } + + const linesABound = linesA.length - 1; + + let index = -1; + for await (const lineB of source) { + index++; + + if (index > linesABound) { + return (index === linesA.length && lineB.length === 0); + } + + const lineA = linesA[index]; + + if (lineA.length === 0) { + if (lineB.length === 0) { + // both lines are empty, check next line + continue; + } + // lineA is empty but lineB is not + return false; + } + // now lineA can not be empty + if (lineB.length === 0) { + // lineB is empty but lineA is not + return false; + } + + // now both lines can not be empty + + const firstCharA = lineA.charCodeAt(0); + const firstCharB = lineB.charCodeAt(0); + + if (firstCharA !== firstCharB) { + return false; + } + + // now firstCharA is equal to firstCharB, we only need to check the first char + if (firstCharA === 35 /* # */) { + continue; + } + // adguard conf + if (firstCharA === 33 /* ! */) { + continue; + } + + if ( + firstCharA === 47 /* / */ + && lineA[1] === '/' && lineB[1] === '/' + && lineA[3] === '#' && lineB[3] === '#' + ) { + continue; + } + + if (lineA !== lineB) { + return false; + } + } + + // The file becomes larger + return !(index < linesABound); +} + +export async function compareAndWriteFile(span: Span, linesA: string[], filePath: string) { + const linesALen = linesA.length; + + const isEqual = await span.traceChildAsync(`compare ${filePath}`, async () => { + if (fs.existsSync(filePath)) { + return fileEqual(linesA, readFileByLine(filePath)); + } + + console.log(`${filePath} does not exists, writing...`); + return false; + }); + + if (isEqual) { + console.log(picocolors.gray(picocolors.dim(`same content, bail out writing: ${filePath}`))); + return; + } + + await span.traceChildAsync(`writing ${filePath}`, async () => { + // The default highwater mark is normally 16384, + // So we make sure direct write to file if the content is + // most likely less than 500 lines + if (linesALen < 500) { + return writeFile(filePath, fastStringArrayJoin(linesA, '\n') + '\n'); + } + + const writeStream = fs.createWriteStream(filePath); + for (let i = 0; i < linesALen; i++) { + const p = asyncWriteToStream(writeStream, linesA[i] + '\n'); + // eslint-disable-next-line no-await-in-loop -- stream high water mark + if (p) await p; + } + + writeStream.end(); + }); +} diff --git a/Build/lib/rules/base.ts b/Build/lib/rules/base.ts index 2ba1426a..44b48e53 100644 --- a/Build/lib/rules/base.ts +++ b/Build/lib/rules/base.ts @@ -1,13 +1,7 @@ import type { Span } from '../../trace'; import { HostnameSmolTrie } from '../trie'; import { invariant, not } from 'foxts/guard'; -import picocolors from 'picocolors'; -import fs from 'node:fs'; -import { writeFile } from '../misc'; import type { MaybePromise } from '../misc'; -import { fastStringArrayJoin } from 'foxts/fast-string-array-join'; -import { readFileByLine } from '../fetch-text-by-line'; -import { asyncWriteToStream } from 'foxts/async-write-to-stream'; import type { BaseWriteStrategy } from '../writing-strategy/base'; import { merge as mergeCidr } from 'fast-cidr-tools'; import { createRetrieKeywordFilter as createKeywordFilter } from 'foxts/retrie'; @@ -496,105 +490,3 @@ export class FileOutput { return this; } } - -export async function fileEqual(linesA: string[], source: AsyncIterable | Iterable): Promise { - if (linesA.length === 0) { - return false; - } - - const linesABound = linesA.length - 1; - - let index = -1; - for await (const lineB of source) { - index++; - - if (index > linesABound) { - return (index === linesA.length && lineB.length === 0); - } - - const lineA = linesA[index]; - - if (lineA.length === 0) { - if (lineB.length === 0) { - // both lines are empty, check next line - continue; - } - // lineA is empty but lineB is not - return false; - } - // now lineA can not be empty - if (lineB.length === 0) { - // lineB is empty but lineA is not - return false; - } - - // now both lines can not be empty - - const firstCharA = lineA.charCodeAt(0); - const firstCharB = lineB.charCodeAt(0); - - if (firstCharA !== firstCharB) { - return false; - } - - // now firstCharA is equal to firstCharB, we only need to check the first char - if (firstCharA === 35 /* # */) { - continue; - } - // adguard conf - if (firstCharA === 33 /* ! */) { - continue; - } - - if ( - firstCharA === 47 /* / */ - && lineA[1] === '/' && lineB[1] === '/' - && lineA[3] === '#' && lineB[3] === '#' - ) { - continue; - } - - if (lineA !== lineB) { - return false; - } - } - - // The file becomes larger - return !(index < linesABound); -} - -export async function compareAndWriteFile(span: Span, linesA: string[], filePath: string) { - const linesALen = linesA.length; - - const isEqual = await span.traceChildAsync(`compare ${filePath}`, async () => { - if (fs.existsSync(filePath)) { - return fileEqual(linesA, readFileByLine(filePath)); - } - - console.log(`${filePath} does not exists, writing...`); - return false; - }); - - if (isEqual) { - console.log(picocolors.gray(picocolors.dim(`same content, bail out writing: ${filePath}`))); - return; - } - - await span.traceChildAsync(`writing ${filePath}`, async () => { - // The default highwater mark is normally 16384, - // So we make sure direct write to file if the content is - // most likely less than 500 lines - if (linesALen < 500) { - return writeFile(filePath, fastStringArrayJoin(linesA, '\n') + '\n'); - } - - const writeStream = fs.createWriteStream(filePath); - for (let i = 0; i < linesALen; i++) { - const p = asyncWriteToStream(writeStream, linesA[i] + '\n'); - // eslint-disable-next-line no-await-in-loop -- stream high water mark - if (p) await p; - } - - writeStream.end(); - }); -} diff --git a/Dist/Build/_get-lum-apex-domains.cjs b/Dist/Build/_get-lum-apex-domains.cjs new file mode 100644 index 00000000..479fdb73 --- /dev/null +++ b/Dist/Build/_get-lum-apex-domains.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),_getLumApexDomains$1=require('./_get-lum-apex-domains2.cjs');var _getLumApexDomainsExports = _getLumApexDomains$1.__require(); +const _getLumApexDomains = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(_getLumApexDomainsExports);module.exports=_getLumApexDomains; \ No newline at end of file diff --git a/Dist/Build/_get-lum-apex-domains2.cjs b/Dist/Build/_get-lum-apex-domains2.cjs new file mode 100644 index 00000000..c32fbf58 --- /dev/null +++ b/Dist/Build/_get-lum-apex-domains2.cjs @@ -0,0 +1,28 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const _getLumApexDomains=require('../_virtual/_get-lum-apex-domains.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),require$$0=require('tldts');var hasRequired_getLumApexDomains; + +function require_getLumApexDomains () { + if (hasRequired_getLumApexDomains) return _getLumApexDomains.__exports; + hasRequired_getLumApexDomains = 1; + Object.defineProperty(_getLumApexDomains.__exports, "__esModule", { + value: true + }); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _tldts = /*#__PURE__*/ _interop_require_default(require$$0); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + (async ()=>{ + const lines = await Array.fromAsync(await (0, _fetchtextbyline.fetchRemoteTextByLine)('https://raw.githubusercontent.com/durablenapkin/block/master/luminati.txt', true)); + const set = new Set(); + lines.forEach((line)=>{ + const apexDomain = _tldts.default.getDomain(line.slice(8)); + if (apexDomain) { + set.add(apexDomain); + } + }); + console.log(Array.from(set).map((line)=>'.' + line).join('\n')); + })(); + return _getLumApexDomains.__exports; +}exports.__require=require_getLumApexDomains; \ No newline at end of file diff --git a/Dist/Build/build-apple-cdn.cjs b/Dist/Build/build-apple-cdn.cjs new file mode 100644 index 00000000..65e6a509 --- /dev/null +++ b/Dist/Build/build-apple-cdn.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildAppleCdn$1=require('./build-apple-cdn2.cjs');var buildAppleCdnExports = buildAppleCdn$1.__require(); +const buildAppleCdn = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildAppleCdnExports);module.exports=buildAppleCdn; \ No newline at end of file diff --git a/Dist/Build/build-apple-cdn2.cjs b/Dist/Build/build-apple-cdn2.cjs new file mode 100644 index 00000000..eb9b0e9a --- /dev/null +++ b/Dist/Build/build-apple-cdn2.cjs @@ -0,0 +1,44 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildAppleCdn=require('../_virtual/build-apple-cdn.cjs'),parseDnsmasq=require('./lib/parse-dnsmasq.cjs'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),memoPromise=require('./lib/memo-promise.cjs'),domainset=require('./lib/rules/domainset.cjs'),fetchRetry=require('./lib/fetch-retry.cjs');var hasRequiredBuildAppleCdn; + +function requireBuildAppleCdn () { + if (hasRequiredBuildAppleCdn) return buildAppleCdn.__module.exports; + hasRequiredBuildAppleCdn = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + buildAppleCdn: function() { + return buildAppleCdn; + }, + getAppleCdnDomainsPromise: function() { + return getAppleCdnDomainsPromise; + } + }); + const _parsednsmasq = /*@__PURE__*/ parseDnsmasq.__require(); + const _trace = /*@__PURE__*/ index.__require(); + const _description = /*@__PURE__*/ description.__require(); + const _memopromise = /*@__PURE__*/ memoPromise.__require(); + const _domainset = /*@__PURE__*/ domainset.__require(); + const _fetchretry = /*@__PURE__*/ fetchRetry.__require(); + const getAppleCdnDomainsPromise = (0, _memopromise.createMemoizedPromise)(()=>(0, _fetchretry.$$fetch)('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf').then(_parsednsmasq.parseFelixDnsmasqFromResp)); + const buildAppleCdn = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const res = await span.traceChildPromise('get apple cdn domains', getAppleCdnDomainsPromise()); + return new _domainset.DomainsetOutput(span, 'apple_cdn').withTitle('Sukka\'s Ruleset - Apple CDN').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains Apple\'s domains using their China mainland CDN servers.', + '', + 'Data from:', + ' - https://github.com/felixonmars/dnsmasq-china-list' + ]).bulkAddDomainSuffix(res).write(); + }); + } (buildAppleCdn.__module, buildAppleCdn.__module.exports)); + return buildAppleCdn.__module.exports; +}exports.__require=requireBuildAppleCdn; \ No newline at end of file diff --git a/Dist/Build/build-cdn-download-conf.cjs b/Dist/Build/build-cdn-download-conf.cjs new file mode 100644 index 00000000..ff380e43 --- /dev/null +++ b/Dist/Build/build-cdn-download-conf.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildCdnDownloadConf$1=require('./build-cdn-download-conf2.cjs');var buildCdnDownloadConfExports = buildCdnDownloadConf$1.__require(); +const buildCdnDownloadConf = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildCdnDownloadConfExports);module.exports=buildCdnDownloadConf; \ No newline at end of file diff --git a/Dist/Build/build-cdn-download-conf2.cjs b/Dist/Build/build-cdn-download-conf2.cjs new file mode 100644 index 00000000..542f6d3f --- /dev/null +++ b/Dist/Build/build-cdn-download-conf2.cjs @@ -0,0 +1,86 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildCdnDownloadConf=require('../_virtual/build-cdn-download-conf.cjs'),require$$0$1=require('node:path'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),trie=require('./lib/trie.cjs'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),appendArrayInPlace=require('./lib/append-array-in-place.cjs'),dir=require('./constants/dir.cjs'),domainset=require('./lib/rules/domainset.cjs'),rejectDataSource=require('./constants/reject-data-source.cjs'),require$$0=require('foxts/append-set-elements-to-array');var hasRequiredBuildCdnDownloadConf; + +function requireBuildCdnDownloadConf () { + if (hasRequiredBuildCdnDownloadConf) return buildCdnDownloadConf.__module.exports; + hasRequiredBuildCdnDownloadConf = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildCdnDownloadConf", { + enumerable: true, + get: function() { + return buildCdnDownloadConf; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _trie = /*@__PURE__*/ trie.__require(); + const _trace = /*@__PURE__*/ index.__require(); + const _description = /*@__PURE__*/ description.__require(); + const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require(); + const _dir = /*@__PURE__*/ dir.__require(); + const _domainset = /*@__PURE__*/ domainset.__require(); + const _rejectdatasource = /*@__PURE__*/ rejectDataSource.__require(); + const _appendsetelementstoarray = require$$0; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const getS3OSSDomainsPromise = (async ()=>{ + const trie = new _trie.HostnameTrie(); + for await (const line of (await (0, _fetchtextbyline.fetchRemoteTextByLine)('https://publicsuffix.org/list/public_suffix_list.dat', true))){ + trie.add(line); + } + /** + * Extract OSS domain from publicsuffix list + */ const S3OSSDomains = new Set(); + trie.find('.amazonaws.com').forEach((line)=>{ + if ((line.startsWith('s3-') || line.startsWith('s3.')) && !line.includes('cn-')) { + S3OSSDomains.add('.' + line); + } + }); + trie.find('.scw.cloud').forEach((line)=>{ + if ((line.startsWith('s3-') || line.startsWith('s3.')) && !line.includes('cn-')) { + S3OSSDomains.add('.' + line); + } + }); + trie.find('sakurastorage.jp').forEach((line)=>{ + if (line.startsWith('s3-') || line.startsWith('s3.')) { + S3OSSDomains.add('.' + line); + } + }); + return S3OSSDomains; + })(); + const cdnDomainsListPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/cdn.conf')); + const downloadDomainSetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/download.conf')); + const steamDomainSetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/game-download.conf')); + const buildCdnDownloadConf = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const [S3OSSDomains, cdnDomainsList, downloadDomainSet, steamDomainSet] = await Promise.all([ + getS3OSSDomainsPromise, + cdnDomainsListPromise, + downloadDomainSetPromise, + steamDomainSetPromise + ]); + // Move S3 domains to download domain set, since S3 files may be large + (0, _appendsetelementstoarray.appendSetElementsToArray)(downloadDomainSet, S3OSSDomains); + (0, _appendarrayinplace.appendArrayInPlace)(downloadDomainSet, steamDomainSet); + // we have whitelisted the crashlytics domain, and we also want to put it in CDN policy + (0, _appendarrayinplace.appendArrayInPlace)(cdnDomainsList, _rejectdatasource.CRASHLYTICS_WHITELIST); + return Promise.all([ + new _domainset.DomainsetOutput(span, 'cdn').withTitle('Sukka\'s Ruleset - CDN Domains').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains object storage and static assets CDN domains.' + ]).addFromDomainset(cdnDomainsList).write(), + new _domainset.DomainsetOutput(span, 'download').withTitle('Sukka\'s Ruleset - Large Files Hosting Domains').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains domains for software updating & large file hosting.' + ]).addFromDomainset(downloadDomainSet).write() + ]); + }); + } (buildCdnDownloadConf.__module, buildCdnDownloadConf.__module.exports)); + return buildCdnDownloadConf.__module.exports; +}exports.__require=requireBuildCdnDownloadConf; \ No newline at end of file diff --git a/Dist/Build/build-chn-cidr.cjs b/Dist/Build/build-chn-cidr.cjs new file mode 100644 index 00000000..822c9f73 --- /dev/null +++ b/Dist/Build/build-chn-cidr.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildChnCidr$1=require('./build-chn-cidr2.cjs');var buildChnCidrExports = buildChnCidr$1.__require(); +const buildChnCidr = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildChnCidrExports);module.exports=buildChnCidr; \ No newline at end of file diff --git a/Dist/Build/build-chn-cidr2.cjs b/Dist/Build/build-chn-cidr2.cjs new file mode 100644 index 00000000..bee98874 --- /dev/null +++ b/Dist/Build/build-chn-cidr2.cjs @@ -0,0 +1,77 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildChnCidr=require('../_virtual/build-chn-cidr.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),index=require('./trace/index.cjs'),require$$2=require('fast-cidr-tools'),memoPromise=require('./lib/memo-promise.cjs'),cidr=require('./constants/cidr.cjs'),appendArrayInPlace=require('./lib/append-array-in-place.cjs'),ip=require('./lib/rules/ip.cjs'),fsMemo=require('./lib/fs-memo.cjs'),description=require('./constants/description.cjs');var hasRequiredBuildChnCidr; + +function requireBuildChnCidr () { + if (hasRequiredBuildChnCidr) return buildChnCidr.__module.exports; + hasRequiredBuildChnCidr = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + buildChnCidr: function() { + return buildChnCidr; + }, + getChnCidrPromise: function() { + return getChnCidrPromise; + } + }); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _trace = /*@__PURE__*/ index.__require(); + const _fastcidrtools = require$$2; + const _memopromise = /*@__PURE__*/ memoPromise.__require(); + const _cidr = /*@__PURE__*/ cidr.__require(); + const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require(); + const _ip = /*@__PURE__*/ ip.__require(); + const _fsmemo = /*@__PURE__*/ fsMemo.__require(); + const _description = /*@__PURE__*/ description.__require(); + const PROBE_CHN_CIDR_V4 = [ + // NetEase Hangzhou + '223.252.196.38', + // Aliyun ShenZhen + '120.78.92.171' + ]; + const getChnCidrPromise = (0, _memopromise.createMemoizedPromise)((0, _fsmemo.cachedOnlyFail)(async function getChnCidr() { + const [_cidr4, cidr6] = await Promise.all([ + (0, _fetchtextbyline.fetchRemoteTextByLine)('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt', true).then(Array.fromAsync), + (0, _fetchtextbyline.fetchRemoteTextByLine)('https://gaoyifan.github.io/china-operator-ip/china6.txt', true).then(Array.fromAsync) + ]); + const cidr4 = (0, _fastcidrtools.exclude)((0, _appendarrayinplace.appendArrayInPlace)(_cidr4, _cidr.CN_CIDR_MISSING_IN_CHNROUTE), _cidr.NON_CN_CIDR_INCLUDED_IN_CHNROUTE, true); + for (const probeIp of PROBE_CHN_CIDR_V4){ + if (!(0, _fastcidrtools.contains)(cidr4, PROBE_CHN_CIDR_V4)) { + const err = new TypeError('chnroutes missing probe IP'); + err.cause = probeIp; + throw err; + } + } + return [ + cidr4, + cidr6 + ]; + }, { + serializer: JSON.stringify, + deserializer: JSON.parse + })); + const buildChnCidr = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const [filteredCidr4, cidr6] = await span.traceChildAsync('download chnroutes2', getChnCidrPromise); + // Can not use SHARED_DESCRIPTION here as different license + const description = (0, _description.createFileDescription)('CC BY-SA 2.0'); + return Promise.all([ + new _ip.IPListOutput(span, 'china_ip', false).withTitle('Sukka\'s Ruleset - Mainland China IPv4 CIDR').withDescription([ + ...description, + 'Data from https://misaka.io (misakaio @ GitHub)' + ]).bulkAddCIDR4(filteredCidr4).write(), + new _ip.IPListOutput(span, 'china_ip_ipv6', false).withTitle('Sukka\'s Ruleset - Mainland China IPv6 CIDR').withDescription([ + ...description, + 'Data from https://github.com/gaoyifan/china-operator-ip' + ]).bulkAddCIDR6(cidr6).write() + ]); + }); + } (buildChnCidr.__module, buildChnCidr.__module.exports)); + return buildChnCidr.__module.exports; +}exports.__require=requireBuildChnCidr; \ No newline at end of file diff --git a/Dist/Build/build-cloudmounter-rules.cjs b/Dist/Build/build-cloudmounter-rules.cjs new file mode 100644 index 00000000..1a860fc7 --- /dev/null +++ b/Dist/Build/build-cloudmounter-rules.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildCloudmounterRules$1=require('./build-cloudmounter-rules2.cjs');var buildCloudmounterRulesExports = buildCloudmounterRules$1.__require(); +const buildCloudmounterRules = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildCloudmounterRulesExports);module.exports=buildCloudmounterRules; \ No newline at end of file diff --git a/Dist/Build/build-cloudmounter-rules2.cjs b/Dist/Build/build-cloudmounter-rules2.cjs new file mode 100644 index 00000000..43acea6d --- /dev/null +++ b/Dist/Build/build-cloudmounter-rules2.cjs @@ -0,0 +1,36 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildCloudmounterRules=require('../_virtual/build-cloudmounter-rules.cjs'),cloudmounter=require('../Source/non_ip/cloudmounter.cjs'),description=require('./constants/description.cjs'),index=require('./trace/index.cjs'),ruleset=require('./lib/rules/ruleset.cjs');var hasRequiredBuildCloudmounterRules; + +function requireBuildCloudmounterRules () { + if (hasRequiredBuildCloudmounterRules) return buildCloudmounterRules.__module.exports; + hasRequiredBuildCloudmounterRules = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildCloudMounterRules", { + enumerable: true, + get: function() { + return buildCloudMounterRules; + } + }); + const _cloudmounter = /*@__PURE__*/ cloudmounter.__require(); + const _description = /*@__PURE__*/ description.__require(); + const _trace = /*@__PURE__*/ index.__require(); + const _ruleset = /*@__PURE__*/ ruleset.__require(); + const buildCloudMounterRules = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + // AND,((SRC-IP,192.168.1.110), (DOMAIN, example.com)) + const results = _cloudmounter.DOMAINS.flatMap((domain)=>_cloudmounter.PROCESS_NAMES.flatMap((process)=>[ + `AND,((${domain}),(PROCESS-NAME,${process}))`, + ...[ + '10.0.0.0/8', + // '127.0.0.0/8', + '172.16.0.0/12', + '192.168.0.0/16' + ].map((cidr)=>`AND,((${domain}),(SRC-IP,${cidr}))`) + ])); + const description = _description.SHARED_DESCRIPTION; + return new _ruleset.RulesetOutput(span, 'cloudmounter', 'non_ip').withTitle('Sukka\'s Ruleset - CloudMounter / RaiDrive').withDescription(description).addFromRuleset(results).write(); + }); + } (buildCloudmounterRules.__module, buildCloudmounterRules.__module.exports)); + return buildCloudmounterRules.__module.exports; +}exports.__require=requireBuildCloudmounterRules; \ No newline at end of file diff --git a/Dist/Build/build-common.cjs b/Dist/Build/build-common.cjs new file mode 100644 index 00000000..50082e5f --- /dev/null +++ b/Dist/Build/build-common.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildCommon$1=require('./build-common2.cjs');var buildCommonExports = buildCommon$1.__require(); +const buildCommon = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildCommonExports);module.exports=buildCommon; \ No newline at end of file diff --git a/Dist/Build/build-common2.cjs b/Dist/Build/build-common2.cjs new file mode 100644 index 00000000..f533bba2 --- /dev/null +++ b/Dist/Build/build-common2.cjs @@ -0,0 +1,161 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildCommon=require('../_virtual/build-common.cjs'),require$$0=require('node:path'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),processLine=require('./lib/process-line.cjs'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),require$$5=require('fdir'),appendArrayInPlace=require('./lib/append-array-in-place.cjs'),dir=require('./constants/dir.cjs'),domainset=require('./lib/rules/domainset.cjs'),ruleset=require('./lib/rules/ruleset.cjs');var hasRequiredBuildCommon; + +function requireBuildCommon () { + if (hasRequiredBuildCommon) return buildCommon.__module.exports; + hasRequiredBuildCommon = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildCommon", { + enumerable: true, + get: function() { + return buildCommon; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_wildcard(require$$0); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _processline = /*@__PURE__*/ processLine.__require(); + const _trace = /*@__PURE__*/ index.__require(); + const _description = /*@__PURE__*/ description.__require(); + const _fdir = require$$5; + const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require(); + const _dir = /*@__PURE__*/ dir.__require(); + const _domainset = /*@__PURE__*/ domainset.__require(); + const _ruleset = /*@__PURE__*/ ruleset.__require(); + function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); + } + function _interop_require_wildcard(obj, nodeInterop) { + if (obj && obj.__esModule) { + return obj; + } + if (obj === null || typeof obj !== "object" && typeof obj !== "function") { + return { + default: obj + }; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = { + __proto__: null + }; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; + } + const MAGIC_COMMAND_SKIP = '# $ custom_build_script'; + const MAGIC_COMMAND_TITLE = '# $ meta_title '; + const MAGIC_COMMAND_DESCRIPTION = '# $ meta_description '; + const MAGIC_COMMAND_SGMODULE_MITM_HOSTNAMES = '# $ sgmodule_mitm_hostnames '; + const clawSourceDirPromise = new _fdir.fdir().withRelativePaths().filter((filepath, isDirectory)=>{ + if (isDirectory) return true; + const extname = _nodepath.extname(filepath); + return !(extname === '.js' || extname === '.ts'); + }).crawl(_dir.SOURCE_DIR).withPromise(); + const buildCommon = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const promises = []; + const paths = await clawSourceDirPromise; + for(let i = 0, len = paths.length; i < len; i++){ + const relativePath = paths[i]; + const fullPath = _dir.SOURCE_DIR + _nodepath.sep + relativePath; + // if ( + // relativePath.startsWith('ip/') + // || relativePath.startsWith('non_ip/') + // ) { + promises.push(transform(span, fullPath, relativePath)); + // continue; + // } + // console.error(picocolors.red(`[build-comman] Unknown file: ${relativePath}`)); + } + return Promise.all(promises); + }); + const $skip = Symbol('skip'); + function processFile(span, sourcePath) { + return span.traceChildAsync(`process file: ${sourcePath}`, async ()=>{ + const lines = []; + let title = ''; + const descriptions = []; + let sgmodulePathname = null; + try { + for await (const line of (0, _fetchtextbyline.readFileByLine)(sourcePath)){ + if (line.startsWith(MAGIC_COMMAND_SKIP)) { + return $skip; + } + if (line.startsWith(MAGIC_COMMAND_TITLE)) { + title = line.slice(MAGIC_COMMAND_TITLE.length).trim(); + continue; + } + if (line.startsWith(MAGIC_COMMAND_DESCRIPTION)) { + descriptions.push(line.slice(MAGIC_COMMAND_DESCRIPTION.length).trim()); + continue; + } + if (line.startsWith(MAGIC_COMMAND_SGMODULE_MITM_HOSTNAMES)) { + sgmodulePathname = line.slice(MAGIC_COMMAND_SGMODULE_MITM_HOSTNAMES.length).trim(); + continue; + } + const l = (0, _processline.processLine)(line); + if (l) { + lines.push(l); + } + } + } catch (e) { + console.error('Error processing', sourcePath); + console.trace(e); + } + return [ + title, + descriptions, + lines, + sgmodulePathname + ]; + }); + } + async function transform(parentSpan, sourcePath, relativePath) { + const extname = _nodepath.extname(sourcePath); + const id = _nodepath.basename(sourcePath, extname); + return parentSpan.traceChild(`transform ruleset: ${id}`).traceAsyncFn(async (span)=>{ + const type = relativePath.split(_nodepath.sep)[0]; + if (type !== 'ip' && type !== 'non_ip' && type !== 'domainset') { + throw new TypeError(`Invalid type: ${type}`); + } + const res = await processFile(span, sourcePath); + if (res === $skip) return; + const [title, descriptions, lines, sgmoduleName] = res; + let finalDescriptions; + if (descriptions.length) { + finalDescriptions = _description.SHARED_DESCRIPTION.slice(); + finalDescriptions.push(''); + (0, _appendarrayinplace.appendArrayInPlace)(finalDescriptions, descriptions); + } else { + finalDescriptions = _description.SHARED_DESCRIPTION; + } + if (type === 'domainset') { + return new _domainset.DomainsetOutput(span, id).withTitle(title).withDescription(finalDescriptions).addFromDomainset(lines).write(); + } + return new _ruleset.RulesetOutput(span, id, type).withTitle(title).withDescription(finalDescriptions).withMitmSgmodulePath(sgmoduleName).addFromRuleset(lines).write(); + }); + } + } (buildCommon.__module, buildCommon.__module.exports)); + return buildCommon.__module.exports; +}exports.__require=requireBuildCommon; \ No newline at end of file diff --git a/Dist/Build/build-deprecate-files.cjs b/Dist/Build/build-deprecate-files.cjs new file mode 100644 index 00000000..788ed761 --- /dev/null +++ b/Dist/Build/build-deprecate-files.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildDeprecateFiles$1=require('./build-deprecate-files2.cjs');var buildDeprecateFilesExports = buildDeprecateFiles$1.__require(); +const buildDeprecateFiles = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildDeprecateFilesExports);module.exports=buildDeprecateFiles; \ No newline at end of file diff --git a/Dist/Build/build-deprecate-files2.cjs b/Dist/Build/build-deprecate-files2.cjs new file mode 100644 index 00000000..a3275b4b --- /dev/null +++ b/Dist/Build/build-deprecate-files2.cjs @@ -0,0 +1,67 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildDeprecateFiles=require('../_virtual/build-deprecate-files.cjs'),dir=require('./constants/dir.cjs'),createFile=require('./lib/create-file.cjs'),index=require('./trace/index.cjs'),require$$0=require('node:path'),require$$2=require('node:fs/promises');var hasRequiredBuildDeprecateFiles; + +function requireBuildDeprecateFiles () { + if (hasRequiredBuildDeprecateFiles) return buildDeprecateFiles.__module.exports; + hasRequiredBuildDeprecateFiles = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildDeprecateFiles", { + enumerable: true, + get: function() { + return buildDeprecateFiles; + } + }); + const _dir = /*@__PURE__*/ dir.__require(); + const _createfile = /*@__PURE__*/ createFile.__require(); + const _trace = /*@__PURE__*/ index.__require(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _promises = /*#__PURE__*/ _interop_require_default(require$$2); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const DEPRECATED_FILES = [ + [ + 'non_ip/global_plus', + 'This file has been merged with non_ip/global' + ], + [ + 'domainset/reject_sukka', + 'This file has been merged with domainset/reject' + ], + [ + 'domainset/reject_phishing', + 'This file has been merged with domainset/reject' + ] + ]; + const REMOVED_FILES = [ + 'Internal/cdn.txt', + 'List/internal/appprofile.php', + 'Clash/domainset/steam.txt', + 'Clash/non_ip/clash_fake_ip_filter.txt', + 'sing-box/domainset/steam.json', + 'Modules/sukka_unlock_abema.sgmodule', + 'Modules/sukka_exclude_reservered_ip.sgmodule' + ]; + const buildDeprecateFiles = (0, _trace.task)(require.main === module, __filename)((span)=>span.traceChildAsync('create deprecated files', async (childSpan)=>{ + const promises = REMOVED_FILES.map((f)=>_promises.default.rm(_nodepath.default.join(_dir.PUBLIC_DIR, f), { + force: true, + recursive: true + })); + for (const [filePath, description] of DEPRECATED_FILES){ + const content = [ + '#########################################', + '# Sukka\'s Ruleset - Deprecated', + `# ${description}`, + '################## EOF ##################' + ]; + promises.push((0, _createfile.compareAndWriteFile)(childSpan, content, _nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, `${filePath}.conf`)), (0, _createfile.compareAndWriteFile)(childSpan, content, _nodepath.default.resolve(_dir.OUTPUT_CLASH_DIR, `${filePath}.txt`))); + } + return Promise.all(promises); + })); + } (buildDeprecateFiles.__module, buildDeprecateFiles.__module.exports)); + return buildDeprecateFiles.__module.exports; +}exports.__require=requireBuildDeprecateFiles; \ No newline at end of file diff --git a/Dist/Build/build-domestic-direct-lan-ruleset-dns-mapping-module.cjs b/Dist/Build/build-domestic-direct-lan-ruleset-dns-mapping-module.cjs new file mode 100644 index 00000000..61fc2436 --- /dev/null +++ b/Dist/Build/build-domestic-direct-lan-ruleset-dns-mapping-module.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildDomesticDirectLanRulesetDnsMappingModule$1=require('./build-domestic-direct-lan-ruleset-dns-mapping-module2.cjs');var buildDomesticDirectLanRulesetDnsMappingModuleExports = buildDomesticDirectLanRulesetDnsMappingModule$1.__require(); +const buildDomesticDirectLanRulesetDnsMappingModule = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildDomesticDirectLanRulesetDnsMappingModuleExports);module.exports=buildDomesticDirectLanRulesetDnsMappingModule; \ No newline at end of file diff --git a/Dist/Build/build-domestic-direct-lan-ruleset-dns-mapping-module2.cjs b/Dist/Build/build-domestic-direct-lan-ruleset-dns-mapping-module2.cjs new file mode 100644 index 00000000..8e082beb --- /dev/null +++ b/Dist/Build/build-domestic-direct-lan-ruleset-dns-mapping-module2.cjs @@ -0,0 +1,305 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildDomesticDirectLanRulesetDnsMappingModule=require('../_virtual/build-domestic-direct-lan-ruleset-dns-mapping-module.cjs'),require$$0=require('node:path'),domestic=require('../Source/non_ip/domestic.cjs'),direct=require('../Source/non_ip/direct.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),createFile=require('./lib/create-file.cjs'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),memoPromise=require('./lib/memo-promise.cjs'),require$$8=require('yaml'),appendArrayInPlace=require('./lib/append-array-in-place.cjs'),dir=require('./constants/dir.cjs'),ruleset=require('./lib/rules/ruleset.cjs');var hasRequiredBuildDomesticDirectLanRulesetDnsMappingModule; + +function requireBuildDomesticDirectLanRulesetDnsMappingModule () { + if (hasRequiredBuildDomesticDirectLanRulesetDnsMappingModule) return buildDomesticDirectLanRulesetDnsMappingModule.__module.exports; + hasRequiredBuildDomesticDirectLanRulesetDnsMappingModule = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + buildDomesticRuleset: function() { + return buildDomesticRuleset; + }, + createGetDnsMappingRule: function() { + return createGetDnsMappingRule; + }, + getDomesticAndDirectDomainsRulesetPromise: function() { + return getDomesticAndDirectDomainsRulesetPromise; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _domestic = /*@__PURE__*/ domestic.__require(); + const _direct = /*@__PURE__*/ direct.__require(); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _createfile = /*@__PURE__*/ createFile.__require(); + const _trace = /*@__PURE__*/ index.__require(); + const _description = /*@__PURE__*/ description.__require(); + const _memopromise = /*@__PURE__*/ memoPromise.__require(); + const _yaml = /*#__PURE__*/ _interop_require_wildcard(require$$8); + const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require(); + const _dir = /*@__PURE__*/ dir.__require(); + const _ruleset = /*@__PURE__*/ ruleset.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); + } + function _interop_require_wildcard(obj, nodeInterop) { + if (obj && obj.__esModule) { + return obj; + } + if (obj === null || typeof obj !== "object" && typeof obj !== "function") { + return { + default: obj + }; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = { + __proto__: null + }; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; + } + function createGetDnsMappingRule(allowWildcard) { + const hasWildcard = (domain)=>{ + if (domain.includes('*') || domain.includes('?')) { + if (!allowWildcard) { + throw new TypeError(`Wildcard domain is not supported: ${domain}`); + } + return true; + } + return false; + }; + return (domain)=>{ + const results = []; + if (domain[0] === '$') { + const d = domain.slice(1); + if (hasWildcard(domain)) { + results.push(`DOMAIN-WILDCARD,${d}`); + } else { + results.push(`DOMAIN,${d}`); + } + } else if (domain[0] === '+') { + const d = domain.slice(1); + if (hasWildcard(domain)) { + results.push(`DOMAIN-WILDCARD,*.${d}`); + } else { + results.push(`DOMAIN-SUFFIX,${d}`); + } + } else if (hasWildcard(domain)) { + results.push(`DOMAIN-WILDCARD,${domain}`, `DOMAIN-WILDCARD,*.${domain}`); + } else { + results.push(`DOMAIN-SUFFIX,${domain}`); + } + return results; + }; + } + const getDomesticAndDirectDomainsRulesetPromise = (0, _memopromise.createMemoizedPromise)(async ()=>{ + const domestics = await (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip/domestic.conf')); + const directs = await (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.resolve(_dir.SOURCE_DIR, 'non_ip/direct.conf')); + const lans = []; + const getDnsMappingRuleWithWildcard = createGetDnsMappingRule(true); + [ + _domestic.DOH_BOOTSTRAP, + _domestic.DOMESTICS + ].forEach((item)=>{ + Object.values(item).forEach(({ domains })=>{ + (0, _appendarrayinplace.appendArrayInPlace)(domestics, domains.flatMap(getDnsMappingRuleWithWildcard)); + }); + }); + Object.values(_direct.DIRECTS).forEach(({ domains })=>{ + (0, _appendarrayinplace.appendArrayInPlace)(directs, domains.flatMap(getDnsMappingRuleWithWildcard)); + }); + Object.values(_direct.LAN).forEach(({ domains })=>{ + (0, _appendarrayinplace.appendArrayInPlace)(directs, domains.flatMap(getDnsMappingRuleWithWildcard)); + }); + return [ + domestics, + directs, + lans + ]; + }); + const buildDomesticRuleset = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const [domestics, directs, lans] = await getDomesticAndDirectDomainsRulesetPromise(); + const dataset = [ + _domestic.DOH_BOOTSTRAP, + _domestic.DOMESTICS, + _direct.DIRECTS, + _direct.LAN + ].flatMap(Object.entries); + return Promise.all([ + new _ruleset.RulesetOutput(span, 'domestic', 'non_ip').withTitle('Sukka\'s Ruleset - Domestic Domains').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains known addresses that are avaliable in the Mainland China.' + ]).addFromRuleset(domestics).write(), + new _ruleset.RulesetOutput(span, 'direct', 'non_ip').withTitle('Sukka\'s Ruleset - Direct Rules').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains domains and process that should not be proxied.' + ]).addFromRuleset(directs).write(), + new _ruleset.RulesetOutput(span, 'lan', 'non_ip').withTitle('Sukka\'s Ruleset - LAN').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file includes rules for LAN DOMAIN and reserved TLDs.' + ]).addFromRuleset(lans).write(), + ...dataset.map(([name, { ruleset, domains }])=>{ + if (!ruleset) { + return; + } + const output = new _ruleset.SurgeOnlyRulesetOutput(span, name.toLowerCase(), 'sukka_local_dns_mapping', _dir.OUTPUT_MODULES_RULES_DIR).withTitle(`Sukka's Ruleset - Local DNS Mapping (${name})`).withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This is an internal rule that is only referenced by sukka_local_dns_mapping.sgmodule', + 'Do not use this file in your Rule section, all rules are included in non_ip/domestic.conf already.' + ]); + domains.forEach((domain)=>{ + switch(domain[0]){ + case '$': + output.addDomain(domain.slice(1)); + break; + case '+': + output.addDomainSuffix(domain.slice(1)); + break; + default: + output.addDomainSuffix(domain); + break; + } + }); + return output.write(); + }), + (0, _createfile.compareAndWriteFile)(span, [ + '#!name=[Sukka] Local DNS Mapping', + `#!desc=Last Updated: ${new Date().toISOString()}`, + '', + '[Host]', + ...Object.entries(// I use an object to deduplicate the domains + // Otherwise I could just construct an array directly + dataset.reduce((acc, cur)=>{ + const ruleset_name = cur[0].toLowerCase(); + const { domains, dns, hosts, ruleset } = cur[1]; + Object.entries(hosts).forEach(([dns, ips])=>{ + acc[dns] ||= ips.join(', '); + }); + if (ruleset) { + acc[`RULE-SET:https://ruleset.skk.moe/Modules/Rules/sukka_local_dns_mapping/${ruleset_name}.conf`] ||= `server:${dns}`; + } else { + domains.forEach((domain)=>{ + switch(domain[0]){ + case '$': + acc[domain.slice(1)] ||= `server:${dns}`; + break; + case '+': + acc[`*.${domain.slice(1)}`] ||= `server:${dns}`; + break; + default: + acc[domain] ||= `server:${dns}`; + acc[`*.${domain}`] ||= `server:${dns}`; + break; + } + }); + } + return acc; + }, {})).map(([dns, ips])=>`${dns} = ${ips}`) + ], _nodepath.default.resolve(_dir.OUTPUT_MODULES_DIR, 'sukka_local_dns_mapping.sgmodule')), + (0, _createfile.compareAndWriteFile)(span, _yaml.stringify(dataset.reduce((acc, cur)=>{ + const { domains, dns, ...rest } = cur[1]; + domains.forEach((domain)=>{ + switch(domain[0]){ + case '$': + domain = domain.slice(1); + break; + case '+': + domain = `*.${domain.slice(1)}`; + break; + default: + domain = `+.${domain}`; + break; + } + acc.dns['nameserver-policy'][domain] = dns === 'system' ? [ + 'system://', + 'system', + 'dhcp://system' + ] : dns; + }); + if ('hosts' in rest) { + Object.assign(acc.hosts, rest.hosts); + } + return acc; + }, { + dns: { + 'nameserver-policy': {} + }, + hosts: {} + }), { + version: '1.1' + }).split('\n'), _nodepath.default.join(_dir.OUTPUT_INTERNAL_DIR, 'clash_nameserver_policy.yaml')), + (0, _createfile.compareAndWriteFile)(span, [ + '# Local DNS Mapping for AdGuard Home', + 'tls://1.12.12.12', + 'tls://120.53.53.53', + 'https://1.12.12.12/dns-query', + 'https://120.53.53.53/dns-query', + '[//]udp://10.10.1.1:53', + ...[ + _domestic.DOMESTICS, + _direct.DIRECTS, + _direct.LAN + ].flatMap(Object.values).flatMap(({ domains, dns: _dns })=>domains.flatMap((domain)=>{ + let dns; + if (_dns in _domestic.AdGuardHomeDNSMapping) { + dns = _domestic.AdGuardHomeDNSMapping[_dns].join(' '); + } else { + console.warn(`Unknown DNS "${_dns}" not in AdGuardHomeDNSMapping`); + dns = _dns; + } + // if ( + // // AdGuard Home has built-in AS112 / private PTR handling + // domain.endsWith('.arpa') + // // Ignore simple hostname + // || !domain.includes('.') + // ) { + // return []; + // } + if (domain[0] === '$') { + return [ + `[/${domain.slice(1)}/]${dns}` + ]; + } + if (domain[0] === '+') { + return [ + `[/${domain.slice(1)}/]${dns}` + ]; + } + return [ + `[/${domain}/]${dns}` + ]; + })) + ], _nodepath.default.resolve(_dir.OUTPUT_INTERNAL_DIR, 'dns_mapping_adguardhome.conf')) + ]); + }); + } (buildDomesticDirectLanRulesetDnsMappingModule.__module, buildDomesticDirectLanRulesetDnsMappingModule.__module.exports)); + return buildDomesticDirectLanRulesetDnsMappingModule.__module.exports; +}exports.__require=requireBuildDomesticDirectLanRulesetDnsMappingModule; \ No newline at end of file diff --git a/Dist/Build/build-internal-reverse-chn-cidr.cjs b/Dist/Build/build-internal-reverse-chn-cidr.cjs new file mode 100644 index 00000000..09e637cc --- /dev/null +++ b/Dist/Build/build-internal-reverse-chn-cidr.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildInternalReverseChnCidr$1=require('./build-internal-reverse-chn-cidr2.cjs');var buildInternalReverseChnCidrExports = buildInternalReverseChnCidr$1.__require(); +const buildInternalReverseChnCidr = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildInternalReverseChnCidrExports);module.exports=buildInternalReverseChnCidr; \ No newline at end of file diff --git a/Dist/Build/build-internal-reverse-chn-cidr2.cjs b/Dist/Build/build-internal-reverse-chn-cidr2.cjs new file mode 100644 index 00000000..23c52438 --- /dev/null +++ b/Dist/Build/build-internal-reverse-chn-cidr2.cjs @@ -0,0 +1,77 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildInternalReverseChnCidr=require('../_virtual/build-internal-reverse-chn-cidr.cjs'),require$$0$1=require('node:path'),index=require('./trace/index.cjs'),buildChnCidr=require('./build-chn-cidr2.cjs'),require$$1=require('node:fs'),dir=require('./constants/dir.cjs'),require$$0=require('foxts/async-write-to-stream'),misc=require('./lib/misc.cjs'),require$$7=require('worktank'),require$$8=require('url');var hasRequiredBuildInternalReverseChnCidr; + +function requireBuildInternalReverseChnCidr () { + if (hasRequiredBuildInternalReverseChnCidr) return buildInternalReverseChnCidr.__module.exports; + hasRequiredBuildInternalReverseChnCidr = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildInternalReverseChnCIDR", { + enumerable: true, + get: function() { + return buildInternalReverseChnCIDR; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _trace = /*@__PURE__*/ index.__require(); + const _buildchncidr = buildChnCidr.__require(); + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1); + const _dir = /*@__PURE__*/ dir.__require(); + const _asyncwritetostream = require$$0; + const _misc = /*@__PURE__*/ misc.__require(); + const _worktank = /*#__PURE__*/ _interop_require_default(require$$7); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const pool = new _worktank.default({ + name: 'build-internal-reverse-chn-cidr', + size: 1, + timeout: 10000, + warmup: true, + autoterminate: 30000, + env: {}, + methods: { + // eslint-disable-next-line object-shorthand -- workertank + getreversedCidr: async function(cidr, importMetaUrl) { + // TODO: createRequire is a temporary workaround for https://github.com/nodejs/node/issues/51956 + const { default: module1 } = await import('node:module'); + const __require = module1.createRequire(importMetaUrl); + const { exclude, merge } = __require('fast-cidr-tools'); + const { RESERVED_IPV4_CIDR, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } = __require('./constants/cidr'); + const { appendArrayInPlace } = __require('./lib/append-array-in-place'); + return merge(appendArrayInPlace(exclude([ + '0.0.0.0/0' + ], RESERVED_IPV4_CIDR.concat(cidr), true), // https://github.com/misakaio/chnroutes2/issues/25 + NON_CN_CIDR_INCLUDED_IN_CHNROUTE), true); + } + } + }); + const buildInternalReverseChnCIDR = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const [cidr] = await span.traceChildPromise('download chnroutes2', (0, _buildchncidr.getChnCidrPromise)()); + const reversedCidr = await span.traceChildAsync('build reversed chn cidr', async ()=>{ + const reversedCidr = await pool.exec('getreversedCidr', [ + cidr, + require$$8.pathToFileURL(__filename).toString() + ]); + pool.terminate(); + return reversedCidr; + }); + const outputFile = _nodepath.default.join(_dir.OUTPUT_INTERNAL_DIR, 'reversed-chn-cidr.txt'); + await (0, _misc.mkdirp)(_dir.OUTPUT_INTERNAL_DIR); + const writeStream = _nodefs.default.createWriteStream(outputFile); + for (const line of reversedCidr){ + const p = (0, _asyncwritetostream.asyncWriteToStream)(writeStream, line + '\n'); + if (p) { + // eslint-disable-next-line no-await-in-loop -- stream high water mark + await p; + } + } + await (0, _asyncwritetostream.asyncWriteToStream)(writeStream, '\n'); + writeStream.end(); + }); + } (buildInternalReverseChnCidr.__module, buildInternalReverseChnCidr.__module.exports)); + return buildInternalReverseChnCidr.__module.exports; +}exports.__require=requireBuildInternalReverseChnCidr; \ No newline at end of file diff --git a/Dist/Build/build-microsoft-cdn.cjs b/Dist/Build/build-microsoft-cdn.cjs new file mode 100644 index 00000000..9912c3c0 --- /dev/null +++ b/Dist/Build/build-microsoft-cdn.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildMicrosoftCdn$1=require('./build-microsoft-cdn2.cjs');var buildMicrosoftCdnExports = buildMicrosoftCdn$1.__require(); +const buildMicrosoftCdn = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildMicrosoftCdnExports);module.exports=buildMicrosoftCdn; \ No newline at end of file diff --git a/Dist/Build/build-microsoft-cdn2.cjs b/Dist/Build/build-microsoft-cdn2.cjs new file mode 100644 index 00000000..5310a0ed --- /dev/null +++ b/Dist/Build/build-microsoft-cdn2.cjs @@ -0,0 +1,84 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildMicrosoftCdn=require('../_virtual/build-microsoft-cdn.cjs'),index=require('./trace/index.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),trie=require('./lib/trie.cjs'),description=require('./constants/description.cjs'),memoPromise=require('./lib/memo-promise.cjs'),parseDnsmasq=require('./lib/parse-dnsmasq.cjs'),ruleset=require('./lib/rules/ruleset.cjs'),appendArrayInPlace=require('./lib/append-array-in-place.cjs');var hasRequiredBuildMicrosoftCdn; + +function requireBuildMicrosoftCdn () { + if (hasRequiredBuildMicrosoftCdn) return buildMicrosoftCdn.__module.exports; + hasRequiredBuildMicrosoftCdn = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + buildMicrosoftCdn: function() { + return buildMicrosoftCdn; + }, + getMicrosoftCdnRulesetPromise: function() { + return getMicrosoftCdnRulesetPromise; + } + }); + const _trace = /*@__PURE__*/ index.__require(); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _trie = /*@__PURE__*/ trie.__require(); + const _description = /*@__PURE__*/ description.__require(); + const _memopromise = /*@__PURE__*/ memoPromise.__require(); + const _parsednsmasq = /*@__PURE__*/ parseDnsmasq.__require(); + const _ruleset = /*@__PURE__*/ ruleset.__require(); + const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require(); + const PROBE_DOMAINS = [ + '.microsoft.com', + '.windows.net', + '.windows.com', + '.windowsupdate.com', + '.windowssearch.com', + '.office.net' + ]; + const DOMAINS = [ + 'res.cdn.office.net', + 'res-1.cdn.office.net', + 'statics.teams.cdn.office.net' + ]; + const DOMAIN_SUFFIXES = [ + 'download.prss.microsoft.com' + ]; + const BLACKLIST = [ + 'www.microsoft.com', + 'windowsupdate.com' + ]; + const getMicrosoftCdnRulesetPromise = (0, _memopromise.createMemoizedPromise)(async ()=>{ + // First trie is to find the microsoft domains that matches probe domains + const trie = new _trie.HostnameSmolTrie(); + for await (const line of (await (0, _fetchtextbyline.fetchRemoteTextByLine)('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf'))){ + const domain = (0, _parsednsmasq.extractDomainsFromFelixDnsmasq)(line); + if (domain) { + trie.add(domain); + } + } + // remove blacklist domain from trie, to prevent them from being included in the later dump + BLACKLIST.forEach((black)=>trie.whitelist(black)); + const domains = DOMAINS; + const domainSuffixes = (0, _appendarrayinplace.appendArrayInPlace)(PROBE_DOMAINS.flatMap((domain)=>trie.find(domain)), DOMAIN_SUFFIXES); + return [ + domains, + domainSuffixes + ]; + }); + const buildMicrosoftCdn = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const description = [ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains Microsoft\'s domains using their China mainland CDN servers.', + '', + 'Data from:', + ' - https://github.com/felixonmars/dnsmasq-china-list' + ]; + const [domains, domainSuffixes] = await span.traceChildPromise('get microsoft cdn domains', getMicrosoftCdnRulesetPromise()); + return new _ruleset.RulesetOutput(span, 'microsoft_cdn', 'non_ip').withTitle('Sukka\'s Ruleset - Microsoft CDN').withDescription(description).bulkAddDomain(domains).bulkAddDomainSuffix(domainSuffixes).write(); + }); + } (buildMicrosoftCdn.__module, buildMicrosoftCdn.__module.exports)); + return buildMicrosoftCdn.__module.exports; +}exports.__require=requireBuildMicrosoftCdn; \ No newline at end of file diff --git a/Dist/Build/build-public.cjs b/Dist/Build/build-public.cjs new file mode 100644 index 00000000..b7db6294 --- /dev/null +++ b/Dist/Build/build-public.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildPublic$1=require('./build-public2.cjs');var buildPublicExports = buildPublic$1.__require(); +const buildPublic = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildPublicExports);module.exports=buildPublic; \ No newline at end of file diff --git a/Dist/Build/build-public2.cjs b/Dist/Build/build-public2.cjs new file mode 100644 index 00000000..7ccf5210 --- /dev/null +++ b/Dist/Build/build-public2.cjs @@ -0,0 +1,158 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildPublic=require('../_virtual/build-public.cjs'),require$$0$1=require('node:path'),require$$1=require('node:fs'),require$$2=require('node:fs/promises'),index=require('./trace/index.cjs'),treeDir=require('./lib/tree-dir.cjs'),dir=require('./constants/dir.cjs'),misc=require('./lib/misc.cjs'),require$$0=require('picocolors'),require$$8=require('foxts/tagged'),createFile=require('./lib/create-file.cjs');var hasRequiredBuildPublic; + +function requireBuildPublic () { + if (hasRequiredBuildPublic) return buildPublic.__module.exports; + hasRequiredBuildPublic = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildPublic", { + enumerable: true, + get: function() { + return buildPublic; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1); + const _promises = /*#__PURE__*/ _interop_require_default(require$$2); + const _trace = /*@__PURE__*/ index.__require(); + const _treedir = /*@__PURE__*/ treeDir.__require(); + const _dir = /*@__PURE__*/ dir.__require(); + const _misc = /*@__PURE__*/ misc.__require(); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0); + const _tagged = require$$8; + const _createfile = /*@__PURE__*/ createFile.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const mockDir = _nodepath.default.join(_dir.ROOT_DIR, 'Mock'); + const modulesDir = _nodepath.default.join(_dir.ROOT_DIR, 'Modules'); + async function copyDirContents(srcDir, destDir) { + const promises = []; + for await (const entry of (await _promises.default.opendir(srcDir))){ + const src = _nodepath.default.join(srcDir, entry.name); + const dest = _nodepath.default.join(destDir, entry.name); + if (entry.isDirectory()) { + console.warn(_picocolors.default.red('[build public] cant copy directory'), src); + } else { + promises.push(_promises.default.copyFile(src, dest, _nodefs.default.constants.COPYFILE_FICLONE)); + } + } + return Promise.all(promises); + } + const buildPublic = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + await span.traceChildAsync('copy rest of the files', async ()=>{ + await Promise.all([ + // mkdirp(OUTPUT_MODULES_DIR), + (0, _misc.mkdirp)(_dir.OUTPUT_MODULES_RULES_DIR), + (0, _misc.mkdirp)(_dir.OUTPUT_MOCK_DIR) + ]); + await Promise.all([ + copyDirContents(modulesDir, _dir.OUTPUT_MODULES_DIR), + copyDirContents(mockDir, _dir.OUTPUT_MOCK_DIR) + ]); + }); + const html = await span.traceChild('generate index.html').traceAsyncFn(()=>(0, _treedir.treeDir)(_dir.PUBLIC_DIR).then(generateHtml)); + await (0, _createfile.compareAndWriteFile)(span, [ + '/*', + ' cache-control: public, max-age=240, stale-while-revalidate=60, stale-if-error=15', + 'https://:project.pages.dev/*', + ' X-Robots-Tag: noindex', + '/Modules/*', + ' content-type: text/plain; charset=utf-8', + '/List/*', + ' content-type: text/plain; charset=utf-8' + ], _nodepath.default.join(_dir.PUBLIC_DIR, '_headers')); + await (0, _createfile.compareAndWriteFile)(span, [ + '#
',
+		        '#########################################',
+		        '# Sukka\'s Ruleset - 404 Not Found',
+		        '################## EOF ##################
' + ], _nodepath.default.join(_dir.PUBLIC_DIR, '404.html')); + return (0, _misc.writeFile)(_nodepath.default.join(_dir.PUBLIC_DIR, 'index.html'), html); + }); + const priorityOrder = { + domainset: 1, + non_ip: 2, + ip: 3, + List: 10, + Surge: 11, + Clash: 12, + 'sing-box': 13, + Modules: 20, + Script: 30, + Mock: 40, + Assets: 50, + Internal: 60, + LICENSE: 70, + default: Number.MAX_VALUE + }; + const prioritySorter = (a, b)=>(priorityOrder[a.name] || priorityOrder.default) - (priorityOrder[b.name] || priorityOrder.default) || (0, _misc.fastStringCompare)(a.name, b.name); + function walk(tree) { + let result = ''; + tree.sort(prioritySorter); + for(let i = 0, len = tree.length; i < len; i++){ + const entry = tree[i]; + if (entry.type === _treedir.TreeFileType.DIRECTORY) { + result += (0, _tagged.tagged)` +
  • + ${entry.name} +
      + ${walk(entry.children)} +
    +
  • + `; + } else if (/* entry.type === 'file' && */ entry.name !== 'index.html') { + result += (0, _tagged.tagged)`
  • ${entry.name}
  • `; + } + } + return result; + } + function generateHtml(tree) { + return (0, _tagged.tagged)` + + + + + + Surge Ruleset Server | Sukka (@SukkaW) + + + + + + + + + + + + + + + + + + + +
    +

    Sukka Ruleset Server

    +

    + Made by Sukka | Source @ GitHub | Licensed under AGPL-3.0 +

    +

    Last Build: ${new Date().toISOString()}

    +
    +
      + ${walk(tree)} +
    +
    + + + `; + } + } (buildPublic.__module, buildPublic.__module.exports)); + return buildPublic.__module.exports; +}exports.__require=requireBuildPublic; \ No newline at end of file diff --git a/Dist/Build/build-reject-domainset.cjs b/Dist/Build/build-reject-domainset.cjs new file mode 100644 index 00000000..7e54bb3b --- /dev/null +++ b/Dist/Build/build-reject-domainset.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildRejectDomainset$1=require('./build-reject-domainset2.cjs');var buildRejectDomainsetExports = buildRejectDomainset$1.__require(); +const buildRejectDomainset = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildRejectDomainsetExports);module.exports=buildRejectDomainset; \ No newline at end of file diff --git a/Dist/Build/build-reject-domainset2.cjs b/Dist/Build/build-reject-domainset2.cjs new file mode 100644 index 00000000..4a8e15a4 --- /dev/null +++ b/Dist/Build/build-reject-domainset2.cjs @@ -0,0 +1,141 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildRejectDomainset=require('../_virtual/build-reject-domainset.cjs'),require$$0=require('node:path'),require$$1=require('node:process'),hosts=require('./lib/parse-filter/hosts.cjs'),domainlists=require('./lib/parse-filter/domainlists.cjs'),filters=require('./lib/parse-filter/filters.cjs'),rejectDataSource=require('./constants/reject-data-source.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),getPhishingDomains=require('./lib/get-phishing-domains.cjs'),require$$10=require('foxts/add-array-elements-to-set'),dir=require('./constants/dir.cjs'),domainset=require('./lib/rules/domainset.cjs'),shared=require('./lib/parse-filter/shared.cjs');var hasRequiredBuildRejectDomainset; + +function requireBuildRejectDomainset () { + if (hasRequiredBuildRejectDomainset) return buildRejectDomainset.__module.exports; + hasRequiredBuildRejectDomainset = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildRejectDomainSet", { + enumerable: true, + get: function() { + return buildRejectDomainSet; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _nodeprocess = /*#__PURE__*/ _interop_require_default(require$$1); + const _hosts = /*@__PURE__*/ hosts.__require(); + const _domainlists = /*@__PURE__*/ domainlists.__require(); + const _filters = /*@__PURE__*/ filters.__require(); + const _rejectdatasource = /*@__PURE__*/ rejectDataSource.__require(); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _trace = /*@__PURE__*/ index.__require(); + const _description = /*@__PURE__*/ description.__require(); + const _getphishingdomains = /*@__PURE__*/ getPhishingDomains.__require(); + const _addarrayelementstoset = require$$10; + const _dir = /*@__PURE__*/ dir.__require(); + const _domainset = /*@__PURE__*/ domainset.__require(); + const _shared = /*@__PURE__*/ shared.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const readLocalRejectDomainsetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/reject_sukka.conf')); + const readLocalRejectExtraDomainsetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/reject_sukka_extra.conf')); + const readLocalRejectRulesetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip/reject.conf')); + const readLocalRejectDropRulesetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip/reject-drop.conf')); + const readLocalRejectNoDropRulesetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip/reject-no-drop.conf')); + const readLocalMyRejectRulesetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip/my_reject.conf')); + const hostsDownloads = _rejectdatasource.HOSTS.map((entry)=>(0, _hosts.processHostsWithPreload)(...entry)); + const hostsExtraDownloads = _rejectdatasource.HOSTS_EXTRA.map((entry)=>(0, _hosts.processHostsWithPreload)(...entry)); + const domainListsDownloads = _rejectdatasource.DOMAIN_LISTS.map((entry)=>(0, _domainlists.processDomainListsWithPreload)(...entry)); + const domainListsExtraDownloads = _rejectdatasource.DOMAIN_LISTS_EXTRA.map((entry)=>(0, _domainlists.processDomainListsWithPreload)(...entry)); + const adguardFiltersDownloads = _rejectdatasource.ADGUARD_FILTERS.map((entry)=>(0, _filters.processFilterRulesWithPreload)(...entry)); + const adguardFiltersExtraDownloads = _rejectdatasource.ADGUARD_FILTERS_EXTRA.map((entry)=>(0, _filters.processFilterRulesWithPreload)(...entry)); + const adguardFiltersWhitelistsDownloads = _rejectdatasource.ADGUARD_FILTERS_WHITELIST.map((entry)=>(0, _filters.processFilterRulesWithPreload)(...entry)); + const buildRejectDomainSet = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const rejectBaseDescription = [ + ..._description.SHARED_DESCRIPTION, + '', + 'The domainset supports AD blocking, tracking protection, privacy protection, anti-phishing, anti-mining', + '', + 'Build from:', + ..._rejectdatasource.HOSTS.map((host)=>` - ${host[0]}`), + ..._rejectdatasource.DOMAIN_LISTS.map((domainList)=>` - ${domainList[0]}`), + ..._rejectdatasource.ADGUARD_FILTERS.map((filter)=>` - ${Array.isArray(filter) ? filter[0] : filter}`) + ]; + const rejectOutput = new _domainset.DomainsetOutput(span, 'reject').withTitle('Sukka\'s Ruleset - Reject Base').withDescription(rejectBaseDescription); + const rejectExtraOutput = new _domainset.DomainsetOutput(span, 'reject_extra').withTitle('Sukka\'s Ruleset - Reject Extra').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'The domainset supports AD blocking, tracking protection, privacy protection, anti-phishing, anti-mining', + '', + 'Build from:', + ..._rejectdatasource.HOSTS_EXTRA.map((host)=>` - ${host[0]}`), + ..._rejectdatasource.DOMAIN_LISTS_EXTRA.map((domainList)=>` - ${domainList[0]}`), + ..._rejectdatasource.ADGUARD_FILTERS_EXTRA.map((filter)=>` - ${Array.isArray(filter) ? filter[0] : filter}`), + ..._rejectdatasource.PHISHING_DOMAIN_LISTS_EXTRA.map((domainList)=>` - ${domainList[0]}`) + ]); + const appendArrayToRejectOutput = rejectOutput.addFromDomainset.bind(rejectOutput); + const appendArrayToRejectExtraOutput = rejectExtraOutput.addFromDomainset.bind(rejectExtraOutput); + /** Whitelists */ const filterRuleWhitelistDomainSets = new Set(_rejectdatasource.PREDEFINED_WHITELIST); + // Parse from AdGuard Filters + await span.traceChild('download and process hosts / adblock filter rules').traceAsyncFn((childSpan)=>Promise.all([ + // Parse from remote hosts & domain lists + hostsDownloads.map((task)=>task(childSpan).then(appendArrayToRejectOutput)), + hostsExtraDownloads.map((task)=>task(childSpan).then(appendArrayToRejectExtraOutput)), + domainListsDownloads.map((task)=>task(childSpan).then(appendArrayToRejectOutput)), + domainListsExtraDownloads.map((task)=>task(childSpan).then(appendArrayToRejectExtraOutput)), + adguardFiltersDownloads.map((task)=>task(childSpan).then(({ whiteDomains, whiteDomainSuffixes, blackDomains, blackDomainSuffixes })=>{ + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomains); + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomainSuffixes, (suffix)=>'.' + suffix); + rejectOutput.bulkAddDomain(blackDomains); + rejectOutput.bulkAddDomainSuffix(blackDomainSuffixes); + })), + adguardFiltersExtraDownloads.map((task)=>task(childSpan).then(({ whiteDomains, whiteDomainSuffixes, blackDomains, blackDomainSuffixes })=>{ + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomains); + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomainSuffixes, (suffix)=>'.' + suffix); + rejectExtraOutput.bulkAddDomain(blackDomains); + rejectExtraOutput.bulkAddDomainSuffix(blackDomainSuffixes); + })), + adguardFiltersWhitelistsDownloads.map((task)=>task(childSpan).then(({ whiteDomains, whiteDomainSuffixes, blackDomains, blackDomainSuffixes })=>{ + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomains); + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomainSuffixes, (suffix)=>'.' + suffix); + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, blackDomains); + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, blackDomainSuffixes, (suffix)=>'.' + suffix); + })), + (0, _getphishingdomains.getPhishingDomains)(childSpan).then(appendArrayToRejectExtraOutput), + readLocalRejectDomainsetPromise.then(appendArrayToRejectOutput), + readLocalRejectDomainsetPromise.then(appendArrayToRejectExtraOutput), + readLocalRejectExtraDomainsetPromise.then(appendArrayToRejectExtraOutput), + // Dedupe domainSets + // span.traceChildAsync('collect black keywords/suffixes', async () => + /** + * Collect DOMAIN, DOMAIN-SUFFIX, and DOMAIN-KEYWORD from non_ip/reject.conf for deduplication + * DOMAIN-WILDCARD is not really useful for deduplication, it is only included in AdGuardHome output + */ rejectOutput.addFromRuleset(readLocalRejectRulesetPromise), + rejectExtraOutput.addFromRuleset(readLocalRejectRulesetPromise) + ].flat())); + if (_shared.foundDebugDomain.value) { + // eslint-disable-next-line sukka/unicorn/no-process-exit -- cli App + _nodeprocess.default.exit(1); + } + await Promise.all([ + rejectOutput.done(), + rejectExtraOutput.done() + ]); + // whitelist + span.traceChildSync('whitelist', ()=>{ + for (const domain of filterRuleWhitelistDomainSets){ + rejectOutput.whitelistDomain(domain); + rejectExtraOutput.whitelistDomain(domain); + } + rejectOutput.domainTrie.dump(rejectExtraOutput.whitelistDomain.bind(rejectExtraOutput)); + }); + await Promise.all([ + rejectOutput.write(), + rejectExtraOutput.write() + ]); + // we are going to re-use rejectOutput's domainTrie and mutate it + // so we must wait until we write rejectOutput to disk after we can mutate its trie + const rejectOutputAdGuardHome = new _domainset.AdGuardHomeOutput(span, 'reject-adguardhome', _dir.OUTPUT_INTERNAL_DIR).withTitle('Sukka\'s Ruleset - Blocklist for AdGuardHome').withDescription([ + 'The domainset supports AD blocking, tracking protection, privacy protection, anti-phishing, anti-mining' + ]); + rejectOutputAdGuardHome.domainTrie = rejectOutput.domainTrie; + await rejectOutputAdGuardHome.addFromRuleset(readLocalMyRejectRulesetPromise).addFromRuleset(readLocalRejectRulesetPromise).addFromRuleset(readLocalRejectDropRulesetPromise).addFromRuleset(readLocalRejectNoDropRulesetPromise).write(); + }); + } (buildRejectDomainset.__module, buildRejectDomainset.__module.exports)); + return buildRejectDomainset.__module.exports; +}exports.__require=requireBuildRejectDomainset; \ No newline at end of file diff --git a/Dist/Build/build-reject-ip-list.cjs b/Dist/Build/build-reject-ip-list.cjs new file mode 100644 index 00000000..c29aabd5 --- /dev/null +++ b/Dist/Build/build-reject-ip-list.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildRejectIpList$1=require('./build-reject-ip-list2.cjs');var buildRejectIpListExports = buildRejectIpList$1.__require(); +const buildRejectIpList = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildRejectIpListExports);module.exports=buildRejectIpList; \ No newline at end of file diff --git a/Dist/Build/build-reject-ip-list2.cjs b/Dist/Build/build-reject-ip-list2.cjs new file mode 100644 index 00000000..6b4eaf41 --- /dev/null +++ b/Dist/Build/build-reject-ip-list2.cjs @@ -0,0 +1,96 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildRejectIpList=require('../_virtual/build-reject-ip-list.cjs'),require$$0=require('node:path'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),createFile=require('./lib/create-file.cjs'),dir=require('./constants/dir.cjs'),fetchRetry=require('./lib/fetch-retry.cjs'),fetchAssets=require('./lib/fetch-assets.cjs'),misc=require('./lib/misc.cjs'),badboy_asn=require('../Source/ip/badboy_asn.cjs'),ruleset=require('./lib/rules/ruleset.cjs');var hasRequiredBuildRejectIpList; + +function requireBuildRejectIpList () { + if (hasRequiredBuildRejectIpList) return buildRejectIpList.__module.exports; + hasRequiredBuildRejectIpList = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildRejectIPList", { + enumerable: true, + get: function() { + return buildRejectIPList; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _trace = /*@__PURE__*/ index.__require(); + const _description = /*@__PURE__*/ description.__require(); + const _createfile = /*@__PURE__*/ createFile.__require(); + const _dir = /*@__PURE__*/ dir.__require(); + const _fetchretry = /*@__PURE__*/ fetchRetry.__require(); + const _fetchassets = /*@__PURE__*/ fetchAssets.__require(); + const _misc = /*@__PURE__*/ misc.__require(); + const _badboy_asn = /*@__PURE__*/ badboy_asn.__require(); + const _ruleset = /*@__PURE__*/ ruleset.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const BOGUS_NXDOMAIN_URL = 'https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/bogus-nxdomain.china.conf'; + const getBogusNxDomainIPsPromise = (0, _fetchretry.$$fetch)(BOGUS_NXDOMAIN_URL).then(async (resp)=>{ + const ipv4 = []; + const ipv6 = []; + for await (const line of (0, _fetchtextbyline.createReadlineInterfaceFromResponse)(resp, true)){ + if (line.startsWith('bogus-nxdomain=')) { + const ip = line.slice(15).trim(); + const v = (0, _misc.fastIpVersion)(ip); + if (v === 4) { + ipv4.push(ip); + } else if (v === 6) { + ipv6.push(ip); + } + } + } + return [ + ipv4, + ipv6 + ]; + }); + const BOTNET_FILTER_URL = 'https://malware-filter.pages.dev/botnet-filter-dnscrypt-blocked-ips.txt'; + const BOTNET_FILTER_MIRROR_URL = [ + 'https://botnet-filter.pages.dev/botnet-filter-dnscrypt-blocked-ips.txt', + 'https://malware-filter.gitlab.io/malware-filter/botnet-filter-dnscrypt-blocked-ips.txt', + 'https://malware-filter.gitlab.io/botnet-filter/botnet-filter-dnscrypt-blocked-ips.txt' + ]; + const getBotNetFilterIPsPromise = (0, _fetchassets.fetchAssets)(BOTNET_FILTER_URL, BOTNET_FILTER_MIRROR_URL, true).then((arr)=>arr.reduce((acc, ip)=>{ + const v = (0, _misc.fastIpVersion)(ip); + if (v === 4) { + acc[0].push(ip); + } else if (v === 6) { + acc[1].push(ip); + } + return acc; + }, [ + [], + [] + ])); + const readLocalRejectIpListPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.resolve(_dir.SOURCE_DIR, 'ip/reject.conf')); + const buildRejectIPList = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const [bogusNxDomainIPs, botNetIPs] = await Promise.all([ + span.traceChildPromise('get bogus nxdomain ips', getBogusNxDomainIPsPromise), + span.traceChildPromise('get botnet ips', getBotNetFilterIPsPromise) + ]); + return Promise.all([ + new _ruleset.RulesetOutput(span, 'reject', 'ip').withTitle('Sukka\'s Ruleset - Anti Bogus Domain').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains known addresses that are hijacking NXDOMAIN results returned by DNS servers, and botnet controller IPs.', + '', + 'Data from:', + ' - https://github.com/felixonmars/dnsmasq-china-list', + ' - https://github.com/curbengh/botnet-filter' + ]).addFromRuleset(readLocalRejectIpListPromise).bulkAddCIDR4NoResolve(bogusNxDomainIPs[0]).bulkAddCIDR6NoResolve(bogusNxDomainIPs[1]).bulkAddCIDR4NoResolve(botNetIPs[0]).bulkAddCIDR6NoResolve(botNetIPs[1]).bulkAddIPASN(_badboy_asn.AUGUST_ASN).bulkAddIPASN(_badboy_asn.HUIZE_ASN).write(), + (0, _createfile.compareAndWriteFile)(span, [ + _badboy_asn.AUGUST_ASN.join(' ') + ], _nodepath.default.join(_dir.OUTPUT_INTERNAL_DIR, 'august_asn.txt')), + (0, _createfile.compareAndWriteFile)(span, [ + _badboy_asn.HUIZE_ASN.join(' ') + ], _nodepath.default.join(_dir.OUTPUT_INTERNAL_DIR, 'huize_asn.txt')) + ]); + }); + } (buildRejectIpList.__module, buildRejectIpList.__module.exports)); + return buildRejectIpList.__module.exports; +}exports.__require=requireBuildRejectIpList; \ No newline at end of file diff --git a/Dist/Build/build-sgmodule-always-realip.cjs b/Dist/Build/build-sgmodule-always-realip.cjs new file mode 100644 index 00000000..467efa20 --- /dev/null +++ b/Dist/Build/build-sgmodule-always-realip.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildSgmoduleAlwaysRealip$1=require('./build-sgmodule-always-realip2.cjs');var buildSgmoduleAlwaysRealipExports = buildSgmoduleAlwaysRealip$1.__require(); +const buildSgmoduleAlwaysRealip = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildSgmoduleAlwaysRealipExports);module.exports=buildSgmoduleAlwaysRealip; \ No newline at end of file diff --git a/Dist/Build/build-sgmodule-always-realip2.cjs b/Dist/Build/build-sgmodule-always-realip2.cjs new file mode 100644 index 00000000..19731364 --- /dev/null +++ b/Dist/Build/build-sgmodule-always-realip2.cjs @@ -0,0 +1,136 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildSgmoduleAlwaysRealip=require('../_virtual/build-sgmodule-always-realip.cjs'),require$$0=require('node:path'),index=require('./trace/index.cjs'),createFile=require('./lib/create-file.cjs'),direct=require('../Source/non_ip/direct.cjs'),domestic=require('../Source/non_ip/domestic.cjs'),require$$8=require('yaml'),dir=require('./constants/dir.cjs'),appendArrayInPlace=require('./lib/append-array-in-place.cjs'),description=require('./constants/description.cjs'),buildDomesticDirectLanRulesetDnsMappingModule=require('./build-domestic-direct-lan-ruleset-dns-mapping-module2.cjs'),clash=require('./lib/writing-strategy/clash.cjs'),base=require('./lib/rules/base.cjs');var hasRequiredBuildSgmoduleAlwaysRealip; + +function requireBuildSgmoduleAlwaysRealip () { + if (hasRequiredBuildSgmoduleAlwaysRealip) return buildSgmoduleAlwaysRealip.__module.exports; + hasRequiredBuildSgmoduleAlwaysRealip = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildAlwaysRealIPModule", { + enumerable: true, + get: function() { + return buildAlwaysRealIPModule; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _trace = /*@__PURE__*/ index.__require(); + const _createfile = /*@__PURE__*/ createFile.__require(); + const _direct = /*@__PURE__*/ direct.__require(); + const _domestic = /*@__PURE__*/ domestic.__require(); + const _yaml = /*#__PURE__*/ _interop_require_wildcard(require$$8); + const _dir = /*@__PURE__*/ dir.__require(); + const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require(); + const _description = /*@__PURE__*/ description.__require(); + const _builddomesticdirectlanrulesetdnsmappingmodule = buildDomesticDirectLanRulesetDnsMappingModule.__require(); + const _clash = /*@__PURE__*/ clash.__require(); + const _base = /*@__PURE__*/ base.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); + } + function _interop_require_wildcard(obj, nodeInterop) { + if (obj && obj.__esModule) { + return obj; + } + if (obj === null || typeof obj !== "object" && typeof obj !== "function") { + return { + default: obj + }; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = { + __proto__: null + }; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; + } + const HOSTNAMES = [ + // Network Detection, Captive Portal + 'dns.msftncsi.com', + // '*.msftconnecttest.com', + // 'network-test.debian.org', + // 'detectportal.firefox.com', + // Handle SNAT conversation properly + '*.srv.nintendo.net', + '*.stun.playstation.net', + 'xbox.*.microsoft.com', + '*.xboxlive.com', + '*.turn.twilio.com', + '*.stun.twilio.com', + 'stun.syncthing.net', + 'stun.*' + ]; + const buildAlwaysRealIPModule = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const surge = []; + const clashFakeIpFilter = new _base.FileOutput(span, 'clash_fake_ip_filter').withTitle('Sukka\'s Ruleset - Always Real IP Plus').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'Clash.Meta fake-ip-filter as ruleset' + ]).withStrategies([ + new _clash.ClashDomainSet('domainset') + ]); + // Intranet, Router Setup, and mant more + const dataset = [ + _direct.DIRECTS, + _direct.LAN, + _domestic.DOMESTICS, + _domestic.DOH_BOOTSTRAP + ].reduce((acc, item)=>{ + Object.values(item).forEach((i)=>{ + if (i.realip) { + acc.push(i); + } + }); + return acc; + }, []); + const getDnsMappingRuleWithoutWildcard = (0, _builddomesticdirectlanrulesetdnsmappingmodule.createGetDnsMappingRule)(false); + for (const { domains } of dataset){ + clashFakeIpFilter.addFromRuleset(domains.flatMap(getDnsMappingRuleWithoutWildcard)); + } + return Promise.all([ + (0, _createfile.compareAndWriteFile)(span, [ + '#!name=[Sukka] Always Real IP Plus', + `#!desc=Last Updated: ${new Date().toISOString()}`, + '', + '[General]', + `always-real-ip = %APPEND% ${HOSTNAMES.concat(surge).join(', ')}` + ], _nodepath.default.resolve(_dir.OUTPUT_MODULES_DIR, 'sukka_common_always_realip.sgmodule')), + (0, _createfile.compareAndWriteFile)(span, _yaml.stringify({ + dns: { + 'fake-ip-filter': (0, _appendarrayinplace.appendArrayInPlace)(/** clash */ dataset.flatMap(({ domains })=>domains.map((domain)=>`+.${domain}`)), HOSTNAMES) + } + }, { + version: '1.1' + }).split('\n'), _nodepath.default.join(_dir.OUTPUT_INTERNAL_DIR, 'clash_fake_ip_filter.yaml')) + ]); + }); + } (buildSgmoduleAlwaysRealip.__module, buildSgmoduleAlwaysRealip.__module.exports)); + return buildSgmoduleAlwaysRealip.__module.exports; +}exports.__require=requireBuildSgmoduleAlwaysRealip; \ No newline at end of file diff --git a/Dist/Build/build-sgmodule-redirect.cjs b/Dist/Build/build-sgmodule-redirect.cjs new file mode 100644 index 00000000..cc9520f2 --- /dev/null +++ b/Dist/Build/build-sgmodule-redirect.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildSgmoduleRedirect$1=require('./build-sgmodule-redirect2.cjs');var buildSgmoduleRedirectExports = buildSgmoduleRedirect$1.__require(); +const buildSgmoduleRedirect = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildSgmoduleRedirectExports);module.exports=buildSgmoduleRedirect; \ No newline at end of file diff --git a/Dist/Build/build-sgmodule-redirect2.cjs b/Dist/Build/build-sgmodule-redirect2.cjs new file mode 100644 index 00000000..cc38e5de --- /dev/null +++ b/Dist/Build/build-sgmodule-redirect2.cjs @@ -0,0 +1,508 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildSgmoduleRedirect=require('../_virtual/build-sgmodule-redirect.cjs'),require$$0=require('node:path'),index=require('./trace/index.cjs'),createFile=require('./lib/create-file.cjs'),require$$5=require('tldts-experimental'),require$$6=require('foxts/guard'),dir=require('./constants/dir.cjs');var hasRequiredBuildSgmoduleRedirect; + +function requireBuildSgmoduleRedirect () { + if (hasRequiredBuildSgmoduleRedirect) return buildSgmoduleRedirect.__module.exports; + hasRequiredBuildSgmoduleRedirect = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildRedirectModule", { + enumerable: true, + get: function() { + return buildRedirectModule; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _trace = /*@__PURE__*/ index.__require(); + const _createfile = /*@__PURE__*/ createFile.__require(); + const _tldtsexperimental = require$$5; + const _guard = require$$6; + const _dir = /*@__PURE__*/ dir.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function escapeRegExp(string = '') { + const reRegExpChar = /[$()*+.?[\\\]^{|}]/g; + const reHasRegExpChar = new RegExp(reRegExpChar.source); + return string && reHasRegExpChar.test(string) ? string.replaceAll(reRegExpChar, String.raw`\$&`) : string; + } + const REDIRECT_MIRROR_HEADER = [ + // Gravatar + [ + 'gravatar.neworld.org/', + 'https://secure.gravatar.com/' + ], + [ + 'cdn.v2ex.com/gravatar/', + 'https://secure.gravatar.com/avatar/' + ], + // U.SB + [ + 'cdnjs.loli.net/', + 'https://cdnjs.cloudflare.com/' + ], + [ + 'fonts.loli.net/', + 'https://fonts.googleapis.com/' + ], + [ + 'gstatic.loli.net/', + 'https://fonts.gstatic.com/' + ], + [ + 'themes.loli.net/', + 'https://themes.googleusercontent.com/' + ], + [ + 'ajax.loli.net/', + 'https://ajax.googleapis.com/' + ], + [ + 'gravatar.loli.net/', + 'https://secure.gravatar.com/' + ], + // Geekzu + [ + 'gapis.geekzu.org/ajax/', + 'https://ajax.googleapis.com/' + ], + [ + 'fonts.geekzu.org/', + 'https://fonts.googleapis.com/' + ], + [ + 'gapis.geekzu.org/g-fonts/', + 'https://fonts.gstatic.com/' + ], + [ + 'gapis.geekzu.org/g-themes/', + 'https://themes.googleusercontent.com/' + ], + [ + 'sdn.geekzu.org/', + 'https://secure.gravatar.com/' + ], + // libravatar + [ + 'seccdn.libravatar.org/gravatarproxy/', + 'https://secure.gravatar.com/' + ], + // gh-proxy + [ + 'github.moeyy.xyz/', + 'https://' + ], + // 7ED Services + [ + 'use.sevencdn.com/css', + 'https://fonts.googleapis.com/css' + ], + [ + 'use.sevencdn.com/ajax/libs/', + 'https://cdnjs.cloudflare.com/ajax/libs/' + ], + [ + 'use.sevencdn.com/gajax/', + 'https://ajax.googleapis.com/ajax/' + ], + [ + 'use.sevencdn.com/chart', + 'https://chart.googleapis.com/chart' + ], + [ + 'use.sevencdn.com/avatar', + 'https://secure.gravatar.com/avatar' + ], + [ + 'raw.gitmirror.com/', + 'https://raw.githubusercontent.com/' + ], + [ + 'gist.gitmirror.com/', + 'https://gist.githubusercontent.com/' + ], + [ + 'raw.githubusercontents.com/', + 'https://raw.githubusercontent.com/' + ], + [ + 'gist.githubusercontents.com/', + 'https://gist.githubusercontent.com/' + ], + [ + 'cdn.gitmirror.com/', + 'https://cdn.statically.io/' + ], + // FastGit + [ + 'raw.fastgit.org/', + 'https://raw.githubusercontent.com/' + ], + // ['assets.fastgit.org/', 'https://github.githubassets.com/'], + // jsDelivr + [ + 'fastly.jsdelivr.net/', + 'https://cdn.jsdelivr.net/' + ], + [ + 'gcore.jsdelivr.net/', + 'https://cdn.jsdelivr.net/' + ], + [ + 'testingcf.jsdelivr.net/', + 'https://cdn.jsdelivr.net/' + ], + // JSDMirror + [ + 'cdn.jsdmirror.com/', + 'https://cdn.jsdelivr.net/' + ], + [ + 'cdn.jsdmirror.cn/', + 'https://cdn.jsdelivr.net/' + ], + // onmicrosoft.cn + [ + 'jsd.onmicrosoft.cn/', + 'https://cdn.jsdelivr.net/' + ], + [ + 'npm.onmicrosoft.cn/', + 'https://unpkg.com/' + ], + [ + 'cdnjs.onmicrosoft.cn/', + 'https://cdnjs.cloudflare.com/ajax/libs/' + ], + // KGitHub + [ + 'raw.kgithub.com/', + 'https://raw.githubusercontent.com/' + ], + [ + 'raw.kkgithub.com/', + 'https://raw.githubusercontent.com/' + ], + // cdn.iocdn.cc + [ + 'cdn.iocdn.cc/avatar/', + 'https://secure.gravatar.com/avatar/' + ], + [ + 'cdn.iocdn.cc/css', + 'https://fonts.googleapis.com/css' + ], + [ + 'cdn.iocdn.cc/icon', + 'https://fonts.googleapis.com/icon' + ], + [ + 'cdn.iocdn.cc/earlyaccess', + 'https://fonts.googleapis.com/earlyaccess' + ], + [ + 'cdn.iocdn.cc/s', + 'fonts.gstatic.com/s' + ], + [ + 'cdn.iocdn.cc/static', + 'themes.googleusercontent.com/static' + ], + [ + 'cdn.iocdn.cc/ajax', + 'ajax.googleapis.com/ajax' + ], + [ + 'cdn.iocdn.cc/', + 'https://cdn.jsdelivr.net/' + ], + // wp-china-yes + [ + 'googlefonts.admincdn.com/', + 'https://fonts.googleapis.com/' + ], + [ + 'googleajax.admincdn.com/', + 'https://ajax.googleapis.com/' + ], + [ + 'cdnjs.admincdn.com/', + 'https://cdnjs.cloudflare.com/ajax/libs/' + ], + // Polyfill + [ + 'polyfill.io/', + 'https://cdnjs.cloudflare.com/polyfill/' + ], + [ + 'polyfill.top/', + 'https://cdnjs.cloudflare.com/polyfill/' + ], + [ + 'polyfill-js.cn/', + 'https://cdnjs.cloudflare.com/polyfill/' + ], + [ + 'cdn.polyfill.io/', + 'https://cdnjs.cloudflare.com/polyfill/' + ], + [ + 'fastly-polyfill.io/', + 'https://cdnjs.cloudflare.com/polyfill/' + ], + [ + 'fastly-polyfill.net/', + 'https://cdnjs.cloudflare.com/polyfill/' + ], + // BootCDN has been controlled by a malicious actor and being used to spread malware + [ + 'cdn.bootcss.com/', + 'https://cdnjs.cloudflare.com/ajax/libs/' + ], + [ + 'cdn.bootcdn.net/', + 'https://cdnjs.cloudflare.com/ajax/libs/' + ], + [ + 'cdn.staticfile.net/', + 'https://cdnjs.cloudflare.com/ajax/libs/' + ], + [ + 'cdn.staticfile.org/', + 'https://cdnjs.cloudflare.com/ajax/libs/' + ], + // Misc + [ + 'pics.javbus.com/', + 'https://i0.wp.com/pics.javbus.com/' + ] + ]; + const REDIRECT_MIRROR_307 = [ + // Redirect Google + [ + 'google.cn/', + 'https://google.com/' + ], + [ + 'www.google.cn/', + 'https://www.google.com/' + ], + [ + 'g.cn/', + 'https://google.com/' + ], + [ + 'ditu.google.cn/', + 'https://maps.google.com/' + ], + [ + 'maps.google.cn/', + 'https://maps.google.com/' + ], + [ + 'www.g.cn/', + 'https://www.google.com/' + ], + // avg.tv/sm114514 -> https://www.nicovideo.jp/watch/sm114514 + [ + 'acg.tv/sm', + 'https://www.nicovideo.jp/watch/sm' + ], + [ + 'acg.tv/', + 'https://b23.tv/' + ], + // Minecraft Wiki + [ + 'minecraft.fandom.com/wiki/', + 'https://minecraft.wiki/w/' + ], + [ + 'minecraft.fandom.com/', + 'https://minecraft.wiki/' + ], + [ + 'missav.com/', + 'https://missav.ws/' + ] + ]; + const REDIRECT_FAKEWEBSITES = [ + // IGN China to IGN Global + [ + 'ign.xn--fiqs8s', + 'https://cn.ign.com/ccpref/us' + ], + // Fuck Makeding + [ + 'abbyychina.com', + 'https://www.abbyy.cn' + ], + [ + 'bartender.cc', + 'https://cn.seagullscientific.com' + ], + [ + 'betterzip.net', + 'https://macitbetter.com' + ], + [ + 'beyondcompare.cc', + 'https://www.scootersoftware.com' + ], + [ + 'bingdianhuanyuan.cn', + 'https://www.faronics.com' + ], + [ + 'chemdraw.com.cn', + 'https://revvitysignals.com/products/research/chemdraw' + ], + [ + 'codesoftchina.com', + 'https://www.teklynx.com' + ], + [ + 'coreldrawchina.com', + 'https://www.coreldraw.com' + ], + [ + 'crossoverchina.com', + 'https://www.codeweavers.com' + ], + [ + 'easyrecoverychina.com', + 'https://www.ontrack.com' + ], + [ + 'ediuschina.com', + 'https://www.grassvalley.com' + ], + [ + 'flstudiochina.com', + 'https://www.image-line.com/fl-studio' + ], + [ + 'formysql.com', + 'https://www.navicat.com.cn' + ], + [ + 'guitarpro.cc', + 'https://www.guitar-pro.com' + ], + [ + 'huishenghuiying.com.cn', + 'https://www.corel.com' + ], + [ + 'iconworkshop.cn', + 'https://www.axialis.com/iconworkshop' + ], + [ + 'imindmap.cc', + 'https://imindmap.com/zh-cn' + ], + [ + 'jihehuaban.com.cn', + 'https://sketch.io' + ], + [ + 'keyshot.cc', + 'https://www.keyshot.com' + ], + [ + 'mathtype.cn', + 'https://www.wiris.com/en/mathtype' + ], + [ + 'mindmanager.cc', + 'https://www.mindjet.com' + ], + [ + 'mindmapper.cc', + 'https://mindmapper.com' + ], + [ + 'mycleanmymac.com', + 'https://macpaw.com/cleanmymac' + ], + [ + 'nicelabel.cc', + 'https://www.nicelabel.com' + ], + [ + 'ntfsformac.cc', + 'https://www.tuxera.com/products/tuxera-ntfs-for-mac-cn' + ], + [ + 'ntfsformac.cn', + 'https://www.paragon-software.com/ufsdhome/zh/ntfs-mac' + ], + [ + 'overturechina.com', + 'https://sonicscores.com/overture' + ], + [ + 'passwordrecovery.cn', + 'https://cn.elcomsoft.com/aopr.html' + ], + [ + 'pdfexpert.cc', + 'https://pdfexpert.com/zh' + ], + [ + 'ultraiso.net', + 'https://cn.ezbsystems.com/ultraiso' + ], + [ + 'vegaschina.cn', + 'https://www.vegas.com' + ], + [ + 'xmindchina.net', + 'https://www.xmind.cn' + ], + [ + 'xshellcn.com', + 'https://www.netsarang.com/products/xsh_overview.html' + ], + [ + 'yuanchengxiezuo.com', + 'https://www.teamviewer.com/zhcn' + ], + [ + 'zbrushcn.com', + 'https://www.maxon.net/en/zbrush' + ] + ]; + const buildRedirectModule = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const domains = Array.from(new Set([ + ...REDIRECT_MIRROR_HEADER.map(([from])=>(0, _tldtsexperimental.getHostname)(from, { + detectIp: false + })), + ...REDIRECT_FAKEWEBSITES.flatMap(([from])=>[ + from, + `*.${from}` + ]), + ...REDIRECT_MIRROR_307.map(([from])=>(0, _tldtsexperimental.getHostname)(from, { + detectIp: false + })) + ])).filter(_guard.isTruthy); + return (0, _createfile.compareAndWriteFile)(span, [ + '#!name=[Sukka] URL Redirect', + `#!desc=Last Updated: ${new Date().toISOString()} Size: ${domains.length}`, + '', + '[MITM]', + `hostname = %APPEND% ${domains.join(', ')}`, + '', + '[URL Rewrite]', + ...REDIRECT_MIRROR_HEADER.map(([from, to])=>`^https?://${escapeRegExp(from)}(.*) ${to}$1 header`), + ...REDIRECT_FAKEWEBSITES.map(([from, to])=>`^https?://(www.)?${escapeRegExp(from)} ${to} 307`), + ...REDIRECT_MIRROR_307.map(([from, to])=>`^https?://${escapeRegExp(from)}(.*) ${to}$1 307`) + ], _nodepath.default.join(_dir.OUTPUT_MODULES_DIR, 'sukka_url_redirect.sgmodule')); + }); + } (buildSgmoduleRedirect.__module, buildSgmoduleRedirect.__module.exports)); + return buildSgmoduleRedirect.__module.exports; +}exports.__require=requireBuildSgmoduleRedirect; \ No newline at end of file diff --git a/Dist/Build/build-speedtest-domainset.cjs b/Dist/Build/build-speedtest-domainset.cjs new file mode 100644 index 00000000..a95a440b --- /dev/null +++ b/Dist/Build/build-speedtest-domainset.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildSpeedtestDomainset$1=require('./build-speedtest-domainset2.cjs');var buildSpeedtestDomainsetExports = buildSpeedtestDomainset$1.__require(); +const buildSpeedtestDomainset = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildSpeedtestDomainsetExports);module.exports=buildSpeedtestDomainset; \ No newline at end of file diff --git a/Dist/Build/build-speedtest-domainset2.cjs b/Dist/Build/build-speedtest-domainset2.cjs new file mode 100644 index 00000000..15b8bd3f --- /dev/null +++ b/Dist/Build/build-speedtest-domainset2.cjs @@ -0,0 +1,113 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildSpeedtestDomainset=require('../_virtual/build-speedtest-domainset.cjs'),require$$0=require('node:path'),require$$5=require('tldts-experimental'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),domainset=require('./lib/rules/domainset.cjs'),dir=require('./constants/dir.cjs'),require$$7=require('@henrygd/queue'),fetchRetry=require('./lib/fetch-retry.cjs');var hasRequiredBuildSpeedtestDomainset; + +function requireBuildSpeedtestDomainset () { + if (hasRequiredBuildSpeedtestDomainset) return buildSpeedtestDomainset.__module.exports; + hasRequiredBuildSpeedtestDomainset = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildSpeedtestDomainSet", { + enumerable: true, + get: function() { + return buildSpeedtestDomainSet; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _tldtsexperimental = /*#__PURE__*/ _interop_require_default(require$$5); + const _trace = /*@__PURE__*/ index.__require(); + const _description = /*@__PURE__*/ description.__require(); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _domainset = /*@__PURE__*/ domainset.__require(); + const _dir = /*@__PURE__*/ dir.__require(); + const _queue = require$$7; + const _fetchretry = /*@__PURE__*/ fetchRetry.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const KEYWORDS = [ + 'Hong Kong', + 'Taiwan', + 'China Telecom', + 'China Mobile', + 'China Unicom', + 'Japan', + 'Tokyo', + 'Singapore', + 'Korea', + 'Seoul', + 'Canada', + 'Toronto', + 'Montreal', + 'Los Ang', + 'San Jos', + 'Seattle', + 'New York', + 'Dallas', + 'Miami', + 'Berlin', + 'Frankfurt', + 'London', + 'Paris', + 'Amsterdam', + 'Moscow', + 'Australia', + 'Sydney', + 'Brazil', + 'Turkey' + ]; + const s = (0, _queue.newQueue)(2); + const latestTopUserAgentsPromise = (0, _fetchretry.$$fetch)('https://raw.githubusercontent.com/microlinkhq/top-user-agents/master/src/desktop.json').then((res)=>res.json()).then((userAgents)=>userAgents.filter((ua)=>ua.startsWith('Mozilla/5.0 '))); + const getSpeedtestHostsGroupsPromise = Promise.all(KEYWORDS.flatMap(querySpeedtestApi)); + const buildSpeedtestDomainSet = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const output = new _domainset.DomainsetOutput(span, 'speedtest').withTitle('Sukka\'s Ruleset - Speedtest Domains').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains common speedtest endpoints.' + ]).addFromDomainset((0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.resolve(_dir.SOURCE_DIR, 'domainset/speedtest.conf'))).addFromDomainset((0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, 'domainset/speedtest.conf'))); + const hostnameGroup = await span.traceChildPromise('get speedtest hosts groups', getSpeedtestHostsGroupsPromise); + hostnameGroup.forEach(output.bulkAddDomain.bind(output)); + return output.write(); + }); + async function querySpeedtestApi(keyword) { + const topUserAgents = await latestTopUserAgentsPromise; + const url = `https://www.speedtest.net/api/js/servers?engine=js&search=${keyword}&limit=100`; + try { + const randomUserAgent = topUserAgents[Math.floor(Math.random() * topUserAgents.length)]; + const data = await s.add(()=>(0, _fetchretry.$$fetch)(url, { + headers: { + dnt: '1', + Referer: 'https://www.speedtest.net/', + accept: 'application/json, text/plain, */*', + 'User-Agent': randomUserAgent, + 'Accept-Language': 'en-US,en;q=0.9', + ...randomUserAgent.includes('Chrome') ? { + 'Sec-Ch-Ua-Mobile': '?0', + 'Sec-Fetch-Dest': 'empty', + 'Sec-Fetch-Mode': 'cors', + 'Sec-Fetch-Site': 'same-origin', + 'Sec-Gpc': '1' + } : {} + }, + signal: AbortSignal.timeout(1000 * 60) + }).then((res)=>res.json())); + return data.reduce((prev, cur)=>{ + const hn = _tldtsexperimental.default.getHostname(cur.host || cur.url, { + detectIp: false, + validateHostname: true + }); + if (hn) { + prev.push(hn); + } + return prev; + }, []); + } catch (e) { + console.error(e); + return []; + } + } + } (buildSpeedtestDomainset.__module, buildSpeedtestDomainset.__module.exports)); + return buildSpeedtestDomainset.__module.exports; +}exports.__require=requireBuildSpeedtestDomainset; \ No newline at end of file diff --git a/Dist/Build/build-sspanel-appprofile.cjs b/Dist/Build/build-sspanel-appprofile.cjs new file mode 100644 index 00000000..e6afa791 --- /dev/null +++ b/Dist/Build/build-sspanel-appprofile.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildSspanelAppprofile$1=require('./build-sspanel-appprofile2.cjs');var buildSspanelAppprofileExports = buildSspanelAppprofile$1.__require(); +const buildSspanelAppprofile = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildSspanelAppprofileExports);module.exports=buildSspanelAppprofile; \ No newline at end of file diff --git a/Dist/Build/build-sspanel-appprofile2.cjs b/Dist/Build/build-sspanel-appprofile2.cjs new file mode 100644 index 00000000..44011f40 --- /dev/null +++ b/Dist/Build/build-sspanel-appprofile2.cjs @@ -0,0 +1,217 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildSspanelAppprofile=require('../_virtual/build-sspanel-appprofile.cjs'),buildAppleCdn=require('./build-apple-cdn2.cjs'),buildDomesticDirectLanRulesetDnsMappingModule=require('./build-domestic-direct-lan-ruleset-dns-mapping-module2.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),index=require('./trace/index.cjs'),require$$0=require('node:path'),stream=require('../Source/stream.cjs'),buildChnCidr=require('./build-chn-cidr2.cjs'),buildTelegramCidr=require('./build-telegram-cidr2.cjs'),createFile=require('./lib/create-file.cjs'),buildMicrosoftCdn=require('./build-microsoft-cdn2.cjs'),require$$6=require('foxts/guard'),appendArrayInPlace=require('./lib/append-array-in-place.cjs'),dir=require('./constants/dir.cjs'),ruleset=require('./lib/rules/ruleset.cjs');var hasRequiredBuildSspanelAppprofile; + +function requireBuildSspanelAppprofile () { + if (hasRequiredBuildSspanelAppprofile) return buildSspanelAppprofile.__module.exports; + hasRequiredBuildSspanelAppprofile = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildSSPanelUIMAppProfile", { + enumerable: true, + get: function() { + return buildSSPanelUIMAppProfile; + } + }); + const _buildapplecdn = buildAppleCdn.__require(); + const _builddomesticdirectlanrulesetdnsmappingmodule = buildDomesticDirectLanRulesetDnsMappingModule.__require(); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _trace = /*@__PURE__*/ index.__require(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _stream = /*@__PURE__*/ stream.__require(); + const _buildchncidr = buildChnCidr.__require(); + const _buildtelegramcidr = buildTelegramCidr.__require(); + const _createfile = /*@__PURE__*/ createFile.__require(); + const _buildmicrosoftcdn = buildMicrosoftCdn.__require(); + const _guard = require$$6; + const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require(); + const _dir = /*@__PURE__*/ dir.__require(); + const _ruleset = /*@__PURE__*/ ruleset.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const POLICY_GROUPS = [ + [ + 'Default Proxy', + true, + false + ], + [ + 'Global', + true, + true + ], + [ + 'Microsoft & Apple', + true, + true + ], + [ + 'Stream', + true, + false + ], + [ + 'Steam Download', + true, + true + ], + [ + 'Domestic', + false, + true + ], + [ + 'Final Match', + true, + true + ] + ]; + const steamDomainsPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/game-download.conf')); + const buildSSPanelUIMAppProfile = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const [[domesticRules, directRules, lanRules], appleCdnDomains, [microsoftCdnDomains, microsoftCdnDomainSuffixes], appleCnRules, neteaseMusicRules, microsoftRules, appleRules, streamRules, steamDomainset, globalRules, telegramRules, [domesticCidrs4, domesticCidrs6], [streamCidrs4, streamCidrs6], { ipcidr: telegramCidrs4, ipcidr6: telegramCidrs6 }, rawLanCidrs] = await Promise.all([ + // domestic - domains + (0, _builddomesticdirectlanrulesetdnsmappingmodule.getDomesticAndDirectDomainsRulesetPromise)(), + (0, _buildapplecdn.getAppleCdnDomainsPromise)(), + (0, _buildmicrosoftcdn.getMicrosoftCdnRulesetPromise)(), + (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/apple_cn.conf')), + (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/neteasemusic.conf')), + // microsoft & apple - domains + (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/microsoft.conf')), + (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/apple_services.conf')), + // stream - domains + _stream.ALL.flatMap((i)=>i.rules), + // steam - domains + steamDomainsPromise, + // global - domains + (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/global.conf')), + (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/telegram.conf')), + // domestic - ip cidr + (0, _buildchncidr.getChnCidrPromise)(), + _stream.ALL.reduce((acc, i)=>{ + if (i.ip) { + (0, _appendarrayinplace.appendArrayInPlace)(acc[0], i.ip.v4); + (0, _appendarrayinplace.appendArrayInPlace)(acc[1], i.ip.v6); + } + return acc; + }, [ + [], + [] + ]), + // global - ip cidr + (0, _buildtelegramcidr.getTelegramCIDRPromise)(), + // lan - ip cidr + (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'ip/lan.conf')) + ]); + const domestic = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromRuleset(domesticRules).bulkAddDomainSuffix(appleCdnDomains).bulkAddDomain(microsoftCdnDomains).bulkAddDomainSuffix(microsoftCdnDomainSuffixes).addFromRuleset(appleCnRules).addFromRuleset(neteaseMusicRules); + const microsoftApple = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromRuleset(microsoftRules).addFromRuleset(appleRules); + const stream = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromRuleset(streamRules); + const steam = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromDomainset(steamDomainset); + const global = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromRuleset(globalRules).addFromRuleset(telegramRules); + const direct = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromRuleset(directRules).addFromRuleset(lanRules); + const domesticCidr = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'ip').bulkAddCIDR4(domesticCidrs4).bulkAddCIDR6(domesticCidrs6); + const streamCidr = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'ip').bulkAddCIDR4(streamCidrs4).bulkAddCIDR6(streamCidrs6); + const telegramCidr = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'ip').bulkAddCIDR4(telegramCidrs4).bulkAddCIDR6(telegramCidrs6); + const lanCidrs = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'ip').addFromRuleset(rawLanCidrs); + const output = generateAppProfile(...(await Promise.all([ + domestic.compile(), + microsoftApple.compile(), + stream.compile(), + steam.compile(), + global.compile(), + direct.compile(), + domesticCidr.compile(), + streamCidr.compile(), + telegramCidr.compile(), + lanCidrs.compile() + ])).map((output)=>(0, _guard.nullthrow)(output[0]))); + await (0, _createfile.compareAndWriteFile)(span, output, _nodepath.default.resolve(_dir.OUTPUT_INTERNAL_DIR, 'appprofile.php')); + }); + function generateAppProfile(directDomains, microsoftAppleDomains, streamDomains, steamDomains, globalDomains, lanDomains, directCidrs, streamCidrs, globalCidrs, lanCidrs) { + const redults = [ + ' 7890,', + ' \'socks-port\' => 7891,', + ' \'allow-lan\' => false,', + ' \'mode\' => \'Rule\',', + ' \'ipv6\' => true,', + ' \'log-level\' => \'error\',', + ' \'external-controller\' => \'0.0.0.0:9090\',', + ' \'tun\' => [', + ' \'enable\' => true,', + ' \'stack\' => \'system\',', + ' \'auto-route\' => true,', + ' \'auto-redir\' => true,', + ' \'auto-detect-interface\' => true,', + ' \'dns-hijack\' => [', + ' \'8.8.8.8:53\',', + ' \'any:53\',', + ' \'tcp://8.8.8.8:53\',', + ' \'tcp://any:53\',', + ' ]', + ' ]', + '];', + '', + `$_ENV['Clash_Group_Indexes'] = [${JSON.stringify(POLICY_GROUPS.reduce((acc, [, insertProxy], index)=>{ + if (insertProxy) { + acc.push(index); + } + return acc; + }, [])).slice(1, -1)}];`, + '$_ENV[\'Clash_Group_Config\'] = [', + ' \'proxy-groups\' => [' + ]; + (0, _appendarrayinplace.appendArrayInPlace)(redults, POLICY_GROUPS.flatMap(([name, insertProxy, insertDirect])=>[ + ' [', + ` 'name' => '${name}',`, + ' \'type\' => \'select\',', + ' \'proxies\' => [', + insertProxy && name !== 'Default Proxy' && ' \'Default Proxy\',', + insertDirect && ' \'DIRECT\',', + ' ],', + ' ],' + ].filter(_guard.isTruthy))); + (0, _appendarrayinplace.appendArrayInPlace)(redults, [ + ' ],', + ' \'rules\' => [' + ]); + // domestic - domains + (0, _appendarrayinplace.appendArrayInPlace)(redults, directDomains.map((line)=>` '${line},Domestic',`)); + // microsoft & apple - domains + (0, _appendarrayinplace.appendArrayInPlace)(redults, microsoftAppleDomains.map((line)=>` '${line},Microsoft & Apple',`)); + // stream - domains + (0, _appendarrayinplace.appendArrayInPlace)(redults, streamDomains.map((line)=>` '${line},Stream',`)); + // steam download - domains + (0, _appendarrayinplace.appendArrayInPlace)(redults, steamDomains.map((line)=>` '${line},Steam Download',`)); + // global - domains + (0, _appendarrayinplace.appendArrayInPlace)(redults, globalDomains.map((line)=>` '${line},Global',`)); + // microsoft & apple - ip cidr (nope) + // lan - domains + (0, _appendarrayinplace.appendArrayInPlace)(redults, lanDomains.map((line)=>` '${line},DIRECT',`)); + // stream - ip cidr + (0, _appendarrayinplace.appendArrayInPlace)(redults, streamCidrs.map((line)=>` '${line},Stream',`)); + // global - ip cidr + (0, _appendarrayinplace.appendArrayInPlace)(redults, globalCidrs.map((line)=>` '${line},Global',`)); + // domestic - ip cidr + (0, _appendarrayinplace.appendArrayInPlace)(redults, directCidrs.map((line)=>` '${line},Domestic',`)); + // lan - ip cidr + (0, _appendarrayinplace.appendArrayInPlace)(redults, lanCidrs.map((line)=>` '${line},DIRECT',`)); + // match + (0, _appendarrayinplace.appendArrayInPlace)(redults, [ + ' \'MATCH,Final Match\',', + ' ],', + '];' + ]); + return redults; + } + } (buildSspanelAppprofile.__module, buildSspanelAppprofile.__module.exports)); + return buildSspanelAppprofile.__module.exports; +}exports.__require=requireBuildSspanelAppprofile; \ No newline at end of file diff --git a/Dist/Build/build-stream-service.cjs b/Dist/Build/build-stream-service.cjs new file mode 100644 index 00000000..c48fc846 --- /dev/null +++ b/Dist/Build/build-stream-service.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildStreamService$1=require('./build-stream-service2.cjs');var buildStreamServiceExports = buildStreamService$1.__require(); +const buildStreamService = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildStreamServiceExports);module.exports=buildStreamService; \ No newline at end of file diff --git a/Dist/Build/build-stream-service2.cjs b/Dist/Build/build-stream-service2.cjs new file mode 100644 index 00000000..a42b7b43 --- /dev/null +++ b/Dist/Build/build-stream-service2.cjs @@ -0,0 +1,48 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildStreamService=require('../_virtual/build-stream-service.cjs'),index=require('./trace/index.cjs'),stream=require('../Source/stream.cjs'),description=require('./constants/description.cjs'),ruleset=require('./lib/rules/ruleset.cjs');var hasRequiredBuildStreamService; + +function requireBuildStreamService () { + if (hasRequiredBuildStreamService) return buildStreamService.__module.exports; + hasRequiredBuildStreamService = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildStreamService", { + enumerable: true, + get: function() { + return buildStreamService; + } + }); + const _trace = /*@__PURE__*/ index.__require(); + const _stream = /*@__PURE__*/ stream.__require(); + const _description = /*@__PURE__*/ description.__require(); + const _ruleset = /*@__PURE__*/ ruleset.__require(); + function createRulesetForStreamService(span, fileId, title, streamServices) { + return [ + // Domains + new _ruleset.RulesetOutput(span, fileId, 'non_ip').withTitle(`Sukka's Ruleset - Stream Services: ${title}`).withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + ...streamServices.map((i)=>`- ${i.name}`) + ]).addFromRuleset(streamServices.flatMap((i)=>i.rules)).write(), + // IP + new _ruleset.RulesetOutput(span, fileId, 'ip').withTitle(`Sukka's Ruleset - Stream Services IPs: ${title}`).withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + ...streamServices.map((i)=>`- ${i.name}`) + ]).bulkAddCIDR4NoResolve(streamServices.flatMap((i)=>i.ip?.v4 ?? [])).bulkAddCIDR6NoResolve(streamServices.flatMap((i)=>i.ip?.v6 ?? [])).write() + ]; + } + const buildStreamService = (0, _trace.task)(require.main === module, __filename)(async (span)=>Promise.all([ + createRulesetForStreamService(span, 'stream', 'All', _stream.ALL), + createRulesetForStreamService(span, 'stream_us', 'North America', _stream.NORTH_AMERICA), + createRulesetForStreamService(span, 'stream_eu', 'Europe', _stream.EU), + createRulesetForStreamService(span, 'stream_hk', 'Hong Kong', _stream.HK), + createRulesetForStreamService(span, 'stream_tw', 'Taiwan', _stream.TW), + createRulesetForStreamService(span, 'stream_jp', 'Japan', _stream.JP), + // createRulesetForStreamService('stream_au', 'Oceania', AU), + createRulesetForStreamService(span, 'stream_kr', 'Korean', _stream.KR) + ].flat())); + } (buildStreamService.__module, buildStreamService.__module.exports)); + return buildStreamService.__module.exports; +}exports.__require=requireBuildStreamService; \ No newline at end of file diff --git a/Dist/Build/build-telegram-cidr.cjs b/Dist/Build/build-telegram-cidr.cjs new file mode 100644 index 00000000..6cb44cd1 --- /dev/null +++ b/Dist/Build/build-telegram-cidr.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildTelegramCidr$1=require('./build-telegram-cidr2.cjs');var buildTelegramCidrExports = buildTelegramCidr$1.__require(); +const buildTelegramCidr = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildTelegramCidrExports);module.exports=buildTelegramCidr; \ No newline at end of file diff --git a/Dist/Build/build-telegram-cidr2.cjs b/Dist/Build/build-telegram-cidr2.cjs new file mode 100644 index 00000000..f96134f0 --- /dev/null +++ b/Dist/Build/build-telegram-cidr2.cjs @@ -0,0 +1,69 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildTelegramCidr=require('../_virtual/build-telegram-cidr.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),memoPromise=require('./lib/memo-promise.cjs'),ruleset=require('./lib/rules/ruleset.cjs'),fetchRetry=require('./lib/fetch-retry.cjs'),misc=require('./lib/misc.cjs');var hasRequiredBuildTelegramCidr; + +function requireBuildTelegramCidr () { + if (hasRequiredBuildTelegramCidr) return buildTelegramCidr.__module.exports; + hasRequiredBuildTelegramCidr = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + buildTelegramCIDR: function() { + return buildTelegramCIDR; + }, + getTelegramCIDRPromise: function() { + return getTelegramCIDRPromise; + } + }); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _trace = /*@__PURE__*/ index.__require(); + const _description = /*@__PURE__*/ description.__require(); + const _memopromise = /*@__PURE__*/ memoPromise.__require(); + const _ruleset = /*@__PURE__*/ ruleset.__require(); + const _fetchretry = /*@__PURE__*/ fetchRetry.__require(); + const _misc = /*@__PURE__*/ misc.__require(); + const getTelegramCIDRPromise = (0, _memopromise.createMemoizedPromise)(async ()=>{ + const resp = await (0, _fetchretry.$$fetch)('https://core.telegram.org/resources/cidr.txt'); + const lastModified = resp.headers.get('last-modified'); + const date = lastModified ? new Date(lastModified) : new Date(); + const ipcidr = [ + // Telegram secret backup CIDR, announced by AS62041 + // see also https://github.com/Telegram-FOSS-Team/Telegram-FOSS/blob/10da5406ed92d30c6add3b25d40b2b3b6995d873/TMessagesProj/src/main/java/org/telegram/tgnet/ConnectionsManager.java#L1157 + '95.161.64.0/20' + ]; + const ipcidr6 = []; + for await (const cidr of (0, _fetchtextbyline.createReadlineInterfaceFromResponse)(resp, true)){ + const v = (0, _misc.fastIpVersion)(cidr); + if (v === 4) { + ipcidr.push(cidr); + } else if (v === 6) { + ipcidr6.push(cidr); + } + } + return { + date, + ipcidr, + ipcidr6 + }; + }); + const buildTelegramCIDR = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const { date, ipcidr, ipcidr6 } = await span.traceChildAsync('get telegram cidr', getTelegramCIDRPromise); + if (ipcidr.length + ipcidr6.length === 0) { + throw new Error('Failed to fetch data!'); + } + const description = [ + ..._description.SHARED_DESCRIPTION, + 'Data from:', + ' - https://core.telegram.org/resources/cidr.txt' + ]; + return new _ruleset.RulesetOutput(span, 'telegram', 'ip').withTitle('Sukka\'s Ruleset - Telegram IP CIDR').withDescription(description).withDate(date).bulkAddCIDR4NoResolve(ipcidr).bulkAddCIDR6NoResolve(ipcidr6).write(); + }); + } (buildTelegramCidr.__module, buildTelegramCidr.__module.exports)); + return buildTelegramCidr.__module.exports; +}exports.__require=requireBuildTelegramCidr; \ No newline at end of file diff --git a/Dist/Build/constants/cidr.cjs b/Dist/Build/constants/cidr.cjs new file mode 100644 index 00000000..d6d5a8ef --- /dev/null +++ b/Dist/Build/constants/cidr.cjs @@ -0,0 +1,92 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const cidr=require('../../_virtual/cidr.cjs');var hasRequiredCidr; + +function requireCidr () { + if (hasRequiredCidr) return cidr.__exports; + hasRequiredCidr = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + CN_CIDR_MISSING_IN_CHNROUTE: function() { + return CN_CIDR_MISSING_IN_CHNROUTE; + }, + NON_CN_CIDR_INCLUDED_IN_CHNROUTE: function() { + return NON_CN_CIDR_INCLUDED_IN_CHNROUTE; + }, + RESERVED_IPV4_CIDR: function() { + return RESERVED_IPV4_CIDR; + } + }); + const RESERVED_IPV4_CIDR = [ + '0.0.0.0/8', + '10.0.0.0/8', + '100.64.0.0/10', + '127.0.0.0/8', + '169.254.0.0/16', + '172.16.0.0/12', + '192.0.0.0/24', + '192.0.2.0/24', + // 192.88.99.0 // is currently being broadcast by HE and Comcast + '192.168.0.0/16', + '198.18.0.0/15', + '198.51.100.0/24', + '203.0.113.0/24', + '224.0.0.0/4', + '233.252.0.0/24', + '240.0.0.0/4' + ]; + const NON_CN_CIDR_INCLUDED_IN_CHNROUTE = [ + '223.118.0.0/15', + '223.120.0.0/15' + ]; + const CN_CIDR_MISSING_IN_CHNROUTE = [ + // Baidu Public DNS + '180.76.76.0/24', + // Ali Public DNS + '223.5.5.0/24', + '223.6.6.0/24', + // Tencent DNSPod Public DNS + '119.29.29.0/24', + '119.28.28.0/24', + '120.53.53.0/24', + '1.12.12.0/24', + '1.12.34.0/24', + // ByteDance Public DNS + '180.184.1.0/24', + '180.184.2.0/24', + // 360 Public DNS + '101.198.198.0/24', + '101.198.199.0/24', + // ChinaTelecom + '103.7.141.0/24', + // Aliyun Shenzhen + '120.78.0.0/16', + // wy.com.cn + '211.99.96.0/19', + // AS58593, Azure China + '40.72.0.0/15', + '42.159.0.0/16', + '52.130.0.0/17', + '52.131.0.0/16', + '103.9.8.0/22', + '139.217.0.0/16', + '139.219.0.0/16', + '143.64.0.0/16', + '159.27.0.0/16', + '163.228.0.0/16', + // NetEase + '223.252.194.0/24', + '223.252.196.0/24', + // Xiamen Kuaikuai + '180.188.36.0/22' // no route globally + ]; + } (cidr.__exports)); + return cidr.__exports; +}exports.__require=requireCidr; \ No newline at end of file diff --git a/Dist/Build/constants/description.cjs b/Dist/Build/constants/description.cjs new file mode 100644 index 00000000..0a685fe8 --- /dev/null +++ b/Dist/Build/constants/description.cjs @@ -0,0 +1,34 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const description=require('../../_virtual/description.cjs');var hasRequiredDescription; + +function requireDescription () { + if (hasRequiredDescription) return description.__exports; + hasRequiredDescription = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + SHARED_DESCRIPTION: function() { + return SHARED_DESCRIPTION; + }, + createFileDescription: function() { + return createFileDescription; + } + }); + function createFileDescription(license = 'AGPL 3.0') { + return [ + `License: ${license}`, + 'Homepage: https://ruleset.skk.moe', + 'GitHub: https://github.com/SukkaW/Surge' + ]; + } + const SHARED_DESCRIPTION = createFileDescription('AGPL 3.0'); + } (description.__exports)); + return description.__exports; +}exports.__require=requireDescription; \ No newline at end of file diff --git a/Dist/Build/constants/dir.cjs b/Dist/Build/constants/dir.cjs new file mode 100644 index 00000000..231862f3 --- /dev/null +++ b/Dist/Build/constants/dir.cjs @@ -0,0 +1,71 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const dir=require('../../_virtual/dir.cjs'),require$$0=require('node:path'),require$$1=require('node:process');var hasRequiredDir; + +function requireDir () { + if (hasRequiredDir) return dir.__exports; + hasRequiredDir = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + CACHE_DIR: function() { + return CACHE_DIR; + }, + OUTPUT_CLASH_DIR: function() { + return OUTPUT_CLASH_DIR; + }, + OUTPUT_INTERNAL_DIR: function() { + return OUTPUT_INTERNAL_DIR; + }, + OUTPUT_MOCK_DIR: function() { + return OUTPUT_MOCK_DIR; + }, + OUTPUT_MODULES_DIR: function() { + return OUTPUT_MODULES_DIR; + }, + OUTPUT_MODULES_RULES_DIR: function() { + return OUTPUT_MODULES_RULES_DIR; + }, + OUTPUT_SINGBOX_DIR: function() { + return OUTPUT_SINGBOX_DIR; + }, + OUTPUT_SURGE_DIR: function() { + return OUTPUT_SURGE_DIR; + }, + PUBLIC_DIR: function() { + return PUBLIC_DIR; + }, + ROOT_DIR: function() { + return ROOT_DIR; + }, + SOURCE_DIR: function() { + return SOURCE_DIR; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _nodeprocess = /*#__PURE__*/ _interop_require_default(require$$1); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const ROOT_DIR = _nodepath.default.resolve(__dirname, '../..'); + const CACHE_DIR = _nodepath.default.resolve(ROOT_DIR, '.cache'); + const SOURCE_DIR = _nodepath.default.join(ROOT_DIR, 'Source'); + const PUBLIC_DIR = _nodeprocess.default.env.PUBLIC_DIR || _nodepath.default.resolve(ROOT_DIR, 'public'); + const OUTPUT_SURGE_DIR = _nodepath.default.join(PUBLIC_DIR, 'List'); + const OUTPUT_CLASH_DIR = _nodepath.default.resolve(PUBLIC_DIR, 'Clash'); + const OUTPUT_SINGBOX_DIR = _nodepath.default.resolve(PUBLIC_DIR, 'sing-box'); + const OUTPUT_MODULES_DIR = _nodepath.default.resolve(PUBLIC_DIR, 'Modules'); + const OUTPUT_MODULES_RULES_DIR = _nodepath.default.resolve(OUTPUT_MODULES_DIR, 'Rules'); + const OUTPUT_INTERNAL_DIR = _nodepath.default.resolve(PUBLIC_DIR, 'Internal'); + const OUTPUT_MOCK_DIR = _nodepath.default.resolve(PUBLIC_DIR, 'Mock'); + } (dir.__exports)); + return dir.__exports; +}exports.__require=requireDir; \ No newline at end of file diff --git a/Dist/Build/constants/domains.cjs b/Dist/Build/constants/domains.cjs new file mode 100644 index 00000000..5ea0d9b5 --- /dev/null +++ b/Dist/Build/constants/domains.cjs @@ -0,0 +1,148 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const domains=require('../../_virtual/domains.cjs');var hasRequiredDomains; + +function requireDomains () { + if (hasRequiredDomains) return domains.__exports; + hasRequiredDomains = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "ICP_TLD", { + enumerable: true, + get: function() { + return ICP_TLD; + } + }); + const ICP_TLD = [ + 'ren', + 'wang', + 'citic', + 'top', + 'sohu', + 'xin', + 'com', + 'net', + 'club', + 'xyz', + 'site', + 'shop', + 'info', + 'mobi', + 'red', + 'pro', + 'kim', + 'ltd', + 'group', + 'biz', + 'link', + 'store', + 'tech', + 'fun', + 'online', + 'art', + 'design', + 'love', + 'center', + 'video', + 'social', + 'team', + 'show', + 'cool', + 'zone', + 'world', + 'today', + 'city', + 'chat', + 'company', + 'live', + 'fund', + 'gold', + 'plus', + 'guru', + 'run', + 'pub', + 'email', + 'life', + 'co', + 'baidu', + 'cloud', + 'host', + 'space', + 'press', + 'website', + 'archi', + 'asia', + 'bio', + 'black', + 'blue', + 'green', + 'lotto', + 'organic', + 'pet', + 'pink', + 'poker', + 'promo', + 'ski', + 'vote', + 'voto', + 'icu', + 'fans', + 'unicom', + 'jpmorgan', + 'chase', + 'cc', + 'band', + 'cab', + 'cafe', + 'cash', + 'fan', + 'fyi', + 'games', + 'market', + 'mba', + 'news', + 'media', + 'sale', + 'shopping', + 'studio', + 'tax', + 'technology', + 'vin', + 'baby', + 'college', + 'monster', + 'protection', + 'rent', + 'security', + 'storage', + 'theatre', + 'bond', + 'cyou', + 'uno', + 'school', + 'global', + 'me', + 'pw', + 'hk', + 'tv', + 'saxo', + 'click', + 'auto', + 'autos', + 'beauty', + 'boats', + 'car', + 'cars', + 'hair', + 'homes', + 'makeup', + 'motorcycles', + 'quest', + 'skin', + 'tickets', + 'yachts', + 'kids' + ]; + } (domains.__exports)); + return domains.__exports; +}exports.__require=requireDomains; \ No newline at end of file diff --git a/Dist/Build/constants/loose-tldts-opt.cjs b/Dist/Build/constants/loose-tldts-opt.cjs new file mode 100644 index 00000000..95d51551 --- /dev/null +++ b/Dist/Build/constants/loose-tldts-opt.cjs @@ -0,0 +1,47 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const looseTldtsOpt=require('../../_virtual/loose-tldts-opt.cjs');var hasRequiredLooseTldtsOpt; + +function requireLooseTldtsOpt () { + if (hasRequiredLooseTldtsOpt) return looseTldtsOpt.__exports; + hasRequiredLooseTldtsOpt = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + loosTldOptWithPrivateDomains: function() { + return loosTldOptWithPrivateDomains; + }, + looseTldtsOpt: function() { + return looseTldtsOpt; + }, + normalizeTldtsOpt: function() { + return normalizeTldtsOpt; + } + }); + const looseTldtsOpt = { + allowPrivateDomains: false, + extractHostname: false, + validateHostname: false, + detectIp: false, + mixedInputs: false + }; + const loosTldOptWithPrivateDomains = { + ...looseTldtsOpt, + allowPrivateDomains: true + }; + const normalizeTldtsOpt = { + allowPrivateDomains: true, + // in normalizeDomain, we only care if it contains IP, we don't care if we need to extract it + // by setting detectIp to false and manually check ip outside tldts.parse, we can skip the tldts + // inner "extractHostname" call + detectIp: false + }; + } (looseTldtsOpt.__exports)); + return looseTldtsOpt.__exports; +}exports.__require=requireLooseTldtsOpt; \ No newline at end of file diff --git a/Dist/Build/constants/reject-data-source.cjs b/Dist/Build/constants/reject-data-source.cjs new file mode 100644 index 00000000..86e4851c --- /dev/null +++ b/Dist/Build/constants/reject-data-source.cjs @@ -0,0 +1,584 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const rejectDataSource=require('../../_virtual/reject-data-source.cjs');var hasRequiredRejectDataSource; + +function requireRejectDataSource () { + if (hasRequiredRejectDataSource) return rejectDataSource.__exports; + hasRequiredRejectDataSource = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + ADGUARD_FILTERS: function() { + return ADGUARD_FILTERS; + }, + ADGUARD_FILTERS_EXTRA: function() { + return ADGUARD_FILTERS_EXTRA; + }, + ADGUARD_FILTERS_WHITELIST: function() { + return ADGUARD_FILTERS_WHITELIST; + }, + CRASHLYTICS_WHITELIST: function() { + return CRASHLYTICS_WHITELIST; + }, + DEBUG_DOMAIN_TO_FIND: function() { + return DEBUG_DOMAIN_TO_FIND; + }, + DOMAIN_LISTS: function() { + return DOMAIN_LISTS; + }, + DOMAIN_LISTS_EXTRA: function() { + return DOMAIN_LISTS_EXTRA; + }, + HOSTS: function() { + return HOSTS; + }, + HOSTS_EXTRA: function() { + return HOSTS_EXTRA; + }, + PHISHING_DOMAIN_LISTS_EXTRA: function() { + return PHISHING_DOMAIN_LISTS_EXTRA; + }, + PHISHING_HOSTS_EXTRA: function() { + return PHISHING_HOSTS_EXTRA; + }, + PREDEFINED_WHITELIST: function() { + return PREDEFINED_WHITELIST; + } + }); + const DEBUG_DOMAIN_TO_FIND = null; // example.com | null + const HOSTS = [ + [ + // WindowsSpyBlocker hasn't been updated since 2022-06-16, let's use jsDelivr as primary URL + 'https://cdn.jsdelivr.net/gh/crazy-max/WindowsSpyBlocker@master/data/hosts/spy.txt', + [ + 'https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt' + ], + true + ], + [ + 'https://raw.githubusercontent.com/jerryn70/GoodbyeAds/master/Extension/GoodbyeAds-Xiaomi-Extension.txt', + null, + false + ], + [ + 'https://raw.githubusercontent.com/jerryn70/GoodbyeAds/master/Extension/GoodbyeAds-Huawei-AdBlock.txt', + null, + false + ] + ]; + const HOSTS_EXTRA = [ + [ + 'https://raw.githubusercontent.com/durablenapkin/block/master/tvstream.txt', + null, + true + ], + // This stupid hosts blocks t.co, so we determine that this is also bullshit, so it is extra + [ + 'https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext', + [ + 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/thirdparties/pgl.yoyo.org/as/serverlist' + ], + true + ], + // Dan Pollock's hosts file, 0.0.0.0 version is 30 KiB smaller + [ + 'https://someonewhocares.org/hosts/zero/hosts', + [ + 'https://proxy.cdn.skk.moe/https/someonewhocares.org/hosts/zero/hosts' + ], + true + ], + // ad-wars is not actively maintained since 2023.11, so we use jsDelivr as primary URL + [ + 'https://cdn.jsdelivr.net/gh/jdlingyu/ad-wars@master/hosts', + [ + 'https://raw.githubusercontent.com/jdlingyu/ad-wars/master/hosts' + ], + false + ] + ]; + const DOMAIN_LISTS = []; + const DOMAIN_LISTS_EXTRA = [ + // CoinBlockerList - Full + // The CoinBlockerList is no longer maintained and even close-source, so we no longer trust it + // instead we maintain a list of our own + // BarbBlock + // The barbblock list has never been updated since 2019-05, so we set a 14 days cache ttl + [ + 'https://paulgb.github.io/BarbBlock/blacklists/domain-list.txt', + [ + 'https://raw.githubusercontent.com/paulgb/BarbBlock/refs/heads/main/blacklists/domain-list.txt' + ], + true + ], + // DigitalSide Threat-Intel - OSINT Hub + // Update once per day + [ + 'https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt', + [], + true + ], + // AdGuard CNAME Filter Combined + // Update on a 7 days basis, so we can also use jsDelivr as primary URL + [ + 'https://cdn.jsdelivr.net/gh/AdguardTeam/cname-trackers@master/data/combined_disguised_ads_justdomains.txt', + [ + 'https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/data/combined_disguised_ads_justdomains.txt' + ], + true + ], + [ + 'https://cdn.jsdelivr.net/gh/AdguardTeam/cname-trackers@master/data/combined_disguised_trackers_justdomains.txt', + [ + 'https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/data/combined_disguised_trackers_justdomains.txt' + ], + true + ], + [ + 'https://cdn.jsdelivr.net/gh/AdguardTeam/cname-trackers@master/data/combined_disguised_clickthroughs_justdomains.txt', + [ + 'https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/data/combined_disguised_clickthroughs_justdomains.txt' + ], + true + ], + [ + 'https://cdn.jsdelivr.net/gh/AdguardTeam/cname-trackers@master/data/combined_disguised_microsites_justdomains.txt', + [ + 'https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/data/combined_disguised_microsites_justdomains.txt' + ], + true + ], + // ['https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/data/combined_disguised_mail_trackers_justdomains.txt', [], true], + // Curben's PUP Domains Blocklist + // The PUP filter has paused the update since 2023-05, so we set a 14 days cache ttl, and move it to extra + // [ + // 'https://pup-filter.pages.dev/pup-filter-domains.txt', + // [ + // // 'https://malware-filter.pages.dev/pup-filter-domains.txt', + // // 'https://malware-filter.gitlab.io/malware-filter/pup-filter-domains.txt', + // 'https://malware-filter.gitlab.io/pup-filter/pup-filter-domains.txt' + // // 'https://curbengh.github.io/pup-filter/pup-filter-domains.txt', + // // 'https://malware-filter.pages.dev/pup-filter-domains.txt' + // ], + // true + // ], + // Curben's UrlHaus Malicious URL Blocklist + [ + 'https://urlhaus-filter.pages.dev/urlhaus-filter-domains.txt', + [ + 'https://malware-filter.pages.dev/urlhaus-filter-domains.txt', + 'https://malware-filter.gitlab.io/urlhaus-filter/urlhaus-filter-domains.txt', + 'https://malware-filter.gitlab.io/malware-filter/urlhaus-filter-domains.txt', + 'https://curbengh.github.io/urlhaus-filter/urlhaus-filter-domains.txt' + ], + true + ], + // Spam404 + // Not actively maintained, let's use jsDelivr as primary URL + [ + 'https://cdn.jsdelivr.net/gh/Spam404/lists@master/main-blacklist.txt', + [ + 'https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt' + ], + true + ] + ]; + const PHISHING_HOSTS_EXTRA = [ + [ + 'https://raw.githubusercontent.com/durablenapkin/scamblocklist/master/hosts.txt', + [], + true + ] + ]; + const PHISHING_DOMAIN_LISTS_EXTRA = [ + [ + 'https://phishing-filter.pages.dev/phishing-filter-domains.txt', + [ + 'https://malware-filter.pages.dev/phishing-filter-domains.txt', + 'https://malware-filter.gitlab.io/phishing-filter/phishing-filter-domains.txt', + 'https://malware-filter.gitlab.io/malware-filter/phishing-filter-domains.txt', + 'https://curbengh.github.io/phishing-filter/phishing-filter-domains.txt' + ], + true + ], + [ + 'https://phishing.army/download/phishing_army_blocklist.txt', + [], + true + ] + ]; + const ADGUARD_FILTERS = [ + // EasyList + [ + 'https://easylist.to/easylist/easylist.txt', + [ + 'https://easylist-downloads.adblockplus.org/easylist.txt', + 'https://secure.fanboy.co.nz/easylist.txt', + 'https://ublockorigin.github.io/uAssetsCDN/thirdparties/easylist.txt', + 'https://ublockorigin.pages.dev/thirdparties/easylist.txt', + 'https://raw.githubusercontent.com/easylist/easylist/gh-pages/easylist.txt', + 'https://filters.adtidy.org/extension/ublock/filters/101_optimized.txt' + ] + ], + // EasyPrivacy + [ + 'https://easylist.to/easylist/easyprivacy.txt', + [ + 'https://easylist-downloads.adblockplus.org/easyprivacy.txt', + 'https://secure.fanboy.co.nz/easyprivacy.txt', + 'https://ublockorigin.github.io/uAssetsCDN/thirdparties/easyprivacy.txt', + 'https://ublockorigin.pages.dev/thirdparties/easyprivacy.txt', + 'https://raw.githubusercontent.com/easylist/easylist/gh-pages/easyprivacy.txt', + 'https://filters.adtidy.org/extension/ublock/filters/118_optimized.txt' + ] + ], + // AdGuard Base Filter + [ + 'https://filters.adtidy.org/extension/ublock/filters/2_without_easylist.txt', + [ + 'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/2_without_easylist.txt' + ] + ], + // AdGuard Mobile AD + [ + 'https://filters.adtidy.org/extension/ublock/filters/11_optimized.txt', + [ + 'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/2_without_easylist.txt' + ] + ], + // AdGuard Tracking Protection + [ + 'https://filters.adtidy.org/extension/ublock/filters/3_optimized.txt', + [ + 'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/3_optimized.txt' + ] + ], + // AdGuard Chinese filter (EasyList China + AdGuard Chinese filter) + [ + 'https://filters.adtidy.org/extension/ublock/filters/224_optimized.txt', + [ + 'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/224_optimized.txt' + ] + ], + // GameConsoleAdblockList + // Update almost once per 1 to 3 months, let's set a 10 days cache ttl + [ + 'https://cdn.jsdelivr.net/gh/DandelionSprout/adfilt@master/GameConsoleAdblockList.txt', + [ + 'https://raw.githubusercontent.com/DandelionSprout/adfilt/master/GameConsoleAdblockList.txt' + ] + ], + // PiHoleBlocklist + // Update almost once per 3 months, let's set a 10 days cache ttl + [ + 'https://perflyst.github.io/PiHoleBlocklist/SmartTV-AGH.txt', + [ + 'https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/SmartTV-AGH.txt' + ] + ], + // uBlock Origin Unbreak + [ + 'https://ublockorigin.github.io/uAssetsCDN/filters/unbreak.min.txt', + [ + 'https://ublockorigin.pages.dev/filters/unbreak.min.txt' + ] + ] + ]; + const ADGUARD_FILTERS_WHITELIST = [ + [ + 'https://adguardteam.github.io/AdGuardSDNSFilter/Filters/exceptions.txt', + [ + 'https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/Filters/exceptions.txt' + ] + ], + [ + 'https://adguardteam.github.io/AdGuardSDNSFilter/Filters/exclusions.txt', + [ + 'https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/Filters/exclusions.txt' + ] + ] + ]; + const ADGUARD_FILTERS_EXTRA = [ + // AdGuard DNS Filter + // way too many other countries' domains (JP, Spanish, RU, VN, Turkish, Ukarainian, Dutch, etc.) + // EasyList, EasyPrivacy, Chinese and general filters are already included in base data source + [ + 'https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt', + [ + 'https://filters.adtidy.org/extension/ublock/filters/15_optimized.txt', + 'https://adguardteam.github.io/HostlistsRegistry/assets/filter_1.txt' + ] + ], + // no coin list adguard list is more maintained than its hosts + [ + 'https://raw.githubusercontent.com/hoshsadiq/adblock-nocoin-list/master/nocoin.txt', + [], + true + ], + // AdGuard Annoyances filter + [ + 'https://filters.adtidy.org/extension/ublock/filters/14_optimized.txt', + [ + 'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/14_optimized.txt' + ], + true + ], + // AdGuard Cookie Notices, included in Annoyances filter + // ['https://filters.adtidy.org/extension/ublock/filters/18_optimized.txt', null, true], + // EasyList Germany filter, not even included in extra for now + // [ + // 'https://easylist.to/easylistgermany/easylistgermany.txt', + // [ + // 'https://easylist-downloads.adblockplus.org/easylistgermany.txt' + // ], + // + // ], + // AdGuard Japanese filter + [ + 'https://filters.adtidy.org/extension/ublock/filters/7_optimized.txt', + [ + 'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/7_optimized.txt' + ] + ], + // uBlock Origin Filter List + [ + 'https://ublockorigin.github.io/uAssetsCDN/filters/filters.min.txt', + [ + 'https://ublockorigin.pages.dev/filters/filters.min.txt' + ] + ], + // AdGuard Popup Overlay - included in Annoyances filter + // ['https://filters.adtidy.org/extension/ublock/filters/19_optimized.txt', null, true], + // AdGuard Mobile Banner + // almost all generic rule + // ['https://filters.adtidy.org/extension/ublock/filters/20_optimized.txt', null], + // uBlock Origin Badware Risk List + [ + 'https://ublockorigin.github.io/uAssetsCDN/filters/badware.min.txt', + [ + 'https://ublockorigin.pages.dev/filters/badware.min.txt' + ] + ], + // uBlock Origin Privacy List + [ + 'https://ublockorigin.github.io/uAssetsCDN/filters/privacy.min.txt', + [ + 'https://ublockorigin.pages.dev/filters/privacy.min.txt' + ] + ], + // uBlock Origin Resource Abuse: merged in uBlock Origin Privacy List + // [ + // 'https://ublockorigin.github.io/uAssetsCDN/filters/resource-abuse.txt', + // ['https://ublockorigin.pages.dev/filters/resource-abuse.txt'] + // ], + // uBlock Origin Annoyances (the un-merged of Fanboy Annoyances List) + [ + 'https://ublockorigin.github.io/uAssetsCDN/filters/annoyances.min.txt', + [ + 'https://ublockorigin.pages.dev/filters/annoyances.min.txt' + ] + ], + // EasyList Annoyances + [ + 'https://ublockorigin.github.io/uAssetsCDN/thirdparties/easylist-annoyances.txt', + [ + 'https://ublockorigin.pages.dev/thirdparties/easylist-annoyances.txt' + ] + ], + // EasyList - Newsletters + [ + 'https://ublockorigin.github.io/uAssetsCDN/thirdparties/easylist-newsletters.txt', + [ + 'https://ublockorigin.pages.dev/thirdparties/easylist-newsletters.txt' + ] + ], + // EasyList - Notifications + [ + 'https://ublockorigin.github.io/uAssets/thirdparties/easylist-notifications.txt', + [ + 'https://ublockorigin.pages.dev/thirdparties/easylist-notifications.txt' + ] + ], + // Fanboy Cookie Monster (EasyList Cookie List) + [ + 'https://ublockorigin.github.io/uAssets/thirdparties/easylist-cookies.txt', + [ + 'https://ublockorigin.pages.dev/thirdparties/easylist-cookies.txt', + 'https://secure.fanboy.co.nz/fanboy-cookiemonster_ubo.txt' + ] + ], + // Dandelion Sprout's Annoyances + [ + 'https://filters.adtidy.org/extension/ublock/filters/250_optimized.txt', + [ + 'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/250_optimized.txt' + ], + true + ], + // Adblock Warning Removal List + [ + 'https://easylist-downloads.adblockplus.org/antiadblockfilters.txt', + [ + 'https://filters.adtidy.org/extension/ublock/filters/207_optimized.txt' + ], + true + ] + ]; + const CRASHLYTICS_WHITELIST = [ + // VSCode Telemetry, see https://sts.online.visualstudio.com/api/swagger/index.html + 'sts.online.visualstudio.com', + // Sentry + '.ingest.sentry.io', + '.ingest.us.sentry.io', + '.ingest.de.sentry.io', + // bugsnag + '.sessions.bugsnag.com', + '.notify.bugsnag.com', + // influxdata + '.cloud.influxdata.com', + '.cloud1.influxdata.com', + '.cloud2.influxdata.com', + // split.io A/B flag + 'streaming.split.io', + 'telemetry.split.io', + 'sdk.split.io', + // Google + // -ds.metric.gstatic.com are specifically exempted from reject, but it could use secondary proxy policy + '.metric.gstatic.com', + // Misc + 'telemetry.1passwordservices.com', + 'events.tableplus.com', + 'telemetry.nextjs.org', + 'telemetry.vercel.com', + 'stats.setapp.com', + 'stats.setapp.macpaw.dev', + '.app-analytics-services.com', + '.telemetry.services.yofi.ai', + '.cdn.pubnub.com', + '.data.debugbear.com', + '.cdn.applicationinsights.io', + '.applicationinsights.azure.com', + '.applicationinsights.azure.cn', + '.api.loganalytics.io', + '.bugly.qcloud.com', + '.cdn.signalfx.com', + '.crash-reports.browser.yandex.net', + '.crashlytics2.l.google.com', + '.crashlyticsreports-pa.googleapis.com', + '.e.crashlytics.com', + '.events.backtrace.io', + 'auth.split.io', + 'events.split.io', + 'streaming.split.io', + '.in.appcenter.ms', + '.loggly.com', + '.logz.io', + '.opentelemetry.io', + '.raygun.io', + '.rum.cronitor.io', + '.settings.crashlytics.com', + '.sny.monosnap.com', + '.lr-ingest.com', + '.cdn.rollbar.com', + '.api.instabug.com', + '.ensighten.com', + 'api.crashguard.me' + ]; + const PREDEFINED_WHITELIST = [ + ...CRASHLYTICS_WHITELIST, + '.localhost', + '.local', + '.localdomain', + '.broadcasthost', + '.ip6-loopback', + '.ip6-localnet', + '.ip6-mcastprefix', + '.ip6-allnodes', + '.ip6-allrouters', + '.ip6-allhosts', + '.mcastprefix', + '.skk.moe', + 'analytics.google.com', + '.cloud.answerhub.com', + 'ae01.alicdn.com', + '.whoami.akamai.net', + '.whoami.ds.akahelp.net', + '.instant.page', + '.piwik.pro', + 'mixpanel.com', + 'cdn.mxpnl.com', + '.heapanalytics.com', + '.segment.com', + '.segmentify.com', + '.t.co', + '.survicate.com', + '.perfops.io', + '.d2axgrpnciinw7.cloudfront.net', + '.sb-cd.com', + '.storage.yandexcloud.net', + '.login.microsoftonline.com', + 'api.xiaomi.com', + 'api.io.mi.com', + '.cdn.userreport.com', + '.ip-api.com', + '.fastly-analytics.com', + '.digitaloceanspaces.com', + 's3.nl-ams.scw.cloud', + '.geolocation-db.com', + '.uploads.codesandbox.io', + '.vlscppe.microsoft.com', + '.statsig.com', + '.pstmrk.it', + '.clicks.mlsend.com', + 'email.accounts.bitly.com', + 'adsense.google.com', + 'api.vip.miui.com', + 'api.comm.miui.com', + '.ai.api.xiaomi.com', + 'm.stripe.com', + // yet stupid AdGuardDNSFilter blocks all of it. Stupid AdGuard + '.w3s.link', + '.r2.dev', + 'mlsend.com', + 'ab.chatgpt.com', + 'jnn-pa.googleapis.com', + 'imasdk.googleapis.com', + '.l.qq.com', + '.in-addr.arpa', + '.ip6.arpa', + '.clients.your-server.de', + '.bc.googleusercontent.com', + '.host.secureserver.net', + '.ip.linodeusercontent.com', + '.static.akamaitechnologies.com', + '.compute.amazonaws.com', + '.shoppy.gg', + 'transcend-cdn.com', + 'store1.gofile.io', + 'ad.12306.cn', + '.ib.snssdk.com', + '.nstool.netease.com', + '.wns.windows.com', + '.lon.llnw.net', + '.lcy.llnw.net', + 'repo.huaweicloud.com', + '.hubspotlinks.com', + 'cldup.com', + // Doesn't make sense: CNAME domains + '.cdn.cloudflare.net', + '.apple-dns.net', + '.data.microsoft.com.akadns.net', + // Expired domains + '.expobarrio.com', + '.hamdandates.com', + '.amzone.co.jp' + ]; + } (rejectDataSource.__exports)); + return rejectDataSource.__exports; +}exports.__require=requireRejectDataSource; \ No newline at end of file diff --git a/Dist/Build/download-mock-assets.cjs b/Dist/Build/download-mock-assets.cjs new file mode 100644 index 00000000..5f12ede8 --- /dev/null +++ b/Dist/Build/download-mock-assets.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),downloadMockAssets$1=require('./download-mock-assets2.cjs');var downloadMockAssetsExports = downloadMockAssets$1.__require(); +const downloadMockAssets = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(downloadMockAssetsExports);module.exports=downloadMockAssets; \ No newline at end of file diff --git a/Dist/Build/download-mock-assets2.cjs b/Dist/Build/download-mock-assets2.cjs new file mode 100644 index 00000000..f02932da --- /dev/null +++ b/Dist/Build/download-mock-assets2.cjs @@ -0,0 +1,58 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const downloadMockAssets=require('../_virtual/download-mock-assets.cjs'),index=require('./trace/index.cjs'),require$$0=require('node:path'),require$$1=require('node:fs'),require$$2=require('node:stream/promises'),dir=require('./constants/dir.cjs'),misc=require('./lib/misc.cjs'),fetchRetry=require('./lib/fetch-retry.cjs');var hasRequiredDownloadMockAssets; + +function requireDownloadMockAssets () { + if (hasRequiredDownloadMockAssets) return downloadMockAssets.__module.exports; + hasRequiredDownloadMockAssets = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "downloadMockAssets", { + enumerable: true, + get: function() { + return downloadMockAssets; + } + }); + const _trace = /*@__PURE__*/ index.__require(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1); + const _promises = require$$2; + const _dir = /*@__PURE__*/ dir.__require(); + const _misc = /*@__PURE__*/ misc.__require(); + const _fetchretry = /*@__PURE__*/ fetchRetry.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const ASSETS_LIST = { + 'www-google-analytics-com_ga.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/google-analytics-ga.js', + 'www-googletagservices-com_gpt.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/googletagservices-gpt.js', + 'www-google-analytics-com_analytics.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/google-analytics.js', + 'www-googlesyndication-com_adsbygoogle.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/googlesyndication-adsbygoogle.js', + 'amazon-adsystem-com_amazon-apstag.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/amazon-apstag.js' + }; + const downloadMockAssets = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const p = (0, _misc.mkdirp)(_dir.OUTPUT_MOCK_DIR); + if (p) { + await p; + } + return Promise.all(Object.entries(ASSETS_LIST).map(([filename, url])=>span.traceChildAsync(url, async ()=>{ + const res = await (0, _fetchretry.$$fetch)(url); + if (!res.ok) { + console.error(`Failed to download ${url}`); + // we can safely skip this since we can always use previous version + return; + } + if (!res.body) { + console.error(`Empty body from ${url}`); + // we can safely skip this since we can always use previous version + return; + } + const src = _nodepath.default.join(_dir.OUTPUT_MOCK_DIR, filename); + return (0, _promises.pipeline)(res.body, _nodefs.default.createWriteStream(src, 'utf-8')); + }))); + }); + } (downloadMockAssets.__module, downloadMockAssets.__module.exports)); + return downloadMockAssets.__module.exports; +}exports.__require=requireDownloadMockAssets; \ No newline at end of file diff --git a/Dist/Build/download-previous-build.cjs b/Dist/Build/download-previous-build.cjs new file mode 100644 index 00000000..53c6c780 --- /dev/null +++ b/Dist/Build/download-previous-build.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),downloadPreviousBuild$1=require('./download-previous-build2.cjs');var downloadPreviousBuildExports = downloadPreviousBuild$1.__require(); +const downloadPreviousBuild = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(downloadPreviousBuildExports);module.exports=downloadPreviousBuild; \ No newline at end of file diff --git a/Dist/Build/download-previous-build2.cjs b/Dist/Build/download-previous-build2.cjs new file mode 100644 index 00000000..9e848098 --- /dev/null +++ b/Dist/Build/download-previous-build2.cjs @@ -0,0 +1,99 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const downloadPreviousBuild=require('../_virtual/download-previous-build.cjs'),require$$0$1=require('node:path'),require$$1$1=require('node:fs'),require$$2=require('node:stream/promises'),index=require('./trace/index.cjs'),require$$4=require('tar-fs'),require$$5=require('node:zlib'),require$$1=require('undici'),require$$0=require('picocolors'),dir=require('./constants/dir.cjs'),fetchRetry=require('./lib/fetch-retry.cjs'),misc=require('./lib/misc.cjs'),require$$11=require('ci-info');var hasRequiredDownloadPreviousBuild; + +function requireDownloadPreviousBuild () { + if (hasRequiredDownloadPreviousBuild) return downloadPreviousBuild.__module.exports; + hasRequiredDownloadPreviousBuild = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "downloadPreviousBuild", { + enumerable: true, + get: function() { + return downloadPreviousBuild; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1$1); + const _promises = require$$2; + const _trace = /*@__PURE__*/ index.__require(); + const _tarfs = require$$4; + const _nodezlib = /*#__PURE__*/ _interop_require_default(require$$5); + const _undici = /*#__PURE__*/ _interop_require_default(require$$1); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0); + const _dir = /*@__PURE__*/ dir.__require(); + const _fetchretry = /*@__PURE__*/ fetchRetry.__require(); + const _misc = /*@__PURE__*/ misc.__require(); + const _ciinfo = require$$11; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const GITHUB_CODELOAD_URL = 'https://codeload.github.com/sukkalab/ruleset.skk.moe/tar.gz/master'; + const GITLAB_CODELOAD_URL = 'https://gitlab.com/SukkaW/ruleset.skk.moe/-/archive/master/ruleset.skk.moe-master.tar.gz'; + const downloadPreviousBuild = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + if (_nodefs.default.existsSync(_dir.PUBLIC_DIR) && !(0, _misc.isDirectoryEmptySync)(_dir.PUBLIC_DIR)) { + console.log(_picocolors.default.blue('Public directory exists, skip downloading previous build')); + return; + } + // we uses actions/checkout to download the previous build now, so we should throw if the directory is empty + if (_ciinfo.isCI) { + throw new Error('CI environment detected, but public directory is empty'); + } + const tarGzUrl = await span.traceChildAsync('get tar.gz url', async ()=>{ + const resp = await (0, _fetchretry.requestWithLog)(GITHUB_CODELOAD_URL, { + method: 'HEAD' + }); + if (resp.statusCode !== 200) { + console.warn('Download previous build from GitHub failed! Status:', resp.statusCode); + console.warn('Switch to GitLab'); + return GITLAB_CODELOAD_URL; + } + return GITHUB_CODELOAD_URL; + }); + return span.traceChildAsync('download & extract previoud build', async ()=>{ + const respBody = _undici.default.pipeline(tarGzUrl, { + method: 'GET', + headers: { + 'User-Agent': 'curl/8.9.1', + // https://github.com/unjs/giget/issues/97 + // https://gitlab.com/gitlab-org/gitlab/-/commit/50c11f278d18fe1f3fb12eb595067216bb58ade2 + 'sec-fetch-mode': 'same-origin' + }, + // Allow redirects by default + maxRedirections: 5 + }, ({ statusCode, body })=>{ + if (statusCode !== 200) { + console.warn('Download previous build failed! Status:', statusCode); + if (statusCode === 404) { + throw new Error('Download previous build failed! 404'); + } + } + return body; + }).end(); + const pathPrefix = 'ruleset.skk.moe-master/'; + const gunzip = _nodezlib.default.createGunzip(); + const extract = (0, _tarfs.extract)(_dir.PUBLIC_DIR, { + ignore (_, header) { + if (header) { + if (header.type !== 'file' && header.type !== 'directory') { + return true; + } + if (header.type === 'file' && _nodepath.default.extname(header.name) === '.ts') { + return true; + } + } + return false; + }, + map (header) { + header.name = header.name.replace(pathPrefix, ''); + return header; + } + }); + return (0, _promises.pipeline)(respBody, gunzip, extract); + }); + }); + } (downloadPreviousBuild.__module, downloadPreviousBuild.__module.exports)); + return downloadPreviousBuild.__module.exports; +}exports.__require=requireDownloadPreviousBuild; \ No newline at end of file diff --git a/Dist/Build/index.cjs b/Dist/Build/index.cjs new file mode 100644 index 00000000..021c967b --- /dev/null +++ b/Dist/Build/index.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),index$1=require('./index2.cjs');var BuildExports = index$1.__require(); +const index = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(BuildExports);module.exports=index; \ No newline at end of file diff --git a/Dist/Build/index2.cjs b/Dist/Build/index2.cjs new file mode 100644 index 00000000..9b03deb2 --- /dev/null +++ b/Dist/Build/index2.cjs @@ -0,0 +1,107 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const index=require('../_virtual/index.cjs'),require$$1$2=require('node:process'),require$$1=require('node:os'),require$$1$1=require('node:fs'),downloadPreviousBuild=require('./download-previous-build2.cjs'),buildCommon=require('./build-common2.cjs'),buildRejectIpList=require('./build-reject-ip-list2.cjs'),buildAppleCdn=require('./build-apple-cdn2.cjs'),buildCdnDownloadConf=require('./build-cdn-download-conf2.cjs'),buildRejectDomainset=require('./build-reject-domainset2.cjs'),buildTelegramCidr=require('./build-telegram-cidr2.cjs'),buildChnCidr=require('./build-chn-cidr2.cjs'),buildSpeedtestDomainset=require('./build-speedtest-domainset2.cjs'),buildInternalReverseChnCidr=require('./build-internal-reverse-chn-cidr2.cjs'),buildDomesticDirectLanRulesetDnsMappingModule=require('./build-domestic-direct-lan-ruleset-dns-mapping-module2.cjs'),buildStreamService=require('./build-stream-service2.cjs'),buildSgmoduleRedirect=require('./build-sgmodule-redirect2.cjs'),buildSgmoduleAlwaysRealip=require('./build-sgmodule-always-realip2.cjs'),buildMicrosoftCdn=require('./build-microsoft-cdn2.cjs'),buildSspanelAppprofile=require('./build-sspanel-appprofile2.cjs'),buildPublic=require('./build-public2.cjs'),downloadMockAssets=require('./download-mock-assets2.cjs'),buildCloudmounterRules=require('./build-cloudmounter-rules2.cjs'),index$1=require('./trace/index.cjs'),buildDeprecateFiles=require('./build-deprecate-files2.cjs'),require$$0=require('node:path'),dir=require('./constants/dir.cjs');var hasRequiredBuild; + +function requireBuild () { + if (hasRequiredBuild) return index.__exports; + hasRequiredBuild = 1; + Object.defineProperty(index.__exports, "__esModule", { + value: true + }); + const _nodeprocess = /*#__PURE__*/ _interop_require_default(require$$1$2); + const _nodeos = /*#__PURE__*/ _interop_require_default(require$$1); + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1$1); + const _downloadpreviousbuild = downloadPreviousBuild.__require(); + const _buildcommon = buildCommon.__require(); + const _buildrejectiplist = buildRejectIpList.__require(); + const _buildapplecdn = buildAppleCdn.__require(); + const _buildcdndownloadconf = buildCdnDownloadConf.__require(); + const _buildrejectdomainset = buildRejectDomainset.__require(); + const _buildtelegramcidr = buildTelegramCidr.__require(); + const _buildchncidr = buildChnCidr.__require(); + const _buildspeedtestdomainset = buildSpeedtestDomainset.__require(); + const _buildinternalreversechncidr = buildInternalReverseChnCidr.__require(); + const _builddomesticdirectlanrulesetdnsmappingmodule = buildDomesticDirectLanRulesetDnsMappingModule.__require(); + const _buildstreamservice = buildStreamService.__require(); + const _buildsgmoduleredirect = buildSgmoduleRedirect.__require(); + const _buildsgmodulealwaysrealip = buildSgmoduleAlwaysRealip.__require(); + const _buildmicrosoftcdn = buildMicrosoftCdn.__require(); + const _buildsspanelappprofile = buildSspanelAppprofile.__require(); + const _buildpublic = buildPublic.__require(); + const _downloadmockassets = downloadMockAssets.__require(); + const _buildcloudmounterrules = buildCloudmounterRules.__require(); + const _trace = /*@__PURE__*/ index$1.__require(); + const _builddeprecatefiles = buildDeprecateFiles.__require(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _dir = /*@__PURE__*/ dir.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + _nodeprocess.default.on('uncaughtException', (error)=>{ + console.error('Uncaught exception:', error); + _nodeprocess.default.exit(1); + }); + _nodeprocess.default.on('unhandledRejection', (reason)=>{ + console.error('Unhandled rejection:', reason); + _nodeprocess.default.exit(1); + }); + const buildFinishedLock = _nodepath.default.join(_dir.ROOT_DIR, '.BUILD_FINISHED'); + (async ()=>{ + console.log('Version:', _nodeprocess.default.version); + console.log(`OS: ${_nodeos.default.type()} ${_nodeos.default.release()} ${_nodeos.default.arch()}`); + console.log(`Node.js: ${_nodeprocess.default.versions.node}`); + console.log(`V8: ${_nodeprocess.default.versions.v8}`); + const cpus = _nodeos.default.cpus().reduce((o, cpu)=>{ + o[cpu.model] = (o[cpu.model] || 0) + 1; + return o; + }, {}); + console.log(`CPU: ${Object.keys(cpus).map((key)=>`${key} x ${cpus[key]}`).join('\n')}`); + console.log(`Memory: ${_nodeos.default.totalmem() / (1024 * 1024)} MiB`); + const rootSpan = (0, _trace.createSpan)('root'); + if (_nodefs.default.existsSync(buildFinishedLock)) { + _nodefs.default.unlinkSync(buildFinishedLock); + } + try { + await import('why-is-node-running'); + const downloadPreviousBuildPromise = (0, _downloadpreviousbuild.downloadPreviousBuild)(rootSpan); + const buildCommonPromise = downloadPreviousBuildPromise.then(()=>(0, _buildcommon.buildCommon)(rootSpan)); + await Promise.all([ + downloadPreviousBuildPromise, + buildCommonPromise, + downloadPreviousBuildPromise.then(()=>(0, _buildrejectiplist.buildRejectIPList)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildapplecdn.buildAppleCdn)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildcdndownloadconf.buildCdnDownloadConf)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildrejectdomainset.buildRejectDomainSet)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildtelegramcidr.buildTelegramCIDR)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildchncidr.buildChnCidr)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildspeedtestdomainset.buildSpeedtestDomainSet)(rootSpan)), + (0, _buildinternalreversechncidr.buildInternalReverseChnCIDR)(rootSpan), + downloadPreviousBuildPromise.then(()=>(0, _builddomesticdirectlanrulesetdnsmappingmodule.buildDomesticRuleset)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildsgmoduleredirect.buildRedirectModule)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildsgmodulealwaysrealip.buildAlwaysRealIPModule)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildstreamservice.buildStreamService)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildmicrosoftcdn.buildMicrosoftCdn)(rootSpan)), + Promise.all([ + downloadPreviousBuildPromise, + buildCommonPromise + ]).then(()=>(0, _buildsspanelappprofile.buildSSPanelUIMAppProfile)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildcloudmounterrules.buildCloudMounterRules)(rootSpan)), + (0, _downloadmockassets.downloadMockAssets)(rootSpan) + ]); + await (0, _builddeprecatefiles.buildDeprecateFiles)(rootSpan); + await (0, _buildpublic.buildPublic)(rootSpan); + rootSpan.stop(); + (0, _trace.printTraceResult)(rootSpan.traceResult); + // write a file to demonstrate that the build is finished + _nodefs.default.writeFileSync(buildFinishedLock, 'BUILD_FINISHED\n'); + // Finish the build to avoid leaking timer/fetch ref + await (0, _trace.whyIsNodeRunning)(); + _nodeprocess.default.exit(0); + } catch (e) { + console.error('Something went wrong!'); + console.trace(e); + _nodeprocess.default.exit(1); + } + })(); + return index.__exports; +}exports.__require=requireBuild; \ No newline at end of file diff --git a/Dist/Build/lib/append-array-in-place.cjs b/Dist/Build/lib/append-array-in-place.cjs new file mode 100644 index 00000000..313df8ec --- /dev/null +++ b/Dist/Build/lib/append-array-in-place.cjs @@ -0,0 +1,46 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const appendArrayInPlace=require('../../_virtual/append-array-in-place.cjs');var hasRequiredAppendArrayInPlace; + +function requireAppendArrayInPlace () { + if (hasRequiredAppendArrayInPlace) return appendArrayInPlace.__exports; + hasRequiredAppendArrayInPlace = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + appendArrayInPlace: function() { + return appendArrayInPlace; + }, + appendArrayInPlaceCurried: function() { + return appendArrayInPlaceCurried; + } + }); + const MAX_BLOCK_SIZE = 65535; // max parameter array size for use in Webkit + function appendArrayInPlace(dest, source) { + let offset = 0; + let itemsLeft = source.length; + if (itemsLeft <= MAX_BLOCK_SIZE) { + // eslint-disable-next-line prefer-spread -- performance + dest.push.apply(dest, source); + } else { + while(itemsLeft > 0){ + const pushCount = itemsLeft > MAX_BLOCK_SIZE ? MAX_BLOCK_SIZE : itemsLeft; + const subSource = source.slice(offset, offset + pushCount); + // eslint-disable-next-line prefer-spread -- performance + dest.push.apply(dest, subSource); + itemsLeft -= pushCount; + offset += pushCount; + } + } + return dest; + } + const appendArrayInPlaceCurried = (dest)=>(source)=>appendArrayInPlace(dest, source); + } (appendArrayInPlace.__exports)); + return appendArrayInPlace.__exports; +}exports.__require=requireAppendArrayInPlace; \ No newline at end of file diff --git a/Dist/Build/lib/cache-filesystem.cjs b/Dist/Build/lib/cache-filesystem.cjs new file mode 100644 index 00000000..beb1b39b --- /dev/null +++ b/Dist/Build/lib/cache-filesystem.cjs @@ -0,0 +1,134 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const cacheFilesystem=require('../../_virtual/cache-filesystem.cjs'),require$$0=require('better-sqlite3'),require$$1$1=require('node:os'),require$$0$2=require('node:path'),require$$1=require('node:fs'),require$$0$1=require('picocolors'),require$$3=require('foxts/fast-string-array-join'),require$$6=require('node:perf_hooks');var hasRequiredCacheFilesystem; + +function requireCacheFilesystem () { + if (hasRequiredCacheFilesystem) return cacheFilesystem.__exports; + hasRequiredCacheFilesystem = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + Cache: function() { + return Cache; + }, + deserializeArray: function() { + return deserializeArray; + }, + serializeArray: function() { + return serializeArray; + } + }); + const _bettersqlite3 = /*#__PURE__*/ _interop_require_default(require$$0); + const _nodeos = /*#__PURE__*/ _interop_require_default(require$$1$1); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$2); + const _nodefs = require$$1; + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _faststringarrayjoin = require$$3; + const _nodeperf_hooks = require$$6; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + class Cache { + db; + /** Time before deletion */ tbd = 60 * 1000; + /** SQLite file path */ cachePath; + /** Table name */ tableName; + type; + statement; + constructor({ cachePath = _nodepath.default.join(_nodeos.default.tmpdir() || '/tmp', 'hdc'), tbd, tableName = 'cache', type } = {}){ + const start = _nodeperf_hooks.performance.now(); + this.cachePath = cachePath; + (0, _nodefs.mkdirSync)(this.cachePath, { + recursive: true + }); + if (tbd != null) this.tbd = tbd; + this.tableName = tableName; + if (type) { + this.type = type; + } else { + // @ts-expect-error -- fallback type + this.type = 'string'; + } + const db = (0, _bettersqlite3.default)(_nodepath.default.join(this.cachePath, 'cache.db')); + db.pragma('journal_mode = WAL'); + db.pragma('synchronous = normal'); + db.pragma('temp_store = memory'); + db.pragma('optimize'); + db.prepare(`CREATE TABLE IF NOT EXISTS ${this.tableName} (key TEXT PRIMARY KEY, value ${this.type === 'string' ? 'TEXT' : 'BLOB'}, ttl REAL NOT NULL);`).run(); + db.prepare(`CREATE INDEX IF NOT EXISTS cache_ttl ON ${this.tableName} (ttl);`).run(); + /** cache stmt */ this.statement = { + updateTtl: db.prepare(`UPDATE ${this.tableName} SET ttl = ? WHERE key = ?;`), + del: db.prepare(`DELETE FROM ${this.tableName} WHERE key = ?`), + insert: db.prepare(`INSERT INTO ${this.tableName} (key, value, ttl) VALUES ($key, $value, $valid) ON CONFLICT(key) DO UPDATE SET value = $value, ttl = $valid`), + get: db.prepare(`SELECT ttl, value FROM ${this.tableName} WHERE key = ? LIMIT 1`) + }; + const date = new Date(); + // perform purge on startup + // ttl + tbd < now => ttl < now - tbd + const now = date.getTime() - this.tbd; + db.prepare(`DELETE FROM ${this.tableName} WHERE ttl < ?`).run(now); + this.db = db; + const dateString = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`; + const lastVaccum = this.get('__LAST_VACUUM'); + if (lastVaccum === undefined || lastVaccum !== dateString && date.getUTCDay() === 6) { + console.log(_picocolors.default.magenta('[cache] vacuuming')); + this.set('__LAST_VACUUM', dateString, 10 * 365 * 60 * 60 * 24 * 1000); + this.db.exec('VACUUM;'); + } + const end = _nodeperf_hooks.performance.now(); + console.log(`${_picocolors.default.gray(`[${(end - start).toFixed(3)}ns]`)} cache initialized from ${this.tableName} @ ${this.cachePath}`); + } + set(key, value, ttl = 60 * 1000) { + const valid = Date.now() + ttl; + this.statement.insert.run({ + $key: key, + key, + $value: value, + value, + $valid: valid, + valid + }); + } + get(key) { + const rv = this.statement.get.get(key); + if (!rv) return null; + if (rv.ttl < Date.now()) { + this.del(key); + return null; + } + if (rv.value == null) { + this.del(key); + return null; + } + return rv.value; + } + updateTtl(key, ttl) { + this.statement.updateTtl.run(Date.now() + ttl, key); + } + del(key) { + this.statement.del.run(key); + } + destroy() { + this.db.close(); + } + deleteTable(tableName) { + this.db.exec(`DROP TABLE IF EXISTS ${tableName};`); + } + } + // process.on('exit', () => { + // fsFetchCache.destroy(); + // }); + const separator = '\u0000'; + const serializeArray = (arr)=>(0, _faststringarrayjoin.fastStringArrayJoin)(arr, separator); + const deserializeArray = (str)=>str.split(separator); + } (cacheFilesystem.__exports)); + return cacheFilesystem.__exports; +}exports.__require=requireCacheFilesystem; \ No newline at end of file diff --git a/Dist/Build/lib/create-file.cjs b/Dist/Build/lib/create-file.cjs new file mode 100644 index 00000000..b1cc8448 --- /dev/null +++ b/Dist/Build/lib/create-file.cjs @@ -0,0 +1,114 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const createFile=require('../../_virtual/create-file.cjs'),require$$0=require('foxts/async-write-to-stream'),require$$3=require('foxts/fast-string-array-join'),require$$1=require('node:fs'),require$$0$1=require('picocolors'),fetchTextByLine=require('./fetch-text-by-line.cjs'),misc=require('./misc.cjs');var hasRequiredCreateFile; + +function requireCreateFile () { + if (hasRequiredCreateFile) return createFile.__exports; + hasRequiredCreateFile = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + compareAndWriteFile: function() { + return compareAndWriteFile; + }, + fileEqual: function() { + return fileEqual; + } + }); + const _asyncwritetostream = require$$0; + const _faststringarrayjoin = require$$3; + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _misc = /*@__PURE__*/ misc.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + async function fileEqual(linesA, source) { + if (linesA.length === 0) { + return false; + } + const linesABound = linesA.length - 1; + let index = -1; + for await (const lineB of source){ + index++; + if (index > linesABound) { + return index === linesA.length && lineB.length === 0; + } + const lineA = linesA[index]; + if (lineA.length === 0) { + if (lineB.length === 0) { + continue; + } + // lineA is empty but lineB is not + return false; + } + // now lineA can not be empty + if (lineB.length === 0) { + // lineB is empty but lineA is not + return false; + } + // now both lines can not be empty + const firstCharA = lineA.charCodeAt(0); + const firstCharB = lineB.charCodeAt(0); + if (firstCharA !== firstCharB) { + return false; + } + // now firstCharA is equal to firstCharB, we only need to check the first char + if (firstCharA === 35 /* # */ ) { + continue; + } + // adguard conf + if (firstCharA === 33 /* ! */ ) { + continue; + } + if (firstCharA === 47 /* / */ && lineA[1] === '/' && lineB[1] === '/' && lineA[3] === '#' && lineB[3] === '#') { + continue; + } + if (lineA !== lineB) { + return false; + } + } + // The file becomes larger + return !(index < linesABound); + } + async function compareAndWriteFile(span, linesA, filePath) { + const linesALen = linesA.length; + const isEqual = await span.traceChildAsync(`compare ${filePath}`, async ()=>{ + if (_nodefs.default.existsSync(filePath)) { + return fileEqual(linesA, (0, _fetchtextbyline.readFileByLine)(filePath)); + } + console.log(`${filePath} does not exists, writing...`); + return false; + }); + if (isEqual) { + console.log(_picocolors.default.gray(_picocolors.default.dim(`same content, bail out writing: ${filePath}`))); + return; + } + await span.traceChildAsync(`writing ${filePath}`, async ()=>{ + // The default highwater mark is normally 16384, + // So we make sure direct write to file if the content is + // most likely less than 500 lines + if (linesALen < 500) { + return (0, _misc.writeFile)(filePath, (0, _faststringarrayjoin.fastStringArrayJoin)(linesA, '\n') + '\n'); + } + const writeStream = _nodefs.default.createWriteStream(filePath); + for(let i = 0; i < linesALen; i++){ + const p = (0, _asyncwritetostream.asyncWriteToStream)(writeStream, linesA[i] + '\n'); + // eslint-disable-next-line no-await-in-loop -- stream high water mark + if (p) await p; + } + writeStream.end(); + }); + } + } (createFile.__exports)); + return createFile.__exports; +}exports.__require=requireCreateFile; \ No newline at end of file diff --git a/Dist/Build/lib/fetch-assets.cjs b/Dist/Build/lib/fetch-assets.cjs new file mode 100644 index 00000000..6864fbdf --- /dev/null +++ b/Dist/Build/lib/fetch-assets.cjs @@ -0,0 +1,81 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const fetchAssets=require('../../_virtual/fetch-assets.cjs'),require$$0=require('picocolors'),fetchRetry=require('./fetch-retry.cjs'),require$$2=require('foxts/wait'),require$$6=require('foxts/guard'),textLineTransformStream=require('./text-line-transform-stream.cjs'),processLine=require('./process-line.cjs');var hasRequiredFetchAssets; + +function requireFetchAssets () { + if (hasRequiredFetchAssets) return fetchAssets.__exports; + hasRequiredFetchAssets = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + CustomAbortError: function() { + return CustomAbortError; + }, + fetchAssets: function() { + return fetchAssets; + } + }); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0); + const _fetchretry = /*@__PURE__*/ fetchRetry.__require(); + const _wait = require$$2; + const _guard = require$$6; + const _textlinetransformstream = /*@__PURE__*/ textLineTransformStream.__require(); + const _processline = /*@__PURE__*/ processLine.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + class CustomAbortError extends Error { + name = 'AbortError'; + digest = 'AbortError'; + } + const reusedCustomAbortError = new CustomAbortError(); + async function fetchAssets(url, fallbackUrls, processLine = false) { + const controller = new AbortController(); + const createFetchFallbackPromise = async (url, index)=>{ + if (index >= 0) { + // Most assets can be downloaded within 250ms. To avoid wasting bandwidth, we will wait for 500ms before downloading from the fallback URL. + try { + await (0, _wait.waitWithAbort)(50 + (index + 1) * 100, controller.signal); + } catch { + console.log(_picocolors.default.gray('[fetch cancelled early]'), _picocolors.default.gray(url)); + throw reusedCustomAbortError; + } + } + if (controller.signal.aborted) { + console.log(_picocolors.default.gray('[fetch cancelled]'), _picocolors.default.gray(url)); + throw reusedCustomAbortError; + } + const res = await (0, _fetchretry.$$fetch)(url, { + signal: controller.signal, + ..._fetchretry.defaultRequestInit + }); + let stream = (0, _guard.nullthrow)(res.body).pipeThrough(new TextDecoderStream()).pipeThrough(new _textlinetransformstream.TextLineStream()); + if (processLine) { + stream = stream.pipeThrough(new _processline.ProcessLineStream()); + } + const arr = await Array.fromAsync(stream); + if (arr.length < 1) { + throw new _fetchretry.ResponseError(res, url, 'empty response w/o 304'); + } + controller.abort(); + return arr; + }; + if (!fallbackUrls || fallbackUrls.length === 0) { + return createFetchFallbackPromise(url, -1); + } + return Promise.any([ + createFetchFallbackPromise(url, -1), + ...fallbackUrls.map(createFetchFallbackPromise) + ]); + } + } (fetchAssets.__exports)); + return fetchAssets.__exports; +}exports.__require=requireFetchAssets; \ No newline at end of file diff --git a/Dist/Build/lib/fetch-retry.cjs b/Dist/Build/lib/fetch-retry.cjs new file mode 100644 index 00000000..12bc2a5e --- /dev/null +++ b/Dist/Build/lib/fetch-retry.cjs @@ -0,0 +1,235 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const fetchRetry=require('../../_virtual/fetch-retry.cjs'),require$$0$1=require('picocolors'),require$$1=require('undici'),require$$2=require('undici-cache-store-better-sqlite3'),require$$1$2=require('node:util'),require$$0=require('node:path'),require$$1$1=require('node:fs'),dir=require('../constants/dir.cjs');var hasRequiredFetchRetry; + +function requireFetchRetry () { + if (hasRequiredFetchRetry) return fetchRetry.__exports; + hasRequiredFetchRetry = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + $$fetch: function() { + return $$fetch; + }, + ResponseError: function() { + return ResponseError; + }, + defaultRequestInit: function() { + return defaultRequestInit; + }, + requestWithLog: function() { + return requestWithLog; + } + }); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _undici = /*#__PURE__*/ _interop_require_wildcard(require$$1); + const _undicicachestorebettersqlite3 = require$$2; + const _nodeutil = require$$1$2; + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1$1); + const _dir = /*@__PURE__*/ dir.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); + } + function _interop_require_wildcard(obj, nodeInterop) { + if (obj && obj.__esModule) { + return obj; + } + if (obj === null || typeof obj !== "object" && typeof obj !== "function") { + return { + default: obj + }; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = { + __proto__: null + }; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; + } + if (!_nodefs.default.existsSync(_dir.CACHE_DIR)) { + _nodefs.default.mkdirSync(_dir.CACHE_DIR, { + recursive: true + }); + } + const agent = new _undici.Agent({ + allowH2: true + }); + (0, _undici.setGlobalDispatcher)(agent.compose(_undici.interceptors.dns({ + // disable IPv6 + dualStack: false, + affinity: 4 + }), _undici.interceptors.retry({ + maxRetries: 5, + minTimeout: 500, + maxTimeout: 10 * 1000, + // TODO: this part of code is only for allow more errors to be retried by default + // This should be removed once https://github.com/nodejs/undici/issues/3728 is implemented + retry (err, { state, opts }, cb) { + const errorCode = 'code' in err ? err.code : undefined; + // Any code that is not a Undici's originated and allowed to retry + if (errorCode === 'ERR_UNESCAPED_CHARACTERS' || err.message === 'Request path contains unescaped characters' || err.name === 'AbortError') { + return cb(err); + } + const statusCode = 'statusCode' in err && typeof err.statusCode === 'number' ? err.statusCode : null; + // bail out if the status code matches one of the following + if (statusCode != null && (statusCode === 401 // Unauthorized, should check credentials instead of retrying + || statusCode === 403 // Forbidden, should check permissions instead of retrying + || statusCode === 404 // Not Found, should check URL instead of retrying + || statusCode === 405 // Method Not Allowed, should check method instead of retrying + )) { + return cb(err); + } + // if (errorCode === 'UND_ERR_REQ_RETRY') { + // return cb(err); + // } + const { maxRetries = 5, minTimeout = 500, maxTimeout = 10 * 1000, timeoutFactor = 2, methods = [ + 'GET', + 'HEAD', + 'OPTIONS', + 'PUT', + 'DELETE', + 'TRACE' + ] } = opts.retryOptions || {}; + // If we reached the max number of retries + if (state.counter > maxRetries) { + return cb(err); + } + // If a set of method are provided and the current method is not in the list + if (Array.isArray(methods) && !methods.includes(opts.method)) { + return cb(err); + } + const headers = 'headers' in err && typeof err.headers === 'object' ? err.headers : undefined; + const retryAfterHeader = headers?.['retry-after']; + let retryAfter = -1; + if (retryAfterHeader) { + retryAfter = Number(retryAfterHeader); + retryAfter = Number.isNaN(retryAfter) ? calculateRetryAfterHeader(retryAfterHeader) : retryAfter * 1e3; // Retry-After is in seconds + } + const retryTimeout = retryAfter > 0 ? Math.min(retryAfter, maxTimeout) : Math.min(minTimeout * timeoutFactor ** (state.counter - 1), maxTimeout); + console.log('[fetch retry]', 'schedule retry', { + statusCode, + retryTimeout, + errorCode, + url: opts.origin + }); + // eslint-disable-next-line sukka/prefer-timer-id -- won't leak + setTimeout(()=>cb(null), retryTimeout); + } + }), _undici.interceptors.redirect({ + maxRedirections: 5 + }), _undici.interceptors.cache({ + store: new _undicicachestorebettersqlite3.BetterSqlite3CacheStore({ + location: _nodepath.default.join(_dir.CACHE_DIR, 'undici-better-sqlite3-cache-store.db'), + maxEntrySize: 1024 * 1024 * 100 // 100 MiB + }) + }))); + function calculateRetryAfterHeader(retryAfter) { + const current = Date.now(); + return new Date(retryAfter).getTime() - current; + } + class ResponseError extends Error { + res; + url; + code; + statusCode; + constructor(res, url, ...args){ + const statusCode = 'statusCode' in res ? res.statusCode : res.status; + super('HTTP ' + statusCode + ' ' + args.map((_)=>(0, _nodeutil.inspect)(_)).join(' ')), this.res = res, this.url = url; + if ('captureStackTrace' in Error) { + Error.captureStackTrace(this, ResponseError); + } + // eslint-disable-next-line sukka/unicorn/custom-error-definition -- deliberatly use previous name + this.name = this.constructor.name; + this.res = res; + this.code = statusCode; + this.statusCode = statusCode; + } + } + const defaultRequestInit = { + headers: { + 'User-Agent': 'curl/8.9.1 (https://github.com/SukkaW/Surge)' + } + }; + async function $$fetch(url, init) { + try { + const res = await _undici.default.fetch(url, init); + if (res.status >= 400) { + throw new ResponseError(res, url); + } + if (!(res.status >= 200 && res.status <= 299) && res.status !== 304) { + throw new ResponseError(res, url); + } + return res; + } catch (err) { + if (typeof err === 'object' && err !== null && 'name' in err) { + if (err.name === 'AbortError' || 'digest' in err && err.digest === 'AbortError') { + console.log(_picocolors.default.gray('[fetch abort]'), url); + } + } else { + console.log(_picocolors.default.gray('[fetch fail]'), url, { + name: err.name + }, err); + } + throw err; + } + } + async function requestWithLog(url, opt) { + try { + const res = await _undici.default.request(url, opt); + if (res.statusCode >= 400) { + throw new ResponseError(res, url); + } + if (!(res.statusCode >= 200 && res.statusCode <= 299) && res.statusCode !== 304) { + throw new ResponseError(res, url); + } + return res; + } catch (err) { + if (typeof err === 'object' && err !== null && 'name' in err) { + if (err.name === 'AbortError' || 'digest' in err && err.digest === 'AbortError') { + console.log(_picocolors.default.gray('[fetch abort]'), url); + } + } else { + console.log(_picocolors.default.gray('[fetch fail]'), url, { + name: err.name + }, err); + } + throw err; + } + } + } (fetchRetry.__exports)); + return fetchRetry.__exports; +}exports.__require=requireFetchRetry; \ No newline at end of file diff --git a/Dist/Build/lib/fetch-text-by-line.cjs b/Dist/Build/lib/fetch-text-by-line.cjs new file mode 100644 index 00000000..ad322880 --- /dev/null +++ b/Dist/Build/lib/fetch-text-by-line.cjs @@ -0,0 +1,79 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const fetchTextByLine=require('../../_virtual/fetch-text-by-line.cjs'),require$$1=require('node:fs'),require$$1$1=require('node:readline'),textLineTransformStream=require('./text-line-transform-stream.cjs'),require$$0=require('node:stream/web'),processLine=require('./process-line.cjs'),fetchRetry=require('./fetch-retry.cjs'),require$$6=require('foxts/guard');var hasRequiredFetchTextByLine; + +function requireFetchTextByLine () { + if (hasRequiredFetchTextByLine) return fetchTextByLine.__exports; + hasRequiredFetchTextByLine = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + createReadlineInterfaceFromResponse: function() { + return createReadlineInterfaceFromResponse; + }, + fetchRemoteTextByLine: function() { + return fetchRemoteTextByLine; + }, + readFileByLine: function() { + return readFileByLine; + }, + readFileIntoProcessedArray: function() { + return readFileIntoProcessedArray; + } + }); + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1); + const _nodereadline = /*#__PURE__*/ _interop_require_default(require$$1$1); + const _textlinetransformstream = /*@__PURE__*/ textLineTransformStream.__require(); + const _web = require$$0; + const _processline = /*@__PURE__*/ processLine.__require(); + const _fetchretry = /*@__PURE__*/ fetchRetry.__require(); + const _guard = require$$6; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function readFileByLine(file) { + return _nodereadline.default.createInterface({ + input: _nodefs.default.createReadStream(file /* , { encoding: 'utf-8' } */ ), + crlfDelay: Infinity + }); + } + const createReadlineInterfaceFromResponse = (resp, processLine = false)=>{ + (0, _guard.invariant)(resp.body, 'Failed to fetch remote text'); + if ('bodyUsed' in resp && resp.bodyUsed) { + throw new Error('Body has already been consumed.'); + } + let webStream; + if ('pipeThrough' in resp.body) { + webStream = resp.body; + } else { + throw new TypeError('Invalid response body!'); + } + const resultStream = webStream.pipeThrough(new _web.TextDecoderStream()).pipeThrough(new _textlinetransformstream.TextLineStream()); + if (processLine) { + return resultStream.pipeThrough(new _processline.ProcessLineStream()); + } + return resultStream; + }; + function fetchRemoteTextByLine(url, processLine = false) { + return (0, _fetchretry.$$fetch)(url).then((resp)=>createReadlineInterfaceFromResponse(resp, processLine)); + } + async function readFileIntoProcessedArray(file/* | FileHandle */ ) { + const results = []; + for await (const line of readFileByLine(file)){ + if ((0, _processline.processLine)(line)) { + results.push(line); + } + } + return results; + } + } (fetchTextByLine.__exports)); + return fetchTextByLine.__exports; +}exports.__require=requireFetchTextByLine; \ No newline at end of file diff --git a/Dist/Build/lib/fs-memo.cjs b/Dist/Build/lib/fs-memo.cjs new file mode 100644 index 00000000..271a02cf --- /dev/null +++ b/Dist/Build/lib/fs-memo.cjs @@ -0,0 +1,89 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const fsMemo=require('../../_virtual/fs-memo.cjs'),require$$0$1=require('node:path'),require$$11=require('ci-info'),require$$0=require('picocolors'),cacheFilesystem=require('./cache-filesystem.cjs'),require$$4=require('foxts/serialized-memo'),dir=require('../constants/dir.cjs');var hasRequiredFsMemo; + +function requireFsMemo () { + if (hasRequiredFsMemo) return fsMemo.__exports; + hasRequiredFsMemo = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + cache: function() { + return cache; + }, + cachedOnlyFail: function() { + return cachedOnlyFail; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _ciinfo = require$$11; + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0); + const _cachefilesystem = /*@__PURE__*/ cacheFilesystem.__require(); + const _serializedmemo = require$$4; + const _dir = /*@__PURE__*/ dir.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const fsMemoCache = new _cachefilesystem.Cache({ + cachePath: _nodepath.default.join(_dir.ROOT_DIR, '.cache'), + tableName: 'fs_memo_cache' + }); + const fsMemoCacheProvider = { + has (key) { + return fsMemoCache.get(key) !== null; + }, + delete () { + // noop + }, + get (key) { + return fsMemoCache.get(key) ?? undefined; + }, + set (key, value, ttl) { + fsMemoCache.set(key, value, ttl); + }, + updateTtl (key, ttl) { + fsMemoCache.updateTtl(key, ttl); + } + }; + const TTL = _ciinfo.isCI ? 1.5 * 86400 * 1000 : 7 * 86400 * 1000; + const cache = (0, _serializedmemo.createMemoize)(fsMemoCacheProvider, { + defaultTtl: TTL, + onCacheMiss (key, { humanReadableName, isUseCachedIfFail }) { + const cacheName = _picocolors.default.gray(humanReadableName); + if (isUseCachedIfFail) { + console.log(_picocolors.default.red('[fail] and no cache, throwing'), cacheName); + } else { + console.log(_picocolors.default.yellow('[cache] miss'), cacheName); + } + }, + onCacheUpdate (key, { humanReadableName, isUseCachedIfFail }) { + const cacheName = _picocolors.default.gray(humanReadableName); + if (isUseCachedIfFail) { + console.log(_picocolors.default.gray('[cache] update'), cacheName); + } + }, + onCacheHit (key, { humanReadableName, isUseCachedIfFail }) { + const cacheName = _picocolors.default.gray(humanReadableName); + if (isUseCachedIfFail) { + console.log(_picocolors.default.yellow('[fail] try cache'), cacheName); + } else { + console.log(_picocolors.default.green('[cache] hit'), cacheName); + } + } + }); + const cachedOnlyFail = (0, _serializedmemo.createMemoize)(fsMemoCacheProvider, { + defaultTtl: TTL, + onlyUseCachedIfFail: true + }); // export const cache = createCache(false); + // export const cachedOnlyFail = createCache(true); + } (fsMemo.__exports)); + return fsMemo.__exports; +}exports.__require=requireFsMemo; \ No newline at end of file diff --git a/Dist/Build/lib/get-phishing-domains.cjs b/Dist/Build/lib/get-phishing-domains.cjs new file mode 100644 index 00000000..aee779c9 --- /dev/null +++ b/Dist/Build/lib/get-phishing-domains.cjs @@ -0,0 +1,376 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const getPhishingDomains=require('../../_virtual/get-phishing-domains.cjs'),hosts=require('./parse-filter/hosts.cjs'),domainlists=require('./parse-filter/domainlists.cjs'),require$$5=require('tldts-experimental'),index=require('../trace/index.cjs'),appendArrayInPlace=require('./append-array-in-place.cjs'),rejectDataSource=require('../constants/reject-data-source.cjs'),looseTldtsOpt=require('../constants/loose-tldts-opt.cjs'),require$$0=require('picocolors'),require$$3=require('foxts/retrie'),cacheFilesystem=require('./cache-filesystem.cjs'),fsMemo=require('./fs-memo.cjs'),require$$11=require('ci-info');var hasRequiredGetPhishingDomains; + +function requireGetPhishingDomains () { + if (hasRequiredGetPhishingDomains) return getPhishingDomains.__module.exports; + hasRequiredGetPhishingDomains = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + calcDomainAbuseScore: function() { + return calcDomainAbuseScore; + }, + getPhishingDomains: function() { + return getPhishingDomains; + } + }); + const _hosts = /*@__PURE__*/ hosts.__require(); + const _domainlists = /*@__PURE__*/ domainlists.__require(); + const _tldtsexperimental = /*#__PURE__*/ _interop_require_wildcard(require$$5); + const _trace = /*@__PURE__*/ index.__require(); + const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require(); + const _rejectdatasource = /*@__PURE__*/ rejectDataSource.__require(); + const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.__require(); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0); + const _retrie = require$$3; + const _cachefilesystem = /*@__PURE__*/ cacheFilesystem.__require(); + const _fsmemo = /*@__PURE__*/ fsMemo.__require(); + const _ciinfo = require$$11; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); + } + function _interop_require_wildcard(obj, nodeInterop) { + if (obj && obj.__esModule) { + return obj; + } + if (obj === null || typeof obj !== "object" && typeof obj !== "function") { + return { + default: obj + }; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = { + __proto__: null + }; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; + } + const BLACK_TLD = new Set([ + 'accountant', + 'art', + 'autos', + 'bar', + 'beauty', + 'bid', + 'bio', + 'biz', + 'bond', + 'business', + 'buzz', + 'cc', + 'cf', + 'cfd', + 'click', + 'cloud', + 'club', + 'cn', + 'codes', + 'co.uk', + 'co.in', + 'com.br', + 'com.cn', + 'com.pl', + 'com.vn', + 'cool', + 'cricket', + 'cyou', + 'date', + 'design', + 'digital', + 'download', + 'faith', + 'fit', + 'fun', + 'ga', + 'gd', + 'gives', + 'gq', + 'group', + 'host', + 'icu', + 'id', + 'info', + 'ink', + 'lat', + 'life', + 'live', + 'link', + 'loan', + 'lol', + 'ltd', + 'me', + 'men', + 'ml', + 'mobi', + 'mom', + 'monster', + 'net.pl', + 'one', + 'online', + 'party', + 'pro', + 'pl', + 'pw', + 'racing', + 'rest', + 'review', + 'rf.gd', + 'sa.com', + 'sbs', + 'science', + 'shop', + 'site', + 'skin', + 'space', + 'store', + 'stream', + 'su', + 'surf', + 'tech', + 'tk', + 'tokyo', + 'top', + 'trade', + 'vip', + 'vn', + 'webcam', + 'website', + 'win', + 'xyz', + 'za.com' + ]); + const WHITELIST_MAIN_DOMAINS = new Set([ + // 'w3s.link', // ipfs gateway + // 'dweb.link', // ipfs gateway + // 'nftstorage.link', // ipfs gateway + 'fleek.cool', + 'flk-ipfs.xyz', + 'business.site', + 'page.link', + // 'notion.site', + // 'vercel.app', + 'gitbook.io', + 'zendesk.com', + 'ipfs.eth.aragon.network', + 'wordpress.com' + ]); + const leathalKeywords = (0, _retrie.createRetrieKeywordFilter)([ + 'vinted-', + 'inpost-pl', + 'vlnted-' + ]); + const sensitiveKeywords = (0, _retrie.createRetrieKeywordFilter)([ + '.amazon-', + '-amazon', + 'fb-com', + 'facebook-com', + '-facebook', + 'facebook-', + 'focebaak', + '.facebook.', + 'metamask', + 'www.apple', + '-coinbase', + 'coinbase-', + 'booking-com', + 'booking.com-', + 'booking-eu', + 'vinted-', + 'inpost-pl', + 'login.microsoft', + 'login-microsoft', + 'microsoftonline', + 'google.com-', + 'minecraft', + 'staemco', + 'oferta' + ]); + const lowKeywords = (0, _retrie.createRetrieKeywordFilter)([ + 'transactions-', + 'payment', + 'wallet', + '-transactions', + '-faceb', + '.faceb', + 'facebook', + 'virus-', + 'icloud-', + 'apple-', + '-roblox', + '-co-jp', + 'customer.', + 'customer-', + '.www-', + '.www.', + '.www2', + 'instagram', + 'microsof', + 'passwordreset', + '.google-', + 'recover', + 'banking' + ]); + const processPhihsingDomains = (0, _fsmemo.cache)(function processPhihsingDomains(domainArr) { + const domainCountMap = new Map(); + const domainScoreMap = {}; + let line = ''; + let tld = ''; + let apexDomain = ''; + let subdomain = ''; + // const set = new Set(); + // let duplicateCount = 0; + for(let i = 0, len = domainArr.length; i < len; i++){ + line = domainArr[i]; + // if (set.has(line)) { + // duplicateCount++; + // } else { + // set.add(line); + // } + const parsed = _tldtsexperimental.parse(line, _loosetldtsopt.loosTldOptWithPrivateDomains); + if (parsed.isPrivate) { + continue; + } + tld = parsed.publicSuffix; + apexDomain = parsed.domain; + if (!tld) { + console.log(_picocolors.default.yellow('[phishing domains] E0001'), 'missing tld', { + line, + tld + }); + continue; + } + if (!apexDomain) { + console.log(_picocolors.default.yellow('[phishing domains] E0002'), 'missing domain', { + line, + apexDomain + }); + continue; + } + domainCountMap.set(apexDomain, domainCountMap.has(apexDomain) ? domainCountMap.get(apexDomain) + 1 : 1); + if (!(apexDomain in domainScoreMap)) { + domainScoreMap[apexDomain] = 0; + if (BLACK_TLD.has(tld)) { + domainScoreMap[apexDomain] += 3; + } else if (tld.length > 6) { + domainScoreMap[apexDomain] += 2; + } + if (apexDomain.length >= 18) { + domainScoreMap[apexDomain] += 0.5; + } + } + subdomain = parsed.subdomain; + if (subdomain && !WHITELIST_MAIN_DOMAINS.has(apexDomain)) { + domainScoreMap[apexDomain] += calcDomainAbuseScore(subdomain, line); + } + } + domainCountMap.forEach((count, apexDomain)=>{ + if (// !WHITELIST_MAIN_DOMAINS.has(apexDomain) + domainScoreMap[apexDomain] >= 24 || domainScoreMap[apexDomain] >= 16 && count >= 7 || domainScoreMap[apexDomain] >= 13 && count >= 11 || domainScoreMap[apexDomain] >= 5 && count >= 14 || domainScoreMap[apexDomain] >= 3 && count >= 21 || domainScoreMap[apexDomain] >= 1 && count >= 60) { + domainArr.push('.' + apexDomain); + } + }); + // console.log({ + // score: domainScoreMap['awicksin.com'], + // count: domainCountMap.get('awicksin.com') + // }); + // console.log({ duplicateCount, domainArrLen: domainArr.length }); + return domainArr; + }, { + serializer: _cachefilesystem.serializeArray, + deserializer: _cachefilesystem.deserializeArray, + temporaryBypass: !_ciinfo.isCI || _rejectdatasource.DEBUG_DOMAIN_TO_FIND !== null + }); + const downloads = [ + ..._rejectdatasource.PHISHING_DOMAIN_LISTS_EXTRA.map((entry)=>(0, _domainlists.processDomainListsWithPreload)(...entry)), + ..._rejectdatasource.PHISHING_HOSTS_EXTRA.map((entry)=>(0, _hosts.processHostsWithPreload)(...entry)) + ]; + function getPhishingDomains(parentSpan) { + return parentSpan.traceChild('get phishing domains').traceAsyncFn(async (span)=>{ + const domainArr = await span.traceChildAsync('download/parse/merge phishing domains', async (curSpan)=>{ + const domainArr = []; + const domainGroups = await Promise.all(downloads.map((task)=>task(curSpan))); + domainGroups.forEach((0, _appendarrayinplace.appendArrayInPlaceCurried)(domainArr)); + return domainArr; + }); + return span.traceChildAsync('process phishing domain set', ()=>processPhihsingDomains(domainArr)); + }); + } + function calcDomainAbuseScore(subdomain, fullDomain = subdomain) { + if (leathalKeywords(fullDomain)) { + return 100; + } + let weight = 0; + const hitLowKeywords = lowKeywords(fullDomain); + const sensitiveKeywordsHit = sensitiveKeywords(fullDomain); + if (sensitiveKeywordsHit) { + weight += 10; + if (hitLowKeywords) { + weight += 6; + } + } else if (hitLowKeywords) { + weight += 1.7; + } + const subdomainLength = subdomain.length; + if (subdomainLength > 6) { + weight += 0.015; + if (subdomainLength > 13) { + weight += 0.2; + if (subdomainLength > 20) { + weight += 1; + if (subdomainLength > 30) { + weight += 5; + if (subdomainLength > 40) { + weight += 10; + } + } + } + if (subdomain.indexOf('.', 1) > 1) { + weight += 1; + } + } + } + return weight; + } + if (require.main === module) { + getPhishingDomains(_trace.dummySpan).catch(console.error).finally(()=>{ + _trace.dummySpan.stop(); + (0, _trace.printTraceResult)(_trace.dummySpan.traceResult); + }); + } + } (getPhishingDomains.__module, getPhishingDomains.__module.exports)); + return getPhishingDomains.__module.exports; +}exports.__require=requireGetPhishingDomains; \ No newline at end of file diff --git a/Dist/Build/lib/is-domain-alive.cjs b/Dist/Build/lib/is-domain-alive.cjs new file mode 100644 index 00000000..a89195e7 --- /dev/null +++ b/Dist/Build/lib/is-domain-alive.cjs @@ -0,0 +1,396 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const isDomainAlive=require('../../_virtual/is-domain-alive.cjs'),require$$5=require('tldts-experimental'),looseTldtsOpt=require('../constants/loose-tldts-opt.cjs'),require$$0=require('picocolors'),require$$3$1=require('dns2'),require$$4=require('async-retry'),require$$5$1=require('whoiser'),require$$3=require('foxts/retrie'),require$$1=require('node:process');var hasRequiredIsDomainAlive; + +function requireIsDomainAlive () { + if (hasRequiredIsDomainAlive) return isDomainAlive.__exports; + hasRequiredIsDomainAlive = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + isDomainAlive: function() { + return isDomainAlive; + }, + keyedAsyncMutexWithQueue: function() { + return keyedAsyncMutexWithQueue; + }, + noWhois: function() { + return noWhois; + } + }); + const _tldtsexperimental = /*#__PURE__*/ _interop_require_default(require$$5); + const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.__require(); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0); + const _dns2 = /*#__PURE__*/ _interop_require_default(require$$3$1); + const _asyncretry = /*#__PURE__*/ _interop_require_default(require$$4); + const _whoiser = /*#__PURE__*/ _interop_require_wildcard(require$$5$1); + const _retrie = require$$3; + const _nodeprocess = /*#__PURE__*/ _interop_require_default(require$$1); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); + } + function _interop_require_wildcard(obj, nodeInterop) { + if (obj && obj.__esModule) { + return obj; + } + if (obj === null || typeof obj !== "object" && typeof obj !== "function") { + return { + default: obj + }; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = { + __proto__: null + }; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; + } + const mutex = new Map(); + function keyedAsyncMutexWithQueue(key, fn) { + if (mutex.has(key)) { + return mutex.get(key); + } + const promise = fn(); + mutex.set(key, promise); + return promise; + } + class DnsError extends Error { + message; + server; + name; + constructor(message, server){ + super(message), this.message = message, this.server = server, this.name = 'DnsError'; + } + } + const dohServers = [ + '8.8.8.8', + '8.8.4.4', + '1.0.0.1', + '1.1.1.1', + '162.159.36.1', + '162.159.46.1', + '101.101.101.101', + '185.222.222.222', + '45.11.45.11', + 'dns10.quad9.net', + 'doh.sandbox.opendns.com', + 'unfiltered.adguard-dns.com', + // '0ms.dev', // Proxy Cloudflare + // '76.76.2.0', // ControlD unfiltered, path not /dns-query + // '76.76.10.0', // ControlD unfiltered, path not /dns-query + // 'dns.bebasid.com', // BebasID, path not /dns-query but /unfiltered + // '193.110.81.0', // dns0.eu + // '185.253.5.0', // dns0.eu + // 'zero.dns0.eu', + 'dns.nextdns.io', + 'anycast.dns.nextdns.io', + 'wikimedia-dns.org', + // 'ordns.he.net', + // 'dns.mullvad.net', + 'basic.rethinkdns.com', + '198.54.117.10' // NameCheap DNS, supports DoT, DoH, UDP53 + ].map((dns)=>[ + dns, + _dns2.default.DOHClient({ + dns, + http: false + }) + ]); + const domesticDohServers = [ + '223.5.5.5', + '223.6.6.6', + '120.53.53.53', + '1.12.12.12' + ].map((dns)=>[ + dns, + _dns2.default.DOHClient({ + dns, + http: false + }) + ]); + function createResolve(server) { + return async (...args)=>{ + try { + return await (0, _asyncretry.default)(async ()=>{ + const [dohServer, dohClient] = server[Math.floor(Math.random() * server.length)]; + try { + return { + ...await dohClient(...args), + dns: dohServer + }; + } catch (e) { + // console.error(e); + throw new DnsError(e.message, dohServer); + } + }, { + retries: 5 + }); + } catch (e) { + console.log('[doh error]', ...args, e); + throw e; + } + }; + } + const resolve = createResolve(dohServers); + const domesticResolve = createResolve(domesticDohServers); + async function getWhois(domain) { + return (0, _asyncretry.default)(()=>_whoiser.domain(domain, { + raw: true + }), { + retries: 5 + }); + } + const domainAliveMap = new Map(); + function onDomainAlive(domain) { + domainAliveMap.set(domain, true); + return [ + domain, + true + ]; + } + function onDomainDead(domain) { + domainAliveMap.set(domain, false); + return [ + domain, + false + ]; + } + async function isDomainAlive(domain, isSuffix) { + if (domainAliveMap.has(domain)) { + return [ + domain, + domainAliveMap.get(domain) + ]; + } + const apexDomain = _tldtsexperimental.default.getDomain(domain, _loosetldtsopt.looseTldtsOpt); + if (!apexDomain) { + console.log(_picocolors.default.gray('[domain invalid]'), _picocolors.default.gray('no apex domain'), { + domain + }); + return onDomainAlive(domain); + } + const apexDomainAlive = await keyedAsyncMutexWithQueue(apexDomain, ()=>isApexDomainAlive(apexDomain)); + if (isSuffix) { + return apexDomainAlive; + } + if (!apexDomainAlive[1]) { + return apexDomainAlive; + } + const $domain = domain[0] === '.' ? domain.slice(1) : domain; + const aDns = []; + const aaaaDns = []; + // test 2 times before make sure record is empty + for(let i = 0; i < 2; i++){ + // eslint-disable-next-line no-await-in-loop -- sequential + const aRecords = await resolve($domain, 'A'); + if (aRecords.answers.length > 0) { + return onDomainAlive(domain); + } + aDns.push(aRecords.dns); + } + for(let i = 0; i < 2; i++){ + // eslint-disable-next-line no-await-in-loop -- sequential + const aaaaRecords = await resolve($domain, 'AAAA'); + if (aaaaRecords.answers.length > 0) { + return onDomainAlive(domain); + } + aaaaDns.push(aaaaRecords.dns); + } + // only then, let's test once with domesticDohServers + const aRecords = await domesticResolve($domain, 'A'); + if (aRecords.answers.length > 0) { + return onDomainAlive(domain); + } + aDns.push(aRecords.dns); + const aaaaRecords = await domesticResolve($domain, 'AAAA'); + if (aaaaRecords.answers.length > 0) { + return onDomainAlive(domain); + } + aaaaDns.push(aaaaRecords.dns); + console.log(_picocolors.default.red('[domain dead]'), 'no A/AAAA records', { + domain, + a: aDns, + aaaa: aaaaDns + }); + return onDomainDead($domain); + } + const apexDomainNsResolvePromiseMap = new Map(); + async function isApexDomainAlive(apexDomain) { + if (domainAliveMap.has(apexDomain)) { + return [ + apexDomain, + domainAliveMap.get(apexDomain) + ]; + } + let resp; + if (apexDomainNsResolvePromiseMap.has(apexDomain)) { + resp = await apexDomainNsResolvePromiseMap.get(apexDomain); + } else { + const promise = resolve(apexDomain, 'NS'); + apexDomainNsResolvePromiseMap.set(apexDomain, promise); + resp = await promise; + } + if (resp.answers.length > 0) { + return onDomainAlive(apexDomain); + } + let whois; + try { + whois = await getWhois(apexDomain); + } catch (e) { + console.log(_picocolors.default.red('[whois error]'), { + domain: apexDomain + }, e); + return onDomainAlive(apexDomain); + } + if (_nodeprocess.default.env.DEBUG) { + console.log(JSON.stringify(whois, null, 2)); + } + const whoisError = noWhois(whois); + if (!whoisError) { + console.log(_picocolors.default.gray('[domain alive]'), _picocolors.default.gray('whois found'), { + domain: apexDomain + }); + return onDomainAlive(apexDomain); + } + console.log(_picocolors.default.red('[domain dead]'), 'whois not found', { + domain: apexDomain, + err: whoisError + }); + return onDomainDead(apexDomain); + } + // TODO: this is a workaround for https://github.com/LayeredStudio/whoiser/issues/117 + const whoisNotFoundKeywordTest = (0, _retrie.createRetrieKeywordFilter)([ + 'no match for', + 'does not exist', + 'not found', + 'no found', + 'no entries', + 'no data found', + 'is available for registration', + 'currently available for application', + 'no matching record', + 'no information available about domain name', + 'not been registered', + 'no match!!', + 'status: available', + ' is free', + 'no object found', + 'nothing found', + 'status: free', + 'pendingdelete', + ' has been blocked by ' + ]); + function noWhois(whois) { + let empty = true; + for(const key in whois){ + if (Object.hasOwn(whois, key)) { + empty = false; + // if (key === 'error') { + // // if ( + // // (typeof whois.error === 'string' && whois.error) + // // || (Array.isArray(whois.error) && whois.error.length > 0) + // // ) { + // // console.error(whois); + // // return true; + // // } + // continue; + // } + // if (key === 'text') { + // if (Array.isArray(whois.text)) { + // for (const value of whois.text) { + // if (whoisNotFoundKeywordTest(value.toLowerCase())) { + // return value; + // } + // } + // } + // continue; + // } + // if (key === 'Name Server') { + // // if (Array.isArray(whois[key]) && whois[key].length === 0) { + // // return false; + // // } + // continue; + // } + // if (key === 'Domain Status') { + // if (Array.isArray(whois[key])) { + // for (const status of whois[key]) { + // if (status === 'free' || status === 'AVAILABLE') { + // return key + ': ' + status; + // } + // if (whoisNotFoundKeywordTest(status.toLowerCase())) { + // return key + ': ' + status; + // } + // } + // } + // continue; + // } + // if (typeof whois[key] === 'string' && whois[key]) { + // if (whoisNotFoundKeywordTest(whois[key].toLowerCase())) { + // return key + ': ' + whois[key]; + // } + // continue; + // } + if (key === '__raw' && typeof whois.__raw === 'string') { + const lines = whois.__raw.trim().toLowerCase().replaceAll(/[\t ]+/g, ' ').split(/\r?\n/); + if (_nodeprocess.default.env.DEBUG) { + console.log({ + lines + }); + } + for (const line of lines){ + if (whoisNotFoundKeywordTest(line)) { + return line; + } + } + continue; + } + if (typeof whois[key] === 'object' && !Array.isArray(whois[key])) { + const tmp = noWhois(whois[key]); + if (tmp) { + return tmp; + } + continue; + } + } + } + if (empty) { + return 'whois is empty'; + } + return null; + } + } (isDomainAlive.__exports)); + return isDomainAlive.__exports; +}exports.__require=requireIsDomainAlive; \ No newline at end of file diff --git a/Dist/Build/lib/memo-promise.cjs b/Dist/Build/lib/memo-promise.cjs new file mode 100644 index 00000000..38f7b4ec --- /dev/null +++ b/Dist/Build/lib/memo-promise.cjs @@ -0,0 +1,35 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const memoPromise=require('../../_virtual/memo-promise.cjs');var hasRequiredMemoPromise; + +function requireMemoPromise () { + if (hasRequiredMemoPromise) return memoPromise.__exports; + hasRequiredMemoPromise = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "createMemoizedPromise", { + enumerable: true, + get: function() { + return createMemoizedPromise; + } + }); + const notError = Symbol('notError'); + function createMemoizedPromise(fn, /** whether to create promise immediately or only create after first access */ preload = true) { + let error = notError; + let promise = preload ? fn().catch((e)=>{ + // Here we record the error so that we can throw it later when the function is called + error = e; + // Here we make sure the Promise still returns the never type + throw e; + }) : null; + return ()=>{ + if (error !== notError) { + return Promise.reject(error); + } + promise ??= fn(); + return promise; + }; + } + } (memoPromise.__exports)); + return memoPromise.__exports; +}exports.__require=requireMemoPromise; \ No newline at end of file diff --git a/Dist/Build/lib/misc.cjs b/Dist/Build/lib/misc.cjs new file mode 100644 index 00000000..1ee46a1a --- /dev/null +++ b/Dist/Build/lib/misc.cjs @@ -0,0 +1,122 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const misc=require('../../_virtual/misc.cjs'),require$$0=require('node:path'),require$$1=require('node:fs'),require$$2=require('node:fs/promises');var hasRequiredMisc; + +function requireMisc () { + if (hasRequiredMisc) return misc.__exports; + hasRequiredMisc = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + fastIpVersion: function() { + return fastIpVersion; + }, + fastStringCompare: function() { + return fastStringCompare; + }, + isDirectoryEmptySync: function() { + return isDirectoryEmptySync; + }, + mkdirp: function() { + return mkdirp; + }, + notSupported: function() { + return notSupported; + }, + removeFiles: function() { + return removeFiles; + }, + withBannerArray: function() { + return withBannerArray; + }, + withIdentityContent: function() { + return withIdentityContent; + }, + writeFile: function() { + return writeFile; + } + }); + const _nodepath = require$$0; + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1); + const _promises = /*#__PURE__*/ _interop_require_default(require$$2); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function fastStringCompare(a, b) { + const lenA = a.length; + const lenB = b.length; + const minLen = lenA < lenB ? lenA : lenB; + for(let i = 0; i < minLen; ++i){ + const ca = a.charCodeAt(i); + const cb = b.charCodeAt(i); + if (ca > cb) return 1; + if (ca < cb) return -1; + } + if (lenA === lenB) { + return 0; + } + return lenA > lenB ? 1 : -1; + } + function mkdirp(dir) { + if (_nodefs.default.existsSync(dir)) { + return; + } + return _promises.default.mkdir(dir, { + recursive: true + }); + } + const writeFile = async (destination, input, dir = (0, _nodepath.dirname)(destination))=>{ + const p = mkdirp(dir); + if (p) { + await p; + } + return _promises.default.writeFile(destination, input, { + encoding: 'utf-8' + }); + }; + const removeFiles = async (files)=>Promise.all(files.map((file)=>_promises.default.rm(file, { + force: true + }))); + function withBannerArray(title, description, date, content) { + return [ + '#########################################', + `# ${title}`, + `# Last Updated: ${date.toISOString()}`, + `# Size: ${content.length}`, + ...description.map((line)=>line ? `# ${line}` : '#'), + '#########################################', + ...content, + '################## EOF ##################' + ]; + } + function notSupported(name) { + return (...args)=>{ + console.error(`${name}: not supported.`, args); + throw new Error(`${name}: not implemented.`); + }; + } + function withIdentityContent(title, description, date, content) { + return content; + } + function isDirectoryEmptySync(path) { + const directoryHandle = _nodefs.default.opendirSync(path); + try { + return directoryHandle.readSync() === null; + } finally{ + directoryHandle.closeSync(); + } + } + function fastIpVersion(ip) { + return ip.includes(':') ? 6 : ip.includes('.') ? 4 : 0; + } + } (misc.__exports)); + return misc.__exports; +}exports.__require=requireMisc; \ No newline at end of file diff --git a/Dist/Build/lib/normalize-domain.cjs b/Dist/Build/lib/normalize-domain.cjs new file mode 100644 index 00000000..2d5716f1 --- /dev/null +++ b/Dist/Build/lib/normalize-domain.cjs @@ -0,0 +1,79 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const normalizeDomain=require('../../_virtual/normalize-domain.cjs'),require$$0=require('tldts'),looseTldtsOpt=require('../constants/loose-tldts-opt.cjs'),require$$2=require('foxts/is-probably-ip');var hasRequiredNormalizeDomain; + +function requireNormalizeDomain () { + if (hasRequiredNormalizeDomain) return normalizeDomain.__exports; + hasRequiredNormalizeDomain = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + fastNormalizeDomain: function() { + return fastNormalizeDomain; + }, + fastNormalizeDomainWithoutWww: function() { + return fastNormalizeDomainWithoutWww; + }, + normalizeDomain: function() { + return normalizeDomain; + } + }); + const _tldts = /*#__PURE__*/ _interop_require_default(require$$0); + const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.__require(); + const _isprobablyip = require$$2; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function fastNormalizeDomainWithoutWww(domain, parsed = null) { + // We don't want tldts to call its own "extractHostname" on ip, bail out ip first. + // Now ip has been bailed out, we can safely set normalizeTldtsOpt.detectIp to false. + if ((0, _isprobablyip.isProbablyIpv4)(domain) || (0, _isprobablyip.isProbablyIpv6)(domain)) { + return null; + } + parsed ??= _tldts.default.parse(domain, _loosetldtsopt.normalizeTldtsOpt); + // Private invalid domain (things like .tor, .dn42, etc) + if (!parsed.isIcann && !parsed.isPrivate) return null; + if (parsed.subdomain) { + if (parsed.subdomain === 'www') { + return parsed.domain; + } + if (parsed.subdomain.startsWith('www.')) { + return parsed.subdomain.slice(4) + '.' + parsed.domain; + } + } + return parsed.hostname; + } + function fastNormalizeDomain(domain, parsed = null) { + // We don't want tldts to call its own "extractHostname" on ip, bail out ip first. + // Now ip has been bailed out, we can safely set normalizeTldtsOpt.detectIp to false. + if ((0, _isprobablyip.isProbablyIpv4)(domain) || (0, _isprobablyip.isProbablyIpv6)(domain)) { + return null; + } + parsed ??= _tldts.default.parse(domain, _loosetldtsopt.normalizeTldtsOpt); + // Private invalid domain (things like .tor, .dn42, etc) + if (!parsed.isIcann && !parsed.isPrivate) return null; + return parsed.hostname; + } + function normalizeDomain(domain, parsed = null) { + if (domain.length === 0) return null; + if ((0, _isprobablyip.isProbablyIpv4)(domain) || (0, _isprobablyip.isProbablyIpv6)(domain)) { + return null; + } + parsed ??= _tldts.default.parse(domain, _loosetldtsopt.normalizeTldtsOpt); + // Private invalid domain (things like .tor, .dn42, etc) + if (!parsed.isIcann && !parsed.isPrivate) return null; + // const h = parsed.hostname; + // if (h === null) return null; + return parsed.hostname; + } + } (normalizeDomain.__exports)); + return normalizeDomain.__exports; +}exports.__require=requireNormalizeDomain; \ No newline at end of file diff --git a/Dist/Build/lib/parse-dnsmasq.cjs b/Dist/Build/lib/parse-dnsmasq.cjs new file mode 100644 index 00000000..cb2c4d43 --- /dev/null +++ b/Dist/Build/lib/parse-dnsmasq.cjs @@ -0,0 +1,44 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const parseDnsmasq=require('../../_virtual/parse-dnsmasq.cjs'),fetchTextByLine=require('./fetch-text-by-line.cjs'),normalizeDomain=require('./normalize-domain.cjs');var hasRequiredParseDnsmasq; + +function requireParseDnsmasq () { + if (hasRequiredParseDnsmasq) return parseDnsmasq.__exports; + hasRequiredParseDnsmasq = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + extractDomainsFromFelixDnsmasq: function() { + return extractDomainsFromFelixDnsmasq; + }, + parseFelixDnsmasqFromResp: function() { + return parseFelixDnsmasqFromResp; + } + }); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _normalizedomain = /*@__PURE__*/ normalizeDomain.__require(); + function extractDomainsFromFelixDnsmasq(line) { + if (line.startsWith('server=/') && line.endsWith('/114.114.114.114')) { + return line.slice(8, -16); + } + return null; + } + async function parseFelixDnsmasqFromResp(resp) { + const results = []; + for await (const line of (0, _fetchtextbyline.createReadlineInterfaceFromResponse)(resp, true)){ + const domain = extractDomainsFromFelixDnsmasq(line); + if (domain && (0, _normalizedomain.fastNormalizeDomain)(domain)) { + results.push(domain); + } + } + return results; + } + } (parseDnsmasq.__exports)); + return parseDnsmasq.__exports; +}exports.__require=requireParseDnsmasq; \ No newline at end of file diff --git a/Dist/Build/lib/parse-filter/domainlists.cjs b/Dist/Build/lib/parse-filter/domainlists.cjs new file mode 100644 index 00000000..aa0df1ab --- /dev/null +++ b/Dist/Build/lib/parse-filter/domainlists.cjs @@ -0,0 +1,71 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const domainlists=require('../../../_virtual/domainlists.cjs'),normalizeDomain=require('../normalize-domain.cjs'),processLine=require('../process-line.cjs'),shared=require('./shared.cjs'),fetchAssets=require('../fetch-assets.cjs');var hasRequiredDomainlists; + +function requireDomainlists () { + if (hasRequiredDomainlists) return domainlists.__exports; + hasRequiredDomainlists = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + processDomainLists: function() { + return processDomainLists; + }, + processDomainListsWithPreload: function() { + return processDomainListsWithPreload; + } + }); + const _normalizedomain = /*@__PURE__*/ normalizeDomain.__require(); + const _processline = /*@__PURE__*/ processLine.__require(); + const _shared = /*@__PURE__*/ shared.__require(); + const _fetchassets = /*@__PURE__*/ fetchAssets.__require(); + function domainListLineCb(l, set, meta, normalizeDomain = _normalizedomain.fastNormalizeDomain) { + const line = (0, _processline.processLine)(l); + if (!line) return; + const domain = normalizeDomain(line); + if (!domain) return; + (0, _shared.onBlackFound)(domain, meta); + set.push(domain); + } + function domainListLineCbIncludeAllSubdomain(line, set, meta, normalizeDomain = _normalizedomain.fastNormalizeDomain) { + const domain = normalizeDomain(line); + if (!domain) return; + (0, _shared.onBlackFound)(domain, meta); + set.push('.' + domain); + } + function processDomainLists(span, domainListsUrl, mirrors, includeAllSubDomain = false) { + const lineCb = includeAllSubDomain ? domainListLineCbIncludeAllSubdomain : domainListLineCb; + return span.traceChildAsync(`process domainlist: ${domainListsUrl}`, async (span)=>{ + const filterRules = await span.traceChildAsync('download', ()=>(0, _fetchassets.fetchAssets)(domainListsUrl, mirrors, true)); + const domainSets = []; + span.traceChildSync('parse domain list', ()=>{ + for(let i = 0, len = filterRules.length; i < len; i++){ + lineCb(filterRules[i], domainSets, domainListsUrl, _normalizedomain.fastNormalizeDomainWithoutWww); + } + }); + return domainSets; + }); + } + function processDomainListsWithPreload(domainListsUrl, mirrors, includeAllSubDomain = false) { + const downloadPromise = (0, _fetchassets.fetchAssets)(domainListsUrl, mirrors, true); + const lineCb = includeAllSubDomain ? domainListLineCbIncludeAllSubdomain : domainListLineCb; + return (span)=>span.traceChildAsync(`process domainlist: ${domainListsUrl}`, async (span)=>{ + const filterRules = await span.traceChildPromise('download', downloadPromise); + const domainSets = []; + span.traceChildSync('parse domain list', ()=>{ + for(let i = 0, len = filterRules.length; i < len; i++){ + lineCb(filterRules[i], domainSets, domainListsUrl, _normalizedomain.fastNormalizeDomainWithoutWww); + } + }); + return domainSets; + }); + } + } (domainlists.__exports)); + return domainlists.__exports; +}exports.__require=requireDomainlists; \ No newline at end of file diff --git a/Dist/Build/lib/parse-filter/filters.cjs b/Dist/Build/lib/parse-filter/filters.cjs new file mode 100644 index 00000000..f1f3d7c9 --- /dev/null +++ b/Dist/Build/lib/parse-filter/filters.cjs @@ -0,0 +1,372 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const filters=require('../../../_virtual/filters.cjs'),require$$0=require('picocolors'),fetchAssets=require('../fetch-assets.cjs'),shared=require('./shared.cjs'),require$$3=require('foxts/retrie'),looseTldtsOpt=require('../../constants/loose-tldts-opt.cjs'),require$$5=require('tldts-experimental'),require$$6=require('@ghostery/adblocker'),normalizeDomain=require('../normalize-domain.cjs');var hasRequiredFilters; + +function requireFilters () { + if (hasRequiredFilters) return filters.__exports; + hasRequiredFilters = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + parse: function() { + return parse; + }, + processFilterRulesWithPreload: function() { + return processFilterRulesWithPreload; + } + }); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0); + const _fetchassets = /*@__PURE__*/ fetchAssets.__require(); + const _shared = /*@__PURE__*/ shared.__require(); + const _retrie = require$$3; + const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.__require(); + const _tldtsexperimental = /*#__PURE__*/ _interop_require_default(require$$5); + const _adblocker = require$$6; + const _normalizedomain = /*@__PURE__*/ normalizeDomain.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function processFilterRulesWithPreload(filterRulesUrl, fallbackUrls, includeThirdParty = false) { + const downloadPromise = (0, _fetchassets.fetchAssets)(filterRulesUrl, fallbackUrls); + return (span)=>span.traceChildAsync(`process filter rules: ${filterRulesUrl}`, async (span)=>{ + const filterRules = await span.traceChildPromise('download', downloadPromise); + const whiteDomains = new Set(); + const whiteDomainSuffixes = new Set(); + const blackDomains = new Set(); + const blackDomainSuffixes = new Set(); + const warningMessages = []; + const MUTABLE_PARSE_LINE_RESULT = [ + '', + 2000 + ]; + /** + * @param {string} line + */ const lineCb = (line)=>{ + const result = parse(line, MUTABLE_PARSE_LINE_RESULT, includeThirdParty); + const flag = result[1]; + if (flag === 2000) { + throw new Error(`Didn't parse line: ${line}`); + } + if (flag === 1000) { + return; + } + const hostname = result[0]; + if (flag === 0 || flag === -1) { + (0, _shared.onWhiteFound)(hostname, filterRulesUrl); + } else { + (0, _shared.onBlackFound)(hostname, filterRulesUrl); + } + switch(flag){ + case 0: + whiteDomainSuffixes.add(hostname); + break; + case -1: + whiteDomains.add(hostname); + break; + case 2: + blackDomainSuffixes.add(hostname); + break; + case 1: + blackDomains.add(hostname); + break; + case 10: + warningMessages.push(hostname); + break; + } + }; + span.traceChild('parse adguard filter').traceSyncFn(()=>{ + for(let i = 0, len = filterRules.length; i < len; i++){ + lineCb(filterRules[i]); + } + }); + for(let i = 0, len = warningMessages.length; i < len; i++){ + console.warn(_picocolors.default.yellow(warningMessages[i]), _picocolors.default.gray(_picocolors.default.underline(filterRulesUrl))); + } + console.log(_picocolors.default.gray('[process filter]'), _picocolors.default.gray(filterRulesUrl), _picocolors.default.gray(`white: ${whiteDomains.size + whiteDomainSuffixes.size}`), _picocolors.default.gray(`black: ${blackDomains.size + blackDomainSuffixes.size}`)); + return { + whiteDomains: Array.from(whiteDomains), + whiteDomainSuffixes: Array.from(whiteDomainSuffixes), + blackDomains: Array.from(blackDomains), + blackDomainSuffixes: Array.from(blackDomainSuffixes) + }; + }); + } + // many filter that has modifiers can not work on Surge/Clash because browser context is required + // we can early bail out those rules + const kwfilter = (0, _retrie.createRetrieKeywordFilter)([ + '!', + '?', + '*', + '[', + '(', + ']', + ')', + ',', + '#', + '%', + '&', + '=', + '~', + // special modifier + '$popup', + '$removeparam', + '$redirect', + '$popunder', + '$cname', + '$frame', + '$domain', + '$from', + '$to', + '$csp', + '$replace', + '$urlskip', + // some bad syntax + '^popup' + ]); + function parse($line, result, includeThirdParty) { + if (// doesn't include + !$line.includes('.') // rule with out dot can not be a domain + || kwfilter($line)) { + result[1] = 1000; + return result; + } + const line = $line.trim(); + if (line.length === 0) { + result[1] = 1000; + return result; + } + const firstCharCode = line.charCodeAt(0); + const lastCharCode = line.charCodeAt(line.length - 1); + if (firstCharCode === 47 // 47 `/` + || lastCharCode === 46 // 46 `.`, line.endsWith('.') + || lastCharCode === 45 // 45 `-`, line.endsWith('-') + || lastCharCode === 95 // 95 `_`, line.endsWith('_') + ) { + result[1] = 1000; + return result; + } + if ((line.includes('/') || line.includes(':')) && !line.includes('://')) { + result[1] = 1000; + return result; + } + const filter = _adblocker.NetworkFilter.parse(line); + if (filter) { + if (// filter.isCosmeticFilter() // always false + // filter.isNetworkFilter() // always true + filter.isElemHide() || filter.isGenericHide() || filter.isSpecificHide() || filter.isRedirect() || filter.isRedirectRule() || filter.hasDomains() || filter.isCSP() // must not be csp rule + || !filter.fromHttp() && !filter.fromHttps()) { + // not supported type + result[1] = 1000; + return result; + } + if (!filter.fromAny() && !filter.fromDocument() // $document, $doc + ) { + result[1] = 1000; + return result; + } + if (filter.hostname // filter.hasHostname() // must have + && filter.isPlain() // isPlain() === !isRegex() + && !filter.isFullRegex()) { + const hostname = (0, _normalizedomain.fastNormalizeDomainWithoutWww)(filter.hostname); + if (!hostname) { + result[1] = 1000; + return result; + } + // |: filter.isHostnameAnchor(), + // |: filter.isLeftAnchor(), + // |https://: !filter.isHostnameAnchor() && (filter.fromHttps() || filter.fromHttp()) + const isIncludeAllSubDomain = filter.isHostnameAnchor(); + if (filter.isException() || filter.isBadFilter()) { + result[0] = hostname; + result[1] = isIncludeAllSubDomain ? 0 : -1; + return result; + } + const _1p = filter.firstParty(); + const _3p = filter.thirdParty(); + if (_1p) { + if (_3p) { + result[0] = hostname; + result[1] = isIncludeAllSubDomain ? 2 : 1; + return result; + } + result[1] = 1000; + return result; + } + if (_3p) { + if (includeThirdParty) { + result[0] = hostname; + result[1] = isIncludeAllSubDomain ? 2 : 1; + return result; + } + result[1] = 1000; + return result; + } + } + } + /** + * From now on, we are mostly facing non-standard domain rules (some are regex like) + * + * We can still salvage some of them by removing modifiers + */ let sliceStart = 0; + let sliceEnd = 0; + // After NetworkFilter.parse, it means the line can not be parsed by cliqz NetworkFilter + // We now need to "salvage" the line as much as possible + let white = false; + let includeAllSubDomain = false; + if (firstCharCode === 64 // 64 `@` + && line.charCodeAt(1) === 64 // 64 `@` + ) { + sliceStart += 2; + white = true; + includeAllSubDomain = true; + } + /** + * Some "malformed" regex-based filters can not be parsed by NetworkFilter + * "$genericblock`" is also not supported by NetworkFilter, see: + * https://github.com/ghostery/adblocker/blob/62caf7786ba10ef03beffecd8cd4eec111bcd5ec/packages/adblocker/test/parsing.test.ts#L950 + * + * `@@||cmechina.net^$genericblock` + * `@@|ftp.bmp.ovh^|` + * `@@|adsterra.com^|` + * `@@.atlassian.net$document` + * `@@||ad.alimama.com^$genericblock` + */ switch(line.charCodeAt(sliceStart)){ + case 124: + /** | */ // line.startsWith('@@|') || line.startsWith('|') + sliceStart += 1; + includeAllSubDomain = false; + if (line[sliceStart] === '|') { + sliceStart += 1; + includeAllSubDomain = true; + } + break; + case 46: + { + /** + * `.ay.delivery^` + * `.m.bookben.com^` + * `.wap.x4399.com^` + */ sliceStart += 1; + includeAllSubDomain = true; + break; + } + } + switch(line.charCodeAt(sliceStart)){ + case 58: + { + /** + * `@@://googleadservices.com^|` + * `@@://www.googleadservices.com^|` + * `://mine.torrent.pw^` + * `://say.ac^` + */ if (line[sliceStart + 1] === '/' && line[sliceStart + 2] === '/') { + includeAllSubDomain = false; + sliceStart += 3; + } + break; + } + case 104: + { + /** |http://x.o2.pl^ */ if (line.startsWith('http://', sliceStart)) { + includeAllSubDomain = false; + sliceStart += 7; + } else if (line.startsWith('https://', sliceStart)) { + includeAllSubDomain = false; + sliceStart += 8; + } + break; + } + } + const indexOfDollar = line.indexOf('$', sliceStart); + if (indexOfDollar > -1) { + sliceEnd = indexOfDollar - line.length; + } + /* + * We skip third-party and frame rules, as Surge / Clash can't handle them + * + * `.sharecounter.$third-party` + * `.bbelements.com^$third-party` + * `://o0e.ru^$third-party` + * `.1.1.1.l80.js^$third-party` + */ if (!includeThirdParty && (line.includes('third-party', indexOfDollar + 1) || line.includes('3p', indexOfDollar + 1))) { + result[1] = 1000; + return result; + } + if (line.includes('badfilter', indexOfDollar + 1)) { + white = true; + } + if (line.includes('all', indexOfDollar + 1)) { + includeAllSubDomain = true; + } + /** + * `_vmind.qqvideo.tc.qq.com^` + * `arketing.indianadunes.com^` + * `charlestownwyllie.oaklawnnonantum.com^` + * `-telemetry.officeapps.live.com^` + * `-tracker.biliapi.net` + * `-logging.nextmedia.com` + * `_social_tracking.js^` + */ if (line.charCodeAt(line.length + sliceEnd - 1) === 94) { + /** line.endsWith('^') */ sliceEnd -= 1; + } else if (line.charCodeAt(line.length + sliceEnd - 1) === 124) { + /** line.endsWith('|') */ sliceEnd -= 1; + if (line.charCodeAt(line.length + sliceEnd - 1) === 94) { + /** line.endsWith('^|') */ sliceEnd -= 1; + } + } else if (line.charCodeAt(line.length + sliceEnd - 1) === 46) { + /** line.endsWith('.') */ sliceEnd -= 1; + } + const sliced = sliceStart > 0 || sliceEnd < 0 ? line.slice(sliceStart, sliceEnd === 0 ? undefined : sliceEnd) : line; + if (sliced.length === 0 || sliced.includes('/')) { + result[1] = 1000; + return result; + } + if (sliced.charCodeAt(0) === 45 /* - */ ) { + // line.startsWith('-') is not a valid domain + result[1] = 10; + result[0] = `[parse-filter E0001] (${white ? 'white' : 'black'}) invalid domain: ${JSON.stringify({ + line, + sliced, + sliceStart, + sliceEnd + })}`; + return result; + } + const suffix = _tldtsexperimental.default.getPublicSuffix(sliced, _loosetldtsopt.looseTldtsOpt); + if (!suffix) { + // This exclude domain-like resource like `_social_tracking.js^` + result[1] = 1000; + return result; + } + const domain = (0, _normalizedomain.fastNormalizeDomainWithoutWww)(sliced); + if (domain && domain === sliced) { + result[0] = domain; + if (white) { + result[1] = includeAllSubDomain ? 0 : -1; + } else { + result[1] = includeAllSubDomain ? 2 : 1; + } + return result; + } + result[0] = `[parse-filter E0010] (${white ? 'white' : 'black'}) invalid domain: ${JSON.stringify({ + line, + domain, + suffix, + sliced, + sliceStart, + sliceEnd + })}`; + result[1] = 10; + return result; + } + } (filters.__exports)); + return filters.__exports; +}exports.__require=requireFilters; \ No newline at end of file diff --git a/Dist/Build/lib/parse-filter/hosts.cjs b/Dist/Build/lib/parse-filter/hosts.cjs new file mode 100644 index 00000000..845221c9 --- /dev/null +++ b/Dist/Build/lib/parse-filter/hosts.cjs @@ -0,0 +1,66 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const hosts=require('../../../_virtual/hosts.cjs'),fetchAssets=require('../fetch-assets.cjs'),normalizeDomain=require('../normalize-domain.cjs'),shared=require('./shared.cjs');var hasRequiredHosts; + +function requireHosts () { + if (hasRequiredHosts) return hosts.__exports; + hasRequiredHosts = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + processHosts: function() { + return processHosts; + }, + processHostsWithPreload: function() { + return processHostsWithPreload; + } + }); + const _fetchassets = /*@__PURE__*/ fetchAssets.__require(); + const _normalizedomain = /*@__PURE__*/ normalizeDomain.__require(); + const _shared = /*@__PURE__*/ shared.__require(); + function hostsLineCb(line, set, includeAllSubDomain, meta) { + const _domain = line.split(/\s/)[1]?.trim(); + if (!_domain) { + return; + } + const domain = (0, _normalizedomain.fastNormalizeDomainWithoutWww)(_domain); + if (!domain) { + return; + } + (0, _shared.onBlackFound)(domain, meta); + set.push(includeAllSubDomain ? `.${domain}` : domain); + } + function processHosts(span, hostsUrl, mirrors, includeAllSubDomain = false) { + return span.traceChildAsync(`process hosts: ${hostsUrl}`, async (span)=>{ + const filterRules = await span.traceChild('download').traceAsyncFn(()=>(0, _fetchassets.fetchAssets)(hostsUrl, mirrors, true)); + const domainSets = []; + span.traceChild('parse hosts').traceSyncFn(()=>{ + for(let i = 0, len = filterRules.length; i < len; i++){ + hostsLineCb(filterRules[i], domainSets, includeAllSubDomain, hostsUrl); + } + }); + return domainSets; + }); + } + function processHostsWithPreload(hostsUrl, mirrors, includeAllSubDomain = false) { + const downloadPromise = (0, _fetchassets.fetchAssets)(hostsUrl, mirrors, true); + return (span)=>span.traceChildAsync(`process hosts: ${hostsUrl}`, async (span)=>{ + const filterRules = await span.traceChild('download').tracePromise(downloadPromise); + const domainSets = []; + span.traceChild('parse hosts').traceSyncFn(()=>{ + for(let i = 0, len = filterRules.length; i < len; i++){ + hostsLineCb(filterRules[i], domainSets, includeAllSubDomain, hostsUrl); + } + }); + return domainSets; + }); + } + } (hosts.__exports)); + return hosts.__exports; +}exports.__require=requireHosts; \ No newline at end of file diff --git a/Dist/Build/lib/parse-filter/shared.cjs b/Dist/Build/lib/parse-filter/shared.cjs new file mode 100644 index 00000000..970abe75 --- /dev/null +++ b/Dist/Build/lib/parse-filter/shared.cjs @@ -0,0 +1,52 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const shared=require('../../../_virtual/shared.cjs'),require$$0=require('picocolors'),rejectDataSource=require('../../constants/reject-data-source.cjs'),require$$2=require('foxts/noop');var hasRequiredShared; + +function requireShared () { + if (hasRequiredShared) return shared.__exports; + hasRequiredShared = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + foundDebugDomain: function() { + return foundDebugDomain; + }, + onBlackFound: function() { + return onBlackFound; + }, + onWhiteFound: function() { + return onWhiteFound; + } + }); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0); + const _rejectdatasource = /*@__PURE__*/ rejectDataSource.__require(); + const _noop = require$$2; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const foundDebugDomain = { + value: false + }; + const onBlackFound = _rejectdatasource.DEBUG_DOMAIN_TO_FIND ? (line, meta)=>{ + if (line.includes(_rejectdatasource.DEBUG_DOMAIN_TO_FIND)) { + console.warn(_picocolors.default.red(meta), '(black)', line.replaceAll(_rejectdatasource.DEBUG_DOMAIN_TO_FIND, _picocolors.default.bold(_rejectdatasource.DEBUG_DOMAIN_TO_FIND))); + foundDebugDomain.value = true; + } + } : _noop.noop; + const onWhiteFound = _rejectdatasource.DEBUG_DOMAIN_TO_FIND ? (line, meta)=>{ + if (line.includes(_rejectdatasource.DEBUG_DOMAIN_TO_FIND)) { + console.warn(_picocolors.default.red(meta), '(white)', line.replaceAll(_rejectdatasource.DEBUG_DOMAIN_TO_FIND, _picocolors.default.bold(_rejectdatasource.DEBUG_DOMAIN_TO_FIND))); + foundDebugDomain.value = true; + } + } : _noop.noop; + } (shared.__exports)); + return shared.__exports; +}exports.__require=requireShared; \ No newline at end of file diff --git a/Dist/Build/lib/process-line.cjs b/Dist/Build/lib/process-line.cjs new file mode 100644 index 00000000..50e40658 --- /dev/null +++ b/Dist/Build/lib/process-line.cjs @@ -0,0 +1,79 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const processLine=require('../../_virtual/process-line.cjs'),require$$0=require('node:stream/web');var hasRequiredProcessLine; + +function requireProcessLine () { + if (hasRequiredProcessLine) return processLine.__exports; + hasRequiredProcessLine = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + ProcessLineStream: function() { + return ProcessLineStream; + }, + processLine: function() { + return processLine; + } + }); + const _web = require$$0; + function processLine(line) { + const trimmed = line.trim(); + if (trimmed.length === 0) { + return null; + } + const line_0 = trimmed.charCodeAt(0); + if (// line_0 === 32 /** [space] */ + // || line_0 === 13 /** \r */ + // || line_0 === 10 /** \n */ + line_0 === 33 /** ! */ || line_0 === 47 /** / */ && trimmed.charCodeAt(1) === 47 /** / */ ) { + return null; + } + if (line_0 === 35 /** # */ ) { + if (trimmed.charCodeAt(1) !== 35 /** # */ ) { + // # Comment + return null; + } + if (trimmed.charCodeAt(2) === 35 /** # */ && trimmed.charCodeAt(3) === 35) { + // ################## EOF ################## + return null; + } + /** + * AdGuard Filter can be: + * + * ##.class + * ##tag.class + * ###id + */ } + return trimmed; + } + class ProcessLineStream extends _web.TransformStream { + // private __buf = ''; + constructor(){ + super({ + transform (l, controller) { + const line = processLine(l); + if (line) { + controller.enqueue(line); + } + } + }); + } + } // export class ProcessLineNodeStream extends Transform { + // _transform(chunk: string, encoding: BufferEncoding, callback: TransformCallback) { + // // Convert chunk to string and then to uppercase + // const upperCased = chunk.toUpperCase(); + // // Push transformed data to readable side + // this.push(upperCased); + // // Call callback when done + // callback(); + // } + // } + } (processLine.__exports)); + return processLine.__exports; +}exports.__require=requireProcessLine; \ No newline at end of file diff --git a/Dist/Build/lib/rules/base.cjs b/Dist/Build/lib/rules/base.cjs new file mode 100644 index 00000000..f7a87b8a --- /dev/null +++ b/Dist/Build/lib/rules/base.cjs @@ -0,0 +1,469 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const base=require('../../../_virtual/base.cjs'),trie=require('../trie.cjs'),require$$6=require('foxts/guard'),require$$2=require('fast-cidr-tools'),require$$3=require('foxts/retrie'),require$$0=require('node:path'),surge=require('../writing-strategy/surge.cjs');var hasRequiredBase; + +function requireBase () { + if (hasRequiredBase) return base.__exports; + hasRequiredBase = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "FileOutput", { + enumerable: true, + get: function() { + return FileOutput; + } + }); + const _trie = /*@__PURE__*/ trie.__require(); + const _guard = require$$6; + const _fastcidrtools = require$$2; + const _retrie = require$$3; + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _surge = /*@__PURE__*/ surge.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + class FileOutput { + id; + strategies; + domainTrie; + domainKeywords; + domainWildcard; + userAgent; + processName; + processPath; + urlRegex; + ipcidr; + ipcidrNoResolve; + ipasn; + ipasnNoResolve; + ipcidr6; + ipcidr6NoResolve; + geoip; + groipNoResolve; + sourceIpOrCidr; + sourcePort; + destPort; + otherRules; + pendingPromise; + whitelistDomain; + span; + constructor($span, id){ + this.id = id; + this.strategies = []; + this.domainTrie = new _trie.HostnameSmolTrie(null); + this.domainKeywords = new Set(); + this.domainWildcard = new Set(); + this.userAgent = new Set(); + this.processName = new Set(); + this.processPath = new Set(); + this.urlRegex = new Set(); + this.ipcidr = new Set(); + this.ipcidrNoResolve = new Set(); + this.ipasn = new Set(); + this.ipasnNoResolve = new Set(); + this.ipcidr6 = new Set(); + this.ipcidr6NoResolve = new Set(); + this.geoip = new Set(); + this.groipNoResolve = new Set(); + this.sourceIpOrCidr = new Set(); + this.sourcePort = new Set(); + this.destPort = new Set(); + this.otherRules = []; + this.pendingPromise = null; + this.whitelistDomain = (domain)=>{ + this.domainTrie.whitelist(domain); + return this; + }; + this.title = null; + this.description = null; + this.date = new Date(); + this.strategiesWritten = false; + this.span = $span.traceChild('RuleOutput#' + id); + } + title; + withTitle(title) { + this.title = title; + return this; + } + withStrategies(strategies) { + this.strategies = strategies; + return this; + } + withExtraStrategies(strategy) { + if (strategy) { + this.strategies.push(strategy); + } + } + description; + withDescription(description) { + this.description = description; + return this; + } + date; + withDate(date) { + this.date = date; + return this; + } + addDomain(domain) { + this.domainTrie.add(domain); + return this; + } + bulkAddDomain(domains) { + let d; + for(let i = 0, len = domains.length; i < len; i++){ + d = domains[i]; + if (d !== null) { + this.domainTrie.add(d, false, null, 0); + } + } + return this; + } + addDomainSuffix(domain, lineFromDot = domain[0] === '.') { + this.domainTrie.add(domain, true, lineFromDot ? 1 : 0); + return this; + } + bulkAddDomainSuffix(domains) { + for(let i = 0, len = domains.length; i < len; i++){ + this.addDomainSuffix(domains[i]); + } + return this; + } + addDomainKeyword(keyword) { + this.domainKeywords.add(keyword); + return this; + } + addIPASN(asn) { + this.ipasn.add(asn); + return this; + } + bulkAddIPASN(asns) { + for(let i = 0, len = asns.length; i < len; i++){ + this.ipasn.add(asns[i]); + } + return this; + } + async addFromDomainsetPromise(source) { + for await (const line of source){ + if (line[0] === '.') { + this.addDomainSuffix(line, true); + } else { + this.domainTrie.add(line, false, null, 0); + } + } + } + addFromDomainset(source) { + if (this.pendingPromise) { + if ('then' in source) { + this.pendingPromise = this.pendingPromise.then(()=>source).then((src)=>this.addFromDomainsetPromise(src)); + return this; + } + this.pendingPromise = this.pendingPromise.then(()=>this.addFromDomainsetPromise(source)); + return this; + } + if ('then' in source) { + this.pendingPromise = source.then((src)=>this.addFromDomainsetPromise(src)); + return this; + } + this.pendingPromise = this.addFromDomainsetPromise(source); + return this; + } + async addFromRulesetPromise(source) { + for await (const line of source){ + const splitted = line.split(','); + const type = splitted[0]; + const value = splitted[1]; + const arg = splitted[2]; + switch(type){ + case 'DOMAIN': + this.domainTrie.add(value, false, null, 0); + break; + case 'DOMAIN-SUFFIX': + this.addDomainSuffix(value, false); + break; + case 'DOMAIN-KEYWORD': + this.addDomainKeyword(value); + break; + case 'DOMAIN-WILDCARD': + this.domainWildcard.add(value); + break; + case 'USER-AGENT': + this.userAgent.add(value); + break; + case 'PROCESS-NAME': + if (value.includes('/') || value.includes('\\')) { + this.processPath.add(value); + } else { + this.processName.add(value); + } + break; + case 'URL-REGEX': + { + const [, ...rest] = splitted; + this.urlRegex.add(rest.join(',')); + break; + } + case 'IP-CIDR': + (arg === 'no-resolve' ? this.ipcidrNoResolve : this.ipcidr).add(value); + break; + case 'IP-CIDR6': + (arg === 'no-resolve' ? this.ipcidr6NoResolve : this.ipcidr6).add(value); + break; + case 'IP-ASN': + (arg === 'no-resolve' ? this.ipasnNoResolve : this.ipasn).add(value); + break; + case 'GEOIP': + (arg === 'no-resolve' ? this.groipNoResolve : this.geoip).add(value); + break; + case 'SRC-IP': + this.sourceIpOrCidr.add(value); + break; + case 'SRC-PORT': + this.sourcePort.add(value); + break; + case 'DEST-PORT': + this.destPort.add(value); + break; + default: + this.otherRules.push(line); + break; + } + } + } + addFromRuleset(source) { + if (this.pendingPromise) { + if ('then' in source) { + this.pendingPromise = this.pendingPromise.then(()=>source).then((src)=>this.addFromRulesetPromise(src)); + return this; + } + this.pendingPromise = this.pendingPromise.then(()=>this.addFromRulesetPromise(source)); + return this; + } + if ('then' in source) { + this.pendingPromise = source.then((src)=>this.addFromRulesetPromise(src)); + return this; + } + this.pendingPromise = this.addFromRulesetPromise(source); + return this; + } + static ipToCidr = (ip, version)=>{ + if (ip.includes('/')) return ip; + if (version === 4) { + return ip + '/32'; + } + return ip + '/128'; + }; + bulkAddCIDR4(cidrs) { + for(let i = 0, len = cidrs.length; i < len; i++){ + this.ipcidr.add(FileOutput.ipToCidr(cidrs[i], 4)); + } + return this; + } + bulkAddCIDR4NoResolve(cidrs) { + for(let i = 0, len = cidrs.length; i < len; i++){ + this.ipcidrNoResolve.add(FileOutput.ipToCidr(cidrs[i], 4)); + } + return this; + } + bulkAddCIDR6(cidrs) { + for(let i = 0, len = cidrs.length; i < len; i++){ + this.ipcidr6.add(FileOutput.ipToCidr(cidrs[i], 6)); + } + return this; + } + bulkAddCIDR6NoResolve(cidrs) { + for(let i = 0, len = cidrs.length; i < len; i++){ + this.ipcidr6NoResolve.add(FileOutput.ipToCidr(cidrs[i], 6)); + } + return this; + } + async done() { + await this.pendingPromise; + this.pendingPromise = null; + return this; + } + // private guardPendingPromise() { + // // reverse invariant + // if (this.pendingPromise !== null) { + // console.trace('Pending promise:', this.pendingPromise); + // throw new Error('You should call done() before calling this method'); + // } + // } + // async writeClash(outputDir?: null | string) { + // await this.done(); + // invariant(this.title, 'Missing title'); + // invariant(this.description, 'Missing description'); + // return compareAndWriteFile( + // this.span, + // withBannerArray( + // this.title, + // this.description, + // this.date, + // this.clash() + // ), + // path.join(outputDir ?? OUTPUT_CLASH_DIR, this.type, this.id + '.txt') + // ); + // } + strategiesWritten; + writeToStrategies() { + if (this.pendingPromise) { + throw new Error('You should call done() before calling writeToStrategies()'); + } + if (this.strategiesWritten) { + throw new Error('Strategies already written'); + } + this.strategiesWritten = true; + const kwfilter = (0, _retrie.createRetrieKeywordFilter)(Array.from(this.domainKeywords)); + if (this.strategies.filter((0, _guard.not)(false)).length === 0) { + throw new Error('No strategies to write ' + this.id); + } + this.domainTrie.dumpWithoutDot((domain, includeAllSubdomain)=>{ + if (kwfilter(domain)) { + return; + } + for(let i = 0, len = this.strategies.length; i < len; i++){ + const strategy = this.strategies[i]; + if (strategy) { + if (includeAllSubdomain) { + strategy.writeDomainSuffix(domain); + } else { + strategy.writeDomain(domain); + } + } + } + }, true); + for(let i = 0, len = this.strategies.length; i < len; i++){ + const strategy = this.strategies[i]; + if (!strategy) continue; + if (this.domainKeywords.size) { + strategy.writeDomainKeywords(this.domainKeywords); + } + if (this.domainWildcard.size) { + strategy.writeDomainWildcards(this.domainWildcard); + } + if (this.userAgent.size) { + strategy.writeUserAgents(this.userAgent); + } + if (this.processName.size) { + strategy.writeProcessNames(this.processName); + } + if (this.processPath.size) { + strategy.writeProcessPaths(this.processPath); + } + } + if (this.sourceIpOrCidr.size) { + const sourceIpOrCidr = Array.from(this.sourceIpOrCidr); + for(let i = 0, len = this.strategies.length; i < len; i++){ + const strategy = this.strategies[i]; + if (strategy) { + strategy.writeSourceIpCidrs(sourceIpOrCidr); + } + } + } + for(let i = 0, len = this.strategies.length; i < len; i++){ + const strategy = this.strategies[i]; + if (strategy) { + if (this.sourcePort.size) { + strategy.writeSourcePorts(this.sourcePort); + } + if (this.destPort.size) { + strategy.writeDestinationPorts(this.destPort); + } + if (this.otherRules.length) { + strategy.writeOtherRules(this.otherRules); + } + if (this.urlRegex.size) { + strategy.writeUrlRegexes(this.urlRegex); + } + } + } + let ipcidr = null; + let ipcidrNoResolve = null; + let ipcidr6 = null; + let ipcidr6NoResolve = null; + if (this.ipcidr.size) { + ipcidr = (0, _fastcidrtools.merge)(Array.from(this.ipcidr), true); + } + if (this.ipcidrNoResolve.size) { + ipcidrNoResolve = (0, _fastcidrtools.merge)(Array.from(this.ipcidrNoResolve), true); + } + if (this.ipcidr6.size) { + ipcidr6 = Array.from(this.ipcidr6); + } + if (this.ipcidr6NoResolve.size) { + ipcidr6NoResolve = Array.from(this.ipcidr6NoResolve); + } + for(let i = 0, len = this.strategies.length; i < len; i++){ + const strategy = this.strategies[i]; + if (strategy) { + // no-resolve + if (ipcidrNoResolve?.length) { + strategy.writeIpCidrs(ipcidrNoResolve, true); + } + if (ipcidr6NoResolve?.length) { + strategy.writeIpCidr6s(ipcidr6NoResolve, true); + } + if (this.ipasnNoResolve.size) { + strategy.writeIpAsns(this.ipasnNoResolve, true); + } + if (this.groipNoResolve.size) { + strategy.writeGeoip(this.groipNoResolve, true); + } + // triggers DNS resolution + if (ipcidr?.length) { + strategy.writeIpCidrs(ipcidr, false); + } + if (ipcidr6?.length) { + strategy.writeIpCidr6s(ipcidr6, false); + } + if (this.ipasn.size) { + strategy.writeIpAsns(this.ipasn, false); + } + if (this.geoip.size) { + strategy.writeGeoip(this.geoip, false); + } + } + } + } + write() { + return this.span.traceChildAsync('write all', async (childSpan)=>{ + await this.done(); + childSpan.traceChildSync('write to strategies', this.writeToStrategies.bind(this)); + return childSpan.traceChildAsync('output to disk', (childSpan)=>{ + const promises = []; + (0, _guard.invariant)(this.title, 'Missing title'); + (0, _guard.invariant)(this.description, 'Missing description'); + for(let i = 0, len = this.strategies.length; i < len; i++){ + const strategy = this.strategies[i]; + if (strategy) { + const basename = (strategy.overwriteFilename || this.id) + '.' + strategy.fileExtension; + promises.push(strategy.output(childSpan, this.title, this.description, this.date, _nodepath.default.join(strategy.outputDir, strategy.type ? _nodepath.default.join(strategy.type, basename) : basename))); + } + } + return Promise.all(promises); + }); + }); + } + async compile() { + await this.done(); + this.writeToStrategies(); + return this.strategies.reduce((acc, strategy)=>{ + if (strategy) { + acc.push(strategy.content); + } else { + acc.push(null); + } + return acc; + }, []); + } + withMitmSgmodulePath(moduleName) { + if (moduleName) { + this.withExtraStrategies(new _surge.SurgeMitmSgmodule(moduleName)); + } + return this; + } + } + } (base.__exports)); + return base.__exports; +}exports.__require=requireBase; \ No newline at end of file diff --git a/Dist/Build/lib/rules/domainset.cjs b/Dist/Build/lib/rules/domainset.cjs new file mode 100644 index 00000000..a184937b --- /dev/null +++ b/Dist/Build/lib/rules/domainset.cjs @@ -0,0 +1,47 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const domainset=require('../../../_virtual/domainset.cjs'),adguardhome=require('../writing-strategy/adguardhome.cjs'),clash=require('../writing-strategy/clash.cjs'),singbox=require('../writing-strategy/singbox.cjs'),surge=require('../writing-strategy/surge.cjs'),base=require('./base.cjs');var hasRequiredDomainset; + +function requireDomainset () { + if (hasRequiredDomainset) return domainset.__exports; + hasRequiredDomainset = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + AdGuardHomeOutput: function() { + return AdGuardHomeOutput; + }, + DomainsetOutput: function() { + return DomainsetOutput; + } + }); + const _adguardhome = /*@__PURE__*/ adguardhome.__require(); + const _clash = /*@__PURE__*/ clash.__require(); + const _singbox = /*@__PURE__*/ singbox.__require(); + const _surge = /*@__PURE__*/ surge.__require(); + const _base = /*@__PURE__*/ base.__require(); + class DomainsetOutput extends _base.FileOutput { + strategies = [ + new _surge.SurgeDomainSet(), + new _clash.ClashDomainSet(), + new _singbox.SingboxSource('domainset') + ]; + } + class AdGuardHomeOutput extends _base.FileOutput { + strategies; + constructor(span, id, outputDir){ + super(span, id); + this.strategies = [ + new _adguardhome.AdGuardHome(outputDir) + ]; + } + } + } (domainset.__exports)); + return domainset.__exports; +}exports.__require=requireDomainset; \ No newline at end of file diff --git a/Dist/Build/lib/rules/ip.cjs b/Dist/Build/lib/rules/ip.cjs new file mode 100644 index 00000000..9c084a0a --- /dev/null +++ b/Dist/Build/lib/rules/ip.cjs @@ -0,0 +1,34 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const ip=require('../../../_virtual/ip.cjs'),clash=require('../writing-strategy/clash.cjs'),singbox=require('../writing-strategy/singbox.cjs'),surge=require('../writing-strategy/surge.cjs'),base=require('./base.cjs');var hasRequiredIp; + +function requireIp () { + if (hasRequiredIp) return ip.__exports; + hasRequiredIp = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "IPListOutput", { + enumerable: true, + get: function() { + return IPListOutput; + } + }); + const _clash = /*@__PURE__*/ clash.__require(); + const _singbox = /*@__PURE__*/ singbox.__require(); + const _surge = /*@__PURE__*/ surge.__require(); + const _base = /*@__PURE__*/ base.__require(); + class IPListOutput extends _base.FileOutput { + clashUseRule; + strategies; + constructor(span, id, clashUseRule = true){ + super(span, id), this.clashUseRule = clashUseRule; + this.strategies = [ + new _surge.SurgeRuleSet('ip'), + this.clashUseRule ? new _clash.ClashClassicRuleSet('ip') : new _clash.ClashIPSet(), + new _singbox.SingboxSource('ip') + ]; + } + } + } (ip.__exports)); + return ip.__exports; +}exports.__require=requireIp; \ No newline at end of file diff --git a/Dist/Build/lib/rules/ruleset.cjs b/Dist/Build/lib/rules/ruleset.cjs new file mode 100644 index 00000000..5aba7308 --- /dev/null +++ b/Dist/Build/lib/rules/ruleset.cjs @@ -0,0 +1,59 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const ruleset=require('../../../_virtual/ruleset.cjs'),clash=require('../writing-strategy/clash.cjs'),singbox=require('../writing-strategy/singbox.cjs'),surge=require('../writing-strategy/surge.cjs'),base=require('./base.cjs');var hasRequiredRuleset; + +function requireRuleset () { + if (hasRequiredRuleset) return ruleset.__exports; + hasRequiredRuleset = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + ClashOnlyRulesetOutput: function() { + return ClashOnlyRulesetOutput; + }, + RulesetOutput: function() { + return RulesetOutput; + }, + SurgeOnlyRulesetOutput: function() { + return SurgeOnlyRulesetOutput; + } + }); + const _clash = /*@__PURE__*/ clash.__require(); + const _singbox = /*@__PURE__*/ singbox.__require(); + const _surge = /*@__PURE__*/ surge.__require(); + const _base = /*@__PURE__*/ base.__require(); + class RulesetOutput extends _base.FileOutput { + constructor(span, id, type){ + super(span, id); + this.strategies = [ + new _surge.SurgeRuleSet(type), + new _clash.ClashClassicRuleSet(type), + new _singbox.SingboxSource(type) + ]; + } + } + class SurgeOnlyRulesetOutput extends _base.FileOutput { + constructor(span, id, type, overrideOutputDir){ + super(span, id); + this.strategies = [ + new _surge.SurgeRuleSet(type, overrideOutputDir) + ]; + } + } + class ClashOnlyRulesetOutput extends _base.FileOutput { + constructor(span, id, type){ + super(span, id); + this.strategies = [ + new _clash.ClashClassicRuleSet(type) + ]; + } + } + } (ruleset.__exports)); + return ruleset.__exports; +}exports.__require=requireRuleset; \ No newline at end of file diff --git a/Dist/Build/lib/text-line-transform-stream.cjs b/Dist/Build/lib/text-line-transform-stream.cjs new file mode 100644 index 00000000..6ead9035 --- /dev/null +++ b/Dist/Build/lib/text-line-transform-stream.cjs @@ -0,0 +1,65 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const textLineTransformStream=require('../../_virtual/text-line-transform-stream.cjs'),require$$0=require('node:stream/web');var hasRequiredTextLineTransformStream; + +function requireTextLineTransformStream () { + if (hasRequiredTextLineTransformStream) return textLineTransformStream.__exports; + hasRequiredTextLineTransformStream = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "TextLineStream", { + enumerable: true, + get: function() { + return TextLineStream; + } + }); + const _web = require$$0; + class TextLineStream extends _web.TransformStream { + // private __buf = ''; + constructor({ allowCR = false } = {}){ + let __buf = ''; + let chunkIndex = 0; + super({ + transform (chunk, controller) { + chunk = __buf + chunk; + chunkIndex = 0; + for(;;){ + const lfIndex = chunk.indexOf('\n', chunkIndex); + if (allowCR) { + const crIndex = chunk.indexOf('\r', chunkIndex); + if (crIndex !== -1 && crIndex !== chunk.length - 1 && (lfIndex === -1 || lfIndex - 1 > crIndex)) { + controller.enqueue(chunk.slice(chunkIndex, crIndex)); + chunkIndex = crIndex + 1; + continue; + } + } + if (lfIndex === -1) { + break; + } + // enqueue current line, and loop again to find next line + let crOrLfIndex = lfIndex; + if (chunk[lfIndex - 1] === '\r') { + crOrLfIndex--; + } + controller.enqueue(chunk.slice(chunkIndex, crOrLfIndex)); + chunkIndex = lfIndex + 1; + continue; + } + __buf = chunk.slice(chunkIndex); + }, + flush (controller) { + if (__buf.length > 0) { + // eslint-disable-next-line sukka/string/prefer-string-starts-ends-with -- performance + if (allowCR && __buf[__buf.length - 1] === '\r') { + controller.enqueue(__buf.slice(0, -1)); + } else { + controller.enqueue(__buf); + } + } + } + }); + } + } + } (textLineTransformStream.__exports)); + return textLineTransformStream.__exports; +}exports.__require=requireTextLineTransformStream; \ No newline at end of file diff --git a/Dist/Build/lib/tree-dir.cjs b/Dist/Build/lib/tree-dir.cjs new file mode 100644 index 00000000..c646311a --- /dev/null +++ b/Dist/Build/lib/tree-dir.cjs @@ -0,0 +1,75 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const treeDir=require('../../_virtual/tree-dir.cjs'),require$$2=require('node:fs/promises'),require$$0=require('node:path');var hasRequiredTreeDir; + +function requireTreeDir () { + if (hasRequiredTreeDir) return treeDir.__exports; + hasRequiredTreeDir = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + TreeFileType: function() { + return TreeFileType; + }, + treeDir: function() { + return treeDir; + } + }); + const _promises = /*#__PURE__*/ _interop_require_default(require$$2); + const _nodepath = require$$0; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + var TreeFileType = /*#__PURE__*/ function(TreeFileType) { + TreeFileType[TreeFileType["FILE"] = 1] = "FILE"; + TreeFileType[TreeFileType["DIRECTORY"] = 2] = "DIRECTORY"; + return TreeFileType; + }({}); + async function treeDir(rootPath) { + const tree = []; + const walk = async (dir, node, dirRelativeToRoot = '')=>{ + const promises = []; + for await (const child of (await _promises.default.opendir(dir))){ + // Ignore hidden files + if (child.name[0] === '.' || child.name === 'CNAME') { + continue; + } + const childFullPath = child.parentPath + _nodepath.sep + child.name; + const childRelativeToRoot = dirRelativeToRoot + _nodepath.sep + child.name; + if (child.isDirectory()) { + const newNode = { + type: 2, + name: child.name, + path: childRelativeToRoot, + children: [] + }; + node.push(newNode); + promises.push(walk(childFullPath, newNode.children, childRelativeToRoot)); + continue; + } + if (child.isFile()) { + const newNode = { + type: 1, + name: child.name, + path: childRelativeToRoot + }; + node.push(newNode); + continue; + } + } + return Promise.all(promises); + }; + await walk(rootPath, tree); + return tree; + } + } (treeDir.__exports)); + return treeDir.__exports; +}exports.__require=requireTreeDir; \ No newline at end of file diff --git a/Dist/Build/lib/trie.cjs b/Dist/Build/lib/trie.cjs new file mode 100644 index 00000000..d99eb4d7 --- /dev/null +++ b/Dist/Build/lib/trie.cjs @@ -0,0 +1,540 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const trie=require('../../_virtual/trie.cjs'),misc=require('./misc.cjs'),require$$1=require('node:util'),require$$2=require('foxts/noop'),require$$3=require('foxts/fast-string-array-join'),require$$4=require('foxts/bitwise');/** + * Hostbane-Optimized Trie based on Mnemonist Trie + */ + +var hasRequiredTrie; + +function requireTrie () { + if (hasRequiredTrie) return trie.__exports; + hasRequiredTrie = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + HostnameSmolTrie: function() { + return HostnameSmolTrie; + }, + HostnameTrie: function() { + return HostnameTrie; + } + }); + const _misc = /*@__PURE__*/ misc.__require(); + const _nodeutil = /*#__PURE__*/ _interop_require_default(require$$1); + const _noop = require$$2; + const _faststringarrayjoin = require$$3; + const _bitwise = require$$4; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + var _computedKey; + const START = 1 << 1; + const INCLUDE_ALL_SUBDOMAIN = 1 << 2; + function deepTrieNodeToJSON(node, unpackMeta) { + const obj = {}; + obj['[start]'] = (0, _bitwise.getBit)(node[0], START); + obj['[subdomain]'] = (0, _bitwise.getBit)(node[0], INCLUDE_ALL_SUBDOMAIN); + if (node[3] != null) { + if (unpackMeta) { + obj['[meta]'] = unpackMeta(node[3]); + } else { + obj['[meta]'] = node[3]; + } + } + node[2].forEach((value, key)=>{ + obj[key] = deepTrieNodeToJSON(value, unpackMeta); + }); + return obj; + } + const createNode = (parent = null)=>[ + 1, + parent, + new Map(), + null + ]; + function hostnameToTokens(hostname, hostnameFromIndex) { + const tokens = hostname.split('.'); + const results = []; + let token = ''; + for(let i = hostnameFromIndex, l = tokens.length; i < l; i++){ + token = tokens[i]; + if (token.length > 0) { + results.push(token); + } else { + throw new TypeError(JSON.stringify({ + hostname, + hostnameFromIndex + }, null, 2)); + } + } + return results; + } + function walkHostnameTokens(hostname, onToken, hostnameFromIndex) { + const tokens = hostname.split('.'); + const l = tokens.length - 1; + // we are at the first of hostname, no splitor there + let token = ''; + for(let i = l; i >= hostnameFromIndex; i--){ + token = tokens[i]; + if (token.length > 0) { + const t = onToken(token); + if (t === null) { + return null; + } + // if the callback returns true, we should skip the rest + if (t) { + return true; + } + } + } + return false; + } + _computedKey = _nodeutil.default.inspect.custom; + class Triebase { + $root = createNode(); + $size = 0; + get root() { + return this.$root; + } + constructor(from){ + // Actually build trie + if (Array.isArray(from)) { + for(let i = 0, l = from.length; i < l; i++){ + this.add(from[i]); + } + } else if (from) { + from.forEach((value)=>this.add(value)); + } + } + walkIntoLeafWithTokens(tokens, onLoop = _noop.noop) { + let node = this.$root; + let parent = node; + let token; + let child = node[2]; + // reverse lookup from end to start + for(let i = tokens.length - 1; i >= 0; i--){ + token = tokens[i]; + // if (token === '') { + // break; + // } + parent = node; + child = node[2]; + // cache node index access is 20% faster than direct access when doing twice + if (child.has(token)) { + node = child.get(token); + } else { + return null; + } + onLoop(node, parent, token); + } + return { + node, + parent + }; + } + walkIntoLeafWithSuffix(suffix, hostnameFromIndex, onLoop = _noop.noop) { + let node = this.$root; + let parent = node; + let child = node[2]; + const onToken = (token)=>{ + // if (token === '') { + // return true; + // } + parent = node; + child = node[2]; + if (child.has(token)) { + node = child.get(token); + } else { + return null; + } + onLoop(node, parent, token); + return false; + }; + if (walkHostnameTokens(suffix, onToken, hostnameFromIndex) === null) { + return null; + } + return { + node, + parent + }; + } + contains(suffix, includeAllSubdomain = suffix[0] === '.') { + const hostnameFromIndex = suffix[0] === '.' ? 1 : 0; + const res = this.walkIntoLeafWithSuffix(suffix, hostnameFromIndex); + if (!res) return false; + if (includeAllSubdomain) return (0, _bitwise.getBit)(res.node[0], INCLUDE_ALL_SUBDOMAIN); + return true; + } + static bfsResults = [ + null, + [] + ]; + static dfs(nodeStack, suffixStack) { + const node = nodeStack.pop(); + const suffix = suffixStack.pop(); + node[2].forEach((childNode, k)=>{ + // Pushing the child node to the stack for next iteration of DFS + nodeStack.push(childNode); + suffixStack.push([ + k, + ...suffix + ]); + }); + Triebase.bfsResults[0] = node; + Triebase.bfsResults[1] = suffix; + return Triebase.bfsResults; + } + static dfsWithSort(nodeStack, suffixStack) { + const node = nodeStack.pop(); + const suffix = suffixStack.pop(); + const child = node[2]; + if (child.size) { + const keys = Array.from(child.keys()).sort(Triebase.compare); + for(let i = 0, l = keys.length; i < l; i++){ + const key = keys[i]; + const childNode = child.get(key); + // Pushing the child node to the stack for next iteration of DFS + nodeStack.push(childNode); + suffixStack.push([ + key, + ...suffix + ]); + } + } + Triebase.bfsResults[0] = node; + Triebase.bfsResults[1] = suffix; + return Triebase.bfsResults; + } + walk(onMatches, initialNode = this.$root, initialSuffix = [], withSort = false) { + const bfsImpl = withSort ? Triebase.dfsWithSort : Triebase.dfs; + const nodeStack = []; + nodeStack.push(initialNode); + // Resolving initial string (begin the start of the stack) + const suffixStack = []; + suffixStack.push(initialSuffix); + let node = initialNode; + let r; + do { + r = bfsImpl(nodeStack, suffixStack); + node = r[0]; + const suffix = r[1]; + // If the node is a sentinel, we push the suffix to the results + if ((0, _bitwise.getBit)(node[0], START)) { + onMatches(suffix, (0, _bitwise.getBit)(node[0], INCLUDE_ALL_SUBDOMAIN), node[3]); + } + }while (nodeStack.length) + } + static compare(a, b) { + if (a === b) return 0; + return a.length - b.length || (0, _misc.fastStringCompare)(a, b); + } + walkWithSort(onMatches, initialNode = this.$root, initialSuffix = []) { + const nodeStack = []; + nodeStack.push(initialNode); + // Resolving initial string (begin the start of the stack) + const suffixStack = []; + suffixStack.push(initialSuffix); + let node = initialNode; + let child = node[2]; + do { + node = nodeStack.pop(); + const suffix = suffixStack.pop(); + child = node[2]; + if (child.size) { + const keys = Array.from(child.keys()).sort(Triebase.compare); + for(let i = 0, l = keys.length; i < l; i++){ + const key = keys[i]; + const childNode = child.get(key); + // Pushing the child node to the stack for next iteration of DFS + nodeStack.push(childNode); + suffixStack.push([ + key, + ...suffix + ]); + } + } + // If the node is a sentinel, we push the suffix to the results + if ((0, _bitwise.getBit)(node[0], START)) { + onMatches(suffix, (0, _bitwise.getBit)(node[0], INCLUDE_ALL_SUBDOMAIN), node[3]); + } + }while (nodeStack.length) + } + getSingleChildLeaf(tokens) { + let toPrune = null; + let tokenToPrune = null; + const onLoop = (node, parent, token)=>{ + // Keeping track of a potential branch to prune + const child = node[2]; + // console.log({ + // child, parent, token + // }); + // console.log(this.inspect(0)); + if (toPrune !== null) { + if (child.size > 1) { + // The branch has some children, the branch need retain. + // And we need to abort prune that parent branch, so we set it to null + toPrune = null; + tokenToPrune = null; + } + } else if (child.size < 1) { + // There is only one token child, or no child at all, we can prune it safely + // It is now the top-est branch that could potentially being pruned + toPrune = parent; + tokenToPrune = token; + } + }; + const res = this.walkIntoLeafWithTokens(tokens, onLoop); + if (res === null) return null; + return { + node: res.node, + toPrune, + tokenToPrune, + parent: res.parent + }; + } + /** + * Method used to retrieve every item in the trie with the given prefix. + */ find(inputSuffix, subdomainOnly = inputSuffix[0] === '.', hostnameFromIndex = inputSuffix[0] === '.' ? 1 : 0) { + const inputTokens = hostnameToTokens(inputSuffix, hostnameFromIndex); + const res = this.walkIntoLeafWithTokens(inputTokens); + if (res === null) return []; + const results = []; + const onMatches = subdomainOnly ? (suffix, subdomain)=>{ + const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'); + if (!subdomain && subStringEqual(inputSuffix, d, 1)) return; + results.push(subdomain ? '.' + d : d); + } : (suffix, subdomain)=>{ + const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'); + results.push(subdomain ? '.' + d : d); + }; + this.walk(onMatches, res.node, inputTokens); + return results; + } + /** + * Method used to delete a prefix from the trie. + */ remove(suffix) { + const res = this.getSingleChildLeaf(hostnameToTokens(suffix, 0)); + if (res === null) return false; + if ((0, _bitwise.missingBit)(res.node[0], START)) return false; + this.$size--; + const { node, toPrune, tokenToPrune } = res; + if (tokenToPrune && toPrune) { + toPrune[2].delete(tokenToPrune); + } else { + node[0] = (0, _bitwise.deleteBit)(node[0], START); + } + return true; + } + // eslint-disable-next-line @typescript-eslint/unbound-method -- safe + delete = this.remove; + /** + * Method used to assert whether the given prefix exists in the Trie. + */ has(suffix, includeAllSubdomain = suffix[0] === '.') { + const hostnameFromIndex = suffix[0] === '.' ? 1 : 0; + const res = this.walkIntoLeafWithSuffix(suffix, hostnameFromIndex); + if (res === null) return false; + if ((0, _bitwise.missingBit)(res.node[0], START)) return false; + if (includeAllSubdomain) return (0, _bitwise.getBit)(res.node[0], INCLUDE_ALL_SUBDOMAIN); + return true; + } + dumpWithoutDot(onSuffix, withSort = false) { + const handleSuffix = (suffix, subdomain)=>{ + onSuffix((0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'), subdomain); + }; + if (withSort) { + this.walkWithSort(handleSuffix); + } else { + this.walk(handleSuffix); + } + } + dump(onSuffix, withSort = false) { + const results = []; + const handleSuffix = onSuffix ? (suffix, subdomain)=>{ + const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'); + onSuffix(subdomain ? '.' + d : d); + } : (suffix, subdomain)=>{ + const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'); + results.push(subdomain ? '.' + d : d); + }; + if (withSort) { + this.walkWithSort(handleSuffix); + } else { + this.walk(handleSuffix); + } + return results; + } + dumpMeta(onMeta, withSort = false) { + const results = []; + const handleMeta = onMeta ? (_suffix, _subdomain, meta)=>onMeta(meta) : (_suffix, _subdomain, meta)=>results.push(meta); + if (withSort) { + this.walkWithSort(handleMeta); + } else { + this.walk(handleMeta); + } + return results; + } + dumpWithMeta(onSuffix, withSort = false) { + const results = []; + const handleSuffix = onSuffix ? (suffix, subdomain, meta)=>{ + const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'); + return onSuffix(subdomain ? '.' + d : d, meta); + } : (suffix, subdomain, meta)=>{ + const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'); + results.push([ + subdomain ? '.' + d : d, + meta + ]); + }; + if (withSort) { + this.walkWithSort(handleSuffix); + } else { + this.walk(handleSuffix); + } + return results; + } + inspect(depth, unpackMeta) { + return (0, _faststringarrayjoin.fastStringArrayJoin)(JSON.stringify(deepTrieNodeToJSON(this.$root, unpackMeta), null, 2).split('\n').map((line)=>' '.repeat(depth) + line), '\n'); + } + [_computedKey](depth) { + return this.inspect(depth); + } + merge(trie) { + const handleSuffix = (suffix, subdomain, meta)=>{ + this.add((0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'), subdomain, meta); + }; + trie.walk(handleSuffix); + return this; + } + } + class HostnameSmolTrie extends Triebase { + smolTree = true; + add(suffix, includeAllSubdomain = suffix[0] === '.', meta, hostnameFromIndex = suffix[0] === '.' ? 1 : 0) { + let node = this.$root; + let curNodeChildren = node[2]; + const onToken = (token)=>{ + curNodeChildren = node[2]; + if (curNodeChildren.has(token)) { + node = curNodeChildren.get(token); + // During the adding of `[start]blog|.skk.moe` and find out that there is a `[start].skk.moe` in the trie, skip adding the rest of the node + if ((0, _bitwise.getBit)(node[0], INCLUDE_ALL_SUBDOMAIN)) { + return true; + } + } else { + const newNode = createNode(node); + curNodeChildren.set(token, newNode); + node = newNode; + } + return false; + }; + // When walkHostnameTokens returns true, we should skip the rest + if (walkHostnameTokens(suffix, onToken, hostnameFromIndex)) { + return; + } + // If we are in smolTree mode, we need to do something at the end of the loop + if (includeAllSubdomain) { + // Trying to add `[.]sub.example.com` where there is already a `blog.sub.example.com` in the trie + // Make sure parent `[start]sub.example.com` (without dot) is removed (SETINEL to false) + // (/** parent */ node[2]!)[0] = false; + // Removing the rest of the parent's child nodes + node[2].clear(); + // The SENTINEL of this node will be set to true at the end of the function, so we don't need to set it here + // we can use else-if here, because the children is now empty, we don't need to check the leading "." + } else if ((0, _bitwise.getBit)(node[0], INCLUDE_ALL_SUBDOMAIN)) { + // Trying to add `example.com` when there is already a `.example.com` in the trie + // No need to increment size and set SENTINEL to true (skip this "new" item) + return; + } + node[0] = (0, _bitwise.setBit)(node[0], START); + if (includeAllSubdomain) { + node[0] = (0, _bitwise.setBit)(node[0], INCLUDE_ALL_SUBDOMAIN); + } else { + node[0] = (0, _bitwise.deleteBit)(node[0], INCLUDE_ALL_SUBDOMAIN); + } + node[3] = meta; + } + whitelist(suffix, includeAllSubdomain = suffix[0] === '.', hostnameFromIndex = suffix[0] === '.' ? 1 : 0) { + const tokens = hostnameToTokens(suffix, hostnameFromIndex); + const res = this.getSingleChildLeaf(tokens); + if (res === null) return; + const { node, toPrune, tokenToPrune } = res; + // Trying to whitelist `[start].sub.example.com` where there might already be a `[start]blog.sub.example.com` in the trie + if (includeAllSubdomain) { + // If there is a `[start]sub.example.com` here, remove it + node[0] = (0, _bitwise.deleteBit)(node[0], INCLUDE_ALL_SUBDOMAIN); + node[0] = (0, _bitwise.deleteBit)(node[0], START); + // Removing all the child nodes by empty the children + node[2].clear(); + } else { + // Trying to whitelist `example.com` when there is already a `.example.com` in the trie + node[0] = (0, _bitwise.deleteBit)(node[0], INCLUDE_ALL_SUBDOMAIN); + } + // return early if not found + if ((0, _bitwise.missingBit)(node[0], START)) return; + if (toPrune && tokenToPrune) { + toPrune[2].delete(tokenToPrune); + } else { + node[0] = (0, _bitwise.deleteBit)(node[0], START); + } + } + } + class HostnameTrie extends Triebase { + get size() { + return this.$size; + } + add(suffix, includeAllSubdomain = suffix[0] === '.', meta, hostnameFromIndex = suffix[0] === '.' ? 1 : 0) { + let node = this.$root; + let child = node[2]; + const onToken = (token)=>{ + child = node[2]; + if (child.has(token)) { + node = child.get(token); + } else { + const newNode = createNode(node); + child.set(token, newNode); + node = newNode; + } + return false; + }; + // When walkHostnameTokens returns true, we should skip the rest + if (walkHostnameTokens(suffix, onToken, hostnameFromIndex)) { + return; + } + // if same entry has been added before, skip + if ((0, _bitwise.getBit)(node[0], START)) { + return; + } + this.$size++; + node[0] = (0, _bitwise.setBit)(node[0], START); + if (includeAllSubdomain) { + node[0] = (0, _bitwise.setBit)(node[0], INCLUDE_ALL_SUBDOMAIN); + } else { + node[0] = (0, _bitwise.deleteBit)(node[0], INCLUDE_ALL_SUBDOMAIN); + } + node[3] = meta; + } + } + // function deepEqualArray(a: string[], b: string[]) { + // let len = a.length; + // if (len !== b.length) return false; + // while (len--) { + // if (a[len] !== b[len]) return false; + // } + // return true; + // }; + function subStringEqual(needle, haystack, needleIndex = 0) { + for(let i = 0, l = haystack.length; i < l; i++){ + if (needle[i + needleIndex] !== haystack[i]) return false; + } + return true; + } + } (trie.__exports)); + return trie.__exports; +}exports.__require=requireTrie; \ No newline at end of file diff --git a/Dist/Build/lib/writing-strategy/adguardhome.cjs b/Dist/Build/lib/writing-strategy/adguardhome.cjs new file mode 100644 index 00000000..7d074649 --- /dev/null +++ b/Dist/Build/lib/writing-strategy/adguardhome.cjs @@ -0,0 +1,113 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const adguardhome=require('../../../_virtual/adguardhome.cjs'),require$$0=require('foxts/escape-string-regexp'),base=require('./base.cjs'),require$$2=require('foxts/noop'),misc=require('../misc.cjs');var hasRequiredAdguardhome; + +function requireAdguardhome () { + if (hasRequiredAdguardhome) return adguardhome.__exports; + hasRequiredAdguardhome = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "AdGuardHome", { + enumerable: true, + get: function() { + return AdGuardHome; + } + }); + const _escapestringregexp = require$$0; + const _base = /*@__PURE__*/ base.__require(); + const _noop = require$$2; + const _misc = /*@__PURE__*/ misc.__require(); + class AdGuardHome extends _base.BaseWriteStrategy { + // readonly type = 'domainset'; + fileExtension = 'txt'; + type = ''; + result = []; + // eslint-disable-next-line @typescript-eslint/class-methods-use-this -- abstract method + withPadding(title, description, date, content) { + return [ + `! Title: ${title}`, + '! Last modified: ' + date.toUTCString(), + '! Expires: 6 hours', + '! License: https://github.com/SukkaW/Surge/blob/master/LICENSE', + '! Homepage: https://github.com/SukkaW/Surge', + `! Description: ${description.join(' ')}`, + '!', + ...content, + '! EOF' + ]; + } + writeDomain(domain) { + this.result.push(`|${domain}^`); + } + // const whitelistArray = sortDomains(Array.from(whitelist)); + // for (let i = 0, len = whitelistArray.length; i < len; i++) { + // const domain = whitelistArray[i]; + // if (domain[0] === '.') { + // results.push(`@@||${domain.slice(1)}^`); + // } else { + // results.push(`@@|${domain}^`); + // } + // } + writeDomainSuffix(domain) { + this.result.push(`||${domain}^`); + } + writeDomainKeywords(keywords) { + for (const keyword of keywords){ + // Use regex to match keyword + this.result.push(`/${(0, _escapestringregexp.escapeStringRegexp)(keyword)}/`); + } + } + writeDomainWildcards(wildcards) { + for (const wildcard of wildcards){ + const processed = wildcard.replaceAll('?', '*'); + if (processed.startsWith('*.')) { + this.result.push(`||${processed.slice(2)}^`); + } else { + this.result.push(`|${processed}^`); + } + } + } + writeUserAgents = _noop.noop; + writeProcessNames = _noop.noop; + writeProcessPaths = _noop.noop; + writeUrlRegexes = _noop.noop; + writeIpCidrs(ipGroup, noResolve) { + if (noResolve) { + // When IP is provided to AdGuardHome, any domain resolve to those IP will be blocked + // So we can't do noResolve + return; + } + for (const ipcidr of ipGroup){ + if (ipcidr.endsWith('/32')) { + this.result.push(`||${ipcidr.slice(0, -3)}`); + /* else if (ipcidr.endsWith('.0/24')) { + results.push(`||${ipcidr.slice(0, -6)}.*`); + } */ } else { + this.result.push(`||${ipcidr}^`); + } + } + } + writeIpCidr6s(ipGroup, noResolve) { + if (noResolve) { + // When IP is provided to AdGuardHome, any domain resolve to those IP will be blocked + // So we can't do noResolve + return; + } + for (const ipcidr of ipGroup){ + if (ipcidr.endsWith('/128')) { + this.result.push(`||${ipcidr.slice(0, -4)}`); + } else { + this.result.push(`||${ipcidr}`); + } + } + } + writeGeoip = (0, _misc.notSupported)('writeGeoip'); + writeIpAsns = (0, _misc.notSupported)('writeIpAsns'); + writeSourceIpCidrs = (0, _misc.notSupported)('writeSourceIpCidrs'); + writeSourcePorts = (0, _misc.notSupported)('writeSourcePorts'); + writeDestinationPorts = _noop.noop; + writeOtherRules = _noop.noop; + } + } (adguardhome.__exports)); + return adguardhome.__exports; +}exports.__require=requireAdguardhome; \ No newline at end of file diff --git a/Dist/Build/lib/writing-strategy/base.cjs b/Dist/Build/lib/writing-strategy/base.cjs new file mode 100644 index 00000000..241a17cf --- /dev/null +++ b/Dist/Build/lib/writing-strategy/base.cjs @@ -0,0 +1,63 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const base=require('../../../_virtual/base2.cjs'),createFile=require('../create-file.cjs');var hasRequiredBase; + +function requireBase () { + if (hasRequiredBase) return base.__exports; + hasRequiredBase = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "BaseWriteStrategy", { + enumerable: true, + get: function() { + return BaseWriteStrategy; + } + }); + const _createfile = /*@__PURE__*/ createFile.__require(); + class BaseWriteStrategy { + outputDir; + /** + * Sometimes a ruleset will create extra files (e.g. reject-url-regex w/ mitm.sgmodule), + * and doesn't share the same filename and id. This property is used to overwrite the filename. + */ overwriteFilename; + withFilename(filename) { + this.overwriteFilename = filename; + return this; + } + constructor(outputDir){ + this.outputDir = outputDir; + this.overwriteFilename = null; + } + static domainWildCardToRegex = (domain)=>{ + let result = '^'; + for(let i = 0, len = domain.length; i < len; i++){ + switch(domain[i]){ + case '.': + result += String.raw`\.`; + break; + case '*': + result += String.raw`[\w.-]*?`; + break; + case '?': + result += String.raw`[\w.-]`; + break; + default: + result += domain[i]; + } + } + result += '$'; + return result; + }; + output(span, title, description, date, filePath) { + if (!this.result) { + return; + } + return (0, _createfile.compareAndWriteFile)(span, this.withPadding(title, description, date, this.result), filePath); + } + get content() { + return this.result; + } + } + } (base.__exports)); + return base.__exports; +}exports.__require=requireBase; \ No newline at end of file diff --git a/Dist/Build/lib/writing-strategy/clash.cjs b/Dist/Build/lib/writing-strategy/clash.cjs new file mode 100644 index 00000000..03b0a8ce --- /dev/null +++ b/Dist/Build/lib/writing-strategy/clash.cjs @@ -0,0 +1,172 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const clash=require('../../../_virtual/clash.cjs'),require$$0=require('foxts/append-set-elements-to-array'),base=require('./base.cjs'),require$$2=require('foxts/noop'),misc=require('../misc.cjs'),dir=require('../../constants/dir.cjs'),appendArrayInPlace=require('../append-array-in-place.cjs');var hasRequiredClash; + +function requireClash () { + if (hasRequiredClash) return clash.__exports; + hasRequiredClash = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + ClashClassicRuleSet: function() { + return ClashClassicRuleSet; + }, + ClashDomainSet: function() { + return ClashDomainSet; + }, + ClashIPSet: function() { + return ClashIPSet; + } + }); + const _appendsetelementstoarray = require$$0; + const _base = /*@__PURE__*/ base.__require(); + const _noop = require$$2; + const _misc = /*@__PURE__*/ misc.__require(); + const _dir = /*@__PURE__*/ dir.__require(); + const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require(); + class ClashDomainSet extends _base.BaseWriteStrategy { + outputDir; + // readonly type = 'domainset'; + fileExtension; + type; + result; + constructor(outputDir = _dir.OUTPUT_CLASH_DIR){ + super(outputDir), this.outputDir = outputDir, this.fileExtension = 'txt', this.type = 'domainset', this.result = [ + 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe' + ], this.withPadding = _misc.withBannerArray, this.writeDomainKeywords = _noop.noop, this.writeDomainWildcards = _noop.noop, this.writeUserAgents = _noop.noop, this.writeProcessNames = _noop.noop, this.writeProcessPaths = _noop.noop, this.writeUrlRegexes = _noop.noop, this.writeIpCidrs = _noop.noop, this.writeIpCidr6s = _noop.noop, this.writeGeoip = _noop.noop, this.writeIpAsns = _noop.noop, this.writeSourceIpCidrs = _noop.noop, this.writeSourcePorts = _noop.noop, this.writeDestinationPorts = _noop.noop, this.writeOtherRules = _noop.noop; + } + withPadding; + writeDomain(domain) { + this.result.push(domain); + } + writeDomainSuffix(domain) { + this.result.push('+.' + domain); + } + writeDomainKeywords; + writeDomainWildcards; + writeUserAgents; + writeProcessNames; + writeProcessPaths; + writeUrlRegexes; + writeIpCidrs; + writeIpCidr6s; + writeGeoip; + writeIpAsns; + writeSourceIpCidrs; + writeSourcePorts; + writeDestinationPorts; + writeOtherRules; + } + class ClashIPSet extends _base.BaseWriteStrategy { + outputDir; + // readonly type = 'domainset'; + fileExtension; + type; + result; + constructor(outputDir = _dir.OUTPUT_CLASH_DIR){ + super(outputDir), this.outputDir = outputDir, this.fileExtension = 'txt', this.type = 'ip', this.result = [], this.withPadding = _misc.withBannerArray, this.writeDomain = (0, _misc.notSupported)('writeDomain'), this.writeDomainSuffix = (0, _misc.notSupported)('writeDomainSuffix'), this.writeDomainKeywords = (0, _misc.notSupported)('writeDomainKeywords'), this.writeDomainWildcards = (0, _misc.notSupported)('writeDomainWildcards'), this.writeUserAgents = (0, _misc.notSupported)('writeUserAgents'), this.writeProcessNames = (0, _misc.notSupported)('writeProcessNames'), this.writeProcessPaths = (0, _misc.notSupported)('writeProcessPaths'), this.writeUrlRegexes = (0, _misc.notSupported)('writeUrlRegexes'), this.writeGeoip = (0, _misc.notSupported)('writeGeoip'), this.writeIpAsns = (0, _misc.notSupported)('writeIpAsns'), this.writeSourceIpCidrs = (0, _misc.notSupported)('writeSourceIpCidrs'), this.writeSourcePorts = (0, _misc.notSupported)('writeSourcePorts'), this.writeDestinationPorts = _noop.noop, this.writeOtherRules = _noop.noop; + } + withPadding; + writeDomain; + writeDomainSuffix; + writeDomainKeywords; + writeDomainWildcards; + writeUserAgents; + writeProcessNames; + writeProcessPaths; + writeUrlRegexes; + writeIpCidrs(ipCidr) { + (0, _appendarrayinplace.appendArrayInPlace)(this.result, ipCidr); + } + writeIpCidr6s(ipCidr6) { + (0, _appendarrayinplace.appendArrayInPlace)(this.result, ipCidr6); + } + writeGeoip; + writeIpAsns; + writeSourceIpCidrs; + writeSourcePorts; + writeDestinationPorts; + writeOtherRules; + } + class ClashClassicRuleSet extends _base.BaseWriteStrategy { + type; + outputDir; + fileExtension; + result; + constructor(type/* | (string & {}) */ , outputDir = _dir.OUTPUT_CLASH_DIR){ + super(outputDir), this.type = type, this.outputDir = outputDir, this.fileExtension = 'txt', this.result = [ + 'DOMAIN,this_ruleset_is_made_by_sukkaw.ruleset.skk.moe' + ], this.withPadding = _misc.withBannerArray, this.writeUserAgents = _noop.noop, this.writeUrlRegexes = _noop.noop, this.writeOtherRules = _noop.noop; + } + withPadding; + writeDomain(domain) { + this.result.push('DOMAIN,' + domain); + } + writeDomainSuffix(domain) { + this.result.push('DOMAIN-SUFFIX,' + domain); + } + writeDomainKeywords(keyword) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, keyword, (i)=>`DOMAIN-KEYWORD,${i}`); + } + writeDomainWildcards(wildcard) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, wildcard, (i)=>`DOMAIN-REGEX,${ClashClassicRuleSet.domainWildCardToRegex(i)}`); + } + writeUserAgents; + writeProcessNames(processName) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processName, (i)=>`PROCESS-NAME,${i}`); + } + writeProcessPaths(processPath) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processPath, (i)=>`PROCESS-PATH,${i}`); + } + writeUrlRegexes; + writeIpCidrs(ipCidr, noResolve) { + for(let i = 0, len = ipCidr.length; i < len; i++){ + this.result.push(`IP-CIDR,${ipCidr[i]}${noResolve ? ',no-resolve' : ''}`); + } + } + writeIpCidr6s(ipCidr6, noResolve) { + for(let i = 0, len = ipCidr6.length; i < len; i++){ + this.result.push(`IP-CIDR6,${ipCidr6[i]}${noResolve ? ',no-resolve' : ''}`); + } + } + writeGeoip(geoip, noResolve) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, geoip, (i)=>`GEOIP,${i}${noResolve ? ',no-resolve' : ''}`); + } + writeIpAsns(asns, noResolve) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, asns, (i)=>`IP-ASN,${i}${noResolve ? ',no-resolve' : ''}`); + } + writeSourceIpCidrs(sourceIpCidr) { + for(let i = 0, len = sourceIpCidr.length; i < len; i++){ + const value = sourceIpCidr[i]; + if (value.includes('/')) { + this.result.push(`SRC-IP-CIDR,${value}`); + continue; + } + const v = (0, _misc.fastIpVersion)(value); + if (v === 4) { + this.result.push(`SRC-IP-CIDR,${value}/32`); + continue; + } + if (v === 6) { + this.result.push(`SRC-IP-CIDR6,${value}/128`); + continue; + } + } + } + writeSourcePorts(port) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`SRC-PORT,${i}`); + } + writeDestinationPorts(port) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`DST-PORT,${i}`); + } + writeOtherRules; + } + } (clash.__exports)); + return clash.__exports; +}exports.__require=requireClash; \ No newline at end of file diff --git a/Dist/Build/lib/writing-strategy/singbox.cjs b/Dist/Build/lib/writing-strategy/singbox.cjs new file mode 100644 index 00000000..27b43b32 --- /dev/null +++ b/Dist/Build/lib/writing-strategy/singbox.cjs @@ -0,0 +1,121 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const singbox=require('../../../_virtual/singbox.cjs'),base=require('./base.cjs'),appendArrayInPlace=require('../append-array-in-place.cjs'),require$$2=require('foxts/noop'),misc=require('../misc.cjs'),require$$4=require('json-stringify-pretty-compact'),dir=require('../../constants/dir.cjs');var hasRequiredSingbox; + +function requireSingbox () { + if (hasRequiredSingbox) return singbox.__exports; + hasRequiredSingbox = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "SingboxSource", { + enumerable: true, + get: function() { + return SingboxSource; + } + }); + const _base = /*@__PURE__*/ base.__require(); + const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require(); + const _noop = require$$2; + const _misc = /*@__PURE__*/ misc.__require(); + const _jsonstringifyprettycompact = /*#__PURE__*/ _interop_require_default(require$$4); + const _dir = /*@__PURE__*/ dir.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + class SingboxSource extends _base.BaseWriteStrategy { + type; + outputDir; + fileExtension; + static jsonToLines = (json)=>(0, _jsonstringifyprettycompact.default)(json).split('\n'); + singbox; + get result() { + return SingboxSource.jsonToLines({ + version: 2, + rules: [ + this.singbox + ] + }); + } + constructor(/** Since sing-box only have one format that does not reflect type, we need to specify it */ type/* | (string & {}) */ , outputDir = _dir.OUTPUT_SINGBOX_DIR){ + super(outputDir), this.type = type, this.outputDir = outputDir, this.fileExtension = 'json', this.singbox = { + domain: [ + 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe' + ], + domain_suffix: [ + 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe' + ] + }, this.withPadding = _misc.withIdentityContent, this.writeUserAgents = _noop.noop, this.writeUrlRegexes = _noop.noop, this.writeGeoip = _noop.noop, this.writeIpAsns = _noop.noop, this.writeOtherRules = _noop.noop; + } + withPadding; + writeDomain(domain) { + this.singbox.domain.push(domain); + } + writeDomainSuffix(domain) { + this.singbox.domain_suffix.push(domain); + } + writeDomainKeywords(keyword) { + (0, _appendarrayinplace.appendArrayInPlace)(this.singbox.domain_keyword ??= [], Array.from(keyword)); + } + writeDomainWildcards(wildcard) { + (0, _appendarrayinplace.appendArrayInPlace)(this.singbox.domain_regex ??= [], Array.from(wildcard, SingboxSource.domainWildCardToRegex)); + } + writeUserAgents; + writeProcessNames(processName) { + (0, _appendarrayinplace.appendArrayInPlace)(this.singbox.process_name ??= [], Array.from(processName)); + } + writeProcessPaths(processPath) { + (0, _appendarrayinplace.appendArrayInPlace)(this.singbox.process_path ??= [], Array.from(processPath)); + } + writeUrlRegexes; + writeIpCidrs(ipCidr) { + (0, _appendarrayinplace.appendArrayInPlace)(this.singbox.ip_cidr ??= [], ipCidr); + } + writeIpCidr6s(ipCidr6) { + (0, _appendarrayinplace.appendArrayInPlace)(this.singbox.ip_cidr ??= [], ipCidr6); + } + writeGeoip; + writeIpAsns; + writeSourceIpCidrs(sourceIpCidr) { + this.singbox.source_ip_cidr ??= []; + for(let i = 0, len = sourceIpCidr.length; i < len; i++){ + const value = sourceIpCidr[i]; + if (value.includes('/')) { + this.singbox.source_ip_cidr.push(value); + continue; + } + const v = (0, _misc.fastIpVersion)(value); + if (v === 4) { + this.singbox.source_ip_cidr.push(`${value}/32`); + continue; + } + if (v === 6) { + this.singbox.source_ip_cidr.push(`${value}/128`); + continue; + } + } + } + writeSourcePorts(port) { + this.singbox.source_port ??= []; + for (const i of port){ + const tmp = Number(i); + if (!Number.isNaN(tmp)) { + this.singbox.source_port.push(tmp); + } + } + } + writeDestinationPorts(port) { + this.singbox.port ??= []; + for (const i of port){ + const tmp = Number(i); + if (!Number.isNaN(tmp)) { + this.singbox.port.push(tmp); + } + } + } + writeOtherRules; + } + } (singbox.__exports)); + return singbox.__exports; +}exports.__require=requireSingbox; \ No newline at end of file diff --git a/Dist/Build/lib/writing-strategy/surge.cjs b/Dist/Build/lib/writing-strategy/surge.cjs new file mode 100644 index 00000000..5af7be01 --- /dev/null +++ b/Dist/Build/lib/writing-strategy/surge.cjs @@ -0,0 +1,246 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const surge=require('../../../_virtual/surge.cjs'),require$$0=require('foxts/append-set-elements-to-array'),base=require('./base.cjs'),appendArrayInPlace=require('../append-array-in-place.cjs'),require$$2=require('foxts/noop'),require$$2$1=require('foxts/is-probably-ip'),require$$0$1=require('picocolors'),normalizeDomain=require('../normalize-domain.cjs'),dir=require('../../constants/dir.cjs'),misc=require('../misc.cjs');var hasRequiredSurge; + +function requireSurge () { + if (hasRequiredSurge) return surge.__exports; + hasRequiredSurge = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + SurgeDomainSet: function() { + return SurgeDomainSet; + }, + SurgeMitmSgmodule: function() { + return SurgeMitmSgmodule; + }, + SurgeRuleSet: function() { + return SurgeRuleSet; + } + }); + const _appendsetelementstoarray = require$$0; + const _base = /*@__PURE__*/ base.__require(); + const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require(); + const _noop = require$$2; + const _isprobablyip = require$$2$1; + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _normalizedomain = /*@__PURE__*/ normalizeDomain.__require(); + const _dir = /*@__PURE__*/ dir.__require(); + const _misc = /*@__PURE__*/ misc.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + class SurgeDomainSet extends _base.BaseWriteStrategy { + // readonly type = 'domainset'; + fileExtension = 'conf'; + type = 'domainset'; + result = [ + 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe' + ]; + constructor(outputDir = _dir.OUTPUT_SURGE_DIR){ + super(outputDir); + } + withPadding = _misc.withBannerArray; + writeDomain(domain) { + this.result.push(domain); + } + writeDomainSuffix(domain) { + this.result.push('.' + domain); + } + writeDomainKeywords = _noop.noop; + writeDomainWildcards = _noop.noop; + writeUserAgents = _noop.noop; + writeProcessNames = _noop.noop; + writeProcessPaths = _noop.noop; + writeUrlRegexes = _noop.noop; + writeIpCidrs = _noop.noop; + writeIpCidr6s = _noop.noop; + writeGeoip = _noop.noop; + writeIpAsns = _noop.noop; + writeSourceIpCidrs = _noop.noop; + writeSourcePorts = _noop.noop; + writeDestinationPorts = _noop.noop; + writeOtherRules = _noop.noop; + } + class SurgeRuleSet extends _base.BaseWriteStrategy { + type; + outputDir; + fileExtension; + result; + constructor(/** Surge RULE-SET can be both ip or non_ip, so this needs to be specified */ type, outputDir = _dir.OUTPUT_SURGE_DIR){ + super(outputDir), this.type = type, this.outputDir = outputDir, this.fileExtension = 'conf', this.result = [ + 'DOMAIN,this_ruleset_is_made_by_sukkaw.ruleset.skk.moe' + ], this.withPadding = _misc.withBannerArray; + } + withPadding; + writeDomain(domain) { + this.result.push('DOMAIN,' + domain); + } + writeDomainSuffix(domain) { + this.result.push('DOMAIN-SUFFIX,' + domain); + } + writeDomainKeywords(keyword) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, keyword, (i)=>`DOMAIN-KEYWORD,${i}`); + } + writeDomainWildcards(wildcard) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, wildcard, (i)=>`DOMAIN-WILDCARD,${i}`); + } + writeUserAgents(userAgent) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, userAgent, (i)=>`USER-AGENT,${i}`); + } + writeProcessNames(processName) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processName, (i)=>`PROCESS-NAME,${i}`); + } + writeProcessPaths(processPath) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processPath, (i)=>`PROCESS-NAME,${i}`); + } + writeUrlRegexes(urlRegex) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, urlRegex, (i)=>`URL-REGEX,${i}`); + } + writeIpCidrs(ipCidr, noResolve) { + for(let i = 0, len = ipCidr.length; i < len; i++){ + this.result.push(`IP-CIDR,${ipCidr[i]}${noResolve ? ',no-resolve' : ''}`); + } + } + writeIpCidr6s(ipCidr6, noResolve) { + for(let i = 0, len = ipCidr6.length; i < len; i++){ + this.result.push(`IP-CIDR6,${ipCidr6[i]}${noResolve ? ',no-resolve' : ''}`); + } + } + writeGeoip(geoip, noResolve) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, geoip, (i)=>`GEOIP,${i}${noResolve ? ',no-resolve' : ''}`); + } + writeIpAsns(asns, noResolve) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, asns, (i)=>`IP-ASN,${i}${noResolve ? ',no-resolve' : ''}`); + } + writeSourceIpCidrs(sourceIpCidr) { + for(let i = 0, len = sourceIpCidr.length; i < len; i++){ + this.result.push(`SRC-IP,${sourceIpCidr[i]}`); + } + } + writeSourcePorts(port) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`SRC-PORT,${i}`); + } + writeDestinationPorts(port) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`DEST-PORT,${i}`); + } + writeOtherRules(rule) { + (0, _appendarrayinplace.appendArrayInPlace)(this.result, rule); + } + } + class SurgeMitmSgmodule extends _base.BaseWriteStrategy { + // readonly type = 'domainset'; + fileExtension = 'sgmodule'; + type = ''; + rules = new Set(); + get result() { + if (this.rules.size === 0) { + return null; + } + return [ + '#!name=[Sukka] Surge Reject MITM', + `#!desc=为 URL Regex 规则组启用 MITM (size: ${this.rules.size})`, + '', + '[MITM]', + 'hostname = %APPEND% ' + Array.from(this.rules).join(', ') + ]; + } + withPadding = _misc.withIdentityContent; + constructor(moduleName, outputDir = _dir.OUTPUT_MODULES_DIR){ + super(outputDir); + this.withFilename(moduleName); + } + writeDomain = _noop.noop; + writeDomainSuffix = _noop.noop; + writeDomainKeywords = _noop.noop; + writeDomainWildcards = _noop.noop; + writeUserAgents = _noop.noop; + writeProcessNames = _noop.noop; + writeProcessPaths = _noop.noop; + writeUrlRegexes(urlRegexes) { + const urlRegexResults = []; + const parsedFailures = []; + const parsed = []; + for (let urlRegex of urlRegexes){ + if (urlRegex.startsWith('http://') || urlRegex.startsWith('^http://')) { + continue; + } + if (urlRegex.startsWith('^https?://')) { + urlRegex = urlRegex.slice(10); + } + if (urlRegex.startsWith('^https://')) { + urlRegex = urlRegex.slice(9); + } + const potentialHostname = urlRegex.split('/')[0]// pre process regex + .replaceAll(String.raw`\.`, '.').replaceAll('.+', '*').replaceAll(/([a-z])\?/g, '($1|)')// convert regex to surge hostlist syntax + .replaceAll('([a-z])', '?').replaceAll(String.raw`\d`, '?').replaceAll(/\*+/g, '*'); + let processed = [ + potentialHostname + ]; + const matches = [ + ...potentialHostname.matchAll(/\((?:([^()|]+)\|)+([^()|]*)\)/g) + ]; + if (matches.length > 0) { + const replaceVariant = (combinations, fullMatch, options)=>{ + const newCombinations = []; + combinations.forEach((combination)=>{ + options.forEach((option)=>{ + newCombinations.push(combination.replace(fullMatch, option)); + }); + }); + return newCombinations; + }; + for(let i = 0; i < matches.length; i++){ + const match = matches[i]; + const [_, ...options] = match; + processed = replaceVariant(processed, _, options); + } + } + urlRegexResults.push({ + origin: potentialHostname, + processed + }); + } + for (const i of urlRegexResults){ + for (const processed of i.processed){ + if ((0, _normalizedomain.normalizeDomain)(processed.replaceAll('*', 'a').replaceAll('?', 'b'))) { + parsed.push([ + i.origin, + processed + ]); + } else if (!(0, _isprobablyip.isProbablyIpv4)(processed)) { + parsedFailures.push([ + i.origin, + processed + ]); + } + } + } + if (parsedFailures.length > 0) { + console.error(_picocolors.default.bold('Parsed Failed')); + console.table(parsedFailures); + } + for(let i = 0, len = parsed.length; i < len; i++){ + this.rules.add(parsed[i][1]); + } + } + writeIpCidrs = _noop.noop; + writeIpCidr6s = _noop.noop; + writeGeoip = _noop.noop; + writeIpAsns = _noop.noop; + writeSourceIpCidrs = _noop.noop; + writeSourcePorts = _noop.noop; + writeDestinationPorts = _noop.noop; + writeOtherRules = _noop.noop; + } + } (surge.__exports)); + return surge.__exports; +}exports.__require=requireSurge; \ No newline at end of file diff --git a/Dist/Build/trace/index.cjs b/Dist/Build/trace/index.cjs new file mode 100644 index 00000000..29fc716e --- /dev/null +++ b/Dist/Build/trace/index.cjs @@ -0,0 +1,182 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const index=require('../../_virtual/index2.cjs'),require$$2=require('foxts/noop'),require$$0=require('node:path'),require$$1=require('node:process'),require$$0$1=require('picocolors');var hasRequiredTrace; + +function requireTrace () { + if (hasRequiredTrace) return index.__exports; + hasRequiredTrace = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + createSpan: function() { + return createSpan; + }, + dummySpan: function() { + return dummySpan; + }, + printTraceResult: function() { + return printTraceResult; + }, + task: function() { + return task; + }, + whyIsNodeRunning: function() { + return whyIsNodeRunning; + } + }); + const _noop = require$$2; + const _nodepath = require$$0; + const _nodeprocess = /*#__PURE__*/ _interop_require_default(require$$1); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const SPAN_STATUS_START = 0; + const SPAN_STATUS_END = 1; + const spanTag = Symbol('span'); + const rootTraceResult = { + name: 'root', + start: 0, + end: 0, + children: [] + }; + function createSpan(name, parentTraceResult) { + const start = performance.now(); + let curTraceResult; + if (parentTraceResult == null) { + curTraceResult = rootTraceResult; + } else { + curTraceResult = { + name, + start, + end: 0, + children: [] + }; + parentTraceResult.children.push(curTraceResult); + } + let status = SPAN_STATUS_START; + const stop = (time)=>{ + if (status === SPAN_STATUS_END) { + throw new Error(`span already stopped: ${name}`); + } + const end = time ?? performance.now(); + curTraceResult.end = end; + status = SPAN_STATUS_END; + }; + const traceChild = (name)=>createSpan(name, curTraceResult); + const span = { + [spanTag]: true, + stop, + traceChild, + traceSyncFn (fn) { + const res = fn(span); + span.stop(); + return res; + }, + async traceAsyncFn (fn) { + const res = await fn(span); + span.stop(); + return res; + }, + traceResult: curTraceResult, + async tracePromise (promise) { + const res = await promise; + span.stop(); + return res; + }, + traceChildSync: (name, fn)=>traceChild(name).traceSyncFn(fn), + traceChildAsync: (name, fn)=>traceChild(name).traceAsyncFn(fn), + traceChildPromise: (name, promise)=>traceChild(name).tracePromise(promise) + }; + // eslint-disable-next-line sukka/no-redundant-variable -- self reference + return span; + } + const dummySpan = createSpan(''); + function task(importMetaMain, importMetaPath) { + return (fn, customName)=>{ + const taskName = customName ?? (0, _nodepath.basename)(importMetaPath, (0, _nodepath.extname)(importMetaPath)); + let cleanup = _noop.noop; + const onCleanup = (cb)=>{ + cleanup = cb; + }; + const dummySpan = createSpan(taskName); + if (importMetaMain) { + _nodeprocess.default.on('uncaughtException', (error)=>{ + console.error('Uncaught exception:', error); + _nodeprocess.default.exit(1); + }); + _nodeprocess.default.on('unhandledRejection', (reason)=>{ + console.error('Unhandled rejection:', reason); + _nodeprocess.default.exit(1); + }); + dummySpan.traceChildAsync('dummy', (childSpan)=>fn(childSpan, onCleanup)).finally(()=>{ + dummySpan.stop(); + printTraceResult(dummySpan.traceResult); + _nodeprocess.default.nextTick(whyIsNodeRunning); + }); + } + return async (span)=>{ + if (span) { + return span.traceChildAsync(taskName, (childSpan)=>fn(childSpan, onCleanup).finally(()=>cleanup())); + } + return fn(dummySpan, onCleanup).finally(()=>cleanup()); + }; + }; + } + async function whyIsNodeRunning() { + const mod = await import('why-is-node-running'); + return mod.default(); + } + function printTraceResult(traceResult = rootTraceResult) { + printStats(traceResult.children); + printTree(traceResult, (node)=>{ + if (node.end - node.start < 0) { + return node.name; + } + return `${node.name} ${_picocolors.default.bold(`${(node.end - node.start).toFixed(3)}ms`)}`; + }); + } + function printTree(initialTree, printNode) { + function printBranch(tree, branch, isGraphHead, isChildOfLastBranch) { + const children = tree.children; + let branchHead = ''; + if (!isGraphHead) { + branchHead = children.length > 0 ? '┬ ' : '─ '; + } + const toPrint = printNode(tree, `${branch}${branchHead}`); + if (typeof toPrint === 'string') { + console.log(`${branch}${branchHead}${toPrint}`); + } + let baseBranch = branch; + if (!isGraphHead) { + baseBranch = branch.slice(0, -2) + (isChildOfLastBranch ? ' ' : '│ '); + } + const nextBranch = `${baseBranch}├─`; + const lastBranch = `${baseBranch}└─`; + children.forEach((child, index)=>{ + const last = children.length - 1 === index; + printBranch(child, last ? lastBranch : nextBranch, false, last); + }); + } + printBranch(initialTree, '', true, false); + } + function printStats(stats) { + const longestTaskName = Math.max(...stats.map((i)=>i.name.length)); + const realStart = Math.min(...stats.map((i)=>i.start)); + const realEnd = Math.max(...stats.map((i)=>i.end)); + const statsStep = (realEnd - realStart) / 120 | 0; + stats.sort((a, b)=>a.start - b.start).forEach((stat)=>{ + console.log(`[${stat.name}]${' '.repeat(longestTaskName - stat.name.length)}`, ' '.repeat((stat.start - realStart) / statsStep | 0), '='.repeat(Math.max((stat.end - stat.start) / statsStep | 0, 1))); + }); + } + } (index.__exports)); + return index.__exports; +}exports.__require=requireTrace; \ No newline at end of file diff --git a/Dist/Build/trim-source.cjs b/Dist/Build/trim-source.cjs new file mode 100644 index 00000000..e40f597d --- /dev/null +++ b/Dist/Build/trim-source.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),trimSource$1=require('./trim-source2.cjs');var trimSourceExports = trimSource$1.__require(); +const trimSource = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(trimSourceExports);module.exports=trimSource; \ No newline at end of file diff --git a/Dist/Build/trim-source2.cjs b/Dist/Build/trim-source2.cjs new file mode 100644 index 00000000..2fcc3299 --- /dev/null +++ b/Dist/Build/trim-source2.cjs @@ -0,0 +1,47 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const trimSource=require('../_virtual/trim-source.cjs'),require$$0=require('node:path'),require$$2=require('node:fs/promises'),require$$5=require('fdir'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),dir=require('./constants/dir.cjs');var hasRequiredTrimSource; + +function requireTrimSource () { + if (hasRequiredTrimSource) return trimSource.__exports; + hasRequiredTrimSource = 1; + Object.defineProperty(trimSource.__exports, "__esModule", { + value: true + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _promises = /*#__PURE__*/ _interop_require_default(require$$2); + const _fdir = require$$5; + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _dir = /*@__PURE__*/ dir.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + (async ()=>{ + const promises = []; + const paths = await new _fdir.fdir().withFullPaths()// .exclude((dirName, dirPath) => { + // if (dirName === 'domainset' || dirName === 'ip' || dirName === 'non_ip') { + // return false; + // } + // console.error(picocolors.red(`[build-comman] Unknown dir: ${dirPath}`)); + // return true; + // }) + .filter((filepath, isDirectory)=>{ + if (isDirectory) return true; + const extname = _nodepath.default.extname(filepath); + return !(extname === '.js' || extname === '.ts'); + }).crawl(_dir.SOURCE_DIR).withPromise(); + for(let i = 0, len = paths.length; i < len; i++){ + const fullPath = paths[i]; + promises.push(trimFileLines(fullPath)); + } + return Promise.all(promises); + })(); + async function trimFileLines(file) { + let result = ''; + for await (const line of (0, _fetchtextbyline.readFileByLine)(file)){ + result += line.trim() + '\n'; + } + return _promises.default.writeFile(file, result); + } + return trimSource.__exports; +}exports.__require=requireTrimSource; \ No newline at end of file diff --git a/Dist/Build/validate-domain-alive.cjs b/Dist/Build/validate-domain-alive.cjs new file mode 100644 index 00000000..25929220 --- /dev/null +++ b/Dist/Build/validate-domain-alive.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),validateDomainAlive$1=require('./validate-domain-alive2.cjs');var validateDomainAliveExports = validateDomainAlive$1.__require(); +const validateDomainAlive = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(validateDomainAliveExports);module.exports=validateDomainAlive; \ No newline at end of file diff --git a/Dist/Build/validate-domain-alive2.cjs b/Dist/Build/validate-domain-alive2.cjs new file mode 100644 index 00000000..7078c7fb --- /dev/null +++ b/Dist/Build/validate-domain-alive2.cjs @@ -0,0 +1,94 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const validateDomainAlive=require('../_virtual/validate-domain-alive.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),processLine=require('./lib/process-line.cjs'),dir=require('./constants/dir.cjs'),require$$0=require('node:path'),require$$7=require('@henrygd/queue'),isDomainAlive=require('./lib/is-domain-alive.cjs'),require$$5=require('fdir');var hasRequiredValidateDomainAlive; + +function requireValidateDomainAlive () { + if (hasRequiredValidateDomainAlive) return validateDomainAlive.__exports; + hasRequiredValidateDomainAlive = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + runAgainstDomainset: function() { + return runAgainstDomainset; + }, + runAgainstRuleset: function() { + return runAgainstRuleset; + } + }); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _processline = /*@__PURE__*/ processLine.__require(); + const _dir = /*@__PURE__*/ dir.__require(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _queue = require$$7; + const _isdomainalive = /*@__PURE__*/ isDomainAlive.__require(); + const _fdir = require$$5; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const queue = (0, _queue.newQueue)(24); + const deadDomains = []; + function onDomain(args) { + if (!args[1]) { + deadDomains.push(args[0]); + } + } + (async ()=>{ + const domainSets = await new _fdir.fdir().withFullPaths().crawl(_dir.SOURCE_DIR + _nodepath.default.sep + 'domainset').withPromise(); + const domainRules = await new _fdir.fdir().withFullPaths().crawl(_dir.SOURCE_DIR + _nodepath.default.sep + 'non_ip').withPromise(); + await Promise.all([ + ...domainSets.map(runAgainstDomainset), + ...domainRules.map(runAgainstRuleset) + ]); + console.log(); + console.log(); + console.log(JSON.stringify(deadDomains)); + })(); + async function runAgainstRuleset(filepath) { + const extname = _nodepath.default.extname(filepath); + if (extname !== '.conf') { + console.log('[skip]', filepath); + return; + } + const promises = []; + for await (const l of (0, _fetchtextbyline.readFileByLine)(filepath)){ + const line = (0, _processline.processLine)(l); + if (!line) continue; + const [type, domain] = line.split(','); + switch(type){ + case 'DOMAIN-SUFFIX': + case 'DOMAIN': + { + promises.push(queue.add(()=>(0, _isdomainalive.keyedAsyncMutexWithQueue)(domain, ()=>(0, _isdomainalive.isDomainAlive)(domain, type === 'DOMAIN-SUFFIX'))).then(onDomain)); + break; + } + } + } + await Promise.all(promises); + console.log('[done]', filepath); + } + async function runAgainstDomainset(filepath) { + const extname = _nodepath.default.extname(filepath); + if (extname !== '.conf') { + console.log('[skip]', filepath); + return; + } + const promises = []; + for await (const l of (0, _fetchtextbyline.readFileByLine)(filepath)){ + const line = (0, _processline.processLine)(l); + if (!line) continue; + promises.push(queue.add(()=>(0, _isdomainalive.keyedAsyncMutexWithQueue)(line, ()=>(0, _isdomainalive.isDomainAlive)(line, line[0] === '.'))).then(onDomain)); + } + await Promise.all(promises); + console.log('[done]', filepath); + } + } (validateDomainAlive.__exports)); + return validateDomainAlive.__exports; +}exports.__require=requireValidateDomainAlive; \ No newline at end of file diff --git a/Dist/Build/validate-domestic.cjs b/Dist/Build/validate-domestic.cjs new file mode 100644 index 00000000..ae261ca9 --- /dev/null +++ b/Dist/Build/validate-domestic.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),validateDomestic$1=require('./validate-domestic2.cjs');var validateDomesticExports = validateDomestic$1.__require(); +const validateDomestic = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(validateDomesticExports);module.exports=validateDomestic; \ No newline at end of file diff --git a/Dist/Build/validate-domestic2.cjs b/Dist/Build/validate-domestic2.cjs new file mode 100644 index 00000000..88b1983b --- /dev/null +++ b/Dist/Build/validate-domestic2.cjs @@ -0,0 +1,81 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const validateDomestic=require('../_virtual/validate-domestic.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),require$$3=require('csv-parse/sync'),trie=require('./lib/trie.cjs'),require$$0=require('node:path'),processLine=require('./lib/process-line.cjs'),dir=require('./constants/dir.cjs'),parseDnsmasq=require('./lib/parse-dnsmasq.cjs'),fetchRetry=require('./lib/fetch-retry.cjs');var hasRequiredValidateDomestic; + +function requireValidateDomestic () { + if (hasRequiredValidateDomestic) return validateDomestic.__exports; + hasRequiredValidateDomestic = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "parseDomesticList", { + enumerable: true, + get: function() { + return parseDomesticList; + } + }); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _sync = require$$3; + const _trie = /*@__PURE__*/ trie.__require(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _processline = /*@__PURE__*/ processLine.__require(); + const _dir = /*@__PURE__*/ dir.__require(); + const _parsednsmasq = /*@__PURE__*/ parseDnsmasq.__require(); + const _fetchretry = /*@__PURE__*/ fetchRetry.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + async function parseDomesticList() { + const trie = new _trie.HostnameSmolTrie(await (0, _parsednsmasq.parseFelixDnsmasqFromResp)(await (0, _fetchretry.$$fetch)('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf'))); + const top5000 = new Set(); + const res = await (await (0, _fetchretry.$$fetch)('https://radar.cloudflare.com/charts/LargerTopDomainsTable/attachment?id=1077&top=10000', { + headers: { + accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', + 'accept-language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,zh-TW;q=0.6,es;q=0.5', + 'sec-ch-ua': '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"', + 'sec-ch-ua-mobile': '?0', + 'sec-ch-ua-platform': '"macOS"', + 'sec-fetch-dest': 'document', + 'sec-fetch-mode': 'navigate', + 'sec-fetch-site': 'none', + 'sec-fetch-user': '?1', + 'upgrade-insecure-requests': '1' + } + })).text(); + const stream = (0, _sync.parse)(res); + for await (const [domain] of stream){ + if (trie.has(domain)) { + top5000.add(domain); + } + console.log({ + domain + }); + } + const notIncludedDomestic = new Set(top5000); + const runAgainstRuleset = async (ruleset)=>{ + for await (const l of (0, _fetchtextbyline.readFileByLine)(ruleset)){ + const line = (0, _processline.processLine)(l); + if (!line) continue; + const [type, domain] = line.split(','); + if (type === 'DOMAIN-SUFFIX') { + if (top5000.has(domain)) { + notIncludedDomestic.delete(domain); + } + } else if (type === 'DOMAIN-KEYWORD') { + for (const d of top5000){ + if (d.includes(domain)) { + notIncludedDomestic.delete(d); + } + } + } + } + }; + // await Promise.all([ + await runAgainstRuleset(_nodepath.default.resolve(_dir.SOURCE_DIR, 'non_ip/domestic.conf')); + // ]); + console.log(notIncludedDomestic.size, notIncludedDomestic); + } + } (validateDomestic.__exports)); + return validateDomestic.__exports; +}exports.__require=requireValidateDomestic; \ No newline at end of file diff --git a/Dist/Build/validate-gfwlist.cjs b/Dist/Build/validate-gfwlist.cjs new file mode 100644 index 00000000..583ec3db --- /dev/null +++ b/Dist/Build/validate-gfwlist.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),validateGfwlist$1=require('./validate-gfwlist2.cjs');var validateGfwlistExports = validateGfwlist$1.__require(); +const validateGfwlist = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(validateGfwlistExports);module.exports=validateGfwlist; \ No newline at end of file diff --git a/Dist/Build/validate-gfwlist2.cjs b/Dist/Build/validate-gfwlist2.cjs new file mode 100644 index 00000000..0903d924 --- /dev/null +++ b/Dist/Build/validate-gfwlist2.cjs @@ -0,0 +1,153 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const validateGfwlist=require('../_virtual/validate-gfwlist.cjs'),processLine=require('./lib/process-line.cjs'),normalizeDomain=require('./lib/normalize-domain.cjs'),trie=require('./lib/trie.cjs'),require$$3$1=require('csv-parse/sync'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),require$$0=require('node:path'),dir=require('./constants/dir.cjs'),require$$3=require('foxts/retrie'),fetchRetry=require('./lib/fetch-retry.cjs');var hasRequiredValidateGfwlist; + +function requireValidateGfwlist () { + if (hasRequiredValidateGfwlist) return validateGfwlist.__module.exports; + hasRequiredValidateGfwlist = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "parseGfwList", { + enumerable: true, + get: function() { + return parseGfwList; + } + }); + const _processline = /*@__PURE__*/ processLine.__require(); + const _normalizedomain = /*@__PURE__*/ normalizeDomain.__require(); + const _trie = /*@__PURE__*/ trie.__require(); + const _sync = require$$3$1; + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _dir = /*@__PURE__*/ dir.__require(); + const _retrie = require$$3; + const _fetchretry = /*@__PURE__*/ fetchRetry.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + async function parseGfwList() { + const whiteSet = new Set(); + const trie = new _trie.HostnameSmolTrie(); + const excludeGfwList = (0, _retrie.createRetrieKeywordFilter)([ + '.*', + '*', + '=', + '[', + '/', + '?' + ]); + const text = await (await (0, _fetchretry.$$fetch)('https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt')).text(); + for (const l of atob(text).split('\n')){ + const line = (0, _processline.processLine)(l); + if (!line) continue; + if (excludeGfwList(line)) { + continue; + } + if (line.startsWith('@@||')) { + whiteSet.add('.' + line.slice(4)); + continue; + } + if (line.startsWith('@@|http://')) { + whiteSet.add(line.slice(10)); + continue; + } + if (line.startsWith('@@|https://')) { + whiteSet.add(line.slice(11)); + continue; + } + if (line.startsWith('||')) { + trie.add('.' + line.slice(2)); + continue; + } + if (line.startsWith('|')) { + trie.add(line.slice(1)); + continue; + } + if (line.startsWith('.')) { + trie.add(line); + continue; + } + const d = (0, _normalizedomain.fastNormalizeDomain)(line); + if (d) { + trie.add(d); + continue; + } + } + for (const l of (await (await (0, _fetchretry.$$fetch)('https://raw.githubusercontent.com/Loyalsoldier/cn-blocked-domain/release/domains.txt')).text()).split('\n')){ + trie.add(l); + } + const res = await (await (0, _fetchretry.$$fetch)('https://litter.catbox.moe/sqmgyn.csv', { + headers: { + accept: '*/*', + 'user-agent': 'curl/8.9.1' + } + })).text(); + const topDomains = (0, _sync.parse)(res); + const keywordSet = new Set(); + const runAgainstRuleset = async (ruleset)=>{ + for await (const l of (0, _fetchtextbyline.readFileByLine)(ruleset)){ + const line = (0, _processline.processLine)(l); + if (!line) continue; + const [type, domain] = line.split(','); + switch(type){ + case 'DOMAIN-SUFFIX': + { + trie.whitelist('.' + domain); + break; + } + case 'DOMAIN': + { + trie.whitelist(domain); + break; + } + case 'DOMAIN-KEYWORD': + { + keywordSet.add(domain); + break; + } + } + } + }; + const runAgainstDomainset = async (ruleset)=>{ + for await (const l of (0, _fetchtextbyline.readFileByLine)(ruleset)){ + const line = (0, _processline.processLine)(l); + if (!line) continue; + trie.whitelist(line); + } + }; + await Promise.all([ + runAgainstRuleset(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/global.conf')), + runAgainstRuleset(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/reject.conf')), + runAgainstRuleset(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/telegram.conf')), + runAgainstRuleset(_nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, 'non_ip/stream.conf')), + runAgainstRuleset(_nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, 'non_ip/ai.conf')), + runAgainstRuleset(_nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, 'non_ip/microsoft.conf')), + runAgainstDomainset(_nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, 'domainset/reject.conf')), + runAgainstDomainset(_nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, 'domainset/cdn.conf')) + ]); + whiteSet.forEach((domain)=>trie.whitelist(domain)); + const kwfilter = (0, _retrie.createRetrieKeywordFilter)([ + ...keywordSet + ]); + const missingTop10000Gfwed = new Set(); + console.log(trie.has('.mojim.com')); + for await (const [domain] of topDomains){ + if (trie.has(domain) && !kwfilter(domain)) { + missingTop10000Gfwed.add(domain); + } + } + console.log(JSON.stringify(Array.from(missingTop10000Gfwed), null, 2)); + return [ + whiteSet, + trie, + missingTop10000Gfwed + ]; + } + if (require.main === module) { + parseGfwList().catch(console.error); + } + } (validateGfwlist.__module, validateGfwlist.__module.exports)); + return validateGfwlist.__module.exports; +}exports.__require=requireValidateGfwlist; \ No newline at end of file diff --git a/Dist/Build/validate-global-tld.cjs b/Dist/Build/validate-global-tld.cjs new file mode 100644 index 00000000..57668b3a --- /dev/null +++ b/Dist/Build/validate-global-tld.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),validateGlobalTld$1=require('./validate-global-tld2.cjs');var validateGlobalTldExports = validateGlobalTld$1.__require(); +const validateGlobalTld = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(validateGlobalTldExports);module.exports=validateGlobalTld; \ No newline at end of file diff --git a/Dist/Build/validate-global-tld2.cjs b/Dist/Build/validate-global-tld2.cjs new file mode 100644 index 00000000..0bd35d04 --- /dev/null +++ b/Dist/Build/validate-global-tld2.cjs @@ -0,0 +1,53 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const validateGlobalTld=require('../_virtual/validate-global-tld.cjs'),require$$0=require('node:path'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),trie=require('./lib/trie.cjs'),dir=require('./constants/dir.cjs'),domains=require('./constants/domains.cjs'),require$$5=require('tldts-experimental'),looseTldtsOpt=require('./constants/loose-tldts-opt.cjs');var hasRequiredValidateGlobalTld; + +function requireValidateGlobalTld () { + if (hasRequiredValidateGlobalTld) return validateGlobalTld.__exports; + hasRequiredValidateGlobalTld = 1; + Object.defineProperty(validateGlobalTld.__exports, "__esModule", { + value: true + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _trie = /*@__PURE__*/ trie.__require(); + const _dir = /*@__PURE__*/ dir.__require(); + const _domains = /*@__PURE__*/ domains.__require(); + const _tldtsexperimental = /*#__PURE__*/ _interop_require_default(require$$5); + const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + (async ()=>{ + const trie = new _trie.HostnameSmolTrie(); + const extraWhiteTLDs = new Set(); + for await (const line of (0, _fetchtextbyline.readFileByLine)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip', 'domestic.conf'))){ + const [type, domain] = line.split(','); + if (type !== 'DOMAIN' && type !== 'DOMAIN-SUFFIX') { + continue; + } + if (domain === 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe') { + continue; + } + const tld = _tldtsexperimental.default.getPublicSuffix(domain, _loosetldtsopt.looseTldtsOpt); + if (tld) { + extraWhiteTLDs.add(tld); + } + } + for await (const line of (0, _fetchtextbyline.readFileByLine)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip', 'global.conf'))){ + const [type, domain] = line.split(','); + switch(type){ + case 'DOMAIN': + trie.add(domain); + break; + case 'DOMAIN-SUFFIX': + trie.add(domain, true); + break; + } + } + _domains.ICP_TLD.forEach((tld)=>trie.whitelist(tld, true)); + extraWhiteTLDs.forEach((tld)=>trie.whitelist(tld, true)); + console.log(trie.dump().join('\n')); + })(); + return validateGlobalTld.__exports; +}exports.__require=requireValidateGlobalTld; \ No newline at end of file diff --git a/Dist/Build/validate-hash-collision-test.cjs b/Dist/Build/validate-hash-collision-test.cjs new file mode 100644 index 00000000..e52adf9a --- /dev/null +++ b/Dist/Build/validate-hash-collision-test.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),validateHashCollisionTest$1=require('./validate-hash-collision-test2.cjs');var validateHashCollisionTestExports = validateHashCollisionTest$1.__require(); +const validateHashCollisionTest = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(validateHashCollisionTestExports);module.exports=validateHashCollisionTest; \ No newline at end of file diff --git a/Dist/Build/validate-hash-collision-test2.cjs b/Dist/Build/validate-hash-collision-test2.cjs new file mode 100644 index 00000000..0e7ee4e3 --- /dev/null +++ b/Dist/Build/validate-hash-collision-test2.cjs @@ -0,0 +1,54 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const validateHashCollisionTest=require('../_virtual/validate-hash-collision-test.cjs'),require$$5=require('fdir'),dir=require('./constants/dir.cjs'),require$$0=require('node:path'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),require$$4=require('hash-wasm');/* eslint-disable no-await-in-loop -- no concurrent */ + +var hasRequiredValidateHashCollisionTest; + +function requireValidateHashCollisionTest () { + if (hasRequiredValidateHashCollisionTest) return validateHashCollisionTest.__exports; + hasRequiredValidateHashCollisionTest = 1; + Object.defineProperty(validateHashCollisionTest.__exports, "__esModule", { + value: true + }); + const _fdir = require$$5; + const _dir = /*@__PURE__*/ dir.__require(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _hashwasm = require$$4; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + (async ()=>{ + const hashMap = new Map(); + const runHash = async (inputs)=>{ + for (const input of inputs){ + const hash = await (0, _hashwasm.xxhash3)(input); + if (!hashMap.has(hash)) { + hashMap.set(hash, new Set()); + } + hashMap.get(hash).add(input); + } + }; + const files = await new _fdir.fdir().withRelativePaths().crawl(_dir.OUTPUT_SURGE_DIR).withPromise(); + for (const file of files){ + const fullpath = _nodepath.default.join(_dir.OUTPUT_SURGE_DIR, file); + if (file.startsWith('domainset' + _nodepath.default.sep)) { + await runHash((await (0, _fetchtextbyline.readFileIntoProcessedArray)(fullpath)).map((i)=>i[0] === '.' ? i.slice(1) : i)); + } else if (file.startsWith('non_ip' + _nodepath.default.sep)) { + await runHash((await (0, _fetchtextbyline.readFileIntoProcessedArray)(fullpath)).map((i)=>i.split(',')[1])); + } + } + console.log(hashMap.size); + let collision = 0; + hashMap.forEach((v, k)=>{ + if (v.size > 1) { + collision++; + console.log(k, '=>', v); + } + }); + if (collision === 0) { + console.log(hashMap); + } + })(); + return validateHashCollisionTest.__exports; +}exports.__require=requireValidateHashCollisionTest; \ No newline at end of file diff --git a/Dist/Build/validate-reject-stats.cjs b/Dist/Build/validate-reject-stats.cjs new file mode 100644 index 00000000..db5049a8 --- /dev/null +++ b/Dist/Build/validate-reject-stats.cjs @@ -0,0 +1,2 @@ +'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),validateRejectStats$1=require('./validate-reject-stats2.cjs');var validateRejectStatsExports = validateRejectStats$1.__require(); +const validateRejectStats = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(validateRejectStatsExports);module.exports=validateRejectStats; \ No newline at end of file diff --git a/Dist/Build/validate-reject-stats2.cjs b/Dist/Build/validate-reject-stats2.cjs new file mode 100644 index 00000000..7291da16 --- /dev/null +++ b/Dist/Build/validate-reject-stats2.cjs @@ -0,0 +1,42 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const validateRejectStats=require('../_virtual/validate-reject-stats.cjs'),require$$0$1=require('node:path'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),dir=require('./constants/dir.cjs'),processLine=require('./lib/process-line.cjs'),require$$0=require('tldts'),looseTldtsOpt=require('./constants/loose-tldts-opt.cjs');var hasRequiredValidateRejectStats; + +function requireValidateRejectStats () { + if (hasRequiredValidateRejectStats) return validateRejectStats.__exports; + hasRequiredValidateRejectStats = 1; + Object.defineProperty(validateRejectStats.__exports, "__esModule", { + value: true + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require(); + const _dir = /*@__PURE__*/ dir.__require(); + const _processline = /*@__PURE__*/ processLine.__require(); + const _tldts = /*#__PURE__*/ _interop_require_default(require$$0); + const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.__require(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + (async ()=>{ + const rejectDomainCountMap = await runAgainstDomainset(new Map(), _nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'domainset', 'reject.conf')); + const rejectExtraDomainCountMap = await runAgainstDomainset(new Map(), _nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'domainset', 'reject_extra.conf')); + const rejectDomainCountArr = Array.from(rejectDomainCountMap).sort((a, b)=>b[1] - a[1]).filter(([, count])=>count > 20); + const rejectExtraDomainCountArr = Array.from(rejectExtraDomainCountMap).sort((a, b)=>b[1] - a[1]).filter(([, count])=>count > 20); + console.table(rejectDomainCountArr); + console.table(rejectExtraDomainCountArr); + })(); + async function runAgainstDomainset(rejectDomainCountMap, file) { + for await (const line of (0, _fetchtextbyline.readFileByLine)(file)){ + if (!(0, _processline.processLine)(line)) { + continue; + } + const apexDomain = _tldts.default.getDomain(line, _loosetldtsopt.loosTldOptWithPrivateDomains); + if (!apexDomain) { + continue; + } + rejectDomainCountMap.set(apexDomain, rejectDomainCountMap.has(apexDomain) ? rejectDomainCountMap.get(apexDomain) + 1 : 1); + } + return rejectDomainCountMap; + } + return validateRejectStats.__exports; +}exports.__require=requireValidateRejectStats; \ No newline at end of file diff --git a/Dist/Source/ip/badboy_asn.cjs b/Dist/Source/ip/badboy_asn.cjs new file mode 100644 index 00000000..dbf52177 --- /dev/null +++ b/Dist/Source/ip/badboy_asn.cjs @@ -0,0 +1,50 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const badboy_asn=require('../../_virtual/badboy_asn.cjs');var hasRequiredBadboy_asn; + +function requireBadboy_asn () { + if (hasRequiredBadboy_asn) return badboy_asn.__exports; + hasRequiredBadboy_asn = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + AUGUST_ASN: function() { + return AUGUST_ASN; + }, + HUIZE_ASN: function() { + return HUIZE_ASN; + } + }); + const AUGUST_ASN = [ + '1012', + '945', + '401111', + '62853', + '27523', + '7719', + '54625', + '7257', + '18044', + '62489', + '5111', + '14651', + '7480' // Friend of August, stealing others' XC at STUIX + ]; + const HUIZE_ASN = [ + '61302', + '44324', + '53808', + '60539', + '60842', + '140915', + '40115' // MoeDove + ]; + } (badboy_asn.__exports)); + return badboy_asn.__exports; +}exports.__require=requireBadboy_asn; \ No newline at end of file diff --git a/Dist/Source/non_ip/cloudmounter.cjs b/Dist/Source/non_ip/cloudmounter.cjs new file mode 100644 index 00000000..d6c9f7d6 --- /dev/null +++ b/Dist/Source/non_ip/cloudmounter.cjs @@ -0,0 +1,39 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const cloudmounter=require('../../_virtual/cloudmounter.cjs');var hasRequiredCloudmounter; + +function requireCloudmounter () { + if (hasRequiredCloudmounter) return cloudmounter.__exports; + hasRequiredCloudmounter = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + DOMAINS: function() { + return DOMAINS; + }, + PROCESS_NAMES: function() { + return PROCESS_NAMES; + } + }); + const DOMAINS = [ + 'DOMAIN-SUFFIX,sharepoint.com', + 'DOMAIN-SUFFIX,graph.microsoft.com', + 'DOMAIN,www.googleapis.com', + 'DOMAIN,api.onedrive.com', + 'DOMAIN-SUFFIX,storage.live.com', + 'DOMAIN-SUFFIX,files.1drv.com', + 'DOMAIN-SUFFIX,my.microsoftpersonalcontent.com', + 'DOMAIN-WILDCARD,*-medi*.svc.ms' + ]; + const PROCESS_NAMES = [ + '*CloudMounter' + ]; + } (cloudmounter.__exports)); + return cloudmounter.__exports; +}exports.__require=requireCloudmounter; \ No newline at end of file diff --git a/Dist/Source/non_ip/direct.cjs b/Dist/Source/non_ip/direct.cjs new file mode 100644 index 00000000..52c987bd --- /dev/null +++ b/Dist/Source/non_ip/direct.cjs @@ -0,0 +1,147 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const direct=require('../../_virtual/direct.cjs');var hasRequiredDirect; + +function requireDirect () { + if (hasRequiredDirect) return direct.__exports; + hasRequiredDirect = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + DIRECTS: function() { + return DIRECTS; + }, + LAN: function() { + return LAN; + } + }); + const DIRECTS = { + HOTSPOT_CAPTIVE_PORTAL: { + dns: 'system', + hosts: {}, + realip: false, + ruleset: false, + domains: [ + 'securelogin.com.cn', + '$captive.apple.com', + '$hotspot.cslwifi.com' + ] + }, + SYSTEM: { + dns: 'system', + hosts: {}, + realip: true, + ruleset: false, + domains: [ + '+m2m', + // '+ts.net', // TailScale Magic DNS + // AdGuard + '$injections.adguard.org', + '$local.adguard.org', + // Auto Discovery + '+bogon' + ] + } + }; + const LAN = { + ROUTER: { + dns: 'system', + hosts: {}, + realip: false, + ruleset: true, + domains: [ + '+home', + // 'zte.home', // ZTE CPE + // 'airbox.home', + // 'bthub.home', + // 'bthomehub.home', + // 'hitronhub.home', + // 'web.setup.home' + // Aruba Router + '$instant.arubanetworks.com', + '$setmeup.arubanetworks.com', + // ASUS router + '$router.asus.com', + '$repeater.asus.com', + 'asusrouter.com', + // NetGear + 'routerlogin.net', + 'routerlogin.com', + // Tenda WiFi + // 'tendawifi.com', + // TP-Link Router + 'tplinkwifi.net', + 'tplogin.cn', + 'tplinkap.net', + 'tplinkmodem.net', + 'tplinkplclogin.net', + 'tplinkrepeater.net', + // UniFi + '+ui.direct', + '$unifi', + // Other Router + // '$router.com', + '+huaweimobilewifi.com', + '+router', + // 'my.router', + // 'samsung.router', + // '$easy.box', // Vodafone EasyBox + '$aterm.me', + '$console.gl-inet.com', + // '$fritz.box', + // '$fritz.repeater', + // '$myfritz.box', + // '$speedport.ip', // Telekom + // '$giga.cube', // Vodafone GigaCube + '$homerouter.cpe', + '$mobile.hotspot', + '$ntt.setup', + '$pi.hole', + '+plex.direct' + ] + }, + LAN: { + dns: 'system', + hosts: { + }, + realip: true, + ruleset: true, + domains: [ + '+lan', + // 'amplifi.lan', + // '$localhost', + '+localdomain', + 'home.arpa', + // AS112 + '10.in-addr.arpa', + '16.172.in-addr.arpa', + '17.172.in-addr.arpa', + '18.172.in-addr.arpa', + '19.172.in-addr.arpa', + // '2?.172.in-addr.arpa', + '20.172.in-addr.arpa', + '21.172.in-addr.arpa', + '22.172.in-addr.arpa', + '23.172.in-addr.arpa', + '24.172.in-addr.arpa', + '25.172.in-addr.arpa', + '26.172.in-addr.arpa', + '27.172.in-addr.arpa', + '28.172.in-addr.arpa', + '29.172.in-addr.arpa', + '30.172.in-addr.arpa', + '31.172.in-addr.arpa', + '168.192.in-addr.arpa', + '254.169.in-addr.arpa' + ] + } + }; + } (direct.__exports)); + return direct.__exports; +}exports.__require=requireDirect; \ No newline at end of file diff --git a/Dist/Source/non_ip/domestic.cjs b/Dist/Source/non_ip/domestic.cjs new file mode 100644 index 00000000..eb3e3179 --- /dev/null +++ b/Dist/Source/non_ip/domestic.cjs @@ -0,0 +1,437 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const domestic=require('../../_virtual/domestic.cjs');var hasRequiredDomestic; + +function requireDomestic () { + if (hasRequiredDomestic) return domestic.__exports; + hasRequiredDomestic = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + AdGuardHomeDNSMapping: function() { + return AdGuardHomeDNSMapping; + }, + DOH_BOOTSTRAP: function() { + return DOH_BOOTSTRAP; + }, + DOMESTICS: function() { + return DOMESTICS; + } + }); + const DOMESTICS = { + ALIBABA: { + hosts: {}, + dns: 'quic://dns.alidns.com:853', + realip: false, + ruleset: true, + domains: [ + 'uc.cn', + // 'ucweb.com', // UC International + 'alibaba.com', + '+alicdn.com', + '+ialicdn.com', + '+myalicdn.com', + '+alidns.com', + '+aliimg.com', + 'aliyun.com', + '+aliyuncs.com', + '+alikunlun.com', + '+alikunlun.net', + '+cdngslb.com', + 'alipay.com', + 'alipay.cn', + 'alipay.com.cn', + '+alipayobjects.com', + 'alibaba-inc.com', + '+alibabausercontent.com', + '+alibabadns.com', + 'alibabachengdun.com', + 'alicloudccp.com', + 'alipan.com', + 'aliyundrive.com', + 'aliyundrive.net', + 'cainiao.com', + 'cainiao.com.cn', + 'cainiaoyizhan.com', + 'guoguo-app.com', + 'etao.com', + 'yitao.com', + '1688.com', + 'amap.com', + 'gaode.com', + 'autonavi.com', + 'dingtalk.com', + 'mxhichina.com', + 'soku.com', + 'tb.cn', + 'taobao.com', + '+taobaocdn.com', + '+tbcache.com', + 'tmall.com', + // 'tmall.hk', + 'goofish.com', + 'xiami.com', + 'xiami.net', + '+ykimg.com', + 'youku.com', + 'tudou.com', + '+cibntv.net', + 'ele.me', + '+elemecdn.com', + 'feizhu.com', + 'taopiaopiao.com', + 'fliggy.com', + 'koubei.com', + 'mybank.cn', + 'mmstat.com', + 'uczzd.cn', + 'iconfont.cn', + 'freshhema.com', + 'hemamax.com', + 'hemaos.com', + 'hemashare.cn', + 'shyhhema.com', + 'sm.cn', + 'npmmirror.com', + 'alios.cn', + 'wandoujia.com', + 'aligames.com', + '25pp.com', + '+aliapp.org', + 'tanx.com', + 'hellobike.com', + '+hichina.com', + '+yunos.com', + // Bilibili Aliyun CDN + '$upos-sz-mirrorali.bilivideo.com', + '$upos-sz-estgoss.bilivideo.com' + ] + }, + TENCENT: { + hosts: {}, + dns: 'https://doh.pub/dns-query', + realip: false, + ruleset: true, + domains: [ + // 'dns.pub', + // 'doh.pub', + // 'dot.pub', + '+qcloud.com', + '+gtimg.cn', + '+gtimg.com', + '+gtimg.com.cn', + '+gdtimg.com', + '+idqqimg.com', + '+udqqimg.com', + '+igamecj.com', + 'myapp.com', + '+myqcloud.com', + 'dnspod.com', + '+qpic.cn', + '+qlogo.cn', + 'qq.com', + 'qq.com.cn', + // 'qq.wang', + // 'qqmail.cn', // not owned by QQ, is sold on hichina.com + '+qqmail.com', + 'qzone.com', + '+tencent-cloud.net', + '+tencent-cloud.com', + 'tencent.com', + 'tencent.com.cn', + 'tencentmusic.com', + 'weixinbridge.com', + 'weixin.com', + // 'wechat.com', exclude `sgshort.wechat.com` + 'weiyun.com', + 'soso.com', + 'sogo.com', + 'sogou.com', + '+sogoucdn.com', + '+roblox.cn', + 'robloxdev.cn', + 'wegame.com', + 'wegame.com.cn', + 'wegameplus.com', + 'cdn-go.cn', + '+tencentcs.cn', + '+qcloudimg.com', + 'dnspod.cn', + 'anticheatexpert.com', + '$url.cn', + '+qlivecdn.com', + '+tcdnlive.com', + '+dnsv1.com', + '+smtcdns.net', + 'coding.net', + '+codehub.cn' + ] + }, + BILIBILI: { + dns: 'https://doh.pub/dns-query', + hosts: {}, + realip: false, + ruleset: true, + domains: [ + // '$upos-sz-mirrorcoso1.bilivideo.com', // already included in bilivideo.com + // '$upos-sz-estgcos.bilivideo.com', // already included in bilivideo.com, tencent cloud cdn + '$acg.tv', + '$b23.tv', + 'bilibili.cn', + 'bilibili.com', + // 'bilibili.tv', + '+acgvideo.com', + '+bilivideo.com', + '+bilivideo.cn', + '+bilivideo.net', + '+hdslb.com', + '+biliimg.com', + '+biliapi.com', + '+biliapi.net', + // 'biligame.cn', // not owned by bilibili, was put on sale by ename + 'biligame.com', + '+biligame.net', + 'bilicomic.com', + 'bilicomics.com', + // 'bilibilipay.cn', // not owned by bilibili + // 'bilibilipay.com', // not owned by bilibili + '+bilicdn1.com' + ] + }, + XIAOMI: { + dns: 'https://doh.pub/dns-query', + hosts: {}, + realip: false, + ruleset: true, + domains: [ + 'mi.com', + 'duokan.com', + '+mi-img.com', + '+mi-idc.com', + '+xiaoaisound.com', + '+xiaomixiaoai.com', + '+mi-fds.com', + '+mifile.cn', + '+mijia.tech', + 'miui.com', + 'xiaomi.com', + 'xiaomi.cn', + 'xiaomi.net', + 'xiaomiev.com', + 'xiaomiyoupin.com' + ] + }, + BYTEDANCE: { + dns: '180.184.2.2', + hosts: {}, + realip: false, + ruleset: true, + domains: [ + 'bytedance.com', + '+bytecdn.cn', + '+volccdn.com', + '+toutiaoimg.com', + '+toutiaoimg.cn', + '+toutiaostatic.com', + '+toutiaovod.com', + '+toutiaocloud.com', + 'toutiaopage.com', + 'feiliao.com', + 'iesdouyin.com', + '+pstatp.com', + 'snssdk.com', + '+bytegoofy.com', + 'toutiao.com', + 'feishu.cn', + 'feishu.net', + '+feishucdn.com', + '+feishupkg.com', + 'douyin.com', + '+douyinpic.com', + '+douyinstatic.com', + '+douyincdn.com', + '+douyinliving.com', + '+douyinvod.com', + 'huoshan.com', + '+huoshanstatic.com', + 'huoshanzhibo.com', + 'ixigua.com', + '+ixiguavideo.com', + '+ixgvideo.com', + '+volccdn.com', + '+byted-static.com', + 'volces.com', + 'baike.com', + '+zjcdn.com', + '+zijieapi.com', + 'feelgood.cn', + '+bytetcc.com', + '+bytednsdoc.com', + '+byteimg.com', + '+byteacctimg.com', + '+ibytedapm.com', + 'oceanengine.com', + '+edge-byted.com', + '+volcvideo.com' + ] + }, + BAIDU: { + dns: '180.76.76.76', + hosts: {}, + realip: false, + ruleset: true, + domains: [ + '91.com', + 'hao123.com', + 'baidu.cn', + 'baidu.com', + 'iqiyi.com', + '+iqiyipic.com', + '+baidubce.com', + '+bcelive.com', + '+baiducontent.com', + '+baidustatic.com', + '+bdstatic.com', + '+bdimg.com', + '+bcebos.com', + '+baidupcs.com', + '+baidubcr.com', + '+yunjiasu-cdn.net', + 'tieba.com', + 'xiaodutv.com', + '+shifen.com', + '+jomodns.com', + '+bdydns.com', + '+jomoxc.com', + '+duapp.com', + '+antpcdn.com', + // Bilibili Baidu CDN + '$upos-sz-mirrorbd.bilivideo.com', + '$upos-sz-mirrorbos.bilivideo.com' + ] + }, + QIHOO360: { + hosts: {}, + dns: 'https://doh.360.cn/dns-query', + realip: false, + ruleset: true, + domains: [ + '+qhimg.com', + '+qhimgs.com', + '+qhimgs?.com', + // '+qhimgs0.com', + // '+qhimgs1.com', + // '+qhimgs2.com', + // '+qhimgs3.com', + // '+qhimgs4.com', + // '+qhimgs5.com', + // '+qhimgs6.com', + '+qhres.com', + '+qhres2.com', + '+qhmsg.com', + '+qhstatic.com', + '+qhupdate.com', + '+qihucdn.com', + '360.com', + '360.cn', + '360.net', + '360safe.com', + '+360tpcdn.com', + '360os.com', + '+360webcache.com', + '360kuai.com', + 'so.com', + 'haosou.com', + 'yunpan.cn', + 'yunpan.com', + 'yunpan.com.cn', + '+qh-cdn.com', + 'baomitu.com', + 'qiku.com' + ] + } + }; + const DOH_BOOTSTRAP = { + ALIBABA: { + hosts: { + 'dns.alidns.com': [ + '223.5.5.5', + '223.6.6.6', + '2400:3200:baba::1', + '2400:3200::1' + ] + }, + realip: false, + ruleset: false, + dns: 'quic://223.5.5.5:853', + domains: [ + '$dns.alidns.com' + ] + }, + DNSPOD: { + hosts: { + // 'dot.pub': ['120.53.53.53', '1.12.12.12'], + 'doh.pub': [ + '120.53.53.53', + '1.12.12.12' + ] + }, + realip: false, + ruleset: false, + dns: 'https://1.12.12.12/dns-query', + domains: [ + // '$dot.pub', + '$doh.pub' + ] + }, + QIHOO360: { + hosts: { + }, + realip: false, + ruleset: false, + // Surge only supports UDP 53 or Hosts as the bootstrap server of domain DoH + dns: '101.198.198.198', + domains: [ + // '$dns.360.cn', + // '$dot.360.cn', + '$doh.360.cn' + ] + } + }; + const AdGuardHomeDNSMapping = { + system: [ + 'udp://10.10.1.1:53' + ], + 'https://doh.pub/dns-query': [ + 'tls://1.12.12.12', + 'tls://120.53.53.53', + 'https://1.12.12.12/dns-query', + 'https://120.53.53.53/dns-query' + ], + 'quic://dns.alidns.com:853': [ + 'quic://223.5.5.5', + 'quic://223.6.6.6', + 'h3://223.5.5.5/dns-query', + 'h3://223.6.6.6/dns-query' + ], + 'https://doh.360.cn/dns-query': [ + 'https://doh.360.cn/dns-query', + 'tls://dot.360.cn' + ], + '180.76.76.76': [ + 'udp://180.76.76.76' + ], + '180.184.2.2': [ + 'udp://180.184.2.2', + 'udp://180.184.1.1' + ] + }; + } (domestic.__exports)); + return domestic.__exports; +}exports.__require=requireDomestic; \ No newline at end of file diff --git a/Dist/Source/stream.cjs b/Dist/Source/stream.cjs new file mode 100644 index 00000000..59becc00 --- /dev/null +++ b/Dist/Source/stream.cjs @@ -0,0 +1,858 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const stream=require('../_virtual/stream.cjs');var hasRequiredStream; + +function requireStream () { + if (hasRequiredStream) return stream.__exports; + hasRequiredStream = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + ALL: function() { + return ALL; + }, + AU: function() { + return AU; + }, + EU: function() { + return EU; + }, + HK: function() { + return HK; + }, + JP: function() { + return JP; + }, + KR: function() { + return KR; + }, + NORTH_AMERICA: function() { + return NORTH_AMERICA; + }, + SOUTH_EAST_ASIA: function() { + return SOUTH_EAST_ASIA; + }, + TW: function() { + return TW; + } + }); + const $4GTV = { + name: '4gtv', + rules: [ + 'DOMAIN-SUFFIX,4gtv.tv', + 'DOMAIN,4gtvfreepcvod-cds.cdn.hinet.net' + ] + }; + const ALL4 = { + name: 'All4', + rules: [ + 'DOMAIN-SUFFIX,c4assets.com', + 'DOMAIN-SUFFIX,channel4.com', + 'USER-AGENT,All4*' + ] + }; + const AMAZON_PRIME_VIDEO = { + name: 'Amazon Prime Video', + rules: [ + 'DOMAIN,avodmp4s3ww-a.akamaihd.net', + 'DOMAIN,d1v5ir2lpwr8os.cloudfront.net', + 'DOMAIN,d22qjgkvxw22r6.cloudfront.net', + 'DOMAIN,d25xi40x97liuc.cloudfront.net', + 'DOMAIN,dmqdd6hw24ucf.cloudfront.net', + 'DOMAIN,d27xxe7juh1us6.cloudfront.net', + 'DOMAIN,d184dfn36gombl.cloudfront.net', + 'DOMAIN,d1xfray82862hr.cloudfront.net', + 'DOMAIN,d3196yreox78o9.cloudfront.net', + 'DOMAIN-KEYWORD,avoddashs', + 'DOMAIN-SUFFIX,aiv-cdn.net', + 'DOMAIN-SUFFIX,aiv-delivery.net', + 'DOMAIN-SUFFIX,amazonvideo.com', + 'DOMAIN-SUFFIX,amazonvideo.cc', + 'DOMAIN-SUFFIX,media-amazon.com', + 'DOMAIN-SUFFIX,primevideo.com', + 'DOMAIN-SUFFIX,prime-video.com', + 'DOMAIN-SUFFIX,primevideo.cc', + 'DOMAIN-SUFFIX,primevideo.info', + 'DOMAIN-SUFFIX,primevideo.org', + 'DOMAIN-SUFFIX,primevideo.tv', + 'DOMAIN-SUFFIX,amazonvideodirect.cc', + 'DOMAIN-SUFFIX,amazonprimevideos.com', + 'DOMAIN-SUFFIX,atv-ps.amazon.com', + 'DOMAIN-SUFFIX,avodmp4s3ww-a.akamaihd.net', + 'DOMAIN-SUFFIX,fls-na.amazon.com', + 'USER-AGENT,InstantVideo.US*', + 'USER-AGENT,Prime Video*', + 'PROCESS-NAME,com.amazon.avod.thirdpartyclient' + ] + }; + const ABEMA_TV = { + name: 'AbemaTV', + rules: [ + // Pure Front-End detection https://ds-linear-abematv.akamaized.net/region check HTTP 200 + 'DOMAIN,ds-linear-abematv.akamaized.net', + 'DOMAIN-SUFFIX,abema.io', + 'DOMAIN-SUFFIX,abema.tv', + 'DOMAIN-SUFFIX,ameba.jp', + 'DOMAIN-SUFFIX,abema-tv.com', + 'DOMAIN-SUFFIX,hayabusa.dev', + 'DOMAIN-SUFFIX,hayabusa.io', + 'DOMAIN-SUFFIX,hayabusa.media', + 'DOMAIN-SUFFIX,amebame.com', + 'DOMAIN-SUFFIX,amebaownd.com', + 'DOMAIN-SUFFIX,amebaowndme.com', + 'DOMAIN-SUFFIX,ameblo.jp', + 'DOMAIN-SUFFIX,dokusho-ojikan.jp', + 'DOMAIN-SUFFIX,winticket.jp', + 'USER-AGENT,AbemaTV*' + ] + }; + const APPLE_TV = { + name: 'Apple TV', + rules: [ + 'DOMAIN,ocvideo.apple.com', + 'DOMAIN,linear.tv.apple.com', + 'DOMAIN,play-edge.itunes.apple.com', + 'DOMAIN,np-edge.itunes.apple.com', + 'DOMAIN,uts-api.itunes.apple.com', + 'DOMAIN,hls-amt.itunes.apple.com', + 'DOMAIN,hls.itunes.apple.com', + 'USER-AGENT,AppleTV*', + 'USER-AGENT,com.apple.tv*', + 'PROCESS-NAME,tv' + ] + }; + const APPLE_MUSIC_TV = { + name: 'Apple Music TV', + rules: [ + 'DOMAIN-SUFFIX,applemusic.com', + 'PROCESS-NAME,music' + ] + }; + const BAHAMUT = { + name: 'Bahamut', + rules: [ + // 'DOMAIN,bahamut.akamaized.net', // Akamai based CDN, no geoblock at all + 'DOMAIN,gamer-cds.cdn.hinet.net', + 'DOMAIN,gamer2-cds.cdn.hinet.net', + 'DOMAIN-SUFFIX,viblast.com', + 'DOMAIN-SUFFIX,bahamut.com.tw', + 'DOMAIN-SUFFIX,ani.gamer.com.tw', + 'USER-AGENT,Anime*' + ] + }; + const BBC = { + name: 'BBC', + rules: [ + 'DOMAIN-SUFFIX,tvlicensing.co.uk', + 'DOMAIN-KEYWORD,bbcfmt', + 'DOMAIN-KEYWORD,uk-live', + 'DOMAIN-SUFFIX,bbc.co.uk', + 'DOMAIN-SUFFIX,bbci.co.uk', + 'USER-AGENT,BBCiPlayer*' + ] + }; + const BILIBILI_INTL = { + name: 'Bilibili International', + rules: [ + 'DOMAIN-SUFFIX,biliintl.com', + 'DOMAIN,apm-misaka.biliapi.net', + 'DOMAIN,upos-bstar-mirrorakam.akamaized.net', + 'DOMAIN,upos-bstar1-mirrorakam.akamaized.net', + // upos-sz-mirroralibstar1.bilivideo.com, from domain bilivideo.com and without geoblocking + 'DOMAIN-SUFFIX,bilibili.tv', + 'PROCESS-NAME,com.bstar.intl' + ] + }; + const DAZN = { + name: 'DAZN', + rules: [ + 'DOMAIN,d151l6v8er5bdm.cloudfront.net', + 'DOMAIN,d1sgwhnao7452x.cloudfront.net', + 'DOMAIN-KEYWORD,voddazn', + 'DOMAIN-SUFFIX,dazn-api.com', + 'DOMAIN-SUFFIX,dazn.com', + 'DOMAIN-SUFFIX,dazndn.com', + 'DOMAIN-SUFFIX,indazn.com', + 'DOMAIN-SUFFIX,indaznlab.com', + 'DOMAIN-SUFFIX,dca-ll-livedazn-dznlivejp.s.llnwi.net', + 'DOMAIN-SUFFIX,dcalivedazn.akamaized.net', + 'DOMAIN-SUFFIX,dcblivedazn.akamaized.net', + 'USER-AGENT,DAZN*' + ] + }; + const DEEZER = { + name: 'Deezer', + rules: [ + 'DOMAIN-SUFFIX,deezer.com', + 'DOMAIN-SUFFIX,dzcdn.net', + 'USER-AGENT,Deezer*' + ] + }; + const DISNEY_PLUS = { + name: 'Disney+', + rules: [ + 'DOMAIN,cdn.registerdisney.go.com', + 'DOMAIN-SUFFIX,bamgrid.com', + 'DOMAIN-SUFFIX,disney-plus.net', + 'DOMAIN-SUFFIX,disneyplus.com', + 'DOMAIN-SUFFIX,dssott.com', + 'DOMAIN-SUFFIX,disneystreaming.com', + 'USER-AGENT,Disney+*' + ] + }; + const DISCOVERY_PLUS = { + name: 'Discovery+', + rules: [ + 'USER-AGENT,DPlus*', + 'USER-AGENT,discovery+*', + 'DOMAIN-SUFFIX,disco-api.com', + 'DOMAIN-SUFFIX,discoveryplus.co.uk', + 'DOMAIN-SUFFIX,discoveryplus.com', + 'DOMAIN-SUFFIX,discoveryplus.in', + 'DOMAIN-SUFFIX,dnitv.com' + ] + }; + const DMM = { + name: 'DMM', + rules: [ + 'DOMAIN-SUFFIX,dmm.co.jp', + 'DOMAIN-SUFFIX,dmm.com', + 'DOMAIN-SUFFIX,dmm-extension.com' + ] + }; + const ENCORE_TVB = { + name: 'encoreTVB', + rules: [ + 'DOMAIN,bcbolt446c5271-a.akamaihd.net', + 'DOMAIN,edge.api.brightcove.com', + 'DOMAIN-SUFFIX,encoretvb.com', + 'USER-AGENT,encoreTVB*', + 'USER-AGENT,TVer-Release*' + ] + }; + const ENCORE_TVB_JP_TVER = { + name: 'encoreTVB JP', + rules: [ + 'DOMAIN-SUFFIX,tver.jp' + ] + }; + const FOX_NOW = { + name: 'Fox Now', + rules: [ + 'DOMAIN-SUFFIX,fox.com', + 'DOMAIN-SUFFIX,foxdcg.com', + 'DOMAIN-SUFFIX,uplynk.com', + 'USER-AGENT,FOX NOW*' + ] + }; + const FOX_PLUS = { + name: 'Fox+', + rules: [ + 'DOMAIN,dashasiafox.akamaized.net', + 'DOMAIN,staticasiafox.akamaized.net', + 'DOMAIN-SUFFIX,foxplus.com', + 'DOMAIN-SUFFIX,theplatform.com', + 'USER-AGENT,FOXPlus*' + ] + }; + const HBO = { + name: 'HBO Go / HBO Now / HBO Max / Max', + rules: [ + 'DOMAIN-SUFFIX,hbo.com', + 'DOMAIN-SUFFIX,hbogo.com', + 'DOMAIN-SUFFIX,hbonow.com', + 'USER-AGENT,HBO NOW*', + 'USER-AGENT,HBOMAX*', + 'DOMAIN-SUFFIX,hbomax.com', + 'DOMAIN-SUFFIX,hbomaxcdn.com', + // 'USER-AGENT,Max', + // 'PROCESS-NAME,com.wbd.stream', + 'DOMAIN-SUFFIX,max.com', + 'DOMAIN-SUFFIX,discomax.com' + ] + }; + const HBO_ASIA = { + name: 'HBO Asia', + rules: [ + 'DOMAIN-SUFFIX,hboasia.com', + 'DOMAIN-SUFFIX,hbogoasia.com', + 'DOMAIN-SUFFIX,hbogoasia.hk', + 'DOMAIN-KEYWORD,.hbogoasia.', + 'DOMAIN,44wilhpljf.execute-api.ap-southeast-1.amazonaws.com', + // 'DOMAIN,bcbolthboa-a.akamaihd.net', + // 'DOMAIN,cf-images.ap-southeast-1.prod.boltdns.net', + // 'DOMAIN,dai3fd1oh325y.cloudfront.net', + // 'DOMAIN,hboasia1-i.akamaihd.net', + // 'DOMAIN,hboasia2-i.akamaihd.net', + // 'DOMAIN,hboasia3-i.akamaihd.net', + // 'DOMAIN,hboasia4-i.akamaihd.net', + // 'DOMAIN,hboasia5-i.akamaihd.net', + // 'DOMAIN,hbogoprod-vod.akamaized.net', + 'DOMAIN,manifest.prod.boltdns.net', + 'DOMAIN,players.brightcove.net', + // 'DOMAIN,hboasialive.akamaized.net', + 'DOMAIN,hbounify-prod.evergent.com', + 'DOMAIN,hbolb.onwardsmg.com' + ] + }; + const HIMALAYA_FM = { + name: 'Himalaya FM', + rules: [ + 'USER-AGENT,Himalaya*', + 'DOMAIN-SUFFIX,himalaya.com' + ] + }; + const HULU = { + name: 'Hulu', + rules: [ + 'DOMAIN-SUFFIX,hulu.com', + 'DOMAIN-SUFFIX,hulu.tv', + 'DOMAIN-SUFFIX,hulu.us', + 'DOMAIN-SUFFIX,huluim.com', + 'DOMAIN-SUFFIX,hulustream.com', + 'USER-AGENT,Hulu*', + 'PROCESS-NAME,com.hulu.plus' + ] + }; + const HULU_JP = { + name: 'Hulu Japan', + rules: [ + 'DOMAIN-SUFFIX,happyon.jp', + 'DOMAIN-SUFFIX,hjholdings.jp', + 'DOMAIN-SUFFIX,hulu.jp' + ] + }; + const HWTV = { + name: 'HWTV', + rules: [ + 'USER-AGENT,HWTVMobile*', + 'DOMAIN-SUFFIX,5itv.tv', + 'DOMAIN-SUFFIX,ocnttv.com' + ] + }; + const ITV = { + name: 'ITV', + rules: [ + 'DOMAIN,itvpnpmobile-a.akamaihd.net', + 'DOMAIN-SUFFIX,itv.com', + 'USER-AGENT,ITV_Player*' + ] + }; + const IQIYI_GLOBAL = { + name: 'iQiYi Global', + rules: [ + 'DOMAIN-SUFFIX,iq.com', + 'DOMAIN,cache.video.iqiyi.com', + 'DOMAIN,cache-video.iq.com', + 'DOMAIN,akmcdnoversea-tw.inter.ptqy.gitv.tv', + 'DOMAIN,chuangcachecdnoversea-tw.inter.ptqy.gitv.tv', + 'DOMAIN-SUFFIX,inter.iqiyi.com', + 'DOMAIN-SUFFIX,intl-rcd.iqiyi.com', + 'DOMAIN-SUFFIX,intl-subscription.iqiyi.com', + 'DOMAIN-SUFFIX,intl.iqiyi.com' + ] + }; + const JOOX = { + name: 'JOOX', + rules: [ + 'DOMAIN-SUFFIX,joox.com', + 'DOMAIN-KEYWORD,jooxweb-api', + 'USER-AGENT,JOOX*', + 'USER-AGENT,WeMusic*', + 'PROCESS-NAME,com.tencent.ibg.joox' + ] + }; + const KKBOX = { + name: 'KKBOX', + rules: [ + 'DOMAIN-SUFFIX,kfs.io', + 'DOMAIN-SUFFIX,kkbox.com', + 'DOMAIN-SUFFIX,kkbox.com.tw', + 'DOMAIN-SUFFIX,kkbox-prime.com', + 'DOMAIN-SUFFIX,kktix.com' + ] + }; + const KKTV = { + name: 'KKTV', + rules: [ + 'DOMAIN-SUFFIX,kk.stream', + 'DOMAIN-SUFFIX,kktv.com.tw', + 'DOMAIN-SUFFIX,kktv.me', + 'USER-AGENT,com.kktv.ios.kktv*', + 'USER-AGENT,KKTV*' + ] + }; + const LINE_TV = { + name: 'Line TV', + rules: [ + 'DOMAIN,d3c7rimkq79yfu.cloudfront.net', + 'DOMAIN-SUFFIX,linetv.tw', + 'USER-AGENT,LINE TV*', + 'PROCESS-NAME,com.linecorp.linetv' + ] + }; + const LITV = { + name: 'LiTV', + rules: [ + 'DOMAIN,litvfreemobile-hichannel.cdn.hinet.net', + 'DOMAIN-SUFFIX,litv.tv' + ] + }; + const MY5 = { + name: 'My5', + rules: [ + 'DOMAIN,d349g9zuie06uo.cloudfront.net', + 'DOMAIN-SUFFIX,channel5.com', + 'DOMAIN-SUFFIX,my5.tv', + 'USER-AGENT,My5*' + ] + }; + const MYTV_SUPER = { + name: 'myTV Super', + rules: [ + 'DOMAIN-SUFFIX,mytvsuper.com', + 'DOMAIN-SUFFIX,tvb.com', + 'DOMAIN-SUFFIX,psg.cdn.hgc.com.hk', + 'USER-AGENT,mytv*', + 'DOMAIN-KEYWORD,nowtv100', + 'DOMAIN-KEYWORD,rthklive' + ] + }; + const NAVER_TV = { + name: 'Naver TV', + rules: [ + 'USER-AGENT,Naver TV*', + 'DOMAIN-SUFFIX,tv.naver.com', + 'DOMAIN-SUFFIX,smartmediarep.com' + ] + }; + const NICONICO = { + name: 'niconico', + rules: [ + 'DOMAIN-SUFFIX,dmc.nico', + 'DOMAIN-SUFFIX,nicovideo.jp', + 'DOMAIN-SUFFIX,asset.domand.nicovideo.jp', + // 'DOMAIN-SUFFIX,nimg.jp', + 'DOMAIN-SUFFIX,socdm.com', + 'USER-AGENT,Niconico*' + ] + }; + const NETFLIX = { + name: 'Netflix', + ip: { + v4: [ + '23.246.18.0/23', + '37.77.184.0/21', + '45.57.0.0/17', + '64.120.128.0/17', + '66.197.128.0/17', + '69.53.224.0/19', + '108.175.32.0/20', + '185.2.220.0/22', + '185.9.188.0/22', + '192.173.64.0/18', + '198.38.96.0/19', + '198.45.48.0/20', + '208.75.76.0/22' + ], + v6: [ + '2607:fb10::/32', + '2620:10c:7000::/44', + '2a00:86c0::/32', + '2a03:5640::/32' + ] + }, + rules: [ + 'DOMAIN-SUFFIX,netflix.ca', + 'DOMAIN-SUFFIX,netflix.com', + 'DOMAIN-SUFFIX,netflix.net', + 'DOMAIN-SUFFIX,nflxext.com', + 'DOMAIN-SUFFIX,nflximg.com', + 'DOMAIN-SUFFIX,nflximg.net', + 'DOMAIN-SUFFIX,nflxso.net', + 'DOMAIN-SUFFIX,nflxvideo.net', + 'DOMAIN-SUFFIX,nflxsearch.net', + 'DOMAIN-SUFFIX,netflix.com.edgesuite.net', + 'DOMAIN-KEYWORD,netflixdnstest', + 'DOMAIN-KEYWORD,dualstack.apiproxy-', + 'DOMAIN-KEYWORD,dualstack.ichnaea-web-', + 'DOMAIN-KEYWORD,apiproxy-device-prod-nlb-', + 'USER-AGENT,Argo*', + 'PROCESS-NAME,com.netflix.mediaclient' + ] + }; + const NHK_PLUS = { + name: 'NHK Plus', + rules: [ + // Pure Front-End detection just like AbemaTV: https://location-plus.nhk.jp/geoip/area.json + 'DOMAIN-SUFFIX,location-plus.nhk.jp' + ] + }; + const NOW_E = { + name: 'Now E', + rules: [ + 'DOMAIN-SUFFIX,nowe.com' + ] + }; + const OVERCAST_FM = { + name: 'Overcast FM', + rules: [ + 'USER-AGENT,Overcast*', + 'DOMAIN-SUFFIX,overcast.fm' + ] + }; + const PARAMOUNT = { + name: 'Paramount+', + rules: [ + 'USER-AGENT,PPlus*', + 'DOMAIN-SUFFIX,pluto.tv', + 'DOMAIN-SUFFIX,cbsi.com', + 'DOMAIN-SUFFIX,cbsaavideo.com', + 'DOMAIN-SUFFIX,cbsivideo.com', + 'DOMAIN-SUFFIX,paramountplus.com', + 'DOMAIN,cbsi.live.ott.irdeto.com', + 'DOMAIN,cbsplaylistserver.aws.syncbak.com', + 'DOMAIN,cbsservice.aws.syncbak.com', + 'DOMAIN,link.theplatform.com' + ] + }; + const PBS = { + name: 'PBS', + rules: [ + 'USER-AGENT,PBS*', + 'DOMAIN-SUFFIX,pbs.org' + ] + }; + const PEACOCK = { + name: 'Peacock', + rules: [ + 'USER-AGENT,PeacockMobile*', + 'DOMAIN-SUFFIX,peacocktv.com' + ] + }; + const PANDORA = { + name: 'Pandora', + rules: [ + 'DOMAIN-SUFFIX,pandora.com', + 'USER-AGENT,Pandora*' + ] + }; + const PORNHUB = { + name: 'Pornhub', + rules: [ + 'DOMAIN-SUFFIX,phprcdn.com', + 'DOMAIN-SUFFIX,pornhub.com', + 'DOMAIN-SUFFIX,pornhubpremium.com' + ] + }; + const SOUNDCLOUD = { + name: 'SoundCloud', + rules: [ + // 'DOMAIN-SUFFIX,sndcdn.com', + 'DOMAIN-SUFFIX,soundcloud.com', + 'USER-AGENT,SoundCloud*' + ] + }; + const SPOTIFY = { + name: 'Spotify', + ip: { + v4: [ + '35.186.224.47/32' + ], + v6: [] + }, + rules: [ + 'DOMAIN-KEYWORD,-spotify-com', + 'DOMAIN-SUFFIX,pscdn.co', + 'DOMAIN-SUFFIX,scdn.co', + 'DOMAIN-SUFFIX,spoti.fi', + 'DOMAIN-SUFFIX,spotify.com', + 'DOMAIN-SUFFIX,byspotify.com', + 'DOMAIN-SUFFIX,spotify-everywhere.com', + 'DOMAIN-SUFFIX,spotify.design', + 'DOMAIN-SUFFIX,spotifycdn.com', + 'DOMAIN-SUFFIX,spotifycdn.net', + 'DOMAIN-SUFFIX,spotifycharts.com', + 'DOMAIN-SUFFIX,spotifycodes.com', + 'DOMAIN-SUFFIX,spotifyforbrands.com', + 'DOMAIN-SUFFIX,spotifyjobs.com', + 'DOMAIN-SUFFIX,spotify-com.akamaized.net', + 'DOMAIN-SUFFIX,spotifynewsroom.jp', + 'DOMAIN-SUFFIX,spotilocal.com', + 'DOMAIN-SUFFIX,tospotify.com', + 'USER-AGENT,*Spotify*' + ] + }; + const TVB_ANYWHERE = { + name: 'TVB Anywhere', + rules: [ + 'DOMAIN-KEYWORD,tvbanywhere' + ] + }; + const TAIWAN_GOOD = { + name: 'TaiwanGood', + rules: [ + 'DOMAIN,hamifans.emome.net', + 'DOMAIN-SUFFIX,skyking.com.tw', + 'USER-AGENT,TaiwanGood*', + 'PROCESS-NAME,com.twgood.android' + ] + }; + const TIDAL = { + name: 'TIDAL', + rules: [ + 'USER-AGENT,TIDAL*', + 'DOMAIN-SUFFIX,tidal.com', + 'DOMAIN-SUFFIX,tidalhifi.com' + ] + }; + const TIKTOK = { + name: 'TikTok', + rules: [ + 'DOMAIN-SUFFIX,byteoversea.com', + 'DOMAIN-SUFFIX,ibytedtos.com', + // 'DOMAIN-SUFFIX,ibyteimg.com', // We confirm that tiktokcdn DOES NOT have ANY geoblock + 'DOMAIN-SUFFIX,ipstatp.com', + 'DOMAIN-SUFFIX,isnssdk.com', + 'DOMAIN-SUFFIX,muscdn.com', + 'DOMAIN-SUFFIX,musical.ly', + 'DOMAIN-SUFFIX,tiktok.com', + 'DOMAIN-SUFFIX,tiktok.us', + 'DOMAIN-SUFFIX,tiktokv.us', + 'DOMAIN-SUFFIX,tik-tokapi.com', + // 'DOMAIN-SUFFIX,tiktokcdn.com', // We confirm that tiktokcdn DOES NOT have ANY geoblock + 'DOMAIN-SUFFIX,tiktokv.com', + 'DOMAIN-SUFFIX,tiktokw.com', + 'DOMAIN-KEYWORD,-tiktokcdn-com', + 'USER-AGENT,TikTok*' + ] + }; + const TWITCH = { + name: 'Twitch', + rules: [ + 'DOMAIN-SUFFIX,jtvnw.net', + 'DOMAIN-SUFFIX,ttvnw.net', + 'DOMAIN-SUFFIX,twitch.tv', + 'DOMAIN-SUFFIX,twitchcdn.net', + 'DOMAIN-SUFFIX,twitchsvc.net', + 'DOMAIN-SUFFIX,ext-twitch.tv', + 'PROCESS-NAME,tv.twitch.android.app' + ] + }; + const VIUTV = { + name: 'ViuTV', + rules: [ + 'DOMAIN,api.viu.now.com', + 'DOMAIN,d1k2us671qcoau.cloudfront.net', + 'DOMAIN,d2anahhhmp1ffz.cloudfront.net', + 'DOMAIN,dfp6rglgjqszk.cloudfront.net', + 'DOMAIN-SUFFIX,viu.com', + 'DOMAIN-SUFFIX,viu.now.com', + 'DOMAIN-SUFFIX,viu.tv', + 'PROCESS-NAME,com.viu.pad', + 'PROCESS-NAME,com.viu.phone', + 'PROCESS-NAME,com.vuclip.viu', + 'PROCESS-NAME,com.hktve.viutv', + 'USER-AGENT,Viu*' + ] + }; + const YOUTUBE = { + name: 'YouTube', + rules: [ + 'DOMAIN,youtubei.googleapis.com', + 'DOMAIN,youtube.googleapis.com', + 'DOMAIN-SUFFIX,googlevideo.com', + 'DOMAIN-SUFFIX,youtube.com', + 'DOMAIN-SUFFIX,withyoutube.com', + 'DOMAIN-SUFFIX,youtubeeducation.com', + 'DOMAIN-SUFFIX,youtubegaming.com', + 'DOMAIN-SUFFIX,youtubekids.com', + 'DOMAIN-SUFFIX,youtube-nocookie.com', + 'USER-AGENT,com.google.ios.youtube*', + 'USER-AGENT,YouTube*' + ] + }; + const YOUTUBE_MUSIC = { + name: 'YouTube Music', + rules: [ + 'USER-AGENT,com.google.ios.youtubemusic*', + 'USER-AGENT,YouTubeMusic*' + ] + }; + const SHOWTIME = { + name: 'SHOWTIME', + rules: [ + 'DOMAIN-SUFFIX,sho.com', + 'DOMAIN-SUFFIX,showtime.com' + ] + }; + const WETV = { + name: 'WeTV', + ip: { + v4: [ + '150.109.28.51/32' + ], + v6: [] + }, + rules: [ + 'USER-AGENT,WeTV*', + 'DOMAIN-SUFFIX,wetv.vip', + 'DOMAIN-SUFFIX,wetvinfo.com' + ] + }; + const VUDU = { + name: 'Vudu', + rules: [ + 'DOMAIN-SUFFIX,vudu.com' + ] + }; + const ALL = [ + $4GTV, + ABEMA_TV, + AMAZON_PRIME_VIDEO, + ALL4, + APPLE_TV, + APPLE_MUSIC_TV, + BAHAMUT, + BBC, + BILIBILI_INTL, + DAZN, + DEEZER, + DISNEY_PLUS, + DISCOVERY_PLUS, + DMM, + ENCORE_TVB, + ENCORE_TVB_JP_TVER, + FOX_NOW, + FOX_PLUS, + HBO, + HBO_ASIA, + HIMALAYA_FM, + HULU, + HWTV, + IQIYI_GLOBAL, + ITV, + JOOX, + KKBOX, + KKTV, + LINE_TV, + LITV, + MY5, + MYTV_SUPER, + NETFLIX, + NAVER_TV, + NICONICO, + NHK_PLUS, + NOW_E, + OVERCAST_FM, + PARAMOUNT, + PBS, + PEACOCK, + PANDORA, + PORNHUB, + SOUNDCLOUD, + SHOWTIME, + SPOTIFY, + TAIWAN_GOOD, + TIDAL, + TIKTOK, + TVB_ANYWHERE, + TWITCH, + VIUTV, + VUDU, + WETV, + YOUTUBE, + YOUTUBE_MUSIC + ]; + const NORTH_AMERICA = [ + FOX_NOW, + FOX_PLUS, + HULU, + HULU_JP, + VUDU, + // HBO, + // www.nfl.com + // epix.com + // starz.com + // www.philo.com + // https://www.shudder.com/ + // https://www.britbox.com + // crackle.com + // www.cwtv.com + // www.aetv.com + // https://www.nba.com/watch/ + // fubo.tv + // mola.tv + // https://setantasports.com/ + // tubitv.com + // SlingTV + // PlutoTV + // AcornTV + SHOWTIME, + ENCORE_TVB, + // Funimation + DISCOVERY_PLUS, + PARAMOUNT, + PEACOCK + ]; + const EU = [ + // RakutenTV + // Funimation + // SkyShowTime + // HBO, + // MathSpot + // SkyGo + // BritBox + ITV, + // BBC Channel 4 + // BBC Channel 5 + BBC + ]; + const HK = [ + NOW_E, + VIUTV, + MYTV_SUPER, + HBO_ASIA, + BILIBILI_INTL + ]; + const TW = [ + KKTV, + LITV, + // MyVideo + $4GTV, + LINE_TV, + // HamiVideo + // CatchPlay + HBO_ASIA, + BAHAMUT + ]; + const JP = [ + DMM, + // DMMTV + ABEMA_TV, + NICONICO, + // music.jp + // Telasa + // Paravi + // unext + HULU_JP, + ENCORE_TVB_JP_TVER, + NHK_PLUS + ]; + const AU = []; + const KR = [ + // WAVEE + // Tving + // CoupangPlay + NAVER_TV + ]; + const SOUTH_EAST_ASIA = []; + } (stream.__exports)); + return stream.__exports; +}exports.__require=requireStream; \ No newline at end of file diff --git a/Dist/_get-lum-apex-domains.cjs b/Dist/_get-lum-apex-domains.cjs new file mode 100644 index 00000000..51a846ae --- /dev/null +++ b/Dist/_get-lum-apex-domains.cjs @@ -0,0 +1,29 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),fetchTextByLine=require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require$$0=require('tldts');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('node:readline'),require('node:stream/web'),require('foxts/guard');var _getLumApexDomains$1 = {};var hasRequired_getLumApexDomains; + +function require_getLumApexDomains () { + if (hasRequired_getLumApexDomains) return _getLumApexDomains$1; + hasRequired_getLumApexDomains = 1; + Object.defineProperty(_getLumApexDomains$1, "__esModule", { + value: true + }); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _tldts = /*#__PURE__*/ _interop_require_default(require$$0); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + (async ()=>{ + const lines = await Array.fromAsync(await (0, _fetchtextbyline.fetchRemoteTextByLine)('https://raw.githubusercontent.com/durablenapkin/block/master/luminati.txt', true)); + const set = new Set(); + lines.forEach((line)=>{ + const apexDomain = _tldts.default.getDomain(line.slice(8)); + if (apexDomain) { + set.add(apexDomain); + } + }); + console.log(Array.from(set).map((line)=>'.' + line).join('\n')); + })(); + return _getLumApexDomains$1; +}var _getLumApexDomainsExports = require_getLumApexDomains(); +const _getLumApexDomains = /*@__PURE__*/fetchRetry.g(_getLumApexDomainsExports);module.exports=_getLumApexDomains; \ No newline at end of file diff --git a/Dist/_virtual/_commonjsHelpers.cjs b/Dist/_virtual/_commonjsHelpers.cjs new file mode 100644 index 00000000..4786084e --- /dev/null +++ b/Dist/_virtual/_commonjsHelpers.cjs @@ -0,0 +1,3 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});function getDefaultExportFromCjs (x) { + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; +}exports.getDefaultExportFromCjs=getDefaultExportFromCjs; \ No newline at end of file diff --git a/Dist/_virtual/_get-lum-apex-domains.cjs b/Dist/_virtual/_get-lum-apex-domains.cjs new file mode 100644 index 00000000..ad6e3702 --- /dev/null +++ b/Dist/_virtual/_get-lum-apex-domains.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var _getLumApexDomains = {};exports.__exports=_getLumApexDomains; \ No newline at end of file diff --git a/Dist/_virtual/adguardhome.cjs b/Dist/_virtual/adguardhome.cjs new file mode 100644 index 00000000..8007d070 --- /dev/null +++ b/Dist/_virtual/adguardhome.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var adguardhome = {};exports.__exports=adguardhome; \ No newline at end of file diff --git a/Dist/_virtual/append-array-in-place.cjs b/Dist/_virtual/append-array-in-place.cjs new file mode 100644 index 00000000..3b482d97 --- /dev/null +++ b/Dist/_virtual/append-array-in-place.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var appendArrayInPlace = {};exports.__exports=appendArrayInPlace; \ No newline at end of file diff --git a/Dist/_virtual/badboy_asn.cjs b/Dist/_virtual/badboy_asn.cjs new file mode 100644 index 00000000..bce02395 --- /dev/null +++ b/Dist/_virtual/badboy_asn.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var badboy_asn = {};exports.__exports=badboy_asn; \ No newline at end of file diff --git a/Dist/_virtual/base.cjs b/Dist/_virtual/base.cjs new file mode 100644 index 00000000..f3fe267f --- /dev/null +++ b/Dist/_virtual/base.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var base = {};exports.__exports=base; \ No newline at end of file diff --git a/Dist/_virtual/base2.cjs b/Dist/_virtual/base2.cjs new file mode 100644 index 00000000..f3fe267f --- /dev/null +++ b/Dist/_virtual/base2.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var base = {};exports.__exports=base; \ No newline at end of file diff --git a/Dist/_virtual/build-apple-cdn.cjs b/Dist/_virtual/build-apple-cdn.cjs new file mode 100644 index 00000000..f6be6a83 --- /dev/null +++ b/Dist/_virtual/build-apple-cdn.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildAppleCdn = {exports: {}};exports.__module=buildAppleCdn; \ No newline at end of file diff --git a/Dist/_virtual/build-cdn-download-conf.cjs b/Dist/_virtual/build-cdn-download-conf.cjs new file mode 100644 index 00000000..6ce9bf50 --- /dev/null +++ b/Dist/_virtual/build-cdn-download-conf.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildCdnDownloadConf = {exports: {}};exports.__module=buildCdnDownloadConf; \ No newline at end of file diff --git a/Dist/_virtual/build-chn-cidr.cjs b/Dist/_virtual/build-chn-cidr.cjs new file mode 100644 index 00000000..82e8d0ed --- /dev/null +++ b/Dist/_virtual/build-chn-cidr.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildChnCidr = {exports: {}};exports.__module=buildChnCidr; \ No newline at end of file diff --git a/Dist/_virtual/build-cloudmounter-rules.cjs b/Dist/_virtual/build-cloudmounter-rules.cjs new file mode 100644 index 00000000..5be47692 --- /dev/null +++ b/Dist/_virtual/build-cloudmounter-rules.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildCloudmounterRules = {exports: {}};exports.__module=buildCloudmounterRules; \ No newline at end of file diff --git a/Dist/_virtual/build-common.cjs b/Dist/_virtual/build-common.cjs new file mode 100644 index 00000000..e73dd51c --- /dev/null +++ b/Dist/_virtual/build-common.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildCommon = {exports: {}};exports.__module=buildCommon; \ No newline at end of file diff --git a/Dist/_virtual/build-deprecate-files.cjs b/Dist/_virtual/build-deprecate-files.cjs new file mode 100644 index 00000000..502d2e4b --- /dev/null +++ b/Dist/_virtual/build-deprecate-files.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildDeprecateFiles = {exports: {}};exports.__module=buildDeprecateFiles; \ No newline at end of file diff --git a/Dist/_virtual/build-domestic-direct-lan-ruleset-dns-mapping-module.cjs b/Dist/_virtual/build-domestic-direct-lan-ruleset-dns-mapping-module.cjs new file mode 100644 index 00000000..7008edb5 --- /dev/null +++ b/Dist/_virtual/build-domestic-direct-lan-ruleset-dns-mapping-module.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildDomesticDirectLanRulesetDnsMappingModule = {exports: {}};exports.__module=buildDomesticDirectLanRulesetDnsMappingModule; \ No newline at end of file diff --git a/Dist/_virtual/build-internal-reverse-chn-cidr.cjs b/Dist/_virtual/build-internal-reverse-chn-cidr.cjs new file mode 100644 index 00000000..18203988 --- /dev/null +++ b/Dist/_virtual/build-internal-reverse-chn-cidr.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildInternalReverseChnCidr = {exports: {}};exports.__module=buildInternalReverseChnCidr; \ No newline at end of file diff --git a/Dist/_virtual/build-microsoft-cdn.cjs b/Dist/_virtual/build-microsoft-cdn.cjs new file mode 100644 index 00000000..8451a903 --- /dev/null +++ b/Dist/_virtual/build-microsoft-cdn.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildMicrosoftCdn = {exports: {}};exports.__module=buildMicrosoftCdn; \ No newline at end of file diff --git a/Dist/_virtual/build-public.cjs b/Dist/_virtual/build-public.cjs new file mode 100644 index 00000000..20341d06 --- /dev/null +++ b/Dist/_virtual/build-public.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildPublic = {exports: {}};exports.__module=buildPublic; \ No newline at end of file diff --git a/Dist/_virtual/build-reject-domainset.cjs b/Dist/_virtual/build-reject-domainset.cjs new file mode 100644 index 00000000..e590e833 --- /dev/null +++ b/Dist/_virtual/build-reject-domainset.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildRejectDomainset = {exports: {}};exports.__module=buildRejectDomainset; \ No newline at end of file diff --git a/Dist/_virtual/build-reject-ip-list.cjs b/Dist/_virtual/build-reject-ip-list.cjs new file mode 100644 index 00000000..cf9a33aa --- /dev/null +++ b/Dist/_virtual/build-reject-ip-list.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildRejectIpList = {exports: {}};exports.__module=buildRejectIpList; \ No newline at end of file diff --git a/Dist/_virtual/build-sgmodule-always-realip.cjs b/Dist/_virtual/build-sgmodule-always-realip.cjs new file mode 100644 index 00000000..666dae11 --- /dev/null +++ b/Dist/_virtual/build-sgmodule-always-realip.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildSgmoduleAlwaysRealip = {exports: {}};exports.__module=buildSgmoduleAlwaysRealip; \ No newline at end of file diff --git a/Dist/_virtual/build-sgmodule-redirect.cjs b/Dist/_virtual/build-sgmodule-redirect.cjs new file mode 100644 index 00000000..8f580391 --- /dev/null +++ b/Dist/_virtual/build-sgmodule-redirect.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildSgmoduleRedirect = {exports: {}};exports.__module=buildSgmoduleRedirect; \ No newline at end of file diff --git a/Dist/_virtual/build-speedtest-domainset.cjs b/Dist/_virtual/build-speedtest-domainset.cjs new file mode 100644 index 00000000..540c2254 --- /dev/null +++ b/Dist/_virtual/build-speedtest-domainset.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildSpeedtestDomainset = {exports: {}};exports.__module=buildSpeedtestDomainset; \ No newline at end of file diff --git a/Dist/_virtual/build-sspanel-appprofile.cjs b/Dist/_virtual/build-sspanel-appprofile.cjs new file mode 100644 index 00000000..eb5f7ee0 --- /dev/null +++ b/Dist/_virtual/build-sspanel-appprofile.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildSspanelAppprofile = {exports: {}};exports.__module=buildSspanelAppprofile; \ No newline at end of file diff --git a/Dist/_virtual/build-stream-service.cjs b/Dist/_virtual/build-stream-service.cjs new file mode 100644 index 00000000..fded0a71 --- /dev/null +++ b/Dist/_virtual/build-stream-service.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildStreamService = {exports: {}};exports.__module=buildStreamService; \ No newline at end of file diff --git a/Dist/_virtual/build-telegram-cidr.cjs b/Dist/_virtual/build-telegram-cidr.cjs new file mode 100644 index 00000000..d8c313fd --- /dev/null +++ b/Dist/_virtual/build-telegram-cidr.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var buildTelegramCidr = {exports: {}};exports.__module=buildTelegramCidr; \ No newline at end of file diff --git a/Dist/_virtual/cache-filesystem.cjs b/Dist/_virtual/cache-filesystem.cjs new file mode 100644 index 00000000..697d3116 --- /dev/null +++ b/Dist/_virtual/cache-filesystem.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var cacheFilesystem = {};exports.__exports=cacheFilesystem; \ No newline at end of file diff --git a/Dist/_virtual/cidr.cjs b/Dist/_virtual/cidr.cjs new file mode 100644 index 00000000..b0563e1d --- /dev/null +++ b/Dist/_virtual/cidr.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var cidr = {};exports.__exports=cidr; \ No newline at end of file diff --git a/Dist/_virtual/clash.cjs b/Dist/_virtual/clash.cjs new file mode 100644 index 00000000..f1ce1068 --- /dev/null +++ b/Dist/_virtual/clash.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var clash = {};exports.__exports=clash; \ No newline at end of file diff --git a/Dist/_virtual/cloudmounter.cjs b/Dist/_virtual/cloudmounter.cjs new file mode 100644 index 00000000..f88ee66b --- /dev/null +++ b/Dist/_virtual/cloudmounter.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var cloudmounter = {};exports.__exports=cloudmounter; \ No newline at end of file diff --git a/Dist/_virtual/create-file.cjs b/Dist/_virtual/create-file.cjs new file mode 100644 index 00000000..321dfb0c --- /dev/null +++ b/Dist/_virtual/create-file.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var createFile = {};exports.__exports=createFile; \ No newline at end of file diff --git a/Dist/_virtual/description.cjs b/Dist/_virtual/description.cjs new file mode 100644 index 00000000..d54624d1 --- /dev/null +++ b/Dist/_virtual/description.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var description = {};exports.__exports=description; \ No newline at end of file diff --git a/Dist/_virtual/dir.cjs b/Dist/_virtual/dir.cjs new file mode 100644 index 00000000..8a9891fb --- /dev/null +++ b/Dist/_virtual/dir.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var dir = {};exports.__exports=dir; \ No newline at end of file diff --git a/Dist/_virtual/direct.cjs b/Dist/_virtual/direct.cjs new file mode 100644 index 00000000..a6f6f44b --- /dev/null +++ b/Dist/_virtual/direct.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var direct = {};exports.__exports=direct; \ No newline at end of file diff --git a/Dist/_virtual/domainlists.cjs b/Dist/_virtual/domainlists.cjs new file mode 100644 index 00000000..7ffe0693 --- /dev/null +++ b/Dist/_virtual/domainlists.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var domainlists = {};exports.__exports=domainlists; \ No newline at end of file diff --git a/Dist/_virtual/domains.cjs b/Dist/_virtual/domains.cjs new file mode 100644 index 00000000..f70bb6e0 --- /dev/null +++ b/Dist/_virtual/domains.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var domains = {};exports.__exports=domains; \ No newline at end of file diff --git a/Dist/_virtual/domainset.cjs b/Dist/_virtual/domainset.cjs new file mode 100644 index 00000000..25cba3c1 --- /dev/null +++ b/Dist/_virtual/domainset.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var domainset = {};exports.__exports=domainset; \ No newline at end of file diff --git a/Dist/_virtual/domestic.cjs b/Dist/_virtual/domestic.cjs new file mode 100644 index 00000000..c4415fa7 --- /dev/null +++ b/Dist/_virtual/domestic.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var domestic = {};exports.__exports=domestic; \ No newline at end of file diff --git a/Dist/_virtual/download-mock-assets.cjs b/Dist/_virtual/download-mock-assets.cjs new file mode 100644 index 00000000..fe4ce103 --- /dev/null +++ b/Dist/_virtual/download-mock-assets.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var downloadMockAssets = {exports: {}};exports.__module=downloadMockAssets; \ No newline at end of file diff --git a/Dist/_virtual/download-previous-build.cjs b/Dist/_virtual/download-previous-build.cjs new file mode 100644 index 00000000..43c47967 --- /dev/null +++ b/Dist/_virtual/download-previous-build.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var downloadPreviousBuild = {exports: {}};exports.__module=downloadPreviousBuild; \ No newline at end of file diff --git a/Dist/_virtual/fetch-assets.cjs b/Dist/_virtual/fetch-assets.cjs new file mode 100644 index 00000000..86f12c35 --- /dev/null +++ b/Dist/_virtual/fetch-assets.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var fetchAssets = {};exports.__exports=fetchAssets; \ No newline at end of file diff --git a/Dist/_virtual/fetch-retry.cjs b/Dist/_virtual/fetch-retry.cjs new file mode 100644 index 00000000..51973be6 --- /dev/null +++ b/Dist/_virtual/fetch-retry.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var fetchRetry = {};exports.__exports=fetchRetry; \ No newline at end of file diff --git a/Dist/_virtual/fetch-text-by-line.cjs b/Dist/_virtual/fetch-text-by-line.cjs new file mode 100644 index 00000000..4d9dacb1 --- /dev/null +++ b/Dist/_virtual/fetch-text-by-line.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var fetchTextByLine = {};exports.__exports=fetchTextByLine; \ No newline at end of file diff --git a/Dist/_virtual/filters.cjs b/Dist/_virtual/filters.cjs new file mode 100644 index 00000000..615cec1d --- /dev/null +++ b/Dist/_virtual/filters.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var filters = {};exports.__exports=filters; \ No newline at end of file diff --git a/Dist/_virtual/fs-memo.cjs b/Dist/_virtual/fs-memo.cjs new file mode 100644 index 00000000..fa8628b8 --- /dev/null +++ b/Dist/_virtual/fs-memo.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var fsMemo = {};exports.__exports=fsMemo; \ No newline at end of file diff --git a/Dist/_virtual/get-phishing-domains.cjs b/Dist/_virtual/get-phishing-domains.cjs new file mode 100644 index 00000000..2829182b --- /dev/null +++ b/Dist/_virtual/get-phishing-domains.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var getPhishingDomains = {exports: {}};exports.__module=getPhishingDomains; \ No newline at end of file diff --git a/Dist/_virtual/hosts.cjs b/Dist/_virtual/hosts.cjs new file mode 100644 index 00000000..7e83099e --- /dev/null +++ b/Dist/_virtual/hosts.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var hosts = {};exports.__exports=hosts; \ No newline at end of file diff --git a/Dist/_virtual/index.cjs b/Dist/_virtual/index.cjs new file mode 100644 index 00000000..9772ee9c --- /dev/null +++ b/Dist/_virtual/index.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var Build = {};exports.__exports=Build; \ No newline at end of file diff --git a/Dist/_virtual/index2.cjs b/Dist/_virtual/index2.cjs new file mode 100644 index 00000000..c6f9aaa4 --- /dev/null +++ b/Dist/_virtual/index2.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var trace = {};exports.__exports=trace; \ No newline at end of file diff --git a/Dist/_virtual/ip.cjs b/Dist/_virtual/ip.cjs new file mode 100644 index 00000000..f20c8b60 --- /dev/null +++ b/Dist/_virtual/ip.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var ip = {};exports.__exports=ip; \ No newline at end of file diff --git a/Dist/_virtual/is-domain-alive.cjs b/Dist/_virtual/is-domain-alive.cjs new file mode 100644 index 00000000..d5349bfc --- /dev/null +++ b/Dist/_virtual/is-domain-alive.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var isDomainAlive = {};exports.__exports=isDomainAlive; \ No newline at end of file diff --git a/Dist/_virtual/loose-tldts-opt.cjs b/Dist/_virtual/loose-tldts-opt.cjs new file mode 100644 index 00000000..27dcbe8a --- /dev/null +++ b/Dist/_virtual/loose-tldts-opt.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var looseTldtsOpt = {};exports.__exports=looseTldtsOpt; \ No newline at end of file diff --git a/Dist/_virtual/memo-promise.cjs b/Dist/_virtual/memo-promise.cjs new file mode 100644 index 00000000..ccb5f094 --- /dev/null +++ b/Dist/_virtual/memo-promise.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var memoPromise = {};exports.__exports=memoPromise; \ No newline at end of file diff --git a/Dist/_virtual/misc.cjs b/Dist/_virtual/misc.cjs new file mode 100644 index 00000000..af1c392c --- /dev/null +++ b/Dist/_virtual/misc.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var misc = {};exports.__exports=misc; \ No newline at end of file diff --git a/Dist/_virtual/normalize-domain.cjs b/Dist/_virtual/normalize-domain.cjs new file mode 100644 index 00000000..60929800 --- /dev/null +++ b/Dist/_virtual/normalize-domain.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var normalizeDomain = {};exports.__exports=normalizeDomain; \ No newline at end of file diff --git a/Dist/_virtual/parse-dnsmasq.cjs b/Dist/_virtual/parse-dnsmasq.cjs new file mode 100644 index 00000000..ade17704 --- /dev/null +++ b/Dist/_virtual/parse-dnsmasq.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var parseDnsmasq = {};exports.__exports=parseDnsmasq; \ No newline at end of file diff --git a/Dist/_virtual/process-line.cjs b/Dist/_virtual/process-line.cjs new file mode 100644 index 00000000..6510f7ef --- /dev/null +++ b/Dist/_virtual/process-line.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var processLine = {};exports.__exports=processLine; \ No newline at end of file diff --git a/Dist/_virtual/reject-data-source.cjs b/Dist/_virtual/reject-data-source.cjs new file mode 100644 index 00000000..97802f84 --- /dev/null +++ b/Dist/_virtual/reject-data-source.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var rejectDataSource = {};exports.__exports=rejectDataSource; \ No newline at end of file diff --git a/Dist/_virtual/ruleset.cjs b/Dist/_virtual/ruleset.cjs new file mode 100644 index 00000000..f77cb884 --- /dev/null +++ b/Dist/_virtual/ruleset.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var ruleset = {};exports.__exports=ruleset; \ No newline at end of file diff --git a/Dist/_virtual/shared.cjs b/Dist/_virtual/shared.cjs new file mode 100644 index 00000000..c74135c5 --- /dev/null +++ b/Dist/_virtual/shared.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var shared = {};exports.__exports=shared; \ No newline at end of file diff --git a/Dist/_virtual/singbox.cjs b/Dist/_virtual/singbox.cjs new file mode 100644 index 00000000..a62e85b3 --- /dev/null +++ b/Dist/_virtual/singbox.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var singbox = {};exports.__exports=singbox; \ No newline at end of file diff --git a/Dist/_virtual/stream.cjs b/Dist/_virtual/stream.cjs new file mode 100644 index 00000000..1e3b7f2e --- /dev/null +++ b/Dist/_virtual/stream.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var stream = {};exports.__exports=stream; \ No newline at end of file diff --git a/Dist/_virtual/surge.cjs b/Dist/_virtual/surge.cjs new file mode 100644 index 00000000..ff89a545 --- /dev/null +++ b/Dist/_virtual/surge.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var surge = {};exports.__exports=surge; \ No newline at end of file diff --git a/Dist/_virtual/text-line-transform-stream.cjs b/Dist/_virtual/text-line-transform-stream.cjs new file mode 100644 index 00000000..0974240e --- /dev/null +++ b/Dist/_virtual/text-line-transform-stream.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var textLineTransformStream = {};exports.__exports=textLineTransformStream; \ No newline at end of file diff --git a/Dist/_virtual/tree-dir.cjs b/Dist/_virtual/tree-dir.cjs new file mode 100644 index 00000000..efedb9e4 --- /dev/null +++ b/Dist/_virtual/tree-dir.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var treeDir = {};exports.__exports=treeDir; \ No newline at end of file diff --git a/Dist/_virtual/trie.cjs b/Dist/_virtual/trie.cjs new file mode 100644 index 00000000..a0508000 --- /dev/null +++ b/Dist/_virtual/trie.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var trie = {};exports.__exports=trie; \ No newline at end of file diff --git a/Dist/_virtual/trim-source.cjs b/Dist/_virtual/trim-source.cjs new file mode 100644 index 00000000..628b8467 --- /dev/null +++ b/Dist/_virtual/trim-source.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var trimSource = {};exports.__exports=trimSource; \ No newline at end of file diff --git a/Dist/_virtual/validate-domain-alive.cjs b/Dist/_virtual/validate-domain-alive.cjs new file mode 100644 index 00000000..5b107b10 --- /dev/null +++ b/Dist/_virtual/validate-domain-alive.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var validateDomainAlive = {};exports.__exports=validateDomainAlive; \ No newline at end of file diff --git a/Dist/_virtual/validate-domestic.cjs b/Dist/_virtual/validate-domestic.cjs new file mode 100644 index 00000000..d1fe0520 --- /dev/null +++ b/Dist/_virtual/validate-domestic.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var validateDomestic = {};exports.__exports=validateDomestic; \ No newline at end of file diff --git a/Dist/_virtual/validate-gfwlist.cjs b/Dist/_virtual/validate-gfwlist.cjs new file mode 100644 index 00000000..366aed3a --- /dev/null +++ b/Dist/_virtual/validate-gfwlist.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var validateGfwlist = {exports: {}};exports.__module=validateGfwlist; \ No newline at end of file diff --git a/Dist/_virtual/validate-global-tld.cjs b/Dist/_virtual/validate-global-tld.cjs new file mode 100644 index 00000000..33fd7025 --- /dev/null +++ b/Dist/_virtual/validate-global-tld.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var validateGlobalTld = {};exports.__exports=validateGlobalTld; \ No newline at end of file diff --git a/Dist/_virtual/validate-hash-collision-test.cjs b/Dist/_virtual/validate-hash-collision-test.cjs new file mode 100644 index 00000000..b75c483f --- /dev/null +++ b/Dist/_virtual/validate-hash-collision-test.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var validateHashCollisionTest = {};exports.__exports=validateHashCollisionTest; \ No newline at end of file diff --git a/Dist/_virtual/validate-reject-stats.cjs b/Dist/_virtual/validate-reject-stats.cjs new file mode 100644 index 00000000..3a4b11b5 --- /dev/null +++ b/Dist/_virtual/validate-reject-stats.cjs @@ -0,0 +1 @@ +'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});var validateRejectStats = {};exports.__exports=validateRejectStats; \ No newline at end of file diff --git a/Dist/build-apple-cdn.cjs b/Dist/build-apple-cdn.cjs new file mode 100644 index 00000000..7accc805 --- /dev/null +++ b/Dist/build-apple-cdn.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildAppleCdn$1=require('./chunks/build-apple-cdn.CNsnkTO_.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/parse-dnsmasq.CiH7YJVY.cjs'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('foxts/is-probably-ip'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('json-stringify-pretty-compact'),require('./chunks/trie.Vu1FNyv-.cjs'),require('foxts/fast-string-array-join'),require('foxts/bitwise'),require('fast-cidr-tools'),require('foxts/retrie'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('./chunks/memo-promise.BbOsVeGo.cjs'),require('./chunks/domainset.CSQfKAtf.cjs'),require('foxts/escape-string-regexp');var buildAppleCdnExports = buildAppleCdn$1.r(); +const buildAppleCdn = /*@__PURE__*/fetchRetry.g(buildAppleCdnExports);module.exports=buildAppleCdn; \ No newline at end of file diff --git a/Dist/build-cdn-download-conf.cjs b/Dist/build-cdn-download-conf.cjs new file mode 100644 index 00000000..4b9f0b70 --- /dev/null +++ b/Dist/build-cdn-download-conf.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildCdnDownloadConf$1=require('./chunks/build-cdn-download-conf.Dj0KZ2lm.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('./chunks/trie.Vu1FNyv-.cjs'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('foxts/noop'),require('foxts/fast-string-array-join'),require('foxts/bitwise'),require('./chunks/index.B8Uk9n3v.cjs'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('json-stringify-pretty-compact'),require('fast-cidr-tools'),require('foxts/retrie'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('foxts/is-probably-ip'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('./chunks/domainset.CSQfKAtf.cjs'),require('foxts/escape-string-regexp'),require('./chunks/reject-data-source.DaKwvNlG.cjs');var buildCdnDownloadConfExports = buildCdnDownloadConf$1.r(); +const buildCdnDownloadConf = /*@__PURE__*/fetchRetry.g(buildCdnDownloadConfExports);module.exports=buildCdnDownloadConf; \ No newline at end of file diff --git a/Dist/build-chn-cidr.cjs b/Dist/build-chn-cidr.cjs new file mode 100644 index 00000000..7457fe34 --- /dev/null +++ b/Dist/build-chn-cidr.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildChnCidr$1=require('./chunks/build-chn-cidr.BjyqKcvm.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('fast-cidr-tools'),require('./chunks/memo-promise.BbOsVeGo.cjs'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('json-stringify-pretty-compact'),require('./chunks/trie.Vu1FNyv-.cjs'),require('foxts/fast-string-array-join'),require('foxts/bitwise'),require('foxts/retrie'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('foxts/is-probably-ip'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('./chunks/fs-memo.Dw823m02.cjs'),require('ci-info'),require('better-sqlite3'),require('node:os'),require('node:perf_hooks'),require('foxts/serialized-memo');var buildChnCidrExports = buildChnCidr$1.r(); +const buildChnCidr = /*@__PURE__*/fetchRetry.g(buildChnCidrExports);module.exports=buildChnCidr; \ No newline at end of file diff --git a/Dist/build-cloudmounter-rules.cjs b/Dist/build-cloudmounter-rules.cjs new file mode 100644 index 00000000..806ee1e0 --- /dev/null +++ b/Dist/build-cloudmounter-rules.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildCloudmounterRules$1=require('./chunks/build-cloudmounter-rules.RMp-w3JV.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('foxts/noop'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('json-stringify-pretty-compact'),require('./chunks/trie.Vu1FNyv-.cjs'),require('foxts/fast-string-array-join'),require('foxts/bitwise'),require('foxts/guard'),require('fast-cidr-tools'),require('foxts/retrie'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/is-probably-ip'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('./chunks/index.B8Uk9n3v.cjs'),require('./chunks/ruleset.iYH0XOC1.cjs');var buildCloudmounterRulesExports = buildCloudmounterRules$1.r(); +const buildCloudmounterRules = /*@__PURE__*/fetchRetry.g(buildCloudmounterRulesExports);module.exports=buildCloudmounterRules; \ No newline at end of file diff --git a/Dist/build-common.cjs b/Dist/build-common.cjs new file mode 100644 index 00000000..cf41b722 --- /dev/null +++ b/Dist/build-common.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildCommon$1=require('./chunks/build-common.DBhs-fKR.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('json-stringify-pretty-compact'),require('./chunks/trie.Vu1FNyv-.cjs'),require('foxts/fast-string-array-join'),require('foxts/bitwise'),require('fast-cidr-tools'),require('foxts/retrie'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('foxts/is-probably-ip'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('fdir'),require('./chunks/domainset.CSQfKAtf.cjs'),require('foxts/escape-string-regexp'),require('./chunks/ruleset.iYH0XOC1.cjs');var buildCommonExports = buildCommon$1.r(); +const buildCommon = /*@__PURE__*/fetchRetry.g(buildCommonExports);module.exports=buildCommon; \ No newline at end of file diff --git a/Dist/build-deprecate-files.cjs b/Dist/build-deprecate-files.cjs new file mode 100644 index 00000000..3cf46fbd --- /dev/null +++ b/Dist/build-deprecate-files.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildDeprecateFiles$1=require('./chunks/build-deprecate-files.BeL0QUfk.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('foxts/fast-string-array-join'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop');var buildDeprecateFilesExports = buildDeprecateFiles$1.r(); +const buildDeprecateFiles = /*@__PURE__*/fetchRetry.g(buildDeprecateFilesExports);module.exports=buildDeprecateFiles; \ No newline at end of file diff --git a/Dist/build-domestic-direct-lan-ruleset-dns-mapping-module.cjs b/Dist/build-domestic-direct-lan-ruleset-dns-mapping-module.cjs new file mode 100644 index 00000000..e5fe12b9 --- /dev/null +++ b/Dist/build-domestic-direct-lan-ruleset-dns-mapping-module.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildDomesticDirectLanRulesetDnsMappingModule$1=require('./chunks/build-domestic-direct-lan-ruleset-dns-mapping-module.T1tgVza_.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('foxts/fast-string-array-join'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('json-stringify-pretty-compact'),require('./chunks/trie.Vu1FNyv-.cjs'),require('foxts/bitwise'),require('fast-cidr-tools'),require('foxts/retrie'),require('foxts/is-probably-ip'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('./chunks/memo-promise.BbOsVeGo.cjs'),require('yaml'),require('./chunks/ruleset.iYH0XOC1.cjs');var buildDomesticDirectLanRulesetDnsMappingModuleExports = buildDomesticDirectLanRulesetDnsMappingModule$1.r(); +const buildDomesticDirectLanRulesetDnsMappingModule = /*@__PURE__*/fetchRetry.g(buildDomesticDirectLanRulesetDnsMappingModuleExports);module.exports=buildDomesticDirectLanRulesetDnsMappingModule; \ No newline at end of file diff --git a/Dist/build-internal-reverse-chn-cidr.cjs b/Dist/build-internal-reverse-chn-cidr.cjs new file mode 100644 index 00000000..1237092b --- /dev/null +++ b/Dist/build-internal-reverse-chn-cidr.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildInternalReverseChnCidr$1=require('./chunks/build-internal-reverse-chn-cidr.C6CBihfs.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('./chunks/build-chn-cidr.BjyqKcvm.cjs'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('fast-cidr-tools'),require('./chunks/memo-promise.BbOsVeGo.cjs'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('json-stringify-pretty-compact'),require('./chunks/trie.Vu1FNyv-.cjs'),require('foxts/fast-string-array-join'),require('foxts/bitwise'),require('foxts/retrie'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('foxts/is-probably-ip'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('./chunks/fs-memo.Dw823m02.cjs'),require('ci-info'),require('better-sqlite3'),require('node:os'),require('node:perf_hooks'),require('foxts/serialized-memo'),require('worktank'),require('url');var buildInternalReverseChnCidrExports = buildInternalReverseChnCidr$1.r(); +const buildInternalReverseChnCidr = /*@__PURE__*/fetchRetry.g(buildInternalReverseChnCidrExports);module.exports=buildInternalReverseChnCidr; \ No newline at end of file diff --git a/Dist/build-microsoft-cdn.cjs b/Dist/build-microsoft-cdn.cjs new file mode 100644 index 00000000..5479980a --- /dev/null +++ b/Dist/build-microsoft-cdn.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildMicrosoftCdn$1=require('./chunks/build-microsoft-cdn.CCw86frc.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('./chunks/trie.Vu1FNyv-.cjs'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('foxts/fast-string-array-join'),require('foxts/bitwise'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('json-stringify-pretty-compact'),require('fast-cidr-tools'),require('foxts/retrie'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('foxts/is-probably-ip'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('./chunks/memo-promise.BbOsVeGo.cjs'),require('./chunks/parse-dnsmasq.CiH7YJVY.cjs'),require('./chunks/ruleset.iYH0XOC1.cjs');var buildMicrosoftCdnExports = buildMicrosoftCdn$1.r(); +const buildMicrosoftCdn = /*@__PURE__*/fetchRetry.g(buildMicrosoftCdnExports);module.exports=buildMicrosoftCdn; \ No newline at end of file diff --git a/Dist/build-public.cjs b/Dist/build-public.cjs new file mode 100644 index 00000000..a25779c8 --- /dev/null +++ b/Dist/build-public.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildPublic$1=require('./chunks/build-public.8-AWnl05.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('node:fs/promises'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('./chunks/misc.BpcQjda1.cjs'),require('foxts/tagged'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('foxts/fast-string-array-join'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/guard');var buildPublicExports = buildPublic$1.r(); +const buildPublic = /*@__PURE__*/fetchRetry.g(buildPublicExports);module.exports=buildPublic; \ No newline at end of file diff --git a/Dist/build-reject-domainset.cjs b/Dist/build-reject-domainset.cjs new file mode 100644 index 00000000..0ac6e369 --- /dev/null +++ b/Dist/build-reject-domainset.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildRejectDomainset$1=require('./chunks/build-reject-domainset.BCoJGSBE.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/fetch-assets.aqw2YOi8.cjs'),require('foxts/wait'),require('foxts/guard'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('foxts/is-probably-ip'),require('./chunks/reject-data-source.DaKwvNlG.cjs'),require('foxts/noop'),require('foxts/retrie'),require('tldts-experimental'),require('@ghostery/adblocker'),require('./chunks/index.B8Uk9n3v.cjs'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('json-stringify-pretty-compact'),require('./chunks/trie.Vu1FNyv-.cjs'),require('foxts/fast-string-array-join'),require('foxts/bitwise'),require('fast-cidr-tools'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('./chunks/fs-memo.Dw823m02.cjs'),require('ci-info'),require('better-sqlite3'),require('node:os'),require('node:perf_hooks'),require('foxts/serialized-memo'),require('foxts/add-array-elements-to-set'),require('./chunks/domainset.CSQfKAtf.cjs'),require('foxts/escape-string-regexp');var buildRejectDomainsetExports = buildRejectDomainset$1.r(); +const buildRejectDomainset = /*@__PURE__*/fetchRetry.g(buildRejectDomainsetExports);module.exports=buildRejectDomainset; \ No newline at end of file diff --git a/Dist/build-reject-ip-list.cjs b/Dist/build-reject-ip-list.cjs new file mode 100644 index 00000000..d7771adb --- /dev/null +++ b/Dist/build-reject-ip-list.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildRejectIpList$1=require('./chunks/build-reject-ip-list.D6Cjv0d8.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('json-stringify-pretty-compact'),require('./chunks/trie.Vu1FNyv-.cjs'),require('foxts/fast-string-array-join'),require('foxts/bitwise'),require('fast-cidr-tools'),require('foxts/retrie'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('foxts/is-probably-ip'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('./chunks/fetch-assets.aqw2YOi8.cjs'),require('foxts/wait'),require('./chunks/ruleset.iYH0XOC1.cjs');var buildRejectIpListExports = buildRejectIpList$1.r(); +const buildRejectIpList = /*@__PURE__*/fetchRetry.g(buildRejectIpListExports);module.exports=buildRejectIpList; \ No newline at end of file diff --git a/Dist/build-sgmodule-always-realip.cjs b/Dist/build-sgmodule-always-realip.cjs new file mode 100644 index 00000000..bcb13649 --- /dev/null +++ b/Dist/build-sgmodule-always-realip.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildSgmoduleAlwaysRealip$1=require('./chunks/build-sgmodule-always-realip.CuBgClIT.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('foxts/fast-string-array-join'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('./chunks/build-domestic-direct-lan-ruleset-dns-mapping-module.T1tgVza_.cjs'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('json-stringify-pretty-compact'),require('./chunks/trie.Vu1FNyv-.cjs'),require('foxts/bitwise'),require('fast-cidr-tools'),require('foxts/retrie'),require('foxts/is-probably-ip'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('./chunks/memo-promise.BbOsVeGo.cjs'),require('yaml'),require('./chunks/ruleset.iYH0XOC1.cjs');var buildSgmoduleAlwaysRealipExports = buildSgmoduleAlwaysRealip$1.r(); +const buildSgmoduleAlwaysRealip = /*@__PURE__*/fetchRetry.g(buildSgmoduleAlwaysRealipExports);module.exports=buildSgmoduleAlwaysRealip; \ No newline at end of file diff --git a/Dist/build-sgmodule-redirect.cjs b/Dist/build-sgmodule-redirect.cjs new file mode 100644 index 00000000..55c4e81c --- /dev/null +++ b/Dist/build-sgmodule-redirect.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildSgmoduleRedirect$1=require('./chunks/build-sgmodule-redirect.iquVSpqW.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('foxts/fast-string-array-join'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('tldts-experimental');var buildSgmoduleRedirectExports = buildSgmoduleRedirect$1.r(); +const buildSgmoduleRedirect = /*@__PURE__*/fetchRetry.g(buildSgmoduleRedirectExports);module.exports=buildSgmoduleRedirect; \ No newline at end of file diff --git a/Dist/build-speedtest-domainset.cjs b/Dist/build-speedtest-domainset.cjs new file mode 100644 index 00000000..46e63e0a --- /dev/null +++ b/Dist/build-speedtest-domainset.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildSpeedtestDomainset$1=require('./chunks/build-speedtest-domainset.D2jYMvWN.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('tldts-experimental'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('json-stringify-pretty-compact'),require('./chunks/trie.Vu1FNyv-.cjs'),require('foxts/fast-string-array-join'),require('foxts/bitwise'),require('foxts/guard'),require('fast-cidr-tools'),require('foxts/retrie'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/is-probably-ip'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('./chunks/domainset.CSQfKAtf.cjs'),require('foxts/escape-string-regexp'),require('@henrygd/queue');var buildSpeedtestDomainsetExports = buildSpeedtestDomainset$1.r(); +const buildSpeedtestDomainset = /*@__PURE__*/fetchRetry.g(buildSpeedtestDomainsetExports);module.exports=buildSpeedtestDomainset; \ No newline at end of file diff --git a/Dist/build-sspanel-appprofile.cjs b/Dist/build-sspanel-appprofile.cjs new file mode 100644 index 00000000..39d5ca19 --- /dev/null +++ b/Dist/build-sspanel-appprofile.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildSspanelAppprofile$1=require('./chunks/build-sspanel-appprofile.DbsFXAyN.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/build-apple-cdn.CNsnkTO_.cjs'),require('./chunks/parse-dnsmasq.CiH7YJVY.cjs'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('foxts/is-probably-ip'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('json-stringify-pretty-compact'),require('./chunks/trie.Vu1FNyv-.cjs'),require('foxts/fast-string-array-join'),require('foxts/bitwise'),require('fast-cidr-tools'),require('foxts/retrie'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('./chunks/memo-promise.BbOsVeGo.cjs'),require('./chunks/domainset.CSQfKAtf.cjs'),require('foxts/escape-string-regexp'),require('./chunks/build-domestic-direct-lan-ruleset-dns-mapping-module.T1tgVza_.cjs'),require('yaml'),require('./chunks/ruleset.iYH0XOC1.cjs'),require('./chunks/stream.C9eZuk9f.cjs'),require('./chunks/build-chn-cidr.BjyqKcvm.cjs'),require('./chunks/fs-memo.Dw823m02.cjs'),require('ci-info'),require('better-sqlite3'),require('node:os'),require('node:perf_hooks'),require('foxts/serialized-memo'),require('./chunks/build-telegram-cidr.05NmRbUx.cjs'),require('./chunks/build-microsoft-cdn.CCw86frc.cjs');var buildSspanelAppprofileExports = buildSspanelAppprofile$1.r(); +const buildSspanelAppprofile = /*@__PURE__*/fetchRetry.g(buildSspanelAppprofileExports);module.exports=buildSspanelAppprofile; \ No newline at end of file diff --git a/Dist/build-stream-service.cjs b/Dist/build-stream-service.cjs new file mode 100644 index 00000000..40a76e9a --- /dev/null +++ b/Dist/build-stream-service.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildStreamService$1=require('./chunks/build-stream-service.BKBKJK6i.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('./chunks/stream.C9eZuk9f.cjs'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('json-stringify-pretty-compact'),require('./chunks/trie.Vu1FNyv-.cjs'),require('foxts/fast-string-array-join'),require('foxts/bitwise'),require('foxts/guard'),require('fast-cidr-tools'),require('foxts/retrie'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/is-probably-ip'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('./chunks/ruleset.iYH0XOC1.cjs');var buildStreamServiceExports = buildStreamService$1.r(); +const buildStreamService = /*@__PURE__*/fetchRetry.g(buildStreamServiceExports);module.exports=buildStreamService; \ No newline at end of file diff --git a/Dist/build-telegram-cidr.cjs b/Dist/build-telegram-cidr.cjs new file mode 100644 index 00000000..4b4ab39a --- /dev/null +++ b/Dist/build-telegram-cidr.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),buildTelegramCidr$1=require('./chunks/build-telegram-cidr.05NmRbUx.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('json-stringify-pretty-compact'),require('./chunks/trie.Vu1FNyv-.cjs'),require('foxts/fast-string-array-join'),require('foxts/bitwise'),require('fast-cidr-tools'),require('foxts/retrie'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('foxts/is-probably-ip'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('./chunks/memo-promise.BbOsVeGo.cjs'),require('./chunks/ruleset.iYH0XOC1.cjs');var buildTelegramCidrExports = buildTelegramCidr$1.r(); +const buildTelegramCidr = /*@__PURE__*/fetchRetry.g(buildTelegramCidrExports);module.exports=buildTelegramCidr; \ No newline at end of file diff --git a/Dist/chunks/base.C13YY5P3.cjs b/Dist/chunks/base.C13YY5P3.cjs new file mode 100644 index 00000000..fc7d1e59 --- /dev/null +++ b/Dist/chunks/base.C13YY5P3.cjs @@ -0,0 +1,1145 @@ +'use strict';const require$$0=require('foxts/append-set-elements-to-array'),require$$2=require('foxts/noop'),misc=require('./misc.BpcQjda1.cjs'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),require$$4=require('json-stringify-pretty-compact'),trie=require('./trie.Vu1FNyv-.cjs'),require$$6=require('foxts/guard'),require$$2$2=require('fast-cidr-tools'),require$$3=require('foxts/retrie'),require$$0$2=require('node:path'),createFile=require('./create-file.loOMbJEN.cjs'),require$$2$1=require('foxts/is-probably-ip'),require$$0$1=require('picocolors'),normalizeDomain=require('./normalize-domain.Cfz4j8eP.cjs');var description = {};var hasRequiredDescription; + +function requireDescription () { + if (hasRequiredDescription) return description; + hasRequiredDescription = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + SHARED_DESCRIPTION: function() { + return SHARED_DESCRIPTION; + }, + createFileDescription: function() { + return createFileDescription; + } + }); + function createFileDescription(license = 'AGPL 3.0') { + return [ + `License: ${license}`, + 'Homepage: https://ruleset.skk.moe', + 'GitHub: https://github.com/SukkaW/Surge' + ]; + } + const SHARED_DESCRIPTION = createFileDescription('AGPL 3.0'); + } (description)); + return description; +}var base$1 = {};var hasRequiredBase$1; + +function requireBase$1 () { + if (hasRequiredBase$1) return base$1; + hasRequiredBase$1 = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "BaseWriteStrategy", { + enumerable: true, + get: function() { + return BaseWriteStrategy; + } + }); + const _createfile = /*@__PURE__*/ createFile.r(); + class BaseWriteStrategy { + outputDir; + /** + * Sometimes a ruleset will create extra files (e.g. reject-url-regex w/ mitm.sgmodule), + * and doesn't share the same filename and id. This property is used to overwrite the filename. + */ overwriteFilename; + withFilename(filename) { + this.overwriteFilename = filename; + return this; + } + constructor(outputDir){ + this.outputDir = outputDir; + this.overwriteFilename = null; + } + static domainWildCardToRegex = (domain)=>{ + let result = '^'; + for(let i = 0, len = domain.length; i < len; i++){ + switch(domain[i]){ + case '.': + result += String.raw`\.`; + break; + case '*': + result += String.raw`[\w.-]*?`; + break; + case '?': + result += String.raw`[\w.-]`; + break; + default: + result += domain[i]; + } + } + result += '$'; + return result; + }; + output(span, title, description, date, filePath) { + if (!this.result) { + return; + } + return (0, _createfile.compareAndWriteFile)(span, this.withPadding(title, description, date, this.result), filePath); + } + get content() { + return this.result; + } + } + } (base$1)); + return base$1; +}var clash = {};var appendArrayInPlace = {};var hasRequiredAppendArrayInPlace; + +function requireAppendArrayInPlace () { + if (hasRequiredAppendArrayInPlace) return appendArrayInPlace; + hasRequiredAppendArrayInPlace = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + appendArrayInPlace: function() { + return appendArrayInPlace; + }, + appendArrayInPlaceCurried: function() { + return appendArrayInPlaceCurried; + } + }); + const MAX_BLOCK_SIZE = 65535; // max parameter array size for use in Webkit + function appendArrayInPlace(dest, source) { + let offset = 0; + let itemsLeft = source.length; + if (itemsLeft <= MAX_BLOCK_SIZE) { + // eslint-disable-next-line prefer-spread -- performance + dest.push.apply(dest, source); + } else { + while(itemsLeft > 0){ + const pushCount = itemsLeft > MAX_BLOCK_SIZE ? MAX_BLOCK_SIZE : itemsLeft; + const subSource = source.slice(offset, offset + pushCount); + // eslint-disable-next-line prefer-spread -- performance + dest.push.apply(dest, subSource); + itemsLeft -= pushCount; + offset += pushCount; + } + } + return dest; + } + const appendArrayInPlaceCurried = (dest)=>(source)=>appendArrayInPlace(dest, source); + } (appendArrayInPlace)); + return appendArrayInPlace; +}var hasRequiredClash; + +function requireClash () { + if (hasRequiredClash) return clash; + hasRequiredClash = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + ClashClassicRuleSet: function() { + return ClashClassicRuleSet; + }, + ClashDomainSet: function() { + return ClashDomainSet; + }, + ClashIPSet: function() { + return ClashIPSet; + } + }); + const _appendsetelementstoarray = require$$0; + const _base = /*@__PURE__*/ requireBase$1(); + const _noop = require$$2; + const _misc = /*@__PURE__*/ misc.r(); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _appendarrayinplace = /*@__PURE__*/ requireAppendArrayInPlace(); + class ClashDomainSet extends _base.BaseWriteStrategy { + outputDir; + // readonly type = 'domainset'; + fileExtension; + type; + result; + constructor(outputDir = _dir.OUTPUT_CLASH_DIR){ + super(outputDir), this.outputDir = outputDir, this.fileExtension = 'txt', this.type = 'domainset', this.result = [ + 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe' + ], this.withPadding = _misc.withBannerArray, this.writeDomainKeywords = _noop.noop, this.writeDomainWildcards = _noop.noop, this.writeUserAgents = _noop.noop, this.writeProcessNames = _noop.noop, this.writeProcessPaths = _noop.noop, this.writeUrlRegexes = _noop.noop, this.writeIpCidrs = _noop.noop, this.writeIpCidr6s = _noop.noop, this.writeGeoip = _noop.noop, this.writeIpAsns = _noop.noop, this.writeSourceIpCidrs = _noop.noop, this.writeSourcePorts = _noop.noop, this.writeDestinationPorts = _noop.noop, this.writeOtherRules = _noop.noop; + } + withPadding; + writeDomain(domain) { + this.result.push(domain); + } + writeDomainSuffix(domain) { + this.result.push('+.' + domain); + } + writeDomainKeywords; + writeDomainWildcards; + writeUserAgents; + writeProcessNames; + writeProcessPaths; + writeUrlRegexes; + writeIpCidrs; + writeIpCidr6s; + writeGeoip; + writeIpAsns; + writeSourceIpCidrs; + writeSourcePorts; + writeDestinationPorts; + writeOtherRules; + } + class ClashIPSet extends _base.BaseWriteStrategy { + outputDir; + // readonly type = 'domainset'; + fileExtension; + type; + result; + constructor(outputDir = _dir.OUTPUT_CLASH_DIR){ + super(outputDir), this.outputDir = outputDir, this.fileExtension = 'txt', this.type = 'ip', this.result = [], this.withPadding = _misc.withBannerArray, this.writeDomain = (0, _misc.notSupported)('writeDomain'), this.writeDomainSuffix = (0, _misc.notSupported)('writeDomainSuffix'), this.writeDomainKeywords = (0, _misc.notSupported)('writeDomainKeywords'), this.writeDomainWildcards = (0, _misc.notSupported)('writeDomainWildcards'), this.writeUserAgents = (0, _misc.notSupported)('writeUserAgents'), this.writeProcessNames = (0, _misc.notSupported)('writeProcessNames'), this.writeProcessPaths = (0, _misc.notSupported)('writeProcessPaths'), this.writeUrlRegexes = (0, _misc.notSupported)('writeUrlRegexes'), this.writeGeoip = (0, _misc.notSupported)('writeGeoip'), this.writeIpAsns = (0, _misc.notSupported)('writeIpAsns'), this.writeSourceIpCidrs = (0, _misc.notSupported)('writeSourceIpCidrs'), this.writeSourcePorts = (0, _misc.notSupported)('writeSourcePorts'), this.writeDestinationPorts = _noop.noop, this.writeOtherRules = _noop.noop; + } + withPadding; + writeDomain; + writeDomainSuffix; + writeDomainKeywords; + writeDomainWildcards; + writeUserAgents; + writeProcessNames; + writeProcessPaths; + writeUrlRegexes; + writeIpCidrs(ipCidr) { + (0, _appendarrayinplace.appendArrayInPlace)(this.result, ipCidr); + } + writeIpCidr6s(ipCidr6) { + (0, _appendarrayinplace.appendArrayInPlace)(this.result, ipCidr6); + } + writeGeoip; + writeIpAsns; + writeSourceIpCidrs; + writeSourcePorts; + writeDestinationPorts; + writeOtherRules; + } + class ClashClassicRuleSet extends _base.BaseWriteStrategy { + type; + outputDir; + fileExtension; + result; + constructor(type/* | (string & {}) */ , outputDir = _dir.OUTPUT_CLASH_DIR){ + super(outputDir), this.type = type, this.outputDir = outputDir, this.fileExtension = 'txt', this.result = [ + 'DOMAIN,this_ruleset_is_made_by_sukkaw.ruleset.skk.moe' + ], this.withPadding = _misc.withBannerArray, this.writeUserAgents = _noop.noop, this.writeUrlRegexes = _noop.noop, this.writeOtherRules = _noop.noop; + } + withPadding; + writeDomain(domain) { + this.result.push('DOMAIN,' + domain); + } + writeDomainSuffix(domain) { + this.result.push('DOMAIN-SUFFIX,' + domain); + } + writeDomainKeywords(keyword) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, keyword, (i)=>`DOMAIN-KEYWORD,${i}`); + } + writeDomainWildcards(wildcard) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, wildcard, (i)=>`DOMAIN-REGEX,${ClashClassicRuleSet.domainWildCardToRegex(i)}`); + } + writeUserAgents; + writeProcessNames(processName) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processName, (i)=>`PROCESS-NAME,${i}`); + } + writeProcessPaths(processPath) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processPath, (i)=>`PROCESS-PATH,${i}`); + } + writeUrlRegexes; + writeIpCidrs(ipCidr, noResolve) { + for(let i = 0, len = ipCidr.length; i < len; i++){ + this.result.push(`IP-CIDR,${ipCidr[i]}${noResolve ? ',no-resolve' : ''}`); + } + } + writeIpCidr6s(ipCidr6, noResolve) { + for(let i = 0, len = ipCidr6.length; i < len; i++){ + this.result.push(`IP-CIDR6,${ipCidr6[i]}${noResolve ? ',no-resolve' : ''}`); + } + } + writeGeoip(geoip, noResolve) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, geoip, (i)=>`GEOIP,${i}${noResolve ? ',no-resolve' : ''}`); + } + writeIpAsns(asns, noResolve) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, asns, (i)=>`IP-ASN,${i}${noResolve ? ',no-resolve' : ''}`); + } + writeSourceIpCidrs(sourceIpCidr) { + for(let i = 0, len = sourceIpCidr.length; i < len; i++){ + const value = sourceIpCidr[i]; + if (value.includes('/')) { + this.result.push(`SRC-IP-CIDR,${value}`); + continue; + } + const v = (0, _misc.fastIpVersion)(value); + if (v === 4) { + this.result.push(`SRC-IP-CIDR,${value}/32`); + continue; + } + if (v === 6) { + this.result.push(`SRC-IP-CIDR6,${value}/128`); + continue; + } + } + } + writeSourcePorts(port) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`SRC-PORT,${i}`); + } + writeDestinationPorts(port) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`DST-PORT,${i}`); + } + writeOtherRules; + } + } (clash)); + return clash; +}var singbox = {};var hasRequiredSingbox; + +function requireSingbox () { + if (hasRequiredSingbox) return singbox; + hasRequiredSingbox = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "SingboxSource", { + enumerable: true, + get: function() { + return SingboxSource; + } + }); + const _base = /*@__PURE__*/ requireBase$1(); + const _appendarrayinplace = /*@__PURE__*/ requireAppendArrayInPlace(); + const _noop = require$$2; + const _misc = /*@__PURE__*/ misc.r(); + const _jsonstringifyprettycompact = /*#__PURE__*/ _interop_require_default(require$$4); + const _dir = /*@__PURE__*/ fetchRetry.a(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + class SingboxSource extends _base.BaseWriteStrategy { + type; + outputDir; + fileExtension; + static jsonToLines = (json)=>(0, _jsonstringifyprettycompact.default)(json).split('\n'); + singbox; + get result() { + return SingboxSource.jsonToLines({ + version: 2, + rules: [ + this.singbox + ] + }); + } + constructor(/** Since sing-box only have one format that does not reflect type, we need to specify it */ type/* | (string & {}) */ , outputDir = _dir.OUTPUT_SINGBOX_DIR){ + super(outputDir), this.type = type, this.outputDir = outputDir, this.fileExtension = 'json', this.singbox = { + domain: [ + 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe' + ], + domain_suffix: [ + 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe' + ] + }, this.withPadding = _misc.withIdentityContent, this.writeUserAgents = _noop.noop, this.writeUrlRegexes = _noop.noop, this.writeGeoip = _noop.noop, this.writeIpAsns = _noop.noop, this.writeOtherRules = _noop.noop; + } + withPadding; + writeDomain(domain) { + this.singbox.domain.push(domain); + } + writeDomainSuffix(domain) { + this.singbox.domain_suffix.push(domain); + } + writeDomainKeywords(keyword) { + (0, _appendarrayinplace.appendArrayInPlace)(this.singbox.domain_keyword ??= [], Array.from(keyword)); + } + writeDomainWildcards(wildcard) { + (0, _appendarrayinplace.appendArrayInPlace)(this.singbox.domain_regex ??= [], Array.from(wildcard, SingboxSource.domainWildCardToRegex)); + } + writeUserAgents; + writeProcessNames(processName) { + (0, _appendarrayinplace.appendArrayInPlace)(this.singbox.process_name ??= [], Array.from(processName)); + } + writeProcessPaths(processPath) { + (0, _appendarrayinplace.appendArrayInPlace)(this.singbox.process_path ??= [], Array.from(processPath)); + } + writeUrlRegexes; + writeIpCidrs(ipCidr) { + (0, _appendarrayinplace.appendArrayInPlace)(this.singbox.ip_cidr ??= [], ipCidr); + } + writeIpCidr6s(ipCidr6) { + (0, _appendarrayinplace.appendArrayInPlace)(this.singbox.ip_cidr ??= [], ipCidr6); + } + writeGeoip; + writeIpAsns; + writeSourceIpCidrs(sourceIpCidr) { + this.singbox.source_ip_cidr ??= []; + for(let i = 0, len = sourceIpCidr.length; i < len; i++){ + const value = sourceIpCidr[i]; + if (value.includes('/')) { + this.singbox.source_ip_cidr.push(value); + continue; + } + const v = (0, _misc.fastIpVersion)(value); + if (v === 4) { + this.singbox.source_ip_cidr.push(`${value}/32`); + continue; + } + if (v === 6) { + this.singbox.source_ip_cidr.push(`${value}/128`); + continue; + } + } + } + writeSourcePorts(port) { + this.singbox.source_port ??= []; + for (const i of port){ + const tmp = Number(i); + if (!Number.isNaN(tmp)) { + this.singbox.source_port.push(tmp); + } + } + } + writeDestinationPorts(port) { + this.singbox.port ??= []; + for (const i of port){ + const tmp = Number(i); + if (!Number.isNaN(tmp)) { + this.singbox.port.push(tmp); + } + } + } + writeOtherRules; + } + } (singbox)); + return singbox; +}var surge = {};var hasRequiredSurge; + +function requireSurge () { + if (hasRequiredSurge) return surge; + hasRequiredSurge = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + SurgeDomainSet: function() { + return SurgeDomainSet; + }, + SurgeMitmSgmodule: function() { + return SurgeMitmSgmodule; + }, + SurgeRuleSet: function() { + return SurgeRuleSet; + } + }); + const _appendsetelementstoarray = require$$0; + const _base = /*@__PURE__*/ requireBase$1(); + const _appendarrayinplace = /*@__PURE__*/ requireAppendArrayInPlace(); + const _noop = require$$2; + const _isprobablyip = require$$2$1; + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _normalizedomain = /*@__PURE__*/ normalizeDomain.r(); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _misc = /*@__PURE__*/ misc.r(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + class SurgeDomainSet extends _base.BaseWriteStrategy { + // readonly type = 'domainset'; + fileExtension = 'conf'; + type = 'domainset'; + result = [ + 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe' + ]; + constructor(outputDir = _dir.OUTPUT_SURGE_DIR){ + super(outputDir); + } + withPadding = _misc.withBannerArray; + writeDomain(domain) { + this.result.push(domain); + } + writeDomainSuffix(domain) { + this.result.push('.' + domain); + } + writeDomainKeywords = _noop.noop; + writeDomainWildcards = _noop.noop; + writeUserAgents = _noop.noop; + writeProcessNames = _noop.noop; + writeProcessPaths = _noop.noop; + writeUrlRegexes = _noop.noop; + writeIpCidrs = _noop.noop; + writeIpCidr6s = _noop.noop; + writeGeoip = _noop.noop; + writeIpAsns = _noop.noop; + writeSourceIpCidrs = _noop.noop; + writeSourcePorts = _noop.noop; + writeDestinationPorts = _noop.noop; + writeOtherRules = _noop.noop; + } + class SurgeRuleSet extends _base.BaseWriteStrategy { + type; + outputDir; + fileExtension; + result; + constructor(/** Surge RULE-SET can be both ip or non_ip, so this needs to be specified */ type, outputDir = _dir.OUTPUT_SURGE_DIR){ + super(outputDir), this.type = type, this.outputDir = outputDir, this.fileExtension = 'conf', this.result = [ + 'DOMAIN,this_ruleset_is_made_by_sukkaw.ruleset.skk.moe' + ], this.withPadding = _misc.withBannerArray; + } + withPadding; + writeDomain(domain) { + this.result.push('DOMAIN,' + domain); + } + writeDomainSuffix(domain) { + this.result.push('DOMAIN-SUFFIX,' + domain); + } + writeDomainKeywords(keyword) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, keyword, (i)=>`DOMAIN-KEYWORD,${i}`); + } + writeDomainWildcards(wildcard) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, wildcard, (i)=>`DOMAIN-WILDCARD,${i}`); + } + writeUserAgents(userAgent) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, userAgent, (i)=>`USER-AGENT,${i}`); + } + writeProcessNames(processName) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processName, (i)=>`PROCESS-NAME,${i}`); + } + writeProcessPaths(processPath) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processPath, (i)=>`PROCESS-NAME,${i}`); + } + writeUrlRegexes(urlRegex) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, urlRegex, (i)=>`URL-REGEX,${i}`); + } + writeIpCidrs(ipCidr, noResolve) { + for(let i = 0, len = ipCidr.length; i < len; i++){ + this.result.push(`IP-CIDR,${ipCidr[i]}${noResolve ? ',no-resolve' : ''}`); + } + } + writeIpCidr6s(ipCidr6, noResolve) { + for(let i = 0, len = ipCidr6.length; i < len; i++){ + this.result.push(`IP-CIDR6,${ipCidr6[i]}${noResolve ? ',no-resolve' : ''}`); + } + } + writeGeoip(geoip, noResolve) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, geoip, (i)=>`GEOIP,${i}${noResolve ? ',no-resolve' : ''}`); + } + writeIpAsns(asns, noResolve) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, asns, (i)=>`IP-ASN,${i}${noResolve ? ',no-resolve' : ''}`); + } + writeSourceIpCidrs(sourceIpCidr) { + for(let i = 0, len = sourceIpCidr.length; i < len; i++){ + this.result.push(`SRC-IP,${sourceIpCidr[i]}`); + } + } + writeSourcePorts(port) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`SRC-PORT,${i}`); + } + writeDestinationPorts(port) { + (0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`DEST-PORT,${i}`); + } + writeOtherRules(rule) { + (0, _appendarrayinplace.appendArrayInPlace)(this.result, rule); + } + } + class SurgeMitmSgmodule extends _base.BaseWriteStrategy { + // readonly type = 'domainset'; + fileExtension = 'sgmodule'; + type = ''; + rules = new Set(); + get result() { + if (this.rules.size === 0) { + return null; + } + return [ + '#!name=[Sukka] Surge Reject MITM', + `#!desc=为 URL Regex 规则组启用 MITM (size: ${this.rules.size})`, + '', + '[MITM]', + 'hostname = %APPEND% ' + Array.from(this.rules).join(', ') + ]; + } + withPadding = _misc.withIdentityContent; + constructor(moduleName, outputDir = _dir.OUTPUT_MODULES_DIR){ + super(outputDir); + this.withFilename(moduleName); + } + writeDomain = _noop.noop; + writeDomainSuffix = _noop.noop; + writeDomainKeywords = _noop.noop; + writeDomainWildcards = _noop.noop; + writeUserAgents = _noop.noop; + writeProcessNames = _noop.noop; + writeProcessPaths = _noop.noop; + writeUrlRegexes(urlRegexes) { + const urlRegexResults = []; + const parsedFailures = []; + const parsed = []; + for (let urlRegex of urlRegexes){ + if (urlRegex.startsWith('http://') || urlRegex.startsWith('^http://')) { + continue; + } + if (urlRegex.startsWith('^https?://')) { + urlRegex = urlRegex.slice(10); + } + if (urlRegex.startsWith('^https://')) { + urlRegex = urlRegex.slice(9); + } + const potentialHostname = urlRegex.split('/')[0]// pre process regex + .replaceAll(String.raw`\.`, '.').replaceAll('.+', '*').replaceAll(/([a-z])\?/g, '($1|)')// convert regex to surge hostlist syntax + .replaceAll('([a-z])', '?').replaceAll(String.raw`\d`, '?').replaceAll(/\*+/g, '*'); + let processed = [ + potentialHostname + ]; + const matches = [ + ...potentialHostname.matchAll(/\((?:([^()|]+)\|)+([^()|]*)\)/g) + ]; + if (matches.length > 0) { + const replaceVariant = (combinations, fullMatch, options)=>{ + const newCombinations = []; + combinations.forEach((combination)=>{ + options.forEach((option)=>{ + newCombinations.push(combination.replace(fullMatch, option)); + }); + }); + return newCombinations; + }; + for(let i = 0; i < matches.length; i++){ + const match = matches[i]; + const [_, ...options] = match; + processed = replaceVariant(processed, _, options); + } + } + urlRegexResults.push({ + origin: potentialHostname, + processed + }); + } + for (const i of urlRegexResults){ + for (const processed of i.processed){ + if ((0, _normalizedomain.normalizeDomain)(processed.replaceAll('*', 'a').replaceAll('?', 'b'))) { + parsed.push([ + i.origin, + processed + ]); + } else if (!(0, _isprobablyip.isProbablyIpv4)(processed)) { + parsedFailures.push([ + i.origin, + processed + ]); + } + } + } + if (parsedFailures.length > 0) { + console.error(_picocolors.default.bold('Parsed Failed')); + console.table(parsedFailures); + } + for(let i = 0, len = parsed.length; i < len; i++){ + this.rules.add(parsed[i][1]); + } + } + writeIpCidrs = _noop.noop; + writeIpCidr6s = _noop.noop; + writeGeoip = _noop.noop; + writeIpAsns = _noop.noop; + writeSourceIpCidrs = _noop.noop; + writeSourcePorts = _noop.noop; + writeDestinationPorts = _noop.noop; + writeOtherRules = _noop.noop; + } + } (surge)); + return surge; +}var base = {};var hasRequiredBase; + +function requireBase () { + if (hasRequiredBase) return base; + hasRequiredBase = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "FileOutput", { + enumerable: true, + get: function() { + return FileOutput; + } + }); + const _trie = /*@__PURE__*/ trie.r(); + const _guard = require$$6; + const _fastcidrtools = require$$2$2; + const _retrie = require$$3; + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$2); + const _surge = /*@__PURE__*/ requireSurge(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + class FileOutput { + id; + strategies; + domainTrie; + domainKeywords; + domainWildcard; + userAgent; + processName; + processPath; + urlRegex; + ipcidr; + ipcidrNoResolve; + ipasn; + ipasnNoResolve; + ipcidr6; + ipcidr6NoResolve; + geoip; + groipNoResolve; + sourceIpOrCidr; + sourcePort; + destPort; + otherRules; + pendingPromise; + whitelistDomain; + span; + constructor($span, id){ + this.id = id; + this.strategies = []; + this.domainTrie = new _trie.HostnameSmolTrie(null); + this.domainKeywords = new Set(); + this.domainWildcard = new Set(); + this.userAgent = new Set(); + this.processName = new Set(); + this.processPath = new Set(); + this.urlRegex = new Set(); + this.ipcidr = new Set(); + this.ipcidrNoResolve = new Set(); + this.ipasn = new Set(); + this.ipasnNoResolve = new Set(); + this.ipcidr6 = new Set(); + this.ipcidr6NoResolve = new Set(); + this.geoip = new Set(); + this.groipNoResolve = new Set(); + this.sourceIpOrCidr = new Set(); + this.sourcePort = new Set(); + this.destPort = new Set(); + this.otherRules = []; + this.pendingPromise = null; + this.whitelistDomain = (domain)=>{ + this.domainTrie.whitelist(domain); + return this; + }; + this.title = null; + this.description = null; + this.date = new Date(); + this.strategiesWritten = false; + this.span = $span.traceChild('RuleOutput#' + id); + } + title; + withTitle(title) { + this.title = title; + return this; + } + withStrategies(strategies) { + this.strategies = strategies; + return this; + } + withExtraStrategies(strategy) { + if (strategy) { + this.strategies.push(strategy); + } + } + description; + withDescription(description) { + this.description = description; + return this; + } + date; + withDate(date) { + this.date = date; + return this; + } + addDomain(domain) { + this.domainTrie.add(domain); + return this; + } + bulkAddDomain(domains) { + let d; + for(let i = 0, len = domains.length; i < len; i++){ + d = domains[i]; + if (d !== null) { + this.domainTrie.add(d, false, null, 0); + } + } + return this; + } + addDomainSuffix(domain, lineFromDot = domain[0] === '.') { + this.domainTrie.add(domain, true, lineFromDot ? 1 : 0); + return this; + } + bulkAddDomainSuffix(domains) { + for(let i = 0, len = domains.length; i < len; i++){ + this.addDomainSuffix(domains[i]); + } + return this; + } + addDomainKeyword(keyword) { + this.domainKeywords.add(keyword); + return this; + } + addIPASN(asn) { + this.ipasn.add(asn); + return this; + } + bulkAddIPASN(asns) { + for(let i = 0, len = asns.length; i < len; i++){ + this.ipasn.add(asns[i]); + } + return this; + } + async addFromDomainsetPromise(source) { + for await (const line of source){ + if (line[0] === '.') { + this.addDomainSuffix(line, true); + } else { + this.domainTrie.add(line, false, null, 0); + } + } + } + addFromDomainset(source) { + if (this.pendingPromise) { + if ('then' in source) { + this.pendingPromise = this.pendingPromise.then(()=>source).then((src)=>this.addFromDomainsetPromise(src)); + return this; + } + this.pendingPromise = this.pendingPromise.then(()=>this.addFromDomainsetPromise(source)); + return this; + } + if ('then' in source) { + this.pendingPromise = source.then((src)=>this.addFromDomainsetPromise(src)); + return this; + } + this.pendingPromise = this.addFromDomainsetPromise(source); + return this; + } + async addFromRulesetPromise(source) { + for await (const line of source){ + const splitted = line.split(','); + const type = splitted[0]; + const value = splitted[1]; + const arg = splitted[2]; + switch(type){ + case 'DOMAIN': + this.domainTrie.add(value, false, null, 0); + break; + case 'DOMAIN-SUFFIX': + this.addDomainSuffix(value, false); + break; + case 'DOMAIN-KEYWORD': + this.addDomainKeyword(value); + break; + case 'DOMAIN-WILDCARD': + this.domainWildcard.add(value); + break; + case 'USER-AGENT': + this.userAgent.add(value); + break; + case 'PROCESS-NAME': + if (value.includes('/') || value.includes('\\')) { + this.processPath.add(value); + } else { + this.processName.add(value); + } + break; + case 'URL-REGEX': + { + const [, ...rest] = splitted; + this.urlRegex.add(rest.join(',')); + break; + } + case 'IP-CIDR': + (arg === 'no-resolve' ? this.ipcidrNoResolve : this.ipcidr).add(value); + break; + case 'IP-CIDR6': + (arg === 'no-resolve' ? this.ipcidr6NoResolve : this.ipcidr6).add(value); + break; + case 'IP-ASN': + (arg === 'no-resolve' ? this.ipasnNoResolve : this.ipasn).add(value); + break; + case 'GEOIP': + (arg === 'no-resolve' ? this.groipNoResolve : this.geoip).add(value); + break; + case 'SRC-IP': + this.sourceIpOrCidr.add(value); + break; + case 'SRC-PORT': + this.sourcePort.add(value); + break; + case 'DEST-PORT': + this.destPort.add(value); + break; + default: + this.otherRules.push(line); + break; + } + } + } + addFromRuleset(source) { + if (this.pendingPromise) { + if ('then' in source) { + this.pendingPromise = this.pendingPromise.then(()=>source).then((src)=>this.addFromRulesetPromise(src)); + return this; + } + this.pendingPromise = this.pendingPromise.then(()=>this.addFromRulesetPromise(source)); + return this; + } + if ('then' in source) { + this.pendingPromise = source.then((src)=>this.addFromRulesetPromise(src)); + return this; + } + this.pendingPromise = this.addFromRulesetPromise(source); + return this; + } + static ipToCidr = (ip, version)=>{ + if (ip.includes('/')) return ip; + if (version === 4) { + return ip + '/32'; + } + return ip + '/128'; + }; + bulkAddCIDR4(cidrs) { + for(let i = 0, len = cidrs.length; i < len; i++){ + this.ipcidr.add(FileOutput.ipToCidr(cidrs[i], 4)); + } + return this; + } + bulkAddCIDR4NoResolve(cidrs) { + for(let i = 0, len = cidrs.length; i < len; i++){ + this.ipcidrNoResolve.add(FileOutput.ipToCidr(cidrs[i], 4)); + } + return this; + } + bulkAddCIDR6(cidrs) { + for(let i = 0, len = cidrs.length; i < len; i++){ + this.ipcidr6.add(FileOutput.ipToCidr(cidrs[i], 6)); + } + return this; + } + bulkAddCIDR6NoResolve(cidrs) { + for(let i = 0, len = cidrs.length; i < len; i++){ + this.ipcidr6NoResolve.add(FileOutput.ipToCidr(cidrs[i], 6)); + } + return this; + } + async done() { + await this.pendingPromise; + this.pendingPromise = null; + return this; + } + // private guardPendingPromise() { + // // reverse invariant + // if (this.pendingPromise !== null) { + // console.trace('Pending promise:', this.pendingPromise); + // throw new Error('You should call done() before calling this method'); + // } + // } + // async writeClash(outputDir?: null | string) { + // await this.done(); + // invariant(this.title, 'Missing title'); + // invariant(this.description, 'Missing description'); + // return compareAndWriteFile( + // this.span, + // withBannerArray( + // this.title, + // this.description, + // this.date, + // this.clash() + // ), + // path.join(outputDir ?? OUTPUT_CLASH_DIR, this.type, this.id + '.txt') + // ); + // } + strategiesWritten; + writeToStrategies() { + if (this.pendingPromise) { + throw new Error('You should call done() before calling writeToStrategies()'); + } + if (this.strategiesWritten) { + throw new Error('Strategies already written'); + } + this.strategiesWritten = true; + const kwfilter = (0, _retrie.createRetrieKeywordFilter)(Array.from(this.domainKeywords)); + if (this.strategies.filter((0, _guard.not)(false)).length === 0) { + throw new Error('No strategies to write ' + this.id); + } + this.domainTrie.dumpWithoutDot((domain, includeAllSubdomain)=>{ + if (kwfilter(domain)) { + return; + } + for(let i = 0, len = this.strategies.length; i < len; i++){ + const strategy = this.strategies[i]; + if (strategy) { + if (includeAllSubdomain) { + strategy.writeDomainSuffix(domain); + } else { + strategy.writeDomain(domain); + } + } + } + }, true); + for(let i = 0, len = this.strategies.length; i < len; i++){ + const strategy = this.strategies[i]; + if (!strategy) continue; + if (this.domainKeywords.size) { + strategy.writeDomainKeywords(this.domainKeywords); + } + if (this.domainWildcard.size) { + strategy.writeDomainWildcards(this.domainWildcard); + } + if (this.userAgent.size) { + strategy.writeUserAgents(this.userAgent); + } + if (this.processName.size) { + strategy.writeProcessNames(this.processName); + } + if (this.processPath.size) { + strategy.writeProcessPaths(this.processPath); + } + } + if (this.sourceIpOrCidr.size) { + const sourceIpOrCidr = Array.from(this.sourceIpOrCidr); + for(let i = 0, len = this.strategies.length; i < len; i++){ + const strategy = this.strategies[i]; + if (strategy) { + strategy.writeSourceIpCidrs(sourceIpOrCidr); + } + } + } + for(let i = 0, len = this.strategies.length; i < len; i++){ + const strategy = this.strategies[i]; + if (strategy) { + if (this.sourcePort.size) { + strategy.writeSourcePorts(this.sourcePort); + } + if (this.destPort.size) { + strategy.writeDestinationPorts(this.destPort); + } + if (this.otherRules.length) { + strategy.writeOtherRules(this.otherRules); + } + if (this.urlRegex.size) { + strategy.writeUrlRegexes(this.urlRegex); + } + } + } + let ipcidr = null; + let ipcidrNoResolve = null; + let ipcidr6 = null; + let ipcidr6NoResolve = null; + if (this.ipcidr.size) { + ipcidr = (0, _fastcidrtools.merge)(Array.from(this.ipcidr), true); + } + if (this.ipcidrNoResolve.size) { + ipcidrNoResolve = (0, _fastcidrtools.merge)(Array.from(this.ipcidrNoResolve), true); + } + if (this.ipcidr6.size) { + ipcidr6 = Array.from(this.ipcidr6); + } + if (this.ipcidr6NoResolve.size) { + ipcidr6NoResolve = Array.from(this.ipcidr6NoResolve); + } + for(let i = 0, len = this.strategies.length; i < len; i++){ + const strategy = this.strategies[i]; + if (strategy) { + // no-resolve + if (ipcidrNoResolve?.length) { + strategy.writeIpCidrs(ipcidrNoResolve, true); + } + if (ipcidr6NoResolve?.length) { + strategy.writeIpCidr6s(ipcidr6NoResolve, true); + } + if (this.ipasnNoResolve.size) { + strategy.writeIpAsns(this.ipasnNoResolve, true); + } + if (this.groipNoResolve.size) { + strategy.writeGeoip(this.groipNoResolve, true); + } + // triggers DNS resolution + if (ipcidr?.length) { + strategy.writeIpCidrs(ipcidr, false); + } + if (ipcidr6?.length) { + strategy.writeIpCidr6s(ipcidr6, false); + } + if (this.ipasn.size) { + strategy.writeIpAsns(this.ipasn, false); + } + if (this.geoip.size) { + strategy.writeGeoip(this.geoip, false); + } + } + } + } + write() { + return this.span.traceChildAsync('write all', async (childSpan)=>{ + await this.done(); + childSpan.traceChildSync('write to strategies', this.writeToStrategies.bind(this)); + return childSpan.traceChildAsync('output to disk', (childSpan)=>{ + const promises = []; + (0, _guard.invariant)(this.title, 'Missing title'); + (0, _guard.invariant)(this.description, 'Missing description'); + for(let i = 0, len = this.strategies.length; i < len; i++){ + const strategy = this.strategies[i]; + if (strategy) { + const basename = (strategy.overwriteFilename || this.id) + '.' + strategy.fileExtension; + promises.push(strategy.output(childSpan, this.title, this.description, this.date, _nodepath.default.join(strategy.outputDir, strategy.type ? _nodepath.default.join(strategy.type, basename) : basename))); + } + } + return Promise.all(promises); + }); + }); + } + async compile() { + await this.done(); + this.writeToStrategies(); + return this.strategies.reduce((acc, strategy)=>{ + if (strategy) { + acc.push(strategy.content); + } else { + acc.push(null); + } + return acc; + }, []); + } + withMitmSgmodulePath(moduleName) { + if (moduleName) { + this.withExtraStrategies(new _surge.SurgeMitmSgmodule(moduleName)); + } + return this; + } + } + } (base)); + return base; +}exports.a=requireAppendArrayInPlace;exports.b=requireBase;exports.c=requireClash;exports.d=requireBase$1;exports.e=requireSurge;exports.f=requireSingbox;exports.r=requireDescription; \ No newline at end of file diff --git a/Dist/chunks/build-apple-cdn.CNsnkTO_.cjs b/Dist/chunks/build-apple-cdn.CNsnkTO_.cjs new file mode 100644 index 00000000..89616d06 --- /dev/null +++ b/Dist/chunks/build-apple-cdn.CNsnkTO_.cjs @@ -0,0 +1,45 @@ +'use strict';const parseDnsmasq=require('./parse-dnsmasq.CiH7YJVY.cjs'),index=require('./index.B8Uk9n3v.cjs'),base=require('./base.C13YY5P3.cjs'),memoPromise=require('./memo-promise.BbOsVeGo.cjs'),domainset=require('./domainset.CSQfKAtf.cjs'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs');var buildAppleCdn = {exports: {}};var hasRequiredBuildAppleCdn; + +function requireBuildAppleCdn () { + if (hasRequiredBuildAppleCdn) return buildAppleCdn.exports; + hasRequiredBuildAppleCdn = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + buildAppleCdn: function() { + return buildAppleCdn; + }, + getAppleCdnDomainsPromise: function() { + return getAppleCdnDomainsPromise; + } + }); + const _parsednsmasq = /*@__PURE__*/ parseDnsmasq.r(); + const _trace = /*@__PURE__*/ index.r(); + const _description = /*@__PURE__*/ base.r(); + const _memopromise = /*@__PURE__*/ memoPromise.r(); + const _domainset = /*@__PURE__*/ domainset.r(); + const _fetchretry = /*@__PURE__*/ fetchRetry.r(); + const getAppleCdnDomainsPromise = (0, _memopromise.createMemoizedPromise)(()=>(0, _fetchretry.$$fetch)('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf').then(_parsednsmasq.parseFelixDnsmasqFromResp)); + console.log({ module, main: require.main }); + const buildAppleCdn = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const res = await span.traceChildPromise('get apple cdn domains', getAppleCdnDomainsPromise()); + return new _domainset.DomainsetOutput(span, 'apple_cdn').withTitle('Sukka\'s Ruleset - Apple CDN').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains Apple\'s domains using their China mainland CDN servers.', + '', + 'Data from:', + ' - https://github.com/felixonmars/dnsmasq-china-list' + ]).bulkAddDomainSuffix(res).write(); + }); + } (buildAppleCdn, buildAppleCdn.exports)); + return buildAppleCdn.exports; +}exports.r=requireBuildAppleCdn; diff --git a/Dist/chunks/build-cdn-download-conf.Dj0KZ2lm.cjs b/Dist/chunks/build-cdn-download-conf.Dj0KZ2lm.cjs new file mode 100644 index 00000000..e764a334 --- /dev/null +++ b/Dist/chunks/build-cdn-download-conf.Dj0KZ2lm.cjs @@ -0,0 +1,86 @@ +'use strict';const require$$0$1=require('node:path'),fetchTextByLine=require('./fetch-text-by-line.YY5b5610.cjs'),trie=require('./trie.Vu1FNyv-.cjs'),index=require('./index.B8Uk9n3v.cjs'),base=require('./base.C13YY5P3.cjs'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),domainset=require('./domainset.CSQfKAtf.cjs'),rejectDataSource=require('./reject-data-source.DaKwvNlG.cjs'),require$$0=require('foxts/append-set-elements-to-array');var buildCdnDownloadConf = {exports: {}};var hasRequiredBuildCdnDownloadConf; + +function requireBuildCdnDownloadConf () { + if (hasRequiredBuildCdnDownloadConf) return buildCdnDownloadConf.exports; + hasRequiredBuildCdnDownloadConf = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildCdnDownloadConf", { + enumerable: true, + get: function() { + return buildCdnDownloadConf; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _trie = /*@__PURE__*/ trie.r(); + const _trace = /*@__PURE__*/ index.r(); + const _description = /*@__PURE__*/ base.r(); + const _appendarrayinplace = /*@__PURE__*/ base.a(); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _domainset = /*@__PURE__*/ domainset.r(); + const _rejectdatasource = /*@__PURE__*/ rejectDataSource.r(); + const _appendsetelementstoarray = require$$0; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const getS3OSSDomainsPromise = (async ()=>{ + const trie = new _trie.HostnameTrie(); + for await (const line of (await (0, _fetchtextbyline.fetchRemoteTextByLine)('https://publicsuffix.org/list/public_suffix_list.dat', true))){ + trie.add(line); + } + /** + * Extract OSS domain from publicsuffix list + */ const S3OSSDomains = new Set(); + trie.find('.amazonaws.com').forEach((line)=>{ + if ((line.startsWith('s3-') || line.startsWith('s3.')) && !line.includes('cn-')) { + S3OSSDomains.add('.' + line); + } + }); + trie.find('.scw.cloud').forEach((line)=>{ + if ((line.startsWith('s3-') || line.startsWith('s3.')) && !line.includes('cn-')) { + S3OSSDomains.add('.' + line); + } + }); + trie.find('sakurastorage.jp').forEach((line)=>{ + if (line.startsWith('s3-') || line.startsWith('s3.')) { + S3OSSDomains.add('.' + line); + } + }); + return S3OSSDomains; + })(); + const cdnDomainsListPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/cdn.conf')); + const downloadDomainSetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/download.conf')); + const steamDomainSetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/game-download.conf')); + const buildCdnDownloadConf = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const [S3OSSDomains, cdnDomainsList, downloadDomainSet, steamDomainSet] = await Promise.all([ + getS3OSSDomainsPromise, + cdnDomainsListPromise, + downloadDomainSetPromise, + steamDomainSetPromise + ]); + // Move S3 domains to download domain set, since S3 files may be large + (0, _appendsetelementstoarray.appendSetElementsToArray)(downloadDomainSet, S3OSSDomains); + (0, _appendarrayinplace.appendArrayInPlace)(downloadDomainSet, steamDomainSet); + // we have whitelisted the crashlytics domain, and we also want to put it in CDN policy + (0, _appendarrayinplace.appendArrayInPlace)(cdnDomainsList, _rejectdatasource.CRASHLYTICS_WHITELIST); + return Promise.all([ + new _domainset.DomainsetOutput(span, 'cdn').withTitle('Sukka\'s Ruleset - CDN Domains').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains object storage and static assets CDN domains.' + ]).addFromDomainset(cdnDomainsList).write(), + new _domainset.DomainsetOutput(span, 'download').withTitle('Sukka\'s Ruleset - Large Files Hosting Domains').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains domains for software updating & large file hosting.' + ]).addFromDomainset(downloadDomainSet).write() + ]); + }); + } (buildCdnDownloadConf, buildCdnDownloadConf.exports)); + return buildCdnDownloadConf.exports; +}exports.r=requireBuildCdnDownloadConf; \ No newline at end of file diff --git a/Dist/chunks/build-chn-cidr.BjyqKcvm.cjs b/Dist/chunks/build-chn-cidr.BjyqKcvm.cjs new file mode 100644 index 00000000..4e77c87b --- /dev/null +++ b/Dist/chunks/build-chn-cidr.BjyqKcvm.cjs @@ -0,0 +1,201 @@ +'use strict';const fetchTextByLine=require('./fetch-text-by-line.YY5b5610.cjs'),index=require('./index.B8Uk9n3v.cjs'),require$$2=require('fast-cidr-tools'),memoPromise=require('./memo-promise.BbOsVeGo.cjs'),base=require('./base.C13YY5P3.cjs'),fsMemo=require('./fs-memo.Dw823m02.cjs');var buildChnCidr = {exports: {}};var cidr = {};var hasRequiredCidr; + +function requireCidr () { + if (hasRequiredCidr) return cidr; + hasRequiredCidr = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + CN_CIDR_MISSING_IN_CHNROUTE: function() { + return CN_CIDR_MISSING_IN_CHNROUTE; + }, + NON_CN_CIDR_INCLUDED_IN_CHNROUTE: function() { + return NON_CN_CIDR_INCLUDED_IN_CHNROUTE; + }, + RESERVED_IPV4_CIDR: function() { + return RESERVED_IPV4_CIDR; + } + }); + const RESERVED_IPV4_CIDR = [ + '0.0.0.0/8', + '10.0.0.0/8', + '100.64.0.0/10', + '127.0.0.0/8', + '169.254.0.0/16', + '172.16.0.0/12', + '192.0.0.0/24', + '192.0.2.0/24', + // 192.88.99.0 // is currently being broadcast by HE and Comcast + '192.168.0.0/16', + '198.18.0.0/15', + '198.51.100.0/24', + '203.0.113.0/24', + '224.0.0.0/4', + '233.252.0.0/24', + '240.0.0.0/4' + ]; + const NON_CN_CIDR_INCLUDED_IN_CHNROUTE = [ + '223.118.0.0/15', + '223.120.0.0/15' + ]; + const CN_CIDR_MISSING_IN_CHNROUTE = [ + // Baidu Public DNS + '180.76.76.0/24', + // Ali Public DNS + '223.5.5.0/24', + '223.6.6.0/24', + // Tencent DNSPod Public DNS + '119.29.29.0/24', + '119.28.28.0/24', + '120.53.53.0/24', + '1.12.12.0/24', + '1.12.34.0/24', + // ByteDance Public DNS + '180.184.1.0/24', + '180.184.2.0/24', + // 360 Public DNS + '101.198.198.0/24', + '101.198.199.0/24', + // ChinaTelecom + '103.7.141.0/24', + // Aliyun Shenzhen + '120.78.0.0/16', + // wy.com.cn + '211.99.96.0/19', + // AS58593, Azure China + '40.72.0.0/15', + '42.159.0.0/16', + '52.130.0.0/17', + '52.131.0.0/16', + '103.9.8.0/22', + '139.217.0.0/16', + '139.219.0.0/16', + '143.64.0.0/16', + '159.27.0.0/16', + '163.228.0.0/16', + // NetEase + '223.252.194.0/24', + '223.252.196.0/24', + // Xiamen Kuaikuai + '180.188.36.0/22' // no route globally + ]; + } (cidr)); + return cidr; +}var ip = {};var hasRequiredIp; + +function requireIp () { + if (hasRequiredIp) return ip; + hasRequiredIp = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "IPListOutput", { + enumerable: true, + get: function() { + return IPListOutput; + } + }); + const _clash = /*@__PURE__*/ base.c(); + const _singbox = /*@__PURE__*/ base.f(); + const _surge = /*@__PURE__*/ base.e(); + const _base = /*@__PURE__*/ base.b(); + class IPListOutput extends _base.FileOutput { + clashUseRule; + strategies; + constructor(span, id, clashUseRule = true){ + super(span, id), this.clashUseRule = clashUseRule; + this.strategies = [ + new _surge.SurgeRuleSet('ip'), + this.clashUseRule ? new _clash.ClashClassicRuleSet('ip') : new _clash.ClashIPSet(), + new _singbox.SingboxSource('ip') + ]; + } + } + } (ip)); + return ip; +}var hasRequiredBuildChnCidr; + +function requireBuildChnCidr () { + if (hasRequiredBuildChnCidr) return buildChnCidr.exports; + hasRequiredBuildChnCidr = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + buildChnCidr: function() { + return buildChnCidr; + }, + getChnCidrPromise: function() { + return getChnCidrPromise; + } + }); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _trace = /*@__PURE__*/ index.r(); + const _fastcidrtools = require$$2; + const _memopromise = /*@__PURE__*/ memoPromise.r(); + const _cidr = /*@__PURE__*/ requireCidr(); + const _appendarrayinplace = /*@__PURE__*/ base.a(); + const _ip = /*@__PURE__*/ requireIp(); + const _fsmemo = /*@__PURE__*/ fsMemo.r(); + const _description = /*@__PURE__*/ base.r(); + const PROBE_CHN_CIDR_V4 = [ + // NetEase Hangzhou + '223.252.196.38', + // Aliyun ShenZhen + '120.78.92.171' + ]; + const getChnCidrPromise = (0, _memopromise.createMemoizedPromise)((0, _fsmemo.cachedOnlyFail)(async function getChnCidr() { + const [_cidr4, cidr6] = await Promise.all([ + (0, _fetchtextbyline.fetchRemoteTextByLine)('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt', true).then(Array.fromAsync), + (0, _fetchtextbyline.fetchRemoteTextByLine)('https://gaoyifan.github.io/china-operator-ip/china6.txt', true).then(Array.fromAsync) + ]); + const cidr4 = (0, _fastcidrtools.exclude)((0, _appendarrayinplace.appendArrayInPlace)(_cidr4, _cidr.CN_CIDR_MISSING_IN_CHNROUTE), _cidr.NON_CN_CIDR_INCLUDED_IN_CHNROUTE, true); + for (const probeIp of PROBE_CHN_CIDR_V4){ + if (!(0, _fastcidrtools.contains)(cidr4, PROBE_CHN_CIDR_V4)) { + const err = new TypeError('chnroutes missing probe IP'); + err.cause = probeIp; + throw err; + } + } + return [ + cidr4, + cidr6 + ]; + }, { + serializer: JSON.stringify, + deserializer: JSON.parse + })); + const buildChnCidr = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const [filteredCidr4, cidr6] = await span.traceChildAsync('download chnroutes2', getChnCidrPromise); + // Can not use SHARED_DESCRIPTION here as different license + const description = (0, _description.createFileDescription)('CC BY-SA 2.0'); + return Promise.all([ + new _ip.IPListOutput(span, 'china_ip', false).withTitle('Sukka\'s Ruleset - Mainland China IPv4 CIDR').withDescription([ + ...description, + 'Data from https://misaka.io (misakaio @ GitHub)' + ]).bulkAddCIDR4(filteredCidr4).write(), + new _ip.IPListOutput(span, 'china_ip_ipv6', false).withTitle('Sukka\'s Ruleset - Mainland China IPv6 CIDR').withDescription([ + ...description, + 'Data from https://github.com/gaoyifan/china-operator-ip' + ]).bulkAddCIDR6(cidr6).write() + ]); + }); + } (buildChnCidr, buildChnCidr.exports)); + return buildChnCidr.exports; +}exports.r=requireBuildChnCidr; \ No newline at end of file diff --git a/Dist/chunks/build-cloudmounter-rules.RMp-w3JV.cjs b/Dist/chunks/build-cloudmounter-rules.RMp-w3JV.cjs new file mode 100644 index 00000000..9e8909ff --- /dev/null +++ b/Dist/chunks/build-cloudmounter-rules.RMp-w3JV.cjs @@ -0,0 +1,74 @@ +'use strict';const base=require('./base.C13YY5P3.cjs'),index=require('./index.B8Uk9n3v.cjs'),ruleset=require('./ruleset.iYH0XOC1.cjs');var buildCloudmounterRules = {exports: {}};var cloudmounter = {};var hasRequiredCloudmounter; + +function requireCloudmounter () { + if (hasRequiredCloudmounter) return cloudmounter; + hasRequiredCloudmounter = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + DOMAINS: function() { + return DOMAINS; + }, + PROCESS_NAMES: function() { + return PROCESS_NAMES; + } + }); + const DOMAINS = [ + 'DOMAIN-SUFFIX,sharepoint.com', + 'DOMAIN-SUFFIX,graph.microsoft.com', + 'DOMAIN,www.googleapis.com', + 'DOMAIN,api.onedrive.com', + 'DOMAIN-SUFFIX,storage.live.com', + 'DOMAIN-SUFFIX,files.1drv.com', + 'DOMAIN-SUFFIX,my.microsoftpersonalcontent.com', + 'DOMAIN-WILDCARD,*-medi*.svc.ms' + ]; + const PROCESS_NAMES = [ + '*CloudMounter' + ]; + } (cloudmounter)); + return cloudmounter; +}var hasRequiredBuildCloudmounterRules; + +function requireBuildCloudmounterRules () { + if (hasRequiredBuildCloudmounterRules) return buildCloudmounterRules.exports; + hasRequiredBuildCloudmounterRules = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildCloudMounterRules", { + enumerable: true, + get: function() { + return buildCloudMounterRules; + } + }); + const _cloudmounter = /*@__PURE__*/ requireCloudmounter(); + const _description = /*@__PURE__*/ base.r(); + const _trace = /*@__PURE__*/ index.r(); + const _ruleset = /*@__PURE__*/ ruleset.r(); + const buildCloudMounterRules = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + // AND,((SRC-IP,192.168.1.110), (DOMAIN, example.com)) + const results = _cloudmounter.DOMAINS.flatMap((domain)=>_cloudmounter.PROCESS_NAMES.flatMap((process)=>[ + `AND,((${domain}),(PROCESS-NAME,${process}))`, + ...[ + '10.0.0.0/8', + // '127.0.0.0/8', + '172.16.0.0/12', + '192.168.0.0/16' + ].map((cidr)=>`AND,((${domain}),(SRC-IP,${cidr}))`) + ])); + const description = _description.SHARED_DESCRIPTION; + return new _ruleset.RulesetOutput(span, 'cloudmounter', 'non_ip').withTitle('Sukka\'s Ruleset - CloudMounter / RaiDrive').withDescription(description).addFromRuleset(results).write(); + }); + } (buildCloudmounterRules, buildCloudmounterRules.exports)); + return buildCloudmounterRules.exports; +}exports.r=requireBuildCloudmounterRules; \ No newline at end of file diff --git a/Dist/chunks/build-common.DBhs-fKR.cjs b/Dist/chunks/build-common.DBhs-fKR.cjs new file mode 100644 index 00000000..86446814 --- /dev/null +++ b/Dist/chunks/build-common.DBhs-fKR.cjs @@ -0,0 +1,161 @@ +'use strict';const require$$0=require('node:path'),fetchTextByLine=require('./fetch-text-by-line.YY5b5610.cjs'),index=require('./index.B8Uk9n3v.cjs'),base=require('./base.C13YY5P3.cjs'),require$$5=require('fdir'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),domainset=require('./domainset.CSQfKAtf.cjs'),ruleset=require('./ruleset.iYH0XOC1.cjs');var buildCommon = {exports: {}};var hasRequiredBuildCommon; + +function requireBuildCommon () { + if (hasRequiredBuildCommon) return buildCommon.exports; + hasRequiredBuildCommon = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildCommon", { + enumerable: true, + get: function() { + return buildCommon; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_wildcard(require$$0); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _processline = /*@__PURE__*/ fetchTextByLine.r(); + const _trace = /*@__PURE__*/ index.r(); + const _description = /*@__PURE__*/ base.r(); + const _fdir = require$$5; + const _appendarrayinplace = /*@__PURE__*/ base.a(); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _domainset = /*@__PURE__*/ domainset.r(); + const _ruleset = /*@__PURE__*/ ruleset.r(); + function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); + } + function _interop_require_wildcard(obj, nodeInterop) { + if (obj && obj.__esModule) { + return obj; + } + if (obj === null || typeof obj !== "object" && typeof obj !== "function") { + return { + default: obj + }; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = { + __proto__: null + }; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; + } + const MAGIC_COMMAND_SKIP = '# $ custom_build_script'; + const MAGIC_COMMAND_TITLE = '# $ meta_title '; + const MAGIC_COMMAND_DESCRIPTION = '# $ meta_description '; + const MAGIC_COMMAND_SGMODULE_MITM_HOSTNAMES = '# $ sgmodule_mitm_hostnames '; + const clawSourceDirPromise = new _fdir.fdir().withRelativePaths().filter((filepath, isDirectory)=>{ + if (isDirectory) return true; + const extname = _nodepath.extname(filepath); + return !(extname === '.js' || extname === '.ts'); + }).crawl(_dir.SOURCE_DIR).withPromise(); + const buildCommon = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const promises = []; + const paths = await clawSourceDirPromise; + for(let i = 0, len = paths.length; i < len; i++){ + const relativePath = paths[i]; + const fullPath = _dir.SOURCE_DIR + _nodepath.sep + relativePath; + // if ( + // relativePath.startsWith('ip/') + // || relativePath.startsWith('non_ip/') + // ) { + promises.push(transform(span, fullPath, relativePath)); + // continue; + // } + // console.error(picocolors.red(`[build-comman] Unknown file: ${relativePath}`)); + } + return Promise.all(promises); + }); + const $skip = Symbol('skip'); + function processFile(span, sourcePath) { + return span.traceChildAsync(`process file: ${sourcePath}`, async ()=>{ + const lines = []; + let title = ''; + const descriptions = []; + let sgmodulePathname = null; + try { + for await (const line of (0, _fetchtextbyline.readFileByLine)(sourcePath)){ + if (line.startsWith(MAGIC_COMMAND_SKIP)) { + return $skip; + } + if (line.startsWith(MAGIC_COMMAND_TITLE)) { + title = line.slice(MAGIC_COMMAND_TITLE.length).trim(); + continue; + } + if (line.startsWith(MAGIC_COMMAND_DESCRIPTION)) { + descriptions.push(line.slice(MAGIC_COMMAND_DESCRIPTION.length).trim()); + continue; + } + if (line.startsWith(MAGIC_COMMAND_SGMODULE_MITM_HOSTNAMES)) { + sgmodulePathname = line.slice(MAGIC_COMMAND_SGMODULE_MITM_HOSTNAMES.length).trim(); + continue; + } + const l = (0, _processline.processLine)(line); + if (l) { + lines.push(l); + } + } + } catch (e) { + console.error('Error processing', sourcePath); + console.trace(e); + } + return [ + title, + descriptions, + lines, + sgmodulePathname + ]; + }); + } + async function transform(parentSpan, sourcePath, relativePath) { + const extname = _nodepath.extname(sourcePath); + const id = _nodepath.basename(sourcePath, extname); + return parentSpan.traceChild(`transform ruleset: ${id}`).traceAsyncFn(async (span)=>{ + const type = relativePath.split(_nodepath.sep)[0]; + if (type !== 'ip' && type !== 'non_ip' && type !== 'domainset') { + throw new TypeError(`Invalid type: ${type}`); + } + const res = await processFile(span, sourcePath); + if (res === $skip) return; + const [title, descriptions, lines, sgmoduleName] = res; + let finalDescriptions; + if (descriptions.length) { + finalDescriptions = _description.SHARED_DESCRIPTION.slice(); + finalDescriptions.push(''); + (0, _appendarrayinplace.appendArrayInPlace)(finalDescriptions, descriptions); + } else { + finalDescriptions = _description.SHARED_DESCRIPTION; + } + if (type === 'domainset') { + return new _domainset.DomainsetOutput(span, id).withTitle(title).withDescription(finalDescriptions).addFromDomainset(lines).write(); + } + return new _ruleset.RulesetOutput(span, id, type).withTitle(title).withDescription(finalDescriptions).withMitmSgmodulePath(sgmoduleName).addFromRuleset(lines).write(); + }); + } + } (buildCommon, buildCommon.exports)); + return buildCommon.exports; +}exports.r=requireBuildCommon; \ No newline at end of file diff --git a/Dist/chunks/build-deprecate-files.BeL0QUfk.cjs b/Dist/chunks/build-deprecate-files.BeL0QUfk.cjs new file mode 100644 index 00000000..b0682b3e --- /dev/null +++ b/Dist/chunks/build-deprecate-files.BeL0QUfk.cjs @@ -0,0 +1,67 @@ +'use strict';const fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),createFile=require('./create-file.loOMbJEN.cjs'),index=require('./index.B8Uk9n3v.cjs'),require$$0=require('node:path'),require$$2=require('node:fs/promises');var buildDeprecateFiles = {exports: {}};var hasRequiredBuildDeprecateFiles; + +function requireBuildDeprecateFiles () { + if (hasRequiredBuildDeprecateFiles) return buildDeprecateFiles.exports; + hasRequiredBuildDeprecateFiles = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildDeprecateFiles", { + enumerable: true, + get: function() { + return buildDeprecateFiles; + } + }); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _createfile = /*@__PURE__*/ createFile.r(); + const _trace = /*@__PURE__*/ index.r(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _promises = /*#__PURE__*/ _interop_require_default(require$$2); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const DEPRECATED_FILES = [ + [ + 'non_ip/global_plus', + 'This file has been merged with non_ip/global' + ], + [ + 'domainset/reject_sukka', + 'This file has been merged with domainset/reject' + ], + [ + 'domainset/reject_phishing', + 'This file has been merged with domainset/reject' + ] + ]; + const REMOVED_FILES = [ + 'Internal/cdn.txt', + 'List/internal/appprofile.php', + 'Clash/domainset/steam.txt', + 'Clash/non_ip/clash_fake_ip_filter.txt', + 'sing-box/domainset/steam.json', + 'Modules/sukka_unlock_abema.sgmodule', + 'Modules/sukka_exclude_reservered_ip.sgmodule' + ]; + const buildDeprecateFiles = (0, _trace.task)(require.main === module, __filename)((span)=>span.traceChildAsync('create deprecated files', async (childSpan)=>{ + const promises = REMOVED_FILES.map((f)=>_promises.default.rm(_nodepath.default.join(_dir.PUBLIC_DIR, f), { + force: true, + recursive: true + })); + for (const [filePath, description] of DEPRECATED_FILES){ + const content = [ + '#########################################', + '# Sukka\'s Ruleset - Deprecated', + `# ${description}`, + '################## EOF ##################' + ]; + promises.push((0, _createfile.compareAndWriteFile)(childSpan, content, _nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, `${filePath}.conf`)), (0, _createfile.compareAndWriteFile)(childSpan, content, _nodepath.default.resolve(_dir.OUTPUT_CLASH_DIR, `${filePath}.txt`))); + } + return Promise.all(promises); + })); + } (buildDeprecateFiles, buildDeprecateFiles.exports)); + return buildDeprecateFiles.exports; +}exports.r=requireBuildDeprecateFiles; \ No newline at end of file diff --git a/Dist/chunks/build-domestic-direct-lan-ruleset-dns-mapping-module.T1tgVza_.cjs b/Dist/chunks/build-domestic-direct-lan-ruleset-dns-mapping-module.T1tgVza_.cjs new file mode 100644 index 00000000..a252181a --- /dev/null +++ b/Dist/chunks/build-domestic-direct-lan-ruleset-dns-mapping-module.T1tgVza_.cjs @@ -0,0 +1,887 @@ +'use strict';const require$$0=require('node:path'),fetchTextByLine=require('./fetch-text-by-line.YY5b5610.cjs'),createFile=require('./create-file.loOMbJEN.cjs'),index=require('./index.B8Uk9n3v.cjs'),base=require('./base.C13YY5P3.cjs'),memoPromise=require('./memo-promise.BbOsVeGo.cjs'),require$$8=require('yaml'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),ruleset=require('./ruleset.iYH0XOC1.cjs');var buildDomesticDirectLanRulesetDnsMappingModule = {exports: {}};var domestic = {};var hasRequiredDomestic; + +function requireDomestic () { + if (hasRequiredDomestic) return domestic; + hasRequiredDomestic = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + AdGuardHomeDNSMapping: function() { + return AdGuardHomeDNSMapping; + }, + DOH_BOOTSTRAP: function() { + return DOH_BOOTSTRAP; + }, + DOMESTICS: function() { + return DOMESTICS; + } + }); + const DOMESTICS = { + ALIBABA: { + hosts: {}, + dns: 'quic://dns.alidns.com:853', + realip: false, + ruleset: true, + domains: [ + 'uc.cn', + // 'ucweb.com', // UC International + 'alibaba.com', + '+alicdn.com', + '+ialicdn.com', + '+myalicdn.com', + '+alidns.com', + '+aliimg.com', + 'aliyun.com', + '+aliyuncs.com', + '+alikunlun.com', + '+alikunlun.net', + '+cdngslb.com', + 'alipay.com', + 'alipay.cn', + 'alipay.com.cn', + '+alipayobjects.com', + 'alibaba-inc.com', + '+alibabausercontent.com', + '+alibabadns.com', + 'alibabachengdun.com', + 'alicloudccp.com', + 'alipan.com', + 'aliyundrive.com', + 'aliyundrive.net', + 'cainiao.com', + 'cainiao.com.cn', + 'cainiaoyizhan.com', + 'guoguo-app.com', + 'etao.com', + 'yitao.com', + '1688.com', + 'amap.com', + 'gaode.com', + 'autonavi.com', + 'dingtalk.com', + 'mxhichina.com', + 'soku.com', + 'tb.cn', + 'taobao.com', + '+taobaocdn.com', + '+tbcache.com', + 'tmall.com', + // 'tmall.hk', + 'goofish.com', + 'xiami.com', + 'xiami.net', + '+ykimg.com', + 'youku.com', + 'tudou.com', + '+cibntv.net', + 'ele.me', + '+elemecdn.com', + 'feizhu.com', + 'taopiaopiao.com', + 'fliggy.com', + 'koubei.com', + 'mybank.cn', + 'mmstat.com', + 'uczzd.cn', + 'iconfont.cn', + 'freshhema.com', + 'hemamax.com', + 'hemaos.com', + 'hemashare.cn', + 'shyhhema.com', + 'sm.cn', + 'npmmirror.com', + 'alios.cn', + 'wandoujia.com', + 'aligames.com', + '25pp.com', + '+aliapp.org', + 'tanx.com', + 'hellobike.com', + '+hichina.com', + '+yunos.com', + // Bilibili Aliyun CDN + '$upos-sz-mirrorali.bilivideo.com', + '$upos-sz-estgoss.bilivideo.com' + ] + }, + TENCENT: { + hosts: {}, + dns: 'https://doh.pub/dns-query', + realip: false, + ruleset: true, + domains: [ + // 'dns.pub', + // 'doh.pub', + // 'dot.pub', + '+qcloud.com', + '+gtimg.cn', + '+gtimg.com', + '+gtimg.com.cn', + '+gdtimg.com', + '+idqqimg.com', + '+udqqimg.com', + '+igamecj.com', + 'myapp.com', + '+myqcloud.com', + 'dnspod.com', + '+qpic.cn', + '+qlogo.cn', + 'qq.com', + 'qq.com.cn', + // 'qq.wang', + // 'qqmail.cn', // not owned by QQ, is sold on hichina.com + '+qqmail.com', + 'qzone.com', + '+tencent-cloud.net', + '+tencent-cloud.com', + 'tencent.com', + 'tencent.com.cn', + 'tencentmusic.com', + 'weixinbridge.com', + 'weixin.com', + // 'wechat.com', exclude `sgshort.wechat.com` + 'weiyun.com', + 'soso.com', + 'sogo.com', + 'sogou.com', + '+sogoucdn.com', + '+roblox.cn', + 'robloxdev.cn', + 'wegame.com', + 'wegame.com.cn', + 'wegameplus.com', + 'cdn-go.cn', + '+tencentcs.cn', + '+qcloudimg.com', + 'dnspod.cn', + 'anticheatexpert.com', + '$url.cn', + '+qlivecdn.com', + '+tcdnlive.com', + '+dnsv1.com', + '+smtcdns.net', + 'coding.net', + '+codehub.cn' + ] + }, + BILIBILI: { + dns: 'https://doh.pub/dns-query', + hosts: {}, + realip: false, + ruleset: true, + domains: [ + // '$upos-sz-mirrorcoso1.bilivideo.com', // already included in bilivideo.com + // '$upos-sz-estgcos.bilivideo.com', // already included in bilivideo.com, tencent cloud cdn + '$acg.tv', + '$b23.tv', + 'bilibili.cn', + 'bilibili.com', + // 'bilibili.tv', + '+acgvideo.com', + '+bilivideo.com', + '+bilivideo.cn', + '+bilivideo.net', + '+hdslb.com', + '+biliimg.com', + '+biliapi.com', + '+biliapi.net', + // 'biligame.cn', // not owned by bilibili, was put on sale by ename + 'biligame.com', + '+biligame.net', + 'bilicomic.com', + 'bilicomics.com', + // 'bilibilipay.cn', // not owned by bilibili + // 'bilibilipay.com', // not owned by bilibili + '+bilicdn1.com' + ] + }, + XIAOMI: { + dns: 'https://doh.pub/dns-query', + hosts: {}, + realip: false, + ruleset: true, + domains: [ + 'mi.com', + 'duokan.com', + '+mi-img.com', + '+mi-idc.com', + '+xiaoaisound.com', + '+xiaomixiaoai.com', + '+mi-fds.com', + '+mifile.cn', + '+mijia.tech', + 'miui.com', + 'xiaomi.com', + 'xiaomi.cn', + 'xiaomi.net', + 'xiaomiev.com', + 'xiaomiyoupin.com' + ] + }, + BYTEDANCE: { + dns: '180.184.2.2', + hosts: {}, + realip: false, + ruleset: true, + domains: [ + 'bytedance.com', + '+bytecdn.cn', + '+volccdn.com', + '+toutiaoimg.com', + '+toutiaoimg.cn', + '+toutiaostatic.com', + '+toutiaovod.com', + '+toutiaocloud.com', + 'toutiaopage.com', + 'feiliao.com', + 'iesdouyin.com', + '+pstatp.com', + 'snssdk.com', + '+bytegoofy.com', + 'toutiao.com', + 'feishu.cn', + 'feishu.net', + '+feishucdn.com', + '+feishupkg.com', + 'douyin.com', + '+douyinpic.com', + '+douyinstatic.com', + '+douyincdn.com', + '+douyinliving.com', + '+douyinvod.com', + 'huoshan.com', + '+huoshanstatic.com', + 'huoshanzhibo.com', + 'ixigua.com', + '+ixiguavideo.com', + '+ixgvideo.com', + '+volccdn.com', + '+byted-static.com', + 'volces.com', + 'baike.com', + '+zjcdn.com', + '+zijieapi.com', + 'feelgood.cn', + '+bytetcc.com', + '+bytednsdoc.com', + '+byteimg.com', + '+byteacctimg.com', + '+ibytedapm.com', + 'oceanengine.com', + '+edge-byted.com', + '+volcvideo.com' + ] + }, + BAIDU: { + dns: '180.76.76.76', + hosts: {}, + realip: false, + ruleset: true, + domains: [ + '91.com', + 'hao123.com', + 'baidu.cn', + 'baidu.com', + 'iqiyi.com', + '+iqiyipic.com', + '+baidubce.com', + '+bcelive.com', + '+baiducontent.com', + '+baidustatic.com', + '+bdstatic.com', + '+bdimg.com', + '+bcebos.com', + '+baidupcs.com', + '+baidubcr.com', + '+yunjiasu-cdn.net', + 'tieba.com', + 'xiaodutv.com', + '+shifen.com', + '+jomodns.com', + '+bdydns.com', + '+jomoxc.com', + '+duapp.com', + '+antpcdn.com', + // Bilibili Baidu CDN + '$upos-sz-mirrorbd.bilivideo.com', + '$upos-sz-mirrorbos.bilivideo.com' + ] + }, + QIHOO360: { + hosts: {}, + dns: 'https://doh.360.cn/dns-query', + realip: false, + ruleset: true, + domains: [ + '+qhimg.com', + '+qhimgs.com', + '+qhimgs?.com', + // '+qhimgs0.com', + // '+qhimgs1.com', + // '+qhimgs2.com', + // '+qhimgs3.com', + // '+qhimgs4.com', + // '+qhimgs5.com', + // '+qhimgs6.com', + '+qhres.com', + '+qhres2.com', + '+qhmsg.com', + '+qhstatic.com', + '+qhupdate.com', + '+qihucdn.com', + '360.com', + '360.cn', + '360.net', + '360safe.com', + '+360tpcdn.com', + '360os.com', + '+360webcache.com', + '360kuai.com', + 'so.com', + 'haosou.com', + 'yunpan.cn', + 'yunpan.com', + 'yunpan.com.cn', + '+qh-cdn.com', + 'baomitu.com', + 'qiku.com' + ] + } + }; + const DOH_BOOTSTRAP = { + ALIBABA: { + hosts: { + 'dns.alidns.com': [ + '223.5.5.5', + '223.6.6.6', + '2400:3200:baba::1', + '2400:3200::1' + ] + }, + realip: false, + ruleset: false, + dns: 'quic://223.5.5.5:853', + domains: [ + '$dns.alidns.com' + ] + }, + DNSPOD: { + hosts: { + // 'dot.pub': ['120.53.53.53', '1.12.12.12'], + 'doh.pub': [ + '120.53.53.53', + '1.12.12.12' + ] + }, + realip: false, + ruleset: false, + dns: 'https://1.12.12.12/dns-query', + domains: [ + // '$dot.pub', + '$doh.pub' + ] + }, + QIHOO360: { + hosts: { + }, + realip: false, + ruleset: false, + // Surge only supports UDP 53 or Hosts as the bootstrap server of domain DoH + dns: '101.198.198.198', + domains: [ + // '$dns.360.cn', + // '$dot.360.cn', + '$doh.360.cn' + ] + } + }; + const AdGuardHomeDNSMapping = { + system: [ + 'udp://10.10.1.1:53' + ], + 'https://doh.pub/dns-query': [ + 'tls://1.12.12.12', + 'tls://120.53.53.53', + 'https://1.12.12.12/dns-query', + 'https://120.53.53.53/dns-query' + ], + 'quic://dns.alidns.com:853': [ + 'quic://223.5.5.5', + 'quic://223.6.6.6', + 'h3://223.5.5.5/dns-query', + 'h3://223.6.6.6/dns-query' + ], + 'https://doh.360.cn/dns-query': [ + 'https://doh.360.cn/dns-query', + 'tls://dot.360.cn' + ], + '180.76.76.76': [ + 'udp://180.76.76.76' + ], + '180.184.2.2': [ + 'udp://180.184.2.2', + 'udp://180.184.1.1' + ] + }; + } (domestic)); + return domestic; +}var direct = {};var hasRequiredDirect; + +function requireDirect () { + if (hasRequiredDirect) return direct; + hasRequiredDirect = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + DIRECTS: function() { + return DIRECTS; + }, + LAN: function() { + return LAN; + } + }); + const DIRECTS = { + HOTSPOT_CAPTIVE_PORTAL: { + dns: 'system', + hosts: {}, + realip: false, + ruleset: false, + domains: [ + 'securelogin.com.cn', + '$captive.apple.com', + '$hotspot.cslwifi.com' + ] + }, + SYSTEM: { + dns: 'system', + hosts: {}, + realip: true, + ruleset: false, + domains: [ + '+m2m', + // '+ts.net', // TailScale Magic DNS + // AdGuard + '$injections.adguard.org', + '$local.adguard.org', + // Auto Discovery + '+bogon' + ] + } + }; + const LAN = { + ROUTER: { + dns: 'system', + hosts: {}, + realip: false, + ruleset: true, + domains: [ + '+home', + // 'zte.home', // ZTE CPE + // 'airbox.home', + // 'bthub.home', + // 'bthomehub.home', + // 'hitronhub.home', + // 'web.setup.home' + // Aruba Router + '$instant.arubanetworks.com', + '$setmeup.arubanetworks.com', + // ASUS router + '$router.asus.com', + '$repeater.asus.com', + 'asusrouter.com', + // NetGear + 'routerlogin.net', + 'routerlogin.com', + // Tenda WiFi + // 'tendawifi.com', + // TP-Link Router + 'tplinkwifi.net', + 'tplogin.cn', + 'tplinkap.net', + 'tplinkmodem.net', + 'tplinkplclogin.net', + 'tplinkrepeater.net', + // UniFi + '+ui.direct', + '$unifi', + // Other Router + // '$router.com', + '+huaweimobilewifi.com', + '+router', + // 'my.router', + // 'samsung.router', + // '$easy.box', // Vodafone EasyBox + '$aterm.me', + '$console.gl-inet.com', + // '$fritz.box', + // '$fritz.repeater', + // '$myfritz.box', + // '$speedport.ip', // Telekom + // '$giga.cube', // Vodafone GigaCube + '$homerouter.cpe', + '$mobile.hotspot', + '$ntt.setup', + '$pi.hole', + '+plex.direct' + ] + }, + LAN: { + dns: 'system', + hosts: { + }, + realip: true, + ruleset: true, + domains: [ + '+lan', + // 'amplifi.lan', + // '$localhost', + '+localdomain', + 'home.arpa', + // AS112 + '10.in-addr.arpa', + '16.172.in-addr.arpa', + '17.172.in-addr.arpa', + '18.172.in-addr.arpa', + '19.172.in-addr.arpa', + // '2?.172.in-addr.arpa', + '20.172.in-addr.arpa', + '21.172.in-addr.arpa', + '22.172.in-addr.arpa', + '23.172.in-addr.arpa', + '24.172.in-addr.arpa', + '25.172.in-addr.arpa', + '26.172.in-addr.arpa', + '27.172.in-addr.arpa', + '28.172.in-addr.arpa', + '29.172.in-addr.arpa', + '30.172.in-addr.arpa', + '31.172.in-addr.arpa', + '168.192.in-addr.arpa', + '254.169.in-addr.arpa' + ] + } + }; + } (direct)); + return direct; +}var hasRequiredBuildDomesticDirectLanRulesetDnsMappingModule; + +function requireBuildDomesticDirectLanRulesetDnsMappingModule () { + if (hasRequiredBuildDomesticDirectLanRulesetDnsMappingModule) return buildDomesticDirectLanRulesetDnsMappingModule.exports; + hasRequiredBuildDomesticDirectLanRulesetDnsMappingModule = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + buildDomesticRuleset: function() { + return buildDomesticRuleset; + }, + createGetDnsMappingRule: function() { + return createGetDnsMappingRule; + }, + getDomesticAndDirectDomainsRulesetPromise: function() { + return getDomesticAndDirectDomainsRulesetPromise; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _domestic = /*@__PURE__*/ requireDomestic(); + const _direct = /*@__PURE__*/ requireDirect(); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _createfile = /*@__PURE__*/ createFile.r(); + const _trace = /*@__PURE__*/ index.r(); + const _description = /*@__PURE__*/ base.r(); + const _memopromise = /*@__PURE__*/ memoPromise.r(); + const _yaml = /*#__PURE__*/ _interop_require_wildcard(require$$8); + const _appendarrayinplace = /*@__PURE__*/ base.a(); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _ruleset = /*@__PURE__*/ ruleset.r(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); + } + function _interop_require_wildcard(obj, nodeInterop) { + if (obj && obj.__esModule) { + return obj; + } + if (obj === null || typeof obj !== "object" && typeof obj !== "function") { + return { + default: obj + }; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = { + __proto__: null + }; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; + } + function createGetDnsMappingRule(allowWildcard) { + const hasWildcard = (domain)=>{ + if (domain.includes('*') || domain.includes('?')) { + if (!allowWildcard) { + throw new TypeError(`Wildcard domain is not supported: ${domain}`); + } + return true; + } + return false; + }; + return (domain)=>{ + const results = []; + if (domain[0] === '$') { + const d = domain.slice(1); + if (hasWildcard(domain)) { + results.push(`DOMAIN-WILDCARD,${d}`); + } else { + results.push(`DOMAIN,${d}`); + } + } else if (domain[0] === '+') { + const d = domain.slice(1); + if (hasWildcard(domain)) { + results.push(`DOMAIN-WILDCARD,*.${d}`); + } else { + results.push(`DOMAIN-SUFFIX,${d}`); + } + } else if (hasWildcard(domain)) { + results.push(`DOMAIN-WILDCARD,${domain}`, `DOMAIN-WILDCARD,*.${domain}`); + } else { + results.push(`DOMAIN-SUFFIX,${domain}`); + } + return results; + }; + } + const getDomesticAndDirectDomainsRulesetPromise = (0, _memopromise.createMemoizedPromise)(async ()=>{ + const domestics = await (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip/domestic.conf')); + const directs = await (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.resolve(_dir.SOURCE_DIR, 'non_ip/direct.conf')); + const lans = []; + const getDnsMappingRuleWithWildcard = createGetDnsMappingRule(true); + [ + _domestic.DOH_BOOTSTRAP, + _domestic.DOMESTICS + ].forEach((item)=>{ + Object.values(item).forEach(({ domains })=>{ + (0, _appendarrayinplace.appendArrayInPlace)(domestics, domains.flatMap(getDnsMappingRuleWithWildcard)); + }); + }); + Object.values(_direct.DIRECTS).forEach(({ domains })=>{ + (0, _appendarrayinplace.appendArrayInPlace)(directs, domains.flatMap(getDnsMappingRuleWithWildcard)); + }); + Object.values(_direct.LAN).forEach(({ domains })=>{ + (0, _appendarrayinplace.appendArrayInPlace)(directs, domains.flatMap(getDnsMappingRuleWithWildcard)); + }); + return [ + domestics, + directs, + lans + ]; + }); + const buildDomesticRuleset = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const [domestics, directs, lans] = await getDomesticAndDirectDomainsRulesetPromise(); + const dataset = [ + _domestic.DOH_BOOTSTRAP, + _domestic.DOMESTICS, + _direct.DIRECTS, + _direct.LAN + ].flatMap(Object.entries); + return Promise.all([ + new _ruleset.RulesetOutput(span, 'domestic', 'non_ip').withTitle('Sukka\'s Ruleset - Domestic Domains').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains known addresses that are avaliable in the Mainland China.' + ]).addFromRuleset(domestics).write(), + new _ruleset.RulesetOutput(span, 'direct', 'non_ip').withTitle('Sukka\'s Ruleset - Direct Rules').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains domains and process that should not be proxied.' + ]).addFromRuleset(directs).write(), + new _ruleset.RulesetOutput(span, 'lan', 'non_ip').withTitle('Sukka\'s Ruleset - LAN').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file includes rules for LAN DOMAIN and reserved TLDs.' + ]).addFromRuleset(lans).write(), + ...dataset.map(([name, { ruleset, domains }])=>{ + if (!ruleset) { + return; + } + const output = new _ruleset.SurgeOnlyRulesetOutput(span, name.toLowerCase(), 'sukka_local_dns_mapping', _dir.OUTPUT_MODULES_RULES_DIR).withTitle(`Sukka's Ruleset - Local DNS Mapping (${name})`).withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This is an internal rule that is only referenced by sukka_local_dns_mapping.sgmodule', + 'Do not use this file in your Rule section, all rules are included in non_ip/domestic.conf already.' + ]); + domains.forEach((domain)=>{ + switch(domain[0]){ + case '$': + output.addDomain(domain.slice(1)); + break; + case '+': + output.addDomainSuffix(domain.slice(1)); + break; + default: + output.addDomainSuffix(domain); + break; + } + }); + return output.write(); + }), + (0, _createfile.compareAndWriteFile)(span, [ + '#!name=[Sukka] Local DNS Mapping', + `#!desc=Last Updated: ${new Date().toISOString()}`, + '', + '[Host]', + ...Object.entries(// I use an object to deduplicate the domains + // Otherwise I could just construct an array directly + dataset.reduce((acc, cur)=>{ + const ruleset_name = cur[0].toLowerCase(); + const { domains, dns, hosts, ruleset } = cur[1]; + Object.entries(hosts).forEach(([dns, ips])=>{ + acc[dns] ||= ips.join(', '); + }); + if (ruleset) { + acc[`RULE-SET:https://ruleset.skk.moe/Modules/Rules/sukka_local_dns_mapping/${ruleset_name}.conf`] ||= `server:${dns}`; + } else { + domains.forEach((domain)=>{ + switch(domain[0]){ + case '$': + acc[domain.slice(1)] ||= `server:${dns}`; + break; + case '+': + acc[`*.${domain.slice(1)}`] ||= `server:${dns}`; + break; + default: + acc[domain] ||= `server:${dns}`; + acc[`*.${domain}`] ||= `server:${dns}`; + break; + } + }); + } + return acc; + }, {})).map(([dns, ips])=>`${dns} = ${ips}`) + ], _nodepath.default.resolve(_dir.OUTPUT_MODULES_DIR, 'sukka_local_dns_mapping.sgmodule')), + (0, _createfile.compareAndWriteFile)(span, _yaml.stringify(dataset.reduce((acc, cur)=>{ + const { domains, dns, ...rest } = cur[1]; + domains.forEach((domain)=>{ + switch(domain[0]){ + case '$': + domain = domain.slice(1); + break; + case '+': + domain = `*.${domain.slice(1)}`; + break; + default: + domain = `+.${domain}`; + break; + } + acc.dns['nameserver-policy'][domain] = dns === 'system' ? [ + 'system://', + 'system', + 'dhcp://system' + ] : dns; + }); + if ('hosts' in rest) { + Object.assign(acc.hosts, rest.hosts); + } + return acc; + }, { + dns: { + 'nameserver-policy': {} + }, + hosts: {} + }), { + version: '1.1' + }).split('\n'), _nodepath.default.join(_dir.OUTPUT_INTERNAL_DIR, 'clash_nameserver_policy.yaml')), + (0, _createfile.compareAndWriteFile)(span, [ + '# Local DNS Mapping for AdGuard Home', + 'tls://1.12.12.12', + 'tls://120.53.53.53', + 'https://1.12.12.12/dns-query', + 'https://120.53.53.53/dns-query', + '[//]udp://10.10.1.1:53', + ...[ + _domestic.DOMESTICS, + _direct.DIRECTS, + _direct.LAN + ].flatMap(Object.values).flatMap(({ domains, dns: _dns })=>domains.flatMap((domain)=>{ + let dns; + if (_dns in _domestic.AdGuardHomeDNSMapping) { + dns = _domestic.AdGuardHomeDNSMapping[_dns].join(' '); + } else { + console.warn(`Unknown DNS "${_dns}" not in AdGuardHomeDNSMapping`); + dns = _dns; + } + // if ( + // // AdGuard Home has built-in AS112 / private PTR handling + // domain.endsWith('.arpa') + // // Ignore simple hostname + // || !domain.includes('.') + // ) { + // return []; + // } + if (domain[0] === '$') { + return [ + `[/${domain.slice(1)}/]${dns}` + ]; + } + if (domain[0] === '+') { + return [ + `[/${domain.slice(1)}/]${dns}` + ]; + } + return [ + `[/${domain}/]${dns}` + ]; + })) + ], _nodepath.default.resolve(_dir.OUTPUT_INTERNAL_DIR, 'dns_mapping_adguardhome.conf')) + ]); + }); + } (buildDomesticDirectLanRulesetDnsMappingModule, buildDomesticDirectLanRulesetDnsMappingModule.exports)); + return buildDomesticDirectLanRulesetDnsMappingModule.exports; +}exports.a=requireDirect;exports.b=requireDomestic;exports.r=requireBuildDomesticDirectLanRulesetDnsMappingModule; \ No newline at end of file diff --git a/Dist/chunks/build-internal-reverse-chn-cidr.C6CBihfs.cjs b/Dist/chunks/build-internal-reverse-chn-cidr.C6CBihfs.cjs new file mode 100644 index 00000000..5a709390 --- /dev/null +++ b/Dist/chunks/build-internal-reverse-chn-cidr.C6CBihfs.cjs @@ -0,0 +1,77 @@ +'use strict';const require$$0$1=require('node:path'),index=require('./index.B8Uk9n3v.cjs'),buildChnCidr=require('./build-chn-cidr.BjyqKcvm.cjs'),require$$1=require('node:fs'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),require$$0=require('foxts/async-write-to-stream'),misc=require('./misc.BpcQjda1.cjs'),require$$7=require('worktank'),require$$8=require('url');var buildInternalReverseChnCidr = {exports: {}};var hasRequiredBuildInternalReverseChnCidr; + +function requireBuildInternalReverseChnCidr () { + if (hasRequiredBuildInternalReverseChnCidr) return buildInternalReverseChnCidr.exports; + hasRequiredBuildInternalReverseChnCidr = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildInternalReverseChnCIDR", { + enumerable: true, + get: function() { + return buildInternalReverseChnCIDR; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _trace = /*@__PURE__*/ index.r(); + const _buildchncidr = buildChnCidr.r(); + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _asyncwritetostream = require$$0; + const _misc = /*@__PURE__*/ misc.r(); + const _worktank = /*#__PURE__*/ _interop_require_default(require$$7); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const pool = new _worktank.default({ + name: 'build-internal-reverse-chn-cidr', + size: 1, + timeout: 10000, + warmup: true, + autoterminate: 30000, + env: {}, + methods: { + // eslint-disable-next-line object-shorthand -- workertank + getreversedCidr: async function(cidr, importMetaUrl) { + // TODO: createRequire is a temporary workaround for https://github.com/nodejs/node/issues/51956 + const { default: module1 } = await import('node:module'); + const __require = module1.createRequire(importMetaUrl); + const { exclude, merge } = __require('fast-cidr-tools'); + const { RESERVED_IPV4_CIDR, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } = __require('./constants/cidr'); + const { appendArrayInPlace } = __require('./lib/append-array-in-place'); + return merge(appendArrayInPlace(exclude([ + '0.0.0.0/0' + ], RESERVED_IPV4_CIDR.concat(cidr), true), // https://github.com/misakaio/chnroutes2/issues/25 + NON_CN_CIDR_INCLUDED_IN_CHNROUTE), true); + } + } + }); + const buildInternalReverseChnCIDR = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const [cidr] = await span.traceChildPromise('download chnroutes2', (0, _buildchncidr.getChnCidrPromise)()); + const reversedCidr = await span.traceChildAsync('build reversed chn cidr', async ()=>{ + const reversedCidr = await pool.exec('getreversedCidr', [ + cidr, + require$$8.pathToFileURL(__filename).toString() + ]); + pool.terminate(); + return reversedCidr; + }); + const outputFile = _nodepath.default.join(_dir.OUTPUT_INTERNAL_DIR, 'reversed-chn-cidr.txt'); + await (0, _misc.mkdirp)(_dir.OUTPUT_INTERNAL_DIR); + const writeStream = _nodefs.default.createWriteStream(outputFile); + for (const line of reversedCidr){ + const p = (0, _asyncwritetostream.asyncWriteToStream)(writeStream, line + '\n'); + if (p) { + // eslint-disable-next-line no-await-in-loop -- stream high water mark + await p; + } + } + await (0, _asyncwritetostream.asyncWriteToStream)(writeStream, '\n'); + writeStream.end(); + }); + } (buildInternalReverseChnCidr, buildInternalReverseChnCidr.exports)); + return buildInternalReverseChnCidr.exports; +}exports.r=requireBuildInternalReverseChnCidr; \ No newline at end of file diff --git a/Dist/chunks/build-microsoft-cdn.CCw86frc.cjs b/Dist/chunks/build-microsoft-cdn.CCw86frc.cjs new file mode 100644 index 00000000..cfad4e8f --- /dev/null +++ b/Dist/chunks/build-microsoft-cdn.CCw86frc.cjs @@ -0,0 +1,84 @@ +'use strict';const index=require('./index.B8Uk9n3v.cjs'),fetchTextByLine=require('./fetch-text-by-line.YY5b5610.cjs'),trie=require('./trie.Vu1FNyv-.cjs'),base=require('./base.C13YY5P3.cjs'),memoPromise=require('./memo-promise.BbOsVeGo.cjs'),parseDnsmasq=require('./parse-dnsmasq.CiH7YJVY.cjs'),ruleset=require('./ruleset.iYH0XOC1.cjs');var buildMicrosoftCdn = {exports: {}};var hasRequiredBuildMicrosoftCdn; + +function requireBuildMicrosoftCdn () { + if (hasRequiredBuildMicrosoftCdn) return buildMicrosoftCdn.exports; + hasRequiredBuildMicrosoftCdn = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + buildMicrosoftCdn: function() { + return buildMicrosoftCdn; + }, + getMicrosoftCdnRulesetPromise: function() { + return getMicrosoftCdnRulesetPromise; + } + }); + const _trace = /*@__PURE__*/ index.r(); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _trie = /*@__PURE__*/ trie.r(); + const _description = /*@__PURE__*/ base.r(); + const _memopromise = /*@__PURE__*/ memoPromise.r(); + const _parsednsmasq = /*@__PURE__*/ parseDnsmasq.r(); + const _ruleset = /*@__PURE__*/ ruleset.r(); + const _appendarrayinplace = /*@__PURE__*/ base.a(); + const PROBE_DOMAINS = [ + '.microsoft.com', + '.windows.net', + '.windows.com', + '.windowsupdate.com', + '.windowssearch.com', + '.office.net' + ]; + const DOMAINS = [ + 'res.cdn.office.net', + 'res-1.cdn.office.net', + 'statics.teams.cdn.office.net' + ]; + const DOMAIN_SUFFIXES = [ + 'download.prss.microsoft.com' + ]; + const BLACKLIST = [ + 'www.microsoft.com', + 'windowsupdate.com' + ]; + const getMicrosoftCdnRulesetPromise = (0, _memopromise.createMemoizedPromise)(async ()=>{ + // First trie is to find the microsoft domains that matches probe domains + const trie = new _trie.HostnameSmolTrie(); + for await (const line of (await (0, _fetchtextbyline.fetchRemoteTextByLine)('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf'))){ + const domain = (0, _parsednsmasq.extractDomainsFromFelixDnsmasq)(line); + if (domain) { + trie.add(domain); + } + } + // remove blacklist domain from trie, to prevent them from being included in the later dump + BLACKLIST.forEach((black)=>trie.whitelist(black)); + const domains = DOMAINS; + const domainSuffixes = (0, _appendarrayinplace.appendArrayInPlace)(PROBE_DOMAINS.flatMap((domain)=>trie.find(domain)), DOMAIN_SUFFIXES); + return [ + domains, + domainSuffixes + ]; + }); + const buildMicrosoftCdn = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const description = [ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains Microsoft\'s domains using their China mainland CDN servers.', + '', + 'Data from:', + ' - https://github.com/felixonmars/dnsmasq-china-list' + ]; + const [domains, domainSuffixes] = await span.traceChildPromise('get microsoft cdn domains', getMicrosoftCdnRulesetPromise()); + return new _ruleset.RulesetOutput(span, 'microsoft_cdn', 'non_ip').withTitle('Sukka\'s Ruleset - Microsoft CDN').withDescription(description).bulkAddDomain(domains).bulkAddDomainSuffix(domainSuffixes).write(); + }); + } (buildMicrosoftCdn, buildMicrosoftCdn.exports)); + return buildMicrosoftCdn.exports; +}exports.r=requireBuildMicrosoftCdn; \ No newline at end of file diff --git a/Dist/chunks/build-public.8-AWnl05.cjs b/Dist/chunks/build-public.8-AWnl05.cjs new file mode 100644 index 00000000..1db85286 --- /dev/null +++ b/Dist/chunks/build-public.8-AWnl05.cjs @@ -0,0 +1,232 @@ +'use strict';const require$$0=require('node:path'),require$$1=require('node:fs'),require$$2=require('node:fs/promises'),index=require('./index.B8Uk9n3v.cjs'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),misc=require('./misc.BpcQjda1.cjs'),require$$0$1=require('picocolors'),require$$8=require('foxts/tagged'),createFile=require('./create-file.loOMbJEN.cjs');var buildPublic = {exports: {}};var treeDir = {};var hasRequiredTreeDir; + +function requireTreeDir () { + if (hasRequiredTreeDir) return treeDir; + hasRequiredTreeDir = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + TreeFileType: function() { + return TreeFileType; + }, + treeDir: function() { + return treeDir; + } + }); + const _promises = /*#__PURE__*/ _interop_require_default(require$$2); + const _nodepath = require$$0; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + var TreeFileType = /*#__PURE__*/ function(TreeFileType) { + TreeFileType[TreeFileType["FILE"] = 1] = "FILE"; + TreeFileType[TreeFileType["DIRECTORY"] = 2] = "DIRECTORY"; + return TreeFileType; + }({}); + async function treeDir(rootPath) { + const tree = []; + const walk = async (dir, node, dirRelativeToRoot = '')=>{ + const promises = []; + for await (const child of (await _promises.default.opendir(dir))){ + // Ignore hidden files + if (child.name[0] === '.' || child.name === 'CNAME') { + continue; + } + const childFullPath = child.parentPath + _nodepath.sep + child.name; + const childRelativeToRoot = dirRelativeToRoot + _nodepath.sep + child.name; + if (child.isDirectory()) { + const newNode = { + type: 2, + name: child.name, + path: childRelativeToRoot, + children: [] + }; + node.push(newNode); + promises.push(walk(childFullPath, newNode.children, childRelativeToRoot)); + continue; + } + if (child.isFile()) { + const newNode = { + type: 1, + name: child.name, + path: childRelativeToRoot + }; + node.push(newNode); + continue; + } + } + return Promise.all(promises); + }; + await walk(rootPath, tree); + return tree; + } + } (treeDir)); + return treeDir; +}var hasRequiredBuildPublic; + +function requireBuildPublic () { + if (hasRequiredBuildPublic) return buildPublic.exports; + hasRequiredBuildPublic = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildPublic", { + enumerable: true, + get: function() { + return buildPublic; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1); + const _promises = /*#__PURE__*/ _interop_require_default(require$$2); + const _trace = /*@__PURE__*/ index.r(); + const _treedir = /*@__PURE__*/ requireTreeDir(); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _misc = /*@__PURE__*/ misc.r(); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _tagged = require$$8; + const _createfile = /*@__PURE__*/ createFile.r(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const mockDir = _nodepath.default.join(_dir.ROOT_DIR, 'Mock'); + const modulesDir = _nodepath.default.join(_dir.ROOT_DIR, 'Modules'); + async function copyDirContents(srcDir, destDir) { + const promises = []; + for await (const entry of (await _promises.default.opendir(srcDir))){ + const src = _nodepath.default.join(srcDir, entry.name); + const dest = _nodepath.default.join(destDir, entry.name); + if (entry.isDirectory()) { + console.warn(_picocolors.default.red('[build public] cant copy directory'), src); + } else { + promises.push(_promises.default.copyFile(src, dest, _nodefs.default.constants.COPYFILE_FICLONE)); + } + } + return Promise.all(promises); + } + const buildPublic = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + await span.traceChildAsync('copy rest of the files', async ()=>{ + await Promise.all([ + // mkdirp(OUTPUT_MODULES_DIR), + (0, _misc.mkdirp)(_dir.OUTPUT_MODULES_RULES_DIR), + (0, _misc.mkdirp)(_dir.OUTPUT_MOCK_DIR) + ]); + await Promise.all([ + copyDirContents(modulesDir, _dir.OUTPUT_MODULES_DIR), + copyDirContents(mockDir, _dir.OUTPUT_MOCK_DIR) + ]); + }); + const html = await span.traceChild('generate index.html').traceAsyncFn(()=>(0, _treedir.treeDir)(_dir.PUBLIC_DIR).then(generateHtml)); + await (0, _createfile.compareAndWriteFile)(span, [ + '/*', + ' cache-control: public, max-age=240, stale-while-revalidate=60, stale-if-error=15', + 'https://:project.pages.dev/*', + ' X-Robots-Tag: noindex', + '/Modules/*', + ' content-type: text/plain; charset=utf-8', + '/List/*', + ' content-type: text/plain; charset=utf-8' + ], _nodepath.default.join(_dir.PUBLIC_DIR, '_headers')); + await (0, _createfile.compareAndWriteFile)(span, [ + '#
    ',
    +		        '#########################################',
    +		        '# Sukka\'s Ruleset - 404 Not Found',
    +		        '################## EOF ##################
    ' + ], _nodepath.default.join(_dir.PUBLIC_DIR, '404.html')); + return (0, _misc.writeFile)(_nodepath.default.join(_dir.PUBLIC_DIR, 'index.html'), html); + }); + const priorityOrder = { + domainset: 1, + non_ip: 2, + ip: 3, + List: 10, + Surge: 11, + Clash: 12, + 'sing-box': 13, + Modules: 20, + Script: 30, + Mock: 40, + Assets: 50, + Internal: 60, + LICENSE: 70, + default: Number.MAX_VALUE + }; + const prioritySorter = (a, b)=>(priorityOrder[a.name] || priorityOrder.default) - (priorityOrder[b.name] || priorityOrder.default) || (0, _misc.fastStringCompare)(a.name, b.name); + function walk(tree) { + let result = ''; + tree.sort(prioritySorter); + for(let i = 0, len = tree.length; i < len; i++){ + const entry = tree[i]; + if (entry.type === _treedir.TreeFileType.DIRECTORY) { + result += (0, _tagged.tagged)` +
  • + ${entry.name} +
      + ${walk(entry.children)} +
    +
  • + `; + } else if (/* entry.type === 'file' && */ entry.name !== 'index.html') { + result += (0, _tagged.tagged)`
  • ${entry.name}
  • `; + } + } + return result; + } + function generateHtml(tree) { + return (0, _tagged.tagged)` + + + + + + Surge Ruleset Server | Sukka (@SukkaW) + + + + + + + + + + + + + + + + + + + +
    +

    Sukka Ruleset Server

    +

    + Made by Sukka | Source @ GitHub | Licensed under AGPL-3.0 +

    +

    Last Build: ${new Date().toISOString()}

    +
    +
      + ${walk(tree)} +
    +
    + + + `; + } + } (buildPublic, buildPublic.exports)); + return buildPublic.exports; +}exports.r=requireBuildPublic; \ No newline at end of file diff --git a/Dist/chunks/build-reject-domainset.BCoJGSBE.cjs b/Dist/chunks/build-reject-domainset.BCoJGSBE.cjs new file mode 100644 index 00000000..03d1d719 --- /dev/null +++ b/Dist/chunks/build-reject-domainset.BCoJGSBE.cjs @@ -0,0 +1,1073 @@ +'use strict';const require$$0$1=require('node:path'),require$$1=require('node:process'),fetchAssets=require('./fetch-assets.aqw2YOi8.cjs'),normalizeDomain=require('./normalize-domain.Cfz4j8eP.cjs'),require$$0=require('picocolors'),rejectDataSource=require('./reject-data-source.DaKwvNlG.cjs'),require$$2=require('foxts/noop'),fetchTextByLine=require('./fetch-text-by-line.YY5b5610.cjs'),require$$3=require('foxts/retrie'),looseTldtsOpt=require('./loose-tldts-opt.DLUpGXpj.cjs'),require$$5=require('tldts-experimental'),require$$6=require('@ghostery/adblocker'),index=require('./index.B8Uk9n3v.cjs'),base=require('./base.C13YY5P3.cjs'),fsMemo=require('./fs-memo.Dw823m02.cjs'),require$$11=require('ci-info'),require$$10=require('foxts/add-array-elements-to-set'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),domainset=require('./domainset.CSQfKAtf.cjs');var buildRejectDomainset = {exports: {}};var hosts = {};var shared = {};var hasRequiredShared; + +function requireShared () { + if (hasRequiredShared) return shared; + hasRequiredShared = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + foundDebugDomain: function() { + return foundDebugDomain; + }, + onBlackFound: function() { + return onBlackFound; + }, + onWhiteFound: function() { + return onWhiteFound; + } + }); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0); + const _rejectdatasource = /*@__PURE__*/ rejectDataSource.r(); + const _noop = require$$2; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const foundDebugDomain = { + value: false + }; + const onBlackFound = _rejectdatasource.DEBUG_DOMAIN_TO_FIND ? (line, meta)=>{ + if (line.includes(_rejectdatasource.DEBUG_DOMAIN_TO_FIND)) { + console.warn(_picocolors.default.red(meta), '(black)', line.replaceAll(_rejectdatasource.DEBUG_DOMAIN_TO_FIND, _picocolors.default.bold(_rejectdatasource.DEBUG_DOMAIN_TO_FIND))); + foundDebugDomain.value = true; + } + } : _noop.noop; + const onWhiteFound = _rejectdatasource.DEBUG_DOMAIN_TO_FIND ? (line, meta)=>{ + if (line.includes(_rejectdatasource.DEBUG_DOMAIN_TO_FIND)) { + console.warn(_picocolors.default.red(meta), '(white)', line.replaceAll(_rejectdatasource.DEBUG_DOMAIN_TO_FIND, _picocolors.default.bold(_rejectdatasource.DEBUG_DOMAIN_TO_FIND))); + foundDebugDomain.value = true; + } + } : _noop.noop; + } (shared)); + return shared; +}var hasRequiredHosts; + +function requireHosts () { + if (hasRequiredHosts) return hosts; + hasRequiredHosts = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + processHosts: function() { + return processHosts; + }, + processHostsWithPreload: function() { + return processHostsWithPreload; + } + }); + const _fetchassets = /*@__PURE__*/ fetchAssets.r(); + const _normalizedomain = /*@__PURE__*/ normalizeDomain.r(); + const _shared = /*@__PURE__*/ requireShared(); + function hostsLineCb(line, set, includeAllSubDomain, meta) { + const _domain = line.split(/\s/)[1]?.trim(); + if (!_domain) { + return; + } + const domain = (0, _normalizedomain.fastNormalizeDomainWithoutWww)(_domain); + if (!domain) { + return; + } + (0, _shared.onBlackFound)(domain, meta); + set.push(includeAllSubDomain ? `.${domain}` : domain); + } + function processHosts(span, hostsUrl, mirrors, includeAllSubDomain = false) { + return span.traceChildAsync(`process hosts: ${hostsUrl}`, async (span)=>{ + const filterRules = await span.traceChild('download').traceAsyncFn(()=>(0, _fetchassets.fetchAssets)(hostsUrl, mirrors, true)); + const domainSets = []; + span.traceChild('parse hosts').traceSyncFn(()=>{ + for(let i = 0, len = filterRules.length; i < len; i++){ + hostsLineCb(filterRules[i], domainSets, includeAllSubDomain, hostsUrl); + } + }); + return domainSets; + }); + } + function processHostsWithPreload(hostsUrl, mirrors, includeAllSubDomain = false) { + const downloadPromise = (0, _fetchassets.fetchAssets)(hostsUrl, mirrors, true); + return (span)=>span.traceChildAsync(`process hosts: ${hostsUrl}`, async (span)=>{ + const filterRules = await span.traceChild('download').tracePromise(downloadPromise); + const domainSets = []; + span.traceChild('parse hosts').traceSyncFn(()=>{ + for(let i = 0, len = filterRules.length; i < len; i++){ + hostsLineCb(filterRules[i], domainSets, includeAllSubDomain, hostsUrl); + } + }); + return domainSets; + }); + } + } (hosts)); + return hosts; +}var domainlists = {};var hasRequiredDomainlists; + +function requireDomainlists () { + if (hasRequiredDomainlists) return domainlists; + hasRequiredDomainlists = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + processDomainLists: function() { + return processDomainLists; + }, + processDomainListsWithPreload: function() { + return processDomainListsWithPreload; + } + }); + const _normalizedomain = /*@__PURE__*/ normalizeDomain.r(); + const _processline = /*@__PURE__*/ fetchTextByLine.r(); + const _shared = /*@__PURE__*/ requireShared(); + const _fetchassets = /*@__PURE__*/ fetchAssets.r(); + function domainListLineCb(l, set, meta, normalizeDomain = _normalizedomain.fastNormalizeDomain) { + const line = (0, _processline.processLine)(l); + if (!line) return; + const domain = normalizeDomain(line); + if (!domain) return; + (0, _shared.onBlackFound)(domain, meta); + set.push(domain); + } + function domainListLineCbIncludeAllSubdomain(line, set, meta, normalizeDomain = _normalizedomain.fastNormalizeDomain) { + const domain = normalizeDomain(line); + if (!domain) return; + (0, _shared.onBlackFound)(domain, meta); + set.push('.' + domain); + } + function processDomainLists(span, domainListsUrl, mirrors, includeAllSubDomain = false) { + const lineCb = includeAllSubDomain ? domainListLineCbIncludeAllSubdomain : domainListLineCb; + return span.traceChildAsync(`process domainlist: ${domainListsUrl}`, async (span)=>{ + const filterRules = await span.traceChildAsync('download', ()=>(0, _fetchassets.fetchAssets)(domainListsUrl, mirrors, true)); + const domainSets = []; + span.traceChildSync('parse domain list', ()=>{ + for(let i = 0, len = filterRules.length; i < len; i++){ + lineCb(filterRules[i], domainSets, domainListsUrl, _normalizedomain.fastNormalizeDomainWithoutWww); + } + }); + return domainSets; + }); + } + function processDomainListsWithPreload(domainListsUrl, mirrors, includeAllSubDomain = false) { + const downloadPromise = (0, _fetchassets.fetchAssets)(domainListsUrl, mirrors, true); + const lineCb = includeAllSubDomain ? domainListLineCbIncludeAllSubdomain : domainListLineCb; + return (span)=>span.traceChildAsync(`process domainlist: ${domainListsUrl}`, async (span)=>{ + const filterRules = await span.traceChildPromise('download', downloadPromise); + const domainSets = []; + span.traceChildSync('parse domain list', ()=>{ + for(let i = 0, len = filterRules.length; i < len; i++){ + lineCb(filterRules[i], domainSets, domainListsUrl, _normalizedomain.fastNormalizeDomainWithoutWww); + } + }); + return domainSets; + }); + } + } (domainlists)); + return domainlists; +}var filters = {};var hasRequiredFilters; + +function requireFilters () { + if (hasRequiredFilters) return filters; + hasRequiredFilters = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + parse: function() { + return parse; + }, + processFilterRulesWithPreload: function() { + return processFilterRulesWithPreload; + } + }); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0); + const _fetchassets = /*@__PURE__*/ fetchAssets.r(); + const _shared = /*@__PURE__*/ requireShared(); + const _retrie = require$$3; + const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.r(); + const _tldtsexperimental = /*#__PURE__*/ _interop_require_default(require$$5); + const _adblocker = require$$6; + const _normalizedomain = /*@__PURE__*/ normalizeDomain.r(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function processFilterRulesWithPreload(filterRulesUrl, fallbackUrls, includeThirdParty = false) { + const downloadPromise = (0, _fetchassets.fetchAssets)(filterRulesUrl, fallbackUrls); + return (span)=>span.traceChildAsync(`process filter rules: ${filterRulesUrl}`, async (span)=>{ + const filterRules = await span.traceChildPromise('download', downloadPromise); + const whiteDomains = new Set(); + const whiteDomainSuffixes = new Set(); + const blackDomains = new Set(); + const blackDomainSuffixes = new Set(); + const warningMessages = []; + const MUTABLE_PARSE_LINE_RESULT = [ + '', + 2000 + ]; + /** + * @param {string} line + */ const lineCb = (line)=>{ + const result = parse(line, MUTABLE_PARSE_LINE_RESULT, includeThirdParty); + const flag = result[1]; + if (flag === 2000) { + throw new Error(`Didn't parse line: ${line}`); + } + if (flag === 1000) { + return; + } + const hostname = result[0]; + if (flag === 0 || flag === -1) { + (0, _shared.onWhiteFound)(hostname, filterRulesUrl); + } else { + (0, _shared.onBlackFound)(hostname, filterRulesUrl); + } + switch(flag){ + case 0: + whiteDomainSuffixes.add(hostname); + break; + case -1: + whiteDomains.add(hostname); + break; + case 2: + blackDomainSuffixes.add(hostname); + break; + case 1: + blackDomains.add(hostname); + break; + case 10: + warningMessages.push(hostname); + break; + } + }; + span.traceChild('parse adguard filter').traceSyncFn(()=>{ + for(let i = 0, len = filterRules.length; i < len; i++){ + lineCb(filterRules[i]); + } + }); + for(let i = 0, len = warningMessages.length; i < len; i++){ + console.warn(_picocolors.default.yellow(warningMessages[i]), _picocolors.default.gray(_picocolors.default.underline(filterRulesUrl))); + } + console.log(_picocolors.default.gray('[process filter]'), _picocolors.default.gray(filterRulesUrl), _picocolors.default.gray(`white: ${whiteDomains.size + whiteDomainSuffixes.size}`), _picocolors.default.gray(`black: ${blackDomains.size + blackDomainSuffixes.size}`)); + return { + whiteDomains: Array.from(whiteDomains), + whiteDomainSuffixes: Array.from(whiteDomainSuffixes), + blackDomains: Array.from(blackDomains), + blackDomainSuffixes: Array.from(blackDomainSuffixes) + }; + }); + } + // many filter that has modifiers can not work on Surge/Clash because browser context is required + // we can early bail out those rules + const kwfilter = (0, _retrie.createRetrieKeywordFilter)([ + '!', + '?', + '*', + '[', + '(', + ']', + ')', + ',', + '#', + '%', + '&', + '=', + '~', + // special modifier + '$popup', + '$removeparam', + '$redirect', + '$popunder', + '$cname', + '$frame', + '$domain', + '$from', + '$to', + '$csp', + '$replace', + '$urlskip', + // some bad syntax + '^popup' + ]); + function parse($line, result, includeThirdParty) { + if (// doesn't include + !$line.includes('.') // rule with out dot can not be a domain + || kwfilter($line)) { + result[1] = 1000; + return result; + } + const line = $line.trim(); + if (line.length === 0) { + result[1] = 1000; + return result; + } + const firstCharCode = line.charCodeAt(0); + const lastCharCode = line.charCodeAt(line.length - 1); + if (firstCharCode === 47 // 47 `/` + || lastCharCode === 46 // 46 `.`, line.endsWith('.') + || lastCharCode === 45 // 45 `-`, line.endsWith('-') + || lastCharCode === 95 // 95 `_`, line.endsWith('_') + ) { + result[1] = 1000; + return result; + } + if ((line.includes('/') || line.includes(':')) && !line.includes('://')) { + result[1] = 1000; + return result; + } + const filter = _adblocker.NetworkFilter.parse(line); + if (filter) { + if (// filter.isCosmeticFilter() // always false + // filter.isNetworkFilter() // always true + filter.isElemHide() || filter.isGenericHide() || filter.isSpecificHide() || filter.isRedirect() || filter.isRedirectRule() || filter.hasDomains() || filter.isCSP() // must not be csp rule + || !filter.fromHttp() && !filter.fromHttps()) { + // not supported type + result[1] = 1000; + return result; + } + if (!filter.fromAny() && !filter.fromDocument() // $document, $doc + ) { + result[1] = 1000; + return result; + } + if (filter.hostname // filter.hasHostname() // must have + && filter.isPlain() // isPlain() === !isRegex() + && !filter.isFullRegex()) { + const hostname = (0, _normalizedomain.fastNormalizeDomainWithoutWww)(filter.hostname); + if (!hostname) { + result[1] = 1000; + return result; + } + // |: filter.isHostnameAnchor(), + // |: filter.isLeftAnchor(), + // |https://: !filter.isHostnameAnchor() && (filter.fromHttps() || filter.fromHttp()) + const isIncludeAllSubDomain = filter.isHostnameAnchor(); + if (filter.isException() || filter.isBadFilter()) { + result[0] = hostname; + result[1] = isIncludeAllSubDomain ? 0 : -1; + return result; + } + const _1p = filter.firstParty(); + const _3p = filter.thirdParty(); + if (_1p) { + if (_3p) { + result[0] = hostname; + result[1] = isIncludeAllSubDomain ? 2 : 1; + return result; + } + result[1] = 1000; + return result; + } + if (_3p) { + if (includeThirdParty) { + result[0] = hostname; + result[1] = isIncludeAllSubDomain ? 2 : 1; + return result; + } + result[1] = 1000; + return result; + } + } + } + /** + * From now on, we are mostly facing non-standard domain rules (some are regex like) + * + * We can still salvage some of them by removing modifiers + */ let sliceStart = 0; + let sliceEnd = 0; + // After NetworkFilter.parse, it means the line can not be parsed by cliqz NetworkFilter + // We now need to "salvage" the line as much as possible + let white = false; + let includeAllSubDomain = false; + if (firstCharCode === 64 // 64 `@` + && line.charCodeAt(1) === 64 // 64 `@` + ) { + sliceStart += 2; + white = true; + includeAllSubDomain = true; + } + /** + * Some "malformed" regex-based filters can not be parsed by NetworkFilter + * "$genericblock`" is also not supported by NetworkFilter, see: + * https://github.com/ghostery/adblocker/blob/62caf7786ba10ef03beffecd8cd4eec111bcd5ec/packages/adblocker/test/parsing.test.ts#L950 + * + * `@@||cmechina.net^$genericblock` + * `@@|ftp.bmp.ovh^|` + * `@@|adsterra.com^|` + * `@@.atlassian.net$document` + * `@@||ad.alimama.com^$genericblock` + */ switch(line.charCodeAt(sliceStart)){ + case 124: + /** | */ // line.startsWith('@@|') || line.startsWith('|') + sliceStart += 1; + includeAllSubDomain = false; + if (line[sliceStart] === '|') { + sliceStart += 1; + includeAllSubDomain = true; + } + break; + case 46: + { + /** + * `.ay.delivery^` + * `.m.bookben.com^` + * `.wap.x4399.com^` + */ sliceStart += 1; + includeAllSubDomain = true; + break; + } + } + switch(line.charCodeAt(sliceStart)){ + case 58: + { + /** + * `@@://googleadservices.com^|` + * `@@://www.googleadservices.com^|` + * `://mine.torrent.pw^` + * `://say.ac^` + */ if (line[sliceStart + 1] === '/' && line[sliceStart + 2] === '/') { + includeAllSubDomain = false; + sliceStart += 3; + } + break; + } + case 104: + { + /** |http://x.o2.pl^ */ if (line.startsWith('http://', sliceStart)) { + includeAllSubDomain = false; + sliceStart += 7; + } else if (line.startsWith('https://', sliceStart)) { + includeAllSubDomain = false; + sliceStart += 8; + } + break; + } + } + const indexOfDollar = line.indexOf('$', sliceStart); + if (indexOfDollar > -1) { + sliceEnd = indexOfDollar - line.length; + } + /* + * We skip third-party and frame rules, as Surge / Clash can't handle them + * + * `.sharecounter.$third-party` + * `.bbelements.com^$third-party` + * `://o0e.ru^$third-party` + * `.1.1.1.l80.js^$third-party` + */ if (!includeThirdParty && (line.includes('third-party', indexOfDollar + 1) || line.includes('3p', indexOfDollar + 1))) { + result[1] = 1000; + return result; + } + if (line.includes('badfilter', indexOfDollar + 1)) { + white = true; + } + if (line.includes('all', indexOfDollar + 1)) { + includeAllSubDomain = true; + } + /** + * `_vmind.qqvideo.tc.qq.com^` + * `arketing.indianadunes.com^` + * `charlestownwyllie.oaklawnnonantum.com^` + * `-telemetry.officeapps.live.com^` + * `-tracker.biliapi.net` + * `-logging.nextmedia.com` + * `_social_tracking.js^` + */ if (line.charCodeAt(line.length + sliceEnd - 1) === 94) { + /** line.endsWith('^') */ sliceEnd -= 1; + } else if (line.charCodeAt(line.length + sliceEnd - 1) === 124) { + /** line.endsWith('|') */ sliceEnd -= 1; + if (line.charCodeAt(line.length + sliceEnd - 1) === 94) { + /** line.endsWith('^|') */ sliceEnd -= 1; + } + } else if (line.charCodeAt(line.length + sliceEnd - 1) === 46) { + /** line.endsWith('.') */ sliceEnd -= 1; + } + const sliced = sliceStart > 0 || sliceEnd < 0 ? line.slice(sliceStart, sliceEnd === 0 ? undefined : sliceEnd) : line; + if (sliced.length === 0 || sliced.includes('/')) { + result[1] = 1000; + return result; + } + if (sliced.charCodeAt(0) === 45 /* - */ ) { + // line.startsWith('-') is not a valid domain + result[1] = 10; + result[0] = `[parse-filter E0001] (${white ? 'white' : 'black'}) invalid domain: ${JSON.stringify({ + line, + sliced, + sliceStart, + sliceEnd + })}`; + return result; + } + const suffix = _tldtsexperimental.default.getPublicSuffix(sliced, _loosetldtsopt.looseTldtsOpt); + if (!suffix) { + // This exclude domain-like resource like `_social_tracking.js^` + result[1] = 1000; + return result; + } + const domain = (0, _normalizedomain.fastNormalizeDomainWithoutWww)(sliced); + if (domain && domain === sliced) { + result[0] = domain; + if (white) { + result[1] = includeAllSubDomain ? 0 : -1; + } else { + result[1] = includeAllSubDomain ? 2 : 1; + } + return result; + } + result[0] = `[parse-filter E0010] (${white ? 'white' : 'black'}) invalid domain: ${JSON.stringify({ + line, + domain, + suffix, + sliced, + sliceStart, + sliceEnd + })}`; + result[1] = 10; + return result; + } + } (filters)); + return filters; +}var getPhishingDomains = {exports: {}};var hasRequiredGetPhishingDomains; + +function requireGetPhishingDomains () { + if (hasRequiredGetPhishingDomains) return getPhishingDomains.exports; + hasRequiredGetPhishingDomains = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + calcDomainAbuseScore: function() { + return calcDomainAbuseScore; + }, + getPhishingDomains: function() { + return getPhishingDomains; + } + }); + const _hosts = /*@__PURE__*/ requireHosts(); + const _domainlists = /*@__PURE__*/ requireDomainlists(); + const _tldtsexperimental = /*#__PURE__*/ _interop_require_wildcard(require$$5); + const _trace = /*@__PURE__*/ index.r(); + const _appendarrayinplace = /*@__PURE__*/ base.a(); + const _rejectdatasource = /*@__PURE__*/ rejectDataSource.r(); + const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.r(); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0); + const _retrie = require$$3; + const _cachefilesystem = /*@__PURE__*/ fsMemo.a(); + const _fsmemo = /*@__PURE__*/ fsMemo.r(); + const _ciinfo = require$$11; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); + } + function _interop_require_wildcard(obj, nodeInterop) { + if (obj && obj.__esModule) { + return obj; + } + if (obj === null || typeof obj !== "object" && typeof obj !== "function") { + return { + default: obj + }; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = { + __proto__: null + }; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; + } + const BLACK_TLD = new Set([ + 'accountant', + 'art', + 'autos', + 'bar', + 'beauty', + 'bid', + 'bio', + 'biz', + 'bond', + 'business', + 'buzz', + 'cc', + 'cf', + 'cfd', + 'click', + 'cloud', + 'club', + 'cn', + 'codes', + 'co.uk', + 'co.in', + 'com.br', + 'com.cn', + 'com.pl', + 'com.vn', + 'cool', + 'cricket', + 'cyou', + 'date', + 'design', + 'digital', + 'download', + 'faith', + 'fit', + 'fun', + 'ga', + 'gd', + 'gives', + 'gq', + 'group', + 'host', + 'icu', + 'id', + 'info', + 'ink', + 'lat', + 'life', + 'live', + 'link', + 'loan', + 'lol', + 'ltd', + 'me', + 'men', + 'ml', + 'mobi', + 'mom', + 'monster', + 'net.pl', + 'one', + 'online', + 'party', + 'pro', + 'pl', + 'pw', + 'racing', + 'rest', + 'review', + 'rf.gd', + 'sa.com', + 'sbs', + 'science', + 'shop', + 'site', + 'skin', + 'space', + 'store', + 'stream', + 'su', + 'surf', + 'tech', + 'tk', + 'tokyo', + 'top', + 'trade', + 'vip', + 'vn', + 'webcam', + 'website', + 'win', + 'xyz', + 'za.com' + ]); + const WHITELIST_MAIN_DOMAINS = new Set([ + // 'w3s.link', // ipfs gateway + // 'dweb.link', // ipfs gateway + // 'nftstorage.link', // ipfs gateway + 'fleek.cool', + 'flk-ipfs.xyz', + 'business.site', + 'page.link', + // 'notion.site', + // 'vercel.app', + 'gitbook.io', + 'zendesk.com', + 'ipfs.eth.aragon.network', + 'wordpress.com' + ]); + const leathalKeywords = (0, _retrie.createRetrieKeywordFilter)([ + 'vinted-', + 'inpost-pl', + 'vlnted-' + ]); + const sensitiveKeywords = (0, _retrie.createRetrieKeywordFilter)([ + '.amazon-', + '-amazon', + 'fb-com', + 'facebook-com', + '-facebook', + 'facebook-', + 'focebaak', + '.facebook.', + 'metamask', + 'www.apple', + '-coinbase', + 'coinbase-', + 'booking-com', + 'booking.com-', + 'booking-eu', + 'vinted-', + 'inpost-pl', + 'login.microsoft', + 'login-microsoft', + 'microsoftonline', + 'google.com-', + 'minecraft', + 'staemco', + 'oferta' + ]); + const lowKeywords = (0, _retrie.createRetrieKeywordFilter)([ + 'transactions-', + 'payment', + 'wallet', + '-transactions', + '-faceb', + '.faceb', + 'facebook', + 'virus-', + 'icloud-', + 'apple-', + '-roblox', + '-co-jp', + 'customer.', + 'customer-', + '.www-', + '.www.', + '.www2', + 'instagram', + 'microsof', + 'passwordreset', + '.google-', + 'recover', + 'banking' + ]); + const processPhihsingDomains = (0, _fsmemo.cache)(function processPhihsingDomains(domainArr) { + const domainCountMap = new Map(); + const domainScoreMap = {}; + let line = ''; + let tld = ''; + let apexDomain = ''; + let subdomain = ''; + // const set = new Set(); + // let duplicateCount = 0; + for(let i = 0, len = domainArr.length; i < len; i++){ + line = domainArr[i]; + // if (set.has(line)) { + // duplicateCount++; + // } else { + // set.add(line); + // } + const parsed = _tldtsexperimental.parse(line, _loosetldtsopt.loosTldOptWithPrivateDomains); + if (parsed.isPrivate) { + continue; + } + tld = parsed.publicSuffix; + apexDomain = parsed.domain; + if (!tld) { + console.log(_picocolors.default.yellow('[phishing domains] E0001'), 'missing tld', { + line, + tld + }); + continue; + } + if (!apexDomain) { + console.log(_picocolors.default.yellow('[phishing domains] E0002'), 'missing domain', { + line, + apexDomain + }); + continue; + } + domainCountMap.set(apexDomain, domainCountMap.has(apexDomain) ? domainCountMap.get(apexDomain) + 1 : 1); + if (!(apexDomain in domainScoreMap)) { + domainScoreMap[apexDomain] = 0; + if (BLACK_TLD.has(tld)) { + domainScoreMap[apexDomain] += 3; + } else if (tld.length > 6) { + domainScoreMap[apexDomain] += 2; + } + if (apexDomain.length >= 18) { + domainScoreMap[apexDomain] += 0.5; + } + } + subdomain = parsed.subdomain; + if (subdomain && !WHITELIST_MAIN_DOMAINS.has(apexDomain)) { + domainScoreMap[apexDomain] += calcDomainAbuseScore(subdomain, line); + } + } + domainCountMap.forEach((count, apexDomain)=>{ + if (// !WHITELIST_MAIN_DOMAINS.has(apexDomain) + domainScoreMap[apexDomain] >= 24 || domainScoreMap[apexDomain] >= 16 && count >= 7 || domainScoreMap[apexDomain] >= 13 && count >= 11 || domainScoreMap[apexDomain] >= 5 && count >= 14 || domainScoreMap[apexDomain] >= 3 && count >= 21 || domainScoreMap[apexDomain] >= 1 && count >= 60) { + domainArr.push('.' + apexDomain); + } + }); + // console.log({ + // score: domainScoreMap['awicksin.com'], + // count: domainCountMap.get('awicksin.com') + // }); + // console.log({ duplicateCount, domainArrLen: domainArr.length }); + return domainArr; + }, { + serializer: _cachefilesystem.serializeArray, + deserializer: _cachefilesystem.deserializeArray, + temporaryBypass: !_ciinfo.isCI || _rejectdatasource.DEBUG_DOMAIN_TO_FIND !== null + }); + const downloads = [ + ..._rejectdatasource.PHISHING_DOMAIN_LISTS_EXTRA.map((entry)=>(0, _domainlists.processDomainListsWithPreload)(...entry)), + ..._rejectdatasource.PHISHING_HOSTS_EXTRA.map((entry)=>(0, _hosts.processHostsWithPreload)(...entry)) + ]; + function getPhishingDomains(parentSpan) { + return parentSpan.traceChild('get phishing domains').traceAsyncFn(async (span)=>{ + const domainArr = await span.traceChildAsync('download/parse/merge phishing domains', async (curSpan)=>{ + const domainArr = []; + const domainGroups = await Promise.all(downloads.map((task)=>task(curSpan))); + domainGroups.forEach((0, _appendarrayinplace.appendArrayInPlaceCurried)(domainArr)); + return domainArr; + }); + return span.traceChildAsync('process phishing domain set', ()=>processPhihsingDomains(domainArr)); + }); + } + function calcDomainAbuseScore(subdomain, fullDomain = subdomain) { + if (leathalKeywords(fullDomain)) { + return 100; + } + let weight = 0; + const hitLowKeywords = lowKeywords(fullDomain); + const sensitiveKeywordsHit = sensitiveKeywords(fullDomain); + if (sensitiveKeywordsHit) { + weight += 10; + if (hitLowKeywords) { + weight += 6; + } + } else if (hitLowKeywords) { + weight += 1.7; + } + const subdomainLength = subdomain.length; + if (subdomainLength > 6) { + weight += 0.015; + if (subdomainLength > 13) { + weight += 0.2; + if (subdomainLength > 20) { + weight += 1; + if (subdomainLength > 30) { + weight += 5; + if (subdomainLength > 40) { + weight += 10; + } + } + } + if (subdomain.indexOf('.', 1) > 1) { + weight += 1; + } + } + } + return weight; + } + if (require.main === module) { + getPhishingDomains(_trace.dummySpan).catch(console.error).finally(()=>{ + _trace.dummySpan.stop(); + (0, _trace.printTraceResult)(_trace.dummySpan.traceResult); + }); + } + } (getPhishingDomains, getPhishingDomains.exports)); + return getPhishingDomains.exports; +}var hasRequiredBuildRejectDomainset; + +function requireBuildRejectDomainset () { + if (hasRequiredBuildRejectDomainset) return buildRejectDomainset.exports; + hasRequiredBuildRejectDomainset = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildRejectDomainSet", { + enumerable: true, + get: function() { + return buildRejectDomainSet; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _nodeprocess = /*#__PURE__*/ _interop_require_default(require$$1); + const _hosts = /*@__PURE__*/ requireHosts(); + const _domainlists = /*@__PURE__*/ requireDomainlists(); + const _filters = /*@__PURE__*/ requireFilters(); + const _rejectdatasource = /*@__PURE__*/ rejectDataSource.r(); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _trace = /*@__PURE__*/ index.r(); + const _description = /*@__PURE__*/ base.r(); + const _getphishingdomains = /*@__PURE__*/ requireGetPhishingDomains(); + const _addarrayelementstoset = require$$10; + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _domainset = /*@__PURE__*/ domainset.r(); + const _shared = /*@__PURE__*/ requireShared(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const readLocalRejectDomainsetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/reject_sukka.conf')); + const readLocalRejectExtraDomainsetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/reject_sukka_extra.conf')); + const readLocalRejectRulesetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip/reject.conf')); + const readLocalRejectDropRulesetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip/reject-drop.conf')); + const readLocalRejectNoDropRulesetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip/reject-no-drop.conf')); + const readLocalMyRejectRulesetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip/my_reject.conf')); + const hostsDownloads = _rejectdatasource.HOSTS.map((entry)=>(0, _hosts.processHostsWithPreload)(...entry)); + const hostsExtraDownloads = _rejectdatasource.HOSTS_EXTRA.map((entry)=>(0, _hosts.processHostsWithPreload)(...entry)); + const domainListsDownloads = _rejectdatasource.DOMAIN_LISTS.map((entry)=>(0, _domainlists.processDomainListsWithPreload)(...entry)); + const domainListsExtraDownloads = _rejectdatasource.DOMAIN_LISTS_EXTRA.map((entry)=>(0, _domainlists.processDomainListsWithPreload)(...entry)); + const adguardFiltersDownloads = _rejectdatasource.ADGUARD_FILTERS.map((entry)=>(0, _filters.processFilterRulesWithPreload)(...entry)); + const adguardFiltersExtraDownloads = _rejectdatasource.ADGUARD_FILTERS_EXTRA.map((entry)=>(0, _filters.processFilterRulesWithPreload)(...entry)); + const adguardFiltersWhitelistsDownloads = _rejectdatasource.ADGUARD_FILTERS_WHITELIST.map((entry)=>(0, _filters.processFilterRulesWithPreload)(...entry)); + const buildRejectDomainSet = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const rejectBaseDescription = [ + ..._description.SHARED_DESCRIPTION, + '', + 'The domainset supports AD blocking, tracking protection, privacy protection, anti-phishing, anti-mining', + '', + 'Build from:', + ..._rejectdatasource.HOSTS.map((host)=>` - ${host[0]}`), + ..._rejectdatasource.DOMAIN_LISTS.map((domainList)=>` - ${domainList[0]}`), + ..._rejectdatasource.ADGUARD_FILTERS.map((filter)=>` - ${Array.isArray(filter) ? filter[0] : filter}`) + ]; + const rejectOutput = new _domainset.DomainsetOutput(span, 'reject').withTitle('Sukka\'s Ruleset - Reject Base').withDescription(rejectBaseDescription); + const rejectExtraOutput = new _domainset.DomainsetOutput(span, 'reject_extra').withTitle('Sukka\'s Ruleset - Reject Extra').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'The domainset supports AD blocking, tracking protection, privacy protection, anti-phishing, anti-mining', + '', + 'Build from:', + ..._rejectdatasource.HOSTS_EXTRA.map((host)=>` - ${host[0]}`), + ..._rejectdatasource.DOMAIN_LISTS_EXTRA.map((domainList)=>` - ${domainList[0]}`), + ..._rejectdatasource.ADGUARD_FILTERS_EXTRA.map((filter)=>` - ${Array.isArray(filter) ? filter[0] : filter}`), + ..._rejectdatasource.PHISHING_DOMAIN_LISTS_EXTRA.map((domainList)=>` - ${domainList[0]}`) + ]); + const appendArrayToRejectOutput = rejectOutput.addFromDomainset.bind(rejectOutput); + const appendArrayToRejectExtraOutput = rejectExtraOutput.addFromDomainset.bind(rejectExtraOutput); + /** Whitelists */ const filterRuleWhitelistDomainSets = new Set(_rejectdatasource.PREDEFINED_WHITELIST); + // Parse from AdGuard Filters + await span.traceChild('download and process hosts / adblock filter rules').traceAsyncFn((childSpan)=>Promise.all([ + // Parse from remote hosts & domain lists + hostsDownloads.map((task)=>task(childSpan).then(appendArrayToRejectOutput)), + hostsExtraDownloads.map((task)=>task(childSpan).then(appendArrayToRejectExtraOutput)), + domainListsDownloads.map((task)=>task(childSpan).then(appendArrayToRejectOutput)), + domainListsExtraDownloads.map((task)=>task(childSpan).then(appendArrayToRejectExtraOutput)), + adguardFiltersDownloads.map((task)=>task(childSpan).then(({ whiteDomains, whiteDomainSuffixes, blackDomains, blackDomainSuffixes })=>{ + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomains); + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomainSuffixes, (suffix)=>'.' + suffix); + rejectOutput.bulkAddDomain(blackDomains); + rejectOutput.bulkAddDomainSuffix(blackDomainSuffixes); + })), + adguardFiltersExtraDownloads.map((task)=>task(childSpan).then(({ whiteDomains, whiteDomainSuffixes, blackDomains, blackDomainSuffixes })=>{ + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomains); + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomainSuffixes, (suffix)=>'.' + suffix); + rejectExtraOutput.bulkAddDomain(blackDomains); + rejectExtraOutput.bulkAddDomainSuffix(blackDomainSuffixes); + })), + adguardFiltersWhitelistsDownloads.map((task)=>task(childSpan).then(({ whiteDomains, whiteDomainSuffixes, blackDomains, blackDomainSuffixes })=>{ + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomains); + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomainSuffixes, (suffix)=>'.' + suffix); + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, blackDomains); + (0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, blackDomainSuffixes, (suffix)=>'.' + suffix); + })), + (0, _getphishingdomains.getPhishingDomains)(childSpan).then(appendArrayToRejectExtraOutput), + readLocalRejectDomainsetPromise.then(appendArrayToRejectOutput), + readLocalRejectDomainsetPromise.then(appendArrayToRejectExtraOutput), + readLocalRejectExtraDomainsetPromise.then(appendArrayToRejectExtraOutput), + // Dedupe domainSets + // span.traceChildAsync('collect black keywords/suffixes', async () => + /** + * Collect DOMAIN, DOMAIN-SUFFIX, and DOMAIN-KEYWORD from non_ip/reject.conf for deduplication + * DOMAIN-WILDCARD is not really useful for deduplication, it is only included in AdGuardHome output + */ rejectOutput.addFromRuleset(readLocalRejectRulesetPromise), + rejectExtraOutput.addFromRuleset(readLocalRejectRulesetPromise) + ].flat())); + if (_shared.foundDebugDomain.value) { + // eslint-disable-next-line sukka/unicorn/no-process-exit -- cli App + _nodeprocess.default.exit(1); + } + await Promise.all([ + rejectOutput.done(), + rejectExtraOutput.done() + ]); + // whitelist + span.traceChildSync('whitelist', ()=>{ + for (const domain of filterRuleWhitelistDomainSets){ + rejectOutput.whitelistDomain(domain); + rejectExtraOutput.whitelistDomain(domain); + } + rejectOutput.domainTrie.dump(rejectExtraOutput.whitelistDomain.bind(rejectExtraOutput)); + }); + await Promise.all([ + rejectOutput.write(), + rejectExtraOutput.write() + ]); + // we are going to re-use rejectOutput's domainTrie and mutate it + // so we must wait until we write rejectOutput to disk after we can mutate its trie + const rejectOutputAdGuardHome = new _domainset.AdGuardHomeOutput(span, 'reject-adguardhome', _dir.OUTPUT_INTERNAL_DIR).withTitle('Sukka\'s Ruleset - Blocklist for AdGuardHome').withDescription([ + 'The domainset supports AD blocking, tracking protection, privacy protection, anti-phishing, anti-mining' + ]); + rejectOutputAdGuardHome.domainTrie = rejectOutput.domainTrie; + await rejectOutputAdGuardHome.addFromRuleset(readLocalMyRejectRulesetPromise).addFromRuleset(readLocalRejectRulesetPromise).addFromRuleset(readLocalRejectDropRulesetPromise).addFromRuleset(readLocalRejectNoDropRulesetPromise).write(); + }); + } (buildRejectDomainset, buildRejectDomainset.exports)); + return buildRejectDomainset.exports; +}exports.r=requireBuildRejectDomainset; \ No newline at end of file diff --git a/Dist/chunks/build-reject-ip-list.D6Cjv0d8.cjs b/Dist/chunks/build-reject-ip-list.D6Cjv0d8.cjs new file mode 100644 index 00000000..bfe08a62 --- /dev/null +++ b/Dist/chunks/build-reject-ip-list.D6Cjv0d8.cjs @@ -0,0 +1,145 @@ +'use strict';const require$$0=require('node:path'),fetchTextByLine=require('./fetch-text-by-line.YY5b5610.cjs'),index=require('./index.B8Uk9n3v.cjs'),base=require('./base.C13YY5P3.cjs'),createFile=require('./create-file.loOMbJEN.cjs'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),fetchAssets=require('./fetch-assets.aqw2YOi8.cjs'),misc=require('./misc.BpcQjda1.cjs'),ruleset=require('./ruleset.iYH0XOC1.cjs');var buildRejectIpList = {exports: {}};var badboy_asn = {};var hasRequiredBadboy_asn; + +function requireBadboy_asn () { + if (hasRequiredBadboy_asn) return badboy_asn; + hasRequiredBadboy_asn = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + AUGUST_ASN: function() { + return AUGUST_ASN; + }, + HUIZE_ASN: function() { + return HUIZE_ASN; + } + }); + const AUGUST_ASN = [ + '1012', + '945', + '401111', + '62853', + '27523', + '7719', + '54625', + '7257', + '18044', + '62489', + '5111', + '14651', + '7480' // Friend of August, stealing others' XC at STUIX + ]; + const HUIZE_ASN = [ + '61302', + '44324', + '53808', + '60539', + '60842', + '140915', + '40115' // MoeDove + ]; + } (badboy_asn)); + return badboy_asn; +}var hasRequiredBuildRejectIpList; + +function requireBuildRejectIpList () { + if (hasRequiredBuildRejectIpList) return buildRejectIpList.exports; + hasRequiredBuildRejectIpList = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildRejectIPList", { + enumerable: true, + get: function() { + return buildRejectIPList; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _trace = /*@__PURE__*/ index.r(); + const _description = /*@__PURE__*/ base.r(); + const _createfile = /*@__PURE__*/ createFile.r(); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _fetchretry = /*@__PURE__*/ fetchRetry.r(); + const _fetchassets = /*@__PURE__*/ fetchAssets.r(); + const _misc = /*@__PURE__*/ misc.r(); + const _badboy_asn = /*@__PURE__*/ requireBadboy_asn(); + const _ruleset = /*@__PURE__*/ ruleset.r(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const BOGUS_NXDOMAIN_URL = 'https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/bogus-nxdomain.china.conf'; + const getBogusNxDomainIPsPromise = (0, _fetchretry.$$fetch)(BOGUS_NXDOMAIN_URL).then(async (resp)=>{ + const ipv4 = []; + const ipv6 = []; + for await (const line of (0, _fetchtextbyline.createReadlineInterfaceFromResponse)(resp, true)){ + if (line.startsWith('bogus-nxdomain=')) { + const ip = line.slice(15).trim(); + const v = (0, _misc.fastIpVersion)(ip); + if (v === 4) { + ipv4.push(ip); + } else if (v === 6) { + ipv6.push(ip); + } + } + } + return [ + ipv4, + ipv6 + ]; + }); + const BOTNET_FILTER_URL = 'https://malware-filter.pages.dev/botnet-filter-dnscrypt-blocked-ips.txt'; + const BOTNET_FILTER_MIRROR_URL = [ + 'https://botnet-filter.pages.dev/botnet-filter-dnscrypt-blocked-ips.txt', + 'https://malware-filter.gitlab.io/malware-filter/botnet-filter-dnscrypt-blocked-ips.txt', + 'https://malware-filter.gitlab.io/botnet-filter/botnet-filter-dnscrypt-blocked-ips.txt' + ]; + const getBotNetFilterIPsPromise = (0, _fetchassets.fetchAssets)(BOTNET_FILTER_URL, BOTNET_FILTER_MIRROR_URL, true).then((arr)=>arr.reduce((acc, ip)=>{ + const v = (0, _misc.fastIpVersion)(ip); + if (v === 4) { + acc[0].push(ip); + } else if (v === 6) { + acc[1].push(ip); + } + return acc; + }, [ + [], + [] + ])); + const readLocalRejectIpListPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.resolve(_dir.SOURCE_DIR, 'ip/reject.conf')); + const buildRejectIPList = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const [bogusNxDomainIPs, botNetIPs] = await Promise.all([ + span.traceChildPromise('get bogus nxdomain ips', getBogusNxDomainIPsPromise), + span.traceChildPromise('get botnet ips', getBotNetFilterIPsPromise) + ]); + return Promise.all([ + new _ruleset.RulesetOutput(span, 'reject', 'ip').withTitle('Sukka\'s Ruleset - Anti Bogus Domain').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains known addresses that are hijacking NXDOMAIN results returned by DNS servers, and botnet controller IPs.', + '', + 'Data from:', + ' - https://github.com/felixonmars/dnsmasq-china-list', + ' - https://github.com/curbengh/botnet-filter' + ]).addFromRuleset(readLocalRejectIpListPromise).bulkAddCIDR4NoResolve(bogusNxDomainIPs[0]).bulkAddCIDR6NoResolve(bogusNxDomainIPs[1]).bulkAddCIDR4NoResolve(botNetIPs[0]).bulkAddCIDR6NoResolve(botNetIPs[1]).bulkAddIPASN(_badboy_asn.AUGUST_ASN).bulkAddIPASN(_badboy_asn.HUIZE_ASN).write(), + (0, _createfile.compareAndWriteFile)(span, [ + _badboy_asn.AUGUST_ASN.join(' ') + ], _nodepath.default.join(_dir.OUTPUT_INTERNAL_DIR, 'august_asn.txt')), + (0, _createfile.compareAndWriteFile)(span, [ + _badboy_asn.HUIZE_ASN.join(' ') + ], _nodepath.default.join(_dir.OUTPUT_INTERNAL_DIR, 'huize_asn.txt')) + ]); + }); + } (buildRejectIpList, buildRejectIpList.exports)); + return buildRejectIpList.exports; +}exports.r=requireBuildRejectIpList; \ No newline at end of file diff --git a/Dist/chunks/build-sgmodule-always-realip.CuBgClIT.cjs b/Dist/chunks/build-sgmodule-always-realip.CuBgClIT.cjs new file mode 100644 index 00000000..8b1bf388 --- /dev/null +++ b/Dist/chunks/build-sgmodule-always-realip.CuBgClIT.cjs @@ -0,0 +1,136 @@ +'use strict';const require$$0=require('node:path'),index=require('./index.B8Uk9n3v.cjs'),createFile=require('./create-file.loOMbJEN.cjs'),buildDomesticDirectLanRulesetDnsMappingModule=require('./build-domestic-direct-lan-ruleset-dns-mapping-module.T1tgVza_.cjs'),require$$8=require('yaml'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),base=require('./base.C13YY5P3.cjs');var buildSgmoduleAlwaysRealip = {exports: {}};var hasRequiredBuildSgmoduleAlwaysRealip; + +function requireBuildSgmoduleAlwaysRealip () { + if (hasRequiredBuildSgmoduleAlwaysRealip) return buildSgmoduleAlwaysRealip.exports; + hasRequiredBuildSgmoduleAlwaysRealip = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildAlwaysRealIPModule", { + enumerable: true, + get: function() { + return buildAlwaysRealIPModule; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _trace = /*@__PURE__*/ index.r(); + const _createfile = /*@__PURE__*/ createFile.r(); + const _direct = /*@__PURE__*/ buildDomesticDirectLanRulesetDnsMappingModule.a(); + const _domestic = /*@__PURE__*/ buildDomesticDirectLanRulesetDnsMappingModule.b(); + const _yaml = /*#__PURE__*/ _interop_require_wildcard(require$$8); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _appendarrayinplace = /*@__PURE__*/ base.a(); + const _description = /*@__PURE__*/ base.r(); + const _builddomesticdirectlanrulesetdnsmappingmodule = buildDomesticDirectLanRulesetDnsMappingModule.r(); + const _clash = /*@__PURE__*/ base.c(); + const _base = /*@__PURE__*/ base.b(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); + } + function _interop_require_wildcard(obj, nodeInterop) { + if (obj && obj.__esModule) { + return obj; + } + if (obj === null || typeof obj !== "object" && typeof obj !== "function") { + return { + default: obj + }; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = { + __proto__: null + }; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; + } + const HOSTNAMES = [ + // Network Detection, Captive Portal + 'dns.msftncsi.com', + // '*.msftconnecttest.com', + // 'network-test.debian.org', + // 'detectportal.firefox.com', + // Handle SNAT conversation properly + '*.srv.nintendo.net', + '*.stun.playstation.net', + 'xbox.*.microsoft.com', + '*.xboxlive.com', + '*.turn.twilio.com', + '*.stun.twilio.com', + 'stun.syncthing.net', + 'stun.*' + ]; + const buildAlwaysRealIPModule = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const surge = []; + const clashFakeIpFilter = new _base.FileOutput(span, 'clash_fake_ip_filter').withTitle('Sukka\'s Ruleset - Always Real IP Plus').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'Clash.Meta fake-ip-filter as ruleset' + ]).withStrategies([ + new _clash.ClashDomainSet('domainset') + ]); + // Intranet, Router Setup, and mant more + const dataset = [ + _direct.DIRECTS, + _direct.LAN, + _domestic.DOMESTICS, + _domestic.DOH_BOOTSTRAP + ].reduce((acc, item)=>{ + Object.values(item).forEach((i)=>{ + if (i.realip) { + acc.push(i); + } + }); + return acc; + }, []); + const getDnsMappingRuleWithoutWildcard = (0, _builddomesticdirectlanrulesetdnsmappingmodule.createGetDnsMappingRule)(false); + for (const { domains } of dataset){ + clashFakeIpFilter.addFromRuleset(domains.flatMap(getDnsMappingRuleWithoutWildcard)); + } + return Promise.all([ + (0, _createfile.compareAndWriteFile)(span, [ + '#!name=[Sukka] Always Real IP Plus', + `#!desc=Last Updated: ${new Date().toISOString()}`, + '', + '[General]', + `always-real-ip = %APPEND% ${HOSTNAMES.concat(surge).join(', ')}` + ], _nodepath.default.resolve(_dir.OUTPUT_MODULES_DIR, 'sukka_common_always_realip.sgmodule')), + (0, _createfile.compareAndWriteFile)(span, _yaml.stringify({ + dns: { + 'fake-ip-filter': (0, _appendarrayinplace.appendArrayInPlace)(/** clash */ dataset.flatMap(({ domains })=>domains.map((domain)=>`+.${domain}`)), HOSTNAMES) + } + }, { + version: '1.1' + }).split('\n'), _nodepath.default.join(_dir.OUTPUT_INTERNAL_DIR, 'clash_fake_ip_filter.yaml')) + ]); + }); + } (buildSgmoduleAlwaysRealip, buildSgmoduleAlwaysRealip.exports)); + return buildSgmoduleAlwaysRealip.exports; +}exports.r=requireBuildSgmoduleAlwaysRealip; \ No newline at end of file diff --git a/Dist/chunks/build-sgmodule-redirect.iquVSpqW.cjs b/Dist/chunks/build-sgmodule-redirect.iquVSpqW.cjs new file mode 100644 index 00000000..c4586bfa --- /dev/null +++ b/Dist/chunks/build-sgmodule-redirect.iquVSpqW.cjs @@ -0,0 +1,508 @@ +'use strict';const require$$0=require('node:path'),index=require('./index.B8Uk9n3v.cjs'),createFile=require('./create-file.loOMbJEN.cjs'),require$$5=require('tldts-experimental'),require$$6=require('foxts/guard'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs');var buildSgmoduleRedirect = {exports: {}};var hasRequiredBuildSgmoduleRedirect; + +function requireBuildSgmoduleRedirect () { + if (hasRequiredBuildSgmoduleRedirect) return buildSgmoduleRedirect.exports; + hasRequiredBuildSgmoduleRedirect = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildRedirectModule", { + enumerable: true, + get: function() { + return buildRedirectModule; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _trace = /*@__PURE__*/ index.r(); + const _createfile = /*@__PURE__*/ createFile.r(); + const _tldtsexperimental = require$$5; + const _guard = require$$6; + const _dir = /*@__PURE__*/ fetchRetry.a(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function escapeRegExp(string = '') { + const reRegExpChar = /[$()*+.?[\\\]^{|}]/g; + const reHasRegExpChar = new RegExp(reRegExpChar.source); + return string && reHasRegExpChar.test(string) ? string.replaceAll(reRegExpChar, String.raw`\$&`) : string; + } + const REDIRECT_MIRROR_HEADER = [ + // Gravatar + [ + 'gravatar.neworld.org/', + 'https://secure.gravatar.com/' + ], + [ + 'cdn.v2ex.com/gravatar/', + 'https://secure.gravatar.com/avatar/' + ], + // U.SB + [ + 'cdnjs.loli.net/', + 'https://cdnjs.cloudflare.com/' + ], + [ + 'fonts.loli.net/', + 'https://fonts.googleapis.com/' + ], + [ + 'gstatic.loli.net/', + 'https://fonts.gstatic.com/' + ], + [ + 'themes.loli.net/', + 'https://themes.googleusercontent.com/' + ], + [ + 'ajax.loli.net/', + 'https://ajax.googleapis.com/' + ], + [ + 'gravatar.loli.net/', + 'https://secure.gravatar.com/' + ], + // Geekzu + [ + 'gapis.geekzu.org/ajax/', + 'https://ajax.googleapis.com/' + ], + [ + 'fonts.geekzu.org/', + 'https://fonts.googleapis.com/' + ], + [ + 'gapis.geekzu.org/g-fonts/', + 'https://fonts.gstatic.com/' + ], + [ + 'gapis.geekzu.org/g-themes/', + 'https://themes.googleusercontent.com/' + ], + [ + 'sdn.geekzu.org/', + 'https://secure.gravatar.com/' + ], + // libravatar + [ + 'seccdn.libravatar.org/gravatarproxy/', + 'https://secure.gravatar.com/' + ], + // gh-proxy + [ + 'github.moeyy.xyz/', + 'https://' + ], + // 7ED Services + [ + 'use.sevencdn.com/css', + 'https://fonts.googleapis.com/css' + ], + [ + 'use.sevencdn.com/ajax/libs/', + 'https://cdnjs.cloudflare.com/ajax/libs/' + ], + [ + 'use.sevencdn.com/gajax/', + 'https://ajax.googleapis.com/ajax/' + ], + [ + 'use.sevencdn.com/chart', + 'https://chart.googleapis.com/chart' + ], + [ + 'use.sevencdn.com/avatar', + 'https://secure.gravatar.com/avatar' + ], + [ + 'raw.gitmirror.com/', + 'https://raw.githubusercontent.com/' + ], + [ + 'gist.gitmirror.com/', + 'https://gist.githubusercontent.com/' + ], + [ + 'raw.githubusercontents.com/', + 'https://raw.githubusercontent.com/' + ], + [ + 'gist.githubusercontents.com/', + 'https://gist.githubusercontent.com/' + ], + [ + 'cdn.gitmirror.com/', + 'https://cdn.statically.io/' + ], + // FastGit + [ + 'raw.fastgit.org/', + 'https://raw.githubusercontent.com/' + ], + // ['assets.fastgit.org/', 'https://github.githubassets.com/'], + // jsDelivr + [ + 'fastly.jsdelivr.net/', + 'https://cdn.jsdelivr.net/' + ], + [ + 'gcore.jsdelivr.net/', + 'https://cdn.jsdelivr.net/' + ], + [ + 'testingcf.jsdelivr.net/', + 'https://cdn.jsdelivr.net/' + ], + // JSDMirror + [ + 'cdn.jsdmirror.com/', + 'https://cdn.jsdelivr.net/' + ], + [ + 'cdn.jsdmirror.cn/', + 'https://cdn.jsdelivr.net/' + ], + // onmicrosoft.cn + [ + 'jsd.onmicrosoft.cn/', + 'https://cdn.jsdelivr.net/' + ], + [ + 'npm.onmicrosoft.cn/', + 'https://unpkg.com/' + ], + [ + 'cdnjs.onmicrosoft.cn/', + 'https://cdnjs.cloudflare.com/ajax/libs/' + ], + // KGitHub + [ + 'raw.kgithub.com/', + 'https://raw.githubusercontent.com/' + ], + [ + 'raw.kkgithub.com/', + 'https://raw.githubusercontent.com/' + ], + // cdn.iocdn.cc + [ + 'cdn.iocdn.cc/avatar/', + 'https://secure.gravatar.com/avatar/' + ], + [ + 'cdn.iocdn.cc/css', + 'https://fonts.googleapis.com/css' + ], + [ + 'cdn.iocdn.cc/icon', + 'https://fonts.googleapis.com/icon' + ], + [ + 'cdn.iocdn.cc/earlyaccess', + 'https://fonts.googleapis.com/earlyaccess' + ], + [ + 'cdn.iocdn.cc/s', + 'fonts.gstatic.com/s' + ], + [ + 'cdn.iocdn.cc/static', + 'themes.googleusercontent.com/static' + ], + [ + 'cdn.iocdn.cc/ajax', + 'ajax.googleapis.com/ajax' + ], + [ + 'cdn.iocdn.cc/', + 'https://cdn.jsdelivr.net/' + ], + // wp-china-yes + [ + 'googlefonts.admincdn.com/', + 'https://fonts.googleapis.com/' + ], + [ + 'googleajax.admincdn.com/', + 'https://ajax.googleapis.com/' + ], + [ + 'cdnjs.admincdn.com/', + 'https://cdnjs.cloudflare.com/ajax/libs/' + ], + // Polyfill + [ + 'polyfill.io/', + 'https://cdnjs.cloudflare.com/polyfill/' + ], + [ + 'polyfill.top/', + 'https://cdnjs.cloudflare.com/polyfill/' + ], + [ + 'polyfill-js.cn/', + 'https://cdnjs.cloudflare.com/polyfill/' + ], + [ + 'cdn.polyfill.io/', + 'https://cdnjs.cloudflare.com/polyfill/' + ], + [ + 'fastly-polyfill.io/', + 'https://cdnjs.cloudflare.com/polyfill/' + ], + [ + 'fastly-polyfill.net/', + 'https://cdnjs.cloudflare.com/polyfill/' + ], + // BootCDN has been controlled by a malicious actor and being used to spread malware + [ + 'cdn.bootcss.com/', + 'https://cdnjs.cloudflare.com/ajax/libs/' + ], + [ + 'cdn.bootcdn.net/', + 'https://cdnjs.cloudflare.com/ajax/libs/' + ], + [ + 'cdn.staticfile.net/', + 'https://cdnjs.cloudflare.com/ajax/libs/' + ], + [ + 'cdn.staticfile.org/', + 'https://cdnjs.cloudflare.com/ajax/libs/' + ], + // Misc + [ + 'pics.javbus.com/', + 'https://i0.wp.com/pics.javbus.com/' + ] + ]; + const REDIRECT_MIRROR_307 = [ + // Redirect Google + [ + 'google.cn/', + 'https://google.com/' + ], + [ + 'www.google.cn/', + 'https://www.google.com/' + ], + [ + 'g.cn/', + 'https://google.com/' + ], + [ + 'ditu.google.cn/', + 'https://maps.google.com/' + ], + [ + 'maps.google.cn/', + 'https://maps.google.com/' + ], + [ + 'www.g.cn/', + 'https://www.google.com/' + ], + // avg.tv/sm114514 -> https://www.nicovideo.jp/watch/sm114514 + [ + 'acg.tv/sm', + 'https://www.nicovideo.jp/watch/sm' + ], + [ + 'acg.tv/', + 'https://b23.tv/' + ], + // Minecraft Wiki + [ + 'minecraft.fandom.com/wiki/', + 'https://minecraft.wiki/w/' + ], + [ + 'minecraft.fandom.com/', + 'https://minecraft.wiki/' + ], + [ + 'missav.com/', + 'https://missav.ws/' + ] + ]; + const REDIRECT_FAKEWEBSITES = [ + // IGN China to IGN Global + [ + 'ign.xn--fiqs8s', + 'https://cn.ign.com/ccpref/us' + ], + // Fuck Makeding + [ + 'abbyychina.com', + 'https://www.abbyy.cn' + ], + [ + 'bartender.cc', + 'https://cn.seagullscientific.com' + ], + [ + 'betterzip.net', + 'https://macitbetter.com' + ], + [ + 'beyondcompare.cc', + 'https://www.scootersoftware.com' + ], + [ + 'bingdianhuanyuan.cn', + 'https://www.faronics.com' + ], + [ + 'chemdraw.com.cn', + 'https://revvitysignals.com/products/research/chemdraw' + ], + [ + 'codesoftchina.com', + 'https://www.teklynx.com' + ], + [ + 'coreldrawchina.com', + 'https://www.coreldraw.com' + ], + [ + 'crossoverchina.com', + 'https://www.codeweavers.com' + ], + [ + 'easyrecoverychina.com', + 'https://www.ontrack.com' + ], + [ + 'ediuschina.com', + 'https://www.grassvalley.com' + ], + [ + 'flstudiochina.com', + 'https://www.image-line.com/fl-studio' + ], + [ + 'formysql.com', + 'https://www.navicat.com.cn' + ], + [ + 'guitarpro.cc', + 'https://www.guitar-pro.com' + ], + [ + 'huishenghuiying.com.cn', + 'https://www.corel.com' + ], + [ + 'iconworkshop.cn', + 'https://www.axialis.com/iconworkshop' + ], + [ + 'imindmap.cc', + 'https://imindmap.com/zh-cn' + ], + [ + 'jihehuaban.com.cn', + 'https://sketch.io' + ], + [ + 'keyshot.cc', + 'https://www.keyshot.com' + ], + [ + 'mathtype.cn', + 'https://www.wiris.com/en/mathtype' + ], + [ + 'mindmanager.cc', + 'https://www.mindjet.com' + ], + [ + 'mindmapper.cc', + 'https://mindmapper.com' + ], + [ + 'mycleanmymac.com', + 'https://macpaw.com/cleanmymac' + ], + [ + 'nicelabel.cc', + 'https://www.nicelabel.com' + ], + [ + 'ntfsformac.cc', + 'https://www.tuxera.com/products/tuxera-ntfs-for-mac-cn' + ], + [ + 'ntfsformac.cn', + 'https://www.paragon-software.com/ufsdhome/zh/ntfs-mac' + ], + [ + 'overturechina.com', + 'https://sonicscores.com/overture' + ], + [ + 'passwordrecovery.cn', + 'https://cn.elcomsoft.com/aopr.html' + ], + [ + 'pdfexpert.cc', + 'https://pdfexpert.com/zh' + ], + [ + 'ultraiso.net', + 'https://cn.ezbsystems.com/ultraiso' + ], + [ + 'vegaschina.cn', + 'https://www.vegas.com' + ], + [ + 'xmindchina.net', + 'https://www.xmind.cn' + ], + [ + 'xshellcn.com', + 'https://www.netsarang.com/products/xsh_overview.html' + ], + [ + 'yuanchengxiezuo.com', + 'https://www.teamviewer.com/zhcn' + ], + [ + 'zbrushcn.com', + 'https://www.maxon.net/en/zbrush' + ] + ]; + const buildRedirectModule = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const domains = Array.from(new Set([ + ...REDIRECT_MIRROR_HEADER.map(([from])=>(0, _tldtsexperimental.getHostname)(from, { + detectIp: false + })), + ...REDIRECT_FAKEWEBSITES.flatMap(([from])=>[ + from, + `*.${from}` + ]), + ...REDIRECT_MIRROR_307.map(([from])=>(0, _tldtsexperimental.getHostname)(from, { + detectIp: false + })) + ])).filter(_guard.isTruthy); + return (0, _createfile.compareAndWriteFile)(span, [ + '#!name=[Sukka] URL Redirect', + `#!desc=Last Updated: ${new Date().toISOString()} Size: ${domains.length}`, + '', + '[MITM]', + `hostname = %APPEND% ${domains.join(', ')}`, + '', + '[URL Rewrite]', + ...REDIRECT_MIRROR_HEADER.map(([from, to])=>`^https?://${escapeRegExp(from)}(.*) ${to}$1 header`), + ...REDIRECT_FAKEWEBSITES.map(([from, to])=>`^https?://(www.)?${escapeRegExp(from)} ${to} 307`), + ...REDIRECT_MIRROR_307.map(([from, to])=>`^https?://${escapeRegExp(from)}(.*) ${to}$1 307`) + ], _nodepath.default.join(_dir.OUTPUT_MODULES_DIR, 'sukka_url_redirect.sgmodule')); + }); + } (buildSgmoduleRedirect, buildSgmoduleRedirect.exports)); + return buildSgmoduleRedirect.exports; +}exports.r=requireBuildSgmoduleRedirect; \ No newline at end of file diff --git a/Dist/chunks/build-speedtest-domainset.D2jYMvWN.cjs b/Dist/chunks/build-speedtest-domainset.D2jYMvWN.cjs new file mode 100644 index 00000000..7e0b834f --- /dev/null +++ b/Dist/chunks/build-speedtest-domainset.D2jYMvWN.cjs @@ -0,0 +1,113 @@ +'use strict';const require$$0=require('node:path'),require$$5=require('tldts-experimental'),index=require('./index.B8Uk9n3v.cjs'),base=require('./base.C13YY5P3.cjs'),fetchTextByLine=require('./fetch-text-by-line.YY5b5610.cjs'),domainset=require('./domainset.CSQfKAtf.cjs'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),require$$7=require('@henrygd/queue');var buildSpeedtestDomainset = {exports: {}};var hasRequiredBuildSpeedtestDomainset; + +function requireBuildSpeedtestDomainset () { + if (hasRequiredBuildSpeedtestDomainset) return buildSpeedtestDomainset.exports; + hasRequiredBuildSpeedtestDomainset = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildSpeedtestDomainSet", { + enumerable: true, + get: function() { + return buildSpeedtestDomainSet; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _tldtsexperimental = /*#__PURE__*/ _interop_require_default(require$$5); + const _trace = /*@__PURE__*/ index.r(); + const _description = /*@__PURE__*/ base.r(); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _domainset = /*@__PURE__*/ domainset.r(); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _queue = require$$7; + const _fetchretry = /*@__PURE__*/ fetchRetry.r(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const KEYWORDS = [ + 'Hong Kong', + 'Taiwan', + 'China Telecom', + 'China Mobile', + 'China Unicom', + 'Japan', + 'Tokyo', + 'Singapore', + 'Korea', + 'Seoul', + 'Canada', + 'Toronto', + 'Montreal', + 'Los Ang', + 'San Jos', + 'Seattle', + 'New York', + 'Dallas', + 'Miami', + 'Berlin', + 'Frankfurt', + 'London', + 'Paris', + 'Amsterdam', + 'Moscow', + 'Australia', + 'Sydney', + 'Brazil', + 'Turkey' + ]; + const s = (0, _queue.newQueue)(2); + const latestTopUserAgentsPromise = (0, _fetchretry.$$fetch)('https://raw.githubusercontent.com/microlinkhq/top-user-agents/master/src/desktop.json').then((res)=>res.json()).then((userAgents)=>userAgents.filter((ua)=>ua.startsWith('Mozilla/5.0 '))); + const getSpeedtestHostsGroupsPromise = Promise.all(KEYWORDS.flatMap(querySpeedtestApi)); + const buildSpeedtestDomainSet = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const output = new _domainset.DomainsetOutput(span, 'speedtest').withTitle('Sukka\'s Ruleset - Speedtest Domains').withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + 'This file contains common speedtest endpoints.' + ]).addFromDomainset((0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.resolve(_dir.SOURCE_DIR, 'domainset/speedtest.conf'))).addFromDomainset((0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, 'domainset/speedtest.conf'))); + const hostnameGroup = await span.traceChildPromise('get speedtest hosts groups', getSpeedtestHostsGroupsPromise); + hostnameGroup.forEach(output.bulkAddDomain.bind(output)); + return output.write(); + }); + async function querySpeedtestApi(keyword) { + const topUserAgents = await latestTopUserAgentsPromise; + const url = `https://www.speedtest.net/api/js/servers?engine=js&search=${keyword}&limit=100`; + try { + const randomUserAgent = topUserAgents[Math.floor(Math.random() * topUserAgents.length)]; + const data = await s.add(()=>(0, _fetchretry.$$fetch)(url, { + headers: { + dnt: '1', + Referer: 'https://www.speedtest.net/', + accept: 'application/json, text/plain, */*', + 'User-Agent': randomUserAgent, + 'Accept-Language': 'en-US,en;q=0.9', + ...randomUserAgent.includes('Chrome') ? { + 'Sec-Ch-Ua-Mobile': '?0', + 'Sec-Fetch-Dest': 'empty', + 'Sec-Fetch-Mode': 'cors', + 'Sec-Fetch-Site': 'same-origin', + 'Sec-Gpc': '1' + } : {} + }, + signal: AbortSignal.timeout(1000 * 60) + }).then((res)=>res.json())); + return data.reduce((prev, cur)=>{ + const hn = _tldtsexperimental.default.getHostname(cur.host || cur.url, { + detectIp: false, + validateHostname: true + }); + if (hn) { + prev.push(hn); + } + return prev; + }, []); + } catch (e) { + console.error(e); + return []; + } + } + } (buildSpeedtestDomainset, buildSpeedtestDomainset.exports)); + return buildSpeedtestDomainset.exports; +}exports.r=requireBuildSpeedtestDomainset; \ No newline at end of file diff --git a/Dist/chunks/build-sspanel-appprofile.DbsFXAyN.cjs b/Dist/chunks/build-sspanel-appprofile.DbsFXAyN.cjs new file mode 100644 index 00000000..26113c36 --- /dev/null +++ b/Dist/chunks/build-sspanel-appprofile.DbsFXAyN.cjs @@ -0,0 +1,217 @@ +'use strict';const buildAppleCdn=require('./build-apple-cdn.CNsnkTO_.cjs'),buildDomesticDirectLanRulesetDnsMappingModule=require('./build-domestic-direct-lan-ruleset-dns-mapping-module.T1tgVza_.cjs'),fetchTextByLine=require('./fetch-text-by-line.YY5b5610.cjs'),index=require('./index.B8Uk9n3v.cjs'),require$$0=require('node:path'),stream=require('./stream.C9eZuk9f.cjs'),buildChnCidr=require('./build-chn-cidr.BjyqKcvm.cjs'),buildTelegramCidr=require('./build-telegram-cidr.05NmRbUx.cjs'),createFile=require('./create-file.loOMbJEN.cjs'),buildMicrosoftCdn=require('./build-microsoft-cdn.CCw86frc.cjs'),require$$6=require('foxts/guard'),base=require('./base.C13YY5P3.cjs'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),ruleset=require('./ruleset.iYH0XOC1.cjs');var buildSspanelAppprofile = {exports: {}};var hasRequiredBuildSspanelAppprofile; + +function requireBuildSspanelAppprofile () { + if (hasRequiredBuildSspanelAppprofile) return buildSspanelAppprofile.exports; + hasRequiredBuildSspanelAppprofile = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildSSPanelUIMAppProfile", { + enumerable: true, + get: function() { + return buildSSPanelUIMAppProfile; + } + }); + const _buildapplecdn = buildAppleCdn.r(); + const _builddomesticdirectlanrulesetdnsmappingmodule = buildDomesticDirectLanRulesetDnsMappingModule.r(); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _trace = /*@__PURE__*/ index.r(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _stream = /*@__PURE__*/ stream.r(); + const _buildchncidr = buildChnCidr.r(); + const _buildtelegramcidr = buildTelegramCidr.r(); + const _createfile = /*@__PURE__*/ createFile.r(); + const _buildmicrosoftcdn = buildMicrosoftCdn.r(); + const _guard = require$$6; + const _appendarrayinplace = /*@__PURE__*/ base.a(); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _ruleset = /*@__PURE__*/ ruleset.r(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const POLICY_GROUPS = [ + [ + 'Default Proxy', + true, + false + ], + [ + 'Global', + true, + true + ], + [ + 'Microsoft & Apple', + true, + true + ], + [ + 'Stream', + true, + false + ], + [ + 'Steam Download', + true, + true + ], + [ + 'Domestic', + false, + true + ], + [ + 'Final Match', + true, + true + ] + ]; + const steamDomainsPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/game-download.conf')); + const buildSSPanelUIMAppProfile = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const [[domesticRules, directRules, lanRules], appleCdnDomains, [microsoftCdnDomains, microsoftCdnDomainSuffixes], appleCnRules, neteaseMusicRules, microsoftRules, appleRules, streamRules, steamDomainset, globalRules, telegramRules, [domesticCidrs4, domesticCidrs6], [streamCidrs4, streamCidrs6], { ipcidr: telegramCidrs4, ipcidr6: telegramCidrs6 }, rawLanCidrs] = await Promise.all([ + // domestic - domains + (0, _builddomesticdirectlanrulesetdnsmappingmodule.getDomesticAndDirectDomainsRulesetPromise)(), + (0, _buildapplecdn.getAppleCdnDomainsPromise)(), + (0, _buildmicrosoftcdn.getMicrosoftCdnRulesetPromise)(), + (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/apple_cn.conf')), + (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/neteasemusic.conf')), + // microsoft & apple - domains + (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/microsoft.conf')), + (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/apple_services.conf')), + // stream - domains + _stream.ALL.flatMap((i)=>i.rules), + // steam - domains + steamDomainsPromise, + // global - domains + (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/global.conf')), + (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/telegram.conf')), + // domestic - ip cidr + (0, _buildchncidr.getChnCidrPromise)(), + _stream.ALL.reduce((acc, i)=>{ + if (i.ip) { + (0, _appendarrayinplace.appendArrayInPlace)(acc[0], i.ip.v4); + (0, _appendarrayinplace.appendArrayInPlace)(acc[1], i.ip.v6); + } + return acc; + }, [ + [], + [] + ]), + // global - ip cidr + (0, _buildtelegramcidr.getTelegramCIDRPromise)(), + // lan - ip cidr + (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'ip/lan.conf')) + ]); + const domestic = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromRuleset(domesticRules).bulkAddDomainSuffix(appleCdnDomains).bulkAddDomain(microsoftCdnDomains).bulkAddDomainSuffix(microsoftCdnDomainSuffixes).addFromRuleset(appleCnRules).addFromRuleset(neteaseMusicRules); + const microsoftApple = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromRuleset(microsoftRules).addFromRuleset(appleRules); + const stream = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromRuleset(streamRules); + const steam = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromDomainset(steamDomainset); + const global = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromRuleset(globalRules).addFromRuleset(telegramRules); + const direct = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromRuleset(directRules).addFromRuleset(lanRules); + const domesticCidr = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'ip').bulkAddCIDR4(domesticCidrs4).bulkAddCIDR6(domesticCidrs6); + const streamCidr = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'ip').bulkAddCIDR4(streamCidrs4).bulkAddCIDR6(streamCidrs6); + const telegramCidr = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'ip').bulkAddCIDR4(telegramCidrs4).bulkAddCIDR6(telegramCidrs6); + const lanCidrs = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'ip').addFromRuleset(rawLanCidrs); + const output = generateAppProfile(...(await Promise.all([ + domestic.compile(), + microsoftApple.compile(), + stream.compile(), + steam.compile(), + global.compile(), + direct.compile(), + domesticCidr.compile(), + streamCidr.compile(), + telegramCidr.compile(), + lanCidrs.compile() + ])).map((output)=>(0, _guard.nullthrow)(output[0]))); + await (0, _createfile.compareAndWriteFile)(span, output, _nodepath.default.resolve(_dir.OUTPUT_INTERNAL_DIR, 'appprofile.php')); + }); + function generateAppProfile(directDomains, microsoftAppleDomains, streamDomains, steamDomains, globalDomains, lanDomains, directCidrs, streamCidrs, globalCidrs, lanCidrs) { + const redults = [ + ' 7890,', + ' \'socks-port\' => 7891,', + ' \'allow-lan\' => false,', + ' \'mode\' => \'Rule\',', + ' \'ipv6\' => true,', + ' \'log-level\' => \'error\',', + ' \'external-controller\' => \'0.0.0.0:9090\',', + ' \'tun\' => [', + ' \'enable\' => true,', + ' \'stack\' => \'system\',', + ' \'auto-route\' => true,', + ' \'auto-redir\' => true,', + ' \'auto-detect-interface\' => true,', + ' \'dns-hijack\' => [', + ' \'8.8.8.8:53\',', + ' \'any:53\',', + ' \'tcp://8.8.8.8:53\',', + ' \'tcp://any:53\',', + ' ]', + ' ]', + '];', + '', + `$_ENV['Clash_Group_Indexes'] = [${JSON.stringify(POLICY_GROUPS.reduce((acc, [, insertProxy], index)=>{ + if (insertProxy) { + acc.push(index); + } + return acc; + }, [])).slice(1, -1)}];`, + '$_ENV[\'Clash_Group_Config\'] = [', + ' \'proxy-groups\' => [' + ]; + (0, _appendarrayinplace.appendArrayInPlace)(redults, POLICY_GROUPS.flatMap(([name, insertProxy, insertDirect])=>[ + ' [', + ` 'name' => '${name}',`, + ' \'type\' => \'select\',', + ' \'proxies\' => [', + insertProxy && name !== 'Default Proxy' && ' \'Default Proxy\',', + insertDirect && ' \'DIRECT\',', + ' ],', + ' ],' + ].filter(_guard.isTruthy))); + (0, _appendarrayinplace.appendArrayInPlace)(redults, [ + ' ],', + ' \'rules\' => [' + ]); + // domestic - domains + (0, _appendarrayinplace.appendArrayInPlace)(redults, directDomains.map((line)=>` '${line},Domestic',`)); + // microsoft & apple - domains + (0, _appendarrayinplace.appendArrayInPlace)(redults, microsoftAppleDomains.map((line)=>` '${line},Microsoft & Apple',`)); + // stream - domains + (0, _appendarrayinplace.appendArrayInPlace)(redults, streamDomains.map((line)=>` '${line},Stream',`)); + // steam download - domains + (0, _appendarrayinplace.appendArrayInPlace)(redults, steamDomains.map((line)=>` '${line},Steam Download',`)); + // global - domains + (0, _appendarrayinplace.appendArrayInPlace)(redults, globalDomains.map((line)=>` '${line},Global',`)); + // microsoft & apple - ip cidr (nope) + // lan - domains + (0, _appendarrayinplace.appendArrayInPlace)(redults, lanDomains.map((line)=>` '${line},DIRECT',`)); + // stream - ip cidr + (0, _appendarrayinplace.appendArrayInPlace)(redults, streamCidrs.map((line)=>` '${line},Stream',`)); + // global - ip cidr + (0, _appendarrayinplace.appendArrayInPlace)(redults, globalCidrs.map((line)=>` '${line},Global',`)); + // domestic - ip cidr + (0, _appendarrayinplace.appendArrayInPlace)(redults, directCidrs.map((line)=>` '${line},Domestic',`)); + // lan - ip cidr + (0, _appendarrayinplace.appendArrayInPlace)(redults, lanCidrs.map((line)=>` '${line},DIRECT',`)); + // match + (0, _appendarrayinplace.appendArrayInPlace)(redults, [ + ' \'MATCH,Final Match\',', + ' ],', + '];' + ]); + return redults; + } + } (buildSspanelAppprofile, buildSspanelAppprofile.exports)); + return buildSspanelAppprofile.exports; +}exports.r=requireBuildSspanelAppprofile; \ No newline at end of file diff --git a/Dist/chunks/build-stream-service.BKBKJK6i.cjs b/Dist/chunks/build-stream-service.BKBKJK6i.cjs new file mode 100644 index 00000000..e2f69381 --- /dev/null +++ b/Dist/chunks/build-stream-service.BKBKJK6i.cjs @@ -0,0 +1,48 @@ +'use strict';const index=require('./index.B8Uk9n3v.cjs'),stream=require('./stream.C9eZuk9f.cjs'),base=require('./base.C13YY5P3.cjs'),ruleset=require('./ruleset.iYH0XOC1.cjs');var buildStreamService = {exports: {}};var hasRequiredBuildStreamService; + +function requireBuildStreamService () { + if (hasRequiredBuildStreamService) return buildStreamService.exports; + hasRequiredBuildStreamService = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "buildStreamService", { + enumerable: true, + get: function() { + return buildStreamService; + } + }); + const _trace = /*@__PURE__*/ index.r(); + const _stream = /*@__PURE__*/ stream.r(); + const _description = /*@__PURE__*/ base.r(); + const _ruleset = /*@__PURE__*/ ruleset.r(); + function createRulesetForStreamService(span, fileId, title, streamServices) { + return [ + // Domains + new _ruleset.RulesetOutput(span, fileId, 'non_ip').withTitle(`Sukka's Ruleset - Stream Services: ${title}`).withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + ...streamServices.map((i)=>`- ${i.name}`) + ]).addFromRuleset(streamServices.flatMap((i)=>i.rules)).write(), + // IP + new _ruleset.RulesetOutput(span, fileId, 'ip').withTitle(`Sukka's Ruleset - Stream Services IPs: ${title}`).withDescription([ + ..._description.SHARED_DESCRIPTION, + '', + ...streamServices.map((i)=>`- ${i.name}`) + ]).bulkAddCIDR4NoResolve(streamServices.flatMap((i)=>i.ip?.v4 ?? [])).bulkAddCIDR6NoResolve(streamServices.flatMap((i)=>i.ip?.v6 ?? [])).write() + ]; + } + const buildStreamService = (0, _trace.task)(require.main === module, __filename)(async (span)=>Promise.all([ + createRulesetForStreamService(span, 'stream', 'All', _stream.ALL), + createRulesetForStreamService(span, 'stream_us', 'North America', _stream.NORTH_AMERICA), + createRulesetForStreamService(span, 'stream_eu', 'Europe', _stream.EU), + createRulesetForStreamService(span, 'stream_hk', 'Hong Kong', _stream.HK), + createRulesetForStreamService(span, 'stream_tw', 'Taiwan', _stream.TW), + createRulesetForStreamService(span, 'stream_jp', 'Japan', _stream.JP), + // createRulesetForStreamService('stream_au', 'Oceania', AU), + createRulesetForStreamService(span, 'stream_kr', 'Korean', _stream.KR) + ].flat())); + } (buildStreamService, buildStreamService.exports)); + return buildStreamService.exports; +}exports.r=requireBuildStreamService; \ No newline at end of file diff --git a/Dist/chunks/build-telegram-cidr.05NmRbUx.cjs b/Dist/chunks/build-telegram-cidr.05NmRbUx.cjs new file mode 100644 index 00000000..8b36ac37 --- /dev/null +++ b/Dist/chunks/build-telegram-cidr.05NmRbUx.cjs @@ -0,0 +1,69 @@ +'use strict';const fetchTextByLine=require('./fetch-text-by-line.YY5b5610.cjs'),index=require('./index.B8Uk9n3v.cjs'),base=require('./base.C13YY5P3.cjs'),memoPromise=require('./memo-promise.BbOsVeGo.cjs'),ruleset=require('./ruleset.iYH0XOC1.cjs'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),misc=require('./misc.BpcQjda1.cjs');var buildTelegramCidr = {exports: {}};var hasRequiredBuildTelegramCidr; + +function requireBuildTelegramCidr () { + if (hasRequiredBuildTelegramCidr) return buildTelegramCidr.exports; + hasRequiredBuildTelegramCidr = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + buildTelegramCIDR: function() { + return buildTelegramCIDR; + }, + getTelegramCIDRPromise: function() { + return getTelegramCIDRPromise; + } + }); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _trace = /*@__PURE__*/ index.r(); + const _description = /*@__PURE__*/ base.r(); + const _memopromise = /*@__PURE__*/ memoPromise.r(); + const _ruleset = /*@__PURE__*/ ruleset.r(); + const _fetchretry = /*@__PURE__*/ fetchRetry.r(); + const _misc = /*@__PURE__*/ misc.r(); + const getTelegramCIDRPromise = (0, _memopromise.createMemoizedPromise)(async ()=>{ + const resp = await (0, _fetchretry.$$fetch)('https://core.telegram.org/resources/cidr.txt'); + const lastModified = resp.headers.get('last-modified'); + const date = lastModified ? new Date(lastModified) : new Date(); + const ipcidr = [ + // Telegram secret backup CIDR, announced by AS62041 + // see also https://github.com/Telegram-FOSS-Team/Telegram-FOSS/blob/10da5406ed92d30c6add3b25d40b2b3b6995d873/TMessagesProj/src/main/java/org/telegram/tgnet/ConnectionsManager.java#L1157 + '95.161.64.0/20' + ]; + const ipcidr6 = []; + for await (const cidr of (0, _fetchtextbyline.createReadlineInterfaceFromResponse)(resp, true)){ + const v = (0, _misc.fastIpVersion)(cidr); + if (v === 4) { + ipcidr.push(cidr); + } else if (v === 6) { + ipcidr6.push(cidr); + } + } + return { + date, + ipcidr, + ipcidr6 + }; + }); + const buildTelegramCIDR = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const { date, ipcidr, ipcidr6 } = await span.traceChildAsync('get telegram cidr', getTelegramCIDRPromise); + if (ipcidr.length + ipcidr6.length === 0) { + throw new Error('Failed to fetch data!'); + } + const description = [ + ..._description.SHARED_DESCRIPTION, + 'Data from:', + ' - https://core.telegram.org/resources/cidr.txt' + ]; + return new _ruleset.RulesetOutput(span, 'telegram', 'ip').withTitle('Sukka\'s Ruleset - Telegram IP CIDR').withDescription(description).withDate(date).bulkAddCIDR4NoResolve(ipcidr).bulkAddCIDR6NoResolve(ipcidr6).write(); + }); + } (buildTelegramCidr, buildTelegramCidr.exports)); + return buildTelegramCidr.exports; +}exports.r=requireBuildTelegramCidr; \ No newline at end of file diff --git a/Dist/chunks/create-file.loOMbJEN.cjs b/Dist/chunks/create-file.loOMbJEN.cjs new file mode 100644 index 00000000..0192ede7 --- /dev/null +++ b/Dist/chunks/create-file.loOMbJEN.cjs @@ -0,0 +1,114 @@ +'use strict';const require$$0=require('foxts/async-write-to-stream'),require$$3=require('foxts/fast-string-array-join'),require$$1=require('node:fs'),require$$0$1=require('picocolors'),fetchTextByLine=require('./fetch-text-by-line.YY5b5610.cjs'),misc=require('./misc.BpcQjda1.cjs');var createFile = {};var hasRequiredCreateFile; + +function requireCreateFile () { + if (hasRequiredCreateFile) return createFile; + hasRequiredCreateFile = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + compareAndWriteFile: function() { + return compareAndWriteFile; + }, + fileEqual: function() { + return fileEqual; + } + }); + const _asyncwritetostream = require$$0; + const _faststringarrayjoin = require$$3; + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _misc = /*@__PURE__*/ misc.r(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + async function fileEqual(linesA, source) { + if (linesA.length === 0) { + return false; + } + const linesABound = linesA.length - 1; + let index = -1; + for await (const lineB of source){ + index++; + if (index > linesABound) { + return index === linesA.length && lineB.length === 0; + } + const lineA = linesA[index]; + if (lineA.length === 0) { + if (lineB.length === 0) { + continue; + } + // lineA is empty but lineB is not + return false; + } + // now lineA can not be empty + if (lineB.length === 0) { + // lineB is empty but lineA is not + return false; + } + // now both lines can not be empty + const firstCharA = lineA.charCodeAt(0); + const firstCharB = lineB.charCodeAt(0); + if (firstCharA !== firstCharB) { + return false; + } + // now firstCharA is equal to firstCharB, we only need to check the first char + if (firstCharA === 35 /* # */ ) { + continue; + } + // adguard conf + if (firstCharA === 33 /* ! */ ) { + continue; + } + if (firstCharA === 47 /* / */ && lineA[1] === '/' && lineB[1] === '/' && lineA[3] === '#' && lineB[3] === '#') { + continue; + } + if (lineA !== lineB) { + return false; + } + } + // The file becomes larger + return !(index < linesABound); + } + async function compareAndWriteFile(span, linesA, filePath) { + const linesALen = linesA.length; + const isEqual = await span.traceChildAsync(`compare ${filePath}`, async ()=>{ + if (_nodefs.default.existsSync(filePath)) { + return fileEqual(linesA, (0, _fetchtextbyline.readFileByLine)(filePath)); + } + console.log(`${filePath} does not exists, writing...`); + return false; + }); + if (isEqual) { + console.log(_picocolors.default.gray(_picocolors.default.dim(`same content, bail out writing: ${filePath}`))); + return; + } + await span.traceChildAsync(`writing ${filePath}`, async ()=>{ + // The default highwater mark is normally 16384, + // So we make sure direct write to file if the content is + // most likely less than 500 lines + if (linesALen < 500) { + return (0, _misc.writeFile)(filePath, (0, _faststringarrayjoin.fastStringArrayJoin)(linesA, '\n') + '\n'); + } + const writeStream = _nodefs.default.createWriteStream(filePath); + for(let i = 0; i < linesALen; i++){ + const p = (0, _asyncwritetostream.asyncWriteToStream)(writeStream, linesA[i] + '\n'); + // eslint-disable-next-line no-await-in-loop -- stream high water mark + if (p) await p; + } + writeStream.end(); + }); + } + } (createFile)); + return createFile; +}exports.r=requireCreateFile; \ No newline at end of file diff --git a/Dist/chunks/domainset.CSQfKAtf.cjs b/Dist/chunks/domainset.CSQfKAtf.cjs new file mode 100644 index 00000000..8e43963a --- /dev/null +++ b/Dist/chunks/domainset.CSQfKAtf.cjs @@ -0,0 +1,159 @@ +'use strict';const require$$0=require('foxts/escape-string-regexp'),base=require('./base.C13YY5P3.cjs'),require$$2=require('foxts/noop'),misc=require('./misc.BpcQjda1.cjs');var domainset = {};var adguardhome = {};var hasRequiredAdguardhome; + +function requireAdguardhome () { + if (hasRequiredAdguardhome) return adguardhome; + hasRequiredAdguardhome = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "AdGuardHome", { + enumerable: true, + get: function() { + return AdGuardHome; + } + }); + const _escapestringregexp = require$$0; + const _base = /*@__PURE__*/ base.d(); + const _noop = require$$2; + const _misc = /*@__PURE__*/ misc.r(); + class AdGuardHome extends _base.BaseWriteStrategy { + // readonly type = 'domainset'; + fileExtension = 'txt'; + type = ''; + result = []; + // eslint-disable-next-line @typescript-eslint/class-methods-use-this -- abstract method + withPadding(title, description, date, content) { + return [ + `! Title: ${title}`, + '! Last modified: ' + date.toUTCString(), + '! Expires: 6 hours', + '! License: https://github.com/SukkaW/Surge/blob/master/LICENSE', + '! Homepage: https://github.com/SukkaW/Surge', + `! Description: ${description.join(' ')}`, + '!', + ...content, + '! EOF' + ]; + } + writeDomain(domain) { + this.result.push(`|${domain}^`); + } + // const whitelistArray = sortDomains(Array.from(whitelist)); + // for (let i = 0, len = whitelistArray.length; i < len; i++) { + // const domain = whitelistArray[i]; + // if (domain[0] === '.') { + // results.push(`@@||${domain.slice(1)}^`); + // } else { + // results.push(`@@|${domain}^`); + // } + // } + writeDomainSuffix(domain) { + this.result.push(`||${domain}^`); + } + writeDomainKeywords(keywords) { + for (const keyword of keywords){ + // Use regex to match keyword + this.result.push(`/${(0, _escapestringregexp.escapeStringRegexp)(keyword)}/`); + } + } + writeDomainWildcards(wildcards) { + for (const wildcard of wildcards){ + const processed = wildcard.replaceAll('?', '*'); + if (processed.startsWith('*.')) { + this.result.push(`||${processed.slice(2)}^`); + } else { + this.result.push(`|${processed}^`); + } + } + } + writeUserAgents = _noop.noop; + writeProcessNames = _noop.noop; + writeProcessPaths = _noop.noop; + writeUrlRegexes = _noop.noop; + writeIpCidrs(ipGroup, noResolve) { + if (noResolve) { + // When IP is provided to AdGuardHome, any domain resolve to those IP will be blocked + // So we can't do noResolve + return; + } + for (const ipcidr of ipGroup){ + if (ipcidr.endsWith('/32')) { + this.result.push(`||${ipcidr.slice(0, -3)}`); + /* else if (ipcidr.endsWith('.0/24')) { + results.push(`||${ipcidr.slice(0, -6)}.*`); + } */ } else { + this.result.push(`||${ipcidr}^`); + } + } + } + writeIpCidr6s(ipGroup, noResolve) { + if (noResolve) { + // When IP is provided to AdGuardHome, any domain resolve to those IP will be blocked + // So we can't do noResolve + return; + } + for (const ipcidr of ipGroup){ + if (ipcidr.endsWith('/128')) { + this.result.push(`||${ipcidr.slice(0, -4)}`); + } else { + this.result.push(`||${ipcidr}`); + } + } + } + writeGeoip = (0, _misc.notSupported)('writeGeoip'); + writeIpAsns = (0, _misc.notSupported)('writeIpAsns'); + writeSourceIpCidrs = (0, _misc.notSupported)('writeSourceIpCidrs'); + writeSourcePorts = (0, _misc.notSupported)('writeSourcePorts'); + writeDestinationPorts = _noop.noop; + writeOtherRules = _noop.noop; + } + } (adguardhome)); + return adguardhome; +}var hasRequiredDomainset; + +function requireDomainset () { + if (hasRequiredDomainset) return domainset; + hasRequiredDomainset = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + AdGuardHomeOutput: function() { + return AdGuardHomeOutput; + }, + DomainsetOutput: function() { + return DomainsetOutput; + } + }); + const _adguardhome = /*@__PURE__*/ requireAdguardhome(); + const _clash = /*@__PURE__*/ base.c(); + const _singbox = /*@__PURE__*/ base.f(); + const _surge = /*@__PURE__*/ base.e(); + const _base = /*@__PURE__*/ base.b(); + class DomainsetOutput extends _base.FileOutput { + strategies = [ + new _surge.SurgeDomainSet(), + new _clash.ClashDomainSet(), + new _singbox.SingboxSource('domainset') + ]; + } + class AdGuardHomeOutput extends _base.FileOutput { + strategies; + constructor(span, id, outputDir){ + super(span, id); + this.strategies = [ + new _adguardhome.AdGuardHome(outputDir) + ]; + } + } + } (domainset)); + return domainset; +}exports.r=requireDomainset; \ No newline at end of file diff --git a/Dist/chunks/download-mock-assets.Dk5F6scb.cjs b/Dist/chunks/download-mock-assets.Dk5F6scb.cjs new file mode 100644 index 00000000..02743778 --- /dev/null +++ b/Dist/chunks/download-mock-assets.Dk5F6scb.cjs @@ -0,0 +1,58 @@ +'use strict';const index=require('./index.B8Uk9n3v.cjs'),require$$0=require('node:path'),require$$1=require('node:fs'),require$$2=require('node:stream/promises'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),misc=require('./misc.BpcQjda1.cjs');var downloadMockAssets = {exports: {}};var hasRequiredDownloadMockAssets; + +function requireDownloadMockAssets () { + if (hasRequiredDownloadMockAssets) return downloadMockAssets.exports; + hasRequiredDownloadMockAssets = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "downloadMockAssets", { + enumerable: true, + get: function() { + return downloadMockAssets; + } + }); + const _trace = /*@__PURE__*/ index.r(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1); + const _promises = require$$2; + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _misc = /*@__PURE__*/ misc.r(); + const _fetchretry = /*@__PURE__*/ fetchRetry.r(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const ASSETS_LIST = { + 'www-google-analytics-com_ga.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/google-analytics-ga.js', + 'www-googletagservices-com_gpt.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/googletagservices-gpt.js', + 'www-google-analytics-com_analytics.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/google-analytics.js', + 'www-googlesyndication-com_adsbygoogle.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/googlesyndication-adsbygoogle.js', + 'amazon-adsystem-com_amazon-apstag.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/amazon-apstag.js' + }; + const downloadMockAssets = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + const p = (0, _misc.mkdirp)(_dir.OUTPUT_MOCK_DIR); + if (p) { + await p; + } + return Promise.all(Object.entries(ASSETS_LIST).map(([filename, url])=>span.traceChildAsync(url, async ()=>{ + const res = await (0, _fetchretry.$$fetch)(url); + if (!res.ok) { + console.error(`Failed to download ${url}`); + // we can safely skip this since we can always use previous version + return; + } + if (!res.body) { + console.error(`Empty body from ${url}`); + // we can safely skip this since we can always use previous version + return; + } + const src = _nodepath.default.join(_dir.OUTPUT_MOCK_DIR, filename); + return (0, _promises.pipeline)(res.body, _nodefs.default.createWriteStream(src, 'utf-8')); + }))); + }); + } (downloadMockAssets, downloadMockAssets.exports)); + return downloadMockAssets.exports; +}exports.r=requireDownloadMockAssets; \ No newline at end of file diff --git a/Dist/chunks/download-previous-build.-XKJmEYz.cjs b/Dist/chunks/download-previous-build.-XKJmEYz.cjs new file mode 100644 index 00000000..ee6a0fc1 --- /dev/null +++ b/Dist/chunks/download-previous-build.-XKJmEYz.cjs @@ -0,0 +1,99 @@ +'use strict';const require$$0$1=require('node:path'),require$$1$1=require('node:fs'),require$$2=require('node:stream/promises'),index=require('./index.B8Uk9n3v.cjs'),require$$4=require('tar-fs'),require$$5=require('node:zlib'),require$$1=require('undici'),require$$0=require('picocolors'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),misc=require('./misc.BpcQjda1.cjs'),require$$11=require('ci-info');var downloadPreviousBuild = {exports: {}};var hasRequiredDownloadPreviousBuild; + +function requireDownloadPreviousBuild () { + if (hasRequiredDownloadPreviousBuild) return downloadPreviousBuild.exports; + hasRequiredDownloadPreviousBuild = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "downloadPreviousBuild", { + enumerable: true, + get: function() { + return downloadPreviousBuild; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1$1); + const _promises = require$$2; + const _trace = /*@__PURE__*/ index.r(); + const _tarfs = require$$4; + const _nodezlib = /*#__PURE__*/ _interop_require_default(require$$5); + const _undici = /*#__PURE__*/ _interop_require_default(require$$1); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _fetchretry = /*@__PURE__*/ fetchRetry.r(); + const _misc = /*@__PURE__*/ misc.r(); + const _ciinfo = require$$11; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const GITHUB_CODELOAD_URL = 'https://codeload.github.com/sukkalab/ruleset.skk.moe/tar.gz/master'; + const GITLAB_CODELOAD_URL = 'https://gitlab.com/SukkaW/ruleset.skk.moe/-/archive/master/ruleset.skk.moe-master.tar.gz'; + const downloadPreviousBuild = (0, _trace.task)(require.main === module, __filename)(async (span)=>{ + if (_nodefs.default.existsSync(_dir.PUBLIC_DIR) && !(0, _misc.isDirectoryEmptySync)(_dir.PUBLIC_DIR)) { + console.log(_picocolors.default.blue('Public directory exists, skip downloading previous build')); + return; + } + // we uses actions/checkout to download the previous build now, so we should throw if the directory is empty + if (_ciinfo.isCI) { + throw new Error('CI environment detected, but public directory is empty'); + } + const tarGzUrl = await span.traceChildAsync('get tar.gz url', async ()=>{ + const resp = await (0, _fetchretry.requestWithLog)(GITHUB_CODELOAD_URL, { + method: 'HEAD' + }); + if (resp.statusCode !== 200) { + console.warn('Download previous build from GitHub failed! Status:', resp.statusCode); + console.warn('Switch to GitLab'); + return GITLAB_CODELOAD_URL; + } + return GITHUB_CODELOAD_URL; + }); + return span.traceChildAsync('download & extract previoud build', async ()=>{ + const respBody = _undici.default.pipeline(tarGzUrl, { + method: 'GET', + headers: { + 'User-Agent': 'curl/8.9.1', + // https://github.com/unjs/giget/issues/97 + // https://gitlab.com/gitlab-org/gitlab/-/commit/50c11f278d18fe1f3fb12eb595067216bb58ade2 + 'sec-fetch-mode': 'same-origin' + }, + // Allow redirects by default + maxRedirections: 5 + }, ({ statusCode, body })=>{ + if (statusCode !== 200) { + console.warn('Download previous build failed! Status:', statusCode); + if (statusCode === 404) { + throw new Error('Download previous build failed! 404'); + } + } + return body; + }).end(); + const pathPrefix = 'ruleset.skk.moe-master/'; + const gunzip = _nodezlib.default.createGunzip(); + const extract = (0, _tarfs.extract)(_dir.PUBLIC_DIR, { + ignore (_, header) { + if (header) { + if (header.type !== 'file' && header.type !== 'directory') { + return true; + } + if (header.type === 'file' && _nodepath.default.extname(header.name) === '.ts') { + return true; + } + } + return false; + }, + map (header) { + header.name = header.name.replace(pathPrefix, ''); + return header; + } + }); + return (0, _promises.pipeline)(respBody, gunzip, extract); + }); + }); + } (downloadPreviousBuild, downloadPreviousBuild.exports)); + return downloadPreviousBuild.exports; +}exports.r=requireDownloadPreviousBuild; \ No newline at end of file diff --git a/Dist/chunks/fetch-assets.aqw2YOi8.cjs b/Dist/chunks/fetch-assets.aqw2YOi8.cjs new file mode 100644 index 00000000..3080fa76 --- /dev/null +++ b/Dist/chunks/fetch-assets.aqw2YOi8.cjs @@ -0,0 +1,81 @@ +'use strict';const require$$0=require('picocolors'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),require$$2=require('foxts/wait'),require$$6=require('foxts/guard'),fetchTextByLine=require('./fetch-text-by-line.YY5b5610.cjs');var fetchAssets = {};var hasRequiredFetchAssets; + +function requireFetchAssets () { + if (hasRequiredFetchAssets) return fetchAssets; + hasRequiredFetchAssets = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + CustomAbortError: function() { + return CustomAbortError; + }, + fetchAssets: function() { + return fetchAssets; + } + }); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0); + const _fetchretry = /*@__PURE__*/ fetchRetry.r(); + const _wait = require$$2; + const _guard = require$$6; + const _textlinetransformstream = /*@__PURE__*/ fetchTextByLine.b(); + const _processline = /*@__PURE__*/ fetchTextByLine.r(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + class CustomAbortError extends Error { + name = 'AbortError'; + digest = 'AbortError'; + } + const reusedCustomAbortError = new CustomAbortError(); + async function fetchAssets(url, fallbackUrls, processLine = false) { + const controller = new AbortController(); + const createFetchFallbackPromise = async (url, index)=>{ + if (index >= 0) { + // Most assets can be downloaded within 250ms. To avoid wasting bandwidth, we will wait for 500ms before downloading from the fallback URL. + try { + await (0, _wait.waitWithAbort)(50 + (index + 1) * 100, controller.signal); + } catch { + console.log(_picocolors.default.gray('[fetch cancelled early]'), _picocolors.default.gray(url)); + throw reusedCustomAbortError; + } + } + if (controller.signal.aborted) { + console.log(_picocolors.default.gray('[fetch cancelled]'), _picocolors.default.gray(url)); + throw reusedCustomAbortError; + } + const res = await (0, _fetchretry.$$fetch)(url, { + signal: controller.signal, + ..._fetchretry.defaultRequestInit + }); + let stream = (0, _guard.nullthrow)(res.body).pipeThrough(new TextDecoderStream()).pipeThrough(new _textlinetransformstream.TextLineStream()); + if (processLine) { + stream = stream.pipeThrough(new _processline.ProcessLineStream()); + } + const arr = await Array.fromAsync(stream); + if (arr.length < 1) { + throw new _fetchretry.ResponseError(res, url, 'empty response w/o 304'); + } + controller.abort(); + return arr; + }; + if (!fallbackUrls || fallbackUrls.length === 0) { + return createFetchFallbackPromise(url, -1); + } + return Promise.any([ + createFetchFallbackPromise(url, -1), + ...fallbackUrls.map(createFetchFallbackPromise) + ]); + } + } (fetchAssets)); + return fetchAssets; +}exports.r=requireFetchAssets; \ No newline at end of file diff --git a/Dist/chunks/fetch-retry.D06uBUaW.cjs b/Dist/chunks/fetch-retry.D06uBUaW.cjs new file mode 100644 index 00000000..425e37d7 --- /dev/null +++ b/Dist/chunks/fetch-retry.D06uBUaW.cjs @@ -0,0 +1,307 @@ +'use strict';const require$$0$1=require('picocolors'),require$$1$1=require('undici'),require$$2=require('undici-cache-store-better-sqlite3'),require$$1$3=require('node:util'),require$$0=require('node:path'),require$$1$2=require('node:fs'),require$$1=require('node:process');function getDefaultExportFromCjs (x) { + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; +}var fetchRetry = {};var dir = {};var hasRequiredDir; + +function requireDir () { + if (hasRequiredDir) return dir; + hasRequiredDir = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + CACHE_DIR: function() { + return CACHE_DIR; + }, + OUTPUT_CLASH_DIR: function() { + return OUTPUT_CLASH_DIR; + }, + OUTPUT_INTERNAL_DIR: function() { + return OUTPUT_INTERNAL_DIR; + }, + OUTPUT_MOCK_DIR: function() { + return OUTPUT_MOCK_DIR; + }, + OUTPUT_MODULES_DIR: function() { + return OUTPUT_MODULES_DIR; + }, + OUTPUT_MODULES_RULES_DIR: function() { + return OUTPUT_MODULES_RULES_DIR; + }, + OUTPUT_SINGBOX_DIR: function() { + return OUTPUT_SINGBOX_DIR; + }, + OUTPUT_SURGE_DIR: function() { + return OUTPUT_SURGE_DIR; + }, + PUBLIC_DIR: function() { + return PUBLIC_DIR; + }, + ROOT_DIR: function() { + return ROOT_DIR; + }, + SOURCE_DIR: function() { + return SOURCE_DIR; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _nodeprocess = /*#__PURE__*/ _interop_require_default(require$$1); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const ROOT_DIR = _nodepath.default.resolve(__dirname, '../..'); + const CACHE_DIR = _nodepath.default.resolve(ROOT_DIR, '.cache'); + const SOURCE_DIR = _nodepath.default.join(ROOT_DIR, 'Source'); + const PUBLIC_DIR = _nodeprocess.default.env.PUBLIC_DIR || _nodepath.default.resolve(ROOT_DIR, 'public'); + const OUTPUT_SURGE_DIR = _nodepath.default.join(PUBLIC_DIR, 'List'); + const OUTPUT_CLASH_DIR = _nodepath.default.resolve(PUBLIC_DIR, 'Clash'); + const OUTPUT_SINGBOX_DIR = _nodepath.default.resolve(PUBLIC_DIR, 'sing-box'); + const OUTPUT_MODULES_DIR = _nodepath.default.resolve(PUBLIC_DIR, 'Modules'); + const OUTPUT_MODULES_RULES_DIR = _nodepath.default.resolve(OUTPUT_MODULES_DIR, 'Rules'); + const OUTPUT_INTERNAL_DIR = _nodepath.default.resolve(PUBLIC_DIR, 'Internal'); + const OUTPUT_MOCK_DIR = _nodepath.default.resolve(PUBLIC_DIR, 'Mock'); + } (dir)); + return dir; +}var hasRequiredFetchRetry; + +function requireFetchRetry () { + if (hasRequiredFetchRetry) return fetchRetry; + hasRequiredFetchRetry = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + $$fetch: function() { + return $$fetch; + }, + ResponseError: function() { + return ResponseError; + }, + defaultRequestInit: function() { + return defaultRequestInit; + }, + requestWithLog: function() { + return requestWithLog; + } + }); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _undici = /*#__PURE__*/ _interop_require_wildcard(require$$1$1); + const _undicicachestorebettersqlite3 = require$$2; + const _nodeutil = require$$1$3; + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1$2); + const _dir = /*@__PURE__*/ requireDir(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); + } + function _interop_require_wildcard(obj, nodeInterop) { + if (obj && obj.__esModule) { + return obj; + } + if (obj === null || typeof obj !== "object" && typeof obj !== "function") { + return { + default: obj + }; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = { + __proto__: null + }; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; + } + if (!_nodefs.default.existsSync(_dir.CACHE_DIR)) { + _nodefs.default.mkdirSync(_dir.CACHE_DIR, { + recursive: true + }); + } + const agent = new _undici.Agent({ + allowH2: true + }); + (0, _undici.setGlobalDispatcher)(agent.compose(_undici.interceptors.dns({ + // disable IPv6 + dualStack: false, + affinity: 4 + }), _undici.interceptors.retry({ + maxRetries: 5, + minTimeout: 500, + maxTimeout: 10 * 1000, + // TODO: this part of code is only for allow more errors to be retried by default + // This should be removed once https://github.com/nodejs/undici/issues/3728 is implemented + retry (err, { state, opts }, cb) { + const errorCode = 'code' in err ? err.code : undefined; + // Any code that is not a Undici's originated and allowed to retry + if (errorCode === 'ERR_UNESCAPED_CHARACTERS' || err.message === 'Request path contains unescaped characters' || err.name === 'AbortError') { + return cb(err); + } + const statusCode = 'statusCode' in err && typeof err.statusCode === 'number' ? err.statusCode : null; + // bail out if the status code matches one of the following + if (statusCode != null && (statusCode === 401 // Unauthorized, should check credentials instead of retrying + || statusCode === 403 // Forbidden, should check permissions instead of retrying + || statusCode === 404 // Not Found, should check URL instead of retrying + || statusCode === 405 // Method Not Allowed, should check method instead of retrying + )) { + return cb(err); + } + // if (errorCode === 'UND_ERR_REQ_RETRY') { + // return cb(err); + // } + const { maxRetries = 5, minTimeout = 500, maxTimeout = 10 * 1000, timeoutFactor = 2, methods = [ + 'GET', + 'HEAD', + 'OPTIONS', + 'PUT', + 'DELETE', + 'TRACE' + ] } = opts.retryOptions || {}; + // If we reached the max number of retries + if (state.counter > maxRetries) { + return cb(err); + } + // If a set of method are provided and the current method is not in the list + if (Array.isArray(methods) && !methods.includes(opts.method)) { + return cb(err); + } + const headers = 'headers' in err && typeof err.headers === 'object' ? err.headers : undefined; + const retryAfterHeader = headers?.['retry-after']; + let retryAfter = -1; + if (retryAfterHeader) { + retryAfter = Number(retryAfterHeader); + retryAfter = Number.isNaN(retryAfter) ? calculateRetryAfterHeader(retryAfterHeader) : retryAfter * 1e3; // Retry-After is in seconds + } + const retryTimeout = retryAfter > 0 ? Math.min(retryAfter, maxTimeout) : Math.min(minTimeout * timeoutFactor ** (state.counter - 1), maxTimeout); + console.log('[fetch retry]', 'schedule retry', { + statusCode, + retryTimeout, + errorCode, + url: opts.origin + }); + // eslint-disable-next-line sukka/prefer-timer-id -- won't leak + setTimeout(()=>cb(null), retryTimeout); + } + }), _undici.interceptors.redirect({ + maxRedirections: 5 + }), _undici.interceptors.cache({ + store: new _undicicachestorebettersqlite3.BetterSqlite3CacheStore({ + location: _nodepath.default.join(_dir.CACHE_DIR, 'undici-better-sqlite3-cache-store.db'), + maxEntrySize: 1024 * 1024 * 100 // 100 MiB + }) + }))); + function calculateRetryAfterHeader(retryAfter) { + const current = Date.now(); + return new Date(retryAfter).getTime() - current; + } + class ResponseError extends Error { + res; + url; + code; + statusCode; + constructor(res, url, ...args){ + const statusCode = 'statusCode' in res ? res.statusCode : res.status; + super('HTTP ' + statusCode + ' ' + args.map((_)=>(0, _nodeutil.inspect)(_)).join(' ')), this.res = res, this.url = url; + if ('captureStackTrace' in Error) { + Error.captureStackTrace(this, ResponseError); + } + // eslint-disable-next-line sukka/unicorn/custom-error-definition -- deliberatly use previous name + this.name = this.constructor.name; + this.res = res; + this.code = statusCode; + this.statusCode = statusCode; + } + } + const defaultRequestInit = { + headers: { + 'User-Agent': 'curl/8.9.1 (https://github.com/SukkaW/Surge)' + } + }; + async function $$fetch(url, init) { + try { + const res = await _undici.default.fetch(url, init); + if (res.status >= 400) { + throw new ResponseError(res, url); + } + if (!(res.status >= 200 && res.status <= 299) && res.status !== 304) { + throw new ResponseError(res, url); + } + return res; + } catch (err) { + if (typeof err === 'object' && err !== null && 'name' in err) { + if (err.name === 'AbortError' || 'digest' in err && err.digest === 'AbortError') { + console.log(_picocolors.default.gray('[fetch abort]'), url); + } + } else { + console.log(_picocolors.default.gray('[fetch fail]'), url, { + name: err.name + }, err); + } + throw err; + } + } + async function requestWithLog(url, opt) { + try { + const res = await _undici.default.request(url, opt); + if (res.statusCode >= 400) { + throw new ResponseError(res, url); + } + if (!(res.statusCode >= 200 && res.statusCode <= 299) && res.statusCode !== 304) { + throw new ResponseError(res, url); + } + return res; + } catch (err) { + if (typeof err === 'object' && err !== null && 'name' in err) { + if (err.name === 'AbortError' || 'digest' in err && err.digest === 'AbortError') { + console.log(_picocolors.default.gray('[fetch abort]'), url); + } + } else { + console.log(_picocolors.default.gray('[fetch fail]'), url, { + name: err.name + }, err); + } + throw err; + } + } + } (fetchRetry)); + return fetchRetry; +}exports.a=requireDir;exports.g=getDefaultExportFromCjs;exports.r=requireFetchRetry; \ No newline at end of file diff --git a/Dist/chunks/fetch-text-by-line.YY5b5610.cjs b/Dist/chunks/fetch-text-by-line.YY5b5610.cjs new file mode 100644 index 00000000..abf462ee --- /dev/null +++ b/Dist/chunks/fetch-text-by-line.YY5b5610.cjs @@ -0,0 +1,221 @@ +'use strict';const require$$1=require('node:fs'),require$$1$1=require('node:readline'),require$$0=require('node:stream/web'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),require$$6=require('foxts/guard');var processLine = {};var hasRequiredProcessLine; + +function requireProcessLine () { + if (hasRequiredProcessLine) return processLine; + hasRequiredProcessLine = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + ProcessLineStream: function() { + return ProcessLineStream; + }, + processLine: function() { + return processLine; + } + }); + const _web = require$$0; + function processLine(line) { + const trimmed = line.trim(); + if (trimmed.length === 0) { + return null; + } + const line_0 = trimmed.charCodeAt(0); + if (// line_0 === 32 /** [space] */ + // || line_0 === 13 /** \r */ + // || line_0 === 10 /** \n */ + line_0 === 33 /** ! */ || line_0 === 47 /** / */ && trimmed.charCodeAt(1) === 47 /** / */ ) { + return null; + } + if (line_0 === 35 /** # */ ) { + if (trimmed.charCodeAt(1) !== 35 /** # */ ) { + // # Comment + return null; + } + if (trimmed.charCodeAt(2) === 35 /** # */ && trimmed.charCodeAt(3) === 35) { + // ################## EOF ################## + return null; + } + /** + * AdGuard Filter can be: + * + * ##.class + * ##tag.class + * ###id + */ } + return trimmed; + } + class ProcessLineStream extends _web.TransformStream { + // private __buf = ''; + constructor(){ + super({ + transform (l, controller) { + const line = processLine(l); + if (line) { + controller.enqueue(line); + } + } + }); + } + } // export class ProcessLineNodeStream extends Transform { + // _transform(chunk: string, encoding: BufferEncoding, callback: TransformCallback) { + // // Convert chunk to string and then to uppercase + // const upperCased = chunk.toUpperCase(); + // // Push transformed data to readable side + // this.push(upperCased); + // // Call callback when done + // callback(); + // } + // } + } (processLine)); + return processLine; +}var fetchTextByLine = {};var textLineTransformStream = {};var hasRequiredTextLineTransformStream; + +function requireTextLineTransformStream () { + if (hasRequiredTextLineTransformStream) return textLineTransformStream; + hasRequiredTextLineTransformStream = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "TextLineStream", { + enumerable: true, + get: function() { + return TextLineStream; + } + }); + const _web = require$$0; + class TextLineStream extends _web.TransformStream { + // private __buf = ''; + constructor({ allowCR = false } = {}){ + let __buf = ''; + let chunkIndex = 0; + super({ + transform (chunk, controller) { + chunk = __buf + chunk; + chunkIndex = 0; + for(;;){ + const lfIndex = chunk.indexOf('\n', chunkIndex); + if (allowCR) { + const crIndex = chunk.indexOf('\r', chunkIndex); + if (crIndex !== -1 && crIndex !== chunk.length - 1 && (lfIndex === -1 || lfIndex - 1 > crIndex)) { + controller.enqueue(chunk.slice(chunkIndex, crIndex)); + chunkIndex = crIndex + 1; + continue; + } + } + if (lfIndex === -1) { + break; + } + // enqueue current line, and loop again to find next line + let crOrLfIndex = lfIndex; + if (chunk[lfIndex - 1] === '\r') { + crOrLfIndex--; + } + controller.enqueue(chunk.slice(chunkIndex, crOrLfIndex)); + chunkIndex = lfIndex + 1; + continue; + } + __buf = chunk.slice(chunkIndex); + }, + flush (controller) { + if (__buf.length > 0) { + // eslint-disable-next-line sukka/string/prefer-string-starts-ends-with -- performance + if (allowCR && __buf[__buf.length - 1] === '\r') { + controller.enqueue(__buf.slice(0, -1)); + } else { + controller.enqueue(__buf); + } + } + } + }); + } + } + } (textLineTransformStream)); + return textLineTransformStream; +}var hasRequiredFetchTextByLine; + +function requireFetchTextByLine () { + if (hasRequiredFetchTextByLine) return fetchTextByLine; + hasRequiredFetchTextByLine = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + createReadlineInterfaceFromResponse: function() { + return createReadlineInterfaceFromResponse; + }, + fetchRemoteTextByLine: function() { + return fetchRemoteTextByLine; + }, + readFileByLine: function() { + return readFileByLine; + }, + readFileIntoProcessedArray: function() { + return readFileIntoProcessedArray; + } + }); + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1); + const _nodereadline = /*#__PURE__*/ _interop_require_default(require$$1$1); + const _textlinetransformstream = /*@__PURE__*/ requireTextLineTransformStream(); + const _web = require$$0; + const _processline = /*@__PURE__*/ requireProcessLine(); + const _fetchretry = /*@__PURE__*/ fetchRetry.r(); + const _guard = require$$6; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function readFileByLine(file) { + return _nodereadline.default.createInterface({ + input: _nodefs.default.createReadStream(file /* , { encoding: 'utf-8' } */ ), + crlfDelay: Infinity + }); + } + const createReadlineInterfaceFromResponse = (resp, processLine = false)=>{ + (0, _guard.invariant)(resp.body, 'Failed to fetch remote text'); + if ('bodyUsed' in resp && resp.bodyUsed) { + throw new Error('Body has already been consumed.'); + } + let webStream; + if ('pipeThrough' in resp.body) { + webStream = resp.body; + } else { + throw new TypeError('Invalid response body!'); + } + const resultStream = webStream.pipeThrough(new _web.TextDecoderStream()).pipeThrough(new _textlinetransformstream.TextLineStream()); + if (processLine) { + return resultStream.pipeThrough(new _processline.ProcessLineStream()); + } + return resultStream; + }; + function fetchRemoteTextByLine(url, processLine = false) { + return (0, _fetchretry.$$fetch)(url).then((resp)=>createReadlineInterfaceFromResponse(resp, processLine)); + } + async function readFileIntoProcessedArray(file/* | FileHandle */ ) { + const results = []; + for await (const line of readFileByLine(file)){ + if ((0, _processline.processLine)(line)) { + results.push(line); + } + } + return results; + } + } (fetchTextByLine)); + return fetchTextByLine; +}exports.a=requireFetchTextByLine;exports.b=requireTextLineTransformStream;exports.r=requireProcessLine; \ No newline at end of file diff --git a/Dist/chunks/fs-memo.Dw823m02.cjs b/Dist/chunks/fs-memo.Dw823m02.cjs new file mode 100644 index 00000000..a13e4e9f --- /dev/null +++ b/Dist/chunks/fs-memo.Dw823m02.cjs @@ -0,0 +1,222 @@ +'use strict';const require$$0$2=require('node:path'),require$$11=require('ci-info'),require$$0$1=require('picocolors'),require$$0=require('better-sqlite3'),require$$1$1=require('node:os'),require$$1=require('node:fs'),require$$3=require('foxts/fast-string-array-join'),require$$6=require('node:perf_hooks'),require$$4=require('foxts/serialized-memo'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs');var cacheFilesystem = {};var hasRequiredCacheFilesystem; + +function requireCacheFilesystem () { + if (hasRequiredCacheFilesystem) return cacheFilesystem; + hasRequiredCacheFilesystem = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + Cache: function() { + return Cache; + }, + deserializeArray: function() { + return deserializeArray; + }, + serializeArray: function() { + return serializeArray; + } + }); + const _bettersqlite3 = /*#__PURE__*/ _interop_require_default(require$$0); + const _nodeos = /*#__PURE__*/ _interop_require_default(require$$1$1); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$2); + const _nodefs = require$$1; + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _faststringarrayjoin = require$$3; + const _nodeperf_hooks = require$$6; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + class Cache { + db; + /** Time before deletion */ tbd = 60 * 1000; + /** SQLite file path */ cachePath; + /** Table name */ tableName; + type; + statement; + constructor({ cachePath = _nodepath.default.join(_nodeos.default.tmpdir() || '/tmp', 'hdc'), tbd, tableName = 'cache', type } = {}){ + const start = _nodeperf_hooks.performance.now(); + this.cachePath = cachePath; + (0, _nodefs.mkdirSync)(this.cachePath, { + recursive: true + }); + if (tbd != null) this.tbd = tbd; + this.tableName = tableName; + if (type) { + this.type = type; + } else { + // @ts-expect-error -- fallback type + this.type = 'string'; + } + const db = (0, _bettersqlite3.default)(_nodepath.default.join(this.cachePath, 'cache.db')); + db.pragma('journal_mode = WAL'); + db.pragma('synchronous = normal'); + db.pragma('temp_store = memory'); + db.pragma('optimize'); + db.prepare(`CREATE TABLE IF NOT EXISTS ${this.tableName} (key TEXT PRIMARY KEY, value ${this.type === 'string' ? 'TEXT' : 'BLOB'}, ttl REAL NOT NULL);`).run(); + db.prepare(`CREATE INDEX IF NOT EXISTS cache_ttl ON ${this.tableName} (ttl);`).run(); + /** cache stmt */ this.statement = { + updateTtl: db.prepare(`UPDATE ${this.tableName} SET ttl = ? WHERE key = ?;`), + del: db.prepare(`DELETE FROM ${this.tableName} WHERE key = ?`), + insert: db.prepare(`INSERT INTO ${this.tableName} (key, value, ttl) VALUES ($key, $value, $valid) ON CONFLICT(key) DO UPDATE SET value = $value, ttl = $valid`), + get: db.prepare(`SELECT ttl, value FROM ${this.tableName} WHERE key = ? LIMIT 1`) + }; + const date = new Date(); + // perform purge on startup + // ttl + tbd < now => ttl < now - tbd + const now = date.getTime() - this.tbd; + db.prepare(`DELETE FROM ${this.tableName} WHERE ttl < ?`).run(now); + this.db = db; + const dateString = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`; + const lastVaccum = this.get('__LAST_VACUUM'); + if (lastVaccum === undefined || lastVaccum !== dateString && date.getUTCDay() === 6) { + console.log(_picocolors.default.magenta('[cache] vacuuming')); + this.set('__LAST_VACUUM', dateString, 10 * 365 * 60 * 60 * 24 * 1000); + this.db.exec('VACUUM;'); + } + const end = _nodeperf_hooks.performance.now(); + console.log(`${_picocolors.default.gray(`[${(end - start).toFixed(3)}ns]`)} cache initialized from ${this.tableName} @ ${this.cachePath}`); + } + set(key, value, ttl = 60 * 1000) { + const valid = Date.now() + ttl; + this.statement.insert.run({ + $key: key, + key, + $value: value, + value, + $valid: valid, + valid + }); + } + get(key) { + const rv = this.statement.get.get(key); + if (!rv) return null; + if (rv.ttl < Date.now()) { + this.del(key); + return null; + } + if (rv.value == null) { + this.del(key); + return null; + } + return rv.value; + } + updateTtl(key, ttl) { + this.statement.updateTtl.run(Date.now() + ttl, key); + } + del(key) { + this.statement.del.run(key); + } + destroy() { + this.db.close(); + } + deleteTable(tableName) { + this.db.exec(`DROP TABLE IF EXISTS ${tableName};`); + } + } + // process.on('exit', () => { + // fsFetchCache.destroy(); + // }); + const separator = '\u0000'; + const serializeArray = (arr)=>(0, _faststringarrayjoin.fastStringArrayJoin)(arr, separator); + const deserializeArray = (str)=>str.split(separator); + } (cacheFilesystem)); + return cacheFilesystem; +}var fsMemo = {};var hasRequiredFsMemo; + +function requireFsMemo () { + if (hasRequiredFsMemo) return fsMemo; + hasRequiredFsMemo = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + cache: function() { + return cache; + }, + cachedOnlyFail: function() { + return cachedOnlyFail; + } + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$2); + const _ciinfo = require$$11; + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _cachefilesystem = /*@__PURE__*/ requireCacheFilesystem(); + const _serializedmemo = require$$4; + const _dir = /*@__PURE__*/ fetchRetry.a(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const fsMemoCache = new _cachefilesystem.Cache({ + cachePath: _nodepath.default.join(_dir.ROOT_DIR, '.cache'), + tableName: 'fs_memo_cache' + }); + const fsMemoCacheProvider = { + has (key) { + return fsMemoCache.get(key) !== null; + }, + delete () { + // noop + }, + get (key) { + return fsMemoCache.get(key) ?? undefined; + }, + set (key, value, ttl) { + fsMemoCache.set(key, value, ttl); + }, + updateTtl (key, ttl) { + fsMemoCache.updateTtl(key, ttl); + } + }; + const TTL = _ciinfo.isCI ? 1.5 * 86400 * 1000 : 7 * 86400 * 1000; + const cache = (0, _serializedmemo.createMemoize)(fsMemoCacheProvider, { + defaultTtl: TTL, + onCacheMiss (key, { humanReadableName, isUseCachedIfFail }) { + const cacheName = _picocolors.default.gray(humanReadableName); + if (isUseCachedIfFail) { + console.log(_picocolors.default.red('[fail] and no cache, throwing'), cacheName); + } else { + console.log(_picocolors.default.yellow('[cache] miss'), cacheName); + } + }, + onCacheUpdate (key, { humanReadableName, isUseCachedIfFail }) { + const cacheName = _picocolors.default.gray(humanReadableName); + if (isUseCachedIfFail) { + console.log(_picocolors.default.gray('[cache] update'), cacheName); + } + }, + onCacheHit (key, { humanReadableName, isUseCachedIfFail }) { + const cacheName = _picocolors.default.gray(humanReadableName); + if (isUseCachedIfFail) { + console.log(_picocolors.default.yellow('[fail] try cache'), cacheName); + } else { + console.log(_picocolors.default.green('[cache] hit'), cacheName); + } + } + }); + const cachedOnlyFail = (0, _serializedmemo.createMemoize)(fsMemoCacheProvider, { + defaultTtl: TTL, + onlyUseCachedIfFail: true + }); // export const cache = createCache(false); + // export const cachedOnlyFail = createCache(true); + } (fsMemo)); + return fsMemo; +}exports.a=requireCacheFilesystem;exports.r=requireFsMemo; \ No newline at end of file diff --git a/Dist/chunks/index.B8Uk9n3v.cjs b/Dist/chunks/index.B8Uk9n3v.cjs new file mode 100644 index 00000000..643333c6 --- /dev/null +++ b/Dist/chunks/index.B8Uk9n3v.cjs @@ -0,0 +1,182 @@ +'use strict';const require$$2=require('foxts/noop'),require$$0=require('node:path'),require$$1=require('node:process'),require$$0$1=require('picocolors');var trace = {};var hasRequiredTrace; + +function requireTrace () { + if (hasRequiredTrace) return trace; + hasRequiredTrace = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + createSpan: function() { + return createSpan; + }, + dummySpan: function() { + return dummySpan; + }, + printTraceResult: function() { + return printTraceResult; + }, + task: function() { + return task; + }, + whyIsNodeRunning: function() { + return whyIsNodeRunning; + } + }); + const _noop = require$$2; + const _nodepath = require$$0; + const _nodeprocess = /*#__PURE__*/ _interop_require_default(require$$1); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const SPAN_STATUS_START = 0; + const SPAN_STATUS_END = 1; + const spanTag = Symbol('span'); + const rootTraceResult = { + name: 'root', + start: 0, + end: 0, + children: [] + }; + function createSpan(name, parentTraceResult) { + const start = performance.now(); + let curTraceResult; + if (parentTraceResult == null) { + curTraceResult = rootTraceResult; + } else { + curTraceResult = { + name, + start, + end: 0, + children: [] + }; + parentTraceResult.children.push(curTraceResult); + } + let status = SPAN_STATUS_START; + const stop = (time)=>{ + if (status === SPAN_STATUS_END) { + throw new Error(`span already stopped: ${name}`); + } + const end = time ?? performance.now(); + curTraceResult.end = end; + status = SPAN_STATUS_END; + }; + const traceChild = (name)=>createSpan(name, curTraceResult); + const span = { + [spanTag]: true, + stop, + traceChild, + traceSyncFn (fn) { + const res = fn(span); + span.stop(); + return res; + }, + async traceAsyncFn (fn) { + const res = await fn(span); + span.stop(); + return res; + }, + traceResult: curTraceResult, + async tracePromise (promise) { + const res = await promise; + span.stop(); + return res; + }, + traceChildSync: (name, fn)=>traceChild(name).traceSyncFn(fn), + traceChildAsync: (name, fn)=>traceChild(name).traceAsyncFn(fn), + traceChildPromise: (name, promise)=>traceChild(name).tracePromise(promise) + }; + // eslint-disable-next-line sukka/no-redundant-variable -- self reference + return span; + } + const dummySpan = createSpan(''); + function task(importMetaMain, importMetaPath) { + return (fn, customName)=>{ + const taskName = customName ?? (0, _nodepath.basename)(importMetaPath, (0, _nodepath.extname)(importMetaPath)); + let cleanup = _noop.noop; + const onCleanup = (cb)=>{ + cleanup = cb; + }; + const dummySpan = createSpan(taskName); + if (importMetaMain) { + _nodeprocess.default.on('uncaughtException', (error)=>{ + console.error('Uncaught exception:', error); + _nodeprocess.default.exit(1); + }); + _nodeprocess.default.on('unhandledRejection', (reason)=>{ + console.error('Unhandled rejection:', reason); + _nodeprocess.default.exit(1); + }); + dummySpan.traceChildAsync('dummy', (childSpan)=>fn(childSpan, onCleanup)).finally(()=>{ + dummySpan.stop(); + printTraceResult(dummySpan.traceResult); + _nodeprocess.default.nextTick(whyIsNodeRunning); + }); + } + return async (span)=>{ + if (span) { + return span.traceChildAsync(taskName, (childSpan)=>fn(childSpan, onCleanup).finally(()=>cleanup())); + } + return fn(dummySpan, onCleanup).finally(()=>cleanup()); + }; + }; + } + async function whyIsNodeRunning() { + const mod = await import('why-is-node-running'); + return mod.default(); + } + function printTraceResult(traceResult = rootTraceResult) { + printStats(traceResult.children); + printTree(traceResult, (node)=>{ + if (node.end - node.start < 0) { + return node.name; + } + return `${node.name} ${_picocolors.default.bold(`${(node.end - node.start).toFixed(3)}ms`)}`; + }); + } + function printTree(initialTree, printNode) { + function printBranch(tree, branch, isGraphHead, isChildOfLastBranch) { + const children = tree.children; + let branchHead = ''; + if (!isGraphHead) { + branchHead = children.length > 0 ? '┬ ' : '─ '; + } + const toPrint = printNode(tree, `${branch}${branchHead}`); + if (typeof toPrint === 'string') { + console.log(`${branch}${branchHead}${toPrint}`); + } + let baseBranch = branch; + if (!isGraphHead) { + baseBranch = branch.slice(0, -2) + (isChildOfLastBranch ? ' ' : '│ '); + } + const nextBranch = `${baseBranch}├─`; + const lastBranch = `${baseBranch}└─`; + children.forEach((child, index)=>{ + const last = children.length - 1 === index; + printBranch(child, last ? lastBranch : nextBranch, false, last); + }); + } + printBranch(initialTree, '', true, false); + } + function printStats(stats) { + const longestTaskName = Math.max(...stats.map((i)=>i.name.length)); + const realStart = Math.min(...stats.map((i)=>i.start)); + const realEnd = Math.max(...stats.map((i)=>i.end)); + const statsStep = (realEnd - realStart) / 120 | 0; + stats.sort((a, b)=>a.start - b.start).forEach((stat)=>{ + console.log(`[${stat.name}]${' '.repeat(longestTaskName - stat.name.length)}`, ' '.repeat((stat.start - realStart) / statsStep | 0), '='.repeat(Math.max((stat.end - stat.start) / statsStep | 0, 1))); + }); + } + } (trace)); + return trace; +}exports.r=requireTrace; \ No newline at end of file diff --git a/Dist/chunks/loose-tldts-opt.DLUpGXpj.cjs b/Dist/chunks/loose-tldts-opt.DLUpGXpj.cjs new file mode 100644 index 00000000..4fe3051e --- /dev/null +++ b/Dist/chunks/loose-tldts-opt.DLUpGXpj.cjs @@ -0,0 +1,47 @@ +'use strict';var looseTldtsOpt = {};var hasRequiredLooseTldtsOpt; + +function requireLooseTldtsOpt () { + if (hasRequiredLooseTldtsOpt) return looseTldtsOpt; + hasRequiredLooseTldtsOpt = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + loosTldOptWithPrivateDomains: function() { + return loosTldOptWithPrivateDomains; + }, + looseTldtsOpt: function() { + return looseTldtsOpt; + }, + normalizeTldtsOpt: function() { + return normalizeTldtsOpt; + } + }); + const looseTldtsOpt = { + allowPrivateDomains: false, + extractHostname: false, + validateHostname: false, + detectIp: false, + mixedInputs: false + }; + const loosTldOptWithPrivateDomains = { + ...looseTldtsOpt, + allowPrivateDomains: true + }; + const normalizeTldtsOpt = { + allowPrivateDomains: true, + // in normalizeDomain, we only care if it contains IP, we don't care if we need to extract it + // by setting detectIp to false and manually check ip outside tldts.parse, we can skip the tldts + // inner "extractHostname" call + detectIp: false + }; + } (looseTldtsOpt)); + return looseTldtsOpt; +}exports.r=requireLooseTldtsOpt; \ No newline at end of file diff --git a/Dist/chunks/memo-promise.BbOsVeGo.cjs b/Dist/chunks/memo-promise.BbOsVeGo.cjs new file mode 100644 index 00000000..1ca3f8b3 --- /dev/null +++ b/Dist/chunks/memo-promise.BbOsVeGo.cjs @@ -0,0 +1,35 @@ +'use strict';var memoPromise = {};var hasRequiredMemoPromise; + +function requireMemoPromise () { + if (hasRequiredMemoPromise) return memoPromise; + hasRequiredMemoPromise = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "createMemoizedPromise", { + enumerable: true, + get: function() { + return createMemoizedPromise; + } + }); + const notError = Symbol('notError'); + function createMemoizedPromise(fn, /** whether to create promise immediately or only create after first access */ preload = true) { + let error = notError; + let promise = preload ? fn().catch((e)=>{ + // Here we record the error so that we can throw it later when the function is called + error = e; + // Here we make sure the Promise still returns the never type + throw e; + }) : null; + return ()=>{ + if (error !== notError) { + return Promise.reject(error); + } + promise ??= fn(); + return promise; + }; + } + } (memoPromise)); + return memoPromise; +}exports.r=requireMemoPromise; \ No newline at end of file diff --git a/Dist/chunks/misc.BpcQjda1.cjs b/Dist/chunks/misc.BpcQjda1.cjs new file mode 100644 index 00000000..a4270af7 --- /dev/null +++ b/Dist/chunks/misc.BpcQjda1.cjs @@ -0,0 +1,122 @@ +'use strict';const require$$0=require('node:path'),require$$1=require('node:fs'),require$$2=require('node:fs/promises');var misc = {};var hasRequiredMisc; + +function requireMisc () { + if (hasRequiredMisc) return misc; + hasRequiredMisc = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + fastIpVersion: function() { + return fastIpVersion; + }, + fastStringCompare: function() { + return fastStringCompare; + }, + isDirectoryEmptySync: function() { + return isDirectoryEmptySync; + }, + mkdirp: function() { + return mkdirp; + }, + notSupported: function() { + return notSupported; + }, + removeFiles: function() { + return removeFiles; + }, + withBannerArray: function() { + return withBannerArray; + }, + withIdentityContent: function() { + return withIdentityContent; + }, + writeFile: function() { + return writeFile; + } + }); + const _nodepath = require$$0; + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1); + const _promises = /*#__PURE__*/ _interop_require_default(require$$2); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function fastStringCompare(a, b) { + const lenA = a.length; + const lenB = b.length; + const minLen = lenA < lenB ? lenA : lenB; + for(let i = 0; i < minLen; ++i){ + const ca = a.charCodeAt(i); + const cb = b.charCodeAt(i); + if (ca > cb) return 1; + if (ca < cb) return -1; + } + if (lenA === lenB) { + return 0; + } + return lenA > lenB ? 1 : -1; + } + function mkdirp(dir) { + if (_nodefs.default.existsSync(dir)) { + return; + } + return _promises.default.mkdir(dir, { + recursive: true + }); + } + const writeFile = async (destination, input, dir = (0, _nodepath.dirname)(destination))=>{ + const p = mkdirp(dir); + if (p) { + await p; + } + return _promises.default.writeFile(destination, input, { + encoding: 'utf-8' + }); + }; + const removeFiles = async (files)=>Promise.all(files.map((file)=>_promises.default.rm(file, { + force: true + }))); + function withBannerArray(title, description, date, content) { + return [ + '#########################################', + `# ${title}`, + `# Last Updated: ${date.toISOString()}`, + `# Size: ${content.length}`, + ...description.map((line)=>line ? `# ${line}` : '#'), + '#########################################', + ...content, + '################## EOF ##################' + ]; + } + function notSupported(name) { + return (...args)=>{ + console.error(`${name}: not supported.`, args); + throw new Error(`${name}: not implemented.`); + }; + } + function withIdentityContent(title, description, date, content) { + return content; + } + function isDirectoryEmptySync(path) { + const directoryHandle = _nodefs.default.opendirSync(path); + try { + return directoryHandle.readSync() === null; + } finally{ + directoryHandle.closeSync(); + } + } + function fastIpVersion(ip) { + return ip.includes(':') ? 6 : ip.includes('.') ? 4 : 0; + } + } (misc)); + return misc; +}exports.r=requireMisc; \ No newline at end of file diff --git a/Dist/chunks/normalize-domain.Cfz4j8eP.cjs b/Dist/chunks/normalize-domain.Cfz4j8eP.cjs new file mode 100644 index 00000000..f7299bd5 --- /dev/null +++ b/Dist/chunks/normalize-domain.Cfz4j8eP.cjs @@ -0,0 +1,79 @@ +'use strict';const require$$0=require('tldts'),looseTldtsOpt=require('./loose-tldts-opt.DLUpGXpj.cjs'),require$$2=require('foxts/is-probably-ip');var normalizeDomain = {};var hasRequiredNormalizeDomain; + +function requireNormalizeDomain () { + if (hasRequiredNormalizeDomain) return normalizeDomain; + hasRequiredNormalizeDomain = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + fastNormalizeDomain: function() { + return fastNormalizeDomain; + }, + fastNormalizeDomainWithoutWww: function() { + return fastNormalizeDomainWithoutWww; + }, + normalizeDomain: function() { + return normalizeDomain; + } + }); + const _tldts = /*#__PURE__*/ _interop_require_default(require$$0); + const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.r(); + const _isprobablyip = require$$2; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function fastNormalizeDomainWithoutWww(domain, parsed = null) { + // We don't want tldts to call its own "extractHostname" on ip, bail out ip first. + // Now ip has been bailed out, we can safely set normalizeTldtsOpt.detectIp to false. + if ((0, _isprobablyip.isProbablyIpv4)(domain) || (0, _isprobablyip.isProbablyIpv6)(domain)) { + return null; + } + parsed ??= _tldts.default.parse(domain, _loosetldtsopt.normalizeTldtsOpt); + // Private invalid domain (things like .tor, .dn42, etc) + if (!parsed.isIcann && !parsed.isPrivate) return null; + if (parsed.subdomain) { + if (parsed.subdomain === 'www') { + return parsed.domain; + } + if (parsed.subdomain.startsWith('www.')) { + return parsed.subdomain.slice(4) + '.' + parsed.domain; + } + } + return parsed.hostname; + } + function fastNormalizeDomain(domain, parsed = null) { + // We don't want tldts to call its own "extractHostname" on ip, bail out ip first. + // Now ip has been bailed out, we can safely set normalizeTldtsOpt.detectIp to false. + if ((0, _isprobablyip.isProbablyIpv4)(domain) || (0, _isprobablyip.isProbablyIpv6)(domain)) { + return null; + } + parsed ??= _tldts.default.parse(domain, _loosetldtsopt.normalizeTldtsOpt); + // Private invalid domain (things like .tor, .dn42, etc) + if (!parsed.isIcann && !parsed.isPrivate) return null; + return parsed.hostname; + } + function normalizeDomain(domain, parsed = null) { + if (domain.length === 0) return null; + if ((0, _isprobablyip.isProbablyIpv4)(domain) || (0, _isprobablyip.isProbablyIpv6)(domain)) { + return null; + } + parsed ??= _tldts.default.parse(domain, _loosetldtsopt.normalizeTldtsOpt); + // Private invalid domain (things like .tor, .dn42, etc) + if (!parsed.isIcann && !parsed.isPrivate) return null; + // const h = parsed.hostname; + // if (h === null) return null; + return parsed.hostname; + } + } (normalizeDomain)); + return normalizeDomain; +}exports.r=requireNormalizeDomain; \ No newline at end of file diff --git a/Dist/chunks/parse-dnsmasq.CiH7YJVY.cjs b/Dist/chunks/parse-dnsmasq.CiH7YJVY.cjs new file mode 100644 index 00000000..21b99bc1 --- /dev/null +++ b/Dist/chunks/parse-dnsmasq.CiH7YJVY.cjs @@ -0,0 +1,44 @@ +'use strict';const fetchTextByLine=require('./fetch-text-by-line.YY5b5610.cjs'),normalizeDomain=require('./normalize-domain.Cfz4j8eP.cjs');var parseDnsmasq = {};var hasRequiredParseDnsmasq; + +function requireParseDnsmasq () { + if (hasRequiredParseDnsmasq) return parseDnsmasq; + hasRequiredParseDnsmasq = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + extractDomainsFromFelixDnsmasq: function() { + return extractDomainsFromFelixDnsmasq; + }, + parseFelixDnsmasqFromResp: function() { + return parseFelixDnsmasqFromResp; + } + }); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _normalizedomain = /*@__PURE__*/ normalizeDomain.r(); + function extractDomainsFromFelixDnsmasq(line) { + if (line.startsWith('server=/') && line.endsWith('/114.114.114.114')) { + return line.slice(8, -16); + } + return null; + } + async function parseFelixDnsmasqFromResp(resp) { + const results = []; + for await (const line of (0, _fetchtextbyline.createReadlineInterfaceFromResponse)(resp, true)){ + const domain = extractDomainsFromFelixDnsmasq(line); + if (domain && (0, _normalizedomain.fastNormalizeDomain)(domain)) { + results.push(domain); + } + } + return results; + } + } (parseDnsmasq)); + return parseDnsmasq; +}exports.r=requireParseDnsmasq; \ No newline at end of file diff --git a/Dist/chunks/reject-data-source.DaKwvNlG.cjs b/Dist/chunks/reject-data-source.DaKwvNlG.cjs new file mode 100644 index 00000000..271829b5 --- /dev/null +++ b/Dist/chunks/reject-data-source.DaKwvNlG.cjs @@ -0,0 +1,584 @@ +'use strict';var rejectDataSource = {};var hasRequiredRejectDataSource; + +function requireRejectDataSource () { + if (hasRequiredRejectDataSource) return rejectDataSource; + hasRequiredRejectDataSource = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + ADGUARD_FILTERS: function() { + return ADGUARD_FILTERS; + }, + ADGUARD_FILTERS_EXTRA: function() { + return ADGUARD_FILTERS_EXTRA; + }, + ADGUARD_FILTERS_WHITELIST: function() { + return ADGUARD_FILTERS_WHITELIST; + }, + CRASHLYTICS_WHITELIST: function() { + return CRASHLYTICS_WHITELIST; + }, + DEBUG_DOMAIN_TO_FIND: function() { + return DEBUG_DOMAIN_TO_FIND; + }, + DOMAIN_LISTS: function() { + return DOMAIN_LISTS; + }, + DOMAIN_LISTS_EXTRA: function() { + return DOMAIN_LISTS_EXTRA; + }, + HOSTS: function() { + return HOSTS; + }, + HOSTS_EXTRA: function() { + return HOSTS_EXTRA; + }, + PHISHING_DOMAIN_LISTS_EXTRA: function() { + return PHISHING_DOMAIN_LISTS_EXTRA; + }, + PHISHING_HOSTS_EXTRA: function() { + return PHISHING_HOSTS_EXTRA; + }, + PREDEFINED_WHITELIST: function() { + return PREDEFINED_WHITELIST; + } + }); + const DEBUG_DOMAIN_TO_FIND = null; // example.com | null + const HOSTS = [ + [ + // WindowsSpyBlocker hasn't been updated since 2022-06-16, let's use jsDelivr as primary URL + 'https://cdn.jsdelivr.net/gh/crazy-max/WindowsSpyBlocker@master/data/hosts/spy.txt', + [ + 'https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt' + ], + true + ], + [ + 'https://raw.githubusercontent.com/jerryn70/GoodbyeAds/master/Extension/GoodbyeAds-Xiaomi-Extension.txt', + null, + false + ], + [ + 'https://raw.githubusercontent.com/jerryn70/GoodbyeAds/master/Extension/GoodbyeAds-Huawei-AdBlock.txt', + null, + false + ] + ]; + const HOSTS_EXTRA = [ + [ + 'https://raw.githubusercontent.com/durablenapkin/block/master/tvstream.txt', + null, + true + ], + // This stupid hosts blocks t.co, so we determine that this is also bullshit, so it is extra + [ + 'https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext', + [ + 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/thirdparties/pgl.yoyo.org/as/serverlist' + ], + true + ], + // Dan Pollock's hosts file, 0.0.0.0 version is 30 KiB smaller + [ + 'https://someonewhocares.org/hosts/zero/hosts', + [ + 'https://proxy.cdn.skk.moe/https/someonewhocares.org/hosts/zero/hosts' + ], + true + ], + // ad-wars is not actively maintained since 2023.11, so we use jsDelivr as primary URL + [ + 'https://cdn.jsdelivr.net/gh/jdlingyu/ad-wars@master/hosts', + [ + 'https://raw.githubusercontent.com/jdlingyu/ad-wars/master/hosts' + ], + false + ] + ]; + const DOMAIN_LISTS = []; + const DOMAIN_LISTS_EXTRA = [ + // CoinBlockerList - Full + // The CoinBlockerList is no longer maintained and even close-source, so we no longer trust it + // instead we maintain a list of our own + // BarbBlock + // The barbblock list has never been updated since 2019-05, so we set a 14 days cache ttl + [ + 'https://paulgb.github.io/BarbBlock/blacklists/domain-list.txt', + [ + 'https://raw.githubusercontent.com/paulgb/BarbBlock/refs/heads/main/blacklists/domain-list.txt' + ], + true + ], + // DigitalSide Threat-Intel - OSINT Hub + // Update once per day + [ + 'https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt', + [], + true + ], + // AdGuard CNAME Filter Combined + // Update on a 7 days basis, so we can also use jsDelivr as primary URL + [ + 'https://cdn.jsdelivr.net/gh/AdguardTeam/cname-trackers@master/data/combined_disguised_ads_justdomains.txt', + [ + 'https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/data/combined_disguised_ads_justdomains.txt' + ], + true + ], + [ + 'https://cdn.jsdelivr.net/gh/AdguardTeam/cname-trackers@master/data/combined_disguised_trackers_justdomains.txt', + [ + 'https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/data/combined_disguised_trackers_justdomains.txt' + ], + true + ], + [ + 'https://cdn.jsdelivr.net/gh/AdguardTeam/cname-trackers@master/data/combined_disguised_clickthroughs_justdomains.txt', + [ + 'https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/data/combined_disguised_clickthroughs_justdomains.txt' + ], + true + ], + [ + 'https://cdn.jsdelivr.net/gh/AdguardTeam/cname-trackers@master/data/combined_disguised_microsites_justdomains.txt', + [ + 'https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/data/combined_disguised_microsites_justdomains.txt' + ], + true + ], + // ['https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/data/combined_disguised_mail_trackers_justdomains.txt', [], true], + // Curben's PUP Domains Blocklist + // The PUP filter has paused the update since 2023-05, so we set a 14 days cache ttl, and move it to extra + // [ + // 'https://pup-filter.pages.dev/pup-filter-domains.txt', + // [ + // // 'https://malware-filter.pages.dev/pup-filter-domains.txt', + // // 'https://malware-filter.gitlab.io/malware-filter/pup-filter-domains.txt', + // 'https://malware-filter.gitlab.io/pup-filter/pup-filter-domains.txt' + // // 'https://curbengh.github.io/pup-filter/pup-filter-domains.txt', + // // 'https://malware-filter.pages.dev/pup-filter-domains.txt' + // ], + // true + // ], + // Curben's UrlHaus Malicious URL Blocklist + [ + 'https://urlhaus-filter.pages.dev/urlhaus-filter-domains.txt', + [ + 'https://malware-filter.pages.dev/urlhaus-filter-domains.txt', + 'https://malware-filter.gitlab.io/urlhaus-filter/urlhaus-filter-domains.txt', + 'https://malware-filter.gitlab.io/malware-filter/urlhaus-filter-domains.txt', + 'https://curbengh.github.io/urlhaus-filter/urlhaus-filter-domains.txt' + ], + true + ], + // Spam404 + // Not actively maintained, let's use jsDelivr as primary URL + [ + 'https://cdn.jsdelivr.net/gh/Spam404/lists@master/main-blacklist.txt', + [ + 'https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt' + ], + true + ] + ]; + const PHISHING_HOSTS_EXTRA = [ + [ + 'https://raw.githubusercontent.com/durablenapkin/scamblocklist/master/hosts.txt', + [], + true + ] + ]; + const PHISHING_DOMAIN_LISTS_EXTRA = [ + [ + 'https://phishing-filter.pages.dev/phishing-filter-domains.txt', + [ + 'https://malware-filter.pages.dev/phishing-filter-domains.txt', + 'https://malware-filter.gitlab.io/phishing-filter/phishing-filter-domains.txt', + 'https://malware-filter.gitlab.io/malware-filter/phishing-filter-domains.txt', + 'https://curbengh.github.io/phishing-filter/phishing-filter-domains.txt' + ], + true + ], + [ + 'https://phishing.army/download/phishing_army_blocklist.txt', + [], + true + ] + ]; + const ADGUARD_FILTERS = [ + // EasyList + [ + 'https://easylist.to/easylist/easylist.txt', + [ + 'https://easylist-downloads.adblockplus.org/easylist.txt', + 'https://secure.fanboy.co.nz/easylist.txt', + 'https://ublockorigin.github.io/uAssetsCDN/thirdparties/easylist.txt', + 'https://ublockorigin.pages.dev/thirdparties/easylist.txt', + 'https://raw.githubusercontent.com/easylist/easylist/gh-pages/easylist.txt', + 'https://filters.adtidy.org/extension/ublock/filters/101_optimized.txt' + ] + ], + // EasyPrivacy + [ + 'https://easylist.to/easylist/easyprivacy.txt', + [ + 'https://easylist-downloads.adblockplus.org/easyprivacy.txt', + 'https://secure.fanboy.co.nz/easyprivacy.txt', + 'https://ublockorigin.github.io/uAssetsCDN/thirdparties/easyprivacy.txt', + 'https://ublockorigin.pages.dev/thirdparties/easyprivacy.txt', + 'https://raw.githubusercontent.com/easylist/easylist/gh-pages/easyprivacy.txt', + 'https://filters.adtidy.org/extension/ublock/filters/118_optimized.txt' + ] + ], + // AdGuard Base Filter + [ + 'https://filters.adtidy.org/extension/ublock/filters/2_without_easylist.txt', + [ + 'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/2_without_easylist.txt' + ] + ], + // AdGuard Mobile AD + [ + 'https://filters.adtidy.org/extension/ublock/filters/11_optimized.txt', + [ + 'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/2_without_easylist.txt' + ] + ], + // AdGuard Tracking Protection + [ + 'https://filters.adtidy.org/extension/ublock/filters/3_optimized.txt', + [ + 'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/3_optimized.txt' + ] + ], + // AdGuard Chinese filter (EasyList China + AdGuard Chinese filter) + [ + 'https://filters.adtidy.org/extension/ublock/filters/224_optimized.txt', + [ + 'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/224_optimized.txt' + ] + ], + // GameConsoleAdblockList + // Update almost once per 1 to 3 months, let's set a 10 days cache ttl + [ + 'https://cdn.jsdelivr.net/gh/DandelionSprout/adfilt@master/GameConsoleAdblockList.txt', + [ + 'https://raw.githubusercontent.com/DandelionSprout/adfilt/master/GameConsoleAdblockList.txt' + ] + ], + // PiHoleBlocklist + // Update almost once per 3 months, let's set a 10 days cache ttl + [ + 'https://perflyst.github.io/PiHoleBlocklist/SmartTV-AGH.txt', + [ + 'https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/SmartTV-AGH.txt' + ] + ], + // uBlock Origin Unbreak + [ + 'https://ublockorigin.github.io/uAssetsCDN/filters/unbreak.min.txt', + [ + 'https://ublockorigin.pages.dev/filters/unbreak.min.txt' + ] + ] + ]; + const ADGUARD_FILTERS_WHITELIST = [ + [ + 'https://adguardteam.github.io/AdGuardSDNSFilter/Filters/exceptions.txt', + [ + 'https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/Filters/exceptions.txt' + ] + ], + [ + 'https://adguardteam.github.io/AdGuardSDNSFilter/Filters/exclusions.txt', + [ + 'https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/Filters/exclusions.txt' + ] + ] + ]; + const ADGUARD_FILTERS_EXTRA = [ + // AdGuard DNS Filter + // way too many other countries' domains (JP, Spanish, RU, VN, Turkish, Ukarainian, Dutch, etc.) + // EasyList, EasyPrivacy, Chinese and general filters are already included in base data source + [ + 'https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt', + [ + 'https://filters.adtidy.org/extension/ublock/filters/15_optimized.txt', + 'https://adguardteam.github.io/HostlistsRegistry/assets/filter_1.txt' + ] + ], + // no coin list adguard list is more maintained than its hosts + [ + 'https://raw.githubusercontent.com/hoshsadiq/adblock-nocoin-list/master/nocoin.txt', + [], + true + ], + // AdGuard Annoyances filter + [ + 'https://filters.adtidy.org/extension/ublock/filters/14_optimized.txt', + [ + 'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/14_optimized.txt' + ], + true + ], + // AdGuard Cookie Notices, included in Annoyances filter + // ['https://filters.adtidy.org/extension/ublock/filters/18_optimized.txt', null, true], + // EasyList Germany filter, not even included in extra for now + // [ + // 'https://easylist.to/easylistgermany/easylistgermany.txt', + // [ + // 'https://easylist-downloads.adblockplus.org/easylistgermany.txt' + // ], + // + // ], + // AdGuard Japanese filter + [ + 'https://filters.adtidy.org/extension/ublock/filters/7_optimized.txt', + [ + 'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/7_optimized.txt' + ] + ], + // uBlock Origin Filter List + [ + 'https://ublockorigin.github.io/uAssetsCDN/filters/filters.min.txt', + [ + 'https://ublockorigin.pages.dev/filters/filters.min.txt' + ] + ], + // AdGuard Popup Overlay - included in Annoyances filter + // ['https://filters.adtidy.org/extension/ublock/filters/19_optimized.txt', null, true], + // AdGuard Mobile Banner + // almost all generic rule + // ['https://filters.adtidy.org/extension/ublock/filters/20_optimized.txt', null], + // uBlock Origin Badware Risk List + [ + 'https://ublockorigin.github.io/uAssetsCDN/filters/badware.min.txt', + [ + 'https://ublockorigin.pages.dev/filters/badware.min.txt' + ] + ], + // uBlock Origin Privacy List + [ + 'https://ublockorigin.github.io/uAssetsCDN/filters/privacy.min.txt', + [ + 'https://ublockorigin.pages.dev/filters/privacy.min.txt' + ] + ], + // uBlock Origin Resource Abuse: merged in uBlock Origin Privacy List + // [ + // 'https://ublockorigin.github.io/uAssetsCDN/filters/resource-abuse.txt', + // ['https://ublockorigin.pages.dev/filters/resource-abuse.txt'] + // ], + // uBlock Origin Annoyances (the un-merged of Fanboy Annoyances List) + [ + 'https://ublockorigin.github.io/uAssetsCDN/filters/annoyances.min.txt', + [ + 'https://ublockorigin.pages.dev/filters/annoyances.min.txt' + ] + ], + // EasyList Annoyances + [ + 'https://ublockorigin.github.io/uAssetsCDN/thirdparties/easylist-annoyances.txt', + [ + 'https://ublockorigin.pages.dev/thirdparties/easylist-annoyances.txt' + ] + ], + // EasyList - Newsletters + [ + 'https://ublockorigin.github.io/uAssetsCDN/thirdparties/easylist-newsletters.txt', + [ + 'https://ublockorigin.pages.dev/thirdparties/easylist-newsletters.txt' + ] + ], + // EasyList - Notifications + [ + 'https://ublockorigin.github.io/uAssets/thirdparties/easylist-notifications.txt', + [ + 'https://ublockorigin.pages.dev/thirdparties/easylist-notifications.txt' + ] + ], + // Fanboy Cookie Monster (EasyList Cookie List) + [ + 'https://ublockorigin.github.io/uAssets/thirdparties/easylist-cookies.txt', + [ + 'https://ublockorigin.pages.dev/thirdparties/easylist-cookies.txt', + 'https://secure.fanboy.co.nz/fanboy-cookiemonster_ubo.txt' + ] + ], + // Dandelion Sprout's Annoyances + [ + 'https://filters.adtidy.org/extension/ublock/filters/250_optimized.txt', + [ + 'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/250_optimized.txt' + ], + true + ], + // Adblock Warning Removal List + [ + 'https://easylist-downloads.adblockplus.org/antiadblockfilters.txt', + [ + 'https://filters.adtidy.org/extension/ublock/filters/207_optimized.txt' + ], + true + ] + ]; + const CRASHLYTICS_WHITELIST = [ + // VSCode Telemetry, see https://sts.online.visualstudio.com/api/swagger/index.html + 'sts.online.visualstudio.com', + // Sentry + '.ingest.sentry.io', + '.ingest.us.sentry.io', + '.ingest.de.sentry.io', + // bugsnag + '.sessions.bugsnag.com', + '.notify.bugsnag.com', + // influxdata + '.cloud.influxdata.com', + '.cloud1.influxdata.com', + '.cloud2.influxdata.com', + // split.io A/B flag + 'streaming.split.io', + 'telemetry.split.io', + 'sdk.split.io', + // Google + // -ds.metric.gstatic.com are specifically exempted from reject, but it could use secondary proxy policy + '.metric.gstatic.com', + // Misc + 'telemetry.1passwordservices.com', + 'events.tableplus.com', + 'telemetry.nextjs.org', + 'telemetry.vercel.com', + 'stats.setapp.com', + 'stats.setapp.macpaw.dev', + '.app-analytics-services.com', + '.telemetry.services.yofi.ai', + '.cdn.pubnub.com', + '.data.debugbear.com', + '.cdn.applicationinsights.io', + '.applicationinsights.azure.com', + '.applicationinsights.azure.cn', + '.api.loganalytics.io', + '.bugly.qcloud.com', + '.cdn.signalfx.com', + '.crash-reports.browser.yandex.net', + '.crashlytics2.l.google.com', + '.crashlyticsreports-pa.googleapis.com', + '.e.crashlytics.com', + '.events.backtrace.io', + 'auth.split.io', + 'events.split.io', + 'streaming.split.io', + '.in.appcenter.ms', + '.loggly.com', + '.logz.io', + '.opentelemetry.io', + '.raygun.io', + '.rum.cronitor.io', + '.settings.crashlytics.com', + '.sny.monosnap.com', + '.lr-ingest.com', + '.cdn.rollbar.com', + '.api.instabug.com', + '.ensighten.com', + 'api.crashguard.me' + ]; + const PREDEFINED_WHITELIST = [ + ...CRASHLYTICS_WHITELIST, + '.localhost', + '.local', + '.localdomain', + '.broadcasthost', + '.ip6-loopback', + '.ip6-localnet', + '.ip6-mcastprefix', + '.ip6-allnodes', + '.ip6-allrouters', + '.ip6-allhosts', + '.mcastprefix', + '.skk.moe', + 'analytics.google.com', + '.cloud.answerhub.com', + 'ae01.alicdn.com', + '.whoami.akamai.net', + '.whoami.ds.akahelp.net', + '.instant.page', + '.piwik.pro', + 'mixpanel.com', + 'cdn.mxpnl.com', + '.heapanalytics.com', + '.segment.com', + '.segmentify.com', + '.t.co', + '.survicate.com', + '.perfops.io', + '.d2axgrpnciinw7.cloudfront.net', + '.sb-cd.com', + '.storage.yandexcloud.net', + '.login.microsoftonline.com', + 'api.xiaomi.com', + 'api.io.mi.com', + '.cdn.userreport.com', + '.ip-api.com', + '.fastly-analytics.com', + '.digitaloceanspaces.com', + 's3.nl-ams.scw.cloud', + '.geolocation-db.com', + '.uploads.codesandbox.io', + '.vlscppe.microsoft.com', + '.statsig.com', + '.pstmrk.it', + '.clicks.mlsend.com', + 'email.accounts.bitly.com', + 'adsense.google.com', + 'api.vip.miui.com', + 'api.comm.miui.com', + '.ai.api.xiaomi.com', + 'm.stripe.com', + // yet stupid AdGuardDNSFilter blocks all of it. Stupid AdGuard + '.w3s.link', + '.r2.dev', + 'mlsend.com', + 'ab.chatgpt.com', + 'jnn-pa.googleapis.com', + 'imasdk.googleapis.com', + '.l.qq.com', + '.in-addr.arpa', + '.ip6.arpa', + '.clients.your-server.de', + '.bc.googleusercontent.com', + '.host.secureserver.net', + '.ip.linodeusercontent.com', + '.static.akamaitechnologies.com', + '.compute.amazonaws.com', + '.shoppy.gg', + 'transcend-cdn.com', + 'store1.gofile.io', + 'ad.12306.cn', + '.ib.snssdk.com', + '.nstool.netease.com', + '.wns.windows.com', + '.lon.llnw.net', + '.lcy.llnw.net', + 'repo.huaweicloud.com', + '.hubspotlinks.com', + 'cldup.com', + // Doesn't make sense: CNAME domains + '.cdn.cloudflare.net', + '.apple-dns.net', + '.data.microsoft.com.akadns.net', + // Expired domains + '.expobarrio.com', + '.hamdandates.com', + '.amzone.co.jp' + ]; + } (rejectDataSource)); + return rejectDataSource; +}exports.r=requireRejectDataSource; \ No newline at end of file diff --git a/Dist/chunks/ruleset.iYH0XOC1.cjs b/Dist/chunks/ruleset.iYH0XOC1.cjs new file mode 100644 index 00000000..9af43afe --- /dev/null +++ b/Dist/chunks/ruleset.iYH0XOC1.cjs @@ -0,0 +1,59 @@ +'use strict';const base=require('./base.C13YY5P3.cjs');var ruleset = {};var hasRequiredRuleset; + +function requireRuleset () { + if (hasRequiredRuleset) return ruleset; + hasRequiredRuleset = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + ClashOnlyRulesetOutput: function() { + return ClashOnlyRulesetOutput; + }, + RulesetOutput: function() { + return RulesetOutput; + }, + SurgeOnlyRulesetOutput: function() { + return SurgeOnlyRulesetOutput; + } + }); + const _clash = /*@__PURE__*/ base.c(); + const _singbox = /*@__PURE__*/ base.f(); + const _surge = /*@__PURE__*/ base.e(); + const _base = /*@__PURE__*/ base.b(); + class RulesetOutput extends _base.FileOutput { + constructor(span, id, type){ + super(span, id); + this.strategies = [ + new _surge.SurgeRuleSet(type), + new _clash.ClashClassicRuleSet(type), + new _singbox.SingboxSource(type) + ]; + } + } + class SurgeOnlyRulesetOutput extends _base.FileOutput { + constructor(span, id, type, overrideOutputDir){ + super(span, id); + this.strategies = [ + new _surge.SurgeRuleSet(type, overrideOutputDir) + ]; + } + } + class ClashOnlyRulesetOutput extends _base.FileOutput { + constructor(span, id, type){ + super(span, id); + this.strategies = [ + new _clash.ClashClassicRuleSet(type) + ]; + } + } + } (ruleset)); + return ruleset; +}exports.r=requireRuleset; \ No newline at end of file diff --git a/Dist/chunks/stream.C9eZuk9f.cjs b/Dist/chunks/stream.C9eZuk9f.cjs new file mode 100644 index 00000000..836d9467 --- /dev/null +++ b/Dist/chunks/stream.C9eZuk9f.cjs @@ -0,0 +1,858 @@ +'use strict';var stream = {};var hasRequiredStream; + +function requireStream () { + if (hasRequiredStream) return stream; + hasRequiredStream = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + ALL: function() { + return ALL; + }, + AU: function() { + return AU; + }, + EU: function() { + return EU; + }, + HK: function() { + return HK; + }, + JP: function() { + return JP; + }, + KR: function() { + return KR; + }, + NORTH_AMERICA: function() { + return NORTH_AMERICA; + }, + SOUTH_EAST_ASIA: function() { + return SOUTH_EAST_ASIA; + }, + TW: function() { + return TW; + } + }); + const $4GTV = { + name: '4gtv', + rules: [ + 'DOMAIN-SUFFIX,4gtv.tv', + 'DOMAIN,4gtvfreepcvod-cds.cdn.hinet.net' + ] + }; + const ALL4 = { + name: 'All4', + rules: [ + 'DOMAIN-SUFFIX,c4assets.com', + 'DOMAIN-SUFFIX,channel4.com', + 'USER-AGENT,All4*' + ] + }; + const AMAZON_PRIME_VIDEO = { + name: 'Amazon Prime Video', + rules: [ + 'DOMAIN,avodmp4s3ww-a.akamaihd.net', + 'DOMAIN,d1v5ir2lpwr8os.cloudfront.net', + 'DOMAIN,d22qjgkvxw22r6.cloudfront.net', + 'DOMAIN,d25xi40x97liuc.cloudfront.net', + 'DOMAIN,dmqdd6hw24ucf.cloudfront.net', + 'DOMAIN,d27xxe7juh1us6.cloudfront.net', + 'DOMAIN,d184dfn36gombl.cloudfront.net', + 'DOMAIN,d1xfray82862hr.cloudfront.net', + 'DOMAIN,d3196yreox78o9.cloudfront.net', + 'DOMAIN-KEYWORD,avoddashs', + 'DOMAIN-SUFFIX,aiv-cdn.net', + 'DOMAIN-SUFFIX,aiv-delivery.net', + 'DOMAIN-SUFFIX,amazonvideo.com', + 'DOMAIN-SUFFIX,amazonvideo.cc', + 'DOMAIN-SUFFIX,media-amazon.com', + 'DOMAIN-SUFFIX,primevideo.com', + 'DOMAIN-SUFFIX,prime-video.com', + 'DOMAIN-SUFFIX,primevideo.cc', + 'DOMAIN-SUFFIX,primevideo.info', + 'DOMAIN-SUFFIX,primevideo.org', + 'DOMAIN-SUFFIX,primevideo.tv', + 'DOMAIN-SUFFIX,amazonvideodirect.cc', + 'DOMAIN-SUFFIX,amazonprimevideos.com', + 'DOMAIN-SUFFIX,atv-ps.amazon.com', + 'DOMAIN-SUFFIX,avodmp4s3ww-a.akamaihd.net', + 'DOMAIN-SUFFIX,fls-na.amazon.com', + 'USER-AGENT,InstantVideo.US*', + 'USER-AGENT,Prime Video*', + 'PROCESS-NAME,com.amazon.avod.thirdpartyclient' + ] + }; + const ABEMA_TV = { + name: 'AbemaTV', + rules: [ + // Pure Front-End detection https://ds-linear-abematv.akamaized.net/region check HTTP 200 + 'DOMAIN,ds-linear-abematv.akamaized.net', + 'DOMAIN-SUFFIX,abema.io', + 'DOMAIN-SUFFIX,abema.tv', + 'DOMAIN-SUFFIX,ameba.jp', + 'DOMAIN-SUFFIX,abema-tv.com', + 'DOMAIN-SUFFIX,hayabusa.dev', + 'DOMAIN-SUFFIX,hayabusa.io', + 'DOMAIN-SUFFIX,hayabusa.media', + 'DOMAIN-SUFFIX,amebame.com', + 'DOMAIN-SUFFIX,amebaownd.com', + 'DOMAIN-SUFFIX,amebaowndme.com', + 'DOMAIN-SUFFIX,ameblo.jp', + 'DOMAIN-SUFFIX,dokusho-ojikan.jp', + 'DOMAIN-SUFFIX,winticket.jp', + 'USER-AGENT,AbemaTV*' + ] + }; + const APPLE_TV = { + name: 'Apple TV', + rules: [ + 'DOMAIN,ocvideo.apple.com', + 'DOMAIN,linear.tv.apple.com', + 'DOMAIN,play-edge.itunes.apple.com', + 'DOMAIN,np-edge.itunes.apple.com', + 'DOMAIN,uts-api.itunes.apple.com', + 'DOMAIN,hls-amt.itunes.apple.com', + 'DOMAIN,hls.itunes.apple.com', + 'USER-AGENT,AppleTV*', + 'USER-AGENT,com.apple.tv*', + 'PROCESS-NAME,tv' + ] + }; + const APPLE_MUSIC_TV = { + name: 'Apple Music TV', + rules: [ + 'DOMAIN-SUFFIX,applemusic.com', + 'PROCESS-NAME,music' + ] + }; + const BAHAMUT = { + name: 'Bahamut', + rules: [ + // 'DOMAIN,bahamut.akamaized.net', // Akamai based CDN, no geoblock at all + 'DOMAIN,gamer-cds.cdn.hinet.net', + 'DOMAIN,gamer2-cds.cdn.hinet.net', + 'DOMAIN-SUFFIX,viblast.com', + 'DOMAIN-SUFFIX,bahamut.com.tw', + 'DOMAIN-SUFFIX,ani.gamer.com.tw', + 'USER-AGENT,Anime*' + ] + }; + const BBC = { + name: 'BBC', + rules: [ + 'DOMAIN-SUFFIX,tvlicensing.co.uk', + 'DOMAIN-KEYWORD,bbcfmt', + 'DOMAIN-KEYWORD,uk-live', + 'DOMAIN-SUFFIX,bbc.co.uk', + 'DOMAIN-SUFFIX,bbci.co.uk', + 'USER-AGENT,BBCiPlayer*' + ] + }; + const BILIBILI_INTL = { + name: 'Bilibili International', + rules: [ + 'DOMAIN-SUFFIX,biliintl.com', + 'DOMAIN,apm-misaka.biliapi.net', + 'DOMAIN,upos-bstar-mirrorakam.akamaized.net', + 'DOMAIN,upos-bstar1-mirrorakam.akamaized.net', + // upos-sz-mirroralibstar1.bilivideo.com, from domain bilivideo.com and without geoblocking + 'DOMAIN-SUFFIX,bilibili.tv', + 'PROCESS-NAME,com.bstar.intl' + ] + }; + const DAZN = { + name: 'DAZN', + rules: [ + 'DOMAIN,d151l6v8er5bdm.cloudfront.net', + 'DOMAIN,d1sgwhnao7452x.cloudfront.net', + 'DOMAIN-KEYWORD,voddazn', + 'DOMAIN-SUFFIX,dazn-api.com', + 'DOMAIN-SUFFIX,dazn.com', + 'DOMAIN-SUFFIX,dazndn.com', + 'DOMAIN-SUFFIX,indazn.com', + 'DOMAIN-SUFFIX,indaznlab.com', + 'DOMAIN-SUFFIX,dca-ll-livedazn-dznlivejp.s.llnwi.net', + 'DOMAIN-SUFFIX,dcalivedazn.akamaized.net', + 'DOMAIN-SUFFIX,dcblivedazn.akamaized.net', + 'USER-AGENT,DAZN*' + ] + }; + const DEEZER = { + name: 'Deezer', + rules: [ + 'DOMAIN-SUFFIX,deezer.com', + 'DOMAIN-SUFFIX,dzcdn.net', + 'USER-AGENT,Deezer*' + ] + }; + const DISNEY_PLUS = { + name: 'Disney+', + rules: [ + 'DOMAIN,cdn.registerdisney.go.com', + 'DOMAIN-SUFFIX,bamgrid.com', + 'DOMAIN-SUFFIX,disney-plus.net', + 'DOMAIN-SUFFIX,disneyplus.com', + 'DOMAIN-SUFFIX,dssott.com', + 'DOMAIN-SUFFIX,disneystreaming.com', + 'USER-AGENT,Disney+*' + ] + }; + const DISCOVERY_PLUS = { + name: 'Discovery+', + rules: [ + 'USER-AGENT,DPlus*', + 'USER-AGENT,discovery+*', + 'DOMAIN-SUFFIX,disco-api.com', + 'DOMAIN-SUFFIX,discoveryplus.co.uk', + 'DOMAIN-SUFFIX,discoveryplus.com', + 'DOMAIN-SUFFIX,discoveryplus.in', + 'DOMAIN-SUFFIX,dnitv.com' + ] + }; + const DMM = { + name: 'DMM', + rules: [ + 'DOMAIN-SUFFIX,dmm.co.jp', + 'DOMAIN-SUFFIX,dmm.com', + 'DOMAIN-SUFFIX,dmm-extension.com' + ] + }; + const ENCORE_TVB = { + name: 'encoreTVB', + rules: [ + 'DOMAIN,bcbolt446c5271-a.akamaihd.net', + 'DOMAIN,edge.api.brightcove.com', + 'DOMAIN-SUFFIX,encoretvb.com', + 'USER-AGENT,encoreTVB*', + 'USER-AGENT,TVer-Release*' + ] + }; + const ENCORE_TVB_JP_TVER = { + name: 'encoreTVB JP', + rules: [ + 'DOMAIN-SUFFIX,tver.jp' + ] + }; + const FOX_NOW = { + name: 'Fox Now', + rules: [ + 'DOMAIN-SUFFIX,fox.com', + 'DOMAIN-SUFFIX,foxdcg.com', + 'DOMAIN-SUFFIX,uplynk.com', + 'USER-AGENT,FOX NOW*' + ] + }; + const FOX_PLUS = { + name: 'Fox+', + rules: [ + 'DOMAIN,dashasiafox.akamaized.net', + 'DOMAIN,staticasiafox.akamaized.net', + 'DOMAIN-SUFFIX,foxplus.com', + 'DOMAIN-SUFFIX,theplatform.com', + 'USER-AGENT,FOXPlus*' + ] + }; + const HBO = { + name: 'HBO Go / HBO Now / HBO Max / Max', + rules: [ + 'DOMAIN-SUFFIX,hbo.com', + 'DOMAIN-SUFFIX,hbogo.com', + 'DOMAIN-SUFFIX,hbonow.com', + 'USER-AGENT,HBO NOW*', + 'USER-AGENT,HBOMAX*', + 'DOMAIN-SUFFIX,hbomax.com', + 'DOMAIN-SUFFIX,hbomaxcdn.com', + // 'USER-AGENT,Max', + // 'PROCESS-NAME,com.wbd.stream', + 'DOMAIN-SUFFIX,max.com', + 'DOMAIN-SUFFIX,discomax.com' + ] + }; + const HBO_ASIA = { + name: 'HBO Asia', + rules: [ + 'DOMAIN-SUFFIX,hboasia.com', + 'DOMAIN-SUFFIX,hbogoasia.com', + 'DOMAIN-SUFFIX,hbogoasia.hk', + 'DOMAIN-KEYWORD,.hbogoasia.', + 'DOMAIN,44wilhpljf.execute-api.ap-southeast-1.amazonaws.com', + // 'DOMAIN,bcbolthboa-a.akamaihd.net', + // 'DOMAIN,cf-images.ap-southeast-1.prod.boltdns.net', + // 'DOMAIN,dai3fd1oh325y.cloudfront.net', + // 'DOMAIN,hboasia1-i.akamaihd.net', + // 'DOMAIN,hboasia2-i.akamaihd.net', + // 'DOMAIN,hboasia3-i.akamaihd.net', + // 'DOMAIN,hboasia4-i.akamaihd.net', + // 'DOMAIN,hboasia5-i.akamaihd.net', + // 'DOMAIN,hbogoprod-vod.akamaized.net', + 'DOMAIN,manifest.prod.boltdns.net', + 'DOMAIN,players.brightcove.net', + // 'DOMAIN,hboasialive.akamaized.net', + 'DOMAIN,hbounify-prod.evergent.com', + 'DOMAIN,hbolb.onwardsmg.com' + ] + }; + const HIMALAYA_FM = { + name: 'Himalaya FM', + rules: [ + 'USER-AGENT,Himalaya*', + 'DOMAIN-SUFFIX,himalaya.com' + ] + }; + const HULU = { + name: 'Hulu', + rules: [ + 'DOMAIN-SUFFIX,hulu.com', + 'DOMAIN-SUFFIX,hulu.tv', + 'DOMAIN-SUFFIX,hulu.us', + 'DOMAIN-SUFFIX,huluim.com', + 'DOMAIN-SUFFIX,hulustream.com', + 'USER-AGENT,Hulu*', + 'PROCESS-NAME,com.hulu.plus' + ] + }; + const HULU_JP = { + name: 'Hulu Japan', + rules: [ + 'DOMAIN-SUFFIX,happyon.jp', + 'DOMAIN-SUFFIX,hjholdings.jp', + 'DOMAIN-SUFFIX,hulu.jp' + ] + }; + const HWTV = { + name: 'HWTV', + rules: [ + 'USER-AGENT,HWTVMobile*', + 'DOMAIN-SUFFIX,5itv.tv', + 'DOMAIN-SUFFIX,ocnttv.com' + ] + }; + const ITV = { + name: 'ITV', + rules: [ + 'DOMAIN,itvpnpmobile-a.akamaihd.net', + 'DOMAIN-SUFFIX,itv.com', + 'USER-AGENT,ITV_Player*' + ] + }; + const IQIYI_GLOBAL = { + name: 'iQiYi Global', + rules: [ + 'DOMAIN-SUFFIX,iq.com', + 'DOMAIN,cache.video.iqiyi.com', + 'DOMAIN,cache-video.iq.com', + 'DOMAIN,akmcdnoversea-tw.inter.ptqy.gitv.tv', + 'DOMAIN,chuangcachecdnoversea-tw.inter.ptqy.gitv.tv', + 'DOMAIN-SUFFIX,inter.iqiyi.com', + 'DOMAIN-SUFFIX,intl-rcd.iqiyi.com', + 'DOMAIN-SUFFIX,intl-subscription.iqiyi.com', + 'DOMAIN-SUFFIX,intl.iqiyi.com' + ] + }; + const JOOX = { + name: 'JOOX', + rules: [ + 'DOMAIN-SUFFIX,joox.com', + 'DOMAIN-KEYWORD,jooxweb-api', + 'USER-AGENT,JOOX*', + 'USER-AGENT,WeMusic*', + 'PROCESS-NAME,com.tencent.ibg.joox' + ] + }; + const KKBOX = { + name: 'KKBOX', + rules: [ + 'DOMAIN-SUFFIX,kfs.io', + 'DOMAIN-SUFFIX,kkbox.com', + 'DOMAIN-SUFFIX,kkbox.com.tw', + 'DOMAIN-SUFFIX,kkbox-prime.com', + 'DOMAIN-SUFFIX,kktix.com' + ] + }; + const KKTV = { + name: 'KKTV', + rules: [ + 'DOMAIN-SUFFIX,kk.stream', + 'DOMAIN-SUFFIX,kktv.com.tw', + 'DOMAIN-SUFFIX,kktv.me', + 'USER-AGENT,com.kktv.ios.kktv*', + 'USER-AGENT,KKTV*' + ] + }; + const LINE_TV = { + name: 'Line TV', + rules: [ + 'DOMAIN,d3c7rimkq79yfu.cloudfront.net', + 'DOMAIN-SUFFIX,linetv.tw', + 'USER-AGENT,LINE TV*', + 'PROCESS-NAME,com.linecorp.linetv' + ] + }; + const LITV = { + name: 'LiTV', + rules: [ + 'DOMAIN,litvfreemobile-hichannel.cdn.hinet.net', + 'DOMAIN-SUFFIX,litv.tv' + ] + }; + const MY5 = { + name: 'My5', + rules: [ + 'DOMAIN,d349g9zuie06uo.cloudfront.net', + 'DOMAIN-SUFFIX,channel5.com', + 'DOMAIN-SUFFIX,my5.tv', + 'USER-AGENT,My5*' + ] + }; + const MYTV_SUPER = { + name: 'myTV Super', + rules: [ + 'DOMAIN-SUFFIX,mytvsuper.com', + 'DOMAIN-SUFFIX,tvb.com', + 'DOMAIN-SUFFIX,psg.cdn.hgc.com.hk', + 'USER-AGENT,mytv*', + 'DOMAIN-KEYWORD,nowtv100', + 'DOMAIN-KEYWORD,rthklive' + ] + }; + const NAVER_TV = { + name: 'Naver TV', + rules: [ + 'USER-AGENT,Naver TV*', + 'DOMAIN-SUFFIX,tv.naver.com', + 'DOMAIN-SUFFIX,smartmediarep.com' + ] + }; + const NICONICO = { + name: 'niconico', + rules: [ + 'DOMAIN-SUFFIX,dmc.nico', + 'DOMAIN-SUFFIX,nicovideo.jp', + 'DOMAIN-SUFFIX,asset.domand.nicovideo.jp', + // 'DOMAIN-SUFFIX,nimg.jp', + 'DOMAIN-SUFFIX,socdm.com', + 'USER-AGENT,Niconico*' + ] + }; + const NETFLIX = { + name: 'Netflix', + ip: { + v4: [ + '23.246.18.0/23', + '37.77.184.0/21', + '45.57.0.0/17', + '64.120.128.0/17', + '66.197.128.0/17', + '69.53.224.0/19', + '108.175.32.0/20', + '185.2.220.0/22', + '185.9.188.0/22', + '192.173.64.0/18', + '198.38.96.0/19', + '198.45.48.0/20', + '208.75.76.0/22' + ], + v6: [ + '2607:fb10::/32', + '2620:10c:7000::/44', + '2a00:86c0::/32', + '2a03:5640::/32' + ] + }, + rules: [ + 'DOMAIN-SUFFIX,netflix.ca', + 'DOMAIN-SUFFIX,netflix.com', + 'DOMAIN-SUFFIX,netflix.net', + 'DOMAIN-SUFFIX,nflxext.com', + 'DOMAIN-SUFFIX,nflximg.com', + 'DOMAIN-SUFFIX,nflximg.net', + 'DOMAIN-SUFFIX,nflxso.net', + 'DOMAIN-SUFFIX,nflxvideo.net', + 'DOMAIN-SUFFIX,nflxsearch.net', + 'DOMAIN-SUFFIX,netflix.com.edgesuite.net', + 'DOMAIN-KEYWORD,netflixdnstest', + 'DOMAIN-KEYWORD,dualstack.apiproxy-', + 'DOMAIN-KEYWORD,dualstack.ichnaea-web-', + 'DOMAIN-KEYWORD,apiproxy-device-prod-nlb-', + 'USER-AGENT,Argo*', + 'PROCESS-NAME,com.netflix.mediaclient' + ] + }; + const NHK_PLUS = { + name: 'NHK Plus', + rules: [ + // Pure Front-End detection just like AbemaTV: https://location-plus.nhk.jp/geoip/area.json + 'DOMAIN-SUFFIX,location-plus.nhk.jp' + ] + }; + const NOW_E = { + name: 'Now E', + rules: [ + 'DOMAIN-SUFFIX,nowe.com' + ] + }; + const OVERCAST_FM = { + name: 'Overcast FM', + rules: [ + 'USER-AGENT,Overcast*', + 'DOMAIN-SUFFIX,overcast.fm' + ] + }; + const PARAMOUNT = { + name: 'Paramount+', + rules: [ + 'USER-AGENT,PPlus*', + 'DOMAIN-SUFFIX,pluto.tv', + 'DOMAIN-SUFFIX,cbsi.com', + 'DOMAIN-SUFFIX,cbsaavideo.com', + 'DOMAIN-SUFFIX,cbsivideo.com', + 'DOMAIN-SUFFIX,paramountplus.com', + 'DOMAIN,cbsi.live.ott.irdeto.com', + 'DOMAIN,cbsplaylistserver.aws.syncbak.com', + 'DOMAIN,cbsservice.aws.syncbak.com', + 'DOMAIN,link.theplatform.com' + ] + }; + const PBS = { + name: 'PBS', + rules: [ + 'USER-AGENT,PBS*', + 'DOMAIN-SUFFIX,pbs.org' + ] + }; + const PEACOCK = { + name: 'Peacock', + rules: [ + 'USER-AGENT,PeacockMobile*', + 'DOMAIN-SUFFIX,peacocktv.com' + ] + }; + const PANDORA = { + name: 'Pandora', + rules: [ + 'DOMAIN-SUFFIX,pandora.com', + 'USER-AGENT,Pandora*' + ] + }; + const PORNHUB = { + name: 'Pornhub', + rules: [ + 'DOMAIN-SUFFIX,phprcdn.com', + 'DOMAIN-SUFFIX,pornhub.com', + 'DOMAIN-SUFFIX,pornhubpremium.com' + ] + }; + const SOUNDCLOUD = { + name: 'SoundCloud', + rules: [ + // 'DOMAIN-SUFFIX,sndcdn.com', + 'DOMAIN-SUFFIX,soundcloud.com', + 'USER-AGENT,SoundCloud*' + ] + }; + const SPOTIFY = { + name: 'Spotify', + ip: { + v4: [ + '35.186.224.47/32' + ], + v6: [] + }, + rules: [ + 'DOMAIN-KEYWORD,-spotify-com', + 'DOMAIN-SUFFIX,pscdn.co', + 'DOMAIN-SUFFIX,scdn.co', + 'DOMAIN-SUFFIX,spoti.fi', + 'DOMAIN-SUFFIX,spotify.com', + 'DOMAIN-SUFFIX,byspotify.com', + 'DOMAIN-SUFFIX,spotify-everywhere.com', + 'DOMAIN-SUFFIX,spotify.design', + 'DOMAIN-SUFFIX,spotifycdn.com', + 'DOMAIN-SUFFIX,spotifycdn.net', + 'DOMAIN-SUFFIX,spotifycharts.com', + 'DOMAIN-SUFFIX,spotifycodes.com', + 'DOMAIN-SUFFIX,spotifyforbrands.com', + 'DOMAIN-SUFFIX,spotifyjobs.com', + 'DOMAIN-SUFFIX,spotify-com.akamaized.net', + 'DOMAIN-SUFFIX,spotifynewsroom.jp', + 'DOMAIN-SUFFIX,spotilocal.com', + 'DOMAIN-SUFFIX,tospotify.com', + 'USER-AGENT,*Spotify*' + ] + }; + const TVB_ANYWHERE = { + name: 'TVB Anywhere', + rules: [ + 'DOMAIN-KEYWORD,tvbanywhere' + ] + }; + const TAIWAN_GOOD = { + name: 'TaiwanGood', + rules: [ + 'DOMAIN,hamifans.emome.net', + 'DOMAIN-SUFFIX,skyking.com.tw', + 'USER-AGENT,TaiwanGood*', + 'PROCESS-NAME,com.twgood.android' + ] + }; + const TIDAL = { + name: 'TIDAL', + rules: [ + 'USER-AGENT,TIDAL*', + 'DOMAIN-SUFFIX,tidal.com', + 'DOMAIN-SUFFIX,tidalhifi.com' + ] + }; + const TIKTOK = { + name: 'TikTok', + rules: [ + 'DOMAIN-SUFFIX,byteoversea.com', + 'DOMAIN-SUFFIX,ibytedtos.com', + // 'DOMAIN-SUFFIX,ibyteimg.com', // We confirm that tiktokcdn DOES NOT have ANY geoblock + 'DOMAIN-SUFFIX,ipstatp.com', + 'DOMAIN-SUFFIX,isnssdk.com', + 'DOMAIN-SUFFIX,muscdn.com', + 'DOMAIN-SUFFIX,musical.ly', + 'DOMAIN-SUFFIX,tiktok.com', + 'DOMAIN-SUFFIX,tiktok.us', + 'DOMAIN-SUFFIX,tiktokv.us', + 'DOMAIN-SUFFIX,tik-tokapi.com', + // 'DOMAIN-SUFFIX,tiktokcdn.com', // We confirm that tiktokcdn DOES NOT have ANY geoblock + 'DOMAIN-SUFFIX,tiktokv.com', + 'DOMAIN-SUFFIX,tiktokw.com', + 'DOMAIN-KEYWORD,-tiktokcdn-com', + 'USER-AGENT,TikTok*' + ] + }; + const TWITCH = { + name: 'Twitch', + rules: [ + 'DOMAIN-SUFFIX,jtvnw.net', + 'DOMAIN-SUFFIX,ttvnw.net', + 'DOMAIN-SUFFIX,twitch.tv', + 'DOMAIN-SUFFIX,twitchcdn.net', + 'DOMAIN-SUFFIX,twitchsvc.net', + 'DOMAIN-SUFFIX,ext-twitch.tv', + 'PROCESS-NAME,tv.twitch.android.app' + ] + }; + const VIUTV = { + name: 'ViuTV', + rules: [ + 'DOMAIN,api.viu.now.com', + 'DOMAIN,d1k2us671qcoau.cloudfront.net', + 'DOMAIN,d2anahhhmp1ffz.cloudfront.net', + 'DOMAIN,dfp6rglgjqszk.cloudfront.net', + 'DOMAIN-SUFFIX,viu.com', + 'DOMAIN-SUFFIX,viu.now.com', + 'DOMAIN-SUFFIX,viu.tv', + 'PROCESS-NAME,com.viu.pad', + 'PROCESS-NAME,com.viu.phone', + 'PROCESS-NAME,com.vuclip.viu', + 'PROCESS-NAME,com.hktve.viutv', + 'USER-AGENT,Viu*' + ] + }; + const YOUTUBE = { + name: 'YouTube', + rules: [ + 'DOMAIN,youtubei.googleapis.com', + 'DOMAIN,youtube.googleapis.com', + 'DOMAIN-SUFFIX,googlevideo.com', + 'DOMAIN-SUFFIX,youtube.com', + 'DOMAIN-SUFFIX,withyoutube.com', + 'DOMAIN-SUFFIX,youtubeeducation.com', + 'DOMAIN-SUFFIX,youtubegaming.com', + 'DOMAIN-SUFFIX,youtubekids.com', + 'DOMAIN-SUFFIX,youtube-nocookie.com', + 'USER-AGENT,com.google.ios.youtube*', + 'USER-AGENT,YouTube*' + ] + }; + const YOUTUBE_MUSIC = { + name: 'YouTube Music', + rules: [ + 'USER-AGENT,com.google.ios.youtubemusic*', + 'USER-AGENT,YouTubeMusic*' + ] + }; + const SHOWTIME = { + name: 'SHOWTIME', + rules: [ + 'DOMAIN-SUFFIX,sho.com', + 'DOMAIN-SUFFIX,showtime.com' + ] + }; + const WETV = { + name: 'WeTV', + ip: { + v4: [ + '150.109.28.51/32' + ], + v6: [] + }, + rules: [ + 'USER-AGENT,WeTV*', + 'DOMAIN-SUFFIX,wetv.vip', + 'DOMAIN-SUFFIX,wetvinfo.com' + ] + }; + const VUDU = { + name: 'Vudu', + rules: [ + 'DOMAIN-SUFFIX,vudu.com' + ] + }; + const ALL = [ + $4GTV, + ABEMA_TV, + AMAZON_PRIME_VIDEO, + ALL4, + APPLE_TV, + APPLE_MUSIC_TV, + BAHAMUT, + BBC, + BILIBILI_INTL, + DAZN, + DEEZER, + DISNEY_PLUS, + DISCOVERY_PLUS, + DMM, + ENCORE_TVB, + ENCORE_TVB_JP_TVER, + FOX_NOW, + FOX_PLUS, + HBO, + HBO_ASIA, + HIMALAYA_FM, + HULU, + HWTV, + IQIYI_GLOBAL, + ITV, + JOOX, + KKBOX, + KKTV, + LINE_TV, + LITV, + MY5, + MYTV_SUPER, + NETFLIX, + NAVER_TV, + NICONICO, + NHK_PLUS, + NOW_E, + OVERCAST_FM, + PARAMOUNT, + PBS, + PEACOCK, + PANDORA, + PORNHUB, + SOUNDCLOUD, + SHOWTIME, + SPOTIFY, + TAIWAN_GOOD, + TIDAL, + TIKTOK, + TVB_ANYWHERE, + TWITCH, + VIUTV, + VUDU, + WETV, + YOUTUBE, + YOUTUBE_MUSIC + ]; + const NORTH_AMERICA = [ + FOX_NOW, + FOX_PLUS, + HULU, + HULU_JP, + VUDU, + // HBO, + // www.nfl.com + // epix.com + // starz.com + // www.philo.com + // https://www.shudder.com/ + // https://www.britbox.com + // crackle.com + // www.cwtv.com + // www.aetv.com + // https://www.nba.com/watch/ + // fubo.tv + // mola.tv + // https://setantasports.com/ + // tubitv.com + // SlingTV + // PlutoTV + // AcornTV + SHOWTIME, + ENCORE_TVB, + // Funimation + DISCOVERY_PLUS, + PARAMOUNT, + PEACOCK + ]; + const EU = [ + // RakutenTV + // Funimation + // SkyShowTime + // HBO, + // MathSpot + // SkyGo + // BritBox + ITV, + // BBC Channel 4 + // BBC Channel 5 + BBC + ]; + const HK = [ + NOW_E, + VIUTV, + MYTV_SUPER, + HBO_ASIA, + BILIBILI_INTL + ]; + const TW = [ + KKTV, + LITV, + // MyVideo + $4GTV, + LINE_TV, + // HamiVideo + // CatchPlay + HBO_ASIA, + BAHAMUT + ]; + const JP = [ + DMM, + // DMMTV + ABEMA_TV, + NICONICO, + // music.jp + // Telasa + // Paravi + // unext + HULU_JP, + ENCORE_TVB_JP_TVER, + NHK_PLUS + ]; + const AU = []; + const KR = [ + // WAVEE + // Tving + // CoupangPlay + NAVER_TV + ]; + const SOUTH_EAST_ASIA = []; + } (stream)); + return stream; +}exports.r=requireStream; \ No newline at end of file diff --git a/Dist/chunks/trie.Vu1FNyv-.cjs b/Dist/chunks/trie.Vu1FNyv-.cjs new file mode 100644 index 00000000..4ece6481 --- /dev/null +++ b/Dist/chunks/trie.Vu1FNyv-.cjs @@ -0,0 +1,540 @@ +'use strict';const misc=require('./misc.BpcQjda1.cjs'),require$$1=require('node:util'),require$$2=require('foxts/noop'),require$$3=require('foxts/fast-string-array-join'),require$$4=require('foxts/bitwise');var trie = {};/** + * Hostbane-Optimized Trie based on Mnemonist Trie + */ + +var hasRequiredTrie; + +function requireTrie () { + if (hasRequiredTrie) return trie; + hasRequiredTrie = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + HostnameSmolTrie: function() { + return HostnameSmolTrie; + }, + HostnameTrie: function() { + return HostnameTrie; + } + }); + const _misc = /*@__PURE__*/ misc.r(); + const _nodeutil = /*#__PURE__*/ _interop_require_default(require$$1); + const _noop = require$$2; + const _faststringarrayjoin = require$$3; + const _bitwise = require$$4; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + var _computedKey; + const START = 1 << 1; + const INCLUDE_ALL_SUBDOMAIN = 1 << 2; + function deepTrieNodeToJSON(node, unpackMeta) { + const obj = {}; + obj['[start]'] = (0, _bitwise.getBit)(node[0], START); + obj['[subdomain]'] = (0, _bitwise.getBit)(node[0], INCLUDE_ALL_SUBDOMAIN); + if (node[3] != null) { + if (unpackMeta) { + obj['[meta]'] = unpackMeta(node[3]); + } else { + obj['[meta]'] = node[3]; + } + } + node[2].forEach((value, key)=>{ + obj[key] = deepTrieNodeToJSON(value, unpackMeta); + }); + return obj; + } + const createNode = (parent = null)=>[ + 1, + parent, + new Map(), + null + ]; + function hostnameToTokens(hostname, hostnameFromIndex) { + const tokens = hostname.split('.'); + const results = []; + let token = ''; + for(let i = hostnameFromIndex, l = tokens.length; i < l; i++){ + token = tokens[i]; + if (token.length > 0) { + results.push(token); + } else { + throw new TypeError(JSON.stringify({ + hostname, + hostnameFromIndex + }, null, 2)); + } + } + return results; + } + function walkHostnameTokens(hostname, onToken, hostnameFromIndex) { + const tokens = hostname.split('.'); + const l = tokens.length - 1; + // we are at the first of hostname, no splitor there + let token = ''; + for(let i = l; i >= hostnameFromIndex; i--){ + token = tokens[i]; + if (token.length > 0) { + const t = onToken(token); + if (t === null) { + return null; + } + // if the callback returns true, we should skip the rest + if (t) { + return true; + } + } + } + return false; + } + _computedKey = _nodeutil.default.inspect.custom; + class Triebase { + $root = createNode(); + $size = 0; + get root() { + return this.$root; + } + constructor(from){ + // Actually build trie + if (Array.isArray(from)) { + for(let i = 0, l = from.length; i < l; i++){ + this.add(from[i]); + } + } else if (from) { + from.forEach((value)=>this.add(value)); + } + } + walkIntoLeafWithTokens(tokens, onLoop = _noop.noop) { + let node = this.$root; + let parent = node; + let token; + let child = node[2]; + // reverse lookup from end to start + for(let i = tokens.length - 1; i >= 0; i--){ + token = tokens[i]; + // if (token === '') { + // break; + // } + parent = node; + child = node[2]; + // cache node index access is 20% faster than direct access when doing twice + if (child.has(token)) { + node = child.get(token); + } else { + return null; + } + onLoop(node, parent, token); + } + return { + node, + parent + }; + } + walkIntoLeafWithSuffix(suffix, hostnameFromIndex, onLoop = _noop.noop) { + let node = this.$root; + let parent = node; + let child = node[2]; + const onToken = (token)=>{ + // if (token === '') { + // return true; + // } + parent = node; + child = node[2]; + if (child.has(token)) { + node = child.get(token); + } else { + return null; + } + onLoop(node, parent, token); + return false; + }; + if (walkHostnameTokens(suffix, onToken, hostnameFromIndex) === null) { + return null; + } + return { + node, + parent + }; + } + contains(suffix, includeAllSubdomain = suffix[0] === '.') { + const hostnameFromIndex = suffix[0] === '.' ? 1 : 0; + const res = this.walkIntoLeafWithSuffix(suffix, hostnameFromIndex); + if (!res) return false; + if (includeAllSubdomain) return (0, _bitwise.getBit)(res.node[0], INCLUDE_ALL_SUBDOMAIN); + return true; + } + static bfsResults = [ + null, + [] + ]; + static dfs(nodeStack, suffixStack) { + const node = nodeStack.pop(); + const suffix = suffixStack.pop(); + node[2].forEach((childNode, k)=>{ + // Pushing the child node to the stack for next iteration of DFS + nodeStack.push(childNode); + suffixStack.push([ + k, + ...suffix + ]); + }); + Triebase.bfsResults[0] = node; + Triebase.bfsResults[1] = suffix; + return Triebase.bfsResults; + } + static dfsWithSort(nodeStack, suffixStack) { + const node = nodeStack.pop(); + const suffix = suffixStack.pop(); + const child = node[2]; + if (child.size) { + const keys = Array.from(child.keys()).sort(Triebase.compare); + for(let i = 0, l = keys.length; i < l; i++){ + const key = keys[i]; + const childNode = child.get(key); + // Pushing the child node to the stack for next iteration of DFS + nodeStack.push(childNode); + suffixStack.push([ + key, + ...suffix + ]); + } + } + Triebase.bfsResults[0] = node; + Triebase.bfsResults[1] = suffix; + return Triebase.bfsResults; + } + walk(onMatches, initialNode = this.$root, initialSuffix = [], withSort = false) { + const bfsImpl = withSort ? Triebase.dfsWithSort : Triebase.dfs; + const nodeStack = []; + nodeStack.push(initialNode); + // Resolving initial string (begin the start of the stack) + const suffixStack = []; + suffixStack.push(initialSuffix); + let node = initialNode; + let r; + do { + r = bfsImpl(nodeStack, suffixStack); + node = r[0]; + const suffix = r[1]; + // If the node is a sentinel, we push the suffix to the results + if ((0, _bitwise.getBit)(node[0], START)) { + onMatches(suffix, (0, _bitwise.getBit)(node[0], INCLUDE_ALL_SUBDOMAIN), node[3]); + } + }while (nodeStack.length) + } + static compare(a, b) { + if (a === b) return 0; + return a.length - b.length || (0, _misc.fastStringCompare)(a, b); + } + walkWithSort(onMatches, initialNode = this.$root, initialSuffix = []) { + const nodeStack = []; + nodeStack.push(initialNode); + // Resolving initial string (begin the start of the stack) + const suffixStack = []; + suffixStack.push(initialSuffix); + let node = initialNode; + let child = node[2]; + do { + node = nodeStack.pop(); + const suffix = suffixStack.pop(); + child = node[2]; + if (child.size) { + const keys = Array.from(child.keys()).sort(Triebase.compare); + for(let i = 0, l = keys.length; i < l; i++){ + const key = keys[i]; + const childNode = child.get(key); + // Pushing the child node to the stack for next iteration of DFS + nodeStack.push(childNode); + suffixStack.push([ + key, + ...suffix + ]); + } + } + // If the node is a sentinel, we push the suffix to the results + if ((0, _bitwise.getBit)(node[0], START)) { + onMatches(suffix, (0, _bitwise.getBit)(node[0], INCLUDE_ALL_SUBDOMAIN), node[3]); + } + }while (nodeStack.length) + } + getSingleChildLeaf(tokens) { + let toPrune = null; + let tokenToPrune = null; + const onLoop = (node, parent, token)=>{ + // Keeping track of a potential branch to prune + const child = node[2]; + // console.log({ + // child, parent, token + // }); + // console.log(this.inspect(0)); + if (toPrune !== null) { + if (child.size > 1) { + // The branch has some children, the branch need retain. + // And we need to abort prune that parent branch, so we set it to null + toPrune = null; + tokenToPrune = null; + } + } else if (child.size < 1) { + // There is only one token child, or no child at all, we can prune it safely + // It is now the top-est branch that could potentially being pruned + toPrune = parent; + tokenToPrune = token; + } + }; + const res = this.walkIntoLeafWithTokens(tokens, onLoop); + if (res === null) return null; + return { + node: res.node, + toPrune, + tokenToPrune, + parent: res.parent + }; + } + /** + * Method used to retrieve every item in the trie with the given prefix. + */ find(inputSuffix, subdomainOnly = inputSuffix[0] === '.', hostnameFromIndex = inputSuffix[0] === '.' ? 1 : 0) { + const inputTokens = hostnameToTokens(inputSuffix, hostnameFromIndex); + const res = this.walkIntoLeafWithTokens(inputTokens); + if (res === null) return []; + const results = []; + const onMatches = subdomainOnly ? (suffix, subdomain)=>{ + const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'); + if (!subdomain && subStringEqual(inputSuffix, d, 1)) return; + results.push(subdomain ? '.' + d : d); + } : (suffix, subdomain)=>{ + const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'); + results.push(subdomain ? '.' + d : d); + }; + this.walk(onMatches, res.node, inputTokens); + return results; + } + /** + * Method used to delete a prefix from the trie. + */ remove(suffix) { + const res = this.getSingleChildLeaf(hostnameToTokens(suffix, 0)); + if (res === null) return false; + if ((0, _bitwise.missingBit)(res.node[0], START)) return false; + this.$size--; + const { node, toPrune, tokenToPrune } = res; + if (tokenToPrune && toPrune) { + toPrune[2].delete(tokenToPrune); + } else { + node[0] = (0, _bitwise.deleteBit)(node[0], START); + } + return true; + } + // eslint-disable-next-line @typescript-eslint/unbound-method -- safe + delete = this.remove; + /** + * Method used to assert whether the given prefix exists in the Trie. + */ has(suffix, includeAllSubdomain = suffix[0] === '.') { + const hostnameFromIndex = suffix[0] === '.' ? 1 : 0; + const res = this.walkIntoLeafWithSuffix(suffix, hostnameFromIndex); + if (res === null) return false; + if ((0, _bitwise.missingBit)(res.node[0], START)) return false; + if (includeAllSubdomain) return (0, _bitwise.getBit)(res.node[0], INCLUDE_ALL_SUBDOMAIN); + return true; + } + dumpWithoutDot(onSuffix, withSort = false) { + const handleSuffix = (suffix, subdomain)=>{ + onSuffix((0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'), subdomain); + }; + if (withSort) { + this.walkWithSort(handleSuffix); + } else { + this.walk(handleSuffix); + } + } + dump(onSuffix, withSort = false) { + const results = []; + const handleSuffix = onSuffix ? (suffix, subdomain)=>{ + const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'); + onSuffix(subdomain ? '.' + d : d); + } : (suffix, subdomain)=>{ + const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'); + results.push(subdomain ? '.' + d : d); + }; + if (withSort) { + this.walkWithSort(handleSuffix); + } else { + this.walk(handleSuffix); + } + return results; + } + dumpMeta(onMeta, withSort = false) { + const results = []; + const handleMeta = onMeta ? (_suffix, _subdomain, meta)=>onMeta(meta) : (_suffix, _subdomain, meta)=>results.push(meta); + if (withSort) { + this.walkWithSort(handleMeta); + } else { + this.walk(handleMeta); + } + return results; + } + dumpWithMeta(onSuffix, withSort = false) { + const results = []; + const handleSuffix = onSuffix ? (suffix, subdomain, meta)=>{ + const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'); + return onSuffix(subdomain ? '.' + d : d, meta); + } : (suffix, subdomain, meta)=>{ + const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'); + results.push([ + subdomain ? '.' + d : d, + meta + ]); + }; + if (withSort) { + this.walkWithSort(handleSuffix); + } else { + this.walk(handleSuffix); + } + return results; + } + inspect(depth, unpackMeta) { + return (0, _faststringarrayjoin.fastStringArrayJoin)(JSON.stringify(deepTrieNodeToJSON(this.$root, unpackMeta), null, 2).split('\n').map((line)=>' '.repeat(depth) + line), '\n'); + } + [_computedKey](depth) { + return this.inspect(depth); + } + merge(trie) { + const handleSuffix = (suffix, subdomain, meta)=>{ + this.add((0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'), subdomain, meta); + }; + trie.walk(handleSuffix); + return this; + } + } + class HostnameSmolTrie extends Triebase { + smolTree = true; + add(suffix, includeAllSubdomain = suffix[0] === '.', meta, hostnameFromIndex = suffix[0] === '.' ? 1 : 0) { + let node = this.$root; + let curNodeChildren = node[2]; + const onToken = (token)=>{ + curNodeChildren = node[2]; + if (curNodeChildren.has(token)) { + node = curNodeChildren.get(token); + // During the adding of `[start]blog|.skk.moe` and find out that there is a `[start].skk.moe` in the trie, skip adding the rest of the node + if ((0, _bitwise.getBit)(node[0], INCLUDE_ALL_SUBDOMAIN)) { + return true; + } + } else { + const newNode = createNode(node); + curNodeChildren.set(token, newNode); + node = newNode; + } + return false; + }; + // When walkHostnameTokens returns true, we should skip the rest + if (walkHostnameTokens(suffix, onToken, hostnameFromIndex)) { + return; + } + // If we are in smolTree mode, we need to do something at the end of the loop + if (includeAllSubdomain) { + // Trying to add `[.]sub.example.com` where there is already a `blog.sub.example.com` in the trie + // Make sure parent `[start]sub.example.com` (without dot) is removed (SETINEL to false) + // (/** parent */ node[2]!)[0] = false; + // Removing the rest of the parent's child nodes + node[2].clear(); + // The SENTINEL of this node will be set to true at the end of the function, so we don't need to set it here + // we can use else-if here, because the children is now empty, we don't need to check the leading "." + } else if ((0, _bitwise.getBit)(node[0], INCLUDE_ALL_SUBDOMAIN)) { + // Trying to add `example.com` when there is already a `.example.com` in the trie + // No need to increment size and set SENTINEL to true (skip this "new" item) + return; + } + node[0] = (0, _bitwise.setBit)(node[0], START); + if (includeAllSubdomain) { + node[0] = (0, _bitwise.setBit)(node[0], INCLUDE_ALL_SUBDOMAIN); + } else { + node[0] = (0, _bitwise.deleteBit)(node[0], INCLUDE_ALL_SUBDOMAIN); + } + node[3] = meta; + } + whitelist(suffix, includeAllSubdomain = suffix[0] === '.', hostnameFromIndex = suffix[0] === '.' ? 1 : 0) { + const tokens = hostnameToTokens(suffix, hostnameFromIndex); + const res = this.getSingleChildLeaf(tokens); + if (res === null) return; + const { node, toPrune, tokenToPrune } = res; + // Trying to whitelist `[start].sub.example.com` where there might already be a `[start]blog.sub.example.com` in the trie + if (includeAllSubdomain) { + // If there is a `[start]sub.example.com` here, remove it + node[0] = (0, _bitwise.deleteBit)(node[0], INCLUDE_ALL_SUBDOMAIN); + node[0] = (0, _bitwise.deleteBit)(node[0], START); + // Removing all the child nodes by empty the children + node[2].clear(); + } else { + // Trying to whitelist `example.com` when there is already a `.example.com` in the trie + node[0] = (0, _bitwise.deleteBit)(node[0], INCLUDE_ALL_SUBDOMAIN); + } + // return early if not found + if ((0, _bitwise.missingBit)(node[0], START)) return; + if (toPrune && tokenToPrune) { + toPrune[2].delete(tokenToPrune); + } else { + node[0] = (0, _bitwise.deleteBit)(node[0], START); + } + } + } + class HostnameTrie extends Triebase { + get size() { + return this.$size; + } + add(suffix, includeAllSubdomain = suffix[0] === '.', meta, hostnameFromIndex = suffix[0] === '.' ? 1 : 0) { + let node = this.$root; + let child = node[2]; + const onToken = (token)=>{ + child = node[2]; + if (child.has(token)) { + node = child.get(token); + } else { + const newNode = createNode(node); + child.set(token, newNode); + node = newNode; + } + return false; + }; + // When walkHostnameTokens returns true, we should skip the rest + if (walkHostnameTokens(suffix, onToken, hostnameFromIndex)) { + return; + } + // if same entry has been added before, skip + if ((0, _bitwise.getBit)(node[0], START)) { + return; + } + this.$size++; + node[0] = (0, _bitwise.setBit)(node[0], START); + if (includeAllSubdomain) { + node[0] = (0, _bitwise.setBit)(node[0], INCLUDE_ALL_SUBDOMAIN); + } else { + node[0] = (0, _bitwise.deleteBit)(node[0], INCLUDE_ALL_SUBDOMAIN); + } + node[3] = meta; + } + } + // function deepEqualArray(a: string[], b: string[]) { + // let len = a.length; + // if (len !== b.length) return false; + // while (len--) { + // if (a[len] !== b[len]) return false; + // } + // return true; + // }; + function subStringEqual(needle, haystack, needleIndex = 0) { + for(let i = 0, l = haystack.length; i < l; i++){ + if (needle[i + needleIndex] !== haystack[i]) return false; + } + return true; + } + } (trie)); + return trie; +}exports.r=requireTrie; \ No newline at end of file diff --git a/Dist/download-mock-assets.cjs b/Dist/download-mock-assets.cjs new file mode 100644 index 00000000..9b780705 --- /dev/null +++ b/Dist/download-mock-assets.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),downloadMockAssets$1=require('./chunks/download-mock-assets.Dk5F6scb.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('node:stream/promises'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises');var downloadMockAssetsExports = downloadMockAssets$1.r(); +const downloadMockAssets = /*@__PURE__*/fetchRetry.g(downloadMockAssetsExports);module.exports=downloadMockAssets; \ No newline at end of file diff --git a/Dist/download-previous-build.cjs b/Dist/download-previous-build.cjs new file mode 100644 index 00000000..81dd4d0d --- /dev/null +++ b/Dist/download-previous-build.cjs @@ -0,0 +1,2 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),downloadPreviousBuild$1=require('./chunks/download-previous-build.-XKJmEYz.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:path'),require('node:fs'),require('node:process'),require('node:stream/promises'),require('./chunks/index.B8Uk9n3v.cjs'),require('foxts/noop'),require('tar-fs'),require('node:zlib'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('ci-info');var downloadPreviousBuildExports = downloadPreviousBuild$1.r(); +const downloadPreviousBuild = /*@__PURE__*/fetchRetry.g(downloadPreviousBuildExports);module.exports=downloadPreviousBuild; \ No newline at end of file diff --git a/Dist/index.cjs b/Dist/index.cjs new file mode 100644 index 00000000..339d53b1 --- /dev/null +++ b/Dist/index.cjs @@ -0,0 +1,108 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),require$$1$2=require('node:process'),require$$1=require('node:os'),require$$1$1=require('node:fs'),downloadPreviousBuild=require('./chunks/download-previous-build.-XKJmEYz.cjs'),buildCommon=require('./chunks/build-common.DBhs-fKR.cjs'),buildRejectIpList=require('./chunks/build-reject-ip-list.D6Cjv0d8.cjs'),buildAppleCdn=require('./chunks/build-apple-cdn.CNsnkTO_.cjs'),buildCdnDownloadConf=require('./chunks/build-cdn-download-conf.Dj0KZ2lm.cjs'),buildRejectDomainset=require('./chunks/build-reject-domainset.BCoJGSBE.cjs'),buildTelegramCidr=require('./chunks/build-telegram-cidr.05NmRbUx.cjs'),buildChnCidr=require('./chunks/build-chn-cidr.BjyqKcvm.cjs'),buildSpeedtestDomainset=require('./chunks/build-speedtest-domainset.D2jYMvWN.cjs'),buildInternalReverseChnCidr=require('./chunks/build-internal-reverse-chn-cidr.C6CBihfs.cjs'),buildDomesticDirectLanRulesetDnsMappingModule=require('./chunks/build-domestic-direct-lan-ruleset-dns-mapping-module.T1tgVza_.cjs'),buildStreamService=require('./chunks/build-stream-service.BKBKJK6i.cjs'),buildSgmoduleRedirect=require('./chunks/build-sgmodule-redirect.iquVSpqW.cjs'),buildSgmoduleAlwaysRealip=require('./chunks/build-sgmodule-always-realip.CuBgClIT.cjs'),buildMicrosoftCdn=require('./chunks/build-microsoft-cdn.CCw86frc.cjs'),buildSspanelAppprofile=require('./chunks/build-sspanel-appprofile.DbsFXAyN.cjs'),buildPublic=require('./chunks/build-public.8-AWnl05.cjs'),downloadMockAssets=require('./chunks/download-mock-assets.Dk5F6scb.cjs'),buildCloudmounterRules=require('./chunks/build-cloudmounter-rules.RMp-w3JV.cjs'),index$1=require('./chunks/index.B8Uk9n3v.cjs'),buildDeprecateFiles=require('./chunks/build-deprecate-files.BeL0QUfk.cjs'),require$$0=require('node:path');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:stream/promises'),require('tar-fs'),require('node:zlib'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('ci-info'),require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('./chunks/base.C13YY5P3.cjs'),require('foxts/append-set-elements-to-array'),require('foxts/noop'),require('json-stringify-pretty-compact'),require('./chunks/trie.Vu1FNyv-.cjs'),require('foxts/fast-string-array-join'),require('foxts/bitwise'),require('fast-cidr-tools'),require('foxts/retrie'),require('./chunks/create-file.loOMbJEN.cjs'),require('foxts/async-write-to-stream'),require('foxts/is-probably-ip'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('fdir'),require('./chunks/domainset.CSQfKAtf.cjs'),require('foxts/escape-string-regexp'),require('./chunks/ruleset.iYH0XOC1.cjs'),require('./chunks/fetch-assets.aqw2YOi8.cjs'),require('foxts/wait'),require('./chunks/parse-dnsmasq.CiH7YJVY.cjs'),require('./chunks/memo-promise.BbOsVeGo.cjs'),require('./chunks/reject-data-source.DaKwvNlG.cjs'),require('tldts-experimental'),require('@ghostery/adblocker'),require('./chunks/fs-memo.Dw823m02.cjs'),require('better-sqlite3'),require('node:perf_hooks'),require('foxts/serialized-memo'),require('foxts/add-array-elements-to-set'),require('@henrygd/queue'),require('worktank'),require('url'),require('yaml'),require('./chunks/stream.C9eZuk9f.cjs'),require('foxts/tagged');var Build = {};var hasRequiredBuild; + +function requireBuild () { + if (hasRequiredBuild) return Build; + hasRequiredBuild = 1; + Object.defineProperty(Build, "__esModule", { + value: true + }); + const _nodeprocess = /*#__PURE__*/ _interop_require_default(require$$1$2); + const _nodeos = /*#__PURE__*/ _interop_require_default(require$$1); + const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1$1); + const _downloadpreviousbuild = downloadPreviousBuild.r(); + const _buildcommon = buildCommon.r(); + const _buildrejectiplist = buildRejectIpList.r(); + const _buildapplecdn = buildAppleCdn.r(); + const _buildcdndownloadconf = buildCdnDownloadConf.r(); + const _buildrejectdomainset = buildRejectDomainset.r(); + const _buildtelegramcidr = buildTelegramCidr.r(); + const _buildchncidr = buildChnCidr.r(); + const _buildspeedtestdomainset = buildSpeedtestDomainset.r(); + const _buildinternalreversechncidr = buildInternalReverseChnCidr.r(); + const _builddomesticdirectlanrulesetdnsmappingmodule = buildDomesticDirectLanRulesetDnsMappingModule.r(); + const _buildstreamservice = buildStreamService.r(); + const _buildsgmoduleredirect = buildSgmoduleRedirect.r(); + const _buildsgmodulealwaysrealip = buildSgmoduleAlwaysRealip.r(); + const _buildmicrosoftcdn = buildMicrosoftCdn.r(); + const _buildsspanelappprofile = buildSspanelAppprofile.r(); + const _buildpublic = buildPublic.r(); + const _downloadmockassets = downloadMockAssets.r(); + const _buildcloudmounterrules = buildCloudmounterRules.r(); + const _trace = /*@__PURE__*/ index$1.r(); + const _builddeprecatefiles = buildDeprecateFiles.r(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _dir = /*@__PURE__*/ fetchRetry.a(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + _nodeprocess.default.on('uncaughtException', (error)=>{ + console.error('Uncaught exception:', error); + _nodeprocess.default.exit(1); + }); + _nodeprocess.default.on('unhandledRejection', (reason)=>{ + console.error('Unhandled rejection:', reason); + _nodeprocess.default.exit(1); + }); + const buildFinishedLock = _nodepath.default.join(_dir.ROOT_DIR, '.BUILD_FINISHED'); + (async ()=>{ + console.log('Version:', _nodeprocess.default.version); + console.log(`OS: ${_nodeos.default.type()} ${_nodeos.default.release()} ${_nodeos.default.arch()}`); + console.log(`Node.js: ${_nodeprocess.default.versions.node}`); + console.log(`V8: ${_nodeprocess.default.versions.v8}`); + const cpus = _nodeos.default.cpus().reduce((o, cpu)=>{ + o[cpu.model] = (o[cpu.model] || 0) + 1; + return o; + }, {}); + console.log(`CPU: ${Object.keys(cpus).map((key)=>`${key} x ${cpus[key]}`).join('\n')}`); + console.log(`Memory: ${_nodeos.default.totalmem() / (1024 * 1024)} MiB`); + const rootSpan = (0, _trace.createSpan)('root'); + if (_nodefs.default.existsSync(buildFinishedLock)) { + _nodefs.default.unlinkSync(buildFinishedLock); + } + try { + await import('why-is-node-running'); + const downloadPreviousBuildPromise = (0, _downloadpreviousbuild.downloadPreviousBuild)(rootSpan); + const buildCommonPromise = downloadPreviousBuildPromise.then(()=>(0, _buildcommon.buildCommon)(rootSpan)); + await Promise.all([ + downloadPreviousBuildPromise, + buildCommonPromise, + downloadPreviousBuildPromise.then(()=>(0, _buildrejectiplist.buildRejectIPList)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildapplecdn.buildAppleCdn)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildcdndownloadconf.buildCdnDownloadConf)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildrejectdomainset.buildRejectDomainSet)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildtelegramcidr.buildTelegramCIDR)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildchncidr.buildChnCidr)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildspeedtestdomainset.buildSpeedtestDomainSet)(rootSpan)), + (0, _buildinternalreversechncidr.buildInternalReverseChnCIDR)(rootSpan), + downloadPreviousBuildPromise.then(()=>(0, _builddomesticdirectlanrulesetdnsmappingmodule.buildDomesticRuleset)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildsgmoduleredirect.buildRedirectModule)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildsgmodulealwaysrealip.buildAlwaysRealIPModule)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildstreamservice.buildStreamService)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildmicrosoftcdn.buildMicrosoftCdn)(rootSpan)), + Promise.all([ + downloadPreviousBuildPromise, + buildCommonPromise + ]).then(()=>(0, _buildsspanelappprofile.buildSSPanelUIMAppProfile)(rootSpan)), + downloadPreviousBuildPromise.then(()=>(0, _buildcloudmounterrules.buildCloudMounterRules)(rootSpan)), + (0, _downloadmockassets.downloadMockAssets)(rootSpan) + ]); + await (0, _builddeprecatefiles.buildDeprecateFiles)(rootSpan); + await (0, _buildpublic.buildPublic)(rootSpan); + rootSpan.stop(); + (0, _trace.printTraceResult)(rootSpan.traceResult); + // write a file to demonstrate that the build is finished + _nodefs.default.writeFileSync(buildFinishedLock, 'BUILD_FINISHED\n'); + // Finish the build to avoid leaking timer/fetch ref + await (0, _trace.whyIsNodeRunning)(); + _nodeprocess.default.exit(0); + } catch (e) { + console.error('Something went wrong!'); + console.trace(e); + _nodeprocess.default.exit(1); + } + })(); + return Build; +}var BuildExports = requireBuild(); +const index = /*@__PURE__*/fetchRetry.g(BuildExports);module.exports=index; \ No newline at end of file diff --git a/Dist/trim-source.cjs b/Dist/trim-source.cjs new file mode 100644 index 00000000..ac029bdc --- /dev/null +++ b/Dist/trim-source.cjs @@ -0,0 +1,48 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),require$$0=require('node:path'),require$$2=require('node:fs/promises'),require$$5=require('fdir'),fetchTextByLine=require('./chunks/fetch-text-by-line.YY5b5610.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:fs'),require('node:process'),require('node:readline'),require('node:stream/web'),require('foxts/guard');var trimSource$1 = {};var hasRequiredTrimSource; + +function requireTrimSource () { + if (hasRequiredTrimSource) return trimSource$1; + hasRequiredTrimSource = 1; + Object.defineProperty(trimSource$1, "__esModule", { + value: true + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _promises = /*#__PURE__*/ _interop_require_default(require$$2); + const _fdir = require$$5; + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _dir = /*@__PURE__*/ fetchRetry.a(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + (async ()=>{ + const promises = []; + const paths = await new _fdir.fdir().withFullPaths()// .exclude((dirName, dirPath) => { + // if (dirName === 'domainset' || dirName === 'ip' || dirName === 'non_ip') { + // return false; + // } + // console.error(picocolors.red(`[build-comman] Unknown dir: ${dirPath}`)); + // return true; + // }) + .filter((filepath, isDirectory)=>{ + if (isDirectory) return true; + const extname = _nodepath.default.extname(filepath); + return !(extname === '.js' || extname === '.ts'); + }).crawl(_dir.SOURCE_DIR).withPromise(); + for(let i = 0, len = paths.length; i < len; i++){ + const fullPath = paths[i]; + promises.push(trimFileLines(fullPath)); + } + return Promise.all(promises); + })(); + async function trimFileLines(file) { + let result = ''; + for await (const line of (0, _fetchtextbyline.readFileByLine)(file)){ + result += line.trim() + '\n'; + } + return _promises.default.writeFile(file, result); + } + return trimSource$1; +}var trimSourceExports = requireTrimSource(); +const trimSource = /*@__PURE__*/fetchRetry.g(trimSourceExports);module.exports=trimSource; \ No newline at end of file diff --git a/Dist/validate-domain-alive.cjs b/Dist/validate-domain-alive.cjs new file mode 100644 index 00000000..53a56ed2 --- /dev/null +++ b/Dist/validate-domain-alive.cjs @@ -0,0 +1,490 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),fetchTextByLine=require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require$$0$1=require('node:path'),require$$7=require('@henrygd/queue'),require$$5=require('tldts-experimental'),looseTldtsOpt=require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require$$0=require('picocolors'),require$$3$1=require('dns2'),require$$4=require('async-retry'),require$$5$1=require('whoiser'),require$$3=require('foxts/retrie'),require$$1=require('node:process'),require$$5$2=require('fdir');require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:fs'),require('node:readline'),require('node:stream/web'),require('foxts/guard');var validateDomainAlive$1 = {};var isDomainAlive = {};var hasRequiredIsDomainAlive; + +function requireIsDomainAlive () { + if (hasRequiredIsDomainAlive) return isDomainAlive; + hasRequiredIsDomainAlive = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + isDomainAlive: function() { + return isDomainAlive; + }, + keyedAsyncMutexWithQueue: function() { + return keyedAsyncMutexWithQueue; + }, + noWhois: function() { + return noWhois; + } + }); + const _tldtsexperimental = /*#__PURE__*/ _interop_require_default(require$$5); + const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.r(); + const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0); + const _dns2 = /*#__PURE__*/ _interop_require_default(require$$3$1); + const _asyncretry = /*#__PURE__*/ _interop_require_default(require$$4); + const _whoiser = /*#__PURE__*/ _interop_require_wildcard(require$$5$1); + const _retrie = require$$3; + const _nodeprocess = /*#__PURE__*/ _interop_require_default(require$$1); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); + } + function _interop_require_wildcard(obj, nodeInterop) { + if (obj && obj.__esModule) { + return obj; + } + if (obj === null || typeof obj !== "object" && typeof obj !== "function") { + return { + default: obj + }; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = { + __proto__: null + }; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; + } + const mutex = new Map(); + function keyedAsyncMutexWithQueue(key, fn) { + if (mutex.has(key)) { + return mutex.get(key); + } + const promise = fn(); + mutex.set(key, promise); + return promise; + } + class DnsError extends Error { + message; + server; + name; + constructor(message, server){ + super(message), this.message = message, this.server = server, this.name = 'DnsError'; + } + } + const dohServers = [ + '8.8.8.8', + '8.8.4.4', + '1.0.0.1', + '1.1.1.1', + '162.159.36.1', + '162.159.46.1', + '101.101.101.101', + '185.222.222.222', + '45.11.45.11', + 'dns10.quad9.net', + 'doh.sandbox.opendns.com', + 'unfiltered.adguard-dns.com', + // '0ms.dev', // Proxy Cloudflare + // '76.76.2.0', // ControlD unfiltered, path not /dns-query + // '76.76.10.0', // ControlD unfiltered, path not /dns-query + // 'dns.bebasid.com', // BebasID, path not /dns-query but /unfiltered + // '193.110.81.0', // dns0.eu + // '185.253.5.0', // dns0.eu + // 'zero.dns0.eu', + 'dns.nextdns.io', + 'anycast.dns.nextdns.io', + 'wikimedia-dns.org', + // 'ordns.he.net', + // 'dns.mullvad.net', + 'basic.rethinkdns.com', + '198.54.117.10' // NameCheap DNS, supports DoT, DoH, UDP53 + ].map((dns)=>[ + dns, + _dns2.default.DOHClient({ + dns, + http: false + }) + ]); + const domesticDohServers = [ + '223.5.5.5', + '223.6.6.6', + '120.53.53.53', + '1.12.12.12' + ].map((dns)=>[ + dns, + _dns2.default.DOHClient({ + dns, + http: false + }) + ]); + function createResolve(server) { + return async (...args)=>{ + try { + return await (0, _asyncretry.default)(async ()=>{ + const [dohServer, dohClient] = server[Math.floor(Math.random() * server.length)]; + try { + return { + ...await dohClient(...args), + dns: dohServer + }; + } catch (e) { + // console.error(e); + throw new DnsError(e.message, dohServer); + } + }, { + retries: 5 + }); + } catch (e) { + console.log('[doh error]', ...args, e); + throw e; + } + }; + } + const resolve = createResolve(dohServers); + const domesticResolve = createResolve(domesticDohServers); + async function getWhois(domain) { + return (0, _asyncretry.default)(()=>_whoiser.domain(domain, { + raw: true + }), { + retries: 5 + }); + } + const domainAliveMap = new Map(); + function onDomainAlive(domain) { + domainAliveMap.set(domain, true); + return [ + domain, + true + ]; + } + function onDomainDead(domain) { + domainAliveMap.set(domain, false); + return [ + domain, + false + ]; + } + async function isDomainAlive(domain, isSuffix) { + if (domainAliveMap.has(domain)) { + return [ + domain, + domainAliveMap.get(domain) + ]; + } + const apexDomain = _tldtsexperimental.default.getDomain(domain, _loosetldtsopt.looseTldtsOpt); + if (!apexDomain) { + console.log(_picocolors.default.gray('[domain invalid]'), _picocolors.default.gray('no apex domain'), { + domain + }); + return onDomainAlive(domain); + } + const apexDomainAlive = await keyedAsyncMutexWithQueue(apexDomain, ()=>isApexDomainAlive(apexDomain)); + if (isSuffix) { + return apexDomainAlive; + } + if (!apexDomainAlive[1]) { + return apexDomainAlive; + } + const $domain = domain[0] === '.' ? domain.slice(1) : domain; + const aDns = []; + const aaaaDns = []; + // test 2 times before make sure record is empty + for(let i = 0; i < 2; i++){ + // eslint-disable-next-line no-await-in-loop -- sequential + const aRecords = await resolve($domain, 'A'); + if (aRecords.answers.length > 0) { + return onDomainAlive(domain); + } + aDns.push(aRecords.dns); + } + for(let i = 0; i < 2; i++){ + // eslint-disable-next-line no-await-in-loop -- sequential + const aaaaRecords = await resolve($domain, 'AAAA'); + if (aaaaRecords.answers.length > 0) { + return onDomainAlive(domain); + } + aaaaDns.push(aaaaRecords.dns); + } + // only then, let's test once with domesticDohServers + const aRecords = await domesticResolve($domain, 'A'); + if (aRecords.answers.length > 0) { + return onDomainAlive(domain); + } + aDns.push(aRecords.dns); + const aaaaRecords = await domesticResolve($domain, 'AAAA'); + if (aaaaRecords.answers.length > 0) { + return onDomainAlive(domain); + } + aaaaDns.push(aaaaRecords.dns); + console.log(_picocolors.default.red('[domain dead]'), 'no A/AAAA records', { + domain, + a: aDns, + aaaa: aaaaDns + }); + return onDomainDead($domain); + } + const apexDomainNsResolvePromiseMap = new Map(); + async function isApexDomainAlive(apexDomain) { + if (domainAliveMap.has(apexDomain)) { + return [ + apexDomain, + domainAliveMap.get(apexDomain) + ]; + } + let resp; + if (apexDomainNsResolvePromiseMap.has(apexDomain)) { + resp = await apexDomainNsResolvePromiseMap.get(apexDomain); + } else { + const promise = resolve(apexDomain, 'NS'); + apexDomainNsResolvePromiseMap.set(apexDomain, promise); + resp = await promise; + } + if (resp.answers.length > 0) { + return onDomainAlive(apexDomain); + } + let whois; + try { + whois = await getWhois(apexDomain); + } catch (e) { + console.log(_picocolors.default.red('[whois error]'), { + domain: apexDomain + }, e); + return onDomainAlive(apexDomain); + } + if (_nodeprocess.default.env.DEBUG) { + console.log(JSON.stringify(whois, null, 2)); + } + const whoisError = noWhois(whois); + if (!whoisError) { + console.log(_picocolors.default.gray('[domain alive]'), _picocolors.default.gray('whois found'), { + domain: apexDomain + }); + return onDomainAlive(apexDomain); + } + console.log(_picocolors.default.red('[domain dead]'), 'whois not found', { + domain: apexDomain, + err: whoisError + }); + return onDomainDead(apexDomain); + } + // TODO: this is a workaround for https://github.com/LayeredStudio/whoiser/issues/117 + const whoisNotFoundKeywordTest = (0, _retrie.createRetrieKeywordFilter)([ + 'no match for', + 'does not exist', + 'not found', + 'no found', + 'no entries', + 'no data found', + 'is available for registration', + 'currently available for application', + 'no matching record', + 'no information available about domain name', + 'not been registered', + 'no match!!', + 'status: available', + ' is free', + 'no object found', + 'nothing found', + 'status: free', + 'pendingdelete', + ' has been blocked by ' + ]); + function noWhois(whois) { + let empty = true; + for(const key in whois){ + if (Object.hasOwn(whois, key)) { + empty = false; + // if (key === 'error') { + // // if ( + // // (typeof whois.error === 'string' && whois.error) + // // || (Array.isArray(whois.error) && whois.error.length > 0) + // // ) { + // // console.error(whois); + // // return true; + // // } + // continue; + // } + // if (key === 'text') { + // if (Array.isArray(whois.text)) { + // for (const value of whois.text) { + // if (whoisNotFoundKeywordTest(value.toLowerCase())) { + // return value; + // } + // } + // } + // continue; + // } + // if (key === 'Name Server') { + // // if (Array.isArray(whois[key]) && whois[key].length === 0) { + // // return false; + // // } + // continue; + // } + // if (key === 'Domain Status') { + // if (Array.isArray(whois[key])) { + // for (const status of whois[key]) { + // if (status === 'free' || status === 'AVAILABLE') { + // return key + ': ' + status; + // } + // if (whoisNotFoundKeywordTest(status.toLowerCase())) { + // return key + ': ' + status; + // } + // } + // } + // continue; + // } + // if (typeof whois[key] === 'string' && whois[key]) { + // if (whoisNotFoundKeywordTest(whois[key].toLowerCase())) { + // return key + ': ' + whois[key]; + // } + // continue; + // } + if (key === '__raw' && typeof whois.__raw === 'string') { + const lines = whois.__raw.trim().toLowerCase().replaceAll(/[\t ]+/g, ' ').split(/\r?\n/); + if (_nodeprocess.default.env.DEBUG) { + console.log({ + lines + }); + } + for (const line of lines){ + if (whoisNotFoundKeywordTest(line)) { + return line; + } + } + continue; + } + if (typeof whois[key] === 'object' && !Array.isArray(whois[key])) { + const tmp = noWhois(whois[key]); + if (tmp) { + return tmp; + } + continue; + } + } + } + if (empty) { + return 'whois is empty'; + } + return null; + } + } (isDomainAlive)); + return isDomainAlive; +}var hasRequiredValidateDomainAlive; + +function requireValidateDomainAlive () { + if (hasRequiredValidateDomainAlive) return validateDomainAlive$1; + hasRequiredValidateDomainAlive = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + runAgainstDomainset: function() { + return runAgainstDomainset; + }, + runAgainstRuleset: function() { + return runAgainstRuleset; + } + }); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _processline = /*@__PURE__*/ fetchTextByLine.r(); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _queue = require$$7; + const _isdomainalive = /*@__PURE__*/ requireIsDomainAlive(); + const _fdir = require$$5$2; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + const queue = (0, _queue.newQueue)(24); + const deadDomains = []; + function onDomain(args) { + if (!args[1]) { + deadDomains.push(args[0]); + } + } + (async ()=>{ + const domainSets = await new _fdir.fdir().withFullPaths().crawl(_dir.SOURCE_DIR + _nodepath.default.sep + 'domainset').withPromise(); + const domainRules = await new _fdir.fdir().withFullPaths().crawl(_dir.SOURCE_DIR + _nodepath.default.sep + 'non_ip').withPromise(); + await Promise.all([ + ...domainSets.map(runAgainstDomainset), + ...domainRules.map(runAgainstRuleset) + ]); + console.log(); + console.log(); + console.log(JSON.stringify(deadDomains)); + })(); + async function runAgainstRuleset(filepath) { + const extname = _nodepath.default.extname(filepath); + if (extname !== '.conf') { + console.log('[skip]', filepath); + return; + } + const promises = []; + for await (const l of (0, _fetchtextbyline.readFileByLine)(filepath)){ + const line = (0, _processline.processLine)(l); + if (!line) continue; + const [type, domain] = line.split(','); + switch(type){ + case 'DOMAIN-SUFFIX': + case 'DOMAIN': + { + promises.push(queue.add(()=>(0, _isdomainalive.keyedAsyncMutexWithQueue)(domain, ()=>(0, _isdomainalive.isDomainAlive)(domain, type === 'DOMAIN-SUFFIX'))).then(onDomain)); + break; + } + } + } + await Promise.all(promises); + console.log('[done]', filepath); + } + async function runAgainstDomainset(filepath) { + const extname = _nodepath.default.extname(filepath); + if (extname !== '.conf') { + console.log('[skip]', filepath); + return; + } + const promises = []; + for await (const l of (0, _fetchtextbyline.readFileByLine)(filepath)){ + const line = (0, _processline.processLine)(l); + if (!line) continue; + promises.push(queue.add(()=>(0, _isdomainalive.keyedAsyncMutexWithQueue)(line, ()=>(0, _isdomainalive.isDomainAlive)(line, line[0] === '.'))).then(onDomain)); + } + await Promise.all(promises); + console.log('[done]', filepath); + } + } (validateDomainAlive$1)); + return validateDomainAlive$1; +}var validateDomainAliveExports = requireValidateDomainAlive(); +const validateDomainAlive = /*@__PURE__*/fetchRetry.g(validateDomainAliveExports);module.exports=validateDomainAlive; \ No newline at end of file diff --git a/Dist/validate-domestic.cjs b/Dist/validate-domestic.cjs new file mode 100644 index 00000000..11d1f510 --- /dev/null +++ b/Dist/validate-domestic.cjs @@ -0,0 +1,82 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),fetchTextByLine=require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require$$3=require('csv-parse/sync'),trie=require('./chunks/trie.Vu1FNyv-.cjs'),require$$0=require('node:path'),parseDnsmasq=require('./chunks/parse-dnsmasq.CiH7YJVY.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:fs'),require('node:process'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('foxts/noop'),require('foxts/fast-string-array-join'),require('foxts/bitwise'),require('./chunks/normalize-domain.Cfz4j8eP.cjs'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('foxts/is-probably-ip');var validateDomestic$1 = {};var hasRequiredValidateDomestic; + +function requireValidateDomestic () { + if (hasRequiredValidateDomestic) return validateDomestic$1; + hasRequiredValidateDomestic = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "parseDomesticList", { + enumerable: true, + get: function() { + return parseDomesticList; + } + }); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _sync = require$$3; + const _trie = /*@__PURE__*/ trie.r(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _processline = /*@__PURE__*/ fetchTextByLine.r(); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _parsednsmasq = /*@__PURE__*/ parseDnsmasq.r(); + const _fetchretry = /*@__PURE__*/ fetchRetry.r(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + async function parseDomesticList() { + const trie = new _trie.HostnameSmolTrie(await (0, _parsednsmasq.parseFelixDnsmasqFromResp)(await (0, _fetchretry.$$fetch)('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf'))); + const top5000 = new Set(); + const res = await (await (0, _fetchretry.$$fetch)('https://radar.cloudflare.com/charts/LargerTopDomainsTable/attachment?id=1077&top=10000', { + headers: { + accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', + 'accept-language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,zh-TW;q=0.6,es;q=0.5', + 'sec-ch-ua': '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"', + 'sec-ch-ua-mobile': '?0', + 'sec-ch-ua-platform': '"macOS"', + 'sec-fetch-dest': 'document', + 'sec-fetch-mode': 'navigate', + 'sec-fetch-site': 'none', + 'sec-fetch-user': '?1', + 'upgrade-insecure-requests': '1' + } + })).text(); + const stream = (0, _sync.parse)(res); + for await (const [domain] of stream){ + if (trie.has(domain)) { + top5000.add(domain); + } + console.log({ + domain + }); + } + const notIncludedDomestic = new Set(top5000); + const runAgainstRuleset = async (ruleset)=>{ + for await (const l of (0, _fetchtextbyline.readFileByLine)(ruleset)){ + const line = (0, _processline.processLine)(l); + if (!line) continue; + const [type, domain] = line.split(','); + if (type === 'DOMAIN-SUFFIX') { + if (top5000.has(domain)) { + notIncludedDomestic.delete(domain); + } + } else if (type === 'DOMAIN-KEYWORD') { + for (const d of top5000){ + if (d.includes(domain)) { + notIncludedDomestic.delete(d); + } + } + } + } + }; + // await Promise.all([ + await runAgainstRuleset(_nodepath.default.resolve(_dir.SOURCE_DIR, 'non_ip/domestic.conf')); + // ]); + console.log(notIncludedDomestic.size, notIncludedDomestic); + } + } (validateDomestic$1)); + return validateDomestic$1; +}var validateDomesticExports = requireValidateDomestic(); +const validateDomestic = /*@__PURE__*/fetchRetry.g(validateDomesticExports);module.exports=validateDomestic; \ No newline at end of file diff --git a/Dist/validate-gfwlist.cjs b/Dist/validate-gfwlist.cjs new file mode 100644 index 00000000..67c75b2f --- /dev/null +++ b/Dist/validate-gfwlist.cjs @@ -0,0 +1,154 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),fetchTextByLine=require('./chunks/fetch-text-by-line.YY5b5610.cjs'),normalizeDomain=require('./chunks/normalize-domain.Cfz4j8eP.cjs'),trie=require('./chunks/trie.Vu1FNyv-.cjs'),require$$3$1=require('csv-parse/sync'),require$$0=require('node:path'),require$$3=require('foxts/retrie');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:fs'),require('node:process'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('tldts'),require('./chunks/loose-tldts-opt.DLUpGXpj.cjs'),require('foxts/is-probably-ip'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('foxts/noop'),require('foxts/fast-string-array-join'),require('foxts/bitwise');var validateGfwlist$1 = {exports: {}};var hasRequiredValidateGfwlist; + +function requireValidateGfwlist () { + if (hasRequiredValidateGfwlist) return validateGfwlist$1.exports; + hasRequiredValidateGfwlist = 1; + (function (module, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "parseGfwList", { + enumerable: true, + get: function() { + return parseGfwList; + } + }); + const _processline = /*@__PURE__*/ fetchTextByLine.r(); + const _normalizedomain = /*@__PURE__*/ normalizeDomain.r(); + const _trie = /*@__PURE__*/ trie.r(); + const _sync = require$$3$1; + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _retrie = require$$3; + const _fetchretry = /*@__PURE__*/ fetchRetry.r(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + async function parseGfwList() { + const whiteSet = new Set(); + const trie = new _trie.HostnameSmolTrie(); + const excludeGfwList = (0, _retrie.createRetrieKeywordFilter)([ + '.*', + '*', + '=', + '[', + '/', + '?' + ]); + const text = await (await (0, _fetchretry.$$fetch)('https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt')).text(); + for (const l of atob(text).split('\n')){ + const line = (0, _processline.processLine)(l); + if (!line) continue; + if (excludeGfwList(line)) { + continue; + } + if (line.startsWith('@@||')) { + whiteSet.add('.' + line.slice(4)); + continue; + } + if (line.startsWith('@@|http://')) { + whiteSet.add(line.slice(10)); + continue; + } + if (line.startsWith('@@|https://')) { + whiteSet.add(line.slice(11)); + continue; + } + if (line.startsWith('||')) { + trie.add('.' + line.slice(2)); + continue; + } + if (line.startsWith('|')) { + trie.add(line.slice(1)); + continue; + } + if (line.startsWith('.')) { + trie.add(line); + continue; + } + const d = (0, _normalizedomain.fastNormalizeDomain)(line); + if (d) { + trie.add(d); + continue; + } + } + for (const l of (await (await (0, _fetchretry.$$fetch)('https://raw.githubusercontent.com/Loyalsoldier/cn-blocked-domain/release/domains.txt')).text()).split('\n')){ + trie.add(l); + } + const res = await (await (0, _fetchretry.$$fetch)('https://litter.catbox.moe/sqmgyn.csv', { + headers: { + accept: '*/*', + 'user-agent': 'curl/8.9.1' + } + })).text(); + const topDomains = (0, _sync.parse)(res); + const keywordSet = new Set(); + const runAgainstRuleset = async (ruleset)=>{ + for await (const l of (0, _fetchtextbyline.readFileByLine)(ruleset)){ + const line = (0, _processline.processLine)(l); + if (!line) continue; + const [type, domain] = line.split(','); + switch(type){ + case 'DOMAIN-SUFFIX': + { + trie.whitelist('.' + domain); + break; + } + case 'DOMAIN': + { + trie.whitelist(domain); + break; + } + case 'DOMAIN-KEYWORD': + { + keywordSet.add(domain); + break; + } + } + } + }; + const runAgainstDomainset = async (ruleset)=>{ + for await (const l of (0, _fetchtextbyline.readFileByLine)(ruleset)){ + const line = (0, _processline.processLine)(l); + if (!line) continue; + trie.whitelist(line); + } + }; + await Promise.all([ + runAgainstRuleset(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/global.conf')), + runAgainstRuleset(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/reject.conf')), + runAgainstRuleset(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/telegram.conf')), + runAgainstRuleset(_nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, 'non_ip/stream.conf')), + runAgainstRuleset(_nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, 'non_ip/ai.conf')), + runAgainstRuleset(_nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, 'non_ip/microsoft.conf')), + runAgainstDomainset(_nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, 'domainset/reject.conf')), + runAgainstDomainset(_nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, 'domainset/cdn.conf')) + ]); + whiteSet.forEach((domain)=>trie.whitelist(domain)); + const kwfilter = (0, _retrie.createRetrieKeywordFilter)([ + ...keywordSet + ]); + const missingTop10000Gfwed = new Set(); + console.log(trie.has('.mojim.com')); + for await (const [domain] of topDomains){ + if (trie.has(domain) && !kwfilter(domain)) { + missingTop10000Gfwed.add(domain); + } + } + console.log(JSON.stringify(Array.from(missingTop10000Gfwed), null, 2)); + return [ + whiteSet, + trie, + missingTop10000Gfwed + ]; + } + if (require.main === module) { + parseGfwList().catch(console.error); + } + } (validateGfwlist$1, validateGfwlist$1.exports)); + return validateGfwlist$1.exports; +}var validateGfwlistExports = requireValidateGfwlist(); +const validateGfwlist = /*@__PURE__*/fetchRetry.g(validateGfwlistExports);module.exports=validateGfwlist; \ No newline at end of file diff --git a/Dist/validate-global-tld.cjs b/Dist/validate-global-tld.cjs new file mode 100644 index 00000000..bd7db769 --- /dev/null +++ b/Dist/validate-global-tld.cjs @@ -0,0 +1,201 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),require$$0=require('node:path'),fetchTextByLine=require('./chunks/fetch-text-by-line.YY5b5610.cjs'),trie=require('./chunks/trie.Vu1FNyv-.cjs'),require$$5=require('tldts-experimental'),looseTldtsOpt=require('./chunks/loose-tldts-opt.DLUpGXpj.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:fs'),require('node:process'),require('node:readline'),require('node:stream/web'),require('foxts/guard'),require('./chunks/misc.BpcQjda1.cjs'),require('node:fs/promises'),require('foxts/noop'),require('foxts/fast-string-array-join'),require('foxts/bitwise');var validateGlobalTld$1 = {};var domains = {};var hasRequiredDomains; + +function requireDomains () { + if (hasRequiredDomains) return domains; + hasRequiredDomains = 1; + (function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "ICP_TLD", { + enumerable: true, + get: function() { + return ICP_TLD; + } + }); + const ICP_TLD = [ + 'ren', + 'wang', + 'citic', + 'top', + 'sohu', + 'xin', + 'com', + 'net', + 'club', + 'xyz', + 'site', + 'shop', + 'info', + 'mobi', + 'red', + 'pro', + 'kim', + 'ltd', + 'group', + 'biz', + 'link', + 'store', + 'tech', + 'fun', + 'online', + 'art', + 'design', + 'love', + 'center', + 'video', + 'social', + 'team', + 'show', + 'cool', + 'zone', + 'world', + 'today', + 'city', + 'chat', + 'company', + 'live', + 'fund', + 'gold', + 'plus', + 'guru', + 'run', + 'pub', + 'email', + 'life', + 'co', + 'baidu', + 'cloud', + 'host', + 'space', + 'press', + 'website', + 'archi', + 'asia', + 'bio', + 'black', + 'blue', + 'green', + 'lotto', + 'organic', + 'pet', + 'pink', + 'poker', + 'promo', + 'ski', + 'vote', + 'voto', + 'icu', + 'fans', + 'unicom', + 'jpmorgan', + 'chase', + 'cc', + 'band', + 'cab', + 'cafe', + 'cash', + 'fan', + 'fyi', + 'games', + 'market', + 'mba', + 'news', + 'media', + 'sale', + 'shopping', + 'studio', + 'tax', + 'technology', + 'vin', + 'baby', + 'college', + 'monster', + 'protection', + 'rent', + 'security', + 'storage', + 'theatre', + 'bond', + 'cyou', + 'uno', + 'school', + 'global', + 'me', + 'pw', + 'hk', + 'tv', + 'saxo', + 'click', + 'auto', + 'autos', + 'beauty', + 'boats', + 'car', + 'cars', + 'hair', + 'homes', + 'makeup', + 'motorcycles', + 'quest', + 'skin', + 'tickets', + 'yachts', + 'kids' + ]; + } (domains)); + return domains; +}var hasRequiredValidateGlobalTld; + +function requireValidateGlobalTld () { + if (hasRequiredValidateGlobalTld) return validateGlobalTld$1; + hasRequiredValidateGlobalTld = 1; + Object.defineProperty(validateGlobalTld$1, "__esModule", { + value: true + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _trie = /*@__PURE__*/ trie.r(); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _domains = /*@__PURE__*/ requireDomains(); + const _tldtsexperimental = /*#__PURE__*/ _interop_require_default(require$$5); + const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.r(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + (async ()=>{ + const trie = new _trie.HostnameSmolTrie(); + const extraWhiteTLDs = new Set(); + for await (const line of (0, _fetchtextbyline.readFileByLine)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip', 'domestic.conf'))){ + const [type, domain] = line.split(','); + if (type !== 'DOMAIN' && type !== 'DOMAIN-SUFFIX') { + continue; + } + if (domain === 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe') { + continue; + } + const tld = _tldtsexperimental.default.getPublicSuffix(domain, _loosetldtsopt.looseTldtsOpt); + if (tld) { + extraWhiteTLDs.add(tld); + } + } + for await (const line of (0, _fetchtextbyline.readFileByLine)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip', 'global.conf'))){ + const [type, domain] = line.split(','); + switch(type){ + case 'DOMAIN': + trie.add(domain); + break; + case 'DOMAIN-SUFFIX': + trie.add(domain, true); + break; + } + } + _domains.ICP_TLD.forEach((tld)=>trie.whitelist(tld, true)); + extraWhiteTLDs.forEach((tld)=>trie.whitelist(tld, true)); + console.log(trie.dump().join('\n')); + })(); + return validateGlobalTld$1; +}var validateGlobalTldExports = requireValidateGlobalTld(); +const validateGlobalTld = /*@__PURE__*/fetchRetry.g(validateGlobalTldExports);module.exports=validateGlobalTld; \ No newline at end of file diff --git a/Dist/validate-hash-collision-test.cjs b/Dist/validate-hash-collision-test.cjs new file mode 100644 index 00000000..538f2f69 --- /dev/null +++ b/Dist/validate-hash-collision-test.cjs @@ -0,0 +1,55 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),require$$5=require('fdir'),require$$0=require('node:path'),fetchTextByLine=require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require$$4=require('hash-wasm');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:fs'),require('node:process'),require('node:readline'),require('node:stream/web'),require('foxts/guard');var validateHashCollisionTest$1 = {};/* eslint-disable no-await-in-loop -- no concurrent */ + +var hasRequiredValidateHashCollisionTest; + +function requireValidateHashCollisionTest () { + if (hasRequiredValidateHashCollisionTest) return validateHashCollisionTest$1; + hasRequiredValidateHashCollisionTest = 1; + Object.defineProperty(validateHashCollisionTest$1, "__esModule", { + value: true + }); + const _fdir = require$$5; + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _hashwasm = require$$4; + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + (async ()=>{ + const hashMap = new Map(); + const runHash = async (inputs)=>{ + for (const input of inputs){ + const hash = await (0, _hashwasm.xxhash3)(input); + if (!hashMap.has(hash)) { + hashMap.set(hash, new Set()); + } + hashMap.get(hash).add(input); + } + }; + const files = await new _fdir.fdir().withRelativePaths().crawl(_dir.OUTPUT_SURGE_DIR).withPromise(); + for (const file of files){ + const fullpath = _nodepath.default.join(_dir.OUTPUT_SURGE_DIR, file); + if (file.startsWith('domainset' + _nodepath.default.sep)) { + await runHash((await (0, _fetchtextbyline.readFileIntoProcessedArray)(fullpath)).map((i)=>i[0] === '.' ? i.slice(1) : i)); + } else if (file.startsWith('non_ip' + _nodepath.default.sep)) { + await runHash((await (0, _fetchtextbyline.readFileIntoProcessedArray)(fullpath)).map((i)=>i.split(',')[1])); + } + } + console.log(hashMap.size); + let collision = 0; + hashMap.forEach((v, k)=>{ + if (v.size > 1) { + collision++; + console.log(k, '=>', v); + } + }); + if (collision === 0) { + console.log(hashMap); + } + })(); + return validateHashCollisionTest$1; +}var validateHashCollisionTestExports = requireValidateHashCollisionTest(); +const validateHashCollisionTest = /*@__PURE__*/fetchRetry.g(validateHashCollisionTestExports);module.exports=validateHashCollisionTest; \ No newline at end of file diff --git a/Dist/validate-reject-stats.cjs b/Dist/validate-reject-stats.cjs new file mode 100644 index 00000000..e36e7a90 --- /dev/null +++ b/Dist/validate-reject-stats.cjs @@ -0,0 +1,43 @@ +'use strict';const fetchRetry=require('./chunks/fetch-retry.D06uBUaW.cjs'),require$$0$1=require('node:path'),fetchTextByLine=require('./chunks/fetch-text-by-line.YY5b5610.cjs'),require$$0=require('tldts'),looseTldtsOpt=require('./chunks/loose-tldts-opt.DLUpGXpj.cjs');require('picocolors'),require('undici'),require('undici-cache-store-better-sqlite3'),require('node:util'),require('node:fs'),require('node:process'),require('node:readline'),require('node:stream/web'),require('foxts/guard');var validateRejectStats$1 = {};var hasRequiredValidateRejectStats; + +function requireValidateRejectStats () { + if (hasRequiredValidateRejectStats) return validateRejectStats$1; + hasRequiredValidateRejectStats = 1; + Object.defineProperty(validateRejectStats$1, "__esModule", { + value: true + }); + const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1); + const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a(); + const _dir = /*@__PURE__*/ fetchRetry.a(); + const _processline = /*@__PURE__*/ fetchTextByLine.r(); + const _tldts = /*#__PURE__*/ _interop_require_default(require$$0); + const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.r(); + function _interop_require_default(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + (async ()=>{ + const rejectDomainCountMap = await runAgainstDomainset(new Map(), _nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'domainset', 'reject.conf')); + const rejectExtraDomainCountMap = await runAgainstDomainset(new Map(), _nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'domainset', 'reject_extra.conf')); + const rejectDomainCountArr = Array.from(rejectDomainCountMap).sort((a, b)=>b[1] - a[1]).filter(([, count])=>count > 20); + const rejectExtraDomainCountArr = Array.from(rejectExtraDomainCountMap).sort((a, b)=>b[1] - a[1]).filter(([, count])=>count > 20); + console.table(rejectDomainCountArr); + console.table(rejectExtraDomainCountArr); + })(); + async function runAgainstDomainset(rejectDomainCountMap, file) { + for await (const line of (0, _fetchtextbyline.readFileByLine)(file)){ + if (!(0, _processline.processLine)(line)) { + continue; + } + const apexDomain = _tldts.default.getDomain(line, _loosetldtsopt.loosTldOptWithPrivateDomains); + if (!apexDomain) { + continue; + } + rejectDomainCountMap.set(apexDomain, rejectDomainCountMap.has(apexDomain) ? rejectDomainCountMap.get(apexDomain) + 1 : 1); + } + return rejectDomainCountMap; + } + return validateRejectStats$1; +}var validateRejectStatsExports = requireValidateRejectStats(); +const validateRejectStats = /*@__PURE__*/fetchRetry.g(validateRejectStatsExports);module.exports=validateRejectStats; \ No newline at end of file