From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 134991FF189 for ; Fri, 8 Aug 2025 12:27:44 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8535F13F53; Fri, 8 Aug 2025 12:29:18 +0200 (CEST) From: Hannes Laimer To: pmg-devel@lists.proxmox.com Date: Fri, 8 Aug 2025 12:28:36 +0200 Message-ID: <20250808102836.50441-1-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.2 MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1754648901422 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.024 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. 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. [spamreport-verbose.tt, utils.pm, spamreport-short.tt, pmgqm.pm] Subject: [pmg-devel] [PATCH pmg-api v2] fix #2452: pmgqm support 1-24h timespans for status/send X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pmg-devel-bounces@lists.proxmox.com Sender: "pmg-devel" Signed-off-by: Hannes Laimer --- I didn't find a section for this in the docs(maybe I missed it), if there is one, and depending on what it says maybe we have to update that as well. (I can send a followup in that case) since v1: - update default templates - 1..24h instead of 1..23h (thought `today` would be 24h, but it's not) src/PMG/CLI/pmgqm.pm | 8 ++++---- src/PMG/Utils.pm | 10 ++++++++-- src/templates/spamreport-short.tt | 4 +++- src/templates/spamreport-verbose.tt | 4 +++- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/PMG/CLI/pmgqm.pm b/src/PMG/CLI/pmgqm.pm index 23968f2..41f9f1a 100755 --- a/src/PMG/CLI/pmgqm.pm +++ b/src/PMG/CLI/pmgqm.pm @@ -90,9 +90,9 @@ __PACKAGE__->register_method({ additionalProperties => 0, properties => { timespan => { - description => "Select time span.", + description => "Select time span. Accepts 'today', 'yesterday', 'week' or '1h'..'24h' for the last N hours.", type => 'string', - enum => ['today', 'yesterday', 'week'], + pattern => '^(today|yesterday|week|([1-9]|1[0-9]|2[0-4])h)$', default => 'today', optional => 1, }, @@ -167,9 +167,9 @@ __PACKAGE__->register_method({ }, ), timespan => { - description => "Select time span.", + description => "Select time span. Accepts 'today', 'yesterday', 'week' or '1h'..'24h' for the last N hours.", type => 'string', - enum => ['today', 'yesterday', 'week'], + pattern => '^(today|yesterday|week|([1-9]|1[0-9]|2[0-4])h)$', default => 'today', optional => 1, }, diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm index 890096f..ddfa732 100644 --- a/src/PMG/Utils.pm +++ b/src/PMG/Utils.pm @@ -1392,13 +1392,19 @@ sub finalize_report { sub lookup_timespan { my ($timespan) = @_; - my (undef, undef, undef, $mday, $mon, $year) = localtime(time()); + my $now = time(); + my (undef, undef, undef, $mday, $mon, $year) = localtime($now); my $daystart = timelocal(0, 0, 0, $mday, $mon, $year); my $start; my $end; - if ($timespan eq 'today') { + if ($timespan =~ m/^(\d{1,2})h$/) { + my $hours = int($1); + die "invalid hour timespan '$timespan'\n" if $hours < 1 || $hours > 24; + $end = $now; + $start = $end - $hours * 3600; + } elsif ($timespan eq 'today') { $start = $daystart; $end = $start + 86400; } elsif ($timespan eq 'yesterday') { diff --git a/src/templates/spamreport-short.tt b/src/templates/spamreport-short.tt index 5c88389..53c6b15 100644 --- a/src/templates/spamreport-short.tt +++ b/src/templates/spamreport-short.tt @@ -1,6 +1,8 @@ [%- IF timespan == 'week' -%] [%- SET title = "Weekly Spam Report for '${pmail}' - ${date}'" -%] -[%- ELSE %] +[%- ELSIF timespan.substr(timespan.length - 1) == 'h' -%] +[%- SET title = "Spam Report (last ${timespan}) for '${pmail}' - ${date}" -%] +[%- ELSE -%] [%- SET title = "Daily Spam Report for '${pmail}' - ${date}" -%] [%- END -%] diff --git a/src/templates/spamreport-verbose.tt b/src/templates/spamreport-verbose.tt index 2b2915d..9b7032e 100644 --- a/src/templates/spamreport-verbose.tt +++ b/src/templates/spamreport-verbose.tt @@ -1,6 +1,8 @@ [%- IF timespan == 'week' -%] [%- SET title = "Weekly Spam Report for '${pmail}' - ${date}'" -%] -[%- ELSE %] +[%- ELSIF timespan.substr(timespan.length - 1) == 'h' -%] +[%- SET title = "Spam Report (last ${timespan}) for '${pmail}' - ${date}" -%] +[%- ELSE -%] [%- SET title = "Daily Spam Report for '${pmail}' - ${date}" -%] [%- END -%] -- 2.47.2 _______________________________________________ pmg-devel mailing list pmg-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel