From 5f85594b323ff06d6783e20d62afeb8b38732346 Mon Sep 17 00:00:00 2001 From: mwiegand Date: Sat, 9 Oct 2021 22:15:03 +0200 Subject: [PATCH] wip --- bin/{script-template => script_template} | 0 bin/wireguard_client_config | 26 ++++++++++++++++++++++++ bundles/wireguard/metadata.py | 1 + 3 files changed, 27 insertions(+) rename bin/{script-template => script_template} (100%) create mode 100755 bin/wireguard_client_config diff --git a/bin/script-template b/bin/script_template similarity index 100% rename from bin/script-template rename to bin/script_template diff --git a/bin/wireguard_client_config b/bin/wireguard_client_config new file mode 100755 index 0000000..bdeb940 --- /dev/null +++ b/bin/wireguard_client_config @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +from bundlewrap.repo import Repository +from os.path import realpath, dirname +from sys import argv +from ipaddress import ip_network, ip_interface + + +repo = Repository(dirname(dirname(realpath(__file__)))) +server_node = repo.get_node('htz.mails') +data = server_node.metadata.get(f'wireguard/clients/{argv[1]}') + +print( +f'''[Interface] +PrivateKey = {data['privkey']} +ListenPort = 51820 +Address = {data['ip']} +DNS = 8.8.8.8 + +[Peer] +PublicKey = {data['pubkey']} +PresharedKey = {data['psk']} +AllowedIPs = 10.0.0.0/16 +Endpoint = {str(ip_interface(server_node.metadata.get('network/external/ipv4')).ip)}:51820 +PersistentKeepalive = 10''' +) diff --git a/bundles/wireguard/metadata.py b/bundles/wireguard/metadata.py index eb97336..4ec3618 100644 --- a/bundles/wireguard/metadata.py +++ b/bundles/wireguard/metadata.py @@ -153,6 +153,7 @@ def client_peer_specific(metadata): @metadata_reactor.provides( 'wireguard/peers', + 'wireguard/clients', ) def common_peer_data(metadata): peers = {