Skip to content

Commit

Permalink
Chore: build sukka_always_real_ip.sgmodule w/ script
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Dec 20, 2023
1 parent d41b4d0 commit b0dd250
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ List/
Clash/
Modules/sukka_local_dns_mapping.sgmodule
Modules/sukka_url_redirect.sgmodule
Modules/sukka_common_always_realip.sgmodule
Mock/www-google-analytics-com_ga.js
Mock/www-googletagservices-com_gpt.js
Mock/www-google-analytics-com_analytics.js
Expand Down
56 changes: 56 additions & 0 deletions Build/build-sgmodule-always-realip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import path from 'path';
import { task } from './lib/trace-runner';
import { compareAndWriteFile } from './lib/create-file';

const HOSTNAMES = [
// Intranet
'*.lan',
'*.localdomain',
'*.localhost',
'*.home.arpa',
// Network Detection, Captive Portal
'*.msftncsi.com',
'*.msftconnecttest.com',
'network-test.debian.org',
'detectportal.firefox.com',
'resolver1.opendns.com',
// Handle SNAT conversation properly
'*.srv.nintendo.net',
'*.stun.playstation.net',
'xbox.*.microsoft.com',
'*.xboxlive.com',
'*.turn.twilio.com',
'*.stun.twilio.com',
'stun.*.*',
'stun.*.*.*',
// NTP
'time.*.com', 'time.*.gov, time.*.edu.cn, time.*.apple.com', 'time1.*.com', 'time2.*.com', 'time3.*.com', 'time4.*.com', 'time5.*.com', 'time6.*.com', 'time7.*.com', 'time8.*.com', 'time9.*.com, ntp.*.com, ntp1.*.com, ntp2.*.com, ntp3.*.com, ntp4.*.com, ntp5.*.com, ntp6.*.com, ntp7.*.com', 'time1.*.com', 'time2.*.com', 'time3.*.com', 'time4.*.com', 'time5.*.com', 'time6.*.com', 'time7.*.com', 'time8.*.com', 'ti me9.*.com', '*.time.edu.cn', '*.ntp.org.cn', '*.pool.ntp.org', 'time1.cloud.tencent.com',
// AdGuard
'local.adguard.org',
'injections.adguard.org',
// QQ Login
'localhost.ptlogin2.qq.com',
'localhost.sec.qq.com',
'localhost.work.weixin.qq.com',
// Microsoft Auto Discovery
'PDC._msDCS.*.*',
'DC._msDCS.*.*',
'GC._msDCS.*.*'
] as const;

export const buildAlwaysRealIPModule = task(import.meta.path, async () => {
return compareAndWriteFile(
[
'#!name=[Sukka] Always Real IP Plus',
`#!desc=Last Updated: ${new Date().toISOString()}`,
'',
'[General]',
`always-real-ip = %APPEND% ${HOSTNAMES.join(', ')}`
],
path.resolve(import.meta.dir, '../Modules/sukka_common_always_realip.sgmodule')
);
});

if (import.meta.main) {
buildAlwaysRealIPModule();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function escapeRegExp(string = '') {
: string;
}

const REDIRECT = /** @type {const} */ ([
const REDIRECT = [
// Gravatar
['gravatar.neworld.org/', 'https://secure.gravatar.com/'],
['cdn.v2ex.com/gravatar/', 'https://secure.gravatar.com/avatar/'],
Expand Down Expand Up @@ -69,7 +69,7 @@ const REDIRECT = /** @type {const} */ ([
['pics.javbus.com/', 'https://i0.wp.com/pics.javbus.com/'],
['googlefonts.wp-china-yes.net/', 'https://fonts.googleapis.com/'],
['googleajax.wp-china-yes.net/', 'https://ajax.googleapis.com/']
]);
] as const;

export const buildRedirectModule = task(import.meta.path, async () => {
const domains = Array.from(new Set(REDIRECT.map(([from]) => tldts.getHostname(from, { detectIp: false })))).filter(Boolean);
Expand Down
15 changes: 11 additions & 4 deletions Build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ import { buildInternalCDNDomains } from './build-internal-cdn-rules';
// import { buildInternalChnDomains } from './build-internal-chn-domains';
import { buildDomesticRuleset } from './build-domestic-ruleset';
import { buildStreamService } from './build-stream-service';
import { buildRedirectModule } from './build-redirect-module';

import { buildRedirectModule } from './build-sgmodule-redirect';
import { buildAlwaysRealIPModule } from './build-sgmodule-always-realip';

import { validate } from './validate-domainset';

import { buildMicrosoftCdn } from './build-microsoft-cdn';
import { buildSSPanelUIMAppProfile } from './build-sspanel-appprofile';

import { buildPublic } from './build-public';
import { downloadMockAssets } from './download-mock-assets';
// import type { TaskResult } from './lib/trace-runner';

import type { TaskResult } from './lib/trace-runner';

(async () => {
console.log('Bun version:', Bun.version);
console.log('Bun version:', Bun.version, Bun.revision);

try {
// TODO: restore this once Bun has fixed their worker
Expand Down Expand Up @@ -66,6 +70,8 @@ import { downloadMockAssets } from './download-mock-assets';
const buildDomesticRulesetPromise = downloadPreviousBuildPromise.then(() => buildDomesticRuleset());

const buildRedirectModulePromise = downloadPreviousBuildPromise.then(() => buildRedirectModule());
const buildAlwaysRealIPModulePromise = downloadPreviousBuildPromise.then(() => buildAlwaysRealIPModule());

const buildStreamServicePromise = downloadPreviousBuildPromise.then(() => buildStreamService());

const buildMicrosoftCdnPromise = downloadPreviousBuildPromise.then(() => buildMicrosoftCdn());
Expand All @@ -92,6 +98,7 @@ import { downloadMockAssets } from './download-mock-assets';
// buildInternalChnDomainsPromise,
buildDomesticRulesetPromise,
buildRedirectModulePromise,
buildAlwaysRealIPModulePromise,
buildStreamServicePromise,
buildMicrosoftCdnPromise,
buildSSPanelUIMAppProfilePromise,
Expand All @@ -112,7 +119,7 @@ import { downloadMockAssets } from './download-mock-assets';
}
})();

function printStats(stats: Array<{ start: number, end: number, taskName: string }>): void {
function printStats(stats: TaskResult[]): void {
stats.sort((a, b) => a.start - b.start);

const longestTaskName = Math.max(...stats.map(i => i.taskName.length));
Expand Down
5 changes: 0 additions & 5 deletions Modules/sukka_common_always_realip.sgmodule

This file was deleted.

0 comments on commit b0dd250

Please sign in to comment.