fix(normalsub): robustly parse URIs with spaces in node names
fix(singbox): correct password generation for various URI auth formats
This commit is contained in:
@ -255,8 +255,7 @@ class HysteriaCLI:
|
|||||||
output = self._run_command(['show-user-uri', '-u', username, '-a'])
|
output = self._run_command(['show-user-uri', '-u', username, '-a'])
|
||||||
if not output:
|
if not output:
|
||||||
return []
|
return []
|
||||||
# Find all hy2:// links in the output
|
return re.findall(r'hy2://.*', output)
|
||||||
return re.findall(r'(hy2://[^\s]+)', output)
|
|
||||||
|
|
||||||
def get_all_labeled_uris(self, username: str) -> List[Dict[str, str]]:
|
def get_all_labeled_uris(self, username: str) -> List[Dict[str, str]]:
|
||||||
"""Fetches all URIs and their labels."""
|
"""Fetches all URIs and their labels."""
|
||||||
@ -264,8 +263,7 @@ class HysteriaCLI:
|
|||||||
if not output:
|
if not output:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# This regex captures the label (e.g., "IPv4", "Node: DE (IPv6)") and the URI
|
matches = re.findall(r"^(.*?):\s*(hy2://.*)$", output, re.MULTILINE)
|
||||||
matches = re.findall(r"^(.*?):\s*(hy2://[^\s]+)", output, re.MULTILINE)
|
|
||||||
return [{'label': label.strip(), 'uri': uri} for label, uri in matches]
|
return [{'label': label.strip(), 'uri': uri} for label, uri in matches]
|
||||||
|
|
||||||
|
|
||||||
@ -320,15 +318,24 @@ class SingboxConfigGenerator:
|
|||||||
if not uri:
|
if not uri:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# A simplified parser since we already have the full URI
|
|
||||||
try:
|
try:
|
||||||
parsed_url = urlparse(uri)
|
parsed_url = urlparse(uri)
|
||||||
server = parsed_url.hostname
|
server = parsed_url.hostname
|
||||||
server_port = parsed_url.port
|
server_port = parsed_url.port
|
||||||
password = parsed_url.password
|
auth_password = parsed_url.password
|
||||||
full_user = unquote(parsed_url.username)
|
auth_user = unquote(parsed_url.username or '')
|
||||||
obfs_password = parse_qs(parsed_url.query).get('obfs-password', [''])[0]
|
obfs_password = parse_qs(parsed_url.query).get('obfs-password', [''])[0]
|
||||||
except Exception:
|
|
||||||
|
if auth_password:
|
||||||
|
if auth_user:
|
||||||
|
final_password = f"{auth_user}:{auth_password}"
|
||||||
|
else:
|
||||||
|
final_password = auth_password
|
||||||
|
else:
|
||||||
|
final_password = auth_user
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error during Singbox config generation from URI: {e}, URI: {uri}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -340,7 +347,7 @@ class SingboxConfigGenerator:
|
|||||||
"type": "salamander",
|
"type": "salamander",
|
||||||
"password": obfs_password
|
"password": obfs_password
|
||||||
},
|
},
|
||||||
"password": f"{full_user}:{password}",
|
"password": final_password,
|
||||||
"tls": {
|
"tls": {
|
||||||
"enabled": True,
|
"enabled": True,
|
||||||
"server_name": fragment if fragment else self.default_sni,
|
"server_name": fragment if fragment else self.default_sni,
|
||||||
@ -354,7 +361,6 @@ class SingboxConfigGenerator:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
combined_config = self.get_template()
|
combined_config = self.get_template()
|
||||||
# Clear any placeholder hysteria2 outbounds
|
|
||||||
combined_config['outbounds'] = [out for out in combined_config['outbounds'] if out.get('type') != 'hysteria2']
|
combined_config['outbounds'] = [out for out in combined_config['outbounds'] if out.get('type') != 'hysteria2']
|
||||||
|
|
||||||
hysteria_outbounds = []
|
hysteria_outbounds = []
|
||||||
@ -368,7 +374,6 @@ class SingboxConfigGenerator:
|
|||||||
|
|
||||||
all_tags = [out['tag'] for out in hysteria_outbounds]
|
all_tags = [out['tag'] for out in hysteria_outbounds]
|
||||||
|
|
||||||
# Update 'select' and 'auto' groups
|
|
||||||
for outbound in combined_config['outbounds']:
|
for outbound in combined_config['outbounds']:
|
||||||
if outbound.get('tag') == 'select':
|
if outbound.get('tag') == 'select':
|
||||||
outbound['outbounds'] = ["auto"] + all_tags
|
outbound['outbounds'] = ["auto"] + all_tags
|
||||||
|
|||||||
Reference in New Issue
Block a user