2009-05-07 Esteban Sánchez <estebans@artica.es>

* 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
This commit is contained in:
esanchezm 2009-05-07 14:44:26 +00:00
parent a39a672b01
commit 30f72921fc
11 changed files with 188 additions and 66 deletions

View File

@ -1,3 +1,30 @@
2009-05-07 Esteban Sánchez <estebans@artica.es>
* 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 <vanooste@rcbi.rochester.edu>
* godmode/agentes/configurar_agente.php: get_agent_id changed and caused

View File

@ -82,11 +82,11 @@ echo "</a>";
// Autorefresh
echo '</td><td width="20%">';
if ($config["refr"]) {
echo '<a id="autorefresh" class="white_grey_bold" href="'.get_url_refresh ().'&amp;refr=0"><img src="images/page_lightning.png" class="bot" alt="lightning" />&nbsp;'. __('Autorefresh');
echo '<a id="autorefresh" class="white_grey_bold" href="'.get_url_refresh (array ('refr' => 0)).'"><img src="images/page_lightning.png" class="bot" alt="lightning" />&nbsp;'. __('Autorefresh');
echo ' (<span id="refrcounter">'.date ("i:s", $config["refr"]).'</span>)';
echo '</a>';
} else {
echo '<a id="autorefresh" class="white_bold" href="'.get_url_refresh ().'&amp;refr="><img src="images/page_lightning.png" class="bot" alt="lightning" />&nbsp;'.__('Autorefresh').'</a>';
echo '<a id="autorefresh" class="white_bold" href="'.get_url_refresh (array ('refr' => '')).'"><img src="images/page_lightning.png" class="bot" alt="lightning" />&nbsp;'.__('Autorefresh').'</a>';
$values = array ('5' => '5 '.__('seconds'),
'10' => '10 '.__('seconds'),
'15' => '15 '.__('seconds'),

View File

@ -46,7 +46,7 @@ echo '</li>';
echo '<li class="'.($tab == 'edit_modules' ? 'nomn_high' : 'nomn').'">';
echo '<a href="index.php?sec=gagente&sec2=godmode/agentes/massive_operations&tab=edit_modules">';
print_image ("images/book_edit.png", false, $img_style);
print_image ("images/edit.png", false, $img_style);
echo '&nbsp; '.__('Edit modules').'</a>';
echo '</li>';

View File

@ -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 '</td>';

View File

@ -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');

View File

@ -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;
}
?>

View File

@ -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) {

View File

@ -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 = '<div class="pagination">';
// Show GOTO FIRST button
$output .= '<a class="pagination go_first" href="'.$url.'&amp;offset=0">'.print_image ("images/control_start_blue.png", true, array ("class" => "bot")).'</a>&nbsp;';
$output .= '<a class="pagination go_first" href="'.$url.'&amp;'.$offset_name.'=0">'.print_image ("images/control_start_blue.png", true, array ("class" => "bot")).'</a>&nbsp;';
// Show PREVIOUS button
if ($index_page > 0) {
$index_page_prev = ($index_page - (floor ($block_limit / 2))) * $pagination;
if ($index_page_prev < 0)
$index_page_prev = 0;
$output .= '<a class="pagination go_rewind" href="'.$url.'&amp;offset='.$index_page_prev.'">'.print_image ("images/control_rewind_blue.png", true, array ("class" => "bot")).'</a>';
$output .= '<a class="pagination go_rewind" href="'.$url.'&amp;'.$offset_name.'='.$index_page_prev.'">'.print_image ("images/control_rewind_blue.png", true, array ("class" => "bot")).'</a>';
}
$output .= "&nbsp;&nbsp;";
// Draw blocks markers
@ -822,7 +832,7 @@ function pagination ($count, $url, $offset = 0, $pagination = 0, $return = false
$inicio_bloque_fake = $inicio_bloque + 1;
// To Calculate last block (doesnt end with round data,
// it must be shown if not round to block limit)
$output .= '<a class="pagination" href="'.$url.'&amp;offset='.$inicio_bloque.'">';
$output .= '<a class="pagination" href="'.$url.'&amp;'.$offset_name.'='.$inicio_bloque.'">';
if ($inicio_bloque == $offset) {
$output .= "<b>[ $i ]</b>";
} else {
@ -837,7 +847,7 @@ function pagination ($count, $url, $offset = 0, $pagination = 0, $return = false
$prox_bloque = ($i + ceil ($block_limit / 2)) * $pagination;
if ($prox_bloque > $count)
$prox_bloque = ($count -1) - $pagination;
$output .= '<a class="pagination go_fastforward" href="'.$url.'&amp;offset='.$prox_bloque.'">'.print_image ("images/control_fastforward_blue.png", true, array ("class" => "bot")).'</a>';
$output .= '<a class="pagination go_fastforward" href="'.$url.'&amp;'.$offset_name.'='.$prox_bloque.'">'.print_image ("images/control_fastforward_blue.png", true, array ("class" => "bot")).'</a>';
$i = $index_counter;
}
// if exists more registers than i can put in a page (defined by $block_size config parameter)
@ -846,7 +856,7 @@ function pagination ($count, $url, $offset = 0, $pagination = 0, $return = false
// as painted in last block (last integer block).
if (($count - $pagination) > 0) {
$myoffset = floor (($count - 1) / $pagination) * $pagination;
$output .= '<a class="pagination go_last" href="'.$url.'&amp;offset='.$myoffset.'">'.print_image ("images/control_end_blue.png", true, array ("class" => "bot")).'</a>';
$output .= '<a class="pagination go_last" href="'.$url.'&amp;'.$offset_name.'='.$myoffset.'">'.print_image ("images/control_end_blue.png", true, array ("class" => "bot")).'</a>';
}
// End div and layout
$output .= "</div>";
@ -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 .= '&amp;'.$key.'='.$value;
}
foreach ($_POST as $key => $value) {
$url .= '&amp;'.$key.'='.$value;
$url .= $key.'='.$value.'&amp;';
}
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.'&amp;';
}
$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.'&amp;';
}
/* Removes final & */
$pos = strrpos ($url, '&amp;', 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;
}
?>

View File

@ -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;
}

View File

@ -169,7 +169,7 @@ foreach ($alerts_simple as $alert) {
echo '<form method="post" action="'.$url.'">';
if (!empty ($table->data)) {
pagination ($total, $url, $offset);
pagination ($total, $url);
print_table ($table);
} else {
echo '<div class="nf">'.__('No simple alerts found').'</div>';

View File

@ -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 "<h2>".__('Pandora Agents')." &raquo; ".__('Summary')."</h2>";
if ($group_id > 1) {
echo '<form method="post" action="'.get_url_refresh ().'&amp;group_id='.$group_id.'">';
echo '<form method="post" action="'.get_url_refresh (array ('group_id' => $group_id)).'">';
} else {
echo '<form method="post" action="'.get_url_refresh ().'">';
}
@ -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;