From f1eb217ed282104ba7b6ee26f53fd0e019e7d1ae Mon Sep 17 00:00:00 2001 From: Olivier Poitrey Date: Sat, 7 Oct 2023 03:02:04 +0200 Subject: [PATCH] Add UDM content filtering feature detection --- install.sh | 19 +++++++++++++++++++ router/ubios/setup.go | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/install.sh b/install.sh index fe108bda..45cf49cc 100755 --- a/install.sh +++ b/install.sh @@ -98,8 +98,23 @@ uninstall() { fi } +precheck() { + if [ -e "/data/unifi" ] && [ -f "/run/dnsfilter/dnsfilter" ]; then + log_warn "UDM Content Filtering feature is enabled. Please disable it to use NextDNS." + log_warn "" + log_warn " To disable it, go to Settings > Network" + log_warn " For each network, set the Content Filtering feature to None." + log_warn "" + while [ -f "/run/dnsfilter/dnsfilter" ]; do + sleep 1 + done + log_info "Content Filtering feature successfuly disabled." + fi +} + configure() { log_debug "Start configure" + precheck args="" add_arg() { for value in $2; do @@ -666,6 +681,10 @@ log_info() { printf "INFO: %s\n" "$*" >&2 } +log_warn() { + printf "\033[33mWARN: %s\033[0m\n" "$*" >&2 +} + log_error() { printf "\033[31mERROR: %s\033[0m\n" "$*" >&2 } diff --git a/router/ubios/setup.go b/router/ubios/setup.go index 93942ae9..99cae7d0 100644 --- a/router/ubios/setup.go +++ b/router/ubios/setup.go @@ -28,6 +28,9 @@ func New() (*Router, bool) { } func (r *Router) Configure(c *config.Config) error { + if dnsFilterEnabled() { + return fmt.Errorf(`UDM "Content Filtering" feature is enabled. Please disable it to use NextDNS.`) + } c.Listens = []string{net.JoinHostPort("localhost", r.ListenPort)} r.ClientReporting = c.ReportClientInfo if c.CacheSize == "0" || c.CacheSize == "" { @@ -55,6 +58,11 @@ func (r *Router) setupDNSMasq() error { return killDNSMasq() } +func dnsFilterEnabled() bool { + _, err := os.Stat("/run/dnsfilter/dnsfilter") + return err == nil +} + func killDNSMasq() error { b, err := os.ReadFile("/run/dnsmasq.pid") if err != nil {