diff --git a/core/src/main/java/org/nzbhydra/downloading/downloadurls/DownloadUrlBuilder.java b/core/src/main/java/org/nzbhydra/downloading/downloadurls/DownloadUrlBuilder.java index abdabd3f2..b516fba77 100644 --- a/core/src/main/java/org/nzbhydra/downloading/downloadurls/DownloadUrlBuilder.java +++ b/core/src/main/java/org/nzbhydra/downloading/downloadurls/DownloadUrlBuilder.java @@ -18,10 +18,12 @@ import lombok.extern.slf4j.Slf4j; import org.nzbhydra.config.ConfigProvider; +import org.nzbhydra.config.HistoryUserInfoType; import org.nzbhydra.config.MainConfig; import org.nzbhydra.config.downloading.DownloadType; import org.nzbhydra.logging.LoggingMarkers; import org.nzbhydra.searching.db.SearchResultEntity; +import org.nzbhydra.web.SessionStorage; import org.nzbhydra.web.UrlCalculator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -78,6 +80,10 @@ private String getDownloadLink(Long searchResultId, boolean internal, DownloadTy builder.path("/" + searchResultId); builder.queryParam("apikey", main.getApiKey()); } + HistoryUserInfoType infoType = configProvider.getBaseConfig().getMain().getLogging().getHistoryUserInfoType(); + if (infoType.isLogUserInfo() && SessionStorage.username.get() != null) { + builder.queryParam("username", SessionStorage.username.get()); + } return builder.toUriString(); } } diff --git a/core/src/main/java/org/nzbhydra/downloading/nzbs/NzbHandlingWeb.java b/core/src/main/java/org/nzbhydra/downloading/nzbs/NzbHandlingWeb.java index d209e8dff..a9584bd9c 100644 --- a/core/src/main/java/org/nzbhydra/downloading/nzbs/NzbHandlingWeb.java +++ b/core/src/main/java/org/nzbhydra/downloading/nzbs/NzbHandlingWeb.java @@ -135,6 +135,7 @@ public ResponseEntity downloadNzbForUsers(@PathVariable("guid") long gui @RequestMapping(value = "/getnzb/api/{guid}", produces = "application/x-nzb") public ResponseEntity downloadNzbWithApikey(@PathVariable("guid") long guid, @RequestParam(required = false) String apikey) throws WrongApiKeyException { logger.debug("downloadNzbWithApikey guid: {}", guid); + BaseConfig baseConfig = configProvider.getBaseConfig(); if ((apikey == null || !apikey.equals(baseConfig.getMain().getApiKey())) && !noApiKeyNeeded) { logger.error("Received NZB API download call with wrong API key"); diff --git a/core/src/main/java/org/nzbhydra/web/Interceptor.java b/core/src/main/java/org/nzbhydra/web/Interceptor.java index 71ee18e1b..4c1e4bdc6 100644 --- a/core/src/main/java/org/nzbhydra/web/Interceptor.java +++ b/core/src/main/java/org/nzbhydra/web/Interceptor.java @@ -51,11 +51,19 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons if (configProvider.getBaseConfig().getMain().getLogging().isLogIpAddresses()) { MDC.put("IPADDRESS", ip); } - if (configProvider.getBaseConfig().getMain().getLogging().isLogUsername() && !Strings.isNullOrEmpty(request.getRemoteUser())) { - MDC.put("USERNAME", request.getRemoteUser()); - } + SessionStorage.IP.set(ip); - SessionStorage.username.set(request.getRemoteUser()); + + if (request.getRemoteUser() != null) { + SessionStorage.username.set(request.getRemoteUser()); + } else if (request.getParameter("username") != null) { + SessionStorage.username.set(request.getParameter("username")); + } + if (configProvider.getBaseConfig().getMain().getLogging().isLogUsername()) { + if (!Strings.isNullOrEmpty(SessionStorage.username.get())) { + MDC.put("USERNAME", SessionStorage.username.get()); + } + } SessionStorage.userAgent.set(userAgentMapper.getUserAgent(request.getHeader("User-Agent"))); SessionStorage.requestUrl.set(request.getRequestURI()); diff --git a/core/src/main/resources/changelog.yaml b/core/src/main/resources/changelog.yaml index 3ab702d58..0b5d6b77a 100644 --- a/core/src/main/resources/changelog.yaml +++ b/core/src/main/resources/changelog.yaml @@ -2,6 +2,8 @@ - version: "v7.12.0" date: "2025-01-05" changes: + - type: "feature" + text: "If enabled log and/or store username for NZB links. This way when sending a link to be downloaded from hydra the username that caused the download will be known. See #981" - type: "fix" text: "Fix paging for search / download / notification history." - type: "fix" diff --git a/shared/mapping/src/main/java/org/nzbhydra/config/HistoryUserInfoType.java b/shared/mapping/src/main/java/org/nzbhydra/config/HistoryUserInfoType.java index 4c53eec86..a66a1ca5b 100644 --- a/shared/mapping/src/main/java/org/nzbhydra/config/HistoryUserInfoType.java +++ b/shared/mapping/src/main/java/org/nzbhydra/config/HistoryUserInfoType.java @@ -4,5 +4,9 @@ public enum HistoryUserInfoType { BOTH, IP, USERNAME, - NONE + NONE; + + public boolean isLogUserInfo() { + return this == BOTH || this == USERNAME; + } }