wireguard: Create function for building conf files

Signed-off-by: Frederico Gomes <fredericojfgomes@gmail.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Frederico Gomes authored and James Valleroy committed 2026-05-23 08:54:03 -04:00
1 parent 81e60dff0e
commit bb6729a99a
1 file changed
+22
+22
View File
@@ -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"""