diff --git a/server.go b/server.go index 6712f79..afc14e2 100644 --- a/server.go +++ b/server.go @@ -392,19 +392,25 @@ func handlePinLease(w http.ResponseWriter, r *http.Request) { return } - // Check if already pinned. + // If already pinned, unpin first so we can re-pin with updated hostname. pinned, err := parsePinnedHosts() if err != nil { log.Printf("ERROR parsing pinned hosts: %v", err) writeJSON(w, http.StatusInternalServerError, ErrorResponse{Error: "failed to read config"}) return } - if _, exists := pinned[strings.ToLower(req.MAC)]; exists { - writeJSON(w, http.StatusConflict, PinResponse{ - Success: false, - Message: fmt.Sprintf("%s is already pinned", req.MAC), - }) - return + if existingHost, exists := pinned[strings.ToLower(req.MAC)]; exists { + if existingHost == req.Hostname { + // Same hostname — nothing to change. + writeJSON(w, http.StatusOK, PinResponse{Success: true, Message: "already pinned"}) + return + } + // Hostname changed — unpin old entry, then repin. + if err := unpinLease(req.MAC); err != nil { + log.Printf("ERROR unpinning for repin: %v", err) + writeJSON(w, http.StatusInternalServerError, ErrorResponse{Error: "failed to update config"}) + return + } } if err := pinLease(req.MAC, req.IP, req.Hostname); err != nil { diff --git a/web/app.js b/web/app.js index dd5531d..bd4ed2f 100644 --- a/web/app.js +++ b/web/app.js @@ -1,6 +1,6 @@ /** * DHCP Lease Manager — client-side logic. - * Uses Zoraxy's $.cjax() for CSRF-safe AJAX (jQuery is available from parent frame). + * Uses Zoraxy's $.cjax() for CSRF-safe AJAX (jQuery available from parent frame). */ // --------------------------------------------------------------------------- @@ -34,6 +34,7 @@ function renderLeases(data) { var rows = leases.map(function (lease) { var isPermanent = lease.status === 'permanent'; + var hasHostname = lease.hostname && lease.hostname.trim() !== ''; return ( '' + '' + esc(lease.hostname || '--') + '' + @@ -44,15 +45,24 @@ function renderLeases(data) { esc(lease.status) + '' + '' + - '' + + '' + (isPermanent - ? '' - : '' + - '