adds human.txt, site.txt, and 404.html
This commit is contained in:
@@ -38,6 +38,7 @@ var validFiles map[string]string = map[string]string{
|
||||
"/favicon-16x16.png": TYPE_IMAGE_PNG,
|
||||
"/favicon-32x32.png": TYPE_IMAGE_PNG,
|
||||
"/favicon.ico": TYPE_IMAGE_PNG,
|
||||
"/human.txt": TYPE_TEXT_PLAIN,
|
||||
"/js/bootstrap.bundle.min.js.map": TYPE_APPLICATION_JSON,
|
||||
"/js/bootstrap.bundle.min.js": TYPE_TEXT_JS,
|
||||
"/js/jquery.min.js": TYPE_TEXT_JS,
|
||||
@@ -140,7 +141,7 @@ func webJSON(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
cves := cisa.Read()
|
||||
if len(cves.Vulnerabilities) == 0 {
|
||||
w.Write([]byte("{}"))
|
||||
w.Write([]byte("{}")) //nolint:errcheck
|
||||
return
|
||||
} else if len(cves.Vulnerabilities) < 3 {
|
||||
num = len(cves.Vulnerabilities)
|
||||
@@ -150,7 +151,7 @@ func webJSON(w http.ResponseWriter, r *http.Request) {
|
||||
config.Cfg.Log.Debug("unable to convert CVES to JSON", "error", err, "url", r.URL.Path)
|
||||
}
|
||||
|
||||
w.Write(output)
|
||||
w.Write(output) //nolint:errcheck
|
||||
}
|
||||
|
||||
func webTXT(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -159,4 +160,6 @@ func webTXT(w http.ResponseWriter, r *http.Request) {
|
||||
tmpltError(w, http.StatusBadRequest, "Invalid http method.")
|
||||
return
|
||||
}
|
||||
|
||||
tmpltTXT(w)
|
||||
}
|
||||
|
@@ -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