diff --git a/cmd/dhcp4d/dhcp4d.go b/cmd/dhcp4d/dhcp4d.go index 7eb798d..6514b1a 100644 --- a/cmd/dhcp4d/dhcp4d.go +++ b/cmd/dhcp4d/dhcp4d.go @@ -16,14 +16,17 @@ package main import ( + "bytes" "encoding/json" "flag" "fmt" + "html/template" "io/ioutil" "net" "net/http" "os" "os/signal" + "sort" "syscall" "time" @@ -65,6 +68,106 @@ func updateNonExpired(leases []*dhcp4d.Lease) { var ouiDB = oui.NewDB("/perm/dhcp4d/oui") +var leases []*dhcp4d.Lease + +var ( + timefmt = func(t time.Time) string { + return t.Format("2006-01-02 15:04") + } + leasesTmpl = template.Must(template.New("").Funcs(template.FuncMap{ + "timefmt": timefmt, + "since": func(t time.Time) string { + dur := time.Since(t) + if dur.Hours() > 24 { + return timefmt(t) + } + return dur.Truncate(1 * time.Second).String() + }, + }).Parse(` +
+ +