diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index d1b5318f88..758ee6811a 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.730-190111 +Version: 7.0NG.730-190116 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 72960a6318..4e5706c7cf 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.730-190111" +pandora_version="7.0NG.730-190116" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 8ca0e748a6..9646cee020 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -42,7 +42,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '7.0NG.730'; -use constant AGENT_BUILD => '190111'; +use constant AGENT_BUILD => '190116'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index 2e5c1eceaf..bd1b569af4 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.730 -%define release 190111 +%define release 190116 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index b725d63a08..1156c6297a 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.730 -%define release 190111 +%define release 190116 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer index 902fc67022..b4c3b66bab 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -10,7 +10,7 @@ # ********************************************************************** PI_VERSION="7.0NG.730" -PI_BUILD="190111" +PI_BUILD="190116" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index affb521211..3c639031de 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{190111} +{190116} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 877abd9b57..87cec0dbac 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("7.0NG.730(Build 190111)") +#define PANDORA_VERSION ("7.0NG.730(Build 190116)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index f97e885ed9..91df373d23 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(7.0NG.730(Build 190111))" + VALUE "ProductVersion", "(7.0NG.730(Build 190116))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index ddbf2c8119..d7e1669bf6 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.730-190111 +Version: 7.0NG.730-190116 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index 0a8a8b2b97..af3a24ea27 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.730-190111" +pandora_version="7.0NG.730-190116" package_pear=0 package_pandora=1 diff --git a/pandora_console/ajax.php b/pandora_console/ajax.php index 97ffe031a9..c7d21fff1a 100644 --- a/pandora_console/ajax.php +++ b/pandora_console/ajax.php @@ -14,6 +14,15 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +// Enable profiler for testing +if (!defined("__PAN_XHPROF__")) define ("__PAN_XHPROF__", 0); + +if (__PAN_XHPROF__ === 1) { + if (function_exists('tideways_xhprof_enable')) { + tideways_xhprof_enable(); + } +} + if ((! file_exists("include/config.php")) || (! is_readable("include/config.php"))) { exit; } @@ -88,4 +97,8 @@ if (file_exists ($page)) { else { echo '
Sorry! I can\'t find the page '.$page.'!'; } + +if (__PAN_XHPROF__ === 1) { + pandora_xhprof_display_result("ajax", "console"); +} ?> diff --git a/pandora_console/godmode/massive/massive_delete_modules.php b/pandora_console/godmode/massive/massive_delete_modules.php index 8462d75b7e..74860bb50f 100755 --- a/pandora_console/godmode/massive/massive_delete_modules.php +++ b/pandora_console/godmode/massive/massive_delete_modules.php @@ -285,7 +285,7 @@ else { $filter = false; } $names = agents_get_modules (array_keys ($agents), - 'DISTINCT(tagente_modulo.nombre)', $filter, false); + 'tagente_modulo.nombre', $filter, false); foreach ($names as $name) { $modules[$name['nombre']] = $name['nombre']; } diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index f09d495c0a..35d5bd1abc 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -51,31 +51,27 @@ if ($update) { $agents_ = array(); $force = get_parameter('force_type', false); - + if ($agents_select == false) { $agents_select = array(); } - - foreach ($agents_select as $agent_name) { - $agents_[] = agents_get_agent_id($agent_name); - } + $agents_ = $agents_select; $modules_ = $module_name; - } else if ($selection_mode == 'agents') { $force = get_parameter('force_group', false); - + $agents_ = $agents_id; $modules_ = $modules_select; } - + $success = 0; $count = 0; - + if ($agents_ == false) $agents_ = array(); - + // If the option to select all of one group or module type is checked if ($force) { if ($force == 'type') { diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index afdd2fc759..4138b048f6 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -193,25 +193,49 @@ if ($dialogue_event_response) { $event_id = get_parameter ('event_id'); $response_id = get_parameter ('response_id'); $command = get_parameter ('target'); - + $massive = get_parameter ('massive'); + $end = get_parameter ('end'); + $show_execute_again_btn = get_parameter ('show_execute_again_btn'); + $out_iterator = get_parameter ('out_iterator'); $event_response = db_get_row('tevent_response','id',$response_id); $event = db_get_row('tevento','id_evento',$event_id); $prompt = "
> "; - switch($event_response['type']) { case 'command': - echo "
"; - echo $prompt.sprintf(__('Executing command: %s',$command)); - echo "

