From 1f16abd4bdb85daba1f2e9f4340769590b0b4528 Mon Sep 17 00:00:00 2001 From: Tatiana Llorente Date: Fri, 8 May 2020 15:39:24 +0200 Subject: [PATCH] Ent 5701 quitar feature de chat --- .../extras/delete_files/delete_files.txt | 7 +- pandora_console/general/header.php | 15 +- pandora_console/godmode/users/user_list.php | 2 - pandora_console/include/functions_ui.php | 2 - pandora_console/include/functions_users.php | 594 ------------------ pandora_console/include/javascript/webchat.js | 47 -- pandora_console/index.php | 51 -- pandora_console/operation/menu.php | 6 - pandora_console/operation/users/webchat.php | 345 ---------- 9 files changed, 8 insertions(+), 1061 deletions(-) delete mode 100644 pandora_console/include/javascript/webchat.js delete mode 100644 pandora_console/operation/users/webchat.php diff --git a/pandora_console/extras/delete_files/delete_files.txt b/pandora_console/extras/delete_files/delete_files.txt index c0d8f0a9db..b18abb678d 100644 --- a/pandora_console/extras/delete_files/delete_files.txt +++ b/pandora_console/extras/delete_files/delete_files.txt @@ -1 +1,6 @@ -operation/servers/recon_view.php \ No newline at end of file +operation/servers/recon_view.php +operation/users/webchat.php +include/javascript/webchat.js +attachment/pandora_chat.log.json.txt +attachment/pandora_chat.user_list.json.txt +attachment/pandora_chat.global_counter.txt \ No newline at end of file diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index b443926a63..8aa11ea4d9 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -81,13 +81,6 @@ if ($config['menu_type'] == 'classic') { } - // Chat messages. - $header_chat = "
'; - - // Search. $acl_head_search = true; if ($config['acl_enterprise'] == 1 && !users_is_admin()) { @@ -417,7 +410,7 @@ if ($config['menu_type'] == 'classic') { echo '
'.$config['custom_title_header'].''.$config['custom_subtitle_header'].'
'.$header_searchbar.'
-
'.$header_chat, $header_autorefresh, $header_autorefresh_counter, $header_discovery, $servers_list, $header_feedback, $header_support, $header_docu, $header_user, $header_logout.'
'; +
'.$header_autorefresh, $header_autorefresh_counter, $header_discovery, $servers_list, $header_feedback, $header_support, $header_docu, $header_user, $header_logout.'
'; ?> @@ -640,8 +633,6 @@ if ($config['menu_type'] == 'classic') { var fixed_header = ; - var new_chat = ; - function showinterpreter(){ document.onclick = function(e) { @@ -789,9 +780,7 @@ if ($config['menu_type'] == 'classic') { $('div#head').addClass('fixed_header'); $('div#main').css('padding-top', $('div#head').innerHeight() + 'px'); } - - check_new_chats_icon('icon_new_messages_chat'); - + /* Temporal fix to hide graphics when ui_dialog are displayed */ $("#yougotalert").click(function () { $("#agent_access").css("display", "none"); diff --git a/pandora_console/godmode/users/user_list.php b/pandora_console/godmode/users/user_list.php index d106f5010a..8fb461a355 100644 --- a/pandora_console/godmode/users/user_list.php +++ b/pandora_console/godmode/users/user_list.php @@ -160,8 +160,6 @@ if (isset($_GET['user_del'])) { $result = delete_user($id_user); if ($result) { - users_save_logout($user_row, true); - db_pandora_audit( 'User management', __('Deleted user %s', io_safe_input($id_user)) diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 0ce95daf78..5926766685 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -1908,8 +1908,6 @@ function ui_process_page_head($string, $bitfield) ); // Load base64 javascript library. $config['js']['base64'] = 'include/javascript/encode_decode_base64.js'; - // Load webchat javascript library. - $config['js']['webchat'] = 'include/javascript/webchat.js'; // Load qrcode library. $config['js']['qrcode'] = 'include/javascript/qrcode.js'; // Load intro.js library (for bubbles and clippy). diff --git a/pandora_console/include/functions_users.php b/pandora_console/include/functions_users.php index 86e4475eea..af0616a610 100755 --- a/pandora_console/include/functions_users.php +++ b/pandora_console/include/functions_users.php @@ -497,508 +497,6 @@ function users_get_user_by_id($id_user) } -define('MAX_TIMES', 10); - -// -// WEBCHAT FUNCTIONS///////////////////////////////// -// -function users_get_last_messages($last_time=false) -{ - $file_global_counter_chat = $config['attachment_store'].'/pandora_chat.global_counter.txt'; - - // First lock the file - $fp_global_counter = @fopen($file_global_counter_chat, 'a+'); - if ($fp_global_counter === false) { - echo json_encode($return); - - return; - } - - // Try to look MAX_TIMES times - $tries = 0; - while (!flock($fp_global_counter, LOCK_EX)) { - $tries++; - if ($tries > MAX_TIMES) { - echo json_encode($return); - - return; - } - - sleep(1); - } - - fscanf($fp_global_counter, '%d', $global_counter_file); - if (empty($global_counter_file)) { - $global_counter_file = 0; - } - - $timestamp = time(); - if ($last_time === false) { - $last_time = (24 * 60 * 60); - } - - $from = ($timestamp - $last_time); - - $log_chat_file = $config['attachment_store'].'/pandora_chat.log.json.txt'; - - $return = [ - 'correct' => false, - 'log' => [], - ]; - - if (!file_exists($log_chat_file)) { - touch($log_chat_file); - } - - $text_encode = @file_get_contents($log_chat_file); - $log = json_decode($text_encode, true); - - if ($log !== false) { - if ($log === null) { - $log = []; - } - - $log_last_time = []; - foreach ($log as $message) { - if ($message['timestamp'] >= $from) { - $log_last_time[] = $message; - } - } - - $return['correct'] = true; - $return['log'] = $log_last_time; - $return['global_counter'] = $global_counter_file; - } - - echo json_encode($return); - - fclose($fp_global_counter); - - return; -} - - -function users_save_login() -{ - global $config; - - $file_global_user_list = $config['attachment_store'].'/pandora_chat.user_list.json.txt'; - - $user = db_get_row_filter( - 'tusuario', - ['id_user' => $config['id_user']] - ); - - $message = sprintf( - __('User %s login at %s'), - $user['fullname'], - date($config['date_format']) - ); - users_save_text_message($message, 'notification'); - - // First lock the file - $fp_user_list = @fopen($file_global_user_list, 'a+'); - if ($fp_user_list === false) { - return; - } - - // Try to look MAX_TIMES times - $tries = 0; - while (!flock($fp_user_list, LOCK_EX)) { - $tries++; - if ($tries > MAX_TIMES) { - return; - } - - sleep(1); - } - - @fscanf($fp_user_list, "%[^\n]", $user_list_json); - - $user_list = json_decode($user_list_json, true); - if (empty($user_list)) { - $user_list[$config['id_user']] = [ - 'name' => $user['fullname'], - 'count' => 1, - ]; - } else if (isset($user_list[$config['id_user']])) { - $user_list[$config['id_user']] = [ - 'name' => $user['fullname'], - 'count' => $user_list[$config['id_user']]['count'], - ]; - } else { - $users_count = count($user_list); - $user_list[$config['id_user']] = [ - 'name' => $user['fullname'], - 'count' => ++$users_count, - ]; - } - - // Clean the file - ftruncate($fp_user_list, 0); - - $status = fwrite($fp_user_list, json_encode($user_list)); - - if ($status === false) { - fclose($fp_user_list); - - return; - } - - fclose($fp_user_list); -} - - -function users_save_logout($user=false, $delete=false) -{ - global $config; - - $return = [ - 'correct' => false, - 'users' => [], - ]; - - $file_global_user_list = $config['attachment_store'].'/pandora_chat.user_list.json.txt'; - - if (empty($user)) { - $user = db_get_row_filter( - 'tusuario', - ['id_user' => $config['id_user']] - ); - } - - if ($delete) { - $no_json_output = true; - $message = sprintf( - __('User %s was deleted in the DB at %s'), - $user['fullname'], - date($config['date_format']) - ); - } else { - $no_json_output = false; - $message = sprintf( - __('User %s logout at %s'), - $user['fullname'], - date($config['date_format']) - ); - } - - users_save_text_message($message, 'notification', $no_json_output); - - // First lock the file - $fp_user_list = @fopen($file_global_user_list, 'a+'); - if ($fp_user_list === false) { - return; - } - - // Try to look MAX_TIMES times - $tries = 0; - while (!flock($fp_user_list, LOCK_EX)) { - $tries++; - if ($tries > MAX_TIMES) { - return; - } - - sleep(1); - } - - @fscanf($fp_user_list, "%[^\n]", $user_list_json); - - $user_list = json_decode($user_list_json, true); - if (empty($user_list)) { - $user_list = []; - } - - unset($user_list[$user['id_user']]); - - // Clean the file - ftruncate($fp_user_list, 0); - - $status = fwrite($fp_user_list, json_encode($user_list)); - - if ($status === false) { - fclose($fp_user_list); - - return; - } - - fclose($fp_user_list); -} - - -function users_save_text_message($message=false, $type='message', $no_json_output=false) -{ - global $config; - - $file_global_counter_chat = $config['attachment_store'].'/pandora_chat.global_counter.txt'; - $log_chat_file = $config['attachment_store'].'/pandora_chat.log.json.txt'; - - $return = ['correct' => false]; - - $id_user = $config['id_user']; - $user = db_get_row_filter( - 'tusuario', - ['id_user' => $id_user] - ); - - $message_data = []; - $message_data['type'] = $type; - $message_data['id_user'] = $id_user; - $message_data['user_name'] = $user['fullname']; - $message_data['text'] = io_safe_input_html($message); - // The $message_data['timestamp'] set when adquire the files to save. - // First lock the file - $fp_global_counter = @fopen($file_global_counter_chat, 'a+'); - if ($fp_global_counter === false) { - if (!$no_json_output) { - echo json_encode($return); - } - - return; - } - - // Try to look MAX_TIMES times - $tries = 0; - while (!flock($fp_global_counter, LOCK_EX)) { - $tries++; - if ($tries > MAX_TIMES) { - if (!$no_json_output) { - echo json_encode($return); - } - - return; - } - - sleep(1); - } - - @fscanf($fp_global_counter, '%d', $global_counter_file); - if (empty($global_counter_file)) { - $global_counter_file = 0; - } - - // Clean the file - ftruncate($fp_global_counter, 0); - - $message_data['timestamp'] = time(); - $message_data['human_time'] = date($config['date_format'], $message_data['timestamp']); - - $global_counter = ($global_counter_file + 1); - - $status = fwrite($fp_global_counter, $global_counter); - - if ($status === false) { - fclose($fp_global_counter); - - if (!$no_json_output) { - echo json_encode($return); - } - - return; - } else { - $text_encode = @file_get_contents($log_chat_file); - $log = json_decode($text_encode, true); - $log[$global_counter] = $message_data; - $status = file_put_contents($log_chat_file, json_encode($log)); - - fclose($fp_global_counter); - - $return['correct'] = true; - if (!$no_json_output) { - echo json_encode($return); - } - } - - return; -} - - -function users_long_polling_check_messages($global_counter) -{ - global $config; - - $file_global_counter_chat = $config['attachment_store'].'/pandora_chat.global_counter.txt'; - $log_chat_file = $config['attachment_store'].'/pandora_chat.log.json.txt'; - - $changes = false; - - $tries_general = 0; - - $error = false; - - while (!$changes) { - // First lock the file - $fp_global_counter = @fopen($file_global_counter_chat, 'a+'); - if ($fp_global_counter) { - // Try to look MAX_TIMES times - $tries = 0; - $lock = true; - while (!flock($fp_global_counter, LOCK_EX)) { - $tries++; - if ($tries > MAX_TIMES) { - $lock = false; - $error = true; - break; - } - - sleep(1); - } - - if ($lock) { - @fscanf($fp_global_counter, '%d', $global_counter_file); - if (empty($global_counter_file)) { - $global_counter_file = 0; - } - - if ($global_counter_file > $global_counter) { - // TODO Optimize slice the array. - $text_encode = @file_get_contents($log_chat_file); - $log = json_decode($text_encode, true); - - $return_log = []; - foreach ($log as $key => $message) { - if ($key <= $global_counter) { - continue; - } - - $return_log[] = $message; - } - - $return = [ - 'correct' => true, - 'global_counter' => $global_counter_file, - 'log' => $return_log, - ]; - - echo json_encode($return); - - fclose($fp_global_counter); - - return; - } - } - - fclose($fp_global_counter); - } - - sleep(3); - $tries_general = ($tries_general + 3); - - if ($tries_general > MAX_TIMES) { - break; - } - } - - // Because maybe the exit of loop for exaust. - echo json_encode(['correct' => false, 'error' => $error]); - - return; -} - - -/** - * Get the last global counter for chat. - * - * @param string $mode There are two modes 'json', 'return' and 'session'. And json is by default. - */ -function users_get_last_global_counter($mode='json') -{ - global $config; - - $file_global_counter_chat = $config['attachment_store'].'/pandora_chat.global_counter.txt'; - - $global_counter_file = 0; - - $fp_global_counter = @fopen($file_global_counter_chat, 'a+'); - if ($fp_global_counter) { - $tries = 0; - $lock = true; - while (!flock($fp_global_counter, LOCK_EX)) { - $tries++; - if ($tries > MAX_TIMES) { - $lock = false; - break; - } - - sleep(1); - } - - if ($lock) { - @fscanf($fp_global_counter, '%d', $global_counter_file); - if (empty($global_counter_file)) { - $global_counter_file = 0; - } - - fclose($fp_global_counter); - } - } - - switch ($mode) { - case 'json': - echo json_encode(['correct' => true, 'global_counter' => $global_counter_file]); - break; - - case 'return': - return $global_counter_file; - - break; - case 'session': - $_SESSION['global_counter_chat'] = $global_counter_file; - break; - } -} - - -/** - * Get the last global counter for chat. - * - * @param string $mode There are two modes 'json', 'return' and 'session'. And json is by default. - */ -function users_get_last_type_message() -{ - global $config; - - $return = 'false'; - - $file_global_counter_chat = $config['attachment_store'].'/pandora_chat.global_counter.txt'; - $log_chat_file = $config['attachment_store'].'/pandora_chat.log.json.txt'; - - $global_counter_file = 0; - - $fp_global_counter = @fopen($file_global_counter_chat, 'a+'); - if ($fp_global_counter) { - $tries = 0; - $lock = true; - while (!flock($fp_global_counter, LOCK_EX)) { - $tries++; - if ($tries > MAX_TIMES) { - $lock = false; - break; - } - - sleep(1); - } - - if ($lock) { - $text_encode = @file_get_contents($log_chat_file); - $log = json_decode($text_encode, true); - - // Prevent from error when chat file log doesn't exists - if (empty($log)) { - $return = false; - } else { - $last = end($log); - $return = $last['type']; - } - - fclose($fp_global_counter); - } - } - - return $return; -} - - function users_is_admin($id_user=false) { global $config; @@ -1026,98 +524,6 @@ function users_is_admin($id_user=false) } -function users_is_last_system_message() -{ - $type = users_get_last_type_message(); - - if ($type != 'message') { - return true; - } else { - return false; - } -} - - -function users_check_users() -{ - global $config; - - $return = [ - 'correct' => false, - 'users' => '', - ]; - - $users_with_session = db_get_all_rows_sql('SELECT tsessions_php.data FROM pandora.tsessions_php;'); - $users_logged_now = []; - foreach ($users_with_session as $user_with_session) { - $tmp_id_user = explode('"', $user_with_session['data']); - array_push($users_logged_now, $tmp_id_user[1]); - } - - $file_global_user_list = $config['attachment_store'].'/pandora_chat.user_list.json.txt'; - - // First lock the file - $fp_user_list = @fopen($file_global_user_list, 'a+'); - if ($fp_user_list === false) { - echo json_encode($return); - - return; - } - - // Try to look MAX_TIMES times - $tries = 0; - while (!flock($fp_user_list, LOCK_EX)) { - $tries++; - if ($tries > MAX_TIMES) { - echo json_encode($return); - - return; - } - - sleep(1); - } - - @fscanf($fp_user_list, "%[^\n]", $user_list_json); - - $user_list = json_decode($user_list_json, true); - if (empty($user_list)) { - $user_list = []; - } - - // Compare both user list. Meanwhile the user from chat file have an active - // session, his continue in the list of active chat users - $user_name_list = []; - foreach ($user_list as $key => $user) { - if (in_array($key, $users_logged_now)) { - array_push($user_name_list, $user['name']); - } else { - unset($user_list[$key]); - } - } - - // Clean the file - ftruncate($fp_user_list, 0); - - // Update the file with the correct list of users - $status = fwrite($fp_user_list, json_encode($user_list)); - - /* - if ($status === false) { - fclose($fp_user_list); - - return; - } */ - // Closing the resource - fclose($fp_user_list); - - $return['correct'] = true; - $return['users'] = implode('
', $user_name_list); - echo json_encode($return); - - return; -} - - // Check if a user can manage a group when group is all // This function dont check acls of the group, only if the // user is admin or pandora manager and the group is all diff --git a/pandora_console/include/javascript/webchat.js b/pandora_console/include/javascript/webchat.js deleted file mode 100644 index 09c7ae81df..0000000000 --- a/pandora_console/include/javascript/webchat.js +++ /dev/null @@ -1,47 +0,0 @@ -function check_new_chats_icon(id_icon) { - if (new_chat) { - $("#" + id_icon).pulsate(); - } -} - -function check_new_chats_icon_ajax(id_icon) { - var exit = false; - - url_chunks = location.href.split("&"); - $.each(url_chunks, function(key, chunk) { - if (chunk == "sec2=operation/users/webchat") exit = true; - return; - }); - - if (exit) { - return; - } - - old = global_counter_chat; - get_last_global_counter(); - - if (old < global_counter_chat) { - $("#" + id_icon).pulsate(); - } - - setTimeout('check_new_chats_icon("' + id_icon + '")', 5000); -} - -function get_last_global_counter() { - var parameters = {}; - parameters["page"] = "operation/users/webchat"; - parameters["get_last_global_counter"] = 1; - - $.ajax({ - type: "POST", - url: "ajax.php", - data: parameters, - dataType: "json", - async: false, - success: function(data) { - if (data["correct"] == 1) { - global_counter_chat = data["global_counter"]; - } - } - }); -} diff --git a/pandora_console/index.php b/pandora_console/index.php index cc79382b82..4d643de5ae 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -1002,60 +1002,9 @@ if ($process_login) { } } - // Set the initial global counter for chat. - users_get_last_global_counter('session'); - $config['logged'] = true; } -// ---------------------------------------------------------------------- -// Get old parameters before navigation. -$old_sec = ''; -$old_sec2 = ''; -$old_page = ''; -if (isset($_SERVER['HTTP_REFERER'])) { - $old_page = $_SERVER['HTTP_REFERER']; -} - -$chunks = explode('?', $old_page); -if (count($chunks) == 2) { - $chunks = explode('&', $chunks[1]); - - foreach ($chunks as $chunk) { - if (strstr($chunk, 'sec=') !== false) { - $old_sec = str_replace('sec=', '', $chunk); - } - - if (strstr($chunk, 'sec2=') !== false) { - $old_sec = str_replace('sec2=', '', $chunk); - } - } -} - -$_SESSION['new_chat'] = false; -if ($old_sec2 == 'operation/users/webchat') { - users_get_last_global_counter('session'); -} - -if ($page == 'operation/users/webchat') { - // Reload the global counter. - users_get_last_global_counter('session'); -} - -if (isset($_SESSION['global_counter_chat'])) { - $old_global_counter_chat = $_SESSION['global_counter_chat']; -} else { - $old_global_counter_chat = users_get_last_global_counter('return'); -} - -$now_global_counter_chat = users_get_last_global_counter('return'); - -if ($old_global_counter_chat != $now_global_counter_chat) { - if (!users_is_last_system_message()) { - $_SESSION['new_chat'] = true; - } -} - require_once 'general/register.php'; if (get_parameter('login', 0) !== 0) { diff --git a/pandora_console/operation/menu.php b/pandora_console/operation/menu.php index 6b22d71c28..11fb477380 100644 --- a/pandora_console/operation/menu.php +++ b/pandora_console/operation/menu.php @@ -482,12 +482,6 @@ $sub['operation/users/user_edit_notifications']['text'] = __('Configure user not $sub['operation/users/user_edit_notifications']['id'] = 'Configure user notifications'; $sub['operation/users/user_edit_notifications']['refr'] = 0; -// ANY user can chat with other user and dogs. -// Users. -$sub['operation/users/webchat']['text'] = __('WebChat'); -$sub['operation/users/webchat']['id'] = 'WebChat'; -$sub['operation/users/webchat']['refr'] = 0; - // Incidents. if (check_acl($config['id_user'], 0, 'IR') diff --git a/pandora_console/operation/users/webchat.php b/pandora_console/operation/users/webchat.php deleted file mode 100644 index 94eb12ddcf..0000000000 --- a/pandora_console/operation/users/webchat.php +++ /dev/null @@ -1,345 +0,0 @@ - false]); - } - - return; -} - -global $config; - -check_login(); - -ui_print_page_header(__('Webchat'), 'images/comments.png', false, '', false, ''); - -$table = new stdClass(); - -$table->width = '100%'; -$table->class = 'databox filters'; -$table->style[0][1] = 'text-align: right; vertical-align: top;'; - -$table->data[0][0] = '
'; -$table->data[0][1] = '

'.__('Users Online').'

'.'
'; -$table->data[1][0] = ''.__('Message').'   '.html_print_input_text( - 'message_box', - '', - '', - 100, - 150, - true -); -html_print_table($table); - -echo "
".html_print_button( - __('Send message'), - 'send', - false, - 'send_message()', - 'class="sub next" style="float:right"', - true -).'
'; - -?> -