} elseif ($cfg['maximal_upload_size'] > 0) {
echo t('2_BIG') . ', ' . t('FILE_LIM') . " " . $cfg['maximal_upload_size'] . " MB.";
}
-?>')"/>
+?>'); control_selected_file_extension(<?php
+ echo json_encode(array_map('strtolower', $cfg['disallowed_extensions']));
+?>, '<?php echo t('EXT_NOT_ALLOWED'); ?>.')"/>
</p>
<div id="options">
} else {
echo '<p class="config"></p>';
}
+if (!empty($cfg['disallowed_extensions'])) {
+ echo '<p class="config">' . t('EXT_LIM') . ' ' . implode(', ', $cfg['disallowed_extensions']) . '</p>';
+}
?>
<p id="max_file_size" class="config"></p>
*/
$cfg['maximal_upload_size'] = 0;
+/* Forbid specific file extensions from being uploaded.
+ * Leave empty to allow every extension.
+ * Extensions are matched case-insensitively and without the leading dot.
+ * $cfg['disallowed_extensions'] = array('exe', 'bat', 'sh', 'php');
+ */
+$cfg['disallowed_extensions'] = array();
+
/* Proxy IP
* If the installation is behind some reverse proxies, it is possible to set
* the allowed proxy IP.
}
}
+// UX-only: script.php enforces disallowed_extensions independently, this
+// just warns the user before they submit a doomed upload.
+function control_selected_file_extension(disallowed_extensions, error_str)
+{
+ f_name = document.getElementById('file_select').files[0].name;
+ f_ext = f_name.includes('.') ? f_name.split('.').pop().toLowerCase() : '';
+ if (disallowed_extensions.includes(f_ext))
+ {
+ pop_failure(error_str);
+ document.getElementById('send').style.display = 'none';
+ }
+}
+
function XHRErrorHandler(e)
{
var text = "${e.type}: ${e.loaded} bytes transferred"
return $bytes;
}
+/**
+ * checks if a file name's extension is allowed to be uploaded
+ * @param $cfg jirafeau config
+ * @param $filename the name of the file being uploaded
+ * @returns true if the extension is allowed
+ */
+function jirafeau_is_extension_allowed($cfg, $filename)
+{
+ if (empty($cfg['disallowed_extensions'])) {
+ return true;
+ }
+
+ $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
+ $disallowed = array_map('strtolower', $cfg['disallowed_extensions']);
+
+ return !in_array($extension, $disallowed);
+}
+
/**
* gets the maximum upload size according to php.ini
* @returns the maximum upload size in bytes
"UP_PSW": "Upload password",
"2_BIG": "The file is too big",
"FILE_LIM": "File size limited to",
+ "EXT_NOT_ALLOWED": "This file extension is not allowed",
+ "EXT_LIM": "Disallowed file extensions:",
"FILE_DIR_W": "The file directory is not writable.",
"LINK_DIR_W": "The link directory is not writable.",
"ASYNC_DIR_W": "The async directory is not writable.",
exit;
}
+ // Check file extension
+ if (!jirafeau_is_extension_allowed($cfg, $_FILES['file']['name'])) {
+ echo 'Error 27: This file extension is not allowed.';
+ exit;
+ }
+
// Check if one time download is enabled
if (!$cfg['one_time_download'] && isset($_POST['one_time_download'])) {
echo 'Error 26: One time download is disabled.';
exit;
}
+ // Check file extension
+ if (!jirafeau_is_extension_allowed($cfg, $_POST['filename'])) {
+ echo 'Error 28: This file extension is not allowed.';
+ exit;
+ }
+
$type = '';
if (isset($_POST['type'])) {
$type = $_POST['type'];