From 779a134022e4ccf80fa4cf03dae6880572ffaf7f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 13 Feb 2023 12:27:23 +0100 Subject: [PATCH] Fix call of antivirus must be done using utils->executeCLI --- htdocs/core/class/antivir.class.php | 54 ++++++++--------------------- 1 file changed, 14 insertions(+), 40 deletions(-) diff --git a/htdocs/core/class/antivir.class.php b/htdocs/core/class/antivir.class.php index dc38d38185e..cb195b58f5d 100644 --- a/htdocs/core/class/antivir.class.php +++ b/htdocs/core/class/antivir.class.php @@ -81,63 +81,37 @@ class AntiVir } $fullcommand = $this->getCliCommand($file); + //$fullcommand="/usr/bin/clamdscan --fdpass '/tmp/phpuxoAEo'" //$fullcommand='"c:\Program Files (x86)\ClamWin\bin\clamscan.exe" --database="C:\Program Files (x86)\ClamWin\lib" "c:\temp\aaa.txt"'; - $fullcommand .= ' 2>&1'; // This is to get error output - $output = array(); $return_var = 0; $safemode = ini_get("safe_mode"); // Create a clean fullcommand dol_syslog("AntiVir::dol_avscan_file Run command=".$fullcommand." with safe_mode ".($safemode ? "on" : "off")); - // Run CLI command. If run of Windows, you can get return with echo %ERRORLEVEL% - $lastline = exec($fullcommand, $output, $return_var); + // Run CLI command. + include_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php'; + $utils = new Utils($this->db); + $outputfile = $conf->user->dir_temp.'/antivir.tmp'; + $result = $utils->executeCLI($fullcommand, $outputfile); + + $return_var = $result['result']; + $output = $result['output']; + $errorstring = $result['error']; if (is_null($output)) { $output = array(); } - //print "x".$lastline." - ".join(',',$output)." - ".$return_var."y";exit; - - /* - $outputfile=$conf->admin->dir_temp.'/dol_avscan_file.out.'.session_id(); - $handle = fopen($outputfile, 'w'); - if ($handle) - { - $handlein = popen($fullcommand, 'r'); - while (!feof($handlein)) - { - $read = fgets($handlein); - fwrite($handle,$read); - } - pclose($handlein); - - $errormsg = fgets($handle,2048); - $this->output=$errormsg; - - fclose($handle); - - if (!empty($conf->global->MAIN_UMASK)) - @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); - } - else - { - $langs->load("errors"); - dol_syslog("Failed to open file ".$outputfile,LOG_ERR); - $this->error="ErrorFailedToWriteInDir"; - $return=-1; - } - */ - - dol_syslog("AntiVir::dol_avscan_file Result return_var=".$return_var." output=".join(',', $output)); + dol_syslog("AntiVir::dol_avscan_file Result return_var=".$return_var." output=".$output); $returncodevirus = 1; if ($return_var == $returncodevirus) { // Virus found - $this->errors = $output; + $this->errors = array($errorstring, $output); return -99; } if ($return_var > 0) { // If other error - $this->errors = $output; + $this->errors = array($errorstring, $output); return -98; } @@ -178,7 +152,7 @@ class AntiVir } if (preg_match("/\s/", $command)) { - $command = escapeshellarg($command); // Use quotes on command. Using escapeshellcmd fails. + $command = escapeshellarg($command); // Force use of quotes on command. Using escapeshellcmd fails. } $ret = $command.' '.$param;