mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 09:56:38 +02:00

These patches are maintained in an publicly accessible Arch repository, see: http://lists.eduforge.org/cgi-bin/archzoom.cgi/arch-eduforge@catalyst.net.nz--2004-MIRROR/moodle--eduforge--1.3.3 Index of arch patches in this commit: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-82 2004-09-20 00:52:11 GMT Penny Leach <penny@catalyst.net.nz> better attempt to find files in handlevirus.php based on output from clam arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-83 2004-09-20 01:16:22 GMT Penny Leach <penny@catalyst.net.nz> better instructions for handlevirus.php running Full logs: Revision: moodle--eduforge--1.3.3--patch-82 Archive: arch-eduforge@catalyst.net.nz--2004 Creator: Penny Leach <penny@catalyst.net.nz> Date: Mon Sep 20 12:52:11 NZST 2004 Standard-date: 2004-09-20 00:52:11 GMT Modified-files: admin/handlevirus.php New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-82 Summary: better attempt to find files in handlevirus.php based on output from clam Keywords: Revision: moodle--eduforge--1.3.3--patch-83 Archive: arch-eduforge@catalyst.net.nz--2004 Creator: Penny Leach <penny@catalyst.net.nz> Date: Mon Sep 20 13:16:22 NZST 2004 Standard-date: 2004-09-20 01:16:22 GMT Modified-files: admin/handlevirus.php New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-83 Summary: better instructions for handlevirus.php running Keywords:
111 lines
3.2 KiB
PHP
111 lines
3.2 KiB
PHP
<?
|
|
/** This expects the output from a command like
|
|
* clamscan -r --infected --no-summary <files> 2>&1 | php -d error_log=/path/to/log thisfile.php
|
|
* also it's important that the output of clamscan prints the FULL PATH to each infected file, so use absolute paths for area to scan
|
|
* also it should be run as root, or whatever the webserver runs as so that it has the right permissions in the quarantine dir etc.
|
|
* php -d error_log=/path/to/log thisfile.php will override the default error log for php cli, which is stderr, so if you want this script to just print stuff out, use php thisfile.php instead.
|
|
*/
|
|
|
|
|
|
$fd = fopen('php://stdin','r');
|
|
if (!$fd) {
|
|
exit();
|
|
}
|
|
|
|
$FULLME='cron';
|
|
require_once(dirname(dirname(__FILE__)).'/config.php');
|
|
require_once($CFG->dirroot.'/lib/uploadlib.php'); // contains virus handling stuff.
|
|
|
|
$site = get_site();
|
|
|
|
while(!feof($fd)) {
|
|
$entry = fgets($fd);
|
|
if (strlen(trim($entry)) == 0) {
|
|
continue;
|
|
}
|
|
if (!$file = validate_line($entry)) {
|
|
continue;
|
|
}
|
|
$bits = explode('/',$file);
|
|
$a->filename = $bits[count($bits)-1];
|
|
|
|
if (!$log = get_record("log","module","upload","info",$file,"action","upload")) {
|
|
$a->action = clam_handle_infected_file($file,0,false);
|
|
clam_replace_infected_file($file);
|
|
notify_admins_unknown($file,$a);
|
|
continue;
|
|
}
|
|
$action = clam_handle_infected_file($file,$log->userid,true);
|
|
clam_replace_infected_file($file);
|
|
|
|
$user = get_record("user","id",$log->userid);
|
|
$course = get_record("course","id",$log->course);
|
|
$subject = get_string('virusfoundsubject','moodle',$site->fullname);
|
|
$a->date = userdate($log->time);
|
|
|
|
$a->action = $action;
|
|
$a->course = $course->fullname;
|
|
$a->user = $user->firstname.' '.$user->lastname;
|
|
|
|
notify_user($user,$subject,$a);
|
|
notify_admins($user,$subject,$a);
|
|
}
|
|
fclose($fd);
|
|
|
|
|
|
function notify_user($user,$subject,$a) {
|
|
|
|
if (!$user) {
|
|
return false;
|
|
}
|
|
$body = get_string('virusfoundlater','moodle',$a);
|
|
email_to_user($user,get_admin(),$subject,$body);
|
|
}
|
|
|
|
|
|
function notify_admins($user,$subject,$a) {
|
|
|
|
$admins = get_admins();
|
|
|
|
$body = get_string('virusfoundlateradmin','moodle',$a);
|
|
foreach ($admins as $admin) {
|
|
email_to_user($admin,$admin,$subject,$body);
|
|
}
|
|
}
|
|
|
|
function notify_admins_unknown($file,$a) {
|
|
|
|
global $site;
|
|
|
|
$admins = get_admins();
|
|
$subject = get_string('virusfoundsubject','moodle',$site->fullname);
|
|
$body = get_string('virusfoundlateradminnolog','moodle',$a);
|
|
foreach ($admins as $admin) {
|
|
email_to_user($admin,$admin,$subject,$body);
|
|
}
|
|
}
|
|
|
|
function validate_line($line) {
|
|
global $CFG;
|
|
if (strpos($line,"FOUND") === false) {
|
|
return false;
|
|
}
|
|
$index = strpos($line,":");
|
|
$file = substr($line,0,$index);
|
|
$file = preg_replace('/\/\//','/',$file);
|
|
if (!file_exists($file)) {
|
|
// try and prepend dataroot, that might fix it (maybe)
|
|
if ($file{0} == "/") {
|
|
$file = $CFG->dataroot.$file;
|
|
}
|
|
else {
|
|
$file = $CFG->dataroot."/".$file;
|
|
}
|
|
if (!file_exists($file)) {
|
|
return false;
|
|
}
|
|
}
|
|
return $file;
|
|
}
|
|
|
|
?>
|