From d12791c03f9dcf0fc93b9992272c425c9cb12cc8 Mon Sep 17 00:00:00 2001 From: "tatiana.llorente@artica.es" Date: Thu, 25 Oct 2018 10:41:40 +0200 Subject: [PATCH 01/42] Added parameter width id agent - #2958 --- pandora_console/godmode/alerts/alert_list.builder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandora_console/godmode/alerts/alert_list.builder.php b/pandora_console/godmode/alerts/alert_list.builder.php index d32ab3ed48..5092d9b5f0 100644 --- a/pandora_console/godmode/alerts/alert_list.builder.php +++ b/pandora_console/godmode/alerts/alert_list.builder.php @@ -65,6 +65,8 @@ if (! $id_agente) { $params['selectbox_id'] = 'id_agent_module'; $params['javascript_is_function_select'] = true; $params['metaconsole_enabled'] = false; + $params['use_hidden_input_idagent'] = true; + $params['print_hidden_input_idagent'] = true; $table->data['agent'][1] = ui_print_agent_autocomplete_input($params); } From 4b522d3f0349f92c32b80b52064905b54162f78d Mon Sep 17 00:00:00 2001 From: "tatiana.llorente@artica.es" Date: Thu, 25 Oct 2018 13:18:28 +0200 Subject: [PATCH 02/42] Added disabled field in sql query - #2955 --- pandora_console/include/functions_groupview.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora_console/include/functions_groupview.php b/pandora_console/include/functions_groupview.php index 15b4d577bf..41ada4fecf 100644 --- a/pandora_console/include/functions_groupview.php +++ b/pandora_console/include/functions_groupview.php @@ -68,6 +68,7 @@ function groupview_get_modules_counters($groups_ids = false) { ta.id_grupo AS g FROM $table ta WHERE ta.id_grupo IN ($groups_ids) + AND ta.disabled = 0 GROUP BY ta.id_grupo UNION ALL SELECT SUM(ta.normal_count) AS module_normal, From ad652c82fa0eb48407722f2f1c50135c816c10de Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Thu, 25 Oct 2018 13:56:17 +0200 Subject: [PATCH 03/42] fixed english and spanish version of plugin-in macros help dialog --- pandora_console/include/help/en/help_plugin_macros.php | 8 ++++---- pandora_console/include/help/es/help_plugin_macros.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pandora_console/include/help/en/help_plugin_macros.php b/pandora_console/include/help/en/help_plugin_macros.php index 1660c45e13..6d1e508b21 100644 --- a/pandora_console/include/help/en/help_plugin_macros.php +++ b/pandora_console/include/help/en/help_plugin_macros.php @@ -31,10 +31,10 @@ Hidden this macros because they cannot edit in the module form -->
  • _plugin_parameters_ : Plug-in Parameters of the module.
  • -
  • _name_tag_ : Nombre de los tags asociados al módulo.
  • -
  • _email_tag_ : Emails asociados a los tags de módulos.
  • -
  • _phone_tag_ : Teléfonos asociados a los tags de módulos.
  • -
  • _moduletags_ : Teléfonos asociados a los tags de módulos.
  • +
  • _name_tag_ : Names of the tags associated to the module.
  • +
  • _email_tag_ : Emails associated to module tags.
  • +
  • _phone_tag_ : Phone numbers associated to module tags.
  • +
  • _moduletags_ : URLs associated to module tags.
  • _agentcustomfield_n_: Agent custom field number n (eg. _agentcustomfield_9_).
  • diff --git a/pandora_console/include/help/es/help_plugin_macros.php b/pandora_console/include/help/es/help_plugin_macros.php index 701d15f35e..77c97aa4d7 100644 --- a/pandora_console/include/help/es/help_plugin_macros.php +++ b/pandora_console/include/help/es/help_plugin_macros.php @@ -30,9 +30,9 @@ Hidden this macros because they cannot edit in the module form -->

  • _plugin_parameters_ : Parámetros del Plug-in del módulo.
  • -
  • _name_tag_ : Names of the tags associated to the module.
  • -
  • _email_tag_ : Emails associated to the module tags.
  • -
  • _phone_tag_ : Phone numbers associated to the module tags.
  • -
  • _moduletags_ : URLs associated to the module tags.
  • +
  • _name_tag_ : Nombre de los tags asociados al módulo.
  • +
  • _email_tag_ : Emails asociados a los tags de módulos.
  • +
  • _phone_tag_ : Teléfonos asociados a los tags de módulos.
  • +
  • _moduletags_ : URLs asociadas a los tags de módulos.
  • _agentcustomfield_n_: Campo personalizado número n del agente (eg. _agentcustomfield_9_).
  • From 2849d62faa6e8cd62101b9bf31d723ed5c85f026 Mon Sep 17 00:00:00 2001 From: enriquecd Date: Thu, 25 Oct 2018 19:48:23 +0200 Subject: [PATCH 04/42] Add generic API functions set access control and traps functions - #2978 --- pandora_console/include/functions_api.php | 276 ++++++++++++++++++++++ 1 file changed, 276 insertions(+) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index a2fc33d938..cff419acb4 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -30,6 +30,7 @@ include_once($config['homedir'] . "/include/functions_network_components.php"); include_once($config['homedir'] . "/include/functions_netflow.php"); include_once($config['homedir'] . "/include/functions_servers.php"); include_once($config['homedir'] . "/include/functions_planned_downtimes.php"); +include_once($config['homedir'] . "/include/functions_db.php"); enterprise_include_once ('include/functions_local_components.php'); enterprise_include_once ('include/functions_events.php'); enterprise_include_once ('include/functions_agents.php'); @@ -11505,7 +11506,282 @@ function util_api_check_agent_and_print_error($id_agent, $returnType, $access = return false; } +function api_get_user_info($thrash1, $thrash2, $other, $returnType) { + if (defined ('METACONSOLE')) { + return; + } + + $separator = ';'; + + $other = json_decode(base64_decode($other['data']),true); + + $sql = 'select * from tusuario where id_user = "'.$other[0]['id_user'].'" and password = "'.$other[0]['password'].'"'; + + $user_info = db_get_all_rows_sql($sql); + if (count($user_info) > 0 and $user_info !== false) { + $data = array('type' => 'array', 'data' => $user_info); + returnData($returnType, $data, $separator); + } + else { + return 0; + } +} + + +/* + +This function receives different parameters to process one of these actions the logging process in our application from the records in the audit of pandora fms, to avoid concurrent access of administrator users, and optionally to prohibit access to non-administrator users: + +Parameter 0 + +The User ID that attempts the action is used to check the status of the application for access. + +Parameter 1 + +Login, logout, exclude, browse. + +These requests receive a response that we can treat as we consider, this function only sends answers, does not perform any action in your application, you must customize them. + +Login action: free (register our access), taken, denied (if you are not an administrator user and parameter four is set to 1, register the expulsion). + +Browse action: It has the same answers as login, but does not register anything in the audit. + +Logout action: It records the deslogeo but does not send a response. + +All other actions do not return a response, + +Parameter 2 + +IP address of the application is also used to check the status of the application for access. + +Parameter 3 + +Name of the application, it is also used to check the status of the application for access. + +Parameter 4 + +If you mark 1 you will avoid the access to the non-administrators users, returning the response `denied' and registering that expulsion in the audit of pandora fms. + +*/ + + + +function api_set_access_process($thrash1, $thrash2, $other, $returnType) { + if (defined ('METACONSOLE')) { + return; + } + + $other['data'] = explode('|',$other['data']); + + $sql = 'select id_usuario,utimestamp from tsesion where descripcion like "%'.$other['data'][2].'%" and accion like "%'.$other['data'][3].' Logon%" and id_usuario IN (select id_user from tusuario where is_admin = 1) and id_usuario != "'.$other['data'][0].'" order by utimestamp DESC limit 1'; + $audit_concurrence = db_get_all_rows_sql($sql); + $sql_user = 'select id_usuario,utimestamp from tsesion where descripcion like "%'.$other['data'][2].'%" and accion like "%'.$other['data'][3].' Logon%" and id_usuario IN (select id_user from tusuario where is_admin = 1) and id_usuario = "'.$other['data'][0].'" order by utimestamp DESC limit 1'; + $audit_concurrence_user = db_get_all_rows_sql($sql_user); + $sql2 = 'select id_usuario,utimestamp,accion from tsesion where descripcion like "%'.$other['data'][2].'%" and accion like "%'.$other['data'][3].' Logoff%" and id_usuario = "'.$audit_concurrence[0]['id_usuario'].'" order by utimestamp DESC limit 1'; + $audit_concurrence_2 = db_get_all_rows_sql($sql2); + + //The user trying to log in is an administrator + if(users_is_admin($other['data'][0])){ + //The admin user is trying to login + if($other['data'][1] == 'login'){ + // Check if there is an administrator user logged in prior to our last login + if($audit_concurrence[0]['utimestamp'] > $audit_concurrence_user[0]['utimestamp']){ + // Check if the administrator user logged in later to us has unlogged and left the node free + if($audit_concurrence[0]['utimestamp'] > $audit_concurrence_2[0]['utimestamp']){ + // The administrator user logged in later has not yet unlogged + returnData('string', array('type' => 'string', 'data' => 'taken')); + } + else{ + // The administrator user logged in later has already unlogged + returnData('string', array('type' => 'string', 'data' => 'free')); + } + } + else{ + // There is no administrator user who has logged in since then to log us in. + db_pandora_audit($other['data'][3].' Logon', 'Logged in '.$other['data'][3].' node '.$other['data'][2] , $other['data'][0]); + returnData('string', array('type' => 'string', 'data' => 'free')); + } + + } + elseif ($other['data'][1] == 'logout') { + // The administrator user wants to log out + db_pandora_audit($other['data'][3].' Logoff', 'Logout from '.$other['data'][3].' node '.$other['data'][2], $other['data'][0]); + } + elseif ($other['data'][1] == 'exclude') { + // The administrator user has ejected another administrator user who was logged in + db_pandora_audit($other['data'][3].' Logon', 'Logged in '.$other['data'][3].' node '.$other['data'][2] , $other['data'][0]); + db_pandora_audit($other['data'][3].' Logoff', 'Logout from '.$other['data'][3].' node '.$other['data'][2] , $audit_concurrence[0]['id_usuario']); + + } + //The admin user is trying to browse + elseif ($other['data'][1] == 'browse') { + // Check if there is an administrator user logged in prior to our last login + if($audit_concurrence[0]['utimestamp'] > $audit_concurrence_user[0]['utimestamp']){ + // Check if the administrator user logged in later to us has unlogged and left the node free + if($audit_concurrence[0]['utimestamp'] > $audit_concurrence_2[0]['utimestamp']){ + // The administrator user logged in later has not yet unlogged + returnData('string', array('type' => 'string', 'data' => $audit_concurrence[0]['id_usuario'])); + } + else{ + // The administrator user logged in later has already unlogged + returnData('string', array('type' => 'string', 'data' => 'free')); + } + } + else{ + // There is no administrator user who has logged in since then to log us in. + returnData('string', array('type' => 'string', 'data' => 'free')); + } + + } + elseif ($other['data'][1] == 'cancelled'){ + //The administrator user tries to log in having another administrator logged in, but instead of expelling him he cancels his log in. + db_pandora_audit($other['data'][3].' cancelled access', 'Cancelled access in '.$other['data'][3].' node '.$other['data'][2] , $other['data'][0]); + returnData('string', array('type' => 'string', 'data' => 'cancelled')); + } + +} +else{ + + if($other['data'][4] == 1){ + //The user trying to log in is not an administrator and is not allowed no admin access + db_pandora_audit($other['data'][3].' denied access', 'Denied access to non-admin user '.$other['data'][3].' node '.$other['data'][2] , $other['data'][0]); + returnData('string', array('type' => 'string', 'data' => 'denied')); + } + else{ + //The user trying to log in is not an administrator and is allowed no admin access + if($other['data'][1] == 'login'){ + //The user trying to login is not admin, can enter without concurrent use filter + db_pandora_audit($other['data'][3].' Logon', 'Logged in '.$other['data'][3].' node '.$other['data'][2] , $other['data'][0]); + returnData('string', array('type' => 'string', 'data' => 'free')); + + } + elseif ($other['data'][1] == 'logout') { + //The user trying to logoff is not admin + db_pandora_audit($other['data'][3].' Logoff', 'Logout from '.$other['data'][3].' node '.$other['data'][2], $other['data'][0]); + } + elseif ($other['data'][1] == 'browse'){ + //The user trying to browse in an app page is not admin, can enter without concurrent use filter + returnData('string', array('type' => 'string', 'data' => 'free')); + } + } + } +} + + +function api_get_traps($thrash1, $thrash2, $other, $returnType) { + + if (defined ('METACONSOLE')) { + return; + } + + $other['data'] = explode('|',$other['data']); + + $other['data'][1] = date("Y-m-d H:i:s",$other['data'][1]); + + $sql = 'SELECT * from ttrap where timestamp >= "'.$other['data'][1].'"'; + + // $sql = 'SELECT * from ttrap where source = "'.$other['data'][0].'" and timestamp >= "'.$other['data'][1].'"'; + + if($other['data'][4]){ + $other['data'][4] = date("Y-m-d H:i:s",$other['data'][4]); + $sql .= ' and timestamp <= "'.$other['data'][4].'"'; + } + + if($other['data'][2]){ + $sql .= ' limit '.$other['data'][2]; + } + + if($other['data'][3]){ + $sql .= ' offset '.$other['data'][3]; + } + + if($other['data'][5]){ + $sql .= ' and status = 0'; + } + + if(sizeof($other['data']) == 0){ + $sql = 'SELECT * from ttrap'; + } + + + $traps = db_get_all_rows_sql($sql); + + if($other['data'][6]){ + + foreach ($traps as $key => $value) { + + if(!strpos($value['oid_custom'],$other['data'][6]) && $other['data'][7] == 'false'){ + unset($traps[$key]); + } + + if(strpos($value['oid_custom'],$other['data'][6]) && $other['data'][7] == 'true'){ + unset($traps[$key]); + } + + } + + } + + $traps_json = json_encode($traps); + + if (count($traps) > 0 and $traps !== false) { + returnData('string', array('type' => 'string', 'data' => $traps_json)); + } + else { + return 0; + } + +} + +function api_set_validate_traps ($id, $thrash2, $other, $thrash3) { + + if (defined ('METACONSOLE')) { + return; + } + + if($id == 'all'){ + $result = db_process_sql_update('ttrap',array('status' => 1)); + } + else{ + $result = db_process_sql_update('ttrap', + array('status' => 1), array('id_trap' => $id)); + } + + if (is_error($result)) { + // TODO: Improve the error returning more info + returnError('error_update_trap', __('Error in trap update.')); + } + else { + returnData('string', + array('type' => 'string', + 'data' => __('Validated traps.'))); + } + } + +function api_set_delete_traps ($id, $thrash2, $other, $thrash3) { + + if (defined ('METACONSOLE')) { + return; + } + + if($id == 'all'){ + $result = db_process_sql ('delete from ttrap'); + } + else{ + $result = db_process_sql_delete('ttrap',array('id_trap' => $id)); + } + + if (is_error($result)) { + // TODO: Improve the error returning more info + returnError('error_delete_trap', __('Error in trap delete.')); + } + else { + returnData('string', + array('type' => 'string', + 'data' => __('Deleted traps.'))); + } + } From 74016c928fea3a17769c18b83c5e4066853a5f4d Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Tue, 30 Oct 2018 10:20:31 +0100 Subject: [PATCH 05/42] fixed bug: failing load of post process and unit fields in plugin component in module creation --- .../agentes/module_manager_editor_common.php | 2 +- pandora_console/include/javascript/pandora.js | 43 ++++++++++++++++++- .../include/javascript/pandora_modules.js | 19 +++++++- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php index 0527bea08d..19dcc94ffa 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_common.php +++ b/pandora_console/godmode/agentes/module_manager_editor_common.php @@ -439,7 +439,7 @@ $table_advanced->data[2][1] .= html_print_input_hidden ('moduletype', $moduletyp $table_advanced->data[2][3] = __('Post process').' ' . ui_print_help_icon ('postprocess', true); $table_advanced->data[2][4] = html_print_extended_select_for_post_process('post_process', - $post_process, '', '', '0', false, true, false, true, + $post_process, '', '', '0', false, true, false, false, $disabledBecauseInPolicy); $table_advanced->colspan[2][4] = 3; diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index 2b323a55f1..1ca0759801 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -594,12 +594,51 @@ function post_process_select_init_unit(name,selected) { function post_process_select_events_unit(name,selected) { $('.' + name + '_toggler').click(function() { - $('#' + name + '_select option[value=none]').attr("selected",true); - $('#text-' + name + '_text').val(""); + var value = $('#text-' + name + '_text').val(); + + var count = $('#' + name + '_select option') + .filter(function(i, item) { + + if ($(item).val() == value) + return true; + else return false; + }) + .length; + + if (count != 1) { + $('#' + name + '_select') + .append($("