diff --git a/Furious/Action/Import.py b/Furious/Action/Import.py index 4fb52cb..4c0ba24 100644 --- a/Furious/Action/Import.py +++ b/Furious/Action/Import.py @@ -31,6 +31,7 @@ from Furious.Utility.Utility import ( StateContext, ServerStorage, bootstrapIcon, + parseHostPort, enumValueWrapper, protocolRepr, ) @@ -262,7 +263,9 @@ class ImportLinkAction(Action): remark = urllib.parse.unquote(parseResult.fragment) - uuid_, remote_host, remote_port = re.split(r'[@:]', parseResult.netloc) + uuid_, server = parseResult.netloc.split('@') + + remote_host, remote_port = parseHostPort(server) encryption = queryObject.get('encryption', 'none') type_ = queryObject.get('type', 'tcp') @@ -301,9 +304,11 @@ class ImportLinkAction(Action): ) return remark, True - except Exception: + except Exception as ex: # Any non-exit exceptions + logger.error(f'import share link failed: {data}. Exception: {ex}') + return '', False @staticmethod @@ -316,18 +321,24 @@ class ImportLinkAction(Action): remark = urllib.parse.unquote(result.fragment) try: - # Try pack with 3 element - userinfo, address, port = re.split(r'[@:]', result.netloc) + # Try pack with 4 element + + methodPassword, server = result.netloc.split('@') + + method, password = methodPassword.split(':') + + address, port = parseHostPort(server) + except ValueError: + # Unpack error. Try pack with 3 element + userinfo, server = result.netloc.split('@') + + address, port = parseHostPort(server) # Some old SS share link doesn't add padding # in base64 encoding. Add padding to userinfo method, password = ( Base64Encoder.decode(userinfo + '===').decode().split(':') ) - except ValueError: - # Unpack error. Try pack with 4 element - - method, password, address, port = re.split(r'[@:]', result.netloc) except Exception as ex: # Any non-exit exceptions @@ -359,6 +370,8 @@ class ImportLinkAction(Action): except Exception as ex: # Any non-exit exceptions + logger.error(f'import share link failed: {data}. Exception: {ex}') + return '', False @staticmethod @@ -370,6 +383,7 @@ class ImportLinkAction(Action): # ss://base64... myData = Base64Encoder.decode(data[5:]).decode() myJSON = XrayCoreConfiguration.build( + # For sslegacy, we don't try to consider IPv6 case ProxyOutboundObjectSS(*re.split(r'[@:]', myData)) ) @@ -406,7 +420,9 @@ class ImportLinkAction(Action): remark = urllib.parse.unquote(parseResult.fragment) - password, address, port = re.split(r'[@:]', parseResult.netloc) + password, server = parseResult.netloc.split('@') + + address, port = parseHostPort(server) type_ = queryObject.get('type', 'tcp') # For Trojan: Assign tls by default @@ -442,9 +458,11 @@ class ImportLinkAction(Action): ) return remark, True - except Exception: + except Exception as ex: # Any non-exit exceptions + logger.error(f'import share link failed: {data}. Exception: {ex}') + return '', False @staticmethod @@ -497,6 +515,8 @@ class ImportLinkAction(Action): importServerArgs, ) + logger.error(f'unsupported share link: {shareLink}') + return '', False def triggeredCallback(self, checked): diff --git a/Furious/Core/Intellisense.py b/Furious/Core/Intellisense.py index c8a2c7c..2613a07 100644 --- a/Furious/Core/Intellisense.py +++ b/Furious/Core/Intellisense.py @@ -16,7 +16,7 @@ # along with this program. If not, see . from Furious.Core.Core import XrayCore, Hysteria1, Hysteria2 -from Furious.Utility.Utility import Protocol, protocolRepr +from Furious.Utility.Utility import Protocol, protocolRepr, parseHostPort class Intellisense: @@ -113,11 +113,14 @@ class Intellisense: return '' - if Intellisense.getCoreType(ob) == Hysteria1.name(): - return ob['server'].split(':')[0] - - if Intellisense.getCoreType(ob) == Hysteria2.name(): - return ob['server'].split(':')[0] + if ( + Intellisense.getCoreType(ob) == Hysteria1.name() + or Intellisense.getCoreType(ob) == Hysteria2.name() + ): + if ob['server'].count(',') == 0: + return parseHostPort(ob['server'])[0] + else: + return parseHostPort(ob['server'].split(',')[0])[0] return '' except Exception: @@ -154,11 +157,16 @@ class Intellisense: return '' - if Intellisense.getCoreType(ob) == Hysteria1.name(): - return ob['server'].split(':')[1] + if ( + Intellisense.getCoreType(ob) == Hysteria1.name() + or Intellisense.getCoreType(ob) == Hysteria2.name() + ): + if ob['server'].count(',') == 0: + return parseHostPort(ob['server'])[1] + else: + server, dynamicPort = ob['server'].split(',') - if Intellisense.getCoreType(ob) == Hysteria2.name(): - return ob['server'].split(':')[1] + return f'{parseHostPort(server)[1]},{dynamicPort}' return '' except Exception: diff --git a/Furious/Utility/Proxy.py b/Furious/Utility/Proxy.py index b3d418b..a97b8eb 100644 --- a/Furious/Utility/Proxy.py +++ b/Furious/Utility/Proxy.py @@ -16,7 +16,7 @@ # along with this program. If not, see . from Furious.Utility.Constants import PLATFORM -from Furious.Utility.Utility import runCommand +from Furious.Utility.Utility import runCommand, parseHostPort import logging import subprocess @@ -124,7 +124,7 @@ class _Proxy: if PLATFORM == 'Linux': try: - host, port = server.split(':') + host, port = parseHostPort(server) linuxProxyConfig('proxy.http', 'host', host) linuxProxyConfig('proxy.http', 'port', port) @@ -143,8 +143,8 @@ class _Proxy: if PLATFORM == 'Darwin': try: - darwinProxyConfig('setwebproxy', *server.split(':')) - darwinProxyConfig('setsecurewebproxy', *server.split(':')) + darwinProxyConfig('setwebproxy', *parseHostPort(server)) + darwinProxyConfig('setsecurewebproxy', *parseHostPort(server)) darwinProxyConfig('setproxybypassdomains', *bypass.split(';')) except Exception: # Any non-exit exceptions diff --git a/Furious/Widget/EditConfiguration.py b/Furious/Widget/EditConfiguration.py index ebb2036..2acd111 100644 --- a/Furious/Widget/EditConfiguration.py +++ b/Furious/Widget/EditConfiguration.py @@ -52,6 +52,7 @@ from Furious.Utility.Utility import ( SupportConnectedCallback, bootstrapIcon, enumValueWrapper, + parseHostPort, eventLoopWait, swapListItem, moveToCenter, @@ -747,8 +748,8 @@ def useProxyServerIfPossible(manager, loggerAction): if proxyServer: logger.info(f'{loggerAction} uses proxy server {proxyServer}') - # Checked. split should not throw exceptions - proxyHost, proxyPort = proxyServer.split(':') + # Checked. Should not throw exceptions + proxyHost, proxyPort = parseHostPort(proxyServer) # Checked. int(proxyPort) should not throw exceptions manager.setProxy(