feat: full edit menu (5 fields), delete [b] back, fix status display

This commit is contained in:
admin 2026-08-04 07:53:26 +00:00
parent 9c6ddd2da1
commit 678fa83f31

View file

@ -134,13 +134,12 @@ def remove_container(name):
print(f"{name} removed") print(f"{name} removed")
def container_status(): def container_status():
r = run("docker ps --filter 'name=wallarm-' --format '{{.Names}}\t{{.Status}}\t{{.Ports}}'") r = run("docker ps --filter 'name=wallarm-' --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' 2>/dev/null")
if not r.stdout.strip(): if not r.stdout.strip():
print("No containers running.") print("No containers running.")
return return
print("\n─── Containers ───") print("\n─── Containers ───")
for line in r.stdout.strip().split("\n"): print(r.stdout)
print(f" {line}")
# ─── Deploy All ─────────────────────────────────────────────────────── # ─── Deploy All ───────────────────────────────────────────────────────
@ -322,22 +321,54 @@ def edit_nodes():
idx = int(c) - 1 idx = int(c) - 1
if idx < 0 or idx >= len(s): return if idx < 0 or idx >= len(s): return
n = s[idx] n = s[idx]
print(f"\nEditing {n['name']}. Enter to keep current:")
port = input(f"Port [{n.get('port','')}]: ").strip() cfg = load_config()
upstream = input(f"Upstream [{n.get('upstream_ip','')}:{n.get('upstream_port','')}]: ").strip() nc = cfg.get(n['name'], {})
if port: n['port'] = int(port)
if ':' in upstream: while True:
ip, p = upstream.split(':') print(f"\n─── Editing: {n['name']} ───")
n['upstream_ip'] = ip; n['upstream_port'] = int(p) print(f" [1] Token: {'*'*8}")
save_state({"nodes": s}) print(f" [2] Cloud: {nc.get('cloud','EU')}")
print(f"✅ Updated. Restart to apply.") print(f" [3] Port: {n.get('port','')}")
print(f" [4] Upstream: {nc.get('upstream_ip','')}:{nc.get('upstream_port','')}")
print(f" [5] Mode: {nc.get('mode','monitoring')}")
print(f" [s] Save & restart")
print(f" [b] Back")
c = input("\nEdit field: ").strip()
if c == '1': nc['token'] = input("New token: ").strip() or nc.get('token','')
elif c == '2':
print(" [1] EU [2] US")
r = input("Cloud: ").strip()
nc['cloud'] = "US" if r == "2" else "EU"
elif c == '3': nc['port'] = input("Port: ").strip() or nc.get('port','')
elif c == '4':
up = input("Upstream (ip:port): ").strip()
if ':' in up:
ip, p = up.split(':')
nc['upstream_ip'] = ip; nc['upstream_port'] = p
elif c == '5':
print(" [1] monitoring [2] safe_blocking [3] block [4] off")
m = input("Mode: ").strip()
nc['mode'] = {"1":"monitoring","2":"safe_blocking","3":"block","4":"off"}.get(m, nc.get('mode','monitoring'))
elif c.lower() == 's':
with open(CONF, "w") as f: json.dump(cfg, f, indent=2)
deploy_container(n['name'], nc['token'], nc.get('cloud','EU'),
str(nc.get('port','')), nc.get('upstream_ip',''),
str(nc.get('upstream_port','')), "",
nc.get('mode','monitoring'))
print(f"{n['name']} updated & restarted.")
break
elif c.lower() == 'b': break
def remove_menu(): def remove_menu():
s = load_state().get("nodes", []) s = load_state().get("nodes", [])
if not s: print("No nodes."); return if not s: print("No nodes."); return
print("\n─── Delete Node ───") print("\n─── Delete Node ───")
for i, n in enumerate(s): for i, n in enumerate(s):
print(f" [{i+1}] {n['name']} (port {n.get('port','')})") print(f" [{i+1}] {n['name']} (port {n.get('port','')})")
print(" [b] Back")
c = input("\nSelect: ").strip() c = input("\nSelect: ").strip()
if c.lower() == 'b': return
if not c.isdigit(): return if not c.isdigit(): return
idx = int(c) - 1 idx = int(c) - 1
if 0 <= idx < len(s): if 0 <= idx < len(s):