Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify the HTML5 canvas-based remote consoles under a single endpoint #5761

Merged
merged 4 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions app/assets/javascripts/remote_consoles/webmks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,41 @@
//= require_tree ../locale
//= require gettext/all

/* global WMKS */

$(function() {
// WebMKS cannot be a part of the asset pipeline, therefore, it has to be loaded with this hack
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = '/webmks/css/wmks-all.css';
document.head.appendChild(link);

var script = document.createElement('script');
var WEBMKS_JS_PATH = '/webmks/wmks.min.js';
// Test if the file exists under the given path
fetch(WEBMKS_JS_PATH, {
method: 'HEAD',
cache: 'no-cache',
}).then(function(response) {
return new Promise(function(resolve, reject) {
if (!response.ok) {
// Reject the promise if there's any error with the request, i.e. the file doesn't exist
reject();
} else {
// Create a <link> tag that loads the CSS file and append it to the page
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = '/webmks/css/wmks-all.css';
document.head.appendChild(link);

script.onload = function() {
// Create a <script> tag that loads the JS file
var script = document.createElement('script');
script.src = WEBMKS_JS_PATH;
// Set an onload function that resolves the promise
script.onload = function() {
resolve();
};
// Append the <script> tag to the page
document.head.appendChild(script);
}
});
}).then(function() {
// Set up the remote console after the JS is loaded
var host = window.location.hostname;
var encrypt = window.location.protocol === 'https:';
var port = encrypt ? 443 : 80;
Expand All @@ -35,7 +59,6 @@ $(function() {
var wmks = WMKS.createWMKS('remote-console', options).register(WMKS.CONST.Events.CONNECTION_STATE_CHANGE, function(event, data) {
if (data.state === WMKS.CONST.ConnectionState.CONNECTED) {
$('#connection-status').text(__('Connected'));
console.log('connection state change: connected');
}
});

Expand All @@ -48,8 +71,7 @@ $(function() {
$('#keymap').on('change', function() {
wmks.setOption('keyboardLayoutId', this.value);
});
};

script.src = '/webmks/wmks.min.js';
document.head.appendChild(script);
}).catch(function() {
$('#remote-console').html(__('The appliance has no access to the assets required to run the WebMKS console. For more info please see the documentation.'));
});
});
2 changes: 0 additions & 2 deletions app/controllers/ops_controller/settings/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,6 @@ def settings_get_form_vars
session[:selected_roles] = new[:server][:role].split(",") if !new[:server].nil? && !new[:server][:role].nil?
end
@host_choices = session[:host_choices]
new[:server][:remote_console_type] = params[:console_type] if params[:console_type]

settings_get_form_vars_sync_ntp

Expand Down Expand Up @@ -836,7 +835,6 @@ def settings_set_form_vars_server
@edit[:current][:server][:role] = @edit[:current][:server][:role] ? @edit[:current][:server][:role].split(",").sort.join(",") : ""
@edit[:current][:server][:timezone] = "UTC" if @edit[:current][:server][:timezone].blank?
@edit[:current][:server][:locale] = "default" if @edit[:current][:server][:locale].blank?
@edit[:current][:server][:remote_console_type] ||= "VNC"
@edit[:current][:smtp][:enable_starttls_auto] = GenericMailer.default_for_enable_starttls_auto if @edit[:current][:smtp][:enable_starttls_auto].nil?
@edit[:current][:smtp][:openssl_verify_mode] ||= "none"
@edit[:current][:ntp] ||= {}
Expand Down
13 changes: 4 additions & 9 deletions app/controllers/vm_remote.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
module VmRemote
extend ActiveSupport::Concern

# Launch a VM console
def console
console_type = ::Settings.server.remote_console_type.downcase
params[:task_id] ? console_after_task(console_type) : console_before_task(console_type)
def vmrc_console
params[:task_id] ? console_after_task('vmrc') : console_before_task('vmrc')
end
alias vmrc_console console # VMRC needs its own URL for RBAC checking

def launch_cockpit
vm = identify_record(params[:id], VmOrTemplate)
Expand All @@ -25,7 +22,6 @@ def html5_console
end

def launch_vmrc_console
console_type = ::Settings.server.remote_console_type.downcase
@vm = @record = identify_record(params[:id], VmOrTemplate)
host = @record.ext_management_system.hostname || @record.ext_management_system.ipaddress
options = {
Expand All @@ -37,7 +33,7 @@ def launch_vmrc_console
:name => @record.name,
:vmrc_uri => build_vmrc_uri(host, @record.ems_ref, params[:ticket])
}
render :template => "vm_common/console_#{console_type}",
render :template => "vm_common/console_vmrc",
:layout => false,
:locals => options
end
Expand Down Expand Up @@ -70,7 +66,6 @@ def console_before_task(console_type)
record = identify_record(params[:id], VmOrTemplate)
ems = record.ext_management_system
if ems.class.ems_type == 'vmwarews'
ticket_type = :vnc if console_type == 'html5'
begin
ems.validate_remote_console_vmrc_support
rescue MiqException::RemoteConsoleNotSupportedError => e
Expand Down Expand Up @@ -104,7 +99,7 @@ def console_after_task(console_type)
url = if miq_task.task_results[:remote_url]
miq_task.task_results[:remote_url]
else
console_action = %w[html5 webmks].include?(console_type) ? 'launch_html5_console' : 'launch_vmrc_console'
console_action = %w[html5].include?(console_type) ? 'launch_html5_console' : 'launch_vmrc_console'
url_for_only_path(:controller => controller_name,
:action => console_action,
:id => j(params[:id]),
Expand Down
21 changes: 0 additions & 21 deletions app/helpers/application_helper/button/vm_console.rb

This file was deleted.

12 changes: 12 additions & 0 deletions app/helpers/application_helper/button/vm_html5_console.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class ApplicationHelper::Button::VmHtml5Console < ApplicationHelper::Button::Basic
needs :@record

def visible?
%w[vnc webmks spice].any? { |type| @record.send(:console_supported?, type) }
end

def disabled?
@error_message = _('The web-based VNC console is not available because the VM is not powered on') if @record.current_state != 'on'
@error_message.present?
end
end
4 changes: 2 additions & 2 deletions app/helpers/application_helper/button/vm_vmrc_console.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class ApplicationHelper::Button::VmVmrcConsole < ApplicationHelper::Button::VmConsole
class ApplicationHelper::Button::VmVmrcConsole < ApplicationHelper::Button::Basic
needs :@record

def visible?
console_supports_type?('VMRC')
@record.vendor == 'vmware'
end

def disabled?
Expand Down
28 changes: 0 additions & 28 deletions app/helpers/application_helper/button/vm_vnc_console.rb

This file was deleted.

35 changes: 0 additions & 35 deletions app/helpers/application_helper/button/vm_webmks_console.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,10 @@ def self.included(included_class)
included_class.button(
:vm_vnc_console,
'pficon pficon-screen fa-lg',
N_('Open a web-based VNC or SPICE console for this VM'),
N_('Open a web-based HTML5 console for this VM'),
N_('VM Console'),
:url => "html5_console",
:klass => ApplicationHelper::Button::VmVncConsole),
included_class.button(
:vm_webmks_console,
'pficon pficon-screen fa-lg',
N_('Open a web-based WebMKS console for this VM'),
N_('VM Console'),
:url => "console",
:confirm => N_("Open a WebMKS console for this VM"),
:klass => ApplicationHelper::Button::VmWebmksConsole
),
:klass => ApplicationHelper::Button::VmHtml5Console),
included_class.button(
:cockpit_console,
'pficon pficon-screen fa-lg',
Expand Down
20 changes: 6 additions & 14 deletions app/helpers/application_helper/toolbar/x_vm_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,27 +255,19 @@ class ApplicationHelper::Toolbar::XVmCenter < ApplicationHelper::Toolbar::Basic
N_('Access'),
:items => [
button(
:vm_webmks_console,
:vm_html5_console,
'pficon pficon-screen fa-lg',
N_('Open a web-based WebMKS console for this VM'),
N_('VM Console'),
:url => "console",
:confirm => N_("Open a WebMKS console for this VM"),
:klass => ApplicationHelper::Button::VmWebmksConsole),
button(
:vm_vnc_console,
'pficon pficon-screen fa-lg',
N_('Open a web-based VNC or SPICE console for this VM'),
N_('Open a web-based HTML5 console for this VM'),
N_('VM Console'),
:url => "html5_console",
:klass => ApplicationHelper::Button::VmVncConsole),
:klass => ApplicationHelper::Button::VmHtml5Console),
button(
:vm_vmrc_console,
'pficon pficon-screen fa-lg',
N_('Open a web-based VMRC console for this VM. This requires that VMRC is pre-configured to work in your browser.'),
N_('VM Console'),
N_('Open a VMRC console for this VM. This requires that VMRC is installed and pre-configured to work in your browser.'),
N_('VMRC Console'),
:url => "vmrc_console",
:confirm => N_("Opening a VM web-based VMRC console requires that VMRC is pre-configured to work in your browser. Are you sure?"),
:confirm => N_("Opening a VMRC console requires that VMRC is installed and pre-configured to work in your browser. Are you sure?"),
:klass => ApplicationHelper::Button::VmVmrcConsole),
button(
:cockpit_console,
Expand Down
8 changes: 0 additions & 8 deletions app/helpers/vmware_console_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ module VmwareConsoleHelper
['Swiss‐German', "de-CH"]
].freeze

# Helper method for retrieving vmware remote console options for a <select> field
def vmware_remote_console_items(webmks)
items = [[_("VNC"), "VNC"], [_("VMware VMRC Plugin"), "VMRC"]]
# Add the item if the required assets are present or the webmks console is already selected
items.unshift([_("VMware WebMKS"), "WebMKS"]) if webmks_assets_provided? || webmks
items
end

def webmks_assets_provided?
Rails.root.join('public', 'webmks').exist?
end
Expand Down
14 changes: 0 additions & 14 deletions app/views/ops/_settings_server_tab.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,6 @@
:javascript
miqSelectPickerEvent('repository_scanning_defaultsmartproxy', "#{url}")
%hr
%h3
= _("VMware Console Support")
.form-horizontal
.form-group
%label.col-md-2.control-label
= _("Use")
.col-md-8
= select_tag('console_type',
options_for_select(vmware_remote_console_items(@edit[:new][:server][:remote_console_type] == 'WebMKS'),
:selected => @edit[:new][:server][:remote_console_type]),
:class => "selectpicker")
:javascript
miqSelectPickerEvent('console_type', "#{url}")
%hr
%h3
= _("NTP Servers")
.form-horizontal
Expand Down
3 changes: 0 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3011,7 +3011,6 @@
advanced_settings
accordion_select
button
console
edit_vm
resize_vm
resize_field_changed
Expand Down Expand Up @@ -3110,7 +3109,6 @@
accordion_select
advanced_settings
button
console
edit_vm
event_logs
explorer
Expand Down Expand Up @@ -3203,7 +3201,6 @@
accordion_select
advanced_settings
button
console
drift_all
drift_differences
drift_history
Expand Down
Loading