diff --git a/.drone.yml b/.drone.yml index cbedf7e..43e3f8d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -18,27 +18,6 @@ steps: tags: - amd64-latest ---- -kind: pipeline -name: arm64 - -platform: - os: linux - arch: arm64 - -steps: - - name: docker - image: plugins/docker - settings: - username: - from_secret: docker_username - password: - from_secret: docker_password - repo: registry.meow.tf/joker/godns - registry: registry.meow.tf - tags: - - arm64-latest - --- kind: pipeline name: manifest @@ -59,7 +38,6 @@ steps: depends_on: - amd64 - - arm64 image_pull_secrets: - dockerconfigjson \ No newline at end of file diff --git a/.gitignore b/.gitignore index d05c4ea..a4e31e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /bin godns godns.log -etc/godns.conf \ No newline at end of file +etc/godns.conf +godns.exe \ No newline at end of file diff --git a/cache.go b/cache.go index d06d429..ebaabc9 100644 --- a/cache.go +++ b/cache.go @@ -4,8 +4,8 @@ import ( "fmt" "time" - "github.com/miekg/dns" "crypto/md5" + "github.com/miekg/dns" ) type KeyNotFound struct { diff --git a/cache_memory.go b/cache_memory.go index 45ee65d..5e57f21 100644 --- a/cache_memory.go +++ b/cache_memory.go @@ -1,9 +1,9 @@ package main import ( - "time" - "sync" "github.com/miekg/dns" + "sync" + "time" ) type MemoryCache struct { diff --git a/etc/godns.example.conf b/etc/godns.example.conf index 287eaaf..6b3b8cd 100644 --- a/etc/godns.example.conf +++ b/etc/godns.example.conf @@ -1,6 +1,6 @@ #Toml config file title = "GODNS" -Version = "0.2.2" +Version = "0.2.3" Author = "kenshin, tystuyfzand" debug = false diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..29fcab7 --- /dev/null +++ b/go.mod @@ -0,0 +1,15 @@ +module godns + +go 1.12 + +require ( + github.com/BurntSushi/toml v0.3.1 + github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b + github.com/caarlos0/env v3.5.0+incompatible + github.com/fsnotify/fsnotify v1.4.7 + github.com/hoisie/redis v0.0.0-20160730154456-b5c6e81454e0 + github.com/miekg/dns v1.1.18 + github.com/ryanuber/go-glob v1.0.0 + github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 + github.com/stretchr/testify v1.4.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..341713a --- /dev/null +++ b/go.sum @@ -0,0 +1,53 @@ +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b h1:L/QXpzIa3pOvUGt1D1lA5KjYhPBAN/3iWdP7xeFS9F0= +github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA= +github.com/caarlos0/env v3.5.0+incompatible h1:Yy0UN8o9Wtr/jGHZDpCBLpNrzcFLLM2yixi/rBrKyJs= +github.com/caarlos0/env v3.5.0+incompatible/go.mod h1:tdCsowwCzMLdkqRYDlHpZCp2UooDD3MspDBjZ2AD02Y= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/hoisie/redis v0.0.0-20160730154456-b5c6e81454e0 h1:mjZV3MTu2A5gwfT5G9IIiLGdwZNciyVq5qqnmJJZ2JI= +github.com/hoisie/redis v0.0.0-20160730154456-b5c6e81454e0/go.mod h1:pMYMxVaKJqCDC1JUg/XbPJ4/fSazB25zORpFzqsIGIc= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/miekg/dns v1.1.18 h1:RP3QrPVgq8fLiw0mjYwVGNaIsCc9MxNFlRHu8PlAeiY= +github.com/miekg/dns v1.1.18/go.mod h1:WgzbA6oji13JREwiNsRDNfl7jYdPnmz+VEuLrA+/48M= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk= +github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 h1:WN9BUFbdyOsSH/XohnWpXOlq9NBD5sGAB2FciQMUEe8= +github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 h1:Gv7RPwsi3eZ2Fgewe3CBsuOebPwO27PoXzRpJPsvSSM= +golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM= +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd h1:DBH9mDw0zluJT/R+nGuV3jWFWLFaHyYZWD4tOT+cjn0= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/hosts.go b/hosts.go index 668c695..657cda7 100644 --- a/hosts.go +++ b/hosts.go @@ -5,10 +5,10 @@ import ( "time" "github.com/hoisie/redis" - ) +) type Hosts struct { - providers []HostProvider + providers []HostProvider refreshInterval time.Duration } diff --git a/hosts_file.go b/hosts_file.go index ab65245..b1b1af8 100644 --- a/hosts_file.go +++ b/hosts_file.go @@ -1,13 +1,13 @@ package main import ( - "sync" - "github.com/fsnotify/fsnotify" - "strings" - "os" "bufio" - "regexp" + "github.com/fsnotify/fsnotify" "github.com/ryanuber/go-glob" + "os" + "regexp" + "strings" + "sync" ) type FileHosts struct { diff --git a/hosts_redis.go b/hosts_redis.go index db4cee7..760aa26 100644 --- a/hosts_redis.go +++ b/hosts_redis.go @@ -2,9 +2,9 @@ package main import ( "github.com/hoisie/redis" - "sync" + "github.com/ryanuber/go-glob" "strings" - "github.com/ryanuber/go-glob" + "sync" ) type RedisHosts struct { @@ -19,7 +19,7 @@ type RedisHosts struct { func NewRedisProvider(rc *redis.Client, key string) HostProvider { rh := &RedisHosts{ redis: rc, - key: key, + key: key, hosts: make(map[string]string), } @@ -38,7 +38,7 @@ func NewRedisProvider(rc *redis.Client, key string) HostProvider { go rc.Subscribe(sub, nil, nil, nil, messages) for { - msg := <- messages + msg := <-messages if msg.Channel == "godns:update" { logger.Debug("Refreshing redis records due to update") @@ -89,7 +89,7 @@ func (r *RedisHosts) Get(domain string) ([]string, bool) { } if idx := strings.Index(domain, "."); idx != -1 { - wildcard := "*." + domain[strings.Index(domain, ".") + 1:] + wildcard := "*." + domain[strings.Index(domain, ".")+1:] if ip, ok := r.hosts[wildcard]; ok { return strings.Split(ip, ","), true diff --git a/resolver.go b/resolver.go index 1fbace8..39931e0 100644 --- a/resolver.go +++ b/resolver.go @@ -3,6 +3,7 @@ package main import ( "bufio" "fmt" + "log" "net" "os" "strconv" @@ -50,6 +51,8 @@ func NewResolver(c ResolvSettings) *Resolver { if len(c.ServerListFile) > 0 { r.ReadServerListFile(c.ServerListFile) + + log.Println("Read servers", strings.Join(r.servers, ", ")) } if len(c.ResolvFile) > 0 { @@ -112,7 +115,7 @@ func (r *Resolver) parseServerListFile(buf *os.File) { continue } - line = strings.TrimSpace(line[idx:]) + line = strings.TrimSpace(line[idx+1:]) if strings.HasPrefix(line, "https://") { r.servers = append(r.servers, line) diff --git a/server.go b/server.go index 8602a16..020ee48 100644 --- a/server.go +++ b/server.go @@ -6,7 +6,7 @@ import ( "time" "github.com/miekg/dns" - ) +) type Server struct { host string @@ -29,19 +29,19 @@ func (s *Server) Run() { udpHandler.HandleFunc(".", handler.DoUDP) tcpServer := &dns.Server{ - Addr: s.Addr(), - Net: "tcp", - Handler: tcpHandler, - ReadTimeout: s.rTimeout, + Addr: s.Addr(), + Net: "tcp", + Handler: tcpHandler, + ReadTimeout: s.rTimeout, WriteTimeout: s.wTimeout, } udpServer := &dns.Server{ - Addr: s.Addr(), - Net: "udp", - Handler: udpHandler, - UDPSize: 65535, - ReadTimeout: s.rTimeout, + Addr: s.Addr(), + Net: "udp", + Handler: udpHandler, + UDPSize: 65535, + ReadTimeout: s.rTimeout, WriteTimeout: s.wTimeout, } diff --git a/utils.go b/utils.go index 6e9bb61..9a19434 100644 --- a/utils.go +++ b/utils.go @@ -3,7 +3,7 @@ package main import ( "net" "regexp" - ) +) func isDomain(domain string) bool { if isIP(domain) { @@ -15,4 +15,4 @@ func isDomain(domain string) bool { func isIP(ip string) bool { return net.ParseIP(ip) != nil -} \ No newline at end of file +}