Merge branch 'ent-7020-movidas-del-wizard' into 'develop'

Ent 7020 movidas del wizard

See merge request artica/pandorafms!3816
This commit is contained in:
Daniel Rodriguez 2021-02-09 16:25:06 +01:00
commit df603853ad
8 changed files with 503 additions and 289 deletions

View File

@ -653,6 +653,30 @@ $table_other->data[14][1] = html_print_input_text(
true
);
$table_other->data[15][0] = __('SNMP walk binary');
$table_other->data[15][1] = html_print_input_text(
'snmpwalk',
$config['snmpwalk'],
'',
50,
10,
true
);
$tip = ui_print_help_tip(
__('SNMP bulk walk is not able to request V1 SNMP, this option will be used instead (by default snmpwalk, slower).'),
true
);
$table_other->data[16][0] = __('SNMP walk binary (fallback)').$tip;
$table_other->data[16][1] = html_print_input_text(
'snmpwalk_fallback',
$config['snmpwalk_fallback'],
'',
50,
10,
true
);
echo '<form id="form_setup" method="post">';
echo '<fieldset>';

View File

@ -232,6 +232,17 @@ class AgentWizard extends HTML
*/
private $interfacesFound;
/**
* Some useful information about interfaces:
* `name` => [
* operstatus
* adminstatus
* ]
*
* @var array
*/
private $interfacesData;
/**
* X64 Interfaces
*
@ -260,6 +271,13 @@ class AgentWizard extends HTML
*/
private $moduleBlocks;
/**
* Extra arguments for SNMP call.
*
* @var string
*/
private $extraArguments = '';
/**
* Constructor
@ -913,16 +931,34 @@ class AgentWizard extends HTML
*/
public function performSNMPInterfaces($receivedOid)
{
// Path for get the IPs (ipv4).
$snmpIpDiscover = '.1.3.6.1.2.1.4.34.1.4.1.4';
$snmpIpIndexes = '.1.3.6.1.2.1.4.34.1.3.1.4';
$ipsResult = [];
// In this case we need the full information provided by snmpwalk.
$ipsResult = $this->snmpwalkValues($snmpIpDiscover, false, true);
$indexes = $this->snmpwalkValues($snmpIpIndexes, false, true);
$unicastIpReferences = [];
foreach ($indexes as $k => $v) {
$key = str_replace($snmpIpIndexes.'.', '', $k);
// Only catch the unicast records.
if ((preg_match('/unicast/', $ipsResult[$snmpIpDiscover.'.'.$key]) === 1)) {
$value = explode(': ', $v)[1];
$unicastIpReferences[$value] = $key;
}
}
// Create a list with the interfaces.
$interfaces = [];
foreach ($receivedOid as $keyOid => $nameOid) {
list($nameKey, $indexKey) = explode(
'.',
str_replace('IF-MIB::', '', $keyOid)
);
list($typeValue, $value) = explode(': ', $nameOid);
foreach ($receivedOid as $indexKey => $name) {
if ($indexKey[0] === '.') {
$indexKey = substr($indexKey, 1, strlen($indexKey));
}
// Set the name of interface.
$interfaces[$indexKey]['name'] = $value;
$interfaces[$indexKey]['name'] = $name;
// Get the description.
$interfaces[$indexKey]['descr'] = $this->snmpgetValue(
'.1.3.6.1.2.1.2.2.1.2.'.$indexKey
@ -933,40 +969,8 @@ class AgentWizard extends HTML
);
// Get unicast IP address.
$interfaces[$indexKey]['ip'] = '';
// Path for get the IPs (ipv4).
$snmpIpDiscover = '.1.3.6.1.2.1.4.34.1.4.1.4';
$ipsResult = [];
// In this case we need the full information provided by snmpwalk.
$snmpwalkIps = sprintf(
'snmpwalk -On -v%s -c %s %s %s',
$this->version,
$this->community,
$this->targetIp,
$snmpIpDiscover
);
exec($snmpwalkIps, $ipsResult);
foreach ($ipsResult as $ipResult) {
list($ipOidDirection, $ipOidValue) = explode(' = ', $ipResult);
// Only catch the unicast records.
if ((preg_match('/unicast/', $ipOidValue) === 1)) {
$tmpIpOidDirection = str_replace(
$snmpIpDiscover,
'',
$ipOidDirection
);
$snmpIpIndexDiscover = '.1.3.6.1.2.1.4.34.1.3.1.4';
$snmpIpIndexDiscover .= $tmpIpOidDirection;
$snmpgetIpIndex = $this->snmpgetValue($snmpIpIndexDiscover);
// If this Ip index number match with the current index key.
if ($snmpgetIpIndex === $indexKey) {
$interfaces[$indexKey]['ip'] .= substr(
$tmpIpOidDirection,
1
);
}
} else {
continue;
}
if (isset($unicastIpReferences[$indexKey]) === true) {
$interfaces[$indexKey]['ip'] = '';
}
}
@ -985,13 +989,15 @@ class AgentWizard extends HTML
public function performSNMPGeneral($receivedOid)
{
// Getting the Symbolic Name of the OID.
$symbolicName = explode('OID:', array_shift($receivedOid));
// Translate the Symbolic Name to numeric OID.
$output_oid = '';
exec('snmptranslate -On '.$symbolicName[1], $output_oid);
if (is_array($receivedOid) === false) {
// No PEN.
return;
}
// The PEN is hosted in the seventh position.
$tmpPEN = explode('.', $output_oid[0]);
$tmpPEN = explode('.', array_shift($receivedOid));
$pen = $tmpPEN[7];
// Then look in DB if the PEN is registered.
$penFound = db_get_value('manufacturer', 'tpen', 'pen', $pen);
if ($penFound === false) {
@ -1029,21 +1035,10 @@ class AgentWizard extends HTML
if ($this->wizardSection === 'snmp_interfaces_explorer') {
// 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,
$check_x64 = $this->snmpwalkValues(
$snmp_tmp,
$this->targetPort,
$this->server,
$this->extraArguments
false,
true
);
if ($check_x64) {
@ -1056,21 +1051,10 @@ class AgentWizard extends HTML
// 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,
$receivedOid = $this->snmpwalkValues(
$oidExplore,
$this->targetPort,
$this->server,
$this->extraArguments
false,
true
);
} else {
// Get the device PEN.
@ -1078,21 +1062,10 @@ class AgentWizard extends HTML
}
// Doc Interfaces de red.
$receivedOid = get_snmpwalk(
$this->targetIp,
$this->version,
$this->community,
$this->authUserV3,
$this->securityLevelV3,
$this->authMethodV3,
$this->authPassV3,
$this->privacyMethodV3,
$this->privacyPassV3,
0,
$receivedOid = $this->snmpwalkValues(
$oidExplore,
$this->targetPort,
$this->server,
$this->extraArguments
false,
false
);
if (empty($receivedOid) || preg_grep('/no.*object/i', $receivedOid)) {
@ -1100,21 +1073,10 @@ class AgentWizard extends HTML
$oidExplore = '1.3.6.1.2.1.2.2.1.2';
// Doc Interfaces de red.
$receivedOid = get_snmpwalk(
$this->targetIp,
$this->version,
$this->community,
$this->authUserV3,
$this->securityLevelV3,
$this->authMethodV3,
$this->authPassV3,
$this->privacyMethodV3,
$this->privacyPassV3,
0,
$receivedOid = $this->snmpwalkValues(
$oidExplore,
$this->targetPort,
$this->server,
$this->extraArguments
false,
true
);
}
@ -1197,18 +1159,8 @@ class AgentWizard extends HTML
public function listModulesToCreate()
{
$data = get_parameter('data', '');
$data = json_decode(io_safe_output($data), true);
$data = array_reduce(
$data,
function ($carry, $item) {
$carry[$item['name']] = $item['value'];
return $carry;
},
[]
);
$candidateModules = $this->candidateModuleToCreate($data);
$this->sectionUrl = $this->baseUrl.'&wizard_section='.$this->wizardSection;
@ -2442,6 +2394,7 @@ class AgentWizard extends HTML
// Get current value.
$currentValue = $this->snmpgetValue($moduleData['value']);
// It unit of measure have data, attach to current value.
if (empty($moduleData['module_unit']) === false) {
$currentValue .= ' '.$moduleData['module_unit'];
@ -2486,42 +2439,59 @@ class AgentWizard extends HTML
'action' => $this->sectionUrl,
'id' => 'form-filter-interfaces',
'method' => 'POST',
'class' => 'modal flex flex-row',
'class' => 'modal flex flex-row searchbox',
'extra' => '',
];
// Inputs.
$inputs = [];
$inputs[] = [
'direct' => 1,
'class' => 'select-interfaces',
'block_content' => [
[
'label' => __('Select all filtered interfaces'),
'arguments' => [
'name' => 'select-all-interfaces',
'type' => 'switch',
'class' => '',
'return' => true,
'value' => 1,
'onclick' => 'switchBlockControlInterfaces(this);',
// Inputs.
$inputs = [
[
'direct' => 1,
'class' => 'select-interfaces',
'block_content' => [
[
'label' => __('Select all filtered interfaces'),
'arguments' => [
'name' => 'select-all-interfaces',
'type' => 'switch',
'class' => '',
'return' => true,
'value' => 1,
'onclick' => 'switchBlockControlInterfaces(this);',
],
],
],
],
];
$inputs[] = [
'direct' => 1,
'block_content' => [
[
'label' => __('Search'),
'id' => 'txt-filter-search',
'arguments' => [
'name' => 'filter-search',
'type' => 'text',
'class' => '',
'return' => true,
],
[
'label' => __('Search'),
'id' => 'txt-filter-search',
'class' => 'textbox',
'arguments' => [
'name' => 'filter-search',
'type' => 'text',
'return' => true,
],
],
[
'label' => __('OperStatus UP'),
'arguments' => [
'name' => 'search-oper',
'type' => 'switch',
'id' => 'search-oper',
'onchange' => 'filterInterfaces()',
'value' => 0,
'return' => true,
],
],
[
'label' => __('AdminStatus UP'),
'arguments' => [
'name' => 'search-admin',
'type' => 'switch',
'id' => 'search-admin',
'onchange' => 'filterInterfaces()',
'value' => 0,
'return' => true,
],
],
];
@ -2577,6 +2547,7 @@ class AgentWizard extends HTML
// Get current value.
$currentValue = $this->snmpgetValue($moduleData['value']);
// Format current value with thousands and decimals.
if (is_numeric($currentValue) === true) {
$decimals = (is_float($currentValue) === true) ? 2 : 0;
@ -3023,6 +2994,12 @@ class AgentWizard extends HTML
$snmpwalkCombined = [];
foreach ($snmpwalkNames as $index => $name) {
if (isset($name) !== true
|| isset($snmpwalkValues[$index]) !== true
) {
continue;
}
$snmpwalkCombined[$index] = [
'name' => $name,
'value' => $snmpwalkValues[$index],
@ -3263,32 +3240,26 @@ class AgentWizard extends HTML
*/
private function snmpgetValue(string $oid, ?bool $full_output=false)
{
$output = get_snmpwalk(
$this->targetIp,
$this->version,
$this->community,
$this->authUserV3,
$this->securityLevelV3,
$this->authMethodV3,
$this->authPassV3,
$this->privacyMethodV3,
$this->privacyPassV3,
0,
$oid,
$this->targetPort,
$this->server,
$this->extraArguments,
(($full_output === false) ? '-Oa -On' : '-Oa')
);
if ($oid[0] !== '.') {
$oid = '.'.$oid;
}
$output = $this->snmpwalkValues($oid, false, true, true);
if (is_array($output) === true) {
foreach ($output as $k => $v) {
if ($full_output === true) {
return $k.' = '.$v;
if ($k[0] !== '.') {
$k = '.'.$k;
}
$value = explode(': ', $v, 2);
return $value[1];
if ($k == $oid) {
if ($full_output === true) {
return $k.' = '.$v;
}
$value = explode(': ', $v, 2);
return $value[1];
}
}
}
@ -3301,11 +3272,49 @@ class AgentWizard extends HTML
*
* @param string $oid Oid for get the values.
* @param boolean $full_output Array with full output.
* @param boolean $pure Return results as received by get_snmwalk.
* @param boolean $get If get operation, adjust key.
*
* @return array
*/
private function snmpwalkValues(string $oid, bool $full_output=false)
{
private function snmpwalkValues(
string $oid,
bool $full_output=false,
bool $pure=false,
bool $get=false
) {
static $__cached_walks;
if ($__cached_walks === null) {
$__cached_walks = [];
}
if ($oid[0] !== '.') {
$oid = '.'.$oid;
}
if ($get === true) {
// Request from snmpget. Cache is in tree.
$tree_oid = strrev($oid);
$tree_oid = strrev(
substr(
$tree_oid,
(strpos($tree_oid, '.') + 1),
strlen($tree_oid)
)
);
$key = $tree_oid.'-'.((int) $full_output).'-'.((int) $pure);
// Request entire sub-tree.
$oid = $tree_oid;
} else {
$key = $oid.'-'.((int) $full_output).'-'.((int) $pure);
}
if (isset($__cached_walks[$key]) === true) {
return $__cached_walks[$key];
}
$output = [];
$temporal = get_snmpwalk(
$this->targetIp,
@ -3325,6 +3334,11 @@ class AgentWizard extends HTML
(($full_output === false) ? '-Oa -On' : '-Oa')
);
if ($pure === true) {
$__cached_walks[$key] = $temporal;
return $temporal;
}
if (empty($temporal) === false) {
foreach ($temporal as $key => $oid_unit) {
if ($full_output === true) {
@ -3337,6 +3351,7 @@ class AgentWizard extends HTML
}
}
$__cached_walks[$key] = $output;
return $output;
}
@ -3586,6 +3601,40 @@ class AgentWizard extends HTML
}
/**
* Retrieve operstatus for given interface.
*
* @param string $interface_name Interface name.
*
* @return integer OperStatus.
*/
private function getOperStatus(string $interface_name)
{
if (is_array($this->interfacesData[$interface_name]) === true) {
return (int) $this->interfacesData[$interface_name]['operstatus'];
}
return 0;
}
/**
* Retrieve adminstatus for given interface.
*
* @param string $interface_name Interface name.
*
* @return integer AdminStatus.
*/
private function getAdminStatus(string $interface_name)
{
if (is_array($this->interfacesData[$interface_name]) === true) {
return (int) $this->interfacesData[$interface_name]['adminstatus'];
}
return 0;
}
/**
* Create the tables with toggle interface for show the modules availables.
*
@ -3607,6 +3656,8 @@ class AgentWizard extends HTML
) {
$output = '';
foreach ($blocks as $idBlock => $block) {
$md5IdBlock = hash('md5', $idBlock);
// Data with all components.
$blockData = $block['data'];
@ -3622,6 +3673,13 @@ class AgentWizard extends HTML
$blockComponentList .= $component['component_id'].',';
}
$is_up = false;
if ($this->getOperStatus($idBlock) === 1
&& $this->getAdminSTatus($idBlock) === 1
) {
$is_up = true;
}
$blockComponentList = chop($blockComponentList, ',');
// Title of Block.
if ($isInterface === true) {
@ -3632,15 +3690,16 @@ class AgentWizard extends HTML
);
$blockTitle .= '</b>';
} else {
$blockTitle = html_print_checkbox_switch_extended(
'interfaz_select_'.$idBlock,
1,
true,
false,
'',
'form="form-create-modules" class="interfaz_select"',
true,
''
$blockTitle = html_print_input(
[
'type' => 'switch',
'name' => 'interfaz_select_'.$idBlock,
'value' => $is_up,
'disabled' => false,
'attributes' => 'form="form-create-modules" class="interfaz_select" ',
'return' => true,
'id' => $md5IdBlock,
]
);
$blockTitle .= '<b>'.$block['name'];
$blockTitle .= '&nbsp;&nbsp;';
@ -3826,7 +3885,7 @@ class AgentWizard extends HTML
false,
false,
'',
'',
$md5IdBlock,
'',
'',
false,
@ -3866,7 +3925,7 @@ class AgentWizard extends HTML
false,
false,
'',
'',
$md5IdBlock,
'',
'',
false,
@ -3889,7 +3948,7 @@ class AgentWizard extends HTML
false,
false,
'',
'',
$md5IdBlock,
'',
'',
false,
@ -3932,7 +3991,7 @@ class AgentWizard extends HTML
false,
false,
'',
'',
$md5IdBlock,
'',
'',
false,
@ -3955,7 +4014,7 @@ class AgentWizard extends HTML
false,
false,
'',
'',
$md5IdBlock,
'',
'',
false,
@ -4037,7 +4096,7 @@ class AgentWizard extends HTML
'module-active-'.$uniqueId,
$module['module_enabled'],
true,
false,
$md5IdBlock,
'form="form-create-modules"'
);
@ -4046,7 +4105,7 @@ class AgentWizard extends HTML
'module-type-'.$uniqueId,
$module['type'],
true,
false,
$md5IdBlock,
'form="form-create-modules"'
);
@ -4055,7 +4114,7 @@ class AgentWizard extends HTML
'module-unit-'.$uniqueId,
$module['unit'],
true,
false,
$md5IdBlock,
'form="form-create-modules"'
);
@ -4064,7 +4123,7 @@ class AgentWizard extends HTML
'module-value-'.$uniqueId,
$module['value'],
true,
false,
$md5IdBlock,
'form="form-create-modules"'
);
@ -4073,7 +4132,7 @@ class AgentWizard extends HTML
'module-macros-'.$uniqueId,
base64_encode($module['macros']),
true,
false,
$md5IdBlock,
'form="form-create-modules"'
);
@ -4082,7 +4141,7 @@ class AgentWizard extends HTML
'module-name-oid-'.$uniqueId,
$module['name_oid'],
true,
false,
$md5IdBlock,
'form="form-create-modules"'
);
@ -4091,7 +4150,7 @@ class AgentWizard extends HTML
'module-scan_type-'.$uniqueId,
$module['scan_type'],
true,
false,
$md5IdBlock,
'form="form-create-modules"'
);
@ -4100,7 +4159,7 @@ class AgentWizard extends HTML
'module-execution_type-'.$uniqueId,
$module['execution_type'],
true,
false,
$md5IdBlock,
'form="form-create-modules"'
);
@ -4109,7 +4168,7 @@ class AgentWizard extends HTML
'module-query_class-'.$uniqueId,
$module['query_class'],
true,
false,
$md5IdBlock,
'form="form-create-modules"'
);
@ -4118,7 +4177,7 @@ class AgentWizard extends HTML
'module-query_key_field-'.$uniqueId,
$module['query_key_field'],
true,
false,
$md5IdBlock,
'form="form-create-modules"'
);
@ -4127,7 +4186,7 @@ class AgentWizard extends HTML
'module-scan_filters-'.$uniqueId,
$module['scan_filters'],
true,
false,
$md5IdBlock,
'form="form-create-modules"'
);
@ -4136,7 +4195,7 @@ class AgentWizard extends HTML
'module-query_filters-'.$uniqueId,
base64_encode($module['query_filters']),
true,
false,
$md5IdBlock,
'form="form-create-modules"'
);
@ -4147,7 +4206,7 @@ class AgentWizard extends HTML
'module-default_name-'.$uniqueId,
$module['name'],
true,
false,
$md5IdBlock,
'form="form-create-modules"'
);
@ -4155,7 +4214,7 @@ class AgentWizard extends HTML
'module-default_description-'.$uniqueId,
$module['description'],
true,
false,
$md5IdBlock,
'form="form-create-modules"'
);
}
@ -4167,6 +4226,10 @@ class AgentWizard extends HTML
$open = true;
$buttonSwitch = false;
$attr = 'operstatus="'.$this->getOperStatus($idBlock).'" ';
$attr .= 'adminstatus="';
$attr .= $this->getAdminStatus($idBlock).'" ';
$class = 'box-shadow white_table_graph interfaces_search';
$reverseImg = true;
if ($isPrincipal === true) {
@ -4176,22 +4239,25 @@ class AgentWizard extends HTML
$reverseImg = false;
}
$output .= ui_toggle(
$content,
$blockTitle,
'',
$idBlock,
$open,
true,
'',
'white-box-content',
$class,
'images/arrow_down_green.png',
'images/arrow_right_green.png',
false,
$reverseImg,
$buttonSwitch,
'form="form-create-modules"'
$output .= ui_print_toggle(
[
'content' => $content,
'name' => $blockTitle,
'title' => '',
'id' => $idBlock,
'hidden_default' => $open,
'return' => true,
'toggle_class' => '',
'container_class' => 'white-box-content',
'main_class' => $class,
'img_a' => 'images/arrow_down_green.png',
'img_b' => 'images/arrow_right_green.png',
'clean' => false,
'reverseImg' => $reverseImg,
'switch' => $buttonSwitch,
'attributes_switch' => 'form="form-create-modules"',
'toggl_attr' => $attr,
]
);
}
@ -4232,16 +4298,35 @@ class AgentWizard extends HTML
// Definition object.
$definition = [];
// Fulfill extra info.
$this->interfacesData[$data['name']] = [];
// IfOperStatus.
$adminStatusValue = 1;
if (empty($data) === false) {
$adminStatusValue = $this->snmpgetValue(
'1.3.6.1.2.1.2.2.1.7.'.$value
);
preg_match('/\((\d+?)\)/', $adminStatusValue, $match);
$adminStatusValue = (int) $match[1];
}
// IfOperStatus.
$operStatusValue = 1;
if (empty($data) === false) {
$operStatusValue = $this->snmpgetValue(
'1.3.6.1.2.1.2.2.1.8.'.$value
);
preg_match('/\((\d+?)\)/', $operStatusValue, $match);
$operStatusValue = (int) $match[1];
}
// Store aux data.
$this->interfacesData[$data['name']]['adminstatus'] = $adminStatusValue;
$this->interfacesData[$data['name']]['operstatus'] = $operStatusValue;
if ($adminStatusValue === 3) {
$min_warning = 3;
$max_warning = 4;
@ -5007,6 +5092,45 @@ class AgentWizard extends HTML
ob_start();
?>
<script type="text/javascript">
function filterInterfaces() {
var string = $('#text-filter-search').val().trim();
var filter_online = document.getElementById('search-admin').checked;
var filter_up = document.getElementById('search-oper').checked;
var regex = new RegExp(string, 'i');
var interfaces = $('.interfaces_search');
interfaces.each(function() {
if (string == ''
&& filter_up == false
&& filter_online == false
) {
$(this).removeClass('hidden');
return;
}
if (this.id.match(regex)) {
$(this).removeClass('hidden');
} else {
$(this).addClass('hidden');
}
if (filter_online == true) {
if ($(this).attr('adminstatus') != 1) {
$(this).addClass('hidden');
}
}
if (filter_up == true) {
if ($(this).attr('operstatus') != 1) {
$(this).addClass('hidden');
}
}
});
}
$(document).ready(function() {
// Meta.
var meta = "<?php echo is_metaconsole(); ?>";
@ -5020,20 +5144,7 @@ class AgentWizard extends HTML
// Filter search interfaces snmp.
$('#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 == '') {
$(this).removeClass('hidden');
} else {
if (this.id.match(regex)) {
$(this).removeClass('hidden');
} else {
$(this).addClass('hidden');
}
}
});
filterInterfaces();
});
// Loading.
@ -5212,29 +5323,18 @@ class AgentWizard extends HTML
* Controls checkboxes for modules.
*/
function switchBlockControlInterfaces(e) {
var string = $('#text-filter-search').val();
if (string == '') {
if (e.checked) {
$(".interfaz_select").prop("checked", true);
} else {
$(".interfaz_select").prop("checked", false);
}
} else {
var regex = new RegExp(string);
var interfaces = $('.interfaces_search');
interfaces.each(function() {
if (this.id.match(regex)) {
$(this).removeClass('hidden');
if (e.checked) {
$("input[name='interfaz_select_" + this.id + "']")
.prop("checked", true);
} else {
$("input[name='interfaz_select_" + this.id + "']")
.prop("checked", false);
}
}
});
// Apply filters if not done yet.
//filterInterfaces();
// Select targets.
var interfaces = document.querySelectorAll(
'.interfaces_search:not(.hidden)'
);
// Apply selection.
for (let iface of interfaces) {
iface.querySelector('input[type="checkbox"]').checked = e.checked;
}
}
/**
@ -5245,16 +5345,37 @@ class AgentWizard extends HTML
title: "<?php echo __('Modules about to be created'); ?>",
message: function() {
var id = "div-" + uniqId();
var loading = "<?php echo __('Loading'); ?>" + "...";
var loading = "<?php echo __('Loading, this operation might take several minutes...'); ?>";
var datas = {};
let inputs = document.querySelectorAll("input,textarea");
for (let input of inputs) {
let id = input.className;
let chkbox =document.getElementById('interfaz_select_'+id);
if (chkbox != undefined
&& chkbox.checked == false
) {
// Skip disabled containers.
continue;
}
if (input.type != "checkbox") {
datas[input.name] = input.value;
}
if (input.type == "checkbox" && input.checked) {
datas[input.name] = input.value;
}
};
$.ajax({
method: "post",
url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
data: {
page: "<?php echo $this->ajaxController; ?>",
method: "listModulesToCreate",
data: JSON.stringify(
$('#form-create-modules').serializeArray()
),
data: JSON.stringify(datas),
id_agente: "<?php echo $this->idAgent; ?>",
id: "<?php echo $this->idPolicy; ?>"
},

View File

@ -2012,22 +2012,22 @@ function get_snmpwalk(
$base_oid = escapeshellarg($base_oid);
}
if (empty($config['snmpwalk'])) {
switch (PHP_OS) {
case 'FreeBSD':
$snmpwalk_bin = '/usr/local/bin/snmpwalk';
break;
switch (PHP_OS) {
case 'FreeBSD':
$snmpwalk_bin = '/usr/local/bin/snmpwalk';
break;
case 'NetBSD':
$snmpwalk_bin = '/usr/pkg/bin/snmpwalk';
break;
case 'NetBSD':
$snmpwalk_bin = '/usr/pkg/bin/snmpwalk';
break;
default:
default:
if ($snmp_version == '1') {
$snmpwalk_bin = 'snmpwalk';
break;
}
} else {
$snmpwalk_bin = $config['snmpwalk'];
} else {
$snmpwalk_bin = 'snmpbulkwalk';
}
break;
}
switch (PHP_OS) {
@ -2035,6 +2035,7 @@ function get_snmpwalk(
case 'WINNT':
case 'Windows':
$error_redir_dir = 'NUL';
$snmpwalk_bin = 'snmpwalk';
break;
default:
@ -2042,6 +2043,14 @@ function get_snmpwalk(
break;
}
if (empty($config['snmpwalk']) === false) {
if ($snmp_version == '1') {
$snmpwalk_bin = $config['snmpwalk_fallback'];
} else {
$snmpwalk_bin = $config['snmpwalk'];
}
}
$output = [];
$rc = 0;
switch ($snmp_version) {

View File

@ -864,6 +864,14 @@ function config_update_config()
if (!config_update_value('row_limit_csv', get_parameter('row_limit_csv'))) {
$error_update[] = __('Row limit in csv log');
}
if (!config_update_value('snmpwalk', get_parameter('snmpwalk'))) {
$error_update[] = __('SNMP walk binary path');
}
if (!config_update_value('snmpwalk_fallback', get_parameter('snmpwalk_fallback'))) {
$error_update[] = __('SNMP walk binary path (fallback for v1)');
}
break;
case 'vis':
@ -1872,6 +1880,32 @@ function config_process_config()
config_update_value('row_limit_csv', 10000);
}
if (!isset($config['snmpwalk'])) {
switch (PHP_OS) {
case 'FreeBSD':
config_update_value('snmpwalk', '/usr/local/bin/snmpwalk');
break;
case 'NetBSD':
config_update_value('snmpwalk', '/usr/pkg/bin/snmpwalk');
break;
case 'WIN32':
case 'WINNT':
case 'Windows':
config_update_value('snmpwalk', 'snmpwalk');
break;
default:
config_update_value('snmpwalk', 'snmpbulkwalk');
break;
}
}
if (!isset($config['snmpwalk_fallback'])) {
config_update_value('snmpwalk_fallback', 'snmpwalk');
}
if (!isset($config['event_purge'])) {
config_update_value('event_purge', 15);
}

View File

@ -3586,7 +3586,7 @@ function html_print_checkbox_switch_extended(
if ($id == '') {
$output .= ' id="checkbox-'.$id_aux.'"';
} else {
$output .= ' '.$id.'"';
$output .= ' id="'.$id.'"';
}
if ($script != '') {
@ -4247,7 +4247,7 @@ function html_print_switch($attributes=[])
$attributes['style'] = '';
}
$disabled_class .= (bool) ($attributes['disabled']) ? ' p-slider-disabled' : '';
$disabled_class = (bool) ($attributes['disabled']) ? ' p-slider-disabled' : '';
return "<label class='p-switch' style='".$attributes['style']."'>
<input type='checkbox' ".$html_expand.">

View File

@ -227,7 +227,7 @@ function io_safe_output_array(&$item, $key=false, $utf8=true)
* @param string|array $value String or array of strings to be cleaned.
* @param boolean $utf8 Flag, set the output encoding in utf8, by default true.
*
* @return unknown_type
* @return string
*/
function io_safe_output($value, $utf8=true)
{

View File

@ -2923,7 +2923,7 @@ function ui_progress(
$id = uniqid();
ui_require_css_file('progress');
$output .= '<span id="'.$id.'" class="progress_main" data-label="'.$text;
$output = '<span id="'.$id.'" class="progress_main" data-label="'.$text;
$output .= '" style="width: '.$width.'; height: '.$height.'em; border: 1px solid '.$color.'">';
$output .= '<span id="'.$id.'_progress" class="progress" style="width: '.$progress.'%; background: '.$color.'"></span>';
$output .= '</span>';
@ -3076,7 +3076,7 @@ function ui_progress_extend(
ui_require_css_file('progress');
// Main container.
$output .= '<div class="progress_main_noborder" ';
$output = '<div class="progress_main_noborder" ';
$output .= '" style="width:'.$data['width'].'%;';
$output .= ' height:'.$data['height'].'em;">';
@ -3419,6 +3419,7 @@ function ui_print_datatable(array $parameters)
$js .= $parameters['drawCallback'];
}
$columns = '';
for ($i = 1; $i <= (count($parameters['columns']) - 3); $i++) {
if ($i != (count($parameters['columns']) - 3)) {
$columns .= $i.',';
@ -3747,18 +3748,23 @@ function ui_print_event_priority(
/**
* Print a code into a DIV and enable a toggle to show and hide it.
*
* @param string $code Html code.
* @param string $name Name of the link.
* @param string $title Title of the link.
* @param string $id Block id.
* @param boolean $hidden_default If the div will be hidden by default (default: true).
* @param boolean $return Whether to return an output string or echo now (default: true).
* @param string $toggle_class Toggle class.
* @param string $container_class Container class.
* @param string $main_class Main object class.
* @param string $img_a Image (closed).
* @param string $img_b Image (opened).
* @param string $clean Do not encapsulate with class boxes, clean print.
* @param string $code Html code.
* @param string $name Name of the link.
* @param string $title Title of the link.
* @param string $id Block id.
* @param boolean $hidden_default If the div will be hidden by default (default: true).
* @param boolean $return Whether to return an output string or echo now (default: true).
* @param string $toggle_class Toggle class.
* @param string $container_class Container class.
* @param string $main_class Main object class.
* @param string $img_a Image (closed).
* @param string $img_b Image (opened).
* @param string $clean Do not encapsulate with class boxes, clean print.
* @param boolean $reverseImg Reverse img.
* @param boolean $switch Use switch.
* @param string $attributes_switch Switch attributes.
* @param string $toggl_attr Main box extra attributes.
* @param boolean|null $switch_on Switch enabled disabled or depending on hidden_Default.
*
* @return string HTML.
*/
@ -3777,7 +3783,9 @@ function ui_toggle(
$clean=false,
$reverseImg=false,
$switch=false,
$attributes_switch=''
$attributes_switch='',
$toggl_attr='',
$switch_on=null
) {
// Generate unique Id.
$uniqid = uniqid('');
@ -3817,7 +3825,7 @@ function ui_toggle(
}
// Link to toggle.
$output = '<div class="'.$main_class.'" id="'.$id.'">';
$output = '<div class="'.$main_class.'" id="'.$id.'" '.$toggl_attr.'>';
$output .= '<div class="'.$header_class.'" style="cursor: pointer;" id="tgl_ctrl_'.$uniqid.'">';
if ($reverseImg === false) {
if ($switch === true) {
@ -3827,7 +3835,7 @@ function ui_toggle(
'content' => html_print_checkbox_switch_extended(
'box_enable_toggle'.$uniqid,
1,
($hidden_default === true) ? 0 : 1,
($switch_on === null) ? (($hidden_default === true) ? 0 : 1) : $switch_on,
false,
'',
$attributes_switch,
@ -3953,7 +3961,12 @@ function ui_print_toggle($data)
(isset($data['main_class']) === true) ? $data['main_class'] : 'box-shadow white_table_graph',
(isset($data['img_a']) === true) ? $data['img_a'] : 'images/arrow_down_green.png',
(isset($data['img_b']) === true) ? $data['img_b'] : 'images/arrow_right_green.png',
(isset($data['clean']) === true) ? $data['clean'] : false
(isset($data['clean']) === true) ? $data['clean'] : false,
(isset($data['reverseImg']) === true) ? $data['reverseImg'] : false,
(isset($data['switch']) === true) ? $data['switch'] : false,
(isset($data['attributes_switch']) === true) ? $data['attributes_switch'] : '',
(isset($data['toggl_attr']) === true) ? $data['toggl_attr'] : '',
(isset($data['switch_on']) === true) ? $data['switch_on'] : null
);
}
@ -5661,12 +5674,6 @@ function ui_print_module_string_value(
$value = io_safe_input($value);
}
$is_snapshot = is_snapshot_data($module['datos']);
$is_large_image = is_text_to_black_string($module['datos']);
if (($config['command_snapshot']) && ($is_snapshot || $is_large_image)) {
$row[7] = ui_get_snapshot_image($link, $is_snapshot).'&nbsp;&nbsp;';
}
$is_snapshot = is_snapshot_data($value);
$is_large_image = is_text_to_black_string($value);
if (($config['command_snapshot']) && ($is_snapshot || $is_large_image)) {
@ -5733,6 +5740,7 @@ function ui_print_module_string_value(
*/
function ui_print_tags_view($title='', $tags=[])
{
$tv = '';
if (!empty($title)) {
$tv .= '<div class="tag-wrapper">';
$tv .= '<h3>'.$title.'</h3>';
@ -6071,6 +6079,7 @@ function ui_print_comments($comments)
}
}
$last_comment = [];
foreach ($comments_array as $comm) {
// Show the comments more recent first.
if (is_array($comm)) {

View File

@ -148,3 +148,20 @@ ul.wizard li > textarea {
.action_button_list li {
display: inline;
}
.searchbox ul {
justify-content: space-between;
}
.searchbox ul li:not(.textbox) {
flex-direction: row-reverse !important;
justify-content: flex-end !important;
}
.searchbox ul li.textbox label {
width: auto;
}
.searchbox ul li.textbox {
justify-content: space-evenly !important;
flex: 1 1 auto;
}