public async Task <ActionResult <ConsoleSummary> > Ticket(string id) { await AuthorizeAction(id, "ticket"); var info = await _pod.Display(id); if (info.Url.HasValue()) { _logger.LogDebug("ticket url: {0}", info.Url); var src = new Uri(info.Url); string target = ""; string qs = ""; string internalHost = src.Host.Split('.').First(); string domain = Request.Host.Value.IndexOf(".") >= 0 ? Request.Host.Value.Substring(Request.Host.Value.IndexOf(".") + 1) : Request.Host.Value; switch (_pod.Options.TicketUrlHandler.ToLower()) { case "querystring": qs = $"?vmhost={src.Host}"; target = _pod.Options.ConsoleUrl; break; case "local-app": target = $"{Request.Host.Value}/{internalHost}"; break; case "external-domain": target = $"{internalHost}.{domain}"; break; case "host-map": var map = _pod.Options.TicketUrlHostMap; if (map.ContainsKey(src.Host)) { target = map[src.Host]; } break; } if (target.HasValue()) { info.Url = info.Url.Replace(src.Host, target); } info.Url += qs; } return(Ok(info)); }
public async Task <ConsoleSummary> Ticket(string vmId) { var info = await _pod.Display(vmId); var gamespace = await _gamespaceStore.Load(info.IsolationId); if (gamespace != null) { gamespace.LastActivity = DateTime.UtcNow; await _gamespaceStore.Update(gamespace); } if (info.Url.HasValue()) { var src = new Uri(info.Url); info.Url = info.Url.Replace(src.Host, _options.ConsoleHost) + $"?vmhost={src.Host}"; } return(info); }
public async Task <ActionResult <VmConsole> > GetVmTicket(string id) { AuthorizeAny( () => Actor.IsAdmin, () => CanManageVm(id, Actor.Id).Result ); var info = await _pod.Display(id); if (info.Url.IsEmpty()) { return(Ok(info)); } Logger.LogDebug($"mks url: {info.Url}"); var src = new Uri(info.Url); string target = ""; string qs = ""; string internalHost = src.Host.Split('.').First(); string domain = Request.Host.Value.IndexOf(".") >= 0 ? Request.Host.Value.Substring(Request.Host.Value.IndexOf(".") + 1) : Request.Host.Value; switch (_pod.Options.TicketUrlHandler.ToLower()) { case "local-app": target = $"{Request.Host.Value}{Request.PathBase}{internalHost}"; break; case "external-domain": target = $"{internalHost}.{domain}"; break; case "host-map": var map = _pod.Options.TicketUrlHostMap; if (map.ContainsKey(src.Host)) { target = map[src.Host]; } break; // TODO: make this default after publishing change case "none": case "": break; case "querystring": default: qs = $"?vmhost={src.Host}"; target = _options.ConsoleHost; break; } if (target.NotEmpty()) { info.Url = info.Url.Replace(src.Host, target); } info.Url += qs; Logger.LogDebug($"mks url: {info.Url}"); return(Ok(info)); }