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,8 +207,49 @@ func run() int {
|
|||
|
||||
switch strings.ToLower(req["request"].(string)) {
|
||||
case "dot":
|
||||
fmt.Println(res["dot"])
|
||||
runDot(res)
|
||||
case "list", "getpeers", "getswitchpeers", "getdht", "getsessions", "dhtping":
|
||||
runVariousInfo(res, verbose)
|
||||
case "gettuntap", "settuntap":
|
||||
runGetAndSetTunTap(res)
|
||||
case "getself":
|
||||
runGetSelf(res, verbose)
|
||||
case "getswitchqueues":
|
||||
runGetSwitchQueues(res)
|
||||
case "addpeer", "removepeer", "addallowedencryptionpublickey", "removeallowedencryptionpublickey", "addsourcesubnet", "addroute", "removesourcesubnet", "removeroute":
|
||||
runAddsAndRemoves(res)
|
||||
case "getallowedencryptionpublickeys":
|
||||
runGetAllowedEncryptionPublicKeys(res)
|
||||
case "getmulticastinterfaces":
|
||||
runGetMulticastInterfaces(res)
|
||||
case "getsourcesubnets":
|
||||
runGetSourceSubnets(res)
|
||||
case "getroutes":
|
||||
runGetRoutes(res)
|
||||
case "settunnelrouting":
|
||||
fallthrough
|
||||
case "gettunnelrouting":
|
||||
runGetTunnelRouting(res)
|
||||
default:
|
||||
if json, err := json.MarshalIndent(recv["response"], "", " "); err == nil {
|
||||
fmt.Println(string(json))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.Println("Error receiving response:", err)
|
||||
}
|
||||
|
||||
if v, ok := recv["status"]; ok && v != "success" {
|
||||
return 1
|
||||
}
|
||||
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
|
||||
|
@ -269,7 +310,9 @@ func run() int {
|
|||
fmt.Println()
|
||||
}
|
||||
}
|
||||
case "gettuntap", "settuntap":
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -279,7 +322,9 @@ func run() int {
|
|||
fmt.Println("TAP mode:", tap_mode)
|
||||
}
|
||||
}
|
||||
case "getself":
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -309,7 +354,9 @@ func run() int {
|
|||
}
|
||||
}
|
||||
}
|
||||
case "getswitchqueues":
|
||||
}
|
||||
|
||||
func runGetSwitchQueues(res map[string]interface{}) {
|
||||
maximumqueuesize := float64(4194304)
|
||||
portqueues := make(map[float64]float64)
|
||||
portqueuesize := make(map[float64]float64)
|
||||
|
@ -357,7 +404,9 @@ func run() int {
|
|||
uint(k), uint(v), uint(queuesizepercent), uint(portqueuepackets[k]))
|
||||
}
|
||||
}
|
||||
case "addpeer", "removepeer", "addallowedencryptionpublickey", "removeallowedencryptionpublickey", "addsourcesubnet", "addroute", "removesourcesubnet", "removeroute":
|
||||
}
|
||||
|
||||
func runAddsAndRemoves(res map[string]interface{}) {
|
||||
if _, ok := res["added"]; ok {
|
||||
for _, v := range res["added"].([]interface{}) {
|
||||
fmt.Println("Added:", fmt.Sprint(v))
|
||||
|
@ -378,7 +427,9 @@ func run() int {
|
|||
fmt.Println("Not removed:", fmt.Sprint(v))
|
||||
}
|
||||
}
|
||||
case "getallowedencryptionpublickeys":
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -389,7 +440,9 @@ func run() int {
|
|||
fmt.Println("-", v)
|
||||
}
|
||||
}
|
||||
case "getmulticastinterfaces":
|
||||
}
|
||||
|
||||
func runGetMulticastInterfaces(res map[string]interface{}) {
|
||||
if _, ok := res["multicast_interfaces"]; !ok {
|
||||
fmt.Println("No multicast interfaces found")
|
||||
} else if res["multicast_interfaces"] == nil {
|
||||
|
@ -400,7 +453,9 @@ func run() int {
|
|||
fmt.Println("-", v)
|
||||
}
|
||||
}
|
||||
case "getsourcesubnets":
|
||||
}
|
||||
|
||||
func runGetSourceSubnets(res map[string]interface{}) {
|
||||
if _, ok := res["source_subnets"]; !ok {
|
||||
fmt.Println("No source subnets found")
|
||||
} else if res["source_subnets"] == nil {
|
||||
|
@ -411,7 +466,9 @@ func run() int {
|
|||
fmt.Println("-", v)
|
||||
}
|
||||
}
|
||||
case "getroutes":
|
||||
}
|
||||
|
||||
func runGetRoutes(res map[string]interface{}) {
|
||||
if routes, ok := res["routes"].(map[string]interface{}); !ok {
|
||||
fmt.Println("No routes found")
|
||||
} else {
|
||||
|
@ -426,9 +483,9 @@ func run() int {
|
|||
}
|
||||
}
|
||||
}
|
||||
case "settunnelrouting":
|
||||
fallthrough
|
||||
case "gettunnelrouting":
|
||||
}
|
||||
|
||||
func runGetTunnelRouting(res map[string]interface{}) {
|
||||
if enabled, ok := res["enabled"].(bool); !ok {
|
||||
fmt.Println("Tunnel routing is disabled")
|
||||
} else if !enabled {
|
||||
|
@ -436,17 +493,4 @@ func run() int {
|
|||
} else {
|
||||
fmt.Println("Tunnel routing is enabled")
|
||||
}
|
||||
default:
|
||||
if json, err := json.MarshalIndent(recv["response"], "", " "); err == nil {
|
||||
fmt.Println(string(json))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.Println("Error receiving response:", err)
|
||||
}
|
||||
|
||||
if v, ok := recv["status"]; ok && v != "success" {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue