added online users feature

This commit is contained in:
SJ 2013-07-24 22:14:05 +02:00
parent 920f4208ba
commit 93e9c7ce33
16 changed files with 159 additions and 1 deletions

View File

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

View File

@ -23,6 +23,12 @@ create table if not exists `customer_settings` (
`branding_logo` varchar(255) default null, `branding_logo` varchar(255) default null,
`support_link` varchar(255) default null, `support_link` varchar(255) default null,
`colour` varchar(255) default null `colour` varchar(255) default null
) Engine=InnoDB; ) Engine=InnoDB;
create table if not exists `online` (
`username` varchar(255) not null unique,
`ts` int default 0,
`last_activity` int default 0,
`ipaddr` varchar(255) default null
) Engine=InnoDB;

View File

@ -272,6 +272,7 @@ define('TABLE_RETENTION_RULE', 'retention_rule');
define('TABLE_OPTION', 'option'); define('TABLE_OPTION', 'option');
define('TABLE_LDAP', 'ldap'); define('TABLE_LDAP', 'ldap');
define('TABLE_CUSTOMER_SETTINGS', 'customer_settings'); define('TABLE_CUSTOMER_SETTINGS', 'customer_settings');
define('TABLE_ONLINE', 'online');
define('TABLE_GOOGLE', 'google'); define('TABLE_GOOGLE', 'google');
define('TABLE_GOOGLE_IMAP', 'google_imap'); define('TABLE_GOOGLE_IMAP', 'google_imap');
define('VIEW_MESSAGES', 'v_messages'); define('VIEW_MESSAGES', 'v_messages');

View File

@ -18,6 +18,9 @@ class ControllerHealthWorker extends Controller {
$this->load->model('health/health'); $this->load->model('health/health');
$this->load->model('stat/counter'); $this->load->model('stat/counter');
if(ENABLE_SAAS == 1) {
$this->load->model('saas/customer');
}
$request = Registry::get('request'); $request = Registry::get('request');
@ -37,6 +40,9 @@ class ControllerHealthWorker extends Controller {
$this->data['health'][] = $this->model_health_health->checksmtp($smtp, $lang->data['text_error']); $this->data['health'][] = $this->model_health_health->checksmtp($smtp, $lang->data['text_error']);
} }
if(ENABLE_SAAS == 1) {
$this->data['num_of_online_users'] = $this->model_saas_customer->count_online();
}
$this->data['processed_emails'] = $this->model_health_health->count_processed_emails(); $this->data['processed_emails'] = $this->model_health_health->count_processed_emails();

View File

@ -29,6 +29,7 @@ class ControllerLoginLogin extends Controller {
if(ENABLE_SAAS == 1) { if(ENABLE_SAAS == 1) {
$this->load->model('saas/ldap'); $this->load->model('saas/ldap');
$this->load->model('saas/customer');
} }
$this->document->title = $this->data['text_login']; $this->document->title = $this->data['text_login'];
@ -39,6 +40,10 @@ class ControllerLoginLogin extends Controller {
$this->model_user_prefs->get_user_preferences($_SESSION['username']); $this->model_user_prefs->get_user_preferences($_SESSION['username']);
if(ENABLE_SAAS == 1) {
$this->model_saas_customer->online($_SESSION['username']);
}
LOGGER('logged in'); LOGGER('logged in');
if(isAdminUser() == 1) { if(isAdminUser() == 1) {

View File

@ -18,6 +18,11 @@ class ControllerLoginLogout extends Controller {
$this->document->title = $this->data['text_logout']; $this->document->title = $this->data['text_logout'];
if(ENABLE_SAAS == 1) {
$this->load->model('saas/customer');
$this->model_saas_customer->offline(Registry::get('username'));
}
logout(); logout();
$this->render(); $this->render();

View File

@ -0,0 +1,33 @@
<?php
class ControllerStatOnline extends Controller {
private $error = array();
public function index(){
$this->id = "content";
$this->template = "stat/online.tpl";
$this->layout = "common/layout";
$request = Registry::get('request');
$db = Registry::get('db');
$this->load->model('saas/customer');
$this->document->title = $this->data['text_statistics'];
if(Registry::get('admin_user') == 0) {
die("go away");
}
$this->data['users'] = $this->model_saas_customer->get_online_users();
$this->render();
}
}
?>

View File

@ -73,6 +73,15 @@ if(Registry::get('username')) {
else { else {
$action = new Router('search/search'); $action = new Router('search/search');
} }
if(ENABLE_SAAS == 1) {
$query = $db->query("UPDATE " . TABLE_ONLINE . " SET last_activity=? WHERE username=?", array(NOW, Registry::get('username')));
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']));
}
}
} }
else { else {
if(ENABLE_GOOGLE_LOGIN == 1 && isset($request->get['route']) && $request->get['route'] == 'login/google') { if(ENABLE_GOOGLE_LOGIN == 1 && isset($request->get['route']) && $request->get['route'] == 'login/google') {

View File

@ -164,8 +164,10 @@ $_['text_invalid_policy_setting'] = "Ungültige Methodeneinstellung";
$_['text_invalid_uid'] = "Benutzerkennung ungültig"; $_['text_invalid_uid'] = "Benutzerkennung ungültig";
$_['text_invalid_username'] = "Ungültiger Benutzername"; $_['text_invalid_username'] = "Ungültiger Benutzername";
$_['text_ipaddr'] = "IP-Adresse"; $_['text_ipaddr'] = "IP-Adresse";
$_['text_language'] = "Sprache"; $_['text_language'] = "Sprache";
$_['text_last'] = "Letzte"; $_['text_last'] = "Letzte";
$_['text_last_activity'] = "Letzte Aktivitat";
$_['text_last_update'] = "Letzte Aktualisierung"; $_['text_last_update'] = "Letzte Aktualisierung";
$_['text_latest_emails'] = "Letzte Nachrichten"; $_['text_latest_emails'] = "Letzte Nachrichten";
$_['text_ldap'] = "LDAP"; $_['text_ldap'] = "LDAP";
@ -177,6 +179,7 @@ $_['text_ldap_host'] = "LDAP-Host";
$_['text_ldap_type'] = "LDAP-Typ"; $_['text_ldap_type'] = "LDAP-Typ";
$_['text_load'] = "Laden"; $_['text_load'] = "Laden";
$_['text_loading'] = "lade"; $_['text_loading'] = "lade";
$_['text_logged_in'] = "Logged in";
$_['text_logged_out'] = "Sie haben sich abgemeldet"; $_['text_logged_out'] = "Sie haben sich abgemeldet";
$_['text_login'] = "Anmeldung"; $_['text_login'] = "Anmeldung";
$_['text_login2'] = "Anmeldung"; $_['text_login2'] = "Anmeldung";

View File

@ -164,8 +164,10 @@ $_['text_invalid_policy_setting'] = "Invalid policy setting";
$_['text_invalid_uid'] = "Invalid uid"; $_['text_invalid_uid'] = "Invalid uid";
$_['text_invalid_username'] = "Invalid username"; $_['text_invalid_username'] = "Invalid username";
$_['text_ipaddr'] = "IP address"; $_['text_ipaddr'] = "IP address";
$_['text_language'] = "Language"; $_['text_language'] = "Language";
$_['text_last'] = "Last"; $_['text_last'] = "Last";
$_['text_last_activity'] = "Last activity";
$_['text_last_update'] = "Last update"; $_['text_last_update'] = "Last update";
$_['text_latest_emails'] = "Latest emails"; $_['text_latest_emails'] = "Latest emails";
$_['text_ldap'] = "LDAP"; $_['text_ldap'] = "LDAP";
@ -177,6 +179,7 @@ $_['text_ldap_host'] = "LDAP host";
$_['text_ldap_type'] = "LDAP type"; $_['text_ldap_type'] = "LDAP type";
$_['text_load'] = "Load"; $_['text_load'] = "Load";
$_['text_loading'] = "loading"; $_['text_loading'] = "loading";
$_['text_logged_in'] = "Logged in";
$_['text_logged_out'] = "You are logged out"; $_['text_logged_out'] = "You are logged out";
$_['text_login'] = "Login"; $_['text_login'] = "Login";
$_['text_login2'] = "login"; $_['text_login2'] = "login";

View File

@ -167,6 +167,7 @@ $_['text_ipaddr'] = "IP c
$_['text_language'] = "Nyelv"; $_['text_language'] = "Nyelv";
$_['text_last'] = "Utolsó"; $_['text_last'] = "Utolsó";
$_['text_last_activity'] = "Utolsó aktivitás";
$_['text_latest_emails'] = "Legfrissebb emailek"; $_['text_latest_emails'] = "Legfrissebb emailek";
$_['text_last_update'] = "Utolsó frissítés"; $_['text_last_update'] = "Utolsó frissítés";
$_['text_ldap'] = "LDAP"; $_['text_ldap'] = "LDAP";
@ -178,6 +179,7 @@ $_['text_ldap_host'] = "LDAP kiszolg
$_['text_ldap_type'] = "LDAP típus"; $_['text_ldap_type'] = "LDAP típus";
$_['text_load'] = "Betöltés"; $_['text_load'] = "Betöltés";
$_['text_loading'] = "töltődik"; $_['text_loading'] = "töltődik";
$_['text_logged_in'] = "Bejelentkezés";
$_['text_logged_out'] = "Ön kijelentkezett"; $_['text_logged_out'] = "Ön kijelentkezett";
$_['text_login'] = "Bejelentkezés"; $_['text_login'] = "Bejelentkezés";
$_['text_login2'] = "bejelentkezés"; $_['text_login2'] = "bejelentkezés";

View File

@ -167,6 +167,7 @@ $_['text_ipaddr'] = "IP cím";
$_['text_language'] = "Nyelv"; $_['text_language'] = "Nyelv";
$_['text_last'] = "Utolsó"; $_['text_last'] = "Utolsó";
$_['text_last_activity'] = "Utolsó aktivitás";
$_['text_latest_emails'] = "Legfrissebb emailek"; $_['text_latest_emails'] = "Legfrissebb emailek";
$_['text_last_update'] = "Utolsó frissítés"; $_['text_last_update'] = "Utolsó frissítés";
$_['text_ldap'] = "LDAP"; $_['text_ldap'] = "LDAP";
@ -178,6 +179,7 @@ $_['text_ldap_host'] = "LDAP kiszolgáló";
$_['text_ldap_type'] = "LDAP típus"; $_['text_ldap_type'] = "LDAP típus";
$_['text_load'] = "Betöltés"; $_['text_load'] = "Betöltés";
$_['text_loading'] = "töltődik"; $_['text_loading'] = "töltődik";
$_['text_logged_in'] = "Bejelentkezés";
$_['text_logged_out'] = "Ön kijelentkezett"; $_['text_logged_out'] = "Ön kijelentkezett";
$_['text_login'] = "Bejelentkezés"; $_['text_login'] = "Bejelentkezés";
$_['text_login2'] = "bejelentkezés"; $_['text_login2'] = "bejelentkezés";

View File

@ -163,6 +163,7 @@ $_['text_ipaddr'] = "Endereço IP";
$_['text_language'] = "Idioma"; $_['text_language'] = "Idioma";
$_['text_last'] = "Último"; $_['text_last'] = "Último";
$_['text_last_activity'] = "Last activity";
$_['text_last_update'] = "Última atualização"; $_['text_last_update'] = "Última atualização";
$_['text_latest_emails'] = "Emails mais recentes"; $_['text_latest_emails'] = "Emails mais recentes";
$_['text_ldap_auditor_member_dn'] = "Auditor member DN"; $_['text_ldap_auditor_member_dn'] = "Auditor member DN";
@ -173,6 +174,7 @@ $_['text_ldap_host'] = "LDAP host";
$_['text_ldap_type'] = "LDAP type"; $_['text_ldap_type'] = "LDAP type";
$_['text_load'] = "Carregar"; $_['text_load'] = "Carregar";
$_['text_loading'] = "carregando"; $_['text_loading'] = "carregando";
$_['text_logged_in'] = "Logged in";
$_['text_logged_out'] = "Você não está logado"; $_['text_logged_out'] = "Você não está logado";
$_['text_login'] = "Login"; $_['text_login'] = "Login";
$_['text_login2'] = "login"; $_['text_login2'] = "login";

View File

@ -111,6 +111,43 @@ class ModelSaasCustomer extends Model
return $data; return $data;
} }
public function online($username = '') {
if($username == '') { return 0; }
$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));
}
return 1;
}
public function offline($username = '') {
if($username == '') { return 0; }
$query = $this->db->query("DELETE FROM " . TABLE_ONLINE . " WHERE username=?", array($username));
return 1;
}
public function count_online() {
$query = $this->db->query("SELECT COUNT(*) AS num FROM " . TABLE_ONLINE);
return $query->row['num'];
}
public function get_online_users() {
$query = $this->db->query("SELECT * FROM " . TABLE_ONLINE . " ORDER BY username ASC");
return $query->rows;
}
} }
?> ?>

