Added the software version to the mail default template and cli help text, updated README and build script
This commit is contained in:
parent
e9f39d25b4
commit
9f31bf557d
6 changed files with 33 additions and 17 deletions
|
@ -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.
|
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.
|
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).
|
For an example, take a look at `DEFAULT_SUBJECT_TEMPLATE` and `DEFAULT_BODY_TEMPLATE` in [template.go](./template.go).
|
||||||
|
|
19
build.sh
19
build.sh
|
@ -2,14 +2,13 @@
|
||||||
|
|
||||||
VERSION=$(git describe --tags)
|
VERSION=$(git describe --tags)
|
||||||
|
|
||||||
# i386
|
function build() {
|
||||||
GOOS=linux GOARCH=386 go build -o dist/wid-notifier_${VERSION}_linux_i386
|
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
|
build linux "386" i386
|
||||||
GOOS=linux GOARCH=amd64 go build -o dist/wid-notifier_${VERSION}_linux_amd64
|
build linux amd64 amd64
|
||||||
|
build linux arm arm
|
||||||
# arm
|
build linux arm64 arm64
|
||||||
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
|
|
||||||
|
|
2
mail.go
2
mail.go
|
@ -61,7 +61,7 @@ func (r Recipient) sendNotices(notices []WidNotice, template MailTemplate, auth
|
||||||
data = cacheResult
|
data = cacheResult
|
||||||
} else {
|
} else {
|
||||||
cacheMisses++
|
cacheMisses++
|
||||||
mailContent, err := template.generate(n)
|
mailContent, err := template.generate(TemplateData{n, Version})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.error("Could not create mail from template")
|
logger.error("Could not create mail from template")
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
|
|
5
main.go
5
main.go
|
@ -16,7 +16,10 @@ func main() {
|
||||||
// get cli arguments
|
// get cli arguments
|
||||||
args := os.Args
|
args := os.Args
|
||||||
if len(args) < 2 {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
configFilePath := os.Args[1]
|
configFilePath := os.Args[1]
|
||||||
|
|
17
template.go
17
template.go
|
@ -26,7 +26,16 @@ Affected Products:{{ range $product := .ProductNames }}
|
||||||
|
|
||||||
Assigned CVEs:{{ range $cve := .Cves }}
|
Assigned CVEs:{{ range $cve := .Cves }}
|
||||||
- {{ $cve }} -> https://www.cve.org/CVERecord?id={{ $cve }}
|
- {{ $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 {
|
type MailTemplateConfig struct {
|
||||||
SubjectTemplate string `json:"subject"`
|
SubjectTemplate string `json:"subject"`
|
||||||
|
@ -38,14 +47,14 @@ type MailTemplate struct {
|
||||||
BodyTemplate template.Template
|
BodyTemplate template.Template
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t MailTemplate) generate(notice WidNotice) (MailContent, error) {
|
func (t MailTemplate) generate(data TemplateData) (MailContent, error) {
|
||||||
c := MailContent{}
|
c := MailContent{}
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
err := t.SubjectTemplate.Execute(buffer, notice)
|
err := t.SubjectTemplate.Execute(buffer, data)
|
||||||
if err != nil { return c, err }
|
if err != nil { return c, err }
|
||||||
c.Subject = buffer.String()
|
c.Subject = buffer.String()
|
||||||
buffer.Truncate(0) // we can recycle our buffer
|
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 }
|
if err != nil { return c, err }
|
||||||
c.Body = buffer.String()
|
c.Body = buffer.String()
|
||||||
return c, nil
|
return c, nil
|
||||||
|
|
3
version.go
Normal file
3
version.go
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
var Version = "devel"
|
Loading…
Add table
Add a link
Reference in a new issue