File: opendns.go

package info (click to toggle)
hellfire 0.0~git20180708.bf3c390-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 96 kB
  • sloc: makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,579 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package hellfire // import "pathspider.net/hellfire"

import (
	"fmt"
	"log"
	"strings"
)

type OpenDNSList struct {
	TestList
	listname string
	filename string
}

// URL format string to download the OpenDNS public domain list from. The %s
// will be replaced with the name of the list as specified in the call to
// SetListName before the job feeder is activated.
const OpenDNSListURL string = "https://raw.githubusercontent.com/opendns/public-domain-lists/master/opendns-%s-domains.txt"

func (l *OpenDNSList) SetFilename(filename string) {
	l.filename = filename
}

// The SetListName method allows selection of the OpenDNS list to use. This
// function accepts either "top" or "random" as the list name.
//
// This function must be called before FeedJobs() or the application will panic.
func (l *OpenDNSList) SetListName(listname string) {
	listname = strings.ToLower(listname)
	if listname == "top" || listname == "random" {
		l.listname = listname
	} else {
		panic("List name must be either \"top\" or \"random\".")
	}
}

func (l *OpenDNSList) FeedJobs(jobs chan map[string]interface{}) {
	var openDNSList *CSVList

	if l.filename == "" {
		if l.listname == "" {
			panic("The list name to use was not specified.")
		}
		listUrl := fmt.Sprintf(OpenDNSListURL, l.listname)
		urlReader, err := getReaderFromUrl(listUrl)
		if err != nil {
			log.Fatalf("Unable to get <%s>: %s", listUrl, err)
		}

		openDNSList = CSVListFromReader(urlReader)
	} else {
		openDNSList = CSVListFromFile(l.filename)
	}
	openDNSList.SetHeader([]string{"domain"})
	openDNSList.FeedJobs(jobs)
}