From 30ffa6805b5d385259aa74a1ed445e2531b3fc61 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 6 Aug 2023 01:54:01 +0400 Subject: [PATCH] Omit IP if a network type is not www or yggdrasil. --- internal/http/handlers.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/internal/http/handlers.go b/internal/http/handlers.go index 881b33d..e8a4b3d 100644 --- a/internal/http/handlers.go +++ b/internal/http/handlers.go @@ -123,9 +123,13 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) { } typ, _ := utils.NetworkType(r.Host) + ip := r.Header.Get("X-Real-IP") + if typ != "www" && typ != "ygg" { + ip = "" + } h.logFile.Printf("| up | %s | %s | %s | SHA256 %s | %s | %d | %s", - r.Header.Get("X-Real-IP"), typ, fHandler.Filename, fHash, fSaltedHash, fHandler.Size, r.UserAgent()) + ip, typ, fHandler.Filename, fHash, fSaltedHash, fHandler.Size, r.UserAgent()) w.WriteHeader(http.StatusCreated) } else { @@ -169,10 +173,14 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) { } defer fd.Close() - netTyp, _ := utils.NetworkType(r.Host) + typ, _ := utils.NetworkType(r.Host) + ip := r.Header.Get("X-Real-IP") + if typ != "www" && typ != "ygg" { + ip = "" + } h.logFile.Printf("| dw | %s | %s | %s | %s | %s", - r.Header.Get("X-Real-IP"), netTyp, name, saltedHash, r.UserAgent()) + ip, typ, name, saltedHash, r.UserAgent()) http.ServeContent(w, r, path, stat.ModTime(), fd) } @@ -199,10 +207,14 @@ func (h *UploadHandlers) Delete(w http.ResponseWriter, r *http.Request) { return } - netTyp, _ := utils.NetworkType(r.Host) + typ, _ := utils.NetworkType(r.Host) + ip := r.Header.Get("X-Real-IP") + if typ != "www" && typ != "ygg" { + ip = "" + } h.logFile.Printf("| dt | %s | %s | %s | %s", - r.Header.Get("X-Real-IP"), netTyp, saltedHash, r.UserAgent()) + ip, typ, saltedHash, r.UserAgent()) if strings.Contains(r.UserAgent(), "curl") || strings.Contains(r.UserAgent(), "Wget") { fmt.Fprintln(w, "File was successfully deleted.")