online users fix

This commit is contained in:
SJ 2013-07-25 11:56:52 +02:00
parent 3664b775bb
commit 3d8d08f2bd
5 changed files with 20 additions and 7 deletions

View File

@ -371,9 +371,10 @@ create table if not exists `customer_settings` (
create table if not exists `online` (
`username` varchar(255) not null unique,
`username` varchar(255) not null,
`ts` int default 0,
`last_activity` int default 0,
`ipaddr` varchar(255) default null
`ipaddr` varchar(255) default null,
unique(`username`,`ipaddr`)
) Engine=InnoDB;

View File

@ -75,7 +75,7 @@ if(Registry::get('username')) {
}
if(ENABLE_SAAS == 1) {
$query = $db->query("UPDATE " . TABLE_ONLINE . " SET last_activity=? WHERE username=?", array(NOW, Registry::get('username')));
$query = $db->query("UPDATE " . TABLE_ONLINE . " SET last_activity=? WHERE username=? AND ipaddr=?", array(NOW, Registry::get('username'), $_SERVER['REMOTE_ADDR']));
if($db->countAffected() == 0) {
$query = $db->query("INSERT INTO " . TABLE_ONLINE . " (username, ts, last_activity, ipaddr) VALUES(?,?,?,?)", array(Registry::get('username'), NOW, NOW, $_SERVER['REMOTE_ADDR']));

View File

@ -118,7 +118,7 @@ class ModelSaasCustomer extends Model
$query = $this->db->query("INSERT INTO " . TABLE_ONLINE . " (username, ts, last_activity, ipaddr) VALUES(?,?,?,?)", array($username, NOW, NOW, $_SERVER['REMOTE_ADDR']));
if($this->db->countAffected() == 0) {
$query = $this->db->query("UPDATE " . TABLE_ONLINE . " SET ts=?, last_activity=?, ipaddr=? WHERE username=?", array(NOW, $_SERVER['REMOTE_ADDR'], $username));
$query = $this->db->query("UPDATE " . TABLE_ONLINE . " SET ts=?, last_activity=? WHERE username=? AND ipaddr=?", array(NOW, $username, $_SERVER['REMOTE_ADDR']));
}
return 1;
@ -128,7 +128,7 @@ class ModelSaasCustomer extends Model
public function offline($username = '') {
if($username == '') { return 0; }
$query = $this->db->query("DELETE FROM " . TABLE_ONLINE . " WHERE username=?", array($username));
$query = $this->db->query("DELETE FROM " . TABLE_ONLINE . " WHERE username=? AND ipaddr=?", array($username, $_SERVER['REMOTE_ADDR']));
return 1;
}

View File

@ -921,9 +921,14 @@ var Piler =
clear_ldap_test: function()
{
$('#LDAPTEST').html('');
}
},
reload_page: function()
{
location.reload(true);
}
}

View File

@ -32,7 +32,14 @@
<link rel="shortcut icon" href="/view/theme/default/assets/ico/favicon.png">
</head>
<body<?php if(isset($this->request->get['route']) && $this->request->get['route'] == 'health/health') { ?> onload="Piler.load_health(); setInterval('Piler.load_health()', Piler.health_refresh * 1000);"<?php } ?>>
<body<?php
if(isset($this->request->get['route'])) {
if($this->request->get['route'] == 'health/health') { ?> onload="Piler.load_health(); setInterval('Piler.load_health()', Piler.health_refresh * 1000);"<?php }
if($this->request->get['route'] == 'stat/online') { ?> onload="setInterval('Piler.reload_page()', Piler.health_refresh * 1000);"<?php }
} ?>>
<div id="piler1" class="container">