Output text configs #2

Open
Fedor-Lyanguzov wants to merge 6 commits from output-text-files into main
Showing only changes of commit 1b37f1b57d - Show all commits
+18 -21
View File
@@ -1,5 +1,4 @@
from dataclasses import dataclass from dataclasses import dataclass
from textwrap import dedent
@dataclass @dataclass
@@ -12,22 +11,20 @@ class Peer:
def format_static_peer(static_peer, routes, keepalive=30): def format_static_peer(static_peer, routes, keepalive=30):
return f""" return (
[Peer] "[Peer]\n"
PublicKey = {static_peer.public_key} f"PublicKey = {static_peer.public_key}\n"
AllowedIPs = {routes} f"AllowedIPs = {routes}\n"
Endpoint = {static_peer.endpoint}:{static_peer.port} f"Endpoint = {static_peer.endpoint}:{static_peer.port}\n"
PersistentKeepAlive = {keepalive} f"PersistentKeepAlive = {keepalive}\n"
""".strip() ).strip()
def format_interface(peer, dns, forward=False): def format_interface(peer, dns, forward=False):
if forward: if forward:
forward = dedent( forward = (
"""\ "PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE\n"
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE "PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE\n"
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
"""
) )
# wg0 always? # wg0 always?
# eth0 always? # eth0 always?
@@ -38,11 +35,11 @@ def format_interface(peer, dns, forward=False):
else: else:
port = "" port = ""
dns = f"DNS = {dns}\n" dns = f"DNS = {dns}\n"
return f""" return (
[Interface] "[Interface]\n"
PrivateKey = {peer.private_key} f"PrivateKey = {peer.private_key}\n"
Address = {peer.address_cidr} f"Address = {peer.address_cidr}\n"
{port}\ f"{port}"
{dns}\ f"{dns}"
{forward}\ f"{forward}"
""".strip() ).strip()