mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-14 08:34:39 +00:00
Firewall: Aliases: support partial alias exports, closes https://github.com/opnsense/core/issues/8320
Pass selected items to export button and filter results, while here, also pretty-print the results so their easier to inspect locally.
This commit is contained in:
parent
a3d588cca2
commit
09eba5d82f
@ -376,10 +376,27 @@ class AliasController extends ApiMutableModelControllerBase
|
||||
*/
|
||||
public function exportAction()
|
||||
{
|
||||
if ($this->request->isGet()) {
|
||||
if ($this->request->isGet() || $this->request->isPost()) {
|
||||
if (!empty($this->request->get('ids'))) {
|
||||
/* partial select */
|
||||
if (is_array($this->request->get('ids'))) {
|
||||
$items = $this->request->get('ids');
|
||||
} else {
|
||||
$items = explode(',', (string)$this->request->get('ids'));
|
||||
}
|
||||
$payload = ['aliases' => ['alias' => []]];
|
||||
foreach ($this->getModel()->aliases->alias->iterateItems() as $key => $node) {
|
||||
if (in_array($key, $items)) {
|
||||
$payload['aliases']['alias'][$key] = $this->getRawNodes($node);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* full dump */
|
||||
$payload = $this->getRawNodes($this->getModel());
|
||||
}
|
||||
// return raw, unescaped since this content is intended for direct download
|
||||
$this->response->setContentType('application/json', 'UTF-8');
|
||||
$this->response->setContent(json_encode($this->getRawNodes($this->getModel())));
|
||||
$this->response->setContent(json_encode($payload, JSON_PRETTY_PRINT));
|
||||
} else {
|
||||
throw new UserException("Unsupported request type");
|
||||
}
|
||||
|
||||
@ -446,7 +446,12 @@
|
||||
* export all configured aliases to json
|
||||
*/
|
||||
$("#exportbtn").click(function(){
|
||||
ajaxGet("/api/firewall/alias/export", {}, function(data, status){
|
||||
let selected_rows = $("#grid-aliases").bootgrid("getSelectedRows");
|
||||
let params = {};
|
||||
if (selected_rows.length > 0) {
|
||||
params['ids'] = selected_rows;
|
||||
}
|
||||
ajaxCall("/api/firewall/alias/export", params, function(data, status){
|
||||
if (data.aliases) {
|
||||
let output_data = JSON.stringify(data, null, 2);
|
||||
let a_tag = $('<a></a>').attr('href','data:application/json;charset=utf8,' + encodeURIComponent(output_data))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user