diff --git a/src/sunstone/public/app/tabs/provision-tab/vms/list.js b/src/sunstone/public/app/tabs/provision-tab/vms/list.js index 9a3d50ef31..c44a5f15a9 100644 --- a/src/sunstone/public/app/tabs/provision-tab/vms/list.js +++ b/src/sunstone/public/app/tabs/provision-tab/vms/list.js @@ -27,6 +27,7 @@ define(function(require) { var Sunstone = require("sunstone"); var TemplateUtils = require("utils/template-utils"); var VMsTableUtils = require('../../vms-tab/utils/datatable-common'); + var RemoteActions = require('utils/remote-actions'); var TemplateConfirmPoweroff = require("hbs!./confirm_poweroff"); var TemplateConfirmReboot = require("hbs!./confirm_reboot"); @@ -792,18 +793,30 @@ define(function(require) { }, success: function(_, response){ if (OpenNebulaVM.isVNCSupported(vm_data)) { - - var urlAndLink = Vnc.getURLAndLink(response); + var link = RemoteActions.getLink(response,{ + port: Config.vncProxyPort, + connnection_type: 'vnc', + extra_params: [ + 'port=' + Config.vncProxyPort, + 'encrypt=' + Config.vncWSS, + !Config.requestVNCPassword && 'password=' + response.password + ] + }); // Open in a new tab the noVNC connection - window.open(urlAndLink.link); + window.open(link); button.removeAttr("disabled"); } else if (OpenNebulaVM.isSPICESupported(vm_data)) { - var urlAndLink = Spice.getURLAndLink(response); - // Open in a new tab the noVNC connection - window.open(urlAndLink.link); - - button.removeAttr("disabled"); + var link = RemoteActions.getLink(response, { + port: Config.vncProxyPort, + connnection_type: 'spice', + extra_params: [ + 'password=' + response.password, + 'encrypt=' + config.user_config.vnc_wss, + ] + }); + // Open in a new tab the SPICE connection + window.open(link); } else { Notifier.notifyError("The remote console is not enabled for this VM"); } diff --git a/src/sunstone/public/app/tabs/vms-tab/actions.js b/src/sunstone/public/app/tabs/vms-tab/actions.js index 9f795b5e7c..1d4a2bad51 100644 --- a/src/sunstone/public/app/tabs/vms-tab/actions.js +++ b/src/sunstone/public/app/tabs/vms-tab/actions.js @@ -22,6 +22,7 @@ define(function(require) { var OpenNebulaVM = require('opennebula/vm'); var CommonActions = require('utils/common-actions'); var Files = require('utils/files'); + var RemoteActions = require('utils/remote-actions'); var CREATE_APP_DIALOG_ID = require('tabs/marketplaceapps-tab/form-panels/create/formPanelId'); var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId'); @@ -260,7 +261,7 @@ define(function(require) { type: "single", call: OpenNebulaVM.vnc, callback: function(request, response) { - var link = getLink(response,{ + var link = RemoteActions.getLink(response,{ port: Config.vncProxyPort, connnection_type: 'vnc', extra_params: [ @@ -269,8 +270,8 @@ define(function(require) { !Config.requestVNCPassword && 'password=' + response.password ] }); - // Open in a new tab the noVNC connection - window.open(link); + // Open in a new tab the noVNC connection + window.open(link); }, error: function(req, resp) { Notifier.onError(req, resp); @@ -292,13 +293,13 @@ define(function(require) { callback: function(request, response) { response["vm_name"] = request.request.data[0].extra_param; var fireedge_endpoint = new URL(Config.publicFireedgeEndpoint); - var link = getLink(response,{ + var link = RemoteActions.getLink(response,{ host: fireedge_endpoint.hostname, port: fireedge_endpoint.port, connnection_type: 'vmrc', extra_path: '/fireedge/vmrc/' + response.data.ticket, }); - // Open in a new tab the noVNC connection + // Open in a new tab the VMRC connection window.open(link); }, error: function(req, resp) { @@ -318,7 +319,7 @@ define(function(require) { type: "single", call: OpenNebulaVM.vnc, callback: function(request, response) { - var link = getLink(response, { + var link = RemoteActions.getLink(response, { port: Config.vncProxyPort, connnection_type: 'spice', extra_params: [ @@ -326,7 +327,7 @@ define(function(require) { 'encrypt=' + config.user_config.vnc_wss, ] }); - // Open in a new tab the noVNC connection + // Open in a new tab the SPICE connection window.open(link); }, error: function(req, resp) { @@ -371,7 +372,7 @@ define(function(require) { type: "single", call: OpenNebulaVM.guac, callback: function(_, response) { - var link = getLink(response, { + var link = RemoteActions.getLink(response, { connnection_type: 'guac', extra_path: '/fireedge/guacamole' }); @@ -460,46 +461,5 @@ define(function(require) { }; - /** - * - * @param {Object} response Callback response with the token and info - * @param {Object} options - * @returns - */ - function getLink(response, options){ - options = $.extend({ - host: undefined, - port: undefined, - connnection_type: '', - extra_path: '', - extra_params: [] - }, options); - - var params = options.extra_params.concat([ - response.token && 'token=' + response.token, - response.info && 'info=' + response.info - ]).filter(Boolean); - - var endpoint = new URL(window.location.href); - var websocketProtocol = endpoint.protocol === 'https:' ? 'wss:' : 'ws:'; - - var websocket = websocketProtocol + '//'; - - if (options.host && options.port) - websocket += options.host + ':' + options.port - else if (options.port) - websocket += endpoint.hostname + ':' + options.port - else - websocket += endpoint.host; - - websocket += options.extra_path + '?' + params.join("&"); - - var encoded_socket = btoa(websocket); - - var link = endpoint.origin + "/" + options.connnection_type + "?socket=" + encoded_socket; - - return link; - } - return _actions; }); diff --git a/src/sunstone/public/app/utils/remote-actions.js b/src/sunstone/public/app/utils/remote-actions.js index 17533c1562..89e5a549c6 100644 --- a/src/sunstone/public/app/utils/remote-actions.js +++ b/src/sunstone/public/app/utils/remote-actions.js @@ -290,6 +290,47 @@ define(function(require) { }) } + /** + * + * @param {Object} response Callback response with the token and info + * @param {Object} options + * @returns + */ + function _getLink(response, options){ + options = $.extend({ + host: undefined, + port: undefined, + connnection_type: '', + extra_path: '', + extra_params: [] + }, options); + + var params = options.extra_params.concat([ + response.token && 'token=' + response.token, + response.info && 'info=' + response.info + ]).filter(Boolean); + + var endpoint = new URL(window.location.href); + var websocketProtocol = endpoint.protocol === 'https:' ? 'wss:' : 'ws:'; + + var websocket = websocketProtocol + '//'; + + if (options.host && options.port) + websocket += options.host + ':' + options.port + else if (options.port) + websocket += endpoint.hostname + ':' + options.port + else + websocket += endpoint.host; + + websocket += options.extra_path + '?' + params.join("&"); + + var encoded_socket = btoa(websocket); + + var link = endpoint.origin + "/" + options.connnection_type + "?socket=" + encoded_socket; + + return link; + } + return { 'callSpice': _callSpice, 'callVNC': _callVNC, @@ -301,6 +342,7 @@ define(function(require) { 'callGuacRDP': _callGuacRDP, 'callGuacVNC': _callGuacVNC, 'renderActionsHtml': _renderActionsHtml, - 'bindActionsToContext': _bindActionsToContext + 'bindActionsToContext': _bindActionsToContext, + 'getLink': _getLink }; });