implemented UPLOAD_CODE variable

If configured, needs a code as POST/GET variable for every upload. Also adds a input field to the main template
This commit is contained in:
Chris
2023-09-06 15:57:15 +02:00
parent cccb80de03
commit 61acb5420b
6 changed files with 43 additions and 27 deletions

View File

@@ -108,8 +108,8 @@ Read [here](/rtfm/CONFIG.md) what those options do
- [x] MASTER_DELETE_IP - [x] MASTER_DELETE_IP
- [x] UPLOAD_FORM_LOCATION - [x] UPLOAD_FORM_LOCATION
- [x] S3 Backend - [x] S3 Backend
- [x] UPLOAD_CODE
- [ ] UPLOAD_QUOTA - [ ] UPLOAD_QUOTA
- [ ] UPLOAD_CODE
- [ ] LOW_PROFILE - [ ] LOW_PROFILE
- [ ] IMAGE_CHANGE_CODE - [ ] IMAGE_CHANGE_CODE
- [ ] MAX_RESIZED_IMAGES - [ ] MAX_RESIZED_IMAGES

View File

@@ -919,4 +919,12 @@ function executeUploadPermission()
http_response_code(403); http_response_code(403);
exit(json_encode(array('status'=>'err','reason'=> 'Access denied'))); exit(json_encode(array('status'=>'err','reason'=> 'Access denied')));
} }
else if(defined('UPLOAD_CODE') && UPLOAD_CODE!='')
{
if(!isset($_REQUEST['uploadcode']) || $_REQUEST['uploadcode']!=UPLOAD_CODE)
{
http_response_code(403);
exit(json_encode(array('status'=>'err','reason'=> 'Incorrect upload code specified - Access denied')));
}
}
} }

View File

@@ -1,34 +1,39 @@
Dropzone.autoDiscover = false; Dropzone.autoDiscover = false;
$(function() { $(function () {
var myDropzone = new Dropzone("#dropzone"); var myDropzone = new Dropzone("#dropzone");
//console.log(myDropzone.options); //console.log(myDropzone.options);
if(maxUploadFileSize !== undefined) if (maxUploadFileSize !== undefined)
myDropzone.options.maxFilesize = maxUploadFileSize; myDropzone.options.maxFilesize = maxUploadFileSize;
myDropzone.options.timeout = 0, myDropzone.options.timeout = 0,
myDropzone.on("success", function(file,response) { myDropzone.on("sending", function(file, xhr, formData) {
console.log("raw response: "+response); formData.append("uploadcode", document.getElementById("uploadcode").value);
if(response==null || response =="null") });
$("#uploadinfo").append("<div class='alert alert-danger' role='alert'><strong>Error uploading "+file.name+"</strong><br/>Reason is unknown :(</div>") myDropzone.on('error', function(file, response) {
else alert("Error: "+response.reason);
{ });
var o = response; myDropzone.on("success", function (file, response) {
if(o.status=='ok') console.log("raw response: " + response);
$("#uploadinfo").append("<div class='alert alert-success' role='alert'><strong>"+file.name+"</strong> uploaded as <a target='_blank' href='/"+o.hash+"'>"+o.hash+"</a><br/>URL: <a target='_blank' href='"+o.url+"'>"+o.url+"</a> <button class='btn btn-xs' onClick='navigator.clipboard.writeText(\""+o.url+"\");'>Copy URL</button></div>") if (response == null || response == "null")
else if(o.status=='err') $("#uploadinfo").append("<div class='alert alert-danger' role='alert'><strong>Error uploading " + file.name + "</strong><br/>Reason is unknown :(</div>")
$("#uploadinfo").append("<div class='alert alert-danger' role='alert'><strong>Error uploading "+file.name+"</strong><br/>Reason: "+o.reason+"</div>") else {
console.log(o) var o = response;
} if (o.status == 'ok')
}); $("#uploadinfo").append("<div class='alert alert-success' role='alert'><strong>" + file.name + "</strong> uploaded as <a target='_blank' href='/" + o.hash + "'>" + o.hash + "</a><br/>URL: <a target='_blank' href='" + o.url + "'>" + o.url + "</a> <button class='btn btn-xs' onClick='navigator.clipboard.writeText(\"" + o.url + "\");'>Copy URL</button></div>")
else if (o.status == 'err')
$("#uploadinfo").append("<div class='alert alert-danger' role='alert'><strong>Error uploading " + file.name + "</strong><br/>Reason: " + o.reason + "</div>")
console.log(o)
}
});
document.onpaste = function(event){ document.onpaste = function (event) {
var items = (event.clipboardData || event.originalEvent.clipboardData).items; var items = (event.clipboardData || event.originalEvent.clipboardData).items;
for (index in items) { for (index in items) {
var item = items[index]; var item = items[index];
if (item.kind === 'file') { if (item.kind === 'file') {
// adds the file to your dropzone instance // adds the file to your dropzone instance
myDropzone.addFile(item.getAsFile()) myDropzone.addFile(item.getAsFile())
} }
} }
} }
}) })

