organic: Enhance external apis
This commit is contained in:
@@ -1,16 +1,58 @@
|
||||
<?php
|
||||
|
||||
$AUTHORITIES = [
|
||||
'AT-BIO-301' => [
|
||||
'id' => 'AT-BIO-301', 'countryCode' => 'AT', 'handle' => 'ABG',
|
||||
'name' => 'Austria Bio Garantie GmbH', 'website' => 'https://www.bio-garantie.at/', 'apis' => ['easy-cert']
|
||||
],
|
||||
'AT-BIO-302' => [
|
||||
'id' => 'AT-BIO-302', 'countryCode' => 'AT', 'handle' => 'ABG-LW',
|
||||
'name' => 'Austria Bio Garantie – Landwirtschaft GmbH', 'website' => 'https://www.bio-garantie.at/', 'apis' => ['easy-cert']
|
||||
],
|
||||
'AT-BIO-401' => [
|
||||
'id' => 'AT-BIO-401', 'countryCode' => 'AT', 'handle' => 'BIOS',
|
||||
'name' => 'BIOS – Biokontrollservice Österreich GmbH', 'website' => 'https://www.bios-kontrolle.at/', 'apis' => ['bioqs']
|
||||
],
|
||||
'AT-BIO-402' => [
|
||||
'id' => 'AT-BIO-402', 'countryCode' => 'AT', 'handle' => 'LACON',
|
||||
'name' => 'LACON GmbH ', 'website' => 'https://www.lacon-institut.com/', 'apis' => ['easy-cert']
|
||||
],
|
||||
'AT-BIO-501' => [
|
||||
'id' => 'AT-BIO-501', 'countryCode' => 'AT', 'handle' => 'SLK',
|
||||
'name' => 'SLK GesmbH', 'website' => 'https://slk.at/', 'apis' => ['bioc']
|
||||
],
|
||||
'AT-BIO-901' => [
|
||||
'id' => 'AT-BIO-901', 'countryCode' => 'AT', 'handle' => 'LVA',
|
||||
'name' => 'LVA GmbH', 'website' => 'https://www.lva.at/', 'apis' => []
|
||||
],
|
||||
'AT-BIO-902' => [
|
||||
'id' => 'AT-BIO-902', 'countryCode' => 'AT', 'handle' => 'SGS',
|
||||
'name' => 'SGS Austria Controll-Co. Ges.m.b.H.', 'website' => 'https://www.sgs.com/de-at ', 'apis' => ['bioc']
|
||||
],
|
||||
'AT-BIO-903' => [
|
||||
'id' => 'AT-BIO-903', 'countryCode' => 'AT', 'handle' => 'LKV',
|
||||
'name' => 'LKV Austria Gemeinnützige GmbH', 'website' => 'https://www.lkv.at/', 'apis' => ['bioc', 'lkv']
|
||||
],
|
||||
];
|
||||
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
|
||||
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: 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 !== '/' && str_ends_with($info, '/')) {
|
||||
header('Status: 303');
|
||||
header('Content-Length: 0');
|
||||
header('Location: /organic/' . substr($info, 0, -1));
|
||||
exit;
|
||||
}
|
||||
@@ -22,8 +64,10 @@ if (str_starts_with($info, '/certificates/')) {
|
||||
$id = substr($id, 0, -4);
|
||||
}
|
||||
if (str_contains($id, '/') || !file_exists("certificates/$id.pdf")) {
|
||||
header('Content-Length: 0');
|
||||
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')) {
|
||||
@@ -52,28 +96,32 @@ if (str_starts_with($info, '/certificates/')) {
|
||||
exit;
|
||||
} else if ($info === '/authorities') {
|
||||
header('Content-Type: application/json; charset=UTF-8');
|
||||
echo <<<EOF
|
||||
{"data":[
|
||||
{"id":"AT-BIO-301","countryCode":"AT","handle":"ABG","name":"Austria Bio Garantie GmbH","website":"https://www.bio-garantie.at/","apis":["easy-cert"]},
|
||||
{"id":"AT-BIO-302","countryCode":"AT","handle":"ABG-LW","name":"Austria Bio Garantie – Landwirtschaft GmbH","website":"https://www.bio-garantie.at/","apis":["easy-cert"]},
|
||||
{"id":"AT-BIO-401","countryCode":"AT","handle":"BIOS","name":"BIOS – Biokontrollservice Österreich GmbH","website":"https://www.bios-kontrolle.at/","apis":["bioqs"]},
|
||||
{"id":"AT-BIO-402","countryCode":"AT","handle":"LACON","name":"LACON GmbH ","website":"https://www.lacon-institut.com/","apis":["easy-cert"]},
|
||||
{"id":"AT-BIO-501","countryCode":"AT","handle":"SLK","name":"SLK GesmbH","website":"https://slk.at/","apis":["bioc"]},
|
||||
{"id":"AT-BIO-901","countryCode":"AT","handle":"LVA","name":"LVA GmbH","website":"https://www.lva.at/","apis":[]},
|
||||
{"id":"AT-BIO-902","countryCode":"AT","handle":"SGS","name":"SGS Austria Controll-Co. Ges.m.b.H.","website":"https://www.sgs.com/de-at ","apis":["bioc"]},
|
||||
{"id":"AT-BIO-903","countryCode":"AT","handle":"LKV","name":"LKV Austria Gemeinnützige GmbH","website":"https://www.lkv.at/","apis":["bioc","lkv"]}
|
||||
]}
|
||||
|
||||
EOF;
|
||||
echo "{\"data\":[\n";
|
||||
$first = true;
|
||||
foreach ($AUTHORITIES as $auth) {
|
||||
if (!$first) echo ",\n";
|
||||
echo " " . jenc($auth);
|
||||
$first = false;
|
||||
}
|
||||
echo "\n]}\n";
|
||||
exit;
|
||||
} else if (str_starts_with($info, '/authorities/')) {
|
||||
$code = $parts[2];
|
||||
header('Content-Type: text/plain; charset=UTF-8');
|
||||
echo "Control Authority Code: $code\n";
|
||||
header('Content-Type: application/json; charset=UTF-8');
|
||||
if (array_key_exists($code, $AUTHORITIES)) {
|
||||
echo jenc($AUTHORITIES[$code]);
|
||||
echo "\n";
|
||||
} else {
|
||||
header('Status: 404');
|
||||
header('Content-Length: 22');
|
||||
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];
|
||||
@@ -82,5 +130,6 @@ EOF;
|
||||
exit;
|
||||
}
|
||||
|
||||
header('Content-Length: 0');
|
||||
header('Status: 404');
|
||||
header('Content-Length: 22');
|
||||
echo "{\"error\":\"not found\"}\n";
|
||||
|
||||
Reference in New Issue
Block a user