feat: add/edit/remove individual nodes, create fw.conf interactively

This commit is contained in:
admin 2026-08-03 14:20:10 +00:00
parent 3037f5f8ef
commit 156c81f230

View file

@ -122,19 +122,94 @@ def main():
return deploy_all()
print(f"═══ Wallarm Docker Manager v{VERSION} ═══\n")
# Check for fw.conf
cfg = load_config()
if not cfg:
print("No fw.conf found. Create one? [Y/n]: ", end="")
if input().strip().lower() in ("", "y", "yes"):
create_config()
cfg = load_config()
else:
print("Create /opt/fw/app/fw.conf manually or use the menu to add nodes.")
while True:
print("\n─── Menu ───")
print(" [1] Deploy all [2] Status [3] Remove [q] Quit")
print(" [1] Deploy all")
print(" [2] Add a node")
print(" [3] Status")
print(" [4] Remove a node")
print(" [5] Edit a node")
print(" [q] Quit")
c = input("\nChoice: ").strip()
if c == "1": deploy_all()
elif c == "2": container_status()
elif c == "3":
print("\nContainers:")
for n in load_state().get("nodes", []):
print(f" [{n['name']}]")
name = input("Name to remove: ").strip()
if name: remove_container(name)
elif c == "2": add_node()
elif c == "3": container_status()
elif c == "4": remove_menu()
elif c == "5": edit_menu()
elif c.lower() == "q": break
def create_config():
print("\n─── Create Node Config ───")
name = input("Node name: ").strip()
if not name: return
token = input("Wallarm token: ").strip()
cloud = input("Cloud [EU]: ").strip() or "EU"
port = input("Port [8081]: ").strip() or "8081"
upstream_ip = input("Upstream IP [127.0.0.1]: ").strip() or "127.0.0.1"
upstream_port = input("Upstream port [80]: ").strip() or "80"
mode = input("Mode [monitoring]: ").strip() or "monitoring"
cfg = load_config()
cfg[name] = {"token": token, "cloud": cloud, "port": port,
"upstream_ip": upstream_ip, "upstream_port": upstream_port,
"labels": f"group={name}", "mode": mode}
os.makedirs(APP, exist_ok=True)
with open(CONF, "w") as f:
json.dump(cfg, f, indent=2)
print(f"{name} added to fw.conf")
def add_node():
create_config()
cfg = load_config()
if cfg:
# Deploy just the newly added node
for name in list(cfg.keys()):
if not any(n["name"] == name for n in load_state().get("nodes", [])):
deploy_container(name, cfg[name]["token"], cfg[name].get("cloud","EU"),
str(cfg[name].get("port","8081")), cfg[name].get("upstream_ip",""),
str(cfg[name].get("upstream_port","80")), "",
cfg[name].get("mode","monitoring"))
def remove_menu():
s = load_state().get("nodes", [])
if not s: print("No nodes deployed."); return
print("\n─── Remove Node ───")
for i, n in enumerate(s):
print(f" [{i+1}] {n['name']} (port {n.get('port','')})")
c = input("\nSelect number: ").strip()
if not c.isdigit() or int(c) < 1 or int(c) > len(s): return
remove_container(s[int(c)-1]["name"])
def edit_menu():
cfg = load_config()
if not cfg: print("No nodes in fw.conf"); return
print("\n─── Edit Node ───")
names = list(cfg.keys())
for i, name in enumerate(names):
nc = cfg[name]
print(f" [{i+1}] {name} (port {nc.get('port','')})")
c = input("\nSelect number: ").strip()
if not c.isdigit() or int(c) < 1 or int(c) > len(names): return
name = names[int(c)-1]
nc = cfg[name]
print(f"\nEditing {name}. Leave blank to keep current value:")
for key, prompt in [("port","Port"), ("upstream_ip","Upstream IP"),
("upstream_port","Upstream port"), ("mode","Mode")]:
v = input(f"{prompt} [{nc.get(key,'')}]: ").strip()
if v: nc[key] = v
with open(CONF, "w") as f: json.dump(cfg, f, indent=2)
print(f"{name} updated in fw.conf. Re-deploy to apply changes.")
if __name__ == "__main__":
main()