Files
wireguard-ui-multi/internal/api/ui_handlers.go
T
sysopsandClaude Sonnet 5 41894e67c6 Fix 404s: serve UI templates/static from configurable ui-root, not CWD
The web UI 404'd in production because templates/static were loaded
via relative paths ("internal/ui/templates", "internal/ui/static"),
which only resolved when running from the repo checkout. systemd sets
WorkingDirectory=/var/lib/wireguard-ui-multi, so those paths never
existed there.

Add a -ui-root flag (default /usr/local/share/wireguard-ui-multi/ui),
have install.sh copy internal/ui there, and resolve templates/static
paths through it instead of hardcoded relative strings.

Also add release-binary fast path to bootstrap.sh (falls back to
source build with CGO_ENABLED=0/-trimpath if no release exists yet),
and document real hardware/build-RAM requirements in the README.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-10 18:18:48 +02:00

40 lines
936 B
Go

package api
import (
"net/http"
)
// hasSession reports whether the request carries a valid, non-expired session cookie.
func (a *API) hasSession(r *http.Request) bool {
c, err := r.Cookie(sessionCookieName)
if err != nil {
return false
}
_, ok := a.sessions.Get(c.Value)
return ok
}
func (a *API) handleDashboard(w http.ResponseWriter, r *http.Request) {
if !a.hasSession(r) {
http.Redirect(w, r, "/login", http.StatusFound)
return
}
http.ServeFile(w, r, a.templatesDir()+"/dashboard.html")
}
func (a *API) handleLoginPage(w http.ResponseWriter, r *http.Request) {
if a.hasSession(r) {
http.Redirect(w, r, "/", http.StatusFound)
return
}
http.ServeFile(w, r, a.templatesDir()+"/login.html")
}
func (a *API) handleServerPage(w http.ResponseWriter, r *http.Request) {
if !a.hasSession(r) {
http.Redirect(w, r, "/login", http.StatusFound)
return
}
http.ServeFile(w, r, a.templatesDir()+"/server.html")
}