From ad0c50de88677fe7a7ad16293fd13942d3b96b8b Mon Sep 17 00:00:00 2001 From: raulmateos Date: Tue, 22 Mar 2011 22:11:57 +0000 Subject: [PATCH] 2011-03-22 Raul Mateos * extensions/ssh_console.php, extensions/vnc_view.php, extensions/update_manager.php, extensions/users_connected.php, extensions/extension_uploader.php, extensions/insert_data.php, extensions/module_groups.php, extensions/plugin_registration.php: Cleaned code and updated page disclaimers. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4120 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 10 +- .../extensions/extension_uploader.php | 16 +- pandora_console/extensions/insert_data.php | 164 +++++++------ pandora_console/extensions/module_groups.php | 30 +-- .../extensions/plugin_registration.php | 55 ++--- pandora_console/extensions/ssh_console.php | 21 +- pandora_console/extensions/system_info.php | 229 +++++++++--------- pandora_console/extensions/update_manager.php | 12 +- .../extensions/users_connected.php | 74 +++--- pandora_console/extensions/vnc_view.php | 15 +- .../include/functions_reporting.php | 4 +- 11 files changed, 324 insertions(+), 306 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index e9558df2fe..a8f37bbbf3 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,7 +1,15 @@ +2011-03-22 Raul Mateos + + * extensions/ssh_console.php, extensions/vnc_view.php, + extensions/update_manager.php, extensions/users_connected.php, + extensions/extension_uploader.php, extensions/insert_data.php, + extensions/module_groups.php, extensions/plugin_registration.php: + Cleaned code and updated page disclaimers. + 2011-03-22 Raul Mateos * extensions/resource_registration.php, - extensions/resource_exporation.php, extensions/agent_modules.php: + extensions/resource_exportation.php, extensions/agent_modules.php: Cleaned code and updated page disclaimers. * include/functions_reporting.php: Removed SVN errors in code. diff --git a/pandora_console/extensions/extension_uploader.php b/pandora_console/extensions/extension_uploader.php index bfb9bf2ec4..091615eebc 100644 --- a/pandora_console/extensions/extension_uploader.php +++ b/pandora_console/extensions/extension_uploader.php @@ -1,15 +1,17 @@ "; print_table($table); echo "
"; - print_input_hidden('upload', 1); - print_submit_button(__('Upload'), 'submit', false, 'class="sub add"'); - echo "
"; + print_input_hidden('upload', 1); + print_submit_button(__('Upload'), 'submit', false, 'class="sub add"'); + echo ""; echo ""; } diff --git a/pandora_console/extensions/insert_data.php b/pandora_console/extensions/insert_data.php index a090480105..ce49ead6c0 100644 --- a/pandora_console/extensions/insert_data.php +++ b/pandora_console/extensions/insert_data.php @@ -1,15 +1,17 @@ $id_agent)); - $agentModule = get_db_row_filter('tagente_modulo', array('id_agente_modulo' => $id_agent_module)); - - $date2 = str_replace('-', '/', $date); - $time2 = DATE("H:i", strtotime($time)); - - $date_xml = $date2 . ' ' . $time2 . ':00'; - - - - if ($csv !== false) { - $file = file($csv['tmp_name']); - foreach ($file as $line) { - $tokens = explode(';', $line); - - createXMLData($agent, $agentModule, trim($tokens[0]), trim($tokens[1])); - } - } - else { - createXMLData($agent, $agentModule, $date_xml, $data); - } - } - } - - - - echo '
'; - echo __("Please check that the directory \"/var/spool/pandora/data_in\" is writeable by the apache user.

The CSV file format is date;value<newline>date;value<newline>... The date in CSV is in format Y/m/d H:i:s."); - echo '
'; - - $table = null; - $table->width = '80%'; - $table->style = array(); - $table->style[0] = 'font-weight: bolder;'; - - $table->data = array(); - $table->data[0][0] = __('Agent'); + if ($save) { + if (!check_acl($config['id_user'], get_agent_group(get_agent_id($id_agent)), "AW")) { + print_error_message(__('You haven\'t privileges for insert data in the agent.')); + } + else { + $agent = get_db_row_filter('tagente', array('nombre' => $id_agent)); + $agentModule = get_db_row_filter('tagente_modulo', array('id_agente_modulo' => $id_agent_module)); + + $date2 = str_replace('-', '/', $date); + $time2 = DATE("H:i", strtotime($time)); + + $date_xml = $date2 . ' ' . $time2 . ':00'; + + if ($csv !== false) { + $file = file($csv['tmp_name']); + foreach ($file as $line) { + $tokens = explode(';', $line); + createXMLData($agent, $agentModule, trim($tokens[0]), trim($tokens[1])); + } + } + else { + createXMLData($agent, $agentModule, $date_xml, $data); + } + } +} + + + + echo '
'; + echo __("Please check that the directory \"/var/spool/pandora/data_in\" is writeable by the apache user.

