Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
},
"license": "GPL-3.0",
"dependencies": {
"ip-address": "5.8.9",
"pako": "^2.1.0",
"webdav": "^5.9.0"
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/ProxyEngineChrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function FindProxyForURL(url, host, noDiagnostics) {
// subscription skip bypass rules/ don't apply proxy
let subMatchedRule = findMatchedUrlInRules(url, host, hostAndPort, compiledRules.SubscriptionRules);
if (subMatchedRule) {
return makeResultForAlwaysEnabledForced(userMatchedRule)
return makeResultForAlwaysEnabledForced(subMatchedRule)
}
// subscription bypass rules/ apply proxy by force
Expand Down
108 changes: 13 additions & 95 deletions src/lib/RuleImporterSwitchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
* @source https://github.com/FelisCatus/SwitchyOmega
* @license GPL3
*/
const Utils = require('./Utils').Utils;
const { Address4, Address6 } = require('ip-address');
const IP = {
v4: { Address: Address4 },
v6: { Address: Address6 }
};
Comment on lines +9 to +14

const strStartsWith = function (str, prefix) {
return str.substr(0, prefix.length) === prefix;
};
Expand Down Expand Up @@ -435,9 +442,9 @@ const Conditions = {
},
normalizeIp: function (addr) {
let ref1;
return ((ref1 = addr.correctForm) != null ? ref1 : addr.canonicalForm).call(addr);
return ((ref1 = addr.canonicalForm) != null ? ref1 : addr.correctForm).call(addr);
},
//ipv6Max: new IP.v6.Address('::/0').endAddress().canonicalForm(),
ipv6Max: new IP.v6.Address('::/0').endAddress().canonicalForm(),
localHosts: ["127.0.0.1", "[::1]", "localhost"],
getWeekdayList: function (condition) {
let i, j, k, results, results1;
Expand Down Expand Up @@ -871,101 +878,12 @@ const Conditions = {
return addr.isInSubnet(cache.addr);
},
compile: function (condition, cache) {
let hostIsInNet, hostIsInNetEx, hostLooksLikeIp;
cache = cache.analyzed;
hostLooksLikeIp = cache.addr.v4 ? new U2.AST_Binary({
left: new U2.AST_Sub({
expression: new U2.AST_SymbolRef({
name: 'host'
}),
property: new U2.AST_Binary({
left: new U2.AST_Dot({
expression: new U2.AST_SymbolRef({
name: 'host'
}),
property: 'length'
}),
operator: '-',
right: new U2.AST_Number({
value: 1
})
})
}),
operator: '>=',
right: new U2.AST_Number({
value: 0
})
}) : new U2.AST_Binary({
left: new U2.AST_Call({
expression: new U2.AST_Dot({
expression: new U2.AST_SymbolRef({
name: 'host'
}),
property: 'indexOf'
}),
args: [
new U2.AST_String({
value: ':'
})
]
}),
operator: '>=',
right: new U2.AST_Number({
value: 0
})
});
if (cache.addr.subnetMask === 0) {
return hostLooksLikeIp;
let regex = Utils.ipCidrNotationToRegExp(cache.normalized, cache.addr.parsedSubnet);
if (!regex) {
throw new Error(`Failed to compile CIDR rule ${cache.normalized}/${cache.addr.parsedSubnet} to regex`);
}
hostIsInNet = new U2.AST_Call({
expression: new U2.AST_SymbolRef({
name: 'isInNet'
}),
args: [
new U2.AST_SymbolRef({
name: 'host'
}), new U2.AST_String({
value: cache.normalized
}), new U2.AST_String({
value: cache.mask
})
]
});
if (!cache.addr.v4) {
hostIsInNetEx = new U2.AST_Call({
expression: new U2.AST_SymbolRef({
name: 'isInNetEx'
}),
args: [
new U2.AST_SymbolRef({
name: 'host'
}), new U2.AST_String({
value: cache.normalized + cache.addr.subnet
})
]
});
hostIsInNet = new U2.AST_Conditional({
condition: new U2.AST_Binary({
left: new U2.AST_UnaryPrefix({
operator: 'typeof',
expression: new U2.AST_SymbolRef({
name: 'isInNetEx'
})
}),
operator: '===',
right: new U2.AST_String({
value: 'function'
})
}),
consequent: hostIsInNetEx,
alternative: hostIsInNet
});
}
return new U2.AST_Binary({
left: hostLooksLikeIp,
operator: '&&',
right: hostIsInNet
});
return this.regTest('host', regex);
Comment on lines +882 to +886
},
str: function (condition) {
return condition.ip + '/' + condition.prefixLength;
Expand Down