mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 08:45:12 +02:00
#12687 Added import/export prd
This commit is contained in:
parent
9bdcfb4b4d
commit
95f8519d5d
@ -208,6 +208,9 @@ if ($access_console_node === true) {
|
|||||||
|
|
||||||
$sub['godmode/setup/os']['text'] = __('Operating systems');
|
$sub['godmode/setup/os']['text'] = __('Operating systems');
|
||||||
$sub['godmode/setup/os']['id'] = 'edit_OS';
|
$sub['godmode/setup/os']['id'] = 'edit_OS';
|
||||||
|
|
||||||
|
$sub['godmode/resources/resources_export_import']['text'] = __('Resources export/import');
|
||||||
|
$sub['godmode/resources/resources_export_import']['id'] = 'resources_export_import';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((bool) check_acl($config['id_user'], 0, 'AW') === true) {
|
if ((bool) check_acl($config['id_user'], 0, 'AW') === true) {
|
||||||
|
160
pandora_console/godmode/resources/resources_export_import.php
Normal file
160
pandora_console/godmode/resources/resources_export_import.php
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server list view.
|
||||||
|
*
|
||||||
|
* @category Server
|
||||||
|
* @package Pandora FMS
|
||||||
|
* @subpackage Community
|
||||||
|
* @version 1.0.0
|
||||||
|
* @license See below
|
||||||
|
*
|
||||||
|
* ______ ___ _______ _______ ________
|
||||||
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||||
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||||
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||||
|
*
|
||||||
|
* ============================================================================
|
||||||
|
* Copyright (c) 2005-2024 Pandora FMS
|
||||||
|
* Please see https://pandorafms.com/community/ for full contribution list
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation for version 2.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
* ============================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Load global vars.
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
check_login();
|
||||||
|
|
||||||
|
if (check_acl($config['id_user'], 0, 'PM') === false) {
|
||||||
|
db_pandora_audit(
|
||||||
|
AUDIT_LOG_ACL_VIOLATION,
|
||||||
|
'Trying to access resources exportation and importation'
|
||||||
|
);
|
||||||
|
include 'general/noaccess.php';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once $config['homedir'].'/include/class/Prd.class.php';
|
||||||
|
|
||||||
|
$table = new stdClass();
|
||||||
|
$table->id = 'import_data_table';
|
||||||
|
$table->class = 'databox filter-table-adv';
|
||||||
|
$table->width = '100%';
|
||||||
|
$table->data = [];
|
||||||
|
$table->style = [];
|
||||||
|
$table->size = [];
|
||||||
|
|
||||||
|
$table->data[0][0] = html_print_label_input_block(
|
||||||
|
__('Resource importation'),
|
||||||
|
html_print_input_file('resource_import', true)
|
||||||
|
);
|
||||||
|
|
||||||
|
$table->data[0][1] = html_print_label_input_block(
|
||||||
|
__('Group filter'),
|
||||||
|
html_print_select_groups(false, 'AW', true, 'group', '', '', __('All'), 0, true)
|
||||||
|
);
|
||||||
|
|
||||||
|
html_print_table($table);
|
||||||
|
|
||||||
|
$table = new stdClass();
|
||||||
|
$table->id = 'export_data_table';
|
||||||
|
$table->class = 'databox filter-table-adv';
|
||||||
|
$table->width = '100%';
|
||||||
|
$table->data = [];
|
||||||
|
$table->style = [];
|
||||||
|
$table->size = [];
|
||||||
|
$table->size[0] = '50%';
|
||||||
|
$table->size[1] = '50%';
|
||||||
|
|
||||||
|
// Instance of the prd class.
|
||||||
|
$prd = new Prd();
|
||||||
|
|
||||||
|
$export_type = $prd->getTypesPrd();
|
||||||
|
|
||||||
|
$table->data[0][0] = html_print_label_input_block(
|
||||||
|
__('Export type'),
|
||||||
|
html_print_select(
|
||||||
|
$export_type,
|
||||||
|
'export_type',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
__('None'),
|
||||||
|
0,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
'w40p'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$table->data[1][0] = '';
|
||||||
|
|
||||||
|
$table->data[2][0] = html_print_button(
|
||||||
|
__('Export'),
|
||||||
|
'export_button',
|
||||||
|
false,
|
||||||
|
'',
|
||||||
|
['class' => 'flex_justify invisible_important'],
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
html_print_table($table);
|
||||||
|
|
||||||
|
?>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$("#export_type").change(function(e) {
|
||||||
|
if ($(this).val() === '0') {
|
||||||
|
$("#button-export_button").addClass("invisible_important");
|
||||||
|
$("#export_data_table-1-0").html('');
|
||||||
|
} else {
|
||||||
|
$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
url: "ajax.php",
|
||||||
|
dataType: "html",
|
||||||
|
data: {
|
||||||
|
page: 'include/ajax/resources.ajax',
|
||||||
|
getResource: 1,
|
||||||
|
type: $(this).val(),
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
$("#export_data_table-1-0").append(`${data}`);
|
||||||
|
$("#button-export_button").removeClass("invisible_important");
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
console.error("Fatal error in AJAX call to interpreter order", data)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#button-export_button").click(function(e) {
|
||||||
|
const value = $("#select_value").val();
|
||||||
|
if (value !== '0') {
|
||||||
|
$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
url: "ajax.php",
|
||||||
|
dataType: "html",
|
||||||
|
data: {
|
||||||
|
page: 'include/ajax/resources.ajax',
|
||||||
|
exportPrd: 1,
|
||||||
|
type: $("#export_type").val(),
|
||||||
|
value: value,
|
||||||
|
name: $("#select_value").text(),
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
console.error("Fatal error in AJAX call to interpreter order", data)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
74
pandora_console/include/ajax/resources.ajax.php
Normal file
74
pandora_console/include/ajax/resources.ajax.php
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Pandora FMS- https://pandorafms.com.
|
||||||
|
* ==================================================
|
||||||
|
* Copyright (c) 2005-2023 Pandora FMS
|
||||||
|
* Please see https://pandorafms.com/community/ for full contribution list
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
* as published by the Free Software Foundation; version 2
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if ((bool) is_ajax() === true) {
|
||||||
|
include_once $config['homedir'].'/include/class/Prd.class.php';
|
||||||
|
|
||||||
|
$getResource = (bool) get_parameter('getResource', false);
|
||||||
|
$exportPrd = (bool) get_parameter('exportPrd', false);
|
||||||
|
|
||||||
|
$prd = new Prd();
|
||||||
|
|
||||||
|
if ($getResource === true) {
|
||||||
|
$type = (string) get_parameter('type', '');
|
||||||
|
$result = false;
|
||||||
|
|
||||||
|
$check = $prd->getOnePrdData($type);
|
||||||
|
if (empty($check) === false) {
|
||||||
|
switch ($type) {
|
||||||
|
case 'visual_console':
|
||||||
|
$result = html_print_label_input_block(
|
||||||
|
__('Visual console'),
|
||||||
|
io_safe_output(
|
||||||
|
html_print_select_from_sql(
|
||||||
|
'SELECT id, name FROM tlayout',
|
||||||
|
'select_value',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
0,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
GENERIC_SIZE_TEXT,
|
||||||
|
'w40p',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// TODO.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $result;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($exportPrd === true) {
|
||||||
|
$type = (string) get_parameter('type', '');
|
||||||
|
$value = (int) get_parameter('value', 0);
|
||||||
|
$name = (string) get_parameter('name', '');
|
||||||
|
|
||||||
|
$prd->exportPrd($type, $value, $name);
|
||||||
|
}
|
||||||
|
}
|
281
pandora_console/include/class/Prd.class.php
Normal file
281
pandora_console/include/class/Prd.class.php
Normal file
@ -0,0 +1,281 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Tips to Pandora FMS feature.
|
||||||
|
*
|
||||||
|
* @category Class
|
||||||
|
* @package Pandora FMS
|
||||||
|
* @subpackage Tips Window
|
||||||
|
* @version 1.0.0
|
||||||
|
* @license See below
|
||||||
|
*
|
||||||
|
* ______ ___ _______ _______ ________
|
||||||
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||||
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||||
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||||
|
*
|
||||||
|
* ============================================================================
|
||||||
|
* Copyright (c) 2005-2024 Pandora FMS
|
||||||
|
* Please see https://pandorafms.com/community/ for full contribution list
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation for version 2.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
* ============================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Begin.
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Prd.
|
||||||
|
*/
|
||||||
|
class Prd
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prd data.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $prdData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Column references.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $columnRefs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Json references.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $jsonRefs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some error message.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $message;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @throws Exception On error.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->prdData = [
|
||||||
|
'visual_console' => [
|
||||||
|
'label' => __('Visual console'),
|
||||||
|
'items' => [
|
||||||
|
'table' => 'tlayout',
|
||||||
|
'value' => 'id',
|
||||||
|
'show' => 'name',
|
||||||
|
],
|
||||||
|
'data' => [
|
||||||
|
[
|
||||||
|
'table' => 'tlayout',
|
||||||
|
'ref' => 'id',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'table' => 'tlayout_data',
|
||||||
|
'ref' => 'id_layout',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->columnRefs = [
|
||||||
|
'tlayout_data' => [
|
||||||
|
'id_agent' => [
|
||||||
|
'table' => 'tagente',
|
||||||
|
'id' => 'id_agente',
|
||||||
|
'column' => 'nombre',
|
||||||
|
],
|
||||||
|
'id_agente_modulo' => [
|
||||||
|
'table' => 'tagente_modulo',
|
||||||
|
'id' => 'id_agente_modulo',
|
||||||
|
'column' => 'nombre',
|
||||||
|
'join' => [
|
||||||
|
'id_agente' => [
|
||||||
|
'table' => 'tagente',
|
||||||
|
'id' => 'id_agente',
|
||||||
|
'column' => 'nombre',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->jsonRefs = [
|
||||||
|
'twidget_dashboard' => [
|
||||||
|
'options' => [
|
||||||
|
'agent' => [
|
||||||
|
'array' => false,
|
||||||
|
'table' => 'tagente',
|
||||||
|
'id' => 'id_agente',
|
||||||
|
'column' => 'nombre',
|
||||||
|
],
|
||||||
|
'module' => [
|
||||||
|
'array' => false,
|
||||||
|
'table' => 'tagente_modulo',
|
||||||
|
'id' => 'id_agente_modulo',
|
||||||
|
'column' => 'nombre',
|
||||||
|
'join' => [
|
||||||
|
'id_agente' => [
|
||||||
|
'table' => 'tagente',
|
||||||
|
'id' => 'id_agente',
|
||||||
|
'column' => 'nombre',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->message = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a JSON error.
|
||||||
|
*
|
||||||
|
* @param string $msg Error message.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function error(string $msg)
|
||||||
|
{
|
||||||
|
echo json_encode(
|
||||||
|
['error' => $msg]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get $prdData.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getPrdData(): array
|
||||||
|
{
|
||||||
|
return $this->prdData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get one $prdData.
|
||||||
|
*
|
||||||
|
* @param string $item Item to be searched in array.
|
||||||
|
*
|
||||||
|
* @return boolean|array
|
||||||
|
*/
|
||||||
|
public function getOnePrdData(string $item): bool|array
|
||||||
|
{
|
||||||
|
if (isset($this->prdData[$item]) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->prdData[$item];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get $columnRefs.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getColumnRefs(): array
|
||||||
|
{
|
||||||
|
return $this->columnRefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get one $columnRefs.
|
||||||
|
*
|
||||||
|
* @param string $item Item to be searched in array.
|
||||||
|
*
|
||||||
|
* @return boolean|array
|
||||||
|
*/
|
||||||
|
public function getOneColumnRefs(string $item): bool|array
|
||||||
|
{
|
||||||
|
if (isset($this->columnRefs[$item]) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->columnRefs[$item];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get $jsonRefs.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getJsonRefs(): array
|
||||||
|
{
|
||||||
|
return $this->jsonRefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get types of prd.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getTypesPrd(): array
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
foreach ($this->prdData as $key => $value) {
|
||||||
|
$result[$key] = $value['label'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export prd.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function exportPrd(string $type, $value, $name) :array
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
$prd_data = $this->getOnePrdData($type);
|
||||||
|
if (empty($prd_data) === false) {
|
||||||
|
$result['prd_data'] = [
|
||||||
|
'type' => $type,
|
||||||
|
'name' => $name,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($prd_data['data'] as $key => $element) {
|
||||||
|
$sql = sprintf(
|
||||||
|
'SELECT * FROM %s WHERE %s = %s',
|
||||||
|
$element['table'],
|
||||||
|
$element['ref'],
|
||||||
|
$value,
|
||||||
|
);
|
||||||
|
|
||||||
|
$test = db_get_all_rows_sql($sql);
|
||||||
|
|
||||||
|
// $result[$element['table']]
|
||||||
|
// hd($test, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user