mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 12:16:49 +00:00
A stopped VM, an unreachable or unsupported console and a disabled serial console rendered the lite VNC page under the error: it connected to novncd anyway, showed "Something went wrong" and offered keys, Scale and Send CtrlAltDel for a console that was not there. A refused console was a bare text 403 inside the popup. - console-error.html: the console shell with the VM's name and the reason, no menu and no script; a refused or unknown VM gets it with 403 and without the VM's name, as before for everyone (no superuser exception). - The view signs the console token only for a page that connects. - console-menu.html: the Send key(s) menu and Fullscreen, included by the console pages; the serial page lists only the keys it sends (the VNC groups did nothing there). - Every console window is titled "<VM> - Console". - The lite page no longer takes a VNC password from its link. - The shell lost its 850px x 600px corner radius (a grey arc on the serial and error pages) and spans the window (container-fluid).
207 lines
No EOL
7.2 KiB
HTML
Executable file
207 lines
No EOL
7.2 KiB
HTML
Executable file
{% extends "console-base.html" %}
|
|
{% load i18n %}
|
|
{% load static %}
|
|
|
|
{% block head %}
|
|
<!--
|
|
noVNC example: lightweight example using minimal UI and features
|
|
This is a self-contained file which doesn't import WebUtil or external CSS.
|
|
Copyright (C) 2019 The noVNC Authors
|
|
noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
|
|
This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
|
|
Connect parameters are provided in query string:
|
|
http://example.com/?scale=true (the proxy host, port and path come from the server)
|
|
-->
|
|
<!-- Stylesheets -->
|
|
<link rel="stylesheet" href='{% static "js/novnc/app/styles/lite.css" %}'>
|
|
|
|
<!-- actual script modules -->
|
|
<script type="module" crossorigin="anonymous">
|
|
// RFB holds the API to connect and communicate with a VNC server
|
|
import RFB from '{% static "js/novnc/core/rfb.js" %}';
|
|
import { bindKeyAction, bindSendKeys } from '{% static "js/console_keys.js" %}';
|
|
|
|
let rfb;
|
|
let desktopName;
|
|
|
|
// When this function is called we have
|
|
// successfully connected to a server
|
|
function connectedToServer(e) {
|
|
status("Connected to " + desktopName);
|
|
}
|
|
|
|
// This function is called when we are disconnected
|
|
function disconnectedFromServer(e) {
|
|
if (e.detail.clean) {
|
|
status("Disconnected");
|
|
} else {
|
|
status("Something went wrong, connection is closed");
|
|
}
|
|
}
|
|
|
|
// When this function is called, the server requires
|
|
// credentials to authenticate
|
|
function credentialsAreRequired(e) {
|
|
const password = prompt("Password Required:");
|
|
rfb.sendCredentials({ password: password });
|
|
}
|
|
|
|
// When this function is called we have received
|
|
// a desktop name from the server
|
|
function updateDesktopName(e) {
|
|
desktopName = e.detail.name;
|
|
}
|
|
|
|
function fullscreen() {
|
|
if (document.fullscreenElement || // alternative standard method
|
|
document.mozFullScreenElement || // currently working methods
|
|
document.webkitFullscreenElement ||
|
|
document.msFullscreenElement) {
|
|
if (document.exitFullscreen) {
|
|
document.exitFullscreen();
|
|
} else if (document.mozCancelFullScreen) {
|
|
document.mozCancelFullScreen();
|
|
} else if (document.webkitExitFullscreen) {
|
|
document.webkitExitFullscreen();
|
|
} else if (document.msExitFullscreen) {
|
|
document.msExitFullscreen();
|
|
}
|
|
} else {
|
|
const el = document.documentElement;
|
|
const request = el.requestFullscreen ||
|
|
el.mozRequestFullScreen ||
|
|
el.webkitRequestFullscreen ||
|
|
el.msRequestFullscreen;
|
|
if (request) {
|
|
request.call(el).catch(() => {});
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
document.addEventListener('fullscreenchange', () => {
|
|
if (document.fullscreenElement) {
|
|
if ('keyboard' in navigator && typeof navigator.keyboard.lock === 'function') {
|
|
navigator.keyboard.lock(['AltLeft', 'AltRight', 'Tab', 'Escape']).catch(() => {});
|
|
}
|
|
} else {
|
|
if ('keyboard' in navigator && typeof navigator.keyboard.unlock === 'function') {
|
|
navigator.keyboard.unlock();
|
|
}
|
|
}
|
|
});
|
|
|
|
function machineShutdown() {
|
|
rfb.machineShutdown();
|
|
}
|
|
function machineReboot() {
|
|
rfb.machineReboot();
|
|
}
|
|
function machineReset() {
|
|
rfb.machineReset();
|
|
}
|
|
|
|
// Show a status text in the top bar
|
|
function status(text) {
|
|
document.getElementById('noVNC_status').textContent = text;
|
|
}
|
|
|
|
bindKeyAction('machineShutdownButton', machineShutdown);
|
|
bindKeyAction('machineRebootButton', machineReboot);
|
|
bindKeyAction('machineResetButton', machineReset);
|
|
bindKeyAction('fullscreen_button', fullscreen);
|
|
// fit the remote screen to the window, or show it 1:1 with scrollbars
|
|
bindKeyAction('scale_button', () => {
|
|
rfb.scaleViewport = !rfb.scaleViewport;
|
|
const link = document.querySelector('#scale_button a');
|
|
link.classList.toggle('active', rfb.scaleViewport);
|
|
link.setAttribute('aria-pressed', rfb.scaleViewport);
|
|
});
|
|
|
|
bindSendKeys(() => rfb);
|
|
|
|
// novncd behind the panel's own address (nginx's /novncd/), never a host
|
|
// from the link: the page sends it a console token
|
|
const host = window.location.hostname;
|
|
let port = window.location.port;
|
|
|
|
// the VNC password, for a user who may open the console without it;
|
|
// otherwise the server asks for it (credentialsrequired)
|
|
{% if perms.instances.passwordless_console and console_passwd %}
|
|
const credentials = { password: '{{ console_passwd|escapejs }}' };
|
|
{% else %}
|
|
const credentials = {};
|
|
{% endif %}
|
|
|
|
const path = 'novncd/';
|
|
|
|
// | | | | | |
|
|
// | | | Connect | | |
|
|
// v v v v v v
|
|
|
|
status("Connecting");
|
|
|
|
// Build the websocket URL used to connect
|
|
let url;
|
|
if (window.location.protocol === "https:") {
|
|
url = 'wss';
|
|
} else {
|
|
url = 'ws';
|
|
}
|
|
url += '://' + host;
|
|
if (port) {
|
|
url += ':' + port;
|
|
}
|
|
if (path) {
|
|
url += path.startsWith('/') ? path : ('/' + path);
|
|
} else {
|
|
url += '/';
|
|
}
|
|
const token = '{{ token|escapejs }}';
|
|
if (token) {
|
|
url += (url.includes('?') ? '&' : '?') + 'token=' + encodeURIComponent(token);
|
|
}
|
|
|
|
// Creating a new RFB object will start a new connection
|
|
rfb = new RFB(document.getElementById('noVNC_container'), url,
|
|
{ credentials: credentials });
|
|
|
|
// Add listeners to important events from the RFB module
|
|
rfb.addEventListener("connect", connectedToServer);
|
|
rfb.addEventListener("disconnect", disconnectedFromServer);
|
|
rfb.addEventListener("credentialsrequired", credentialsAreRequired);
|
|
rfb.addEventListener("desktopname", updateDesktopName);
|
|
|
|
// Set parameters that can be changed on an active connection
|
|
rfb.scaleViewport = {{ scale|yesno:"true,false" }};
|
|
rfb.viewOnly = {{ view_only|yesno:"true,false" }};
|
|
rfb.resizeSession = {{ resize_session|yesno:"true,false" }};
|
|
rfb.clipViewport = {{ clip_viewport|yesno:"true,false" }};
|
|
|
|
</script>
|
|
{% endblock %}
|
|
|
|
{% block navbarmenu %}
|
|
{% include "console-menu.html" %}
|
|
<li class="nav-item" id="scale_button">
|
|
<a class="nav-link{% if scale %} active{% endif %}" href="#" role="button" aria-pressed="{{ scale|yesno:"true,false" }}">{% trans "Scale" %}</a>
|
|
</li>
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<div id="noVNC_status_bar">
|
|
<div id="noVNC_left_dummy_elem"></div>
|
|
<div id="noVNC_status">{% trans 'Loading' %}</div>
|
|
<div id="noVNC_buttons">
|
|
<input type="button" value="Send CtrlAltDel" id="sendCtrlAltDelButton" class="noVNC_shown">
|
|
<span id="noVNC_power_buttons" class="noVNC_hidden">
|
|
<input type="button" value="Shutdown" id="machineShutdownButton">
|
|
<input type="button" value="Reboot" id="machineRebootButton">
|
|
<input type="button" value="Reset" id="machineResetButton">
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<div id="noVNC_container">
|
|
<!-- This is where the remote screen will appear -->
|
|
</div>
|
|
{% endblock %} |