[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/classes/antivirus/ -> manager.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Manager class for antivirus integration.
  19   *
  20   * @package    core_antivirus
  21   * @copyright  2015 Ruslan Kabalin, Lancaster University.
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core\antivirus;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Class used for various antivirus related stuff.
  31   *
  32   * @package    core_antivirus
  33   * @copyright  2015 Ruslan Kabalin, Lancaster University.
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class manager {
  37      /**
  38       * Returns list of enabled antiviruses.
  39       *
  40       * @return array Array ('antivirusname'=>stdClass antivirus object).
  41       */
  42      private static function get_enabled() {
  43          global $CFG;
  44  
  45          $active = array();
  46          if (empty($CFG->antiviruses)) {
  47              return $active;
  48          }
  49  
  50          foreach (explode(',', $CFG->antiviruses) as $e) {
  51              if ($antivirus = self::get_antivirus($e)) {
  52                  if ($antivirus->is_configured()) {
  53                      $active[$e] = $antivirus;
  54                  }
  55              }
  56          }
  57          return $active;
  58      }
  59  
  60      /**
  61       * Scan file using all enabled antiviruses, throws exception in case of infected file.
  62       *
  63       * @param string $file Full path to the file.
  64       * @param string $filename Name of the file (could be different from physical file if temp file is used).
  65       * @param bool $deleteinfected whether infected file needs to be deleted.
  66       * @throws \core\antivirus\scanner_exception If file is infected.
  67       * @return void
  68       */
  69      public static function scan_file($file, $filename, $deleteinfected) {
  70          $antiviruses = self::get_enabled();
  71          foreach ($antiviruses as $antivirus) {
  72              $antivirus->scan_file($file, $filename, $deleteinfected);
  73          }
  74      }
  75  
  76      /**
  77       * Returns instance of antivirus.
  78       *
  79       * @param string $antivirusname name of antivirus.
  80       * @return object|bool antivirus instance or false if does not exist.
  81       */
  82      public static function get_antivirus($antivirusname) {
  83          global $CFG;
  84  
  85          $classname = '\\antivirus_' . $antivirusname . '\\scanner';
  86          if (!class_exists($classname)) {
  87              return false;
  88          }
  89          return new $classname();
  90      }
  91  
  92      /**
  93       * Get the list of available antiviruses.
  94       *
  95       * @return array Array ('antivirusname'=>'localised antivirus name').
  96       */
  97      public static function get_available() {
  98          $antiviruses = array();
  99          foreach (\core_component::get_plugin_list('antivirus') as $antivirusname => $dir) {
 100              $antiviruses[$antivirusname] = get_string('pluginname', 'antivirus_'.$antivirusname);
 101          }
 102          return $antiviruses;
 103      }
 104  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1