Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   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   * Allows admin to configure antiviruses.
  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  require_once('../config.php');
  26  require_once($CFG->libdir.'/adminlib.php');
  27  require_once($CFG->libdir.'/tablelib.php');
  28  
  29  $action  = required_param('action', PARAM_ALPHANUMEXT);
  30  $antivirus  = required_param('antivirus', PARAM_PLUGIN);
  31  $confirm = optional_param('confirm', 0, PARAM_BOOL);
  32  
  33  $PAGE->set_url('/admin/antiviruses.php', array('action' => $action, 'antivirus' => $antivirus));
  34  $PAGE->set_context(context_system::instance());
  35  
  36  require_admin();
  37  
  38  $returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageantiviruses";
  39  
  40  // Get currently installed and enabled antivirus plugins.
  41  $availableantiviruses = \core\antivirus\manager::get_available();
  42  if (!empty($antivirus) and empty($availableantiviruses[$antivirus])) {
  43      redirect ($returnurl);
  44  }
  45  
  46  $activeantiviruses = explode(',', $CFG->antiviruses);
  47  foreach ($activeantiviruses as $key => $active) {
  48      if (empty($availableantiviruses[$active])) {
  49          unset($activeantiviruses[$key]);
  50      }
  51  }
  52  
  53  if (!confirm_sesskey()) {
  54      redirect($returnurl);
  55  }
  56  
  57  switch ($action) {
  58      case 'disable':
  59          // Remove from enabled list.
  60          $key = array_search($antivirus, $activeantiviruses);
  61          unset($activeantiviruses[$key]);
  62          break;
  63  
  64      case 'enable':
  65          // Add to enabled list.
  66          if (!in_array($antivirus, $activeantiviruses)) {
  67              $activeantiviruses[] = $antivirus;
  68              $activeantiviruses = array_unique($activeantiviruses);
  69          }
  70          break;
  71  
  72      case 'down':
  73          $key = array_search($antivirus, $activeantiviruses);
  74          // Check auth plugin is valid.
  75          if ($key !== false) {
  76              // Move down the list.
  77              if ($key < (count($activeantiviruses) - 1)) {
  78                  $fsave = $activeantiviruses[$key];
  79                  $activeantiviruses[$key] = $activeantiviruses[$key + 1];
  80                  $activeantiviruses[$key + 1] = $fsave;
  81              }
  82          }
  83          break;
  84  
  85      case 'up':
  86          $key = array_search($antivirus, $activeantiviruses);
  87          // Check auth is valid.
  88          if ($key !== false) {
  89              // Move up the list.
  90              if ($key >= 1) {
  91                  $fsave = $activeantiviruses[$key];
  92                  $activeantiviruses[$key] = $activeantiviruses[$key - 1];
  93                  $activeantiviruses[$key - 1] = $fsave;
  94              }
  95          }
  96          break;
  97  
  98      default:
  99          break;
 100  }
 101  $new = implode(',', $activeantiviruses);
 102  add_to_config_log('antiviruses', $CFG->antiviruses, $new, 'core');
 103  set_config('antiviruses', $new);
 104  
 105  core_plugin_manager::reset_caches();
 106  
 107  redirect ($returnurl);