mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-30 01:05:39 +02:00
2014-06-20 Alejandro Gallardo <alejandro.gallardo@artica.es>
* extensions/system_info.php: Improved the user experience. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10243 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
661dcbcdb9
commit
6118be9a10
@ -1,3 +1,7 @@
|
|||||||
|
2014-06-20 Alejandro Gallardo <alejandro.gallardo@artica.es>
|
||||||
|
|
||||||
|
* extensions/system_info.php: Improved the user experience.
|
||||||
|
|
||||||
2014-06-18 Miguel de Dios <miguel.dedios@artica.es>
|
2014-06-18 Miguel de Dios <miguel.dedios@artica.es>
|
||||||
|
|
||||||
* include/javascript/d3.v3.4.8.js: added the last version of D3.
|
* include/javascript/d3.v3.4.8.js: added the last version of D3.
|
||||||
|
@ -14,6 +14,27 @@
|
|||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU General Public License for more details.
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
if (is_ajax()) {
|
||||||
|
|
||||||
|
$generate_info = (bool) get_parameter("generate_info");
|
||||||
|
if ($generate_info) {
|
||||||
|
$pandora_diag = (bool) get_parameter("pandora_diag");
|
||||||
|
$system_info = (bool) get_parameter("system_info");
|
||||||
|
$log_info = (bool) get_parameter("log_info");
|
||||||
|
|
||||||
|
$checks = array();
|
||||||
|
$checks['pandora_diagnostic'] = $pandora_diag;
|
||||||
|
$checks['system_info'] = $system_info;
|
||||||
|
$checks['log_info'] = $log_info;
|
||||||
|
$result = generate_info($checks);
|
||||||
|
|
||||||
|
echo json_encode($result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
function getPandoraDiagnostic(&$systemInfo) {
|
function getPandoraDiagnostic(&$systemInfo) {
|
||||||
global $config;
|
global $config;
|
||||||
global $build_version;
|
global $build_version;
|
||||||
@ -197,11 +218,12 @@ function getLastLog($numLines = 2000) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function show_array($title, $anchor, $array = array()) {
|
function show_array($title, $anchor, $array = array()) {
|
||||||
$table = null;
|
|
||||||
|
|
||||||
$table->width = '100%';
|
$table = new StdClass();
|
||||||
$table->titlestyle = 'border: 1px solid black;';
|
$table->width = '98%';
|
||||||
$table->class = "databox_color";
|
$table->class = "databox";
|
||||||
|
$table->head = array();
|
||||||
|
$table->head[0] = $title;
|
||||||
$table->data = array();
|
$table->data = array();
|
||||||
|
|
||||||
foreach ($array as $index => $item) {
|
foreach ($array as $index => $item) {
|
||||||
@ -239,85 +261,13 @@ function show_array($title, $anchor, $array = array()) {
|
|||||||
html_print_table($table);
|
html_print_table($table);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mainSystemInfo() {
|
function generate_info($checks) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
if (! check_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_user'])) {
|
$pandora_diag = isset($checks['pandora_diagnostic']) ? $checks['pandora_diagnostic'] : false;
|
||||||
db_pandora_audit("ACL Violation", "Trying to access Setup Management");
|
$system_info = isset($checks['system_info']) ? $checks['system_info'] : false;
|
||||||
require ("general/noaccess.php");
|
$log_info = isset($checks['log_info']) ? $checks['log_info'] : false;
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$show = (bool) get_parameter('show');
|
|
||||||
$generate = (bool) get_parameter('generate');
|
|
||||||
$pandora_diag = (bool) get_parameter('pandora_diag', 0);
|
|
||||||
$system_info = (bool) get_parameter('system_info', 0);
|
|
||||||
$log_info = (bool) get_parameter('log_info', 0);
|
|
||||||
$log_num_lines = (int) get_parameter('log_num_lines', 2000);
|
|
||||||
|
|
||||||
ui_print_page_header (__("System Info"), "images/extensions.png", false, "", true, "" );
|
|
||||||
|
|
||||||
echo '<div class="notify">';
|
|
||||||
echo __("This extension can run as PHP script in a shell for extract more information, but it must be run as root or across sudo. For example: <i>sudo php /var/www/pandora_console/extensions/system_info.php -d -s -c</i>");
|
|
||||||
echo '</div>';
|
|
||||||
|
|
||||||
echo "<p>" . __('This tool is used just to view your Pandora FMS system logfiles directly from console') . "</p>";
|
|
||||||
|
|
||||||
echo "<form method='post' action='index.php?extension_in_menu=gsetup&sec=gextensions&sec2=extensions/system_info'>";
|
|
||||||
$table = null;
|
|
||||||
$table->width = '98%';
|
|
||||||
$table->align = array();
|
|
||||||
$table->align[1] = 'right';
|
|
||||||
if ($pandora_diag) {
|
|
||||||
$table->data[0][0] = '<a href="#diag_info">' .
|
|
||||||
__('Pandora Diagnostic info') . "</a>";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$table->data[0][0] = __('Pandora Diagnostic info');
|
|
||||||
}
|
|
||||||
$table->data[0][1] = html_print_checkbox('pandora_diag', 1, $pandora_diag, true);
|
|
||||||
if ($system_info) {
|
|
||||||
$table->data[1][0] = '<a href="#system_info">' . __('System info') . '</a>';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$table->data[1][0] = __('System info');
|
|
||||||
}
|
|
||||||
$table->data[1][1] = html_print_checkbox('system_info', 1, $system_info, true);
|
|
||||||
if ($log_info) {
|
|
||||||
$table->data[2][0] = '<a href="#log_info">' . __('Log Info') . '</a>';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$table->data[2][0] = __('Log Info');
|
|
||||||
}
|
|
||||||
$table->data[2][1] = html_print_checkbox('log_info', 1, $log_info, true);
|
|
||||||
$table->data[3][0] = __('Number lines of log');
|
|
||||||
$table->data[3][1] = html_print_input_text('log_num_lines', $log_num_lines, __('Number lines of log'), 5, 10, true);
|
|
||||||
html_print_table($table);
|
|
||||||
echo "<div style='width: " . $table->width . "; text-align: right;'>";
|
|
||||||
html_print_submit_button(__('Generate file'), 'generate', false, 'class="sub next"');
|
|
||||||
echo "</div>";
|
|
||||||
echo "</form>";
|
|
||||||
|
|
||||||
if ($show) {
|
|
||||||
if ($pandora_diag) {
|
|
||||||
$info = array();
|
|
||||||
getPandoraDiagnostic($info);
|
|
||||||
show_array(__('Pandora Diagnostic info'), 'diag_info', $info);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($system_info) {
|
|
||||||
$info = array();
|
|
||||||
getSystemInfo($info);
|
|
||||||
show_array(__('System info'), 'system_info', $info);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($log_info) {
|
|
||||||
echo "<h1><a name='log_info'>" . __('Log Info') . "</a></h1>";
|
|
||||||
getLastLog($log_num_lines);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elseif ($generate) {
|
|
||||||
$tempDirSystem = sys_get_temp_dir();
|
$tempDirSystem = sys_get_temp_dir();
|
||||||
$nameDir = 'dir_' . uniqid();
|
$nameDir = 'dir_' . uniqid();
|
||||||
$tempDir = $tempDirSystem . '/' . $nameDir . '/';
|
$tempDir = $tempDirSystem . '/' . $nameDir . '/';
|
||||||
@ -330,17 +280,18 @@ function mainSystemInfo() {
|
|||||||
|
|
||||||
$url = '<a href="' .$url_zip . 'attachment/last_info.zip">' . __('download here') . '</a>';
|
$url = '<a href="' .$url_zip . 'attachment/last_info.zip">' . __('download here') . '</a>';
|
||||||
|
|
||||||
if ($log_info || $system_info || $pandora_diag) {
|
$result = array();
|
||||||
echo '<b>' . __('File:') . '</b> ' . $url . '<br />';
|
$result['success'] = false;
|
||||||
echo '<b>' . __('Location:') . '</b> ' . $zipArchive;
|
$result['url'] = $url;
|
||||||
}
|
$result['location'] = $zipArchive;
|
||||||
else {
|
|
||||||
echo __('No selected');
|
$some_check = $log_info || $system_info || $pandora_diag;
|
||||||
}
|
|
||||||
|
|
||||||
$zip = new ZipArchive;
|
$zip = new ZipArchive;
|
||||||
|
|
||||||
if ($zip->open($zipArchive, ZIPARCHIVE::CREATE) === true) {
|
$zip_openned = $zip->open($zipArchive, ZIPARCHIVE::CREATE) === true;
|
||||||
|
|
||||||
|
if ($some_check && $zip_openned) {
|
||||||
if ($pandora_diag) {
|
if ($pandora_diag) {
|
||||||
$systemInfo = array();
|
$systemInfo = array();
|
||||||
getPandoraDiagnostic($systemInfo);
|
getPandoraDiagnostic($systemInfo);
|
||||||
@ -413,8 +364,212 @@ function mainSystemInfo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$zip->close();
|
$zip->close();
|
||||||
|
|
||||||
|
$result['date'] = ui_print_timestamp(filectime($zipArchive), true);
|
||||||
|
$result['success'] = true;
|
||||||
|
}
|
||||||
|
elseif (!$some_check) {
|
||||||
|
$result['message'] = __('No options selected');
|
||||||
|
}
|
||||||
|
elseif (!$zip_openned) {
|
||||||
|
$result['message'] = __('There was an error with the zip file');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mainSystemInfo() {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if (! check_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_user'])) {
|
||||||
|
db_pandora_audit("ACL Violation", "Trying to access Setup Management");
|
||||||
|
require ("general/noaccess.php");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$show = (bool) get_parameter('show');
|
||||||
|
$generate = (bool) get_parameter('generate');
|
||||||
|
$pandora_diag = (bool) get_parameter('pandora_diag', 0);
|
||||||
|
$system_info = (bool) get_parameter('system_info', 0);
|
||||||
|
$log_info = (bool) get_parameter('log_info', 0);
|
||||||
|
$log_num_lines = (int) get_parameter('log_num_lines', 2000);
|
||||||
|
|
||||||
|
ui_print_page_header (__("System Info"), "images/extensions.png", false, "", true, "" );
|
||||||
|
|
||||||
|
echo '<div class="notify">';
|
||||||
|
echo __("This extension can run as PHP script in a shell for extract more information, but it must be run as root or across sudo. For example: <i>sudo php /var/www/pandora_console/extensions/system_info.php -d -s -c</i>");
|
||||||
|
echo '</div>';
|
||||||
|
|
||||||
|
$table = null;
|
||||||
|
$table->width = '99%';
|
||||||
|
$table->align = array();
|
||||||
|
$table->align[1] = 'right';
|
||||||
|
if ($pandora_diag) {
|
||||||
|
$table->data[0][0] = '<a href="#diag_info">' .
|
||||||
|
__('Pandora Diagnostic info') . "</a>";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$table->data[0][0] = __('Pandora Diagnostic info');
|
||||||
|
}
|
||||||
|
$table->data[0][1] = html_print_checkbox('pandora_diag', 1, $pandora_diag, true);
|
||||||
|
if ($system_info) {
|
||||||
|
$table->data[1][0] = '<a href="#system_info">' . __('System info') . '</a>';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$table->data[1][0] = __('System info');
|
||||||
|
}
|
||||||
|
$table->data[1][1] = html_print_checkbox('system_info', 1, $system_info, true);
|
||||||
|
if ($log_info) {
|
||||||
|
$table->data[2][0] = '<a href="#log_info">' . __('Log Info') . '</a>';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$table->data[2][0] = __('Log Info');
|
||||||
|
}
|
||||||
|
$table->data[2][1] = html_print_checkbox('log_info', 1, $log_info, true);
|
||||||
|
$table->data[3][0] = __('Number lines of log');
|
||||||
|
$table->data[3][1] = html_print_input_text('log_num_lines', $log_num_lines, __('Number lines of log'), 5, 10, true);
|
||||||
|
|
||||||
|
|
||||||
|
$default_location = $config['attachment_store'] . '/last_info.zip';
|
||||||
|
$file_exists = file_exists($default_location) && is_readable($default_location);
|
||||||
|
|
||||||
|
$table_file = new StdClass();
|
||||||
|
$table_file->id = "table_file";
|
||||||
|
$table_file->width = '99%';
|
||||||
|
$table_file->style = array();
|
||||||
|
$table_file->style[0] = "font-weight: bold";
|
||||||
|
$table_file->data = array();
|
||||||
|
|
||||||
|
$display_file_link = $file_exists ? "" : "style=\"display: none;\"";
|
||||||
|
$url = ui_get_full_url(false) . "attachment/last_info.zip";
|
||||||
|
$file_link = "<a href=\"$url\" $display_file_link>";
|
||||||
|
$file_link .= html_print_image('images/file.png', true, array('title' => __('Download'))); // Download image
|
||||||
|
$file_link .= "</a>";
|
||||||
|
|
||||||
|
$data = array();
|
||||||
|
$data[0] = __('File');
|
||||||
|
$data['cell-link'] = $file_link;
|
||||||
|
$table_file->data['row_link'] = $data;
|
||||||
|
|
||||||
|
$data = array();
|
||||||
|
$data[0] = __('Created');
|
||||||
|
$data['cell-date'] = $file_exists ? ui_print_timestamp(filectime($default_location), true) : '';
|
||||||
|
$table_file->data['row_date'] = $data;
|
||||||
|
|
||||||
|
$data = array();
|
||||||
|
$data[0] = __('Location');
|
||||||
|
$data['cell-location'] = $file_exists ? $default_location : '';
|
||||||
|
$table_file->data['row_location'] = $data;
|
||||||
|
|
||||||
|
echo "<form method='post' action='index.php?extension_in_menu=gsetup&sec=gextensions&sec2=extensions/system_info'>";
|
||||||
|
|
||||||
|
html_print_table($table);
|
||||||
|
|
||||||
|
$display_table_file = $file_exists ? "" : "style=\"display: none;\"";
|
||||||
|
echo "<div id=\"table_file_container\" $display_table_file>";
|
||||||
|
html_print_table($table_file);
|
||||||
|
echo "</div>";
|
||||||
|
|
||||||
|
echo "<br>";
|
||||||
|
echo "<div style='width: " . $table->width . "; text-align: right;'>";
|
||||||
|
html_print_submit_button(__('Generate file'), 'generate', false, 'class="sub next"');
|
||||||
|
html_print_image('images/spinner.gif', false, array('id' => 'spinner_img', 'title' => __('Loading'), 'style' => 'display: none;'));
|
||||||
|
echo "</div>";
|
||||||
|
echo "</form>";
|
||||||
|
|
||||||
|
if ($show) {
|
||||||
|
if ($pandora_diag) {
|
||||||
|
$info = array();
|
||||||
|
getPandoraDiagnostic($info);
|
||||||
|
show_array(__('Pandora Diagnostic info'), 'diag_info', $info);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($system_info) {
|
||||||
|
$info = array();
|
||||||
|
getSystemInfo($info);
|
||||||
|
show_array(__('System info'), 'system_info', $info);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($log_info) {
|
||||||
|
echo "<h1><a name='log_info'>" . __('Log Info') . "</a></h1>";
|
||||||
|
getLastLog($log_num_lines);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elseif ($generate) {
|
||||||
|
$checks = array();
|
||||||
|
$checks['pandora_diagnostic'] = $pandora_diag;
|
||||||
|
$checks['system_info'] = $system_info;
|
||||||
|
$checks['log_info'] = $log_info;
|
||||||
|
$result = generate_info($checks);
|
||||||
|
|
||||||
|
if ($result['success']) {
|
||||||
|
echo '<b>' . __('File') . ':</b> ' . $result['url'] . '<br />';
|
||||||
|
echo '<b>' . __('Location') . ':</b> ' . $result['location'];
|
||||||
|
}
|
||||||
|
elseif (isset($result['message'])) {
|
||||||
|
echo $result['message'];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo __('Error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
$("#submit-generate").click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
generate_info();
|
||||||
|
});
|
||||||
|
|
||||||
|
function generate_info () {
|
||||||
|
$("#submit-generate").hide();
|
||||||
|
$("#spinner_img").show();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: 'ajax.php',
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
page: <?php echo json_encode(EXTENSIONS_DIR) ?> + '/system_info',
|
||||||
|
generate_info: 1,
|
||||||
|
pandora_diag: function() { return $("checkbox-pandora_diag").val(); },
|
||||||
|
system_info: function() { return $("checkbox-system_info").val(); },
|
||||||
|
log_info: function() { return $("checkbox-log_info").val(); }
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
$("#spinner_img").hide();
|
||||||
|
$("#submit-generate").show();
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
|
||||||
|
if (data.success) {
|
||||||
|
$("#table_file-row_link-cell-link").find("a").prop("href", data.url);
|
||||||
|
$("#table_file-row_date-cell-date").html(data.date);
|
||||||
|
$("#table_file-row_location-cell-location").html(data.location);
|
||||||
|
$("#table_file_container").slideDown();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$("#table_file-row_link-cell-link").find("a").prop("href", "");
|
||||||
|
$("#table_file-row_date-cell-date").html("");
|
||||||
|
$("#table_file-row_location-cell-location").html("");
|
||||||
|
$("#table_file_container").slideUp();
|
||||||
|
alert(data.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(xhr, textStatus, errorThrown) {
|
||||||
|
$("#table_file-row_link-cell-link").find("a").prop("href", "");
|
||||||
|
$("#table_file-row_date-cell-date").html("");
|
||||||
|
$("#table_file-row_location-cell-location").html("");
|
||||||
|
$("#table_file_container").slideUp();
|
||||||
|
alert('Error');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
function consoleMode() {
|
function consoleMode() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user