2012-04-23 Miguel de Dios <miguel.dedios@artica.es>

* 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




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6088 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2012-04-23 11:20:28 +00:00
parent 9294f23fd0
commit c6a2e14e04
11 changed files with 867 additions and 127 deletions

View File

@ -1,10 +1,25 @@
2012-04-23 Miguel de Dios <miguel.dedios@artica.es>
* 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 <dario.rodriguez@artica.es>
* 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 <dario.rodriguez@artica.es>

View File

@ -32,17 +32,15 @@ config_check();
<table width="100%" cellpadding="0" cellspacing="0" style="margin:0px; padding:0px; margin-top: 5px;" border="0">
<tr>
<td rowspan="2">
<a href="index.php?sec=main">
<?php
if (!defined ('PANDORA_ENTERPRISE')){
echo html_print_image('images/pandora_header_logo.png', true, array("alt" => 'Pandora FMS Opensource', "border" => '0'));
}
else {
echo html_print_image('images/pandora_header_logo_enterprise.png', true, array("alt" => 'Pandora FMS Enterprise', "border" => '0'));
}
?>
</a>
<a href="index.php?sec=main">
<?php
if (!defined ('PANDORA_ENTERPRISE')){
echo html_print_image('images/pandora_header_logo.png', true, array("alt" => 'Pandora FMS Opensource', "border" => '0'));
} else {
echo html_print_image('images/pandora_header_logo_enterprise.png', true, array("alt" => 'Pandora FMS Enterprise', "border" => '0'));
}
?>
</a>
</td>
<td width="20%">
<?php
@ -57,7 +55,6 @@ config_check();
if ($config["metaconsole"] == 0){
$msg_cnt = messages_get_count ($config["id_user"]);
if ($msg_cnt > 0) {
echo '<div id="dialog_messages" style="display: none"></div>';
ui_require_css_file ('dialog');
@ -70,13 +67,19 @@ config_check();
}
}
if ($config["alert_cnt"] > 0){
echo "<span id='icon_new_messages_chat' style='display: none;'>";
echo "<a href='index.php?sec=workspace&sec2=operation/users/webchat'>";
html_print_image('images/comments.png');
echo "</a>";
echo "</span>";
if ($config["alert_cnt"] > 0) {
echo '<div id="alert_messages" style="display: none"></div>';
ui_require_css_file ('dialog');
echo '<a href="ajax.php?page=operation/system_alert" title="'.__("System alerts detected - Please fix as soon as possible").'" id="show_systemalert_dialog">';
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 '</a>';
echo "&nbsp;";
echo "&nbsp;";
@ -86,7 +89,7 @@ config_check();
html_print_image("images/log-out.png", false, array("alt" => __('Logout'), "class" => 'bot', "title" => __('Logout')));
echo '</a></td>';
echo '<td width="20%">';
if ($config["metaconsole"] == 0){
echo '<a class="white_bold" href="index.php?sec=gservers&amp;sec2=godmode/servers/modificar_server&amp;refr=60">';
@ -111,7 +114,6 @@ config_check();
else {
// TODO: Put here to remark this is a metaconsole
echo "";
}
?>
</td>
@ -125,7 +127,7 @@ config_check();
echo ' (<span id="refrcounter">'.date ("i:s", $config["refr"]).'</span>)';
echo '</a>';
}
else {
else {
$ignored_params['refr'] = '';
echo '<a id="autorefresh" class="white_bold" href="' . ui_get_url_refresh ($ignored_params).'">' . html_print_image("images/page_refresh.png", true, array("class" => 'bot', "alt" => 'lightning')) . '&nbsp;'. __('Autorefresh').'</a>';
$values = array (
@ -155,7 +157,7 @@ config_check();
</tr>
<tr>
<td colspan="2">
<?php
if ($config["metaconsole"] == 0){
?>
@ -199,49 +201,53 @@ if ($config["metaconsole"] == 0){
<script type="text/javascript" src="include/javascript/jquery.ui.draggable.js "></script>
<script type="text/javascript" src="include/javascript/jquery.ui.droppable.js "></script>
<script type="text/javascript" src="include/javascript/jquery.ui.resizable.js "></script>
-->
-->
<script type="text/javascript" src="include/javascript/webchat.js "></script>
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready (function () {
/* Temporal fix to hide graphics when ui_dialog are displayed */
$("#yougotalert").click(function () {
$("#agent_access").css("display", "none");
});
$("#ui_close_dialog_titlebar").click(function () {
$("#agent_access").css("display","");
});
<?php if ($msg_cnt > 0): ?>
$("#yougotmail").pulsate ();
<?php endif; ?>
<?php if ($config["alert_cnt"] > 0): ?>
$("#yougotalert").pulsate ();
<?php endif; ?>
<?php if ($config["refr"]): ?>
t = new Date();
t.setTime (t.getTime () + <?php echo $config["refr"] * 1000; ?>);
$("#refrcounter").countdown ({until: t,
layout: '%M%nn%M:%S%nn%S',
labels: ['', '', '', '', '', '', ''],
onExpiry: function () {
$(this).text ("...");
}
});
<?php else: ?>
$("a#autorefresh").click (function () {
var a = this;
/* <![CDATA[ */
var new_chat = <?php echo (int)$_SESSION['new_chat'];?>;
$(document).ready (function () {
check_new_chats_icon('icon_new_messages_chat');
$(this).hide ().unbind ("click");
$("#combo_refr").show ();
$("select#ref").change (function () {
href = $(a).attr ("href");
$(document).attr ("location", href + this.value);
/* Temporal fix to hide graphics when ui_dialog are displayed */
$("#yougotalert").click(function () {
$("#agent_access").css("display", "none");
});
$("#ui_close_dialog_titlebar").click(function () {
$("#agent_access").css("display","");
});
return false;
<?php if ($msg_cnt > 0): ?>
$("#yougotmail").pulsate ();
<?php endif; ?>
<?php if ($config["alert_cnt"] > 0): ?>
$("#yougotalert").pulsate ();
<?php endif; ?>
<?php if ($config["refr"]): ?>
t = new Date();
t.setTime (t.getTime () + <?php echo $config["refr"] * 1000; ?>);
$("#refrcounter").countdown ({until: t,
layout: '%M%nn%M:%S%nn%S',
labels: ['', '', '', '', '', '', ''],
onExpiry: function () {
$(this).text ("...");
}
});
<?php else: ?>
$("a#autorefresh").click (function () {
var a = this;
$(this).hide ().unbind ("click");
$("#combo_refr").show ();
$("select#ref").change (function () {
href = $(a).attr ("href");
$(document).attr ("location", href + this.value);
});
return false;
});
<?php endif; ?>
});
<?php endif; ?>
});
/* ]]> */
</script>

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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 = '<input id="image-'.$name.$idcounter.'" src="'.$src.'" style="'.$style.'" name="'.$name.'" type="image"';
//Valid attributes (invalid attributes get skipped)
@ -1012,7 +1012,10 @@ function html_print_table (&$table, $return = false) {
$output .= '<td colspan="'. $countcols .'"><div class="tabledivider"></div></td>';
continue;
}
if (!is_array($row))
$row = (array)$row;
/* It's a normal row */
foreach ($row as $key => $item) {
if (!isset ($size[$key])) {

View File

@ -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;
}
?>

View File

@ -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;
});
}
);

View File

@ -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'];
}
}
});
}

View File

@ -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 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
echo '<html xmlns="http://www.w3.org/1999/xhtml">'."\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 '<div id="main_pure">';
}
// http://es2.php.net/manual/en/ref.session.php#64525
// Session locking concurrency speedup!
session_write_close ();

View File

@ -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;
}
}
}
}
}

