Skip to content

Commit 3cbb8bc

Browse files
Xenserver Secure Console Proxy Phase I
1 parent 65d5d4d commit 3cbb8bc

3 files changed

Lines changed: 72 additions & 4 deletions

File tree

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxImageHandler.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ private void doHandle(HttpExchange t) throws Exception, IllegalArgumentException
6161
String sid = queryMap.get("sid");
6262
String tag = queryMap.get("tag");
6363
String ticket = queryMap.get("ticket");
64-
String keyStr = queryMap.get("key");
64+
String keyStr = queryMap.get("key");
65+
String console_url = queryMap.get("consoleurl");
66+
String console_host_session = queryMap.get("sessionref");
6567
int key = 0;
6668

6769
if(tag == null)

‎core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,10 @@ protected GetVncPortAnswer execute(GetVncPortCommand cmd) {
17091709
try {
17101710
Set<VM> vms = VM.getByNameLabel(conn, cmd.getName());
17111711
if(vms.size() == 1) {
1712-
return new GetVncPortAnswer(cmd, getVncPort(conn, vms.iterator().next()));
1712+
int vncport = getVncPort(conn, vms.iterator().next());
1713+
String consoleurl;
1714+
consoleurl = "consoleurl=" +getVncUrl(conn, vms.iterator().next()) + "&" +"sessionref="+ conn.getSessionReference();
1715+
return new GetVncPortAnswer(cmd, consoleurl, vncport);
17131716
} else {
17141717
return new GetVncPortAnswer(cmd, "There are " + vms.size() + " VMs named " + cmd.getName());
17151718
}
@@ -2612,6 +2615,12 @@ protected int getVncPort(Connection conn, VM vm) {
26122615
VM.Record record;
26132616
try {
26142617
record = vm.getRecord(conn);
2618+
Set<Console> consoles = record.consoles;
2619+
if (consoles.isEmpty()) {
2620+
s_logger.warn("There are no Consoles available to the vm : " + record.nameDescription);
2621+
return -1;
2622+
}
2623+
Iterator<Console> i = consoles.iterator();
26152624
} catch (XenAPIException e) {
26162625
String msg = "Unable to get vnc-port due to " + e.toString();
26172626
s_logger.warn(msg, e);
@@ -2634,6 +2643,42 @@ record = vm.getRecord(conn);
26342643
vncport = vncport.replace("\n", "");
26352644
return NumbersUtil.parseInt(vncport, -1);
26362645
}
2646+
2647+
protected String getVncUrl(Connection conn, VM vm) {
2648+
VM.Record record;
2649+
Console c;
2650+
String consoleurl;
2651+
try {
2652+
record = vm.getRecord(conn);
2653+
Set<Console> consoles = record.consoles;
2654+
if (consoles.isEmpty()) {
2655+
s_logger.warn("There are no Consoles available to the vm : " + record.nameDescription);
2656+
return null;
2657+
}
2658+
Iterator<Console> i = consoles.iterator();
2659+
c = i.next();
2660+
consoleurl = c.getLocation(conn);
2661+
} catch (XenAPIException e) {
2662+
String msg = "Unable to get console url due to " + e.toString();
2663+
s_logger.warn(msg, e);
2664+
return null;
2665+
} catch (XmlRpcException e) {
2666+
String msg = "Unable to get console url due to " + e.getMessage();
2667+
s_logger.warn(msg, e);
2668+
return null;
2669+
}
2670+
2671+
if (consoleurl.isEmpty())
2672+
return null;
2673+
else
2674+
return consoleurl;
2675+
2676+
2677+
2678+
}
2679+
2680+
2681+
26372682

26382683
@Override
26392684
public RebootAnswer execute(RebootCommand cmd) {

‎server/src/com/cloud/servlet/ConsoleProxyServlet.java‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ private void handleAccessRequest(HttpServletRequest req, HttpServletResponse res
245245
StringBuffer sb = new StringBuffer();
246246
sb.append("<html><title>").append(escapeHTML(vmName)).append("</title><frameset><frame src=\"").append(composeConsoleAccessUrl(rootUrl, vm, host));
247247
sb.append("\"></frame></frameset></html>");
248+
s_logger.debug("the console url is :: " + sb.toString());
248249
sendResponse(resp, sb.toString());
249250
}
250251

@@ -310,12 +311,26 @@ private String composeThumbnailUrl(String rootUrl, VMInstanceVO vm, HostVO hostV
310311

311312
private String composeConsoleAccessUrl(String rootUrl, VMInstanceVO vm, HostVO hostVo) {
312313
StringBuffer sb = new StringBuffer(rootUrl);
313-
314+
String[] console_session = null;
315+
String console_url = null;
314316
String host = hostVo.getPrivateIpAddress();
315317
Pair<String, Integer> portInfo = _ms.getVncPort(vm);
318+
319+
s_logger.debug("Port info " + portInfo.first());
320+
316321
if(portInfo.first() != null) {
317-
host = portInfo.first();
322+
console_url = host = portInfo.first();
323+
}
324+
325+
System.out.println("Port info " + portInfo.first());
326+
if ( console_url !=null && console_url.startsWith("consoleurl")) {
327+
console_session = console_url.split("&");
328+
host = console_url.substring(19,console_url.indexOf('/', 19)).trim();
318329
}
330+
331+
332+
333+
319334
String sid = vm.getVncPassword();
320335
String tag = String.valueOf(vm.getId());
321336
tag = _identityService.getIdentityUuid("vm_instance", tag);
@@ -326,6 +341,12 @@ private String composeConsoleAccessUrl(String rootUrl, VMInstanceVO vm, HostVO h
326341
sb.append("&sid=").append(sid);
327342
sb.append("&tag=").append(tag);
328343
sb.append("&ticket=").append(ticket);
344+
System.out.println("Port info " + portInfo.first());
345+
346+
if ( console_session !=null && console_session.length == 2){
347+
sb.append("&").append(console_session[0]);
348+
sb.append("&").append(console_session[1]);
349+
}
329350

330351
// for console access, we need guest OS type to help implement keyboard
331352
long guestOs = vm.getGuestOSId();

0 commit comments

Comments
 (0)