From: Luis Henrique Mulinari <onlyirc@gmail.com>
Date: Mon, 23 Nov 2009 19:28:55 +0000 (-0200)
Subject: Limite de tamanho para arquivos de backup agora pode ser definido
X-Git-Url: http://dyck-devel.tns.ufsc.br/git?p=MOODLE%2Fsource%2Fluis.git;a=commitdiff_plain;h=56d6d20ea683b3a941fe92ff0612d37a5ca2537a

Limite de tamanho para arquivos de backup agora pode ser definido
---

diff --git a/admin/settings/security.php b/admin/settings/security.php
index 2e9ac4a..8b0b260 100644
--- a/admin/settings/security.php
+++ b/admin/settings/security.php
@@ -14,6 +14,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
     // maxbytes set to 0 will allow the maxium server lmit for uploads
     $max_upload_choices[0] = get_string('serverlimit', 'admin');
     $temp->add(new admin_setting_configselect('maxbytes', get_string('maxbytes', 'admin'), get_string('configmaxbytes', 'admin'), 0, $max_upload_choices));
+    $temp->add(new admin_setting_configselect('maxbytes_backup', get_string('maxbytes_backup', 'admin'), get_string('configmaxbytes_backup', 'admin'), 0, $max_upload_choices));
 
     $temp->add(new admin_setting_configcheckbox('messaging', get_string('messaging', 'admin'), get_string('configmessaging','admin'), 1));
     $temp->add(new admin_setting_configcheckbox('allowobjectembed', get_string('allowobjectembed', 'admin'), get_string('configallowobjectembed', 'admin'), 0));
