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 'auth' => true
], ],
'quickupload' => [ 'quickupload' => [
'auth' => true 'auth' => true,
'alias' => ['share']
], ],
'logator' => [ 'logator' => [
'alias' => ['logme'] 'alias' => ['logme']

View file

@ -13,17 +13,25 @@ if (!file_exists($path)) {
require('./load_config.php'); require('./load_config.php');
$template = file_get_contents('./nginx.conf.template'); $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) { foreach ($config['modules'] as $moduleName => $moduleConfig) {
$domains = array_merge([$moduleName], $moduleConfig['alias'] ?? []); $domains = array_merge([$moduleName], $moduleConfig['alias'] ?? []);
$domains = array_map(fn ($d) => $d . '.' . $config['domain'], $domains); $domains = array_map(fn ($d) => $d . '.' . $config['domain'], $domains);
$serverName = implode(' ', $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 = $template;
$nginxConfig = str_replace('{{ROOT_PATH}}', $appBasePath, $nginxConfig); $nginxConfig = str_replace('{{ROOT_PATH}}', $appBasePath, $nginxConfig);
$nginxConfig = str_replace('{{SERVER_NAME}}', $serverName, $nginxConfig); $nginxConfig = str_replace('{{SERVER_NAME}}', $serverName, $nginxConfig);
$nginxConfig = str_replace('{{PHP_SOCKET}}', $phpSocket, $nginxConfig); $nginxConfig = str_replace('{{PHP_SOCKET}}', $phpSocket, $nginxConfig);
$nginxConfig = str_replace('{{CUSTOM_CONFIG}}', $customConfig, $nginxConfig);
file_put_contents($path . '/' . $domains[0], $nginxConfig); file_put_contents($path . '/' . $domains[0], $nginxConfig);
echo "> Wrote " . strlen($nginxConfig) . " bytes in " . $path . '/' . $domains[0] . "\n"; 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(); exit();
} }
if (isset($_FILES['file'])) { $file = null;
$f = $_FILES['file']; $isAutoGeneratedFileName = false;
copy($f['tmp_name'], $path . '/' . uniqid() . '_' . slugify($f['name'])); 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"> <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> </div>
<?php <?php
} }
?> ?>
<h3>QuickUpload</h3> <!DOCTYPE html>
<html>
<head>
<title>QuickUpload</title>
</head>
<body>
<h1>QuickUpload</h1>
<form enctype="multipart/form-data" method="POST"> <form enctype="multipart/form-data" method="POST">
<input type="hidden" name="name" value="wow" /> Upload a direct file
<input type="file" name="file" /> <input type="file" name="file" /><input type="submit" value="Submit">
<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> </form>
</body>
</html>

View file

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