Add logs to CPVM connection process (#8924)

* increment cpvm connection logs

* remove sourceIp variable

* increment cpvm connection logs

* extract duplicate error messages to variables

* change logs level from trace to debug in authenticateToVNCServer

* add logs in trace level inside of connection loop

* remove redundant trace log

* add logs to ConsoleProxyNoVNCHandler class

* retrieve client source IP

* add periods to log messages

* change log levels from warn to error inside of catch blocks

* add client IP to successful authentication log

* replace concatenation with String.format()

* remove String.format() and use log4j2 new features instead

* remove String.format() and use log4j2 new features instead

* apply Daan's suggestion

Co-authored-by: dahn <daan.hoogland@gmail.com>

* resolve conflicts

* fix logs with three parameters

* get correct client IP

* use log4j dependencies directly

* apply winterhazel's suggestion

Co-authored-by: Fabricio Duarte <fabricio.duarte.jr@gmail.com>

* remove log proxy

* address winterhazel's suggestions on ConsoleProxyNoVncClient class

* address winterhazel's suggestions on ConsoleProxyNoVNCHandler class

* address winterhazel's suggestions on ConsoleProxyNoVNCHandler class

Co-authored-by: Fabricio Duarte <fabricio.duarte.jr@gmail.com>

---------

Co-authored-by: dahn <daan.hoogland@gmail.com>
Co-authored-by: Fabricio Duarte <fabricio.duarte.jr@gmail.com>
This commit is contained in:
Bernardo De Marco Gonçalves 2024-09-09 15:39:42 -03:00 committed by GitHub
parent b068c68bff
commit 501d8c1e09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
30 changed files with 172 additions and 437 deletions

View File

@ -34,7 +34,16 @@ public class ConsoleProxyClientParam {
private String username;
private String password;
/**
* IP that has generated the console endpoint
*/
private String sourceIP;
/**
* IP of the client that has connected to the console
*/
private String clientIp;
private String websocketUrl;
private String sessionUuid;
@ -201,4 +210,12 @@ public class ConsoleProxyClientParam {
public void setSessionUuid(String sessionUuid) {
this.sessionUuid = sessionUuid;
}
public String getClientIp() {
return clientIp;
}
public void setClientIp(String clientIp) {
this.clientIp = clientIp;
}
}

View File

@ -21,10 +21,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class AjaxFIFOImageCache {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
private List<Integer> fifoQueue;
private Map<Integer, byte[]> cache;

View File

@ -39,17 +39,19 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.core.config.Configurator;
import org.eclipse.jetty.websocket.api.Session;
import com.cloud.consoleproxy.util.Logger;
import com.cloud.utils.PropertiesUtil;
import com.google.gson.Gson;
import com.sun.net.httpserver.HttpServer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
*
* ConsoleProxy, singleton class that manages overall activities in console proxy process. To make legacy code work, we still
*/
public class ConsoleProxy {
protected static Logger LOGGER = Logger.getLogger(ConsoleProxy.class);
protected static Logger LOGGER = LogManager.getLogger(ConsoleProxy.class);
public static final int KEYBOARD_RAW = 0;
public static final int KEYBOARD_COOKED = 1;
@ -280,7 +282,6 @@ public class ConsoleProxy {
public static void startWithContext(Properties conf, Object context, byte[] ksBits, String ksPassword, String password, Boolean isSourceIpCheckEnabled) {
setEncryptorPassword(password);
configLog4j();
Logger.setFactory(new ConsoleProxyLoggerFactory());
LOGGER.info("Start console proxy with context");
if (conf != null) {
@ -427,7 +428,6 @@ public class ConsoleProxy {
public static void main(String[] argv) {
standaloneStart = true;
configLog4j();
Logger.setFactory(new ConsoleProxyLoggerFactory());
InputStream confs = ConsoleProxy.class.getResourceAsStream("/conf/consoleproxy.properties");
Properties conf = new Properties();

View File

@ -32,10 +32,11 @@ import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ConsoleProxyAjaxHandler implements HttpHandler {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
public ConsoleProxyAjaxHandler() {
}

View File

@ -28,10 +28,11 @@ import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ConsoleProxyAjaxImageHandler implements HttpHandler {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
@Override
public void handle(HttpExchange t) throws IOException {

View File

@ -23,10 +23,11 @@ import javax.net.ssl.SSLServerSocket;
import com.sun.net.httpserver.HttpServer;
import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ConsoleProxyBaseServerFactoryImpl implements ConsoleProxyServerFactory {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
@Override
public void init(byte[] ksBits, String ksPassword) {

View File

@ -39,8 +39,16 @@ public class ConsoleProxyClientParam {
private String password;
private String websocketUrl;
/**
* IP that has generated the console endpoint
*/
private String sourceIP;
/**
* IP of the client that has connected to the console
*/
private String clientIp;
private String sessionUuid;
/**
@ -204,4 +212,12 @@ public class ConsoleProxyClientParam {
public void setClientProvidedExtraSecurityToken(String clientProvidedExtraSecurityToken) {
this.clientProvidedExtraSecurityToken = clientProvidedExtraSecurityToken;
}
public String getClientIp() {
return clientIp;
}
public void setClientIp(String clientIp) {
this.clientIp = clientIp;
}
}

View File

@ -24,10 +24,11 @@ import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ConsoleProxyCmdHandler implements HttpHandler {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
@Override
public void handle(HttpExchange t) throws IOException {

View File

@ -19,10 +19,11 @@ package com.cloud.consoleproxy;
import java.util.HashMap;
import java.util.Map;
import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ConsoleProxyHttpHandlerHelper {
protected static Logger LOGGER = Logger.getLogger(ConsoleProxyHttpHandlerHelper.class);
protected static Logger LOGGER = LogManager.getLogger(ConsoleProxyHttpHandlerHelper.class);
public static Map<String, String> getQueryMap(String query) {
String[] params = query.split("&");

View File

@ -1,104 +0,0 @@
// 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 com.cloud.consoleproxy.util.Logger;
import com.cloud.consoleproxy.util.LoggerFactory;
import org.apache.logging.log4j.LogManager;
public class ConsoleProxyLoggerFactory implements LoggerFactory {
public ConsoleProxyLoggerFactory() {
}
@Override
public Logger getLogger(Class<?> clazz) {
return new Log4jLogger(LogManager.getLogger(clazz));
}
public static class Log4jLogger extends Logger {
private org.apache.logging.log4j.Logger logger;
public Log4jLogger(org.apache.logging.log4j.Logger logger) {
this.logger = logger;
}
@Override
public boolean isTraceEnabled() {
return logger.isTraceEnabled();
}
@Override
public boolean isDebugEnabled() {
return logger.isDebugEnabled();
}
@Override
public boolean isInfoEnabled() {
return logger.isInfoEnabled();
}
@Override
public void trace(Object message) {
logger.trace(message);
}
@Override
public void trace(Object message, Throwable exception) {
logger.trace(message, exception);
}
@Override
public void info(Object message) {
logger.info(message);
}
@Override
public void info(Object message, Throwable exception) {
logger.info(message, exception);
}
@Override
public void debug(Object message) {
logger.debug(message);
}
@Override
public void debug(Object message, Throwable exception) {
logger.debug(message, exception);
}
@Override
public void warn(Object message) {
logger.warn(message);
}
@Override
public void warn(Object message, Throwable exception) {
logger.warn(message, exception);
}
@Override
public void error(Object message) {
logger.error(message);
}
@Override
public void error(Object message, Throwable exception) {
logger.error(message, exception);
}
}
}

View File

@ -24,7 +24,8 @@ import java.util.HashMap;
import java.util.Map;
import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;
//
@ -33,7 +34,7 @@ import org.apache.logging.log4j.core.config.Configurator;
// itself and the shell script will re-launch console proxy
//
public class ConsoleProxyMonitor {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
private String[] _argv;
private Map<String, String> _argMap = new HashMap<String, String>();

View File

@ -23,7 +23,8 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.websocket.api.Session;
@ -40,7 +41,7 @@ import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
public class ConsoleProxyNoVNCHandler extends WebSocketHandler {
private ConsoleProxyNoVncClient viewer = null;
protected Logger logger = Logger.getLogger(ConsoleProxyNoVNCHandler.class);
protected Logger logger = LogManager.getLogger(getClass());
public ConsoleProxyNoVNCHandler() {
super();
@ -82,15 +83,16 @@ public class ConsoleProxyNoVNCHandler extends WebSocketHandler {
String ticket = queryMap.get("ticket");
String displayName = queryMap.get("displayname");
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 consoleUrl = queryMap.get("consoleurl");
String consoleHostSession = queryMap.get("sessionref");
String vmLocale = queryMap.get("locale");
String hypervHost = queryMap.get("hypervHost");
String username = queryMap.get("username");
String password = queryMap.get("password");
String sourceIP = queryMap.get("sourceIP");
String websocketUrl = queryMap.get("websocketUrl");
String sessionUuid = queryMap.get("sessionUuid");
String clientIp = session.getRemoteAddress().getAddress().getHostAddress();
if (tag == null)
tag = "";
@ -104,7 +106,7 @@ public class ConsoleProxyNoVNCHandler extends WebSocketHandler {
try {
port = Integer.parseInt(portStr);
} catch (NumberFormatException e) {
logger.warn("Invalid number parameter in query string: " + portStr);
logger.error("Invalid port value in query string: {}. Expected a number.", portStr, e);
throw new IllegalArgumentException(e);
}
@ -112,12 +114,12 @@ public class ConsoleProxyNoVNCHandler extends WebSocketHandler {
try {
ajaxSessionId = Long.parseLong(ajaxSessionIdStr);
} catch (NumberFormatException e) {
logger.warn("Invalid number parameter in query string: " + ajaxSessionIdStr);
logger.error("Invalid ajaxSessionId (sess) value in query string: {}. Expected a number.", ajaxSessionIdStr, e);
throw new IllegalArgumentException(e);
}
}
if (! checkSessionSourceIp(session, sourceIP)) {
if (!checkSessionSourceIp(session, sourceIP, clientIp)) {
return;
}
@ -129,14 +131,17 @@ public class ConsoleProxyNoVNCHandler extends WebSocketHandler {
param.setClientTag(tag);
param.setTicket(ticket);
param.setClientDisplayName(displayName);
param.setClientTunnelUrl(console_url);
param.setClientTunnelSession(console_host_session);
param.setLocale(vm_locale);
param.setClientTunnelUrl(consoleUrl);
param.setClientTunnelSession(consoleHostSession);
param.setLocale(vmLocale);
param.setHypervHost(hypervHost);
param.setUsername(username);
param.setPassword(password);
param.setWebsocketUrl(websocketUrl);
param.setSessionUuid(sessionUuid);
param.setSourceIP(sourceIP);
param.setClientIp(clientIp);
if (queryMap.containsKey("extraSecurityToken")) {
param.setExtraSecurityToken(queryMap.get("extraSecurityToken"));
}
@ -144,8 +149,9 @@ public class ConsoleProxyNoVNCHandler extends WebSocketHandler {
param.setClientProvidedExtraSecurityToken(queryMap.get("extra"));
}
viewer = ConsoleProxy.getNoVncViewer(param, ajaxSessionIdStr, session);
logger.info("Viewer has been created successfully [session UUID: {}, client IP: {}].", sessionUuid, clientIp);
} catch (Exception e) {
logger.warn("Failed to create viewer due to " + e.getMessage(), e);
logger.error("Failed to create viewer [session UUID: {}, client IP: {}] due to {}.", sessionUuid, clientIp, e.getMessage(), e);
return;
} finally {
if (viewer == null) {
@ -154,32 +160,35 @@ public class ConsoleProxyNoVNCHandler extends WebSocketHandler {
}
}
private boolean checkSessionSourceIp(final Session session, final String sourceIP) throws IOException {
// Verify source IP
String sessionSourceIP = session.getRemoteAddress().getAddress().getHostAddress();
logger.info("Get websocket connection request from remote IP : " + sessionSourceIP);
if (ConsoleProxy.isSourceIpCheckEnabled && (sessionSourceIP == null || ! sessionSourceIP.equals(sourceIP))) {
logger.warn("Failed to access console as the source IP to request the console is " + sourceIP);
private boolean checkSessionSourceIp(final Session session, final String sourceIP, String sessionSourceIP) throws IOException {
logger.info("Verifying session source IP {} from WebSocket connection request.", sessionSourceIP);
if (ConsoleProxy.isSourceIpCheckEnabled && (sessionSourceIP == null || !sessionSourceIP.equals(sourceIP))) {
logger.warn("Failed to access console as the source IP to request the console is {}.", sourceIP);
session.disconnect();
return false;
}
logger.debug("Session source IP {} has been verified successfully.", sessionSourceIP);
return true;
}
@OnWebSocketClose
public void onClose(Session session, int statusCode, String reason) throws IOException, InterruptedException {
String sessionSourceIp = session.getRemoteAddress().getAddress().getHostAddress();
logger.debug("Closing WebSocket session [source IP: {}, status code: {}].", sessionSourceIp, statusCode);
if (viewer != null) {
ConsoleProxy.removeViewer(viewer);
}
logger.debug("WebSocket session [source IP: {}, status code: {}] closed successfully.", sessionSourceIp, statusCode);
}
@OnWebSocketFrame
public void onFrame(Frame f) throws IOException {
logger.trace("Sending client [ID: {}] frame of {} bytes.", viewer.getClientId(), f.getPayloadLength());
viewer.sendClientFrame(f);
}
@OnWebSocketError
public void onError(Throwable cause) {
logger.error("Error on websocket", cause);
logger.error("Error on WebSocket [client ID: {}, session UUID: {}].", cause, viewer.getClientId(), viewer.getSessionUuid());
}
}

View File

@ -22,7 +22,8 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.security.KeyStore;
import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
@ -34,7 +35,7 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
public class ConsoleProxyNoVNCServer {
protected static Logger LOGGER = Logger.getLogger(ConsoleProxyNoVNCServer.class);
protected static Logger LOGGER = LogManager.getLogger(ConsoleProxyNoVNCServer.class);
public static final int WS_PORT = 8080;
public static final int WSS_PORT = 8443;
private static final String VNC_CONF_FILE_LOCATION = "/root/vncport";

View File

@ -75,9 +75,9 @@ public class ConsoleProxyNoVncClient implements ConsoleProxyClient {
@Override
public boolean isFrontEndAlive() {
if (!connectionAlive || System.currentTimeMillis()
- getClientLastFrontEndActivityTime() > ConsoleProxy.VIEWER_LINGER_SECONDS * 1000) {
logger.info("Front end has been idle for too long");
long unusedTime = System.currentTimeMillis() - getClientLastFrontEndActivityTime();
if (!connectionAlive || unusedTime > ConsoleProxy.VIEWER_LINGER_SECONDS * 1000) {
logger.info("Front end has been idle for too long ({} ms).", unusedTime);
return false;
}
return true;
@ -95,23 +95,24 @@ public class ConsoleProxyNoVncClient implements ConsoleProxyClient {
client = new NoVncClient();
connectionAlive = true;
this.sessionUuid = param.getSessionUuid();
String clientSourceIp = param.getClientIp();
logger.debug("Initializing client from IP {}.", clientSourceIp);
updateFrontEndActivityTime();
Thread worker = new Thread(new Runnable() {
public void run() {
try {
String tunnelUrl = param.getClientTunnelUrl();
String tunnelSession = param.getClientTunnelSession();
String websocketUrl = param.getWebsocketUrl();
connectClientToVNCServer(tunnelUrl, tunnelSession, websocketUrl);
authenticateToVNCServer();
authenticateToVNCServer(clientSourceIp);
int readBytes;
byte[] b;
while (connectionAlive) {
logger.trace("Connection with client [{}] [IP: {}] is alive.", clientId, clientSourceIp);
if (client.isVncOverWebSocketConnection()) {
if (client.isVncOverWebSocketConnectionOpen()) {
updateFrontEndActivityTime();
@ -122,7 +123,7 @@ public class ConsoleProxyNoVncClient implements ConsoleProxyClient {
int nextBytes = client.getNextBytes();
bytesArr = new byte[nextBytes];
client.readBytes(bytesArr, nextBytes);
logger.trace(String.format("Read [%s] bytes from client [%s]", nextBytes, clientId));
logger.trace("Read [{}] bytes from client [{}].", nextBytes, clientId);
if (nextBytes > 0) {
session.getRemote().sendBytes(ByteBuffer.wrap(bytesArr));
updateFrontEndActivityTime();
@ -132,7 +133,7 @@ public class ConsoleProxyNoVncClient implements ConsoleProxyClient {
} else {
b = new byte[100];
readBytes = client.read(b);
logger.trace(String.format("Read [%s] bytes from client [%s]", readBytes, clientId));
logger.trace("Read [{}] bytes from client [{}].", readBytes, clientId);
if (readBytes == -1 || (readBytes > 0 && !sendReadBytesToNoVNC(b, readBytes))) {
connectionAlive = false;
}
@ -143,7 +144,7 @@ public class ConsoleProxyNoVncClient implements ConsoleProxyClient {
logger.error("Error on sleep for vnc sessions", e);
}
}
logger.info(String.format("Connection with client [%s] is dead.", clientId));
logger.info("Connection with client [{}] [IP: {}] is dead.", clientId, clientSourceIp);
} catch (IOException e) {
logger.error("Error on VNC client", e);
}
@ -158,7 +159,7 @@ public class ConsoleProxyNoVncClient implements ConsoleProxyClient {
session.getRemote().sendBytes(ByteBuffer.wrap(b, 0, readBytes));
updateFrontEndActivityTime();
} catch (WebSocketException | IOException e) {
logger.debug("Connection exception", e);
logger.error("VNC server connection exception.", e);
return false;
}
return true;
@ -176,20 +177,24 @@ public class ConsoleProxyNoVncClient implements ConsoleProxyClient {
*
* Reference: https://github.com/rfbproto/rfbproto/blob/master/rfbproto.rst#7protocol-messages
*/
private void authenticateToVNCServer() throws IOException {
private void authenticateToVNCServer(String clientSourceIp) throws IOException {
if (client.isVncOverWebSocketConnection()) {
logger.debug("Authentication skipped for client [{}] [IP: {}] to VNC server due to WebSocket protocol usage.", clientId, clientSourceIp);
return;
}
if (!client.isVncOverNioSocket()) {
logger.debug("Authenticating client [{}] [IP: {}] to VNC server.", clientId, clientSourceIp);
String ver = client.handshake();
session.getRemote().sendBytes(ByteBuffer.wrap(ver.getBytes(), 0, ver.length()));
byte[] b = client.authenticateTunnel(getClientHostPassword());
session.getRemote().sendBytes(ByteBuffer.wrap(b, 0, 4));
} else {
logger.debug("Authenticating client [{}] [IP: {}] to VNC server through NIO Socket.", clientId, clientSourceIp);
authenticateVNCServerThroughNioSocket();
}
logger.debug("Client [{}] [IP: {}] has been authenticated successfully to VNC server.", clientId, clientSourceIp);
}
/**
@ -233,9 +238,6 @@ public class ConsoleProxyNoVncClient implements ConsoleProxyClient {
protected void authenticateVNCServerThroughNioSocket() {
handshakePhase();
initialisationPhase();
if (logger.isDebugEnabled()) {
logger.debug("Authenticated successfully");
}
}
/**
@ -289,8 +291,7 @@ public class ConsoleProxyNoVncClient implements ConsoleProxyClient {
logger.info(String.format("Connect to VNC over websocket URL: %s", websocketUrl));
ConsoleProxy.ensureRoute(NetUtils.extractHost(websocketUrl));
client.connectToWebSocket(websocketUrl, session);
} else if (tunnelUrl != null && !tunnelUrl.isEmpty() && tunnelSession != null
&& !tunnelSession.isEmpty()) {
} else if (StringUtils.isNotBlank(tunnelUrl) && StringUtils.isNotBlank(tunnelSession)) {
URI uri = new URI(tunnelUrl);
logger.info(String.format("Connect to VNC server via tunnel. url: %s, session: %s",
tunnelUrl, tunnelSession));
@ -304,8 +305,10 @@ public class ConsoleProxyNoVncClient implements ConsoleProxyClient {
ConsoleProxy.ensureRoute(getClientHostAddress());
client.connectTo(getClientHostAddress(), getClientHostPort());
}
logger.info("Connection to VNC server has been established successfully.");
} catch (Throwable e) {
logger.error("Unexpected exception", e);
logger.error("Unexpected exception while connecting to VNC server.", e);
}
}
@ -370,6 +373,7 @@ public class ConsoleProxyNoVncClient implements ConsoleProxyClient {
}
public void updateFrontEndActivityTime() {
logger.trace("Updating last front end activity time.");
lastFrontEndActivityTime = System.currentTimeMillis();
}

View File

@ -28,10 +28,11 @@ import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ConsoleProxyResourceHandler implements HttpHandler {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
static Map<String, String> s_mimeTypes;
static {

View File

@ -32,10 +32,11 @@ import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ConsoleProxyThumbnailHandler implements HttpHandler {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
public ConsoleProxyThumbnailHandler() {
}

View File

@ -25,10 +25,12 @@ import java.util.List;
import com.cloud.consoleproxy.ConsoleProxyRdpClient;
import com.cloud.consoleproxy.util.ImageHelper;
import com.cloud.consoleproxy.util.Logger;
import com.cloud.consoleproxy.util.TileInfo;
import com.cloud.consoleproxy.vnc.FrameBufferCanvas;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import common.BufferedImageCanvas;
public class RdpBufferedImageCanvas extends BufferedImageCanvas implements FrameBufferCanvas {
@ -36,7 +38,7 @@ public class RdpBufferedImageCanvas extends BufferedImageCanvas implements Frame
*
*/
private static final long serialVersionUID = 1L;
protected Logger logger = Logger.getLogger(RdpBufferedImageCanvas.class);
protected Logger logger = LogManager.getLogger(RdpBufferedImageCanvas.class);
private final ConsoleProxyRdpClient _rdpClient;

View File

@ -1,223 +0,0 @@
// 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.util;
// logger facility for dynamic switch between console logger used in Applet and log4j based logger
public class Logger {
private static LoggerFactory factory = null;
public static final int LEVEL_TRACE = 1;
public static final int LEVEL_DEBUG = 2;
public static final int LEVEL_INFO = 3;
public static final int LEVEL_WARN = 4;
public static final int LEVEL_ERROR = 5;
private Class<?> clazz;
private Logger logger;
private static int level = LEVEL_INFO;
public static Logger getLogger(Class<?> clazz) {
return new Logger(clazz);
}
public static void setFactory(LoggerFactory f) {
factory = f;
}
public static void setLevel(int l) {
level = l;
}
public Logger(Class<?> clazz) {
this.clazz = clazz;
}
protected Logger() {
}
public boolean isTraceEnabled() {
if (factory != null) {
if (logger == null)
logger = factory.getLogger(clazz);
return logger.isTraceEnabled();
}
return level <= LEVEL_TRACE;
}
public boolean isDebugEnabled() {
if (factory != null) {
if (logger == null)
logger = factory.getLogger(clazz);
return logger.isDebugEnabled();
}
return level <= LEVEL_DEBUG;
}
public boolean isInfoEnabled() {
if (factory != null) {
if (logger == null)
logger = factory.getLogger(clazz);
return logger.isInfoEnabled();
}
return level <= LEVEL_INFO;
}
public void trace(Object message) {
if (factory != null) {
if (logger == null)
logger = factory.getLogger(clazz);
logger.trace(message);
} else {
if (level <= LEVEL_TRACE)
System.out.println(message);
}
}
public void trace(Object message, Throwable exception) {
if (factory != null) {
if (logger == null)
logger = factory.getLogger(clazz);
logger.trace(message, exception);
} else {
if (level <= LEVEL_TRACE) {
System.out.println(message);
if (exception != null) {
exception.printStackTrace(System.out);
}
}
}
}
public void info(Object message) {
if (factory != null) {
if (logger == null)
logger = factory.getLogger(clazz);
logger.info(message);
} else {
if (level <= LEVEL_INFO)
System.out.println(message);
}
}
public void info(Object message, Throwable exception) {
if (factory != null) {
if (logger == null)
logger = factory.getLogger(clazz);
logger.info(message, exception);
} else {
if (level <= LEVEL_INFO) {
System.out.println(message);
if (exception != null) {
exception.printStackTrace(System.out);
}
}
}
}
public void debug(Object message) {
if (factory != null) {
if (logger == null)
logger = factory.getLogger(clazz);
logger.debug(message);
} else {
if (level <= LEVEL_DEBUG)
System.out.println(message);
}
}
public void debug(Object message, Throwable exception) {
if (factory != null) {
if (logger == null)
logger = factory.getLogger(clazz);
logger.debug(message, exception);
} else {
if (level <= LEVEL_DEBUG) {
System.out.println(message);
if (exception != null) {
exception.printStackTrace(System.out);
}
}
}
}
public void warn(Object message) {
if (factory != null) {
if (logger == null)
logger = factory.getLogger(clazz);
logger.warn(message);
} else {
if (level <= LEVEL_WARN)
System.out.println(message);
}
}
public void warn(Object message, Throwable exception) {
if (factory != null) {
if (logger == null)
logger = factory.getLogger(clazz);
logger.warn(message, exception);
} else {
if (level <= LEVEL_WARN) {
System.out.println(message);
if (exception != null) {
exception.printStackTrace(System.out);
}
}
}
}
public void error(Object message) {
if (factory != null) {
if (logger == null)
logger = factory.getLogger(clazz);
logger.error(message);
} else {
if (level <= LEVEL_ERROR)
System.out.println(message);
}
}
public void error(Object message, Throwable exception) {
if (factory != null) {
if (logger == null)
logger = factory.getLogger(clazz);
logger.error(message, exception);
} else {
if (level <= LEVEL_ERROR) {
System.out.println(message);
if (exception != null) {
exception.printStackTrace(System.out);
}
}
}
}
}

View File

@ -1,21 +0,0 @@
// 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.util;
public interface LoggerFactory {
Logger getLogger(Class<?> clazz);
}

View File

@ -38,6 +38,9 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
//
// This file is originally from XenConsole with modifications
//
@ -48,7 +51,7 @@ import java.util.regex.Pattern;
* connections and import/export operations.
*/
public final class RawHTTP {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
private static final Pattern END_PATTERN = Pattern.compile("^\r\n$");
private static final Pattern HEADER_PATTERN = Pattern.compile("^([A-Z_a-z0-9-]+):\\s*(.*)\r\n$");

View File

@ -27,16 +27,18 @@ import java.io.IOException;
import java.util.List;
import com.cloud.consoleproxy.util.ImageHelper;
import com.cloud.consoleproxy.util.Logger;
import com.cloud.consoleproxy.util.TileInfo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* A <code>BuffereImageCanvas</code> component represents frame buffer image on
* the screen. It also notifies its subscribers when screen is repainted.
*/
public class BufferedImageCanvas extends Canvas implements FrameBufferCanvas {
private static final long serialVersionUID = 1L;
protected Logger logger = Logger.getLogger(BufferedImageCanvas.class);
protected Logger logger = LogManager.getLogger(BufferedImageCanvas.class);
// Offline screen buffer
private BufferedImage offlineImage;

View File

@ -31,7 +31,6 @@ import java.security.spec.KeySpec;
import java.util.Arrays;
import java.util.List;
import com.cloud.consoleproxy.util.Logger;
import com.cloud.consoleproxy.util.RawHTTP;
import com.cloud.consoleproxy.vnc.network.NioSocket;
import com.cloud.consoleproxy.vnc.network.NioSocketHandler;
@ -42,7 +41,11 @@ import com.cloud.consoleproxy.vnc.security.VncTLSSecurity;
import com.cloud.consoleproxy.websocket.WebSocketReverseProxy;
import com.cloud.utils.Pair;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.jetty.websocket.api.Session;
import javax.crypto.BadPaddingException;
@ -54,7 +57,7 @@ import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
public class NoVncClient {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
private Socket socket;
private DataInputStream is;
@ -79,6 +82,7 @@ public class NoVncClient {
port = 80;
}
logger.info("Connecting to VNC server {}:{} ...", host, port);
RawHTTP tunnel = new RawHTTP("CONNECT", host, port, path, session, useSSL);
socket = tunnel.connect();
setTunnelSocketStreams();
@ -86,7 +90,7 @@ public class NoVncClient {
public void connectTo(String host, int port) {
// Connect to server
logger.info(String.format("Connecting to VNC server %s:%s ...", host, port));
logger.info("Connecting to VNC server {}:{} ...", host, port);
try {
NioSocket nioSocket = new NioSocket(host, port);
this.nioSocketConnection = new NioSocketHandlerImpl(nioSocket);
@ -175,8 +179,9 @@ public class NoVncClient {
is.readFully(buf);
String reason = new String(buf, RfbConstants.CHARSET);
logger.error("Authentication to VNC server is failed. Reason: " + reason);
throw new RuntimeException("Authentication to VNC server is failed. Reason: " + reason);
String msg = String.format("Authentication to VNC server has failed. Reason: %s", reason);
logger.error(msg);
throw new RuntimeException(msg);
}
case RfbConstants.NO_AUTH: {
@ -191,9 +196,9 @@ public class NoVncClient {
}
default:
logger.error("Unsupported VNC protocol authorization scheme, scheme code: " + authType + ".");
throw new RuntimeException(
"Unsupported VNC protocol authorization scheme, scheme code: " + authType + ".");
String msg = String.format("Unsupported VNC protocol authorization scheme, scheme code: %d.", authType);
logger.error(msg);
throw new RuntimeException(msg);
}
// Since we've taken care of the auth, we tell the client that there's no auth
// going on

View File

@ -33,13 +33,15 @@ import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import com.cloud.consoleproxy.ConsoleProxyClientListener;
import com.cloud.consoleproxy.util.Logger;
import com.cloud.consoleproxy.util.RawHTTP;
import com.cloud.consoleproxy.vnc.packet.client.KeyboardEventPacket;
import com.cloud.consoleproxy.vnc.packet.client.MouseEventPacket;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class VncClient {
protected static Logger LOGGER = Logger.getLogger(VncClient.class);
protected static Logger LOGGER = LogManager.getLogger(VncClient.class);
private Socket socket;
private DataInputStream is;

View File

@ -27,7 +27,6 @@ import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import com.cloud.consoleproxy.util.Logger;
import com.cloud.consoleproxy.vnc.packet.client.ClientPacket;
import com.cloud.consoleproxy.vnc.packet.client.FramebufferUpdateRequestPacket;
import com.cloud.consoleproxy.vnc.packet.client.KeyboardEventPacket;
@ -35,8 +34,11 @@ import com.cloud.consoleproxy.vnc.packet.client.MouseEventPacket;
import com.cloud.consoleproxy.vnc.packet.client.SetEncodingsPacket;
import com.cloud.consoleproxy.vnc.packet.client.SetPixelFormatPacket;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class VncClientPacketSender implements Runnable, PaintNotificationListener, KeyListener, MouseListener, MouseMotionListener, FrameBufferUpdateListener {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
// Queue for outgoing packets
private final BlockingQueue<ClientPacket> queue = new ArrayBlockingQueue<ClientPacket>(30);

View File

@ -22,12 +22,14 @@ import java.io.DataInputStream;
import java.io.IOException;
import com.cloud.consoleproxy.ConsoleProxyClientListener;
import com.cloud.consoleproxy.util.Logger;
import com.cloud.consoleproxy.vnc.packet.server.FramebufferUpdatePacket;
import com.cloud.consoleproxy.vnc.packet.server.ServerCutText;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class VncServerPacketReceiver implements Runnable {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
private final VncScreenDescription screen;
private BufferedImageCanvas canvas;

View File

@ -16,11 +16,12 @@
// under the License.
package com.cloud.consoleproxy.vnc.packet.server;
import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public abstract class AbstractRect implements Rect {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
protected final int x;
protected final int y;

View File

@ -19,11 +19,13 @@ package com.cloud.consoleproxy.vnc.packet.server;
import java.io.DataInputStream;
import java.io.IOException;
import com.cloud.consoleproxy.util.Logger;
import com.cloud.consoleproxy.vnc.RfbConstants;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ServerCutText {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
private String content;

View File

@ -16,7 +16,6 @@
// under the License.
package com.cloud.consoleproxy.vnc.security;
import com.cloud.consoleproxy.util.Logger;
import com.cloud.consoleproxy.vnc.NoVncClient;
import com.cloud.consoleproxy.vnc.network.NioSocketHandler;
import com.cloud.utils.exception.CloudRuntimeException;
@ -24,12 +23,15 @@ import com.cloud.utils.exception.CloudRuntimeException;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class VncAuthSecurity implements VncSecurity {
private final String vmPass;
private static final int VNC_AUTH_CHALLENGE_SIZE = 16;
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
public VncAuthSecurity(String vmPass) {
this.vmPass = vmPass;

View File

@ -16,7 +16,6 @@
// under the License.
package com.cloud.consoleproxy.vnc.security;
import com.cloud.consoleproxy.util.Logger;
import com.cloud.consoleproxy.vnc.RfbConstants;
import com.cloud.consoleproxy.vnc.network.NioSocketHandler;
import com.cloud.consoleproxy.vnc.network.NioSocketSSLEngineManager;
@ -29,9 +28,12 @@ import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class VncTLSSecurity implements VncSecurity {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
private SSLContext ctx;
private SSLEngine engine;

View File

@ -16,7 +16,6 @@
// under the License.
package com.cloud.consoleproxy.websocket;
import com.cloud.consoleproxy.util.Logger;
import org.eclipse.jetty.websocket.api.Session;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft_6455;
@ -36,6 +35,9 @@ import java.nio.ByteBuffer;
import java.security.cert.X509Certificate;
import java.util.Collections;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* Acts as a websocket reverse proxy between the remoteSession and the connected endpoint
* - Connects to a websocket endpoint and sends the received data to the remoteSession endpoint
@ -51,7 +53,7 @@ public class WebSocketReverseProxy extends WebSocketClient {
private static final DefaultExtension defaultExtension = new DefaultExtension();
private static final Draft_6455 draft = new Draft_6455(Collections.singletonList(defaultExtension), Collections.singletonList(protocol));
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
private Session remoteSession;
private void acceptAllCerts() {