debil-finder/main.go
2021-10-08 15:20:19 +02:00

77 lines
1.5 KiB
Go

package main
import (
"git.ddd.rip/ptrcnull/debil-finder/checks"
"git.ddd.rip/ptrcnull/telegram"
"github.com/CaliDog/certstream-go"
"log"
"os"
"strings"
)
func main() {
tg := telegram.Client{Token: os.Getenv("TELEGRAM_TOKEN")}
chatId := os.Getenv("TELEGRAM_CHAT_ID")
res, err := tg.SendMessage(chatId, "Starting...")
if err != nil {
panic(err)
}
log.Println(res)
c := &checks.Checks{
Message: func(msg string) {
tg.SendMessage(chatId, msg)
},
}
stream, errStream := certstream.CertStreamEventStream(false)
for {
select {
case jq := <-stream:
messageType, err := jq.String("message_type")
if err != nil {
tg.SendMessage(chatId, "failed decoding message: " + err.Error())
}
if messageType != "certificate_update" {
continue
}
allDomains, err := jq.ArrayOfStrings("data", "leaf_cert", "all_domains")
if err != nil {
tg.SendMessage(chatId, "failed getting domains: " + err.Error())
}
polish := false
ndc := false
for _, domain := range allDomains {
if strings.HasSuffix(domain, ".pl") {
polish = true
}
if strings.HasSuffix(domain, "ndc.pl") {
ndc = true
}
}
if !polish {
continue
}
if ndc {
continue
}
log.Println(allDomains)
for _, domain := range allDomains {
if domain[0] == '*' || domain == "sni.cloudflaressl.com" {
continue
}
log.Println("checking " + domain)
go c.CheckGit(domain)
go c.CheckEnv(domain)
go c.CheckIndex(domain)
}
case err := <-errStream:
log.Println(err)
}
}
}