Pretty-format leases so it shows human readable MAC address.
This commit is contained in:
parent
03effab345
commit
8fc5aebf12
14
dhcp.go
14
dhcp.go
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/dhcpd"
|
"github.com/AdguardTeam/AdGuardHome/dhcpd"
|
||||||
"github.com/joomcode/errorx"
|
"github.com/joomcode/errorx"
|
||||||
@ -12,9 +13,20 @@ import (
|
|||||||
var dhcpServer = dhcpd.Server{}
|
var dhcpServer = dhcpd.Server{}
|
||||||
|
|
||||||
func handleDHCPStatus(w http.ResponseWriter, r *http.Request) {
|
func handleDHCPStatus(w http.ResponseWriter, r *http.Request) {
|
||||||
|
rawLeases := dhcpServer.Leases()
|
||||||
|
leases := []map[string]string{}
|
||||||
|
for i := range rawLeases {
|
||||||
|
lease := map[string]string{
|
||||||
|
"mac": rawLeases[i].HWAddr.String(),
|
||||||
|
"ip": rawLeases[i].IP.String(),
|
||||||
|
"expires": rawLeases[i].Expiry.Format(time.RFC3339),
|
||||||
|
}
|
||||||
|
leases = append(leases, lease)
|
||||||
|
|
||||||
|
}
|
||||||
status := map[string]interface{}{
|
status := map[string]interface{}{
|
||||||
"config": config.DHCP,
|
"config": config.DHCP,
|
||||||
"leases": dhcpServer.Leases(),
|
"leases": leases,
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
Loading…
Reference in New Issue
Block a user