From 891f1dff70a18b9c4a6d7870e08e1536cd5945ca Mon Sep 17 00:00:00 2001 From: Anonymous Contributor Date: Mon, 11 Sep 2023 06:05:50 +0200 Subject: [PATCH] Add API endpoint to make IAR files downloadable --- app/Mcp.php | 3 ++- app/api/DownloadIar.php | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 app/api/DownloadIar.php diff --git a/app/Mcp.php b/app/Mcp.php index 94d16cb..3c8c4fe 100644 --- a/app/Mcp.php +++ b/app/Mcp.php @@ -22,7 +22,8 @@ class Mcp implements ConnectionProvider 'getAccessList' => 'Api\\GetAccessList', 'onlineDisplay' => 'Api\\OnlineDisplay', 'viewerWelcomeSite' => 'Api\\ViewerWelcomePage', - 'runCron' => 'Api\\CronStarter' + 'runCron' => 'Api\\CronStarter', + 'downloadIar' => 'Api\\DownloadIar' ], 'page' => [ 'dashboard' => 'Page\\Dashboard', diff --git a/app/api/DownloadIar.php b/app/api/DownloadIar.php new file mode 100644 index 0000000..9db2749 --- /dev/null +++ b/app/api/DownloadIar.php @@ -0,0 +1,24 @@ +app->getDataDir().DIRECTORY_SEPARATOR.'iars'.DIRECTORY_SEPARATOR.$_GET['id'].'.iar'; + if (file_exists($path)) { + header('Content-Type: '.mime_content_type($path)); + header('Content-Disposition: attachment; filename='.$_GET['id'].'.iar'); + header('Content-Length: '.filesize($path)); + readfile($path); + return; + } + } + + http_response_code(404); + } +}