From: Michael Tremer Date: Fri, 27 Sep 2024 15:55:46 +0000 (+0200) Subject: wireguard.cgi: Normalize filenames X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=37174e29de670a33f9be4b90c88b0a96c695dad1;p=people%2Fms%2Fipfire-2.x.git wireguard.cgi: Normalize filenames This is because Windows clients won't import any configurations that have spaces in the filename. Therefore we replace it and remove anything else unwanted on the way. Signed-off-by: Michael Tremer --- diff --git a/config/cfgroot/header.pl b/config/cfgroot/header.pl index 2d4aa89f2..5a4d41308 100644 --- a/config/cfgroot/header.pl +++ b/config/cfgroot/header.pl @@ -17,6 +17,7 @@ use HTML::Entities(); use Socket; use Time::Local; use Encode; +use Unicode::Normalize; require "${General::swroot}/graphs.pl"; @@ -628,6 +629,18 @@ sub escape($) { return HTML::Entities::encode_entities($s); } +sub normalize($) { + my $s = shift; + + # Remove any special characters + $s = &Unicode::Normalize::NFKD($s); + + # Remove any whitespace and replace with dash + $s =~ s/\s+/\-/g; + + return $s; +} + sub cleanhtml { my $outstring =$_[0]; $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y'; diff --git a/html/cgi-bin/wireguard.cgi b/html/cgi-bin/wireguard.cgi index a626358ec..8e91a2f48 100644 --- a/html/cgi-bin/wireguard.cgi +++ b/html/cgi-bin/wireguard.cgi @@ -1028,6 +1028,9 @@ sub show_peer_configuration($$) { # Open a new box &Header::openbox('100%', '', "$Lang::tr{'wg peer configuration'}: $peer{'NAME'}"); + # Make the filename for files + my $filename = &Header::normalize($peer{'NAME'}) . ".conf"; + print <

@@ -1039,7 +1042,7 @@ sub show_peer_configuration($$) {

- + $Lang::tr{'wg download configuration file'}