Imported Upstream version 2.5.11
[libapache-mod-security.git] / rules / util / runav.pl
1 #!/usr/bin/perl
2 #
3 # runav.pl
4 # Copyright (c) 2007 Breach Security
5 #
6 # This script is an interface between ModSecurity and its
7 # ability to intercept files being uploaded through the
8 # web server, and ClamAV
9
10
11 $CLAMSCAN = "clamscan";
12
13 if ($#ARGV != 0) {
14     print "Usage: modsec-clamscan.pl <filename>\n";
15     exit;
16 }
17
18 my ($FILE) = shift @ARGV;
19
20 $cmd = "$CLAMSCAN --stdout --disable-summary $FILE";
21 $input = `$cmd`;
22 $input =~ m/^(.+)/;
23 $error_message = $1;
24
25 $output = "0 Unable to parse clamscan output [$1]";
26
27 if ($error_message =~ m/: Empty file\.?$/) {
28     $output = "1 empty file";
29 }
30 elsif ($error_message =~ m/: (.+) ERROR$/) {
31     $output = "0 clamscan: $1";
32 }
33 elsif ($error_message =~ m/: (.+) FOUND$/) {
34     $output = "0 clamscan: $1";
35 }
36 elsif ($error_message =~ m/: OK$/) {
37     $output = "1 clamscan: OK";
38 }
39
40 print "$output\n";