Skip to content

Commit

Permalink
Added the software version to the mail default template and cli help …
Browse files Browse the repository at this point in the history
…text, updated README and build script
  • Loading branch information
ChaoticByte committed Jul 22, 2024
1 parent e9f39d2 commit 9f31bf5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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).
21 changes: 10 additions & 11 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ func main() {
// get cli arguments
args := os.Args
if len(args) < 2 {
fmt.Printf("Usage: %v <configfile>\nIf the config file doesn't exist, a incomplete configuration with default values is created.\n", args[0])
fmt.Printf( "Usage: %v <configfile>\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]
Expand Down
17 changes: 13 additions & 4 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package main

var Version = "devel"

0 comments on commit 9f31bf5

Please sign in to comment.