Get/set pub+priv keys, create wg0.conf

This commit is contained in:
billz
2021-02-24 18:07:19 +00:00
parent 9bbf698b6a
commit 3ec81ba085
4 changed files with 33 additions and 31 deletions

View File

@@ -4,7 +4,7 @@ require '../../includes/csrf.php';
require_once '../../includes/config.php';
$entity = $_POST['entity'];
if (isset($entity)) {
// generate public/private key pairs for entity
@@ -14,9 +14,10 @@ if (isset($entity)) {
$privkey_tmp = '/tmp/'.$entity.'-private.key';
exec("sudo wg genkey | tee $privkey_tmp | wg pubkey > $pubkey_tmp", $return);
$entity_pubkey = str_replace("\n",'',file_get_contents($pubkey_tmp));
$wgdata['pubkey'] = str_replace("\n",'',file_get_contents($pubkey_tmp));
$wgdata['privkey'] = str_replace("\n",'',file_get_contents($privkey_tmp));
exec("sudo mv $privkey_tmp $privkey", $return);
exec("sudo mv $pubkey_tmp $pubkey", $return);
echo json_encode($entity_pubkey);
echo json_encode($wgdata);
}