From 2b0c849332a23f163672472a5eec1e95a43141d9 Mon Sep 17 00:00:00 2001 From: Phillipp Engelke Date: Mon, 4 Jan 2021 15:53:22 +0100 Subject: [PATCH 1/3] remove vue dependacy --- api.go | 26 ++++++++++++ go.mod | 1 - resources/noscript.gohtml | 83 +++++++++++++++++++++++++++++++++++++++ web/index.html | 1 + 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 resources/noscript.gohtml diff --git a/api.go b/api.go index 4deebee..4c569ce 100644 --- a/api.go +++ b/api.go @@ -4,6 +4,7 @@ package chihuahua import ( "github.com/rs/zerolog/log" + "html/template" "io/ioutil" "net/http" "net/url" @@ -146,8 +147,33 @@ func Api(cfg *Config) { c.String(200, strings.ReplaceAll(string(setupScript), "[CHIHUAHUA_PUBLIC_KEYS]", keyList)) } + noScriptFile, err := pkger.Open("codeberg.org/momar/chihuahua:/resources/noscript.gohtml") + if err != nil { + log.Error().Str("caller", "api").Err(err).Msg("couldn't open noscript.gohtml from web resources") + os.Exit(1) + } + noScript, err := ioutil.ReadAll(noScriptFile) + if err != nil { + log.Error().Str("caller", "api").Err(err).Msg("couldn't read noscript.gohtml from web resources") + os.Exit(1) + } + noScriptTemplate, err := template.New("noscript").Funcs(template.FuncMap{ + "formatTime": func(t time.Time) string {return t.Format("2006-01-02 15:05:05")}, + }).Parse(string(noScript)) + if err != nil { + log.Error().Str("caller", "api").Err(err).Msg("couldn't parse noscript.gohtml from web resources") + os.Exit(1) + } + app := gin.New() app.Use(gin.Recovery()) + app.SetHTMLTemplate(noScriptTemplate) + app.GET("/noscript", func(c *gin.Context) { + c.HTML(200, "noscript", gin.H{ + "Time": time.Now().Format("02.01.2006 15:04:05"), + "Servers": cfg.Servers, + }) + }) app.GET("/setup.sh", getSetupScript) app.GET("/checks", GetCheck(cfg)) app.GET("/checks/*id", GetCheck(cfg)) diff --git a/go.mod b/go.mod index 39cc6a2..8667c60 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,5 @@ require ( github.com/teris-io/cli v1.0.1 golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6 // indirect golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect - golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 // indirect gopkg.in/yaml.v2 v2.2.8 // indirect ) diff --git a/resources/noscript.gohtml b/resources/noscript.gohtml new file mode 100644 index 0000000..c8ae237 --- /dev/null +++ b/resources/noscript.gohtml @@ -0,0 +1,83 @@ + + + + Server Status + + + + + + + + + + +
+ {{ range .Servers}} +
+
+

{{ .Name }}

+
+ {{ range .Checks }} +
+

+ + {{ .Name }} +

+
+
+                                    
+                                        {{ if .Result.Details }}
+                                            {{ .Result.Details }}
+                                        {{ end }}
+                                        {{ if .Result.Error }}
+                                            {{ .Result.Error }}
+                                        {{ end }}
+                                        {{ formatTime .Result.LastUpdate }}
+                                    
+                                
+
+
+ {{ end }} +
+
+ {{ end }} +
+ +
+ + + \ No newline at end of file diff --git a/web/index.html b/web/index.html index d130a89..cd0c633 100644 --- a/web/index.html +++ b/web/index.html @@ -17,6 +17,7 @@ +

-- 2.30.2 From 9cabebb19b29113223c6b9fbef4b037c6fc8efae Mon Sep 17 00:00:00 2001 From: Phillipp Engelke Date: Mon, 4 Jan 2021 16:16:01 +0100 Subject: [PATCH 2/3] fix layout without macy (old layout before macy was used) --- resources/noscript.gohtml | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/resources/noscript.gohtml b/resources/noscript.gohtml index c8ae237..78e6fa1 100644 --- a/resources/noscript.gohtml +++ b/resources/noscript.gohtml @@ -22,9 +22,9 @@

{{ .Name }}

-
+
{{ range .Checks }} -
+

-
-                                    
-                                        {{ if .Result.Details }}
-                                            {{ .Result.Details }}
-                                        {{ end }}
-                                        {{ if .Result.Error }}
-                                            {{ .Result.Error }}
-                                        {{ end }}
-                                        {{ formatTime .Result.LastUpdate }}
-                                    
-                                
+
{{ if .Result.Details }}{{ .Result.Details }}{{ end }}{{ if .Result.Error }}{{ .Result.Error }}{{ end }}
{{ formatTime .Result.LastUpdate }}
{{ end }} -- 2.30.2 From 37902cbc814e148677c3f7a3a8032f7ae62573cb Mon Sep 17 00:00:00 2001 From: Phillipp Engelke Date: Mon, 4 Jan 2021 16:42:24 +0100 Subject: [PATCH 3/3] Add Noscript Notice --- resources/noscript.gohtml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/resources/noscript.gohtml b/resources/noscript.gohtml index 78e6fa1..fee849b 100644 --- a/resources/noscript.gohtml +++ b/resources/noscript.gohtml @@ -17,7 +17,10 @@ -
+
+ IMPORTANT NOTICE: This is the noscript version of Chihuahua! Retrieved on {{ .Time -}}. +
+
{{ range .Servers}}

-- 2.30.2