diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index 9428a362bc..1d41d1ccba 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -494,6 +494,25 @@ if ($id_agent_module) { $module_macros = []; } + + $create_network_from_snmp_browser = get_parameter('create_network_from_snmp_browser', 0); + + if ($create_network_from_snmp_browser) { + $moduletype = get_parameter('id_component_type', 2); + $id_module_type = get_parameter('type', 1); + $name = get_parameter('name', ''); + $description = get_parameter('description'); + $ip_target = get_parameter('target_ip'); + $snmp_community = get_parameter('community'); + $snmp_version = get_parameter('snmp_version'); + $snmp3_auth_user = get_parameter('snmp3_auth_user'); + $snmp3_auth_pass = get_parameter('snmp3_auth_pass'); + $snmp3_auth_method = get_parameter('snmp3_auth_method'); + $snmp3_privacy_method = get_parameter('snmp3_privacy_method'); + $snmp3_privacy_pass = get_parameter('snmp3_privacy_pass'); + $snmp3_security_level = get_parameter('snmp3_security_level'); + $snmp_oid = get_parameter('snmp_oid'); + } } $is_function_policies = enterprise_include_once( diff --git a/pandora_console/godmode/agentes/module_manager_editor_network.php b/pandora_console/godmode/agentes/module_manager_editor_network.php index 0ce82eddd9..f179da95fe 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_network.php +++ b/pandora_console/godmode/agentes/module_manager_editor_network.php @@ -183,7 +183,7 @@ if ($id_module_type >= 15 && $id_module_type <= 18) { $data[3] = html_print_select( $snmp_versions, 'snmp_version', - $tcp_send, + $snmp_version, '', '', '', @@ -496,7 +496,7 @@ if ($id_module_type !== 34 $table_simple->rowstyle['row-cmd-row-2'] = 'display: none;'; } -snmp_browser_print_container(false, '100%', '60%', 'none'); +snmp_browser_print_container(false, '100%', '60%', 'display:none'); ?> + } + + if (is_array($ids)) { + foreach ($ids as $id) { + // Id < 0 for error codes. + if (!$id || $id < 0) { + array_push($fail_modules, $oid['oid']); + } + } + } else { + if (empty($id)) { + array_push($fail_modules, $oid['oid']); + } + } + } + + return $fail_modules; +} + + +/** + * Prints html for create module from snmp massive dialog + * + * @param string $url_form + * @param string $title + * @param boolean $return + * @return void + */ +function snmp_browser_print_create_module_massive($target='agent', $snmp_conf, $return=false) +{ + // String for labels. + switch ($target) { + case 'agent': + $target_item = 'Agents'; + break; + + case 'policy': + $target_item = 'Policies'; + break; + } + + $output .= "
"; + + $strict_user = db_get_value( + 'strict_acl', + 'tusuario', + 'id_user', + $config['id_user'] + ); + + $keys_field = 'id_grupo'; + + $table = new stdClass(); + $table->width = '100%'; + $table->data = []; + + $table->data[0][0] = __('Filter group').""; + + $table->data[0][1] = html_print_select_groups( + false, + 'RR', + users_can_manage_group_all('RR'), + 'group', + '', + '', + '', + 0, + true, + false, + false, + '', + false, + false, + false, + false, + $keys_field, + $strict_user + ); + + $table->data[1][0] = __('Search').""; + $table->data[1][1] = html_print_input_text( + 'filter', + '', + '', + 20, + 150, + true + ); + + $table->data[2][0] = __($target_item.' available').html_print_input_image('select_all_left', 'images/tick.png', 1, '', true, ['title' => __('Select all')]); + $table->data[2][1] = ''; + $table->data[2][2] = __($target_item.' to apply').html_print_input_image('select_all_right', 'images/tick.png', 1, '', true, ['title' => __('Select all')]); + + $table->data[3][0] = html_print_select( + [], + 'id_item[]', + 0, + false, + '', + '', + true, + true, + true, + '', + false, + 'width: 100%;', + [] + ); + + if ($target == 'policy') { + if (enterprise_installed()) { + $table->data[4][0] = html_print_button( + __('Create new policy'), + 'snmp_browser_create_policy', + false, + '', + 'class="sub add" style="margin-left:0px"', + true + ); + } + + $table->data[4][1] = html_print_div( + [ + 'style' => 'display:none', + 'id' => 'policy_modal', + ], + true + ); + } + + $table->cellstyle[3][1] = 'text-align: center'; + $table->data[3][1] = html_print_image( + 'images/darrowright.png', + true, + [ + 'id' => 'right', + 'title' => __('Add'), + ] + ).'



'.html_print_image( + 'images/darrowleft.png', + true, + [ + 'id' => 'left', + 'title' => __('Undo'), + ] + ); + $table->data[3][2] = html_print_select( + [], + 'id_item2[]', + 0, + false, + '', + '', + true, + true, + true, + '', + false, + 'width: 100%;', + [] + ); + + $output .= html_print_table($table, true); + + // SNMP extradata. + $output .= html_print_input_hidden('snmp_extradata', $snmp_conf, true); + + $output .= '
'; + + $output .= ''; + + $script = 'add_module_massive_controller("'.$target.'")'; + + // Add script to output. + $output .= ''; + + if ($return) { + return $output; + } else { + echo $output; + } + +} + + +/** + * Prints form from create snmp module dialog + * + * @param boolean $return + * @return void + */ +function snmp_browser_print_create_modules($return=false) +{ + $output = "'; + + if ($return) { + return $output; + } + + echo $output; + +} + + +function snmp_browser_print_create_policy() +{ + $table = new stdClass(); + + $table->width = '100%'; + $table->class = 'databox filters'; + $table->style = []; + $table->style[0] = 'font-weight: bold; vertical-align: top'; + $table->data = []; + + $table->data[0][0] = __('Name'); + $table->data[0][1] = html_print_input_text('name', $name, '', '60%', 150, true); + + $table->data[1][0] = __('Group'); + $table->data[1][1] = html_print_select_groups( + false, + 'AW', + false, + 'id_group', + $id_group, + '', + '', + '', + true + ); + $table->data[1][1] .= ' '; + $table->data[1][1] .= ui_print_group_icon($id_group, true, 'groups_small', '', false); + $table->data[1][1] .= ''; + + $table->data[2][0] = __('Description'); + $table->data[2][1] = html_print_textarea('description', 3, 30, $description, '', true); + + $output = '
'; + $output .= html_print_table($table, true); + $output .= '
'; + + return $output; + +} diff --git a/pandora_console/include/javascript/pandora_snmp_browser.js b/pandora_console/include/javascript/pandora_snmp_browser.js index dbe8121a64..ef746aa5f4 100644 --- a/pandora_console/include/javascript/pandora_snmp_browser.js +++ b/pandora_console/include/javascript/pandora_snmp_browser.js @@ -42,7 +42,7 @@ function snmpBrowse() { params["snmp3_browser_privacy_method"] = snmp3_privacy_method; params["snmp3_browser_privacy_pass"] = snmp3_privacy_pass; params["action"] = "snmptree"; - params["page"] = "operation/snmpconsole/snmp_browser"; + params["page"] = "include/ajax/snmp_browser.ajax"; // Browse! jQuery.ajax({ @@ -57,6 +57,63 @@ function snmpBrowse() { // Load the SNMP tree $("#snmp_browser").html(data); + + // Manage click and select events. + snmp_browser_events_manage(); + } + }); +} + +function snmp_browser_events_manage() { + // Hide create buttons. + $("#snmp_create_buttons").hide(); + + $("input[id^=checkbox-create]").change(function() { + if ($(this).is(":checked")) { + $("#snmp_create_buttons").show(); + var id_input = $(this).attr("id"); + id_input = id_input.match("checkbox-create_([0-9]+)"); + var checks = $("#ul_" + id_input[1]) + .find("input") + .map(function() { + if (this.id.indexOf("checkbox-create_") != -1) { + return this.id; + } + }) + .get(); + + checks.forEach(function(product, index) { + $("#" + product).prop("checked", "true"); + }); + } else { + var id_input = $(this).attr("id"); + + id_input = id_input.match("checkbox-create_([0-9]+)"); + var checks = $("#ul_" + id_input[1]) + .find("input") + .map(function() { + if (this.id.indexOf("checkbox-create_") != -1) { + return this.id; + } + }) + .get(); + + checks.forEach(function(product, index) { + $("#" + product).prop("checked", false); + }); + } + + // Hide buttons if no ckbox is checked. + var checked = false; + $("input[id^=checkbox-create]").each(function() { + checked = $(this).is(":checked"); + if (checked == true) { + return false; + } + }); + + if (checked == false) { + $("#snmp_create_buttons").hide(); } }); } @@ -187,7 +244,7 @@ function snmpGet(oid) { "server_to_exec=" + server_to_exec, "action=" + "snmpget", "custom_action=" + custom_action, - "page=operation/snmpconsole/snmp_browser" + "page=include/ajax/snmp_browser.ajax" ]; // SNMP get! @@ -224,7 +281,7 @@ function hideOIDData() { // Search the SNMP tree for a matching string function searchText() { var text = $("#text-search_text").val(); - var regexp = new RegExp(text); + var regexp = new RegExp(text, "i"); var search_matches_translation = $( "#hidden-search_matches_translation" ).val(); @@ -348,6 +405,7 @@ function searchNextMatch() { var id = $(".match:eq(" + search_index + ")").attr("id"); // Scroll + var body = $("html, body"); $("#snmp_browser").animate( { scrollTop: @@ -355,7 +413,16 @@ function searchNextMatch() { $("#" + id).offset().top - $("#snmp_browser").offset().top }, - 1000 + 1000, + function() { + // Blink. + $("#" + id) + .fadeOut(100) + .fadeIn(100) + .fadeOut(100) + .fadeIn(100) + .focus(); + } ); // Save the search index @@ -384,7 +451,16 @@ function searchPrevMatch() { $("#" + id).offset().top - $("#snmp_browser").offset().top }, - 1000 + 1000, + function() { + // Blink. + $("#" + id) + .fadeOut(100) + .fadeIn(100) + .fadeOut(100) + .fadeIn(100) + .focus(); + } ); // Save the search index @@ -464,3 +540,99 @@ function setOID() { // Close the SNMP browser $(".ui-dialog-titlebar-close").trigger("click"); } + +/** + * Create module on selected module_target (agent, networlk component or policy). + * + * @param string module_target Target to create module. + * @param return_values Return snmp values. + */ +function snmp_browser_create_modules(module_target, return_post = true) { + var id_check = $("#ul_0") + .find("input") + .map(function() { + if (this.id.indexOf("checkbox-create_") != -1) { + if ($(this).is(":checked")) { + return this.id; + } + } + }) + .get(); + + var target_ip = $("#text-target_ip").val(); + var community = $("#text-community").val(); + var snmp_version = $("#snmp_browser_version").val(); + var snmp3_auth_user = $("#text-snmp3_browser_auth_user").val(); + var snmp3_security_level = $("#snmp3_browser_security_level").val(); + var snmp3_auth_method = $("#snmp3_browser_auth_method").val(); + var snmp3_auth_pass = $("#password-snmp3_browser_auth_pass").val(); + var snmp3_privacy_method = $("#snmp3_browser_privacy_method").val(); + var snmp3_privacy_pass = $("#password-snmp3_browser_privacy_pass").val(); + + var custom_action = $("#hidden-custom_action").val(); + if (custom_action == undefined) { + custom_action = ""; + } + + var oids = []; + id_check.forEach(function(product, index) { + var oid = $("#" + product) + .siblings("a") + .attr("href"); + if (oid.indexOf('javascript: snmpGet("') != -1) { + oid = oid.replace('javascript: snmpGet("', ""); + oid = oid.replace('");', ""); + oids.push(oid); + } + }); + + var snmp_conf = {}; + + snmp_conf["target_ip"] = target_ip; + snmp_conf["community"] = community; + snmp_conf["oids"] = oids; + snmp_conf["snmp_browser_version"] = snmp_version; + snmp_conf["snmp3_browser_auth_user"] = snmp3_auth_user; + snmp_conf["snmp3_browser_security_level"] = snmp3_security_level; + snmp_conf["snmp3_browser_auth_method"] = snmp3_auth_method; + snmp_conf["snmp3_browser_auth_pass"] = snmp3_auth_pass; + snmp_conf["snmp3_browser_privacy_method"] = snmp3_privacy_method; + snmp_conf["snmp3_browser_privacy_pass"] = snmp3_privacy_pass; + snmp_conf["module_target"] = module_target; + snmp_conf["custom_action"] = custom_action; + + var snmp_data = []; + + for (var snmp_data_name in snmp_conf) { + snmp_data.push({ + name: snmp_data_name, + value: snmp_conf[snmp_data_name] + }); + } + + if (return_post) { + return snmp_data; + } else { + var params = {}; + + params["method"] = "snmp_browser_create_modules"; + params["module_target"] = module_target; + params["page"] = "include/ajax/snmp_browser.ajax"; + params["snmp_extradata"] = snmp_data; + + $("input[name=create_modules_" + module_target + "]").removeClass( + "sub add" + ); + $("input[name=create_modules_" + module_target + "]").addClass("sub spinn"); + + $.ajax({ + method: "post", + url: "ajax.php", + data: params, + dataType: "html", + success: function(data) { + snmp_show_result_message(data); + } + }); + } +} diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 4c48f12e80..8d4330003a 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -730,6 +730,7 @@ input.sub { padding-bottom: 10px; padding-top: 10px; padding-left: 15px; + margin-left: 10px; border: 1px solid #888; font-family: "lato", "Open Sans", sans-serif; cursor: pointer; @@ -4300,6 +4301,33 @@ form ul.form_flex li ul li { border: 0px; } +#snmp_browser { + text-align: left; + font-family: "lato-lighter", "Open Sans", sans-serif; + letter-spacing: 0.03pt; + font-size: 8pt; + box-sizing: border-box; + height: 100%; + min-height: 100px; + max-height: 500px; + overflow: auto; + background-color: #f4f5f4; + border: 1px solid #e2e2e2; + border-radius: 4px; + padding: 5px; +} +#snmp_create_buttons { + display: flex; + justify-content: flex-end; + flex-wrap: nowrap; +} + +#snmp_create_buttons > .sub { + display: flex; + margin-left: 10px; + margin-top: 10px; +} + /* library for graphs */ .yAxis.y1Axis > .tickLabel { white-space: nowrap; diff --git a/pandora_console/operation/snmpconsole/snmp_browser.php b/pandora_console/operation/snmpconsole/snmp_browser.php index b68f2d4da5..8db508da27 100644 --- a/pandora_console/operation/snmpconsole/snmp_browser.php +++ b/pandora_console/operation/snmpconsole/snmp_browser.php @@ -30,140 +30,14 @@ global $config; require_once $config['homedir'].'/include/functions_snmp_browser.php'; ui_require_javascript_file('pandora_snmp_browser'); - -// AJAX call. -if (is_ajax()) { - // Read the action to perform. - $action = (string) get_parameter('action', ''); - $target_ip = (string) get_parameter('target_ip', ''); - $community = (string) get_parameter('community', ''); - $snmp_version = (string) get_parameter('snmp_browser_version', ''); - $server_to_exec = (int) get_parameter('server_to_exec', 0); - $snmp3_auth_user = io_safe_output(get_parameter('snmp3_browser_auth_user')); - $snmp3_security_level = get_parameter('snmp3_browser_security_level'); - $snmp3_auth_method = get_parameter('snmp3_browser_auth_method'); - $snmp3_auth_pass = io_safe_output(get_parameter('snmp3_browser_auth_pass')); - $snmp3_privacy_method = get_parameter('snmp3_browser_privacy_method'); - $snmp3_privacy_pass = io_safe_output( - get_parameter('snmp3_browser_privacy_pass') - ); - - // SNMP browser. - if ($action == 'snmptree') { - $starting_oid = (string) get_parameter('starting_oid', '.'); - - $snmp_tree = snmp_browser_get_tree( - $target_ip, - $community, - $starting_oid, - $snmp_version, - $snmp3_auth_user, - $snmp3_security_level, - $snmp3_auth_method, - $snmp3_auth_pass, - $snmp3_privacy_method, - $snmp3_privacy_pass, - $server_to_exec - ); - if (! is_array($snmp_tree)) { - echo $snmp_tree; - } else { - snmp_browser_print_tree( - $snmp_tree, - // Id. - 0, - // Depth. - 0, - // Last. - 0, - // Last_array. - [], - // Sufix. - false, - // Checked. - [], - // Return. - false, - // Descriptive_ids. - false, - // Previous_id. - '' - ); - echo html_print_submit_button( - __('Create network components'), - 'create_network_component', - false, - [ - 'style' => 'display: none; position: absolute; bottom: 0px; right: 35px;', - 'class' => 'sub add', - ], - true - ); - - echo '