Make one time download optional

This commit is contained in:
Erik Lundin 2020-02-25 22:40:57 +01:00 committed by Jerome Jutteau
parent 6a31336d1a
commit 208418c2e0
4 changed files with 27 additions and 6 deletions

View File

@ -178,10 +178,12 @@ else {
<div id="options">
<table id="option_table">
<tr>
<td><?php echo t('ONE_TIME_DL'); ?>:</td>
<td><input type="checkbox" id="one_time_download" /></td>
</tr>
<?php
if ($cfg['one_time_download']) {
echo '<tr><td>' . t('ONE_TIME_DL') . ':</td>';
echo '<td><input type="checkbox" id="one_time_download" /></td></tr>';
}
?>
<tr>
<td><label for="input_key"><?php echo t('PSW') . ':'; ?></label></td>
<td><input type="password" name="key" id="input_key" /></td>

View File

@ -133,6 +133,11 @@ $cfg['availabilities'] = array(
*/
$cfg['availability_default'] = 'month';
/* Give the uploading user the option to have the file
* deleted after the first download.
*/
$cfg['one_time_download'] = true;
/* Set maximal upload size expressed in MB.
* »0« means unlimited upload size.
*/

View File

@ -558,6 +558,8 @@ function async_upload_end (code)
function upload (max_size)
{
var one_time_checkbox = document.getElementById('one_time_download');
var one_time = one_time_checkbox !== null ? one_time_checkbox.checked : false;
if (check_html5_file_api ()
&& document.getElementById('file_select').files[0].size >= max_size)
{
@ -566,7 +568,7 @@ function upload (max_size)
document.getElementById('file_select').files[0],
document.getElementById('select_time').value,
document.getElementById('input_key').value,
document.getElementById('one_time_download').checked,
one_time,
document.getElementById('upload_password').value
);
}
@ -576,7 +578,7 @@ function upload (max_size)
document.getElementById('file_select').files[0],
document.getElementById('select_time').value,
document.getElementById('input_key').value,
document.getElementById('one_time_download').checked,
one_time,
document.getElementById('upload_password').value
);
}

View File

@ -126,6 +126,12 @@ if (isset($_FILES['file']) && is_writable(VAR_FILES)
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;
}
$res = jirafeau_upload($_FILES['file'],
isset($_POST['one_time_download']),
$key, $time, get_ip_address($cfg),
@ -409,6 +415,12 @@ elseif (isset($_GET['init_async'])) {
$key = $_POST['key'];
}
// 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;
}
$time = time();
if (!isset($_POST['time']) || !$cfg['availabilities'][$_POST['time']]) {
echo 'Error 22';