organic: Enhance external apis

This commit is contained in:
2025-12-22 16:56:23 +01:00
parent 551ddd3c11
commit 0cd3b3de8e
10 changed files with 350 additions and 110 deletions

View File

@@ -3,30 +3,38 @@
header('Access-Control-Allow-Origin: *');
if ($_SERVER['REQUEST_METHOD'] !== 'GET' && $_SERVER['REQUEST_METHOD'] !== 'HEAD') {
header('Content-Type: application/json; charset=UTF-8');
header('Status: 405');
header('Content-Length: 0');
header('Content-Length: 56');
header('Allow: GET, HEAD');
echo "{\"error\":\"method not allowed\",\"allow\":[\"GET\",\"HEAD\"]}\n";
exit;
}
$info = $_SERVER['PATH_INFO'];
if ($info === '') {
header('Content-Type: application/json; charset=UTF-8');
header('Status: 404');
header('Content-Length: 0');
header('Content-Length: 22');
echo "{\"error\":\"not found\"}\n";
exit;
}
$certId = substr($info, 1);
$file = tmpfile();
if (!$file) {
header('Content-Type: application/json; charset=UTF-8');
header('Status: 500');
header('Content-Length: 0');
header('Content-Length: 34');
echo "{\"error\":\"internal server error\"}\n";
exit;
}
$filename = stream_get_meta_data($file)['uri'];
if (($pdfName = exec("python3 .attachment.py " . escapeshellarg($certId) . " 2>&1 > $filename ")) === false) {
header('Status: 500');
header('Content-Length: 0');
if (($pdfName = exec("python3 .attachment.py " . escapeshellarg($certId) . " 2>&1 > $filename ")) === "404") {
header('Content-Type: application/json; charset=UTF-8');
header('Status: 404');
header('Content-Length: 22');
echo "{\"error\":\"not found\"}\n";
exit;
}