From d89e3993e719e9778dbde48a315bcdad9e8ad880 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 4 Mar 2019 20:02:35 +0100 Subject: [PATCH] WIP first tasks Former-commit-id: 4fbdab2389d5727c44693b129baa4ceadc6934ae --- pandora_console/general/logon_ok.php | 191 +++++++++++------- .../include/class/ConsoleSupervisor.php | 2 +- .../include/functions_messages.php | 50 +++++ .../operation/messages/message_edit.php | 27 +-- 4 files changed, 170 insertions(+), 100 deletions(-) diff --git a/pandora_console/general/logon_ok.php b/pandora_console/general/logon_ok.php index d0e2070583..e30d82aecc 100644 --- a/pandora_console/general/logon_ok.php +++ b/pandora_console/general/logon_ok.php @@ -1,26 +1,39 @@ @@ -88,7 +113,7 @@ if (!empty($all_data)) { class = 'databox'; @@ -101,12 +126,12 @@ if (!empty($all_data)) { $table->head[0] = ''.__('%s Overview', get_product_name()).''; $table->head_colspan[0] = 4; - // Indicators + // Indicators. $tdata = []; $stats = reporting_get_stats_indicators($data, 120, 10, false); $status = '
'; foreach ($stats as $stat) { - $status .= ''; + $status .= ''; } $status .= '
'.$stat['title'].''.''.$stat['graph'].'
'.$stat['title'].''.$stat['graph'].'
'; @@ -115,25 +140,25 @@ if (!empty($all_data)) { $table->data[] = $tdata; - // Alerts + // Alerts. $tdata = []; $tdata[0] = reporting_get_stats_alerts($data); $table->rowclass[] = ''; $table->data[] = $tdata; - // Modules by status + // Modules by status. $tdata = []; $tdata[0] = reporting_get_stats_modules_status($data, 180, 100); $table->rowclass[] = ''; $table->data[] = $tdata; - // Total agents and modules + // Total agents and modules. $tdata = []; $tdata[0] = reporting_get_stats_agents_monitors($data); $table->rowclass[] = ''; $table->data[] = $tdata; - // Users + // Users. if (users_is_admin()) { $tdata = []; $tdata[0] = reporting_get_stats_users($data); @@ -160,7 +185,7 @@ if (!empty($all_data)) { if (!empty($news)) { - // NEWS BOARD///////////////////////////// + // NEWS BOARD. echo '
'; echo ''; @@ -184,20 +209,72 @@ if (!empty($all_data)) { echo '
'; echo '
'; - // News board + // News board. echo '

'; - // END OF NEWS BOARD///////////////////////////// + // END OF NEWS BOARD. } - // LAST ACTIVITY///////////////////////////// - // Show last activity from this user + $nots = messages_get_overview('utimestamp', 'DESC', false); + if (!empty($nots)) { + // Notifications board. + echo '
'; + + echo ''; + echo ''; + if ($config['prominent_time'] == 'timestamp') { + $comparation_suffix = ''; + } else { + $comparation_suffix = __('ago'); + } + + foreach ($nots as $msg) { + $conversation = io_safe_output( + messages_get_conversation($msg) + ); + + if (is_array($conversation)) { + $text = array_pop($conversation)['message']; + } else { + // Skip empty message. + continue; + } + + $url = ui_get_full_url( + 'index.php?sec=message_list&sec2=operation/messages/message_edit&read_message=1&id_message='.$msg['id_mensaje'] + ); + if ($msg['url'] != '') { + $url = $msg['url']; + } + + echo ''; + echo ''; + echo ''; + } + + echo '
'.__('Pending notifications').'
'.$msg['subject'].'
'; + if ($msg['id_usuario_origen'] != '') { + echo ''.get_user_fullname($msg['id_usuario_origen']).' '; + } + + echo ''.ui_print_timestamp($msg['timestamp'], true).' '.$comparation_suffix.'
'; + echo nl2br($text); + echo '
'; + echo '
'; + + echo '

'; + + // EO Notifications board. + } + + // LAST ACTIVITY. + // Show last activity from this user. echo '
'; $table = new stdClass(); $table->class = 'databox data'; $table->width = '100%'; - // Don't specify px + // Don't specify px. $table->data = []; $table->size = []; $table->size[0] = '5%'; @@ -212,38 +289,14 @@ if (!empty($all_data)) { $table->head[3] = __('Source IP'); $table->head[4] = __('Comments'); $table->title = ''.__('This is your last activity performed on the %s console', get_product_name()).''; - - switch ($config['dbtype']) { - case 'mysql': - $sql = sprintf( - 'SELECT id_usuario,accion, ip_origen,descripcion,utimestamp + $sql = sprintf( + 'SELECT id_usuario,accion, ip_origen,descripcion,utimestamp FROM tsesion WHERE (`utimestamp` > UNIX_TIMESTAMP(NOW()) - '.SECONDS_1WEEK.") AND `id_usuario` = '%s' ORDER BY `utimestamp` DESC LIMIT 10", - $config['id_user'] - ); - break; + $config['id_user'] + ); - case 'postgresql': - $sql = sprintf( - "SELECT \"id_usuario\", accion, \"ip_origen\", descripcion, utimestamp - FROM tsesion - WHERE (\"utimestamp\" > ceil(date_part('epoch', CURRENT_TIMESTAMP)) - ".SECONDS_1WEEK.") - AND \"id_usuario\" = '%s' ORDER BY \"utimestamp\" DESC LIMIT 10", - $config['id_user'] - ); - break; - - case 'oracle': - $sql = sprintf( - "SELECT id_usuario, accion, ip_origen, descripcion, utimestamp - FROM tsesion - WHERE ((utimestamp > ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (".SECONDS_1DAY.')) - '.SECONDS_1WEEK.") - AND id_usuario = '%s') AND rownum <= 10 ORDER BY utimestamp DESC", - $config['id_user'] - ); - break; - } $sessions = db_get_all_rows_sql($sql); @@ -253,24 +306,17 @@ if (!empty($all_data)) { foreach ($sessions as $session) { $data = []; + $session_id_usuario = $session['id_usuario']; + $session_ip_origen = $session['ip_origen']; - switch ($config['dbtype']) { - case 'mysql': - case 'oracle': - $session_id_usuario = $session['id_usuario']; - $session_ip_origen = $session['ip_origen']; - break; - - case 'postgresql': - $session_id_usuario = $session['id_usuario']; - $session_ip_origen = $session['ip_origen']; - break; - } $data[0] = ''.$session_id_usuario.''; $data[1] = ui_print_session_action_icon($session['accion'], true).' '.$session['accion']; - $data[2] = ui_print_help_tip(date($config['date_format'], $session['utimestamp']), true).human_time_comparation($session['utimestamp'], 'tiny'); + $data[2] = ui_print_help_tip( + date($config['date_format'], $session['utimestamp']), + true + ).human_time_comparation($session['utimestamp'], 'tiny'); $data[3] = $session_ip_origen; $description = str_replace([',', ', '], ', ', $session['descripcion']); if (strlen($description) > 100) { @@ -287,8 +333,7 @@ if (!empty($all_data)) { unset($table); echo '
'; echo ''; - // activity - // END OF LAST ACTIVIYY///////////////////////////// + // END OF LAST ACTIVIYY. ?> diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 00f631dbd8..107b13e5c7 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -2115,7 +2115,7 @@ class ConsoleSupervisor if ($config['cron_last_run'] == 0 || (get_system_time() - $config['cron_last_run']) > 3600 ) { - $message_conf_cron = __('DiscoveryConsoleTasks is not running properly'); + $message_conf_cron = __('DiscoveryConsoleTasks is not running properly.').' '; if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') { $message_conf_cron .= __('Discovery relies on a proper setup of cron, the time-based scheduling service'); $message_conf_cron .= '. '.__('Please, add the following line to your crontab file:'); diff --git a/pandora_console/include/functions_messages.php b/pandora_console/include/functions_messages.php index 5374fb7b1e..35066129bc 100644 --- a/pandora_console/include/functions_messages.php +++ b/pandora_console/include/functions_messages.php @@ -582,6 +582,56 @@ function messages_get_overview_sent( } +/** + * Get a message interpreted as a conversation. + * + * @param mixed $data Complete message or message id. + * + * @return mixed False if fails. A string array with the conversation. + */ +function messages_get_conversation($data) +{ + if (is_array($data)) { + $message = $data; + } else { + $message = messages_get_message($data); + } + + if (!isset($message) || !is_array($message)) { + return []; + } + + $conversation = []; + $target_str = $message['mensaje']; + + while (preg_match_all( + '/(.*)On(.*)wrote:(.*)/', + $target_str, + $decoded, + PREG_PATTERN_ORDER + ) !== false && empty($target_str) !== true) { + if (empty($decoded[2]) !== true) { + array_push( + $conversation, + [ + 'message' => array_pop($decoded)[0], + 'date' => array_pop($decoded)[0], + ] + ); + } else { + array_push( + $conversation, + ['message' => $target_str] + ); + } + + $target_str = $decoded[1][0]; + } + + return $conversation; +} + + /** * Get the URL of a message. If field in db is null, it returs a link to * messages view. diff --git a/pandora_console/operation/messages/message_edit.php b/pandora_console/operation/messages/message_edit.php index f116e6609d..039222436e 100644 --- a/pandora_console/operation/messages/message_edit.php +++ b/pandora_console/operation/messages/message_edit.php @@ -114,32 +114,7 @@ if ($read_message) { echo '

Subject: '.$message['subject'].'

'; - $conversation = []; - $target_str = $message['mensaje']; - - while (preg_match_all( - '/(.*)On(.*)wrote:(.*)/', - $target_str, - $decoded, - PREG_PATTERN_ORDER - ) !== false && empty($target_str) !== true) { - if (empty($decoded[2]) !== true) { - array_push( - $conversation, - [ - 'message' => array_pop($decoded)[0], - 'date' => array_pop($decoded)[0], - ] - ); - } else { - array_push( - $conversation, - ['message' => $target_str] - ); - } - - $target_str = $decoded[1][0]; - } + $conversation = messages_get_conversation($message); ui_require_css_file('message_edit'); foreach ($conversation as $row) {