switch to advanced domain.json

This commit is contained in:
Seraphim Strub 2024-07-15 19:37:06 +00:00
parent 1c848e6007
commit a76b11b2b2
6 changed files with 280 additions and 161 deletions

View file

@ -18,9 +18,9 @@ func main() {
scanner := bufio.NewScanner(os.Stdin) scanner := bufio.NewScanner(os.Stdin)
var newDomains []string var newDomains [][]string
fmt.Print("domains: ") fmt.Print("domains (tld separated by ';'): ")
if scanner.Scan() { if scanner.Scan() {
input := scanner.Text() input := scanner.Text()
@ -39,8 +39,9 @@ func main() {
sort.SliceStable(values, func(i, j int) bool { sort.SliceStable(values, func(i, j int) bool {
return values[i] < values[j] return values[i] < values[j]
}) })
for _, value := range values {
newDomains = values newDomains = append(newDomains, strings.Split(value, ";"))
}
} }
logger.Info("domains to add", slog.Any("domains", newDomains)) 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 { for _, domain := range domains {
config.AddDomain(domain) config.AddDomain(domain[0], domain[1])
} }
file, _ := json.MarshalIndent(config.Domains, "", " ") file, _ := json.MarshalIndent(config.Domains, "", " ")
err := os.WriteFile("./cmd/domaincheckbot/config/domain.json", file, 0644) err := os.WriteFile("./cmd/domaincheckbot/config/domain.json", file, 0644)

View file

@ -4,13 +4,13 @@ import (
_ "embed" _ "embed"
"encoding/json" "encoding/json"
"log" "log"
"sort" "slices"
) )
//go:embed domain.json //go:embed domain.json
var domainsFiles []byte var domainsFiles []byte
var Domains []string var Domains map[string][]string
func init() { func init() {
err := json.Unmarshal(domainsFiles, &Domains) err := json.Unmarshal(domainsFiles, &Domains)
@ -19,22 +19,12 @@ func init() {
} }
} }
func AddDomain(domain string) { func AddDomain(domain, tld string) {
domains := append(Domains, domain) if _, ok := Domains[domain]; ok {
sort.SliceStable(domains, func(i, j int) bool { if !slices.Contains(Domains[domain], tld) {
return domains[i] < domains[j] Domains[domain] = append(Domains[domain], tld)
})
Domains = removeDuplicate(domains)
} }
} else {
func removeDuplicate[T string](sliceList []T) []T { Domains[domain] = []string{tld}
allKeys := make(map[T]bool)
var list []T
for _, item := range sliceList {
if _, value := allKeys[item]; !value {
allKeys[item] = true
list = append(list, item)
} }
} }
return list
}

View file

