Merge branch 'ent-5978-actualizacion-eventos-mediante-api' into 'develop'

Added api function for update events

Closes pandora_enterprise#5978

See merge request artica/pandorafms!3305
This commit is contained in:
Alejandro Fraguas 2020-06-16 10:23:09 +02:00
commit b2084e3a1e
2 changed files with 89 additions and 0 deletions

View File

@ -261,6 +261,13 @@ if ($correctLogin) {
}
break;
case 'event':
// Preventive check for users if not available write events
if (! check_acl($config['id_user'], $event['id_grupo'], 'EW')) {
return false;
}
break;
default:
// Ignore.
break;

View File

@ -8796,6 +8796,11 @@ function otherParameter2Filter($other, $return_as_array=false, $use_agent_name=f
}
}
// Esto es extraño, hablar con Tati
/*
$filter['1'] = $filter['sql'];
unset($filter['sql']); */
if (isset($other['data'][4]) && $other['data'][4] != '') {
$idTemplate = db_get_value_filter('id', 'talert_templates', ['name' => $other['data'][4]]);
if ($idTemplate !== false) {
@ -10727,6 +10732,83 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db
}
/**
* Update an event
*
* @param string $id_event Id of the event for change.
* @param string $unused1 Without use.
* @param array $params Dictionary with field,value format with the data for update.
* @param string $unused2 Without use.
* @param string $unused3 Without use.
*
* @return void
*/
function api_set_event($id_event, $unused1, $params, $unused2, $unused3)
{
// Get the event
$event = events_get_event($id_event, false, is_metaconsole());
// If event not exists, end the execution.
if ($event === false) {
returnError(
'event_not_exists',
'Event not exists'
);
return false;
}
$paramsSerialize = [];
// Serialize the data for update
if ($params['type'] === 'array') {
// Keys that is not available to change
$invalidKeys = [
'id_evento',
'id_agente',
'id_grupo',
'timestamp',
'utimestamp',
'id_agentmodule',
'ack_utimestamp',
'data',
];
foreach ($params['data'] as $key_value) {
list($key, $value) = explode(',', $key_value, 2);
if (in_array($key, $invalidKeys) == false) {
$paramsSerialize[$key] = $value;
}
}
}
// In meta or node.
if (is_metaconsole() === true) {
$table = 'tmetaconsole_event';
} else {
$table = 'tevento';
}
// TODO. Stablish security for prevent sql injection?
// Update the row
$result = db_process_sql_update(
$table,
$paramsSerialize,
[ 'id_evento' => $id_event ]
);
// If update results failed
if (empty($result) === true || $result === false) {
returnError(
'failed_event_update',
__('Failed event update')
);
return false;
} else {
returnData('string', ['data' => 'Event updated']);
}
return;
}
/**
*
* @param $trash1