[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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


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