2024-06-03 19:48:39 +02:00
|
|
|
<?php
|
2024-06-13 16:03:44 +02:00
|
|
|
|
|
|
|
if($_SERVER["REQUEST_URI"] == '/metrics') {
|
|
|
|
header('Content-Type: text/plain; version=0.0.4');
|
|
|
|
$config = getenv('CONFIG_FILE');
|
|
|
|
$phpbin = getenv('PHP_BINARY');
|
2024-06-14 20:31:09 +02:00
|
|
|
$output = shell_exec('CONFIG_FILE="' . $config . '" ' . $phpbin . ' ' . $_SERVER['DOCUMENT_ROOT'] . '/script.php');
|
2024-06-13 16:03:44 +02:00
|
|
|
echo $output;
|
2024-06-13 17:43:32 +02:00
|
|
|
} elseif ($_SERVER["REQUEST_URI"] == '/config') {
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
require_once getenv('CONFIG_FILE');
|
|
|
|
echo json_encode($config);
|
2024-06-14 20:49:33 +02:00
|
|
|
} elseif ($_SERVER["REQUEST_URI"] == '/version' && is_dir($_SERVER['DOCUMENT_ROOT'] . '/.git')) {
|
2024-06-13 17:35:10 +02:00
|
|
|
header('Content-Type: application/json');
|
|
|
|
$git = [
|
|
|
|
'lastCommit' => trim(shell_exec('git rev-parse HEAD')),
|
|
|
|
'lastCommitTimestamp' => trim(shell_exec('git log -1 --format=%cd')),
|
|
|
|
'branch' => trim(shell_exec('git rev-parse --abbrev-ref HEAD')),
|
|
|
|
];
|
|
|
|
echo json_encode($git);
|
2024-06-13 16:03:44 +02:00
|
|
|
} else {
|
|
|
|
require_once('vendor/autoload.php');
|
2024-06-14 20:49:33 +02:00
|
|
|
$knownpaths = [
|
|
|
|
'/metrics',
|
|
|
|
'/config'
|
|
|
|
];
|
|
|
|
if (is_dir($_SERVER['DOCUMENT_ROOT'] . '/.git')) $knownpaths[] = '/version';
|
2024-06-13 16:03:44 +02:00
|
|
|
http_response_code(404);
|
|
|
|
$loader = new \Twig\Loader\FilesystemLoader('templates');
|
|
|
|
$twig = new \Twig\Environment($loader, [
|
|
|
|
'cache' => 'twig_cache',
|
|
|
|
]);
|
2024-06-14 20:49:33 +02:00
|
|
|
echo $twig->render('404.twig', ['path' => $_SERVER["REQUEST_URI"], 'knownpaths' => $knownpaths]);
|
2024-06-13 16:03:44 +02:00
|
|
|
}
|