|
|
|
@ -3,11 +3,8 @@ package main
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
"net/http"
|
|
|
|
|
"regexp"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/adamveld12/gopherhole/client/public"
|
|
|
|
@ -16,22 +13,21 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
configFilePath = flag.String("config", "./config.json", "Config file")
|
|
|
|
|
// dbPath = flag.String("db-path", ".", "Directory to write database files to")
|
|
|
|
|
// httpAddr = flag.String("http-address", ":8080", "Bind address for http server")
|
|
|
|
|
// dnsAddr = flag.String("dns-address", ":53", "Bind address for dns server")
|
|
|
|
|
|
|
|
|
|
dbPath = flag.String("db-path", ".", "Directory to write database files to")
|
|
|
|
|
httpAddr = flag.String("http-address", ":80", "Bind address for http server")
|
|
|
|
|
dnsAddr = flag.String("dns-address", ":53", "Bind address for dns server")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
flag.Parse()
|
|
|
|
|
log.SetFlags(log.LUTC | log.Lshortfile)
|
|
|
|
|
|
|
|
|
|
var conf StartupConfig
|
|
|
|
|
if err := LoadStartupConfig(&conf, *configFilePath); err != nil {
|
|
|
|
|
log.Fatalf("%+v", err)
|
|
|
|
|
conf := StartupConfig{
|
|
|
|
|
HTTPAddr: *httpAddr,
|
|
|
|
|
DNSAddr: *dnsAddr,
|
|
|
|
|
DatabaseURL: *dbPath,
|
|
|
|
|
}
|
|
|
|
|
// conf.HTTPAddr = *httpAddr
|
|
|
|
|
// conf.DNSAddr = *dnsAddr
|
|
|
|
|
|
|
|
|
|
log.Printf("%+v", conf)
|
|
|
|
|
store := &internal.Sqlite{
|
|
|
|
|
Path: conf.DatabaseURL,
|
|
|
|
@ -61,7 +57,7 @@ func main() {
|
|
|
|
|
Storage: store,
|
|
|
|
|
RuleEvaluator: re,
|
|
|
|
|
Recursors: internal.Recursor{
|
|
|
|
|
Upstreams: cleanRecursors(conf.Recursors),
|
|
|
|
|
Upstreams: []string{"1.1.1.1:53"},
|
|
|
|
|
Client: dnsClient,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
@ -78,23 +74,3 @@ func main() {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func cleanRecursors(recursors []string) []string {
|
|
|
|
|
cr := []string{}
|
|
|
|
|
reg := regexp.MustCompile(`^((?:\d{1,4}\.?){4})(?::(\d{0,5}))?`)
|
|
|
|
|
for _, r := range recursors {
|
|
|
|
|
if !reg.MatchString(r) {
|
|
|
|
|
log.Fatalf("%s is not a valid DNS server. Must be in ip:addr format.", r)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cleanedIPAddr := r
|
|
|
|
|
if !strings.Contains(r, ":") {
|
|
|
|
|
cleanedIPAddr = fmt.Sprintf("%s:53", r)
|
|
|
|
|
}
|
|
|
|
|
cr = append(cr, cleanedIPAddr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Println(cr)
|
|
|
|
|
|
|
|
|
|
return cr
|
|
|
|
|
}
|
|
|
|
|