View File

@@ -19,8 +19,8 @@ In this file you can set the following options. For a simple working example con
| UPLOAD_FORM_LOCATION | string | If set, will only show the upload form if this url is requested. eg if you set it to /secret/upload then you only see the form if you go to http://your.pictshare.server/secret/upload but bare in mind that the uploads [via API](/rtfm/API.md) will still work for anyone| | UPLOAD_FORM_LOCATION | string | If set, will only show the upload form if this url is requested. eg if you set it to /secret/upload then you only see the form if you go to http://your.pictshare.server/secret/upload but bare in mind that the uploads [via API](/rtfm/API.md) will still work for anyone|
| ALLOWED_SUBNET | IPv4 or IPv6 CIDR | If set, will limit uploads to IPs that match this CIDR | | ALLOWED_SUBNET | IPv4 or IPv6 CIDR | If set, will limit uploads to IPs that match this CIDR |
| ALWAYS_WEBP | bool | If set to `true`, JPGs will always be served as WebP, if the client supports it (if `image/webp` is in header `HTTP_ACCEPT`) | | ALWAYS_WEBP | bool | If set to `true`, JPGs will always be served as WebP, if the client supports it (if `image/webp` is in header `HTTP_ACCEPT`) |
| UPLOAD_CODE | string | If set, all uploads require this code via GET or POST variable "uploadcode" to succeed |
| UPLOAD_QUOTA (NOT IMPLEMENTED) | int | Size in MB. If set, will only allow uploads if combined size of uploads on Server is smaller than this value. Does not account for ALT_FOLDER data and resized versions of original uploads won't be added to calculation | | UPLOAD_QUOTA (NOT IMPLEMENTED) | int | Size in MB. If set, will only allow uploads if combined size of uploads on Server is smaller than this value. Does not account for ALT_FOLDER data and resized versions of original uploads won't be added to calculation |
| UPLOAD_CODE (NOT IMPLEMENTED | string | If set, all uploads require this code via GET or POST variable "uploadcode" or upload will fail |
| MAX_RESIZED_IMAGES (NOT IMPLEMENTED | string | If set, limits count of resized images/videos per file on server | | MAX_RESIZED_IMAGES (NOT IMPLEMENTED | string | If set, limits count of resized images/videos per file on server |

View File

@@ -54,7 +54,7 @@ Every other variable can be referenced against the [default PictShare configurat
- MASTER_DELETE_IP (string | ip which can delete any image) - MASTER_DELETE_IP (string | ip which can delete any image)
- ALLOWED_SUBNET (CIDR IP range (can be comma separated) | IP subnets which are allowed to upload files) - ALLOWED_SUBNET (CIDR IP range (can be comma separated) | IP subnets which are allowed to upload files)
- ALLOW_BLOATING (true/false | can images be bloated to higher resolutions than the originals) - ALLOW_BLOATING (true/false | can images be bloated to higher resolutions than the originals)
- UPLOAD_CODE (string | code that has to be supplied to upload an image) - UPLOAD_CODE (string | Code that has to be supplied via POST or GET, to upload an image)
- UPLOAD_FORM_LOCATION (string | absolute path where upload gui will be shown) - UPLOAD_FORM_LOCATION (string | absolute path where upload gui will be shown)
- LOW_PROFILE (string | won't display error messages on failed uploads) - LOW_PROFILE (string | won't display error messages on failed uploads)
- IMAGE_CHANGE_CODE (string | code if provided, needs to be added to image to apply filter/rotation/etc) - IMAGE_CHANGE_CODE (string | code if provided, needs to be added to image to apply filter/rotation/etc)

View File

@@ -58,6 +58,9 @@
<?php <?php
echo "Max Upload size: ". (int)(ini_get('upload_max_filesize'))."MB / File<br/>"; echo "Max Upload size: ". (int)(ini_get('upload_max_filesize'))."MB / File<br/>";
echo "Allowed file types: ". implode(', ',getAllContentFiletypes()); echo "Allowed file types: ". implode(', ',getAllContentFiletypes());
if(defined('UPLOAD_CODE') && UPLOAD_CODE!='')
echo '<br>Upload Code: <input type="text" id="uploadcode" />';
?> ?>
</p> </p>
<form class="dropzone well" id="dropzone" method="post" action="/api/upload.php" enctype="multipart/form-data"> <form class="dropzone well" id="dropzone" method="post" action="/api/upload.php" enctype="multipart/form-data">