<?php
$path = "/some/directory";
$cnt = 0;
$pass = 0;
$fail = 0;
/* Get running environnement (CLI or not) */
$br = (php_sapi_name() == "cli")? "\n":"<br />\n";
$module = 'clamav';
/* Check if extension is loaded and return all functions */
if (extension_loaded($module))
{
/* Deactive debug */
if (function_exists('cl_debug_off'))
{
cl_debug_off();
}
/* Run cl_info() and return result */
print $br."<b>cl_info() returns : </b>".cl_info().$br;
/* Run cl_info() and return result */
print "<b>cl_version() returns : </b>".cl_version().$br;
/* Run two principal cl_retcode() function and return result for a CL_CLEAN and CL_VIRUS */
print "<b>cl_pretcode(CL_CLEAN) return : </b>".cl_pretcode(CL_CLEAN).$br;
print "<b>cl_pretcode(CL_VIRUS) return : </b>".cl_pretcode(CL_VIRUS).$br.$br;
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle))
{
if($file!="." && $file!="..")
{
/* Run a cl_scanfile() and return the result into $retcode and the virus name if found in $virusname */
$fname = $path."/".$file;
if (file_exists("$fname"))
{
$retcode = cl_scanfile("$fname", $virusname);
if ($retcode == CL_VIRUS)
{
print "<b>File Path : </b>".$file.$br."<b>Return Code : </b>".cl_pretcode($retcode).$br."<b>Virus Name : </b>".$virusname.$br.$br;
$pass++;
} else {
print "<b>File Path : </b>".$file.$br."<b>Return Code : </b>".cl_pretcode($retcode).$br.$br;
$fail++;
}
$cnt++;
}
}
}
print "<b>Results : </b> scanned ".$cnt." files, ".$pass." infected, ".$fail." clean".$br.$br;
} else {
print "Module $module is not loaded into PHP";
}
?>