Skip to content

Commit

Permalink
Add UDM content filtering feature detection
Browse files Browse the repository at this point in the history
  • Loading branch information
rs committed Oct 7, 2023
1 parent d2831b4 commit f1eb217
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
19 changes: 19 additions & 0 deletions install.sh
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions router/ubios/setup.go
Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f1eb217

Please sign in to comment.