Fixed oid for getting x64 interfaces module. Fixed visual (module order) bug

This commit is contained in:
Luis 2020-10-30 14:41:33 +01:00 committed by Daniel Rodriguez
parent 4e67371967
commit 25de1b686a

View File

@ -1,4 +1,5 @@
<?php
/**
* Agent Wizard for SNMP and WMI
*
@ -273,7 +274,7 @@ class AgentWizard extends HTML
// Check access.
check_login();
if (! check_acl($config['id_user'], 0, 'AR')) {
if (!check_acl($config['id_user'], 0, 'AR')) {
db_pandora_audit(
'ACL Violation',
'Trying to access event viewer'
@ -865,7 +866,6 @@ class AgentWizard extends HTML
],
true
);
}
@ -992,10 +992,51 @@ class AgentWizard extends HTML
}
if ($this->wizardSection === 'snmp_interfaces_explorer') {
// First, try x64 interfaces.
// Check if thereis x64 counters.
$snmp_tmp = '.1.3.6.1.2.1.31.1.1.1.6';
$check_x64 = get_snmpwalk(
$this->targetIp,
$this->version,
$this->community,
$this->authUserV3,
$this->securityLevelV3,
$this->authMethodV3,
$this->authPassV3,
$this->privacyMethodV3,
$this->privacyPassV3,
0,
$snmp_tmp,
$this->targetPort,
$this->server,
$this->extraArguments
);
if ($check_x64) {
$this->interfacesx64 = true;
$oidExplore = '.1.3.6.1.2.1.31.1.1.1.1';
} else {
$this->interfacesx64 = false;
$oidExplore = '1.3.6.1.2.1.2.2.1.2';
}
// Explore interface names.
$oidExplore = '.1.3.6.1.2.1.31.1.1.1.1';
$receivedOid = get_snmpwalk(
$this->targetIp,
$this->version,
$this->community,
$this->authUserV3,
$this->securityLevelV3,
$this->authMethodV3,
$this->authPassV3,
$this->privacyMethodV3,
$this->privacyPassV3,
0,
$oidExplore,
$this->targetPort,
$this->server,
$this->extraArguments
);
} else {
// Get the device PEN.
$oidExplore = '.1.3.6.1.2.1.1.2.0';
@ -1310,7 +1351,7 @@ class AgentWizard extends HTML
*
* @return array
*/
public function candidateModuleToCreate(array $data):array
public function candidateModuleToCreate(array $data): array
{
$modulesActivated = [];
$generalInterface = false;
@ -2261,7 +2302,7 @@ class AgentWizard extends HTML
private function replacementMacrosPlugin(
string $text,
array $macros
):string {
): string {
// Only agents.
if (empty($this->idPolicy) === true) {
// Common.
@ -2308,7 +2349,7 @@ class AgentWizard extends HTML
?string $value,
?string $unit='',
?int $moduleType=0
):string {
): string {
if ($moduleType !== MODULE_TYPE_REMOTE_SNMP_INC
&& $moduleType !== MODULE_TYPE_GENERIC_DATA_INC
&& $moduleType !== MODULE_TYPE_REMOTE_TCP_INC
@ -2562,7 +2603,7 @@ class AgentWizard extends HTML
// Unpack the extra fields
// and include with key field in a field set.
$macros = json_decode($module['macros'], true);
$fieldSet = [ '0' => $module['query_key_field'] ];
$fieldSet = ['0' => $module['query_key_field']];
foreach ($macros as $fieldKey => $fieldMacro) {
if (preg_match('/extra_field_/', $fieldKey) !== 0) {
$tmpKey = explode('_', $fieldKey);
@ -3100,7 +3141,6 @@ class AgentWizard extends HTML
// Add Create Modules form.
$this->createModulesForm();
}
}
@ -3209,7 +3249,6 @@ class AgentWizard extends HTML
}
return false;
}
@ -3306,7 +3345,7 @@ class AgentWizard extends HTML
*
* @return array Inputs for common data.
*/
private function getCommonDataInputs():array
private function getCommonDataInputs(): array
{
$inputs[] = [
'id' => 'create-modules-action',
@ -4207,6 +4246,34 @@ class AgentWizard extends HTML
],
];
// Get x86 or x64 modules.
if ($this->interfacesx64 === true) {
$definition_temp = $this->getInterfacesModulesx64($data);
} else {
$definition_temp = $this->getInterfacesModulesx86($data);
}
// General monitoring names.
$general_module_names = [
'ifInOctets / ifHCInOctets',
'ifOutOctets / ifHCOutOctets',
'ifInUcastPkts / ifHCInUcastPkts',
'ifOutUcastPkts / ifHCOutUcastPkts',
'ifInNUcastPkts / ifHCInNUcastPkts',
'ifOutNUcastPkts / ifHCOutNUcastPkts',
];
if ($name == '') {
foreach ($definition_temp as $module => $module_def) {
$definition_temp[$module]['module_name'] = array_shift($general_module_names);
}
}
if (empty($definition_temp) === false) {
$definition = array_merge($definition, $definition_temp);
}
// Continue with common x86 and x84 modules.
// IfAdminStatus.
$moduleName = $name.'ifAdminStatus';
$definition['ifAdminStatus'] = [
@ -4333,19 +4400,6 @@ class AgentWizard extends HTML
],
];
// Get x86 or x64 modules.
if ($this->interfacesx64 === true) {
$definitionx64 = $this->getInterfacesModulesx64($data);
if (empty($definitionx64) === false) {
$definition = array_merge($definition, $definitionx64);
}
} else {
$definitionx86 = $this->getInterfacesModulesx86($data);
if (empty($definitionx86) === false) {
$definition = array_merge($definition, $definitionx86);
}
}
return $definition;
}
@ -4815,7 +4869,7 @@ class AgentWizard extends HTML
try {
exec($execution, $output);
} catch (Exception $ex) {
$output = [ '0' => 'ERROR: Failed execution: '.(string) $ex];
$output = ['0' => 'ERROR: Failed execution: '.(string) $ex];
}
return $output;
@ -4913,7 +4967,7 @@ class AgentWizard extends HTML
// Meta.
var meta = "<?php echo is_metaconsole(); ?>";
var hack_meta = '';
if(meta){
if (meta) {
hack_meta = '../../';
}
@ -4921,15 +4975,15 @@ class AgentWizard extends HTML
showV3Form();
// Filter search interfaces snmp.
$('#text-filter-search').keyup(function () {
$('#text-filter-search').keyup(function() {
var string = $('#text-filter-search').val();
var regex = new RegExp(string);
var interfaces = $('.interfaces_search');
interfaces.each(function(){
if(string == ''){
interfaces.each(function() {
if (string == '') {
$(this).removeClass('hidden');
} else {
if(this.id.match(regex)) {
if (this.id.match(regex)) {
$(this).removeClass('hidden');
} else {
$(this).addClass('hidden');
@ -4939,12 +4993,12 @@ class AgentWizard extends HTML
});
// Loading.
$('#submit-sub-protocol').click(function () {
$('#submit-sub-protocol').click(function() {
$('.wizard-result').remove();
$('#form-create-modules').remove();
$('.textodialogo').remove();
$('.loading-wizard')
.html('<center><span style="font-size:25px;">Loading...</span><img style="width:25px;heigth:25px;" src="'+hack_meta+'images/spinner.gif"></center>');
.html('<center><span style="font-size:25px;">Loading...</span><img style="width:25px;heigth:25px;" src="' + hack_meta + 'images/spinner.gif"></center>');
});
});
@ -4962,10 +5016,10 @@ class AgentWizard extends HTML
function showSecurityLevelForm() {
var selector = $('#securityLevelV3').val();
if(selector === 'authNoPriv' || selector === 'authPriv'){
if (selector === 'authNoPriv' || selector === 'authPriv') {
$('#txt-authMethodV3').removeClass('invisible');
$('#txt-authPassV3').removeClass('invisible');
if(selector === 'authPriv'){
if (selector === 'authPriv') {
$('#txt-privacyMethodV3').removeClass('invisible');
$('#txt-privacyPassV3').removeClass('invisible');
} else {
@ -5015,16 +5069,13 @@ class AgentWizard extends HTML
collision: "fit"
},
title: title,
buttons: [
{
class:
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next",
buttons: [{
class: "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next",
text: "OK",
click: function(e) {
$("#msg").close();
}
}
]
}]
});
}
@ -5054,7 +5105,7 @@ class AgentWizard extends HTML
});
// Set checked.
$("[id*=checkbox-sel_module_" + blockNumber + "]")
.each(function(){
.each(function() {
$(this).prop("checked", true);
});
imageInfoModules.removeClass('hidden');
@ -5066,15 +5117,15 @@ class AgentWizard extends HTML
});
// Set unchecked.
$("[id*=checkbox-sel_module_" + blockNumber + "]")
.each(function(){
.each(function() {
$(this).prop("checked", false);
});
imageInfoModules.addClass('hidden');
}
} else if (type == 'module') {
// Getting the element.
var thisModuleHidden = document.getElementById("hidden-module-active-"+switchName[2]+"_"+moduleNumber);
var thisModule = $("#checkbox-sel_module_"+blockNumber+"_"+moduleNumber);
var thisModuleHidden = document.getElementById("hidden-module-active-" + switchName[2] + "_" + moduleNumber);
var thisModule = $("#checkbox-sel_module_" + blockNumber + "_" + moduleNumber);
// Setting the individual field
if (thisModule.prop('checked')) {
thisModuleHidden.value = '1';
@ -5118,7 +5169,7 @@ class AgentWizard extends HTML
*/
function switchBlockControlInterfaces(e) {
var string = $('#text-filter-search').val();
if(string == ''){
if (string == '') {
if (e.checked) {
$(".interfaz_select").prop("checked", true);
} else {
@ -5127,14 +5178,14 @@ class AgentWizard extends HTML
} else {
var regex = new RegExp(string);
var interfaces = $('.interfaces_search');
interfaces.each(function(){
if(this.id.match(regex)) {
interfaces.each(function() {
if (this.id.match(regex)) {
$(this).removeClass('hidden');
if (e.checked) {
$("input[name='interfaz_select_"+this.id+"']")
$("input[name='interfaz_select_" + this.id + "']")
.prop("checked", true);
} else {
$("input[name='interfaz_select_"+this.id+"']")
$("input[name='interfaz_select_" + this.id + "']")
.prop("checked", false);
}
}
@ -5149,7 +5200,7 @@ class AgentWizard extends HTML
confirmDialog({
title: "<?php echo __('Modules about to be created'); ?>",
message: function() {
var id = "div-"+uniqId();
var id = "div-" + uniqId();
var loading = "<?php echo __('Loading'); ?>" + "...";
$.ajax({
method: "post",
@ -5165,22 +5216,22 @@ class AgentWizard extends HTML
},
datatype: "html",
success: function(data) {
$('#'+id).empty().append(data);
$('#' + id).empty().append(data);
},
error: function(e) {
showMsg(e);
}
});
return "<div id ='"+id+"'>"+loading+"</div>";
return "<div id ='" + id + "'>" + loading + "</div>";
},
ok: "<?php echo __('OK'); ?>",
cancel: "<?php echo __('Cancel'); ?>",
onAccept: function() {
$('#reviewed-modules').submit();
},
size:750,
maxHeight:500
size: 750,
maxHeight: 500
});
}