From 9f31bf557dd8e91fe78bee5730e8ce2d65099fc5 Mon Sep 17 00:00:00 2001 From: ChaoticByte Date: Mon, 22 Jul 2024 19:55:44 +0200 Subject: [PATCH] Added the software version to the mail default template and cli help text, updated README and build script --- README.md | 4 +++- build.sh | 21 ++++++++++----------- mail.go | 2 +- main.go | 5 ++++- template.go | 17 +++++++++++++---- version.go | 3 +++ 6 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 version.go diff --git a/README.md b/README.md index 7b81e52..1c6ddbd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# WID Notifier +# WidNotifier The German [BSI](https://www.bsi.bund.de/) and [LSI Bavaria](https://lsi.bayern.de/) each have a page listing current security notices. This software queries the APIs of these services for new security notices and sends configurable email notifications. @@ -202,4 +202,6 @@ type WidNotice struct { } ``` +Additionally, the field `WidNotifierVersion` holds the version of the software. + For an example, take a look at `DEFAULT_SUBJECT_TEMPLATE` and `DEFAULT_BODY_TEMPLATE` in [template.go](./template.go). diff --git a/build.sh b/build.sh index 7ac90ca..8418388 100755 --- a/build.sh +++ b/build.sh @@ -2,14 +2,13 @@ VERSION=$(git describe --tags) -# i386 -GOOS=linux GOARCH=386 go build -o dist/wid-notifier_${VERSION}_linux_i386 - -# amd64 -GOOS=linux GOARCH=amd64 go build -o dist/wid-notifier_${VERSION}_linux_amd64 - -# arm -GOOS=linux GOARCH=arm go build -o dist/wid-notifier_${VERSION}_linux_arm - -# arm64 -GOOS=linux GOARCH=arm64 go build -o dist/wid-notifier_${VERSION}_linux_arm64 +function build() { + printf "Compiling version ${VERSION} for ${1}/${2}\t" + GOOS=${1} GOARCH=${2} go build -ldflags "-X 'main.Version=${VERSION}'" -o dist/wid-notifier_${VERSION}_${1}_${3} + echo "✅" +} + +build linux "386" i386 +build linux amd64 amd64 +build linux arm arm +build linux arm64 arm64 diff --git a/mail.go b/mail.go index df9763c..e4c5890 100644 --- a/mail.go +++ b/mail.go @@ -61,7 +61,7 @@ func (r Recipient) sendNotices(notices []WidNotice, template MailTemplate, auth data = cacheResult } else { cacheMisses++ - mailContent, err := template.generate(n) + mailContent, err := template.generate(TemplateData{n, Version}) if err != nil { logger.error("Could not create mail from template") logger.error(err) diff --git a/main.go b/main.go index cd9c725..47ce30b 100644 --- a/main.go +++ b/main.go @@ -16,7 +16,10 @@ func main() { // get cli arguments args := os.Args if len(args) < 2 { - fmt.Printf("Usage: %v \nIf the config file doesn't exist, a incomplete configuration with default values is created.\n", args[0]) + fmt.Printf( "Usage: %v \n\nIf the config file doesn't exist, an incomplete \n" + + "configuration with default values is created.\n\nVersion: %s\n", + args[0], + Version) os.Exit(1) } configFilePath := os.Args[1] diff --git a/template.go b/template.go index 7869e1a..7d078e8 100644 --- a/template.go +++ b/template.go @@ -26,7 +26,16 @@ Affected Products:{{ range $product := .ProductNames }} Assigned CVEs:{{ range $cve := .Cves }} - {{ $cve }} -> https://www.cve.org/CVERecord?id={{ $cve }} -{{- end }}{{ end }}` +{{- end }}{{ end }} + + +Sent by WidNotifier {{ .WidNotifierVersion }} +` + +type TemplateData struct { + WidNotice + WidNotifierVersion string +} type MailTemplateConfig struct { SubjectTemplate string `json:"subject"` @@ -38,14 +47,14 @@ type MailTemplate struct { BodyTemplate template.Template } -func (t MailTemplate) generate(notice WidNotice) (MailContent, error) { +func (t MailTemplate) generate(data TemplateData) (MailContent, error) { c := MailContent{} buffer := &bytes.Buffer{} - err := t.SubjectTemplate.Execute(buffer, notice) + err := t.SubjectTemplate.Execute(buffer, data) if err != nil { return c, err } c.Subject = buffer.String() buffer.Truncate(0) // we can recycle our buffer - err = t.BodyTemplate.Execute(buffer, notice) + err = t.BodyTemplate.Execute(buffer, data) if err != nil { return c, err } c.Body = buffer.String() return c, nil diff --git a/version.go b/version.go new file mode 100644 index 0000000..f0ce3c0 --- /dev/null +++ b/version.go @@ -0,0 +1,3 @@ +package main + +var Version = "devel"