NAME

Net::ClamAV::Client - A client class for the ClamAV clamd virus scanner daemon

VERSION

version 0.1

SYNOPSIS

Creating a scanner client

use Net::ClamAV::Client;

# Use a TCP inet domain socket
my $scanner = Net::ClamAV::Client->new(url => "localhost:3310");

# Use a local Unix domain socket:
$scanner = Net::ClamAV::Client->new(url => "/var/run/clamav/clamd.ctl");

die("ClamAV daemon not alive")
    if not defined($scanner) or not $scanner->ping();

Daemon maintenance

my $scanner = Net::ClamAV::Client->new(url => "localhost:3310");

my $version = $scanner->version;
                        # Retrieve the ClamAV version string.

$scanner->reload();     # Reload the malware pattern database.

$scanner->quit();       # Terminates the ClamAV daemon.
$scanner->shutdown();   # Likewise.

Path scanning

# Scan a single file or a whole directory structure,
# and stop at the first infected file. For this to work
# the clamd has to run on the local host:

my $scanner = Net::ClamAV::Client->new(url => "localhost:3310");
my @results = $scanner->scanLocalPath("/etc/groups");

Path scanning (complete)

# Scan a single file or a whole directory structure,
# and scan all files without stopping at the first infected one:
my $scanner = Net::ClamAV::Client->new(url => "localhost:3310");
my @results2 = $scanner->scanLocalPathContinous("/etc/");

Other scanning methods

my $handle;
my $scanner = Net::ClamAV::Client->new(url => "localhost:3310");
# Scan a stream, i.e. read from an I/O handle:
my $result = $scanner->scanStream($handle);

# Scan a scalar value:
my $value; # some file in a scalar
my $result2 = $scanner->scanScalar(\$value);

DESCRIPTION

Net::ClamAV::Client is a class acting as a client for a ClamAV clamd virus scanner daemon. The daemon may run locally or on a remote system as Net::ClamAV::Client can use both Unix domain sockets and TCP/IP sockets. The full functionality of the clamd client/server protocol is supported.

This Module is based on the ClamAV::Client class written by Julian Mehnle <julian@mehnle.net> which is not developed anymore but everything has been written from scratch.

Methods

Constructor

The following constructor is provided:

new(%options): RETURNS Net::ClamAV::Client

Creates a new Net::ClamAV::Client object.

%options is a list of key/value pairs representing any of the following options:

url

A scalar containing the url to the clamd server (e.g. localhost:3310 or /var/run/clamav/clamd.ctl)

Public Instance Methods

The following public methods are provided:

ping : RETURNS SCALAR

Returns true ('PONG') if the ClamAV daemon is alive. Throws a Net::ClamAV::Exception otherwise.

version : RETURNS SCALAR

Returns the Version String of the clamd server. Throws a Net::ClamAV::Exception otherwise.

reload : RETURNS SCALAR

Reloads the clamd virus databases and returns true ('RELOADING') when successfull. Throws a Net::ClamAV::Exception otherwise.

shutdown : RETURNS SCALAR

Shutdowns the clamd server. Throws a Net::ClamAV::Exception when unseccessfull.

quit : RETURNS SCALAR

śame as shutdown

scanLocalPath : RETURNS HASH

Scan a file or directory given as path. Important: The used clamd has to run on the local host for this method to work. Clamd will directly access the given path. Make sure the user running clamd has access rights to it. Scanning stops when the first virus is found or all files within path has been scanned.

The Method returns a Hash with attributes file and result.

my $hash = { file => "the filename a virus was found in", result => "the result of file" };

Throws a Net::ClamAV::Exception on error.

scanLocalPathContinous : RETURNS HASH

Scan a file or directory given as path and do not stop on first virus found. Important: The used clamd has to run on the local host for this method to work. Clamd will directly access the given path. Make sure the user running clamd has access rights to it. Scanning stops when the first virus is found or all files within path has been scanned.

The Method returns an array of hashes with attributes file and result.

my $hash = { file => "the filename a virus was found in", result => "the result of file" };

Throws a Net::ClamAV::Exception on error.

scanLocalPathMulti : RETURNS HASH

Scan a file or directory given as path concurrently. Important: The used clamd has to run on the local host for this method to work. Clamd will directly access the given path. Make sure the user running clamd has access rights to it. Scanning stops when the first virus is found or all files within path has been scanned.

The Method returns an array of hashes with attributes file and result.

my $hash = { file => "the filename a virus was found in", result => "the result of file" };

Throws a Net::ClamAV::Exception on error.

scanLocalFile : RETURNS HASH

Scan one file. Important: The used clamd has to run on the local host for this method to work. Clamd will directly access the given path. Make sure the user running clamd has access rights to it. Scanning stops when the first virus is found or all files within path has been scanned.

The Method returns a hashe with attributes file and result. s my $hash = { file => "the filename a virus was found in", result => "the result of file" };

Throws a Net::ClamAV::Exception on error.

stats : RETURNS HASH

Return the stats of the clamd. NOT SUPPORTED YET

Throws a Net::ClamAV::Exception on error.

scanFileDescriptor : RETURNS HASH

Scans a file given by a file descriptor. NOT SUPPORTED YET

Throws a Net::ClamAV::Exception on error.

startSession

Starts a session with the clamd server within multiple scan commands can be issued.

Throws a Net::ClamAV::Exception on error.

runningSession : RETURNS SCALAR

Checks if a session is running with the clamd server.

Returns 1 if yes, else 0.

endSession

Ends a session with the clamd server within multiple scan commands can be issued.

Throws a Net::ClamAV::Exception on error.

scanStreamFH : RETURNS SCALAR

Scans a file by transmitting it as a stream to the clamd server. The file is given as a IO::Handle.

The Method returns a SCALAR with attributes undef or virusname.

Throws a Net::ClamAV::Exception on error.

scanStreamFile : RETURNS SCALAR

Scans a file by transmitting it as a stream to the clamd server. The file is given as a path.

The Method returns a SCALAR with attributes undef or virusname.

Throws a Net::ClamAV::Exception on error.

scanScalar : RETURNS SCALAR

Scans a SCALAR by transmitting it as a stream to the clamd server. The file is given as a path.

The Method returns a SCALAR with attributes undef or virusname.

Throws a Net::ClamAV::Exception on error.

AUTHOR

Domink Meyer <dmeyer@federationhq.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2021 by Dominik Meyer.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

AVAILABILITY

The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit http://www.perl.com/CPAN/ to find a CPAN site near you, or see https://metacpan.org/module/Net::ClamAV::Client/.

COPYRIGHT AND LICENSE

This software is copyright (c) 2021 by Dominik Meyer.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.