From: Carsten Haerle <carsten.haerle@straightec.de>
To: pmg-devel@lists.proxmox.com
Cc: Carsten Haerle <carsten.haerle@straightec.de>
Subject: [PATCH pmg-api 3/6] fix #8231: api: mynetworks: optionally list automatically trusted networks
Date: Mon, 26 Oct 2026 10:58:48 +0100 [thread overview]
Message-ID: <20261026095852.3243241-4-carsten.haerle@straightec.de> (raw)
In-Reply-To: <20261026095852.3243241-1-carsten.haerle@straightec.de>
With 'automatic=1' the index also returns the networks that are added
to mynetworks automatically, marked with 'automatic: 1' and a comment
that tells where each entry comes from and where it is configured. A
configured entry for the same network takes precedence.
Without the parameter the result is unchanged, so existing API users
that iterate over and modify the list are not affected.
Signed-off-by: Carsten Haerle <carsten.haerle@straightec.de>
---
src/PMG/API2/MyNetworks.pm | 44 +++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/src/PMG/API2/MyNetworks.pm b/src/PMG/API2/MyNetworks.pm
index 565b6f8..30bf448 100644
--- a/src/PMG/API2/MyNetworks.pm
+++ b/src/PMG/API2/MyNetworks.pm
@@ -11,6 +11,7 @@ use PVE::JSONSchema qw(get_standard_option);
use PVE::RESTHandler;
use PVE::INotify;
+use PMG::Cluster;
use PMG::Config;
use base qw(PVE::RESTHandler);
@@ -25,7 +26,15 @@ __PACKAGE__->register_method({
permissions => { check => ['admin', 'audit'] },
parameters => {
additionalProperties => 0,
- properties => {},
+ properties => {
+ automatic => {
+ description => "Also list the networks that are trusted automatically"
+ . " (local network, default relay, transport hosts).",
+ type => 'boolean',
+ optional => 1,
+ default => 0,
+ },
+ },
},
returns => {
type => 'array',
@@ -33,6 +42,12 @@ __PACKAGE__->register_method({
type => "object",
properties => {
cidr => { type => 'string' },
+ comment => { type => 'string', optional => 1 },
+ automatic => {
+ description => "Trusted automatically, cannot be modified here.",
+ type => 'boolean',
+ optional => 1,
+ },
},
},
links => [{ rel => 'child', href => "{cidr}" }],
@@ -48,6 +63,33 @@ __PACKAGE__->register_method({
push @$res, $mynetworks->{$cidr};
}
+ return $res if !$param->{automatic};
+
+ my $cfg = PMG::Config->new();
+ my $nodename = PVE::INotify::nodename();
+ my $int_ip = PMG::Cluster::remote_node_ip($nodename);
+ my $automatic = $cfg->get_automatic_mynetworks($int_ip);
+
+ foreach my $cidr (sort keys %$automatic) {
+ next if $mynetworks->{$cidr}; # a configured entry takes precedence
+
+ my $origin = $automatic->{$cidr};
+ my @why;
+ push @why, "local network of node '$nodename' (Options: Trust Local Network)"
+ if $origin->{local};
+ push @why, "default relay (Relaying)" if $origin->{relay};
+ if (my $domains = $origin->{transport}) {
+ push @why, "transport for " . join(', ', $domains->@*) . " (Transports)";
+ }
+
+ my $entry = {
+ cidr => $cidr,
+ comment => 'automatic: ' . join('; ', @why),
+ automatic => 1,
+ };
+ push @$res, $entry;
+ }
+
return $res;
},
});
--
2.53.0
next prev parent reply other threads:[~2026-10-27 9:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 9:58 [PATCH pmg-api/pmg-gui/pmg-docs 0/6] fix #8231: mail proxy: make automatically trusted networks visible and the local network optional Carsten Haerle
2026-10-26 9:58 ` [PATCH pmg-api 1/6] fix #8231: config: add option to not trust the local network automatically Carsten Haerle
2026-10-26 9:58 ` [PATCH pmg-api 2/6] config: factor out automatically trusted networks Carsten Haerle
2026-10-26 9:58 ` Carsten Haerle [this message]
2026-10-26 9:58 ` [PATCH pmg-api 4/6] fix #8231: config: resolve relay and transport host names for mynetworks Carsten Haerle
2026-10-26 9:58 ` [PATCH pmg-gui 5/6] fix #8231: mail proxy: add trust local network option, show automatic networks Carsten Haerle
2026-10-26 9:58 ` [PATCH pmg-docs 6/6] mail proxy: networks: document automatically trusted networks Carsten Haerle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261026095852.3243241-4-carsten.haerle@straightec.de \
--to=carsten.haerle@straightec.de \
--cc=pmg-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox