pandorafms/pandora_console/include/ajax/resources.ajax.php

105 lines
3.1 KiB
PHP
Raw Normal View History

2024-01-22 17:22:23 +01:00
<?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);
2024-01-24 12:15:16 +01:00
$deleteFile = (bool) get_parameter('deleteFile', false);
2024-01-22 17:22:23 +01:00
$prd = new Prd();
if ($getResource === true) {
$type = (string) get_parameter('type', '');
$result = false;
2024-01-24 12:15:16 +01:00
$data = $prd->getOnePrdData($type);
if (empty($data) === false) {
$sql = sprintf(
'SELECT %s FROM %s',
reset($data['items']['value']).', '.reset($data['items']['show']),
$data['items']['table']
);
$result = html_print_label_input_block(
$data['label'],
io_safe_output(
html_print_select_from_sql(
$sql,
'select_value',
'',
'',
'',
0,
true,
false,
true,
false,
false,
false,
GENERIC_SIZE_TEXT,
'w40p',
),
)
);
2024-01-22 17:22:23 +01:00
}
echo $result;
return;
}
if ($exportPrd === true) {
$type = (string) get_parameter('type', '');
$value = (int) get_parameter('value', 0);
$name = (string) get_parameter('name', '');
2024-01-24 12:15:16 +01:00
$data = $prd->exportPrd($type, $value, $name);
$return = '';
if (empty($data) === false) {
$filename = $type.'-'.date('Ymd').'-'.date('His').'.prd';
$file = $config['attachment_store'].'/'.$filename;
$file_pointer = fopen($file, 'a');
if ($file_pointer !== false) {
$write = fwrite($file_pointer, $data);
if ($write === false) {
$return = -2;
} else {
$return = $filename;
}
fclose($file_pointer);
} else {
$return = -1;
}
}
echo $return;
return;
}
if ($deleteFile === true) {
$filename = (string) get_parameter('filename', '');
unlink($config['attachment_store'].'/'.$filename);
2024-01-22 17:22:23 +01:00
}
}