"; + - echo ""; - echo "
"; - - echo "
"; + if ($massive) { + echo "
"; + echo $prompt.sprintf("(Event #$event_id) ".__('Executing command: %s',$command)); + echo "

"; + + echo ""; + echo "
"; + + if ($end) { + + echo "
"; + } + } + else { + + echo "
"; + echo $prompt.sprintf(__('Executing command: %s',$command)); + echo "

"; + + echo ""; + echo "
"; + + echo "
"; + } + break; case 'url': $command = str_replace("localhost",$_SERVER['SERVER_NAME'],$command); diff --git a/pandora_console/include/auth/mysql.php b/pandora_console/include/auth/mysql.php index ffd618fb65..3b73fd7f37 100644 --- a/pandora_console/include/auth/mysql.php +++ b/pandora_console/include/auth/mysql.php @@ -269,32 +269,8 @@ function process_user_login_remote ($login, $pass, $api = false) { else { delete_user_pass_ldap ($login); } - - $permissions = array(); - if($config['ldap_advanced_config']){ - $i = 0; - - $ldap_adv_perms = json_decode(io_safe_output($config['ldap_adv_perms']), true); - foreach ($ldap_adv_perms as $ldap_adv_perm) { - $attributes = $ldap_adv_perm['groups_ldap']; - - foreach ($attributes as $attr) { - $attr = explode('=', $attr, 2); - foreach ($sr[$attr[0]] as $s_attr) { - if(preg_match('/' . $attr[1] . '/', $s_attr)){ - $permissions[$i]["profile"] = $ldap_adv_perm['profile']; - $permissions[$i]["groups"] = $ldap_adv_perm['group']; - $permissions[$i]["tags"] = implode(",",$ldap_adv_perm['tags']); - $i++; - } - } - } - } - } else { - $permissions[0]["profile"] = $config['default_remote_profile']; - $permissions[0]["groups"][] = $config['default_remote_group']; - $permissions[0]["tags"] = $config['default_assign_tags']; - } + + $permissions = fill_permissions_ldap($sr); if(empty($permissions)) { $config["auth_error"] = __("User not found in database or incorrect password"); return false; @@ -388,33 +364,7 @@ function process_user_login_remote ($login, $pass, $api = false) { } } - $permissions = array(); - if($config['ldap_advanced_config']){ - $i = 0; - - $ldap_adv_perms = json_decode(io_safe_output($config['ldap_adv_perms']), true); - - foreach ($ldap_adv_perms as $ldap_adv_perm) { - $attributes = $ldap_adv_perm['groups_ldap']; - - foreach ($attributes as $attr) { - $attr = explode('=', $attr, 2); - foreach ($sr[$attr[0]] as $s_attr) { - if(preg_match('/' . $attr[1] . '/', $s_attr)){ - $permissions[$i]["profile"] = $ldap_adv_perm['profile']; - $permissions[$i]["groups"] = $ldap_adv_perm['group']; - $permissions[$i]["tags"] = implode(",",$ldap_adv_perm['tags']); - $i++; - } - } - } - } - } else { - $permissions[0]["profile"] = $config['default_remote_profile']; - $permissions[0]["groups"][] = $config['default_remote_group']; - $permissions[0]["tags"] = $config['default_assign_tags']; - } - + $permissions = fill_permissions_ldap($sr); if(empty($permissions)) { $config["auth_error"] = __("User not found in database or incorrect password"); return false; @@ -904,10 +854,11 @@ function create_user_and_permisions_ldap ($id_user, $password, $user_info, $id_profile = $permission["profile"]; $id_groups = $permission["groups"]; $tags = $permission["tags"]; + $no_hierarchy = (bool)$permission["no_hierarchy"] ? 1 : 0; foreach ($id_groups as $id_group) { $profile = profile_create_user_profile( - $id_user, $id_profile, $id_group, false, $tags); + $id_user, $id_profile, $id_group, false, $tags, $no_hierarchy); } if ( defined("METACONSOLE") && $syncronize ) { @@ -934,7 +885,7 @@ function create_user_and_permisions_ldap ($id_user, $password, $user_info, db_process_sql_insert ("tusuario", $values); foreach ($id_groups as $id_group) { $profile = profile_create_user_profile ($id_user, - $id_profile, $id_group, false, $tags); + $id_profile, $id_group, false, $tags, $no_hierarchy); } } @@ -1141,6 +1092,46 @@ function check_permission_ldap ($id_user, $password, $user_info, } } +/** + * Fill permissions array with setup values + * + * @param string sr return value from LDAP connection + * + * @return array with all permission on LDAP authentication + */ +function fill_permissions_ldap ($sr) { + global $config; + + $permissions = array(); + if(!$config['ldap_advanced_config']){ + $permissions[0]["profile"] = $config['default_remote_profile']; + $permissions[0]["groups"][] = $config['default_remote_group']; + $permissions[0]["tags"] = $config['default_assign_tags']; + $permissions[0]["no_hierarchy"] = $config['default_no_hierarchy']; + return $permissions; + } + + // Decode permissions in advanced mode + $ldap_adv_perms = json_decode(io_safe_output($config['ldap_adv_perms']), true); + foreach ($ldap_adv_perms as $ldap_adv_perm) { + $attributes = $ldap_adv_perm['groups_ldap']; + foreach ($attributes as $attr) { + $attr = explode('=', $attr, 2); + foreach ($sr[$attr[0]] as $s_attr) { + if(preg_match('/' . $attr[1] . '/', $s_attr)){ + $permissions[] = array( + "profile" => $ldap_adv_perm['profile'], + "groups" => $ldap_adv_perm['group'], + "tags" => implode(",",$ldap_adv_perm['tags']), + "no_hierarchy" => (bool)$ldap_adv_perm['no_hierarchy'] ? 1 : 0 + ); + } + } + } + } + return $permissions; +} + /** * Update local user pass from ldap user * diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 4a5301cd69..280aba46a5 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -22,7 +22,7 @@ /** * Pandora build version and version */ -$build_version = 'PC190111'; +$build_version = 'PC190116'; $pandora_version = 'v7.0NG.730'; // Do not overwrite default timezone set if defined. diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 1e43ae46fd..f2056f058e 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -3400,5 +3400,39 @@ function validate_csrf_code() { function generate_hash_to_api(){ hash('sha256', db_get_value ('value', 'tupdate_settings', '`key`', 'customer_key')); +} + +/** + * Disable the profiller and display de result + * + * @param string Key to identify the profiler run. + * @param string Way to display the result + * "link" (default): Click into word "Performance" to display the profilling info. + * "console": Display with a message in pandora_console.log. + */ +function pandora_xhprof_display_result($key = "", $method = "link") { + // Check if function exists + if (!function_exists('tideways_xhprof_disable')) { + error_log("Cannot find tideways_xhprof_disable function"); + return; } + + $run_id = uniqid(); + $data = tideways_xhprof_disable(); + $source = "pandora_$key"; + file_put_contents( + sys_get_temp_dir() . "/" . $run_id . ".$source.xhprof", + serialize($data) + ); + $new_url = "http://{$_SERVER['HTTP_HOST']}/profiler/index.php?run={$run_id}&source={$source}"; + switch($method) { + case "console": + error_log("'{$new_url}'"); + case "link": + default: + echo "Performance\n"; + break; + + } +} ?> diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 7b4592171b..b1d258e223 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1233,8 +1233,8 @@ function agents_get_modules ($id_agent = null, $details = false, ON tagente.id_agente = tasg.id_agent WHERE tagente_modulo.delete_pending = 0 AND %s - GROUP BY tagente_modulo.id_agente_modulo - ORDER BY tagente_modulo.nombre', + GROUP BY 1 + ORDER BY 1', ($details != 'tagente_modulo.*' && $indexed) ? 'tagente_modulo.id_agente_modulo,' : '', io_safe_output(implode (",", (array) $details)), $sql_tags_join, diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 53479ae7ed..8695ad9b1d 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -32,6 +32,7 @@ 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"); include_once($config['homedir'] . "/include/functions_event_responses.php"); +include_once($config['homedir'] . "/include/functions_policies.php"); enterprise_include_once ('include/functions_local_components.php'); enterprise_include_once ('include/functions_events.php'); enterprise_include_once ('include/functions_agents.php'); @@ -6448,6 +6449,63 @@ function api_set_update_snmp_module_policy($id, $thrash1, $other, $thrash3) { array('type' => 'string', 'data' => __('SNMP policy module updated.'))); } +/** + * Remove an agent from a policy. + * @param $id Id of the policy + * @param $id2 Id of the agent policy + * @param $trash1 + * @param $trash2 + * + * Example: + * api.php?op=set&op2=remove_agent_from_policy&apipass=1234&user=admin&pass=pandora&id=11&id2=2 + */ +function api_set_remove_agent_from_policy ($id, $id2, $thrash2, $thrash3) { + global $config; + + if (!check_acl($config['id_user'], 0, "AW")){ + returnError('forbidden', 'string'); + return; + } + + if ($id == '' || !$id) { + returnError('error_parameter', __('Error deleting agent from policy. Policy cannot be left blank.')); + return; + } + + if ($id2 == '' || !$id2) { + returnError('error_parameter', __('Error deleting agent from policy. Agent cannot be left blank.')); + return; + } + + $policy = policies_get_policy ($id, false, false); + $agent = db_get_row_filter('tagente', array('id_agente' => $id2)); + $policy_agent = db_get_row_filter('tpolicy_agents', array('id_policy' => $id ,'id_agent' => $id2)); + + if (empty ($policy)){ + returnError('error_policy', __('This policy does not exist.')); + return; + } + if (empty ($agent)){ + returnError('error_agent', __('This agent does not exist.')); + return; + } + if (empty ($policy_agent)){ + returnError('error_policy_agent', __('This agent does not exist in this policy.')); + return; + } + + $return = policies_change_delete_pending_agent($policy_agent['id']); + $data = __('Successfully added to delete pending id agent %d to id policy %d.', $id2, $id); + + if ($return === false) + returnError('error_delete_policy_agent', 'Could not be deleted id agent %d from id policy %d', $id2, $id); + else + returnData('string', array('type' => 'string', 'data' => $data)); + + +} + + /** * Create a new group. And return the id_group of the new group. * @@ -9716,6 +9774,11 @@ function api_set_create_event($id, $trash1, $other, $returnType) { return; } $values['id_grupo'] = $other['data'][1]; + + if (groups_get_name($values['id_grupo']) === false) { + returnError('error_parameter', 'Group ID does not exist'); + return; + } } else { returnError('error_parameter', 'Group ID required.'); @@ -10059,7 +10122,7 @@ function api_get_netflow_get_summary ($discard_1, $discard_2, $params) { } //http://localhost/pandora_console/include/api.php?op=set&op2=validate_event_by_id&id=23&apipass=1234&user=admin&pass=pandora -function api_set_validate_event_by_id ($id, $trash1, $trash2, $returnType) { +function api_set_validate_event_by_id ($id, $trash1 = null, $trash2 = null, $returnType = 'string') { global $config; $data['type'] = 'string'; $check_id = db_get_value('id_evento', 'tevento', 'id_evento', $id); @@ -10078,7 +10141,7 @@ function api_set_validate_event_by_id ($id, $trash1, $trash2, $returnType) { 'ack_utimestamp' => $ack_utimestamp, 'estado' => 1 ); - + $result = db_process_sql_update('tevento', $values, array('id_evento' => $id)); if ($result === false) { diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index bd0c78bd76..17f6d9b345 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -312,6 +312,8 @@ function config_update_config () { $error_update[] = __('Autocreate profile group'); if (!config_update_value ('default_assign_tags', implode(",",get_parameter ('default_assign_tags')))) $error_update[] = __('Autocreate profile tags'); + if (!config_update_value ('default_no_hierarchy', (int)get_parameter ('default_no_hierarchy'))) + $error_update[] = __('Automatically assigned no hierarchy'); if (!config_update_value ('autocreate_blacklist', get_parameter ('autocreate_blacklist'))) $error_update[] = __('Autocreate blacklist'); @@ -1452,7 +1454,10 @@ function config_process_config () { if (!isset ($config['default_assign_tags'])) { config_update_value ( 'default_assign_tags', ''); } - + if (!isset ($config['default_no_hierarchy'])) { + config_update_value ('default_no_hierarchy', 0); + } + if (!isset ($config['ldap_server'])) { config_update_value ( 'ldap_server', 'localhost'); } diff --git a/pandora_console/include/functions_profile.php b/pandora_console/include/functions_profile.php index 01d876697d..292d2892a7 100644 --- a/pandora_console/include/functions_profile.php +++ b/pandora_console/include/functions_profile.php @@ -79,14 +79,10 @@ function profile_create_user_profile ($id_user, $tags = '', $no_hierarchy = false ) { - global $config; if (empty ($id_profile) || $id_group < 0) - return false; - - // Secondary server is an enterprise function - if (!enterprise_installed() && $no_hierarchy) return false; + return false; // Checks if the user exists $result_user = users_get_user_by_id($id_user); diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 02eac5553c..c2fda51dfb 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -158,10 +158,11 @@ function show_response_dialog(event_id, response_id, response) { var params = []; params.push("page=include/ajax/events"); params.push("dialogue_event_response=1"); + params.push("massive=0"); params.push("event_id="+event_id); params.push("target="+response['target']); params.push("response_id="+response_id); - + jQuery.ajax ({ data: params.join ("&"), type: 'POST', @@ -187,6 +188,57 @@ function show_response_dialog(event_id, response_id, response) { }); } +//Show the modal window of event responses when multiple events are selected +function show_massive_response_dialog(event_id, response_id, response, out_iterator, end) { + var ajax_file = $('#hidden-ajax_file').val(); + + var params = []; + params.push("page=include/ajax/events"); + params.push("dialogue_event_response=1"); + params.push("massive=1"); + params.push("end="+end); + params.push("out_iterator="+out_iterator); + params.push("event_id="+event_id); + params.push("target="+response['target']); + params.push("response_id="+response_id); + + + jQuery.ajax ({ + data: params.join ("&"), + response_tg: response['target'], + response_id: response_id, + out_iterator: out_iterator, + type: 'POST', + url: action=ajax_file, + dataType: 'html', + success: function (data) { + if (out_iterator === 0) + $("#event_response_window").empty(); + + $("#event_response_window").hide () + .append (data) + .dialog ({ + title: $('#select_custom_response option:selected').html(), + resizable: true, + draggable: true, + modal: false, + open: function(event, ui) { + $('#response_loading_dialog').hide(); + $('#button-submit_event_response').show(); + }, + close: function(event, ui) { + $( ".chk_val" ).prop( "checked", false ); + }, + width: response['modal_width'], + height: response['modal_height'] + }) + .show (); + + perform_response_massive(this.response_tg, this.response_id, this.out_iterator); + } + }); +} + // Get an event response from db function get_response(response_id) { var ajax_file = $('#hidden-ajax_file').val(); @@ -371,6 +423,42 @@ function perform_response(target, response_id) { return false; } +// Perform a response and put the output into a div +function perform_response_massive(target, response_id, out_iterator) { + var ajax_file = $('#hidden-ajax_file').val(); + + $('#re_exec_command').hide(); + $('#response_loading_command_'+out_iterator).show(); + $('#response_out_'+out_iterator).html(''); + + var finished = 0; + var time = Math.round(+new Date()/1000); + var timeout = time + 10; + + var params = []; + params.push("page=include/ajax/events"); + params.push("perform_event_response=1"); + params.push("target="+target); + params.push("response_id="+response_id) + + jQuery.ajax ({ + data: params.join ("&"), + type: 'POST', + url: action=ajax_file, + async: true, + timeout: 10000, + dataType: 'html', + success: function (data) { + var out = data.replace(/[\n|\r]/g, "
"); + $('#response_out_'+out_iterator).html(out); + $('#response_loading_command_'+out_iterator).hide(); + $('#re_exec_command_'+out_iterator).show(); + } + }); + + return false; +} + // Change the status of an event to new, in process or validated function event_change_status(event_ids) { var ajax_file = $('#hidden-ajax_file').val(); diff --git a/pandora_console/index.php b/pandora_console/index.php index 10a471d295..ee11f1b54f 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -14,6 +14,17 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +// Enable profiler for testing +if (!defined("__PAN_XHPROF__")) define ("__PAN_XHPROF__", 0); + +if (__PAN_XHPROF__ === 1) { + if (function_exists('tideways_xhprof_enable')) { + tideways_xhprof_enable(); + } else { + error_log("Cannot find tideways_xhprof_enable function"); + } +} + //Set character encoding to UTF-8 - fixes a lot of multibyte character headaches if (function_exists ('mb_internal_encoding')) { mb_internal_encoding ("UTF-8"); @@ -1277,3 +1288,8 @@ require('include/php_to_js_values.php'); */ } + \ No newline at end of file diff --git a/pandora_console/install.php b/pandora_console/install.php index bb7ce75b46..a82dfc4ca6 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -116,7 +116,7 @@
"; - ui_toggle($filters, __('Show Options')); + ui_toggle($filters, __('Show Options'), '', false); } else { $table->colspan[3][0] = 7; @@ -778,84 +778,89 @@ $sql = 'SELECT ORDER BY ' . $order['field'] . " " . $order['order'] . ' LIMIT '.$offset.",".$limit_sql; -if (! defined ('METACONSOLE')) { - $result = db_get_all_rows_sql ($sql); - - if ($result === false) { - $result = array (); +// When you enter for the first time you have less than 4 query params in the url +$first_interaction = count($_GET) > 4; +// We do not show the modules until the user searches with the filter +if ($first_interaction) { + if (! defined ('METACONSOLE')) { + $result = db_get_all_rows_sql($sql); + + if ($result === false) { + $result = array(); + } else { + ui_pagination($count, false, $offset); + } } - else - ui_pagination ($count, false, $offset); -} -else { - // For each server defined and not disabled: - $servers = db_get_all_rows_sql ('SELECT * + else { + // For each server defined and not disabled: + $servers = db_get_all_rows_sql('SELECT * FROM tmetaconsole_setup WHERE disabled = 0'); - if ($servers === false) - $servers = array(); - - $result = array(); - $count_modules = 0; - foreach ($servers as $server) { + if ($servers === false) + $servers = array(); + + $result = array(); + $count_modules = 0; + foreach ($servers as $server) { // If connection was good then retrieve all data server - if (metaconsole_connect($server) == NOERR) - $connection = true; - else - $connection = false; - - $result_server = db_get_all_rows_sql ($sql); - - if (!empty($result_server)) { + if (metaconsole_connect($server) == NOERR) + $connection = true; + else + $connection = false; + + $result_server = db_get_all_rows_sql($sql); + + if (!empty($result_server)) { // Create HASH login info - $pwd = $server['auth_token']; - $auth_serialized = json_decode($pwd,true); - - if (is_array($auth_serialized)) { - $pwd = $auth_serialized['auth_token']; - $api_password = $auth_serialized['api_password']; - $console_user = $auth_serialized['console_user']; - $console_password = $auth_serialized['console_password']; - } - - $user = $config['id_user']; - $user_rot13 = str_rot13($config['id_user']); - $hashdata = $user.$pwd; - $hashdata = md5($hashdata); - $url_hash = '&' . - 'loginhash=auto&' . - 'loginhash_data=' . $hashdata . '&' . - 'loginhash_user=' . $user_rot13; - - foreach ($result_server as $result_element_key => $result_element_value) { - - $result_server[$result_element_key]['server_id'] = $server['id']; - $result_server[$result_element_key]['server_name'] = $server['server_name']; - $result_server[$result_element_key]['server_url'] = $server['server_url'].'/'; - $result_server[$result_element_key]['hashdata'] = $hashdata; - $result_server[$result_element_key]['user'] = $config['id_user']; - $result_server[$result_element_key]['groups_in_server'] = - agents_get_all_groups_agent( + $pwd = $server['auth_token']; + $auth_serialized = json_decode($pwd, true); + + if (is_array($auth_serialized)) { + $pwd = $auth_serialized['auth_token']; + $api_password = $auth_serialized['api_password']; + $console_user = $auth_serialized['console_user']; + $console_password = $auth_serialized['console_password']; + } + + $user = $config['id_user']; + $user_rot13 = str_rot13($config['id_user']); + $hashdata = $user . $pwd; + $hashdata = md5($hashdata); + $url_hash = '&' . + 'loginhash=auto&' . + 'loginhash_data=' . $hashdata . '&' . + 'loginhash_user=' . $user_rot13; + + foreach ($result_server as $result_element_key => $result_element_value) { + + $result_server[$result_element_key]['server_id'] = $server['id']; + $result_server[$result_element_key]['server_name'] = $server['server_name']; + $result_server[$result_element_key]['server_url'] = $server['server_url'] . '/'; + $result_server[$result_element_key]['hashdata'] = $hashdata; + $result_server[$result_element_key]['user'] = $config['id_user']; + $result_server[$result_element_key]['groups_in_server'] = + agents_get_all_groups_agent( $result_element_value['id_agent'], $result_element_value['id_group'] - ); - - $count_modules++; - + ); + + $count_modules++; + + } + + $result = array_merge($result, $result_server); } - - $result = array_merge($result, $result_server); + metaconsole_restore_db(); } - metaconsole_restore_db(); + + if ($count_modules > $config['block_size']) { + ui_pagination($count_modules, false, $offset); + } + + // Get number of elements of the pagination + $result = ui_meta_get_subset_array($result, $inferior_limit, $superior_limit); } - - if ($count_modules > $config['block_size']) { - ui_pagination ($count_modules, false, $offset); - } - - // Get number of elements of the pagination - $result = ui_meta_get_subset_array($result, $inferior_limit, $superior_limit); } if (($config['dbtype'] == 'oracle') && ($result !== false)) { @@ -1391,9 +1396,14 @@ if (!empty($result)) { } html_print_table ($table); + +} else { + if ($first_interaction) { + ui_print_info_message(array('no_close' => true, 'message' => __('This group doesn\'t have any monitor'))); + } else { + ui_print_info_message(array('no_close' => true, 'message' => __('Sorry no search parameters'))); + } } -else - ui_print_info_message ( array ( 'no_close' => true, 'message' => __('This group doesn\'t have any monitor') ) ); // End Build List Result ///////////////////////////////////// diff --git a/pandora_console/operation/events/events.build_table.php b/pandora_console/operation/events/events.build_table.php index 92b7eecad8..dab7d5439c 100644 --- a/pandora_console/operation/events/events.build_table.php +++ b/pandora_console/operation/events/events.build_table.php @@ -20,6 +20,8 @@ require_once ($config["homedir"] . "/include/functions_ui.php"); $sort_field = get_parameter("sort_field", "timestamp"); $sort = get_parameter("sort", "down"); +$response_id = get_parameter ("response_id", ""); + $table = new stdClass(); if(!isset($table->width)) { $table->width = '100%'; @@ -887,9 +889,8 @@ else { echo '
'; if (!$readonly && $show_validate_button) { - html_print_button(__('In progress selected'), 'validate_button', false, 'validate_selected(2);', 'class="sub ok"'); - echo " "; - html_print_button(__('Validate selected'), 'validate_button', false, 'validate_selected(1);', 'class="sub ok"'); + $array_events_actions['in_progress_selected'] = 'In progress selected'; + $array_events_actions['validate_selected'] = 'Validate selected'; // Fix: validated_selected JS function has to be included with the proper user ACLs ?> '; echo ''; + + $sql_event_resp = "SELECT id, name FROM tevent_response WHERE type LIKE 'command'"; + $event_responses = db_get_all_rows_sql ($sql_event_resp); + + foreach ($event_responses as $val) + $array_events_actions[$val['id']] = $val['name']; + + if ($config['event_replication'] != 1) { + echo '
'; + echo '
'; + html_print_select($array_events_actions, 'response_id', '', '', '', 0, false, false, false); + echo '  '; + html_print_button(__('Execute event response'), 'submit_event_response', false, 'execute_event_response(true);', 'class="sub next"'); + echo ""; + echo '
'; + echo ''; + echo '
'; + } } + + ?> + + ' . __('No events') . '
'; } echo '
'; } -?> +?> \ No newline at end of file diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index ad692695ae..5f76201864 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -559,6 +559,18 @@ if ($validate) { if ($delete) { $ids = (array) get_parameter ("validate_ids", -1); + // Discard deleting in progress events + $in_process_status = db_get_all_rows_sql(" + SELECT id_evento + FROM tevento + WHERE estado=2"); + + foreach ($in_process_status as $val) { + if (($key = array_search($val['id_evento'], $ids)) !== false) { + unset($ids[$key]); + } + } + if ($ids[0] != -1) { $return = events_delete_event ($ids, ($group_rep == 1), $meta); ui_print_result_message ($return, diff --git a/pandora_console/pandora_console.redhat.spec b/pandora_console/pandora_console.redhat.spec index cf32f238ae..f3cd5523e4 100644 --- a/pandora_console/pandora_console.redhat.spec +++ b/pandora_console/pandora_console.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_console %define version 7.0NG.730 -%define release 190111 +%define release 190116 # User and Group under which Apache is running %define httpd_name httpd diff --git a/pandora_console/pandora_console.spec b/pandora_console/pandora_console.spec index d514072e20..b05edc5e78 100644 --- a/pandora_console/pandora_console.spec +++ b/pandora_console/pandora_console.spec @@ -3,7 +3,7 @@ # %define name pandorafms_console %define version 7.0NG.730 -%define release 190111 +%define release 190116 %define httpd_name httpd # User and Group under which Apache is running %define httpd_name apache2 diff --git a/pandora_server/DEBIAN/control b/pandora_server/DEBIAN/control index 29d38ee28c..674c0d718a 100644 --- a/pandora_server/DEBIAN/control +++ b/pandora_server/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-server -Version: 7.0NG.730-190111 +Version: 7.0NG.730-190116 Architecture: all Priority: optional Section: admin diff --git a/pandora_server/DEBIAN/make_deb_package.sh b/pandora_server/DEBIAN/make_deb_package.sh index c85854c799..a5f005088e 100644 --- a/pandora_server/DEBIAN/make_deb_package.sh +++ b/pandora_server/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.730-190111" +pandora_version="7.0NG.730-190116" package_cpan=0 package_pandora=1 diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 4ca092b1cf..6c90dba2dc 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -45,7 +45,7 @@ our @EXPORT = qw( # version: Defines actual version of Pandora Server for this module only my $pandora_version = "7.0NG.730"; -my $pandora_build = "190111"; +my $pandora_build = "190116"; our $VERSION = $pandora_version." ".$pandora_build; # Setup hash diff --git a/pandora_server/lib/PandoraFMS/PluginTools.pm b/pandora_server/lib/PandoraFMS/PluginTools.pm index bc4842b4b3..5f91cc4b0d 100644 --- a/pandora_server/lib/PandoraFMS/PluginTools.pm +++ b/pandora_server/lib/PandoraFMS/PluginTools.pm @@ -32,7 +32,7 @@ our @ISA = qw(Exporter); # version: Defines actual version of Pandora Server for this module only my $pandora_version = "7.0NG.730"; -my $pandora_build = "190111"; +my $pandora_build = "190116"; our $VERSION = $pandora_version." ".$pandora_build; our %EXPORT_TAGS = ( 'all' => [ qw() ] ); diff --git a/pandora_server/pandora_server.redhat.spec b/pandora_server/pandora_server.redhat.spec index 250d45ae40..87903a3efb 100644 --- a/pandora_server/pandora_server.redhat.spec +++ b/pandora_server/pandora_server.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_server %define version 7.0NG.730 -%define release 190111 +%define release 190116 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index a86f26050b..1f46908e02 100644 --- a/pandora_server/pandora_server.spec +++ b/pandora_server/pandora_server.spec @@ -3,7 +3,7 @@ # %define name pandorafms_server %define version 7.0NG.730 -%define release 190111 +%define release 190116 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index 04a349843c..636984f6b0 100755 --- a/pandora_server/pandora_server_installer +++ b/pandora_server/pandora_server_installer @@ -9,7 +9,7 @@ # ********************************************************************** PI_VERSION="7.0NG.730" -PI_BUILD="190111" +PI_BUILD="190116" MODE=$1 if [ $# -gt 1 ]; then diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 71c18dbf30..da655fa933 100644 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -34,7 +34,7 @@ use PandoraFMS::Config; use PandoraFMS::DB; # version: define current version -my $version = "7.0NG.730 PS190111"; +my $version = "7.0NG.730 PS190116"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 031dba98a7..85e8ce85f6 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -36,7 +36,7 @@ use Encode::Locale; Encode::Locale::decode_argv; # version: define current version -my $version = "7.0NG.730 PS190111"; +my $version = "7.0NG.730 PS190116"; # save program name for logging my $progname = basename($0); @@ -195,6 +195,7 @@ sub help_screen{ help_screen_line('--apply_policy', '', 'Force apply a policy'); help_screen_line('--apply_all_policies', '', 'Force apply to all the policies'); help_screen_line('--add_agent_to_policy', ' ', 'Add an agent to a policy'); + help_screen_line('--remove_agent_from_policy', ' ', 'Delete an agent to a policy'); help_screen_line('--delete_not_policy_modules', '', 'Delete all modules without policy from configuration file'); help_screen_line('--disable_policy_alerts', '', 'Disable all the alerts of a policy'); help_screen_line('--create_policy', ' '); @@ -4101,6 +4102,19 @@ sub cli_policy_add_agent() { } } +############################################################################## +# delete an agent to a policy +# Related option: --remove_agent_from_policy +############################################################################## + +sub cli_policy_delete_agent() { + my ($policy_id, $agent_id) = @ARGV[2..3]; + + my $result = api_call(\%conf,'set', 'remove_agent_from_policy', $policy_id, $agent_id); + print "$result \n\n "; + +} + sub cli_create_planned_downtime() { my $name = @ARGV[2]; my @todo = @ARGV[3..21]; @@ -5836,6 +5850,10 @@ sub pandora_manage_main ($$$) { param_check($ltotal, 2); cli_policy_add_agent(); } + elsif ($param eq '--remove_agent_from_policy') { + param_check($ltotal, 2); + cli_policy_delete_agent(); + } elsif ($param eq '--enable_user') { param_check($ltotal, 1); cli_user_enable();