mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
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:
parent
81e60dff0e
commit
bb6729a99a
@ -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"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user