2009-02-17 Esteban Sanchez <estebans@artica.es>

* godmode/agentes/module_manager_editor.php: Added
	get_module_components operation to AJAX interface. Avoid error
	reporting on snmprealwalk so the JSON doesn't fail. Added support for
	component group selection. Do nothing if the selected component is
	zero.

	* godmode/agentes/module_manager_editor_common.php: Added
	add_component_selection() which makes the task of adding a module
	component to the editor easier and common. It also now filters based
	on component groups first.

	* godmode/agentes/module_manager_editor_network.php,
	godmode/agentes/module_manager_editor_wmi.php: Use
	add_component_selection() instead of duping the code.

	* include/styles/pandora.css: Added style to component elements.

	* include/functions_db.php: Avoid numeric field names on
	format_array_to_where_clause_sql().

	* include/functions_modules.php: Added get_network_components() and
	get_network_component_groups().



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1462 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Esteban Sanchez 2009-02-17 12:17:10 +00:00
parent c3abf055e1
commit 1b74ca3bef
8 changed files with 224 additions and 31 deletions

View File

@ -1,3 +1,28 @@
2009-02-17 Esteban Sanchez <estebans@artica.es>
* godmode/agentes/module_manager_editor.php: Added
get_module_components operation to AJAX interface. Avoid error
reporting on snmprealwalk so the JSON doesn't fail. Added support for
component group selection. Do nothing if the selected component is
zero.
* godmode/agentes/module_manager_editor_common.php: Added
add_component_selection() which makes the task of adding a module
component to the editor easier and common. It also now filters based
on component groups first.
* godmode/agentes/module_manager_editor_network.php,
godmode/agentes/module_manager_editor_wmi.php: Use
add_component_selection() instead of duping the code.
* include/styles/pandora.css: Added style to component elements.
* include/functions_db.php: Avoid numeric field names on
format_array_to_where_clause_sql().
* include/functions_modules.php: Added get_network_components() and
get_network_component_groups().
2009-02-16 Raul Mateos <raulofpandora@gmail.com> 2009-02-16 Raul Mateos <raulofpandora@gmail.com>
* include/config_process.php: Update build after last changes. * include/config_process.php: Update build after last changes.

View File

