[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-clamav/sbin/ -> se3-clamav (source)

   1  #!/usr/bin/perl
   2  # /usr/sbin/se3-clamav
   3  # This file is part of the samba-edu project
   4  #  it is distributed under the terms of the Gnu GPL license
   5  # 
   6  # Report any bug or comment to laurent Cooper <swirly@slis.fr>
   7  
   8  # This programm connects to the se3db to read the directorys to scan
   9  # It store the results of the clamav scan in the satabase;
  10  
  11  use DBI;
  12  use strict;
  13  use File::Temp;
  14  
  15  ###
  16  #
  17  # Config file opening
  18  #
  19  ###
  20  
  21  my $dbhost=`cat /var/www/se3/includes/config.inc.php | grep \"dbhost=\" | cut -d = -f 2 |cut -d \\\" -f 2`;
  22  chomp $dbhost;
  23  my $dbname=`cat /var/www/se3/includes/config.inc.php | grep \"dbname=\" | cut -d = -f 2 |cut -d \\\" -f 2`;
  24  chomp $dbname;
  25  my $dbuser=`cat /var/www/se3/includes/config.inc.php | grep \"dbuser=\" | cut -d = -f 2 |cut -d \\\" -f 2`;
  26  chomp $dbuser;
  27  my $dbpass=`cat /var/www/se3/includes/config.inc.php | grep \"dbpass=\" | cut -d = -f 2 |cut -d \\\" -f 2`;
  28  chomp $dbpass;
  29  
  30  
  31  ###
  32  #
  33  # Determines which scan to make
  34  #
  35  ###
  36  
  37  my $frequency=shift;
  38  
  39  my $dsn="DBI:mysql:$dbname:$dbhost";
  40  my $dbd = DBI->connect($dsn,$dbuser,$dbpass);
  41  my $sth= $dbd->prepare("SELECT * FROM clamav_dirs WHERE frequency=\'$frequency\' ");
  42  $sth->execute;
  43  
  44  my $ref_row;
  45  while ($ref_row = $sth->fetchrow_hashref) {
  46             my $directory = $ref_row->{"directory"};
  47             my $remove = $ref_row->{"remove"};
  48             my $tmp_file=tmpnam();
  49  
  50  #############################
  51  #
  52  # Now scan the directory appropriatly
  53  #           
  54  #############################
  55            
  56            if ($remove eq "0") {
  57               `/usr/bin/nice -n 15 /usr/bin/clamscan -ri -l $tmp_file  $directory >> /dev/null 2>&1`;
  58               } else {             
  59                `/usr/bin/nice -n 15 /usr/bin/clamscan --remove -ri -l $tmp_file  $directory >> /dev/null 2>&1`;
  60               }
  61  
  62  #############################
  63  #
  64  # Flush the result
  65  #
  66  #############################
  67             
  68  
  69             open(CLAMSCAN,$tmp_file);
  70             my $line;
  71             my $summary="";
  72             my $scan_result="";
  73             my $mode="scan";
  74             while (defined ($line=<CLAMSCAN>)) {
  75                if ($mode eq "scan") {
  76                  if( $line =~ /--\ssummary\s--/) {
  77                    $mode="summary";
  78                    } else {
  79                    $scan_result .= $line;}
  80                } else {
  81           $summary .= $line;
  82                      }
  83                  }                       
  84  
  85  #############################
  86  #
  87  # Put it in the database
  88  #
  89  #############################
  90            ## Added to  protect SQL syntax, thank to Jean Le Bail
  91            $summary =~ s/\'/\\\'/g;
  92            $scan_result =~ s/\'/\\\'/g;
  93            ##
  94            $dbd->do("INSERT INTO clamav_scan (directory,summary,result) VALUES ('".$directory."','".$summary."','".$scan_result."')");
  95  
  96  #############################
  97  #           
  98  # Destroy temporary file
  99  #
 100  #############################
 101            unlink($tmp_file);
 102           }
 103  
 104  $dbd->disconnect();         
 105           


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1