These changes implement some better controls for controlling uploads.
1) There is a new site-wide configuration variable called maxbytes, which provides an upper filesize limit for all (student) uploads. 2) There is a new course-level variable called maxbytes, which further limits uploads within a course. 3) There is a new maxbytes field for forums, which further restricts the size allowed in a particular forum. There is also a new config variable in the module configuration to specify a default size to use when defining a new forum. 4) Assignments already had a limit, but this is now aware of the other limits, and like forums there is now a settable default value. 5) Finally, the sizes of files (Gb, Mb, Kb, bytes) is now translatable in the language packs.
This commit is contained in:
@@ -300,6 +300,18 @@
|
||||
<?php print_string("configteacherassignteachers") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>maxbytes:</td>
|
||||
<td>
|
||||
<?php
|
||||
$options = get_max_upload_sizes();
|
||||
choose_from_menu ($options, "maxbytes", $config->maxbytes, "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configmaxbytes") ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td colspan=3 align=center>
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@
|
||||
$strmanagemodules = get_string("managemodules");
|
||||
$strmodulename = get_string("modulename", $module);
|
||||
|
||||
print_header("$site->shortname: $strconfigvariables", $site->fullname,
|
||||
print_header("$site->shortname: $strmodulename: $strconfiguration", $site->fullname,
|
||||
"<a href=\"index.php\">$stradmin</a> -> ".
|
||||
"<a href=\"configure.php\">$strconfiguration</a> -> ".
|
||||
"<a href=\"modules.php\">$strmanagemodules</a> -> $strmodulename", $focus);
|
||||
|
||||
@@ -127,6 +127,14 @@
|
||||
helpbutton("coursegrades", get_string("grades")); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td><P><?php print_string("maximumupload") ?>:</td>
|
||||
<td><?php
|
||||
$choices = get_max_upload_sizes($CFG->maxbytes);
|
||||
choose_from_menu ($choices, "maxbytes", $form->maxbytes, "");
|
||||
helpbutton("courseuploadsize", get_string("maximumupload")); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td><P><?php print_string("wordforteacher") ?>:</td>
|
||||
<td><input type="text" name="teacher" maxlength="100" size=25 value="<?php p($form->teacher) ?>">
|
||||
|
||||
@@ -52,6 +52,13 @@
|
||||
|
||||
if ($scales = get_records("scale", "courseid", "$course->id", "name ASC")) {
|
||||
print_heading($strcustomscales);
|
||||
|
||||
if (isteacheredit($course->id)) {
|
||||
echo "<p align=\"center\">(";
|
||||
print_string("scalestip");
|
||||
echo ")</p>";
|
||||
}
|
||||
|
||||
foreach ($scales as $scale) {
|
||||
$scalemenu = make_menu_from_list($scale->scale);
|
||||
|
||||
@@ -64,6 +71,13 @@
|
||||
print_simple_box_end();
|
||||
echo "<hr />";
|
||||
}
|
||||
|
||||
} else {
|
||||
if (isteacheredit($course->id)) {
|
||||
echo "<p align=\"center\">(";
|
||||
print_string("scalestip");
|
||||
echo ")</p>";
|
||||
}
|
||||
}
|
||||
|
||||
if ($scales = get_records("scale", "courseid", "0", "name ASC")) {
|
||||
|
||||
@@ -505,6 +505,10 @@ function main_upgrade($oldversion=0) {
|
||||
table_column("course_modules", "", "indent", "integer", "5", "unsigned", "0", "", "score");
|
||||
}
|
||||
|
||||
if ($oldversion < 2003092900) {
|
||||
table_column("course", "", "maxbytes", "integer", "10", "unsigned", "0", "", "marker");
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ CREATE TABLE `prefix_course` (
|
||||
`numsections` smallint(5) unsigned NOT NULL default '1',
|
||||
`showrecent` smallint(5) unsigned NOT NULL default '1',
|
||||
`marker` int(10) unsigned NOT NULL default '0',
|
||||
`maxbytes` int(10) unsigned NOT NULL default '0',
|
||||
`visible` int(10) unsigned NOT NULL default '1',
|
||||
`timecreated` int(10) unsigned NOT NULL default '0',
|
||||
`timemodified` int(10) unsigned NOT NULL default '0',
|
||||
|
||||
@@ -254,6 +254,9 @@ function main_upgrade($oldversion=0) {
|
||||
table_column("course_modules", "", "indent", "integer", "5", "unsigned", "0", "", "score");
|
||||
}
|
||||
|
||||
if ($oldversion < 2003092900) {
|
||||
table_column("course", "", "maxbytes", "integer", "10", "unsigned", "0", "", "marker");
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ CREATE TABLE prefix_course (
|
||||
numsections integer NOT NULL default '1',
|
||||
showrecent integer NOT NULL default '1',
|
||||
marker integer NOT NULL default '0',
|
||||
maxbytes integer NOT NULL default '0',
|
||||
visible integer NOT NULL default '1',
|
||||
timecreated integer NOT NULL default '0',
|
||||
timemodified integer NOT NULL default '0'
|
||||
|
||||
+68
-6
@@ -1059,12 +1059,64 @@ function valid_uploaded_file($newfile) {
|
||||
}
|
||||
}
|
||||
|
||||
function get_max_upload_file_size() {
|
||||
function get_max_upload_file_size($sitebytes=0, $coursebytes=0, $modulebytes=0) {
|
||||
/// Returns the maximum size for uploading files
|
||||
/// There are six possible upload limits:
|
||||
///
|
||||
/// 1) in Apache using LimitRequestBody (no way of checking or changing this)
|
||||
/// 2) in php.ini for 'upload_max_filesize' (can not be changed inside PHP)
|
||||
/// 3) in .htaccess for 'upload_max_filesize' (can not be changed inside PHP)
|
||||
/// 4) by the Moodle admin in $CFG->maxbytes
|
||||
/// 5) by the teacher in the current course $course->maxbytes
|
||||
/// 6) by the teacher for the current module, eg $assignment->maxbytes
|
||||
///
|
||||
/// These last two are passed to this function as arguments (in bytes).
|
||||
/// Anything defined as 0 is ignored.
|
||||
/// The smallest of all the non-zero numbers is returned.
|
||||
|
||||
if (! $filesize = ini_get("upload_max_filesize")) {
|
||||
$filesize = "5M";
|
||||
}
|
||||
return get_real_size($filesize);
|
||||
$minimumsize = get_real_size($filesize);
|
||||
|
||||
if ($sitebytes and $sitebytes < $minimumsize) {
|
||||
$minimumsize = $sitebytes;
|
||||
}
|
||||
|
||||
if ($coursebytes and $coursebytes < $minimumsize) {
|
||||
$minimumsize = $coursebytes;
|
||||
}
|
||||
|
||||
if ($modulebytes and $modulebytes < $minimumsize) {
|
||||
$minimumsize = $modulebytes;
|
||||
}
|
||||
|
||||
return $minimumsize;
|
||||
}
|
||||
|
||||
function get_max_upload_sizes($sitebytes=0, $coursebytes=0, $modulebytes=0) {
|
||||
/// Related to the above function - this function returns an
|
||||
/// array of possible sizes in an array, translated to the
|
||||
/// local language.
|
||||
|
||||
if (!$maxsize = get_max_upload_file_size($sitebytes, $coursebytes, $modulebytes)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$filesize[$maxsize] = display_size($maxsize);
|
||||
|
||||
$sizelist = array(10240, 51200, 102400, 512000, 1048576, 2097152,
|
||||
5242880, 10485760, 20971520, 52428800, 104857600);
|
||||
|
||||
foreach ($sizelist as $sizebytes) {
|
||||
if ($sizebytes < $maxsize) {
|
||||
$filesize[$sizebytes] = display_size($sizebytes);
|
||||
}
|
||||
}
|
||||
|
||||
krsort($filesize, SORT_NUMERIC);
|
||||
|
||||
return $filesize;
|
||||
}
|
||||
|
||||
function get_directory_list($rootdir, $excludefile="", $descend=true) {
|
||||
@@ -1127,14 +1179,24 @@ function get_real_size($size=0) {
|
||||
|
||||
function display_size($size) {
|
||||
/// Converts bytes into display form
|
||||
|
||||
static $gb,$mb,$kb,$b;
|
||||
|
||||
if (empty($gb)) {
|
||||
$gb = get_string('sizegb');
|
||||
$mb = get_string('sizemb');
|
||||
$kb = get_string('sizekb');
|
||||
$b = get_string('sizeb');
|
||||
}
|
||||
|
||||
if ($size >= 1073741824) {
|
||||
$size = round($size / 1073741824 * 10) / 10 . "Gb";
|
||||
$size = round($size / 1073741824 * 10) / 10 . $gb;
|
||||
} else if ($size >= 1048576) {
|
||||
$size = round($size / 1048576 * 10) / 10 . "Mb";
|
||||
$size = round($size / 1048576 * 10) / 10 . $mb;
|
||||
} else if ($size >= 1024) {
|
||||
$size = round($size / 1024 * 10) / 10 . "Kb";
|
||||
$size = round($size / 1024 * 10) / 10 . $kb;
|
||||
} else {
|
||||
$size = $size . "b";
|
||||
$size = $size ." $b";
|
||||
}
|
||||
return $size;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<form method="post" action="module.php" name="form">
|
||||
|
||||
<table cellpadding=9 cellspacing=0 >
|
||||
<tr valign=top>
|
||||
<td align=right><p>assignment_maxbytes:</td>
|
||||
<td><?php
|
||||
$choices = get_max_upload_sizes($CFG->maxbytes);
|
||||
choose_from_menu ($choices, "assignment_maxbytes", $CFG->assignment_maxbytes, "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configmaxbytes", "assignment") ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td colspan=3 align=center>
|
||||
<input type="submit" value="<?php print_string("savechanges") ?>"></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</form>
|
||||
@@ -8,6 +8,10 @@ define("UPLOADSINGLE", "1");
|
||||
$ASSIGNMENT_TYPE = array (OFFLINE => get_string("typeoffline", "assignment"),
|
||||
UPLOADSINGLE => get_string("typeuploadsingle", "assignment") );
|
||||
|
||||
if (!isset($CFG->assignment_maxbytes)) {
|
||||
set_config("assignment_maxbytes", 1024000); // Default maximum size for all assignments
|
||||
}
|
||||
|
||||
|
||||
function assignment_add_instance($assignment) {
|
||||
// Given an object containing all the necessary data,
|
||||
|
||||
+6
-23
@@ -25,7 +25,7 @@
|
||||
$form->grade = 100;
|
||||
}
|
||||
if (empty($form->maxbytes)) {
|
||||
$form->maxbytes = "";
|
||||
$form->maxbytes = $CFG->assignment_maxbytes;
|
||||
}
|
||||
if (empty($form->timedue)) {
|
||||
$form->timedue = "";
|
||||
@@ -104,28 +104,11 @@
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p><b><?php print_string("maximumsize", "assignment") ?>:</b></p></td>
|
||||
<td>
|
||||
<?php
|
||||
$sizelist = array("10Kb", "50Kb", "100Kb", "500Kb", "1Mb", "2Mb", "5Mb", "10Mb", "20Mb", "50Mb");
|
||||
$maxsize = get_max_upload_file_size();
|
||||
$sizeinlist = false;
|
||||
foreach ($sizelist as $size) {
|
||||
$sizebytes = get_real_size($size);
|
||||
if ($sizebytes < $maxsize) {
|
||||
$filesize[$sizebytes] = $size;
|
||||
}
|
||||
if ($form->maxbytes == $sizebytes) {
|
||||
$sizeinlist = true;
|
||||
}
|
||||
}
|
||||
$filesize[$maxsize] = display_size($maxsize);
|
||||
if (!$sizeinlist) {
|
||||
$form->maxbytes = get_real_size("500K");
|
||||
}
|
||||
ksort($filesize, SORT_NUMERIC);
|
||||
choose_from_menu($filesize, "maxbytes", "$form->maxbytes", "");
|
||||
?>
|
||||
</td>
|
||||
<td><?php
|
||||
$choices = get_max_upload_sizes($CFG->maxbytes, $course->maxbytes);
|
||||
choose_from_menu ($choices, "maxbytes", $form->maxbytes, "");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p><b><?php print_string("duedate", "assignment") ?>:</b></td>
|
||||
|
||||
@@ -37,6 +37,18 @@
|
||||
<?php print_string("configmanydiscussions", "forum") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>forum_maxbytes:</td>
|
||||
<td><?php
|
||||
$choices = get_max_upload_sizes($CFG->maxbytes);
|
||||
choose_from_menu ($choices, "forum_maxbytes", $CFG->forum_maxbytes, "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configmaxbytes", "forum") ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td colspan=3 align=center>
|
||||
<input type="submit" value="<?php print_string("savechanges") ?>"></td>
|
||||
|
||||
@@ -75,6 +75,10 @@ function forum_upgrade($oldversion) {
|
||||
table_column("forum", "scale", "scale", "integer", "10", "", "0");
|
||||
execute_sql("UPDATE {$CFG->prefix}forum SET scale = (- scale)");
|
||||
}
|
||||
|
||||
if ($oldversion < 2003100600) {
|
||||
table_column("forum", "", "maxbytes", "integer", "10", "unsigned", "0", "", "scale");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ CREATE TABLE prefix_forum (
|
||||
assesstimestart int(10) unsigned NOT NULL default '0',
|
||||
assesstimefinish int(10) unsigned NOT NULL default '0',
|
||||
scale int(10) NOT NULL default '0',
|
||||
maxbytes int(10) unsigned NOT NULL default '0',
|
||||
forcesubscribe tinyint(1) unsigned NOT NULL default '0',
|
||||
timemodified int(10) unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (id),
|
||||
|
||||
@@ -14,6 +14,7 @@ CREATE TABLE prefix_forum (
|
||||
open number(2) default '2' not null,
|
||||
assessed number(10) default '0' NOT NULL,
|
||||
scale number(10) default '0' NOT NULL,
|
||||
maxbytes number(10) default '0' NOT NULL,
|
||||
forcesubscribe number(1) default '0' NOT NULL,
|
||||
timemodified number(10) default '0' NOT NULL
|
||||
);
|
||||
|
||||
@@ -19,6 +19,10 @@ function forum_upgrade($oldversion) {
|
||||
execute_sql("UPDATE {$CFG->prefix}forum SET scale = (- scale)");
|
||||
}
|
||||
|
||||
if ($oldversion < 2003100600) {
|
||||
table_column("forum", "", "maxbytes", "integer", "10", "unsigned", "0", "", "scale");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ CREATE TABLE prefix_forum (
|
||||
assesstimestart integer NOT NULL default '0',
|
||||
assesstimefinish integer NOT NULL default '0',
|
||||
scale integer NOT NULL default '0',
|
||||
maxbytes integer NOT NULL default '0',
|
||||
forcesubscribe integer NOT NULL default '0',
|
||||
timemodified integer NOT NULL default '0'
|
||||
);
|
||||
|
||||
@@ -39,6 +39,11 @@ if (!isset($CFG->forum_manydiscussions)) {
|
||||
set_config("forum_manydiscussions", 100); // Number of discussions on a page
|
||||
}
|
||||
|
||||
if (!isset($CFG->forum_maxbytes)) {
|
||||
set_config("forum_maxbytes", 512000); // Default maximum size for all forums
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// STANDARD FUNCTIONS ///////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1608,9 +1613,22 @@ function forum_add_attachment($post, $newfile) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (!$forum = get_record("forum", "id", $post->forum)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (!$course = get_record("course", "id", $forum->course)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
$maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $forum->maxbytes);
|
||||
|
||||
$newfile_name = clean_filename($newfile['name']);
|
||||
|
||||
if (valid_uploaded_file($newfile)) {
|
||||
if ($maxbytes and $newfile['size'] > $maxbytes) {
|
||||
return "";
|
||||
}
|
||||
if (! $newfile_name) {
|
||||
notify("This file had a wierd filename and couldn't be uploaded");
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
if (!isset($form->forcesubscribe)) {
|
||||
$form->forcesubscribe = "";
|
||||
}
|
||||
if (!isset($form->maxbytes)) {
|
||||
$form->maxbytes = $CFG->forum_maxbytes;
|
||||
}
|
||||
?>
|
||||
<form name="form" method="post" <?php echo $onsubmit ?> action="mod.php">
|
||||
<table cellpadding=5>
|
||||
@@ -91,6 +94,17 @@
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p><b><?php print_string("maxattachmentsize", "forum") ?>:</b></p></td>
|
||||
<td>
|
||||
<?php
|
||||
$choices = get_max_upload_sizes($CFG->maxbytes, $course->maxbytes);
|
||||
$choices[0] = get_string("courseuploadlimit") . " (".display_size($course->maxbytes).")";
|
||||
choose_from_menu ($choices, "maxbytes", $form->maxbytes, "");
|
||||
helpbutton("maxattachmentsize", get_string("maxattachmentsize", "forum"), "forum");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td align=right valign=top><p><b><?php print_string("allowratings", "forum") ?>:</b></p></td>
|
||||
|
||||
+3
-2
@@ -86,11 +86,12 @@
|
||||
<tr valign=top>
|
||||
<td align=right><p><b><?php print_string("attachment", "forum") ?>:<br \>(<?php print_string("optional") ?>) </b></p></td>
|
||||
<td>
|
||||
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo get_max_upload_file_size() ?>">
|
||||
<?php $maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $forum->maxbytes); ?>
|
||||
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $maxbytes ?>">
|
||||
<input type="file" name="attachment" size=40>
|
||||
<?php
|
||||
helpbutton("attachment", get_string("attachment", "forum"), "forum");
|
||||
print_string("maxsize", "", display_size(get_max_upload_file_size()));
|
||||
print_string("maxsize", "", display_size($maxbytes));
|
||||
?>
|
||||
</td>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// This fragment is called by /admin/index.php
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$module->version = 2003082502;
|
||||
$module->version = 2003100600;
|
||||
$module->cron = 60;
|
||||
|
||||
?>
|
||||
|
||||
+6
-3
@@ -175,14 +175,17 @@ if (isadmin()) {
|
||||
</tr>
|
||||
|
||||
|
||||
<?php if (!empty($CFG->gdversion)) { ?>
|
||||
<?php
|
||||
$maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes);
|
||||
if (!empty($CFG->gdversion) and $maxbytes) {
|
||||
?>
|
||||
<tr valign=top>
|
||||
<td><p><?php print_string("newpicture") ?>:</td>
|
||||
<td>
|
||||
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo get_max_upload_file_size() ?>">
|
||||
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $maxbytes ?>">
|
||||
<input type="file" name="imagefile" size=40>
|
||||
<?php helpbutton("picture", get_string("helppicture"));
|
||||
print_string("maxsize", "", display_size(get_max_upload_file_size()));
|
||||
print_string("maxsize", "", display_size($maxbytes));
|
||||
if (isset($err["imagefile"])) formerr($err["imagefile"]);
|
||||
?>
|
||||
</td>
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
// database to determine whether upgrades should
|
||||
// be performed (see lib/db/*.php)
|
||||
|
||||
$version = 2003091800; // The current version is a date (YYYYMMDDXX)
|
||||
$version = 2003092900; // The current version is a date (YYYYMMDDXX)
|
||||
|
||||
$release = "1.2 development"; // User-friendly version number
|
||||
|
||||
|
||||
Reference in New Issue
Block a user