old htb folders
This commit is contained in:
2023-08-29 21:53:22 +02:00
parent 62ab804867
commit 82b0759f1e
21891 changed files with 6277643 additions and 0 deletions

66
HTB/interface/index.php Normal file
View File

@@ -0,0 +1,66 @@
<?php
require __DIR__ . '/vendor/autoload.php';
use Dompdf\Dompdf;
use Dompdf\Options;
$router = new \Bramus\Router\Router();
$router->set404('/api(/.*)?', function () {
header('HTTP/1.1 404 Not Found');
header('Content-Type: application/json');
$jsonArray = array();
$jsonArray['status'] = "404";
$jsonArray['status_text'] = "route not defined";
echo json_encode($jsonArray);
});
$router->post('/api/html2pdf', function () {
$json_data = json_decode(file_get_contents('php://input'), true);
if (isset($json_data['html'])) {
header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
$html = $json_data['html'];
$md5 = md5($html);
$attachment = sprintf("/tmp/%s.pdf", $md5);
if (!file_exists($attachment)) {
$options = new Options();
$options->setIsRemoteEnabled(true);
$dompdf = new Dompdf($options);
$dompdf->loadHtml($html);
$dompdf->setPaper('A5');
$dompdf->render();
$output = $dompdf->output();
file_put_contents($attachment, $output);
header("X-Local-Cache: miss");
} else {
header("X-Local-Cache: hit");
}
header("Cache-Control: public");
header("Content-Type: application/pdf");
header("Content-Transfer-Encoding: Binary");
header("Content-Length:" . filesize($attachment));
header("Content-Disposition: attachment; filename=export.pdf");
readfile($attachment);
} else {
header("HTTP/1.1 422 Unprocessable Entity");
header("Content-Type: application/json");
echo json_encode(array("status_text" => "missing parameters"));
}
});
$router->run();