Repository: 0xERR0R/blocky (Go)

Issue:
Support adblock list syntax
With the latest Pi-hole update the developers added basic AdBlock style syntax support for their adlists.

I hope the same can be implemented in blocky, as it remains the only dns software without support for a compressed format.
AdGuard Home, pfblocker, Pi-hole, Technitium, eBlocker all have 1 or more compressed formats supported.

Preferably, I would like the adblock style to be added just like Pi-hole. But really, any is fine (wildcard, adguard, adblock).

Occasionally, blocky will miss domains that AdGuard Home/Pi-hole catches (using the same lists) because it only supports domains/hosts. 

Another problem with domains/hosts is that not all lists support it. Ive run into cases where I cant use a list at all in blocky because the maintainer dropped it/never added it in the first place.
This used to be the case as well with Pi-hole.

Another voice (oisd maintainer): https://www.reddit.com/r/oisd_blocklist/comments/11s6dov/important_update_changes_to_blocklist_syntax/
Pi-hole's implementation: https://pi-hole.net/blog/2023/03/22/pi-hole-ftl-v5-22-web-v5-19-and-core-v5-16-1-released/#page-content


Discussion:
blocky supports regex lists but not the AdBlock syntax.
Found a list of syntaxes here: https://github.com/collinbarrett/FilterLists/wiki/Syntax  
Supporting more should be pretty easy as long as every line is parsed independently. The AdBlock one is a bit annoying cause it's fairly complex, and we'd be throwing away most lines anyways, but doable.

EDIT: also I don't think blocky currently supports blocking subdomains without using a regex, and that's probably a bigger part of the work here.
> EDIT: also I don't think blocky currently supports blocking subdomains without using a regex, and that's probably a bigger part of the work here.

That's correct blocking of subdomains has to be done with a Regex.
Auto conversion of entries like `*.example.com` or `||example.com^` to the internally used Regex should be possible 
> > EDIT: also I don't think blocky currently supports blocking subdomains without using a regex, and that's probably a bigger part of the work here.
> 
> That's correct blocking of subdomains has to be done with a Regex. Auto conversion of entries like `*.example.com` or `||example.com^` to the internally used Regex should be possible

Wait, so if I have a host list that has subdomains, blocky does not block them?  The logs seem to tell otherwise...
> > > EDIT: also I don't think blocky currently supports blocking subdomains without using a regex, and that's probably a bigger part of the work here.
> 
> > 
> 
> > That's correct blocking of subdomains has to be done with a Regex. Auto conversion of entries like `*.example.com` or `||example.com^` to the internally used Regex should be possible
> 
> 
> 
> Wait, so if I have a host list that has subdomains, blocky does not block them?  The logs seem to tell otherwise...

No, if a subdomain is listed it will be blocked, however subdomains that aren't listed will NOT.
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.
Any plan to re-open this feature request?
Since #1233 (current development version)wildcard lists are now supported.

These should be used in favor of regex since they take much less resources to store and process.
With wildcards being supported I'm not sure we really need adblock format support since as mentioned above, it's more meant for Browser adblocker extensions than DNS.
We can keep this open though.
I hope this will stay open (and, of course, implemented someday), as there are tons of popular filter lists in adblock/adguard format (EasyList stuff, for example) which I would happily add to my blocky, but currently I can't.
AdBlock lists support should be kept open. As seed before, AGH seems to be exceedingly popular and many 'good' lists are available for AGH.

**Would much appreciate if AGH style lists can be supported natively in Blocky.**
> AGH style lists can be supported natively in Blocky

Meantime, maybe somebody has developed and maintains wildcard list converted from Adguard Home list? Or maybe some converter already exists?

Edit 1
Manually converted AGH main list: [AdGuardSDNSFilter.txt](https://github.com/0xERR0R/blocky/files/14576554/AdGuardSDNSFilter.txt)

Any updates on this issue?
I want to migrate from pihole to blocky and it would be nice to have native support for the AdBlock style syntax, so i can use my current pihole lists with blocky without converting and updating them each time upstream gets changes.
Nope no news. 

All implementations I found so far use Regex in the background which have less performance than pure domain or wildcard lists in blocky.
@kwitsch  alright, thank you very much for your answer and fast reply!
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days.
[https://github.com/0xERR0R/blocky/issues/950#issuecomment-1978796760](https://github.com/0xERR0R/blocky/issues/950#issuecomment-1978796760)
> maybe some converter already exists?

https://github.com/zc-devs/agh2blocky
Any news?
Please make it possible.



Patch:
diff --git a/lists/parsers/lines.go b/lists/parsers/lines.go
index b1c71ba9a..504d6c1ae 100644
--- a/lists/parsers/lines.go
+++ b/lists/parsers/lines.go
@@ -70,6 +70,10 @@ func (l *lines) Next(ctx context.Context) (string, error) {
 			continue // empty line
 		}
 
+		if strings.HasPrefix(text, "!") || (l.lineNo == 1 && strings.HasPrefix(text, "[Adblock")) {
+			continue // Adblock comment or identifier header
+		}
+
 		if idx := strings.IndexRune(text, '#'); idx != -1 {
 			if idx == 0 {
 				continue // commented line


Test patch:
diff --git a/lists/parsers/hosts_test.go b/lists/parsers/hosts_test.go
index 0533be451..80d8d8103 100644
--- a/lists/parsers/hosts_test.go
+++ b/lists/parsers/hosts_test.go
@@ -100,7 +100,6 @@ var _ = Describe("Hosts", func() {
 		It("fails", func() {
 			lines := []string{
 				"invalidIP localhost",
-				"!notadomain!",
 				"xn---mllerk1va.com",
 				`/invalid regex ??/`,
 				"invalid.*.wildcard",
diff --git a/lists/parsers/lines_test.go b/lists/parsers/lines_test.go
index ecc47b01d..7b72f7baa 100644
--- a/lists/parsers/lines_test.go
+++ b/lists/parsers/lines_test.go
@@ -183,6 +183,24 @@ var _ = Describe("Lines", func() {
 			Expect(sut.Position()).Should(Equal("line 2"))
 		})
 	})
+
+	When("it has Adblock identifier or comments", func() {
+		BeforeEach(func() {
+			sutReader = linesReader(
+				"[Adblock",
+				"! comment 1",
+				"! comment 2",
+				"second",
+			)
+		})
+
+		It("skips them", func() {
+			str, err := sut.Next(context.Background())
+			Expect(err).Should(Succeed())
+			Expect(str).Should(Equal("second"))
+			Expect(sut.Position()).Should(Equal("line 4"))
+		})
+	})
 })
 
 func linesReader(lines ...string) io.Reader {