]> git.ipfire.org Git - people/mfischer/ipfire-2.x.git/commitdiff
wireguard-functions.pl: Return a hash reference instead of a hash when loading a...
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Apr 2025 17:47:23 +0000 (19:47 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Apr 2025 17:47:23 +0000 (19:47 +0200)
Perl is so absolutely fucking broken and dealing with hashes is such a
massive pain in the rear. I don't want to see this any more.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/cfgroot/wireguard-functions.pl
html/cgi-bin/firewall.cgi
html/cgi-bin/wireguard.cgi

index d38a469185217f79cf7d1a02fc20cfe40424360c..ab1e4a49b8f99457e14bdcc19957ccabc081fcd5 100644 (file)
@@ -186,18 +186,18 @@ sub load_peer($) {
                "KEEPALIVE"             => $peers{$key}[12],
        );
 
-       return %peer;
+       return \%peer;
 }
 
 sub get_peer_by_name($) {
        my $name = shift;
 
        foreach my $key (keys %peers) {
-               my %peer = &load_peer($key);
+               my $peer = &load_peer($key);
 
                # Return the peer if the name matches
-               if ($peer{"NAME"} eq $name) {
-                       return %peer;
+               if ($peer->{"NAME"} eq $name) {
+                       return $peer;
                }
        }
 
@@ -373,15 +373,15 @@ sub generate_peer_configuration($$) {
        my @conf = ();
 
        # Load the peer
-       my %peer = &load_peer($key);
+       my $peer = &load_peer($key);
 
        # Return if we could not find the peer
-       return undef unless (%peer);
+       return undef unless ($peer);
 
        my @allowed_ips = ();
 
        # Convert all subnets into CIDR notation
-       foreach my $subnet ($peer{'LOCAL_SUBNETS'}) {
+       foreach my $subnet ($peer->{'LOCAL_SUBNETS'}) {
                my $netaddress = &Network::get_netaddress($subnet);
                my $prefix     = &Network::get_prefix($subnet);
 
@@ -395,32 +395,32 @@ sub generate_peer_configuration($$) {
        my $endpoint = &get_endpoint();
 
        # Net-2-Net
-       if ($peer{'TYPE'} eq "net") {
+       if ($peer->{'TYPE'} eq "net") {
                # Derive our own public key
-               my $public_key = &derive_public_key($peer{'PRIVATE_KEY'});
+               my $public_key = &derive_public_key($peer->{'PRIVATE_KEY'});
 
                push(@conf,
                        "[Interface]",
                        "PrivateKey = $private_key",
-                       "Port = $peer{'ENDPOINT_PORT'}",
+                       "Port = $peer->{'ENDPOINT_PORT'}",
                        "",
                        "[Peer]",
-                       "Endpoint = ${endpoint}:$peer{'PORT'}",
+                       "Endpoint = ${endpoint}:$peer->{'PORT'}",
                        "PublicKey = $public_key",
-                       "PresharedKey = $peer{'PSK'}",
+                       "PresharedKey = $peer->{'PSK'}",
                        "AllowedIPs = " . join(", ", @allowed_ips),
-                       "PersistentKeepalive = $peer{'KEEPALIVE'}",
+                       "PersistentKeepalive = $peer->{'KEEPALIVE'}",
                );
 
        # Host-2-Net
-       } elsif ($peer{'TYPE'} eq "host") {
+       } elsif ($peer->{'TYPE'} eq "host") {
                # Fetch any DNS servers for hosts
                my @dns = split(/\|/, $settings{'CLIENT_DNS'});
 
                push(@conf,
                        "[Interface]",
                        "PrivateKey = $private_key",
-                       "Address = $peer{'CLIENT_ADDRESS'}",
+                       "Address = $peer->{'CLIENT_ADDRESS'}",
                );
 
                # Optionally add DNS servers
@@ -436,7 +436,7 @@ sub generate_peer_configuration($$) {
                        "[Peer]",
                        "Endpoint = ${endpoint}:$settings{'PORT'}",
                        "PublicKey = $settings{'PUBLIC_KEY'}",
-                       "PresharedKey = $peer{'PSK'}",
+                       "PresharedKey = $peer->{'PSK'}",
                        "AllowedIPs = " . join(", ", @allowed_ips),
                        "PersistentKeepalive = $DEFAULT_KEEPALIVE",
                ));
index 3c02a9a92ac18698e42bcace93b1371c4e867436..855be095d02c991705f1b3e4fb118e7297a93e3f 100644 (file)
@@ -1202,13 +1202,13 @@ EOF
                        # Sort peers by name
                        foreach my $key (sort { $Wireguard::peers{$a}[2] cmp $Wireguard::peers{$b}[2] } keys %Wireguard::peers) {
                                # Load the peer
-                               my %peer = &Wireguard::load_peer($key);
+                               my $peer = &Wireguard::load_peer($key);
 
                                # Is this peer selected?
-                               my $selected = ($fwdfwsettings{$fwdfwsettings{$grp}} eq $peer{'NAME'}) ? "selected" : "";
+                               my $selected = ($fwdfwsettings{$fwdfwsettings{$grp}} eq $peer->{'NAME'}) ? "selected" : "";
 
                                print <<EOF;
-                                       <option value="$peer{'NAME'}" $selected>$peer{'NAME'}</option>
+                                       <option value="$peer->{'NAME'}" $selected>$peer->{'NAME'}</option>
 EOF
                        }
 
index 8e763540adbc901bb882f2908af34b9ac4e5160b..8bfb5df95230595b6f22f623c6ec7e0ddd7366ff 100644 (file)
@@ -332,7 +332,7 @@ END
        my $key = $cgiparams{'KEY'};
 
        # Load the existing peer
-       my %peer = &Wireguard::load_peer($key);
+       my $peer = &Wireguard::load_peer($key);
 
        # Check if the name is valid
        unless (&Wireguard::name_is_valid($cgiparams{"NAME"})) {
@@ -432,7 +432,7 @@ END
                # 3 = Public Key
                $cgiparams{"PUBLIC_KEY"},
                # 4 = Private Key
-               $peer{"PRIVATE_KEY"},
+               $peer->{"PRIVATE_KEY"},
                # 5 = Port
                $cgiparams{"PORT"},
                # 6 = Endpoint Address
@@ -581,7 +581,7 @@ END
                &Header::openpage($Lang::tr{'wireguard'}, 1, '');
 
                # Load the peer
-               my %peer = &Wireguard::load_peer($key);
+               my $peer = &Wireguard::load_peer($key);
 
                # Generate the client configuration
                my $config = &Wireguard::generate_peer_configuration($key, $private_key);
@@ -614,10 +614,10 @@ END
                $config = &MIME::Base64::encode_base64($config);
 
                # Open a new box
-               &Header::openbox('100%', '', "$Lang::tr{'wg peer configuration'}: $peer{'NAME'}");
+               &Header::openbox('100%', '', "$Lang::tr{'wg peer configuration'}: $peer->{'NAME'}");
 
                # Make the filename for files
-               my $filename = &Header::normalize($peer{'NAME'}) . ".conf";
+               my $filename = &Header::normalize($peer->{'NAME'}) . ".conf";
 
                print <<END;
                        <div class="text-center">