adds human.txt, site.txt, and 404.html

This commit is contained in:
Hyatt 2024-01-23 19:45:10 -06:00
parent b78cdf6a74
commit a055940bf6
Signed by: nhyatt
GPG Key ID: C50D0BBB5BC40BEA
7 changed files with 113 additions and 7 deletions

View File

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{ .Title }}</title>
<style type="text/css">
body {
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
font-family: 'Poppins', sans-serif;
background-image: linear-gradient(45deg, #f6d200 25%, #181617 25%, #181617 50%, #f6d200 50%, #f6d200 75%, #181617 75%, #181617 100%);
}
h1 {
text-transform: uppercase;
background: repeating-linear-gradient(
45deg,
#f6d200 ,
#f6d200 10px,
#181617 10px,
#181617 20px
);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-size: 384px;
margin: 0;
line-height: .7;
position: relative;
}
</style>
</head>
<body id="home">
<h1 class="text"><span>{{ printf "%d" .ErrorCode }}</span></h1>
</body>
</html>

16
assets/html/human.txt Normal file
View File

@ -0,0 +1,16 @@
/* TEAM */
Owner: Nicolaas Hyatt
Mastodon: https://mastodon.c.smoothnet.org/@nhyatt
/* CREDIT */
Original Concept: Jan Schaumann
Twitter: https://twitter.com/jschauma
Site: https://istheinternetonfire.com
/* SITE */
Last update: 2024-01-23
Language: English
Doctype: HTML5, GoLang
IDE: VSCodium
Source Code: https://gitea.smoothnet.org/nhyatt/istheinternetonfire

10
assets/html/site.txt.tplt Normal file
View File

@ -0,0 +1,10 @@
Site: https://istheinternetonfire.app
{{ if gt (len .CVEs) 0 }}
Is the internet on fire: Yes!
{{ range .CVEs }}
{{ .CveID | ToUpper }} - {{ .Product }}
{{ .ShortDescription }}
{{ end }}
{{ else }}
Is the internet on fire: No
{{ end }}

View File

@ -1,3 +0,0 @@
{{- range .CVEs }}
{{ .CveID | ToUpper }} - {{ .Product }} - {{ .ShortDescription }}
{{- end }}

View File

@ -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)
}

View File

@ -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
}

View File

@ -58,7 +58,7 @@ func main() {
if len(cves) == 0 {
if err := dns.UpdateTXT("istheinternetonfire.app", "TXT", "Safe for now!"); err != nil {
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(5*60))
continue
}
} else if len(cves) < 3 {
@ -71,7 +71,7 @@ func main() {
}
if err := dns.UpdateTXT("istheinternetonfire.app", "TXT", txtData); err != nil {
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(5*60))
continue
}