Skip to content
This repository was archived by the owner on Jul 8, 2026. It is now read-only.

Commit a8c76ab

Browse files
committed
fix(uninstall): improve config loading and error handling; reset ACL rules after WARP uninstall
1 parent 75db42d commit a8c76ab

1 file changed

Lines changed: 47 additions & 36 deletions

File tree

core/scripts/warp/uninstall.py

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ def systemctl_active(service: str) -> bool:
2222

2323

2424
def load_config(path: Path):
25-
if path.exists():
25+
if not path.exists():
26+
print(f"❌ Config file not found: {path}")
27+
return None
28+
try:
2629
with path.open("r", encoding="utf-8") as f:
2730
return json.load(f)
28-
print(f"❌ Config file not found: {path}")
29-
return None
31+
except json.JSONDecodeError:
32+
print(f"❌ Could not decode JSON from config file: {path}")
33+
return None
3034

3135

3236
def save_config(config: dict, path: Path):
@@ -36,55 +40,62 @@ def save_config(config: dict, path: Path):
3640

3741

3842
def reset_acl_inline(config: dict):
39-
default = [
40-
"reject(geosite:ir)", "reject(geoip:ir)",
41-
"reject(geosite:category-ads-all)", "reject(geoip:private)",
42-
"reject(geosite:google@ads)"
43-
]
44-
updated = []
45-
for item in config.get("acl", {}).get("inline", []):
46-
if item in [
47-
"warps(all)", "warps(geoip:google)", "warps(geosite:google)",
48-
"warps(geosite:netflix)", "warps(geosite:spotify)",
49-
"warps(geosite:openai)", "warps(geoip:openai)"
50-
]:
51-
updated.append("direct")
52-
elif item == "warps(geosite:ir)":
53-
updated.append("reject(geosite:ir)")
54-
elif item == "warps(geoip:ir)":
55-
updated.append("reject(geoip:ir)")
43+
"""
44+
Dynamically cleans up ACL rules after WARP uninstall.
45+
- Removes popular site and 'all traffic' rules.
46+
- Converts any domestic 'warps' rules back to 'reject'.
47+
"""
48+
acl_inline = config.get("acl", {}).get("inline", [])
49+
if not acl_inline:
50+
return config
51+
52+
new_rules = []
53+
54+
rules_to_remove = {
55+
"warps(all)",
56+
"warps(geoip:google)", "warps(geosite:google)",
57+
"warps(geosite:netflix)", "warps(geosite:spotify)",
58+
"warps(geosite:openai)", "warps(geoip:openai)"
59+
}
60+
61+
for rule in acl_inline:
62+
if rule in rules_to_remove:
63+
continue
64+
65+
if rule.startswith("warps("):
66+
new_rules.append(rule.replace("warps(", "reject(", 1))
5667
else:
57-
updated.append(item)
58-
59-
final_inline = default + [i for i in updated if i not in default and i != "direct"]
60-
config["acl"]["inline"] = final_inline
68+
new_rules.append(rule)
69+
70+
config["acl"]["inline"] = new_rules
71+
print("🔧 ACL rules reset from WARP-specific settings.")
6172
return config
6273

6374

6475
def remove_warp_outbound(config: dict):
6576
config["outbounds"] = [
6677
o for o in config.get("outbounds", [])
67-
if not (
68-
o.get("name") == "warps" and
69-
o.get("type") == "direct" and
70-
o.get("direct", {}).get("mode") == 4 and
71-
o.get("direct", {}).get("bindDevice") == "wgcf"
72-
)
78+
if not (o.get("name") == "warps")
7379
]
7480
return config
7581

7682

77-
def remove_porn_blocking(config: dict):
83+
def remove_adult_content_blocking_rule(config: dict):
84+
"""
85+
Removes the adult content blocking rule ('reject(geosite:nsfw)')
86+
as it's coupled with the DNS reset.
87+
"""
7888
inline = config.get("acl", {}).get("inline", [])
79-
if "reject(geosite:category-porn)" in inline:
80-
config["acl"]["inline"] = [i for i in inline if i != "reject(geosite:category-porn)"]
81-
print("🔒 Adult content blocking removed.")
89+
rule_to_remove = "reject(geosite:nsfw)"
90+
if rule_to_remove in inline:
91+
config["acl"]["inline"] = [i for i in inline if i != rule_to_remove]
92+
print("🔒 Adult content blocking rule removed.")
8293
return config
8394

8495

8596
def set_dns(config: dict):
8697
config.setdefault("resolver", {}).setdefault("tls", {})["addr"] = "1.1.1.1:853"
87-
print("🔧 DNS resolver changed to 1.1.1.1:853.")
98+
print("🔧 DNS resolver reset to 1.1.1.1.")
8899
return config
89100

90101

@@ -101,7 +112,7 @@ def main():
101112
if config:
102113
config = reset_acl_inline(config)
103114
config = remove_warp_outbound(config)
104-
config = remove_porn_blocking(config)
115+
config = remove_adult_content_blocking_rule(config)
105116
config = set_dns(config)
106117
save_config(config, TEMP_CONFIG)
107118
restart_hysteria()

0 commit comments

Comments
 (0)