From cb7e2a7d908f0db7201f2b3d7c4fded3caba8586 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 25 Apr 2024 20:13:56 +0200 Subject: [PATCH] wireguard.cgi: Implement toggle enable/disable peers Signed-off-by: Michael Tremer --- html/cgi-bin/wireguard.cgi | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/html/cgi-bin/wireguard.cgi b/html/cgi-bin/wireguard.cgi index 80b793c64..e7e324abe 100644 --- a/html/cgi-bin/wireguard.cgi +++ b/html/cgi-bin/wireguard.cgi @@ -411,6 +411,26 @@ if ($cgiparams{"ACTION"} eq $Lang::tr{'save'}) { } else { goto ADD; } + +# Toggle Enable/Disable +} elsif ($cgiparams{'ACTION'} eq 'TOGGLE-ENABLE-DISABLE') { + my $key = $cgiparams{'KEY'} || 0; + + if (exists $peers{$key}) { + if ($peers{$key}[0] eq "on") { + $peers{$key}[0] = "off"; + } else { + $peers{$key}[0] = "on"; + } + } + + # Store the configuration + &General::writehasharray("/var/ipfire/wireguard/peers", \%peers); + + # Reload if enabled + if ($settings{'ENABLED'} eq "on") { + &General::system("/usr/local/bin/wireguardctrl", "start"); + } } # The main page starts here @@ -601,7 +621,7 @@ EOF
- +
-- 2.39.5