notification for virusscan

Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
jkoberg
2023-03-17 12:45:10 +01:00
parent fc4ba499b1
commit 642d8f0028
4 changed files with 54 additions and 2 deletions

View File

@@ -25,6 +25,9 @@ import (
// all events we care about
var _registeredEvents = []events.Unmarshaller{
// file related
events.PostprocessingStepFinished{},
// space related
events.SpaceDisabled{},
events.SpaceDeleted{},

View File

@@ -25,8 +25,9 @@ import (
var _translationFS embed.FS
var (
_resourceTypeSpace = "storagespace"
_resourceTypeShare = "share"
_resourceTypeResource = "resource"
_resourceTypeSpace = "storagespace"
_resourceTypeShare = "share"
_domain = "userlog"
)
@@ -96,6 +97,13 @@ func (c *Converter) ConvertEvent(event *ehmsg.Event) (OC10Notification, error) {
switch ev := einterface.(type) {
default:
return OC10Notification{}, errors.New("unknown event type")
// file related
case events.PostprocessingStepFinished:
if ev.FinishedStep != events.PPStepAntivirus {
return OC10Notification{}, errors.New("unknown event type")
}
res := ev.Result.(events.VirusscanResult)
return c.virusMessage(event.Id, VirusFound, ev.ExecutingUser, res.ResourceID, ev.Filename, res.Description, res.Scandate)
// space related
case events.SpaceDisabled:
return c.spaceMessage(event.Id, SpaceDisabled, ev.Executant, ev.ID.GetOpaqueId(), ev.Timestamp)
@@ -227,6 +235,30 @@ func (c *Converter) shareMessage(eventid string, nt NotificationTemplate, execut
}, nil
}
func (c *Converter) virusMessage(eventid string, nt NotificationTemplate, executant *user.User, rid *storageprovider.ResourceId, filename string, virus string, ts time.Time) (OC10Notification, error) {
subj, subjraw, msg, msgraw, err := composeMessage(nt, c.locale, c.translationPath, map[string]interface{}{
"resourcename": filename,
"virusdescription": virus,
})
if err != nil {
return OC10Notification{}, err
}
return OC10Notification{
EventID: eventid,
Service: c.serviceName,
UserName: executant.GetUsername(),
Timestamp: ts.Format(time.RFC3339Nano),
ResourceID: storagespace.FormatResourceID(*rid),
ResourceType: _resourceTypeResource,
Subject: subj,
SubjectRaw: subjraw,
Message: msg,
MessageRaw: msgraw,
MessageDetails: generateDetails(nil, nil, nil, nil),
}, nil
}
func (c *Converter) authenticate(usr *user.User) (context.Context, error) {
if ctx, ok := c.contexts[usr.GetId().GetOpaqueId()]; ok {
return ctx, nil

View File

@@ -90,6 +90,18 @@ func (ul *UserlogService) MemorizeEvents(ch <-chan events.Event) {
switch e := event.Event.(type) {
default:
err = errors.New("unhandled event")
// file related
case events.PostprocessingStepFinished:
if e.FinishedStep != events.PPStepAntivirus {
continue
}
result := e.Result.(events.VirusscanResult)
if !result.Infected {
continue
}
// TODO: should space mangers also be informed?
users = append(users, e.ExecutingUser.GetId().GetOpaqueId())
// space related // TODO: how to find spaceadmins?
case events.SpaceDisabled:
users, err = ul.findSpaceMembers(ul.impersonate(e.Executant), e.ID.GetOpaqueId(), viewer)

View File

@@ -5,6 +5,10 @@ func Template(s string) string { return s }
// the available templates
var (
VirusFound = NotificationTemplate{
Subject: Template("Virus found"),
Message: Template("Virus found in {resource}. Upload not possible. Virus: {virus}"),
}
SpaceShared = NotificationTemplate{
Subject: Template("Space shared"),
Message: Template("{user} added you to Space {space}"),
@@ -51,6 +55,7 @@ var _placeholders = map[string]string{
"{user}": "{{ .username }}",
"{space}": "{{ .spacename }}",
"{resource}": "{{ .resourcename }}",
"{virus}": "{{ .virusdescription }}",
}
// NotificationTemplate is the data structure for the notifications