From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id CB64B602F3 for ; Fri, 16 Oct 2020 11:07:25 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id BE6F21917D for ; Fri, 16 Oct 2020 11:06:55 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 7034F1914D for ; Fri, 16 Oct 2020 11:06:54 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 35F4045D8B for ; Fri, 16 Oct 2020 11:06:54 +0200 (CEST) From: Thomas Lamprecht To: pbs-devel@lists.proxmox.com Date: Fri, 16 Oct 2020 11:06:47 +0200 Message-Id: <20201016090648.23887-2-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201016090648.23887-1-t.lamprecht@proxmox.com> References: <20201016090648.23887-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.133 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [rest.rs] Subject: [pbs-devel] [PATCH backup 2/3] server/rest: also log user agent X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Oct 2020 09:07:25 -0000 allows easily to see if a request is from a browser or a proxmox-backup-client CLI Signed-off-by: Thomas Lamprecht --- src/server/rest.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/server/rest.rs b/src/server/rest.rs index 0b3bc067..7235a291 100644 --- a/src/server/rest.rs +++ b/src/server/rest.rs @@ -116,6 +116,7 @@ fn log_response( method: hyper::Method, path_query: &str, resp: &Response, + user_agent: Option, ) { if resp.extensions().get::().is_some() { return; }; @@ -150,7 +151,7 @@ fn log_response( .lock() .unwrap() .log(format!( - "{} - {} [{}] \"{} {}\" {} {}", + "{} - {} [{}] \"{} {}\" {} {} {}", peer.ip(), user, datetime, @@ -158,6 +159,7 @@ fn log_response( path, status.as_str(), resp.body().size_hint().lower(), + user_agent.unwrap_or("-".into()), )); } } @@ -173,6 +175,15 @@ fn get_proxied_peer(headers: &HeaderMap) -> Option { rhost.parse().ok() } +fn get_user_agent(headers: &HeaderMap) -> Option { + let agent = headers.get(header::USER_AGENT)?.to_str(); + agent.map(|s| { + let mut s = s.to_owned(); + s.truncate(128); + s + }).ok() +} + impl tower_service::Service> for ApiService { type Response = Response; type Error = Error; @@ -185,6 +196,7 @@ impl tower_service::Service> for ApiService { fn call(&mut self, req: Request) -> Self::Future { let path = req.uri().path_and_query().unwrap().as_str().to_owned(); let method = req.method().clone(); + let user_agent = get_user_agent(req.headers()); let config = Arc::clone(&self.api_config); let peer = match get_proxied_peer(req.headers()) { @@ -203,7 +215,7 @@ impl tower_service::Service> for ApiService { } }; let logger = config.get_file_log(); - log_response(logger, &peer, method, &path, &response); + log_response(logger, &peer, method, &path, &response, user_agent); Ok(response) } .boxed() -- 2.27.0