/*
* 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 .
*/
/**
* Main Guacamole web service namespace.
* @namespace
*/
var GuacamoleService = GuacamoleService || {};
/**
* An arbitrary Guacamole connection, consisting of an ID/protocol pair.
*
* @constructor
* @param {String} protocol The protocol used by this connection.
* @param {String} id The ID associated with this connection.
*/
GuacamoleService.Connection = function(protocol, id) {
/**
* The protocol associated with this connection.
*/
this.protocol = protocol;
/**
* The ID associated with this connection.
*/
this.id = id;
/**
* All parameters associated with this connection, if available.
*/
this.parameters = {};
/**
* An array of GuacamoleService.Connection.Record listing the usage
* history of this connection.
*/
this.history = [];
};
/**
* Creates a new GuacamoleService.Connection.Record describing a single
* session for the given username and having the given start/end times.
*
* @constructor
* @param {String} username The username of the user who used the connection.
* @param {Number} start The time that the connection began (in UNIX epoch
* milliseconds).
* @param {Number} end The time that the connection ended (in UNIX epoch
* milliseconds). This parameter is optional.
*/
GuacamoleService.Connection.Record = function(username, start, end) {
/**
* The username of the user associated with this record.
* @type String
*/
this.username = username;
/**
* The time the corresponding connection began.
* @type Date
*/
this.start = new Date(start);
/**
* The time the corresponding connection terminated (if any).
* @type Date
*/
this.end = null;
/**
* The duration of this connection, in seconds. This value is only
* defined if the end time is available.
* @type Number
*/
this.duration = null;
// If end time given, intialize end time
if (end) {
this.end = new Date(end);
this.duration = (end - start) / 1000;
}
};
/**
* A basic set of permissions that can be assigned to a user, describing
* whether they can create other users/connections and describing which
* users/connections they have permission to read or modify.
*/
GuacamoleService.PermissionSet = function() {
/**
* Whether permission to create users is granted.
*/
this.create_user = false;
/**
* Whether permission to create connections is granted.
*/
this.create_connection = false;
/**
* Object with a property entry for each readable user.
*/
this.read_user = {};
/**
* Object with a property entry for each updatable user.
*/
this.update_user = {};
/**
* Object with a property entry for each removable user.
*/
this.remove_user = {};
/**
* Object with a property entry for each administerable user.
*/
this.administer_user = {};
/**
* Object with a property entry for each readable connection.
*/
this.read_connection = {};
/**
* Object with a property entry for each updatable connection.
*/
this.update_connection = {};
/**
* Object with a property entry for each removable connection.
*/
this.remove_connection = {};
/**
* Object with a property entry for each administerable connection.
*/
this.administer_connection = {};
};
/**
* Collection of service functions which deal with connections. Each function
* makes an explicit HTTP query to the server, and parses the response.
*/
GuacamoleService.Connections = {
/**
* Comparator which compares two GuacamoleService.Connection objects.
*/
"comparator" : function(a, b) {
return a.id.localeCompare(b.id);
},
/**
* Returns an array of Connections for which the current user has access.
*
* @param {String} parameters Any parameters which should be passed to the
* server for the sake of authentication
* (optional).
* @return {GuacamoleService.Connection[]} An array of Connections for
* which the current user has
* access.
*/
"list" : function(parameters) {
// Construct request URL
var list_url = "connections";
if (parameters) list_url += "?" + parameters;
// Get connection list
var xhr = new XMLHttpRequest();
xhr.open("GET", list_url, false);
xhr.send(null);
// If fail, throw error
if (xhr.status != 200)
throw new Error(xhr.statusText);
// Otherwise, get list
var connections = new Array();
var connectionElements = xhr.responseXML.getElementsByTagName("connection");
for (var i=0; i