Source of file ClamAVEmulator.php
Size: 3,011 Bytes - Last Modified: 2021-12-23T10:21:01+00:00
/var/www/docs.ssmods.com/process/src/src/ClamAVEmulator.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 | <?php namespace Symbiote\SteamedClams; use LogicException; use SilverStripe\Core\Config\Config; /** * For emulating/faking ClamAV results * * This was implemented so Windows users and inexperienced developers can * focus on the logic surrounding the ClamAV daemon, without needing to * know how install it. */ class ClamAVEmulator extends ClamAV { const MODE_UNKNOWN = 0; const MODE_NO_VIRUS = 1; const MODE_HAS_VIRUS = 2; const MODE_OFFLINE = 3; /** * The state of ClamAV to fake * * @var int */ private static $mode = self::MODE_UNKNOWN; /** * The version string to return when emulating. * * @var string */ private static $emulate_version = 'ClamAV 0.99.2/22585/Wed Nov 23 00:21:08 2016'; /** * {@inheritDoc} */ public function version() { $mode = Config::inst()->get(__CLASS__, 'mode'); $emulateVersion = Config::inst()->get(__CLASS__, 'emulate_version'); switch ($mode) { case self::MODE_UNKNOWN: return $this->modeUnknown(); break; case self::MODE_NO_VIRUS: case self::MODE_HAS_VIRUS: return $emulateVersion; break; case self::MODE_OFFLINE: return $this->modeOffline(); break; default: return $this->modeInvalid(); break; } } /** * {@inheritDoc} */ protected function fileScan($filepath) { $mode = Config::inst()->get(__CLASS__, 'mode'); switch ($mode) { case self::MODE_UNKNOWN: return $this->modeUnknown(); break; case self::MODE_NO_VIRUS: return array( 'file' => $filepath, 'stats' => 'OK', ); break; case self::MODE_HAS_VIRUS: return array( 'file' => $filepath, 'stats' => 'Eicar-Test-Signature FOUND', ); break; case self::MODE_OFFLINE: return $this->modeOffline(); break; default: return $this->modeInvalid(); break; } } protected function modeUnknown() { throw new LogicException('Must configure ' . __CLASS__ . '::mode config'); } protected function modeOffline() { $this->last_exception = new \ClamdSocketException( '*EMULATE MODE* No such file or directory "/not-real-root-folder/run/clamav/clamd.ctl"', 2 ); return self::OFFLINE; } protected function modeInvalid() { throw new LogicException( 'Invalid "mode" config with value "' . Config::inst()->get(__CLASS__, 'mode') . '". Use constants provided in ' . __CLASS__ . ' class.' ); } } |