diff --git a/chfs-ng/internal/api/server.go b/chfs-ng/internal/api/server.go index 649bacb..5d58f6a 100644 --- a/chfs-ng/internal/api/server.go +++ b/chfs-ng/internal/api/server.go @@ -85,6 +85,26 @@ func account(r *http.Request, s *Server) *auth.Account { return s.Auth.Guest } +func (s *Server) logOp(r *http.Request, action string) { + if s.Log == nil { + return + } + a := account(r, s) + user := "" + if a != nil { + user = a.Username + } + _ = s.Log.Write(clientIPString(r), user, action) +} + +func clientIPString(r *http.Request) string { + ip := clientIP(r) + if ip == nil { + return "-" + } + return ip.String() +} + func writeJSON(w http.ResponseWriter, v any) { w.Header().Set("Content-Type", "application/json; charset=utf-8") json.NewEncoder(w).Encode(v)