diff --git a/cmd/domaincheckadd/main.go b/cmd/domaincheckadd/main.go index 6406194..5b9babd 100644 --- a/cmd/domaincheckadd/main.go +++ b/cmd/domaincheckadd/main.go @@ -18,9 +18,9 @@ func main() { scanner := bufio.NewScanner(os.Stdin) - var newDomains []string + var newDomains [][]string - fmt.Print("domains: ") + fmt.Print("domains (tld separated by ';'): ") if scanner.Scan() { input := scanner.Text() @@ -39,8 +39,9 @@ func main() { sort.SliceStable(values, func(i, j int) bool { return values[i] < values[j] }) - - newDomains = values + for _, value := range values { + newDomains = append(newDomains, strings.Split(value, ";")) + } } logger.Info("domains to add", slog.Any("domains", newDomains)) @@ -61,9 +62,9 @@ func main() { } -func storeDomains(domains []string) error { +func storeDomains(domains [][]string) error { for _, domain := range domains { - config.AddDomain(domain) + config.AddDomain(domain[0], domain[1]) } file, _ := json.MarshalIndent(config.Domains, "", " ") err := os.WriteFile("./cmd/domaincheckbot/config/domain.json", file, 0644) diff --git a/cmd/domaincheckbot/config/domain.go b/cmd/domaincheckbot/config/domain.go index be27809..d0be9d6 100644 --- a/cmd/domaincheckbot/config/domain.go +++ b/cmd/domaincheckbot/config/domain.go @@ -4,13 +4,13 @@ import ( _ "embed" "encoding/json" "log" - "sort" + "slices" ) //go:embed domain.json var domainsFiles []byte -var Domains []string +var Domains map[string][]string func init() { err := json.Unmarshal(domainsFiles, &Domains) @@ -19,22 +19,12 @@ func init() { } } -func AddDomain(domain string) { - domains := append(Domains, domain) - sort.SliceStable(domains, func(i, j int) bool { - return domains[i] < domains[j] - }) - Domains = removeDuplicate(domains) -} - -func removeDuplicate[T string](sliceList []T) []T { - allKeys := make(map[T]bool) - var list []T - for _, item := range sliceList { - if _, value := allKeys[item]; !value { - allKeys[item] = true - list = append(list, item) +func AddDomain(domain, tld string) { + if _, ok := Domains[domain]; ok { + if !slices.Contains(Domains[domain], tld) { + Domains[domain] = append(Domains[domain], tld) } + } else { + Domains[domain] = []string{tld} } - return list } diff --git a/cmd/domaincheckbot/config/domain.json b/cmd/domaincheckbot/config/domain.json index 98f9379..13f8dff 100644 --- a/cmd/domaincheckbot/config/domain.json +++ b/cmd/domaincheckbot/config/domain.json @@ -1,127 +1,251 @@ -[ - "1488.ch", - "ascii.tools", - "astonish.ch", - "astonishing.ch", - "attribution.ch", - "baloise.ch", - "baloise.com", - "baloise.social", - "blizan.ch", - "buehnenbande.ch", - "cdn.army", - "cdn.exposed", - "cdn.garden", - "cdn.gmbh", - "cloudscale.ch", - "compass-security.com", - "cori.us", - "emh.ch", - "ergon.ch", - "example.com", - "exoscale.com", - "familie.st", - "family.st", - "felizian.ch", - "felizian.st", - "fst.ch", - "fst.dev", - "g8.co", - "g8.com", - "g8.io", - "g8.is", - "g8.lol", - "g8.net", - "g8.nz", - "g8.re", - "g8.si", - "gr8.click", - "gwydi.me", - "heller.support", - "home.cern", - "incline.ch", - "liip.ch", - "linuxfabrik.ch", - "mojang.studio", - "nilu.ch", - "nqa.ch", - "open-systems.com", - "oriented.net", - "phynecs.com", - "poisoned.app", - "poisonedapple.ch", - "puzzle.ch", - "redhat.ch", - "rievo.app", - "rievo.cc", - "rievo.ch", - "rievo.co", - "rievo.co.uk", - "rievo.com", - "rievo.cz", - "rievo.de", - "rievo.dev", - "rievo.eu", - "rievo.eu.org", - "rievo.group", - "rievo.host", - "rievo.info", - "rievo.io", - "rievo.net", - "rievo.org", - "rievo.page", - "rievo.swiss", - "rievo.systems", - "rievo.uk", - "rievo.us", - "rievo.xyz", - "rv.gy", - "rvo.co", - "rvo.com", - "rvo.net", - "rvo.one", - "rvo.re", - "schuer.ch", - "schuerch.ch", - "schuerch.co", - "schuerch.com", - "schuerch.dev", - "schuerch.id", - "schuerch.net", - "schuerch.xyz", - "schur.ch", - "schurch.ch", - "schurch.com", - "schurch.dev", - "schurch.net", - "schwabe.ch", - "scrib.li", - "seraphimstrub.com", - "signage.ch", - "sos-esport.com", - "sos-esports.com", - "sst.ch", - "sst.dev", - "sst.place", - "strub.cc", - "strub.ch", - "strub.co", - "strub.com", - "strub.consulting", - "strub.info", - "strub.net", - "strub.one", - "strub.org", - "strub.st", - "strub.swiss", - "strub.xyz", - "switzer.land", - "swizer.land", - "thehat.ch", - "threema.ch", - "ti8m.com", - "trashcitizen.com", - "unlogis.ch", - "vshn.ch", - "xii.st" -] \ No newline at end of file +{ + "1488": [ + "ch" + ], + "ascii": [ + "tools" + ], + "astonish": [ + "ch" + ], + "astonishing": [ + "ch" + ], + "attribution": [ + "ch" + ], + "baloise": [ + "ch", + "com", + "social" + ], + "blizan": [ + "ch" + ], + "buehnenbande": [ + "ch" + ], + "cdn": [ + "army", + "exposed", + "garden", + "gmbh" + ], + "cloudscale": [ + "ch" + ], + "compass-security": [ + "com" + ], + "cori": [ + "us" + ], + "emh": [ + "ch" + ], + "ergon": [ + "ch" + ], + "example": [ + "com" + ], + "exoscale": [ + "com" + ], + "familie": [ + "st" + ], + "family": [ + "st" + ], + "felizian": [ + "ch", + "st" + ], + "fst": [ + "ch", + "dev" + ], + "g8": [ + "co", + "com", + "io", + "is", + "lol", + "net", + "nz", + "re", + "si" + ], + "gr8": [ + "click" + ], + "gwydi": [ + "me" + ], + "heller": [ + "support" + ], + "home": [ + "cern" + ], + "incline": [ + "ch" + ], + "liip": [ + "ch" + ], + "linuxfabrik": [ + "ch" + ], + "mojang": [ + "studio" + ], + "nilu": [ + "ch" + ], + "nqa": [ + "ch" + ], + "open-systems": [ + "com" + ], + "oriented": [ + "net" + ], + "phynecs": [ + "com" + ], + "poisoned": [ + "app" + ], + "poisonedapple": [ + "ch" + ], + "puzzle": [ + "ch" + ], + "redhat": [ + "ch" + ], + "rievo": [ + "app", + "cc", + "ch", + "co", + "co.uk", + "com", + "cz", + "de", + "dev", + "eu", + "eu.org", + "group", + "host", + "io", + "net", + "org", + "page", + "swiss", + "systems", + "uk", + "us", + "xyz" + ], + "rv": [ + "gy" + ], + "rvo": [ + "co", + "com", + "net", + "one", + "re" + ], + "schuer": [ + "ch" + ], + "schuerch": [ + "ch", + "co", + "com", + "dev", + "id", + "net", + "xyz" + ], + "schur": [ + "ch" + ], + "schurch": [ + "ch", + "com", + "dev", + "net" + ], + "schwabe": [ + "ch" + ], + "scrib": [ + "li" + ], + "seraphimstrub": [ + "com" + ], + "signage": [ + "ch" + ], + "sos-esport": [ + "com" + ], + "sos-esports": [ + "com" + ], + "sst": [ + "ch", + "dev", + "place" + ], + "strub": [ + "cc", + "ch", + "co", + "com", + "consulting", + "info", + "net", + "one", + "org", + "st", + "swiss", + "xyz" + ], + "switzer": [ + "land" + ], + "swizer": [ + "land" + ], + "thehat": [ + "ch" + ], + "threema": [ + "ch" + ], + "ti8m": [ + "com" + ], + "trashcitizen": [ + "com" + ], + "unlogis": [ + "ch" + ], + "vshn": [ + "ch", + "net" + ], + "xii": [ + "st" + ] +} \ No newline at end of file diff --git a/cmd/domaincheckbot/main.go b/cmd/domaincheckbot/main.go index b35687b..fa0cbbd 100644 --- a/cmd/domaincheckbot/main.go +++ b/cmd/domaincheckbot/main.go @@ -65,8 +65,10 @@ func main() { for { select { case <-ticker.C: - for _, d := range config.Domains { - go checkDomain(0, d, query, client) + for d, tlds := range config.Domains { + for _, tld := range tlds { + go checkDomain(0, fmt.Sprintf("%v.%v", d, tld), query, client) + } } case <-quit: @@ -94,7 +96,7 @@ func checkDomain(counter int, d string, query *db.Queries, client webhook.Client logger.Debug("domain did not change", slog.String("domain", d)) return } - logger.Info("domain changed changed", slog.String("domain", d)) + logger.Info("domain changed", slog.String("domain", d)) counter += 1 if counter >= 2 { go sendWebhook(client, domain, retrievedDomain) diff --git a/cmd/domainchecklist/main.go b/cmd/domainchecklist/main.go index c6f0649..8fad752 100644 --- a/cmd/domainchecklist/main.go +++ b/cmd/domainchecklist/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "grow.rievo.dev/discordBots/cmd/domaincheckbot/config" "grow.rievo.dev/discordBots/cmd/domaincheckbot/dns" "log" @@ -9,11 +10,14 @@ import ( func main() { log.Println("check domains in domains.json") - for _, domain := range config.Domains { - d := dns.CheckDomain(domain) - if len(d.NS) > 0 && d.NS[0] == "ns.rievo.ch." { - continue + for domain, tlds := range config.Domains { + for _, tld := range tlds { + d := dns.CheckDomain(fmt.Sprintf("%v.%v", domain, tld)) + if len(d.NS) > 0 && d.NS[0] == "ns.rievo.ch." { + continue + } + log.Println(dns.CheckDomain(fmt.Sprintf("%v.%v", domain, tld))) } - log.Println(dns.CheckDomain(domain)) + } } diff --git a/go.sum b/go.sum index ae0297b..09964bc 100644 --- a/go.sum +++ b/go.sum @@ -61,8 +61,6 @@ modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4= modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0= modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc= modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss= -modernc.org/sqlite v1.30.1 h1:YFhPVfu2iIgUf9kuA1CR7iiHdcEEsI2i+yjRYHscyxk= -modernc.org/sqlite v1.30.1/go.mod h1:DUmsiWQDaAvU4abhc/N+djlom/L2o8f7gZ95RCvyoLU= modernc.org/sqlite v1.30.2 h1:IPVVkhLu5mMVnS1dQgh3h0SAACRWcVk7aoLP9Us3UCk= modernc.org/sqlite v1.30.2/go.mod h1:DUmsiWQDaAvU4abhc/N+djlom/L2o8f7gZ95RCvyoLU= modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=