notification for virusscan
Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
@@ -25,6 +25,9 @@ import (
|
|||||||
|
|
||||||
// all events we care about
|
// all events we care about
|
||||||
var _registeredEvents = []events.Unmarshaller{
|
var _registeredEvents = []events.Unmarshaller{
|
||||||
|
// file related
|
||||||
|
events.PostprocessingStepFinished{},
|
||||||
|
|
||||||
// space related
|
// space related
|
||||||
events.SpaceDisabled{},
|
events.SpaceDisabled{},
|
||||||
events.SpaceDeleted{},
|
events.SpaceDeleted{},
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ import (
|
|||||||
var _translationFS embed.FS
|
var _translationFS embed.FS
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_resourceTypeSpace = "storagespace"
|
_resourceTypeResource = "resource"
|
||||||
_resourceTypeShare = "share"
|
_resourceTypeSpace = "storagespace"
|
||||||
|
_resourceTypeShare = "share"
|
||||||
|
|
||||||
_domain = "userlog"
|
_domain = "userlog"
|
||||||
)
|
)
|
||||||
@@ -96,6 +97,13 @@ func (c *Converter) ConvertEvent(event *ehmsg.Event) (OC10Notification, error) {
|
|||||||
switch ev := einterface.(type) {
|
switch ev := einterface.(type) {
|
||||||
default:
|
default:
|
||||||
return OC10Notification{}, errors.New("unknown event type")
|
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
|
// space related
|
||||||
case events.SpaceDisabled:
|
case events.SpaceDisabled:
|
||||||
return c.spaceMessage(event.Id, SpaceDisabled, ev.Executant, ev.ID.GetOpaqueId(), ev.Timestamp)
|
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
|
}, 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) {
|
func (c *Converter) authenticate(usr *user.User) (context.Context, error) {
|
||||||
if ctx, ok := c.contexts[usr.GetId().GetOpaqueId()]; ok {
|
if ctx, ok := c.contexts[usr.GetId().GetOpaqueId()]; ok {
|
||||||
return ctx, nil
|
return ctx, nil
|
||||||
|
|||||||
@@ -90,6 +90,18 @@ func (ul *UserlogService) MemorizeEvents(ch <-chan events.Event) {
|
|||||||
switch e := event.Event.(type) {
|
switch e := event.Event.(type) {
|
||||||
default:
|
default:
|
||||||
err = errors.New("unhandled event")
|
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?
|
// space related // TODO: how to find spaceadmins?
|
||||||
case events.SpaceDisabled:
|
case events.SpaceDisabled:
|
||||||
users, err = ul.findSpaceMembers(ul.impersonate(e.Executant), e.ID.GetOpaqueId(), viewer)
|
users, err = ul.findSpaceMembers(ul.impersonate(e.Executant), e.ID.GetOpaqueId(), viewer)
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ func Template(s string) string { return s }
|
|||||||
|
|
||||||
// the available templates
|
// the available templates
|
||||||
var (
|
var (
|
||||||
|
VirusFound = NotificationTemplate{
|
||||||
|
Subject: Template("Virus found"),
|
||||||
|
Message: Template("Virus found in {resource}. Upload not possible. Virus: {virus}"),
|
||||||
|
}
|
||||||
SpaceShared = NotificationTemplate{
|
SpaceShared = NotificationTemplate{
|
||||||
Subject: Template("Space shared"),
|
Subject: Template("Space shared"),
|
||||||
Message: Template("{user} added you to Space {space}"),
|
Message: Template("{user} added you to Space {space}"),
|
||||||
@@ -51,6 +55,7 @@ var _placeholders = map[string]string{
|
|||||||
"{user}": "{{ .username }}",
|
"{user}": "{{ .username }}",
|
||||||
"{space}": "{{ .spacename }}",
|
"{space}": "{{ .spacename }}",
|
||||||
"{resource}": "{{ .resourcename }}",
|
"{resource}": "{{ .resourcename }}",
|
||||||
|
"{virus}": "{{ .virusdescription }}",
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotificationTemplate is the data structure for the notifications
|
// NotificationTemplate is the data structure for the notifications
|
||||||
|
|||||||
Reference in New Issue
Block a user