minor tweaks for multi-line nsupdate
This commit is contained in:
44
main.go
44
main.go
@@ -1,13 +1,16 @@
|
||||
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"
|
||||
)
|
||||
|
||||
@@ -34,5 +37,46 @@ func main() {
|
||||
// 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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user