Compare commits
10 commits
53b5ebcb43
...
dcdb1b23d7
| Author | SHA1 | Date | |
|---|---|---|---|
| dcdb1b23d7 | |||
| f8eddfd1d5 | |||
| bb9dc0ee5d | |||
| 2e6da33574 | |||
| b2f27aa3f4 | |||
| 1377fa669a | |||
| 8f492f2432 | |||
| c677114e08 | |||
| 2b64fe576f | |||
| 86c2321fab |
13 changed files with 354 additions and 37 deletions
|
|
@ -3,6 +3,9 @@
|
||||||
return [
|
return [
|
||||||
'domain' => 'lefuturiste.fr',
|
'domain' => 'lefuturiste.fr',
|
||||||
'modules' => [
|
'modules' => [
|
||||||
|
'modules' => [
|
||||||
|
'alias' => ['web-utils', 'utils', 'help-utils', 'help-modules', 'modules-list']
|
||||||
|
],
|
||||||
'random' => [],
|
'random' => [],
|
||||||
'date' => [
|
'date' => [
|
||||||
'alias' => ['printdate']
|
'alias' => ['printdate']
|
||||||
|
|
@ -15,7 +18,8 @@ return [
|
||||||
'auth' => true
|
'auth' => true
|
||||||
],
|
],
|
||||||
'quickupload' => [
|
'quickupload' => [
|
||||||
'auth' => true
|
'auth' => true,
|
||||||
|
'alias' => ['share']
|
||||||
],
|
],
|
||||||
'logator' => [
|
'logator' => [
|
||||||
'alias' => ['logme']
|
'alias' => ['logme']
|
||||||
|
|
@ -23,9 +27,14 @@ return [
|
||||||
'hash' => [],
|
'hash' => [],
|
||||||
'baseconverter' => [
|
'baseconverter' => [
|
||||||
'alias' => ['encode', 'decode']
|
'alias' => ['encode', 'decode']
|
||||||
|
],
|
||||||
|
'uuid' => [],
|
||||||
|
'urlshortner' => [
|
||||||
|
'alias' => ['u', 'url']
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'auth' => [
|
'auth' => [
|
||||||
'root' => 'password'
|
'root' => 'password'
|
||||||
]
|
],
|
||||||
|
'special_token' => 'password'
|
||||||
];
|
];
|
||||||
|
|
@ -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";
|
||||||
|
|
|
||||||
48
index.php
48
index.php
|
|
@ -3,6 +3,26 @@
|
||||||
require('utils.php');
|
require('utils.php');
|
||||||
require('load_config.php');
|
require('load_config.php');
|
||||||
|
|
||||||
|
/* Disable function */
|
||||||
|
if (file_exists('./DISABLE')) {
|
||||||
|
header('X-Disabled: Yes');
|
||||||
|
http_response_code(503);
|
||||||
|
?>
|
||||||
|
<p>503</p>
|
||||||
|
<iframe
|
||||||
|
width="560" height="315" frameborder="0"
|
||||||
|
src="https://www.youtube-nocookie.com/embed/D1rlGA_UGrY?autoplay=1&controls=0"
|
||||||
|
allow="autoplay;encrypted-media;picture-in-picture" allowfullscreen>
|
||||||
|
</iframe>
|
||||||
|
<?php
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
if ($_SERVER['REQUEST_URI'] === '/special-disable?token=' . $config['special_token']) {
|
||||||
|
file_put_contents('./DISABLE', '1');
|
||||||
|
echo "Disabled successfully";
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
function generateHelp($selectedModule) {
|
function generateHelp($selectedModule) {
|
||||||
if (strpos($_SERVER['REQUEST_URI'], '/help') === false) {
|
if (strpos($_SERVER['REQUEST_URI'], '/help') === false) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -13,7 +33,11 @@ function generateHelp($selectedModule) {
|
||||||
}
|
}
|
||||||
$helpConfig = require($additionalHelpPath);
|
$helpConfig = require($additionalHelpPath);
|
||||||
|
|
||||||
echo "<h1>Help for module \"$selectedModule\"</h1>";
|
$moduleTitle = $helpConfig['title'] ?? $selectedModule;
|
||||||
|
echo "<h1>Help for module \"$moduleTitle\"</h1>";
|
||||||
|
if (isset($helpConfig['description'])) {
|
||||||
|
echo "<h3>" . $helpConfig['description'] . "</h3>";
|
||||||
|
}
|
||||||
echo " <ul>";
|
echo " <ul>";
|
||||||
foreach ($helpConfig['actions'] as $action) {
|
foreach ($helpConfig['actions'] as $action) {
|
||||||
?>
|
?>
|
||||||
|
|
@ -47,27 +71,7 @@ if ($selectedModule === null) {
|
||||||
generateHelp($selectedModule['key']);
|
generateHelp($selectedModule['key']);
|
||||||
|
|
||||||
if (isset($selectedModule['auth']) && $selectedModule['auth']) {
|
if (isset($selectedModule['auth']) && $selectedModule['auth']) {
|
||||||
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']))
|
askAuth($config['auth']);
|
||||||
{
|
|
||||||
header("WWW-Authenticate: Basic realm=\"You need to provide user and passwd\"");
|
|
||||||
http_response_code(401);
|
|
||||||
echo "Authentification Required";
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
$providedUsername = $_SERVER['PHP_AUTH_USER'];
|
|
||||||
$providedPassword = $_SERVER['PHP_AUTH_PW'];
|
|
||||||
$found = false;
|
|
||||||
foreach ($config['auth'] as $username => $password) {
|
|
||||||
if ($username === $providedUsername && $password == $providedPassword) {
|
|
||||||
$found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!$found) {
|
|
||||||
header("WWW-Authenticate: Basic realm=\"Invalid auth\"");
|
|
||||||
http_response_code(401);
|
|
||||||
echo "Invalid authentification, try again";
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
require('./modules/' . $selectedModule['key'] . '/' . $selectedModule['key'] . '.php');
|
require('./modules/' . $selectedModule['key'] . '/' . $selectedModule['key'] . '.php');
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,22 @@ return [
|
||||||
'name' => 'List all loggers',
|
'name' => 'List all loggers',
|
||||||
'path' => '/loggers'
|
'path' => '/loggers'
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Create a logger',
|
||||||
|
'path' => '/create'
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'name' => 'Get details about a logger',
|
'name' => 'Get details about a logger',
|
||||||
'path' => '/logger-details?id=YOURID'
|
'path' => '/logger-details?id=YOURID'
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Delete request history for a logger',
|
||||||
|
'path' => '/logger-details?id=YOURID&reset=yes'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Delete a logger',
|
||||||
|
'path' => '/logger-details?id=YOURID&delete=yes'
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'name' => 'Execute a logger',
|
'name' => 'Execute a logger',
|
||||||
'path' => '/YOURID'
|
'path' => '/YOURID'
|
||||||
|
|
|
||||||
25
modules/modules/modules.php
Normal file
25
modules/modules/modules.php
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
<h1> List of modules </h1>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
echo "<ul>\n";
|
||||||
|
foreach ($config['modules'] as $name => $moduleConf) {
|
||||||
|
if ($name == 'modules') { continue; }
|
||||||
|
?>
|
||||||
|
<li>
|
||||||
|
<a href="http://<?= $name . '.' . $config['domain'] ?>"><?= $name ?></a>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if (isset($moduleConf['alias'])) {
|
||||||
|
echo ' : ';
|
||||||
|
foreach ($moduleConf['alias'] as $alias) {
|
||||||
|
?>
|
||||||
|
<a href="http://<?= $alias . '.' . $config['domain'] ?>"><?= $alias ?></a>,
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</li>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
echo "</ul>";
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
header('Are-You-A-Bastard: Yes');
|
||||||
|
|
||||||
echo $_SERVER['REMOTE_ADDR'];
|
echo $_SERVER['REMOTE_ADDR'];
|
||||||
|
|
|
||||||
4
modules/quickupload/nginx_quickupload.conf
Normal file
4
modules/quickupload/nginx_quickupload.conf
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
location /file/ {
|
||||||
|
alias {{ROOT_PATH}}/tmp/quickupload/;
|
||||||
|
autoindex off;
|
||||||
|
}
|
||||||
|
|
@ -11,36 +11,110 @@ function slugify($string){
|
||||||
return strtolower(trim(preg_replace('/[^.A-Za-z0-9-]+/', '-', $string), '-'));
|
return strtolower(trim(preg_replace('/[^.A-Za-z0-9-]+/', '-', $string), '-'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strpos($_SERVER['REQUEST_URI'], '/delete') === 0) {
|
||||||
|
$fileName = $_GET['name'] ?? '';
|
||||||
|
if (empty($fileName)) {
|
||||||
|
echo "ERR: need a file name to work with";
|
||||||
|
http_response_code(400);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
if (dirname($path . '/' . $fileName) !== $path) {
|
||||||
|
echo "ERR: invalid path";
|
||||||
|
http_response_code(400);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
$fileName = str_replace('/', '', $fileName);
|
||||||
|
if (!file_exists($path . '/' . $fileName)) {
|
||||||
|
echo "ERR: invalid path";
|
||||||
|
http_response_code(400);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
unlink($path . '/' . $fileName);
|
||||||
|
if (isset($_GET['redirect']) && $_GET['redirect'] === 'yes') {
|
||||||
|
header('Location: /list');
|
||||||
|
http_response_code(302);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_URI'] === '/list') {
|
if ($_SERVER['REQUEST_URI'] === '/list') {
|
||||||
$files = getFilesAsArray($path);
|
$files = getFilesAsArray($path);
|
||||||
?>
|
?>
|
||||||
<h3>List of uploaded files</h3>
|
<h3>List of uploaded files</h3>
|
||||||
<ul>
|
<div>
|
||||||
<?php
|
<?php
|
||||||
foreach ($files as $fileName) {
|
foreach ($files as $fileName) {
|
||||||
?>
|
?>
|
||||||
<li><a href="/file/<?= $fileName ?>"><?= $fileName ?></a></li>
|
<div
|
||||||
|
style="
|
||||||
|
max-width: 900px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
border: 1px solid gray;
|
||||||
|
margin-bottom: .4em
|
||||||
|
">
|
||||||
|
<div>
|
||||||
|
<a href="/file/<?= $fileName ?>"><?= $fileName ?></a>
|
||||||
|
</div>
|
||||||
|
<a href="/delete?name=<?= $fileName ?>&redirect=yes">Delete</a>
|
||||||
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</ul>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
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>
|
||||||
|
|
|
||||||
115
modules/urlshortner/urlshortner.php
Normal file
115
modules/urlshortner/urlshortner.php
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$path = __DIR__ . '/../../tmp/urlshortner';
|
||||||
|
|
||||||
|
function saveUrls($urlsToStore) {
|
||||||
|
global $path;
|
||||||
|
$data = json_encode([
|
||||||
|
'updated_at' => date('Y-m-d H:i:s'),
|
||||||
|
'urls' => $urlsToStore
|
||||||
|
]);
|
||||||
|
file_put_contents($path . '/urls.json', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file_exists($path)) {
|
||||||
|
mkdir($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file_exists($path . '/urls.json') || file_get_contents($path . '/urls.json') === '') {
|
||||||
|
file_put_contents($path . '/urls.json', '{"urls": []}');
|
||||||
|
}
|
||||||
|
|
||||||
|
$urls = json_decode(file_get_contents($path . '/urls.json'), true)['urls'];
|
||||||
|
|
||||||
|
if (strpos($_SERVER['REQUEST_URI'], '/admin') === 0) {
|
||||||
|
// admin panel
|
||||||
|
askAuth($config['auth']);
|
||||||
|
|
||||||
|
if (strpos($_SERVER['REQUEST_URI'], '/create') !== false) {
|
||||||
|
$url = [
|
||||||
|
'slug' => $_GET['slug'] ?? $_GET['name'] ?? '',
|
||||||
|
'target' => $_GET['target'] ?? '',
|
||||||
|
'created_at' => date('Y-m-d H:i:s')
|
||||||
|
];
|
||||||
|
if (empty($url['slug']) || empty($url['target'])) {
|
||||||
|
echo "Invalid values slug or target";
|
||||||
|
http_response_code(400);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
$urls[] = $url;
|
||||||
|
|
||||||
|
echo "Url was created";
|
||||||
|
saveUrls($urls);
|
||||||
|
if (isset($_GET['redirect'])) {
|
||||||
|
header('Location: ' . $_GET['redirect']);
|
||||||
|
http_response_code(302);
|
||||||
|
}
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
if (strpos($_SERVER['REQUEST_URI'], '/delete') !== false) {
|
||||||
|
if (!isset($_GET['slug']) || empty($_GET['slug'])) {
|
||||||
|
echo "Slug param missing";
|
||||||
|
http_response_code(400);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
$urls = array_filter($urls, fn ($u) => $u['slug'] !== $_GET['slug']);
|
||||||
|
echo "The urls with this slug were deleted";
|
||||||
|
|
||||||
|
saveUrls($urls);
|
||||||
|
if (isset($_GET['redirect'])) {
|
||||||
|
header('Location: ' . $_GET['redirect']);
|
||||||
|
}
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<h1>Url list</h1>
|
||||||
|
<b>Add a URL</b>
|
||||||
|
<form method="get" action="/admin/create">
|
||||||
|
<label for="slug">Slug</label>
|
||||||
|
<input type="text" name="slug" id="slug" />
|
||||||
|
|
||||||
|
<br>
|
||||||
|
<label for="target">Target (link)</label>
|
||||||
|
<input type="url" name="target" id="target" style="min-width: 80%" />
|
||||||
|
|
||||||
|
<input type="hidden" name="redirect" value="/admin" />
|
||||||
|
<br>
|
||||||
|
<button>Create Shortcut</button>
|
||||||
|
</form>
|
||||||
|
<hr>
|
||||||
|
<div>
|
||||||
|
<?php
|
||||||
|
foreach ($urls as $url) {
|
||||||
|
?>
|
||||||
|
<div
|
||||||
|
style="
|
||||||
|
max-width: 900px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
border: 1px solid gray;
|
||||||
|
margin-bottom: .4em
|
||||||
|
">
|
||||||
|
<div>
|
||||||
|
/<?= $url['slug'] ?> : <a href="<?= $url['target'] ?>"><?= $url['target'] ?></a>
|
||||||
|
</div>
|
||||||
|
<a href="/admin/delete?slug=<?= $url['slug'] ?>&redirect=/admin">Delete</a>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($urls as $url) {
|
||||||
|
if (strpos($_SERVER['REQUEST_URI'], '/' . $url['slug']) === 0) {
|
||||||
|
header('Location: ' . $url['target']);
|
||||||
|
http_response_code(302);
|
||||||
|
echo "You've been redirected";
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
http_response_code(404);
|
||||||
|
echo 'ERR: Unknown url';
|
||||||
27
modules/uuid/uuid.php
Normal file
27
modules/uuid/uuid.php
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
header("Content-Type: text/plain");
|
||||||
|
|
||||||
|
function guidv4($data = null) {
|
||||||
|
// Generate 16 bytes (128 bits) of random data or use the data passed into the function.
|
||||||
|
$data = $data ?? random_bytes(16);
|
||||||
|
assert(strlen($data) == 16);
|
||||||
|
|
||||||
|
// Set version to 0100
|
||||||
|
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
|
||||||
|
// Set bits 6-7 to 10
|
||||||
|
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
|
||||||
|
|
||||||
|
// Output the 36 character UUID.
|
||||||
|
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
$inter = guidv4();
|
||||||
|
|
||||||
|
$output = $inter;
|
||||||
|
if (isset($_GET['compact']) && $_GET['compact'] === 'yes') {
|
||||||
|
$output = str_replace('-', '', $inter);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $output;
|
||||||
|
|
||||||
10
modules/uuid/uuid_help.php
Normal file
10
modules/uuid/uuid_help.php
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'actions' => [
|
||||||
|
[
|
||||||
|
'name' => 'Generate compact uuid',
|
||||||
|
'path' => '/?compact=yes'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
@ -2,6 +2,9 @@ server {
|
||||||
index index.html index.php;
|
index index.html index.php;
|
||||||
root {{ROOT_PATH}};
|
root {{ROOT_PATH}};
|
||||||
server_name {{SERVER_NAME}};
|
server_name {{SERVER_NAME}};
|
||||||
|
|
||||||
|
{{CUSTOM_CONFIG}}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
try_files $uri $uri/ /index.php?$args;
|
try_files $uri $uri/ /index.php?$args;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
24
utils.php
24
utils.php
|
|
@ -64,3 +64,27 @@ function deleteAllFiles($path) {
|
||||||
}
|
}
|
||||||
return $count;
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function askAuth($authConfig) {
|
||||||
|
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']))
|
||||||
|
{
|
||||||
|
header("WWW-Authenticate: Basic realm=\"You need to provide user and passwd\"");
|
||||||
|
http_response_code(401);
|
||||||
|
echo "Authentification Required";
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
$providedUsername = $_SERVER['PHP_AUTH_USER'];
|
||||||
|
$providedPassword = $_SERVER['PHP_AUTH_PW'];
|
||||||
|
$found = false;
|
||||||
|
foreach ($authConfig as $username => $password) {
|
||||||
|
if ($username === $providedUsername && $password == $providedPassword) {
|
||||||
|
$found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$found) {
|
||||||
|
header("WWW-Authenticate: Basic realm=\"Invalid auth\"");
|
||||||
|
http_response_code(401);
|
||||||
|
echo "Invalid authentification, try again";
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue