From c7226a16d2a7a5f56c23ff0615148ff100fa6ab5 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Sat, 30 Apr 2022 11:26:39 +0200 Subject: [PATCH] make selection of config-services downloadable as json e.g. for config-services script Signed-off-by: Michael Kaufmann --- lib/Froxlor/Ajax/Ajax.php | 17 +++++++++++++++++ .../Froxlor/settings/configuration.html.twig | 2 ++ .../Froxlor/src/js/components/configfiles.js | 12 ++++++++++++ 3 files changed, 31 insertions(+) diff --git a/lib/Froxlor/Ajax/Ajax.php b/lib/Froxlor/Ajax/Ajax.php index 200e64d5..d6f8b3ab 100644 --- a/lib/Froxlor/Ajax/Ajax.php +++ b/lib/Froxlor/Ajax/Ajax.php @@ -80,6 +80,8 @@ class Ajax return $this->editApiKey(); case 'getConfigDetails': return $this->getConfigDetails(); + case 'getConfigJsonExport': + return $this->getConfigJsonExport(); default: return $this->errorResponse('Action not found!'); } @@ -324,4 +326,19 @@ class Ajax } return $this->errorResponse('Not allowed', 403); } + + /** + * download JSON export of config-selection + */ + private function getConfigJsonExport() + { + if (isset($this->userinfo['adminsession']) && $this->userinfo['adminsession'] == 1 && $this->userinfo['change_serversettings'] == 1) { + $params = $_GET; + unset($params['action']); + unset($params['finish']); + header('Content-disposition: attachment; filename=froxlor-config-' . time() . '.json'); + return $this->jsonResponse($params); + } + return $this->errorResponse('Not allowed', 403); + } } diff --git a/templates/Froxlor/settings/configuration.html.twig b/templates/Froxlor/settings/configuration.html.twig index e8e5cc5a..2d29a5d6 100644 --- a/templates/Froxlor/settings/configuration.html.twig +++ b/templates/Froxlor/settings/configuration.html.twig @@ -104,7 +104,9 @@ {{ lng('admin.configfiles.recommendednote') }}
+ +
diff --git a/templates/Froxlor/src/js/components/configfiles.js b/templates/Froxlor/src/js/components/configfiles.js index 6debff0b..4ab51b03 100644 --- a/templates/Froxlor/src/js/components/configfiles.js +++ b/templates/Froxlor/src/js/components/configfiles.js @@ -12,6 +12,18 @@ $(function () { }) }); + /* + * export/download JSON file (e.g. for usage with config-services) + */ + $('#downloadSelectionAsJson').on('click', function () { + var formData = $(this).closest('form').serialize(); + window.location = "lib/ajax.php?action=getConfigJsonExport&" + formData; + }); + + /* + * open modal window to show selected config-commands/files + * for selected daemon + */ $('.show-config').on('click', function () { var distro = $(this).data('dist'); var section = $(this).data('section');