From 94dd231e1377fcd16956751dbced0cb62c635798 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sun, 6 May 2018 19:31:19 -0500 Subject: [PATCH] add (not working) admin functions for auth keys, needs debugging --- src/yggdrasil/admin.go | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index ddb02818..8ddcd633 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -3,6 +3,7 @@ package yggdrasil import "net" import "os" import "bytes" +import "encoding/hex" import "errors" import "fmt" import "net/url" @@ -104,6 +105,23 @@ func (a *admin) init(c *Core, listenaddr string) { *out = []byte(a.printInfos([]admin_nodeInfo{info})) } }) + a.addHandler("getAuthBoxPubs", nil, func(out *[]byte, _ ...string) { + *out = []byte(a.getAuthBoxPubs()) + }) + a.addHandler("addAuthBoxPub", []string{""}, func(out *[]byte, saddr ...string) { + if a.addAuthBoxPub(saddr[0]) == nil { + *out = []byte("Adding key: " + saddr[0] + "\n") + } else { + *out = []byte("Failed to add key: " + saddr[0] + "\n") + } + }) + a.addHandler("removeAuthBoxPub", []string{""}, func(out *[]byte, sport ...string) { + if a.removeAuthBoxPub(sport[0]) == nil { + *out = []byte("Removing key: " + sport[0] + "\n") + } else { + *out = []byte("Failed to remove key: " + sport[0] + "\n") + } + }) go a.listen() } @@ -347,6 +365,36 @@ func (a *admin) getData_getSessions() []admin_nodeInfo { return infos } +func (a *admin) getAuthBoxPubs() string { + pubs := a.core.peers.getAuthBoxPubs() + var out []string + for _, pub := range pubs { + out = append(out, hex.EncodeToString(pub[:])) + } + out = append(out, "") + return strings.Join(out, "\n") +} + +func (a *admin) addAuthBoxPub(bstr string) (err error) { + boxBytes, err := hex.DecodeString(bstr) + if err != nil { + var box boxPubKey + copy(box[:], boxBytes) + a.core.peers.addAuthBoxPub(&box) + } + return +} + +func (a *admin) removeAuthBoxPub(bstr string) (err error) { + boxBytes, err := hex.DecodeString(bstr) + if err != nil { + var box boxPubKey + copy(box[:], boxBytes) + a.core.peers.removeAuthBoxPub(&box) + } + return +} + func (a *admin) getResponse_dot() []byte { self := a.getData_getSelf().asMap() myAddr := self["IP"]