From bbce2a9916b61683df9d2dacacb8005f809c8bb7 Mon Sep 17 00:00:00 2001 From: vfedosevich Date: Mon, 25 May 2015 06:28:51 -0700 Subject: [PATCH 1/2] Excluding local admins group from users GPO --- .../Windows2012.cs | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs index 3d4e959d..058ccb32 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs @@ -379,7 +379,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices string collectionComputersPath = GetComputerGroupPath(organizationId, collection.Name); CreatePolicy(runSpace, organizationId, string.Format("{0}-administrators", collection.Name), new DirectoryEntry(GetGroupPath(organizationId, collection.Name, GetLocalAdminsGroupName(collection.Name))), new DirectoryEntry(collectionComputersPath), collection.Name); - CreatePolicy(runSpace, organizationId, string.Format("{0}-users", collection.Name), new DirectoryEntry(GetUsersGroupPath(organizationId, collection.Name)) + CreateUsersPolicy(runSpace, organizationId, string.Format("{0}-users", collection.Name), new DirectoryEntry(GetUsersGroupPath(organizationId, collection.Name)) , new DirectoryEntry(collectionComputersPath), collection.Name); CreateHelpDeskPolicy(runSpace, new DirectoryEntry(GetHelpDeskGroupPath(RDSHelpDeskGroup)), new DirectoryEntry(collectionComputersPath), organizationId, collection.Name); } @@ -1137,7 +1137,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices CreatePolicy(runspace, organizationId, string.Format("{0}-administrators", collectionName), new DirectoryEntry(GetGroupPath(organizationId, collectionName, GetLocalAdminsGroupName(collectionName))), new DirectoryEntry(collectionComputersPath), collectionName); - CreatePolicy(runspace, organizationId, string.Format("{0}-users", collectionName), + CreateUsersPolicy(runspace, organizationId, string.Format("{0}-users", collectionName), new DirectoryEntry(GetUsersGroupPath(organizationId, collectionName)), new DirectoryEntry(collectionComputersPath), collectionName); CreateHelpDeskPolicy(runspace, new DirectoryEntry(GetHelpDeskGroupPath(RDSHelpDeskGroup)), new DirectoryEntry(collectionComputersPath), organizationId, collectionName); RemoveRegistryValue(runspace, ScreenSaverGpoKey, administratorsGpo); @@ -1329,6 +1329,13 @@ namespace WebsitePanel.Providers.RemoteDesktopServices } } + private string CreateUsersPolicy(Runspace runspace, string organizationId, string gpoName, DirectoryEntry entry, DirectoryEntry collectionComputersEntry, string collectionName) + { + string gpoId = CreatePolicy(runspace, organizationId, gpoName, entry, collectionComputersEntry, collectionName); + ExcludeAdminsFromUsersPolicy(runspace, gpoId, collectionName); + return gpoId; + } + private string CreatePolicy(Runspace runspace, string organizationId, string gpoName, DirectoryEntry entry, DirectoryEntry collectionComputersEntry, string collectionName) { string gpoId = GetPolicyId(runspace, gpoName); @@ -1360,6 +1367,22 @@ namespace WebsitePanel.Providers.RemoteDesktopServices Collection result = ExecuteRemoteShellCommand(runspace, PrimaryDomainController, cmd); } + private void ExcludeAdminsFromUsersPolicy(Runspace runspace, string gpoId, string collectionName) + { + var scripts = new List + { + string.Format("$adgpo = [ADSI]\"{0}\"", GetGpoPath(gpoId)), + string.Format("$rule = New-Object System.DirectoryServices.ActiveDirectoryAccessRule([System.Security.Principal.NTAccount]\"{0}\\{1}\",\"ExtendedRight\",\"Deny\",[GUID]\"edacfd8f-ffb3-11d1-b41d-00a0c968f939\")", + RootDomain.Split('.').First(), GetLocalAdminsGroupName(collectionName)), + string.Format("$acl = $adgpo.ObjectSecurity"), + string.Format("$acl.AddAccessRule($rule)"), + string.Format("$adgpo.CommitChanges()") + }; + + object[] errors = null; + ExecuteRemoteShellCommand(runspace, PrimaryDomainController, scripts, out errors); + } + private void SetPolicyPermissions(Runspace runspace, string gpoName, DirectoryEntry entry, DirectoryEntry collectionComputersEntry) { var scripts = new List @@ -1752,7 +1775,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices string collectionComputersPath = GetComputerGroupPath(organizationId, collection.Name); CreatePolicy(runSpace, organizationId, string.Format("{0}-administrators", collection.Name), new DirectoryEntry(GetGroupPath(organizationId, collection.Name, GetLocalAdminsGroupName(collection.Name))), new DirectoryEntry(collectionComputersPath), collection.Name); - CreatePolicy(runSpace, organizationId, string.Format("{0}-users", collection.Name), new DirectoryEntry(GetUsersGroupPath(organizationId, collection.Name)) + CreateUsersPolicy(runSpace, organizationId, string.Format("{0}-users", collection.Name), new DirectoryEntry(GetUsersGroupPath(organizationId, collection.Name)) , new DirectoryEntry(collectionComputersPath), collection.Name); CreateHelpDeskPolicy(runSpace, new DirectoryEntry(GetHelpDeskGroupPath(RDSHelpDeskGroup)), new DirectoryEntry(collectionComputersPath), organizationId, collection.Name); @@ -2434,6 +2457,19 @@ namespace WebsitePanel.Providers.RemoteDesktopServices return sb.ToString(); } + private string GetGpoPath(string gpoId) + { + StringBuilder sb = new StringBuilder(); + + AppendProtocol(sb); + AppendCNPath(sb, gpoId); + AppendCNPath(sb, "Policies"); + AppendCNPath(sb, "System"); + AppendDomainPath(sb, RootDomain); + + return sb.ToString(); + } + internal string GetTenantComputerGroupPath(string organizationId) { StringBuilder sb = new StringBuilder(); From 10bd8fe6542034d76bfead917cc745f4cb52ca6d Mon Sep 17 00:00:00 2001 From: vfedosevich Date: Tue, 26 May 2015 05:10:04 -0700 Subject: [PATCH 2/2] Check before RDS users delete --- .../RemoteDesktopServicesController.cs | 9 ++- .../Windows2012.cs | 6 +- .../RDS/RDSEditCollectionUsers.ascx | 74 +++++++++-------- .../RDS/RDSEditCollectionUsers.ascx.cs | 32 +++----- .../RDSCollectionUsers.ascx.resx | 9 +++ .../RDS/UserControls/RDSCollectionUsers.ascx | 37 ++++++++- .../UserControls/RDSCollectionUsers.ascx.cs | 71 +++++++++++++++- .../RDSCollectionUsers.ascx.designer.cs | 81 +++++++++++++++++++ 8 files changed, 255 insertions(+), 64 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs index 7c75150a..975d49c1 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs @@ -1596,7 +1596,14 @@ namespace WebsitePanel.EnterpriseServer var rds = RemoteDesktopServicesHelpers.GetRemoteDesktopServices(RemoteDesktopServicesHelpers.GetRemoteDesktopServiceID(org.PackageId)); var collection = ObjectUtils.FillObjectFromDataReader(DataProvider.GetRDSCollectionById(collectionId)); - var users = rds.GetApplicationUsers(collection.Name, remoteApp.Alias); + string alias = ""; + + if (remoteApp != null) + { + alias = remoteApp.Alias; + } + + var users = rds.GetApplicationUsers(collection.Name, alias); result.AddRange(users); return result; diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs index 058ccb32..62f3db25 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs @@ -709,7 +709,11 @@ namespace WebsitePanel.Providers.RemoteDesktopServices Command cmd = new Command("Get-RDRemoteApp"); cmd.Parameters.Add("CollectionName", collectionName); cmd.Parameters.Add("ConnectionBroker", ConnectionBroker); - cmd.Parameters.Add("Alias", applicationName); + + if (!string.IsNullOrEmpty(applicationName)) + { + cmd.Parameters.Add("Alias", applicationName); + } var application = ExecuteShellCommand(runspace, cmd, false).FirstOrDefault(); diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx index 57a37195..02015403 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx @@ -10,42 +10,40 @@ -
-
-
-
-
-
-
- - - - - -
-
- - - - - - - -
- -
-
-
- -     - +
+
+
+
+
+
+
+ + + - + +
+
+ + + + + +
+ +
+
+
+ +     + +
+
+ +
+
-
- -
-
-
-
-
-
\ No newline at end of file +
+
+
\ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx.cs index 906a2160..efcc68cb 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx.cs @@ -26,7 +26,9 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +using AjaxControlToolkit; using System; +using System.Collections.Generic; using System.Linq; using System.Web.UI.WebControls; using WebsitePanel.EnterpriseServer; @@ -41,31 +43,16 @@ namespace WebsitePanel.Portal.RDS protected void Page_Load(object sender, EventArgs e) { - users.Module = Module; + users.Module = Module; + users.OnRefreshClicked -= OnRefreshClicked; + users.OnRefreshClicked += OnRefreshClicked; if (!IsPostBack) { BindQuota(); - var collectionUsers = ES.Services.RDS.GetRdsCollectionUsers(PanelRequest.CollectionID); - var collection = ES.Services.RDS.GetRdsCollection(PanelRequest.CollectionID); - var localAdmins = ES.Services.RDS.GetRdsCollectionLocalAdmins(PanelRequest.CollectionID); - - foreach (var user in collectionUsers) - { - if (localAdmins.Select(l => l.AccountName).Contains(user.AccountName)) - { - user.IsVIP = true; - } - else - { - user.IsVIP = false; - } - } - - litCollectionName.Text = collection.DisplayName; - users.SetUsers(collectionUsers); + users.BindUsers(); } - } + } private void BindQuota() { @@ -87,6 +74,11 @@ namespace WebsitePanel.Portal.RDS } } + private void OnRefreshClicked(object sender, EventArgs e) + { + ((ModalPopupExtender)asyncTasks.FindControl("ModalPopupProperties")).Hide(); + } + private bool SaveRdsUsers() { try diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/App_LocalResources/RDSCollectionUsers.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/App_LocalResources/RDSCollectionUsers.ascx.resx index 47a2f1e3..1686c266 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/App_LocalResources/RDSCollectionUsers.ascx.resx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/App_LocalResources/RDSCollectionUsers.ascx.resx @@ -126,6 +126,9 @@ Cancel + + Cancel + Delete @@ -153,4 +156,10 @@ Enabled Users + + Warning + + + Unable to remove the following user(s) since they are local admins<br/>or they were granted access to remote applications + \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionUsers.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionUsers.ascx index 1572c47a..138d7f28 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionUsers.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionUsers.ascx @@ -5,7 +5,7 @@
- +
+ +