View File

@ -26,6 +26,13 @@
<th><?php print $text_swap_usage; ?>:</th> <th><?php print $text_swap_usage; ?>:</th>
<td><div class="progress <?php if($swapinfo < HEALTH_RATIO) { ?>progress-success<?php } else { ?>progress-danger<?php } ?>"><div class="bar" style="width: <?php print $swapinfo; ?>%"></div>&nbsp;<?php print $swapinfo; ?>% / <?php print $totalswap; ?> MB</div></td> <td><div class="progress <?php if($swapinfo < HEALTH_RATIO) { ?>progress-success<?php } else { ?>progress-danger<?php } ?>"><div class="bar" style="width: <?php print $swapinfo; ?>%"></div>&nbsp;<?php print $swapinfo; ?>% / <?php print $totalswap; ?> MB</div></td>
</tr> </tr>
<?php if(ENABLE_SAAS == 1) { ?>
<tr>
<th class="span4"><?php print $text_online_users; ?>:</th>
<td class="span8"><a href="index.php?route=stat/online"><?php print $num_of_online_users; ?></a></td>
</tr>
<?php } ?>
</table> </table>

View File

@ -0,0 +1,30 @@
<h4><?php print $text_online_users; ?></h4>
<div class="listarea">
<?php if(isset($users)){ ?>
<table id="ss1" class="table table-striped table-condensed">
<tr>
<th class="domaincell"><?php print $text_username; ?></th>
<th class="domaincell"><?php print $text_ipaddr; ?></th>
<th class="domaincell"><?php print $text_logged_in; ?></th>
<th class="domaincell"><?php print $text_last_activity; ?></th>
</tr>
<?php foreach($users as $user) { ?>
<tr>
<td class="domaincell"><?php print $user['username']; ?></td>
<td class="domaincell"><?php print $user['ipaddr']; ?></td>
<td class="domaincell"><?php print date("Y.m.d. G:i:s", $user['ts']); ?></td>
<td class="domaincell"><?php print date("Y.m.d. G:i:s", $user['last_activity']); ?></td>
</tr>
<?php } ?>
</table>
<?php } ?>
</div>