make selection of config-services downloadable as json e.g. for config-services script

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-04-30 11:26:39 +02:00
parent 422950d386
commit c7226a16d2
3 changed files with 31 additions and 0 deletions

View File

@@ -80,6 +80,8 @@ class Ajax
return $this->editApiKey(); return $this->editApiKey();
case 'getConfigDetails': case 'getConfigDetails':
return $this->getConfigDetails(); return $this->getConfigDetails();
case 'getConfigJsonExport':
return $this->getConfigJsonExport();
default: default:
return $this->errorResponse('Action not found!'); return $this->errorResponse('Action not found!');
} }
@@ -324,4 +326,19 @@ class Ajax
} }
return $this->errorResponse('Not allowed', 403); 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);
}
} }

View File

@@ -104,7 +104,9 @@
{{ lng('admin.configfiles.recommendednote') }} {{ lng('admin.configfiles.recommendednote') }}
</div> </div>
<div class="col-12 col-md-6 text-end"> <div class="col-12 col-md-6 text-end">
<input type="hidden" name="dist" value="{{ distribution }}" />
<button type="button" class="btn btn-outline-secondary" id="selectRecommendedConfig">{{ lng('admin.configfiles.selectrecommended') }}</button> <button type="button" class="btn btn-outline-secondary" id="selectRecommendedConfig">{{ lng('admin.configfiles.selectrecommended') }}</button>
<button type="button" class="btn btn-outline-secondary" id="downloadSelectionAsJson"><i class="fa-solid fa-download"></i> {{ lng('admin.configfiles.downloadselected') }}</button>
<button type="submit" class="btn btn-primary">{{ lng('update.proceed') }}</button> <button type="submit" class="btn btn-primary">{{ lng('update.proceed') }}</button>
</div> </div>
</div> </div>

View File

@@ -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 () { $('.show-config').on('click', function () {
var distro = $(this).data('dist'); var distro = $(this).data('dist');
var section = $(this).data('section'); var section = $(this).data('section');