From 9603814743e53016e6e359464535e0fd6ecedfb5 Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Fri, 17 Sep 2004 04:21:41 +0000 Subject: [PATCH] Small bug fixes for upload class. 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-75 2004-09-17 03:19:50 GMT Penny Leach bug fix for upload class related to optional file uploads (like in user/edit.php) arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-76 2004-09-17 03:23:17 GMT Penny Leach bug fix for upload class related to optional file uploads (like in user/edit.php) arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-77 2004-09-17 03:42:10 GMT Penny Leach more fixes for upload class Full logs: Revision: moodle--eduforge--1.3.3--patch-75 Archive: arch-eduforge@catalyst.net.nz--2004 Creator: Penny Leach Date: Fri Sep 17 15:19:50 NZST 2004 Standard-date: 2004-09-17 03:19:50 GMT Modified-files: lib/uploadlib.php user/edit.php New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-75 Summary: bug fix for upload class related to optional file uploads (like in user/edit.php) Keywords: Revision: moodle--eduforge--1.3.3--patch-76 Archive: arch-eduforge@catalyst.net.nz--2004 Creator: Penny Leach Date: Fri Sep 17 15:23:17 NZST 2004 Standard-date: 2004-09-17 03:23:17 GMT Modified-files: lib/uploadlib.php New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-76 Summary: bug fix for upload class related to optional file uploads (like in user/edit.php) Keywords: Revision: moodle--eduforge--1.3.3--patch-77 Archive: arch-eduforge@catalyst.net.nz--2004 Creator: Penny Leach Date: Fri Sep 17 15:42:10 NZST 2004 Standard-date: 2004-09-17 03:42:10 GMT Modified-files: lang/en/moodle.php lib/uploadlib.php New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-77 Summary: more fixes for upload class Keywords: --- lang/en/moodle.php | 2 +- lib/uploadlib.php | 33 ++++++++++++++++++++++++--------- user/edit.php | 2 +- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/lang/en/moodle.php b/lang/en/moodle.php index caa781b22f..53ca2638ef 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -143,7 +143,7 @@ $string['choosereportfilter'] = 'Choose a filter for the report'; $string['choosetheme'] = 'Choose theme'; $string['chooseuser'] = 'Choose a user'; $string['city'] = 'City/town'; -$string['clambroken'] = 'Your administrator has enabled virus checking for file uploads but has misconfigured something.
Your file upload was NOT successful. Your administrator has been emailed to notify them so they can fix it.'; +$string['clambroken'] = 'Your administrator has enabled virus checking for file uploads but has misconfigured something.
Your file upload was NOT successful. Your administrator has been emailed to notify them so they can fix it.
Maybe try uploading this file later.'; $string['clamdeletedfile'] = 'The file has been deleted'; $string['clamdeletedfilefailed'] ='The file could not be deleted'; $string['clamemailsubject'] = '$a :: Clam AV notification'; diff --git a/lib/uploadlib.php b/lib/uploadlib.php index 6463abd9b2..8e99cf699c 100644 --- a/lib/uploadlib.php +++ b/lib/uploadlib.php @@ -22,8 +22,9 @@ class upload_manager { * @param $recoverifmultiple - if we come across a virus, or if a file doesn't validate or whatever, do we continue? optional, defaults to true. * @param $modbytes - max bytes for this module - this and $course->maxbytes are used to get the maxbytes from get_max_upload_file_size(). * @param $silent - whether to notify errors or not. + * @param $allownull - whether we care if there's no file when we've set the input name. */ - function upload_manager($inputname='',$deleteothers=false,$handlecollisions=false,$course=null,$recoverifmultiple=false,$modbytes=0,$silent=false) { + function upload_manager($inputname='',$deleteothers=false,$handlecollisions=false,$course=null,$recoverifmultiple=false,$modbytes=0,$silent=false,$allownull=false) { global $CFG; @@ -32,10 +33,14 @@ class upload_manager { $this->config->recoverifmultiple = $recoverifmultiple; $this->config->maxbytes = get_max_upload_file_size($CFG->maxbytes,$course->maxbytes,$modbytes); $this->config->silent = $silent; + $this->config->allownull = $allownull; $this->files = array(); $this->status = false; $this->course = $course; $this->inputname = $inputname; + if (empty($this->inputname)) { + $this->config->allownull = true; + } } /** @@ -49,8 +54,8 @@ class upload_manager { if (empty($this->inputname) || $name == $this->inputname) { // if we have input name, only process if it matches. $file['originalname'] = $file['name']; // do this first for the log. $this->files[$name] = $file; // put it in first so we can get uploadlog out in print_upload_log. - $this->status = $this->validate_file($this->files[$name],empty($this->inputname)); // default to only allowing empty on multiple uploads. - if (!$this->status && $this->files[$name]['error'] = 0 || $this->files[$name]['error'] == 4 && empty($this->inputname)) { + $this->status = $this->validate_file($this->files[$name]); // default to only allowing empty on multiple uploads. + if (!$this->status && ($this->files[$name]['error'] == 0 || $this->files[$name]['error'] == 4) && $this->config->allownull) { // this shouldn't cause everything to stop.. modules should be responsible for knowing which if any are compulsory. continue; } @@ -94,7 +99,7 @@ class upload_manager { } } if (!is_array($_FILES) || count($_FILES) == 0) { - return false; + return $this->config->allownull; } $this->status = true; return true; // if we've got this far it means that we're recovering so we want status to be ok. @@ -106,15 +111,12 @@ class upload_manager { * @param $allowempty - this is to allow module owners to control which files are compulsory if this function is being called straight from the module. * @return true if ok. */ - function validate_file(&$file,$allowempty=true) { + function validate_file(&$file) { if (empty($file)) { - return $allowempty; // this shouldn't cause everything to stop.. modules should be responsible for knowing which if any are compulsory. + return false; } if (!is_uploaded_file($file['tmp_name']) || $file['size'] == 0) { $file['uploadlog'] .= "\n".$this->get_file_upload_error($file); - if ($file['error'] == 0 || $file['error'] == 4) { - return $allowempty; - } return false; } if ($file['size'] > $this->config->maxbytes) { @@ -346,6 +348,13 @@ class upload_manager { } return false; } + + /** + * This function returns any errors wrapped up in red + */ + function get_errors() { + return '

'.$this->notify.'

'; + } } /************************************************************************************** @@ -490,6 +499,8 @@ function clam_scan_file(&$file,$course) { return false; // erm, what is this supposed to be then, huh? } + $CFG->pathtoclam = trim($CFG->pathtoclam); + if (!$CFG->pathtoclam || !file_exists($CFG->pathtoclam) || !is_executable($CFG->pathtoclam)) { $newreturn = 1; $notice = get_string('clamlost','moodle',$CFG->pathtoclam); @@ -499,6 +510,10 @@ function clam_scan_file(&$file,$course) { $newreturn = false; } clam_mail_admins($notice); + if ($appendlog) { + $file['uploadlog'] .= "\n".get_string('clambroken'); + $file['clam'] = 1; + } return $newreturn; // return 1 if we're allowing clam failures } diff --git a/user/edit.php b/user/edit.php index 5fb92c216f..68f71d284c 100644 --- a/user/edit.php +++ b/user/edit.php @@ -66,7 +66,7 @@ require_once($CFG->dirroot.'/lib/uploadlib.php'); - $um = new upload_manager('imagefile',false,false,null,false,0,true); + $um = new upload_manager('imagefile',false,false,null,false,0,true,true); if (find_form_errors($user, $usernew, $err,$um)) { if (empty($err['imagefile']) && $usernew->picture = save_profile_image($user->id, $um,'users')) { -- 2.39.5