diff --git a/WebsitePanel/Database/update_db.sql b/WebsitePanel/Database/update_db.sql index 79f3cf66..ac791ff8 100644 --- a/WebsitePanel/Database/update_db.sql +++ b/WebsitePanel/Database/update_db.sql @@ -5508,6 +5508,23 @@ CREATE TABLE [dbo].[RDSCollectionSettings]( GO +IF NOT EXISTS(SELECT * FROM SYS.TABLES WHERE name = 'RDSCertificates') +CREATE TABLE [dbo].[RDSCertificates]( + [ID] [int] IDENTITY(1,1) NOT NULL, + [ServiceId] [int] NOT NULL, + [Content] [ntext] NOT NULL, + [Hash] [nvarchar](255) NOT NULL, + [FileName] [nvarchar](255) NOT NULL, + [ValidFrom] [datetime] NULL, + [ExpiryDate] [datetime] NULL + CONSTRAINT [PK_RDSCertificates] PRIMARY KEY CLUSTERED +( + [ID] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] +) ON [PRIMARY] + +GO + ALTER TABLE [dbo].[RDSCollectionUsers] DROP CONSTRAINT [FK_RDSCollectionUsers_RDSCollectionId] @@ -5548,6 +5565,66 @@ GO /*Remote Desktop Services Procedures*/ +IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'AddRDSCertificate') +DROP PROCEDURE AddRDSCertificate +GO +CREATE PROCEDURE [dbo].[AddRDSCertificate] +( + @RDSCertificateId INT OUTPUT, + @ServiceId INT, + @Content NTEXT, + @Hash NVARCHAR(255), + @FileName NVARCHAR(255), + @ValidFrom DATETIME, + @ExpiryDate DATETIME +) +AS +INSERT INTO RDSCertificates +( + ServiceId, + Content, + Hash, + FileName, + ValidFrom, + ExpiryDate +) +VALUES +( + @ServiceId, + @Content, + @Hash, + @FileName, + @ValidFrom, + @ExpiryDate +) + +SET @RDSCertificateId = SCOPE_IDENTITY() + +RETURN +GO + + +IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetRDSCertificateByServiceId') +DROP PROCEDURE GetRDSCertificateByServiceId +GO +CREATE PROCEDURE [dbo].[GetRDSCertificateByServiceId] +( + @ServiceId INT +) +AS +SELECT TOP 1 + Id, + ServiceId, + Content, + Hash, + FileName, + ValidFrom, + ExpiryDate + FROM RDSCertificates + WHERE ServiceId = @ServiceId + ORDER BY Id DESC +GO + IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'AddRDSServer') DROP PROCEDURE AddRDSServer GO diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/RemoteDesktopServicesProxy.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/RemoteDesktopServicesProxy.cs index 3214d80d..c5fba734 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/RemoteDesktopServicesProxy.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/RemoteDesktopServicesProxy.cs @@ -120,6 +120,10 @@ namespace WebsitePanel.EnterpriseServer { private System.Threading.SendOrPostCallback InstallSessionHostsCertificateOperationCompleted; + private System.Threading.SendOrPostCallback GetRdsCertificateByServiceIdOperationCompleted; + + private System.Threading.SendOrPostCallback AddRdsCertificateOperationCompleted; + /// public esRemoteDesktopServices() { this.Url = "http://localhost:9002/esRemoteDesktopServices.asmx"; @@ -260,6 +264,12 @@ namespace WebsitePanel.EnterpriseServer { /// public event InstallSessionHostsCertificateCompletedEventHandler InstallSessionHostsCertificateCompleted; + /// + public event GetRdsCertificateByServiceIdCompletedEventHandler GetRdsCertificateByServiceIdCompleted; + + /// + public event AddRdsCertificateCompletedEventHandler AddRdsCertificateCompleted; + /// [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/GetRdsCollection", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] public RdsCollection GetRdsCollection(int collectionId) { @@ -2245,20 +2255,16 @@ namespace WebsitePanel.EnterpriseServer { /// [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/InstallSessionHostsCertificate", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] - public ResultObject InstallSessionHostsCertificate(int collectionId, [System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] byte[] certificate, string password) { + public ResultObject InstallSessionHostsCertificate(RdsServer rdsServer) { object[] results = this.Invoke("InstallSessionHostsCertificate", new object[] { - collectionId, - certificate, - password}); + rdsServer}); return ((ResultObject)(results[0])); } /// - public System.IAsyncResult BeginInstallSessionHostsCertificate(int collectionId, byte[] certificate, string password, System.AsyncCallback callback, object asyncState) { + public System.IAsyncResult BeginInstallSessionHostsCertificate(RdsServer rdsServer, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("InstallSessionHostsCertificate", new object[] { - collectionId, - certificate, - password}, callback, asyncState); + rdsServer}, callback, asyncState); } /// @@ -2268,19 +2274,17 @@ namespace WebsitePanel.EnterpriseServer { } /// - public void InstallSessionHostsCertificateAsync(int collectionId, byte[] certificate, string password) { - this.InstallSessionHostsCertificateAsync(collectionId, certificate, password, null); + public void InstallSessionHostsCertificateAsync(RdsServer rdsServer) { + this.InstallSessionHostsCertificateAsync(rdsServer, null); } /// - public void InstallSessionHostsCertificateAsync(int collectionId, byte[] certificate, string password, object userState) { + public void InstallSessionHostsCertificateAsync(RdsServer rdsServer, object userState) { if ((this.InstallSessionHostsCertificateOperationCompleted == null)) { this.InstallSessionHostsCertificateOperationCompleted = new System.Threading.SendOrPostCallback(this.OnInstallSessionHostsCertificateOperationCompleted); } this.InvokeAsync("InstallSessionHostsCertificate", new object[] { - collectionId, - certificate, - password}, this.InstallSessionHostsCertificateOperationCompleted, userState); + rdsServer}, this.InstallSessionHostsCertificateOperationCompleted, userState); } private void OnInstallSessionHostsCertificateOperationCompleted(object arg) { @@ -2290,6 +2294,88 @@ namespace WebsitePanel.EnterpriseServer { } } + /// + [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/GetRdsCertificateByServiceId", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] + public RdsCertificate GetRdsCertificateByServiceId(int serviceId) { + object[] results = this.Invoke("GetRdsCertificateByServiceId", new object[] { + serviceId}); + return ((RdsCertificate)(results[0])); + } + + /// + public System.IAsyncResult BeginGetRdsCertificateByServiceId(int serviceId, System.AsyncCallback callback, object asyncState) { + return this.BeginInvoke("GetRdsCertificateByServiceId", new object[] { + serviceId}, callback, asyncState); + } + + /// + public RdsCertificate EndGetRdsCertificateByServiceId(System.IAsyncResult asyncResult) { + object[] results = this.EndInvoke(asyncResult); + return ((RdsCertificate)(results[0])); + } + + /// + public void GetRdsCertificateByServiceIdAsync(int serviceId) { + this.GetRdsCertificateByServiceIdAsync(serviceId, null); + } + + /// + public void GetRdsCertificateByServiceIdAsync(int serviceId, object userState) { + if ((this.GetRdsCertificateByServiceIdOperationCompleted == null)) { + this.GetRdsCertificateByServiceIdOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetRdsCertificateByServiceIdOperationCompleted); + } + this.InvokeAsync("GetRdsCertificateByServiceId", new object[] { + serviceId}, this.GetRdsCertificateByServiceIdOperationCompleted, userState); + } + + private void OnGetRdsCertificateByServiceIdOperationCompleted(object arg) { + if ((this.GetRdsCertificateByServiceIdCompleted != null)) { + System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg)); + this.GetRdsCertificateByServiceIdCompleted(this, new GetRdsCertificateByServiceIdCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)); + } + } + + /// + [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/AddRdsCertificate", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] + public ResultObject AddRdsCertificate(RdsCertificate certificate) { + object[] results = this.Invoke("AddRdsCertificate", new object[] { + certificate}); + return ((ResultObject)(results[0])); + } + + /// + public System.IAsyncResult BeginAddRdsCertificate(RdsCertificate certificate, System.AsyncCallback callback, object asyncState) { + return this.BeginInvoke("AddRdsCertificate", new object[] { + certificate}, callback, asyncState); + } + + /// + public ResultObject EndAddRdsCertificate(System.IAsyncResult asyncResult) { + object[] results = this.EndInvoke(asyncResult); + return ((ResultObject)(results[0])); + } + + /// + public void AddRdsCertificateAsync(RdsCertificate certificate) { + this.AddRdsCertificateAsync(certificate, null); + } + + /// + public void AddRdsCertificateAsync(RdsCertificate certificate, object userState) { + if ((this.AddRdsCertificateOperationCompleted == null)) { + this.AddRdsCertificateOperationCompleted = new System.Threading.SendOrPostCallback(this.OnAddRdsCertificateOperationCompleted); + } + this.InvokeAsync("AddRdsCertificate", new object[] { + certificate}, this.AddRdsCertificateOperationCompleted, userState); + } + + private void OnAddRdsCertificateOperationCompleted(object arg) { + if ((this.AddRdsCertificateCompleted != null)) { + System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg)); + this.AddRdsCertificateCompleted(this, new AddRdsCertificateCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)); + } + } + /// public new void CancelAsync(object userState) { base.CancelAsync(userState); @@ -3465,4 +3551,56 @@ namespace WebsitePanel.EnterpriseServer { } } } + + /// + [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] + public delegate void GetRdsCertificateByServiceIdCompletedEventHandler(object sender, GetRdsCertificateByServiceIdCompletedEventArgs e); + + /// + [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] + [System.Diagnostics.DebuggerStepThroughAttribute()] + [System.ComponentModel.DesignerCategoryAttribute("code")] + public partial class GetRdsCertificateByServiceIdCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs { + + private object[] results; + + internal GetRdsCertificateByServiceIdCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : + base(exception, cancelled, userState) { + this.results = results; + } + + /// + public RdsCertificate Result { + get { + this.RaiseExceptionIfNecessary(); + return ((RdsCertificate)(this.results[0])); + } + } + } + + /// + [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] + public delegate void AddRdsCertificateCompletedEventHandler(object sender, AddRdsCertificateCompletedEventArgs e); + + /// + [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] + [System.Diagnostics.DebuggerStepThroughAttribute()] + [System.ComponentModel.DesignerCategoryAttribute("code")] + public partial class AddRdsCertificateCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs { + + private object[] results; + + internal AddRdsCertificateCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : + base(exception, cancelled, userState) { + this.results = results; + } + + /// + public ResultObject Result { + get { + this.RaiseExceptionIfNecessary(); + return ((ResultObject)(this.results[0])); + } + } + } } diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs index 49501ef1..d83c4684 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs @@ -4676,6 +4676,37 @@ namespace WebsitePanel.EnterpriseServer #region RDS + public static int AddRdsCertificate(int serviceId, string content, byte[] hash, string fileName, DateTime? validFrom, DateTime? expiryDate) + { + SqlParameter rdsCertificateId = new SqlParameter("@RDSCertificateID", SqlDbType.Int); + rdsCertificateId.Direction = ParameterDirection.Output; + + SqlHelper.ExecuteNonQuery( + ConnectionString, + CommandType.StoredProcedure, + "AddRDSCertificate", + rdsCertificateId, + new SqlParameter("@ServiceId", serviceId), + new SqlParameter("@Content", content), + new SqlParameter("@Hash", Convert.ToBase64String(hash)), + new SqlParameter("@FileName", fileName), + new SqlParameter("@ValidFrom", validFrom), + new SqlParameter("@ExpiryDate", expiryDate) + ); + + return Convert.ToInt32(rdsCertificateId.Value); + } + + public static IDataReader GetRdsCertificateByServiceId(int serviceId) + { + return SqlHelper.ExecuteReader( + ConnectionString, + CommandType.StoredProcedure, + "GetRDSCertificateByServiceId", + new SqlParameter("@ServiceId", serviceId) + ); + } + public static IDataReader GetRdsCollectionSettingsByCollectionId(int collectionId) { return SqlHelper.ExecuteReader( diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs index 269add07..763e96aa 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs @@ -278,19 +278,28 @@ namespace WebsitePanel.EnterpriseServer return SaveRdsCollectionLocalAdminsInternal(users, collectionId); } - public static ResultObject InstallSessionHostsCertificate(int collectionId, byte[] certificate, string password) + public static ResultObject InstallSessionHostsCertificate(RdsServer rdsServer) { - return InstallSessionHostsCertificateInternal(collectionId, certificate, password); + return InstallSessionHostsCertificateInternal(rdsServer); } - private static ResultObject InstallSessionHostsCertificateInternal(int collectionId, byte[] certificate, string password) + public static RdsCertificate GetRdsCertificateByServiceId(int serviceId) + { + return GetRdsCertificateByServiceIdInternal(serviceId); + } + + public static ResultObject AddRdsCertificate(RdsCertificate certificate) + { + return AddRdsCertificateInternal(certificate); + } + + private static ResultObject InstallSessionHostsCertificateInternal(RdsServer rdsServer) { var result = TaskManager.StartResultTask("REMOTE_DESKTOP_SERVICES", "INSTALL_CERTIFICATE"); try - { - var collection = ObjectUtils.FillObjectFromDataReader(DataProvider.GetRDSCollectionById(collectionId)); - Organization org = OrganizationController.GetOrganization(collection.ItemId); + { + Organization org = OrganizationController.GetOrganization(rdsServer.ItemId.Value); if (org == null) { @@ -299,10 +308,17 @@ namespace WebsitePanel.EnterpriseServer return result; } - var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId)); - var servers = ObjectUtils.CreateListFromDataReader(DataProvider.GetRDSServersByCollectionId(collection.Id)).ToList(); + int serviceId = GetRemoteDesktopServiceID(org.PackageId); + var rds = GetRemoteDesktopServices(serviceId); + var certificate = GetRdsCertificateByServiceIdInternal(serviceId); + + var array = Convert.FromBase64String(certificate.Hash); + char[] chars = new char[array.Length / sizeof(char)]; + System.Buffer.BlockCopy(array, 0, chars, 0, array.Length); + string password = new string(chars); + byte[] content = Convert.FromBase64String(certificate.Content); - rds.InstallCertificate(certificate, password, servers.Select(s => s.FqdName).ToArray()); + rds.InstallCertificate(content, password, new string[] {rdsServer.FqdName}); } catch (Exception ex) { @@ -323,6 +339,49 @@ namespace WebsitePanel.EnterpriseServer return result; } + private static RdsCertificate GetRdsCertificateByServiceIdInternal(int serviceId) + { + var result = ObjectUtils.FillObjectFromDataReader(DataProvider.GetRdsCertificateByServiceId(serviceId)); + + return result; + } + + private static ResultObject AddRdsCertificateInternal(RdsCertificate certificate) + { + var result = TaskManager.StartResultTask("REMOTE_DESKTOP_SERVICES", "ADD_RDS_SERVER"); + + try + { + byte[] hash = new byte[certificate.Hash.Length * sizeof(char)]; + System.Buffer.BlockCopy(certificate.Hash.ToCharArray(), 0, hash, 0, hash.Length); + certificate.Id = DataProvider.AddRdsCertificate(certificate.ServiceId, certificate.Content, hash, certificate.FileName, certificate.ValidFrom, certificate.ExpiryDate); + } + catch (Exception ex) + { + if (ex.InnerException != null) + { + result.AddError("Unable to add RDS Certificate", ex.InnerException); + } + else + { + result.AddError("Unable to add RDS Certificate", ex); + } + } + finally + { + if (!result.IsSuccess) + { + TaskManager.CompleteResultTask(result); + } + else + { + TaskManager.CompleteResultTask(); + } + } + + return result; + } + private static RdsCollection GetRdsCollectionInternal(int collectionId) { var collection = ObjectUtils.FillObjectFromDataReader(DataProvider.GetRDSCollectionById(collectionId)); @@ -370,7 +429,7 @@ namespace WebsitePanel.EnterpriseServer var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId)); var organizationUsers = OrganizationController.GetOrganizationUsersPaged(collection.ItemId, null, null, null, 0, Int32.MaxValue).PageUsers; - var organizationAdmins = rds.GetRdsCollectionLocalAdmins(servers.First().FqdName); + var organizationAdmins = rds.GetRdsCollectionLocalAdmins(org.OrganizationId, collection.Name); return organizationUsers.Where(o => organizationAdmins.Select(a => a.ToLower()).Contains(o.DomainUserName.ToLower())).ToList(); } @@ -394,7 +453,7 @@ namespace WebsitePanel.EnterpriseServer var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId)); var servers = ObjectUtils.CreateListFromDataReader(DataProvider.GetRDSServersByCollectionId(collection.Id)).ToList(); - rds.SaveRdsCollectionLocalAdmins(users, servers.Select(s => s.FqdName).ToArray()); + rds.SaveRdsCollectionLocalAdmins(users.Select(u => u.AccountName).ToArray(), servers.Select(s => s.FqdName).ToArray(), org.OrganizationId, collection.Name); } catch (Exception ex) { diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esRemoteDesktopServices.asmx.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esRemoteDesktopServices.asmx.cs index 8cd3ecdb..f377ff8d 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esRemoteDesktopServices.asmx.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esRemoteDesktopServices.asmx.cs @@ -327,9 +327,21 @@ namespace WebsitePanel.EnterpriseServer } [WebMethod] - public ResultObject InstallSessionHostsCertificate(int collectionId, byte[] certificate, string password) + public ResultObject InstallSessionHostsCertificate(RdsServer rdsServer) { - return RemoteDesktopServicesController.InstallSessionHostsCertificate(collectionId, certificate, password); + return RemoteDesktopServicesController.InstallSessionHostsCertificate(rdsServer); + } + + [WebMethod] + public RdsCertificate GetRdsCertificateByServiceId(int serviceId) + { + return RemoteDesktopServicesController.GetRdsCertificateByServiceId(serviceId); + } + + [WebMethod] + public ResultObject AddRdsCertificate(RdsCertificate certificate) + { + return RemoteDesktopServicesController.AddRdsCertificate(certificate); } } } diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs index a176c00f..695f2576 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs @@ -74,8 +74,8 @@ namespace WebsitePanel.Providers.RemoteDesktopServices string GetRdsServerStatus(string serverName); void ShutDownRdsServer(string serverName); void RestartRdsServer(string serverName); - void SaveRdsCollectionLocalAdmins(List users, List hosts); - List GetRdsCollectionLocalAdmins(string hostName); + void SaveRdsCollectionLocalAdmins(List users, List hosts, string collectionName, string organizationId); + List GetRdsCollectionLocalAdmins(string organizationId, string collectionName); void MoveRdsServerToTenantOU(string hostName, string organizationId); void RemoveRdsServerFromTenantOU(string hostName, string organizationId); void InstallCertificate(byte[] certificate, string password, List hostNames); diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsCertificate.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsCertificate.cs new file mode 100644 index 00000000..9d8e0e3e --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsCertificate.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace WebsitePanel.Providers.RemoteDesktopServices +{ + public class RdsCertificate + { + public int Id { get; set; } + public int ServiceId { get; set; } + public string FileName { get; set; } + public string Content { get; set; } + public string Hash { get; set; } + public DateTime? ValidFrom { get; set; } + public DateTime? ExpiryDate { get; set; } + } +} diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj b/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj index 752209d3..c0f01014 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj @@ -129,6 +129,7 @@ + diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs index a0015101..ca1b4c3b 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs @@ -64,6 +64,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices private const string Computers = "Computers"; private const string AdDcComputers = "Domain Controllers"; private const string Users = "users"; + private const string Admins = "Admins"; private const string RdsGroupFormat = "rds-{0}-{1}"; private const string RdsModuleName = "RemoteDesktopServices"; private const string AddNpsString = "netsh nps add np name=\"\"{0}\"\" policysource=\"1\" processingorder=\"{1}\" conditionid=\"0x3d\" conditiondata=\"^5$\" conditionid=\"0x1fb5\" conditiondata=\"{2}\" conditionid=\"0x1e\" conditiondata=\"UserAuthType:(PW|CA)\" profileid=\"0x1005\" profiledata=\"TRUE\" profileid=\"0x100f\" profiledata=\"TRUE\" profileid=\"0x1009\" profiledata=\"0x7\" profileid=\"0x1fe6\" profiledata=\"0x40000000\""; @@ -310,7 +311,8 @@ namespace WebsitePanel.Providers.RemoteDesktopServices //ActiveDirectoryUtils.AddObjectToGroup(GetComputerPath(ConnectionBroker), GetComputerGroupPath(organizationId, collection.Name)); } - CheckOrCreateHelpDeskComputerGroup(); + CheckOrCreateHelpDeskComputerGroup(); + string helpDeskGroupSamAccountName = CheckOrCreateAdGroup(GetHelpDeskGroupPath(RDSHelpDeskGroup), GetRootOUPath(), RDSHelpDeskGroup, RDSHelpDeskGroupDescription); if (!ActiveDirectoryUtils.AdObjectExists(GetUsersGroupPath(organizationId, collection.Name))) { @@ -347,7 +349,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices CreateLocalAdministratorsGroup(rdsServer.FqdName, runSpace); } - AddHelpDeskAdminsGroupToLocalAdmins(runSpace, rdsServer.FqdName); + AddAdGroupToLocalAdmins(runSpace, rdsServer.FqdName, helpDeskGroupSamAccountName); AddComputerToCollectionAdComputerGroup(organizationId, collection.Name, rdsServer); } } @@ -513,11 +515,13 @@ namespace WebsitePanel.Providers.RemoteDesktopServices foreach(var server in servers) { + RemoveGroupFromLocalAdmin(server.FqdName, server.Name, GetLocalAdminsGroupName(collectionName), runSpace); RemoveComputerFromCollectionAdComputerGroup(organizationId, collectionName, server); } ActiveDirectoryUtils.DeleteADObject(GetComputerGroupPath(organizationId, collectionName)); - ActiveDirectoryUtils.DeleteADObject(GetUsersGroupPath(organizationId, collectionName)); + ActiveDirectoryUtils.DeleteADObject(GetUsersGroupPath(organizationId, collectionName)); + ActiveDirectoryUtils.DeleteADObject(GetGroupPath(organizationId, collectionName, GetLocalAdminsGroupName(collectionName))); } catch (Exception e) { @@ -529,12 +533,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices } return result; - } - - public List GetCollectionUsers(string collectionName) - { - return GetUsersToCollectionAdGroup(collectionName); - } + } public bool SetUsersInCollection(string organizationId, string collectionName, List users) { @@ -542,7 +541,9 @@ namespace WebsitePanel.Providers.RemoteDesktopServices try { - SetUsersToCollectionAdGroup(collectionName, organizationId, users); + var usersGroupName = GetUsersGroupName(collectionName); + var usersGroupPath = GetUsersGroupPath(organizationId, collectionName); + SetUsersToCollectionAdGroup(collectionName, organizationId, users, usersGroupName, usersGroupPath); } catch (Exception e) { @@ -573,14 +574,15 @@ namespace WebsitePanel.Providers.RemoteDesktopServices ExecuteShellCommand(runSpace, cmd, false); - CheckOrCreateHelpDeskComputerGroup(); + CheckOrCreateHelpDeskComputerGroup(); + string helpDeskGroupSamAccountName = CheckOrCreateAdGroup(GetHelpDeskGroupPath(RDSHelpDeskGroup), GetRootOUPath(), RDSHelpDeskGroup, RDSHelpDeskGroupDescription); if (!CheckLocalAdminsGroupExists(server.FqdName, runSpace)) { CreateLocalAdministratorsGroup(server.FqdName, runSpace); } - AddHelpDeskAdminsGroupToLocalAdmins(runSpace, server.FqdName); + AddAdGroupToLocalAdmins(runSpace, server.FqdName, helpDeskGroupSamAccountName); AddComputerToCollectionAdComputerGroup(organizationId, collectionName, server); } catch (Exception e) @@ -616,6 +618,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices ExecuteShellCommand(runSpace, cmd, false); + RemoveGroupFromLocalAdmin(server.FqdName, server.Name, GetLocalAdminsGroupName(collectionName), runSpace); RemoveComputerFromCollectionAdComputerGroup(organizationId, collectionName, server); } finally @@ -978,7 +981,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices #region Local Admins - public void SaveRdsCollectionLocalAdmins(List users, List hosts) + public void SaveRdsCollectionLocalAdmins(List users, List hosts, string collectionName, string organizationId) { Runspace runspace = null; @@ -987,6 +990,10 @@ namespace WebsitePanel.Providers.RemoteDesktopServices runspace = OpenRunspace(); var index = ServerSettings.ADRootDomain.LastIndexOf("."); var domainName = ServerSettings.ADRootDomain; + string groupName = GetLocalAdminsGroupName(collectionName); + string groupPath = GetGroupPath(organizationId, collectionName, groupName); + string helpDeskGroupSamAccountName = CheckOrCreateAdGroup(GetHelpDeskGroupPath(RDSHelpDeskGroup), GetRootOUPath(), RDSHelpDeskGroup, RDSHelpDeskGroupDescription); + string localAdminsGroupSamAccountName = CheckOrCreateAdGroup(groupPath, GetOrganizationPath(organizationId), groupName, WspAdministratorsGroupDescription); if (index > 0) { @@ -1004,24 +1011,12 @@ namespace WebsitePanel.Providers.RemoteDesktopServices Log.WriteWarning(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray())); 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())); - var removedUsers = existingAdmins.Where(e => !formUsers.Contains(e)); + } - foreach (var user in newUsers) - { - AddNewLocalAdmin(hostName, user.SamAccountName, runspace); - } + AddAdGroupToLocalAdmins(runspace, hostName, helpDeskGroupSamAccountName); + AddAdGroupToLocalAdmins(runspace, hostName, localAdminsGroupSamAccountName); - foreach (var user in removedUsers) - { - RemoveLocalAdmin(hostName, user, runspace); - } - - AddHelpDeskAdminsGroupToLocalAdmins(runspace, hostName); + SetUsersToCollectionAdGroup(collectionName, organizationId, users, GetLocalAdminsGroupName(collectionName), groupPath); } } finally @@ -1030,27 +1025,11 @@ namespace WebsitePanel.Providers.RemoteDesktopServices } } - public List GetRdsCollectionLocalAdmins(string hostName) - { - Runspace runspace = null; - var result = new List(); - - try - { - runspace = OpenRunspace(); - - if (CheckLocalAdminsGroupExists(hostName, runspace)) - { - result = GetExistingLocalAdmins(hostName, runspace); - } - } - finally - { - CloseRunspace(runspace); - } - - return result; - } + public List GetRdsCollectionLocalAdmins(string organizationId, string collectionName) + { + string groupName = GetLocalAdminsGroupName(collectionName); + return GetUsersToCollectionAdGroup(collectionName, groupName, organizationId); + } private bool CheckLocalAdminsGroupExists(string hostName, Runspace runspace) { @@ -1097,59 +1076,19 @@ namespace WebsitePanel.Providers.RemoteDesktopServices } return errors; - } - - private List GetExistingLocalAdmins(string hostName, Runspace runspace) - { - var result = new List(); - - var scripts = new List - { - string.Format("net localgroup {0} | select -skip 6", WspAdministratorsGroupName) - }; - - object[] errors = null; - var exitingAdmins = ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors); - - if (!errors.Any()) - { - foreach(var user in exitingAdmins.Take(exitingAdmins.Count - 2)) - { - result.Add(user.ToString()); - } - } - - return result; - } - - private object[] AddNewLocalAdmin(string hostName, string samAccountName, Runspace runspace) - { + } + + private void RemoveGroupFromLocalAdmin(string fqdnName, string hostName, string groupName, Runspace runspace) + { var scripts = new List { string.Format("$GroupObj = [ADSI]\"WinNT://{0}/{1}\"", hostName, WspAdministratorsGroupName), - string.Format("$GroupObj.Add(\"WinNT://{0}/{1}\")", ServerSettings.ADRootDomain, samAccountName) + string.Format("$GroupObj.Remove(\"WinNT://{0}/{1}\")", ServerSettings.ADRootDomain, RDSHelpDeskGroup), + string.Format("$GroupObj.Remove(\"WinNT://{0}/{1}\")", ServerSettings.ADRootDomain, groupName) }; object[] errors = null; - ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors); - - return errors; - } - - private object[] RemoveLocalAdmin(string hostName, string user, Runspace runspace) - { - var userObject = user.Split('\\'); - - var scripts = new List - { - string.Format("$GroupObj = [ADSI]\"WinNT://{0}/{1}\"", hostName, WspAdministratorsGroupName), - string.Format("$GroupObj.Remove(\"WinNT://{0}/{1}\")", userObject[0], userObject[1]) - }; - - object[] errors = null; - ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors); - - return errors; + ExecuteRemoteShellCommand(runspace, fqdnName, scripts, out errors); } #endregion @@ -1177,23 +1116,22 @@ namespace WebsitePanel.Providers.RemoteDesktopServices } } - private void AddHelpDeskAdminsGroupToLocalAdmins(Runspace runspace, string hostName) - { - var helpDeskAdminsGroupPath = GetHelpDeskGroupPath(RDSHelpDeskGroup); + private string CheckOrCreateAdGroup(string groupPath, string rootPath, string groupName, string description) + { DirectoryEntry groupEntry = null; - if (!ActiveDirectoryUtils.AdObjectExists(helpDeskAdminsGroupPath)) + if (!ActiveDirectoryUtils.AdObjectExists(groupPath)) { - ActiveDirectoryUtils.CreateGroup(GetRootOUPath(), RDSHelpDeskGroup); - groupEntry = ActiveDirectoryUtils.GetADObject(helpDeskAdminsGroupPath); + ActiveDirectoryUtils.CreateGroup(rootPath, groupName); + groupEntry = ActiveDirectoryUtils.GetADObject(groupPath); if (groupEntry.Properties.Contains("Description")) { - groupEntry.Properties["Description"][0] = RDSHelpDeskGroupDescription; + groupEntry.Properties["Description"][0] = description; } else { - groupEntry.Properties["Description"].Add(RDSHelpDeskGroupDescription); + groupEntry.Properties["Description"].Add(description); } groupEntry.CommitChanges(); @@ -1201,11 +1139,14 @@ namespace WebsitePanel.Providers.RemoteDesktopServices if (groupEntry == null) { - groupEntry = ActiveDirectoryUtils.GetADObject(helpDeskAdminsGroupPath); + groupEntry = ActiveDirectoryUtils.GetADObject(groupPath); } - var samAccountName = ActiveDirectoryUtils.GetADObjectProperty(groupEntry, "sAMAccountName"); - + return ActiveDirectoryUtils.GetADObjectProperty(groupEntry, "sAMAccountName").ToString(); + } + + private void AddAdGroupToLocalAdmins(Runspace runspace, string hostName, string samAccountName) + { var scripts = new List { string.Format("$GroupObj = [ADSI]\"WinNT://{0}/{1}\"", hostName, WspAdministratorsGroupName), @@ -1227,7 +1168,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices try { var guid = Guid.NewGuid(); - var x509Cert = new X509Certificate2(certificate, password, X509KeyStorageFlags.Exportable); + var x509Cert = new X509Certificate2(certificate, password, X509KeyStorageFlags.Exportable); //var content = x509Cert.Export(X509ContentType.Pfx); var filePath = SaveCertificate(certificate, guid); runspace = OpenRunspace(); @@ -1355,21 +1296,17 @@ namespace WebsitePanel.Providers.RemoteDesktopServices return false; } - private void SetUsersToCollectionAdGroup(string collectionName, string organizationId, IEnumerable users) - { - var usersGroupName = GetUsersGroupName(collectionName); - var usersGroupPath = GetUsersGroupPath(organizationId, collectionName); + private void SetUsersToCollectionAdGroup(string collectionName, string organizationId, IEnumerable users, string groupName, string groupPath) + { var orgPath = GetOrganizationPath(organizationId); var orgEntry = ActiveDirectoryUtils.GetADObject(orgPath); - var groupUsers = ActiveDirectoryUtils.GetGroupObjects(usersGroupName, "user", orgEntry); - - //remove all users from group + var groupUsers = ActiveDirectoryUtils.GetGroupObjects(groupName, "user", orgEntry); + foreach (string userPath in groupUsers) { - ActiveDirectoryUtils.RemoveObjectFromGroup(userPath, usersGroupPath); + ActiveDirectoryUtils.RemoveObjectFromGroup(userPath, groupPath); } - - //adding users to group + foreach (var user in users) { var userPath = GetUserPath(organizationId, user); @@ -1377,20 +1314,19 @@ namespace WebsitePanel.Providers.RemoteDesktopServices if (ActiveDirectoryUtils.AdObjectExists(userPath)) { var userObject = ActiveDirectoryUtils.GetADObject(userPath); - var samName = (string)ActiveDirectoryUtils.GetADObjectProperty(userObject, "sAMAccountName"); - var userGroupsPath = GetUsersGroupPath(organizationId, collectionName); - ActiveDirectoryUtils.AddObjectToGroup(userPath, userGroupsPath); + var samName = (string)ActiveDirectoryUtils.GetADObjectProperty(userObject, "sAMAccountName"); + ActiveDirectoryUtils.AddObjectToGroup(userPath, groupPath); } } } - private List GetUsersToCollectionAdGroup(string collectionName) + private List GetUsersToCollectionAdGroup(string collectionName, string groupName, string organizationId) { - var users = new List(); + var users = new List(); + var orgPath = GetOrganizationPath(organizationId); + var orgEntry = ActiveDirectoryUtils.GetADObject(orgPath); - var usersGroupName = GetUsersGroupName(collectionName); - - foreach (string userPath in ActiveDirectoryUtils.GetGroupObjects(usersGroupName, "user")) + foreach (string userPath in ActiveDirectoryUtils.GetGroupObjects(groupName, "user", orgEntry)) { var userObject = ActiveDirectoryUtils.GetADObject(userPath); var samName = (string)ActiveDirectoryUtils.GetADObjectProperty(userObject, "sAMAccountName"); @@ -1738,6 +1674,11 @@ namespace WebsitePanel.Providers.RemoteDesktopServices return string.Format(RdsGroupFormat, collectionName, Users.ToLowerInvariant()); } + private string GetLocalAdminsGroupName(string collectionName) + { + return string.Format(RdsGroupFormat, collectionName, Admins.ToLowerInvariant()); + } + internal string GetComputerGroupPath(string organizationId, string collection) { StringBuilder sb = new StringBuilder(); @@ -1766,6 +1707,20 @@ namespace WebsitePanel.Providers.RemoteDesktopServices return sb.ToString(); } + private string GetGroupPath(string organizationId, string collectionName, string groupName) + { + StringBuilder sb = new StringBuilder(); + + AppendProtocol(sb); + AppendDomainController(sb); + AppendCNPath(sb, groupName); + AppendOUPath(sb, organizationId); + AppendOUPath(sb, RootOU); + AppendDomainPath(sb, RootDomain); + + return sb.ToString(); + } + private string GetUserPath(string organizationId, string loginName) { StringBuilder sb = new StringBuilder(); diff --git a/WebsitePanel/Sources/WebsitePanel.Server.Client/RemoteDesktopServicesProxy.cs b/WebsitePanel/Sources/WebsitePanel.Server.Client/RemoteDesktopServicesProxy.cs index 7d50298d..e9681bb1 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server.Client/RemoteDesktopServicesProxy.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server.Client/RemoteDesktopServicesProxy.cs @@ -18,7 +18,6 @@ namespace WebsitePanel.Providers.RemoteDesktopServices { using System.Web.Services.Protocols; using System; using System.Diagnostics; - using WebsitePanel.Providers.HostedSolution; /// @@ -1515,17 +1514,21 @@ namespace WebsitePanel.Providers.RemoteDesktopServices { /// [System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")] [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/SaveRdsCollectionLocalAdmins", 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 void SaveRdsCollectionLocalAdmins(OrganizationUser[] users, string[] hosts) { + public void SaveRdsCollectionLocalAdmins(string[] users, string[] hosts, string organizationId, string collectionName) { this.Invoke("SaveRdsCollectionLocalAdmins", new object[] { users, - hosts}); + hosts, + organizationId, + collectionName}); } /// - public System.IAsyncResult BeginSaveRdsCollectionLocalAdmins(OrganizationUser[] users, string[] hosts, System.AsyncCallback callback, object asyncState) { + public System.IAsyncResult BeginSaveRdsCollectionLocalAdmins(string[] users, string[] hosts, string organizationId, string collectionName, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("SaveRdsCollectionLocalAdmins", new object[] { users, - hosts}, callback, asyncState); + hosts, + organizationId, + collectionName}, callback, asyncState); } /// @@ -1534,18 +1537,20 @@ namespace WebsitePanel.Providers.RemoteDesktopServices { } /// - public void SaveRdsCollectionLocalAdminsAsync(OrganizationUser[] users, string[] hosts) { - this.SaveRdsCollectionLocalAdminsAsync(users, hosts, null); + public void SaveRdsCollectionLocalAdminsAsync(string[] users, string[] hosts, string organizationId, string collectionName) { + this.SaveRdsCollectionLocalAdminsAsync(users, hosts, organizationId, collectionName, null); } /// - public void SaveRdsCollectionLocalAdminsAsync(OrganizationUser[] users, string[] hosts, object userState) { + public void SaveRdsCollectionLocalAdminsAsync(string[] users, string[] hosts, string organizationId, string collectionName, object userState) { if ((this.SaveRdsCollectionLocalAdminsOperationCompleted == null)) { this.SaveRdsCollectionLocalAdminsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSaveRdsCollectionLocalAdminsOperationCompleted); } this.InvokeAsync("SaveRdsCollectionLocalAdmins", new object[] { users, - hosts}, this.SaveRdsCollectionLocalAdminsOperationCompleted, userState); + hosts, + organizationId, + collectionName}, this.SaveRdsCollectionLocalAdminsOperationCompleted, userState); } private void OnSaveRdsCollectionLocalAdminsOperationCompleted(object arg) { @@ -1558,16 +1563,18 @@ namespace WebsitePanel.Providers.RemoteDesktopServices { /// [System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")] [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/GetRdsCollectionLocalAdmins", 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 string[] GetRdsCollectionLocalAdmins(string hostName) { + public string[] GetRdsCollectionLocalAdmins(string organizationId, string collectionName) { object[] results = this.Invoke("GetRdsCollectionLocalAdmins", new object[] { - hostName}); + organizationId, + collectionName}); return ((string[])(results[0])); } /// - public System.IAsyncResult BeginGetRdsCollectionLocalAdmins(string hostName, System.AsyncCallback callback, object asyncState) { + public System.IAsyncResult BeginGetRdsCollectionLocalAdmins(string organizationId, string collectionName, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("GetRdsCollectionLocalAdmins", new object[] { - hostName}, callback, asyncState); + organizationId, + collectionName}, callback, asyncState); } /// @@ -1577,17 +1584,18 @@ namespace WebsitePanel.Providers.RemoteDesktopServices { } /// - public void GetRdsCollectionLocalAdminsAsync(string hostName) { - this.GetRdsCollectionLocalAdminsAsync(hostName, null); + public void GetRdsCollectionLocalAdminsAsync(string organizationId, string collectionName) { + this.GetRdsCollectionLocalAdminsAsync(organizationId, collectionName, null); } /// - public void GetRdsCollectionLocalAdminsAsync(string hostName, object userState) { + public void GetRdsCollectionLocalAdminsAsync(string organizationId, string collectionName, object userState) { if ((this.GetRdsCollectionLocalAdminsOperationCompleted == null)) { this.GetRdsCollectionLocalAdminsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetRdsCollectionLocalAdminsOperationCompleted); } this.InvokeAsync("GetRdsCollectionLocalAdmins", new object[] { - hostName}, this.GetRdsCollectionLocalAdminsOperationCompleted, userState); + organizationId, + collectionName}, this.GetRdsCollectionLocalAdminsOperationCompleted, userState); } private void OnGetRdsCollectionLocalAdminsOperationCompleted(object arg) { diff --git a/WebsitePanel/Sources/WebsitePanel.Server/RemoteDesktopServices.asmx.cs b/WebsitePanel/Sources/WebsitePanel.Server/RemoteDesktopServices.asmx.cs index 038cc907..9e49fb21 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server/RemoteDesktopServices.asmx.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server/RemoteDesktopServices.asmx.cs @@ -566,12 +566,12 @@ namespace WebsitePanel.Server } [WebMethod, SoapHeader("settings")] - public void SaveRdsCollectionLocalAdmins(List users, List hosts) + public void SaveRdsCollectionLocalAdmins(List users, List hosts, string organizationId, string collectionName) { try { Log.WriteStart("'{0}' SaveRdsCollectionLocalAdmins", ProviderSettings.ProviderName); - RDSProvider.SaveRdsCollectionLocalAdmins(users, hosts); + RDSProvider.SaveRdsCollectionLocalAdmins(users, hosts, collectionName, organizationId); Log.WriteEnd("'{0}' SaveRdsCollectionLocalAdmins", ProviderSettings.ProviderName); } catch (Exception ex) @@ -582,12 +582,12 @@ namespace WebsitePanel.Server } [WebMethod, SoapHeader("settings")] - public List GetRdsCollectionLocalAdmins(string hostName) + public List GetRdsCollectionLocalAdmins(string organizationId, string collectionName) { try { Log.WriteStart("'{0}' GetRdsCollectionLocalAdmins", ProviderSettings.ProviderName); - var result = RDSProvider.GetRdsCollectionLocalAdmins(hostName); + var result = RDSProvider.GetRdsCollectionLocalAdmins(organizationId, collectionName); Log.WriteEnd("'{0}' GetRdsCollectionLocalAdmins", ProviderSettings.ProviderName); return result; diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/App_GlobalResources/WebsitePanel_SharedResources.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/App_GlobalResources/WebsitePanel_SharedResources.ascx.resx index 033cf7f3..27590807 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/App_GlobalResources/WebsitePanel_SharedResources.ascx.resx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/App_GlobalResources/WebsitePanel_SharedResources.ascx.resx @@ -5656,6 +5656,9 @@ Session host certificate not installed + + Session host certificate has been installed + RDS Collection settings not updated diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/App_LocalResources/RDSServers.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/App_LocalResources/RDSServers.ascx.resx index 4677be06..a769c20c 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/App_LocalResources/RDSServers.ascx.resx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/App_LocalResources/RDSServers.ascx.resx @@ -120,6 +120,9 @@ Add RDS Server + + Status + The list of RDS Servers is empty.<br><br>To add a new Server click "Add RDS Sever" button. diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Helpers/RDSHelper.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Helpers/RDSHelper.cs index 0e13992a..9b7c00d2 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Helpers/RDSHelper.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Helpers/RDSHelper.cs @@ -52,11 +52,15 @@ namespace WebsitePanel.Portal { rdsServers = ES.Services.RDS.GetRdsServersPaged("", filterValue, sortColumn, startRowIndex, maximumRows); - return rdsServers.Servers; - //return new RdsServer[] { new RdsServer { Name = "rds.1.server", FqdName = "", Address = "127.0.0.1" }, - // new RdsServer { Name = "rds.2.server", FqdName = "", Address = "127.0.0.2" }, - // new RdsServer { Name = "rds.3.server", FqdName = "", Address = "127.0.0.3" }, - // new RdsServer { Name = "rds.4.server", FqdName = "", Address = "127.0.0.4" }}; + foreach (var rdsServer in rdsServers.Servers) + { + if (rdsServer.ItemId.HasValue) + { + rdsServer.Status = ES.Services.RDS.GetRdsServerStatus(rdsServer.ItemId.Value, rdsServer.FqdName); + } + } + + return rdsServers.Servers; } public int GetOrganizationRdsServersPagedCount(int itemId, string filterValue) diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/App_LocalResources/RDS_Settings.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/App_LocalResources/RDS_Settings.ascx.resx index f3221c01..1b443a76 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/App_LocalResources/RDS_Settings.ascx.resx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/App_LocalResources/RDS_Settings.ascx.resx @@ -126,4 +126,7 @@ Server Name + + Certificate Password: + \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/RDS_Settings.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/RDS_Settings.ascx index 879afc47..57dbeecb 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/RDS_Settings.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/RDS_Settings.ascx @@ -1,5 +1,17 @@ <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RDS_Settings.ascx.cs" Inherits="WebsitePanel.Portal.ProviderControls.RDS_Settings" %> - +
+ + + + + + + + -
+ + + +
diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/RDS_Settings.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/RDS_Settings.ascx.cs index 596af4e5..d85a1c61 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/RDS_Settings.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/RDS_Settings.ascx.cs @@ -31,6 +31,7 @@ using System.Collections.Generic; using System.Web.UI.WebControls; using WebsitePanel.EnterpriseServer; using WebsitePanel.Providers.Common; +using WebsitePanel.Providers.RemoteDesktopServices; namespace WebsitePanel.Portal.ProviderControls { @@ -54,11 +55,10 @@ namespace WebsitePanel.Portal.ProviderControls } public void BindSettings(System.Collections.Specialized.StringDictionary settings) - { + { txtConnectionBroker.Text = settings["ConnectionBroker"]; GWServers = settings["GWServrsList"]; - UpdateLyncServersGrid(); txtRootOU.Text = settings["RootOU"]; @@ -86,7 +86,26 @@ namespace WebsitePanel.Portal.ProviderControls settings["UseCentralNPS"] = chkUseCentralNPS.Checked.ToString(); settings["CentralNPS"] = chkUseCentralNPS.Checked ? txtCentralNPS.Text : string.Empty; - settings["GWServrsList"] = GWServers; + settings["GWServrsList"] = GWServers; + + try + { + if (upPFX.HasFile.Equals(true)) + { + var certificate = new RdsCertificate + { + ServiceId = PanelRequest.ServiceId, + Content = Convert.ToBase64String(upPFX.FileBytes), + FileName = upPFX.FileName, + Hash = txtPFXInstallPassword.Text + }; + + ES.Services.RDS.AddRdsCertificate(certificate); + } + } + catch (Exception) + { + } } protected void chkUseCentralNPS_CheckedChanged(object sender, EventArgs e) diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/RDS_Settings.ascx.designer.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/RDS_Settings.ascx.designer.cs index f0638a0c..9e1ba55e 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/RDS_Settings.ascx.designer.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/RDS_Settings.ascx.designer.cs @@ -1,31 +1,3 @@ -// Copyright (c) 2015, Outercurve Foundation. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, this -// list of conditions and the following disclaimer. -// -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// - Neither the name of the Outercurve Foundation nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -40,6 +12,24 @@ namespace WebsitePanel.Portal.ProviderControls { public partial class RDS_Settings { + /// + /// upPFX control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.FileUpload upPFX; + + /// + /// txtPFXInstallPassword control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.TextBox txtPFXInstallPassword; + /// /// lblConnectionBroker control. /// diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/RDSEditApplicationUsers.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/RDSEditApplicationUsers.ascx.resx index eb391f90..4d916746 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/RDSEditApplicationUsers.ascx.resx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/RDSEditApplicationUsers.ascx.resx @@ -153,4 +153,10 @@ Application Name + + Back to Applications List + + + Save Changes and Exit + \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCreateCollection.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCreateCollection.ascx index e7277028..9549a550 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCreateCollection.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCreateCollection.ascx @@ -28,27 +28,7 @@
- - - - - -
-
-
- -
-
- -
-
- -
-
-
-
+
diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCreateCollection.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCreateCollection.ascx.cs index 21ef3c4d..2d21ad7e 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCreateCollection.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCreateCollection.ascx.cs @@ -63,21 +63,7 @@ namespace WebsitePanel.Portal.RDS } RdsCollection collection = new RdsCollection{ Name = txtCollectionName.Text, DisplayName = txtCollectionName.Text, Servers = servers.GetServers(), Description = "" }; - int collectionId = ES.Services.RDS.AddRdsCollection(PanelRequest.ItemID, collection); - - try - { - if (upPFX.HasFile.Equals(true)) - { - byte[] pfx = upPFX.FileBytes; - string certPassword = txtPFXInstallPassword.Text; - //ES.Services.RDS.InstallSessionHostsCertificate(collectionId, pfx, certPassword); - } - } - catch(Exception ex) - { - messageBox.ShowErrorMessage("RDSSESSIONHOST_CERTIFICATE_NOT_INSTALLED", ex); - } + int collectionId = ES.Services.RDS.AddRdsCollection(PanelRequest.ItemID, collection); Response.Redirect(EditUrl("SpaceID", PanelSecurity.PackageId.ToString(), "rds_edit_collection", "CollectionId=" + collectionId, "ItemID=" + PanelRequest.ItemID)); } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCreateCollection.ascx.designer.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCreateCollection.ascx.designer.cs index f61636b8..b1666d95 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCreateCollection.ascx.designer.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCreateCollection.ascx.designer.cs @@ -75,42 +75,6 @@ namespace WebsitePanel.Portal.RDS { /// protected global::System.Web.UI.WebControls.RequiredFieldValidator valCollectionName; - /// - /// secSelectSertificate control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::WebsitePanel.Portal.CollapsiblePanel secSelectSertificate; - - /// - /// panelSelectSertificate control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Panel panelSelectSertificate; - - /// - /// upPFX control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.FileUpload upPFX; - - /// - /// txtPFXInstallPassword control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.TextBox txtPFXInstallPassword; - /// /// RDSServersPanel control. /// diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx index 6095f06d..e7cf4275 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx @@ -55,8 +55,12 @@
- + + +
diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx.cs index 41bdec12..2a9be753 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx.cs @@ -100,5 +100,10 @@ namespace WebsitePanel.Portal.RDS Response.Redirect(EditUrl("SpaceID", PanelSecurity.PackageId.ToString(), "rds_collection_edit_apps", "CollectionId=" + PanelRequest.CollectionID, "ItemID=" + PanelRequest.ItemID)); } } + + protected void btnExit_Click(object sender, EventArgs e) + { + Response.Redirect(EditUrl("SpaceID", PanelSecurity.PackageId.ToString(), "rds_collection_edit_apps", "CollectionId=" + PanelRequest.CollectionID, "ItemID=" + PanelRequest.ItemID)); + } } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx.designer.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx.designer.cs index fd65d541..62030191 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx.designer.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx.designer.cs @@ -139,12 +139,30 @@ namespace WebsitePanel.Portal.RDS { protected global::WebsitePanel.Portal.RDS.UserControls.RDSCollectionUsers users; /// - /// buttonPanel control. + /// btnSave control. /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// - protected global::WebsitePanel.Portal.ItemButtonPanel buttonPanel; + protected global::System.Web.UI.WebControls.Button btnSave; + + /// + /// btnSaveExit control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Button btnSaveExit; + + /// + /// btnExit control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Button btnExit; } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionApps.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionApps.ascx.cs index 15bf0ecc..0474d715 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionApps.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionApps.ascx.cs @@ -210,7 +210,7 @@ namespace WebsitePanel.Portal.RDS.UserControls RemoteApplication app = new RemoteApplication(); app.Alias = (string)gvApps.DataKeys[i][0]; - app.DisplayName = ((HyperLink)row.FindControl("lnkDisplayName")).Text; + app.DisplayName = ((LinkButton)row.FindControl("lnkDisplayName")).Text; app.FilePath = ((HiddenField)row.FindControl("hfFilePath")).Value; app.RequiredCommandLine = ((HiddenField)row.FindControl("hfRequiredCommandLine")).Value; diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDSServers.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDSServers.ascx index 0aa32a4e..c38baf43 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDSServers.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDSServers.ascx @@ -5,11 +5,18 @@ <%@ Register Src="UserControls/UserDetails.ascx" TagName="UserDetails" TagPrefix="uc2" %> <%@ Register Src="UserControls/CollapsiblePanel.ascx" TagName="CollapsiblePanel" TagPrefix="wsp" %> <%@ Register Src="UserControls/SimpleMessageBox.ascx" TagName="SimpleMessageBox" TagPrefix="wsp" %> +<%@ Register Src="UserControls/PopupHeader.ascx" TagName="PopupHeader" TagPrefix="wsp" %> +<%@ Register Src="UserControls/EnableAsyncTasksSupport.ascx" TagName="EnableAsyncTasksSupport" TagPrefix="wsp" %> - - + + + + + + +
@@ -43,11 +50,45 @@ - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + + + +