Better wildcard matching, though we should still split on . before checking
This commit is contained in:
		@ -2,8 +2,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Title = "GODNS"
 | 
					Title = "GODNS"
 | 
				
			||||||
Version = "0.1.3"
 | 
					Version = "0.2.0"
 | 
				
			||||||
Author = "kenshin"
 | 
					Author = "kenshin, tystuyfzand"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Debug = false
 | 
					Debug = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
#Toml config file
 | 
					#Toml config file
 | 
				
			||||||
title = "GODNS"
 | 
					title = "GODNS"
 | 
				
			||||||
version = "0.2.0"
 | 
					Version = "0.2.1"
 | 
				
			||||||
author = "kenshin, tystuyfzand"
 | 
					Author = "kenshin, tystuyfzand"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
debug = false
 | 
					debug = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -8,6 +8,7 @@ import (
 | 
				
			|||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"bufio"
 | 
						"bufio"
 | 
				
			||||||
	"regexp"
 | 
						"regexp"
 | 
				
			||||||
 | 
						"github.com/ryanuber/go-glob"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type FileHosts struct {
 | 
					type FileHosts struct {
 | 
				
			||||||
@ -63,10 +64,13 @@ func (f *FileHosts) Get(domain string) ([]string, bool) {
 | 
				
			|||||||
	for host, ip := range f.hosts {
 | 
						for host, ip := range f.hosts {
 | 
				
			||||||
		if strings.HasPrefix(host, "*.") {
 | 
							if strings.HasPrefix(host, "*.") {
 | 
				
			||||||
			old, err := publicsuffix.EffectiveTLDPlusOne(host)
 | 
								old, err := publicsuffix.EffectiveTLDPlusOne(host)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if sld == old {
 | 
					
 | 
				
			||||||
 | 
								// Don't blindly accept wildcards, match it against string
 | 
				
			||||||
 | 
								if sld == old && glob.Glob(host, domain) {
 | 
				
			||||||
				return []string{ip}, true
 | 
									return []string{ip}, true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -5,6 +5,7 @@ import (
 | 
				
			|||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"golang.org/x/net/publicsuffix"
 | 
						"golang.org/x/net/publicsuffix"
 | 
				
			||||||
 | 
						"github.com/ryanuber/go-glob"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type RedisHosts struct {
 | 
					type RedisHosts struct {
 | 
				
			||||||
@ -94,10 +95,13 @@ func (r *RedisHosts) Get(domain string) ([]string, bool) {
 | 
				
			|||||||
	for host, ip := range r.hosts {
 | 
						for host, ip := range r.hosts {
 | 
				
			||||||
		if strings.HasPrefix(host, "*.") {
 | 
							if strings.HasPrefix(host, "*.") {
 | 
				
			||||||
			old, err := publicsuffix.EffectiveTLDPlusOne(host)
 | 
								old, err := publicsuffix.EffectiveTLDPlusOne(host)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if sld == old {
 | 
					
 | 
				
			||||||
 | 
								// Don't blindly accept wildcards, match it against string
 | 
				
			||||||
 | 
								if sld == old && glob.Glob(host, domain) {
 | 
				
			||||||
				return strings.Split(ip, ","), true
 | 
									return strings.Split(ip, ","), true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user