feat: Modify WARP status script to output JSON
This commit is contained in:
@ -10,65 +10,44 @@ if str(core_scripts_dir) not in sys.path:
|
||||
|
||||
from paths import *
|
||||
|
||||
colors = {
|
||||
"cyan": "\033[96m",
|
||||
"green": "\033[92m",
|
||||
"red": "\033[91m",
|
||||
"purple": "\033[95m",
|
||||
"end": "\033[0m"
|
||||
}
|
||||
|
||||
def echo_status(label, is_active):
|
||||
status = f"{colors['green']}Active{colors['end']}" if is_active else f"{colors['red']}Inactive{colors['end']}"
|
||||
print(f"{colors['cyan']}{label}:{colors['end']} {status}")
|
||||
|
||||
def check_warp_configuration():
|
||||
status_data = {}
|
||||
|
||||
if not Path(CONFIG_FILE).exists():
|
||||
print(f"{colors['red']}Error: Config file not found at {CONFIG_FILE}{colors['end']}")
|
||||
status_data["error"] = f"Config file not found at {CONFIG_FILE}"
|
||||
print(json.dumps(status_data, indent=4))
|
||||
return
|
||||
|
||||
try:
|
||||
with open(CONFIG_FILE, "r") as f:
|
||||
config = json.load(f)
|
||||
except json.JSONDecodeError:
|
||||
status_data["error"] = f"Invalid JSON in config file: {CONFIG_FILE}"
|
||||
print(json.dumps(status_data, indent=4))
|
||||
return
|
||||
|
||||
with open(CONFIG_FILE, "r") as f:
|
||||
config = json.load(f)
|
||||
|
||||
acl_inline = config.get("acl", {}).get("inline", [])
|
||||
|
||||
def contains_warp(rule_prefixes):
|
||||
return any(rule.startswith(prefix) for rule in acl_inline for prefix in rule_prefixes)
|
||||
|
||||
print("--------------------------------")
|
||||
print(f"{colors['purple']}Current WARP Configuration:{colors['end']}")
|
||||
status_data["all_traffic_via_warp"] = contains_warp(["warps(all)"])
|
||||
status_data["popular_sites_via_warp"] = contains_warp([
|
||||
"warps(geosite:google)",
|
||||
"warps(geoip:google)",
|
||||
"warps(geosite:netflix)",
|
||||
"warps(geosite:spotify)",
|
||||
"warps(geosite:openai)",
|
||||
"warps(geoip:openai)"
|
||||
])
|
||||
status_data["domestic_sites_via_warp"] = contains_warp([
|
||||
"warps(geosite:ir)",
|
||||
"warps(geoip:ir)"
|
||||
])
|
||||
status_data["block_adult_content"] = "reject(geosite:nsfw)" in acl_inline
|
||||
|
||||
echo_status(
|
||||
"All traffic",
|
||||
contains_warp(["warps(all)"])
|
||||
)
|
||||
|
||||
echo_status(
|
||||
"Popular sites (Google, Netflix, etc.)",
|
||||
contains_warp([
|
||||
"warps(geosite:google)",
|
||||
"warps(geoip:google)",
|
||||
"warps(geosite:netflix)",
|
||||
"warps(geosite:spotify)",
|
||||
"warps(geosite:openai)",
|
||||
"warps(geoip:openai)"
|
||||
])
|
||||
)
|
||||
|
||||
echo_status(
|
||||
"Domestic sites (geosite:ir, geoip:ir)",
|
||||
contains_warp([
|
||||
"warps(geosite:ir)",
|
||||
"warps(geoip:ir)"
|
||||
])
|
||||
)
|
||||
|
||||
echo_status(
|
||||
"Block adult content",
|
||||
"reject(geosite:nsfw)" in acl_inline
|
||||
)
|
||||
|
||||
print("--------------------------------")
|
||||
print(json.dumps(status_data, indent=4))
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_warp_configuration()
|
||||
Reference in New Issue
Block a user