Merge branch 'ent-6470-error-componentes-remotos' into 'develop'

Ent 6470 error componentes remotos

Closes pandora_enterprise#6470

See merge request artica/pandorafms!3558
This commit is contained in:
Daniel Rodriguez 2020-10-29 09:48:25 +01:00
commit 5d4723ba15
1 changed files with 16 additions and 8 deletions

View File

@ -3002,7 +3002,7 @@ class AgentWizard extends HTML
$newModule = $module;
// Split the values got to obtain the name.
$tmpFirst = explode('.', $value);
$tmpSecond = explode(' ', $tmpFirst[1]);
$tmpSecond = explode(' ', $tmpFirst[(count($tmpFirst) - 1)]);
// Position 0 is the index, Position 3 is the MIB name.
$snmpwalkNames[$tmpSecond[0]] = $tmpSecond[3];
// Perform the operations for get the values.
@ -3011,6 +3011,11 @@ class AgentWizard extends HTML
$currentOid = $oid.'.'.$tmpSecond[0];
$macros['macros'][$oidName] = $currentOid;
$currentOidValue = $this->snmpgetValue($currentOid);
// If for any reason the value comes empty, add 1.
if ($currentOidValue == '') {
$currentOidValue = 1;
}
$thisOperation = preg_replace(
'/'.$oidName.'/',
$currentOidValue,
@ -4733,17 +4738,18 @@ class AgentWizard extends HTML
* @param integer|null $type Module type.
*
* @return string
* @throws Exception Handle of unwanted operations.
*/
private function evalOperation(
string $operation,
string $unit='',
?int $type=0
) {
try {
// Avoid non-numeric or arithmetic chars for security reasons.
if (preg_match('/(([^0-9\s\+\-\*\/\(\).,])+)/', $operation) === 1) {
$output = 'ERROR';
throw new Exception(sprintf(__("The operation '%s' is not permitted. Review for remote components."), $operation));
} else {
try {
// Get the result of the operation and set it.
$output = '';
eval('$output = '.$operation.';');
@ -4753,9 +4759,11 @@ class AgentWizard extends HTML
$unit,
$type
);
} catch (Exception $e) {
$output = 'ERROR';
}
} catch (Exception $e) {
$this->message['type'][] = 'error';
$this->message['message'][] = $e->getMessage();
$this->showMessage();
}
return $output;