From bb6729a99a1dba583794f03e3bbba152dbf45c5f Mon Sep 17 00:00:00 2001 From: Frederico Gomes Date: Sun, 22 Mar 2026 13:03:14 +0000 Subject: [PATCH] wireguard: Create function for building conf files Signed-off-by: Frederico Gomes Reviewed-by: James Valleroy --- plinth/modules/wireguard/utils.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/plinth/modules/wireguard/utils.py b/plinth/modules/wireguard/utils.py index cdcc19268..7e632c0dd 100644 --- a/plinth/modules/wireguard/utils.py +++ b/plinth/modules/wireguard/utils.py @@ -310,3 +310,25 @@ def remove_client(public_key): settings.remove_peer(peer_index) connection.commit_changes(True) network.reactivate_connection(connection.get_uuid()) + + +def build_client_config(client_ip: str, client_privkey: str, + client_pubkey: str, endpoint: str) -> str: + """Generate WireGuard client config.""" + info = get_info() + server_info = info['my_server'] + if not server_info: + raise RuntimeError("WireGuard server not configured") + + server_pubkey = server_info['public_key'] + + return f"""[Interface] +PrivateKey = {client_privkey} +Address = {client_ip}/32 +DNS = 10.84.0.1 + +[Peer] +PublicKey = {server_pubkey} +AllowedIPs = 0.0.0.0/0 +Endpoint = {endpoint} +PersistentKeepalive = 25"""