diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 1e74aac20..b394d4b06 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -2879,7 +2879,6 @@ function interface_configure($interface = 'wan', $reloadall = false, $linkupeven if ($interface == 'lan') { /* make new hosts file */ system_hosts_generate(); - services_dhcpleases_configure(); } if ($reloadall == true) { diff --git a/src/etc/inc/plugins.inc.d/dnsmasq.inc b/src/etc/inc/plugins.inc.d/dnsmasq.inc index a01119503..6797d5efa 100644 --- a/src/etc/inc/plugins.inc.d/dnsmasq.inc +++ b/src/etc/inc/plugins.inc.d/dnsmasq.inc @@ -270,3 +270,30 @@ function dnsmasq_hosts_generate() return $lhosts . $dhosts; } + +function dnsmasq_dhcpleases_stop() +{ + killbypid('/var/run/dhcpleases.pid', 'TERM', true); +} + +function dnsmasq_dhcpleases_start() +{ + global $config; + + if (!isset($config['dnsmasq']['enable']) || !isset($config['dnsmasq']['regdhcp'])) { + return; + } + + $leases = services_dhcpd_leasesfile(); + if (!file_exists($leases)) { + return; + } + + /* we can let the user choose a domain, but it can be only one */ + $domain = $config['system']['domain']; + + mwexecf( + '/usr/local/sbin/dhcpleases -l %s -d %s -p %s -h %s', + array($leases, $domain, '/var/run/dnsmasq.pid', '/etc/hosts') + ); +} diff --git a/src/etc/inc/services.inc b/src/etc/inc/services.inc index 79b239217..d9e999b78 100644 --- a/src/etc/inc/services.inc +++ b/src/etc/inc/services.inc @@ -314,31 +314,6 @@ function services_dhcpdv6_leasesfile() return "{$g['dhcpd_chroot_path']}/var/db/dhcpd6.leases"; } -function services_dhcpleases_configure() -{ - global $config, $g; - - killbypid('/var/run/dhcpleases.pid', 'TERM', true); - - if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcp'])) { - mwexec("/bin/mkdir -p {$g['dhcpd_chroot_path']}/var/db"); - touch("{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases"); - if (isvalidpid('/var/run/dhcpleases.pid')) { - killbypid('/var/run/dhcpleases.pid', 'HUP'); - } else { - mwexecf( - '/usr/local/sbin/dhcpleases -l %s -d %s -p %s -h %s', - array( - "{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases", - $config['system']['domain'], - '/var/run/dnsmasq.pid', - '/etc/hosts' - ) - ); - } - } -} - function services_dhcpd_configure($family = 'all', $blacklist = array(), $verbose = false) { global $g; diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc index 9fdb2e64d..b26c380b2 100644 --- a/src/etc/inc/system.inc +++ b/src/etc/inc/system.inc @@ -384,9 +384,9 @@ function system_hosts_generate() * Do not remove this because dhcpleases monitors with kqueue * it needs to be killed before writing to hosts files. */ - killbypid('/var/run/dhcpleases.pid', 'TERM', true); - + dnsmasq_dhcpleases_stop(); file_put_contents('/etc/hosts', $hosts); + dnsmasq_dhcpleases_start(); } function system_hostname_configure() @@ -396,10 +396,9 @@ function system_hostname_configure() $syscfg = $config['system']; /* set hostname */ - $status = mwexec("/bin/hostname " . - escapeshellarg("{$syscfg['hostname']}.{$syscfg['domain']}")); + $status = mwexecf('/bin/hostname %s', "{$syscfg['hostname']}.{$syscfg['domain']}"); - /* Setup host GUID ID. This is used by ZFS. */ + /* Setup host GUID ID. This is used by ZFS. */ mwexec("/etc/rc.d/hostid start"); return $status; diff --git a/src/etc/inc/xmlrpc/legacy.inc b/src/etc/inc/xmlrpc/legacy.inc index 2995756da..ba1284b75 100644 --- a/src/etc/inc/xmlrpc/legacy.inc +++ b/src/etc/inc/xmlrpc/legacy.inc @@ -135,7 +135,6 @@ function filter_configure_xmlrpc() system_routing_configure(); setup_gateways_monitor(); system_hosts_generate(); - services_dhcpleases_configure(); local_sync_accounts(); dnsmasq_configure_do(); unbound_configure_do(); diff --git a/src/etc/rc.bootup b/src/etc/rc.bootup index 8cedf620e..16e849582 100755 --- a/src/etc/rc.bootup +++ b/src/etc/rc.bootup @@ -140,9 +140,6 @@ openvpn_prepare_all(); interfaces_configure(); unmute_kernel_msgs(); -/* re-make hosts file after configuring interfaces */ -system_hosts_generate(); - /* start OpenVPN server & clients */ echo "Syncing OpenVPN settings..."; openvpn_resync_all(); @@ -180,7 +177,7 @@ system_routing_enable(); dnsmasq_configure_do(true); unbound_configure_do(true); services_dhcpd_configure('all', array(), true); -services_dhcpleases_configure(); +system_hosts_generate(); services_dhcrelay_configure(true); services_dhcrelay6_configure(true); diff --git a/src/etc/rc.newwanip b/src/etc/rc.newwanip index 8c53a4237..30b079dbb 100755 --- a/src/etc/rc.newwanip +++ b/src/etc/rc.newwanip @@ -139,7 +139,6 @@ if (!empty($bridgetmp)) { /* make new hosts file */ system_hosts_generate(); -services_dhcpleases_configure(); /* check tunneled IPv6 interface tracking */ if (isset($config['interfaces'][$interface]['ipaddrv6'])) { diff --git a/src/etc/rc.reload_all b/src/etc/rc.reload_all index 81845c1c9..3d5d7d8eb 100755 --- a/src/etc/rc.reload_all +++ b/src/etc/rc.reload_all @@ -48,7 +48,6 @@ system_login_configure(); system_timezone_configure(); system_hostname_configure(); system_hosts_generate(); -services_dhcpleases_configure(); system_resolvconf_generate(); system_routing_enable(); interfaces_configure(); diff --git a/src/www/services_dhcp.php b/src/www/services_dhcp.php index add192c88..438bbca2d 100644 --- a/src/www/services_dhcp.php +++ b/src/www/services_dhcp.php @@ -110,7 +110,6 @@ function reconfigure_dhcpd() dhcp_clean_leases(); system_hosts_generate(); clear_subsystem_dirty('hosts'); - services_dhcpleases_configure(); services_dhcpd_configure(); clear_subsystem_dirty('staticmaps'); } diff --git a/src/www/services_dnsmasq.php b/src/www/services_dnsmasq.php index 16b9a76c1..b54d29994 100644 --- a/src/www/services_dnsmasq.php +++ b/src/www/services_dnsmasq.php @@ -118,7 +118,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { /* Update resolv.conf in case the interface bindings exclude localhost. */ system_resolvconf_generate(); system_hosts_generate(); - services_dhcpleases_configure(); dnsmasq_configure_do(); services_dhcpd_configure(); clear_subsystem_dirty('hosts'); diff --git a/src/www/system_advanced_admin.php b/src/www/system_advanced_admin.php index 693835148..3a2aadb0d 100644 --- a/src/www/system_advanced_admin.php +++ b/src/www/system_advanced_admin.php @@ -251,7 +251,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { system_login_configure(); system_hosts_generate(); - services_dhcpleases_configure(); dnsmasq_configure_do(); unbound_configure_do(); services_dhcpd_configure(); diff --git a/src/www/system_general.php b/src/www/system_general.php index 7f0f640f3..9188c7f1a 100644 --- a/src/www/system_general.php +++ b/src/www/system_general.php @@ -224,7 +224,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { prefer_ipv4_or_ipv6(); system_hostname_configure(); system_hosts_generate(); - services_dhcpleases_configure(); system_resolvconf_generate(); dnsmasq_configure_do(); unbound_configure_do();