vpn.keks.cloud/app/Helper/WGKey.php
2020-11-08 03:07:10 +01:00

17 lines
568 B
PHP

<?php
namespace App\Helper;
class WGKey
{
static public function generatePrivateKeyForPeer() {
$folder = sys_get_temp_dir()."/".uniqid("wg-");
mkdir($folder);
exec("cd ".$folder."; wg genkey > privkey; cat privkey | wg pubkey > pubkey; wg genpsk > presharedkey");
$keys = [];
$keys["public"] = trim(file_get_contents($folder."/pubkey"));
$keys["privkey"] = trim(file_get_contents($folder."/privkey"));
$keys["presharedkey"] = trim(file_get_contents($folder."/presharedkey"));
return $keys;
}
}