From: Michael Tremer Date: Fri, 25 Apr 2025 12:53:07 +0000 (+0200) Subject: wireguard.cgi: Normalize the pool address X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=08f60babc98dad3b37c626867f2530998f5ca81c;p=people%2Fstevee%2Fipfire-2.x.git wireguard.cgi: Normalize the pool address Signed-off-by: Michael Tremer --- diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl index 37a436253..ad89fc777 100644 --- a/config/cfgroot/network-functions.pl +++ b/config/cfgroot/network-functions.pl @@ -331,6 +331,19 @@ sub get_netmask($) { return &convert_prefix2netmask($prefix); } +sub normalize_network($) { + my $network = shift; + + my $address = &get_netaddress($network); + my $prefix = &get_prefix($network); + + unless (defined $address && defined $prefix) { + return undef; + } + + return "${address}/${prefix}"; +} + # Returns True if $address is in $network. sub ip_address_in_network($$) { my $address = shift; diff --git a/html/cgi-bin/wireguard.cgi b/html/cgi-bin/wireguard.cgi index cc79347a6..6213fd342 100644 --- a/html/cgi-bin/wireguard.cgi +++ b/html/cgi-bin/wireguard.cgi @@ -68,7 +68,7 @@ if ($cgiparams{"ACTION"} eq $Lang::tr{'save'}) { if (&Wireguard::pool_is_in_use($Wireguard::settings{'CLIENT_POOL'})) { # Ignore any changes if the pool is in use } elsif (&Network::check_subnet($cgiparams{'CLIENT_POOL'})) { - $Wireguard::settings{'CLIENT_POOL'} = $cgiparams{'CLIENT_POOL'}; + $Wireguard::settings{'CLIENT_POOL'} = &Network::normalize_network($cgiparams{'CLIENT_POOL'}); } elsif ($cgiparams{'CLIENT_POOL'} ne '') { push(@errormessages, $Lang::tr{'wg invalid client pool'}); }