From e46cfc566d7b2d69de3c19b93438cbeb5db77fdc Mon Sep 17 00:00:00 2001 From: mdtrooper <tres.14159@gmail.com> Date: Wed, 23 Mar 2011 12:15:53 +0000 Subject: [PATCH] 2011-03-23 Miguel de Dios <miguel.dedios@artica.es> * extensions/insert_data.php, extensions/system_info.php, extensions/agents_modules.php, extensions/ssh_console.php, extensions/resource_registration.php, extensions/resource_exportation.php, extensions/plugin_registration.php: re-ordered and re-cleaned some parts or lines of source code. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4123 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 8 + pandora_console/extensions/agents_modules.php | 6 +- pandora_console/extensions/insert_data.php | 203 +++++++++--------- .../extensions/plugin_registration.php | 6 +- .../extensions/resource_exportation.php | 2 +- .../extensions/resource_registration.php | 4 +- pandora_console/extensions/ssh_console.php | 20 +- pandora_console/extensions/system_info.php | 45 ++-- 8 files changed, 142 insertions(+), 152 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index c8069d9d50..f7b667f548 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2011-03-23 Miguel de Dios <miguel.dedios@artica.es> + + * extensions/insert_data.php, extensions/system_info.php, + extensions/agents_modules.php, extensions/ssh_console.php, + extensions/resource_registration.php, extensions/resource_exportation.php, + extensions/plugin_registration.php: re-ordered and re-cleaned some parts or + lines of source code. + 2011-03-23 Miguel de Dios <miguel.dedios@artica.es> * include/functions_reporting.php: fixed the include "fgraph", did'nt show diff --git a/pandora_console/extensions/agents_modules.php b/pandora_console/extensions/agents_modules.php index 12b14081f9..2aff6abf57 100644 --- a/pandora_console/extensions/agents_modules.php +++ b/pandora_console/extensions/agents_modules.php @@ -167,15 +167,15 @@ function mainAgentsModules() { $nmodules = 0; foreach($modules_by_name as $module) { $nmodules++; - + if($nmodules <= $hor_offset || $nmodules > ($hor_offset+$block)) { continue; } - + $file_name = string2image(printTruncateText($module['name'],15, false, true, false, '...'), 115, 13, 3, 270, '#9EAC8B', 'FFF', 4, 0); echo '<th width="22px">'.print_image($file_name, true, array('title' => $module['name']))."</th>"; } - + if(($hor_offset + $block) < $nmodules) { $new_hor_offset = $hor_offset+$block; echo "<th width='20px' style='vertical-align:top; padding-top: 35px;' rowspan='".($nagents+1)."'><a href='index.php?sec=extensions&sec2=extensions/agents_modules&hor_offset=".$new_hor_offset."&offset=".$offset."&group_id=".$group_id."&modulegroup=".$modulegroup."'>".print_image("images/darrowright.png",true, array('title' => __('More modules')))."</a> </th>"; diff --git a/pandora_console/extensions/insert_data.php b/pandora_console/extensions/insert_data.php index ce49ead6c0..da31bc57ea 100644 --- a/pandora_console/extensions/insert_data.php +++ b/pandora_console/extensions/insert_data.php @@ -45,16 +45,14 @@ function createXMLData($agent, $agentModule, $time, $data) { function mainInsertData() { global $config; - print_page_header (__("Insert data"), "images/extensions.png", false, "", true, ""); - if (! check_acl ($config['id_user'], 0, "AW") && ! is_user_admin ($config['id_user'])) { pandora_audit("ACL Violation", "Trying to access Setup Management"); require ("general/noaccess.php"); return; } - + $save = (bool)get_parameter('save', false); $id_agent = (string)get_parameter('id_agent', ''); $id_agent_module = (int)get_parameter('id_agent_module', ''); @@ -78,39 +76,38 @@ function mainInsertData() { 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 { + $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); } } - else { - createXMLData($agent, $agentModule, $date_xml, $data); - } } -} - - - + echo '<div class="notify">'; echo __("Please check that the directory \"/var/spool/pandora/data_in\" is writeable by the apache user. <br /><br />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 '</div>'; - + $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, '', @@ -129,101 +126,101 @@ function mainInsertData() { $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 "<form method='post' enctype='multipart/form-data'>"; - + print_table($table); - + echo "<div style='text-align: right; width: " . $table->width . "'>"; print_input_hidden('save', 1); print_submit_button(__('Save'), 'submit', ($id_agent === ''), 'class="sub next"'); echo "</div>"; - + echo "</form>"; - + require_css_file ('datepicker'); require_jquery_file ('ui.core'); require_jquery_file ('ui.datepicker'); require_jquery_file ('timeentry'); require_jquery_file ('autocomplete'); ?> - <script type="text/javascript"> - /* <![CDATA[ */ - $(document).ready (function () { - - $("#text_id_agent").autocomplete( - "ajax.php", - { - minChars: 2, - scroll:true, - extraParams: { - page: "operation/agentes/exportdata", - search_agents: 1, - id_group: function() { return $("#id_group").val(); } - }, - formatItem: function (data, i, total) { - if (total == 0) - $("#text_id_agent").css ('background-color', '#cc0000'); - else - $("#text_id_agent").css ('background-color', ''); - if (data == "") - return false; - - return data[0]+'<br><span class="ac_extra_field"><?php echo __("IP") ?>: '+data[1]+'</span>'; - }, - delay: 200 - } - ); +<script type="text/javascript"> + /* <![CDATA[ */ + $(document).ready (function () { - $("#text-time").timeEntry ({ - spinnerImage: 'images/time-entry.png', - spinnerSize: [20, 20, 0] - }); - - $("#text-date").datepicker (); - - }); - - $("#text_id_agent").result ( - function () { - selectAgent = true; - var agent_name = this.value; - $('#id_agent_module').fadeOut ('normal', function () { - $('#id_agent_module').empty (); - var inputs = []; - inputs.push ("agent_name=" + agent_name); - inputs.push ('filter=delete_pending = 0'); - inputs.push ("get_agent_modules_json=1"); - inputs.push ("page=operation/agentes/ver_agente"); - jQuery.ajax ({ - data: inputs.join ("&"), - type: 'GET', - url: action="ajax.php", - timeout: 10000, - dataType: 'json', - success: function (data) { - $('#id_agent_module').append ($('<option></option>').attr ('value', 0).text ("--")); - jQuery.each (data, function (i, val) { - s = js_html_entity_decode (val['nombre']); - $('#id_agent_module').append ($('<option></option>').attr ('value', val['id_agente_modulo']).text (s)); - }); - $('#id_agent_module').enable(); - $('#id_agent_module').fadeIn ('normal'); - - $('#submit-submit').enable(); - $('#submit-submit').fadeIn ('normal'); - } - }); - }); - - + $("#text_id_agent").autocomplete( + "ajax.php", + { + minChars: 2, + scroll:true, + extraParams: { + page: "operation/agentes/exportdata", + search_agents: 1, + id_group: function() { return $("#id_group").val(); } + }, + formatItem: function (data, i, total) { + if (total == 0) + $("#text_id_agent").css ('background-color', '#cc0000'); + else + $("#text_id_agent").css ('background-color', ''); + if (data == "") + return false; + + return data[0]+'<br><span class="ac_extra_field"><?php echo __("IP") ?>: '+data[1]+'</span>'; + }, + delay: 200 } ); - /* ]]> */ - </script> + + $("#text-time").timeEntry ({ + spinnerImage: 'images/time-entry.png', + spinnerSize: [20, 20, 0] + }); + + $("#text-date").datepicker (); + + }); + + $("#text_id_agent").result ( + function () { + selectAgent = true; + var agent_name = this.value; + $('#id_agent_module').fadeOut ('normal', function () { + $('#id_agent_module').empty (); + var inputs = []; + inputs.push ("agent_name=" + agent_name); + inputs.push ('filter=delete_pending = 0'); + inputs.push ("get_agent_modules_json=1"); + inputs.push ("page=operation/agentes/ver_agente"); + jQuery.ajax ({ + data: inputs.join ("&"), + type: 'GET', + url: action="ajax.php", + timeout: 10000, + dataType: 'json', + success: function (data) { + $('#id_agent_module').append ($('<option></option>').attr ('value', 0).text ("--")); + jQuery.each (data, function (i, val) { + s = js_html_entity_decode (val['nombre']); + $('#id_agent_module').append ($('<option></option>').attr ('value', val['id_agente_modulo']).text (s)); + }); + $('#id_agent_module').enable(); + $('#id_agent_module').fadeIn ('normal'); + + $('#submit-submit').enable(); + $('#submit-submit').fadeIn ('normal'); + } + }); + }); + + + } + ); + /* ]]> */ +</script> <?php } add_extension_godmode_function('mainInsertData'); add_godmode_menu_option(__('Insert Data'), 'AW', 'gagente'); -?> +?> \ No newline at end of file diff --git a/pandora_console/extensions/plugin_registration.php b/pandora_console/extensions/plugin_registration.php index b355346dad..d88b4580a6 100644 --- a/pandora_console/extensions/plugin_registration.php +++ b/pandora_console/extensions/plugin_registration.php @@ -16,6 +16,7 @@ function pluginreg_extension_main () { 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"); @@ -47,9 +48,10 @@ function pluginreg_extension_main () { if ($zip) { while ($zip_entry = zip_read($zip)) { if (zip_entry_open($zip, $zip_entry, "r")) { - if (zip_entry_name($zip_entry) == "plugin_definition.ini"){ + if (zip_entry_name($zip_entry) == "plugin_definition.ini") { $basepath = $config["attachment_store"]; - } else { + } + else { $basepath = $config["plugin_store"]; } $filename = $basepath . "/". zip_entry_name($zip_entry); diff --git a/pandora_console/extensions/resource_exportation.php b/pandora_console/extensions/resource_exportation.php index 499d619b0c..e5b7990d01 100644 --- a/pandora_console/extensions/resource_exportation.php +++ b/pandora_console/extensions/resource_exportation.php @@ -372,4 +372,4 @@ function resource_exportation_extension_main() { </script> <?php } -?> +?> \ No newline at end of file diff --git a/pandora_console/extensions/resource_registration.php b/pandora_console/extensions/resource_registration.php index 5f66826b65..7059f7e236 100644 --- a/pandora_console/extensions/resource_registration.php +++ b/pandora_console/extensions/resource_registration.php @@ -815,7 +815,7 @@ function resource_registration_extension_main() { require_once($config['homedir'] . '/include/functions_network_components.php'); require_once($config['homedir'] . '/include/functions_db.php'); enterprise_include_once('include/functions_local_components.php'); - + print_page_header (__('Resource registration'), "images/extensions.png", false, "", true, "" ); if (!extension_loaded("libxml")) { @@ -860,4 +860,4 @@ function resource_registration_extension_main() { add_godmode_menu_option (__('Resource registration'), 'PM','gservers',''); add_extension_godmode_function('resource_registration_extension_main'); -?> +?> \ No newline at end of file diff --git a/pandora_console/extensions/ssh_console.php b/pandora_console/extensions/ssh_console.php index 1c233120e2..8f76c7cd7c 100644 --- a/pandora_console/extensions/ssh_console.php +++ b/pandora_console/extensions/ssh_console.php @@ -26,16 +26,16 @@ function main_ssh_console () { ?> <div> <applet code="com.mindbright.application.MindTerm.class" style="border: 2px;" archive="extensions/ssh_console/mindterm.jar" width="720" height="500"> -<param name="sepframe" value="false"> -<param name="debug" value="false"> -<param name="verbose" value="false"> -<param name="bg-color" value="black"> -<param name="fg-color" value="white"> -<param name="resizable" value="true"> -<param name="save-lines" value="2000"> -<param name="menus" value="pop2"5> -<param name="exit-on-logout" value="true"> -<param name="server" value="<?PHP echo $ip; ?>"> + <param name="sepframe" value="false"> + <param name="debug" value="false"> + <param name="verbose" value="false"> + <param name="bg-color" value="black"> + <param name="fg-color" value="white"> + <param name="resizable" value="true"> + <param name="save-lines" value="2000"> + <param name="menus" value="pop2"5> + <param name="exit-on-logout" value="true"> + <param name="server" value="<?PHP echo $ip; ?>"> </applet> </div> <?php diff --git a/pandora_console/extensions/system_info.php b/pandora_console/extensions/system_info.php index a8e9514378..9d104b8f13 100644 --- a/pandora_console/extensions/system_info.php +++ b/pandora_console/extensions/system_info.php @@ -232,22 +232,23 @@ function mainSystemInfo() { 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 '<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'>"; @@ -284,20 +285,20 @@ function mainSystemInfo() { 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); @@ -309,10 +310,9 @@ function mainSystemInfo() { $tempDir = $tempDirSystem . '/' . $nameDir . '/'; mkdir($tempDir); - $zipArchive = $config['attachment_store'] . '/last_info.zip'; @unlink($zipArchive); - + if ($config['https']) { $http = 'https://'; } @@ -322,7 +322,7 @@ function mainSystemInfo() { $url = '<a href="' .$http.$_SERVER['HTTP_HOST'].$config["homeurl"].'/attachment/last_info.zip">' . __('System info file zipped') . '</a>'; echo '<b>' . __('File:') . '</b> ' . $url; - + $zip = new ZipArchive; if ($zip->open($zipArchive, ZIPARCHIVE::CREATE) === true) { @@ -355,7 +355,7 @@ function mainSystemInfo() { if ($system_info) { $info = array(); getSystemInfo($info); - + $file = fopen($tempDir . 'system_info.txt', 'w'); if ($file !== false) { @@ -377,7 +377,7 @@ 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); @@ -394,26 +394,9 @@ function mainSystemInfo() { 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 "<h1><a name='log_info'>" . __('Log Info') . "</a></h1>"; -// getLastLog($log_num_lines); -// } } } @@ -630,4 +613,4 @@ else { consoleMode(); } -?> +?> \ No newline at end of file