add (not working) admin functions for auth keys, needs debugging

This commit is contained in:
Arceliar 2018-05-06 19:31:19 -05:00
parent 0b391b6e3a
commit 94dd231e13

View File

@ -3,6 +3,7 @@ package yggdrasil
import "net" import "net"
import "os" import "os"
import "bytes" import "bytes"
import "encoding/hex"
import "errors" import "errors"
import "fmt" import "fmt"
import "net/url" import "net/url"
@ -104,6 +105,23 @@ func (a *admin) init(c *Core, listenaddr string) {
*out = []byte(a.printInfos([]admin_nodeInfo{info})) *out = []byte(a.printInfos([]admin_nodeInfo{info}))
} }
}) })
a.addHandler("getAuthBoxPubs", nil, func(out *[]byte, _ ...string) {
*out = []byte(a.getAuthBoxPubs())
})
a.addHandler("addAuthBoxPub", []string{"<boxPubKey>"}, 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{"<boxPubKey>"}, 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() go a.listen()
} }
@ -347,6 +365,36 @@ func (a *admin) getData_getSessions() []admin_nodeInfo {
return infos 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 { func (a *admin) getResponse_dot() []byte {
self := a.getData_getSelf().asMap() self := a.getData_getSelf().asMap()
myAddr := self["IP"] myAddr := self["IP"]