From: Michael Tremer Date: Mon, 26 May 2025 09:31:54 +0000 (+0200) Subject: wireguard-functions.pl: Add a simple function to check if enabled X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fbbaa19d13a828a98170fb3b23330189e9eed1d5;p=ipfire-2.x.git wireguard-functions.pl: Add a simple function to check if enabled Signed-off-by: Michael Tremer --- diff --git a/config/cfgroot/wireguard-functions.pl b/config/cfgroot/wireguard-functions.pl index 11451a615..e8650e7d5 100644 --- a/config/cfgroot/wireguard-functions.pl +++ b/config/cfgroot/wireguard-functions.pl @@ -52,6 +52,11 @@ if (-e "/var/ipfire/wireguard/peers") { "CLIENT_DNS" => $Network::ethernet{'GREEN_ADDRESS'}, }); +# Returns true if WireGuard is enabled +sub is_enabled() { + return ($settings{'ENABLED'} eq "on"); +} + # Returns the local endpoint sub get_endpoint() { my $endpoint = $settings{'ENDPOINT'}; diff --git a/html/cgi-bin/wireguard.cgi b/html/cgi-bin/wireguard.cgi index 6fc01c404..b9661948c 100644 --- a/html/cgi-bin/wireguard.cgi +++ b/html/cgi-bin/wireguard.cgi @@ -94,7 +94,7 @@ if ($cgiparams{"ACTION"} eq $Lang::tr{'save'}) { &General::writehash("/var/ipfire/wireguard/settings", \%Wireguard::settings); # Start if enabled - if ($Wireguard::settings{'ENABLED'} eq "on") { + if (&Wireguard::is_enabled()) { &General::system("/usr/local/bin/wireguardctrl", "start"); } else { &General::system("/usr/local/bin/wireguardctrl", "stop"); @@ -117,7 +117,7 @@ if ($cgiparams{"ACTION"} eq $Lang::tr{'save'}) { &General::writehasharray("/var/ipfire/wireguard/peers", \%Wireguard::peers); # Reload if enabled - if ($Wireguard::settings{'ENABLED'} eq "on") { + if (&Wireguard::is_enabled()) { &General::system("/usr/local/bin/wireguardctrl", "start"); } @@ -230,7 +230,7 @@ if ($cgiparams{"ACTION"} eq $Lang::tr{'save'}) { &General::writehasharray("/var/ipfire/wireguard/peers", \%Wireguard::peers); # Reload if enabled - if ($Wireguard::settings{'ENABLED'} eq "on") { + if (&Wireguard::is_enabled()) { &General::system("/usr/local/bin/wireguardctrl", "start"); } @@ -349,7 +349,7 @@ if ($cgiparams{"ACTION"} eq $Lang::tr{'save'}) { &General::writehasharray("/var/ipfire/wireguard/peers", \%Wireguard::peers); # Reload if enabled - if ($Wireguard::settings{'ENABLED'} eq "on") { + if (&Wireguard::is_enabled()) { &General::system("/usr/local/bin/wireguardctrl", "start"); } @@ -534,7 +534,7 @@ END &General::writehasharray("/var/ipfire/wireguard/peers", \%Wireguard::peers); # Reload if enabled - if ($Wireguard::settings{'ENABLED'} eq "on") { + if (&Wireguard::is_enabled()) { &General::system("/usr/local/bin/wireguardctrl", "start"); } @@ -649,7 +649,7 @@ END &General::writehasharray("/var/ipfire/wireguard/peers", \%Wireguard::peers); # Reload if enabled - if ($Wireguard::settings{'ENABLED'} eq "on") { + if (&Wireguard::is_enabled()) { &General::system("/usr/local/bin/wireguardctrl", "start"); } @@ -765,7 +765,7 @@ END &General::writehasharray("/var/ipfire/wireguard/peers", \%Wireguard::peers); # Reload if enabled - if ($Wireguard::settings{'ENABLED'} eq "on") { + if (&Wireguard::is_enabled()) { &General::system("/usr/local/bin/wireguardctrl", "start"); } } @@ -785,7 +785,7 @@ MAIN: &Header::openbox('100%', '', $Lang::tr{'global settings'}); my %checked = ( - "ENABLED" => ($Wireguard::settings{'ENABLED'} eq "on") ? "checked" : "", + "ENABLED" => (&Wireguard::is_enabled()) ? "checked" : "", ); my %readonly = (