antiviruses.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. * Allows admin to configure antiviruses.
  18. *
  19. * @package core_antivirus
  20. * @copyright 2015 Ruslan Kabalin, Lancaster University.
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. require_once('../config.php');
  24. require_once($CFG->libdir.'/adminlib.php');
  25. require_once($CFG->libdir.'/tablelib.php');
  26. $action = required_param('action', PARAM_ALPHANUMEXT);
  27. $antivirus = required_param('antivirus', PARAM_PLUGIN);
  28. $confirm = optional_param('confirm', 0, PARAM_BOOL);
  29. $PAGE->set_url('/admin/antiviruses.php', array('action' => $action, 'antivirus' => $antivirus));
  30. $PAGE->set_context(context_system::instance());
  31. require_login();
  32. require_capability('moodle/site:config', context_system::instance());
  33. $returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageantiviruses";
  34. // Get currently installed and enabled antivirus plugins.
  35. $availableantiviruses = \core\antivirus\manager::get_available();
  36. if (!empty($antivirus) and empty($availableantiviruses[$antivirus])) {
  37. redirect ($returnurl);
  38. }
  39. $activeantiviruses = explode(',', $CFG->antiviruses);
  40. foreach ($activeantiviruses as $key => $active) {
  41. if (empty($availableantiviruses[$active])) {
  42. unset($activeantiviruses[$key]);
  43. }
  44. }
  45. if (!confirm_sesskey()) {
  46. redirect($returnurl);
  47. }
  48. switch ($action) {
  49. case 'disable':
  50. // Remove from enabled list.
  51. $key = array_search($antivirus, $activeantiviruses);
  52. unset($activeantiviruses[$key]);
  53. break;
  54. case 'enable':
  55. // Add to enabled list.
  56. if (!in_array($antivirus, $activeantiviruses)) {
  57. $activeantiviruses[] = $antivirus;
  58. $activeantiviruses = array_unique($activeantiviruses);
  59. }
  60. break;
  61. case 'down':
  62. $key = array_search($antivirus, $activeantiviruses);
  63. // Check auth plugin is valid.
  64. if ($key !== false) {
  65. // Move down the list.
  66. if ($key < (count($activeantiviruses) - 1)) {
  67. $fsave = $activeantiviruses[$key];
  68. $activeantiviruses[$key] = $activeantiviruses[$key + 1];
  69. $activeantiviruses[$key + 1] = $fsave;
  70. }
  71. }
  72. break;
  73. case 'up':
  74. $key = array_search($antivirus, $activeantiviruses);
  75. // Check auth is valid.
  76. if ($key !== false) {
  77. // Move up the list.
  78. if ($key >= 1) {
  79. $fsave = $activeantiviruses[$key];
  80. $activeantiviruses[$key] = $activeantiviruses[$key - 1];
  81. $activeantiviruses[$key - 1] = $fsave;
  82. }
  83. }
  84. break;
  85. default:
  86. break;
  87. }
  88. set_config('antiviruses', implode(',', $activeantiviruses));
  89. core_plugin_manager::reset_caches();
  90. redirect ($returnurl);