smeserver-clamav/root/sbin/e-smith/smeserver-clamscan

72 lines
2.5 KiB
Perl

#!/usr/bin/perl -w
#----------------------------------------------------------------------
# Clam Antivirus virus scanner filesystem scanning.
#
# copyright (C) 2004 Shad L. Lords <slords@mail.com>
# Copyright (C) 2005 Gordon Rowell <gordonr@gormand.com.au>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License or more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#----------------------------------------------------------------------
use strict;
use esmith::ConfigDB;
my $db = esmith::ConfigDB->open_ro or die "Couldn't open ConfigDB";
my $filesystems = $db->get_prop("clamav", "FilesystemScanFilesystems") || '/';
my $MailReport = $db->get_prop("clamav", "FilesystemScanReportTo") || 'admin';
my $clamscan_opts = " --recursive --infected --stdout" .
" --log /var/log/clamd/clamscan.log";
my $quarantine_dir = $db->get_prop("clamav", "QuarantineDirectory") ||
"/var/spool/clamav/quarantine";
my @exclude = split /,/, ($db->get_prop("clamav", "FilesystemScanExclude") ||
"/proc,/sys,/usr/share/doc");
push @exclude, $quarantine_dir;
$clamscan_opts .= " --exclude=$_" for (@exclude);
$clamscan_opts .= " --no-html"
if ($db->get_prop("clamav", "ScanHTML") || "yes") eq "no";
$clamscan_opts .= " --no-mail"
if ($db->get_prop("clamav", "ScanMail") || "yes") eq "no";
$clamscan_opts .= " --move=$quarantine_dir"
if ($db->get_prop("clamav", "Quarantine") || "disabled") eq "enabled";
$clamscan_opts .= " --official-db-only=yes"
if ($db->get_prop("clamav", "FilesystemScanUnofficialSigs") || 'no') ne "yes";
open CLAMSCAN, "-|", "nice /usr/bin/clamscan $clamscan_opts $filesystems 2> /var/log/clamd/smeserver-clamscan.log";
my @report = <CLAMSCAN>;
close CLAMSCAN;
my $hostname = $db->get_value("SystemName") . "." .
$db->get_value("DomainName");
my $date = localtime;
open MAIL, "| /bin/mail " .
"-s \"[$hostname] Clam Antivirus Scan Results - $date\" $MailReport";
print MAIL @report;
close MAIL;