small tweaks

This commit is contained in:
Hyatt 2024-01-19 17:43:40 -06:00
parent c1739856ce
commit 567cfe8083
Signed by: nhyatt
GPG Key ID: C50D0BBB5BC40BEA
6 changed files with 20 additions and 12795 deletions

View File

@ -19,7 +19,7 @@
</head> </head>
<body style="text-align:center;"> <body style="text-align:center;">
<small> <small>
[<a href="./status.txt">txt</a>]&nbsp;<tt>dig +short txt istheinternetonfire.app | sed 's/" "//g' |sed 's/%n/\n/g'</tt>&nbsp;[<a href="./status.json">json</a>] [<a href="./status.txt">txt</a>]&nbsp;<tt>dig +short txt istheinternetonfire.app | sed 's/" "//g' | sed 's/%n/\n/g'</tt>&nbsp;[<a href="./status.json">json</a>]
</small> </small>
<hr align="CENTER" noshade="noshade" size="2" width="100%"> <hr align="CENTER" noshade="noshade" size="2" width="100%">
{{- if gt (len .CVEs) 0 }} {{- if gt (len .CVEs) 0 }}

View File

@ -2,10 +2,12 @@ package cisa
import ( import (
"encoding/json" "encoding/json"
"net/http"
"sync" "sync"
"time" "time"
"istheinternetonfire.app/internal/config" "istheinternetonfire.app/internal/config"
"istheinternetonfire.app/internal/httpclient"
) )
var ( var (
@ -22,16 +24,12 @@ func Read() CisaJSON {
func Start() { func Start() {
for { for {
/* c := httpclient.NewClient(http.DefaultClient)
c := httpclient.NewClient(http.DefaultClient) d, err := c.Get(config.Cfg.RemoteURL)
d, err := c.Get(config.Cfg.RemoteURL) if err != nil {
if err != nil { time.Sleep(time.Second * 120)
time.Sleep(time.Second * 120) continue
continue }
}
*/
d := GetExampleData()
mu.Lock() mu.Lock()
if err := json.Unmarshal(d, &Cisa); err != nil { if err := json.Unmarshal(d, &Cisa); err != nil {

File diff suppressed because it is too large Load Diff

View File

@ -57,6 +57,7 @@ func (c NsUpdateStruct) Update(record, recordType, value string) error {
if err != nil { if err != nil {
config.Cfg.Log.Info("unable to get existing record", "record", record, "error", err) config.Cfg.Log.Info("unable to get existing record", "record", record, "error", err)
} }
config.Cfg.Log.Debug("comparing records", "old value", r, "new value", value)
if r != value { if r != value {
config.Cfg.Log.Debug("deleting record", "record", record) config.Cfg.Log.Debug("deleting record", "record", record)

View File

@ -55,6 +55,7 @@ func tmpltWebRoot(w http.ResponseWriter, r *http.Request) {
var ( var (
msgBuffer bytes.Buffer msgBuffer bytes.Buffer
cves []cisa.VulStruct cves []cisa.VulStruct
num int = 3
) )
c := cisa.Read() c := cisa.Read()
@ -65,10 +66,14 @@ func tmpltWebRoot(w http.ResponseWriter, r *http.Request) {
} }
} }
if len(cves) < 3 {
num = len(cves)
}
if err := tmplt.Execute(&msgBuffer, struct { if err := tmplt.Execute(&msgBuffer, struct {
CVEs []cisa.VulStruct CVEs []cisa.VulStruct
}{ }{
CVEs: cves[len(cves)-3:], CVEs: cves[len(cves)-num:],
}); err != nil { }); err != nil {
config.Cfg.Log.Debug("unable to execute html template", err) config.Cfg.Log.Debug("unable to execute html template", err)
tmpltError(w, http.StatusInternalServerError, "Template Parse Error.") tmpltError(w, http.StatusInternalServerError, "Template Parse Error.")

View File

@ -56,8 +56,8 @@ func main() {
} }
} }
if len(cves) == 0 { if len(cves) == 0 {
if err := dns.Delete("istheinternetonfire.app", "TXT"); err != nil { if err := dns.Update("istheinternetonfire.app", "TXT", "Safe for now!"); err != nil {
config.Cfg.Log.Error("unable to delete dns record", "error", err) config.Cfg.Log.Error("unable to update dns record", "error", err)
time.Sleep(time.Second * time.Duration(config.Cfg.RefreshSeconds)) time.Sleep(time.Second * time.Duration(config.Cfg.RefreshSeconds))
continue continue
} }
@ -70,10 +70,11 @@ func main() {
txtData += fmt.Sprintf("%s - %s - %s\n", v.CveID, v.Product, v.ShortDescription) txtData += fmt.Sprintf("%s - %s - %s\n", v.CveID, v.Product, v.ShortDescription)
} }
if err := dns.Update("istheinternetonfire.app", "TXT", txtData); err != nil { if err := dns.Update("istheinternetonfire.app", "TXT", txtData); err != nil {
config.Cfg.Log.Error("unable to add dns record", "error", err) config.Cfg.Log.Error("unable to update dns record", "error", err)
time.Sleep(time.Second * time.Duration(config.Cfg.RefreshSeconds)) time.Sleep(time.Second * time.Duration(config.Cfg.RefreshSeconds))
continue continue
} }
time.Sleep(time.Second * time.Duration(config.Cfg.RefreshSeconds)) time.Sleep(time.Second * time.Duration(config.Cfg.RefreshSeconds))
} }
}() }()