package main

import (
	"os"
	"regexp"
	"time"

	"github.com/hashicorp/logutils"
)

type configStructure struct {
	// time configuration
	TimeFormat  string
	TimeZone    *time.Location
	TimeZoneUTC *time.Location

	// logging
	Log *logutils.LevelFilter

	// HTTP Client timeout configurations
	HTTPClientRequestTimeout      int
	HTTPClientConnectTimeout      int
	HTTPClientTLSHandshakeTimeout int
	HTTPClientIdleTimeout         int

	// Download Sources
	URLBlocklistHostFiles []string
	URLBlocklistsSimple   []string

	// Allowlist (regex)
	DomainAllowlist []*regexp.Regexp

	// Named Config Generator
	NamedConfig namedConfigStruct

	// Output Filename
	BindOutputFileName string
}

type namedConfigStruct struct {
	TTL         string
	Domain      string
	Email       string
	Timestamp   string
	Refresh     string
	Retry       string
	Expire      string
	Minimum     string
	NameServers []string
	BadDomains  []string
}

var config = configStructure{
	TimeFormat: "2006-01-02 15:04:05",
	Log: &logutils.LevelFilter{
		Levels: []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARNING", "ERROR"},
		Writer: os.Stderr,
	},

	// Nice blocklist location: https://firebog.net/
	// Default Blocklist
	URLBlocklistHostFiles: []string{
		"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts",
		"http://sysctl.org/cameleon/hosts",
		"https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate%20versions%20Anti-Malware%20List/AntiMalwareHosts.txt",
		"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts",
	},
	URLBlocklistsSimple: []string{
		"https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt",
		"https://s3.amazonaws.com/lists.disconnect.me/simple_malvertising.txt",
		"https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt",
		"https://v.firebog.net/hosts/Prigent-Crypto.txt",
		"https://phishing.army/download/phishing_army_blocklist_extended.txt",
		"https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-malware.txt",
		"https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt",
		"https://dbl.oisd.nl/",
		"https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt",
	},

	// default URL Allow hosts
	DomainAllowlist: []*regexp.Regexp{
		// localhosts included in blocklists for some reason
		regexp.MustCompile(`localhost`),
		regexp.MustCompile(`localhost.localdomain`),
		regexp.MustCompile(`local`),
		regexp.MustCompile(`broadcasthost`),
		regexp.MustCompile(`localhost`),
		regexp.MustCompile(`ip6-localhost`),
		regexp.MustCompile(`ip6-loopback`),
		regexp.MustCompile(`localhost`),
		regexp.MustCompile(`ip6-localnet`),
		regexp.MustCompile(`ip6-mcastprefix`),
		regexp.MustCompile(`ip6-allnodes`),
		regexp.MustCompile(`ip6-allrouters`),
		regexp.MustCompile(`ip6-allhosts`),
		// default allow hosts
		regexp.MustCompile(`(^|\.)` + `thepiratebay\.org`),
		regexp.MustCompile(`(^|\.)` + `sendgrid\.net`),
		regexp.MustCompile(`(^|\.)` + `googleadservices\.com`),
		regexp.MustCompile(`(^|\.)` + `doubleclick\.net`),
		regexp.MustCompile(`(^|\.)` + `sailthru\.com`),
		regexp.MustCompile(`(^|\.)` + `magiskmanager\.com`),
		regexp.MustCompile(`(^|\.)` + `apiservices\.krxd\.net`),
		regexp.MustCompile(`(^|\.)` + `logfiles\.zoom\.us`),
		regexp.MustCompile(`(^|\.)` + `logfiles-va\.zoom\.us`),
		regexp.MustCompile(`(^|\.)` + `nest\.com`),
		regexp.MustCompile(`(^|\.)` + `clients.\.google\.com`),
		regexp.MustCompile(`(^|\.)` + `login\.live\.com`),
		regexp.MustCompile(`(^|\.)` + `unagi\.amazon\.com`),
		regexp.MustCompile(`(^|\.)` + `unagi-na\.amazon\.com`),
		regexp.MustCompile(`(^|\.)` + `duckduckgo\.com`),
		regexp.MustCompile(`(^|\.)` + `msn\.com`),
		regexp.MustCompile(`(^|\.)` + `nexusrules\.officeapps\.live\.com`),
		regexp.MustCompile(`(^|\.)` + `playfabapi\.com`),
		regexp.MustCompile(`(^|\.)` + `vercel-dns\.com`),
	},
}