SmartProxy
SmartProxy copied to clipboard
[Enhancement] Improve SwitchOmega rules importer
SwitchOmega rules importer needs work. Some info of previous discussions #286
Samples:
- Click "Publish Rule List" and the downloaded one:
[SwitchyOmega Conditions]
; Require: SwitchyOmega >= 2.3.2
; Date: 2/20/2024
; Usage: https://github.com/FelisCatus/SwitchyOmega/wiki/RuleListUsage
!internal.example.com
*.example.com
ddsfsdf
ddsfsdf
sdfgegg
!UrlWildcard: tdfsfdsf
UrlRegex: dfsfdsfsdf
Disabled:
HostRegex: testHostRege
- Click "Edit Source Code" in a Switch Profile
[SwitchyOmega Conditions]
@with result
internal.example.com +direct
*.example.com +proxy
ddsfsdf +as2
sdfgegg +ss
UrlWildcard: tdfsfdsf +direct
UrlRegex: dfsfdsfsdf +as3
HostRegex: testHostRege +as3
Disabled: +proxy
* +direct
- backup
{
"+__ruleListOf_auto switch": {
"name": "__ruleListOf_auto switch",
"defaultProfileName": "direct",
"profileType": "RuleListProfile",
"color": "#99dd99",
"format": "AutoProxy",
"matchProfileName": "direct",
"ruleList": "[AutoProxy 0.2.9]\n! Checksum: 9PVgZURV+9DlFwAZIld/ZQ\n! Expires: 6h\n! Title: GFWList4LL\n! GFWList with EVERYTHING included\n! Last Modified: Mon, 19 Feb 2024 10:27:32 -0500\n!\n! HomePage: https://github.com/gfwlist/gfwlist\n! License: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt\n!\n! GFWList is unlikely to fully comprise the real\n! rules being deployed inside GFW system. We try\n! our best to keep the list up to date. Please\n! contact us regarding URL submission / removal,\n! or suggestion / enhancement at issue tracker:\n! https://github.com/gfwlist/gfwlist/issues/.\n\n!---------403/451/503/520 & URL Redirects---------\n!--ehentai\n|http://85.17.73.31/\n!--||adorama.com\n||afreecatv.com\n||agnesb.fr\n||carfax.com\n.casinobellini.com",
"revision": "18deaa1e43f",
"sourceUrl": "http://127.0.0.1:9999/123.txt",
"lastUpdate": "2024-02-27T12:54:54.758Z"
},
"+auto switch": {
"profileType": "SwitchProfile",
"rules": [
{
"condition": {
"conditionType": "HostWildcardCondition",
"pattern": "internal.example.com"
},
"profileName": "direct"
},
{
"condition": {
"conditionType": "HostWildcardCondition",
"pattern": "*.example.com"
},
"profileName": "proxy"
}
],
"name": "auto switch",
"color": "#99dd99",
"defaultProfileName": "__ruleListOf_auto switch",
"revision": "18de3134b36"
},
"+proxy": {
"bypassList": [
{
"pattern": "127.0.0.1",
"conditionType": "BypassCondition"
},
{
"pattern": "::1",
"conditionType": "BypassCondition"
},
{
"pattern": "localhost",
"conditionType": "BypassCondition"
}
],
"profileType": "FixedProfile",
"name": "proxy",
"color": "#99ccee",
"fallbackProxy": {
"port": 8080,
"scheme": "http",
"host": "proxy.example.com"
}
},
"-addConditionsToBottom": false,
"-confirmDeletion": true,
"-downloadInterval": 1440,
"-enableQuickSwitch": false,
"-monitorWebRequests": true,
"-quickSwitchProfiles": [],
"-refreshOnProfileChange": true,
"-revertProxyChanges": true,
"-showExternalProfile": true,
"-showInspectMenu": true,
"-startupProfileName": "",
"schemaVersion": 2,
"+adsad": {
"profileType": "PacProfile",
"name": "adsad",
"pacScript": "function FindProxyForURL(url, host) {\n return \"DIRECT\";\n}",
"color": "#fa8",
"revision": "18de96672e5"
},
"+profile_default_direct": {
"profileType": "FixedProfile",
"name": "profile_default_direct",
"bypassList": [
{
"conditionType": "BypassCondition",
"pattern": "127.0.0.1"
},
{
"conditionType": "BypassCondition",
"pattern": "[::1]"
},
{
"conditionType": "BypassCondition",
"pattern": "localhost"
}
],
"color": "#47b",
"revision": "18deaa3b0d6",
"proxyForHttp": {
"scheme": "https",
"port": 443,
"host": "example.com"
},
"proxyForHttps": {
"scheme": "socks5",
"port": 1080,
"host": "example.com"
},
"proxyForFtp": {
"scheme": "http",
"port": 1080,
"host": "example.com"
}
},
"+pac_url": {
"profileType": "PacProfile",
"name": "pac_url",
"pacScript": "function FindProxyForURL(url, host) {\r\n return \"PROXY test.com:8080\";\r\n}",
"color": "#d497ee",
"revision": "18deaa504d6",
"pacUrl": "http://127.0.0.1:9999/pac.txt",
"lastUpdate": "2024-02-27T12:58:19.705Z"
},
"+virtualprofile": {
"profileType": "VirtualProfile",
"name": "virtualprofile",
"defaultProfileName": "profile_default_direct",
"rules": [],
"color": "#d497ee",
"revision": "18deaa59e87"
}
}
I've came up with this rules file, from what I see so far the ! rule should be returned as white-list by externalAppRuleParser.Switchy.parseAndCompile which is not happening at the moment.
[SwitchyOmega Conditions]
; Require: SwitchyOmega >= 2.3.2
; Date: 2017-6-18
; Usage: https://github.com/FelisCatus/SwitchyOmega/wiki/RuleListUsage
UrlWildcard: *://sub.localhost.com/*
UrlWildcard: *://localhost.com/*
*.ytimg.com
*.youtube.com
UrlWildcard: *google*
UrlWildcard: *tumblr*
UrlWildcard: *youtube*
UrlWildcard: *fbcdn.net*
UrlWildcard: *facebook*
UrlWildcard: *messenger.com*
UrlWildcard: *glgnltks.xyz*
UrlWildcard: *angularjs.org*
UrlWildcard: *npmjs.com/
UrlWildcard: *gist.github.com/*
UrlRegex: ^http:\/\/localhost\.com:3000.*
*wikipedia.org*
*twitter.com*
*html5rocks.com/*
!*.github.com
Mentioning your good observations: @jackyzy823
Current Status
1. Import Rule (with AutoProxy file) doesn't work functionally. The parsed [rules object](https://github.com/salarcode/SmartProxy/blob/dd1cb0629fb6bb0316407e14e31bed30829a1a71/src/lib/RuleImporter.ts#L213) couldn't be [de-serialized](https://github.com/salarcode/SmartProxy/blob/dd1cb0629fb6bb0316407e14e31bed30829a1a71/src/ui/code/settingsPage.ts#L1672) to [ProxyRule](https://github.com/salarcode/SmartProxy/blob/dd1cb0629fb6bb0316407e14e31bed30829a1a71/src/core/definitions.ts#L729) class. 2. Subscribe rule list to SwitchOmega: it ignores "!" mark (means DIRECT) , which have the opposite effect. 3. Some SwitchyOmega condition cause parsing error: it requires U2 (uglify ast) to compile which we are not bundled. So these conditions should be filtered out. (For example FalseCondition (Disableld) , BypassCondition etc ... )Design:
* We could unify some functions of the `Import rule with file` and `Subscribe rule list` . * Use same parser for one format , but different converter to ProxyRule or SubscriptionProxyRule * SwitchyOmega has 2 formats of exported file (and 1 format of backup file) * transitional: without "@with result" mark , * we should handle "!" correctly * we should show a window asking user all these rulse should use which proxy ( default/active/ or others) * modern: with "@with result" mark , * we should handle "+direct" correctly * we should either give up all the proxy servers and show a window asking user all these rulse should use which proxy ( default/active/ or others) * **OR** we should gather all proxy servers in the file and show a window let user define the mapping between original proxies in file to proxies (default/active/or others) in smartproxy . * backup files: * we might also support import `profiles`