adds human.txt, site.txt, and 404.html
This commit is contained in:
@@ -107,5 +107,45 @@ func tmpltStatusNotFound(w http.ResponseWriter, path string) {
|
||||
}
|
||||
|
||||
func tmpltTXT(w http.ResponseWriter) {
|
||||
tmplt, err := template.New("site.txt.tplt").Funcs(template.FuncMap{
|
||||
"ToUpper": strings.ToUpper,
|
||||
}).ParseFS(
|
||||
assets.EmbedHTML,
|
||||
"html/site.txt.tplt",
|
||||
)
|
||||
if err != nil {
|
||||
config.Cfg.Log.Debug("unable to parse template", "error", err)
|
||||
tmpltError(w, http.StatusInternalServerError, "Template Parse Error.")
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
msgBuffer bytes.Buffer
|
||||
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) < 3 {
|
||||
num = len(cves)
|
||||
}
|
||||
|
||||
if err := tmplt.Execute(&msgBuffer, struct {
|
||||
CVEs []cisa.VulStruct
|
||||
}{
|
||||
CVEs: cves[len(cves)-num:],
|
||||
}); err != nil {
|
||||
config.Cfg.Log.Debug("unable to execute html template", err)
|
||||
tmpltError(w, http.StatusInternalServerError, "Template Parse Error.")
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(msgBuffer.Bytes()) //nolint:errcheck
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user