Test d'utilisation de php5-clamavlib

This commit is contained in:
Regis Houssin 2007-10-21 19:37:25 +00:00
parent 71358cd160
commit 18a58130f5
2 changed files with 43 additions and 11 deletions

View File

@ -53,19 +53,24 @@ if ( $_POST["sendit"] && $conf->upload != 0)
if (! is_dir($upload_dir)) create_exdir($upload_dir);
if (is_dir($upload_dir))
{
$result = doliMoveFileUpload($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name']);
if ($result == true)
{
if (doliMoveFileUpload($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name']))
{
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
}
else
{
// Echec transfert (fichier dépassant la limite ?)
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
// print_r($_FILES);
}
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
}
else if ($result == false)
{
// Echec transfert (fichier dépassant la limite ?)
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
// print_r($_FILES);
}
else
{
$mesg = '<div class="error">'.$langs->trans("FileIsInfectedWith",$result).'</div>';
}
}
}
// Suppression fichier

View File

@ -1690,7 +1690,15 @@ function dolibarr_print_error($db='',$error='')
*/
function doliMoveFileUpload($src_file, $dest_file)
{
global $conf;
$file_name = $dest_file;
if ($conf->global->MAIN_USE_AVSCAN)
{
$malware = dol_avscan_file($src_file);
if ($malware) return $malware;
}
// Security:
// On renomme les fichiers avec extention executable car si on a mis le rep
@ -2070,6 +2078,25 @@ function dol_delete_dir_recursive($dir,$count=0)
return $count;
}
/**
\brief Scan les fichiers avec Clamav
\param file Fichier a scanner
\return malware Nom du virus si infecté sinon retourne "null"
*/
function dol_avscan_file($file)
{
$malware = '';
$maxreclevel = 5 ; // maximal recursion level
$maxfiles = 1000; // maximal number of files to be scanned within archive
$maxratio = 200; // maximal compression ratio
$archivememlim = 0; // limit memory usage for bzip2 (0/1)
$maxfilesize = 10485760; // archived files larger than this value (in bytes) will not be scanned
cl_setlimits($maxreclevel, $maxfiles, $maxratio, $archivememlim, $maxfilesize);
$malware = cl_scanfile($file);
return $malware;
}
/**
\brief Fonction print_barre_liste