diff --git a/core/scripts/warp/uninstall.py b/core/scripts/warp/uninstall.py index 4c92184..ae388fc 100644 --- a/core/scripts/warp/uninstall.py +++ b/core/scripts/warp/uninstall.py @@ -22,11 +22,15 @@ def systemctl_active(service: str) -> bool: def load_config(path: Path): - if path.exists(): + if not path.exists(): + print(f"❌ Config file not found: {path}") + return None + try: with path.open("r", encoding="utf-8") as f: return json.load(f) - print(f"❌ Config file not found: {path}") - return None + except json.JSONDecodeError: + print(f"❌ Could not decode JSON from config file: {path}") + return None def save_config(config: dict, path: Path): @@ -36,55 +40,62 @@ def save_config(config: dict, path: Path): def reset_acl_inline(config: dict): - default = [ - "reject(geosite:ir)", "reject(geoip:ir)", - "reject(geosite:category-ads-all)", "reject(geoip:private)", - "reject(geosite:google@ads)" - ] - updated = [] - for item in config.get("acl", {}).get("inline", []): - if item in [ - "warps(all)", "warps(geoip:google)", "warps(geosite:google)", - "warps(geosite:netflix)", "warps(geosite:spotify)", - "warps(geosite:openai)", "warps(geoip:openai)" - ]: - updated.append("direct") - elif item == "warps(geosite:ir)": - updated.append("reject(geosite:ir)") - elif item == "warps(geoip:ir)": - updated.append("reject(geoip:ir)") - else: - updated.append(item) + """ + Dynamically cleans up ACL rules after WARP uninstall. + - Removes popular site and 'all traffic' rules. + - Converts any domestic 'warps' rules back to 'reject'. + """ + acl_inline = config.get("acl", {}).get("inline", []) + if not acl_inline: + return config - final_inline = default + [i for i in updated if i not in default and i != "direct"] - config["acl"]["inline"] = final_inline + new_rules = [] + + rules_to_remove = { + "warps(all)", + "warps(geoip:google)", "warps(geosite:google)", + "warps(geosite:netflix)", "warps(geosite:spotify)", + "warps(geosite:openai)", "warps(geoip:openai)" + } + + for rule in acl_inline: + if rule in rules_to_remove: + continue + + if rule.startswith("warps("): + new_rules.append(rule.replace("warps(", "reject(", 1)) + else: + new_rules.append(rule) + + config["acl"]["inline"] = new_rules + print("🔧 ACL rules reset from WARP-specific settings.") return config def remove_warp_outbound(config: dict): config["outbounds"] = [ o for o in config.get("outbounds", []) - if not ( - o.get("name") == "warps" and - o.get("type") == "direct" and - o.get("direct", {}).get("mode") == 4 and - o.get("direct", {}).get("bindDevice") == "wgcf" - ) + if not (o.get("name") == "warps") ] return config -def remove_porn_blocking(config: dict): +def remove_adult_content_blocking_rule(config: dict): + """ + Removes the adult content blocking rule ('reject(geosite:nsfw)') + as it's coupled with the DNS reset. + """ inline = config.get("acl", {}).get("inline", []) - if "reject(geosite:category-porn)" in inline: - config["acl"]["inline"] = [i for i in inline if i != "reject(geosite:category-porn)"] - print("🔒 Adult content blocking removed.") + rule_to_remove = "reject(geosite:nsfw)" + if rule_to_remove in inline: + config["acl"]["inline"] = [i for i in inline if i != rule_to_remove] + print("🔒 Adult content blocking rule removed.") return config def set_dns(config: dict): config.setdefault("resolver", {}).setdefault("tls", {})["addr"] = "1.1.1.1:853" - print("🔧 DNS resolver changed to 1.1.1.1:853.") + print("🔧 DNS resolver reset to 1.1.1.1.") return config @@ -101,7 +112,7 @@ def main(): if config: config = reset_acl_inline(config) config = remove_warp_outbound(config) - config = remove_porn_blocking(config) + config = remove_adult_content_blocking_rule(config) config = set_dns(config) save_config(config, TEMP_CONFIG) restart_hysteria()