mirror of https://github.com/apache/cloudstack.git
Xenserver Secure Console Proxy Phase I
This commit is contained in:
parent
65d5d4d549
commit
3cbb8bc198
|
|
@ -61,7 +61,9 @@ public class ConsoleProxyAjaxImageHandler implements HttpHandler {
|
|||
String sid = queryMap.get("sid");
|
||||
String tag = queryMap.get("tag");
|
||||
String ticket = queryMap.get("ticket");
|
||||
String keyStr = queryMap.get("key");
|
||||
String keyStr = queryMap.get("key");
|
||||
String console_url = queryMap.get("consoleurl");
|
||||
String console_host_session = queryMap.get("sessionref");
|
||||
int key = 0;
|
||||
|
||||
if(tag == null)
|
||||
|
|
|
|||
|
|
@ -1709,7 +1709,10 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
try {
|
||||
Set<VM> vms = VM.getByNameLabel(conn, cmd.getName());
|
||||
if(vms.size() == 1) {
|
||||
return new GetVncPortAnswer(cmd, getVncPort(conn, vms.iterator().next()));
|
||||
int vncport = getVncPort(conn, vms.iterator().next());
|
||||
String consoleurl;
|
||||
consoleurl = "consoleurl=" +getVncUrl(conn, vms.iterator().next()) + "&" +"sessionref="+ conn.getSessionReference();
|
||||
return new GetVncPortAnswer(cmd, consoleurl, vncport);
|
||||
} else {
|
||||
return new GetVncPortAnswer(cmd, "There are " + vms.size() + " VMs named " + cmd.getName());
|
||||
}
|
||||
|
|
@ -2612,6 +2615,12 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
VM.Record record;
|
||||
try {
|
||||
record = vm.getRecord(conn);
|
||||
Set<Console> consoles = record.consoles;
|
||||
if (consoles.isEmpty()) {
|
||||
s_logger.warn("There are no Consoles available to the vm : " + record.nameDescription);
|
||||
return -1;
|
||||
}
|
||||
Iterator<Console> i = consoles.iterator();
|
||||
} catch (XenAPIException e) {
|
||||
String msg = "Unable to get vnc-port due to " + e.toString();
|
||||
s_logger.warn(msg, e);
|
||||
|
|
@ -2634,6 +2643,42 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
vncport = vncport.replace("\n", "");
|
||||
return NumbersUtil.parseInt(vncport, -1);
|
||||
}
|
||||
|
||||
protected String getVncUrl(Connection conn, VM vm) {
|
||||
VM.Record record;
|
||||
Console c;
|
||||
String consoleurl;
|
||||
try {
|
||||
record = vm.getRecord(conn);
|
||||
Set<Console> consoles = record.consoles;
|
||||
if (consoles.isEmpty()) {
|
||||
s_logger.warn("There are no Consoles available to the vm : " + record.nameDescription);
|
||||
return null;
|
||||
}
|
||||
Iterator<Console> i = consoles.iterator();
|
||||
c = i.next();
|
||||
consoleurl = c.getLocation(conn);
|
||||
} catch (XenAPIException e) {
|
||||
String msg = "Unable to get console url due to " + e.toString();
|
||||
s_logger.warn(msg, e);
|
||||
return null;
|
||||
} catch (XmlRpcException e) {
|
||||
String msg = "Unable to get console url due to " + e.getMessage();
|
||||
s_logger.warn(msg, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (consoleurl.isEmpty())
|
||||
return null;
|
||||
else
|
||||
return consoleurl;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public RebootAnswer execute(RebootCommand cmd) {
|
||||
|
|
|
|||
|
|
@ -245,6 +245,7 @@ public class ConsoleProxyServlet extends HttpServlet {
|
|||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("<html><title>").append(escapeHTML(vmName)).append("</title><frameset><frame src=\"").append(composeConsoleAccessUrl(rootUrl, vm, host));
|
||||
sb.append("\"></frame></frameset></html>");
|
||||
s_logger.debug("the console url is :: " + sb.toString());
|
||||
sendResponse(resp, sb.toString());
|
||||
}
|
||||
|
||||
|
|
@ -310,12 +311,26 @@ public class ConsoleProxyServlet extends HttpServlet {
|
|||
|
||||
private String composeConsoleAccessUrl(String rootUrl, VMInstanceVO vm, HostVO hostVo) {
|
||||
StringBuffer sb = new StringBuffer(rootUrl);
|
||||
|
||||
String[] console_session = null;
|
||||
String console_url = null;
|
||||
String host = hostVo.getPrivateIpAddress();
|
||||
Pair<String, Integer> portInfo = _ms.getVncPort(vm);
|
||||
|
||||
s_logger.debug("Port info " + portInfo.first());
|
||||
|
||||
if(portInfo.first() != null) {
|
||||
host = portInfo.first();
|
||||
console_url = host = portInfo.first();
|
||||
}
|
||||
|
||||
System.out.println("Port info " + portInfo.first());
|
||||
if ( console_url !=null && console_url.startsWith("consoleurl")) {
|
||||
console_session = console_url.split("&");
|
||||
host = console_url.substring(19,console_url.indexOf('/', 19)).trim();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
String sid = vm.getVncPassword();
|
||||
String tag = String.valueOf(vm.getId());
|
||||
tag = _identityService.getIdentityUuid("vm_instance", tag);
|
||||
|
|
@ -326,6 +341,12 @@ public class ConsoleProxyServlet extends HttpServlet {
|
|||
sb.append("&sid=").append(sid);
|
||||
sb.append("&tag=").append(tag);
|
||||
sb.append("&ticket=").append(ticket);
|
||||
System.out.println("Port info " + portInfo.first());
|
||||
|
||||
if ( console_session !=null && console_session.length == 2){
|
||||
sb.append("&").append(console_session[0]);
|
||||
sb.append("&").append(console_session[1]);
|
||||
}
|
||||
|
||||
// for console access, we need guest OS type to help implement keyboard
|
||||
long guestOs = vm.getGuestOSId();
|
||||
|
|
|
|||
Loading…
Reference in New Issue