Added the software version to the mail default template and cli help text, updated README and build script

This commit is contained in:
ChaoticByte 2024-07-22 19:55:44 +02:00
parent e9f39d25b4
commit 9f31bf557d
No known key found for this signature in database
6 changed files with 33 additions and 17 deletions

View file

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

View file

@ -2,14 +2,13 @@
VERSION=$(git describe --tags)
# i386
GOOS=linux GOARCH=386 go build -o dist/wid-notifier_${VERSION}_linux_i386
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 "✅"
}
# 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
build linux "386" i386
build linux amd64 amd64
build linux arm arm
build linux arm64 arm64

View file

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

View file

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

View file

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

3
version.go Normal file
View file

@ -0,0 +1,3 @@
package main
var Version = "devel"