The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClamScanner.cs 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using nClam;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Teknik.Configuration;
  9. namespace Teknik.ContentScanningService
  10. {
  11. public class ClamScanner : ContentScanner
  12. {
  13. public ClamScanner(Config config) : base(config)
  14. { }
  15. public async override Task<ScanResult> ScanFile(Stream stream)
  16. {
  17. var result = new ScanResult();
  18. if (stream != null)
  19. {
  20. // Set the start of the stream
  21. stream.Seek(0, SeekOrigin.Begin);
  22. ClamClient clam = new ClamClient(_config.UploadConfig.ClamConfig.Server, _config.UploadConfig.ClamConfig.Port);
  23. clam.MaxStreamSize = stream.Length;
  24. ClamScanResult scanResult = await clam.SendAndScanFileAsync(stream);
  25. result.RawResult = scanResult.RawResult;
  26. switch (scanResult.Result)
  27. {
  28. case ClamScanResults.Clean:
  29. result.ResultType = ScanResultType.Clean;
  30. break;
  31. case ClamScanResults.VirusDetected:
  32. result.ResultType = ScanResultType.VirusDetected;
  33. result.RawResult = scanResult.InfectedFiles.First().VirusName;
  34. break;
  35. case ClamScanResults.Error:
  36. result.ResultType = ScanResultType.Error;
  37. break;
  38. case ClamScanResults.Unknown:
  39. result.ResultType = ScanResultType.Unknown;
  40. break;
  41. }
  42. }
  43. return result;
  44. }
  45. }
  46. }