From 2ca7253326ac457c7e7e065fa7c6633eae5e805d Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Wed, 23 Nov 2016 18:06:30 +0100 Subject: [PATCH] dnsmasq: domain override for dynamic dhcp lease registration PR: https://github.com/opnsense/core/issues/1250 --- src/etc/inc/plugins.inc.d/dnsmasq.inc | 3 +++ src/www/services_dnsmasq.php | 31 +++++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/etc/inc/plugins.inc.d/dnsmasq.inc b/src/etc/inc/plugins.inc.d/dnsmasq.inc index 47559e779..8cf960069 100644 --- a/src/etc/inc/plugins.inc.d/dnsmasq.inc +++ b/src/etc/inc/plugins.inc.d/dnsmasq.inc @@ -273,6 +273,9 @@ function dnsmasq_hosts_generate() if (isset($config['dnsmasq']['regdhcp']) && file_exists($leases)) { $domain = $config['system']['domain']; + if (isset($config['dnsmasq']['regdhcpdomain'])) { + $domain = $config['dnsmasq']['regdhcpdomain']; + } mwexecf( '/usr/local/sbin/dhcpleases -l %s -d %s -p %s -h %s', array($leases, $domain, '/var/run/dnsmasq.pid', '/var/etc/dnsmasq-hosts') diff --git a/src/www/services_dnsmasq.php b/src/www/services_dnsmasq.php index b54d29994..415c85871 100644 --- a/src/www/services_dnsmasq.php +++ b/src/www/services_dnsmasq.php @@ -46,6 +46,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { // booleans $pconfig['enable'] = isset($config['dnsmasq']['enable']); $pconfig['regdhcp'] = isset($config['dnsmasq']['regdhcp']); + $pconfig['regdhcpdomain'] = !empty($config['dnsmasq']['regdhcpdomain']) ? $config['dnsmasq']['regdhcpdomain'] : null; $pconfig['regdhcpstatic'] = isset($config['dnsmasq']['regdhcpstatic']); $pconfig['dhcpfirst'] = isset($config['dnsmasq']['dhcpfirst']); $pconfig['strict_order'] = isset($config['dnsmasq']['strict_order']); @@ -63,6 +64,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $input_errors = array(); if (isset($pconfig['submit'])) { // validate + if (!empty($pconfig['regdhcpdomain']) && !is_domain($pconfig['regdhcpdomain'])) { + $input_errors[] = gettext("The domain may only contain the characters a-z, 0-9, '-' and '.'."); + } if (!empty($pconfig['port']) && !is_port($pconfig['port'])) { $input_errors[] = gettext("You must specify a valid port number"); } @@ -91,9 +95,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $config['dnsmasq']['domain_needed'] = !empty($pconfig['domain_needed']); $config['dnsmasq']['no_private_reverse'] = !empty($pconfig['no_private_reverse']); $config['dnsmasq']['strictbind'] = !empty($pconfig['strictbind']); + if (!empty($pconfig['regdhcpdomain'])) { + $config['dnsmasq']['regdhcpdomain'] = $pconfig['regdhcpdomain']; + } elseif (isset($config['dnsmasq']['regdhcpdomain'])) { + unset($config['dnsmasq']['regdhcpdomain']); + } if (!empty($pconfig['interface'])) { $config['dnsmasq']['interface'] = implode(",", $pconfig['interface']); - } elseif (isset($config['dnsmasq']['interface'])) { + } elseif (isset($config['dnsmasq']['interface'])) { unset($config['dnsmasq']['interface']); } if (!empty($pconfig['port'])) { @@ -244,11 +253,21 @@ $( document ).ready(function() { /> + + + + + + +