review
This commit is contained in:
parent
6dbbed1c7a
commit
c177ea56ea
2 changed files with 9 additions and 10 deletions
15
config.py
15
config.py
|
@ -6,16 +6,15 @@ from dataclasses import dataclass, InitVar
|
||||||
class Peer:
|
class Peer:
|
||||||
public_key: str
|
public_key: str
|
||||||
endpoint: str | None
|
endpoint: str | None
|
||||||
allowed_ips: str | None = None
|
allowed_ips: list = []
|
||||||
untranslated_networks: InitVar(str | None) = None
|
untranslated_networks: InitVar(str | None) = None
|
||||||
local_translated_range: InitVar(str)
|
local_translated_range: InitVar(str)
|
||||||
wireguard_address: InitVar(str)
|
wireguard_address: InitVar(str)
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
allowed = [self.local_translated_range, wireguard_address]
|
self.allowed_ips = [self.local_translated_range, wireguard_address]
|
||||||
if untranslated_networks != None:
|
if untranslated_networks != None:
|
||||||
allowed.append(untranslated_networks)
|
self.allowed_ips.append(untranslated_networks)
|
||||||
self.allowed_ips = ", ".join(allowed)
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Network:
|
class Network:
|
||||||
|
@ -58,7 +57,7 @@ class Config:
|
||||||
default_dns: DNSServer | None = None
|
default_dns: DNSServer | None = None
|
||||||
dns_servers: dict = {}
|
dns_servers: dict = {}
|
||||||
remote_networks: dict = {}
|
remote_networks: dict = {}
|
||||||
peers: array = []
|
peers: list = []
|
||||||
local_wireguard_address: str = ""
|
local_wireguard_address: str = ""
|
||||||
|
|
||||||
def __post_init__(self, default_dns_address, default_dns_port, data):
|
def __post_init__(self, default_dns_address, default_dns_port, data):
|
||||||
|
@ -106,20 +105,20 @@ class Config:
|
||||||
)
|
)
|
||||||
|
|
||||||
def dns_server(self, qname):
|
def dns_server(self, qname):
|
||||||
# Guess which DNS server call from the requested domain name
|
"""Guess which DNS server call from the requested domain name"""
|
||||||
for dns in self.dns_servers.values():
|
for dns in self.dns_servers.values():
|
||||||
if dns.is_same_zone(qname):
|
if dns.is_same_zone(qname):
|
||||||
return dns
|
return dns
|
||||||
return self.default_dns
|
return self.default_dns
|
||||||
|
|
||||||
def translate(self, ip, network):
|
def translate(self, ip, network):
|
||||||
# Translate if required given ip from given network
|
"""Translate if required given ip from given network"""
|
||||||
if IPv4Address(ip) in self.networks[network].local_range:
|
if IPv4Address(ip) in self.networks[network].local_range:
|
||||||
return self.networks[network].translation_dict[ip]
|
return self.networks[network].translation_dict[ip]
|
||||||
return ip
|
return ip
|
||||||
|
|
||||||
def untranslate(self, ip, network):
|
def untranslate(self, ip, network):
|
||||||
# Give back the original ip from a translated one from given network
|
"""Give back the original ip from a translated one from given network"""
|
||||||
if IPv4Address(ip) in self.networks[network].local_translated_range:
|
if IPv4Address(ip) in self.networks[network].local_translated_range:
|
||||||
return self.networks[network].untranslation_dict[ip]
|
return self.networks[network].untranslation_dict[ip]
|
||||||
return ip
|
return ip
|
||||||
|
|
|
@ -9,6 +9,6 @@ PublicKey = {{ peer.public_key }}
|
||||||
{%- if peer.endpoint is defined %}
|
{%- if peer.endpoint is defined %}
|
||||||
Endpoint = {{ peer.endpoint }}
|
Endpoint = {{ peer.endpoint }}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
AllowedIPs = {{ peer.allowed_ips}}
|
AllowedIPs = {{ peer.allowed_ips | join(', ') }}
|
||||||
PersistentKeepalive = 25
|
PersistentKeepalive = 25
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in a new issue