mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-624: Fix isActive() logic. Approximate activity calculations based on known open connections. Update rendering of active connection vs connection without end date.
This commit is contained in:
@@ -48,6 +48,11 @@ public class MySQLConnectionRecord implements ConnectionRecord {
|
|||||||
*/
|
*/
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this connection is currently active.
|
||||||
|
*/
|
||||||
|
private boolean active;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize this MySQLConnectionRecord with the start/end dates,
|
* Initialize this MySQLConnectionRecord with the start/end dates,
|
||||||
* and the name of the user it represents.
|
* 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 startDate The start date of the connection history.
|
||||||
* @param endDate The end 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 username The name of the user that used the connection.
|
||||||
|
* @param active Whether the connection is currently active.
|
||||||
*/
|
*/
|
||||||
public MySQLConnectionRecord(Date startDate, Date endDate,
|
public MySQLConnectionRecord(Date startDate, Date endDate,
|
||||||
String username) {
|
String username, boolean active) {
|
||||||
if (startDate != null) this.startDate = new Date(startDate.getTime());
|
if (startDate != null) this.startDate = new Date(startDate.getTime());
|
||||||
if (endDate != null) this.endDate = new Date(endDate.getTime());
|
if (endDate != null) this.endDate = new Date(endDate.getTime());
|
||||||
this.username = username;
|
this.username = username;
|
||||||
|
this.active = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -82,8 +89,7 @@ public class MySQLConnectionRecord implements ConnectionRecord {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
// If the end date hasn't been stored yet, the connection is still open.
|
return active;
|
||||||
return endDate == null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -288,16 +288,34 @@ public class ConnectionService {
|
|||||||
userIDSet.add(history.getUser_id());
|
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
|
// Get all the usernames for the users who are in the history
|
||||||
Map<Integer, String> usernameMap = userService.retrieveUsernames(userIDSet);
|
Map<Integer, String> usernameMap = userService.retrieveUsernames(userIDSet);
|
||||||
|
|
||||||
// Create the new ConnectionRecords
|
// Create the new ConnectionRecords
|
||||||
for(ConnectionHistory history : connectionHistories) {
|
for(ConnectionHistory history : connectionHistories) {
|
||||||
|
|
||||||
Date startDate = history.getStart_date();
|
Date startDate = history.getStart_date();
|
||||||
Date endDate = history.getEnd_date();
|
Date endDate = history.getEnd_date();
|
||||||
String username = usernameMap.get(history.getUser_id());
|
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);
|
connectionRecords.add(connectionRecord);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return connectionRecords;
|
return connectionRecords;
|
||||||
|
@@ -842,8 +842,10 @@ GuacAdmin.ConnectionEditor = function(connection, parameters) {
|
|||||||
start.textContent = GuacAdmin.formatDate(record.start);
|
start.textContent = GuacAdmin.formatDate(record.start);
|
||||||
if (record.duration !== null)
|
if (record.duration !== null)
|
||||||
duration.textContent = GuacAdmin.formatSeconds(record.duration);
|
duration.textContent = GuacAdmin.formatSeconds(record.duration);
|
||||||
else
|
else if (record.active)
|
||||||
duration.textContent = "Active now";
|
duration.textContent = "Active now";
|
||||||
|
else
|
||||||
|
duration.textContent = "-";
|
||||||
|
|
||||||
// Add record to pager
|
// Add record to pager
|
||||||
history_pager.addElement(row);
|
history_pager.addElement(row);
|
||||||
|
Reference in New Issue
Block a user