@ -20,6 +20,7 @@ if (defined ('AJAX')) {
$get_network_component = (bool) get_parameter ('get_network_component'); $get_network_component = (bool) get_parameter ('get_network_component');
$snmp_walk = (bool) get_parameter ('snmp_walk'); $snmp_walk = (bool) get_parameter ('snmp_walk');
$get_module_component = (bool) get_parameter ('get_module_component'); $get_module_component = (bool) get_parameter ('get_module_component');
$get_module_components = (bool) get_parameter ('get_module_components');
if ($get_module_component) { if ($get_module_component) {
$id_component = (int) get_parameter ('id_module_component'); $id_component = (int) get_parameter ('id_module_component');
@ -30,12 +31,24 @@ if (defined ('AJAX')) {
return; return;
} }
if ($get_module_components) {
require_once ('include/functions_modules.php');
$id_module_group = (int) get_parameter ('id_module_component_group');
$id_module_component = (int) get_parameter ('id_module_component_type');
$components = get_network_components ($id_module_component,
array ('id_module_group' => $id_module_group));
echo json_encode ($components);
return;
}
if ($snmp_walk) { if ($snmp_walk) {
$ip_target = (string) get_parameter ('ip_target'); $ip_target = (string) get_parameter ('ip_target');
$snmp_community = (string) get_parameter ('snmp_community'); $snmp_community = (string) get_parameter ('snmp_community');
snmp_set_quick_print (1); snmp_set_quick_print (1);
$snmpwalk = snmprealwalk ($ip_target, $snmp_community, NULL); $snmpwalk = @snmprealwalk ($ip_target, $snmp_community, NULL);
if ($snmpwalk === false) { if ($snmpwalk === false) {
echo json_encode ($snmpwalk); echo json_encode ($snmpwalk);
return; return;
@ -232,7 +245,44 @@ $(document).ready (function () {
$("#text-tcp_port").removeAttr ("disabled"); $("#text-tcp_port").removeAttr ("disabled");
} }
}); });
$("#network_component_group").change (function () {
var $select = $("#network_component").hide ();
$("#component").hide ();
if (this.value == 0)
return;
$("#component_loading").show ();
$(".error, #no_component").hide ();
$("option[value!=0]", $select).remove ();
jQuery.post ("ajax.php",
{"page" : "godmode/agentes/module_manager_editor",
"get_module_components" : 1,
"id_module_component_group" : this.value,
"id_module_component_type" : $("#hidden-id_module_component_type").attr ("value")
},
function (data, status) {
if (data == false) {
$("#component_loading").hide ();
$("span#no_component").show ();
return;
}
jQuery.each (data, function (i, val) {
option = $("<option></option>")
.attr ("value", val['id_nc'])
.append (val['name']);
$select.append (option);
});
$("#component_loading").hide ();
$select.show ();
$("#component").show ();
},
"json"
);
});
$("#network_component").change (function () { $("#network_component").change (function () {
if (this.value == 0)
return;
$("#component_loading").show (); $("#component_loading").show ();
$(".error").hide (); $(".error").hide ();
jQuery.post ("ajax.php", jQuery.post ("ajax.php",
@ -298,7 +348,7 @@ $(document).ready (function () {
}, },
function (data, status) { function (data, status) {
if (data == false) { if (data == false) {
$("span.error").show (); $("span#no_snmp").show ();
$("#oid_loading").hide (); $("#oid_loading").hide ();
$("#edit_oid").hide (); $("#edit_oid").hide ();
return false; return false;

View File

@ -64,6 +64,41 @@ function push_table_advanced ($row, $id = false) {
$table_advanced->data = array_merge ($table_advanced->data, $data); $table_advanced->data = array_merge ($table_advanced->data, $data);
} }
function add_component_selection ($id_network_component_type) {
global $table_simple;
$data = array ();
$data[0] = __('Using module component').' ';
$data[0] .= pandora_help ('network_component', true);
$component_groups = get_network_component_groups ($id_network_component_type);
$data[1] = '<span id="component_group" class="left">';
$data[1] .= __('Group').'<br />';
$data[1] .= print_select ($component_groups,
'network_component_group', '', '', '--'.__('Manual setup').'--', 0,
true, false, false);
$data[1] .= '</span>';
$data[1] .= print_input_hidden ('id_module_component_type', $id_network_component_type, true);
$data[1] .= '<span id="no_component" class="invisible error">';
$data[1] .= __('No component was found');
$data[1] .= '</span>';
$data[1] .= '<span id="component" class="invisible right">';
$data[1] .= __('Component').'<br />';
$data[1] .= print_select (array (), 'network_component', '', '',
'---'.__('Manual setup').'---', 0, true);
$data[1] .= '</span>';
$data[1] .= ' <span id="component_loading" class="invisible">';
$data[1] .= '<img src="images/spinner.gif" />';
$data[1] .= '</span>';
$table_simple->colspan['module_component'][1] = 3;
$table_simple->rowstyle['module_component'] = 'background-color: #D4DDC6';
prepend_table_simple ($data, 'module_component');
}
require_once ('include/functions_modules.php');
$update_module_id = (int) get_parameter_get ('update_module'); $update_module_id = (int) get_parameter_get ('update_module');
$table_simple->id = 'simple'; $table_simple->id = 'simple';

View File

@ -25,24 +25,14 @@ if (!isset ($id_agente)) {
$extra_title = __('Network server module'); $extra_title = __('Network server module');
$data = array (); define ('ID_NETWORK_COMPONENT_TYPE', 2);
$data[0] = __('Using module component').' ';
$data[0] .= pandora_help ('network_component', true);
if (empty ($update_module_id)) { if (empty ($update_module_id)) {
$data[1] = print_select_from_sql ('SELECT id_nc, name FROM tnetwork_component WHERE id_modulo = 2', /* Function in module_manager_editor_common.php */
'network_component', '', '', '---'.__('Manual setup').'---', 0, true); add_component_selection (ID_NETWORK_COMPONENT_TYPE);
$data[1] .= ' <span id="component_loading" class="invisible">';
$data[1] .= '<img src="images/spinner.gif" />';
$data[1] .= '</span>';
} else { } else {
/* TODO: Print network component if available */ /* TODO: Print network component if available */
$data[1] = 'TODO';
} }
$table_simple->colspan['module_component'][1] = 3;
$table_simple->rowstyle['module_component'] = 'background-color: #D4DDC6';
prepend_table_simple ($data, 'module_component');
$data = array (); $data = array ();
$data[0] = __('Target IP'); $data[0] = __('Target IP');
@ -79,7 +69,7 @@ $data[1] .= '<span class="invisible" id="oid">';
$data[1] .= print_select (array (), 'select_snmp_oid', $snmp_oid, '', '', 0, true); $data[1] .= print_select (array (), 'select_snmp_oid', $snmp_oid, '', '', 0, true);
$data[1] .= '<img src="images/edit.png" class="invisible clickable" id="edit_oid" />'; $data[1] .= '<img src="images/edit.png" class="invisible clickable" id="edit_oid" />';
$data[1] .= '</span>'; $data[1] .= '</span>';
$data[1] .= '<span class="error invisible">'.__('Unable to do SNMP walk').'</span>'; $data[1] .= '<span id="no_snmp" class="error invisible">'.__('Unable to do SNMP walk').'</span>';
$data[1] .= '</span> <span class="right"><span id="oid_loading" class="invisible">'; $data[1] .= '</span> <span class="right"><span id="oid_loading" class="invisible">';
$data[1] .= '<img src="images/spinner.gif" />'; $data[1] .= '<img src="images/spinner.gif" />';
$data[1] .= '</span>'; $data[1] .= '</span>';

View File

@ -23,24 +23,14 @@ if (!isset ($id_agente)) {
$extra_title = __('WMI server module'); $extra_title = __('WMI server module');
$data = array (); define ('ID_NETWORK_COMPONENT_TYPE', 6);
$data[0] = __('Using module component').' ';
$data[0] .= pandora_help ('network_component', true);
if (empty ($update_module_id)) { if (empty ($update_module_id)) {
$data[1] = print_select_from_sql ('SELECT id_nc, name FROM tnetwork_component WHERE id_modulo = 6', /* Function in module_manager_editor_common.php */
'network_component', '', '', '---'.__('Manual setup').'---', 0, true); add_component_selection (ID_NETWORK_COMPONENT_TYPE);
$data[1] .= ' <span id="component_loading" class="invisible">';
$data[1] .= '<img src="images/spinner.gif" />';
$data[1] .= '</span>';
} else { } else {
/* TODO: Print network component if available */ /* TODO: Print network component if available */
$data[1] = 'TODO';
} }
$table_simple->colspan['module_component'][1] = 3;
$table_simple->rowstyle['module_component'] = 'background-color: #D4DDC6';
prepend_table_simple ($data, 'module_component');
$data = array (); $data = array ();
$data[0] = __('Target IP'); $data[0] = __('Target IP');

View File

@ -1712,6 +1712,10 @@ function format_array_to_where_clause_sql ($values, $join = 'AND') {
$i = 1; $i = 1;
$max = count ($values); $max = count ($values);
foreach ($values as $field => $value) { foreach ($values as $field => $value) {
if (is_numeric ($field))
/* Avoid numeric field names */
continue;
if ($field[0] != "`") { if ($field[0] != "`") {
$field = "`".$field."`"; $field = "`".$field."`";
} }

View File

@ -72,4 +72,94 @@ function copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent) {
return $id_new_module; return $id_new_module;
} }
/**
* Get a list of network components.
*
* @param int Module type id of the requested components.
* @param mixed Aditional filters to the components. It can be an indexed array
* (keys would be the field name and value the expected value, and would be
* joined with an AND operator). Examples:
<code>
$components = get_network_components ($id_module, array ('id_module_group', 10));
$components = get_network_components ($id_module, array ('id_module_group', 10));
</code>
*
* @return array A list of network components matching. Empty array is returned
* if none matches.
*/
function get_network_components ($id_module, $filter = false) {
if (empty ($id_module))
return array ();
$where = '';
if (is_array ($filter)) {
$where = ' AND ';
$where .= format_array_to_where_clause_sql ($filter);
}
$sql = sprintf ('SELECT * FROM tnetwork_component
WHERE `id_modulo` = %d %s',
$id_module, $where);
$components = get_db_all_rows_sql ($sql);
if ($components === false)
return array ();
return $components;
}
/**
* Get a list of network component groups.
*
* The values returned can be passed directly to print_select(). Child groups
* are indented, so ordering on print_select() is NOT recommendable.
*
* @param int If provided, groups must have at least one compoent of the module
* provided. Parents will be included in that case even if they don't have
* components directly.
*
* @return array An ordered list of component groups with childs indented.
*/
function get_network_component_groups ($id_module_components = 0) {
/* Special vars to keep track of indentation level */
static $level = 0;
static $id_parent = 0;
$groups = get_db_all_rows_field_filter ('tnetwork_component_group',
'parent', $id_parent);
if ($groups === false)
return array ();
$retval = array ();
/* Magic indentation is here */
$prefix = str_repeat ('&nbsp;', $level * 3);
foreach ($groups as $group) {
$level++;
$tmp = $id_parent;
$id_parent = $group['id_sg'];
$childs = get_network_component_groups ($id_module_components);
$id_parent = $tmp;
$level--;
if (! empty ($childs) || $id_module_components == 0) {
$retval[$group['id_sg']] = $prefix.$group['name'];
$retval = $retval + $childs;
} else {
/* If components id module is provided, only groups with components
that belongs to this id module are returned */
if ($id_module_components) {
$sql = sprintf ('SELECT COUNT(*)
FROM tnetwork_component
WHERE id_module_group = %d
AND id_modulo = %d',
$group['id_sg'], $id_module_components);
$count = get_db_sql ($sql);
if ($count > 0)
$retval[$group['id_sg']] = $prefix.$group['name'];
}
}
}
return $retval;
}
?> ?>

View File

@ -764,6 +764,15 @@ table#filter_compound_table select,
table#filter_compound_table #text-search { table#filter_compound_table #text-search {
width: 100%; width: 100%;
} }
table#simple select#network_component_group,
table#simple select#network_component {
width: 90%;
}
table#simple span#component_group,
table#simple span#component {
width: 45%;
font-style: italic;
}
.clickable { .clickable {
cursor: pointer; cursor: pointer;
} }
@ -845,8 +854,8 @@ ol.steps li.visited {
} }
/* Common useful styles */ /* Common useful styles */
.left { clear: left; } .left { clear: left; float: left;}
.right { clear: right; } .right { clear: right; float: right;}
.clear { clear:both; } .clear { clear:both; }
.top { .top {
vertical-align: top; vertical-align: top;