2009-05-21 Esteban Sanchez <estebans@artica.es>

* include/functions_network_components.php: Added to repository.
	Functions relative to network components moved here. Added
	create_network_component(), update_network_component() and
	delete_network_component().

	* include/functions_db.php: Removed
	gve_network_component_group_name(), duplicated in
	functions_network_components.php.

	* include/functions_modules.php: Moved functions relative to
	network components to functions_network_components.php.

	* godmode/modules/manage_nc_groups_form.php,
	godmode/modules/manage_network_templates_form.php,
	godmode/modules/manage_nc_groups.php: Use
	get_network_component_group_name() instead of deprecated
	give_network_component_group_name().

	* godmode/modules/manage_network_components.php: Rewritten
	to use pandora functions. Added pagination and better filtering
	and UI.

	* godmode/modules/manage_network_components_form_network.php,
	godmode/modules/manage_network_components_form_wmi.php,
	godmode/modules/manage_network_components_form.php: Some
	changes to adapt from manage_network_components file. Use
	pandora functions.

	* godmode/agentes/module_manager_editor_common.php,
	godmode/agentes/module_manager_editor.php: Include new
	functions_network_components.php file.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1701 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Esteban Sanchez 2009-05-21 11:00:50 +00:00
parent 2203005c8f
commit 960c3ddebd
13 changed files with 589 additions and 478 deletions

View File

@ -1,3 +1,37 @@
2009-05-21 Esteban Sanchez <estebans@artica.es>
* include/functions_network_components.php: Added to repository.
Functions relative to network components moved here. Added
create_network_component(), update_network_component() and
delete_network_component().
* include/functions_db.php: Removed
gve_network_component_group_name(), duplicated in
functions_network_components.php.
* include/functions_modules.php: Moved functions relative to
network components to functions_network_components.php.
* godmode/modules/manage_nc_groups_form.php,
godmode/modules/manage_network_templates_form.php,
godmode/modules/manage_nc_groups.php: Use
get_network_component_group_name() instead of deprecated
give_network_component_group_name().
* godmode/modules/manage_network_components.php: Rewritten
to use pandora functions. Added pagination and better filtering
and UI.
* godmode/modules/manage_network_components_form_network.php,
godmode/modules/manage_network_components_form_wmi.php,
godmode/modules/manage_network_components_form.php: Some
changes to adapt from manage_network_components file. Use
pandora functions.
* godmode/agentes/module_manager_editor_common.php,
godmode/agentes/module_manager_editor.php: Include new
functions_network_components.php file.
2009-05-20 Esteban Sanchez <estebans@artica.es>
* include/functions_alerts.php: Changed interface of

View File