View File

@ -0,0 +1,265 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
if (is_ajax ()) {
global $config;
require_once("include/functions_users.php");
$status = check_login(false);
if ($status) {
$get_last_messages = (bool)get_parameter('get_last_messages', 0);
$send_message = (bool)get_parameter('send_message', 0);
$send_login = (bool)get_parameter('send_login', 0);
$send_logout = (bool)get_parameter('send_logout', 0);
$long_polling_check_messages = (bool)get_parameter('long_polling_check_messages', 0);
$get_last_global_counter = (bool)get_parameter('get_last_global_counter', 0);
if ($get_last_messages) {
$time = (int)get_parameter('time', 24 * 60 * 60);
users_get_last_messages($time);
}
if ($send_message) {
$message = get_parameter('message', false);
users_save_text_message($message);
}
if ($send_login) {
users_save_login();
}
if ($send_logout) {
users_save_logout();
}
if ($long_polling_check_messages) {
$global_counter = (int)get_parameter('global_counter', 0);
users_long_polling_check_messages($global_counter);
}
if ($get_last_global_counter) {
users_get_last_global_counter();
}
}
else {
echo json_encode(array('correct' => 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] = '<div id="chat_box" style="width: 100%;
height: 300px; background: #ffffff; border: 1px inset black;
overflow: auto; padding: 10px;"></div>';
$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);
?>
<script type="text/javascript">
var global_counter_chat = 0;
var chat_log = '';
var user_move_scroll = false;
var first_time = true;
$(document).ready(function() {
$("input[name=\"message_box\"]").keydown(function(e){
//Enter key.
if (e.keyCode == 13) {
send_message();
}
});
init_webchat();
});
$(window).unload(function () {
exit_webchat();
});
function init_webchat() {
send_login_message();
long_polling_check_messages();
}
function long_polling_check_messages() {
var parameters = {};
parameters['page'] = "operation/users/webchat";
parameters['long_polling_check_messages'] = 1;
parameters['global_counter'] = global_counter_chat;
$.ajax({
type: 'POST',
url: 'ajax.php',
data: parameters,
dataType: "json",
success: function(data) {
if (data['correct'] == 1) {
if (first_time) {
print_messages({
0: {'type' : 'notification',
'text': '<?php echo __('Connection established...get last 24h messages...');?>'}
}, true);
first_time = false;
}
global_counter_chat = data['global_counter'];
print_messages(data['log']);
}
else {
print_messages({
0: {'type' : 'error',
'text': '<?php echo __('Error in connection.');?>'}
}, false);
}
long_polling_check_messages();
},
error: function(request, status, err) {
long_polling_check_messages();
}
});
}
function print_messages(messages, clear_chat_box) {
//event_add_text = true;
if (typeof(clear_chat_box) == 'undefined') {
clear_chat_box = false;
}
var html = '';
$.each(messages, function(key, message) {
html = html + '<div ';
if (message['type'] == 'error') {
html = html + "style='color: red; font-style: italic;'";
}
else if (message['type'] == 'notification') {
html = html + "style='color: grey; font-style: italic;'";
}
else if (message['type'] == 'message') {
html = html + "style='color: black; font-style: normal;'";
}
html = html + '>';
if (message['type'] != 'message') {
html = html + message['text'];
}
else {
html = html +
'<span style="color: grey; font-style: italic;">' +
message['human_time'] + '</span>';
html = html + ' ' +
'<span style="color: black; font-weight: bolder;">' +
message['user_name'] + ':&gt; </span>';
html = html + ' ' + message['text'];
}
html = html + '</div>';
});
if (clear_chat_box) {
$("#chat_box").html(html);
}
else {
$("#chat_box").append(html);
}
$("#chat_box").scrollTop($("#chat_box").attr('scrollHeight'));
}
function send_message() {
var parameters = {};
parameters['page'] = "operation/users/webchat";
parameters['send_message'] = 1;
parameters['message'] = $("input[name=\"message_box\"]").val();
$.ajax({
type: 'POST',
url: 'ajax.php',
data: parameters,
dataType: "json",
success: function(data) {
if (data['correct'] == 1) {
$("input[name=\"message_box\"]").val('');
}
else {
print_messages({
0: {'type' : 'error',
'text': '<?php echo __('Error sendding message.');?>'}
}, false);
}
}
});
}
function exit_webchat() {
send_logout_message();
get_last_global_counter();
}
function send_login_message() {
var parameters = {};
parameters['page'] = "operation/users/webchat";
parameters['send_login'] = 1;
$.ajax({
type: 'POST',
url: 'ajax.php',
data: parameters,
dataType: "json",
success: function(data) {
if (data['correct'] == 1) {
}
else {
print_messages({
0: {'type' : 'error',
'text': '<?php echo __('Error login.');?>'}
}, false);
}
}
});
}
function send_logout_message() {
var parameters = {};
parameters['page'] = "operation/users/webchat";
parameters['send_logout'] = 1;
$.ajax({
type: 'POST',
url: 'ajax.php',
data: parameters,
dataType: "json",
success: function(data) {
}
});
}
</script>