feat: Modify WARP status script to output JSON
This commit is contained in:
@ -10,42 +10,30 @@ if str(core_scripts_dir) not in sys.path:
|
|||||||
|
|
||||||
from paths import *
|
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():
|
def check_warp_configuration():
|
||||||
|
status_data = {}
|
||||||
|
|
||||||
if not Path(CONFIG_FILE).exists():
|
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
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
with open(CONFIG_FILE, "r") as f:
|
with open(CONFIG_FILE, "r") as f:
|
||||||
config = json.load(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
|
||||||
|
|
||||||
|
|
||||||
acl_inline = config.get("acl", {}).get("inline", [])
|
acl_inline = config.get("acl", {}).get("inline", [])
|
||||||
|
|
||||||
def contains_warp(rule_prefixes):
|
def contains_warp(rule_prefixes):
|
||||||
return any(rule.startswith(prefix) for rule in acl_inline for prefix in rule_prefixes)
|
return any(rule.startswith(prefix) for rule in acl_inline for prefix in rule_prefixes)
|
||||||
|
|
||||||
print("--------------------------------")
|
status_data["all_traffic_via_warp"] = contains_warp(["warps(all)"])
|
||||||
print(f"{colors['purple']}Current WARP Configuration:{colors['end']}")
|
status_data["popular_sites_via_warp"] = contains_warp([
|
||||||
|
|
||||||
echo_status(
|
|
||||||
"All traffic",
|
|
||||||
contains_warp(["warps(all)"])
|
|
||||||
)
|
|
||||||
|
|
||||||
echo_status(
|
|
||||||
"Popular sites (Google, Netflix, etc.)",
|
|
||||||
contains_warp([
|
|
||||||
"warps(geosite:google)",
|
"warps(geosite:google)",
|
||||||
"warps(geoip:google)",
|
"warps(geoip:google)",
|
||||||
"warps(geosite:netflix)",
|
"warps(geosite:netflix)",
|
||||||
@ -53,22 +41,13 @@ def check_warp_configuration():
|
|||||||
"warps(geosite:openai)",
|
"warps(geosite:openai)",
|
||||||
"warps(geoip:openai)"
|
"warps(geoip:openai)"
|
||||||
])
|
])
|
||||||
)
|
status_data["domestic_sites_via_warp"] = contains_warp([
|
||||||
|
|
||||||
echo_status(
|
|
||||||
"Domestic sites (geosite:ir, geoip:ir)",
|
|
||||||
contains_warp([
|
|
||||||
"warps(geosite:ir)",
|
"warps(geosite:ir)",
|
||||||
"warps(geoip:ir)"
|
"warps(geoip:ir)"
|
||||||
])
|
])
|
||||||
)
|
status_data["block_adult_content"] = "reject(geosite:nsfw)" in acl_inline
|
||||||
|
|
||||||
echo_status(
|
print(json.dumps(status_data, indent=4))
|
||||||
"Block adult content",
|
|
||||||
"reject(geosite:nsfw)" in acl_inline
|
|
||||||
)
|
|
||||||
|
|
||||||
print("--------------------------------")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
check_warp_configuration()
|
check_warp_configuration()
|
||||||
Reference in New Issue
Block a user