feat(QuickUpload): add text field (pastebin like feat)

This commit is contained in:
Matthieu Bessat 2021-10-03 16:30:41 +02:00
parent b2f27aa3f4
commit 2e6da33574
5 changed files with 61 additions and 11 deletions

View file

@ -16,7 +16,8 @@ return [
'auth' => true
],
'quickupload' => [
'auth' => true
'auth' => true,
'alias' => ['share']
],
'logator' => [
'alias' => ['logme']

View file

@ -13,17 +13,25 @@ if (!file_exists($path)) {
require('./load_config.php');
$template = file_get_contents('./nginx.conf.template');
$phpSocket = '/var/run/php/php8.0-fpm.sock';
$phpSocket = $argv[1] ?? '/var/run/php/php8.0-fpm.sock';
foreach ($config['modules'] as $moduleName => $moduleConfig) {
$domains = array_merge([$moduleName], $moduleConfig['alias'] ?? []);
$domains = array_map(fn ($d) => $d . '.' . $config['domain'], $domains);
$serverName = implode(' ', $domains);
$nginxConfPath = './modules/' . $moduleName . '/nginx_' . $moduleName . '.conf';
$customConfig = '';
if (file_exists($nginxConfPath)) {
$customConfig = file_get_contents($nginxConfPath);
$customConfig = str_replace('{{ROOT_PATH}}', $appBasePath, $customConfig);
}
$nginxConfig = $template;
$nginxConfig = str_replace('{{ROOT_PATH}}', $appBasePath, $nginxConfig);
$nginxConfig = str_replace('{{SERVER_NAME}}', $serverName, $nginxConfig);
$nginxConfig = str_replace('{{PHP_SOCKET}}', $phpSocket, $nginxConfig);
$nginxConfig = str_replace('{{CUSTOM_CONFIG}}', $customConfig, $nginxConfig);
file_put_contents($path . '/' . $domains[0], $nginxConfig);
echo "> Wrote " . strlen($nginxConfig) . " bytes in " . $path . '/' . $domains[0] . "\n";

View file

@ -0,0 +1,4 @@
location /file/ {
alias {{ROOT_PATH}}/tmp/quickupload;
autoindex off;
}

View file

@ -28,19 +28,55 @@ if ($_SERVER['REQUEST_URI'] === '/list') {
exit();
}
if (isset($_FILES['file'])) {
$f = $_FILES['file'];
copy($f['tmp_name'], $path . '/' . uniqid() . '_' . slugify($f['name']));
$file = null;
$isAutoGeneratedFileName = false;
if (isset($_POST['name']) && !empty($_POST['name'])) {
$fileName = $_POST['name'];
} else {
$fileName = generateRandomString(6);
$isAutoGeneratedFileName = true;
}
if (isset($_POST['text']) && !empty($_POST['text'])) {
if ($isAutoGeneratedFileName) $fileName .= '.txt';
file_put_contents($path . '/' . $fileName, $_POST['text']);
$file = true;
}
else if (isset($_FILES['file'])) {
$file = $_FILES['file'];
if ($isAutoGeneratedFileName) $fileName .= '_' . slugify($file['name']);
copy($file['tmp_name'], $path . '/' . $fileName);
}
if ($file !== null) {
?>
<div style="padding: 20px; border: 1px solid green; background: green; color: white">
File uploaded!
File uploaded! <a href="/file/<?= $fileName ?>">Click here to find it</a>
</div>
<?php
}
?>
<h3>QuickUpload</h3>
<!DOCTYPE html>
<html>
<head>
<title>QuickUpload</title>
</head>
<body>
<h1>QuickUpload</h1>
<form enctype="multipart/form-data" method="POST">
<input type="hidden" name="name" value="wow" />
<input type="file" name="file" />
<input type="submit" value="Submit">
</form>
Upload a direct file
<input type="file" name="file" /><input type="submit" value="Submit">
<br>
<br>
Or paste your data:
<textarea name="text" style="margin: 1em 0; width:100%; height: 60vh"></textarea><br>
<label for="name">File name:</label>
<input type="text" name="name" />
<br>
<br>
<input type="submit" value="Submit" style="width: 6em; height: 3em;">
</form>
</body>
</html>

View file

@ -5,6 +5,7 @@ server {
location / {
try_files $uri $uri/ /index.php?$args;
}
{{CUSTOM_CONFIG}}
location ^~ /wp-admin {
return 403;
}