version 1.4.1: per-user WARP флаг, fallback-установка PyPI
- app.py: full_warp флаг в warp_rules, _rebuild_egress читает с диска, race condition fix - bot.py: full_warp поддержка в toggle_warp - templates/index.html: чекбокс «Весь трафик через WARP» с full_warp, не авто-включается - install-panel.sh: зеркала PyPI (aliyun), таймаут 120с на pip, fallback на apt --system-site-packages - install-bot.sh: зеркала и fallback для python-telegram-bot - README: версия 1.4, обновлён roadmap
This commit is contained in:
@@ -349,6 +349,43 @@ async def toggle_warp(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
status = "включён"
|
||||
pc["warp_users"] = list(warp_users)
|
||||
Path(PANEL_CONFIG).write_text(json.dumps(pc, indent=2))
|
||||
|
||||
# Перестроить egress
|
||||
cfg = load_mita_config()
|
||||
warp_users_after = set(pc.get("warp_users", []))
|
||||
if not warp_users_after:
|
||||
cfg.pop("egress", None)
|
||||
else:
|
||||
wp = {"name": "warp", "protocol": "SOCKS5_PROXY_PROTOCOL",
|
||||
"host": "127.0.0.1", "port": 40000}
|
||||
has_full = any(pc.get("warp_rules", {}).get(u, {}).get("full_warp") for u in warp_users_after)
|
||||
if has_full:
|
||||
cfg["egress"] = {
|
||||
"proxies": [wp],
|
||||
"rules": [{"ipRanges": ["*"], "domainNames": ["*"],
|
||||
"action": "PROXY", "proxyNames": ["warp"]}],
|
||||
}
|
||||
else:
|
||||
all_dom = set()
|
||||
all_ip = set()
|
||||
for uname in warp_users_after:
|
||||
r = pc.get("warp_rules", {}).get(uname, {})
|
||||
all_dom.update(d for d in r.get("domains", []) if d)
|
||||
all_ip.update(i for i in r.get("ips", []) if i)
|
||||
if all_dom or all_ip:
|
||||
wr = {"action": "PROXY", "proxyNames": ["warp"]}
|
||||
if all_dom: wr["domainNames"] = sorted(all_dom)
|
||||
if all_ip: wr["ipRanges"] = sorted(all_ip)
|
||||
cfg["egress"] = {
|
||||
"proxies": [wp],
|
||||
"rules": [wr, {"ipRanges": ["*"], "domainNames": ["*"], "action": "DIRECT"}],
|
||||
}
|
||||
else:
|
||||
cfg.pop("egress", None)
|
||||
Path(MITA_CONFIG).write_text(json.dumps(cfg, indent=2, ensure_ascii=False))
|
||||
subprocess.run(["mita", "apply", "config", MITA_CONFIG], capture_output=True)
|
||||
subprocess.run(["systemctl", "restart", "mita"], capture_output=True)
|
||||
|
||||
await query.edit_message_text(
|
||||
f"🔄 WARP для `{escape_md(name)}`: *{status}*",
|
||||
reply_markup=InlineKeyboardMarkup([
|
||||
|
||||
Reference in New Issue
Block a user