65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
|
|
"dhcp-lease-manager/zoraxy_plugin"
|
|
)
|
|
|
|
//go:embed web/*
|
|
var webFS embed.FS
|
|
|
|
func main() {
|
|
spec := &zoraxy_plugin.IntroSpect{
|
|
ID: "dhcp-lease-manager",
|
|
Name: "DHCP Lease Manager",
|
|
Author: "Zoraxy Community",
|
|
AuthorContact: "",
|
|
Description: "Manage dnsmasq DHCP leases — view active leases, pin/unpin permanent leases, and reload dnsmasq from the Zoraxy UI.",
|
|
URL: "",
|
|
Type: zoraxy_plugin.PluginType_Utilities,
|
|
VersionMajor: 1,
|
|
VersionMinor: 0,
|
|
VersionPatch: 0,
|
|
UIPath: "/ui",
|
|
}
|
|
|
|
config, err := zoraxy_plugin.ServeAndRecvSpec(spec)
|
|
if err != nil {
|
|
log.Fatalf("failed to receive config: %v", err)
|
|
}
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
// Set up the embedded web UI router.
|
|
uiRouter := zoraxy_plugin.NewPluginEmbedUIRouter(
|
|
spec.ID,
|
|
&webFS,
|
|
"web",
|
|
spec.UIPath,
|
|
)
|
|
|
|
// Register API endpoints under the UI path.
|
|
uiRouter.HandleFunc("/api/leases", handleListLeases, mux)
|
|
uiRouter.HandleFunc("/api/pin", handlePinLease, mux)
|
|
uiRouter.HandleFunc("/api/unpin", handleUnpinLease, mux)
|
|
uiRouter.HandleFunc("/api/reload", handleReload, mux)
|
|
|
|
// Handle graceful shutdown.
|
|
uiRouter.RegisterTerminateHandler(func() {
|
|
log.Println("dhcp-lease-manager shutting down")
|
|
}, mux)
|
|
|
|
uiRouter.AttachHandlerToMux(mux)
|
|
|
|
addr := fmt.Sprintf("127.0.0.1:%d", config.Port)
|
|
log.Printf("dhcp-lease-manager v%d.%d.%d listening on %s",
|
|
spec.VersionMajor, spec.VersionMinor, spec.VersionPatch, addr)
|
|
|
|
if err := http.ListenAndServe(addr, mux); err != nil {
|
|
log.Fatalf("server error: %v", err)
|
|
}
|
|
}
|