Compare commits

...

4 Commits

9 changed files with 462 additions and 89 deletions

99
www/organic/external/bioc/operators.php vendored Normal file
View File

@@ -0,0 +1,99 @@
<?php
header('Access-Control-Allow-Origin: *');
if ($_SERVER['REQUEST_METHOD'] !== 'GET' && $_SERVER['REQUEST_METHOD'] !== 'HEAD') {
header('Status: 405');
header('Content-Length: 0');
header('Allow: GET, HEAD');
exit;
}
function jenc($data): string {
return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
$info = $_SERVER['PATH_INFO'];
if ($info !== '') {
$id = substr($info, 1);
header('Status: 404');
header('Content-Length: 0');
exit;
}
$source_groups = [
[ '',
'0892fdd7-6649-cb3b-75ef-a60649cfebfd', 'fde4ccef-0f36-4db9-9f2f-9bb6009c872a',
'8e6d20d3-6bbe-c7ae-7a77-fb7fa80ee291', '830b3bd7-f1da-e20e-300d-e561bfb8205b',
'ed025d59-056f-ffd0-79e0-05348fe88d59', '95d536c8-c869-9f72-1bce-4256a2a4ce49'
], [ '',
'bef6b49a-3186-ba7f-fffb-281bfb4ca2d2', 'fc7a0cc3-c4b4-a4fb-5b7e-5cf9b68ed198',
'9aecd829-8f3c-6829-449f-9cb511e0c1ff', 'e7a7089b-0fd7-60b9-48af-c0988a90ec37',
'63d570d8-0ab2-b793-fe11-62e0777e4236'
],
];
$country = [
'AT' => 'a1e51f85-27b5-a1e3-65f7-561569884d38',
'DE' => '1be4d468-ba47-08f1-f048-f45869af856f',
][$_GET['country'] ?? null] ?? null;
$postalCode = $_GET['postalCode'] ?? null;
$name = $_GET['name'] ?? null;
$idNr = $_GET['idNr'] ?? null;
if ($country === null) {
header('Status: 400');
header('Content-Length: 0');
exit;
}
$data = [];
$url = "https://www.bioc.info/search/producerSearchQuery?search[name]=" . urlencode($name) . "&search[citycode]=" . urlencode($postalCode) . "&search[operatorId]=" . urlencode($idNr) . "&search[country]=$country";
if ($_GET['allDBs'] === 'true') {
$s = curl_init($url . implode('&sources[]=', $source_groups[0]));
curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
if (($json = curl_exec($s)) === false) {
header('Status: 500');
header('Content-Length: 0');
exit;
}
$res = json_decode($json, true)['results'];
foreach ($res as $r) {
$data[$r['id']] = $r['row'];
}
}
$s = curl_init($url . implode('&sources[]=', $source_groups[1]));
curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
if (($json = curl_exec($s)) === false) {
header('Status: 500');
header('Content-Length: 0');
exit;
}
$res = json_decode($json, true)['results'];
foreach ($res as $r) {
$data[$r['id']] = $r['row'];
}
header('Content-Type: application/json; charset=UTF-8');
$first = true;
echo "{\"data\":[\n";
foreach ($data as $id => $row) {
if (!$first) echo ",\n";
$row = explode("</", $row);
$auth = explode(' ', substr($row[3], strrpos($row[3], '>') + 1), 2);
echo " ";
echo jenc([
'id' => $id,
'name' => substr($row[0], strrpos($row[0], '>') + 1),
'postalCode' => substr($row[1], strrpos($row[1], '>') + 1),
'city' => substr($row[2], strrpos($row[2], '>') + 1),
'authorityCode' => $auth[0],
'authorityName' => $auth[1],
]);
$first = false;
}
echo "\n]}\n";

54
www/organic/external/bioqs/.attachment.py vendored Executable file
View File

@@ -0,0 +1,54 @@
#!/bin/env python3
import re
import argparse
import requests
import sys
BASE_URL = 'https://www.bioqs.at'
URL = f'{BASE_URL}/ACM/faces/form/cms/portal/index.jsp'
ACTION_RE = re.compile(r'action="([^"]*)"')
HIDDEN_RE = re.compile(r'<input type="hidden" name="([^"]*)" .*?value="([^"]*)"')
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument('cert_nr', type=str)
args = parser.parse_args()
s = requests.Session()
r = s.get(f'{URL}?menu_sid=5002')
uri = ACTION_RE.findall(r.text)[0]
hidden = {m[1]: m[2] for m in HIDDEN_RE.finditer(r.text)}
r = s.post(f'{BASE_URL}{uri}', data={
'PartnerCertSearchForm:pcs_seqidall': args.cert_nr,
'PartnerCertSearchForm:button_search': 'Suche starten...',
'PartnerCertSearchForm_SUBMIT': '1',
'javax.faces.ViewState': hidden['javax.faces.ViewState'],
})
p1 = r.text.find(f'>{args.cert_nr}<')
p2 = r.text.find('id="', p1)
p3 = r.text.find('"', p2 + 4)
if p1 == -1 or p2 == -1 or p3 == -1:
exit(1)
id = r.text[p2 + 4:p3]
r = s.post(f'{BASE_URL}{uri}', data={
'PartnerCertSearchForm:_idcl': id,
'PartnerCertSearchForm_SUBMIT': '1',
'javax.faces.ViewState': hidden['javax.faces.ViewState'],
})
if 'Content-Disposition' in r.headers:
dispo = r.headers['Content-Disposition']
if 'filename="' in dispo:
filename = dispo[dispo.find('filename="') + 10:dispo.rfind('"')]
print(filename, file=sys.stderr)
sys.stdout.buffer.write(r.content)
if __name__ == '__main__':
main()

92
www/organic/external/bioqs/.operators.py vendored Executable file
View File

@@ -0,0 +1,92 @@
#!/bin/env python3
import re
import argparse
import requests
import html
import json
import urllib.parse
BASE_URL = 'https://www.bioqs.at'
URL = f'{BASE_URL}/ACM/faces/form/cms/portal/index.jsp'
ACTION_RE = re.compile(r'action="([^"]*)"')
HIDDEN_RE = re.compile(r'<input type="hidden" name="([^"]*)" .*?value="([^"]*)"')
ROW_RE = re.compile(r'<tr[^>]*>\s*(.*?)\s*</tr>', re.DOTALL)
UNCOLLAPSED_ROW_RE = re.compile(r'<tr style="">(\s*<td>\s*(.*?)\s*</td>\s*){7}</tr>', re.DOTALL)
COLLAPSED_ROW_RE = re.compile(r'<table width=[^>]*>\s*(.*?)\s*</table>', re.DOTALL)
TD_RE = re.compile(r'<td[^>]*>\s*(.*?)\s*</td>', re.DOTALL)
TAG_RE = re.compile(r'<[^>]*>')
SPACE_RE = re.compile(r'\s+')
ATTACHMENT_RE = re.compile(r"\[\['cert_attachment_sid','([^']*)'\]\]")
def remove_tags(text: str) -> str:
return SPACE_RE.sub(' ', html.unescape(TAG_RE.sub(' ', text))).strip()
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument('query', type=str)
args = parser.parse_args()
query = {'PartnerCertSearchForm:pcs_' + q.split('=', 1)[0]: urllib.parse.unquote(q.split('=', 1)[-1]) for q in args.query.split('&')}
s = requests.Session()
r = s.get(f'{URL}?menu_sid=5002')
uri = ACTION_RE.findall(r.text)[0]
hidden = {m[1]: m[2] for m in HIDDEN_RE.finditer(r.text)}
r = s.post(f'{BASE_URL}{uri}', data={
**query,
'PartnerCertSearchForm:button_search': 'Suche starten...',
'PartnerCertSearchForm_SUBMIT': '1',
'javax.faces.ViewState': hidden['javax.faces.ViewState'],
})
result_table = r.text[r.text.find('<table'):r.text.rfind('</table>') + 8]
uncollapsed_rows = [tuple(remove_tags(m[1])
for m in TD_RE.finditer(row[0]))
for row in UNCOLLAPSED_ROW_RE.finditer(result_table)]
collapsed_rows = [[tuple(remove_tags((ATTACHMENT_RE.search(m[1]) or m)[1]) for m in TD_RE.finditer(row[1]))
for row in ROW_RE.finditer(tbl[0])]
for tbl in COLLAPSED_ROW_RE.finditer(result_table)]
print('[')
first = True
for row, tbl in zip(uncollapsed_rows, collapsed_rows):
meta = {}
certificates = []
for srow in tbl:
if len(srow) == 1:
[k,v] = srow[0].split(':', 1)
meta[k.strip()] = v.strip()
continue
if len(srow) == 0:
continue
certificates.append({
'nr': srow[0],
'validFrom': '-'.join(reversed(srow[1].split('-'))),
'validTo': '-'.join(reversed(srow[2].split('-'))),
'type': srow[3],
'attachmentSid': srow[4],
'url': f'https://elwig.at/organic/external/bioqs/attachments/{urllib.parse.quote(srow[0])}',
})
if not first:
print(',', flush=True)
print(' ', json.dumps({
'idNr': row[0],
'lfbisNr': row[1] or None,
'name': row[2],
'postalCode': row[3],
'city': row[4],
'address': row[5],
'autorityName': meta['Kontrollstelle'],
'productGroups': meta['Bereiche'],
'certificates': certificates,
}, ensure_ascii=False), end='')
first = False
print('\n]')
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,36 @@
<?php
header('Access-Control-Allow-Origin: *');
if ($_SERVER['REQUEST_METHOD'] !== 'GET' && $_SERVER['REQUEST_METHOD'] !== 'HEAD') {
header('Status: 405');
header('Content-Length: 0');
header('Allow: GET, HEAD');
exit;
}
$info = $_SERVER['PATH_INFO'];
if ($info === '') {
header('Status: 404');
header('Content-Length: 0');
exit;
}
$certId = substr($info, 1);
$file = tmpfile();
if (!$file) {
header('Status: 500');
header('Content-Length: 0');
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');
exit;
}
header('Content-Type: application/pdf');
header('Content-Length: ' . filesize($filename));
header('Content-Disposition: inline; filename="' . $pdfName . '"');
readfile($filename);

View File

@@ -0,0 +1,43 @@
<?php
header('Access-Control-Allow-Origin: *');
if ($_SERVER['REQUEST_METHOD'] !== 'GET' && $_SERVER['REQUEST_METHOD'] !== 'HEAD') {
header('Status: 405');
header('Content-Length: 0');
header('Allow: GET, HEAD');
exit;
}
$info = $_SERVER['PATH_INFO'];
if ($info !== '') {
header('Status: 404');
header('Content-Length: 0');
exit;
}
$query = [];
if (isset($_GET['country'])) {
$query[] = 'country=' . [
'AT' => '1',
'DE' => '2',
][$_GET['country']] ?? '';
}
if (isset($_GET['postalCode'])) {
$query[] = 'zipcode=' . urlencode($_GET['postalCode']);
}
if (isset($_GET['name'])) {
$query[] = 'aname=' . urlencode($_GET['name']);
}
if (isset($_GET['idNr'])) {
$query[] = 'clientcode=' . urlencode($_GET['idNr']);
}
if (isset($_GET['lfbisNr'])) {
$query[] = 'lfbis=' . urlencode($_GET['lfbisNr']);
}
header('Content-Type: application/json; charset=UTF-8');
echo "{\"data\":";
passthru("python3 .operators.py " . escapeshellarg(implode('&', $query)));
echo "}\n";

View File

@@ -231,7 +231,7 @@ $replace = [
'"CountryCode":' => '"countryCode":',
'"xx"' => 'null',
'"XX"' => 'null',
'""' => 'null',
':""' => ':null',
];
$replaceSed = array_map(fn($v, $k): string => "s/$k/$v/", $replace, array_keys($replace));

33
www/organic/external/lkv/operators.php vendored Normal file
View File

@@ -0,0 +1,33 @@
<?php
header('Access-Control-Allow-Origin: *');
if ($_SERVER['REQUEST_METHOD'] !== 'GET' && $_SERVER['REQUEST_METHOD'] !== 'HEAD') {
header('Status: 405');
header('Content-Length: 0');
header('Allow: GET, HEAD');
exit;
}
function jenc($data): string {
return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
$info = $_SERVER['PATH_INFO'];
if ($info !== '') {
header('Status: 404');
header('Content-Length: 0');
exit;
}
header('Content-Type: application/json; charset=UTF-8');
echo "{\"data\":[\n";
passthru(<<<EOF
curl -s 'https://lkv.at/at/zertifizierung/themen/BIO/zertifizierte-BIO-Betriebe.php' | grep '<tr' -A 3 \
| sed 's@<tr>@ {@;s@</tr>@ },@;s@<td><a .*href="\([^"]*\)".*>\(.*\)</a></td>@ "certUrl":"\\1","certNr":"\\2",@;s@<td>\(.*\)<br/>\(.*\)<br/>\([0-9]*\) \(.*\)</td>@ "name":"\\1","address":"\\2","postalCode":"\\3","city":"\\4"@;s@<td>\(.*\)<br/>\(.*\)</td>@ "name":"\\1","type":"\\2"@;\$s/.$//' \
| sed 's@"certUrl":"\(/[^"]*\)"@"certUrl":"https://lkv.at\\1"@' \
| sed 's@\s*",@",@g;s@:"\s*@:"@g'
EOF);
echo "]}\n";

View File

@@ -51,8 +51,20 @@ if (str_starts_with($info, '/certificates/')) {
exit;
} else if ($info === '/authorities') {
header('Content-Length: 0');
header('Status: 501');
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;
exit;
} else if (str_starts_with($info, '/authorities/')) {
$code = $parts[2];

View File

@@ -40,73 +40,47 @@ function jenc($data): string {
return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
$file = tmpfile();
$headerfile = tmpfile();
if (!$file || !$headerfile) {
header('Status: 500');
header('Content-Length: 0');
exit;
}
$filename = stream_get_meta_data($file)['uri'];
$headerfilename = stream_get_meta_data($headerfile)['uri'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$stdin = fopen("php://input", "rb");
while (!feof($stdin)) {
if (($data = fread($stdin, 8192)) === false)
break;
fwrite($file, $data);
}
fclose($stdin);
} else {
if (exec("curl -s -D " . escapeshellarg($headerfilename) . " -o " . escapeshellarg($filename) . " " . escapeshellarg($url)) === false) {
header('Status: 500');
header('Content-Length: 0');
exit;
}
}
if ($format === 'text') {
header('Content-Type: text/plain; charset=UTF-8');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$fd_spec = [
0 => ["pipe", "r"], // stdin
1 => ["pipe", "w"], // stdout
2 => ["pipe", "w"], // stderr
];
$process = proc_open(['pdftotext', '-raw', '-', '-'], $fd_spec, $pipes);
$input = fopen("php://input", "rb");
while (!feof($input)) {
if (($buffer = fread($input, 8192)) === false)
break;
fwrite($pipes[0], $buffer);
}
fclose($input);
fclose($pipes[0]);
fpassthru($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$return_value = proc_close($process);
} else {
passthru("curl -s '" . escapeshellarg($url) . "' | pdftotext -raw - -");
}
passthru("pdftotext -raw " . escapeshellarg($filename) . " -");
} else if ($format === 'sig') {
header('Content-Type: text/plain; charset=UTF-8');
passthru("pdfsig " . escapeshellarg($filename));
} else if ($format === 'json') {
header('Content-Type: application/json; charset=UTF-8');
$fd_spec = [
0 => ["pipe", "r"], // stdin
1 => ["pipe", "w"], // stdout
2 => ["pipe", "w"], // stderr
];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$process = proc_open(['pdftotext', '-raw', '-', '-'], $fd_spec, $pipes);
$input = fopen("php://input", "rb");
while (!feof($input)) {
if (($buffer = fread($input, 8192)) === false)
break;
fwrite($pipes[0], $buffer);
}
fclose($input);
} else {
$process = proc_open(
['bash', '-c',
"curl -s " . escapeshellarg($url) . " | " .
"pdftotext -raw - -"],
$fd_spec,
$pipes
);
}
fclose($pipes[0]);
$text = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$return_value = proc_close($process);
if ($stderr !== '') {
if (exec("pdftotext -raw " . escapeshellarg($filename) . " -", $text) === false) {
header('Status: 500');
header('Content-Length: ' . strlen($stderr));
header('Content-Type: text/plain');
exit($stderr);
header('Content-Length: 0');
exit;
}
$text = implode("\n", $text);
exec("pdfsig " . escapeshellarg($filename), $sig);
$sig = implode("\n", $sig);
$r = preg_match('@([a-z]{2}) (https://webgate\.ec\.europa\.eu/tracesnt/directory/publication/organic-operator/(.*?)\.pdf) (\d+) / (\d+)@', $text, $matches);
if ($r === 1) {
@@ -164,7 +138,7 @@ if ($format === 'text') {
$operator = preg_split('@\s+@', trim($data['I.3']));
$p1 = array_search($splitAddr, $operator);
$p2 = array_search($splitCountry, $operator);
$operatorName = implode(' ', array_filter($operator, fn($k,$i) => $i > 0 && $i < $p1, ARRAY_FILTER_USE_BOTH));
$operatorName = trim(implode(' ', array_filter($operator, fn($k,$i) => $i > 0 && $i < $p1, ARRAY_FILTER_USE_BOTH)), ', ');
[$opAddr, $opPostal, $opCity] = get_address($operator, $p1 + 1, $p2 - 1);
$authority = preg_split('@\s+@', trim($data['I.4']));
@@ -189,6 +163,31 @@ if ($format === 'text') {
$valid1 = implode('-', array_reverse(explode('/', $matches[0][0])));
$valid2 = implode('-', array_reverse(explode('/', $matches[1][0])));
$sigs = [];
foreach (array_slice(explode("\nSignature #", $sig), 1) as $s) {
$sData = [];
$sData2 = [];
preg_match_all('/\n {2}- (([^:\n]*): )?([^\n]*)/', $s, $matches, PREG_SET_ORDER);
foreach ($matches as $m) {
if (strlen($m[2]) === 0) {
$sData2[] = $m[3];
} else {
$sData[$m[2]] = $m[3];
}
}
$sigs[] = [
'signerCommonName' => $sData['Signer Certificate Common Name'],
'valid' => $sData['Signature Validation'] === 'Signature is Valid.',
'trusted' => $sData['Certificate Validation'] === 'Certificate is Trusted.',
'totalDocument' => in_array('Total document signed', $sData2),
'timestamp' => gmdate('Y-m-d\TH:i:s\Z', strtotime($sData['Signing Time'])),
'type' => $sData['Signature Type'],
'hashAlgorithm' => $sData['Signing Hash Algorithm'],
'signerDistinguishedName' => $sData['Signer full Distinguished Name'],
'fieldName' => $sData['Signature Field Name'],
];
}
echo "{\"type\":\"traces\",\"lang\":\"$lang\",\"id\":\"$certId\",\"status\":\"$statusMap[$status]\"";
echo ",\n \"operator\":{\"id\":" . jenc($operatorId).
',"groupOfOperators":' . jenc(!str_starts_with($data['I.2'], '☑')) .
@@ -207,23 +206,34 @@ if ($format === 'text') {
",\n \"productCategories\":" . jenc($products) .
",\n \"validFrom\":" . jenc($valid1) .
',"validTo":' . jenc($valid2) .
",\n \"url\":\"$certUrl\"\n}\n";
} else {
echo "{\"type\":\"unknown\"}\n";
",\n \"url\":\"$certUrl\"" .
",\n \"digitalSignatures\":" . jenc($sigs) .
"\n}\n";
exit;
}
} else {
$fd_spec = [
0 => ["pipe", "r"], // stdin
1 => ["pipe", "w"], // stdout
2 => ["pipe", "w"], // stderr
3 => ["pipe", "w"], // headers
];
$process = proc_open(['curl', '-s', '-D', '/dev/fd/3', $url], $fd_spec, $pipes);
fclose($pipes[0]);
if (preg_match('/AT-BIO-[0-9]{3}/', $text, $matches) === 1) {
$authorityId = $matches[0];
$certId = null;
$certNr = null;
if (preg_match("/$authorityId\.040-[0-9]{7}\.[0-9]{4}\.[0-9]{3}/", $text, $matches) === 1)
$certId = $matches[0];
if (preg_match_all("/\b[0-9]+([._-])[0-9]+\g{-1}[0-9]+\b/", $text, $matches, PREG_SET_ORDER) !== false) {
foreach ($matches as $m) {
if (strlen($m[0]) > 10 && !str_ends_with($certId, $m[0]))
$certNr = $m[0];
}
}
echo "{\"type\":\"$authorityId\",\"lang\":\"de\",\"id\":" . jenc($certId) . ",\"nr\":" . jenc($certNr);
echo ",\n \"operator\":{},\n \"authority\":{\"id\":" . jenc($authorityId) . "}}\n";
exit;
}
echo "{\"type\":\"unknown\"}\n";
} else {
$headers = [];
$status_code = null;
while (($line = fgets($pipes[3])) !== false) {
foreach (explode("\n", file_get_contents($headerfilename)) as $line) {
if (trim($line) === '') break;
if ($status_code === null) {
$status_code = intval(explode(' ', $line)[1]);
@@ -236,9 +246,8 @@ if ($format === 'text') {
$v = trim($v);
$headers[$k] = $v;
}
fclose($pipes[3]);
if ($status_code === 200 && str_starts_with($headers['content-type'], "application/pdf")) {
if (str_starts_with($headers['content-type'], "application/pdf")) {
header('Content-Type: application/pdf');
$content_length = null;
if (isset($headers['content-length'])) {
@@ -246,20 +255,15 @@ if ($format === 'text') {
header('Content-Length: ' . $headers['content-length']);
}
$parts = explode('/', $url);
$filename = $parts[sizeof($parts) - 1];
$realFilename = $parts[sizeof($parts) - 1];
if (isset($headers['content-disposition'])) {
preg_match('@filename="(.*?)"@', $headers['content-disposition'], $matches);
$filename = $matches[1];
$realFilename = $matches[1];
}
header('Content-Disposition: inline; filename="' . $filename . '"');
fpassthru($pipes[1]);
header('Content-Disposition: inline; filename="' . $realFilename . '"');
fpassthru($file);
} else {
header('Status: 500');
header('Content-Length: 0');
}
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$return_value = proc_close($process);
}