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 38A4F94272 for ; Fri, 9 Feb 2024 13:55:12 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 73A47395F1 for ; Fri, 9 Feb 2024 13:54:45 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 for ; Fri, 9 Feb 2024 13:54:43 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6F02746838 for ; Fri, 9 Feb 2024 13:54:43 +0100 (CET) From: Dominik Csapak To: pmg-devel@lists.proxmox.com Date: Fri, 9 Feb 2024 13:54:36 +0100 Message-Id: <20240209125440.2572239-13-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240209125440.2572239-1-d.csapak@proxmox.com> References: <20240209125440.2572239-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.020 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pmg-devel] [PATCH pmg-api 12/12] pmgdb: extend dump output to include add/invert 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: , X-List-Received-Date: Fri, 09 Feb 2024 12:55:12 -0000 if a group type has and/invert set, add a line with that information and for each object group add its mode too in parenthesis Signed-off-by: Dominik Csapak --- src/PMG/CLI/pmgdb.pm | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/PMG/CLI/pmgdb.pm b/src/PMG/CLI/pmgdb.pm index 8368af8..cd94c23 100644 --- a/src/PMG/CLI/pmgdb.pm +++ b/src/PMG/CLI/pmgdb.pm @@ -40,6 +40,8 @@ sub print_objects { sub print_rule { my ($ruledb, $rule) = @_; + $ruledb->load_rule_attributes($rule); + my $direction = { 0 => 'in', 1 => 'out', @@ -52,26 +54,50 @@ sub print_rule { print "Found RULE $rule->{id} (prio: $rule->{priority}, $dir, $active): $rulename\n"; my $print_group = sub { - my ($type, $og) = @_; + my ($type, $og, $print_mode) = @_; my $oname = encode('UTF-8', $og->{name}); - print " FOUND $type GROUP $og->{id}: $oname\n"; + my $mode = ""; + if ($print_mode) { + my $and = $og->{and} // 0; + my $invert = $og->{invert} // 0; + $mode = " (and=$and, invert=$invert)"; + } + print " FOUND $type GROUP $og->{id}${mode}: $oname\n"; print_objects($ruledb, $og); }; + my $print_type_mode = sub { + my ($type) = @_; + my $and = $rule->{"$type-and"}; + my $invert = $rule->{"$type-invert"}; + if (defined($and) || defined($invert)) { + my $print_type = uc($type); + print " $print_type mode: and=" . ($and // 0) . " invert=". ($invert // 0) . "\n"; + } + }; + my ($from, $to, $when, $what, $action) = $ruledb->load_groups($rule); + $print_type_mode->("from") if scalar(@$from); foreach my $og (@$from) { - $print_group->("FROM", $og); + $ruledb->load_group_attributes($og); + $print_group->("FROM", $og, 1); } + $print_type_mode->("to") if scalar(@$to); foreach my $og (@$to) { - $print_group->("TO", $og); + $ruledb->load_group_attributes($og); + $print_group->("TO", $og, 1); } + $print_type_mode->("when") if scalar(@$when); foreach my $og (@$when) { - $print_group->("WHEN", $og); + $ruledb->load_group_attributes($og); + $print_group->("WHEN", $og, 1); } + $print_type_mode->("what") if scalar(@$what); foreach my $og (@$what) { - $print_group->("WHAT", $og); + $ruledb->load_group_attributes($og); + $print_group->("WHAT", $og, 1); } foreach my $og (@$action) { $print_group->("ACTION", $og); -- 2.30.2