Skip to content

Commit

Permalink
Removing Antivirus from config.xml #247
Browse files Browse the repository at this point in the history
  • Loading branch information
dbellettini committed Feb 10, 2013
1 parent e2921d6 commit 0d2fed6
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 85 deletions.
9 changes: 3 additions & 6 deletions app/config/parameters.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
parameters:
universibo:
antivirus:
enabled: false
type: clamav
cmd: /usr/bin/clamscan
opts: '--quiet --recursive'
antivirus_enabled: false
antivirus_cmd: /usr/bin/clamscan
antivirus_opts: '--quiet --recursive'
6 changes: 0 additions & 6 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,5 @@
<regolamento>../universibo/files/regolamento.txt</regolamento>
<staffEmail>[email protected]</staffEmail>
<defaultAnnoAccademico>2011</defaultAnnoAccademico>

<!--<antiVirusEnable>true</antiVirusEnable> -->
<antiVirusEnable>false</antiVirusEnable>
<antiVirusType>clamav</antiVirusType>
<antiVirusClamavCmd>/usr/local/bin/clamscan</antiVirusClamavCmd>
<antiVirusClamavOpts>--quiet --recursive</antiVirusClamavOpts>
</appSettings>
</config>

This file was deleted.

41 changes: 29 additions & 12 deletions src/Universibo/Bundle/LegacyBundle/App/AntiVirus/Clamav.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,59 @@
/**
* Classe antivirus per clamav
*
* @package universibo
* @author Ilias Bartolini <[email protected]>
* @author Davide Bellettini <[email protected]>
* @license GPL, http://www.opensource.org/licenses/gpl-license.php
* @copyright CopyLeft UniversiBO 2001-2005
* @copyright CopyLeft UniversiBO 2001-2013
*/

class Clamav
{

/**
* Command line options
*
* @var type
*/
private $opts = '';

/**
* Clamav command
*
* @var string
*/
private $cmd = '';

public function __construct($cmd, $opts)
/**
* class constructor
*
* @param string $cmd
* @param string $opts
* @param boolean $enabled
*/
public function __construct($cmd, $opts, $enabled)
{
$this->cmd = $cmd;
$this->opts = $opts;
$this->cmd = $cmd;
$this->opts = $opts;
$this->enabled = $enabled;
}

/**
* @return true se ci sono virus, false se _non_ ci sono virus
*/
public function checkFile($filename)
{
if(!$this->enabled) {
return false;
}

$filename = escapeshellarg($filename);

$fullCommand = $this->cmd.' '.$this->opts.' '.$filename;

$output = array();
unset($output);
$returnval = null;

exec ( $fullCommand, $output, $returnval );

if ($returnval == 1) return true;
if ($returnval == 0) return false;


return $returnval != 0;
}
}
29 changes: 12 additions & 17 deletions src/Universibo/Bundle/LegacyBundle/Command/FileAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use Universibo\Bundle\LegacyBundle\Framework\Error;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Universibo\Bundle\CoreBundle\Entity\User;
use Universibo\Bundle\LegacyBundle\App\AntiVirus\AntiVirusFactory;
use Universibo\Bundle\LegacyBundle\Auth\LegacyRoles;
use Universibo\Bundle\LegacyBundle\Entity\Canale;
use Universibo\Bundle\LegacyBundle\Entity\Files\FileItem;
Expand Down Expand Up @@ -444,22 +443,18 @@ public function execute()
'file' => __FILE__, 'line' => __LINE__));
}

$antiVirus = AntiVirusFactory::getAntiVirus($frontcontroller);
//controllo antivirus
if ($antiVirus) {
if ($antiVirus
->checkFile(
$frontcontroller
->getAppSetting('filesPath')
. $nomeFile) === true) {
$transaction->rollback();
Error::throwError(_ERROR_DEFAULT,
array('id_utente' => $user->getId(),
'msg' => 'ATTENZIONE: Il file inviato e\' risultato positivo al controllo antivirus!',
'file' => __FILE__, 'line' => __LINE__,
'log' => false,
'template_engine' => &$template));
}
$fullFileName = $frontcontroller->getAppSetting('filesPath') . $nomeFile;
$antivirus = $this->get('universibo_legacy.antivirus');

if ($antivirus->checkFile($fullFileName)) {
$transaction->rollback();
Error::throwError(_ERROR_DEFAULT, array(
'id_utente' => $user->getId(),
'msg' => 'ATTENZIONE: Il file inviato e\' risultato positivo al controllo antivirus!',
'file' => __FILE__, 'line' => __LINE__,
'log' => false,
'template_engine' => &$template
));
}

$contactService = $this->get('universibo_core.contact.service');
Expand Down
27 changes: 12 additions & 15 deletions src/Universibo/Bundle/LegacyBundle/Command/FileStudentiAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,21 +410,18 @@ public function execute()
'file' => __FILE__, 'line' => __LINE__));
}

//controllo antivirus
if ($antiVirus = AntiVirusFactory::getAntiVirus(
$frontcontroller)) {
if ($antiVirus
->checkFile(
$frontcontroller
->getAppSetting('filesPath')
. $nomeFile) === true) {
$transaction->rollback();
Error::throwError(_ERROR_DEFAULT, array('id_utente' => $user->getId(),
'msg' => 'ATTENZIONE: Il file inviato e\' risultato positivo al controllo antivirus!',
'file' => __FILE__, 'line' => __LINE__,
'log' => false,
'template_engine' => &$template));
}
$fullFileName = $frontcontroller->getAppSetting('filesPath') . $nomeFile;
$antivirus = $this->get('universibo_legacy.antivirus');

if ($antivirus->checkFile($fullFileName)) {
$transaction->rollback();
Error::throwError(_ERROR_DEFAULT, array(
'id_utente' => $user->getId(),
'msg' => 'ATTENZIONE: Il file inviato e\' risultato positivo al controllo antivirus!',
'file' => __FILE__, 'line' => __LINE__,
'log' => false,
'template_engine' => &$template
));
}

//$num_canali = count($f23_canale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@
<argument type="service" id="universibo_legacy.db.connection.main" />
<argument>true</argument>
</service>

<service id="universibo_legacy.antivirus"
class="Universibo\Bundle\LegacyBundle\App\AntiVirus\Clamav">
<argument>%antivirus_cmd%</argument>
<argument>%antivirus_opts%</argument>
<argument>%antivirus_enabled%</argument>
</service>

<service id="universibo_legacy.repository.facolta"
class="Universibo\Bundle\LegacyBundle\Entity\DBFacoltaRepository">
Expand Down

0 comments on commit 0d2fed6

Please sign in to comment.