mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-09 22:51:22 +00:00
Working multiple-config login stub.
This commit is contained in:
@@ -39,6 +39,17 @@
|
||||
<url-pattern>/login</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- Configuration List Servlet -->
|
||||
<servlet>
|
||||
<description>Configuration list servlet.</description>
|
||||
<servlet-name>Configs</servlet-name>
|
||||
<servlet-class>net.sourceforge.guacamole.net.basic.ConfigurationList</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>Configs</servlet-name>
|
||||
<url-pattern>/configs</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- Guacamole Tunnel Servlet -->
|
||||
<servlet>
|
||||
<description>Tunnel servlet.</description>
|
||||
|
@@ -91,16 +91,6 @@
|
||||
new Guacamole.HTTPTunnel("tunnel")
|
||||
);
|
||||
|
||||
try {
|
||||
|
||||
// Connect client
|
||||
guac.connect(data);
|
||||
|
||||
}
|
||||
catch (e) {
|
||||
// TODO: Handle exception ...
|
||||
}
|
||||
|
||||
var menu = document.getElementById("menu");
|
||||
var logo = document.getElementById("status-logo");
|
||||
|
||||
@@ -325,6 +315,23 @@
|
||||
guac.sendKeyEvent(0, KEYSYM_CTRL);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
|
||||
// Get ID
|
||||
var url = window.location.href;
|
||||
var query = url.indexOf("?");
|
||||
var id = url.substring(query+1);
|
||||
|
||||
// Connect client
|
||||
guac.connect("id=" + encodeURIComponent(id));
|
||||
|
||||
}
|
||||
catch (e) {
|
||||
// TODO: Handle exception ...
|
||||
}
|
||||
|
||||
|
||||
/* ]]> */ </script>
|
||||
|
||||
</body>
|
||||
|
@@ -74,22 +74,11 @@
|
||||
<table class="connections">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Protocol</th>
|
||||
<th>Description</th>
|
||||
<th class="protocol">Protocol</th>
|
||||
<th class="name">Name</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>zhz@localhost</td>
|
||||
<td>vnc</td>
|
||||
<td class="description">Connect to test.guac-dev.org via vnc.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>zhz@localhost</td>
|
||||
<td>ssh</td>
|
||||
<td class="description">Connect to test.guac-dev.org via ssh.</td>
|
||||
</tr>
|
||||
<tbody id="connections-tbody">
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -102,6 +91,96 @@
|
||||
<!-- Init -->
|
||||
<script type="text/javascript"> /* <![CDATA[ */
|
||||
|
||||
function Config(protocol, id) {
|
||||
this.protocol = protocol;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
function getConfigList() {
|
||||
|
||||
// Get config list
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "configs", false);
|
||||
xhr.send(null);
|
||||
|
||||
// If fail, throw error
|
||||
if (xhr.status != 200)
|
||||
throw new Error(xhr.statusText);
|
||||
|
||||
// Otherwise, get list
|
||||
var configs = new Array();
|
||||
|
||||
var configElements = xhr.responseXML.getElementsByTagName("config");
|
||||
for (var i=0; i<configElements.length; i++) {
|
||||
configs.push(new Config(
|
||||
configElements[i].getAttribute("protocol"),
|
||||
configElements[i].getAttribute("id")
|
||||
));
|
||||
}
|
||||
|
||||
return configs;
|
||||
|
||||
}
|
||||
|
||||
function resetUI() {
|
||||
|
||||
var configs;
|
||||
try {
|
||||
configs = getConfigList();
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
console.log(e);
|
||||
|
||||
// Show login UI if unable to get configs
|
||||
loginUI.style.display = "";
|
||||
connectionListUI.style.display = "none";
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// Remove all rows from connections list
|
||||
var tbody = document.getElementById("connections-tbody");
|
||||
tbody.innerHTML = "";
|
||||
|
||||
// Add one row per connection
|
||||
for (var i=0; i<configs.length; i++) {
|
||||
|
||||
// Create row and cells
|
||||
var tr = document.createElement("tr");
|
||||
var protocol = document.createElement("td");
|
||||
var id = document.createElement("td");
|
||||
|
||||
// Set CSS
|
||||
protocol.className = "protocol";
|
||||
id.className = "name";
|
||||
|
||||
// Create link to client
|
||||
var clientLink = document.createElement("a");
|
||||
clientLink.setAttribute("href",
|
||||
"client.xhtml?" + encodeURIComponent(configs[i].id));
|
||||
|
||||
// Set cell contents
|
||||
protocol.textContent = configs[i].protocol;
|
||||
clientLink.textContent = configs[i].id;
|
||||
id.appendChild(clientLink);
|
||||
|
||||
// Add cells
|
||||
tr.appendChild(protocol);
|
||||
tr.appendChild(id);
|
||||
|
||||
// Add row
|
||||
tbody.appendChild(tr);
|
||||
|
||||
}
|
||||
|
||||
// If configs could be retrieved, display list
|
||||
loginUI.style.display = "none";
|
||||
connectionListUI.style.display = "";
|
||||
|
||||
}
|
||||
|
||||
var loginForm = document.getElementById("login-form");
|
||||
var loginUI = document.getElementById("login-ui");
|
||||
var connectionListUI = document.getElementById("connection-list-ui");
|
||||
@@ -130,9 +209,7 @@
|
||||
if (xhr.status != 200)
|
||||
throw new Error("Invalid login");
|
||||
|
||||
// Hide login UI, display connections
|
||||
loginUI.style.display = "none";
|
||||
connectionListUI.style.display = "";
|
||||
resetUI();
|
||||
|
||||
}
|
||||
catch (e) {
|
||||
@@ -153,7 +230,7 @@
|
||||
|
||||
}
|
||||
|
||||
loginUI.style.display = "";
|
||||
resetUI();
|
||||
|
||||
/* ]]> */ </script>
|
||||
|
||||
|
@@ -150,6 +150,16 @@ div#connection-list-ui table thead {
|
||||
background: #9A8;
|
||||
}
|
||||
|
||||
div#connection-list-ui table thead th.protocol {
|
||||
width: 1em;
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
div#connection-list-ui table thead th.name {
|
||||
text-align: left;
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
div#connection-list-ui table thead tr {
|
||||
border-top: 1px solid #676;
|
||||
border-bottom: 1px solid gray;
|
||||
@@ -169,6 +179,10 @@ div#connection-list-ui table td {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div#connection-list-ui table td.name {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
div#connection-list-ui table tbody tr:nth-child(even) { background: #CCC; }
|
||||
div#connection-list-ui table tbody tr:nth-child(odd) { background: #EEE; }
|
||||
|
||||
|
Reference in New Issue
Block a user