Skip to content

Commit

Permalink
Add api for server info
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Nov 19, 2024
1 parent fb9e947 commit 3001396
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions adminui/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package adminui

import (
"encoding/json"
"log"
"net/http"

"github.com/NHAS/wag/internal/config"
)

func (au *AdminUI) serverInfo(w http.ResponseWriter, r *http.Request) {

pubkey, port, err := au.firewall.ServerDetails()
if err != nil {
log.Println("error getting server details: ", err)
w.WriteHeader(http.StatusInternalServerError)
return
}

s, err := au.ctrl.GetAllSettings()
if err != nil {
log.Println("error getting server settings: ", err)

w.WriteHeader(http.StatusInternalServerError)
return
}

d := ServerInfoDTO{
PublicKey: pubkey.String(),
ExternalAddress: s.ExternalAddress,
Subnet: config.Values.Wireguard.Range.String(),
Port: port,
Version: au.wagVersion,
}

w.Header().Set("content-type", "application/json")
json.NewEncoder(w).Encode(d)
}

func (au *AdminUI) consoleLog(w http.ResponseWriter, r *http.Request) {
d := LogLinesDTO{
LogItems: au.logQueue.ReadAll(),
}

w.Header().Set("content-type", "application/json")
json.NewEncoder(w).Encode(d)
}

0 comments on commit 3001396

Please sign in to comment.