Commit b0a2c21e authored by Nogweii's avatar Nogweii
Browse files

now we read from a file

parent 773d636f
*.nogweii.net
*.github.com
*.microsoft.com
*.google.com
*.netflix.com
*.cloudflare.com
flowers-to-the-world.com
sni.cloudflaressl.com
......@@ -2,17 +2,23 @@ package main
import (
"strings"
"os"
"bufio"
"github.com/CaliDog/certstream-go"
"github.com/gobwas/glob"
log "github.com/sirupsen/logrus"
)
var globs []glob.Glob
func main() {
log.WithFields(log.Fields{
"version": "0.0.0", // TODO: actually get the version number
}).Info("Starting my certificate alert")
readDomainsFromFile("domains.txt")
stream, errStream := certstream.CertStreamEventStream(true)
for {
......@@ -46,22 +52,6 @@ func main() {
}
func matchesDomains(domainName string) bool {
var globs []glob.Glob
myGlob, err := glob.Compile("*.nogweii.net")
if err != nil {
log.WithFields(log.Fields{"error": err}).Fatal("Failed to compile glob")
}
globs = append(globs, myGlob)
// TODO: replace this with a file
globs = append(globs, glob.MustCompile("*.github.com"))
globs = append(globs, glob.MustCompile("*.microsoft.com"))
globs = append(globs, glob.MustCompile("*.google.com"))
globs = append(globs, glob.MustCompile("*.netflix.com"))
globs = append(globs, glob.MustCompile("*.cloudflare.com"))
globs = append(globs, glob.MustCompile("flowers-to-the-world.com"))
globs = append(globs, glob.MustCompile("sni.cloudflaressl.com"))
var any_match = false
for _, glob := range globs {
any_match = glob.Match(domainName) || any_match
......@@ -69,3 +59,28 @@ func matchesDomains(domainName string) bool {
return any_match
}
func readDomainsFromFile(filepath string) []glob.Glob {
file, err := os.Open(filepath)
if err != nil {
log.WithFields(log.Fields{"error": err}).Fatal("Failed to open file ", filepath)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
text := scanner.Text()
// TODO: skip blank and commented lines
myGlob, err := glob.Compile(text)
if err != nil {
log.WithFields(log.Fields{"error": err}).Fatal("Invalid glob ", text)
}
globs = append(globs, myGlob)
}
if err := scanner.Err(); err != nil {
log.WithFields(log.Fields{"error": err}).Fatal("Could not scan through file")
}
return globs
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment