Skip to content

Commit

Permalink
added integrated upload form, can be disabled with DISABLE_UPLOADFORM…
Browse files Browse the repository at this point in the history
… setting or env in Docker
  • Loading branch information
geek-at committed Dec 8, 2024
1 parent 0425d6f commit 8034a2f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/example.config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// copy this file to config.inc.php
// and edit to your needs

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

// AGE encryption settings
// More info on age encryption: https://github.com/FiloSottile/age
Expand Down
2 changes: 2 additions & 0 deletions docker/rootfs/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ nginx
_buildConfig() {
echo "<?php"

echo "define('DISABLE_UPLOADFORM',${DISABLE_UPLOADFORM:-false});"

echo "define('ENCRYPTION_AGE_SSH_PUBKEY','${ENCRYPTION_AGE_SSH_PUBKEY:-}');"
echo "define('ENCRYPTION_AGE_PUBKEY','${ENCRYPTION_AGE_PUBKEY:-}');"

Expand Down
7 changes: 6 additions & 1 deletion web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@

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

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

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


//functions start here
Expand Down
11 changes: 11 additions & 0 deletions web/lib/upload-template.html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html>
<head>
<title>Upload Backup</title>
<script src="https://unpkg.com/dropzone@5/dist/min/dropzone.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/dropzone@5/dist/min/dropzone.min.css" type="text/css" />
</head>
<body>
<form action="/<?=$url[0]?>" class="dropzone" method="POST" enctype="multipart/form-data">

</form>
</html>

0 comments on commit 8034a2f

Please sign in to comment.