diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs index 91f589c3..c3bd42d7 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs @@ -663,8 +663,8 @@ namespace WebsitePanel.EnterpriseServer } var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId)); - - rds.RemoveCollection(org.OrganizationId, collection.Name); + var servers = ObjectUtils.CreateListFromDataReader(DataProvider.GetRDSServersByCollectionId(collection.Id)).ToArray(); + rds.RemoveCollection(org.OrganizationId, collection.Name, servers); DataProvider.DeleteRDSCollection(collection.Id); } diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs index 133eb575..a176c00f 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs @@ -43,7 +43,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices bool CreateCollection(string organizationId, RdsCollection collection); bool AddRdsServersToDeployment(RdsServer[] servers); RdsCollection GetCollection(string collectionName); - bool RemoveCollection(string organizationId, string collectionName); + bool RemoveCollection(string organizationId, string collectionName, List servers); bool SetUsersInCollection(string organizationId, string collectionName, List users); void AddSessionHostServerToCollection(string organizationId, string collectionName, RdsServer server); void AddSessionHostServersToCollection(string organizationId, string collectionName, List servers); diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs index af65e3c0..5e547dcb 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs @@ -71,6 +71,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices private const string WspAdministratorsGroupDescription = "WSP Administrators"; private const string RdsServersOU = "RDSServers"; private const string RDSHelpDeskComputerGroup = "Websitepanel-RDSHelpDesk-Computer"; + private const string RDSHelpDeskAdminsGroup = "WSP-HelpdeskAdmins"; #endregion @@ -308,10 +309,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices //ActiveDirectoryUtils.AddObjectToGroup(GetComputerPath(ConnectionBroker), GetComputerGroupPath(organizationId, collection.Name)); } - if (!ActiveDirectoryUtils.AdObjectExists(GetHelpDeskComputerGroupPath())) - { - ActiveDirectoryUtils.CreateGroup(GetRootOUPath(), RDSHelpDeskComputerGroup); - } + CheckOrCreateHelpDeskComputerGroup(); if (!ActiveDirectoryUtils.AdObjectExists(GetUsersGroupPath(organizationId, collection.Name))) { @@ -342,7 +340,13 @@ namespace WebsitePanel.Providers.RemoteDesktopServices //add session servers to group foreach (var rdsServer in collection.Servers) - { + { + if (!CheckLocalAdminsGroupExists(rdsServer.FqdName, runSpace)) + { + CreateLocalAdministratorsGroup(rdsServer.FqdName, runSpace); + } + + AddHelpDeskAdminsGroupToLocalAdmins(runSpace, rdsServer.FqdName); AddComputerToCollectionAdComputerGroup(organizationId, collection.Name, rdsServer); } } @@ -471,7 +475,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices return collection; } - public bool RemoveCollection(string organizationId, string collectionName) + public bool RemoveCollection(string organizationId, string collectionName, List servers) { var result = true; @@ -506,10 +510,13 @@ namespace WebsitePanel.Providers.RemoteDesktopServices RemoveNpsPolicy(runSpace, CentralNpsHost, capPolicyName); } - //Remove security group + foreach(var server in servers) + { + RemoveComputerFromCollectionAdComputerGroup(organizationId, collectionName, server); + } ActiveDirectoryUtils.DeleteADObject(GetComputerGroupPath(organizationId, collectionName)); - ActiveDirectoryUtils.DeleteADObject(GetUsersGroupPath(organizationId, collectionName)); + ActiveDirectoryUtils.DeleteADObject(GetUsersGroupPath(organizationId, collectionName)); } catch (Exception e) { @@ -565,11 +572,14 @@ namespace WebsitePanel.Providers.RemoteDesktopServices ExecuteShellCommand(runSpace, cmd, false); - if (!ActiveDirectoryUtils.AdObjectExists(GetHelpDeskComputerGroupPath())) + CheckOrCreateHelpDeskComputerGroup(); + + if (!CheckLocalAdminsGroupExists(server.FqdName, runSpace)) { - ActiveDirectoryUtils.CreateGroup(GetRootOUPath(), RDSHelpDeskComputerGroup); + CreateLocalAdministratorsGroup(server.FqdName, runSpace); } + AddHelpDeskAdminsGroupToLocalAdmins(runSpace, server.FqdName); AddComputerToCollectionAdComputerGroup(organizationId, collectionName, server); } catch (Exception e) @@ -969,7 +979,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices public void SaveRdsCollectionLocalAdmins(List users, List hosts) { - Runspace runspace = null; + Runspace runspace = null; try { @@ -994,7 +1004,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices throw new Exception(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray())); } } - + var existingAdmins = GetExistingLocalAdmins(hostName, runspace).Select(e => e.ToLower()); var formUsers = users.Select(u => string.Format("{0}\\{1}", domainName, u.SamAccountName).ToLower()); var newUsers = users.Where(u => !existingAdmins.Contains(string.Format("{0}\\{1}", domainName, u.SamAccountName).ToLower())); @@ -1009,6 +1019,8 @@ namespace WebsitePanel.Providers.RemoteDesktopServices { RemoveLocalAdmin(hostName, user, runspace); } + + AddHelpDeskAdminsGroupToLocalAdmins(runspace, hostName); } } finally @@ -1141,6 +1153,53 @@ namespace WebsitePanel.Providers.RemoteDesktopServices #endregion + #region RDS Help Desk + + private string GetHelpDeskGroupPath(string groupName) + { + StringBuilder sb = new StringBuilder(); + + AppendProtocol(sb); + AppendDomainController(sb); + AppendCNPath(sb, groupName); + AppendOUPath(sb, RootOU); + AppendDomainPath(sb, RootDomain); + + return sb.ToString(); + } + + private void CheckOrCreateHelpDeskComputerGroup() + { + if (!ActiveDirectoryUtils.AdObjectExists(GetHelpDeskGroupPath(RDSHelpDeskComputerGroup))) + { + ActiveDirectoryUtils.CreateGroup(GetRootOUPath(), RDSHelpDeskComputerGroup); + } + } + + private void AddHelpDeskAdminsGroupToLocalAdmins(Runspace runspace, string hostName) + { + var helpDeskAdminsGroupPath = GetHelpDeskGroupPath(RDSHelpDeskAdminsGroup); + + if (!ActiveDirectoryUtils.AdObjectExists(helpDeskAdminsGroupPath)) + { + ActiveDirectoryUtils.CreateGroup(GetRootOUPath(), RDSHelpDeskAdminsGroup); + } + + var groupEntry = ActiveDirectoryUtils.GetADObject(helpDeskAdminsGroupPath); + var samAccountName = ActiveDirectoryUtils.GetADObjectProperty(groupEntry, "sAMAccountName"); + + var scripts = new List + { + string.Format("$GroupObj = [ADSI]\"WinNT://{0}/{1}\"", hostName, WspAdministratorsGroupName), + string.Format("$GroupObj.Add(\"WinNT://{0}/{1}\")", ServerSettings.ADRootDomain, samAccountName) + }; + + object[] errors = null; + ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors); + } + + #endregion + #region SSL public void InstallCertificate(byte[] certificate, string password, List hostNames) @@ -1356,7 +1415,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices if (!ActiveDirectoryUtils.IsComputerInGroup(samName, RDSHelpDeskComputerGroup)) { - ActiveDirectoryUtils.AddObjectToGroup(computerPath, GetHelpDeskComputerGroupPath()); + ActiveDirectoryUtils.AddObjectToGroup(computerPath, GetHelpDeskGroupPath(RDSHelpDeskComputerGroup)); } } @@ -1383,11 +1442,11 @@ namespace WebsitePanel.Providers.RemoteDesktopServices ActiveDirectoryUtils.RemoveObjectFromGroup(computerPath, GetComputerGroupPath(organizationId, collectionName)); } - if (ActiveDirectoryUtils.AdObjectExists(GetHelpDeskComputerGroupPath())) + if (ActiveDirectoryUtils.AdObjectExists(GetHelpDeskGroupPath(RDSHelpDeskComputerGroup))) { if (ActiveDirectoryUtils.IsComputerInGroup(samName, RDSHelpDeskComputerGroup)) { - ActiveDirectoryUtils.RemoveObjectFromGroup(computerPath, GetHelpDeskComputerGroupPath()); + ActiveDirectoryUtils.RemoveObjectFromGroup(computerPath, GetHelpDeskGroupPath(RDSHelpDeskComputerGroup)); } } } @@ -1673,20 +1732,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices AppendDomainPath(sb, RootDomain); return sb.ToString(); - } - - internal string GetHelpDeskComputerGroupPath() - { - StringBuilder sb = new StringBuilder(); - - AppendProtocol(sb); - AppendDomainController(sb); - AppendCNPath(sb, RDSHelpDeskComputerGroup); - AppendOUPath(sb, RootOU); - AppendDomainPath(sb, RootDomain); - - return sb.ToString(); - } + } internal string GetUsersGroupPath(string organizationId, string collection) { diff --git a/WebsitePanel/Sources/WebsitePanel.Server.Client/RemoteDesktopServicesProxy.cs b/WebsitePanel/Sources/WebsitePanel.Server.Client/RemoteDesktopServicesProxy.cs index 863d17ea..7d50298d 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server.Client/RemoteDesktopServicesProxy.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server.Client/RemoteDesktopServicesProxy.cs @@ -424,18 +424,20 @@ namespace WebsitePanel.Providers.RemoteDesktopServices { /// [System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")] [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/RemoveCollection", RequestNamespace="http://smbsaas/websitepanel/server/", ResponseNamespace="http://smbsaas/websitepanel/server/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] - public bool RemoveCollection(string organizationId, string collectionName) { + public bool RemoveCollection(string organizationId, string collectionName, RdsServer[] servers) { object[] results = this.Invoke("RemoveCollection", new object[] { organizationId, - collectionName}); + collectionName, + servers}); return ((bool)(results[0])); } /// - public System.IAsyncResult BeginRemoveCollection(string organizationId, string collectionName, System.AsyncCallback callback, object asyncState) { + public System.IAsyncResult BeginRemoveCollection(string organizationId, string collectionName, RdsServer[] servers, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("RemoveCollection", new object[] { organizationId, - collectionName}, callback, asyncState); + collectionName, + servers}, callback, asyncState); } /// @@ -445,18 +447,19 @@ namespace WebsitePanel.Providers.RemoteDesktopServices { } /// - public void RemoveCollectionAsync(string organizationId, string collectionName) { - this.RemoveCollectionAsync(organizationId, collectionName, null); + public void RemoveCollectionAsync(string organizationId, string collectionName, RdsServer[] servers) { + this.RemoveCollectionAsync(organizationId, collectionName, servers, null); } /// - public void RemoveCollectionAsync(string organizationId, string collectionName, object userState) { + public void RemoveCollectionAsync(string organizationId, string collectionName, RdsServer[] servers, object userState) { if ((this.RemoveCollectionOperationCompleted == null)) { this.RemoveCollectionOperationCompleted = new System.Threading.SendOrPostCallback(this.OnRemoveCollectionOperationCompleted); } this.InvokeAsync("RemoveCollection", new object[] { organizationId, - collectionName}, this.RemoveCollectionOperationCompleted, userState); + collectionName, + servers}, this.RemoveCollectionOperationCompleted, userState); } private void OnRemoveCollectionOperationCompleted(object arg) { diff --git a/WebsitePanel/Sources/WebsitePanel.Server/RemoteDesktopServices.asmx.cs b/WebsitePanel/Sources/WebsitePanel.Server/RemoteDesktopServices.asmx.cs index 03fec8aa..038cc907 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server/RemoteDesktopServices.asmx.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server/RemoteDesktopServices.asmx.cs @@ -146,12 +146,12 @@ namespace WebsitePanel.Server } [WebMethod, SoapHeader("settings")] - public bool RemoveCollection(string organizationId, string collectionName) + public bool RemoveCollection(string organizationId, string collectionName, List servers) { try { Log.WriteStart("'{0}' RemoveCollection", ProviderSettings.ProviderName); - var result = RDSProvider.RemoveCollection(organizationId, collectionName); + var result = RDSProvider.RemoveCollection(organizationId, collectionName, servers); Log.WriteEnd("'{0}' RemoveCollection", ProviderSettings.ProviderName); return result; } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionApps.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionApps.ascx index 94109cb6..02806956 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionApps.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionApps.ascx @@ -33,7 +33,7 @@ - +