The CSV file format is date;value<newline>date;value<newline>... The date in CSV is in format Y/m/d H:i:s."); + echo '
'; + + $table = null; + $table->width = '80%'; + $table->style = array(); + $table->style[0] = 'font-weight: bolder;'; + + $table->data = array(); + $table->data[0][0] = __('Agent'); $table->data[0][1] = print_input_text_extended ('id_agent', $id_agent, 'text_id_agent', '', 30, 100, false, '', array('style' => 'background: url(images/lightning.png) no-repeat right;'), true) . ' ' . __("Type at least two characters to search") . ''; - $table->data[1][0] = __('Module'); + $table->data[1][0] = __('Module'); $modules = array (); if ($id_agent) $modules = get_agent_modules ($id_agent, false, array("delete_pending" => 0)); $table->data[1][1] = print_select ($modules, 'id_agent_module', $id_agent_module, true, __('Select'), 0, true, false, true, '', ($id_agent === '')); - $table->data[2][0] = __('Data'); - $table->data[2][1] = print_input_text('data', $data, __('Data'), 40, 60, true); - $table->data[3][0] = __('Date'); - $table->data[3][1] = print_input_text ('date', $date, '', 11, 11, true).' '; + $table->data[2][0] = __('Data'); + $table->data[2][1] = print_input_text('data', $data, __('Data'), 40, 60, true); + $table->data[3][0] = __('Date'); + $table->data[3][1] = print_input_text ('date', $date, '', 11, 11, true).' '; $table->data[3][1] .= print_input_text ('time', $time, '', 7, 7, true); - $table->data[4][0] = __('CSV'); - $table->data[4][1] = print_input_file('csv', true); - - echo "
"; - - print_table($table); - - echo "
"; - print_input_hidden('save', 1); - print_submit_button(__('Save'), 'submit', ($id_agent === ''), 'class="sub next"'); - echo "
"; - - echo "
"; - - require_css_file ('datepicker'); + $table->data[4][0] = __('CSV'); + $table->data[4][1] = print_input_file('csv', true); + + echo "
"; + + print_table($table); + + echo "
"; + print_input_hidden('save', 1); + print_submit_button(__('Save'), 'submit', ($id_agent === ''), 'class="sub next"'); + echo "
"; + + echo "
"; + + require_css_file ('datepicker'); require_jquery_file ('ui.core'); require_jquery_file ('ui.datepicker'); require_jquery_file ('timeentry'); require_jquery_file ('autocomplete'); - ?> +?> - \ No newline at end of file +?> diff --git a/pandora_console/extensions/module_groups.php b/pandora_console/extensions/module_groups.php index ad16853207..92802545f7 100644 --- a/pandora_console/extensions/module_groups.php +++ b/pandora_console/extensions/module_groups.php @@ -1,18 +1,20 @@ 0) { - echo '' . __('Number fired of alerts').': ' . $alert["times_fired"] . '
'; + echo '' . __('Number fired of alerts').': ' . $alert["times_fired"] . '
'; $agent = get_db_row('tagente', 'id_agente', $module['id_agente']); echo '' . __('Agent').': '; echo safe_output($agent['nombre']) . '
'; diff --git a/pandora_console/extensions/plugin_registration.php b/pandora_console/extensions/plugin_registration.php index 7aa4a28ea9..b355346dad 100644 --- a/pandora_console/extensions/plugin_registration.php +++ b/pandora_console/extensions/plugin_registration.php @@ -1,25 +1,26 @@
- - - + + + @@ -33,12 +35,11 @@ function main_ssh_console () { - + diff --git a/pandora_console/extensions/system_info.php b/pandora_console/extensions/system_info.php index 284c03579b..a8e9514378 100644 --- a/pandora_console/extensions/system_info.php +++ b/pandora_console/extensions/system_info.php @@ -1,15 +1,17 @@ " . $file_name . ""; echo ""; } } @@ -164,7 +166,7 @@ function logFilesLines($file_name, $numLines) { return ''; } else { - return shell_exec('tail -n ' . $numLines . ' ' . $file_name); + return shell_exec('tail -n ' . $numLines . ' ' . $file_name); } } } @@ -227,104 +229,104 @@ function show_array($title, $anchor, $array = array()) { function mainSystemInfo() { global $config; - if (! check_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_user'])) { - 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); - - print_page_header (__("System Info"), "images/extensions.png", false, "", true, "" ); - - echo '
'; - 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: sudo php /var/www/pandora_console/extensions/system_info.php -d -s -c"); - echo '
'; - - echo "

" . __('This tool is used just to view your Pandora FMS system logfiles directly from console') . "

"; - + if (! check_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_user'])) { + 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); + + print_page_header (__("System Info"), "images/extensions.png", false, "", true, "" ); + + echo '
'; + 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: sudo php /var/www/pandora_console/extensions/system_info.php -d -s -c"); + echo '
'; + + echo "

" . __('This tool is used just to view your Pandora FMS system logfiles directly from console') . "

"; + echo "
"; - $table = null; - $table->width = '80%'; - $table->align = array(); - $table->align[1] = 'right'; + $table = null; + $table->width = '80%'; + $table->align = array(); + $table->align[1] = 'right'; if ($pandora_diag) { - $table->data[0][0] = '' . __('Pandora Diagnostic info') . ""; + $table->data[0][0] = '' . __('Pandora Diagnostic info') . ""; } else { $table->data[0][0] = __('Pandora Diagnostic info'); } - $table->data[0][1] = print_checkbox('pandora_diag', 1, $pandora_diag, true); - if ($system_info) { + $table->data[0][1] = print_checkbox('pandora_diag', 1, $pandora_diag, true); + if ($system_info) { $table->data[1][0] = '' . __('System info') . ''; - } - else { - $table->data[1][0] = __('System info'); - } - $table->data[1][1] = print_checkbox('system_info', 1, $system_info, true); - if ($log_info) { + } + else { + $table->data[1][0] = __('System info'); + } + $table->data[1][1] = print_checkbox('system_info', 1, $system_info, true); + if ($log_info) { $table->data[2][0] = '' . __('Log Info') . ''; - } - else { - $table->data[2][0] = __('Log Info'); - } - $table->data[2][1] = print_checkbox('log_info', 1, $log_info, true); + } + else { + $table->data[2][0] = __('Log Info'); + } + $table->data[2][1] = print_checkbox('log_info', 1, $log_info, true); $table->data[3][0] = __('Number lines of log'); - $table->data[3][1] = print_input_text('log_num_lines', $log_num_lines, __('Number lines of log'), 5, 10, true); - print_table($table); - echo "
"; - //print_submit_button(__('Show'), 'show', false, 'class="sub next"'); - print_submit_button(__('Generate file'), 'generate', false, 'class="sub next"'); - echo "
"; - echo "
"; - - 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 "

" . __('Log Info') . "

"; - getLastLog($log_num_lines); - } - } - elseif ($generate) { + $table->data[3][1] = print_input_text('log_num_lines', $log_num_lines, __('Number lines of log'), 5, 10, true); + print_table($table); + echo "
"; + //print_submit_button(__('Show'), 'show', false, 'class="sub next"'); + print_submit_button(__('Generate file'), 'generate', false, 'class="sub next"'); + echo "
"; + echo ""; + + 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 "

" . __('Log Info') . "

"; + getLastLog($log_num_lines); + } + } + elseif ($generate) { $tempDirSystem = sys_get_temp_dir(); $nameDir = 'dir_' . uniqid(); $tempDir = $tempDirSystem . '/' . $nameDir . '/'; mkdir($tempDir); - - $zipArchive = $config['attachment_store'] . '/last_info.zip'; - @unlink($zipArchive); - - if ($config['https']) { + + $zipArchive = $config['attachment_store'] . '/last_info.zip'; + @unlink($zipArchive); + + if ($config['https']) { $http = 'https://'; } else { - $http = "http://"; - } + $http = "http://"; + } $url = '' . __('System info file zipped') . ''; echo '' . __('File:') . ' ' . $url; - + $zip = new ZipArchive; - if ($zip->open($zipArchive, ZIPARCHIVE::CREATE) === true) { - if ($pandora_diag) { + if ($zip->open($zipArchive, ZIPARCHIVE::CREATE) === true) { + if ($pandora_diag) { $systemInfo = array(); getPandoraDiagnostic($systemInfo); @@ -351,10 +353,9 @@ function mainSystemInfo() { } if ($system_info) { - $info = array(); - getSystemInfo($info); - - + $info = array(); + getSystemInfo($info); + $file = fopen($tempDir . 'system_info.txt', 'w'); if ($file !== false) { @@ -375,11 +376,11 @@ function mainSystemInfo() { } $zip->addFile($tempDir . 'system_info.txt', 'system_info.txt'); - } - - if ($log_info) { - file_put_contents($tempDir . 'pandora_console.log.lines_' . $log_num_lines, getLastLinesLog($config["homedir"]."/pandora_console.log", $log_num_lines)); - $zip->addFile($tempDir . 'pandora_console.log.lines_' . $log_num_lines, 'pandora_console.log.lines_' . $log_num_lines); + } + + if ($log_info) { + file_put_contents($tempDir . 'pandora_console.log.lines_' . $log_num_lines, getLastLinesLog($config["homedir"]."/pandora_console.log", $log_num_lines)); + $zip->addFile($tempDir . 'pandora_console.log.lines_' . $log_num_lines, 'pandora_console.log.lines_' . $log_num_lines); file_put_contents($tempDir . 'pandora_server.log.lines_' . $log_num_lines, getLastLinesLog("/var/log/pandora/pandora_server.log", $log_num_lines)); $zip->addFile($tempDir . 'pandora_server.log.lines_' . $log_num_lines, 'pandora_server.log.lines_' . $log_num_lines); file_put_contents($tempDir . 'pandora_server.error.lines_' . $log_num_lines, getLastLinesLog("/var/log/pandora/pandora_server.error", $log_num_lines)); @@ -392,28 +393,28 @@ function mainSystemInfo() { $zip->addFile($tempDir . 'pandora_server.conf.lines_' . $log_num_lines, 'pandora_server.conf.lines_' . $log_num_lines); file_put_contents($tempDir . 'syslog.lines_' . $log_num_lines, getLastLinesLog("/var/log/syslog", $log_num_lines)); $zip->addFile($tempDir . 'syslog.lines_' . $log_num_lines, 'syslog.lines_' . $log_num_lines); - } - + } + $zip->close(); - } -// -// 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 "

" . __('Log Info') . "

"; -// getLastLog($log_num_lines); -// } - } + } +// +// 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 "

" . __('Log Info') . "

"; +// getLastLog($log_num_lines); +// } + } } function consoleMode() { @@ -629,4 +630,4 @@ else { consoleMode(); } -?> \ No newline at end of file +?> diff --git a/pandora_console/extensions/update_manager.php b/pandora_console/extensions/update_manager.php index 45f7680d8a..84812cbedf 100644 --- a/pandora_console/extensions/update_manager.php +++ b/pandora_console/extensions/update_manager.php @@ -1,15 +1,17 @@ ".__('No other users connected').""; } else { - $table->cellpadding = 4; - $table->cellspacing = 4; - $table->width = 600; - $table->class = "databox"; - $table->size = array (); - $table->data = array (); - $table->head = array (); + $table->cellpadding = 4; + $table->cellspacing = 4; + $table->width = 600; + $table->class = "databox"; + $table->size = array (); + $table->data = array (); + $table->head = array (); - $table->head[0] = __('User'); - $table->head[1] = __('IP'); - $table->head[2] = __('Date'); + $table->head[0] = __('User'); + $table->head[1] = __('IP'); + $table->head[2] = __('Date'); - $rowPair = true; - $iterator = 0; + $rowPair = true; + $iterator = 0; - // Get data - foreach ($rows as $row) { - if ($rowPair) - $table->rowclass[$iterator] = 'rowPair'; - else - $table->rowclass[$iterator] = 'rowOdd'; - $rowPair = !$rowPair; - $iterator++; + // Get data + foreach ($rows as $row) { + if ($rowPair) + $table->rowclass[$iterator] = 'rowPair'; + else + $table->rowclass[$iterator] = 'rowOdd'; + $rowPair = !$rowPair; + $iterator++; - $data = array (); - $data[0] = ''.$row["id_usuario"].''; - $data[1] = $row["ip_origen"]; - $data[2] = $row["fecha"]; - array_push ($table->data, $data); + $data = array (); + $data[0] = ''.$row["id_usuario"].''; + $data[1] = $row["ip_origen"]; + $data[2] = $row["fecha"]; + array_push ($table->data, $data); + } + + print_table ($table); } - - print_table ($table); -} } add_godmode_menu_option (__('Users connected'), 'UM','gusuarios',"users/icon.png"); if (isset($config["id_user"])) { - if (check_acl ($config["id_user"], 0, "UM")) { - add_operation_menu_option(__('Users connected'), 'usuarios',"users/icon.png"); - } + if (check_acl ($config["id_user"], 0, "UM")) { + add_operation_menu_option(__('Users connected'), 'usuarios',"users/icon.png"); + } } add_extension_godmode_function('users_extension_main_god'); diff --git a/pandora_console/extensions/vnc_view.php b/pandora_console/extensions/vnc_view.php index 6f662c3415..a6e42c78e6 100644 --- a/pandora_console/extensions/vnc_view.php +++ b/pandora_console/extensions/vnc_view.php @@ -2,26 +2,27 @@ // Pandora FMS - http://pandorafms.com // ================================================== -// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas +// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas // Please see http://pandorafms.org 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. +// 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 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. function vnc_view() { $idAgent = (int)get_parameter('id_agente', 0); $ipAgent = get_db_value('direccion', 'tagente', 'id_agente', $idAgent); - echo ''; + echo ''; echo ''; echo ''; - echo ''; - echo ''; + echo ''; + echo ''; /* */ } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 1c0b508e7b..5ad422f4af 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -6,12 +6,12 @@ // Please see http://pandorafms.org 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 +// 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 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. /**