Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.4k
noVNC console integration#3967
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -41,6 +41,12 @@ | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.web.context.support.SpringBeanAutowiringSupport; | ||
| import com.cloud.vm.VmDetailConstants; | ||
| import com.google.gson.Gson; | ||
| import com.google.gson.GsonBuilder; | ||
| import com.cloud.consoleproxy.ConsoleProxyManager; | ||
| import com.cloud.exception.PermissionDeniedException; | ||
| import com.cloud.host.HostVO; | ||
| import com.cloud.hypervisor.Hypervisor; | ||
| @@ -59,10 +65,7 @@ | ||
| import com.cloud.vm.UserVmDetailVO; | ||
| import com.cloud.vm.VirtualMachine; | ||
| import com.cloud.vm.VirtualMachineManager; | ||
| import com.cloud.vm.VmDetailConstants; | ||
| import com.cloud.vm.dao.UserVmDetailsDao; | ||
| import com.google.gson.Gson; | ||
| import com.google.gson.GsonBuilder; | ||
| /** | ||
| * Thumbnail access : /console?cmd=thumbnail&vm=xxx&w=xxx&h=xxx | ||
| @@ -478,7 +481,12 @@ private String composeConsoleAccessUrl(String rootUrl, VirtualMachine vm, HostVO | ||
| param.setClientTunnelSession(parsedHostInfo.third()); | ||
| } | ||
| sb.append("/ajax?token=" + encryptor.encryptObject(ConsoleProxyClientParam.class, param)); | ||
| if (param.getHypervHost() != null || !ConsoleProxyManager.NoVncConsoleDefault.value()) { | ||
| sb.append("/ajax?token=" + encryptor.encryptObject(ConsoleProxyClientParam.class, param)); | ||
| } else { | ||
| sb.append("/resource/noVNC/vnc_lite.html?port=" + ConsoleProxyManager.DEFAULT_NOVNC_PORT + "&token=" | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wanted a simpler, minimalist UI, can add this when we get multi lingual keyboard working | ||
| + encryptor.encryptObject(ConsoleProxyClientParam.class, param)); | ||
| } | ||
| // for console access, we need guest OS type to help implement keyboard | ||
| long guestOs = vm.getGuestOSId(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| package com.cloud.consoleproxy; | ||
| import java.io.IOException; | ||
| import java.util.Map; | ||
| import javax.servlet.ServletException; | ||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpServletResponse; | ||
| import com.cloud.consoleproxy.util.Logger; | ||
| import org.eclipse.jetty.server.Request; | ||
| import org.eclipse.jetty.websocket.api.Session; | ||
| import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; | ||
| import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; | ||
| import org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame; | ||
| import org.eclipse.jetty.websocket.api.annotations.WebSocket; | ||
| import org.eclipse.jetty.websocket.api.extensions.Frame; | ||
| import org.eclipse.jetty.websocket.server.WebSocketHandler; | ||
| import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; | ||
| @WebSocket | ||
| public class ConsoleProxyNoVNCHandler extends WebSocketHandler { | ||
| private ConsoleProxyNoVncClient viewer; | ||
| private static final Logger s_logger = Logger.getLogger(ConsoleProxyNoVNCHandler.class); | ||
| public ConsoleProxyNoVNCHandler() { | ||
| super(); | ||
| } | ||
| @Override | ||
| public void configure(WebSocketServletFactory webSocketServletFactory) { | ||
| webSocketServletFactory.register(ConsoleProxyNoVNCHandler.class); | ||
| } | ||
| @Override | ||
| public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) | ||
| throws IOException, ServletException { | ||
| if (this.getWebSocketFactory().isUpgradeRequest(request, response)) { | ||
| response.addHeader("Sec-WebSocket-Protocol", "binary"); | ||
| if (this.getWebSocketFactory().acceptWebSocket(request, response)) { | ||
| baseRequest.setHandled(true); | ||
| return; | ||
| } | ||
| if (response.isCommitted()) { | ||
| return; | ||
| } | ||
| } | ||
| super.handle(target, baseRequest, request, response); | ||
| } | ||
| @OnWebSocketConnect | ||
| public void onConnect(final Session session) throws IOException, InterruptedException { | ||
| String queries = session.getUpgradeRequest().getQueryString(); | ||
| Map<String, String> queryMap = ConsoleProxyHttpHandlerHelper.getQueryMap(queries); | ||
| String host = queryMap.get("host"); | ||
| String portStr = queryMap.get("port"); | ||
| String sid = queryMap.get("sid"); | ||
| String tag = queryMap.get("tag"); | ||
| String ticket = queryMap.get("ticket"); | ||
| String ajaxSessionIdStr = queryMap.get("sess"); | ||
| String console_url = queryMap.get("consoleurl"); | ||
| String console_host_session = queryMap.get("sessionref"); | ||
| String vm_locale = queryMap.get("locale"); | ||
| String hypervHost = queryMap.get("hypervHost"); | ||
| String username = queryMap.get("username"); | ||
| String password = queryMap.get("password"); | ||
| if (tag == null) | ||
| tag = ""; | ||
| long ajaxSessionId = 0; | ||
| int port; | ||
| if (host == null || portStr == null || sid == null) | ||
| throw new IllegalArgumentException(); | ||
| try { | ||
| port = Integer.parseInt(portStr); | ||
| } catch (NumberFormatException e) { | ||
| s_logger.warn("Invalid number parameter in query string: " + portStr); | ||
| throw new IllegalArgumentException(e); | ||
| } | ||
| if (ajaxSessionIdStr != null) { | ||
| try { | ||
| ajaxSessionId = Long.parseLong(ajaxSessionIdStr); | ||
| } catch (NumberFormatException e) { | ||
| s_logger.warn("Invalid number parameter in query string: " + ajaxSessionIdStr); | ||
| throw new IllegalArgumentException(e); | ||
| } | ||
| } | ||
| try { | ||
| ConsoleProxyClientParam param = new ConsoleProxyClientParam(); | ||
| param.setClientHostAddress(host); | ||
| param.setClientHostPort(port); | ||
| param.setClientHostPassword(sid); | ||
| param.setClientTag(tag); | ||
| param.setTicket(ticket); | ||
| param.setClientTunnelUrl(console_url); | ||
| param.setClientTunnelSession(console_host_session); | ||
| param.setLocale(vm_locale); | ||
| param.setHypervHost(hypervHost); | ||
| param.setUsername(username); | ||
| param.setPassword(password); | ||
| viewer = ConsoleProxy.getNoVncViewer(param, ajaxSessionIdStr, session); | ||
| } catch (Exception e) { | ||
| s_logger.warn("Failed to create viewer due to " + e.getMessage(), e); | ||
| return; | ||
| } | ||
| } | ||
| @OnWebSocketClose | ||
| public void onClose(Session session, int statusCode, String reason) throws IOException, InterruptedException { | ||
| ConsoleProxy.removeViewer(viewer); | ||
| } | ||
| @OnWebSocketFrame | ||
| public void onFrame(Frame f) throws IOException { | ||
| viewer.sendClientFrame(f); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be disabled by default at least until all hypervisors tested working properly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested it on KVM, VMware and Xen and it works fine!