organic: Add extended API

This commit is contained in:
2026-09-01 18:02:57 +02:00
parent 028c16be3d
commit 4572323a14
13 changed files with 978 additions and 266 deletions
View File
+44
View File
@@ -0,0 +1,44 @@
<?php
require '../.php/pdf.php';
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json; charset=UTF-8');
if ($_SERVER['REQUEST_METHOD'] !== 'GET' && $_SERVER['REQUEST_METHOD'] !== 'HEAD') {
header('Status: 405');
header('Content-Length: 56');
header('Allow: GET, HEAD');
echo "{\"error\":\"method not allowed\",\"allow\":[\"GET\",\"HEAD\"]}\n";
exit;
}
function jenc($data): string {
return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
$info = substr($_SERVER['PATH_INFO'], 1);
if (strlen($info) !== 31) {
header('Status: 404');
header('Content-Length: 22');
echo "{\"error\":\"not found\"}\n";
exit;
}
$cert = parse_pdf("$info.pdf");
$appendix = parse_pdf("$info.appendix.pdf");
if ($cert === null && $appendix === null) {
header('Status: 404');
header('Content-Length: 22');
echo "{\"error\":\"not found\"}\n";
exit;
}
if ($cert !== null) $cert['pdfUrl'] = "https://elwig.at/organic/certificates/$info.pdf";
if ($appendix !== null) $appendix['pdfUrl'] = "https://elwig.at/organic/certificates/$info.appendix.pdf";
echo jenc([
'traces' => $cert,
'appendix' => $appendix,
]);