From 4d25c6b7d611941559e7fbaa2a6a850ec9274a38 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Mon, 22 Aug 2022 22:14:32 +0200 Subject: [PATCH] add network json editor written in ucode reformat example json to match its output Signed-off-by: Felix Fietkau --- examples/net0.json | 43 +++-- scripts/unet-cli | 414 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 445 insertions(+), 12 deletions(-) create mode 100755 scripts/unet-cli diff --git a/examples/net0.json b/examples/net0.json index 1b96987..3bd0a35 100644 --- a/examples/net0.json +++ b/examples/net0.json @@ -4,39 +4,58 @@ "peer-exchange-port": 3458, "keepalive": 10 }, - "hosts": { "master": { "key": "25sPrbtEtIiANFr00tC5MS2UMfXmHFj/AJyDi4wR8n4=", "endpoint": "192.168.1.3", - "subnet": [ "192.168.3.0/24" ], - "ipaddr": [ "192.168.3.1" ] + "subnet": [ + "192.168.3.0/24" + ], + "ipaddr": [ + "192.168.3.1" + ] }, "ap1": { "key": "mxQQxpwinlDxy0bp564b25il1oDiaf/a8jkaKQBcjw4=", - "groups": [ "ap" ], - "subnet": [ "192.168.4.0/24" ], - "ipaddr": [ "192.168.4.1" ], + "groups": [ + "ap" + ], + "subnet": [ + "192.168.4.0/24" + ], + "ipaddr": [ + "192.168.4.1" + ], "port": 3457 }, "ap2": { "key": "+hiP+1FZci9Hp44gWEPigbsMHMe6De7nnMbVDJFhDjU=", - "groups": [ "ap" ], - "subnet": [ "192.168.5.0/24" ], - "ipaddr": [ "192.168.5.1" ], + "groups": [ + "ap" + ], + "subnet": [ + "192.168.5.0/24" + ], + "ipaddr": [ + "192.168.5.1" + ], "port": 3457 } }, - "services": { "l2-tunnel": { "type": "vxlan", "config": { }, - "members": [ "master", "@ap" ] + "members": [ + "master", + "@ap" + ] }, "usteer": { - "members": [ "@ap" ] + "members": [ + "@ap" + ] } } } diff --git a/scripts/unet-cli b/scripts/unet-cli new file mode 100755 index 0000000..35dc233 --- /dev/null +++ b/scripts/unet-cli @@ -0,0 +1,414 @@ +#!/usr/bin/env ucode + +let fs = require("fs"); + +let script_dir = sourcepath(0, true); +if (fs.basename(script_dir) == "scripts") { + unet_tool = fs.dirname(script_dir) + "/unet-tool"; + if (!fs.access(unet_tool, "x")) { + warn("unet-tool missing\n"); + exit(1); + } +} else { + unet_tool = "unet-tool"; +} + +args = {}; + +defaults = { + port: 51830, + pex_port: 51831, + keepalive: 10, +}; + +function usage() { + warn("Usage: ",fs.basename(sourcepath())," [] [] [