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
+2 -51
View File
@@ -36,13 +36,13 @@ $AUTHORITIES = [
];
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json; charset=UTF-8');
function jenc($data): string {
return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
if ($_SERVER['REQUEST_METHOD'] !== 'GET' && $_SERVER['REQUEST_METHOD'] !== 'HEAD') {
header('Content-Type: application/json; charset=UTF-8');
header('Status: 405');
header('Content-Length: 56');
header('Allow: GET, HEAD');
@@ -58,44 +58,7 @@ if ($info !== '/' && str_ends_with($info, '/')) {
}
$parts = explode('/', $info);
if (str_starts_with($info, '/certificates/')) {
$id = $parts[2];
if (str_ends_with($id, '.txt')) {
$id = substr($id, 0, -4);
}
if (str_contains($id, '/') || !file_exists("certificates/$id.pdf")) {
header('Content-Type: application/json; charset=UTF-8');
header('Status: 404');
header('Content-Length: 22');
echo "{\"error\":\"not found\"}\n";
exit;
}
if (str_ends_with($parts[2], '.txt')) {
$mode = '-layout';
if (isset($_GET['raw']) && strtolower($_GET['raw']) === 'true') {
$mode = '-raw';
}
header('Content-Type: text/plain; charset=UTF-8');
system("pdftotext $mode 'certificates/$id.pdf' -");
exit;
}
if (str_ends_with($id, '.appendix')) {
header('Status: 303');
header('Location: ' . substr($id, 0, -9));;
exit;
}
$cert = shell_exec("pdftotext -raw 'certificates/$id.pdf' -");
$appendix = shell_exec("pdftotext -raw 'certificates/$id.appendix.pdf' -");
$p1 = strpos($cert, "\nI.3 ");
$p2 = strpos($cert, "\nI.4 ");
echo substr($cert, $p1 + 5, $p2 - $p1 - 5);
exit;
} else if ($info === '/authorities') {
header('Content-Type: application/json; charset=UTF-8');
if ($info === '/authorities') {
echo "{\"data\":[\n";
$first = true;
foreach ($AUTHORITIES as $auth) {
@@ -107,7 +70,6 @@ if (str_starts_with($info, '/certificates/')) {
exit;
} else if (str_starts_with($info, '/authorities/')) {
$code = $parts[2];
header('Content-Type: application/json; charset=UTF-8');
if (array_key_exists($code, $AUTHORITIES)) {
echo jenc($AUTHORITIES[$code]);
echo "\n";
@@ -117,17 +79,6 @@ if (str_starts_with($info, '/certificates/')) {
echo "{\"error\":\"not found\"}\n";
}
exit;
} else if ($info === '/operators') {
header('Content-Type: application/json; charset=UTF-8');
header('Status: 501');
header('Content-Length: 27');
echo "{\"error\":\"not implemented\"}\n";
exit;
} else if (str_starts_with($info, '/operators/')) {
$ooid = $parts[2];
header('Content-Type: text/plain; charset=UTF-8');
echo "Organic Operator Id: $ooid\n";
exit;
}
header('Status: 404');