fix: restore operation logging hook
This commit is contained in:
@@ -85,6 +85,26 @@ func account(r *http.Request, s *Server) *auth.Account {
|
|||||||
return s.Auth.Guest
|
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) {
|
func writeJSON(w http.ResponseWriter, v any) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
json.NewEncoder(w).Encode(v)
|
json.NewEncoder(w).Encode(v)
|
||||||
|
|||||||
Reference in New Issue
Block a user