mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 22:55:06 +03:00
Move yggdrasilctl responses to separate functions
This commit is contained in:
parent
b333c7d7f3
commit
fa65253e57
1 changed files with 261 additions and 217 deletions
|
@ -207,235 +207,29 @@ func run() int {
|
||||||
|
|
||||||
switch strings.ToLower(req["request"].(string)) {
|
switch strings.ToLower(req["request"].(string)) {
|
||||||
case "dot":
|
case "dot":
|
||||||
fmt.Println(res["dot"])
|
runDot(res)
|
||||||
case "list", "getpeers", "getswitchpeers", "getdht", "getsessions", "dhtping":
|
case "list", "getpeers", "getswitchpeers", "getdht", "getsessions", "dhtping":
|
||||||
maxWidths := make(map[string]int)
|
runVariousInfo(res, verbose)
|
||||||
var keyOrder []string
|
|
||||||
keysOrdered := false
|
|
||||||
|
|
||||||
for _, tlv := range res {
|
|
||||||
for slk, slv := range tlv.(map[string]interface{}) {
|
|
||||||
if !keysOrdered {
|
|
||||||
for k := range slv.(map[string]interface{}) {
|
|
||||||
if !*verbose {
|
|
||||||
if k == "box_pub_key" || k == "box_sig_key" || k == "nodeinfo" || k == "was_mtu_fixed" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
keyOrder = append(keyOrder, fmt.Sprint(k))
|
|
||||||
}
|
|
||||||
sort.Strings(keyOrder)
|
|
||||||
keysOrdered = true
|
|
||||||
}
|
|
||||||
for k, v := range slv.(map[string]interface{}) {
|
|
||||||
if len(fmt.Sprint(slk)) > maxWidths["key"] {
|
|
||||||
maxWidths["key"] = len(fmt.Sprint(slk))
|
|
||||||
}
|
|
||||||
if len(fmt.Sprint(v)) > maxWidths[k] {
|
|
||||||
maxWidths[k] = len(fmt.Sprint(v))
|
|
||||||
if maxWidths[k] < len(k) {
|
|
||||||
maxWidths[k] = len(k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(keyOrder) > 0 {
|
|
||||||
fmt.Printf("%-"+fmt.Sprint(maxWidths["key"])+"s ", "")
|
|
||||||
for _, v := range keyOrder {
|
|
||||||
fmt.Printf("%-"+fmt.Sprint(maxWidths[v])+"s ", v)
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
|
|
||||||
for slk, slv := range tlv.(map[string]interface{}) {
|
|
||||||
fmt.Printf("%-"+fmt.Sprint(maxWidths["key"])+"s ", slk)
|
|
||||||
for _, k := range keyOrder {
|
|
||||||
preformatted := slv.(map[string]interface{})[k]
|
|
||||||
var formatted string
|
|
||||||
switch k {
|
|
||||||
case "bytes_sent", "bytes_recvd":
|
|
||||||
formatted = fmt.Sprintf("%d", uint(preformatted.(float64)))
|
|
||||||
case "uptime", "last_seen":
|
|
||||||
seconds := uint(preformatted.(float64)) % 60
|
|
||||||
minutes := uint(preformatted.(float64)/60) % 60
|
|
||||||
hours := uint(preformatted.(float64) / 60 / 60)
|
|
||||||
formatted = fmt.Sprintf("%02d:%02d:%02d", hours, minutes, seconds)
|
|
||||||
default:
|
|
||||||
formatted = fmt.Sprint(preformatted)
|
|
||||||
}
|
|
||||||
fmt.Printf("%-"+fmt.Sprint(maxWidths[k])+"s ", formatted)
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "gettuntap", "settuntap":
|
case "gettuntap", "settuntap":
|
||||||
for k, v := range res {
|
runGetAndSetTunTap(res)
|
||||||
fmt.Println("Interface name:", k)
|
|
||||||
if mtu, ok := v.(map[string]interface{})["mtu"].(float64); ok {
|
|
||||||
fmt.Println("Interface MTU:", mtu)
|
|
||||||
}
|
|
||||||
if tap_mode, ok := v.(map[string]interface{})["tap_mode"].(bool); ok {
|
|
||||||
fmt.Println("TAP mode:", tap_mode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "getself":
|
case "getself":
|
||||||
for k, v := range res["self"].(map[string]interface{}) {
|
runGetSelf(res, verbose)
|
||||||
if buildname, ok := v.(map[string]interface{})["build_name"].(string); ok && buildname != "unknown" {
|
|
||||||
fmt.Println("Build name:", buildname)
|
|
||||||
}
|
|
||||||
if buildversion, ok := v.(map[string]interface{})["build_version"].(string); ok && buildversion != "unknown" {
|
|
||||||
fmt.Println("Build version:", buildversion)
|
|
||||||
}
|
|
||||||
fmt.Println("IPv6 address:", k)
|
|
||||||
if subnet, ok := v.(map[string]interface{})["subnet"].(string); ok {
|
|
||||||
fmt.Println("IPv6 subnet:", subnet)
|
|
||||||
}
|
|
||||||
if boxSigKey, ok := v.(map[string]interface{})["key"].(string); ok {
|
|
||||||
fmt.Println("Public key:", boxSigKey)
|
|
||||||
}
|
|
||||||
if coords, ok := v.(map[string]interface{})["coords"].(string); ok {
|
|
||||||
fmt.Println("Coords:", coords)
|
|
||||||
}
|
|
||||||
if *verbose {
|
|
||||||
if nodeID, ok := v.(map[string]interface{})["node_id"].(string); ok {
|
|
||||||
fmt.Println("Node ID:", nodeID)
|
|
||||||
}
|
|
||||||
if boxPubKey, ok := v.(map[string]interface{})["box_pub_key"].(string); ok {
|
|
||||||
fmt.Println("Public encryption key:", boxPubKey)
|
|
||||||
}
|
|
||||||
if boxSigKey, ok := v.(map[string]interface{})["box_sig_key"].(string); ok {
|
|
||||||
fmt.Println("Public signing key:", boxSigKey)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "getswitchqueues":
|
case "getswitchqueues":
|
||||||
maximumqueuesize := float64(4194304)
|
runGetSwitchQueues(res)
|
||||||
portqueues := make(map[float64]float64)
|
|
||||||
portqueuesize := make(map[float64]float64)
|
|
||||||
portqueuepackets := make(map[float64]float64)
|
|
||||||
v := res["switchqueues"].(map[string]interface{})
|
|
||||||
if queuecount, ok := v["queues_count"].(float64); ok {
|
|
||||||
fmt.Printf("Active queue count: %d queues\n", uint(queuecount))
|
|
||||||
}
|
|
||||||
if queuesize, ok := v["queues_size"].(float64); ok {
|
|
||||||
fmt.Printf("Active queue size: %d bytes\n", uint(queuesize))
|
|
||||||
}
|
|
||||||
if highestqueuecount, ok := v["highest_queues_count"].(float64); ok {
|
|
||||||
fmt.Printf("Highest queue count: %d queues\n", uint(highestqueuecount))
|
|
||||||
}
|
|
||||||
if highestqueuesize, ok := v["highest_queues_size"].(float64); ok {
|
|
||||||
fmt.Printf("Highest queue size: %d bytes\n", uint(highestqueuesize))
|
|
||||||
}
|
|
||||||
if m, ok := v["maximum_queues_size"].(float64); ok {
|
|
||||||
maximumqueuesize = m
|
|
||||||
fmt.Printf("Maximum queue size: %d bytes\n", uint(maximumqueuesize))
|
|
||||||
}
|
|
||||||
if queues, ok := v["queues"].([]interface{}); ok {
|
|
||||||
if len(queues) != 0 {
|
|
||||||
fmt.Println("Active queues:")
|
|
||||||
for _, v := range queues {
|
|
||||||
queueport := v.(map[string]interface{})["queue_port"].(float64)
|
|
||||||
queuesize := v.(map[string]interface{})["queue_size"].(float64)
|
|
||||||
queuepackets := v.(map[string]interface{})["queue_packets"].(float64)
|
|
||||||
queueid := v.(map[string]interface{})["queue_id"].(string)
|
|
||||||
portqueues[queueport]++
|
|
||||||
portqueuesize[queueport] += queuesize
|
|
||||||
portqueuepackets[queueport] += queuepackets
|
|
||||||
queuesizepercent := (100 / maximumqueuesize) * queuesize
|
|
||||||
fmt.Printf("- Switch port %d, Stream ID: %v, size: %d bytes (%d%% full), %d packets\n",
|
|
||||||
uint(queueport), []byte(queueid), uint(queuesize),
|
|
||||||
uint(queuesizepercent), uint(queuepackets))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(portqueuesize) > 0 && len(portqueuepackets) > 0 {
|
|
||||||
fmt.Println("Aggregated statistics by switchport:")
|
|
||||||
for k, v := range portqueuesize {
|
|
||||||
queuesizepercent := (100 / (portqueues[k] * maximumqueuesize)) * v
|
|
||||||
fmt.Printf("- Switch port %d, size: %d bytes (%d%% full), %d packets\n",
|
|
||||||
uint(k), uint(v), uint(queuesizepercent), uint(portqueuepackets[k]))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "addpeer", "removepeer", "addallowedencryptionpublickey", "removeallowedencryptionpublickey", "addsourcesubnet", "addroute", "removesourcesubnet", "removeroute":
|
case "addpeer", "removepeer", "addallowedencryptionpublickey", "removeallowedencryptionpublickey", "addsourcesubnet", "addroute", "removesourcesubnet", "removeroute":
|
||||||
if _, ok := res["added"]; ok {
|
runAddsAndRemoves(res)
|
||||||
for _, v := range res["added"].([]interface{}) {
|
|
||||||
fmt.Println("Added:", fmt.Sprint(v))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if _, ok := res["not_added"]; ok {
|
|
||||||
for _, v := range res["not_added"].([]interface{}) {
|
|
||||||
fmt.Println("Not added:", fmt.Sprint(v))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if _, ok := res["removed"]; ok {
|
|
||||||
for _, v := range res["removed"].([]interface{}) {
|
|
||||||
fmt.Println("Removed:", fmt.Sprint(v))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if _, ok := res["not_removed"]; ok {
|
|
||||||
for _, v := range res["not_removed"].([]interface{}) {
|
|
||||||
fmt.Println("Not removed:", fmt.Sprint(v))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "getallowedencryptionpublickeys":
|
case "getallowedencryptionpublickeys":
|
||||||
if _, ok := res["allowed_box_pubs"]; !ok {
|
runGetAllowedEncryptionPublicKeys(res)
|
||||||
fmt.Println("All connections are allowed")
|
|
||||||
} else if res["allowed_box_pubs"] == nil {
|
|
||||||
fmt.Println("All connections are allowed")
|
|
||||||
} else {
|
|
||||||
fmt.Println("Connections are allowed only from the following public box keys:")
|
|
||||||
for _, v := range res["allowed_box_pubs"].([]interface{}) {
|
|
||||||
fmt.Println("-", v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "getmulticastinterfaces":
|
case "getmulticastinterfaces":
|
||||||
if _, ok := res["multicast_interfaces"]; !ok {
|
runGetMulticastInterfaces(res)
|
||||||
fmt.Println("No multicast interfaces found")
|
|
||||||
} else if res["multicast_interfaces"] == nil {
|
|
||||||
fmt.Println("No multicast interfaces found")
|
|
||||||
} else {
|
|
||||||
fmt.Println("Multicast peer discovery is active on:")
|
|
||||||
for _, v := range res["multicast_interfaces"].([]interface{}) {
|
|
||||||
fmt.Println("-", v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "getsourcesubnets":
|
case "getsourcesubnets":
|
||||||
if _, ok := res["source_subnets"]; !ok {
|
runGetSourceSubnets(res)
|
||||||
fmt.Println("No source subnets found")
|
|
||||||
} else if res["source_subnets"] == nil {
|
|
||||||
fmt.Println("No source subnets found")
|
|
||||||
} else {
|
|
||||||
fmt.Println("Source subnets:")
|
|
||||||
for _, v := range res["source_subnets"].([]interface{}) {
|
|
||||||
fmt.Println("-", v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "getroutes":
|
case "getroutes":
|
||||||
if routes, ok := res["routes"].(map[string]interface{}); !ok {
|
runGetRoutes(res)
|
||||||
fmt.Println("No routes found")
|
|
||||||
} else {
|
|
||||||
if res["routes"] == nil || len(routes) == 0 {
|
|
||||||
fmt.Println("No routes found")
|
|
||||||
} else {
|
|
||||||
fmt.Println("Routes:")
|
|
||||||
for k, v := range routes {
|
|
||||||
if pv, ok := v.(string); ok {
|
|
||||||
fmt.Println("-", k, " via ", pv)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "settunnelrouting":
|
case "settunnelrouting":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "gettunnelrouting":
|
case "gettunnelrouting":
|
||||||
if enabled, ok := res["enabled"].(bool); !ok {
|
runGetTunnelRouting(res)
|
||||||
fmt.Println("Tunnel routing is disabled")
|
|
||||||
} else if !enabled {
|
|
||||||
fmt.Println("Tunnel routing is disabled")
|
|
||||||
} else {
|
|
||||||
fmt.Println("Tunnel routing is enabled")
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
if json, err := json.MarshalIndent(recv["response"], "", " "); err == nil {
|
if json, err := json.MarshalIndent(recv["response"], "", " "); err == nil {
|
||||||
fmt.Println(string(json))
|
fmt.Println(string(json))
|
||||||
|
@ -450,3 +244,253 @@ func run() int {
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runDot(res map[string]interface{}) {
|
||||||
|
fmt.Println(res["dot"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func runVariousInfo(res map[string]interface{}, verbose *bool) {
|
||||||
|
maxWidths := make(map[string]int)
|
||||||
|
var keyOrder []string
|
||||||
|
keysOrdered := false
|
||||||
|
|
||||||
|
for _, tlv := range res {
|
||||||
|
for slk, slv := range tlv.(map[string]interface{}) {
|
||||||
|
if !keysOrdered {
|
||||||
|
for k := range slv.(map[string]interface{}) {
|
||||||
|
if !*verbose {
|
||||||
|
if k == "box_pub_key" || k == "box_sig_key" || k == "nodeinfo" || k == "was_mtu_fixed" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
keyOrder = append(keyOrder, fmt.Sprint(k))
|
||||||
|
}
|
||||||
|
sort.Strings(keyOrder)
|
||||||
|
keysOrdered = true
|
||||||
|
}
|
||||||
|
for k, v := range slv.(map[string]interface{}) {
|
||||||
|
if len(fmt.Sprint(slk)) > maxWidths["key"] {
|
||||||
|
maxWidths["key"] = len(fmt.Sprint(slk))
|
||||||
|
}
|
||||||
|
if len(fmt.Sprint(v)) > maxWidths[k] {
|
||||||
|
maxWidths[k] = len(fmt.Sprint(v))
|
||||||
|
if maxWidths[k] < len(k) {
|
||||||
|
maxWidths[k] = len(k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(keyOrder) > 0 {
|
||||||
|
fmt.Printf("%-"+fmt.Sprint(maxWidths["key"])+"s ", "")
|
||||||
|
for _, v := range keyOrder {
|
||||||
|
fmt.Printf("%-"+fmt.Sprint(maxWidths[v])+"s ", v)
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
|
||||||
|
for slk, slv := range tlv.(map[string]interface{}) {
|
||||||
|
fmt.Printf("%-"+fmt.Sprint(maxWidths["key"])+"s ", slk)
|
||||||
|
for _, k := range keyOrder {
|
||||||
|
preformatted := slv.(map[string]interface{})[k]
|
||||||
|
var formatted string
|
||||||
|
switch k {
|
||||||
|
case "bytes_sent", "bytes_recvd":
|
||||||
|
formatted = fmt.Sprintf("%d", uint(preformatted.(float64)))
|
||||||
|
case "uptime", "last_seen":
|
||||||
|
seconds := uint(preformatted.(float64)) % 60
|
||||||
|
minutes := uint(preformatted.(float64)/60) % 60
|
||||||
|
hours := uint(preformatted.(float64) / 60 / 60)
|
||||||
|
formatted = fmt.Sprintf("%02d:%02d:%02d", hours, minutes, seconds)
|
||||||
|
default:
|
||||||
|
formatted = fmt.Sprint(preformatted)
|
||||||
|
}
|
||||||
|
fmt.Printf("%-"+fmt.Sprint(maxWidths[k])+"s ", formatted)
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runGetAndSetTunTap(res map[string]interface{}) {
|
||||||
|
for k, v := range res {
|
||||||
|
fmt.Println("Interface name:", k)
|
||||||
|
if mtu, ok := v.(map[string]interface{})["mtu"].(float64); ok {
|
||||||
|
fmt.Println("Interface MTU:", mtu)
|
||||||
|
}
|
||||||
|
if tap_mode, ok := v.(map[string]interface{})["tap_mode"].(bool); ok {
|
||||||
|
fmt.Println("TAP mode:", tap_mode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runGetSelf(res map[string]interface{}, verbose *bool) {
|
||||||
|
for k, v := range res["self"].(map[string]interface{}) {
|
||||||
|
if buildname, ok := v.(map[string]interface{})["build_name"].(string); ok && buildname != "unknown" {
|
||||||
|
fmt.Println("Build name:", buildname)
|
||||||
|
}
|
||||||
|
if buildversion, ok := v.(map[string]interface{})["build_version"].(string); ok && buildversion != "unknown" {
|
||||||
|
fmt.Println("Build version:", buildversion)
|
||||||
|
}
|
||||||
|
fmt.Println("IPv6 address:", k)
|
||||||
|
if subnet, ok := v.(map[string]interface{})["subnet"].(string); ok {
|
||||||
|
fmt.Println("IPv6 subnet:", subnet)
|
||||||
|
}
|
||||||
|
if boxSigKey, ok := v.(map[string]interface{})["key"].(string); ok {
|
||||||
|
fmt.Println("Public key:", boxSigKey)
|
||||||
|
}
|
||||||
|
if coords, ok := v.(map[string]interface{})["coords"].(string); ok {
|
||||||
|
fmt.Println("Coords:", coords)
|
||||||
|
}
|
||||||
|
if *verbose {
|
||||||
|
if nodeID, ok := v.(map[string]interface{})["node_id"].(string); ok {
|
||||||
|
fmt.Println("Node ID:", nodeID)
|
||||||
|
}
|
||||||
|
if boxPubKey, ok := v.(map[string]interface{})["box_pub_key"].(string); ok {
|
||||||
|
fmt.Println("Public encryption key:", boxPubKey)
|
||||||
|
}
|
||||||
|
if boxSigKey, ok := v.(map[string]interface{})["box_sig_key"].(string); ok {
|
||||||
|
fmt.Println("Public signing key:", boxSigKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runGetSwitchQueues(res map[string]interface{}) {
|
||||||
|
maximumqueuesize := float64(4194304)
|
||||||
|
portqueues := make(map[float64]float64)
|
||||||
|
portqueuesize := make(map[float64]float64)
|
||||||
|
portqueuepackets := make(map[float64]float64)
|
||||||
|
v := res["switchqueues"].(map[string]interface{})
|
||||||
|
if queuecount, ok := v["queues_count"].(float64); ok {
|
||||||
|
fmt.Printf("Active queue count: %d queues\n", uint(queuecount))
|
||||||
|
}
|
||||||
|
if queuesize, ok := v["queues_size"].(float64); ok {
|
||||||
|
fmt.Printf("Active queue size: %d bytes\n", uint(queuesize))
|
||||||
|
}
|
||||||
|
if highestqueuecount, ok := v["highest_queues_count"].(float64); ok {
|
||||||
|
fmt.Printf("Highest queue count: %d queues\n", uint(highestqueuecount))
|
||||||
|
}
|
||||||
|
if highestqueuesize, ok := v["highest_queues_size"].(float64); ok {
|
||||||
|
fmt.Printf("Highest queue size: %d bytes\n", uint(highestqueuesize))
|
||||||
|
}
|
||||||
|
if m, ok := v["maximum_queues_size"].(float64); ok {
|
||||||
|
maximumqueuesize = m
|
||||||
|
fmt.Printf("Maximum queue size: %d bytes\n", uint(maximumqueuesize))
|
||||||
|
}
|
||||||
|
if queues, ok := v["queues"].([]interface{}); ok {
|
||||||
|
if len(queues) != 0 {
|
||||||
|
fmt.Println("Active queues:")
|
||||||
|
for _, v := range queues {
|
||||||
|
queueport := v.(map[string]interface{})["queue_port"].(float64)
|
||||||
|
queuesize := v.(map[string]interface{})["queue_size"].(float64)
|
||||||
|
queuepackets := v.(map[string]interface{})["queue_packets"].(float64)
|
||||||
|
queueid := v.(map[string]interface{})["queue_id"].(string)
|
||||||
|
portqueues[queueport]++
|
||||||
|
portqueuesize[queueport] += queuesize
|
||||||
|
portqueuepackets[queueport] += queuepackets
|
||||||
|
queuesizepercent := (100 / maximumqueuesize) * queuesize
|
||||||
|
fmt.Printf("- Switch port %d, Stream ID: %v, size: %d bytes (%d%% full), %d packets\n",
|
||||||
|
uint(queueport), []byte(queueid), uint(queuesize),
|
||||||
|
uint(queuesizepercent), uint(queuepackets))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(portqueuesize) > 0 && len(portqueuepackets) > 0 {
|
||||||
|
fmt.Println("Aggregated statistics by switchport:")
|
||||||
|
for k, v := range portqueuesize {
|
||||||
|
queuesizepercent := (100 / (portqueues[k] * maximumqueuesize)) * v
|
||||||
|
fmt.Printf("- Switch port %d, size: %d bytes (%d%% full), %d packets\n",
|
||||||
|
uint(k), uint(v), uint(queuesizepercent), uint(portqueuepackets[k]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runAddsAndRemoves(res map[string]interface{}) {
|
||||||
|
if _, ok := res["added"]; ok {
|
||||||
|
for _, v := range res["added"].([]interface{}) {
|
||||||
|
fmt.Println("Added:", fmt.Sprint(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := res["not_added"]; ok {
|
||||||
|
for _, v := range res["not_added"].([]interface{}) {
|
||||||
|
fmt.Println("Not added:", fmt.Sprint(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := res["removed"]; ok {
|
||||||
|
for _, v := range res["removed"].([]interface{}) {
|
||||||
|
fmt.Println("Removed:", fmt.Sprint(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := res["not_removed"]; ok {
|
||||||
|
for _, v := range res["not_removed"].([]interface{}) {
|
||||||
|
fmt.Println("Not removed:", fmt.Sprint(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runGetAllowedEncryptionPublicKeys(res map[string]interface{}) {
|
||||||
|
if _, ok := res["allowed_box_pubs"]; !ok {
|
||||||
|
fmt.Println("All connections are allowed")
|
||||||
|
} else if res["allowed_box_pubs"] == nil {
|
||||||
|
fmt.Println("All connections are allowed")
|
||||||
|
} else {
|
||||||
|
fmt.Println("Connections are allowed only from the following public box keys:")
|
||||||
|
for _, v := range res["allowed_box_pubs"].([]interface{}) {
|
||||||
|
fmt.Println("-", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runGetMulticastInterfaces(res map[string]interface{}) {
|
||||||
|
if _, ok := res["multicast_interfaces"]; !ok {
|
||||||
|
fmt.Println("No multicast interfaces found")
|
||||||
|
} else if res["multicast_interfaces"] == nil {
|
||||||
|
fmt.Println("No multicast interfaces found")
|
||||||
|
} else {
|
||||||
|
fmt.Println("Multicast peer discovery is active on:")
|
||||||
|
for _, v := range res["multicast_interfaces"].([]interface{}) {
|
||||||
|
fmt.Println("-", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runGetSourceSubnets(res map[string]interface{}) {
|
||||||
|
if _, ok := res["source_subnets"]; !ok {
|
||||||
|
fmt.Println("No source subnets found")
|
||||||
|
} else if res["source_subnets"] == nil {
|
||||||
|
fmt.Println("No source subnets found")
|
||||||
|
} else {
|
||||||
|
fmt.Println("Source subnets:")
|
||||||
|
for _, v := range res["source_subnets"].([]interface{}) {
|
||||||
|
fmt.Println("-", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runGetRoutes(res map[string]interface{}) {
|
||||||
|
if routes, ok := res["routes"].(map[string]interface{}); !ok {
|
||||||
|
fmt.Println("No routes found")
|
||||||
|
} else {
|
||||||
|
if res["routes"] == nil || len(routes) == 0 {
|
||||||
|
fmt.Println("No routes found")
|
||||||
|
} else {
|
||||||
|
fmt.Println("Routes:")
|
||||||
|
for k, v := range routes {
|
||||||
|
if pv, ok := v.(string); ok {
|
||||||
|
fmt.Println("-", k, " via ", pv)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runGetTunnelRouting(res map[string]interface{}) {
|
||||||
|
if enabled, ok := res["enabled"].(bool); !ok {
|
||||||
|
fmt.Println("Tunnel routing is disabled")
|
||||||
|
} else if !enabled {
|
||||||
|
fmt.Println("Tunnel routing is disabled")
|
||||||
|
} else {
|
||||||
|
fmt.Println("Tunnel routing is enabled")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue