diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 64d47622dc..e150d60aeb 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,37 @@ +2009-05-21 Esteban Sanchez + + * 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 * include/functions_alerts.php: Changed interface of diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index 666843b343..0141fe07d4 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -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'); diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php index 68018593c4..0589dbd0fb 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_common.php +++ b/pandora_console/godmode/agentes/module_manager_editor_common.php @@ -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'); diff --git a/pandora_console/godmode/modules/manage_nc_groups.php b/pandora_console/godmode/modules/manage_nc_groups.php index ea65477af1..ca2f628757 100644 --- a/pandora_console/godmode/modules/manage_nc_groups.php +++ b/pandora_console/godmode/modules/manage_nc_groups.php @@ -91,7 +91,7 @@ foreach ($groups as $group) { $data[0] = ''.$group["name"].''; - $data[1] = give_network_component_group_name ($group["parent"]); + $data[1] = get_network_component_group_name ($group["parent"]); $data[2] = ' '; diff --git a/pandora_console/godmode/modules/manage_nc_groups_form.php b/pandora_console/godmode/modules/manage_nc_groups_form.php index 804df639c4..164c374963 100644 --- a/pandora_console/godmode/modules/manage_nc_groups_form.php +++ b/pandora_console/godmode/modules/manage_nc_groups_form.php @@ -61,11 +61,11 @@ echo ""; echo "".__('Parent').""; echo ""; echo ""; echo ""; diff --git a/pandora_console/godmode/modules/manage_network_components.php b/pandora_console/godmode/modules/manage_network_components.php index ed3d314b67..120951c876 100644 --- a/pandora_console/godmode/modules/manage_network_components.php +++ b/pandora_console/godmode/modules/manage_network_components.php @@ -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 "

".__('Could not be created')."

"; - else { - echo "

".__('Successfully created')."

"; +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 "

".__('Not updated. Error updating data')."

"; - else - echo "

".__('Successfully updated')."

"; +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 "

".__('Not deleted. Error deleting data')."

"; - else - echo "

".__('Successfully deleted')."

"; - $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 "

".__('Module management')." » "; echo __('Module component management')."

"; -// 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] = '
'; +$table->data[0][4] .= print_submit_button (__('Search'), 'search', false, + 'class="sub search"', true); +$table->data[0][4] .= '
'; -echo "
"; -echo ""; -echo "
"; -echo "
"; -echo __('Group') . " "; -echo "
"; -echo "
"; -echo " "; -echo ""; -echo "
"; +echo ''; +print_table ($table); +echo ''; -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 ''; - echo ''; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - //echo ""; - echo ""; - $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 ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - } - echo "
".__('Module name')."".__('Type')."".__('Interval')."".__('Description')."".__('NC.Group')."".__('Module group'); - echo "".__('Max/Min')."".__('Action')."
"; - echo "".$nombre_modulo.""; - if ($id_tipo > 0) { - echo ""; - } - if ($module_interval2!=0){ - echo "".$module_interval2; - } else { - echo " N/A"; - } - echo "".substr($descripcion,0,30)."".give_network_component_group_name($id_group).""; - if ($module_max == $module_min) { - $module_max = "N/A"; - $module_min = "N/A"; - } - echo $module_max." / ".$module_min; - echo ""; - echo ""; - echo "".__(
"; -} else { - echo "
No modules
"; + $data[0] = ''; + $data[0] .= $component['name']; + $data[0] .= ''; + $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] = '
'; + $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] .= '
'; + + array_push ($table->data, $data); } +print_table ($table); + +echo '
'; +echo '
'; +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 '
'; +echo '
' ?> diff --git a/pandora_console/godmode/modules/manage_network_components_form.php b/pandora_console/godmode/modules/manage_network_components_form.php index 682e4277c1..6ff9ad146f 100644 --- a/pandora_console/godmode/modules/manage_network_components_form.php +++ b/pandora_console/godmode/modules/manage_network_components_form.php @@ -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"); } diff --git a/pandora_console/godmode/modules/manage_network_components_form_network.php b/pandora_console/godmode/modules/manage_network_components_form_network.php index 5d6e827aaf..d8d9ca6487 100644 --- a/pandora_console/godmode/modules/manage_network_components_form_network.php +++ b/pandora_console/godmode/modules/manage_network_components_form_network.php @@ -19,8 +19,7 @@ ?>