} elsif ($cgiparams{"ACTION"} eq "SAVE-PEER-HOST") {
my @free_addresses = ();
my @local_subnets = ();
- my $private_key;
# Fetch or allocate a new key
my $key = $cgiparams{'KEY'} || &General::findhasharraykey(\%Wireguard::peers);
# Generate things for a new peer
if ($is_new) {
# Generate a new private key
- $private_key = &Wireguard::generate_private_key();
+ $cgiparams{"PRIVATE_KEY"} = &Wireguard::generate_private_key();
# Derive the public key
- $cgiparams{"PUBLIC_KEY"} = &Wireguard::derive_public_key($private_key);
+ $cgiparams{"PUBLIC_KEY"} = &Wireguard::derive_public_key($cgiparams{"PRIVATE_KEY"});
# Generate a new PSK
$cgiparams{"PSK"} = &Wireguard::generate_private_key();
# Fetch some configuration parts
} else {
$cgiparams{"PUBLIC_KEY"} = $Wireguard::peers{$key}[3];
+ $cgiparams{"PRIVATE_KEY"} = $Wireguard::peers{$key}[4];
$cgiparams{'CLIENT_ADDRESS'} = $Wireguard::peers{$key}[8];
$cgiparams{"PSK"} = $Wireguard::peers{$key}[11];
}
# 3 = Public Key
$cgiparams{"PUBLIC_KEY"},
# 4 = Private Key
- "",
+ $cgiparams{"PRIVATE_KEY"},
# 5 = Port
"",
# 6 = Endpoint Address
}
# Show the client configuration when creating a new peer
- &show_peer_configuration($key, $private_key) if ($is_new);
+ &show_peer_configuration($key) if ($is_new);
} elsif ($cgiparams{"ACTION"} eq $Lang::tr{'add'}) {
if ($cgiparams{"TYPE"} eq "net") {
exit(0);
-sub show_peer_configuration($$) {
+sub show_peer_configuration($) {
my $key = shift;
- my $private_key = shift;
# The generated QR code
my $qrcode;
my %peer = (
"NAME" => $Wireguard::peers{$key}[2],
"PUBLIC_KEY" => $Wireguard::peers{$key}[3],
+ "PRIVATE_KEY" => $Wireguard::peers{$key}[4],
"CLIENT_ADDRESS" => $Wireguard::peers{$key}[8],
"LOCAL_SUBNETS" => &Wireguard::decode_subnets($Wireguard::peers{$key}[10]),
"PSK" => $Wireguard::peers{$key}[11],
-
- # Other stuff
- "PRIVATE_KEY" => $private_key,
);
# Generate the client configuration
</a>
</p>
- <p class="text-error">
- $Lang::tr{'wg warning configuration only shown once'}
- </p>
-
<p>
<form method="GET" action="">
<button type="submit">$Lang::tr{'done'}</button>