update auth, and admin stats

This commit is contained in:
AJ ONeal 2020-07-21 23:47:47 -06:00
parent 850c52f9dc
commit c7a1d8d3a2
4 changed files with 31 additions and 19 deletions

View File

@ -36,7 +36,7 @@ var primaryDomain string
var relayDomain string var relayDomain string
func help() { func help() {
fmt.Fprintf(os.Stderr, "Usage: mgmt --domain <mgmt.example.com> --tunnel-domain <devices.example.com> --secret <128-bit secret>\n") fmt.Fprintf(os.Stderr, "Usage: mgmt --domain <devices.example.com> --secret <128-bit secret>\n")
} }
func main() { func main() {
@ -51,13 +51,16 @@ func main() {
) )
flag.StringVar(&secret, "secret", "", "a >= 16-character random string for JWT key signing") flag.StringVar(&secret, "secret", "", "a >= 16-character random string for JWT key signing")
flag.StringVar(&primaryDomain, "domain", "", "the base domain to use for all clients") flag.StringVar(&primaryDomain, "domain", "", "the base domain to use for all clients")
flag.StringVar(&relayDomain, "tunnel-domain", "", "the domain name of the tunnel relay service") flag.StringVar(&relayDomain, "tunnel-domain", "", "the domain name of the tunnel relay service, if different from base domain")
flag.Parse() flag.Parse()
if "" == primaryDomain || "" == relayDomain { if "" == primaryDomain {
help() help()
os.Exit(1) os.Exit(1)
} }
if "" == relayDomain {
relayDomain = primaryDomain
}
if "" != os.Getenv("GODADDY_API_KEY") { if "" != os.Getenv("GODADDY_API_KEY") {
id := os.Getenv("GODADDY_API_KEY") id := os.Getenv("GODADDY_API_KEY")

View File

@ -107,34 +107,36 @@ func apiNotFoundHandler(w http.ResponseWriter, r *http.Request) {
} }
type SubscriberStatus struct { type SubscriberStatus struct {
Subject string Subject string `json:"sub"`
Tunnels int RemoteAddr string `json:"socket"`
Clients int Tunnels int `json:"tunnels"`
Clients int `json:"clients"`
// TODO bytes read // TODO bytes read
} }
func getSubscribers(w http.ResponseWriter, r *http.Request) { func getSubscribers(w http.ResponseWriter, r *http.Request) {
statuses := []*SubscriberStatus{} statuses := []*SubscriberStatus{}
table.Servers.Range(func(key, value interface{}) bool { table.Servers.Range(func(key, value interface{}) bool {
tunnels := 0 status := &SubscriberStatus{
clients := 0 Subject: "",
//RemoteAddr: k.(string),
Tunnels: 0,
Clients: 0,
}
//subject := key.(string) //subject := key.(string)
srvMap := value.(*sync.Map) srvMap := value.(*sync.Map)
srvMap.Range(func(k, v interface{}) bool { srvMap.Range(func(k, v interface{}) bool {
tunnels += 1 status.Tunnels++
srv := v.(*table.SubscriberConn) srv := v.(*table.SubscriberConn)
status.Subject = srv.Grants.Subject
srv.Clients.Range(func(k, v interface{}) bool { srv.Clients.Range(func(k, v interface{}) bool {
clients += 1 status.Clients++
return true return true
}) })
statuses = append(statuses, &SubscriberStatus{
Subject: k.(string),
Tunnels: tunnels,
Clients: clients,
})
return true return true
}) })
statuses = append(statuses, status)
return true return true
}) })
_ = json.NewEncoder(w).Encode(&struct { _ = json.NewEncoder(w).Encode(&struct {

View File

@ -251,10 +251,11 @@ func main() {
} }
fmt.Printf("[Directory] %s\n\t%#v\n", *relay, directory) fmt.Printf("[Directory] %s\n\t%#v\n", *relay, directory)
authBase := strings.TrimSuffix(directory.Authenticate.URL, "/inspect")
if "" == *authURL { if "" == *authURL {
*authURL = directory.Authenticate.URL *authURL = authBase
} else { } else {
fmt.Println("Suggested Auth URL:", directory.Authenticate.URL) fmt.Println("Suggested Auth URL:", authBase)
fmt.Println("--auth-url Auth URL:", *authURL) fmt.Println("--auth-url Auth URL:", *authURL)
} }
if "" == *authURL { if "" == *authURL {
@ -362,6 +363,10 @@ func main() {
go func() { go func() {
for { for {
time.Sleep(10 * time.Minute) time.Sleep(10 * time.Minute)
if "" != ClientSecret {
// re-create token unless no secret was supplied
*token, err = authstore.HMACToken(ppid)
}
err = mgmt.Ping(*authURL, *token) err = mgmt.Ping(*authURL, *token)
if nil != err { if nil != err {
fmt.Fprintf(os.Stderr, "failed to ping mgmt server: %s\n", err) fmt.Fprintf(os.Stderr, "failed to ping mgmt server: %s\n", err)

View File

@ -52,11 +52,13 @@ func Register(authURL, secret, ppid string) (kid string, err error) {
} }
auth := &authstore.Authorization{} auth := &authstore.Authorization{}
err = json.NewDecoder(msg).Decode(auth) msgBytes, _ := ioutil.ReadAll(msg)
//err = json.NewDecoder(msg).Decode(auth)
err = json.Unmarshal(msgBytes, auth)
if err != nil { if err != nil {
return "", err return "", err
} }
msgBytes, _ := ioutil.ReadAll(msg) //msgBytes, _ := ioutil.ReadAll(msg)
if "" == auth.PublicKey { if "" == auth.PublicKey {
return "", fmt.Errorf("unexpected server response: no public key: %s", string(msgBytes)) return "", fmt.Errorf("unexpected server response: no public key: %s", string(msgBytes))
} }