9
0
mirror of https://github.com/Lomanic/presence-button-web synced 2024-11-21 21:17:29 +00:00

Add better logs to /status route

Don't needlessly leak button's login/password in these logs
This commit is contained in:
Lomanic 2020-11-07 20:08:50 +01:00
parent ef10e0fcb4
commit 4320babfa6

View File

@ -198,15 +198,18 @@ func imgHandler(w http.ResponseWriter, r *http.Request) {
func statusHandler(w http.ResponseWriter, r *http.Request) { func statusHandler(w http.ResponseWriter, r *http.Request) {
user, pass, ok := r.BasicAuth() user, pass, ok := r.BasicAuth()
fmt.Println("user", user, "pass", pass, "ok", ok) fmt.Printf("status notification by button... ")
if !ok || user != config.ESPUSERNAME || pass != config.ESPPASSWORD { if !ok || user != config.ESPUSERNAME || pass != config.ESPPASSWORD {
fmt.Printf("bad authentication: user:%v pass:%v\n", user, pass)
w.Header().Set("WWW-Authenticate", `Basic realm="Authentication required"`) w.Header().Set("WWW-Authenticate", `Basic realm="Authentication required"`)
http.Error(w, "Authentication required", 401) http.Error(w, "Authentication required", 401)
return return
} }
q := r.URL.Query() q := r.URL.Query()
status.FuzIsOpen = q.Get("fuzisopen") == "1" fuzIsOpen := q.Get("fuzisopen") == "1"
status.LastSeenAsOpen = q.Get("fuzisopen") == "1" fmt.Printf("button pushed: %v\n", fuzIsOpen)
status.FuzIsOpen = fuzIsOpen
status.LastSeenAsOpen = fuzIsOpen
status.LastSeen = time.Now() status.LastSeen = time.Now()
fmt.Fprintf(w, "OK") fmt.Fprintf(w, "OK")