Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Improve SwitchOmega rules importer #345

Open
salarcode opened this issue Feb 27, 2024 · 3 comments
Open

[Enhancement] Improve SwitchOmega rules importer #345

salarcode opened this issue Feb 27, 2024 · 3 comments
Labels
type-enhancement Enhancement to existing feature

Comments

@salarcode
Copy link
Owner

salarcode commented Feb 27, 2024

SwitchOmega rules importer needs work. Some info of previous discussions #286

@salarcode salarcode added type-new-feature Adding a new feature type-enhancement Enhancement to existing feature and removed type-new-feature Adding a new feature labels Feb 27, 2024
@jackyzy823
Copy link
Contributor

Samples:

  1. 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
  1. 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
  1. 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"
    }
}

@salarcode
Copy link
Owner Author

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

@salarcode
Copy link
Owner Author

salarcode commented Mar 16, 2024

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`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement Enhancement to existing feature
Projects
None yet
Development

No branches or pull requests

2 participants