3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * uploadlib.php - This class handles all aspects of fileuploading
23 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') ||
die();
30 * This class handles all aspects of fileuploading
33 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class upload_manager
{
39 * Array to hold local copies of stuff in $_FILES
44 * Holds all configuration stuff
49 * Keep track of if we're ok
50 * (errors for each file are kept in $files['whatever']['uploadlog']
51 * @var boolean $status
55 * The course this file has been uploaded for. {@link $COURSE}
56 * (for logging and virus notifications)
61 * If we're only getting one file.
62 * (for logging and virus notifications)
63 * @var string $inputname
67 * If we're given silent=true in the constructor, this gets built
68 * up to hold info about the process.
74 * Constructor, sets up configuration stuff so we know how to act.
76 * Note: destination not taken as parameter as some modules want to use the insertid in the path and we need to check the other stuff first.
79 * @param string $inputname If this is given the upload manager will only process the file in $_FILES with this name.
80 * @param boolean $deleteothers Whether to delete other files in the destination directory (optional, defaults to false)
81 * @param boolean $handlecollisions Whether to use {@link handle_filename_collision()} or not. (optional, defaults to false)
82 * @param course $course The course the files are being uploaded for (for logging and virus notifications) {@link $COURSE}
83 * @param boolean $recoverifmultiple If we come across a virus, or if a file doesn't validate or whatever, do we continue? optional, defaults to true.
84 * @param int $modbytes Max bytes for this module - this and $course->maxbytes are used to get the maxbytes from {@link get_max_upload_file_size()}.
85 * @param boolean $silent Whether to notify errors or not.
86 * @param boolean $allownull Whether we care if there's no file when we've set the input name.
87 * @param boolean $allownullmultiple Whether we care if there's no files AT ALL when we've got multiples. This won't complain if we have file 1 and file 3 but not file 2, only for NO FILES AT ALL.
89 function upload_manager($inputname='', $deleteothers=false, $handlecollisions=false, $course=null, $recoverifmultiple=false, $modbytes=0, $silent=false, $allownull=false, $allownullmultiple=true) {
93 if (empty($course->id
)) {
97 $this->config
->deleteothers
= $deleteothers;
98 $this->config
->handlecollisions
= $handlecollisions;
99 $this->config
->recoverifmultiple
= $recoverifmultiple;
100 $this->config
->maxbytes
= get_max_upload_file_size($CFG->maxbytes
, $course->maxbytes
, $modbytes);
101 $this->config
->silent
= $silent;
102 $this->config
->allownull
= $allownull;
103 $this->files
= array();
104 $this->status
= false;
105 $this->course
= $course;
106 $this->inputname
= $inputname;
107 if (empty($this->inputname
)) {
108 $this->config
->allownull
= $allownullmultiple;
113 * Gets all entries out of $_FILES and stores them locally in $files and then
114 * checks each one against {@link get_max_upload_file_size()} and calls {@link cleanfilename()}
115 * and scans them for viruses etc.
120 function preprocess_files() {
121 global $CFG, $OUTPUT;
123 foreach ($_FILES as $name => $file) {
124 $this->status
= true; // only set it to true here so that we can check if this function has been called.
125 if (empty($this->inputname
) ||
$name == $this->inputname
) { // if we have input name, only process if it matches.
126 $file['originalname'] = $file['name']; // do this first for the log.
127 $this->files
[$name] = $file; // put it in first so we can get uploadlog out in print_upload_log.
128 $this->files
[$name]['uploadlog'] = ''; // initialize error log
129 $this->status
= $this->validate_file($this->files
[$name]); // default to only allowing empty on multiple uploads.
130 if (!$this->status
&& ($this->files
[$name]['error'] == 0 ||
$this->files
[$name]['error'] == 4) && ($this->config
->allownull ||
empty($this->inputname
))) {
131 // this shouldn't cause everything to stop.. modules should be responsible for knowing which if any are compulsory.
134 if ($this->status
&& !empty($CFG->runclamonupload
)) {
135 $this->status
= clam_scan_moodle_file($this->files
[$name],$this->course
);
137 if (!$this->status
) {
138 if (!$this->config
->recoverifmultiple
&& count($this->files
) > 1) {
140 $a->name
= $this->files
[$name]['originalname'];
141 $a->problem
= $this->files
[$name]['uploadlog'];
142 if (!$this->config
->silent
) {
143 echo $OUTPUT->notification(get_string('uploadfailednotrecovering','moodle',$a));
146 $this->notify
.= '<br />'. get_string('uploadfailednotrecovering','moodle',$a);
148 $this->status
= false;
151 } else if (count($this->files
) == 1) {
153 if (!$this->config
->silent
and !$this->config
->allownull
) {
154 echo $OUTPUT->notification($this->files
[$name]['uploadlog']);
156 $this->notify
.= '<br />'. $this->files
[$name]['uploadlog'];
158 $this->status
= false;
163 $newname = clean_filename($this->files
[$name]['name']);
164 if ($newname != $this->files
[$name]['name']) {
166 $a->oldname
= $this->files
[$name]['name'];
167 $a->newname
= $newname;
168 $this->files
[$name]['uploadlog'] .= get_string('uploadrenamedchars','moodle', $a);
170 $this->files
[$name]['name'] = $newname;
171 $this->files
[$name]['clear'] = true; // ok to save.
172 $this->config
->somethingtosave
= true;
176 if (!is_array($_FILES) ||
count($_FILES) == 0) {
177 return $this->config
->allownull
;
179 $this->status
= true;
180 return true; // if we've got this far it means that we're recovering so we want status to be ok.
184 * Validates a single file entry from _FILES
186 * @param object $file The entry from _FILES to validate
187 * @return boolean True if ok.
189 function validate_file(&$file) {
193 if (!is_uploaded_file($file['tmp_name']) ||
$file['size'] == 0) {
194 $file['uploadlog'] .= "\n".$this->get_file_upload_error($file);
197 if ($file['size'] > $this->config
->maxbytes
) {
198 $file['uploadlog'] .= "\n". get_string('uploadedfiletoobig', 'moodle', $this->config
->maxbytes
);
205 * Moves all the files to the destination directory.
209 * @param string $destination The destination directory.
210 * @return boolean status;
212 function save_files($destination) {
213 global $CFG, $USER, $OUTPUT;
215 if (!$this->status
) { // preprocess_files hasn't been run
216 $this->preprocess_files();
219 // if there are no files, bail before we create an empty directory.
220 if (empty($this->config
->somethingtosave
)) {
224 $savedsomething = false;
227 if (!(strpos($destination, $CFG->dataroot
) === false)) {
228 // take it out for giving to make_upload_directory
229 $destination = substr($destination, strlen($CFG->dataroot
)+
1);
232 if ($destination{strlen($destination)-1} == '/') { // strip off a trailing / if we have one
233 $destination = substr($destination, 0, -1);
236 if (!make_upload_directory($destination, true)) { //TODO maybe put this function here instead of moodlelib.php now.
237 $this->status
= false;
241 $destination = $CFG->dataroot
.'/'. $destination; // now add it back in so we have a full path
243 $exceptions = array(); //need this later if we're deleting other files.
245 foreach (array_keys($this->files
) as $i) {
247 if (!$this->files
[$i]['clear']) {
252 if ($this->config
->handlecollisions
) {
253 $this->handle_filename_collision($destination, $this->files
[$i]);
255 if (move_uploaded_file($this->files
[$i]['tmp_name'], $destination.'/'.$this->files
[$i]['name'])) {
256 chmod($destination .'/'. $this->files
[$i]['name'], $CFG->directorypermissions
);
257 $this->files
[$i]['fullpath'] = $destination.'/'.$this->files
[$i]['name'];
258 $this->files
[$i]['uploadlog'] .= "\n".get_string('uploadedfile');
259 $this->files
[$i]['saved'] = true;
260 $exceptions[] = $this->files
[$i]['name'];
261 // now add it to the log (this is important so we know who to notify if a virus is found later on)
262 clam_log_upload($this->files
[$i]['fullpath'], $this->course
);
263 $savedsomething=true;
266 if ($savedsomething && $this->config
->deleteothers
) {
267 $this->delete_other_files($destination, $exceptions);
270 if (empty($savedsomething)) {
271 $this->status
= false;
272 if ((empty($this->config
->allownull
) && !empty($this->inputname
)) ||
(empty($this->inputname
) && empty($this->config
->allownullmultiple
))) {
273 echo $OUTPUT->notification(get_string('uploadnofilefound'));
277 return $this->status
;
281 * Wrapper function that calls {@link preprocess_files()} and {@link viruscheck_files()} and then {@link save_files()}
282 * Modules that require the insert id in the filepath should not use this and call these functions seperately in the required order.
283 * @parameter string $destination Where to save the uploaded files to.
286 function process_file_uploads($destination) {
287 if ($this->preprocess_files()) {
288 return $this->save_files($destination);
294 * Deletes all the files in a given directory except for the files in $exceptions (full paths)
296 * @param string $destination The directory to clean up.
297 * @param array $exceptions Full paths of files to KEEP.
299 function delete_other_files($destination, $exceptions=null) {
301 $deletedsomething = false;
302 if ($filestodel = get_directory_list($destination)) {
303 foreach ($filestodel as $file) {
304 if (!is_array($exceptions) ||
!in_array($file, $exceptions)) {
305 unlink($destination .'/'. $file);
306 $deletedsomething = true;
310 if ($deletedsomething) {
311 if (!$this->config
->silent
) {
312 echo $OUTPUT->notification(get_string('uploadoldfilesdeleted'));
315 $this->notify
.= '<br />'. get_string('uploadoldfilesdeleted');
321 * Handles filename collisions - if the desired filename exists it will rename it according to the pattern in $format
322 * @param string $destination Destination directory (to check existing files against)
323 * @param object $file Passed in by reference. The current file from $files we're processing.
324 * @return void - modifies &$file parameter.
326 function handle_filename_collision($destination, &$file) {
327 if (!file_exists($destination .'/'. $file['name'])) {
331 $parts = explode('.', $file['name']);
332 if (count($parts) > 1) {
333 $extension = '.'.array_pop($parts);
334 $name = implode('.', $parts);
337 $name = $file['name'];
341 if (preg_match('/^(.*)_(\d*)$/s', $name, $matches)) {
343 $current = (int)$matches[2];
347 while (!$this->check_before_renaming($destination, $name.'_'.$i.$extension, $file)) {
351 $a->oldname
= $file['name'];
352 $file['name'] = $name.'_'.$i.$extension;
353 $a->newname
= $file['name'];
354 $file['uploadlog'] .= "\n". get_string('uploadrenamedcollision','moodle', $a);
358 * This function checks a potential filename against what's on the filesystem already and what's been saved already.
359 * @param string $destination Destination directory (to check existing files against)
360 * @param string $nametocheck The filename to be compared.
361 * @param object $file The current file from $files we're processing.
364 function check_before_renaming($destination, $nametocheck, $file) {
365 if (!file_exists($destination .'/'. $nametocheck)) {
368 if ($this->config
->deleteothers
) {
369 foreach ($this->files
as $tocheck) {
370 // if we're deleting files anyway, it's not THIS file and we care about it and it has the same name and has already been saved..
371 if ($file['tmp_name'] != $tocheck['tmp_name'] && $tocheck['clear'] && $nametocheck == $tocheck['name'] && $tocheck['saved']) {
385 * @param object $file Passed in by reference. The current file from $files we're processing.
387 * @todo Finish documenting this function
389 function get_file_upload_error(&$file) {
391 switch ($file['error']) {
392 case 0: // UPLOAD_ERR_OK
393 if ($file['size'] > 0) {
394 $errmessage = get_string('uploadproblem', $file['name']);
396 $errmessage = get_string('uploadnofilefound'); /// probably a dud file name
400 case 1: // UPLOAD_ERR_INI_SIZE
401 $errmessage = get_string('uploadserverlimit');
404 case 2: // UPLOAD_ERR_FORM_SIZE
405 $errmessage = get_string('uploadformlimit');
408 case 3: // UPLOAD_ERR_PARTIAL
409 $errmessage = get_string('uploadpartialfile');
412 case 4: // UPLOAD_ERR_NO_FILE
413 $errmessage = get_string('uploadnofilefound');
416 // Note: there is no error with a value of 5
418 case 6: // UPLOAD_ERR_NO_TMP_DIR
419 $errmessage = get_string('uploadnotempdir');
422 case 7: // UPLOAD_ERR_CANT_WRITE
423 $errmessage = get_string('uploadcantwrite');
426 case 8: // UPLOAD_ERR_EXTENSION
427 $errmessage = get_string('uploadextension');
431 $errmessage = get_string('uploadproblem', $file['name']);
437 * prints a log of everything that happened (of interest) to each file in _FILES
438 * @param $return - optional, defaults to false (log is echoed)
440 function print_upload_log($return=false,$skipemptyifmultiple=false) {
442 foreach (array_keys($this->files
) as $i => $key) {
443 if (count($this->files
) > 1 && !empty($skipemptyifmultiple) && $this->files
[$key]['error'] == 4) {
446 $str .= '<strong>'. get_string('uploadfilelog', 'moodle', $i+
1) .' '
447 .((!empty($this->files
[$key]['originalname'])) ?
'('.$this->files
[$key]['originalname'].')' : '')
448 .'</strong> :'. nl2br($this->files
[$key]['uploadlog']) .'<br />';
457 * If we're only handling one file (if inputname was given in the constructor) this will return the (possibly changed) filename of the file.
460 function get_new_filename() {
461 if (!empty($this->inputname
) and count($this->files
) == 1 and $this->files
[$this->inputname
]['error'] != 4) {
462 return $this->files
[$this->inputname
]['name'];
468 * If we're only handling one file (if input name was given in the constructor) this will return the full path to the saved file.
471 function get_new_filepath() {
472 if (!empty($this->inputname
) and count($this->files
) == 1 and $this->files
[$this->inputname
]['error'] != 4) {
473 return $this->files
[$this->inputname
]['fullpath'];
479 * If we're only handling one file (if inputname was given in the constructor) this will return the ORIGINAL filename of the file.
482 function get_original_filename() {
483 if (!empty($this->inputname
) and count($this->files
) == 1 and $this->files
[$this->inputname
]['error'] != 4) {
484 return $this->files
[$this->inputname
]['originalname'];
490 * This function returns any errors wrapped up in red.
493 function get_errors() {
494 if (!empty($this->notify
)) {
495 return '<p class="notifyproblem">'. $this->notify
.'</p>';
502 /**************************************************************************************
503 THESE FUNCTIONS ARE OUTSIDE THE CLASS BECAUSE THEY NEED TO BE CALLED FROM OTHER PLACES.
504 FOR EXAMPLE CLAM_HANDLE_INFECTED_FILE AND CLAM_REPLACE_INFECTED_FILE USED FROM CRON
505 UPLOAD_PRINT_FORM_FRAGMENT DOESN'T REALLY BELONG IN THE CLASS BUT CERTAINLY IN THIS FILE
506 ***************************************************************************************/
509 * Deals with an infected file - either moves it to a quarantinedir
510 * (specified in CFG->quarantinedir) or deletes it.
512 * If moving it fails, it deletes it.
516 * @param string $file Full path to the file
517 * @param int $userid If not used, defaults to $USER->id (there in case called from cron)
518 * @param boolean $basiconly Admin level reporting or user level reporting.
519 * @return string Details of what the function did.
521 function clam_handle_infected_file($file, $userid=0, $basiconly=false) {
524 if ($USER && !$userid) {
528 if (file_exists($CFG->quarantinedir
) && is_dir($CFG->quarantinedir
) && is_writable($CFG->quarantinedir
)) {
529 $now = date('YmdHis');
530 if (rename($file, $CFG->quarantinedir
.'/'. $now .'-user-'. $userid .'-infected')) {
532 clam_log_infected($file, $CFG->quarantinedir
.'/'. $now .'-user-'. $userid .'-infected', $userid);
534 $notice .= "\n". get_string('clammovedfilebasic');
537 $notice .= "\n". get_string('clammovedfile', 'moodle', $CFG->quarantinedir
.'/'. $now .'-user-'. $userid .'-infected');
542 $notice .= "\n". get_string('clamdeletedfile');
545 $notice .= "\n". get_string('clamquarantinedirfailed', 'moodle', $CFG->quarantinedir
);
551 $notice .= "\n". get_string('clamdeletedfile');
554 $notice .= "\n". get_string('clamquarantinedirfailed', 'moodle', $CFG->quarantinedir
);
559 clam_log_infected($file, '', $userid);
560 $notice .= "\n". get_string('clamdeletedfile');
564 // still tell the user the file has been deleted. this is only for admins.
565 $notice .= "\n". get_string('clamdeletedfile');
568 $notice .= "\n". get_string('clamdeletedfilefailed');
576 * Replaces the given file with a string.
578 * The replacement string is used to notify that the original file had a virus
579 * This is to avoid missing files but could result in the wrong content-type.
581 * @param string $file Full path to the file.
584 function clam_replace_infected_file($file) {
585 $newcontents = get_string('virusplaceholder');
586 if (!$f = fopen($file, 'w')) {
589 if (!fwrite($f, $newcontents)) {
597 * If $CFG->runclamonupload is set, we scan a given file. (called from {@link preprocess_files()})
599 * This function will add on a uploadlog index in $file.
603 * @param mixed $file The file to scan from $files. or an absolute path to a file.
604 * @param course $course {@link $COURSE}
605 * @return int 1 if good, 0 if something goes wrong (opposite from actual error code from clam)
607 function clam_scan_moodle_file(&$file, $course) {
610 if (is_array($file) && is_uploaded_file($file['tmp_name'])) { // it's from $_FILES
612 $fullpath = $file['tmp_name'];
614 else if (file_exists($file)) { // it's a path to somewhere on the filesystem!
618 return false; // erm, what is this supposed to be then, huh?
621 $CFG->pathtoclam
= trim($CFG->pathtoclam
);
623 if (!$CFG->pathtoclam ||
!file_exists($CFG->pathtoclam
) ||
!is_executable($CFG->pathtoclam
)) {
625 $notice = get_string('clamlost', 'moodle', $CFG->pathtoclam
);
626 if ($CFG->clamfailureonupload
== 'actlikevirus') {
627 $notice .= "\n". get_string('clamlostandactinglikevirus');
628 $notice .= "\n". clam_handle_infected_file($fullpath);
631 clam_message_admins($notice);
633 $file['uploadlog'] .= "\n". get_string('clambroken');
636 return $newreturn; // return 1 if we're allowing clam failures
639 $cmd = $CFG->pathtoclam
.' '. $fullpath ." 2>&1";
641 // before we do anything we need to change perms so that clamscan can read the file (clamdscan won't work otherwise)
642 chmod($fullpath, $CFG->directorypermissions
);
644 exec($cmd, $output, $return);
648 case 0: // glee! we're ok.
649 return 1; // translate clam return code into reasonable return code consistent with everything else.
650 case 1: // bad wicked evil, we have a virus.
651 $info = new stdClass();
652 if (!empty($course)) {
653 $info->course
= $course->fullname
;
656 $info->course
= 'No course';
658 $info->user
= fullname($USER);
659 $notice = get_string('virusfound', 'moodle', $info);
660 $notice .= "\n\n". implode("\n", $output);
661 $notice .= "\n\n". clam_handle_infected_file($fullpath);
662 clam_message_admins($notice);
664 $info->filename
= $file['originalname'];
665 $file['uploadlog'] .= "\n". get_string('virusfounduser', 'moodle', $info);
668 return false; // in this case, 0 means bad.
670 // error - clam failed to run or something went wrong
671 $notice .= get_string('clamfailed', 'moodle', get_clam_error_code($return));
672 $notice .= "\n\n". implode("\n", $output);
674 if ($CFG->clamfailureonupload
== 'actlikevirus') {
675 $notice .= "\n". clam_handle_infected_file($fullpath);
678 clam_message_admins($notice);
680 $file['uploadlog'] .= "\n". get_string('clambroken');
683 return $newreturn; // return 1 if we're allowing failures.
688 * Emails admins about a clam outcome
690 * @param string $notice The body of the email to be sent.
692 function clam_message_admins($notice) {
696 $subject = get_string('clamemailsubject', 'moodle', format_string($site->fullname
));
697 $admins = get_admins();
698 foreach ($admins as $admin) {
699 $eventdata = new stdClass();
700 $eventdata->modulename
= 'moodle';
701 $eventdata->userfrom
= get_admin();
702 $eventdata->userto
= $admin;
703 $eventdata->subject
= $subject;
704 $eventdata->fullmessage
= $notice;
705 $eventdata->fullmessageformat
= FORMAT_PLAIN
;
706 $eventdata->fullmessagehtml
= '';
707 $eventdata->smallmessage
= '';
708 message_send($eventdata);
714 * Returns the string equivalent of a numeric clam error code
716 * @param int $returncode The numeric error code in question.
717 * return string The definition of the error code
719 function get_clam_error_code($returncode) {
720 $returncodes = array();
721 $returncodes[0] = 'No virus found.';
722 $returncodes[1] = 'Virus(es) found.';
723 $returncodes[2] = ' An error occured'; // specific to clamdscan
724 // all after here are specific to clamscan
725 $returncodes[40] = 'Unknown option passed.';
726 $returncodes[50] = 'Database initialization error.';
727 $returncodes[52] = 'Not supported file type.';
728 $returncodes[53] = 'Can\'t open directory.';
729 $returncodes[54] = 'Can\'t open file. (ofm)';
730 $returncodes[55] = 'Error reading file. (ofm)';
731 $returncodes[56] = 'Can\'t stat input file / directory.';
732 $returncodes[57] = 'Can\'t get absolute path name of current working directory.';
733 $returncodes[58] = 'I/O error, please check your filesystem.';
734 $returncodes[59] = 'Can\'t get information about current user from /etc/passwd.';
735 $returncodes[60] = 'Can\'t get information about user \'clamav\' (default name) from /etc/passwd.';
736 $returncodes[61] = 'Can\'t fork.';
737 $returncodes[63] = 'Can\'t create temporary files/directories (check permissions).';
738 $returncodes[64] = 'Can\'t write to temporary directory (please specify another one).';
739 $returncodes[70] = 'Can\'t allocate and clear memory (calloc).';
740 $returncodes[71] = 'Can\'t allocate memory (malloc).';
741 if ($returncodes[$returncode])
742 return $returncodes[$returncode];
743 return get_string('clamunknownerror');
748 * Adds a file upload to the log table so that clam can resolve the filename to the user later if necessary
752 * @param string $newfilepath ?
753 * @param course $course {@link $COURSE}
754 * @param boolean $nourl ?
755 * @todo Finish documenting this function
757 function clam_log_upload($newfilepath, $course=null, $nourl=false) {
759 // get rid of any double // that might have appeared
760 $newfilepath = preg_replace('/\/\//', '/', $newfilepath);
761 if (strpos($newfilepath, $CFG->dataroot
) === false) {
762 $newfilepath = $CFG->dataroot
.'/'. $newfilepath;
766 $courseid = $course->id
;
768 add_to_log($courseid, 'upload', 'upload', ((!$nourl) ?
substr($_SERVER['HTTP_REFERER'], 0, 100) : ''), $newfilepath);
772 * This function logs to error_log and to the log table that an infected file has been found and what's happened to it.
775 * @param string $oldfilepath Full path to the infected file before it was moved.
776 * @param string $newfilepath Full path to the infected file since it was moved to the quarantine directory (if the file was deleted, leave empty).
777 * @param int $userid The user id of the user who uploaded the file.
779 function clam_log_infected($oldfilepath='', $newfilepath='', $userid=0) {
782 add_to_log(0, 'upload', 'infected', $_SERVER['HTTP_REFERER'], $oldfilepath, 0, $userid);
784 $user = $DB->get_record('user', array('id'=>$userid));
786 $errorstr = 'Clam AV has found a file that is infected with a virus. It was uploaded by '
787 . ((empty($user)) ?
' an unknown user ' : fullname($user))
788 . ((empty($oldfilepath)) ?
'. The infected file was caught on upload ('.$oldfilepath.')'
789 : '. The original file path of the infected file was '. $oldfilepath)
790 . ((empty($newfilepath)) ?
'. The file has been deleted ' : '. The file has been moved to a quarantine directory and the new path is '. $newfilepath);
792 error_log($errorstr);
797 * Some of the modules allow moving attachments (glossary), in which case we need to hunt down an original log and change the path.
800 * @param string $oldpath The old path to the file (should be in the log)
801 * @param string $newpath The new path to the file
802 * @param boolean $update If true this function will overwrite old record (used for forum moving etc).
804 function clam_change_log($oldpath, $newpath, $update=true) {
807 if (!$record = $DB->get_record('log', array('info'=>$oldpath, 'module'=>'upload'))) {
810 $record->info
= $newpath;
812 $DB->update_record('log', $record);
815 $DB->insert_record('log', $record);