]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
wireguard.cgi: Normalize filenames
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Sep 2024 15:55:46 +0000 (17:55 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Apr 2025 14:48:53 +0000 (16:48 +0200)
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 <michael.tremer@ipfire.org>
config/cfgroot/header.pl
html/cgi-bin/wireguard.cgi

index 2d4aa89f24623f52aae634b8fef707076fc88762..5a4d413081c7ffe48373e0c6158a29ee9859dcdd 100644 (file)
@@ -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';
index a626358ec31ee65fb6e921e8996e320434dfdbfe..8e91a2f48b10ae391836cb322dcab3db479698aa 100644 (file)
@@ -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 <<END;
                <div class="text-center">
                        <p>
@@ -1039,7 +1042,7 @@ sub show_peer_configuration($$) {
                        </p>
 
                        <p>
-                               <a href="data:text/plain;base64,${config}" download="$peer{'NAME'}.conf">
+                               <a href="data:text/plain;base64,${config}" download="${filename}">
                                        $Lang::tr{'wg download configuration file'}
                                </a>
                        </p>