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

116 lines
3.6 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,
2024-02-08 15:42:00 +01:00
'w90p',
2024-01-24 12:15:16 +01:00
),
2024-02-08 15:42:00 +01:00
),
[
'div_style' => 'display: flex; flex-direction: column; width: 50%',
'div_id' => 'resource_type',
],
2024-01-24 12:15:16 +01:00
);
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-02-12 10:35:01 +01:00
$filename = (string) get_parameter('filename', '');
2024-01-22 17:22:23 +01:00
2024-02-12 10:35:01 +01:00
try {
$data = $prd->exportPrd($type, $value, $name);
} catch (\Exception $e) {
$data = '';
}
2024-01-24 12:15:16 +01:00
2024-02-07 15:49:20 +01:00
$return = [];
2024-01-24 12:15:16 +01:00
if (empty($data) === false) {
2024-02-07 15:49:20 +01:00
$filename_download = date('YmdHis').'-'.$type.'-'.$name.'.prd';
2024-01-24 12:15:16 +01:00
$file = $config['attachment_store'].'/'.$filename;
$file_pointer = fopen($file, 'a');
if ($file_pointer !== false) {
$write = fwrite($file_pointer, $data);
if ($write === false) {
2024-02-07 15:49:20 +01:00
$return['error'] = -2;
2024-02-12 10:35:01 +01:00
unlink($config['attachment_store'].'/'.$filename);
2024-01-24 12:15:16 +01:00
} else {
2024-02-07 15:49:20 +01:00
$return['name'] = $filename;
$return['name_download'] = $filename_download;
2024-01-24 12:15:16 +01:00
}
fclose($file_pointer);
} else {
2024-02-07 15:49:20 +01:00
$return['error'] = -1;
2024-01-24 12:15:16 +01:00
}
}
2024-02-07 15:49:20 +01:00
echo json_encode($return);
2024-01-24 12:15:16 +01:00
return;
}
if ($deleteFile === true) {
$filename = (string) get_parameter('filename', '');
unlink($config['attachment_store'].'/'.$filename);
2024-01-22 17:22:23 +01:00
}
}