ClamAV Scanner for Flysystem is a package by Michael Griego that scans files for malware using the ClamAV antivirus engine. The readme explains in more detail how this adapter works in tandem with a “backing” adapter:
This package provides a filesystem adapter for Flysystem that scans files being read from and written to an underlying filesystem using the popular ClamAV antivirus engine. This adapter acts as a passthrough adapter, sitting in between your application and whichever concrete Flysystem adapter you use to store your files. Since this scanner is itself a Flysystem adapter, it can be implemented in an existing application simply by dropping it in as a replacement to your existing Flysystem adapter so that all filesytem calls go through the ClamAV adapter.
Here’s a gist of the setup, which requires a few things: the backing adapter (i.e., local), the Quahog ClamAV integration library, and the
ClamAvScannerAdapter from this package:
1use League\Flysystem\Adapter\Local;2use Socket\Raw\Factory as SocketFactory;3use Xenolope\Quahog\Client as ClamAVScanner;4use League\Flysystem\Filesystem;5use mgriego\Flysystem\ClamAV\ClamAvScannerAdapter;678$backingAdapter = new Local(__DIR__.'/path/to/root');91011// Create a new socket instance12$socket = (new SocketFactory())->createClient('tcp://127.0.0.1:3310');131415// Create a new instance of the Client16$quahog = new ClamAVScanner($socket);171819// In this case, copies will be scanned.20$adapter = new ClamAvScannerAdapter($quahog, $backingAdapter, true);21$filesystem = new Filesystem($adapter)
During usage, files are scanned during the following operations:
copyif the adapter is configured as such
If ClamAV detects malware in the file during any of those operations, the ClamAvScannerAdapter will throw a VirusFoundException exception. The
getReason() method will give you the name of the malware detected and
getPath() will provide the path of the file in question.
I would recommend going through the readme, which details the background of how to use this adapter as well as properly using the
clamd daemon. To learn more about this package, get full installation instructions, and view the source code on GitHub at mgriego/flysystem-clamav.