@ -16,6 +16,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require_once ('include/functions_network_components.php');
if (is_ajax ()) {
$get_network_component = (bool) get_parameter ('get_network_component');
$snmp_walk = (bool) get_parameter ('snmp_walk');

View File

@ -91,7 +91,7 @@ function add_component_selection ($id_network_component_type) {
prepend_table_simple ($data, 'module_component');
}
require_once ('include/functions_modules.php');
require_once ('include/functions_network_components.php');
$update_module_id = (int) get_parameter_get ('update_module');

View File

@ -91,7 +91,7 @@ foreach ($groups as $group) {
$data[0] = '<a href="index.php?sec=gmodules&sec2=godmode/modules/manage_nc_groups_form&edit=1&id_sg='.$group["id_sg"].'">'.$group["name"].'</a>';
$data[1] = give_network_component_group_name ($group["parent"]);
$data[1] = get_network_component_group_name ($group["parent"]);
$data[2] = '<a href="index.php?sec=gmodules&sec2=godmode/modules/manage_nc_groups&delete=1&id_sg='.$group["id_sg"].'"
onClick="if (!confirm(\''.__('Are you sure?').'\')) return false;">
<img src="images/cross.png"></a>';

View File

@ -61,11 +61,11 @@ echo "<tr>";
echo "<td class='datos2'>".__('Parent')."</td>";
echo "<td class='datos2'>";
echo "<select name='parent'>";
echo "<option value='$parent'>".give_network_component_group_name($parent);
echo "<option value='$parent'>".get_network_component_group_name($parent);
$sql1 = "SELECT * FROM tnetwork_component_group where id_sg != '$parent'";
$result=mysql_query($sql1);
while ($row=mysql_fetch_array($result))
echo "<option value='".$row["id_sg"]."'>".give_network_component_group_name($row["id_sg"]);
echo "<option value='".$row["id_sg"]."'>".get_network_component_group_name($row["id_sg"]);
echo "</select>";
echo "</td></tr><table>";

View File

@ -16,7 +16,6 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Load global vars
require ("include/config.php");
@ -29,210 +28,221 @@ if (! give_acl ($config['id_user'], 0, "PM")) {
exit;
}
$type = "0";
$name = "";
$description = "";
$modulo_max="0";
$modulo_min="0";
$tcp_send="";
$tcp_rcv="";
$tcp_port="";
$snmp_oid="";
$snmp_community="";
$id_module_group="";
$module_interval="";
$id_group = "";
$plugin_parameter = "";
require_once ('include/functions_network_components.php');
// ------------------
// CREATE MODULE
// ------------------
$type = (int) get_parameter ('tipo');
$name = (string) get_parameter ('name');
$description = (string) get_parameter ('descripcion');
$modulo_max = (int) get_parameter ('modulo_max');
$modulo_min = (int) get_parameter ('modulo_min');
$tcp_send = (string) get_parameter ('tcp_send');
$tcp_rcv = (string) get_parameter ('tcp_rcv');
$tcp_port = (int) get_parameter ('tcp_port');
$snmp_oid = (string) get_parameter ('snmp_oid');
$snmp_community = (string) get_parameter ('snmp_community');
$id_module_group = (int) get_parameter ('id_module_group');
$module_interval = (int) get_parameter ('module_interval');
$id_group = (int) get_parameter ('id_group');
$plugin_user = (string) get_parameter ('plugin_user');
$plugin_pass = (string) get_parameter ('plugin_pass');
$plugin_parameter = (string) get_parameter ('plugin_parameter');
$max_timeout = (int) get_parameter ('max_timeout');
$id_modulo = (string) get_parameter ('id_modulo');
$id = (int) get_parameter ('id');
if (isset($_GET["create"])){ // Create module
$type = get_parameter ('tipo');
$name = get_parameter ('name');
$description = get_parameter ('descripcion');
$modulo_max = get_parameter ('modulo_max', 0);
$modulo_min = get_parameter ('modulo_min', 0);
$tcp_send = get_parameter ('tcp_send');
$tcp_rcv = get_parameter ('tcp_rcv');
$tcp_port = get_parameter ('tcp_port');
$snmp_oid = get_parameter ('snmp_oid');
$snmp_community = get_parameter ('snmp_community');
$id_module_group = get_parameter ('id_module_group');
$module_interval = get_parameter ('module_interval');
$id_group = get_parameter ('id_group');
$plugin_user = get_parameter ('plugin_user');
$plugin_pass = get_parameter ('plugin_pass');
$plugin_parameter = get_parameter ('plugin_parameter');
$max_timeout = get_parameter ('max_timeout');
$id_modulo = get_parameter ('id_modulo');
$sql = "INSERT INTO tnetwork_component (name, description, module_interval, type, max, min, tcp_send, tcp_rcv, tcp_port, snmp_oid, snmp_community, id_module_group, id_group, id_modulo, plugin_user, plugin_pass, plugin_parameter, max_timeout)
VALUES ('$name', '$description', '$module_interval', '$type', '$modulo_max', '$modulo_min', '$tcp_send', '$tcp_rcv', '$tcp_port', '$snmp_oid' ,'$snmp_community', '$id_module_group', '$id_group', '$id_modulo', '$plugin_user', '$plugin_pass', '$plugin_parameter', '$max_timeout')";
$create_component = (bool) get_parameter ('create_component');
$update_component = (bool) get_parameter ('update_component');
$delete_component = (bool) get_parameter ('delete_component');
$new_component = (bool) get_parameter ('new_component');
$id_module = process_sql ($sql, 'insert_id');
if ($id_module === false)
echo "<h3 class='error'>".__('Could not be created')."</h3>";
else {
echo "<h3 class='suc'>".__('Successfully created')."</h3>";
if ($create_component) {
$id = create_network_component ($name, $type, $id_group,
array ('description' => $description,
'module_interval' => $module_interval,
'max' => $modulo_max,
'min' => $modulo_min,
'tcp_send' => $tcp_send,
'tcp_rcv' => $tcp_rcv,
'tcp_port' => $tcp_port,
'snmp_oid' => $snmp_oid,
'snmp_community' => $snmp_community,
'id_module_group' => $id_module_group,
'id_modulo' => $id_modulo,
'plugin_user' => $plugin_user,
'plugin_pass' => $plugin_pass,
'plugin_parameter' => $plugin_parameter,
'max_timeout' => $max_timeout));
if ($id === false) {
print_error_message (__('Could not be created'));
include_once ('manage_network_components_form.php');
return;
}
print_success_message (__('Created successfully'));
$id = 0;
}
// ------------------
// UPDATE MODULE
// ------------------
if (isset($_GET["update"])){ // if modified any parameter
$id_nc = get_parameter ('id_nc');
$type = get_parameter ('tipo');
$name = get_parameter ('name');
$description = get_parameter ('descripcion');
$modulo_max = get_parameter ('modulo_max', 0);
$modulo_min = get_parameter ('modulo_min', 0);
$tcp_send = get_parameter ('tcp_send');
$tcp_rcv = get_parameter ('tcp_rcv');
$tcp_port = get_parameter ('tcp_port');
$snmp_oid = get_parameter ('snmp_oid');
$snmp_community = get_parameter ('snmp_community');
$id_module_group = get_parameter ('id_module_group');
$module_interval = get_parameter ('module_interval');
$id_group = get_parameter ('id_group');
$plugin_user = get_parameter ('plugin_user');
$plugin_pass = get_parameter ('plugin_pass');
$plugin_parameter = get_parameter ('plugin_parameter');
$max_timeout = get_parameter ('max_timeout');
$sql ="UPDATE tnetwork_component SET name = '$name',
description = '$description', snmp_oid = '$snmp_oid', snmp_community = '$snmp_community',
id_group = '$id_group', tcp_rcv = '$tcp_rcv', tcp_send = '$tcp_send', max = '$modulo_max',
min = '$modulo_min', tcp_port = '$tcp_port', id_module_group = '$id_module_group', type = '$type',
module_interval = '$module_interval', plugin_user = '$plugin_user', plugin_pass = '$plugin_pass',
plugin_parameter = '$plugin_parameter', max_timeout = '$max_timeout' WHERE id_nc = '$id_nc'";
$result = process_sql ($sql);
if (! $result)
echo "<h3 class='error'>".__('Not updated. Error updating data')."</h3>";
else
echo "<h3 class='suc'>".__('Successfully updated')."</h3>";
if ($update_component) {
$id = (int) get_parameter ('id');
$result = update_network_component ($id,
array ('type' => $type,
'name' => $name,
'id_group' => $id_group,
'description' => $description,
'module_interval' => $module_interval,
'max' => $modulo_max,
'min' => $modulo_min,
'tcp_send' => $tcp_send,
'tcp_rcv' => $tcp_rcv,
'tcp_port' => $tcp_port,
'snmp_oid' => $snmp_oid,
'snmp_community' => $snmp_community,
'id_module_group' => $id_module_group,
'id_modulo' => $id_modulo,
'plugin_user' => $plugin_user,
'plugin_pass' => $plugin_pass,
'plugin_parameter' => $plugin_parameter,
'max_timeout' => $max_timeout));
if ($result === false) {
print_error_message (__('Could not be updated'));
include_once ('manage_network_components_form.php');
return;
}
print_success_message (__('Updated successfully'));
$id = 0;
}
// ------------------
// DELETE MODULE
// ------------------
if (isset($_GET["delete"])){ // if delete
$id_nc = entrada_limpia ($_GET["id_nc"]);
$sql= "DELETE FROM tnetwork_component WHERE id_nc = ".$id_nc;
$result = process_sql ($sql);
if (! $result)
echo "<h3 class='error'>".__('Not deleted. Error deleting data')."</h3>";
else
echo "<h3 class='suc'>".__('Successfully deleted')."</h3>";
$sql = "DELETE FROM tnetwork_profile_component WHERE id_nc = ".$id_nc;
$result = process_sql ($sql);
if ($delete_component) {
$id = (int) get_parameter ('id');
$result = delete_network_component ($id);
print_result_message ($result,
__('Successfully deleted'),
__('Could not be deleted'));
$id = 0;
}
// ------------------
// SHOW MODULES
// ------------------
if ($id || $new_component) {
include_once ('manage_network_components_form.php');
return;
}
$url = get_url_refresh (array ('offset' => false,
'create_component' => false,
'update_component' => false,
'delete_component' => false,
'id_network_component' => false,
'tipo' => false,
'name' => false,
'descripcion' => false,
'modulo_max' => false,
'modulo_min' => false,
'tcp_send' => false,
'tcp_rcv' => false,
'tcp_port' => false,
'snmp_oid' => false,
'snmp_community' => false,
'id_module_group' => false,
'module_interval' => false,
'id_group' => false,
'plugin_user' => false,
'plugin_pass' => false,
'plugin_parameter' => false,
'max_timeout' => false,
'id_modulo' => false));
echo "<h2>".__('Module management')." &raquo; ";
echo __('Module component management')."</h2>";
// Show group selector
if (isset($_POST["ncgroup"])) {
$ncgroup = $_POST["ncgroup"];
} else {
$ncgroup = 0;
}
$search_id_group = (int) get_parameter ('search_id_group');
$search_string = (string) get_parameter ('search_string');
$table->width = '600px';
$table->style = array ();
$table->style[0] = 'font-weight: bold';
$table->style[2] = 'font-weight: bold';
$table->data = array ();
$table->data[0][0] = __('Group');
$table->data[0][1] = print_select (get_network_component_groups (),
'search_id_group', $search_id_group, '', __('All'), 0, true, false, false);
$table->data[0][2] = __('Search');
$table->data[0][3] = print_input_text ('search_string', $search_string, '', 25,
255, true);
$table->data[0][4] = '<div class="action-buttons">';
$table->data[0][4] .= print_submit_button (__('Search'), 'search', false,
'class="sub search"', true);
$table->data[0][4] .= '</div>';
echo "<table cellpadding='4' cellspacing='4' class='databox'>";
echo "<tr><td>";
echo "<form method='POST' action='index.php?sec=gmodules&sec2=godmode/modules/manage_network_components'>";
echo __('Group') . "&nbsp;";
echo "<select name='ncgroup' onChange='javascript:this.form.submit();'>";
if ($ncgroup != 0){
echo "<option value='$ncgroup'>".give_network_component_group_name($ncgroup)."</option>";
}
echo "<option value='0'>".__('All')."</option>";
$result = mysql_query("SELECT * FROM tnetwork_component_group WHERE id_sg != '$ncgroup' ORDER BY name");
while ($row = mysql_fetch_array ($result)) {
echo "<option value='" . $row["id_sg"] . "'>". give_network_component_group_name ($row["id_sg"])."</option>";
}
echo "</select></form></td>";
echo "<td>";
echo "<form method=post action='index.php?sec=gmodules&sec2=godmode/modules/manage_network_components_form&create=1'>";
echo "<select name='id_modulo'>";
echo "<option value='2'>".__('Create a new network component');
echo "<option value='6'>".__('Create a new WMI component');
echo "</select>&nbsp;";
echo "<input type='submit' class='sub next' name='crt' value='".__('Create')."'>";
echo "</td></tr></table>";
echo '<form method="post" action="'.$url.'">';
print_table ($table);
echo '</form>';
if ($ncgroup != 0) {
$sql1 = "SELECT * FROM tnetwork_component WHERE id_group = $ncgroup ORDER BY name";
} else {
$sql1 = "SELECT * FROM tnetwork_component ORDER BY id_group,name";
}
$filter = array ();
if ($search_id_group)
$filter['id_group'] = $search_id_group;
if ($search_string != '')
$filter[] = '(nombre LIKE "%'.$search_id_group.'%" OR description LIKE "%'.$search_id_group.'%" OR tcp_send LIKE "%'.$search_id_group.'%" OR tcp_rcv LIKE "%'.$search_id_group.'%")';
$total_components = get_network_components (false, $filter, 'COUNT(*) AS total');
$total_components = $total_components[0]['total'];
pagination ($total_components, $url);
$filter['offset'] = (int) get_parameter ('offset');
$filter['limit'] = (int) $config['block_size'];
$components = get_network_components (false, $filter,
array ('id_nc', 'name', 'description', 'id_group', 'type', 'max', 'min',
'module_interval'));
if ($components === false)
$components = array ();
unset ($table);
$table->width = '95%';
$table->head = array ();
$table->head[0] = __('Module name');
$table->head[1] = __('Type');
$table->head[2] = __('Interval');
$table->head[3] = __('Description');
$table->head[4] = __('Group');
$table->head[5] = __('Max/Min');
$table->head[6] = __('');
$table->size = array ();
$table->size[6] = '40px';
$table->data = array ();
foreach ($components as $component) {
$data = array ();
$result = mysql_query ($sql1);
if ( $row = mysql_num_rows ($result)){
echo '<table width="90%" cellpadding="4" cellspacing="4" class="databox">';
echo '<tr>';
echo "<th>".__('Module name')."</th>";
echo "<th>".__('Type')."</th>";
echo "<th>".__('Interval')."</th>";
echo "<th>".__('Description')."</th>";
echo "<th>".__('NC.Group')."</th>";
//echo "<th>".__('Module group');
echo "<th>".__('Max/Min')."</th>";
echo "<th width=50>".__('Action')."</th>";
$color=1;
while ($row=mysql_fetch_array($result)){
if ($color == 1){
$tdcolor="datos";
$color =0;
} else {
$tdcolor="datos2";
$color =1;
}
$id_tipo = $row["type"];
$id_group = $row["id_group"];
$nombre_modulo =$row["name"];
$descripcion = $row["description"];
$module_max = $row["max"];
$module_min = $row["min"];
$module_interval2 = $row["module_interval"];
$module_group2 = $row["id_module_group"];
echo "<tr><td class='".$tdcolor."_id'>";
echo "<a href='index.php?sec=gmodules&sec2=godmode/modules/manage_network_components_form&update=1&id_modulo=".$row["id_modulo"]."&id_nc=".$row["id_nc"]."'>".$nombre_modulo."</a></td>";
echo "<td class='".$tdcolor."f9'>";
if ($id_tipo > 0) {
echo "<img src='images/".show_icon_type($id_tipo)."' border='0'>";
}
if ($module_interval2!=0){
echo "<td class='$tdcolor'>".$module_interval2;
} else {
echo "<td class='$tdcolor'> N/A";
}
echo "</td>";
echo "<td class='$tdcolor'>".substr($descripcion,0,30)."</td>";
echo "<td class='$tdcolor'>".give_network_component_group_name($id_group)."</td>";
echo "<td class='$tdcolor'>";
if ($module_max == $module_min) {
$module_max = "N/A";
$module_min = "N/A";
}
echo $module_max." / ".$module_min;
echo "<td class='$tdcolor' align='center'>";
echo "<a href='index.php?sec=gmodules&sec2=godmode/modules/manage_network_components&delete=1&id_nc=".$row["id_nc"]."'>";
echo "<img src='images/cross.png' border=0 alt='".__('Delete')."'></a></td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "<div class='nf'>No modules</div>";
$data[0] = '<a href="index.php?sec=gmodules&sec2=godmode/modules/manage_network_components&id='.$component['id_nc'].'">';
$data[0] .= $component['name'];
$data[0] .= '</a>';
$data[1] = print_moduletype_icon ($component['type'], true);
$data[2] = $component['module_interval'] ? $component['module_interval'] : __('N/A ');
$data[3] = substr ($component['description'], 0, 30);
$data[4] = get_network_component_group_name ($component['id_group']);
$data[5] = $component['max']." / ".$component['min'];
$data[6] = '<form method="post" action="'.$url.'" onsubmit="if (! confirm (\''.__('Are you sure?').'\') return false)">';
$data[6] .= print_input_hidden ('delete_component', 1, true);
$data[6] .= print_input_hidden ('id', $component['id_nc'], true);
$data[6] .= print_input_hidden ('search_id_group', $search_id_group, true);
$data[6] .= print_input_hidden ('search_string', $search_string, true);
$data[6] .= print_input_image ('delete', 'images/cross.png', 1, '', true,
array ('title' => __('Delete')));
$data[6] .= '</form>';
array_push ($table->data, $data);
}
print_table ($table);
echo '<form method="post" action="'.$url.'">';
echo '<div class="action-buttons" style="width: '.$table->width.'">';
print_input_hidden ('new_component', 1);
print_select (array (2 => __('Create a new network component'),
6 => __('Create a new WMI component')),
'id_component_type', '', '', '', '', '');
print_submit_button (__('Create'), 'crt', false, 'class="sub next"');
echo '</div>';
echo '</form>'
?>

View File

@ -28,11 +28,16 @@ if (! give_acl ($config['id_user'], 0, "PM")) {
exit;
}
$id_modulo = (int) get_parameter ("id_modulo", "");
if ($id_modulo == 6) {
require ("godmode/modules/manage_network_components_form_wmi.php");
$id_component_type = (int) get_parameter ('id_component_type');
if (isset ($id)) {
$component = get_network_component ($id, false, 'id_modulo');
if ($component !== false)
$id_component_type =$component['id_modulo'];
}
else if ($id_modulo == 2){
if ($id_component_type == 6) {
require ("godmode/modules/manage_network_components_form_wmi.php");
} else if ($id_component_type == 2) {
require ("godmode/modules/manage_network_components_form_network.php");
}

View File

@ -19,8 +19,7 @@
?>
<script language="JavaScript" type="text/javascript">
<!--
function type_change()
{
function type_change () {
// type 1-4 - Generic_xxxxxx
if ((document.modulo.tipo.value > 0) && (document.modulo.tipo.value < 5)){
document.modulo.snmp_oid.style.background="#ddd";
@ -142,29 +141,27 @@ if (! give_acl ($config['id_user'], 0, "PM")) {
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
"Trying to access Agent Management");
require ("general/noaccess.php");
exit;
return;
}
if (isset($_GET["update"])){ // Edit mode
$id_nc = entrada_limpia ($_GET["id_nc"]);
$sql1 = "SELECT * FROM tnetwork_component where id_nc = $id_nc ORDER BY name";
$result=mysql_query($sql1);
$row=mysql_fetch_array($result);
$name = $row["name"];
$type = $row["type"];
$description = $row["description"];
$modulo_max = $row["max"];
$modulo_min = $row["min"];
$module_interval = $row["module_interval"];
$tcp_port = $row["tcp_port"];
$tcp_rcv = $row["tcp_rcv"];
$tcp_send = $row["tcp_send"];
$snmp_community = $row["snmp_community"];
$snmp_oid = $row["snmp_oid"];
$id_module_group = $row["id_module_group"];
$id_group = $row["id_group"];
} elseif (isset($_GET["create"])){
$id_nc = -1;
if ($id) {
$component = get_network_component ($id);
if ($component === false)
return;
$name = $component["name"];
$type = $component["type"];
$description = $component["description"];
$modulo_max = $component["max"];
$modulo_min = $component["min"];
$module_interval = $component["module_interval"];
$tcp_port = $component["tcp_port"];
$tcp_rcv = $component["tcp_rcv"];
$tcp_send = $component["tcp_send"];
$snmp_community = $component["snmp_community"];
$snmp_oid = $component["snmp_oid"];
$id_module_group = $component["id_module_group"];
$id_group = $component["id_group"];
} else {
$name = "";
$snmp_oid = "";
$description = "";
@ -183,14 +180,13 @@ if (isset($_GET["update"])){ // Edit mode
}
echo "<h2>".__('Module component management')."</h2>";
echo '<table width="700" cellspacing="4" cellpadding="4" class="databox_color">';
echo '<form name="modulo" method="post" action="index.php?sec=gmodules&sec2=godmode/modules/manage_network_components">';
echo '<table width="95%" cellspacing="4" cellpadding="4" class="databox_color">';
// Different Form url if it's a create or if it's a update form
if ($id_nc != -1) {
echo "<form name='modulo' method='post' action='index.php?sec=gmodules&sec2=godmode/modules/manage_network_components&update=1&id_nc=$id_nc'>";
} else {
echo "<form name='modulo' method='post' action='index.php?sec=gmodules&sec2=godmode/modules/manage_network_components&create=1'>";
}
echo "<tr>";
echo '<tr><td class="datos2">'.__('Module name');
echo "<td class='datos2'><input type='text' name='name' size='25' value='$name'>";
@ -202,8 +198,8 @@ echo '<select name="tipo" onChange="type_change()">';
$sql1="SELECT id_tipo, nombre FROM ttipo_modulo WHERE id_tipo != '$type' ORDER BY nombre";
$result=mysql_query($sql1);
echo "<option value='$type'>". get_moduletype_name ($type);
while ($row=mysql_fetch_array($result)){
echo "<option value='".$row["id_tipo"]."'>".$row["nombre"]."</option>";
while ($component=mysql_fetch_array($result)){
echo "<option value='".$component["id_tipo"]."'>".$component["nombre"]."</option>";
}
echo "</select>";
@ -211,14 +207,8 @@ echo "</td></tr>";
echo "<tr>";
echo "<td class='datos'>".__('Group')."</td>";
echo "<td class='datos'>";
echo "<select name='id_group'>";
echo "<option value='$id_group'>".give_network_component_group_name($id_group)."</option>";
$sql1 = "SELECT * FROM tnetwork_component_group where id_sg != '$id_group'";
$result=mysql_query($sql1);
while ($row=mysql_fetch_array($result))
echo "<option value='".$row["id_sg"]."'>".give_network_component_group_name($row["id_sg"])."</option>";
echo "</select>";
print_select (get_network_component_groups (),
'id_group', $id_group, '', '', '', false, false, false);
echo "<td class='datos'>".__('Module group')."</td>";
echo '<td class="datos">';
@ -227,8 +217,8 @@ if ($id_nc != -1 )
echo "<option value='".$id_module_group."'>".get_modulegroup_name($id_module_group);
$sql1='SELECT * FROM tmodule_group';
$result=mysql_query($sql1);
while ($row=mysql_fetch_array($result))
echo "<option value='".$row["id_mg"]."'>".$row["name"]."</option>";
while ($component=mysql_fetch_array($result))
echo "<option value='".$component["id_mg"]."'>".$component["name"]."</option>";
echo "</select>";
echo "<tr>";
@ -276,15 +266,19 @@ echo "</td></tr>";
echo "</table>";
// Module type, hidden
echo '<input type="hidden" name="id_modulo" value="2">';
print_input_hidden ('id_modulo', $id_component_type);
echo "<table width='700px'>";
echo "</tr><td align='right'>";
if ($id_nc != "-1")
echo '<input name="updbutton" type="submit" class="sub upd" value="'.__('Update').'">';
else
echo '<input name="crtbutton" type="submit" class="sub wand" value="'.__('Add').'">';
echo "</form>";
echo "</td></tr></table>";
// Update/Add buttons
echo '<div class="action-buttons" style="width: 95%">';
if ($id) {
print_input_hidden ('update_component', 1);
print_input_hidden ('id', $id);
print_submit_button (__('Update'), 'crt', false, 'class="sub upd"');
} else {
print_input_hidden ('create_component', 1);
print_submit_button (__('Create'), 'crt', false, 'class="sub next"');
}
echo '</div>';
echo '</form>';
?>

View File

@ -26,36 +26,32 @@ if (! give_acl ($config['id_user'], 0, "PM")) {
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
"Trying to access Agent Management");
require ("general/noaccess.php");
exit;
return;
}
// Update an existing component
if (isset($_GET["update"])){
$id_nc = entrada_limpia ($_GET["id_nc"]);
$sql1 = "SELECT * FROM tnetwork_component where id_nc = $id_nc ORDER BY name";
$result=mysql_query($sql1);
$row=mysql_fetch_array($result);
$name = $row["name"];
$type = $row["type"];
$description = $row["description"];
$modulo_max = $row["max"];
$modulo_min = $row["min"];
$module_interval = $row["module_interval"];
$tcp_port = $row["tcp_port"];
$tcp_rcv = $row["tcp_rcv"];
$tcp_send = $row["tcp_send"];
$snmp_community = $row["snmp_community"];
$snmp_oid = $row["snmp_oid"];
$id_module_group = $row["id_module_group"];
$id_group = $row["id_group"];
$plugin_user = $row["plugin_user"];
$plugin_pass = $row["plugin_pass"];
$plugin_parameter = $row["plugin_parameter"];
$max_timeout = $row["max_timeout"];
}
// Add a new component
elseif (isset($_GET["create"])){
$id_nc = -1;
if ($id) {
$component = get_network_component ($id);
if ($component === false)
return;
$name = $component["name"];
$type = $component["type"];
$description = $component["description"];
$modulo_max = $component["max"];
$modulo_min = $component["min"];
$module_interval = $component["module_interval"];
$tcp_port = $component["tcp_port"];
$tcp_rcv = $component["tcp_rcv"];
$tcp_send = $component["tcp_send"];
$snmp_community = $component["snmp_community"];
$snmp_oid = $component["snmp_oid"];
$id_module_group = $component["id_module_group"];
$id_group = $component["id_group"];
$plugin_user = $component["plugin_user"];
$plugin_pass = $component["plugin_pass"];
$plugin_parameter = $component["plugin_parameter"];
$max_timeout = $component["max_timeout"];
} else {
$name = "";
$snmp_oid = "";
$description = "";
@ -78,14 +74,9 @@ elseif (isset($_GET["create"])){
}
echo '<h2>' . __('WMI component management') . '</h2>';
if ($id_nc != -1) {
// Update
echo '<form name="modulo" method="post" action="index.php?sec=gmodules&sec2=godmode/modules/manage_network_components&update=1&id_nc=' . $id_nc . '">';
} else {
// Add
echo '<form name="modulo" method="post" action="index.php?sec=gmodules&sec2=godmode/modules/manage_network_components&create=1">';
}
echo '<table width="700" cellspacing="4" cellpadding="4" class="databox_color">';
echo '<form method="post" action="index.php?sec=gmodules&sec2=godmode/modules/manage_network_components">';
echo '<table width="95%" cellspacing="4" cellpadding="4" class="databox_color">';
echo '<tr>';
// Name
@ -98,8 +89,8 @@ echo '<td class="datos2">';
echo '<select name="tipo">';
echo '<option value="' . $type . '">' . get_moduletype_name ($type);
$result = mysql_query('SELECT id_tipo, nombre FROM ttipo_modulo WHERE categoria IN (0,1,2) ORDER BY nombre;');
while ($row = mysql_fetch_array($result)){
echo '<option value="' . $row['id_tipo'] . '">' . $row['nombre'] . '</option>';
while ($component = mysql_fetch_array($result)){
echo '<option value="' . $component['id_tipo'] . '">' . $component['nombre'] . '</option>';
}
echo '</select>';
echo '</td></tr>';
@ -108,24 +99,19 @@ echo '<tr>';
// Component group
echo '<td class="datos">' . __('Group') . '</td>';
echo '<td class="datos">';
echo '<select name="id_group">';
echo '<option value="' . $id_group . '">' . give_network_component_group_name($id_group) . '</option>';
$result = mysql_query('SELECT * FROM tnetwork_component_group where id_sg != \'' . $id_group . '\';');
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row['id_sg'] . '">' . give_network_component_group_name($row['id_sg']) . '</option>';
}
echo '</select>';
print_select (get_network_component_groups (),
'id_group', $id_group, '', '', '', false, false, false);
// Module group
echo '<td class="datos">' . __('Module group') . '</td>';
echo '<td class="datos">';
echo '<select name="id_module_group">';
if ($id_nc != -1 ) {
if ($id) {
echo '<option value="' . $id_module_group . '">' . get_modulegroup_name($id_module_group);
}
$result = mysql_query('SELECT * FROM tmodule_group');
while ($row = mysql_fetch_array($result))
echo '<option value="' . $row['id_mg'] . '">' . $row['name'] . '</option>';
while ($component = mysql_fetch_array($result))
echo '<option value="' . $component['id_mg'] . '">' . $component['name'] . '</option>';
echo '</select>';
echo '<tr>';
@ -205,17 +191,19 @@ echo '</textarea>';
echo '</td></tr>';
echo '</table>';
// Module type, hidden
echo '<input type="hidden" name="id_modulo" value="6">';
print_input_hidden ('id_modulo', $id_component_type);
// Update/Add buttons
echo '<table width="700px">';
echo '</tr><td align="right">';
if ($id_nc != '-1')
echo '<input name="updbutton" type="submit" class="sub upd" value="'.__('Update').'">';
else
echo '<input name="crtbutton" type="submit" class="sub wand" value="'.__('Add').'">';
echo '</td></tr></table>';
echo '<div class="action-buttons" style="width: 95%">';
if ($id) {
print_input_hidden ('update_component', 1);
print_input_hidden ('id', $id);
print_submit_button (__('Update'), 'crt', false, 'class="sub upd"');
} else {
print_input_hidden ('create_component', 1);
print_submit_button (__('Create'), 'crt', false, 'class="sub next"');
}
echo '</div>';
echo '</form>';
?>

View File

@ -159,7 +159,7 @@ if ($id_np > 0) {
$data[0] = $row["name"];
$data[1] = '<img src="images/'.show_icon_type($row["type"]).'" border="0" />';
$data[2] = substr($row["description"],0,30);
$data[3] = give_network_component_group_name ($row["group"]);
$data[3] = get_network_component_group_name ($row["group"]);
$data[4] = print_checkbox ("components[]", $row["component_id"], false, true);
array_push ($table->data, $data);
}

View File

@ -1325,17 +1325,6 @@ function give_modulecategory_name ($id_category) {
return __('Unknown');
}
/**
* Get a network component group name
*
* @param int Id network component group.
*
* @return string Name of the given network component group
*/
function give_network_component_group_name ($id_network_component_group) {
return (string) get_db_value ('name', 'tnetwork_component_group', 'id_sg', $id_network_component_group);
}
/**
* Get a network profile name.
*

View File

@ -73,171 +73,6 @@ function copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent) {
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, 'id_module_group = 10'));
</code>
* @param mixed Fields to retrieve on each component.
*
* @return array A list of network components matching. Empty array is returned
* if none matches.
*/
function get_network_components ($id_module, $filter = false, $fields = false) {
if (empty ($id_module))
return array ();
if (!is_array ($filter))
$filter = array ();
$filter['id_modulo'] = (int) $id_module;
$components = get_db_all_rows_filter ('tnetwork_component',
$filter, $fields);
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_filter ('tnetwork_component_group',
array ('parent' => $id_parent),
array ('id_sg', 'name'));
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 = (int) $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) {
$count = get_db_value_filter ('COUNT(*)', 'tnetwork_component',
array ('id_group' => (int) $group['id_sg'],
'id_modulo' => $id_module_components));
if ($count > 0)
$retval[$group['id_sg']] = $prefix.$group['name'];
}
}
}
return $retval;
}
/**
* Get a network component.
*
* @param int Component id to be fetched.
* @param array Extra filter.
* @param array Fields to be fetched.
*
* @return array A network component matching id and filter.
*/
function get_network_component ($id_network_component, $filter = false, $fields = false) {
if (empty ($id_network_component))
return false;
if (! is_array ($filter))
$filter = array ();
$filter['id_nc'] = (int) $id_network_component;
return get_db_row_filter ('tnetwork_component', $filter, $fields);
}
/**
* Creates a module in an agent from a network component.
*
* @param int Component id to be created.
* @param int Agent id to create module in.
*
* @return array New agent module id if created. False if could not be created
*/
function create_agent_module_from_network_component ($id_network_component, $id_agent) {
if (! user_access_to_agent ($id_agent, 'AW'))
return false;
$component = get_network_component ($id_network_component,
false,
array ('name',
'description AS descripcion',
'type AS id_tipo_modulo',
'max',
'min',
'module_interval',
'tcp_port',
'tcp_send',
'tcp_rcv',
'snmp_community',
'snmp_oid',
'id_module_group',
'id_modulo',
'plugin_user',
'plugin_pass',
'plugin_parameter',
'max_timeout',
'history_data',
'min_warning',
'max_warning',
'min_critical',
'max_critical',
'min_ff_event'));
if (empty ($component))
return false;
$values = $component;
$len = count ($values) / 2;
for ($i = 0; $i < $len; $i++)
unset ($values[$i]);
$name = $values['name'];
unset ($values['name']);
$values['ip_target'] = get_agent_address ($id_agent);
return create_agent_module ($id_agent, $name, $values);
}
/**
* Get the name of a network components group.
*
* @param int Network components group id.
*
* @return string The name of the components group.
*/
function get_network_component_group_name ($id_network_component_group) {
if (empty ($id_network_component_group))
return false;
return @get_db_value ('name', 'tnetwork_component_group', 'id_sg', $id_network_component_group);
}
/**
* Deletes a module from an agent.
*

View File

@ -0,0 +1,254 @@
<?php
// Pandora FMS - the Flexible Monitoring System
// ============================================
// Copyright (c) 2009 Artica Soluciones Tecnologicas, http://www.artica.es
// Copyright (c) 2009 Esteban Sanchez <estebans@artica.es>
// Please see http://pandora.sourceforge.net 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 (LGPL)
// as published by the Free Software Foundation for 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
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require_once ('include/functions_modules.php');
/**
* 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, 'id_module_group = 10'));
</code>
* @param mixed Fields to retrieve on each component.
*
* @return array A list of network components matching. Empty array is returned
* if none matches.
*/
function get_network_components ($id_module, $filter = false, $fields = false) {
if (! is_array ($filter))
$filter = array ();
if (! empty ($id_module))
$filter['id_modulo'] = (int) $id_module;
$components = get_db_all_rows_filter ('tnetwork_component',
$filter, $fields);
if ($components === false)
return array ();
return $components;
}
/**
* Get the name of a network components group.
*
* @param int Network components group id.
*
* @return string The name of the components group.
*/
function get_network_component_group_name ($id_network_component_group) {
if (empty ($id_network_component_group))
return false;
return @get_db_value ('name', 'tnetwork_component_group', 'id_sg', $id_network_component_group);
}
/**
* 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 component 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_filter ('tnetwork_component_group',
array ('parent' => $id_parent),
array ('id_sg', 'name'));
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 = (int) $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) {
$count = get_db_value_filter ('COUNT(*)', 'tnetwork_component',
array ('id_group' => (int) $group['id_sg'],
'id_modulo' => $id_module_components));
if ($count > 0)
$retval[$group['id_sg']] = $prefix.$group['name'];
}
}
}
return $retval;
}
/**
* Get a network component.
*
* @param int Component id to be fetched.
* @param array Extra filter.
* @param array Fields to be fetched.
*
* @return array A network component matching id and filter.
*/
function get_network_component ($id_network_component, $filter = false, $fields = false) {
if (empty ($id_network_component))
return false;
if (! is_array ($filter))
$filter = array ();
$filter['id_nc'] = (int) $id_network_component;
return get_db_row_filter ('tnetwork_component', $filter, $fields);
}
/**
* Creates a network component.
*
* @param string Component name.
* @param string Component type.
* @param string Component group id.
* @param array Extra values to be set.
*
* @return int New component id. False on error.
*/
function create_network_component ($name, $type, $id_group, $values = false) {
if (empty ($name))
return false;
if (empty ($type))
return false;
if (! is_array ($values))
$values = array ();
$values['name'] = $name;
$values['type'] = (int) $type;
$values['id_group'] = (int) $id_group;
return @process_sql_insert ('tnetwork_component',
$values);
}
/**
* Updates a network component.
*
* @param int Component id.
* @param array Values to be set.
*
* @return bool True if updated. False on error.
*/
function update_network_component ($id_network_component, $values = false) {
if (empty ($id_network_component))
return false;
$component = get_network_component ($id_network_component);
if (empty ($component))
return false;
if (! is_array ($values))
return false;
return (@process_sql_update ('tnetwork_component',
$values,
array ('id_nc' => (int) $id_network_component)) !== false);
}
/**
* Deletes a network component.
*
* @param int Component id.
* @param array Extra filter.
*
* @return bool True if deleted. False on error.
*/
function delete_network_component ($id_network_component) {
if (empty ($id_network_component))
return false;
$filter = array ();
$filter['id_nc'] = $id_network_component;
@process_sql_delete ('tnetwork_profile_component', $filter);
return (@process_sql_delete ('tnetwork_component', $filter) !== false);
}
/**
* Creates a module in an agent from a network component.
*
* @param int Component id to be created.
* @param int Agent id to create module in.
*
* @return array New agent module id if created. False if could not be created
*/
function create_agent_module_from_network_component ($id_network_component, $id_agent) {
if (! user_access_to_agent ($id_agent, 'AW'))
return false;
$component = get_network_component ($id_network_component,
false,
array ('name',
'description AS descripcion',
'type AS id_tipo_modulo',
'max',
'min',
'module_interval',
'tcp_port',
'tcp_send',
'tcp_rcv',
'snmp_community',
'snmp_oid',
'id_module_group',
'id_modulo',
'plugin_user',
'plugin_pass',
'plugin_parameter',
'max_timeout',
'history_data',
'min_warning',
'max_warning',
'min_critical',
'max_critical',
'min_ff_event'));
if (empty ($component))
return false;
$values = $component;
$len = count ($values) / 2;
for ($i = 0; $i < $len; $i++)
unset ($values[$i]);
$name = $values['name'];
unset ($values['name']);
$values['ip_target'] = get_agent_address ($id_agent);
return create_agent_module ($id_agent, $name, $values);
}
?>