mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-05 11:51:16 -06:00
add debug switch for antivirus
Signed-off-by: Christian Richter <crichter@owncloud.com>
This commit is contained in:
@@ -19,6 +19,8 @@ type Config struct {
|
||||
MaxScanSize string `yaml:"max-scan-size" env:"ANTIVIRUS_MAX_SCAN_SIZE" desc:"The maximum scan size the virusscanner can handle. Only this many bytes of a file will be scanned. 0 means unlimited and is the default. Usable common abbreviations: [KB, KiB, GB, GiB, TB, TiB, PB, PiB, EB, EiB], example: 2GB."`
|
||||
|
||||
Context context.Context `yaml:"-" json:"-"`
|
||||
|
||||
DebugScanOutcome string `yaml:"-" env:"ANTIVIRUS_DEBUG_SCAN_OUTCOME" desc:"A predefined outcome for virus scanning, FOR DEBUG PURPOSES ONLY! (example values: \"found,infected\")"`
|
||||
}
|
||||
|
||||
// Service defines the available service configuration.
|
||||
|
||||
@@ -21,14 +21,14 @@ type Scanner interface {
|
||||
}
|
||||
|
||||
// New returns a new scanner from config
|
||||
func New(c config.Scanner) (Scanner, error) {
|
||||
switch c.Type {
|
||||
func New(c *config.Config) (Scanner, error) {
|
||||
switch c.Scanner.Type {
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown av scanner: '%s'", c.Type)
|
||||
return nil, fmt.Errorf("unknown av scanner: '%s'", c.Scanner.Type)
|
||||
case "clamav":
|
||||
return NewClamAV(c.ClamAV.Socket), nil
|
||||
return NewClamAV(c.Scanner.ClamAV.Socket), nil
|
||||
case "icap":
|
||||
return NewICAP(c.ICAP.URL, c.ICAP.Service, time.Duration(c.ICAP.Timeout)*time.Second)
|
||||
return NewICAP(c.Scanner.ICAP.URL, c.Scanner.ICAP.Service, time.Duration(c.Scanner.ICAP.Timeout)*time.Second)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func NewAntivirus(c *config.Config, l log.Logger) (Antivirus, error) {
|
||||
av := Antivirus{c: c, l: l, client: rhttp.GetHTTPClient(rhttp.Insecure(true))}
|
||||
|
||||
var err error
|
||||
av.s, err = scanners.New(c.Scanner)
|
||||
av.s, err = scanners.New(c)
|
||||
if err != nil {
|
||||
return av, err
|
||||
}
|
||||
@@ -102,6 +102,27 @@ func (av Antivirus) Run() error {
|
||||
continue
|
||||
}
|
||||
|
||||
if av.c.DebugScanOutcome != "" {
|
||||
av.l.Warn().Str("antivir, clamav", ">>>>>>> ANTIVIRUS_DEBUG_SCAN_OUTCOME IS SET NO ACTUAL VIRUS SCAN IS PERFORMED!")
|
||||
if err := events.Publish(stream, events.PostprocessingStepFinished{
|
||||
FinishedStep: events.PPStepAntivirus,
|
||||
Outcome: events.PostprocessingOutcome(av.c.DebugScanOutcome),
|
||||
UploadID: ev.UploadID,
|
||||
ExecutingUser: ev.ExecutingUser,
|
||||
Filename: ev.Filename,
|
||||
Result: events.VirusscanResult{
|
||||
Infected: true,
|
||||
Description: "DEBUG: forced outcome",
|
||||
Scandate: time.Now(),
|
||||
ResourceID: ev.ResourceID,
|
||||
ErrorMsg: "DEBUG: forced outcome",
|
||||
},
|
||||
}); err != nil {
|
||||
av.l.Fatal().Err(err).Str("uploadid", ev.UploadID).Interface("resourceID", ev.ResourceID).Msg("cannot publish events - exiting")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
av.l.Debug().Str("uploadid", ev.UploadID).Str("filename", ev.Filename).Msg("Starting virus scan.")
|
||||
var errmsg string
|
||||
res, err := av.process(ev)
|
||||
|
||||
Reference in New Issue
Block a user