Skip to content

Commit

Permalink
userdata strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
zuiwuchang committed Nov 29, 2023
1 parent c7357d7 commit d6505ad
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 11 deletions.
14 changes: 11 additions & 3 deletions bin/js/xray/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ function generateDNS(opts, ips) {
// 阻止訪問
let block = new rule_1.Rule().pushDomain(strategy.blockDomain);
const routing = (_a = opts.userdata) === null || _a === void 0 ? void 0 : _a.routing;
console.log(JSON.stringify(routing));
if (routing) {
proxy.pushDomain(routing.proxyDomain);
direct.pushDomain(routing.directDomain);
block.pushDomain(routing.blockDomain);
switch (strategy.value) {
case 5: // 直連優先
case 6: // 直接連接
direct.pushDomain(routing.directDomain);
proxy.pushDomain(routing.proxyDomain);
break;
default:
proxy.pushDomain(routing.proxyDomain);
direct.pushDomain(routing.directDomain);
break;
}
}
if (proxy.isValid()) {
servers.push(...[
Expand Down
30 changes: 27 additions & 3 deletions bin/js/xray/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,24 @@ function generateRouting(opts) {
},
{
type: 'field',
ip: ['8.8.8.8', '1.1.1.1'],
ip: [
// google
'8.8.8.8',
// cloudflare
'1.1.1.1',
],
outboundTag: 'out-proxy',
},
{
type: 'field',
ip: [
'119.29.29.29',
'223.5.5.5',
'127.0.0.1',
'::1', // ipv6 本機
],
outboundTag: 'out-freedom',
},
];
// 代理訪問
let proxy = new rule_1.Rule().pushDomain(strategy.proxyDomain).pushIP(strategy.proxyIP);
Expand All @@ -36,9 +51,18 @@ function generateRouting(opts) {
let block = new rule_1.Rule().pushDomain(strategy.blockDomain).pushIP(strategy.blockIP);
const routing = (_d = opts.userdata) === null || _d === void 0 ? void 0 : _d.routing;
if (routing) {
proxy.pushDomain(routing.proxyDomain).pushIP(routing.proxyIP);
direct.pushDomain(routing.directDomain).pushIP(routing.directIP);
block.pushDomain(routing.blockDomain).pushIP(routing.blockIP);
switch (strategy.value) {
case 5: // 直連優先
case 6: // 直接連接
direct.pushDomain(routing.directDomain).pushIP(routing.directIP);
proxy.pushDomain(routing.proxyDomain).pushIP(routing.proxyIP);
break;
default:
proxy.pushDomain(routing.proxyDomain).pushIP(routing.proxyIP);
direct.pushDomain(routing.directDomain).pushIP(routing.directIP);
break;
}
}
pushRules(rules, 'out-proxy', proxy);
pushRules(rules, 'out-freedom', direct);
Expand Down
13 changes: 11 additions & 2 deletions bin/ts/xray/dns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,18 @@ export function generateDNS(opts: ConfigureOptions<Userdata>, ips?: Array<string
const routing = opts.userdata?.routing

if (routing) {
proxy.pushDomain(routing.proxyDomain!)
direct.pushDomain(routing.directDomain!)
block.pushDomain(routing.blockDomain!)
switch (strategy.value) {
case 5: // 直連優先
case 6: // 直接連接
direct.pushDomain(routing.directDomain!)
proxy.pushDomain(routing.proxyDomain!)
break
default:
proxy.pushDomain(routing.proxyDomain!)
direct.pushDomain(routing.directDomain!)
break
}
}
if (proxy.isValid()) {
servers.push(...[
Expand Down
30 changes: 27 additions & 3 deletions bin/ts/xray/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,24 @@ export function generateRouting(opts: ConfigureOptions<Userdata>): Routing | und
},
{
type: 'field',
ip: ['8.8.8.8', '1.1.1.1'],
ip: [
// google
'8.8.8.8',
// cloudflare
'1.1.1.1',
],
outboundTag: 'out-proxy',
},
{
type: 'field',
ip: [
'119.29.29.29', // 騰訊
'223.5.5.5', // 阿里
'127.0.0.1', // 本機
'::1', // ipv6 本機
],
outboundTag: 'out-freedom',
},
]
// 代理訪問
let proxy = new StrategyRule().pushDomain(strategy.proxyDomain).pushIP(strategy.proxyIP)
Expand All @@ -119,9 +134,18 @@ export function generateRouting(opts: ConfigureOptions<Userdata>): Routing | und
let block = new StrategyRule().pushDomain(strategy.blockDomain).pushIP(strategy.blockIP)
const routing = opts.userdata?.routing
if (routing) {
proxy.pushDomain(routing.proxyDomain!).pushIP(routing.proxyIP!)
direct.pushDomain(routing.directDomain!).pushIP(routing.directIP!)
block.pushDomain(routing.blockDomain!).pushIP(routing.blockIP!)
switch (strategy.value) {
case 5: // 直連優先
case 6: // 直接連接
direct.pushDomain(routing.directDomain!).pushIP(routing.directIP!)
proxy.pushDomain(routing.proxyDomain!).pushIP(routing.proxyIP!)
break
default:
proxy.pushDomain(routing.proxyDomain!).pushIP(routing.proxyIP!)
direct.pushDomain(routing.directDomain!).pushIP(routing.directIP!)
break
}
}
pushRules(rules, 'out-proxy', proxy)
pushRules(rules, 'out-freedom', direct)
Expand Down

0 comments on commit d6505ad

Please sign in to comment.