MDL-50887 antivirus: Fix style issues.
This commit is contained in:
+24
-24
@@ -30,7 +30,7 @@ $action = required_param('action', PARAM_ALPHANUMEXT);
|
||||
$antivirus = required_param('antivirus', PARAM_PLUGIN);
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
$PAGE->set_url('/admin/antiviruses.php', array('action'=>$action, 'antivirus'=>$antivirus));
|
||||
$PAGE->set_url('/admin/antiviruses.php', array('action' => $action, 'antivirus' => $antivirus));
|
||||
$PAGE->set_context(context_system::instance());
|
||||
|
||||
require_login();
|
||||
@@ -39,15 +39,15 @@ require_capability('moodle/site:config', context_system::instance());
|
||||
$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageantiviruses";
|
||||
|
||||
// Get currently installed and enabled antivirus plugins.
|
||||
$available_antiviruses = antiviruses_get_available();
|
||||
if (!empty($antivirus) and empty($available_antiviruses[$antivirus])) {
|
||||
$availableantiviruses = antiviruses_get_available();
|
||||
if (!empty($antivirus) and empty($availableantiviruses[$antivirus])) {
|
||||
redirect ($returnurl);
|
||||
}
|
||||
|
||||
$active_antiviruses = explode(',', $CFG->antiviruses);
|
||||
foreach ($active_antiviruses as $key=>$active) {
|
||||
if (empty($available_antiviruses[$active])) {
|
||||
unset($active_antiviruses[$key]);
|
||||
$activeantiviruses = explode(',', $CFG->antiviruses);
|
||||
foreach ($activeantiviruses as $key => $active) {
|
||||
if (empty($availableantiviruses[$active])) {
|
||||
unset($activeantiviruses[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,40 +58,40 @@ if (!confirm_sesskey()) {
|
||||
switch ($action) {
|
||||
case 'disable':
|
||||
// Remove from enabled list.
|
||||
$key = array_search($antivirus, $active_antiviruses);
|
||||
unset($active_antiviruses[$key]);
|
||||
$key = array_search($antivirus, $activeantiviruses);
|
||||
unset($activeantiviruses[$key]);
|
||||
break;
|
||||
|
||||
case 'enable':
|
||||
// Add to enabled list.
|
||||
if (!in_array($antivirus, $active_antiviruses)) {
|
||||
$active_antiviruses[] = $antivirus;
|
||||
$active_antiviruses = array_unique($active_antiviruses);
|
||||
if (!in_array($antivirus, $activeantiviruses)) {
|
||||
$activeantiviruses[] = $antivirus;
|
||||
$activeantiviruses = array_unique($activeantiviruses);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'down':
|
||||
$key = array_search($antivirus, $active_antiviruses);
|
||||
$key = array_search($antivirus, $activeantiviruses);
|
||||
// Check auth plugin is valid.
|
||||
if ($key !== false) {
|
||||
// move down the list
|
||||
if ($key < (count($active_antiviruses) - 1)) {
|
||||
$fsave = $active_antiviruses[$key];
|
||||
$active_antiviruses[$key] = $active_antiviruses[$key + 1];
|
||||
$active_antiviruses[$key + 1] = $fsave;
|
||||
// Move down the list.
|
||||
if ($key < (count($activeantiviruses) - 1)) {
|
||||
$fsave = $activeantiviruses[$key];
|
||||
$activeantiviruses[$key] = $activeantiviruses[$key + 1];
|
||||
$activeantiviruses[$key + 1] = $fsave;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'up':
|
||||
$key = array_search($antivirus, $active_antiviruses);
|
||||
$key = array_search($antivirus, $activeantiviruses);
|
||||
// Check auth is valid.
|
||||
if ($key !== false) {
|
||||
// move up the list
|
||||
// Move up the list.
|
||||
if ($key >= 1) {
|
||||
$fsave = $active_antiviruses[$key];
|
||||
$active_antiviruses[$key] = $active_antiviruses[$key - 1];
|
||||
$active_antiviruses[$key - 1] = $fsave;
|
||||
$fsave = $activeantiviruses[$key];
|
||||
$activeantiviruses[$key] = $activeantiviruses[$key - 1];
|
||||
$activeantiviruses[$key - 1] = $fsave;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -100,7 +100,7 @@ switch ($action) {
|
||||
break;
|
||||
}
|
||||
|
||||
set_config('antiviruses', implode(',', $active_antiviruses));
|
||||
set_config('antiviruses', implode(',', $activeantiviruses));
|
||||
core_plugin_manager::reset_caches();
|
||||
|
||||
redirect ($returnurl);
|
||||
@@ -138,13 +138,13 @@ if ($hassiteconfig) {
|
||||
$plugin->load_settings($ADMIN, 'editorsettings', $hassiteconfig);
|
||||
}
|
||||
|
||||
/// Antivirus plugins
|
||||
// Antivirus plugins.
|
||||
$ADMIN->add('modules', new admin_category('antivirussettings', new lang_string('antiviruses', 'antivirus')));
|
||||
$temp = new admin_settingpage('manageantiviruses', new lang_string('antivirussettings', 'antivirus'));
|
||||
$temp->add(new admin_setting_manageantiviruses());
|
||||
$ADMIN->add('antivirussettings', $temp);
|
||||
foreach (core_plugin_manager::instance()->get_plugins_of_type('antivirus') as $plugin) {
|
||||
/** @var \core\plugininfo\antivirus $plugin */
|
||||
/* @var \core\plugininfo\antivirus $plugin */
|
||||
$plugin->load_settings($ADMIN, 'antivirussettings', $hassiteconfig);
|
||||
}
|
||||
|
||||
|
||||
+27
-28
@@ -6497,6 +6497,7 @@ class admin_setting_manageeditors extends admin_setting {
|
||||
/**
|
||||
* Special class for antiviruses administration.
|
||||
*
|
||||
* @copyright 2015 Ruslan Kabalin, Lancaster University.
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class admin_setting_manageantiviruses extends admin_setting {
|
||||
@@ -6529,10 +6530,11 @@ class admin_setting_manageantiviruses extends admin_setting {
|
||||
/**
|
||||
* Always returns '', does not write anything
|
||||
*
|
||||
* @param string $data Unused
|
||||
* @return string Always returns ''
|
||||
*/
|
||||
public function write_setting($data) {
|
||||
// do not write any setting
|
||||
// Do not write any setting.
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -6547,8 +6549,8 @@ class admin_setting_manageantiviruses extends admin_setting {
|
||||
return true;
|
||||
}
|
||||
|
||||
$antiviruses_available = antiviruses_get_available();
|
||||
foreach ($antiviruses_available as $antivirus=>$antivirusstr) {
|
||||
$antivirusesavailable = antiviruses_get_available();
|
||||
foreach ($antivirusesavailable as $antivirus => $antivirusstr) {
|
||||
if (strpos($antivirus, $query) !== false) {
|
||||
return true;
|
||||
}
|
||||
@@ -6569,27 +6571,27 @@ class admin_setting_manageantiviruses extends admin_setting {
|
||||
public function output_html($data, $query='') {
|
||||
global $CFG, $OUTPUT;
|
||||
|
||||
// display strings
|
||||
// Display strings.
|
||||
$txt = get_strings(array('administration', 'settings', 'edit', 'name', 'enable', 'disable',
|
||||
'up', 'down', 'none'));
|
||||
$struninstall = get_string('uninstallplugin', 'core_admin');
|
||||
|
||||
$txt->updown = "$txt->up/$txt->down";
|
||||
|
||||
$antiviruses_available = antiviruses_get_available();
|
||||
$active_antiviruses = explode(',', $CFG->antiviruses);
|
||||
$antivirusesavailable = antiviruses_get_available();
|
||||
$activeantiviruses = explode(',', $CFG->antiviruses);
|
||||
|
||||
$active_antiviruses = array_reverse($active_antiviruses);
|
||||
foreach ($active_antiviruses as $key=>$antivirus) {
|
||||
if (empty($antiviruses_available[$antivirus])) {
|
||||
unset($active_antiviruses[$key]);
|
||||
$activeantiviruses = array_reverse($activeantiviruses);
|
||||
foreach ($activeantiviruses as $key => $antivirus) {
|
||||
if (empty($antivirusesavailable[$antivirus])) {
|
||||
unset($activeantiviruses[$key]);
|
||||
} else {
|
||||
$name = $antiviruses_available[$antivirus];
|
||||
unset($antiviruses_available[$antivirus]);
|
||||
$antiviruses_available[$antivirus] = $name;
|
||||
$name = $antivirusesavailable[$antivirus];
|
||||
unset($antivirusesavailable[$antivirus]);
|
||||
$antivirusesavailable[$antivirus] = $name;
|
||||
}
|
||||
}
|
||||
$antiviruses_available = array_reverse($antiviruses_available, true);
|
||||
$antivirusesavailable = array_reverse($antivirusesavailable, true);
|
||||
$return = $OUTPUT->heading(get_string('actantivirushdr', 'antivirus'), 3, 'main', true);
|
||||
$return .= $OUTPUT->box_start('generalbox antivirusesui');
|
||||
|
||||
@@ -6600,20 +6602,19 @@ class admin_setting_manageantiviruses extends admin_setting {
|
||||
$table->attributes['class'] = 'admintable generaltable';
|
||||
$table->data = array();
|
||||
|
||||
// iterate through auth plugins and add to the display table
|
||||
// Iterate through auth plugins and add to the display table.
|
||||
$updowncount = 1;
|
||||
$antiviruscount = count($active_antiviruses);
|
||||
$antiviruscount = count($activeantiviruses);
|
||||
$url = "antiviruses.php?sesskey=" . sesskey();
|
||||
foreach ($antiviruses_available as $antivirus => $name) {
|
||||
// hide/show link
|
||||
foreach ($antivirusesavailable as $antivirus => $name) {
|
||||
// Hide/show link.
|
||||
$class = '';
|
||||
if (in_array($antivirus, $active_antiviruses)) {
|
||||
if (in_array($antivirus, $activeantiviruses)) {
|
||||
$hideshow = "<a href=\"$url&action=disable&antivirus=$antivirus\">";
|
||||
$hideshow .= "<img src=\"" . $OUTPUT->pix_url('t/hide') . "\" class=\"iconsmall\" alt=\"disable\" /></a>";
|
||||
$enabled = true;
|
||||
$displayname = $name;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$hideshow = "<a href=\"$url&action=enable&antivirus=$antivirus\">";
|
||||
$hideshow .= "<img src=\"" . $OUTPUT->pix_url('t/show') . "\" class=\"iconsmall\" alt=\"enable\" /></a>";
|
||||
$enabled = false;
|
||||
@@ -6621,29 +6622,27 @@ class admin_setting_manageantiviruses extends admin_setting {
|
||||
$class = 'dimmed_text';
|
||||
}
|
||||
|
||||
// up/down link (only if auth is enabled)
|
||||
// Up/down link (only if auth is enabled).
|
||||
$updown = '';
|
||||
if ($enabled) {
|
||||
if ($updowncount > 1) {
|
||||
$updown .= "<a href=\"$url&action=up&antivirus=$antivirus\">";
|
||||
$updown .= "<img src=\"" . $OUTPUT->pix_url('t/up') . "\" alt=\"up\" class=\"iconsmall\" /></a> ";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$updown .= "<img src=\"" . $OUTPUT->pix_url('spacer') . "\" class=\"iconsmall\" alt=\"\" /> ";
|
||||
}
|
||||
if ($updowncount < $antiviruscount) {
|
||||
$updown .= "<a href=\"$url&action=down&antivirus=$antivirus\">";
|
||||
$updown .= "<img src=\"" . $OUTPUT->pix_url('t/down') . "\" alt=\"down\" class=\"iconsmall\" /></a>";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$updown .= "<img src=\"" . $OUTPUT->pix_url('spacer') . "\" class=\"iconsmall\" alt=\"\" />";
|
||||
}
|
||||
++ $updowncount;
|
||||
}
|
||||
|
||||
// settings link
|
||||
// Settings link.
|
||||
if (file_exists($CFG->dirroot.'/lib/antivirus/'.$antivirus.'/settings.php')) {
|
||||
$eurl = new moodle_url('/admin/settings.php', array('section'=>'antivirussettings'.$antivirus));
|
||||
$eurl = new moodle_url('/admin/settings.php', array('section' => 'antivirussettings'.$antivirus));
|
||||
$settings = "<a href='$eurl'>{$txt->settings}</a>";
|
||||
} else {
|
||||
$settings = '';
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
/**
|
||||
* ClamAV antivirus plugin upgrade script.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage antivirus_clamav
|
||||
* @package antivirus_clamav
|
||||
* @copyright 2015 Ruslan Kabalin, Lancaster University.
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
/**
|
||||
* Strings for component 'antivirus_clamav', language 'en'.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage antivirus_clamav
|
||||
* @package antivirus_clamav
|
||||
* @copyright 2015 Ruslan Kabalin, Lancaster University.
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
/**
|
||||
* ClamAV antivirus integration.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage antivirus_clamav
|
||||
* @package antivirus_clamav
|
||||
* @copyright 2015 Ruslan Kabalin, Lancaster University.
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -89,9 +88,9 @@ class antivirus_clamav extends antivirus {
|
||||
if ($deleteinfected) {
|
||||
unlink($file);
|
||||
}
|
||||
throw new antivirus_exception('virusfounduser', '', array('filename'=>$filename));
|
||||
throw new antivirus_exception('virusfounduser', '', array('filename' => $filename));
|
||||
} else {
|
||||
//Unknown problem,
|
||||
// Unknown problem.
|
||||
$notice = get_string('clamfailed', 'antivirus_clamav', $this->get_clam_error_code($return));
|
||||
$notice .= "\n\n". implode("\n", $output);
|
||||
$this->message_admins($notice);
|
||||
@@ -99,7 +98,7 @@ class antivirus_clamav extends antivirus {
|
||||
if ($deleteinfected) {
|
||||
unlink($file);
|
||||
}
|
||||
throw new antivirus_exception('virusfounduser', '', array('filename'=>$filename));
|
||||
throw new antivirus_exception('virusfounduser', '', array('filename' => $filename));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
@@ -112,12 +111,12 @@ class antivirus_clamav extends antivirus {
|
||||
* @param int $returncode The numeric error code in question.
|
||||
* @return string The definition of the error code
|
||||
*/
|
||||
function get_clam_error_code($returncode) {
|
||||
private function get_clam_error_code($returncode) {
|
||||
$returncodes = array();
|
||||
$returncodes[0] = 'No virus found.';
|
||||
$returncodes[1] = 'Virus(es) found.';
|
||||
$returncodes[2] = ' An error occured'; // specific to clamdscan
|
||||
// all after here are specific to clamscan
|
||||
$returncodes[2] = ' An error occured'; // Specific to clamdscan.
|
||||
// All after here are specific to clamscan.
|
||||
$returncodes[40] = 'Unknown option passed.';
|
||||
$returncodes[50] = 'Database initialization error.';
|
||||
$returncodes[52] = 'Not supported file type.';
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
/**
|
||||
* ClamAV admin settings.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage antivirus_clamav
|
||||
* @package antivirus_clamav
|
||||
* @copyright 2015 Ruslan Kabalin, Lancaster University.
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -30,7 +29,11 @@ if ($ADMIN->fulltree) {
|
||||
new lang_string('pathtoclam', 'antivirus_clamav'), new lang_string('configpathtoclam', 'antivirus_clamav'), ''));
|
||||
$settings->add(new admin_setting_configdirectory('antivirus_clamav/quarantinedir',
|
||||
new lang_string('quarantinedir', 'antivirus_clamav'), new lang_string('configquarantinedir', 'antivirus_clamav'), ''));
|
||||
$options = array('donothing' => new lang_string('configclamdonothing', 'antivirus_clamav'), 'actlikevirus' => new lang_string('configclamactlikevirus', 'antivirus_clamav'));
|
||||
$options = array(
|
||||
'donothing' => new lang_string('configclamdonothing', 'antivirus_clamav'),
|
||||
'actlikevirus' => new lang_string('configclamactlikevirus', 'antivirus_clamav'),
|
||||
);
|
||||
$settings->add(new admin_setting_configselect('antivirus_clamav/clamfailureonupload',
|
||||
new lang_string('clamfailureonupload', 'antivirus_clamav'), new lang_string('configclamfailureonupload', 'antivirus_clamav'), 'donothing', $options));
|
||||
new lang_string('clamfailureonupload', 'antivirus_clamav'),
|
||||
new lang_string('configclamfailureonupload', 'antivirus_clamav'), 'donothing', $options));
|
||||
}
|
||||
@@ -17,8 +17,7 @@
|
||||
/**
|
||||
* ClamAV antivirus version file.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage antivirus_clamav
|
||||
* @package antivirus_clamav
|
||||
* @copyright 2015 Ruslan Kabalin, Lancaster University.
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -38,7 +37,7 @@ function antiviruses_get_enabled() {
|
||||
return $active;
|
||||
}
|
||||
|
||||
foreach(explode(',', $CFG->antiviruses) as $e) {
|
||||
foreach (explode(',', $CFG->antiviruses) as $e) {
|
||||
if ($antivirus = antiviruses_get_antivirus($e)) {
|
||||
if ($antivirus->is_configured()) {
|
||||
$active[$e] = $antivirus;
|
||||
@@ -184,7 +183,7 @@ class antivirus_exception extends moodle_exception {
|
||||
* @param mixed $a
|
||||
* @param mixed $debuginfo
|
||||
*/
|
||||
public function __construct($errorcode, $link = '', $a=NULL, $debuginfo=null) {
|
||||
public function __construct($errorcode, $link = '', $a = null, $debuginfo = null) {
|
||||
parent::__construct($errorcode, 'antivirus', $link, $a, $debuginfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,10 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Class for Antiviruses
|
||||
*
|
||||
* @package core_antivirus
|
||||
* @copyright 2015 Ruslan Kabalin, Lancaster University.
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class antivirus extends base {
|
||||
/**
|
||||
@@ -51,10 +55,25 @@ class antivirus extends base {
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the node name to use in admin settings menu for this plugin.
|
||||
*
|
||||
* @return string node name
|
||||
*/
|
||||
public function get_settings_section_name() {
|
||||
return 'antivirussettings' . $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads plugin settings to the settings tree
|
||||
*
|
||||
* This function usually includes settings.php file in plugins folder.
|
||||
* Alternatively it can create a link to some settings page (instance of admin_externalpage)
|
||||
*
|
||||
* @param \part_of_admin_tree $adminroot
|
||||
* @param string $parentnodename
|
||||
* @param bool $hassiteconfig whether the current user has moodle/site:config capability
|
||||
*/
|
||||
public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) {
|
||||
global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them.
|
||||
$ADMIN = $adminroot; // May be used in settings.php.
|
||||
@@ -95,7 +114,7 @@ class antivirus extends base {
|
||||
* @return moodle_url
|
||||
*/
|
||||
public static function get_manage_url() {
|
||||
return new moodle_url('/admin/settings.php', array('section'=>'manageantiviruses'));
|
||||
return new moodle_url('/admin/settings.php', array('section' => 'manageantiviruses'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-2
@@ -1185,7 +1185,7 @@ abstract class repository implements cacheable_object {
|
||||
* permissions of the file are not modified here!
|
||||
*
|
||||
* @static
|
||||
* @depricated since Moodle 3.0
|
||||
* @deprecated since Moodle 3.0
|
||||
* @param string $thefile
|
||||
* @param string $filename name of the file
|
||||
* @param bool $deleteinfected
|
||||
@@ -1319,7 +1319,8 @@ abstract class repository implements cacheable_object {
|
||||
global $DB, $CFG, $USER, $OUTPUT;
|
||||
|
||||
// scan for viruses if possible, throws exception if problem found
|
||||
antiviruses_scan_file($thefile, $record->filename, empty($CFG->repository_no_delete)); //TODO: MDL-28637 this repository_no_delete is a bloody hack!
|
||||
// TODO: MDL-28637 this repository_no_delete is a bloody hack!
|
||||
antiviruses_scan_file($thefile, $record->filename, empty($CFG->repository_no_delete));
|
||||
|
||||
$fs = get_file_storage();
|
||||
// If file name being used.
|
||||
|
||||
Reference in New Issue
Block a user