From: Michael Tremer Date: Tue, 22 Apr 2025 16:09:31 +0000 (+0200) Subject: firewall.cgi: Highlight any deleted WireGuard peers X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=77631ba4c738432c31cd4b6fad0da28b880fb0c7;p=people%2Fstevee%2Fipfire-2.x.git firewall.cgi: Highlight any deleted WireGuard peers Signed-off-by: Michael Tremer --- diff --git a/config/cfgroot/wireguard-functions.pl b/config/cfgroot/wireguard-functions.pl index 82bcb27a4..d38a46918 100644 --- a/config/cfgroot/wireguard-functions.pl +++ b/config/cfgroot/wireguard-functions.pl @@ -189,6 +189,22 @@ sub load_peer($) { return %peer; } +sub get_peer_by_name($) { + my $name = shift; + + foreach my $key (keys %peers) { + my %peer = &load_peer($key); + + # Return the peer if the name matches + if ($peer{"NAME"} eq $name) { + return %peer; + } + } + + # Return undefined if nothing was found + return undef; +} + sub name_is_valid($) { my $name = shift; diff --git a/html/cgi-bin/firewall.cgi b/html/cgi-bin/firewall.cgi index e245ee2a1..842ad731f 100644 --- a/html/cgi-bin/firewall.cgi +++ b/html/cgi-bin/firewall.cgi @@ -2586,10 +2586,10 @@ END @tmpsrc=(); @tmptgt=(); #check if vpn hosts/nets have been deleted - if($$hash{$key}[3] =~ /ipsec/i || $$hash{$key}[3] =~ /ovpn/i){ + if($$hash{$key}[3] =~ /ipsec/i || $$hash{$key}[3] =~ /^wg_/ || $$hash{$key}[3] =~ /ovpn/i){ push (@tmpsrc,$$hash{$key}[4]); } - if($$hash{$key}[5] =~ /ipsec/i || $$hash{$key}[5] =~ /ovpn/i){ + if($$hash{$key}[5] =~ /ipsec/i || $$hash{$key}[5] =~ /^wg_/ || $$hash{$key}[5] =~ /ovpn/i){ push (@tmptgt,$$hash{$key}[6]); } foreach my $host (@tmpsrc){ @@ -2609,6 +2609,10 @@ END if(&fwlib::get_ovpn_host_ip($host,33) eq ''){ $coloryellow='on'; } + } elsif ($$hash{$key}[3] eq 'wg_host_src') { + if (!defined &Wireguard::get_peer_by_name($host)) { + $coloryellow = 'on'; + } } } foreach my $host (@tmptgt){ @@ -2628,6 +2632,10 @@ END if(&fwlib::get_ovpn_host_ip($host,33) eq ''){ $coloryellow='on'; } + } elsif ($$hash{$key}[3] eq 'wg_host_tgt') { + if (!defined &Wireguard::get_peer_by_name($host)) { + $coloryellow = 'on'; + } } } #check if networkgroups or servicegroups are empty