- Click or tap on a user below to manage that user. Depending
- on your access level, users can be added and deleted, and their
- passwords can be changed.
-
-
Connections
-
+
Users
+
-
- Click or tap on a connection below to manage that connection.
- Depending on your access level, connections can be added and
- deleted, and their properties (protocol, hostname, port, etc.)
- can be changed.
-
-
-
-
-
-
+
+ Click or tap on a user below to manage that user. Depending
+ on your access level, users can be added and deleted, and their
+ passwords can be changed.
+
+
+
+
+
+
+
+
+
Connections
+
+
+
+ Click or tap on a connection below to manage that connection.
+ Depending on your access level, connections can be added and
+ deleted, and their properties (protocol, hostname, port, etc.)
+ can be changed.
+
+
+
+
+
+
+
+
+
@@ -76,312 +84,9 @@
-
-
-
+
diff --git a/guacamole/src/main/webapp/scripts/admin.js b/guacamole/src/main/webapp/scripts/admin-ui.js
similarity index 58%
rename from guacamole/src/main/webapp/scripts/admin.js
rename to guacamole/src/main/webapp/scripts/admin-ui.js
index 1cc354918..e2c8653ec 100644
--- a/guacamole/src/main/webapp/scripts/admin.js
+++ b/guacamole/src/main/webapp/scripts/admin-ui.js
@@ -17,10 +17,30 @@
*/
/**
- * Main Guacamole admin namespace.
- * @namespace
+ * General set of UI elements and UI-related functions regarding
+ * administration.
*/
-var GuacAdmin = GuacAdmin || {};
+var GuacAdmin = {
+
+ "lists" : {
+ "connection_list" : document.getElementById("connection-list"),
+ "user_list" : document.getElementById("user-list")
+ },
+
+ "buttons" : {
+ "back" : document.getElementById("back"),
+ "logout" : document.getElementById("logout"),
+ "add_connection" : document.getElementById("add-connection"),
+ "add_user" : document.getElementById("add-user")
+ },
+
+ "fields" : {
+ "connection_id" : document.getElementById("connection-id"),
+ "protocol" : document.getElementById("protocol"),
+ "username" : document.getElementById("username")
+ }
+
+};
/**
* An arbitrary input field.
@@ -554,4 +574,314 @@ GuacAdmin.UserManager = function() {
*/
this.onsave = null;
-};
\ No newline at end of file
+};
+
+/*
+ * Set handler for logout
+ */
+
+GuacAdmin.buttons.logout.onclick = function() {
+ window.location.href = "logout";
+};
+
+/*
+ * Set handler for back button
+ */
+
+GuacAdmin.buttons.back.onclick = function() {
+ window.location.href = "index.xhtml";
+};
+
+/**
+ * Returns whether the given object has at least one property.
+ */
+GuacAdmin.hasEntry = function(object) {
+ for (var name in object)
+ return true;
+ return false;
+};
+
+GuacAdmin.reset = function() {
+
+ /*
+ * Show admin elements if admin permissions available
+ */
+
+ // Get permissions
+ var permissions = GuacamoleService.Permissions.list();
+
+ // Connection management
+ if (permissions.create_connection
+ || GuacAdmin.hasEntry(permissions.update_connection)
+ || GuacAdmin.hasEntry(permissions.remove_connection)
+ || GuacAdmin.hasEntry(permissions.administer_connection))
+ GuacUI.addClass(document.body, "manage-connections");
+ else
+ GuacUI.removeClass(document.body, "manage-connections");
+
+ // User management
+ if (permissions.create_user
+ || GuacAdmin.hasEntry(permissions.update_user)
+ || GuacAdmin.hasEntry(permissions.remove_user)
+ || GuacAdmin.hasEntry(permissions.administer_user))
+ GuacUI.addClass(document.body, "manage-users");
+ else
+ GuacUI.removeClass(document.body, "manage-users");
+
+ // Connection creation
+ if (permissions.create_connection) {
+ GuacUI.addClass(document.body, "add-connections");
+
+ GuacAdmin.buttons.add_connection.onclick = function() {
+
+ // Try to create connection
+ try {
+ var connection = new GuacamoleService.Connection(
+ GuacAdmin.fields.protocol.value, GuacAdmin.fields.connection_id.value);
+ GuacamoleService.Connections.create(connection);
+ GuacAdmin.fields.connection_id.value = "";
+ GuacAdmin.reset();
+ }
+
+ // Alert on failure
+ catch (e) {
+ alert(e.message);
+ }
+
+ };
+
+ }
+
+ // User creation
+ if (permissions.create_user) {
+ GuacUI.addClass(document.body, "add-users");
+
+ GuacAdmin.buttons.add_user.onclick = function() {
+
+ // Attempt to create user
+ try {
+ GuacamoleService.Users.create(GuacAdmin.fields.username.value);
+ GuacAdmin.fields.username.value = "";
+ GuacAdmin.reset();
+ }
+
+ // Alert on failure
+ catch (e) {
+ alert(e.message);
+ }
+
+ };
+
+ }
+
+ /*
+ * Add readable users.
+ */
+
+ var name;
+ var selected_user = null;
+
+ // Add users to list
+ GuacAdmin.lists.user_list.innerHTML = "";
+ for (name in permissions.read_user) {(function(name){
+
+ var item = new GuacAdmin.ListItem("user", name);
+ var item_element = item.getElement();
+ GuacAdmin.lists.user_list.appendChild(item_element);
+
+ item_element.onclick = function() {
+
+ // Ignore clicks if any item is selected
+ if (selected_user) return;
+ else selected_user = name;
+
+ // Get user permissions
+ var user_perms = GuacamoleService.Permissions.list(name);
+
+ // Load buttons
+ var buttons = [new GuacAdmin.Button("Save"),
+ new GuacAdmin.Button("Cancel")];
+
+ if (name in permissions.remove_user)
+ buttons.push(new GuacAdmin.Button("Delete"));
+
+ // User property form.
+ var user_properties = new GuacAdmin.Form(
+
+ /* Fields */
+ [new GuacAdmin.Field.PASSWORD("Password:", [],
+ ["f12a1930-7195-11e2-bcfd-0800200c9a66"]),
+
+ new GuacAdmin.Field.PASSWORD("Re-enter Password:", [],
+ ["f12a1930-7195-11e2-bcfd-0800200c9a66"]),
+
+ new GuacAdmin.Field.LIST("Connections:",
+ Object.keys(permissions.administer_connection),
+ Object.keys(user_perms.read_connection))],
+
+ /* Buttons */
+ buttons
+
+ );
+
+ // Select
+ GuacUI.addClass(GuacAdmin.lists.user_list, "disabled");
+ GuacUI.addClass(item_element, "selected");
+
+ // Handle buttons
+ user_properties.onaction = function(title, fields) {
+
+ try {
+
+ if (title == "Save") {
+
+ // Get passwords
+ var password = fields[0][0];
+ var reentered_password = fields[1][0];
+
+ // Check that passwords match
+ if (password != reentered_password)
+ throw new Error("Passwords do not match.");
+
+ // Do not update password if it's just the
+ // not-changed token
+ if (password == "f12a1930-7195-11e2-bcfd-0800200c9a66")
+ password = null;
+
+ // Set user permissions
+ user_perms.read_connection = {};
+ var connections = fields[2];
+ for (var i=0; i