From e43bca743b36f3bd2e04abba4a3bd3cca7b17595 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Thu, 23 Jan 2025 13:38:52 +0100 Subject: [PATCH] Services: Unbound DNS - flag overwrites when they exists (https://docs.opnsense.org/manual/unbound.html#advanced-configurations) --- plist | 1 + .../System/Status/UnboundOverrideStatus.php | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/opnsense/mvc/app/library/OPNsense/System/Status/UnboundOverrideStatus.php diff --git a/plist b/plist index db3eaa76e..745652b0e 100644 --- a/plist +++ b/plist @@ -578,6 +578,7 @@ /usr/local/opnsense/mvc/app/library/OPNsense/System/Status/LiveMediaStatus.php /usr/local/opnsense/mvc/app/library/OPNsense/System/Status/OpensshOverrideStatus.php /usr/local/opnsense/mvc/app/library/OPNsense/System/Status/SystemBootingStatus.php +/usr/local/opnsense/mvc/app/library/OPNsense/System/Status/UnboundOverrideStatus.php /usr/local/opnsense/mvc/app/library/OPNsense/System/SystemStatus.php /usr/local/opnsense/mvc/app/library/OPNsense/System/SystemStatusCode.php /usr/local/opnsense/mvc/app/library/OPNsense/Trust/Store.php diff --git a/src/opnsense/mvc/app/library/OPNsense/System/Status/UnboundOverrideStatus.php b/src/opnsense/mvc/app/library/OPNsense/System/Status/UnboundOverrideStatus.php new file mode 100644 index 000000000..4f90d4c4e --- /dev/null +++ b/src/opnsense/mvc/app/library/OPNsense/System/Status/UnboundOverrideStatus.php @@ -0,0 +1,65 @@ +internalPriority = 2; + $this->internalPersistent = true; + $this->internalTitle = gettext('Configuration override'); + $this->internalIsBanner = true; + $this->internalScope[] = '/ui/unbound/*'; + } + + public function collectStatus() + { + /* XXX: custom overwrites don't live in their own path, which makes detection less practical */ + $managed_files = []; + $tmp = @file_get_contents('/usr/local/opnsense/service/templates/OPNsense/Unbound/core/+TARGETS') ?? ''; + foreach (explode("\n", $tmp) as $line) { + if (strpos($line, 'unbound.opnsense.d') > 1) { + $managed_files[] = trim(explode(":", $line)[1]); + } + } + foreach (glob('/usr/local/etc/unbound.opnsense.d/*.conf') as $filename) { + if (!in_array($filename, $managed_files)) { + $this->internalMessage = gettext( + 'The configuration contains manual overwrites, these may interfere with the settings configured here.' + ); + $this->internalStatus = SystemStatusCode::NOTICE; + break; + } + } + } +}