2012-04-27 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_events.php: into the function
	"events_validate_event" fixed the return false when fail validation.
	
	* include/functions_network_components.php: fixed the includes.
	
	* operation/agentes/exportdata.php: cleaned source code style.
	
	* include/functions_api.php: fixed the checking error to healty
	level into the function "get_events".
	
	MERGED FROM 4.0.2




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6212 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2012-04-27 12:52:33 +00:00
parent 9b28c8ee1b
commit a3f8d63556
4 changed files with 158 additions and 137 deletions

View File

@ -1,3 +1,17 @@
2012-04-27 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_events.php: into the function
"events_validate_event" fixed the return false when fail validation.
* include/functions_network_components.php: fixed the includes.
* operation/agentes/exportdata.php: cleaned source code style.
* include/functions_api.php: fixed the checking error to healty
level into the function "get_events".
MERGED FROM 4.0.2
2012-04-27 Vanessa Gil <vanessa.gil@artica.es> 2012-04-27 Vanessa Gil <vanessa.gil@artica.es>
* godmode/alerts/alerts_list.list.php: Fixed: Action filter * godmode/alerts/alerts_list.list.php: Fixed: Action filter

View File

@ -1117,20 +1117,20 @@ function set_create_network_module($id, $thrash1, $other, $thrash3) {
*/ */
function set_update_network_module($id_module, $thrash1, $other, $thrash3){ function set_update_network_module($id_module, $thrash1, $other, $thrash3){
if ($id_module == ""){ if ($id_module == "") {
returnError('error_update_network_module', __('Error updating network module. Module name cannot be left blank.')); returnError('error_update_network_module', __('Error updating network module. Module name cannot be left blank.'));
return; return;
} }
$check_id_module = db_get_value ('id_agente_modulo', 'tagente_modulo', 'id_agente_modulo', $id_module); $check_id_module = db_get_value ('id_agente_modulo', 'tagente_modulo', 'id_agente_modulo', $id_module);
if (!$check_id_module){ if (!$check_id_module) {
returnError('error_update_network_module', __('Error updating network module. Id_module doesn\'t exists.')); returnError('error_update_network_module', __('Error updating network module. Id_module doesn\'t exists.'));
return; return;
} }
// If we want to change the module to a new agent // If we want to change the module to a new agent
if ($other['data'][0] != ""){ if ($other['data'][0] != "") {
$id_agent_old = db_get_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_module); $id_agent_old = db_get_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_module);
if ($id_agent_old != $other['data'][0]){ if ($id_agent_old != $other['data'][0]){
@ -1149,8 +1149,8 @@ function set_update_network_module($id_module, $thrash1, $other, $thrash3){
$values = array(); $values = array();
$cont = 0; $cont = 0;
foreach ($network_module_fields as $field){ foreach ($network_module_fields as $field) {
if ($other['data'][$cont] != ""){ if ($other['data'][$cont] != "") {
$values[$field] = $other['data'][$cont]; $values[$field] = $other['data'][$cont];
} }
@ -1184,14 +1184,14 @@ function set_update_network_module($id_module, $thrash1, $other, $thrash3){
function set_create_plugin_module($id, $thrash1, $other, $thrash3) { function set_create_plugin_module($id, $thrash1, $other, $thrash3) {
$agentName = $id; $agentName = $id;
if ($other['data'][22] == ""){ if ($other['data'][22] == "") {
returnError('error_create_plugin_module', __('Error in creation plugin module. Id_plugin cannot be left blank.')); returnError('error_create_plugin_module', __('Error in creation plugin module. Id_plugin cannot be left blank.'));
return; return;
} }
$idAgent = agents_get_agent_id($agentName); $idAgent = agents_get_agent_id($agentName);
if (!$idAgent){ if (!$idAgent) {
returnError('error_create_plugin_module', __('Error in creation plugin module. Agent name doesn\'t exists.')); returnError('error_create_plugin_module', __('Error in creation plugin module. Agent name doesn\'t exists.'));
return; return;
} }
@ -1257,26 +1257,26 @@ function set_create_plugin_module($id, $thrash1, $other, $thrash3) {
*/ */
function set_update_plugin_module($id_module, $thrash1, $other, $thrash3){ function set_update_plugin_module($id_module, $thrash1, $other, $thrash3){
if ($id_module == ""){ if ($id_module == "") {
returnError('error_update_plugin_module', __('Error updating plugin module. Id_module cannot be left blank.')); returnError('error_update_plugin_module', __('Error updating plugin module. Id_module cannot be left blank.'));
return; return;
} }
$check_id_module = db_get_value ('id_agente_modulo', 'tagente_modulo', 'id_agente_modulo', $id_module); $check_id_module = db_get_value ('id_agente_modulo', 'tagente_modulo', 'id_agente_modulo', $id_module);
if (!$check_id_module){ if (!$check_id_module) {
returnError('error_update_plugin_module', __('Error updating plugin module. Id_module doesn\'t exists.')); returnError('error_update_plugin_module', __('Error updating plugin module. Id_module doesn\'t exists.'));
return; return;
} }
// If we want to change the module to a new agent // If we want to change the module to a new agent
if ($other['data'][0] != ""){ if ($other['data'][0] != "") {
$id_agent_old = db_get_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_module); $id_agent_old = db_get_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_module);
if ($id_agent_old != $other['data'][0]){ if ($id_agent_old != $other['data'][0]) {
$id_module_exists = db_get_value_filter ('id_agente_modulo', 'tagente_modulo', array('nombre' => $module_name, 'id_agente' => $other['data'][0])); $id_module_exists = db_get_value_filter ('id_agente_modulo', 'tagente_modulo', array('nombre' => $module_name, 'id_agente' => $other['data'][0]));
if ($id_module_exists){ if ($id_module_exists) {
returnError('error_update_plugin_module', __('Error updating plugin module. Id_module exists in the new agent.')); returnError('error_update_plugin_module', __('Error updating plugin module. Id_module exists in the new agent.'));
return; return;
} }
@ -1290,8 +1290,8 @@ function set_update_plugin_module($id_module, $thrash1, $other, $thrash3){
$values = array(); $values = array();
$cont = 0; $cont = 0;
foreach ($plugin_module_fields as $field){ foreach ($plugin_module_fields as $field) {
if ($other['data'][$cont] != ""){ if ($other['data'][$cont] != "") {
$values[$field] = $other['data'][$cont]; $values[$field] = $other['data'][$cont];
} }
@ -1325,14 +1325,14 @@ function set_update_plugin_module($id_module, $thrash1, $other, $thrash3){
function set_create_data_module($id, $thrash1, $other, $thrash3) { function set_create_data_module($id, $thrash1, $other, $thrash3) {
$agentName = $id; $agentName = $id;
if ($other['data'][0] == ""){ if ($other['data'][0] == "") {
returnError('error_create_data_module', __('Error in creation data module. Module_name cannot be left blank.')); returnError('error_create_data_module', __('Error in creation data module. Module_name cannot be left blank.'));
return; return;
} }
$idAgent = agents_get_agent_id($agentName); $idAgent = agents_get_agent_id($agentName);
if (!$idAgent){ if (!$idAgent) {
returnError('error_create_data_module', __('Error in creation data module. Agent name doesn\'t exists.')); returnError('error_create_data_module', __('Error in creation data module. Agent name doesn\'t exists.'));
return; return;
} }
@ -1389,26 +1389,26 @@ function set_create_data_module($id, $thrash1, $other, $thrash3) {
*/ */
function set_update_data_module($id_module, $thrash1, $other, $thrash3){ function set_update_data_module($id_module, $thrash1, $other, $thrash3){
if ($id_module == ""){ if ($id_module == "") {
returnError('error_update_data_module', __('Error updating data module. Id_module cannot be left blank.')); returnError('error_update_data_module', __('Error updating data module. Id_module cannot be left blank.'));
return; return;
} }
$check_id_module = db_get_value ('id_agente_modulo', 'tagente_modulo', 'id_agente_modulo', $id_module); $check_id_module = db_get_value ('id_agente_modulo', 'tagente_modulo', 'id_agente_modulo', $id_module);
if (!$check_id_module){ if (!$check_id_module) {
returnError('error_update_data_module', __('Error updating data module. Id_module doesn\'t exists.')); returnError('error_update_data_module', __('Error updating data module. Id_module doesn\'t exists.'));
return; return;
} }
// If we want to change the module to a new agent // If we want to change the module to a new agent
if ($other['data'][0] != ""){ if ($other['data'][0] != "") {
$id_agent_old = db_get_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_module); $id_agent_old = db_get_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_module);
if ($id_agent_old != $other['data'][0]){ if ($id_agent_old != $other['data'][0]) {
$id_module_exists = db_get_value_filter ('id_agente_modulo', 'tagente_modulo', array('nombre' => $module_name, 'id_agente' => $other['data'][0])); $id_module_exists = db_get_value_filter ('id_agente_modulo', 'tagente_modulo', array('nombre' => $module_name, 'id_agente' => $other['data'][0]));
if ($id_module_exists){ if ($id_module_exists) {
returnError('error_update_data_module', __('Error updating data module. Id_module exists in the new agent.')); returnError('error_update_data_module', __('Error updating data module. Id_module exists in the new agent.'));
return; return;
} }
@ -1421,7 +1421,7 @@ function set_update_data_module($id_module, $thrash1, $other, $thrash3){
$values = array(); $values = array();
$cont = 0; $cont = 0;
foreach ($data_module_fields as $field){ foreach ($data_module_fields as $field) {
if ($other['data'][$cont] != ""){ if ($other['data'][$cont] != ""){
$values[$field] = $other['data'][$cont]; $values[$field] = $other['data'][$cont];
} }
@ -1464,19 +1464,19 @@ function set_update_data_module($id_module, $thrash1, $other, $thrash3){
function set_create_snmp_module($id, $thrash1, $other, $thrash3) { function set_create_snmp_module($id, $thrash1, $other, $thrash3) {
$agentName = $id; $agentName = $id;
if ($other['data'][0] == ""){ if ($other['data'][0] == "") {
returnError('error_create_snmp_module', __('Error in creation SNMP module. Module_name cannot be left blank.')); returnError('error_create_snmp_module', __('Error in creation SNMP module. Module_name cannot be left blank.'));
return; return;
} }
if ($other['data'][2] < 15 or $other['data'][3] > 17){ if ($other['data'][2] < 15 or $other['data'][3] > 17) {
returnError('error_create_snmp_module', __('Error in creation SNMP module. Invalid id_module_type for a SNMP module.')); returnError('error_create_snmp_module', __('Error in creation SNMP module. Invalid id_module_type for a SNMP module.'));
return; return;
} }
$idAgent = agents_get_agent_id($agentName); $idAgent = agents_get_agent_id($agentName);
if (!$idAgent){ if (!$idAgent) {
returnError('error_create_snmp_module', __('Error in creation SNMP module. Agent name doesn\'t exists.')); returnError('error_create_snmp_module', __('Error in creation SNMP module. Agent name doesn\'t exists.'));
return; return;
} }
@ -1484,7 +1484,7 @@ function set_create_snmp_module($id, $thrash1, $other, $thrash3) {
$name = $other['data'][0]; $name = $other['data'][0];
# SNMP version 3 # SNMP version 3
if ($other['data'][14] == "3"){ if ($other['data'][14] == "3") {
if ($other['data'][23] != "AES" and $other['data'][23] != "DES"){ if ($other['data'][23] != "AES" and $other['data'][23] != "DES"){
returnError('error_create_snmp_module', __('Error in creation SNMP module. snmp3_priv_method doesn\'t exists. Set it to \'AES\' or \'DES\'. ')); returnError('error_create_snmp_module', __('Error in creation SNMP module. snmp3_priv_method doesn\'t exists. Set it to \'AES\' or \'DES\'. '));
@ -1595,26 +1595,26 @@ function set_create_snmp_module($id, $thrash1, $other, $thrash3) {
*/ */
function set_update_snmp_module($id_module, $thrash1, $other, $thrash3) { function set_update_snmp_module($id_module, $thrash1, $other, $thrash3) {
if ($id_module == ""){ if ($id_module == "") {
returnError('error_update_snmp_module', __('Error updating SNMP module. Id_module cannot be left blank.')); returnError('error_update_snmp_module', __('Error updating SNMP module. Id_module cannot be left blank.'));
return; return;
} }
$check_id_module = db_get_value ('id_agente_modulo', 'tagente_modulo', 'id_agente_modulo', $id_module); $check_id_module = db_get_value ('id_agente_modulo', 'tagente_modulo', 'id_agente_modulo', $id_module);
if (!$check_id_module){ if (!$check_id_module) {
returnError('error_update_snmp_module', __('Error updating SNMP module. Id_module doesn\'t exists.')); returnError('error_update_snmp_module', __('Error updating SNMP module. Id_module doesn\'t exists.'));
return; return;
} }
// If we want to change the module to a new agent // If we want to change the module to a new agent
if ($other['data'][0] != ""){ if ($other['data'][0] != "") {
$id_agent_old = db_get_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_module); $id_agent_old = db_get_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_module);
if ($id_agent_old != $other['data'][0]){ if ($id_agent_old != $other['data'][0]) {
$id_module_exists = db_get_value_filter ('id_agente_modulo', 'tagente_modulo', array('nombre' => $module_name, 'id_agente' => $other['data'][0])); $id_module_exists = db_get_value_filter ('id_agente_modulo', 'tagente_modulo', array('nombre' => $module_name, 'id_agente' => $other['data'][0]));
if ($id_module_exists){ if ($id_module_exists) {
returnError('error_update_snmp_module', __('Error updating SNMP module. Id_module exists in the new agent.')); returnError('error_update_snmp_module', __('Error updating SNMP module. Id_module exists in the new agent.'));
return; return;
} }
@ -1622,9 +1622,9 @@ function set_update_snmp_module($id_module, $thrash1, $other, $thrash3) {
} }
# SNMP version 3 # SNMP version 3
if ($other['data'][13] == "3"){ if ($other['data'][13] == "3") {
if ($other['data'][22] != "AES" and $other['data'][22] != "DES"){ if ($other['data'][22] != "AES" and $other['data'][22] != "DES") {
returnError('error_create_snmp_module', __('Error in creation SNMP module. snmp3_priv_method doesn\'t exists. Set it to \'AES\' or \'DES\'. ')); returnError('error_create_snmp_module', __('Error in creation SNMP module. snmp3_priv_method doesn\'t exists. Set it to \'AES\' or \'DES\'. '));
return; return;
} }
@ -1634,7 +1634,7 @@ function set_update_snmp_module($id_module, $thrash1, $other, $thrash3) {
return; return;
} }
if ($other['data'][25] != "MD5" and $other['data'][25] != "SHA"){ if ($other['data'][25] != "MD5" and $other['data'][25] != "SHA") {
returnError('error_create_snmp_module', __('Error in creation SNMP module. snmp3_auth_method doesn\'t exists. Set it to \'MD5\' or \'SHA\'. ')); returnError('error_create_snmp_module', __('Error in creation SNMP module. snmp3_auth_method doesn\'t exists. Set it to \'MD5\' or \'SHA\'. '));
return; return;
} }
@ -1643,7 +1643,6 @@ function set_update_snmp_module($id_module, $thrash1, $other, $thrash3) {
'min_critical', 'max_critical', 'str_critical', 'min_ff_event', 'history_data', 'ip_target', 'tcp_port', 'tcp_send', 'min_critical', 'max_critical', 'str_critical', 'min_ff_event', 'history_data', 'ip_target', 'tcp_port', 'tcp_send',
'snmp_community', 'snmp_oid', 'module_interval', 'post_process', 'min', 'max', 'custom_id', 'descripcion', 'custom_string_1', 'snmp_community', 'snmp_oid', 'module_interval', 'post_process', 'min', 'max', 'custom_id', 'descripcion', 'custom_string_1',
'custom_string_2', 'custom_string_3', 'plugin_parameter', 'plugin_user', 'plugin_pass'); 'custom_string_2', 'custom_string_3', 'plugin_parameter', 'plugin_user', 'plugin_pass');
} }
else { else {
$snmp_module_fields = array('id_agente', 'disabled', 'id_module_group', 'min_warning', 'max_warning', 'str_warning', $snmp_module_fields = array('id_agente', 'disabled', 'id_module_group', 'min_warning', 'max_warning', 'str_warning',
@ -3723,7 +3722,7 @@ function set_enable_disable_user ($id, $thrash2, $other, $thrash3) {
} }
function otherParameter2Filter($other, $array = false) { function otherParameter2Filter($other, $return_as_array = false) {
$filter = array(); $filter = array();
if (($other['data'][1] != null) && ($other['data'][1] != -1) && ($other['data'][1] != '')) { if (($other['data'][1] != null) && ($other['data'][1] != -1) && ($other['data'][1] != '')) {
@ -3770,7 +3769,7 @@ function otherParameter2Filter($other, $array = false) {
} }
if (($other['data'][6] != null) && ($other['data'][6] != -1)) { if (($other['data'][6] != null) && ($other['data'][6] != -1)) {
if ($array) { if ($return_as_array) {
$filter['utimestamp']['>'] = $other['data'][6]; $filter['utimestamp']['>'] = $other['data'][6];
} }
else { else {
@ -3779,7 +3778,7 @@ function otherParameter2Filter($other, $array = false) {
} }
if (($other['data'][7] != null) && ($other['data'][7] != -1)) { if (($other['data'][7] != null) && ($other['data'][7] != -1)) {
if ($array) { if ($return_as_array) {
$filter['utimestamp']['<'] = $other['data'][7]; $filter['utimestamp']['<'] = $other['data'][7];
} }
else { else {
@ -3788,7 +3787,7 @@ function otherParameter2Filter($other, $array = false) {
} }
if (($other['data'][8] != null) && ($other['data'][8] != -1)) { if (($other['data'][8] != null) && ($other['data'][8] != -1)) {
if ($array) { if ($return_as_array) {
$filter['estado'] = $other['data'][8]; $filter['estado'] = $other['data'][8];
} }
else { else {
@ -3801,7 +3800,7 @@ function otherParameter2Filter($other, $array = false) {
} }
if (($other['data'][9] != null) && ($other['data'][9] != "")) { if (($other['data'][9] != null) && ($other['data'][9] != "")) {
if ($array) { if ($return_as_array) {
$filter['evento'] = $other['data'][9]; $filter['evento'] = $other['data'][9];
} }
else { else {
@ -3810,7 +3809,7 @@ function otherParameter2Filter($other, $array = false) {
} }
if ($other['data'][10] != null) { if ($other['data'][10] != null) {
if ($array) { if ($return_as_array) {
$filter['limit'] = $other['data'][10]; $filter['limit'] = $other['data'][10];
} }
else { else {
@ -3819,7 +3818,7 @@ function otherParameter2Filter($other, $array = false) {
} }
if ($other['data'][11] != null) { if ($other['data'][11] != null) {
if ($array) { if ($return_as_array) {
$filter['offset'] = $other['data'][11]; $filter['offset'] = $other['data'][11];
} }
else { else {
@ -3828,7 +3827,7 @@ function otherParameter2Filter($other, $array = false) {
} }
if (isset($other['data'][12]) && ($other['data'][12] != null)) { if (isset($other['data'][12]) && ($other['data'][12] != null)) {
if ($array) { if ($return_as_array) {
$filter['total'] = false; $filter['total'] = false;
$filter['more_criticity'] = false; $filter['more_criticity'] = false;
@ -3845,7 +3844,7 @@ function otherParameter2Filter($other, $array = false) {
} }
} }
else { else {
if ($array) { if ($return_as_array) {
$filter['total'] = false; $filter['total'] = false;
$filter['more_criticity'] = false; $filter['more_criticity'] = false;
} }
@ -3854,7 +3853,7 @@ function otherParameter2Filter($other, $array = false) {
} }
} }
if ($array) { if ($return_as_array) {
return $filter; return $filter;
} }
else { else {
@ -4408,6 +4407,8 @@ function set_validate_events($id_event, $trash1, $other, $return_type, $user_in_
$result = events_validate_event ($id_event, false, $text); $result = events_validate_event ($id_event, false, $text);
//html_debug_print($result, true);
if ($result) { if ($result) {
returnData('string', array('type' => 'string', 'data' => 'Correct validation')); returnData('string', array('type' => 'string', 'data' => 'Correct validation'));
} }
@ -4714,8 +4715,12 @@ function get_events($trash1, $trash2, $other, $returnType, $user_in_db = null) {
get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_db); get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_db);
$last_error = error_get_last(); $last_error = error_get_last();
if (!empty($last_error)) { if (!empty($last_error)) {
$errors = array(E_ERROR, E_WARNING, E_USER_ERROR,
E_USER_WARNING);
if (in_array($last_error['type'], $errors)) {
returnError('ERROR_API_PANDORAFMS', $returnType); returnError('ERROR_API_PANDORAFMS', $returnType);
} }
}
return; return;
} }

View File

@ -193,6 +193,8 @@ function events_validate_event ($id_event, $similars = true, $comment = '', $new
foreach ($id_event as $event) { foreach ($id_event as $event) {
if (check_acl ($config["id_user"], events_get_group ($event), "IW") == 0) { if (check_acl ($config["id_user"], events_get_group ($event), "IW") == 0) {
db_pandora_audit("ACL Violation", "Attempted updating event #".$event); db_pandora_audit("ACL Violation", "Attempted updating event #".$event);
return false;
} }
$comment = '<b>-- '.$new_status_string.' '.__('by').' '.$config['id_user'].' '.'['.date ($config["date_format"]).'] --</b><br>'.$commentbox; $comment = '<b>-- '.$new_status_string.' '.__('by').' '.$config['id_user'].' '.'['.date ($config["date_format"]).'] --</b><br>'.$commentbox;

View File

@ -23,9 +23,9 @@ global $config;
/** /**
* Include modules functions * Include modules functions
*/ */
include_once ($config['homedir'] . 'include/functions_modules.php'); include_once ($config['homedir'] . '/include/functions_modules.php');
include_once ($config['homedir'] . 'include/functions_agents.php'); include_once ($config['homedir'] . '/include/functions_agents.php');
include_once ($config['homedir'] . 'include/functions_users.php'); include_once ($config['homedir'] . '/include/functions_users.php');
/** /**
* Get a list of network components. * Get a list of network components.