web-utils/index.php

78 lines
2 KiB
PHP
Raw Permalink Normal View History

2021-08-08 17:23:49 +00:00
<?php
require('utils.php');
require('load_config.php');
2021-10-03 12:23:32 +00:00
/* 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();
}
2021-08-08 17:23:49 +00:00
function generateHelp($selectedModule) {
if (strpos($_SERVER['REQUEST_URI'], '/help') === false) {
return;
}
$additionalHelpPath = './modules/' . $selectedModule . '/' . $selectedModule . '_help.php';
if (!file_exists($additionalHelpPath)) {
return;
}
$helpConfig = require($additionalHelpPath);
$moduleTitle = $helpConfig['title'] ?? $selectedModule;
echo "<h1>Help for module \"$moduleTitle\"</h1>";
if (isset($helpConfig['description'])) {
echo "<h3>" . $helpConfig['description'] . "</h3>";
}
2021-08-08 17:23:49 +00:00
echo " <ul>";
foreach ($helpConfig['actions'] as $action) {
?>
<li><?= $action['name'] ?> <a href="<?= $action['path'] ?>"><?= $action['path'] ?></a></li>
<?php
}
echo "\n </ul> \n <br>";
echo $helpConfig['append']() ?? '';
exit();
}
$modules = $config['modules'];
$selectedModule = null;
foreach ($modules as $moduleName => $module) {
foreach (array_merge([$moduleName], $module['alias'] ?? []) as $alias) {
if (strpos($_SERVER['HTTP_HOST'], $alias . '.') === 0) {
$selectedModule = $module;
$selectedModule['key'] = $moduleName;
break;
}
2021-08-08 17:23:49 +00:00
}
}
if ($selectedModule === null) {
http_response_code(404);
echo 'unknown module';
}
generateHelp($selectedModule['key']);
if (isset($selectedModule['auth']) && $selectedModule['auth']) {
2021-10-03 12:04:05 +00:00
askAuth($config['auth']);
2021-08-08 17:23:49 +00:00
}
require('./modules/' . $selectedModule['key'] . '/' . $selectedModule['key'] . '.php');