Squashed commit of the following:
commit 787b5d40394889510c24f4abc3a08410ecc96e5e
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Wed Jul 31 15:09:18 2024 +0300
configmigrate: revert
commit a036638c05967298d13ef435dc5b377103cfe163
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Wed Jul 31 09:37:25 2024 +0300
docs
commit a3b2e8de4bab7214dd6b260655bba9f45eee6bd2
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Wed Jul 31 09:18:25 2024 +0300
locales
commit a01a22019ef02ae77e9006dd9444da462419908f
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Wed Jul 31 09:02:14 2024 +0300
filtering: imp code
commit bc268cdd526c82cb605b1a474d51b79f593cd3da
Merge: 5ad88d914 bc6d20ff1
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Wed Jul 31 08:00:05 2024 +0300
Merge remote-tracking branch 'origin/master' into 5009-ecosia-safesearch
commit 5ad88d914cf9b03f399efd481ae39ebd56243e66
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Tue Jul 30 13:49:51 2024 +0300
all: ecosia safesearch
AdGuard Home's DNS filtering go library
Example use:
[ -z "$GOPATH" ] && export GOPATH=$HOME/go
go get -d github.com/AdguardTeam/AdGuardHome/filtering
Create file filter.go
package main
import (
"github.com/AdguardTeam/AdGuardHome/filtering"
"log"
)
func main() {
filter := filtering.New()
filter.AddRule("||dou*ck.net^")
host := "www.doubleclick.net"
res, err := filter.CheckHost(host)
if err != nil {
// temporary failure
log.Fatalf("Failed to check host %q: %s", host, err)
}
if res.IsFiltered {
log.Printf("Host %s is filtered, reason - %q, matched rule: %q", host, res.Reason, res.Rule)
} else {
log.Printf("Host %s is not filtered, reason - %q", host, res.Reason)
}
}
And then run it:
go run filter.go
You will get:
2000/01/01 00:00:00 Host www.doubleclick.net is filtered, reason - 'FilteredBlackList', matched rule: '||dou*ck.net^'
You can also enable checking against AdGuard's SafeBrowsing:
package main
import (
"github.com/AdguardTeam/AdGuardHome/filtering"
"log"
)
func main() {
filter := filtering.New()
filter.EnableSafeBrowsing()
host := "wmconvirus.narod.ru" // hostname for testing safebrowsing
res, err := filter.CheckHost(host)
if err != nil {
// temporary failure
log.Fatalf("Failed to check host %q: %s", host, err)
}
if res.IsFiltered {
log.Printf("Host %s is filtered, reason - %q, matched rule: %q", host, res.Reason, res.Rule)
} else {
log.Printf("Host %s is not filtered, reason - %q", host, res.Reason)
}
}