From 70a3b67ef1a600d2e3a62e725c859387e48cecf3 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 15 Apr 2014 11:42:26 -0700 Subject: [PATCH] GUAC-624: Fix isActive() logic. Approximate activity calculations based on known open connections. Update rendering of active connection vs connection without end date. --- .../net/auth/mysql/MySQLConnectionRecord.java | 12 ++++++++--- .../auth/mysql/service/ConnectionService.java | 20 ++++++++++++++++++- guacamole/src/main/webapp/scripts/admin-ui.js | 4 +++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnectionRecord.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnectionRecord.java index 479add2b9..e723f89b6 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnectionRecord.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnectionRecord.java @@ -48,6 +48,11 @@ public class MySQLConnectionRecord implements ConnectionRecord { */ private String username; + /** + * Whether this connection is currently active. + */ + private boolean active; + /** * Initialize this MySQLConnectionRecord with the start/end dates, * and the name of the user it represents. @@ -55,12 +60,14 @@ public class MySQLConnectionRecord implements ConnectionRecord { * @param startDate The start date of the connection history. * @param endDate The end date of the connection history. * @param username The name of the user that used the connection. + * @param active Whether the connection is currently active. */ public MySQLConnectionRecord(Date startDate, Date endDate, - String username) { + String username, boolean active) { if (startDate != null) this.startDate = new Date(startDate.getTime()); if (endDate != null) this.endDate = new Date(endDate.getTime()); this.username = username; + this.active = active; } @Override @@ -82,8 +89,7 @@ public class MySQLConnectionRecord implements ConnectionRecord { @Override public boolean isActive() { - // If the end date hasn't been stored yet, the connection is still open. - return endDate == null; + return active; } } diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java index a31e3f949..c17e09976 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java @@ -288,16 +288,34 @@ public class ConnectionService { userIDSet.add(history.getUser_id()); } + // Determine whether connection is currently active + int user_count = activeConnectionMap.getCurrentUserCount(connectionID); + // Get all the usernames for the users who are in the history Map usernameMap = userService.retrieveUsernames(userIDSet); // Create the new ConnectionRecords for(ConnectionHistory history : connectionHistories) { + Date startDate = history.getStart_date(); Date endDate = history.getEnd_date(); String username = usernameMap.get(history.getUser_id()); - MySQLConnectionRecord connectionRecord = new MySQLConnectionRecord(startDate, endDate, username); + + // If there are active users, list the top N not-ended connections + // as active (best guess) + MySQLConnectionRecord connectionRecord; + if (user_count > 0 && endDate == null) { + connectionRecord = new MySQLConnectionRecord(startDate, endDate, username, true); + user_count--; + } + + // If no active users, or end date is recorded, connection is not + // active. + else + connectionRecord = new MySQLConnectionRecord(startDate, endDate, username, false); + connectionRecords.add(connectionRecord); + } return connectionRecords; diff --git a/guacamole/src/main/webapp/scripts/admin-ui.js b/guacamole/src/main/webapp/scripts/admin-ui.js index 50bdc19b5..0bf2296ac 100644 --- a/guacamole/src/main/webapp/scripts/admin-ui.js +++ b/guacamole/src/main/webapp/scripts/admin-ui.js @@ -842,8 +842,10 @@ GuacAdmin.ConnectionEditor = function(connection, parameters) { start.textContent = GuacAdmin.formatDate(record.start); if (record.duration !== null) duration.textContent = GuacAdmin.formatSeconds(record.duration); - else + else if (record.active) duration.textContent = "Active now"; + else + duration.textContent = "-"; // Add record to pager history_pager.addElement(row);