diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 2b9a2674c1..08fe44a051 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,10 +1,25 @@ +2012-04-23 Miguel de Dios + + * include/functions_html.php, include/javascript/jquery.pandora.js, + include/functions_db.php: cleaned source code style. + + * include/functions_users.php, index.php, operation/menu.php, + operation/users/webchat.php, include/javascript/webchat.js, + general/header.php: added first version of webchat. + + * include/functions.php: into the function "check_login" added the + parameter $output for some cases don't want see the error page like + as the ajax querys. + + MERGED FROM 4.0.2 + 2012-04-23 Dario Rodriguez * operation/search_reports.php, godmode/reporting/reporting_builder.list_items.php, godmode/reporting/reporting_builder.item_editor.php: Fixed some issues with reportin usability related to new menu structure. - + MERGED FROM 4.0.2 2012-04-23 Dario Rodriguez diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index beef9b84e3..34bd85abdd 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -32,17 +32,15 @@ config_check(); '; echo ' @@ -125,7 +127,7 @@ config_check(); echo ' ('.date ("i:s", $config["refr"]).')'; echo ''; } - else { + else { $ignored_params['refr'] = ''; echo '' . html_print_image("images/page_refresh.png", true, array("class" => 'bot', "alt" => 'lightning')) . ' '. __('Autorefresh').''; $values = array ( @@ -155,7 +157,7 @@ config_check(); '; continue; } - + + if (!is_array($row)) + $row = (array)$row; + /* It's a normal row */ foreach ($row as $key => $item) { if (!isset ($size[$key])) { diff --git a/pandora_console/include/functions_users.php b/pandora_console/include/functions_users.php index 18f05a6195..4000b294f5 100644 --- a/pandora_console/include/functions_users.php +++ b/pandora_console/include/functions_users.php @@ -66,10 +66,10 @@ function users_get_all_model_groups () { $returnGroups = array(); foreach ($groups as $group) $returnGroups[$group['id_mg']] = $group['name']; - + $returnGroups[0] = "Not assigned"; //Module group external to DB but it exist - - + + return $returnGroups; } @@ -89,27 +89,27 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup global $config; $id_user = $config['id_user']; } - + if (isset($id_groups)) { //Get recursive id groups $list_id_groups = array(); foreach ((array)$id_groups as $id_group) { $list_id_groups = array_merge($list_id_groups, groups_get_id_recursive($id_group)); } - + $list_id_groups = array_unique($list_id_groups); - + $groups = db_get_all_rows_filter('tgrupo', array('id_grupo' => $list_id_groups, 'order' => 'parent, nombre')); } else { $groups = db_get_all_rows_in_table ('tgrupo', 'parent, nombre'); } - + $user_groups = array (); - + if (!$groups) - return $user_groups; - + return $user_groups; + if ($returnAllGroup) { //All group if ($returnAllColumns) { $groupall = array('id_grupo' => 0, 'nombre' => __('All'), @@ -123,7 +123,7 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup // Add the All group to the beginning to be always the first array_unshift($groups, $groupall); } - + foreach ($groups as $group) { if ($privilege === false) { if ($returnAllColumns) { @@ -142,7 +142,7 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup } } } - + return $user_groups; } @@ -158,9 +158,9 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup */ function users_get_groups_tree($id_user = false, $privilege = "AR", $returnAllGroup = true) { $user_groups = users_get_groups ($id_user, $privilege, $returnAllGroup, true); - + $user_groups_tree = groups_get_groups_tree_recursive($user_groups); - + return $user_groups_tree; } @@ -177,7 +177,7 @@ function users_get_groups_tree($id_user = false, $privilege = "AR", $returnAllGr */ function users_get_first_group ($id_user = false, $privilege = "AR", $all_group = true) { $groups = array_keys (users_get_groups ($id_user, $privilege)); - + $return = array_shift($groups); if ((!$all_group) && ($return == 0)) { @@ -199,12 +199,12 @@ function users_get_first_group ($id_user = false, $privilege = "AR", $all_group function users_access_to_agent ($id_agent, $mode = "AR", $id_user = false) { if (empty ($id_agent)) return false; - + if ($id_user == false) { global $config; $id_user = $config['id_user']; } - + $id_group = (int) db_get_value ('id_grupo', 'tagente', 'id_agente', (int) $id_agent); return (bool) check_acl ($id_user, $id_group, $mode); } @@ -218,8 +218,348 @@ function users_access_to_agent ($id_agent, $mode = "AR", $id_user = false) { */ function users_get_user_by_id ($id_user){ $result_user = db_get_row('tusuario', 'id_user', $id_user); - - return $result_user; + + return $result_user; } + +//////////////////////////////////////////////////////////////////////// +//////////////////////WEBCHAT FUNCTIONS///////////////////////////////// +//////////////////////////////////////////////////////////////////////// +function users_get_last_messages($last_time = false) { + $file_global_counter_chat = sys_get_temp_dir() . '/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 = sys_get_temp_dir() . '/pandora_chat.log.json.txt'; + + $return = array('correct' => false, 'log' => array()); + + 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 = array(); + + $log_last_time = array(); + 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; + + $user = db_get_row_filter('tusuario', + array('id_user' => $config['id_user'])); + + $message = sprintf(__('User %s login at %s'), $user['fullname'], + date($config['date_format'])); + users_save_text_message($message, 'notification'); +} + +function users_save_logout() { + global $config; + + $user = db_get_row_filter('tusuario', + array('id_user' => $config['id_user'])); + + $message = sprintf(__('User %s logout at %s'), $user['fullname'], + date($config['date_format'])); + users_save_text_message($message, 'notification'); +} + +function users_save_text_message($message = false, $type = 'message') { + global $config; + + $file_global_counter_chat = sys_get_temp_dir() . '/pandora_chat.global_counter.txt'; + $log_chat_file = sys_get_temp_dir() . '/pandora_chat.log.json.txt'; + + $max_times = 10; + + $return = array('correct' => false); + + $id_user = $config['id_user']; + $user = db_get_row_filter('tusuario', + array('id_user' => $id_user)); + + $message_data = array(); + $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) { + 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; + } + + //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); + + 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; + echo json_encode($return); + } + + return; +} + +function users_long_polling_check_messages($global_counter) { + global $config; + + $file_global_counter_chat = sys_get_temp_dir() . '/pandora_chat.global_counter.txt'; + $log_chat_file = sys_get_temp_dir() . '/pandora_chat.log.json.txt'; + + $changes = false; + $max_times = 10; + + 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; + 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 = array(); + foreach ($log as $key => $message) { + if ($key <= $global_counter) continue; + + $return_log[] = $message; + } + + $return = array( + '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); + } + + echo json_encode(array('correct' => false)); + + 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 = sys_get_temp_dir() . '/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(array('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 = sys_get_temp_dir() . '/pandora_chat.global_counter.txt'; + $log_chat_file = sys_get_temp_dir() . '/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); + + $last = end($log); + + $return = $last['type']; + + fclose($fp_global_counter); + } + } + + return $return; +} + +function users_is_last_system_message() { + $type = users_get_last_type_message(); + + if ($type != 'message') + return true; + else + return false; +} ?> diff --git a/pandora_console/include/javascript/jquery.pandora.js b/pandora_console/include/javascript/jquery.pandora.js index 51a46d9460..d6b57260ed 100644 --- a/pandora_console/include/javascript/jquery.pandora.js +++ b/pandora_console/include/javascript/jquery.pandora.js @@ -58,7 +58,7 @@ $(document).ready (function () { return false; }); - + $("a#show_systemalert_dialog").click (function () { jQuery.get ("ajax.php", {"page": "operation/system_alert"}, @@ -69,7 +69,7 @@ $(document).ready (function () { .dialog ({ title: $("a#show_systemalert_dialog").attr ("title"), resizable: true, - draggable: true, + draggable: true, modal: true, overlay: { opacity: 0.5, @@ -133,7 +133,7 @@ $(document).ready (function () { ); return false; }); - + } ); diff --git a/pandora_console/include/javascript/webchat.js b/pandora_console/include/javascript/webchat.js new file mode 100644 index 0000000000..133fde93cb --- /dev/null +++ b/pandora_console/include/javascript/webchat.js @@ -0,0 +1,49 @@ +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) { + console.log(global_counter_chat+" < "+data['global_counter']); + global_counter_chat = data['global_counter']; + } + } + }); +} diff --git a/pandora_console/index.php b/pandora_console/index.php index 6dac666a87..4d773dbc2e 100644 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -99,7 +99,6 @@ $config["pure"] = (bool) get_parameter ("pure"); // Auto Refresh page (can now be disabled anywhere in the script) $config["refr"] = (int) get_parameter ("refr"); - ob_start (); echo ''."\n"; echo ''."\n"; @@ -272,6 +271,46 @@ extensions_load_extensions ($config['extensions']); if ($process_login) { /* Call all extensions login function */ extensions_call_login_function (); + + + + //Set the initial global counter for chat. + users_get_last_global_counter('session'); +} + +//Get old parameters before navigation. +$old_sec = ''; +$old_sec2 = ''; +$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'); +} +$old_global_counter_chat = $_SESSION['global_counter_chat']; +$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; } // Header @@ -286,6 +325,7 @@ else { echo '
'; } + // http://es2.php.net/manual/en/ref.session.php#64525 // Session locking concurrency speedup! session_write_close (); diff --git a/pandora_console/operation/menu.php b/pandora_console/operation/menu.php index 79a679c6ca..54b63f2df5 100644 --- a/pandora_console/operation/menu.php +++ b/pandora_console/operation/menu.php @@ -39,27 +39,28 @@ if (check_acl ($config['id_user'], 0, "AR")) { $sub = array (); $sub["operation/agentes/tactical"]["text"] = __('Tactical view'); $sub["operation/agentes/tactical"]["refr"] = 0; - + $sub["operation/agentes/group_view"]["text"] = __('Group view'); $sub["operation/agentes/group_view"]["refr"] = 0; $sub["operation/agentes/estado_agente"]["text"] = __('Agent detail'); $sub["operation/agentes/estado_agente"]["refr"] = 0; - $sub["operation/agentes/estado_agente"]["subsecs"] = array("godmode/agentes/agent_conf_gis", - "godmode/agentes/agent_disk_conf_editor", - "godmode/agentes/agent_template", - "godmode/agentes/configurar_agente", - "godmode/agentes/modificar_agente", - "godmode/agentes/module_manager", - "godmode/agentes/module_manager_editor", - "godmode/agentes/module_manager_editor_common", - "godmode/agentes/module_manager_editor_data", - "godmode/agentes/module_manager_editor_network", - "godmode/agentes/module_manager_editor_plugin", - "godmode/agentes/module_manager_editor_prediction", - "godmode/agentes/module_manager_editor_wmi", - "operation/agentes/ver_agente"); - + $sub["operation/agentes/estado_agente"]["subsecs"] = array( + "godmode/agentes/agent_conf_gis", + "godmode/agentes/agent_disk_conf_editor", + "godmode/agentes/agent_template", + "godmode/agentes/configurar_agente", + "godmode/agentes/modificar_agente", + "godmode/agentes/module_manager", + "godmode/agentes/module_manager_editor", + "godmode/agentes/module_manager_editor_common", + "godmode/agentes/module_manager_editor_data", + "godmode/agentes/module_manager_editor_network", + "godmode/agentes/module_manager_editor_plugin", + "godmode/agentes/module_manager_editor_prediction", + "godmode/agentes/module_manager_editor_wmi", + "operation/agentes/ver_agente"); + $sub["operation/agentes/alerts_status"]["text"] = __('Alert detail'); $sub["operation/agentes/alerts_status"]["refr"] = 0; @@ -80,10 +81,11 @@ if (check_acl ($config['id_user'], 0, "AR")) { //SNMP Console $sub["operation/snmpconsole/snmp_view"]["text"] = __('SNMP console'); $sub["operation/snmpconsole/snmp_view"]["refr"] = 0; - $sub["operation/snmpconsole/snmp_view"]["subsecs"] = array("enterprise/godmode/snmpconsole", - "godmode/snmpconsole/snmp_trap_editor", - "godmode/snmpconsole/snmp_alert", - "godmode/snmpconsole/snmp_filters"); + $sub["operation/snmpconsole/snmp_view"]["subsecs"] = array( + "enterprise/godmode/snmpconsole", + "godmode/snmpconsole/snmp_trap_editor", + "godmode/snmpconsole/snmp_alert", + "godmode/snmpconsole/snmp_filters"); $sub2 = array(); @@ -127,9 +129,10 @@ if (check_acl ($config['id_user'], 0, "AR")) { //Visual console $sub["godmode/reporting/map_builder"]["text"] = __('Visual console'); //Set godomode path - $sub["godmode/reporting/map_builder"]["subsecs"] = array("godmode/reporting/map_builder", - "godmode/reporting/visual_console_builder"); - + $sub["godmode/reporting/map_builder"]["subsecs"] = array( + "godmode/reporting/map_builder", + "godmode/reporting/visual_console_builder"); + if (!empty($config['vc_refr'])){ $sub["godmode/reporting/map_builder"]["refr"] = $config['vc_refr']; } @@ -188,12 +191,13 @@ if (check_acl ($config['id_user'], 0, "AR")) { $sub["godmode/reporting/graphs"]["text"] = __('Custom graphs'); //Set godomode path - $sub["godmode/reporting/graphs"]["subsecs"] = array("operation/reporting/graph_viewer", - "godmode/reporting/graph_builder"); - + $sub["godmode/reporting/graphs"]["subsecs"] = array( + "operation/reporting/graph_viewer", + "godmode/reporting/graph_builder"); + enterprise_hook ('dashboard_menu'); enterprise_hook ('reporting_godmenu'); - + $menu["reporting"]["sub"] = $sub; //End reporting @@ -296,6 +300,12 @@ $sub = array(); $sub["operation/users/user_edit"]["text"] = __('Edit my user'); $sub["operation/users/user_edit"]["refr"] = 0; +// ANY user can chat with other user and dogs. +// Users +$sub = array(); +$sub["operation/users/webchat"]["text"] = __('WebChat'); +$sub["operation/users/webchat"]["refr"] = 0; + //Incidents if (check_acl ($config['id_user'], 0, "IR") == 1) { $temp_sec2 = $sec2; @@ -305,13 +315,14 @@ if (check_acl ($config['id_user'], 0, "IR") == 1) { else { $sec2 = "operation/incidents/incident"; } - + $sub[$sec2]["text"] = __('Incidents'); $sub[$sec2]["refr"] = 0; - $sub[$sec2]["subsecs"] = array("operation/incidents/incident_detail", - "operation/integria_incidents"); + $sub[$sec2]["subsecs"] = array( + "operation/incidents/incident_detail", + "operation/integria_incidents"); - $sub2 = array (); + $sub2 = array (); $sub2["operation/incidents/incident_statistics"]["text"] = __('Statistics'); $sub[$sec2]["sub2"] = $sub2; @@ -370,10 +381,10 @@ if (check_acl ($config['id_user'], 0, "AR")) { //Check if was displayed inside other menu if ($extension["operation_menu"]["fatherId"] == '') { - $sub[$extension_menu["sec2"]]["text"] = $extension_menu["name"]; $sub[$extension_menu["sec2"]]["refr"] = 0; - } else { + } + else { if (array_key_exists('fatherId',$extension_menu)) { if (strlen($extension_menu['fatherId']) > 0) { $menu[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]["text"] = __($extension_menu['name']); @@ -384,7 +395,7 @@ if (check_acl ($config['id_user'], 0, "AR")) { $menu[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]["enterprise"] = $extension['enterprise']; $menu[$extension_menu['fatherId']]['hasExtensions'] = true; } - } + } } } diff --git a/pandora_console/operation/users/webchat.php b/pandora_console/operation/users/webchat.php new file mode 100644 index 0000000000..74b8d37179 --- /dev/null +++ b/pandora_console/operation/users/webchat.php @@ -0,0 +1,265 @@ + false)); + } + + return; +} + +global $config; + +check_login (); + +ui_print_page_header (__('Webchat'), "images/group.png", false, "", false, ""); + +$table = null; + +$table->width = '95%'; + +$table->colspan[0][0] = 2; + +$table->data[0][0] = '
'; +$table->data[1][0] = html_print_input_text('message_box', '', '', + 100, 150, true); +$table->data[1][1] = html_print_button('send', 'send', false, 'send_message()', + 'class="sub next" style="width: 100%"', true); + +html_print_table($table); +?> +
- - - 'Pandora FMS Opensource', "border" => '0')); - } - else { - echo html_print_image('images/pandora_header_logo_enterprise.png', true, array("alt" => 'Pandora FMS Enterprise', "border" => '0')); - } -?> - + + 'Pandora FMS Opensource', "border" => '0')); + } else { + echo html_print_image('images/pandora_header_logo_enterprise.png', true, array("alt" => 'Pandora FMS Enterprise', "border" => '0')); + } + ?> + 0) { - echo ''; ui_require_css_file ('dialog'); @@ -70,13 +67,19 @@ config_check(); } } - if ($config["alert_cnt"] > 0){ + echo ""; + + if ($config["alert_cnt"] > 0) { echo ''; ui_require_css_file ('dialog'); echo ''; html_print_image ("images/error.png", false, - array ("title" => __('You have %d warning(s)', $config["alert_cnt"]), "id" => "yougotalert", "class" => "bot")); + array ("title" => __('You have %d warning(s)', $config["alert_cnt"]), "id" => "yougotalert", "class" => "bot")); echo ''; echo " "; echo " "; @@ -86,7 +89,7 @@ config_check(); html_print_image("images/log-out.png", false, array("alt" => __('Logout'), "class" => 'bot', "title" => __('Logout'))); echo ''; - + if ($config["metaconsole"] == 0){ echo ''; @@ -111,7 +114,6 @@ config_check(); else { // TODO: Put here to remark this is a metaconsole echo ""; - } ?>
- + @@ -199,49 +201,53 @@ if ($config["metaconsole"] == 0){ - --> - + --> + + diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 28bc0f29dc..b7668b3e72 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -1292,14 +1292,20 @@ function check_sql ($sql) { * Check if login session variables are set. * * It will stop the execution if those variables were not set + * + * @param boolean $output Set return instead the output. By default true. * * @return bool 0 on success exit() on no success */ -function check_login () { +function check_login ($output = true) { global $config; if (!isset ($config["homedir"])) { + if (!$output) { + return false; + } + // No exists $config. Exit inmediatly include("general/noaccess.php"); exit; @@ -1308,7 +1314,8 @@ function check_login () { if ((isset($_SESSION["id_usuario"])) AND ($_SESSION["id_usuario"] != "")) { if (is_user ($_SESSION["id_usuario"])) { $config['id_user'] = $_SESSION["id_usuario"]; - return 0; + + return true; } } else { @@ -1319,11 +1326,15 @@ function check_login () { $user = $_SESSION['user']; $id_user = $user->getIdUser(); if (is_user ($id_user)) { - return 0; + return true; } } } - + + if (!$output) { + return false; + } + db_pandora_audit("No session", "Trying to access without a valid session", "N/A"); include ($config["homedir"]."/general/noaccess.php"); exit; diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index fec28f8e1b..908dc1c81a 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -38,7 +38,7 @@ function db_select_engine() { break; case "oracle": require_once ($config['homedir'] . '/include/db/oracle.php'); - break; + break; } } @@ -54,7 +54,7 @@ function db_connect($host = null, $db = null, $user = null, $pass = null, $histo break; case "oracle": return oracle_connect_db($host, $db, $user, $pass, $history, $port); - break; + break; } } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index aa64c34b61..b63fd50bb9 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -632,7 +632,7 @@ function html_print_input_text ($name, $value, $alt = '', $size = 50, $maxlength if ($size == 0) $size = 10; - + return html_print_input_text_extended ($name, $value, 'text-'.$name, '', $size, $maxlength, $disabled, '', '', $return); } @@ -657,16 +657,16 @@ function html_print_input_image ($name, $src, $value, $style = '', $return = fal /* Checks if user's skin is available */ $isFunctionSkins = enterprise_include_once ('include/functions_skins.php'); - + if ($isFunctionSkins !== ENTERPRISE_NOT_HOOK) { $skin_path = enterprise_hook('skins_get_image_path',array($src)); if ($skin_path) - $src = $skin_path; + $src = $skin_path; } - + // path to image $src = $config["homeurl"] . '/' . $src; - + $output = '