From a5bcd25e5eb4db60df454555300cfb09251f888b Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Tue, 2 Feb 2016 14:10:13 +0100 Subject: [PATCH] New maps in progress... (List, edit and creation pages) --- pandora_console/include/constants.php | 10 + pandora_console/include/functions_maps.php | 5 + .../operation/maps/networkmap_editor.php | 206 +++++++++++++++--- .../operation/maps/networkmap_list.php | 195 ++++++++++++++--- 4 files changed, 362 insertions(+), 54 deletions(-) diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 585a3c0d09..320f358eee 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -475,4 +475,14 @@ define("MAP_GENERATION_PLANO", 1); define("MAP_GENERATION_RADIAL", 2); define("MAP_GENERATION_SPRING1", 3); define("MAP_GENERATION_SPRING2", 4); + +define("MAP_SOURCE_GROUP", 0); +define("MAP_SOURCE_IP_MASK", 1); + +/* Background options */ +define("CENTER", 0); +define("MOSAIC", 1); +define("STRECH", 2); +define("FIT_WIDTH", 3); +define("FIT_HEIGH", 4); ?> diff --git a/pandora_console/include/functions_maps.php b/pandora_console/include/functions_maps.php index 385375296f..b56fbb403b 100644 --- a/pandora_console/include/functions_maps.php +++ b/pandora_console/include/functions_maps.php @@ -72,6 +72,11 @@ function maps_duplicate_map($id) { return (int)$result; } +function maps_delete_map($id) { + $where = 'id=' . $id; + db_process_sql_delete('tmap', $where); +} + function maps_get_count_nodes($id) { $result = db_get_sql("SELECT COUNT(*) FROM titem WHERE id_map = " . $id); return (int)$result; diff --git a/pandora_console/operation/maps/networkmap_editor.php b/pandora_console/operation/maps/networkmap_editor.php index 42d53af534..714738b3bc 100644 --- a/pandora_console/operation/maps/networkmap_editor.php +++ b/pandora_console/operation/maps/networkmap_editor.php @@ -26,40 +26,190 @@ $networkmaps_manage = check_acl ($config['id_user'], 0, "MM"); $id = (int)get_parameter('id_networkmap', 0); $edit_networkmap = (int)get_parameter('edit_networkmap', 0); -$add_networkmap = (int)get_parameter('add_networkmap', 0); +$create_networkmap = (int)get_parameter('create_networkmap', 0); +if ($create_networkmap) { + $type = MAP_TYPE_NETWORKMAP; + $subtype = MAP_SUBTYPE_GROUPS; + $name = ""; + $description = ""; + $source_period = 60 * 5; + $source = MAP_SOURCE_GROUP; + $source_data = "id_group"; + $generation_method = MAP_GENERATION_CIRCULAR; + $show_groups_filter = false; + $show_module_plugins = false; + $show_snmp_modules = false; + $show_modules = false; + $show_policy_modules = false; + $show_pandora_nodes = false; + $show_module_group = false; + $id_tag = 0; + $text = ""; +} + +$not_found = false; +$disabled_select = false; if ($edit_networkmap) { - $name = (string) get_parameter ('name'); - $description = (string) get_parameter ('description'); - $id_group = (int) get_parameter ('id_group'); - $type = (string) get_parameter ('type'); + $disabled_select= true; + $values = db_get_row('tmap', 'id', $id); - if ($name == "") { - $result = 0; + if ($values === false) { + $not_found = true; } else { - $result = maps_update_map ($id, - array ('name' => $name, - 'id_group' => $id_group, - 'description' => $description), - 'type' => $type); + $id_group = $values['id_group']; + + $networkmap_write = check_acl ($config['id_user'], $id_group, "MW"); + $networkmap_manage = check_acl ($config['id_user'], $id_group, "MM"); + + if (!$networkmap_write && !$networkmap_manage) { + db_pandora_audit("ACL Violation", + "Trying to access networkmap"); + require ("general/noaccess.php"); + return; + } + + $type = MAP_TYPE_NETWORKMAP; + $subtype = $values['subtype']; + $name = io_safe_output($values['name']); + $description = io_safe_output($values['description']); + $source_period = $values['source_period']; + $source = $values['source']; + if ($source == 'group') { + $source_data = 'id_group'; + } + else { + $source_data = 'ip_mask'; + } + $generation_method = $values['generation_method']; + $filter = json_decode($values['filter'], true); + $show_groups_filter = $filter['show_groups']; + $show_module_plugins = $filter['show_groups']; + $show_snmp_modules = $filter['show_groups']; + $show_modules = $filter['show_groups']; + $show_policy_modules = $filter['show_groups']; + $show_pandora_nodes = $filter['show_groups']; + $show_module_group = $filter['show_groups']; + $id_tag = $filter['show_groups']; + $text = io_safe_output($filter['show_groups']); } - - $info = ' Name: ' . $name . ' Description: ' . $description . ' ID group: ' . $id_group . ' Type: ' . $type; - - if ($id) { - db_pandora_audit("Networkmap management", "Update networkmap #" . $id, false, false, $info); - } - else { - db_pandora_audit("Networkmap management", "Fail to update networkmap #$id", false, false, $info); - } - - ui_print_result_message ($result, - __('Successfully updated'), - __('Could not be updated')); -} -else if ($add_networkmap) { - } +//+++++++++++++++TABLE TO CREATE/EDIT NETWORKMAP++++++++++++++++++++++ +if ($create_networkmap) { + ui_print_page_header(__('Create networkmap'), "images/bricks.png", + false, "network_list", false); +} +else { + ui_print_page_header(__('Update networkmap'), "images/bricks.png", + false, "network_list", false); +} + +if ($not_found) { + ui_print_error_message(__('Not found networkmap')); +} +else { + $table = null; + $table->id = 'form_editor'; + + $table->width = '98%'; + $table->class = "databox_color"; + + $table->head = array(); + + $table->size = array(); + $table->size[0] = '30%'; + + $table->style = array (); + $table->style[0] = 'font-weight: bold; width: 150px;'; + $table->data = array(); + + $subtype = array( + MAP_SUBTYPE_TOPOLOGY => 'Topology', + MAP_SUBTYPE_POLICIES => 'Policies', + MAP_SUBTYPE_GROUPS => 'Groups', + MAP_SUBTYPE_RADIAL_DYNAMIC => 'Radial Dynamic' + ); + + $table->data[0][0] = __('Subtype'); + $table->data[0][1] = html_print_select($subtype, 'subtype', $subtype, + '', '', 'Topology', true, false, true, '', + $disabled_select); + + $table->data['source'][0] = __('Source'); + $table->data['source'][1] = + html_print_radio_button('source', MAP_SOURCE_GROUP, __('Group'), $source, true) . + html_print_radio_button('source', MAP_SOURCE_IP_MASK, __('CIDR IP mask'), $source, true); + + $generation_method = array( + MAP_GENERATION_RADIAL => 'Radial', + MAP_GENERATION_PLANO => 'Flat', + MAP_GENERATION_CIRCULAR => 'Circular', + MAP_GENERATION_SPRING1 => 'Spring1', + MAP_GENERATION_SPRING2 => 'Spring2' + ); + + $table->data[2][0] = __('Method generation networkmap'); + $table->data[2][1] = html_print_select($generation_method, 'generation_method', $generation_method, + '', '', 'twopi', true, false, true, '', + $disabled_select); + + $table->data[3][0] = __('Name'); + $table->data[3][1] = html_print_input_text ('name', $name, '', 30, + 100,true); + + $table->data[4][0] = __('Group'); + $table->data[4][1] = html_print_select_groups(false, "AR", true, + 'id_group', $id_group, '', '', 0, true); + + $table->data[5][0] = __('Description'); + $table->data[5][1] = html_print_textarea ("description", 2, 65, $description, '', true); + + $table->data[6][0] = __('Show groups filter'); + $table->data[6][1] = html_print_checkbox('show_groups_filter', '1', $show_groups_filter, true); + + $table->data[7][0] = __('Show module plugins'); + $table->data[7][1] = html_print_checkbox('show_groups_filter', '1', $show_module_plugins, true); + + $table->data[8][0] = __('Show snmp modules'); + $table->data[8][1] = html_print_checkbox('show_groups_filter', '1', $show_snmp_modules, true); + + $table->data[9][0] = __('Show modules'); + $table->data[9][1] = html_print_checkbox('show_groups_filter', '1', $show_modules, true); + + $table->data[10][0] = __('Show policy modules'); + $table->data[10][1] = html_print_checkbox('show_groups_filter', '1', $show_policy_modules, true); + + $table->data[11][0] = __('Show pandora nodes'); + $table->data[11][1] = html_print_checkbox('show_groups_filter', '1', $show_pandora_nodes, true); + + $table->data[12][0] = __('Show module group'); + $table->data[12][1] = html_print_checkbox('show_groups_filter', '1', $show_module_group, true); + + $table->data[13][0] = __('Filter by tags'); + $table->data[13][1] = html_print_select (tags_get_user_tags(), "id_tag", $id_tag, '', __('All'), 0, true, false, true, '', false, ''); + + $table->data[14][0] = __('Filter by text'); + $table->data[14][1] = html_print_input_text ('text', $text, '', 20, + 10,true); + + html_print_table($table); + + echo '
'; + echo "
"; + if ($create_networkmap) { + html_print_input_hidden ('save_networkmap', 1); + html_print_submit_button (__('Save networkmap'), 'crt', false, + 'class="sub next"'); + } + else if ($edit_networkmap) { + html_print_input_hidden ('id_networkmap', $id); + html_print_input_hidden ('update_networkmap', 1); + html_print_submit_button (__('Update networkmap'), 'crt', false, + 'class="sub next"'); + } + echo "
"; + echo "
"; +} ?> diff --git a/pandora_console/operation/maps/networkmap_list.php b/pandora_console/operation/maps/networkmap_list.php index 7ea294d2a5..0775207b70 100644 --- a/pandora_console/operation/maps/networkmap_list.php +++ b/pandora_console/operation/maps/networkmap_list.php @@ -58,35 +58,173 @@ if ($migrate_open_networkmaps) width = "100%"; $table->class = "databox data"; @@ -147,7 +285,7 @@ else { $data['name'] = $networkmap['name']; $data['name'] = '' . $networkmap['name'] . ''; @@ -173,19 +311,19 @@ else { } $data['copy'] = '' . html_print_image("images/copy.png", true) . ''; $data['edit'] = '' . html_print_image("images/edit.png", true) . ''; $data['delete'] = '' . @@ -196,6 +334,11 @@ else { html_print_table($table); } +echo '
'; +html_print_input_hidden ('create_networkmap', 1); +html_print_submit_button (__('Create'), "crt", false, 'class="sub next"'); +echo '
'; + ?>