"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;
}
}
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);
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
"[Peer]",
"Endpoint = ${endpoint}:$settings{'PORT'}",
"PublicKey = $settings{'PUBLIC_KEY'}",
- "PresharedKey = $peer{'PSK'}",
+ "PresharedKey = $peer->{'PSK'}",
"AllowedIPs = " . join(", ", @allowed_ips),
"PersistentKeepalive = $DEFAULT_KEEPALIVE",
));
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"})) {
# 3 = Public Key
$cgiparams{"PUBLIC_KEY"},
# 4 = Private Key
- $peer{"PRIVATE_KEY"},
+ $peer->{"PRIVATE_KEY"},
# 5 = Port
$cgiparams{"PORT"},
# 6 = Endpoint Address
&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);
$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">