$snmp) { $data = explode(': ',$snmp); $keydata = explode('::',$key); $keydata2 = explode('.',$keydata[1]); if(!isset($keydata2[1])) { continue; } if(array_key_exists(1,$data)){ $interfaces[$keydata2[1]][$keydata2[0]]['type'] = $data[0]; $interfaces[$keydata2[1]][$keydata2[0]]['value'] = $data[1]; }else { $interfaces[$keydata2[1]][$keydata2[0]]['type'] = ''; $interfaces[$keydata2[1]][$keydata2[0]]['value'] = $data[0]; } $interfaces[$keydata2[1]][$keydata2[0]]['oid'] = $key; $interfaces[$keydata2[1]][$keydata2[0]]['checked'] = 0; } unset($interfaces[0]); } if($create_modules) { $id_snmp_serialize = get_parameter_post('id_snmp_serialize'); $interfaces = unserialize_in_temp($id_snmp_serialize); if(!$interfaces) { $interfaces = array(); } $values = array(); if($tcp_port != ''){ $values['tcp_port'] = $tcp_port; } $values['snmp_community'] = $snmp_community; $values['ip_target'] = $ip_target; $values['tcp_send'] = $snmp_version; if($snmp_version == '3') { $values['plugin_user'] = $snmp3_auth_user; $values['plugin_pass'] = $snmp3_auth_pass; $values['plugin_parameter'] = $snmp3_auth_method; $values['custom_string_1'] = $snmp3_privacy_method; $values['custom_string_2'] = $snmp3_privacy_pass; $values['custom_string_3'] = $snmp3_security_level; } $oids = array(); foreach($interfaces as $key => $interface) { foreach($interface as $key2 => $module) { $oid = get_parameter($key."-".$key2, ''); if($oid != '') { $interfaces[$key][$key2]['checked'] = 1; $oids[$key][] = $interfaces[$key][$key2]['oid']; } else { $interfaces[$key][$key2]['checked'] = 0; } } } $modules = get_parameter('module', array()); $id_snmp = get_parameter('id_snmp'); if($id_snmp == false) { ui_print_error_message (__('No modules selected')); $id_snmp = array(); } if(agents_get_name($id_agent) == false) { ui_print_error_message (__('No agent selected or the agent does not exist')); $id_snmp = array(); } $result = false; $errors = array(); $done = 0; foreach($id_snmp as $id) { if (isset($interfaces[$id]['ifName']) && $interfaces[$id]['ifName']['value'] != ""){ $ifname = $interfaces[$id]['ifName']['value']; } else if (isset($interfaces[$id]['ifDescr']) && $interfaces[$id]['ifDescr']['value'] != ""){ $ifname = $interfaces[$id]['ifDescr']['value']; } foreach($modules as $module) { $oid_array = explode('.',$module); $oid_array[count($oid_array)-1] = $id; $oid = implode('.',$oid_array); // Get the name $name_array = explode('::',$oid_array[0]); $name = $name_array[1] . "_" . $ifname; // Clean the name $name = str_replace ( "\"" , "" , $name); // Proc moduletypes if (preg_match ( "/Status/", $name_array[1])) $module_type = 18; elseif (preg_match ( "/Present/", $name_array[1])) $module_type = 18; elseif (preg_match ( "/PromiscuousMode/", $name_array[1])) $module_type = 18; // String moduletypes elseif (preg_match ( "/Alias/", $name_array[1])) $module_type = 17; elseif (preg_match ( "/Address/", $name_array[1])) $module_type = 17; elseif (preg_match ( "/Name/", $name_array[1])) $module_type = 17; elseif (preg_match ( "/Specific/", $name_array[1])) $module_type = 17; elseif (preg_match ( "/Descr/", $name_array[1])) $module_type = 17; // Specific counters (ends in s) elseif (preg_match ( "/s$/", $name_array[1])) $module_type = 16; // Otherwise, numeric else $module_type = 15; $values['id_tipo_modulo'] = $module_type; $values['descripcion'] = io_safe_input("(" . $ip_target." - ".$name . ") " . $interfaces[$id]['ifDescr']['value']); $values['snmp_oid'] = $oid; $values['id_modulo'] = 2; $result = modules_create_agent_module ($id_agent, io_safe_input($name), $values); if(is_error($result)) { if(!isset($errors[$result])) { $errors[$result] = 0; } $errors[$result]++; } else { $done++; } } } if($done > 0) { ui_print_success_message(__('Successfully modules created')." ($done)"); } if(!empty($errors)) { $msg = __('Could not be created').':'; foreach($errors as $code => $number) { switch($code) { case ERR_EXIST: $msg .= '
'.__('Another module already exists with the same name')." ($number)"; break; case ERR_INCOMPLETE: $msg .= '
'.__('Some required fields are missed').': ('.__('name').') '." ($number)"; break; case ERR_DB: case ERR_GENERIC: default: $msg .= '
'.__('Processing error')." ($number)"; break; } } ui_print_error_message($msg); } } // Create the interface list for the interface $interfaces_list = array(); foreach($interfaces as $interface){ // Get the interface name, removing " " characters and avoid "blank" interfaces if (isset($interface['ifName']) && $interface['ifName']['value'] != ""){ $ifname = $interface['ifName']['value']; } else if (isset($interface['ifDescr']) && $interface['ifDescr']['value'] != ""){ $ifname = $interface['ifDescr']['value']; } else { continue; } $interfaces_list[$interface['ifIndex']['value']] = str_replace ( "\"" , "" , $ifname); } echo ''; echo "
"; $table->width = '98%'; $table->valign[0] = 'top'; $table->valign[1] = 'top'; $table->data[0][0] = '' . __('Target IP') . ''; $table->data[0][1] = html_print_input_text ('ip_target', $ip_target, '', 15, 60, true); $table->data[0][2] = '' . __('Port') . ''; $table->data[0][3] = html_print_input_text ('tcp_port', $tcp_port, '', 5, 20, true); $snmp_versions['1'] = 'v. 1'; $snmp_versions['2'] = 'v. 2'; $snmp_versions['2c'] = 'v. 2c'; $snmp_versions['3'] = 'v. 3'; $table->data[1][0] = '' . __('SNMP community') . ''; $table->data[1][1] = html_print_input_text ('snmp_community', $snmp_community, '', 15, 60, true); $table->data[1][2] = '' . _('SNMP version') . ''; $table->data[1][3] = html_print_select ($snmp_versions, 'snmp_version', $snmp_version, '', '', '', true, false, false, ''); $table->data[1][3] .= ''; html_print_input_hidden('snmpwalk', 1); html_print_table($table); unset($table); //SNMP3 OPTIONS $table->width = '98%'; $table->valign[0] = 'top'; $table->valign[1] = 'top'; $table->data[2][1] = ''.__('Auth user').''; $table->data[2][2] = html_print_input_text ('snmp3_auth_user', $snmp3_auth_user, '', 15, 60, true); $table->data[2][3] = ''.__('Auth password').''; $table->data[2][4] = html_print_input_text ('snmp3_auth_pass', $snmp3_auth_pass, '', 15, 60, true); $table->data[2][4] .= html_print_input_hidden('active_snmp_v3', 0, true); $table->data[5][0] = ''.__('Privacy method').''; $table->data[5][1] = html_print_select(array('DES' => __('DES'), 'AES' => __('AES')), 'snmp3_privacy_method', $snmp3_privacy_method, '', '', '', true); $table->data[5][2] = ''.__('privacy pass').''; $table->data[5][3] = html_print_input_text ('snmp3_privacy_pass', $snmp3_privacy_pass, '', 15, 60, true); $table->data[6][0] = ''.__('Auth method').''; $table->data[6][1] = html_print_select(array('MD5' => __('MD5'), 'SHA' => __('SHA')), 'snmp3_auth_method', $snmp3_auth_method, '', '', '', true); $table->data[6][2] = ''.__('Security level').''; $table->data[6][3] = html_print_select(array('noAuthNoPriv' => __('Not auth and not privacy method'), 'authNoPriv' => __('Auth and not privacy method'), 'authPriv' => __('Auth and privacy method')), 'snmp3_security_level', $snmp3_security_level, '', '', '', true); if($snmp_version == 3) { echo '
'; }else { echo ''; echo "
"; echo ''; html_print_submit_button(__('SNMP Walk'), 'snmp_walk', false, array('class' => 'sub next')); echo "
"; if($snmpwalk && !$snmpis) { echo ''.__('Unable to do SNMP walk').''; } unset($table); echo ""; //echo ""; //echo ""; if(!empty($interfaces_list)){ echo ''; echo ''; echo "
"; $id_snmp_serialize = serialize_in_temp($interfaces, $config['id_user']."_snmp"); html_print_input_hidden('id_snmp_serialize', $id_snmp_serialize); html_print_input_hidden('create_modules', 1); html_print_input_hidden('ip_target', $ip_target); html_print_input_hidden('tcp_port', $tcp_port); html_print_input_hidden('snmp_community', $snmp_community); html_print_input_hidden('snmp_version', $snmp_version); html_print_input_hidden('snmp3_auth_user', $snmp3_auth_user); html_print_input_hidden('snmp3_auth_pass', $snmp3_auth_pass); html_print_input_hidden('snmp3_auth_method', $snmp3_auth_method); html_print_input_hidden('snmp3_privacy_method', $snmp3_privacy_method); html_print_input_hidden('snmp3_privacy_pass', $snmp3_privacy_pass); html_print_input_hidden('snmp3_security_level', $snmp3_security_level); $table->width = '98%'; $table->valign[0] = 'top'; $table->valign[1] = 'top'; //Agent selector $table->data[0][0] = ''.__('Interfaces').''; $table->data[0][1] = ''; $table->data[0][2] = ''.__('Modules').''; $table->data[1][0] = html_print_select ($interfaces_list, 'id_snmp[]', 0, false, '', '', true, true, true, '', false, 'width:200px;'); $table->data[1][1] = html_print_image('images/darrowright.png', true); $table->data[1][2] = html_print_select (array (), 'module[]', 0, false, '', 0, true, true, true, '', false, 'width:200px;'); $table->data[1][2] .= html_print_input_hidden('agent', $id_agent, true); html_print_table($table); echo "
"; html_print_submit_button(__('Create modules'), '', false, array('class' => 'sub add')); echo "
"; unset($table); echo "
"; echo '
'; } ui_require_jquery_file ('pandora.controls'); ui_require_jquery_file ('ajaxqueue'); ui_require_jquery_file ('bgiframe'); //ui_require_jquery_file ('autocomplete'); ?>