From 8b0bd75f29bdbf935e63540515a4931a75551221 Mon Sep 17 00:00:00 2001 From: cclohmar Date: Fri, 24 Jul 2026 10:08:12 +0000 Subject: [PATCH] fix: reload returns 200 JSON on error, fix missing buttons, handle non-JSON responses, add -buildvcs=false --- install.sh | 2 +- server.go | 7 ++++++- web/app.js | 16 +++++++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index b66e6b5..ad09538 100755 --- a/install.sh +++ b/install.sh @@ -501,7 +501,7 @@ install_plugin() { # Build the plugin info "Building plugin binary..." - (cd "$plugin_dir" && go build -o dhcp-lease-manager .) || { + (cd "$plugin_dir" && go build -buildvcs=false -o dhcp-lease-manager .) || { err "Plugin build failed. Check Go installation." exit 1 } diff --git a/server.go b/server.go index d9612df..81be160 100644 --- a/server.go +++ b/server.go @@ -302,7 +302,12 @@ func handleUnpinLease(w http.ResponseWriter, r *http.Request) { func handleReload(w http.ResponseWriter, r *http.Request) { if err := reloadDnsmasq(); err != nil { log.Printf("ERROR reloading dnsmasq: %v", err) - writeJSON(w, http.StatusInternalServerError, ErrorResponse{Error: err.Error()}) + // Return 200 even on error — Zoraxy may intercept non-200 + // responses and replace them with HTML error pages. + writeJSON(w, http.StatusOK, PinResponse{ + Success: false, + Message: fmt.Sprintf("reload failed: %v", err), + }) return } writeJSON(w, http.StatusOK, PinResponse{Success: true, Message: "dnsmasq reloaded"}) diff --git a/web/app.js b/web/app.js index 87e9a62..87dd5d0 100644 --- a/web/app.js +++ b/web/app.js @@ -30,10 +30,16 @@ async function apiFetch(path, opts) { opts.body = JSON.stringify(opts.body); opts.headers['Content-Type'] = 'application/json'; } - const res = await fetch(API_BASE + path, opts); - const data = await res.json(); + var res = await fetch(API_BASE + path, opts); + var text = await res.text(); + try { + var data = JSON.parse(text); + } catch (e) { + // Zoraxy may intercept error responses and return HTML + throw new Error('Unexpected response (status ' + res.status + '). Check plugin is running.'); + } if (!res.ok) { - throw new Error(data.error || data.message || 'Request failed'); + throw new Error(data.error || data.message || 'Request failed (status ' + res.status + ')'); } return data; } @@ -74,8 +80,8 @@ function renderLeases(data) { '' + '' + (isPermanent - ? '' - : '' + ? '' + : '' ) + '' + ''