Refactor: Implement warp status in Python
This commit is contained in:
@ -46,7 +46,7 @@ class Command(Enum):
|
|||||||
INSTALL_WARP = os.path.join(SCRIPT_DIR, 'warp', 'install.py')
|
INSTALL_WARP = os.path.join(SCRIPT_DIR, 'warp', 'install.py')
|
||||||
UNINSTALL_WARP = os.path.join(SCRIPT_DIR, 'warp', 'uninstall.py')
|
UNINSTALL_WARP = os.path.join(SCRIPT_DIR, 'warp', 'uninstall.py')
|
||||||
CONFIGURE_WARP = os.path.join(SCRIPT_DIR, 'warp', 'configure.sh')
|
CONFIGURE_WARP = os.path.join(SCRIPT_DIR, 'warp', 'configure.sh')
|
||||||
STATUS_WARP = os.path.join(SCRIPT_DIR, 'warp', 'status.sh')
|
STATUS_WARP = os.path.join(SCRIPT_DIR, 'warp', 'status.py')
|
||||||
SERVICES_STATUS = os.path.join(SCRIPT_DIR, 'services_status.sh')
|
SERVICES_STATUS = os.path.join(SCRIPT_DIR, 'services_status.sh')
|
||||||
VERSION = os.path.join(SCRIPT_DIR, 'hysteria2', 'version.py')
|
VERSION = os.path.join(SCRIPT_DIR, 'hysteria2', 'version.py')
|
||||||
LIMIT_SCRIPT = os.path.join(SCRIPT_DIR, 'hysteria2', 'limit.sh')
|
LIMIT_SCRIPT = os.path.join(SCRIPT_DIR, 'hysteria2', 'limit.sh')
|
||||||
@ -471,7 +471,7 @@ def configure_warp(all: bool, popular_sites: bool, domestic_sites: bool, block_a
|
|||||||
|
|
||||||
def warp_status() -> str | None:
|
def warp_status() -> str | None:
|
||||||
'''Checks the status of WARP.'''
|
'''Checks the status of WARP.'''
|
||||||
return run_cmd(['bash', Command.STATUS_WARP.value])
|
return run_cmd(['python3', Command.STATUS_WARP.value])
|
||||||
|
|
||||||
|
|
||||||
def start_telegram_bot(token: str, adminid: str):
|
def start_telegram_bot(token: str, adminid: str):
|
||||||
|
|||||||
74
core/scripts/warp/status.py
Normal file
74
core/scripts/warp/status.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
|
|
||||||
|
core_scripts_dir = Path(__file__).resolve().parents[1]
|
||||||
|
if str(core_scripts_dir) not in sys.path:
|
||||||
|
sys.path.append(str(core_scripts_dir))
|
||||||
|
|
||||||
|
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():
|
||||||
|
if not Path(CONFIG_FILE).exists():
|
||||||
|
print(f"{colors['red']}Error: Config file not found at {CONFIG_FILE}{colors['end']}")
|
||||||
|
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']}")
|
||||||
|
|
||||||
|
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("--------------------------------")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
check_warp_configuration()
|
||||||
@ -1,34 +0,0 @@
|
|||||||
source /etc/hysteria/core/scripts/utils.sh
|
|
||||||
source /etc/hysteria/core/scripts/path.sh
|
|
||||||
|
|
||||||
check_warp_configuration() {
|
|
||||||
echo "--------------------------------"
|
|
||||||
echo -e "${LPurple}Current WARP Configuration: ${NC}"
|
|
||||||
|
|
||||||
if jq -e '.acl.inline[]? | select(test("warps\\(all\\)"))' "$CONFIG_FILE" > /dev/null; then
|
|
||||||
echo -e "${cyan}All traffic:${NC} ${green}Active${NC}"
|
|
||||||
else
|
|
||||||
echo -e "${cyan}All traffic:${NC} ${red}Inactive${NC}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if jq -e '.acl.inline[]? | select(test("warps\\(geosite:google\\)")) or select(test("warps\\(geoip:google\\)")) or select(test("warps\\(geosite:netflix\\)")) or select(test("warps\\(geosite:spotify\\)")) or select(test("warps\\(geosite:openai\\)")) or select(test("warps\\(geoip:openai\\)"))' "$CONFIG_FILE" > /dev/null; then
|
|
||||||
echo -e "${cyan}Popular sites (Google, Netflix, etc.):${NC} ${green}Active${NC}"
|
|
||||||
else
|
|
||||||
echo -e "${cyan}Popular sites (Google, Netflix, etc.):${NC} ${red}Inactive${NC}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if jq -e '.acl.inline[]? | select(test("warps\\(geosite:ir\\)")) or select(test("warps\\(geoip:ir\\)"))' "$CONFIG_FILE" > /dev/null; then
|
|
||||||
echo -e "${cyan}Domestic sites (geosite:ir, geoip:ir):${NC} ${green}Active${NC}"
|
|
||||||
else
|
|
||||||
echo -e "${cyan}Domestic sites (geosite:ir, geoip:ir):${NC} ${red}Inactive${NC}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if jq -e '.acl.inline[]? | select(test("reject\\(geosite:nsfw\\)"))' "$CONFIG_FILE" > /dev/null; then
|
|
||||||
echo -e "${cyan}Block adult content:${NC} ${green}Active${NC}"
|
|
||||||
else
|
|
||||||
echo -e "${cyan}Block adult content:${NC} ${red}Inactive${NC}"
|
|
||||||
fi
|
|
||||||
echo "--------------------------------"
|
|
||||||
}
|
|
||||||
define_colors
|
|
||||||
check_warp_configuration
|
|
||||||
Reference in New Issue
Block a user