diff --git a/htdocs/docsoc.php b/htdocs/docsoc.php index bc07cc05ac7..313bdcc4855 100644 --- a/htdocs/docsoc.php +++ b/htdocs/docsoc.php @@ -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 = '
'.$langs->trans("FileTransferComplete").'
'; - //print_r($_FILES); - } - else - { - // Echec transfert (fichier dépassant la limite ?) - $mesg = '
'.$langs->trans("ErrorFileNotUploaded").'
'; - // print_r($_FILES); - } + $mesg = '
'.$langs->trans("FileTransferComplete").'
'; + //print_r($_FILES); } + else if ($result == false) + { + // Echec transfert (fichier dépassant la limite ?) + $mesg = '
'.$langs->trans("ErrorFileNotUploaded").'
'; + // print_r($_FILES); + } + else + { + $mesg = '
'.$langs->trans("FileIsInfectedWith",$result).'
'; + } + } } // Suppression fichier diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index f1bbbc1f72f..108624e8a22 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -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