From b20565d7d50277e880c842b7ff2abc9fc8cdd47f Mon Sep 17 00:00:00 2001 From: Esteban Sanchez Date: Thu, 7 May 2009 14:44:26 +0000 Subject: [PATCH] =?UTF-8?q?2009-05-07=20=20Esteban=20S=C3=A1nchez=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * include/funtions_ui.php: Added get_full_url(). Some changes in get_url_refresh() to make it more powerful. The URL is now optional in pagination(). It's also possible to give the parameter name of the offset so there could be more than one paginations now. * operation/agentes/estado_agente.php, general/header.php: Changes in get_url_refresh(). * godmode/agentes/massive_operations.php: Changed edit icon. * godmode/agentes/module_manager.php: Enterprise API changes. * godmode/agentes/module_manager_editor_network.php: Style corrections. * include/styles/pandora.css: Added conf_error class to textarea elements. * include/functions.php: Added index_array(). Useful to manage database results. * include/functions_alerts.php: Cast some values to integer. * operation/agentes/alerts_status.php: Removed offset parameters, used default value. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1678 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 27 ++++ pandora_console/general/header.php | 4 +- .../godmode/agentes/massive_operations.php | 2 +- .../godmode/agentes/module_manager.php | 5 +- .../agentes/module_manager_editor_network.php | 6 +- pandora_console/include/functions.php | 36 +++++ pandora_console/include/functions_alerts.php | 24 ++-- pandora_console/include/functions_ui.php | 136 +++++++++++++----- pandora_console/include/styles/pandora.css | 5 + .../operation/agentes/alerts_status.php | 2 +- .../operation/agentes/estado_agente.php | 7 +- 11 files changed, 188 insertions(+), 66 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 7960c6bd18..fc0f57b1c8 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,30 @@ +2009-05-07 Esteban Sánchez + + * include/funtions_ui.php: Added get_full_url(). Some changes in + get_url_refresh() to make it more powerful. The URL is now optional + in pagination(). It's also possible to give the parameter name + of the offset so there could be more than one paginations now. + + * operation/agentes/estado_agente.php, + general/header.php: Changes in get_url_refresh(). + + * godmode/agentes/massive_operations.php: Changed edit icon. + + * godmode/agentes/module_manager.php: Enterprise API changes. + + * godmode/agentes/module_manager_editor_network.php: Style corrections. + + * include/styles/pandora.css: Added conf_error class to textarea + elements. + + * include/functions.php: Added index_array(). Useful to manage database + results. + + * include/functions_alerts.php: Cast some values to integer. + + * operation/agentes/alerts_status.php: Removed offset parameters, + used default value. + 2009-05-04 Evi Vanoost * godmode/agentes/configurar_agente.php: get_agent_id changed and caused diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index 49299f58d3..f4c82ec2e7 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -82,11 +82,11 @@ echo ""; // Autorefresh echo ''; if ($config["refr"]) { - echo 'lightning '. __('Autorefresh'); + echo 'lightning '. __('Autorefresh'); echo ' ('.date ("i:s", $config["refr"]).')'; echo ''; } else { - echo 'lightning '.__('Autorefresh').''; + echo 'lightning '.__('Autorefresh').''; $values = array ('5' => '5 '.__('seconds'), '10' => '10 '.__('seconds'), '15' => '15 '.__('seconds'), diff --git a/pandora_console/godmode/agentes/massive_operations.php b/pandora_console/godmode/agentes/massive_operations.php index 985f3d705d..2cf7232958 100644 --- a/pandora_console/godmode/agentes/massive_operations.php +++ b/pandora_console/godmode/agentes/massive_operations.php @@ -46,7 +46,7 @@ echo ''; echo '
  • '; echo ''; -print_image ("images/book_edit.png", false, $img_style); +print_image ("images/edit.png", false, $img_style); echo '  '.__('Edit modules').''; echo '
  • '; diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index 5e694d967d..91dff4f251 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -55,9 +55,8 @@ if ($wmi_available) $modules['wmiserver'] = __('Create a new WMI Server module'); if ($prediction_available) $modules['predictionserver'] = __('Create a new prediction Server module'); -if (!isset ($local_components)) - $local_components = false; -enterprise_hook ('set_enterprise_module_types', array (&$modules, $local_components)); + +enterprise_hook ('set_enterprise_module_types', array (&$modules)); print_select ($modules, 'moduletype', '', '', '', '', false, false, false); print_input_hidden ('edit_module', 1); echo ''; diff --git a/pandora_console/godmode/agentes/module_manager_editor_network.php b/pandora_console/godmode/agentes/module_manager_editor_network.php index 02aca1894d..6eebd3e8e5 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_network.php +++ b/pandora_console/godmode/agentes/module_manager_editor_network.php @@ -78,15 +78,13 @@ push_table_simple ($data, 'snmp_2'); /* Advanced stuff */ $data = array (); $data[0] = __('TCP send').' '.print_help_icon ("tcp_send", true); -$data[1] = print_textarea ('tcp_send', 2, 65, - $tcp_send, '', true); +$data[1] = print_textarea ('tcp_send', 2, 65, $tcp_send, '', true); $table_advanced->colspan['tcp_send'][1] = 3; push_table_advanced ($data, 'tcp_send'); $data[0] = __('TCP receive'); -$data[1] = print_textarea ('tcp_rcv', 2, 65, - $tcp_rcv, '', true); +$data[1] = print_textarea ('tcp_rcv', 2, 65, $tcp_rcv, '', true); $table_advanced->colspan['tcp_receive'][1] = 3; push_table_advanced ($data, 'tcp_receive'); diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 07601245a5..2de35cee07 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -965,4 +965,40 @@ function safe_sql_string ($string) { function is_ajax () { return defined ('AJAX'); } + +/** + * Transform an array of database result into an indexed array. + * + * This function is useful when the results of a database needs to be used + * in a print_select() function. + * + * @param array Array with the results. + * @param string Field of each row in the given array that will act as index. False + * will set all the values. + * @param string Field of each row in the array that will act as value. + * + * @return array An array having the given index as fields and the given values + * as value. + */ +function index_array ($array, $index = 'id', $value = 'name') { + $retval = array (); + + if (! is_array ($array)) + return $retval; + + foreach ($array as $element) { + if (! isset ($element[$index])) + continue; + if ($value === false) { + $retval[$element[$index]] = $element; + continue; + } + + if (! isset ($element[$value])) + continue; + $retval[$element[$index]] = $element[$value]; + } + + return $retval; +} ?> diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index d3963caf45..82b01d401e 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -101,7 +101,7 @@ function create_alert_action ($name, $id_alert_command, $values = false) { if (! is_array ($values)) $values = array (); $values['name'] = $name; - $values['id_alert_command'] = $id_alert_command; + $values['id_alert_command'] = (int) $id_alert_command; return @process_sql_insert ('talert_actions', $values); } @@ -384,8 +384,8 @@ function create_alert_agent_module ($id_agent_module, $id_alert_template, $value if (! is_array ($values)) $values = array (); - $values['id_agent_module'] = $id_agent_module; - $values['id_alert_template'] = $id_alert_template; + $values['id_agent_module'] = (int) $id_agent_module; + $values['id_alert_template'] = (int) $id_alert_template; return @process_sql_insert ('talert_template_modules', $values); } @@ -424,7 +424,7 @@ function get_alerts_agent_module ($id_agent_module, $disabled = false, $filter = $filter = array (); if (! $disabled) $filter['disabled'] = 0; - $filter['id_agent_module'] = $id_agent_module; + $filter['id_agent_module'] = (int) $id_agent_module; return get_db_all_rows_filter ('talert_template_modules', $filter, $fields); @@ -463,8 +463,8 @@ function add_alert_agent_module_action ($id_alert_template_module, $id_alert_act return false; $values = array (); - $values['id_alert_template_module'] = $id_alert_template_module; - $values['id_alert_action'] = $id_alert_action; + $values['id_alert_template_module'] = (int) $id_alert_template_module; + $values['id_alert_action'] = (int) $id_alert_action; $values['fires_max'] = 0; $values['fires_min'] = 0; if ($options) { @@ -583,7 +583,7 @@ function copy_alert_agent_module_to_agent_module ($id_agent_alert, $id_destiny_m /* PHP copy arrays on assignment */ $new_alert = array (); - $new_alert['id_agent_module'] = $id_destiny_module; + $new_alert['id_agent_module'] = (int) $id_destiny_module; $new_alert['id_alert_template'] = $alert['id_alert_template']; $id_new_alert = @process_sql_insert ('talert_template_modules', $new_alert); @@ -630,7 +630,7 @@ function create_alert_compound ($name, $id_agent, $values = false) { if (! is_array ($values)) $values = array (); $values['name'] = $name; - $values['id_agent'] = $id_agent; + $values['id_agent'] = (int) $id_agent; return @process_sql_insert ('talert_compound', $values); } @@ -665,8 +665,8 @@ function add_alert_compound_element ($id_alert_compound, $id_alert_template_modu return false; $values = array (); - $values['id_alert_compound'] = $id_alert_compound; - $values['id_alert_template_module'] = $id_alert_template_module; + $values['id_alert_compound'] = (int) $id_alert_compound; + $values['id_alert_template_module'] = (int) $id_alert_template_module; $values['operation'] = $operation; return @process_sql_insert ('talert_compound_elements', $values); @@ -716,8 +716,8 @@ function add_alert_compound_action ($id_alert_compound, $id_alert_action, $optio return false; $values = array (); - $values['id_alert_compound'] = $id_alert_compound; - $values['id_alert_action'] = $id_alert_action; + $values['id_alert_compound'] = (int) $id_alert_compound; + $values['id_alert_action'] = (int) $id_alert_action; $values['fires_max'] = 0; $values['fires_min'] = 0; if ($options) { diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 72e8e4503e..6f6acf9892 100644 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -748,18 +748,28 @@ function process_page_body ($string, $bitfield) { * * @return string The pagination div or nothing if no pagination needs to be done */ -function pagination ($count, $url, $offset = 0, $pagination = 0, $return = false) { +function pagination ($count, $url = false, $offset = 0, $pagination = 0, $return = false) { global $config; if (empty ($pagination)) { $pagination = $config["block_size"]; } - if (empty ($offset)) { - $offset = (int) get_parameter ('offset'); + $offset_name = 'offset'; + if (is_string ($offset)) { + $offset_name = $offset; + $offset = (int) get_parameter ($offset_name); } - $url = safe_input ($url); + if (empty ($offset)) { + $offset = (int) get_parameter ($offset_name); + } + + if (empty ($url)) { + $url = get_url_refresh (array ($offset_name => false)); + } else { + $url = safe_input ($url); + } /* URL passed render links with some parameter &offset - Offset records passed to next page @@ -800,13 +810,13 @@ function pagination ($count, $url, $offset = 0, $pagination = 0, $return = false $output = '"; @@ -1134,51 +1144,99 @@ function get_include_contents ($filename, $params = false) { /** * Construct and return the URL to be used in order to refresh the current page correctly. * - * @param bool $relative Whether to return the relative URL or the absolute URL. Returns relative by default + * @param array Extra parameters to be added to the URL. It has prevalence over + * GET and POST. False values will be ignored. + * @param bool Whether to return the relative URL or the absolute URL. Returns + * relative by default + * @param bool Whether to add POST values to the URL. */ -function get_url_refresh ($relative = true) { +function get_url_refresh ($params = false, $relative = true, $add_post = true) { // Agent selection filters and refresh global $config; $url = ''; - if (sizeof ($_REQUEST)) + if (sizeof ($_REQUEST)) { //Some (old) browsers don't like the ?&key=var - $url .= '?1=1'; + $url .= '?'; + } + + if (! is_array ($params)) + $params = array (); //We don't clean these variables up as they're only being passed along foreach ($_GET as $key => $value) { - /* Avoid the 1=1 */ - if ($key == 1) + if (isset ($params[$key])) continue; - $url .= '&'.$key.'='.$value; - } - foreach ($_POST as $key => $value) { - $url .= '&'.$key.'='.$value; + $url .= $key.'='.$value.'&'; } - if ($relative === false) { - if ($config['https']) { - //When $config["https"] is set, always force https - $protocol = 'https'; - $ssl = true; - } elseif (isset ($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === true || $_SERVER['HTTPS'] == 'on')) { - $protocol = 'https'; - $ssl = true; - } else { - $protocol = 'http'; - $ssl = false; + if ($add_post) { + foreach ($_POST as $key => $value) { + if (isset ($params[$key])) + continue; + $url .= $key.'='.$value.'&'; } - - $fullurl = $protocol.'://' . $_SERVER['SERVER_NAME']; - - if ((!$ssl && $_SERVER['SERVER_PORT'] != 80) || ($ssl && $_SERVER['SERVER_PORT'] != 443)) { - $fullurl .= ":".$_SERVER['SERVER_PORT']; - } - $fullurl .= $_SERVER['SCRIPT_NAME']; - - return $fullurl.$url; + } + + foreach ($params as $key => $value) { + if ($value === false) + continue; + $url .= $key.'='.$value.'&'; + } + + /* Removes final & */ + $pos = strrpos ($url, '&', 0); + if ($pos) { + $url = substr_replace ($url, '', $pos, 5); + } + + if (! $relative) { + return get_full_url ($url); } return $url; } + +/** + * Returns a full URL in Pandora. + * + * An example of full URL is http:/localhost/pandora_console/index.php?sec=gsetup&sec2=godmode/setup/setup + * + * @param string If provided, it will be added after the index.php + * + * @return string A full URL in Pandora. + */ +function get_full_url ($url = false) { + global $config; + + $was_empty = false; + if (empty ($url)) { + $was_empty = true; + $url = $_SERVER['REQUEST_URI']; + } + + if ($config['https']) { + //When $config["https"] is set, always force https + $protocol = 'https'; + $ssl = true; + } elseif (isset ($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === true || $_SERVER['HTTPS'] == 'on')) { + $protocol = 'https'; + $ssl = true; + } else { + $protocol = 'http'; + $ssl = false; + } + + $fullurl = $protocol.'://' . $_SERVER['SERVER_NAME']; + + if ((!$ssl && $_SERVER['SERVER_PORT'] != 80) || ($ssl && $_SERVER['SERVER_PORT'] != 443)) { + $fullurl .= ":".$_SERVER['SERVER_PORT']; + } + + if (! $was_empty) { + $fullurl .= $_SERVER['SCRIPT_NAME']; + } + + return $fullurl.$url; +} ?> diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 5f67fae454..3634ed2b26 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -42,6 +42,11 @@ textarea.conf_editor { width: 650px; height: 350px; } +textarea.conf_error { + background-image: url(../../images/err.png); + background-repeat: no-repeat; + background-position: top right; +} input { padding: 2px 3px 4px 3px; } diff --git a/pandora_console/operation/agentes/alerts_status.php b/pandora_console/operation/agentes/alerts_status.php index 759ba11329..c499ab08ef 100644 --- a/pandora_console/operation/agentes/alerts_status.php +++ b/pandora_console/operation/agentes/alerts_status.php @@ -169,7 +169,7 @@ foreach ($alerts_simple as $alert) { echo '
    '; if (!empty ($table->data)) { - pagination ($total, $url, $offset); + pagination ($total, $url); print_table ($table); } else { echo '
    '.__('No simple alerts found').'
    '; diff --git a/pandora_console/operation/agentes/estado_agente.php b/pandora_console/operation/agentes/estado_agente.php index 1ab80796c3..27b764c00e 100644 --- a/pandora_console/operation/agentes/estado_agente.php +++ b/pandora_console/operation/agentes/estado_agente.php @@ -47,14 +47,13 @@ if (is_ajax ()) { } // Take some parameters (GET) -$offset = get_parameter ("offset", 0); $group_id = get_parameter ("group_id", 0); $search = get_parameter ("search", ""); echo "

    ".__('Pandora Agents')." » ".__('Summary')."

    "; if ($group_id > 1) { - echo ''; + echo ''; } else { echo ''; } @@ -94,7 +93,7 @@ if ($group_id > 1) { if (!empty ($agent_names)) { $num_agents = get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente WHERE id_agente IN (%s)", implode (",", array_keys ($agent_names)))); - $agents = get_db_all_rows_sql (sprintf ("SELECT * FROM tagente WHERE id_agente IN (%s) ORDER BY nombre ASC LIMIT %d,%d", implode (",", array_keys ($agent_names)), $offset, $config["block_size"])); + $agents = get_db_all_rows_sql (sprintf ("SELECT * FROM tagente WHERE id_agente IN (%s) ORDER BY nombre ASC LIMIT %d,%d", implode (",", array_keys ($agent_names)))); } if (empty ($agents)) { @@ -102,7 +101,7 @@ if (empty ($agents)) { } // Prepare pagination -pagination ($num_agents, get_url_refresh ()."&group_id=".$group_id."&search=".$search, $offset); +pagination ($num_agents, get_url_refresh (array ('group_id' => $group_id, 'search' => $search))); // Show data. $table->cellpadding = 4;