package main import ( "fmt" "log" "os" "os/signal" "syscall" "time" "istheinternetonfire.app/internal/cisa" "istheinternetonfire.app/internal/config" "istheinternetonfire.app/internal/nsupdate" "istheinternetonfire.app/internal/webserver" ) func forever() { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM) sig := <-c log.Printf("[WARNING] shutting down, detected signal: %s", sig) } func main() { // initialize all parameters config.Init() // configure shutdown sequence defer func() { log.Printf("[TRACE] shutdown sequence complete") }() // start webserver go webserver.Start() // get remote data go cisa.Start() // update DNS records go func() { dns := nsupdate.New(config.Cfg.NSUKeyLabel, config.Cfg.NSUKeyAlgorithm, config.Cfg.NSUKey, config.Cfg.NSUServer, config.Cfg.NSUPort, config.Cfg.NSUZone) time.Sleep(time.Second * time.Duration(15)) for { var ( cves []cisa.VulStruct num int = 3 ) c := cisa.Read() for _, i := range c.Vulnerabilities { t, _ := time.Parse("2006-01-02", i.DateAdded) if t.After(time.Now().Add(-time.Hour * 720)) { cves = append(cves, i) } } if len(cves) == 0 { if err := dns.Delete("istheinternetonfire.app", "TXT"); err != nil { config.Cfg.Log.Error("unable to delete dns record", "error", err) time.Sleep(time.Second * time.Duration(config.Cfg.RefreshSeconds)) continue } } else if len(cves) < 3 { num = len(cves) } var txtData string for _, v := range cves[len(cves)-num:] { txtData += fmt.Sprintf("%s - %s - %s\n", v.CveID, v.Product, v.ShortDescription) } if err := dns.Update("istheinternetonfire.app", "TXT", txtData); err != nil { config.Cfg.Log.Error("unable to add dns record", "error", err) time.Sleep(time.Second * time.Duration(config.Cfg.RefreshSeconds)) continue } time.Sleep(time.Second * time.Duration(config.Cfg.RefreshSeconds)) } }() forever() }