1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

moving a bunch of packages under pkg (#124)

* moving a bunch of packages under pkg

* fix gen

* fix tst

* oops

* fix test fo real

* parse mx/a
This commit is contained in:
Craig Peterson
2017-05-25 14:25:39 -04:00
committed by GitHub
parent 01a242480c
commit 42ef9f4b9e
49 changed files with 140 additions and 49 deletions

View File

@ -5,14 +5,13 @@ import (
) )
func main() { func main() {
//go:generate esc -modtime 0 -o js/static.go -pkg js -include helpers\.js -ignore go -prefix js js
conf := &embed.Config{ conf := &embed.Config{
ModTime: "0", ModTime: "0",
OutputFile: "js/static.go", OutputFile: "pkg/js/static.go",
Package: "js", Package: "js",
Prefix: "js", Prefix: "pkg/js",
Private: true, Private: true,
Files: []string{`js/helpers.js`}, Files: []string{`pkg/js/helpers.js`},
} }
embed.Run(conf) embed.Run(conf)
} }

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/StackExchange/dnscontrol/dnsresolver" "github.com/StackExchange/dnscontrol/pkg/dnsresolver"
"github.com/StackExchange/dnscontrol/spflib" "github.com/StackExchange/dnscontrol/pkg/spflib"
) )
func main() { func main() {
@ -27,9 +27,11 @@ func main() {
fmt.Println("---------------------") fmt.Println("---------------------")
fmt.Println() fmt.Println()
res := dnsresolver.NewResolverLive("preload-dns.json") //res := dnsresolver.NewResolverLive("spf-store2.json")
//res := dnsresolver.NewResolverPreloaded("preload-dns.json") res, err := dnsresolver.NewResolverPreloaded("spf-store2.json")
if err != nil {
panic(err)
}
rec, err := spflib.Parse(strings.Join([]string{"v=spf1", rec, err := spflib.Parse(strings.Join([]string{"v=spf1",
"ip4:198.252.206.0/24", "ip4:198.252.206.0/24",
"ip4:192.111.0.0/24", "ip4:192.111.0.0/24",
@ -50,15 +52,15 @@ func main() {
fmt.Println("---------------------") fmt.Println("---------------------")
fmt.Println() fmt.Println()
var spfs []string var spf string
spfs, err = spflib.Lookup("stackex.com", res) spf, err = spflib.Lookup("whatexit.org", res)
if err != nil { if err != nil {
panic(err) panic(err)
} }
rec, err = spflib.Parse(strings.Join(spfs, " "), res) rec, err = spflib.Parse(spf, res)
if err != nil { if err != nil {
panic(err) panic(err)
} }
spflib.DumpSPF(rec, "") spflib.DumpSPF(rec, "")
//res.Close()
} }

View File

@ -0,0 +1,12 @@
{
"_spf.google.com": {
"txt": [
"v=spf1 include:_netblocks.google.com include:_netblocks2.google.com include:_netblocks3.google.com ~all"
]
},
"spf-basic.fogcreek.com": {
"txt": [
"v=spf1 ip4:64.34.80.172 -all"
]
}
}

View File

@ -0,0 +1,69 @@
{
"_netblocks.google.com": {
"txt": [
"v=spf1 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:108.177.8.0/21 ip4:173.194.0.0/16 ip4:207.126.144.0/20 ip4:209.85.128.0/17 ip4:216.58.192.0/19 ip4:216.239.32.0/19 ~all"
]
},
"_netblocks2.google.com": {
"txt": [
"v=spf1 ip6:2001:4860:4000::/36 ip6:2404:6800:4000::/36 ip6:2607:f8b0:4000::/36 ip6:2800:3f0:4000::/36 ip6:2a00:1450:4000::/36 ip6:2c0f:fb50:4000::/36 ~all"
]
},
"_netblocks3.google.com": {
"txt": [
"v=spf1 ip4:172.217.0.0/19 ip4:108.177.96.0/19 ~all"
]
},
"_spf.google.com": {
"txt": [
"v=spf1 include:_netblocks.google.com include:_netblocks2.google.com include:_netblocks3.google.com ~all"
]
},
"mail.zendesk.com": {
"txt": [
"v=spf1 ip4:192.161.144.0/20 ip4:185.12.80.0/22 ip4:96.46.150.192/27 ip4:174.137.46.0/24 ip4:188.172.128.0/20 ip4:216.198.0.0/18 ~all"
]
},
"mailgun.org": {
"txt": [
"google-site-verification=FIGVOKZm6lQFDBJaiC2DdwvBy8TInunoGCt-1gnL4PA",
"v=spf1 include:spf1.mailgun.org include:spf2.mailgun.org ~all"
]
},
"sendgrid.net": {
"txt": [
"v=spf1 ip4:167.89.0.0/17 ip4:208.117.48.0/20 ip4:50.31.32.0/19 ip4:198.37.144.0/20 ip4:198.21.0.0/21 ip4:192.254.112.0/20 ip4:168.245.0.0/17 ~all",
"google-site-verification=NxyooVvVaIgddVa23KTlOEuVPuhffcDqJFV8RzWrAys"
]
},
"servers.mcsv.net": {
"txt": [
"v=spf1 ip4:205.201.128.0/20 ip4:198.2.128.0/18 ip4:148.105.8.0/21 ?all"
]
},
"spf-basic.fogcreek.com": {
"txt": [
"v=spf1 ip4:64.34.80.172 -all"
]
},
"spf.mtasv.net": {
"txt": [
"v=spf1 ip4:50.31.156.96/27 ip4:104.245.209.192/26 ~all"
]
},
"spf1.mailgun.org": {
"txt": [
"v=spf1 ip4:173.193.210.32/27 ip4:50.23.218.192/27 ip4:174.37.226.64/27 ip4:208.43.239.136/30 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:104.130.122.0/23 ip4:146.20.112.0/26 ~all"
]
},
"spf2.mailgun.org": {
"txt": [
"v=spf1 ip4:209.61.151.0/24 ip4:166.78.68.0/22 ip4:198.61.254.0/23 ip4:192.237.158.0/23 ip4:23.253.182.0/23 ip4:104.130.96.0/28 ip4:146.20.113.0/24 ip4:146.20.191.0/24 ~all"
]
},
"whatexit.org": {
"txt": [
"v=spf1 ip6:2607:f2f8:a9c0::3 ip4:174.136.107.195 include:servers.mcsv.net include:_spf.google.com mx:evite.com -all"
]
}
}

View File

@ -10,7 +10,7 @@ import (
"strings" "strings"
"github.com/StackExchange/dnscontrol/models" "github.com/StackExchange/dnscontrol/models"
"github.com/StackExchange/dnscontrol/nameservers" "github.com/StackExchange/dnscontrol/pkg/nameservers"
"github.com/StackExchange/dnscontrol/providers" "github.com/StackExchange/dnscontrol/providers"
_ "github.com/StackExchange/dnscontrol/providers/_all" _ "github.com/StackExchange/dnscontrol/providers/_all"
"github.com/StackExchange/dnscontrol/providers/config" "github.com/StackExchange/dnscontrol/providers/config"

View File

@ -1,2 +0,0 @@
require("js/parse_tests/import.js")

View File

@ -12,10 +12,10 @@ import (
"strings" "strings"
"time" "time"
"github.com/StackExchange/dnscontrol/js"
"github.com/StackExchange/dnscontrol/models" "github.com/StackExchange/dnscontrol/models"
"github.com/StackExchange/dnscontrol/nameservers" "github.com/StackExchange/dnscontrol/pkg/js"
"github.com/StackExchange/dnscontrol/normalize" "github.com/StackExchange/dnscontrol/pkg/nameservers"
"github.com/StackExchange/dnscontrol/pkg/normalize"
"github.com/StackExchange/dnscontrol/providers" "github.com/StackExchange/dnscontrol/providers"
_ "github.com/StackExchange/dnscontrol/providers/_all" _ "github.com/StackExchange/dnscontrol/providers/_all"
"github.com/StackExchange/dnscontrol/providers/config" "github.com/StackExchange/dnscontrol/providers/config"

View File

@ -10,7 +10,7 @@ import (
"reflect" "reflect"
"strconv" "strconv"
"github.com/StackExchange/dnscontrol/transform" "github.com/StackExchange/dnscontrol/pkg/transform"
"github.com/miekg/dns" "github.com/miekg/dns"
"golang.org/x/net/idna" "golang.org/x/net/idna"
) )

View File

@ -12,12 +12,12 @@ import (
) )
const ( const (
testDir = "js/parse_tests" testDir = "pkg/js/parse_tests"
errorDir = "js/error_tests" errorDir = "pkg/js/error_tests"
) )
func init() { func init() {
os.Chdir("..") // go up a directory so we helpers.js is in a consistent place. os.Chdir("../..") // go up a directory so we helpers.js is in a consistent place.
} }
func TestParsedFiles(t *testing.T) { func TestParsedFiles(t *testing.T) {

View File

@ -0,0 +1,2 @@
require("pkg/js/parse_tests/import.js")

View File

@ -189,7 +189,7 @@ func _escFSMustString(useLocal bool, name string) string {
var _escData = map[string]*_escFile{ var _escData = map[string]*_escFile{
"/helpers.js": { "/helpers.js": {
local: "js/helpers.js", local: "pkg/js/helpers.js",
size: 8320, size: 8320,
modtime: 0, modtime: 0,
compressed: ` compressed: `
@ -240,6 +240,6 @@ juGPPwSZXUc736wWxSGRz1JGA/lBJGQc4pypseoabTAEaRwj1nqyQmvwU+ljuaLdYjToWa7VE3qVnY+p
"/": { "/": {
isDir: true, isDir: true,
local: "js", local: "pkg/js",
}, },
} }

View File

@ -6,8 +6,8 @@ import (
"strings" "strings"
"github.com/StackExchange/dnscontrol/models" "github.com/StackExchange/dnscontrol/models"
"github.com/StackExchange/dnscontrol/pkg/transform"
"github.com/StackExchange/dnscontrol/providers" "github.com/StackExchange/dnscontrol/providers"
"github.com/StackExchange/dnscontrol/transform"
"github.com/miekg/dns" "github.com/miekg/dns"
"github.com/miekg/dns/dnsutil" "github.com/miekg/dns/dnsutil"
) )

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/StackExchange/dnscontrol/dnsresolver" "github.com/StackExchange/dnscontrol/pkg/dnsresolver"
) )
type SPFRecord struct { type SPFRecord struct {
@ -18,10 +18,10 @@ type SPFPart struct {
IncludeRecord *SPFRecord IncludeRecord *SPFRecord
} }
func Lookup(target string, dnsres dnsresolver.DnsResolver) ([]string, error) { func Lookup(target string, dnsres dnsresolver.DnsResolver) (string, error) {
txts, err := dnsres.GetTxt(target) txts, err := dnsres.GetTxt(target)
if err != nil { if err != nil {
return nil, err return "", err
} }
var result []string var result []string
for _, txt := range txts { for _, txt := range txts {
@ -29,7 +29,20 @@ func Lookup(target string, dnsres dnsresolver.DnsResolver) ([]string, error) {
result = append(result, txt) result = append(result, txt)
} }
} }
return result, nil if len(result) == 0 {
return "", fmt.Errorf("%s has no spf TXT records", target)
}
if len(result) != 1 {
return "", fmt.Errorf("%s has multiple spf TXT records", target)
}
return result[0], nil
}
var qualifiers = map[byte]bool{
'?': true,
'~': true,
'-': true,
'+': true,
} }
func Parse(text string, dnsres dnsresolver.DnsResolver) (*SPFRecord, error) { func Parse(text string, dnsres dnsresolver.DnsResolver) (*SPFRecord, error) {
@ -40,17 +53,23 @@ func Parse(text string, dnsres dnsresolver.DnsResolver) (*SPFRecord, error) {
rec := &SPFRecord{} rec := &SPFRecord{}
for _, part := range parts[1:] { for _, part := range parts[1:] {
p := &SPFPart{Text: part} p := &SPFPart{Text: part}
if qualifiers[part[0]] {
part = part[1:]
}
rec.Parts = append(rec.Parts, p) rec.Parts = append(rec.Parts, p)
if part == "~all" || part == "-all" || part == "?all" { if part == "all" {
//all. nothing else matters. //all. nothing else matters.
break break
} else if strings.HasPrefix(part, "a") || strings.HasPrefix(part, "mx") {
rec.Lookups++
p.Lookups = 1
} else if strings.HasPrefix(part, "ip4:") || strings.HasPrefix(part, "ip6:") { } else if strings.HasPrefix(part, "ip4:") || strings.HasPrefix(part, "ip6:") {
//ip address, 0 lookups //ip address, 0 lookups
continue continue
} else if strings.HasPrefix(part, "include:") { } else if strings.HasPrefix(part, "include:") {
rec.Lookups++ rec.Lookups++
includeTarget := strings.TrimPrefix(part, "include:") includeTarget := strings.TrimPrefix(part, "include:")
subRecord, err := resolveSPF(includeTarget, dnsres) subRecord, err := Lookup(includeTarget, dnsres)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -59,6 +78,7 @@ func Parse(text string, dnsres dnsresolver.DnsResolver) (*SPFRecord, error) {
return nil, fmt.Errorf("In included spf: %s", err) return nil, fmt.Errorf("In included spf: %s", err)
} }
rec.Lookups += p.IncludeRecord.Lookups rec.Lookups += p.IncludeRecord.Lookups
p.Lookups = p.IncludeRecord.Lookups + 1
} else { } else {
return nil, fmt.Errorf("Unsupported spf part %s", part) return nil, fmt.Errorf("Unsupported spf part %s", part)
} }
@ -77,22 +97,11 @@ func DumpSPF(rec *SPFRecord, indent string) {
fmt.Println() fmt.Println()
indent += "\t" indent += "\t"
for _, p := range rec.Parts { for _, p := range rec.Parts {
if p.IncludeRecord != nil { if p.Lookups > 0 {
fmt.Println(indent + p.Text) fmt.Println(indent + p.Text)
}
if p.IncludeRecord != nil {
DumpSPF(p.IncludeRecord, indent+"\t") DumpSPF(p.IncludeRecord, indent+"\t")
} }
} }
} }
func resolveSPF(target string, dnsres dnsresolver.DnsResolver) (string, error) {
recs, err := dnsres.GetTxt(target)
if err != nil {
return "", err
}
for _, r := range recs {
if strings.HasPrefix(r, "v=spf1 ") {
return r, nil
}
}
return "", fmt.Errorf("No SPF records found for %s", target)
}

View File

@ -4,7 +4,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/StackExchange/dnscontrol/dnsresolver" "github.com/StackExchange/dnscontrol/pkg/dnsresolver"
) )
func TestParse(t *testing.T) { func TestParse(t *testing.T) {

View File

@ -9,9 +9,9 @@ import (
"time" "time"
"github.com/StackExchange/dnscontrol/models" "github.com/StackExchange/dnscontrol/models"
"github.com/StackExchange/dnscontrol/pkg/transform"
"github.com/StackExchange/dnscontrol/providers" "github.com/StackExchange/dnscontrol/providers"
"github.com/StackExchange/dnscontrol/providers/diff" "github.com/StackExchange/dnscontrol/providers/diff"
"github.com/StackExchange/dnscontrol/transform"
"github.com/miekg/dns/dnsutil" "github.com/miekg/dns/dnsutil"
) )

View File

@ -5,7 +5,7 @@ import (
"testing" "testing"
"github.com/StackExchange/dnscontrol/models" "github.com/StackExchange/dnscontrol/models"
"github.com/StackExchange/dnscontrol/transform" "github.com/StackExchange/dnscontrol/pkg/transform"
) )
func newDomainConfig() *models.DomainConfig { func newDomainConfig() *models.DomainConfig {