Coder Social home page Coder Social logo

kissit / php-clamav-scan Goto Github PK

View Code? Open in Web Editor NEW
40.0 9.0 16.0 10 KB

A simple PHP library for ClamAV that is CodeIgniter compatible

Home Page: https://kissitconsulting.com/blog/post/php-clamav-scan-a-simple-library-for-scanning-files-with-clamav-from-php

License: BSD 2-Clause "Simplified" License

PHP 100.00%
php clamav codeigniter

php-clamav-scan's Introduction

php-clamav-scan

A simple PHP class for scanning files using a LOCAL ClamAV/clamd install either via a socket file or network socket (windows). Can either be used on its own or dropped into a Codeigniter app as a library. The main reason this was created was because the legacy php-clamav module is not compatible with PHP 7 and all other options I found were either not drop in compatible with CodeIgniter or were designed for use with Composer. Such a trivial task/library should not be that difficult.

As previously mentioned, the files are scanned using their full path so clamd needs to be run on the web server. Even when using a network socket, the class does not handle the streaming of files over the network in a client/server model(yet). I didn't have a need to do scans over the network but support could easily be added. That being said, it requires the PHP Sockets module be installed. If not already present you must install it based on your system.

To use this on Windows, you must use the network socket option. As far as I'm aware the Windows version of Clamd does not support sockets.

Example standalone usage:

  • Include the class
require 'Clamav.php';
  • Instantiate an object.
$clamav = new Clamav();
  • If you need to customize the Clamd socket path you can do so
$clamav = new Clamav(array('clamd_sock' => '/path/to/clamd.sock'));
  • Scan a file
if($clamav->scan("/path/to/file/to/scan.txt")) {
    echo "YAY, file is safe\n";
} else {
    echo "BOO, file is a virus.  Message: " . $clamav->getMessage() . "\n";
}

Example CodeIgniter Usage

  • Download the file into your application/libraries directory
  • Load the library where desired
$this->load->library('clamav');
  • If you need to customize the Clamd socket path you can do so
$this->load->library('clamav', array('clamd_sock' => '/path/to/clamd.sock'));
  • Scan a file
if($this->clamav->scan("/path/to/file/to/scan.txt")) {
    echo "YAY, file is safe\n";
} else {
    echo "BOO, file is a virus.  Message: " . $clamav->getMessage() . "\n";
}

Example Network Socket Usage

Everything is the same to use a network socket other than you must pass in at least the IP when instantiating the object. You can also include an optional port if you are using something other than the standard 3310.

$clamav = new Clamav(array('clamd_sock' => '/path/to/clamd.sock'));

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.