internal List <RDPConnectionDetails> GetRdpConnectionDetails(CloudHostedInstance instance) { var list = new List <RDPConnectionDetails>(); //check RDP availability foreach (var vm in instance.Instances) { var result = _httpClient.GetAsync($"{LcsUrl}/DeploymentPortal/IsRdpResourceAvailable/{LcsProjectId}/?topologyInstanceId={instance.InstanceId}&virtualMachineInstanceName={vm.MachineName}&deploymentItemName={vm.ItemName}&azureSubscriptionId={instance.AzureSubscriptionId}&group=0&isARMTopology={instance.IsARMTopology}&nsgWarningDisplayed=false&_={DateTimeOffset.Now.ToUnixTimeSeconds()}").Result; result.EnsureSuccessStatusCode(); var responseBody = result.Content.ReadAsStringAsync().Result; var rdpPresentResponse = JsonConvert.DeserializeObject <Response>(responseBody); if (!rdpPresentResponse.Success) { continue; } _httpClient.DefaultRequestHeaders.Remove("Accept"); _httpClient.DefaultRequestHeaders.Remove("X-Requested-With"); _httpClient.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); _httpClient.DefaultRequestHeaders.Add("Upgrade-Insecure-Requests", "1"); result = _httpClient.GetAsync($"{LcsUrl}/DeploymentPortal/IsRdpResourceAvailable/{LcsProjectId}/?topologyInstanceId={instance.InstanceId}&virtualMachineInstanceName={vm.MachineName}&deploymentItemName={vm.ItemName}&azureSubscriptionId={instance.AzureSubscriptionId}&group=0&isARMTopology={instance.IsARMTopology}&nsgWarningDisplayed=false&_={DateTimeOffset.Now.ToUnixTimeSeconds()}&isDownloadEnabled=True").Result; result.EnsureSuccessStatusCode(); responseBody = result.Content.ReadAsStringAsync().Result; var line1 = responseBody.Split('\r', '\n').FirstOrDefault(); if (line1 == null) { continue; } var splited = line1.Split(':'); _httpClient.DefaultRequestHeaders.Remove("Accept"); _httpClient.DefaultRequestHeaders.Add("Accept", "*/*"); _httpClient.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest"); _httpClient.DefaultRequestHeaders.Remove("Upgrade-Insecure-Requests"); vm.Credentials = GetCredentials(instance.EnvironmentId, vm.ItemName); var localAdmin = vm.Credentials.Where(x => x.Key.Contains("Local admin")).ToDictionary(x => x.Key, x => x.Value); var username = localAdmin.First().Key.Split('\\'); var domain = username[0].Split('-')[2]; var rdp = new RDPConnectionDetails { Address = splited[2], Port = splited[3], Domain = domain, Username = username[1], Password = localAdmin.First().Value, Machine = vm.MachineName }; list.Add(rdp); } return(list); }
private void PackagesDataGridView_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { if (rdpConnectionsDataGridView.SelectedRows.Count > 0) { RDPConnection = (RDPConnectionDetails)rdpConnectionsDataGridView.SelectedRows[0].DataBoundItem; } else { Cancelled = true; } Close(); }
private void OkButton_Click(object sender, EventArgs e) { if (rdpConnectionsDataGridView.SelectedRows.Count > 0) { RDPConnection = (RDPConnectionDetails)rdpConnectionsDataGridView.SelectedRows[0].DataBoundItem; } else { Cancelled = true; } Close(); }
private void Page_Loaded(object sender, RoutedEventArgs e) { MainWindow mainWindow = Application.Current.MainWindow as MainWindow; allWMS = mainWindow.AllWMs; vmCombo.ItemsSource = allWMS; CloudHostedInstance personalInstance = null; if (!string.IsNullOrEmpty(Properties.Settings.Default.SelectedPersonalVM)) { foreach (var item in allWMS) { if (item.EnvironmentId == Properties.Settings.Default.SelectedPersonalVM) { personalInstance = item; break; } } if (personalInstance != null) { environmentId = personalInstance.EnvironmentId; vmCombo.SelectedItem = personalInstance; } } MinimizeSetting.IsChecked = Properties.Settings.Default.MimimizeOnStartRDP; Span.IsChecked = Properties.Settings.Default.Span; Resolution.Value = Properties.Settings.Default.Resolution; Multimon.IsChecked = Properties.Settings.Default.Multimon; RDPConnectionDetails connectionDetails = mainWindow.GetDefaultUser(); if (connectionDetails == null) { ClearDefaultUser.IsEnabled = false; UserName.Content = Properties.Resources.NoDefaultUser; } else { ClearDefaultUser.IsEnabled = true; UserName.Content = string.Format(Properties.Resources.ClearDefaultUserTitle, connectionDetails.Username); } RotationSpeed.Text = Properties.Settings.Default.RotationSpeed; }
private void OKButton_Click(object sender, RoutedEventArgs e) { if (UserGrid.SelectedItems.Count == 1) { if (UserGrid.SelectedItem != null) { selectedUser = UserGrid.SelectedItem as RDPConnectionDetails; if (SelectedEnvironment == true) { if (DefaultUser.IsChecked == true) { MainWindow mainWindow = Application.Current.MainWindow as MainWindow; mainWindow.SetDefaultUser(selectedUser); } } this.Close(); } } if (UserGrid.SelectedItems.Count == 0 || UserGrid.SelectedItems.Count > 1) { return; } }
private void StartRDP(RDPConnectionDetails rdpDetails) { }
private void OnWorkerDoWork(object sender, DoWorkEventArgs e) { worker.ReportProgress(25, "Initializing LCS connections"); CookieContainer cookies = MainForm.GetUriCookieContainer(); if (cookies == null) { return; } HttpClientHelper httpClientHelper = new HttpClientHelper(cookies) { LcsUrl = URIHandler.LCS_URL, LcsUpdateUrl = URIHandler.LCS_UPDATE_URL, LcsDiagUrl = URIHandler.LCS_DIAG_URL }; if (rdpData.Command.ToLower() == "connectrdp") { worker.ReportProgress(20, "Loading project"); httpClientHelper.ChangeLcsProjectId(rdpData.ProjectId); ProjectData project = httpClientHelper.GetProject(rdpData.ProjectId); projectNameLabel.Invoke(new MethodInvoker(delegate { projectNameLabel.Text = project.Name; })); worker.ReportProgress(50, "Loading cloud-hosted instances"); CloudHostedInstance chInstance = httpClientHelper.GetCheInstances().FirstOrDefault(e => e.DisplayName == rdpData.Environment); if (chInstance != null) { if (chInstance.CanShowRdp) { worker.ReportProgress(80, "Loading connection details"); var rdpList = httpClientHelper.GetRdpConnectionDetails(chInstance); RDPConnectionDetails rdpEntry = null; if (rdpList != null && rdpList.Count > 0) { if (rdpList.Count > 1) { rdpEntry = MainForm.ChooseRdpLogonUser(rdpList); } else { rdpEntry = rdpList.First(); } if (rdpEntry != null) { using (new RdpCredentials(rdpEntry.Address, $"{rdpEntry.Domain}\\{rdpEntry.Username}", rdpEntry.Password)) { var rdcProcess = new Process { StartInfo = { FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\mstsc.exe"), Arguments = "/v " + $"{rdpEntry.Address}:{rdpEntry.Port}" } }; worker.ReportProgress(95, "Starting connection.."); rdcProcess.Start(); } } else { MessageBox.Show($"Operation cancelled", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show($"Cannot retrieve RDP connection details. This instance is not accessible through RDP or you do not have access to see those details. Check if you have Environment Manager role.", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show($"Cannot retrieve RDP connection details. This instance is not accessible through RDP or you do not have access to see those details. Check if you have Environment Manager role.", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show($"Cannot find cloud-hosted instance with ID {rdpData.Environment} on project {project.Name}", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Unsupported operation", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }