Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
antivirus.inc
1 <?php
29 class Antivirus
30 {
31 
32 
44  public static function scan_file($path='', &$report, $recursive=FALSE)
45  {
46 
47  // Default to OK
48  $status = TRUE;
49  // The check we are using a valid virus scanner
50  $using_av = FALSE;
51  $scanned = FALSE;
52 
53  // Load the virus checker
54  require_once SQ_DATA_PATH.'/private/conf/tools.inc';
55 
56  // Scan the file
57  if (SQ_TOOL_VIRUS_CHECKER_ENABLED) {
58  if (!file_exists(SQ_TOOL_VIRUS_CHECKER_PATH)) {
59  // Unable to scan the file
60  // Warn the user sometime ho hum
61  } else {
62 
63  if (empty($path)) {
64  return $status;
65  } else {
66  $file = $path;
67  }//end if
68 
69  // Check the file exists (it would be a bit dumb to scan nothing!)
70  if (is_dir($file) || file_exists($file)) {
71  $options = Array();
72  switch (SQ_TOOL_VIRUS_CHECKER_TYPE) {
73  case 'f-prot':
74  $options = Array(
75  '-old',
76  );
77  break;
78 
79  default:
80  $options = Array();
81  if ($recursive) $options[] = '-r';
82  }//end switch
83 
84  // Scan the file
85  $path_to_av = SQ_TOOL_VIRUS_CHECKER_PATH;
86  foreach($options as $option) {
87  $path_to_av .= ' '.$option;
88  }//end foreach
89  $command = $path_to_av.' '.escapeshellarg($file).' 2>&1';
90 
91  // Run the command
92  exec($command, $av, $return);
93 
94 
95  // Check the result was correct
96  // That is, we are using a virus scanner
97  // This is so we don't get false positives
98  foreach ($av as $line_no => $line) {
99  // Scan each line
100  if (preg_match('/scanned/', $line)) {
101  $scanned = TRUE;
102  }//end if
103  }//end foreach
104 
105  // Save the report to send back
106  $report = $av;
107 
108  // Sift through the results
109  // Flag if infected
110  if ($return && $scanned) {
111  $status = FALSE;
112  }//end if
113  }//end if
114  }//end if
115  }//end if
116  // Return
117 
118  return $status;
119 
120  }//end scan_file()
121 
122 }//end class
123 
124 ?>