Skip to content

Commit 8034a2f

Browse files
committed
added integrated upload form, can be disabled with DISABLE_UPLOADFORM setting or env in Docker
1 parent 0425d6f commit 8034a2f

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

config/example.config.inc.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// copy this file to config.inc.php
44
// and edit to your needs
55

6+
// site settings
7+
define('DISABLE_UPLOADFORM',false); // set to true to disable the upload form and only allow uploads via API
68

79
// AGE encryption settings
810
// More info on age encryption: https://github.com/FiloSottile/age

docker/rootfs/start.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ nginx
2020
_buildConfig() {
2121
echo "<?php"
2222

23+
echo "define('DISABLE_UPLOADFORM',${DISABLE_UPLOADFORM:-false});"
24+
2325
echo "define('ENCRYPTION_AGE_SSH_PUBKEY','${ENCRYPTION_AGE_SSH_PUBKEY:-}');"
2426
echo "define('ENCRYPTION_AGE_PUBKEY','${ENCRYPTION_AGE_PUBKEY:-}');"
2527

web/index.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,25 @@
2323

2424
//getting the url as array
2525
$url = array_filter(explode('/',ltrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),'/')));
26+
$method = $_SERVER['REQUEST_METHOD'];
2627

2728
//main logic
2829
//deciding what to do based on URL
2930
$hostname = $url[0];
3031
if(!$hostname || $url[0] == 'rtfm') //no hostname? Well let's render the info page
3132
echo renderInfoPage($url[1]);
32-
else //handle an upload
33+
else if($method=='POST') //handle an upload
3334
{
3435
header('Content-Type: application/json');
3536

3637
//let's filter out the hostname and get rid of every special char except for: . _ -
3738
$hostname = preg_replace("/[^a-zA-Z0-9\.\-_]+/", "", $hostname);
3839
echo json_encode(handleUpload($hostname)).PHP_EOL;
3940
}
41+
else if($method=='GET' && defined('DISABLE_UPLOADFORM') && DISABLE_UPLOADFORM!==true) //render file upload dialogue
42+
{
43+
include_once(ROOT.DS.'lib'.DS.'upload-template.html.php');
44+
}
4045

4146

4247
//functions start here

web/lib/upload-template.html.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<html>
2+
<head>
3+
<title>Upload Backup</title>
4+
<script src="https://unpkg.com/dropzone@5/dist/min/dropzone.min.js"></script>
5+
<link rel="stylesheet" href="https://unpkg.com/dropzone@5/dist/min/dropzone.min.css" type="text/css" />
6+
</head>
7+
<body>
8+
<form action="/<?=$url[0]?>" class="dropzone" method="POST" enctype="multipart/form-data">
9+
10+
</form>
11+
</html>

0 commit comments

Comments
 (0)