#!/usr/bin/php -q
<?php
$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' >> /clamavlog/files.log`;
	$files = "$files $files2";
#	`zenity --info --text $files`;
/*	$running = `ps -A | grep clamscan`;
	if($running != "")
	{
	`zenity --error --text "Clamscan is already running. Please wait for the current scan to finish first.
To stop the current scan, (as root) type:
# killall clamscan`;
	exit();
	}*/
	`clamscan -r -l /clamavlog/scan.log $files --no-summary >> /clamavlog/progress.log | echo $! > /clamavlog/pid.log &`;
	$pid = `cat /clamavlog/pid.log`;
	$pid = trim($pid);
	`/usr/bin/vsdep/arg "$numb" "$pid"`;
}
else
{
	$files = "$files $files2";
	`clamscan -r -l /clamavlog/scan.log $files`;
}
$found = `cat -E /clamavlog/progress.log | grep "FOUND\\\\$" | grep -v ": OK\\\\$"`;
`zentiy --info --text "$found"`;
$error = `cat /clamavlog/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 /clamavlog/progress.log`;
	`rm /clamavlog/files.log`;
	`rm /clamavlog/pid.log`;
}#
?>
