2019-08-25 18:38:08 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
registerProvider("domain-list", providerdomainList{})
|
|
|
|
}
|
|
|
|
|
|
|
|
type providerdomainList struct{}
|
|
|
|
|
|
|
|
func (p providerdomainList) GetDomainList(d providerDefinition) ([]entry, error) {
|
|
|
|
r, err := d.GetContent()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Unable to get source content")
|
|
|
|
}
|
|
|
|
defer r.Close()
|
|
|
|
|
|
|
|
logger := log.WithField("provider", d.Name)
|
|
|
|
|
|
|
|
var entries []entry
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(r)
|
|
|
|
for scanner.Scan() {
|
|
|
|
if lineIsComment(scanner.Text()) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
domain := strings.TrimSpace(scanner.Text())
|
|
|
|
|
2019-08-25 19:14:30 +00:00
|
|
|
if strings.Contains(domain, " ") {
|
|
|
|
logger.WithField("line", scanner.Text()).Warn("Invalid line found")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-08-25 18:38:08 +00:00
|
|
|
if isBlacklisted(domain) {
|
|
|
|
logger.WithField("domain", domain).Debug("Skipping because of blacklist")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
entries = append(entries, entry{
|
2020-02-15 13:22:35 +00:00
|
|
|
Domain: domain,
|
|
|
|
Comments: []string{d.Name},
|
2019-08-25 18:38:08 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return entries, nil
|
|
|
|
}
|