Files
guacamole-client/guacamole/src/main/webapp/admin.xhtml

308 lines
12 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<!--
Guacamole - Clientless Remote Desktop
Copyright (C) 2010 Michael Jumper
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="icon" type="image/png" href="images/guacamole-logo-64.png"/>
<link rel="apple-touch-icon" type="image/png" href="images/guacamole-logo-144.png"/>
<link rel="stylesheet" type="text/css" href="styles/ui.css"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=medium-dpi"/>
<title>Guacamole ${project.version}</title>
</head>
<body>
<h1>Administration</h1>
<h2 class="require-manage-users">Users</h2>
<div class="settings section require-manage-users" id="users">
<p>
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.
</p>
<div id="user-add-form">
<div class="icon user add"/><input type="text" class="name" id="username" placeholder="Add user"/><button id="add-user">Add</button>
</div>
<div id="user-list">
</div>
</div>
<h2 class="require-manage-connections">Connections</h2>
<div class="settings section require-manage-connections" id="connections">
<p>
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.
</p>
<div id="connection-add-form">
<div class="icon connection add"/><select id="protocol"><option value="vnc">VNC</option><option value="rdp">RDP</option></select><input type="text" id="connection-id" class="name" placeholder="Add connection"/><button id="add-connection">Add</button>
</div>
<div id="connection-list">
</div>
</div>
<div id="version-dialog">
Guacamole ${project.version}
</div>
<script type="text/javascript" src="scripts/session.js"></script>
<script type="text/javascript" src="scripts/guac-ui.js"></script>
<script type="text/javascript" src="scripts/admin.js"></script>
<script type="text/javascript" src="scripts/service.js"></script>
<script type="text/javascript" src="scripts/history.js"></script>
<script type="text/javascript"><![CDATA[
function hasEntry(object) {
for (var name in object)
return true;
return false;
}
// Elements
var connection_list = document.getElementById("connection-list");
var user_list = document.getElementById("user-list");
var add_connection = document.getElementById("add-connection");
var connection_id = document.getElementById("connection-id");
var protocol = document.getElementById("protocol");
var add_user = document.getElementById("add-user");
var username = document.getElementById("username");
function reset_admin_ui() {
/*
* Show admin elements if admin permissions available
*/
// Get permissions
var permissions = GuacamoleService.Permissions.list();
// Connection management
if (permissions.create_connection
|| hasEntry(permissions.update_connection)
|| hasEntry(permissions.remove_connection)
|| hasEntry(permissions.administer_connection))
GuacUI.addClass(document.body, "manage-connections");
else
GuacUI.removeClass(document.body, "manage-connections");
// User management
if (permissions.create_user
|| hasEntry(permissions.update_user)
|| hasEntry(permissions.remove_user)
|| 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");
add_connection.onclick = function() {
// Try to create connection
try {
var connection = new GuacamoleService.Connection(
protocol.value, connection_id.value);
GuacamoleService.Connections.create(connection);
connection_id.value = "";
reset_admin_ui();
}
// Alert on failure
catch (e) {
alert(e.message);
}
};
}
// User creation
if (permissions.create_user) {
GuacUI.addClass(document.body, "add-users");
add_user.onclick = function() {
// Attempt to create user
try {
GuacamoleService.Users.create(username.value);
username.value = "";
reset_admin_ui();
}
// Alert on failure
catch (e) {
alert(e.message);
}
};
}
/*
* Add readable users.
*/
var name;
var selected_user = null;
// Add users to list
user_list.innerHTML = "";
for (name in permissions.read_user) {(function(name){
var item = new GuacAdmin.ListItem("user", name);
var item_element = item.getElement();
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(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<connections.length; i++)
user_perms.read_connection[connections[i]] = true;
// Save user
GuacamoleService.Users.update(
selected_user, password, user_perms);
reset_admin_ui();
}
else if (title == "Delete") {
GuacamoleService.Users.remove(selected_user);
reset_admin_ui();
}
// Deselect
GuacUI.removeClass(user_list, "disabled");
GuacUI.removeClass(item_element, "selected");
item_element.removeChild(user_properties.getElement());
selected_user = null;
}
catch (e) {
alert(e.message);
}
};
item_element.appendChild(user_properties.getElement());
};
})(name)};
/*
* Add readable connections.
*/
var selected_connection = null;
// Add connections to list
connection_list.innerHTML = "";
for (name in permissions.read_connection) {(function(name){
var item = new GuacAdmin.ListItem("connection", name);
connection_list.appendChild(item.getElement());
})(name)};
}
// Initial load
reset_admin_ui();
]]></script>
</body>
</html>