#!/usr/bin/php -q
<?php
#     Copyright (C) 2005, 2006 Stewart Adam
#    This file is part of FWVirusScanner.

#    FWVirusScanner 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.

#    FWVirusScanner 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 for more details.

#    You should have received a copy of the GNU General Public License
#    along with FWVirusScanner; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
$numb = 0;
$files = "";

unset($_SERVER['argv']['0']);
	foreach($_SERVER['argv'] as $key => $value)
	{#
		$files = "$files '$value'";
	}#
	if($files == "")
	{#
		$files = `zenity --file-selection --multiple --directory --separator=";" --title "Directories"`;
		$files = trim("$files");
		$array = explode(";",$files);
		$files = "";
		foreach($array as $key => $value)
		{##
				$value = eregi_replace(' ','\ ',$value);
				$files = "$files $value";
#				`zenity --info --text "$files"`;
		}##
#				`zenity --info --text "$files"`;
		$files2 = `zenity --file-selection --multiple --separator=";" --title "Files"`;
		$files2 = trim("$files2");
		$files = trim("$files");
		if($files2 == "")
		{##
			if($files == "")
			{###
				exit();
			}###
		}##
		$array2 = explode(";",$files2);
		$files2 = "";
		foreach($array2 as $key => $value)
		{##
			$value = eregi_replace(' ','\\ ',$value);
			$files2 = "$files2 $value";
			$numb = $numb + 1;
		}##
	}#

	$question = `zenity --question --title "Progress?" --text "Enable progress bar? (May increase scan time slightly)";echo $?`;
	$question = trim($question);
	$question = ltrim($question);
	$question = rtrim($question);

$files = trim($files);
$files2 = trim($files2);
if($question == '0')
{
	`find $files -printf '%p \n' >> /var/log/clamav/files.log`;
	$files = "$files $files2";
	`clamscan -r -l /var/log/clamav/scan.log $files --no-summary >> /var/log/clamav/progress.log | echo $! > /var/log/clamav/pid.log &`;
	$pid = `cat /var/log/clamav/pid.log`;
	$pid = trim($pid);
	`/usr/bin/vsdep/arg "$numb" "$pid"`;
}
else
{
	$files = "$files $files2";
	`clamscan -r -l /var/log/clamav/scan.log $files`;
}
$found = `cat -E /var/log/clamav/progress.log | grep "FOUND\\\\$" | grep -v ": OK\\\\$"`;
`zenity --info --text "$found"`;
$error = `cat /var/log/clamav/progress.log | grep "ERROR:"`;
if($found != "")
{#
`zenity --error --title "Infection" --text "The following files were found to be infected, or an error occured during it's scan:
(Ignore the $: It means end-of-line)
$found"`;
}#
elseif($error != "")
{
`zenity --error --title "Infection" --text "The following errors occurred:
$error"`;
}
else
{
`zenity --info --title "All Clean, no errors" --text "All Clean, no errors."`;
}
if($question == "0")
{#
	`rm /var/log/clamav/progress.log`;
	`rm /var/log/clamav/files.log`;
	`rm /var/log/clamav/pid.log`;
}#
?>
