| 1 | package Catalyst::Plugin::ClamAV; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use ClamAV::Client; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 8 | 3 | our $base = 'clamav'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | sub clamscan { | ||||||||||||||||||||||||||
|
Subroutine
clamscan: called CC=7 SCAR=35.3
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 2 | my ( $c, @names ) = @_; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | my $scanner = $c->_init_clam(); | |||||||||||||||||||||||||||
| 14 | 2 | ▶ | unless ($scanner) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | 2 | return -1; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | my $found = 0; | |||||||||||||||||||||||||||
| 19 | 0 | my @virus; | |||||||||||||||||||||||||||
| 20 | 0 | foreach my $name (@names) { | |||||||||||||||||||||||||||
| 21 | 0 | my $upload = $c->req->upload( $name ); | |||||||||||||||||||||||||||
| 22 | 0 | ▶ | next unless $upload; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | my $fh = $upload->fh; | |||||||||||||||||||||||||||
| 25 | 0 | ▶ | if ($fh) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | my $virus = $scanner->scan_stream( $fh ); | |||||||||||||||||||||||||||
| 27 | 0 | seek( $fh, 0, 0 ); | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ( $virus ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | $found++; | |||||||||||||||||||||||||||
| 30 | 0 | push @virus, { | |||||||||||||||||||||||||||
| 31 | name => $name, | ||||||||||||||||||||||||||||
| 32 | signature => $virus, | ||||||||||||||||||||||||||||
| 33 | }; | ||||||||||||||||||||||||||||
| 34 | 0 | $c->log->warn( __PACKAGE__ . " VIRUS found. signature='$virus'" ); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | return wantarray ? @virus : $found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2 | ▶ | sub _init_clam { | ||||||||||||||||||||||||||
|
Subroutine
_init_clam: called CC=7 SCAR=23.2
| |||||||||||||||||||||||||||||
| 42 | 2 | my ($c) = shift; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2 | my %opt; | |||||||||||||||||||||||||||
| 45 | 2 | foreach my $n(qw( socket_name socket_host socket_port )){ | |||||||||||||||||||||||||||
| 46 | 6 | ▶ | $opt{$n} = $c->config->{$base}->{$n} if defined $c->config->{$base}->{$n}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 2 | my ( $scanner, $error ); | |||||||||||||||||||||||||||
| 49 | 2 | eval { | |||||||||||||||||||||||||||
| 50 | 2 | $scanner = ClamAV::Client->new( %opt ); | |||||||||||||||||||||||||||
| 51 | 2 | ▶ | if ( !$scanner or !$scanner->ping ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$scanner and $scanner->ping
MC/DC0%0/2
$scanner and $scanner->ping
$scanner
$scanner->ping
Truth table33%1/3
A and B
A= $scannerB= $scanner->ping
| |||||||||||||||||||||||||||||
| 52 | 0 | $error = 1; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | }; | ||||||||||||||||||||||||||||
| 55 | 2 | ▶ | if ( $@ || $error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ or $error
MC/DC0%0/2
$@ or $error
$@
$error
Truth table33%1/3
A or B
A= $@B= $error
| |||||||||||||||||||||||||||||
| 56 | 2 | $c->log->error(qq{Cannot connect to ClamAV. $@}); | |||||||||||||||||||||||||||
| 57 | 2 | return; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 0 | return $scanner; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 3 | 1; | |||||||||||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||||||||||