From 28fa6a6868cf1d891c69f814b6892c73e243868d Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Fri, 24 Mar 2023 14:37:04 +0100 Subject: [PATCH] system: simplify previous We can add multiple ports (like GUI 80, 443) and still look up only one of them. --- src/etc/inc/plugins.inc.d/dhcpd.inc | 8 ++++---- src/etc/inc/system.inc | 2 +- src/etc/inc/util.inc | 10 +++++++++- src/www/services_dnsmasq.php | 4 ++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/etc/inc/plugins.inc.d/dhcpd.inc b/src/etc/inc/plugins.inc.d/dhcpd.inc index 7666dc4fe..8ff0f5bbe 100644 --- a/src/etc/inc/plugins.inc.d/dhcpd.inc +++ b/src/etc/inc/plugins.inc.d/dhcpd.inc @@ -353,7 +353,7 @@ function dhcpd_radvd_configure($verbose = false, $blacklist = []) $dnslist_tmp = $dhcpv6ifconf['dnsserver']; } elseif (!isset($dhcpv6ifconf['rasamednsasdhcp6']) && !empty($dhcpv6ifconf['radnsserver'][0])) { $dnslist_tmp = $dhcpv6ifconf['radnsserver']; - } elseif (!empty(service_by_name('*', ['ports' => ['53']]))) { + } elseif (!empty(service_by_filter(['ports' => '53']))) { if (is_ipaddrv6($ifcfgipv6)) { $dnslist_tmp[] = $ifcfgipv6; } else { @@ -448,7 +448,7 @@ function dhcpd_radvd_configure($verbose = false, $blacklist = []) $networkv6 = '::/64'; } - if (!empty(service_by_name('*', ['ports' => ['53']]))) { + if (!empty(service_by_filter(['ports' => '53']))) { if (is_ipaddrv6($ifcfgipv6)) { $dnslist[] = $ifcfgipv6; } else { @@ -743,7 +743,7 @@ EOPP; if (!empty($newzone['domain-name'])) { $newzone['dns-servers'] = $dhcpifconf['dnsserver']; } - } elseif (!empty(service_by_name('*', ['ports' => ['53']]))) { + } elseif (!empty(service_by_filter(['ports' => '53']))) { $dnscfg .= " option domain-name-servers {$ifcfgip};"; if (!empty($newzone['domain-name'])) { $newzone['dns-servers'] = [$ifcfgip]; @@ -1459,7 +1459,7 @@ EOD; if (isset($dhcpv6ifconf['dnsserver'][0])) { $dnscfgv6 .= " option dhcp6.name-servers " . join(",", $dhcpv6ifconf['dnsserver']) . ";"; - } elseif (!empty(service_by_name('*', ['ports' => ['53']]))) { + } elseif (!empty(service_by_filter(['ports' => '53']))) { $dnscfgv6 .= " option dhcp6.name-servers {$ifcfgipv6};"; } elseif (!empty($dns_arrv6)) { $dnscfgv6 .= " option dhcp6.name-servers " . join(",", $dns_arrv6) . ";"; diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc index 771fa8500..b238e60ea 100644 --- a/src/etc/inc/system.inc +++ b/src/etc/inc/system.inc @@ -202,7 +202,7 @@ function system_resolvconf_generate($verbose = false) $search[] = $syscfg['dnssearchdomain']; } - if (!isset($syscfg['dnslocalhost']) && !empty(service_by_name('*', ['ports' => ['53']]))) { + if (!isset($syscfg['dnslocalhost']) && !empty(service_by_filter(['ports' => '53']))) { $resolvconf .= "nameserver 127.0.0.1\n"; } diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc index a96c557b4..3cf06152f 100644 --- a/src/etc/inc/util.inc +++ b/src/etc/inc/util.inc @@ -100,6 +100,11 @@ function is_process_running($process) return (intval($retval) == 0); } +function service_by_filter($filter = []) +{ + return service_by_name('*', $filter); +} + function service_by_name($name, $filter = []) { $services = plugins_services(); @@ -114,7 +119,10 @@ function service_by_name($name, $filter = []) $filter['name'] = $name; } foreach ($filter as $key => $value) { - if (isset($service[$key]) && $service[$key] == $value) { + if ( + isset($service[$key]) && ($service[$key] == $value || + (is_array($service[$key]) && in_array($value, $service[$key]))) + ) { return $service; } } diff --git a/src/www/services_dnsmasq.php b/src/www/services_dnsmasq.php index f5a728fe3..4e9b432cc 100644 --- a/src/www/services_dnsmasq.php +++ b/src/www/services_dnsmasq.php @@ -84,8 +84,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } $dnsmasq_port = empty($pconfig['port']) ? "53" : $pconfig['port']; - $port_conflict = service_by_name('*', ['ports' => [$dnsmasq_port]]); - if (!empty($pconfig['enable']) && !empty($port_conflict)) { + $port_conflict = service_by_filter(['ports' => $dnsmasq_port]); + if (!empty($pconfig['enable']) && !empty($port_conflict) && $port_conflict['name'] != 'dnsmasq') { $input_errors[] = sprintf(gettext('%s is currently using this port.'), $port_conflict['description']); }