@ -1,127 +1,251 @@
[ {
"1488.ch", "1488": [
"ascii.tools", "ch"
"astonish.ch", ],
"astonishing.ch", "ascii": [
"attribution.ch", "tools"
"baloise.ch", ],
"baloise.com", "astonish": [
"baloise.social", "ch"
"blizan.ch", ],
"buehnenbande.ch", "astonishing": [
"cdn.army", "ch"
"cdn.exposed", ],
"cdn.garden", "attribution": [
"cdn.gmbh", "ch"
"cloudscale.ch", ],
"compass-security.com", "baloise": [
"cori.us", "ch",
"emh.ch", "com",
"ergon.ch", "social"
"example.com", ],
"exoscale.com", "blizan": [
"familie.st", "ch"
"family.st", ],
"felizian.ch", "buehnenbande": [
"felizian.st", "ch"
"fst.ch", ],
"fst.dev", "cdn": [
"g8.co", "army",
"g8.com", "exposed",
"g8.io", "garden",
"g8.is", "gmbh"
"g8.lol", ],
"g8.net", "cloudscale": [
"g8.nz", "ch"
"g8.re", ],
"g8.si", "compass-security": [
"gr8.click", "com"
"gwydi.me", ],
"heller.support", "cori": [
"home.cern", "us"
"incline.ch", ],
"liip.ch", "emh": [
"linuxfabrik.ch", "ch"
"mojang.studio", ],
"nilu.ch", "ergon": [
"nqa.ch", "ch"
"open-systems.com", ],
"oriented.net", "example": [
"phynecs.com", "com"
"poisoned.app", ],
"poisonedapple.ch", "exoscale": [
"puzzle.ch", "com"
"redhat.ch", ],
"rievo.app", "familie": [
"rievo.cc", "st"
"rievo.ch", ],
"rievo.co", "family": [
"rievo.co.uk", "st"
"rievo.com", ],
"rievo.cz", "felizian": [
"rievo.de", "ch",
"rievo.dev", "st"
"rievo.eu", ],
"rievo.eu.org", "fst": [
"rievo.group", "ch",
"rievo.host", "dev"
"rievo.info", ],
"rievo.io", "g8": [
"rievo.net", "co",
"rievo.org", "com",
"rievo.page", "io",
"rievo.swiss", "is",
"rievo.systems", "lol",
"rievo.uk", "net",
"rievo.us", "nz",
"rievo.xyz", "re",
"rv.gy", "si"
"rvo.co", ],
"rvo.com", "gr8": [
"rvo.net", "click"
"rvo.one", ],
"rvo.re", "gwydi": [
"schuer.ch", "me"
"schuerch.ch", ],
"schuerch.co", "heller": [
"schuerch.com", "support"
"schuerch.dev", ],
"schuerch.id", "home": [
"schuerch.net", "cern"
"schuerch.xyz", ],
"schur.ch", "incline": [
"schurch.ch", "ch"
"schurch.com", ],
"schurch.dev", "liip": [
"schurch.net", "ch"
"schwabe.ch", ],
"scrib.li", "linuxfabrik": [
"seraphimstrub.com", "ch"
"signage.ch", ],
"sos-esport.com", "mojang": [
"sos-esports.com", "studio"
"sst.ch", ],
"sst.dev", "nilu": [
"sst.place", "ch"
"strub.cc", ],
"strub.ch", "nqa": [
"strub.co", "ch"
"strub.com", ],
"strub.consulting", "open-systems": [
"strub.info", "com"
"strub.net", ],
"strub.one", "oriented": [
"strub.org", "net"
"strub.st", ],
"strub.swiss", "phynecs": [
"strub.xyz", "com"
"switzer.land", ],
"swizer.land", "poisoned": [
"thehat.ch", "app"
"threema.ch", ],
"ti8m.com", "poisonedapple": [
"trashcitizen.com", "ch"
"unlogis.ch", ],
"vshn.ch", "puzzle": [
"xii.st" "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"
] ]
}

View file

@ -65,8 +65,10 @@ func main() {
for { for {
select { select {
case <-ticker.C: case <-ticker.C:
for _, d := range config.Domains { for d, tlds := range config.Domains {
go checkDomain(0, d, query, client) for _, tld := range tlds {
go checkDomain(0, fmt.Sprintf("%v.%v", d, tld), query, client)
}
} }
case <-quit: 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)) logger.Debug("domain did not change", slog.String("domain", d))
return return
} }
logger.Info("domain changed changed", slog.String("domain", d)) logger.Info("domain changed", slog.String("domain", d))
counter += 1 counter += 1
if counter >= 2 { if counter >= 2 {
go sendWebhook(client, domain, retrievedDomain) go sendWebhook(client, domain, retrievedDomain)

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"grow.rievo.dev/discordBots/cmd/domaincheckbot/config" "grow.rievo.dev/discordBots/cmd/domaincheckbot/config"
"grow.rievo.dev/discordBots/cmd/domaincheckbot/dns" "grow.rievo.dev/discordBots/cmd/domaincheckbot/dns"
"log" "log"
@ -9,11 +10,14 @@ import (
func main() { func main() {
log.Println("check domains in domains.json") log.Println("check domains in domains.json")
for _, domain := range config.Domains { for domain, tlds := range config.Domains {
d := dns.CheckDomain(domain) for _, tld := range tlds {
d := dns.CheckDomain(fmt.Sprintf("%v.%v", domain, tld))
if len(d.NS) > 0 && d.NS[0] == "ns.rievo.ch." { if len(d.NS) > 0 && d.NS[0] == "ns.rievo.ch." {
continue continue
} }
log.Println(dns.CheckDomain(domain)) log.Println(dns.CheckDomain(fmt.Sprintf("%v.%v", domain, tld)))
}
} }
} }

2
go.sum
View file

@ -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/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc= modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc=
modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss= 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 h1:IPVVkhLu5mMVnS1dQgh3h0SAACRWcVk7aoLP9Us3UCk=
modernc.org/sqlite v1.30.2/go.mod h1:DUmsiWQDaAvU4abhc/N+djlom/L2o8f7gZ95RCvyoLU= modernc.org/sqlite v1.30.2/go.mod h1:DUmsiWQDaAvU4abhc/N+djlom/L2o8f7gZ95RCvyoLU=
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA= modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=