diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index c902a6479a..0d9dbda151 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -64,7 +64,8 @@ $add_comment = (bool) get_parameter('add_comment'); $dialogue_event_response = (bool) get_parameter('dialogue_event_response'); $perform_event_response = (bool) get_parameter('perform_event_response'); $get_response = (bool) get_parameter('get_response'); -$get_response_target = (bool) get_parameter('get_response_target'); +$get_response_massive = (bool) get_parameter('get_response_massive'); +$get_row_response_action = (bool) get_parameter('get_row_response_action'); $get_response_params = (bool) get_parameter('get_response_params'); $get_response_description = (bool) get_parameter('get_response_description'); $meta = get_parameter('meta', 0); @@ -1090,50 +1091,6 @@ if ($get_response_params) { return; } -if ($get_response_target === true) { - if (! check_acl($config['id_user'], 0, 'EW')) { - echo 'unauthorized'; - return; - } - - $response_id = (int) get_parameter('response_id'); - $event_id = (int) get_parameter('event_id'); - $server_id = (int) get_parameter('server_id'); - - try { - if (is_metaconsole() === true - && $server_id > 0 - ) { - $node = new Node($server_id); - $node->connect(); - } - - $event_response = db_get_row('tevent_response', 'id', $response_id); - - if (empty($event_response) === true) { - return; - } - - echo events_get_response_target($event_id, $response_id); - } catch (\Exception $e) { - // Unexistent agent. - if (is_metaconsole() === true - && $server_id > 0 - ) { - $node->disconnect(); - } - - return; - } finally { - if (is_metaconsole() === true - && $server_id > 0 - ) { - $node->disconnect(); - } - } - - return; -} if ($get_response === true) { if (! check_acl($config['id_user'], 0, 'EW')) { @@ -1142,62 +1099,21 @@ if ($get_response === true) { } $response_id = get_parameter('response_id'); - $server_id = (int) get_parameter('server_id'); + $server_id = (int) get_parameter('server_id', 0); + $event_id = (int) get_parameter('event_id', 0); - try { - if (is_metaconsole() === true - && $server_id > 0 - ) { - $node = new Node($server_id); - $node->connect(); - } - - $event_response = db_get_row( - 'tevent_response', - 'id', - $response_id - ); - } catch (\Exception $e) { - // Unexistent agent. - if (is_metaconsole() === true - && $server_id > 0 - ) { - $node->disconnect(); - } - - return; - } finally { - if (is_metaconsole() === true - && $server_id > 0 - ) { - $node->disconnect(); - } - } + $event_response = db_get_row( + 'tevent_response', + 'id', + $response_id + ); if (empty($event_response) === true) { - return; + return []; } - echo json_encode($event_response); - return; -} - -if ($perform_event_response === true) { - global $config; - - if (! check_acl($config['id_user'], 0, 'EW')) { - echo 'unauthorized'; - return; - } - - $target = get_parameter('target', ''); - $response_id = get_parameter('response_id'); - $event_id = (int) get_parameter('event_id'); - $server_id = (int) get_parameter('server_id', 0); - - $event_response = false; - if (empty($target) === true) { + if (empty($event_id) === false) { try { if (is_metaconsole() === true && $server_id > 0 @@ -1206,20 +1122,9 @@ if ($perform_event_response === true) { $node->connect(); } - $event_response = db_get_row( - 'tevent_response', - 'id', - $response_id - ); - - if (empty($event_response) === true) { - return; - } - - $command = events_get_response_target( + $event_response['target'] = events_get_response_target( $event_id, - $response_id, - $server_id + $event_response ); } catch (\Exception $e) { // Unexistent agent. @@ -1237,10 +1142,121 @@ if ($perform_event_response === true) { $node->disconnect(); } } - } else { - $command = $target; } + echo json_encode($event_response); + + return; +} + + +if ($get_response_massive === true) { + if (! check_acl($config['id_user'], 0, 'EW')) { + echo 'unauthorized'; + return; + } + + $response_id = get_parameter('response_id'); + + $event_response = db_get_row( + 'tevent_response', + 'id', + $response_id + ); + + if (empty($event_response) === true) { + return []; + } + + + $events = json_decode( + io_safe_output( + get_parameter('events', '') + ), + true + ); + + $event_response_targets = []; + if (is_metaconsole() === true) { + foreach ($events as $server_id => $idEvents) { + foreach ($idEvents as $idEvent) { + $event_response_targets[$idEvent.'|'.$server_id]['target'] = get_events_get_response_target( + $idEvent, + $event_response, + $server_id + ); + } + } + } else { + foreach ($idEvents as $idEvent) { + $event_response_targets[$idEvent]['target'] = get_events_get_response_target( + $idEvent, + $event_response + ); + } + } + + $result = [ + 'event_response' => $event_response, + 'event_response_targets' => $event_response_targets, + ]; + + echo json_encode($result); + + return; +} + +if ($get_row_response_action === true) { + $response_id = get_parameter('response_id'); + $response = json_decode( + io_safe_output( + get_parameter('response', '') + ), + true + ); + + $end = (bool) get_parameter('end', false); + $index = $response['event_id']; + if (is_metaconsole() === true) { + $index .= '-'.$response['server_id']; + } + + echo get_row_response_action( + $response, + $response_id, + $end, + $index + ); + + return; +} + +if ($perform_event_response === true) { + global $config; + + if (! check_acl($config['id_user'], 0, 'EW')) { + echo __('unauthorized'); + return; + } + + $target = get_parameter('target', ''); + $response_id = get_parameter('response_id'); + $event_id = (int) get_parameter('event_id'); + $server_id = (int) get_parameter('server_id', 0); + $response = json_decode( + io_safe_output( + get_parameter('response', '') + ), + true + ); + + $event_response = $response; + if (empty($event_response) === true) { + echo __('No data'); + return; + } + + $command = $event_response['target']; $command_timeout = ($event_response !== false) ? $event_response['command_timeout'] : 90; if (enterprise_installed() === true) { if ($event_response !== false @@ -1320,7 +1336,7 @@ if ($perform_event_response === true) { break; } - system($timeout_bin.' '.$command_timeout.' '.io_safe_output($command).' 2>&1', $ret_val); + system($timeout_bin.' '.$command_timeout.' '.io_safe_output($command).' 2>&1', $ret_val); } if ($ret_val != 0) { @@ -1343,78 +1359,19 @@ 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); - $server_id = get_parameter('server_id'); + $event_response = json_decode( + io_safe_output( + get_parameter('response', '') + ), + true + ); - $event = db_get_row('tevento', 'id_evento', $event_id); - - $prompt = '
> '; switch ($event_response['type']) { case 'command': - $display_command = (bool) $event_response['display_command']; - $command_str = ($display_command === true) ? $command : ''; - - if ($massive) { - echo "
"; - echo $prompt.sprintf( - '(Event #'.$event_id.') '.__( - 'Executing command: %s', - $command_str - ) - ); - echo '

'; - - echo "
'; - echo "



"; - - if ($end) { - echo "
'; - } - } else { - echo "
"; - - echo $prompt.'Executing command: '.$command_str; - echo '

'; - - echo "'; - echo "


"; - - echo "
'; - } + echo get_row_response_action( + $event_response, + $response_id + ); break; case 'url': diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index c36536348f..5537a7b521 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -3430,7 +3430,7 @@ function events_page_responses($event) __('Execute'), 'custom_response_button', false, - 'execute_response('.$event['id_evento'].','.$server_id.')', + 'execute_response('.$event['id_evento'].','.$server_id.',0)', "class='sub next w70p'", true ); @@ -3438,6 +3438,7 @@ function events_page_responses($event) $table_responses->data[] = $data; + // TODO quitar el async: false. get_response_params and get_response_description. $responses_js = "