Giter VIP home page Giter VIP logo

quahog's Introduction

Quahog

Build Status

Quahog is a simple PHP library to interface with the clamd anti-virus daemon. It was written as all of the libraries out there for interfacing with ClamAV from PHP use exec('clamscan'), which isn't exactly an ideal solution, as clamscan loads the entire database into memory each time it is run - this doesn't, so it scans a lot (lot!) faster.

Installation

It is recommended to install Quahog through composer.

{
    "require": {
        "xenolope/quahog": "3.*"
    }
}

Usage

// Create a new socket instance
$socket = (new \Socket\Raw\Factory())->createClient('unix:///var/run/clamav/clamd.ctl'); # Using a UNIX socket
$socket = (new \Socket\Raw\Factory())->createClient('tcp://192.168.1.1:3310'); # Using a TCP socket

// Create a new instance of the Client
$quahog = new \Xenolope\Quahog\Client($socket);

// Scan a file
$result = $quahog->scanFile('/tmp/virusfile');

// Scan a file or directory recursively
$result = $quahog->contScan('/tmp/virusdirectory');

// Scan a file or directory recursively using multiple threads
$result = $quahog->multiscanFile('/tmp/virusdirectory');

// Scan a stream, and optionally pass the maximum chunk size in bytes
$result = $quahog->scanStream(file_get_contents('/tmp/virusfile'), 1024);

// Scan multiple files in a row
$quahog->startSession();
$result = $quahog->scanFile('/tmp/virusfile');
$result2 = $quahog->scanFile('/tmp/virusfile2');
$quahog->endSession();

// Ping clamd
$result = $quahog->ping();

// Get ClamAV version details
$result = $quahog->version();

// View statistics about the ClamAV scan queue
$result = $quahog->stats();

// Reload the virus database
$quahog->reload();

// Shutdown clamd cleanly
$quahog->shutdown();

Working with the result

// Result is an instance of \Xenolope\Quahog\Result.
$result = $quahog->scanFile('/tmp/virusfile');

// A result id of a session that was used.
$result->getId();

// The file name of the scanned file.
$result->getFilename();

// The reason why a scan resulted in a failure. Returns null if the scan was successful.
$result->getReason();

// A boolean value that is true, in case the scan was successful.
$result->isOk();

// A boolean value that is true, in case the scan failed. This is the opposite of isOk().
$result->hasFailed();

// A boolean value that is true, if a virus was found.
$result->isFound();

// A boolean value that is true, if an error happened.
$result->isError();

Testing

To run the test suite you will need PHPUnit installed. Go to the project root and run:

$ phpunit

License

Quahog is released under the MIT License

quahog's People

Contributors

bkuhl avatar davidvanlaatum avatar derikb avatar gimler avatar jchamberlain avatar jonjo-blur avatar jonjomckay avatar lbialy avatar massivehiggsfield avatar senseexception avatar sharkmachine avatar theonlymerlin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quahog's Issues

Explain start/stop Session methods in README

It seems you need to use startSession() and endSession() if you want to send multiple commands through the socket (unless it's some kind of config issue on my end?). Would be nice to have that be in the documentation. I can do a pull request if you like.

php 7.1

is it support php 7.1 clamav-php module ?

or what is maximum version support ? i did try from sourceforce php-clamav module but

not suport php 7.0 or 7.1 there is supoprt php5.4 and php 5.5 only

so is there way install php 7.0 clamav ?

Deprecation Error by default

I might be missing something horrendously obvious, but when I instantiate the client as laid out in the README, I get a deprecation notice, which in my environment is automatically an error.

Looking at the code, the mode parameter defaults to PHP_BINARY_READ and this mode immediately triggers the deprecation notice.

Would it be possible to release a version 4.x.x (to indicate a breaking change) that defaults to PHP_NORMAL_READ.

If not, perhaps it would be worth highlighting in the README? Happy to do a PR for either option ...

Multiple uploaded files

Hello

When I'm trying to check multiple uploaded files, the first one is scanned correctly but the second one give me an error :

PHP Warning: socket_last_error(): supplied resource is not a valid Socket resource in /***/vendor/clue/socket-raw/src/Exception.php on line 21

I also tried to check 2 times the same file and the second time I check it same error.

Looks like I can use clamav only on one file at time... why?

I'm using scanFile method

I can't use multiScanfile method as I don't want to scan a whole dir....

any idea?

Update of dependencies

This library pretty outdated and needs an update of the following dependencies:

  • PHP 5.6 and 7, also 5.6 as the minimal supported version
  • Using newest Client library (#14)

Also some changes of standards would be nice:

  • PSR-4 in Composer
  • PHPUnit as dev requirement (Easier to test for devs when they know the version)
  • Add missing PHP versions to .travis-ci

@jonjomckay Is this project still maintained?

Session mode broken over tcp

At least when using tcp I am seeing clam respond to commands when in session mode with a number prefix followed by the response. Problem is they arrive in two different tcp packets thus the read call in _receiveResponse only reads the number (eg "1:") and the next command you issue gets the actual response

scanFile returns Permission Denied error

So I am using this library in my Laravel Application.

When I pass through the temp path of an uploaded file through to ->scanFile(), it throws a permissions denied error.

The tmpdir in my php.ini is /tmp, though the permissions for this folder is:

drwxrwxrwt

Is this anything to do with the library, or the setup on my server?

Factory not found

Not sure what I did, but every time I try this I get "Class 'Factory' not found"

Builds on Travis CI are very slow

The builds on Travis CI are really, really slow sometimes - occasionally taking 10 minutes to run. This is mostly because ClamAV takes an abnormally long amount of time to update - we could cache the /var/lib/clamav directory to try and speed this up in the future.

Socket operation failed: Broken pipe (SOCKET_EPIPE) ON Big file Scanning

We have received the "Socket operation failed: Broken pipe (SOCKET_EPIPE)" error when we scan 40 MB file with chunk size of 15 MB.

check my below code

`$this->socket = (new \Socket\Raw\Factory())->createClient(
getenv('CLAMAV_SERVER')
);
$this->quahog = new \Xenolope\Quahog\Client($this->socket);

        //chunkSize (3 * 1024)
        $scannedResult = $this->quahog->scanLocalFile($storedPath, (15 * 1024));`

Update of PHPUnit to 5.7

Because quahog has the minimum PHP version of 5.6, we need to update PHPUnit and quahog's tests to a new version. PHPUnit 5.7 supports PHP 5.6 and is therefore the version of choice.

This is an easypick for developers, who are new to contributing to open source and want to be part it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.