[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 * Base 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 * Base abstract antivirus scanner class. 31 * 32 * @package core 33 * @subpackage antivirus 34 * @copyright 2015 Ruslan Kabalin, Lancaster University. 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 abstract class scanner { 38 /** @var stdClass the config for antivirus */ 39 protected $config; 40 41 /** 42 * Class constructor. 43 * 44 * @return void. 45 */ 46 public function __construct() { 47 // Populate config variable, inheriting class namespace is matching 48 // full plugin name, so we can use it directly to retrieve plugin 49 // configuration. 50 $ref = new \ReflectionClass(get_class($this)); 51 $this->config = get_config($ref->getNamespaceName()); 52 } 53 54 /** 55 * Config get method. 56 * 57 * @param string $property config property to get. 58 * 59 * @return mixed 60 * @throws \coding_exception 61 */ 62 public function get_config($property) { 63 if (property_exists($this->config, $property)) { 64 return $this->config->$property; 65 } 66 throw new \coding_exception('Config property "' . $property . '" doesn\'t exist'); 67 } 68 69 /** 70 * Are the antivirus settings configured? 71 * 72 * @return bool True if plugin has been configured. 73 */ 74 public abstract function is_configured(); 75 76 /** 77 * Scan file, throws exception in case of infected file. 78 * 79 * @param string $file Full path to the file. 80 * @param string $filename Name of the file (could be different from physical file if temp file is used). 81 * @param bool $deleteinfected whether infected file needs to be deleted. 82 * @throws \core\antivirus\scanner_exception If file is infected. 83 * @return void 84 */ 85 public abstract function scan_file($file, $filename, $deleteinfected); 86 87 /** 88 * Email admins about antivirus scan outcomes. 89 * 90 * @param string $notice The body of the email to be sent. 91 * @return void 92 */ 93 public function message_admins($notice) { 94 95 $site = get_site(); 96 97 $subject = get_string('emailsubject', 'antivirus', format_string($site->fullname)); 98 $admins = get_admins(); 99 foreach ($admins as $admin) { 100 $eventdata = new \stdClass(); 101 $eventdata->component = 'moodle'; 102 $eventdata->name = 'errors'; 103 $eventdata->userfrom = get_admin(); 104 $eventdata->userto = $admin; 105 $eventdata->subject = $subject; 106 $eventdata->fullmessage = $notice; 107 $eventdata->fullmessageformat = FORMAT_PLAIN; 108 $eventdata->fullmessagehtml = ''; 109 $eventdata->smallmessage = ''; 110 message_send($eventdata); 111 } 112 } 113 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |