mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-16 14:03:00 +02:00
unbound+DHCP: Read correct DHCP domain name for lease
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
import argparse
|
||||
import datetime
|
||||
import daemon
|
||||
import ipaddress
|
||||
import logging
|
||||
import logging.handlers
|
||||
import re
|
||||
@@ -220,7 +221,47 @@ class Lease(object):
|
||||
|
||||
@property
|
||||
def domain(self):
|
||||
return "local" # XXX
|
||||
# Load ethernet settings
|
||||
ethernet_settings = self.read_settings("/var/ipfire/ethernet/settings")
|
||||
|
||||
# Load DHCP settings
|
||||
dhcp_settings = self.read_settings("/var/ipfire/dhcp/settings")
|
||||
|
||||
subnets = {}
|
||||
for zone in ("GREEN", "BLUE"):
|
||||
if not dhcp_settings.get("ENABLE_%s" % zone) == "on":
|
||||
continue
|
||||
|
||||
netaddr = ethernet_settings.get("%s_NETADDRESS" % zone)
|
||||
submask = ethernet_settings.get("%s_NETMASK" % zone)
|
||||
|
||||
subnet = ipaddress.ip_network("%s/%s" % (netaddr, submask))
|
||||
domain = dhcp_settings.get("DOMAIN_NAME_%s" % zone)
|
||||
|
||||
subnets[subnet] = domain
|
||||
|
||||
address = ipaddress.ip_address(self.ipaddr)
|
||||
|
||||
for subnet, domain in subnets.items():
|
||||
if address in subnet:
|
||||
return domain
|
||||
|
||||
# Fall back to localdomain if no match could be found
|
||||
return "localdomain"
|
||||
|
||||
@staticmethod
|
||||
def read_settings(filename):
|
||||
settings = {}
|
||||
|
||||
with open(filename) as f:
|
||||
for line in f.readlines():
|
||||
# Remove line-breaks
|
||||
line = line.rstrip()
|
||||
|
||||
k, v = line.split("=", 1)
|
||||
settings[k] = v
|
||||
|
||||
return settings
|
||||
|
||||
@property
|
||||
def fqdn(self):
|
||||
|
||||
Reference in New Issue
Block a user