clockwerk-guacamole – Rev 1

Subversion Repositories:
Rev:
<?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/login.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=device-dpi"/>
        <title>Guacamole 0.6.0</title>
    </head>

    <body>

        <div id="login-ui" style="display: none">
            <div id="login-dialog-middle">

                <div id="login-dialog">

                    <p id="login-error"></p>

                    <form id="login-form" action="#" method="post">

                        <div id="login-fields">
                            <table>
                                <tr>
                                    <th>Username</th>
                                    <td><input type="text" name="username" id="username" autofocus="autofocus"/></td>
                                </tr>
                                <tr>
                                    <th>Password</th>
                                    <td><input type="password" name="password" id="password"/></td>
                                </tr>
                            </table>

                            <img class="logo" src="images/guacamole-logo-64.png" alt=""/>
                        </div>

                        <div id="buttons">
                            <input type="submit" name="login" id="login" value="Login"/>
                        </div>

                    </form>
                </div>

            </div>
        </div>

        <!-- Connection list UI -->
        <div id="connection-list-ui" style="display: none">

            <div id="logout-panel">
                <button id="logout">Logout</button>
            </div>
            
            <h1>
                <img class="logo" src="images/guacamole-logo-64.png" alt=""/>
                Available Connections
            </h1>
            
            <table class="connections">
                <thead>
                    <tr>
                        <th class="protocol"> </th>
                        <th class="name">Name</th>
                    </tr>
                </thead>
                <tbody id="connections-tbody">
                </tbody>
            </table>

        </div>

        <div id="version-dialog">
            Guacamole 0.6.0
        </div>

        <script type="text/javascript" src="scripts/connections.js"></script>

        <!-- Init -->
        <script type="text/javascript"> /* <![CDATA[ */

            // Constructs the URL for a client which connects to the connection
            // with the given id.
            function getClientURL(id) {
                
                // Construct URL for client with given id
                return "client.xhtml?id=" + encodeURIComponent(id);
                
            }

            // Resets the interface such that the login UI is displayed if
            // the user is not authenticated (or authentication fails) and
            // the connection list UI (or the client for the only available
            // connection, if there is only one) is displayed if the user is
            // authenticated.
            function resetUI() {

                // Get parameters from query string
                var parameters = window.location.search.substring(1);

                var configs;
                try {
                    configs = getConfigList(parameters);
                }
                catch (e) {

                    // Show login UI if unable to get configs
                    loginUI.style.display = "";
                    connectionListUI.style.display = "none";

                    return;

                }

                // If only one connection, redirect to that.
                if (configs.length == 1) {
                    window.location.href = getClientURL(configs[0].id);
                    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");

                    var protocolIcon = document.createElement("div");
                    protocolIcon.className = "protocol icon " + configs[i].protocol;

                    // Set CSS
                    protocol.className = "protocol";
                    id.className = "name";

                    // Create link to client
                    var clientLink = document.createElement("a");
                    clientLink.setAttribute("href", getClientURL(configs[i].id));

                    // Set cell contents
                    protocol.appendChild(protocolIcon);
                    //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");
            var logout = document.getElementById("logout");
            var username = document.getElementById("username");
            var password = document.getElementById("password");

            logout.onclick = function() {
                window.location.href = "logout";
            };

            loginForm.onsubmit = function() {

                // Get parameters from query string
                var parameters = window.location.search.substring(1);

                // Get username and password from form
                var data =
                       "username=" + encodeURIComponent(username.value)
                    + "&password=" + encodeURIComponent(password.value)

                // Include query parameters in submission data
                if (parameters) data += "&" + parameters;

                try {

                    // Log in
                    var xhr = new XMLHttpRequest();
                    xhr.open("POST", "login", false);
                    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    xhr.send(data);

                    // Handle failures
                    if (xhr.status != 200)
                        throw new Error("Invalid login");

                    // Ensure username/password fiels are blurred after submit
                    username.blur();
                    password.blur();

                    resetUI();

                }
                catch (e) {

                    var loginError = document.getElementById("login-error");

                    // Display error, reset and refocus password field
                    loginError.textContent = e.message;
                    password.value = "";
                    password.focus();

                    return false;

                }

                // On success, hide loginUI, get and show connection list.
                return false;

            }

            // Turn off autocorrect and autocapitalization on usename 
            username.setAttribute("autocorrect", "off");
            username.setAttribute("autocapitalize", "off");

            resetUI();

            /* ]]> */ </script>

    </body>

</html>