diff --git a/files/index.php b/files/index.php
index cca48cb..0c8161c 100644
--- a/files/index.php
+++ b/files/index.php
@@ -202,14 +202,21 @@
                 displaydir($wdir);
             } else {
                 $upload_max_filesize = get_max_upload_file_size($CFG->maxbytes);
+                $upload_max_backup_filesize = get_max_upload_file_size($CFG->maxbytes_backup);
                 $filesize = display_size($upload_max_filesize);
+                $backupfilesize = display_size($upload_max_backup_filesize);
 
                 $struploadafile = get_string("uploadafile");
                 $struploadthisfile = get_string("uploadthisfile");
                 $strmaxsize = get_string("maxsize", "", $filesize);
+                $strmaxbackupsize = get_string("maxbackupsize", "", $backupfilesize);
                 $strcancel = get_string("cancel");
 
-                echo "<p>$struploadafile ($strmaxsize) --> <b>$wdir</b></p>";
+                if (has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
+                    echo "<p>{$struploadafile} ({$strmaxsize}, {$strmaxbackupsize}) --> <b>{$wdir}</b></p>";
+                } else {
+                    echo "<p>{$struploadafile} ({$strmaxsize}) --> <b>{$wdir}</b></p>";
+                }
                 echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"index.php\">";
                 echo "<div>";
                 echo "<table><tr><td colspan=\"2\">";
diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php
index d48fc65..ba0bfa5 100644
--- a/lang/en_utf8/admin.php
+++ b/lang/en_utf8/admin.php
@@ -166,6 +166,7 @@ $string['configlongtimenosee'] = 'If students haven\'t logged in for a very long
 $string['configlookahead'] = 'Days to look ahead';
 $string['configmailnewline'] = 'Newline characters used in mail messages. CRLF is required according to RFC 822bis, some mail servers do automatic conversion from LF to CRLF, other mail servers do incorrect conversion from CRLF to CRCRLF, yet others reject mails with bare LF (qmail for example). Try changing this setting if you are having problems with undelivered emails or double newlines.';
 $string['configmaxbytes'] = 'This specifies a maximum size that uploaded files can be throughout the whole site. This setting is limited by the PHP settings post_max_size and upload_max_filesize, as well as the Apache setting LimitRequestBody. In turn, maxbytes limits the range of sizes that can be chosen at course level or module level. If \'Server Limit\' is chosen, the server maximum allowed by the server will be used.';
+$string['configmaxbytes_backup'] = 'This specifies a maximum size that uploaded backup files can be throughout the whole site. This setting is limited by the PHP settings post_max_size and upload_max_filesize, as well as the Apache setting LimitRequestBody.';
 $string['configsitemaxcategorydepth'] = 'Maximum Category Depth';
 $string['configsitemaxcategorydepthhelp'] = 'This specifies the maximum depth of child categories shown';
 $string['configmaxeditingtime'] = 'This specifies the amount of time people have to re-edit forum postings, glossary comments etc.  Usually 30 minutes is a good value.';
@@ -493,6 +494,7 @@ $string['maintfileopenerror'] = 'Error opening maintenance files!';
 $string['maintinprogress'] = 'Maintenance is in progress...';
 $string['managelang'] = 'Manage';
 $string['maxbytes'] = 'Maximum uploaded file size';
+$string['maxbytes_backup'] = 'Maximum uploaded backup file size';
 $string['maxeditingtime'] = 'Maximum time to edit posts';
 $string['mbstringrecommended'] = 'Installing the optional MBSTRING library is highly recommended in order to improve site performance, particularly if your site is supporting non-Latin languages.';
 $string['mediapluginavi'] = 'Enable .avi filter';
diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php
index 113c795..9ccd848 100644
--- a/lang/en_utf8/moodle.php
+++ b/lang/en_utf8/moodle.php
@@ -935,6 +935,7 @@ $string['maximumgrade'] = 'Maximum grade';
 $string['maximumshort'] = 'Max';
 $string['maximumupload'] = 'Maximum upload size';
 $string['maxsize'] = 'Max size: $a';
+$string['maxbackupsize'] = 'Max backup size: $a';
 $string['memberincourse'] = 'People in the course';
 $string['messagebody'] = 'Message body';
 $string['messagedselectedusers'] = 'Selected users have been messaged and the recipient list has been reset.';
@@ -1576,6 +1577,7 @@ $string['uploadcantwrite'] = 'Failed to write file to disk';
 $string['uploadedfile'] = 'File uploaded successfully';
 $string['uploadedfileto'] = 'Uploaded $a->file to $a->directory';
 $string['uploadedfiletoobig'] = 'Sorry, but that file is too big (limit is $a bytes)';
+$string['uploadedbackupfiletoobig'] = 'Sorry, but that backup file is too big (limit is $a bytes)';
 $string['uploadextension'] = 'File upload stopped by extension';
 $string['uploadfailednotrecovering'] = 'Your file upload has failed because there was a problem with one of the files, $a->name.<br /> Here is a log of the problems:<br />$a->problem<br />Not recovering.';
 $string['uploadfilelog'] = 'Upload log for file $a';
diff --git a/lib/uploadlib.php b/lib/uploadlib.php
index 9d1a001..1270769 100644
--- a/lib/uploadlib.php
+++ b/lib/uploadlib.php
@@ -9,6 +9,8 @@
  * @package moodlecore
  */
 
+include_once("$CFG->libdir/pclzip/pclzip.lib.php");
+
 //error_reporting(E_ALL ^ E_NOTICE);
 /**
  * This class handles all aspects of fileuploading
@@ -78,6 +80,7 @@ class upload_manager {
         $this->config->handlecollisions = $handlecollisions;
         $this->config->recoverifmultiple = $recoverifmultiple;
         $this->config->maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $modbytes);
+        $this->config->maxbytes_backup = get_max_upload_file_size($CFG->maxbytes_backup);
         $this->config->silent = $silent;
         $this->config->allownull = $allownull;
         $this->files = array();
@@ -172,13 +175,35 @@ class upload_manager {
             $file['uploadlog'] .= "\n".$this->get_file_upload_error($file);
             return false;
         }
-        if ($file['size'] > $this->config->maxbytes) {
-            $file['uploadlog'] .= "\n". get_string('uploadedfiletoobig', 'moodle', $this->config->maxbytes);
-            return false;
+        if ($this->is_backup_file($file)) {
+            if ($file['size'] > $this->config->maxbytes_backup) {
+                $file['uploadlog'] .= "\n". get_string('uploadedbackupfiletoobig', 'moodle', $this->config->maxbytes_backup);
+                return false;
+            }
+        } else {
+            if ($file['size'] > $this->config->maxbytes) {
+                $file['uploadlog'] .= "\n". get_string('uploadedfiletoobig', 'moodle', $this->config->maxbytes);
+                return false;
+            }
         }
         return true;
     }
 
+    function is_backup_file($file) {
+        if (mimeinfo('type', $file['name'])) {
+            $archive = new PclZip(cleardoubleslashes($file['tmp_name']));
+            $list = $archive->listContent();
+            foreach ($list as $l) {
+                if ($l['filename'] == 'moodle.xml') {
+                    return true;
+                }
+            }
+            return false;
+        } else {
+            return false;
+        }
+    }
+
     /** 
      * Moves all the files to the destination directory.
      *
@@ -498,8 +523,7 @@ UPLOAD_PRINT_FORM_FRAGMENT DOESN'T REALLY BELONG IN THE CLASS BUT CERTAINLY IN T
  */ 
 function upload_print_form_fragment($numfiles=1, $names=null, $descriptions=null, $uselabels=false, $labelnames=null, $coursebytes=0, $modbytes=0, $return=false) {
     global $CFG;
-    $maxbytes = get_max_upload_file_size($CFG->maxbytes, $coursebytes, $modbytes);
-    $str = '<input type="hidden" name="MAX_FILE_SIZE" value="'. $maxbytes .'" />'."\n";
+
     for ($i = 0; $i < $numfiles; $i++) {
         if (is_array($descriptions) && !empty($descriptions[$i])) {
             $str .= '<strong>'. $descriptions[$i] .'</strong><br />';
