]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
wireguard-functions.pl: Add a simple function to check if enabled
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 26 May 2025 09:31:54 +0000 (11:31 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 26 May 2025 09:31:54 +0000 (11:31 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/cfgroot/wireguard-functions.pl
html/cgi-bin/wireguard.cgi

index 11451a6153bb0440936abc96fd9377b2185b39b2..e8650e7d5c49aa9e8ab6c539b0c257d62dd7ae10 100644 (file)
@@ -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'};
index 6fc01c4045fd9903397680f34f11bf7390f07d78..b9661948c9d7ebd046539db4c077bdf44e7b395c 100644 (file)
@@ -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 = (