This commit is contained in:
Virtuworks 2015-02-23 17:30:16 -05:00
commit e6d3131e95
11 changed files with 275 additions and 145 deletions

View file

@ -2155,16 +2155,16 @@ namespace WebsitePanel.EnterpriseServer {
/// <remarks/> /// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/GetRdsCollectionLocalAdmins", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/GetRdsCollectionLocalAdmins", 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 OrganizationUser[] GetRdsCollectionLocalAdmins(int itemId) { public OrganizationUser[] GetRdsCollectionLocalAdmins(int collectionId) {
object[] results = this.Invoke("GetRdsCollectionLocalAdmins", new object[] { object[] results = this.Invoke("GetRdsCollectionLocalAdmins", new object[] {
itemId}); collectionId});
return ((OrganizationUser[])(results[0])); return ((OrganizationUser[])(results[0]));
} }
/// <remarks/> /// <remarks/>
public System.IAsyncResult BeginGetRdsCollectionLocalAdmins(int itemId, System.AsyncCallback callback, object asyncState) { public System.IAsyncResult BeginGetRdsCollectionLocalAdmins(int collectionId, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetRdsCollectionLocalAdmins", new object[] { return this.BeginInvoke("GetRdsCollectionLocalAdmins", new object[] {
itemId}, callback, asyncState); collectionId}, callback, asyncState);
} }
/// <remarks/> /// <remarks/>
@ -2174,17 +2174,17 @@ namespace WebsitePanel.EnterpriseServer {
} }
/// <remarks/> /// <remarks/>
public void GetRdsCollectionLocalAdminsAsync(int itemId) { public void GetRdsCollectionLocalAdminsAsync(int collectionId) {
this.GetRdsCollectionLocalAdminsAsync(itemId, null); this.GetRdsCollectionLocalAdminsAsync(collectionId, null);
} }
/// <remarks/> /// <remarks/>
public void GetRdsCollectionLocalAdminsAsync(int itemId, object userState) { public void GetRdsCollectionLocalAdminsAsync(int collectionId, object userState) {
if ((this.GetRdsCollectionLocalAdminsOperationCompleted == null)) { if ((this.GetRdsCollectionLocalAdminsOperationCompleted == null)) {
this.GetRdsCollectionLocalAdminsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetRdsCollectionLocalAdminsOperationCompleted); this.GetRdsCollectionLocalAdminsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetRdsCollectionLocalAdminsOperationCompleted);
} }
this.InvokeAsync("GetRdsCollectionLocalAdmins", new object[] { this.InvokeAsync("GetRdsCollectionLocalAdmins", new object[] {
itemId}, this.GetRdsCollectionLocalAdminsOperationCompleted, userState); collectionId}, this.GetRdsCollectionLocalAdminsOperationCompleted, userState);
} }
private void OnGetRdsCollectionLocalAdminsOperationCompleted(object arg) { private void OnGetRdsCollectionLocalAdminsOperationCompleted(object arg) {
@ -2196,18 +2196,18 @@ namespace WebsitePanel.EnterpriseServer {
/// <remarks/> /// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/SaveRdsCollectionLocalAdmins", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/SaveRdsCollectionLocalAdmins", 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 SaveRdsCollectionLocalAdmins(OrganizationUser[] users, int itemId) { public ResultObject SaveRdsCollectionLocalAdmins(OrganizationUser[] users, int collectionId) {
object[] results = this.Invoke("SaveRdsCollectionLocalAdmins", new object[] { object[] results = this.Invoke("SaveRdsCollectionLocalAdmins", new object[] {
users, users,
itemId}); collectionId});
return ((ResultObject)(results[0])); return ((ResultObject)(results[0]));
} }
/// <remarks/> /// <remarks/>
public System.IAsyncResult BeginSaveRdsCollectionLocalAdmins(OrganizationUser[] users, int itemId, System.AsyncCallback callback, object asyncState) { public System.IAsyncResult BeginSaveRdsCollectionLocalAdmins(OrganizationUser[] users, int collectionId, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("SaveRdsCollectionLocalAdmins", new object[] { return this.BeginInvoke("SaveRdsCollectionLocalAdmins", new object[] {
users, users,
itemId}, callback, asyncState); collectionId}, callback, asyncState);
} }
/// <remarks/> /// <remarks/>
@ -2217,18 +2217,18 @@ namespace WebsitePanel.EnterpriseServer {
} }
/// <remarks/> /// <remarks/>
public void SaveRdsCollectionLocalAdminsAsync(OrganizationUser[] users, int itemId) { public void SaveRdsCollectionLocalAdminsAsync(OrganizationUser[] users, int collectionId) {
this.SaveRdsCollectionLocalAdminsAsync(users, itemId, null); this.SaveRdsCollectionLocalAdminsAsync(users, collectionId, null);
} }
/// <remarks/> /// <remarks/>
public void SaveRdsCollectionLocalAdminsAsync(OrganizationUser[] users, int itemId, object userState) { public void SaveRdsCollectionLocalAdminsAsync(OrganizationUser[] users, int collectionId, object userState) {
if ((this.SaveRdsCollectionLocalAdminsOperationCompleted == null)) { if ((this.SaveRdsCollectionLocalAdminsOperationCompleted == null)) {
this.SaveRdsCollectionLocalAdminsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSaveRdsCollectionLocalAdminsOperationCompleted); this.SaveRdsCollectionLocalAdminsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSaveRdsCollectionLocalAdminsOperationCompleted);
} }
this.InvokeAsync("SaveRdsCollectionLocalAdmins", new object[] { this.InvokeAsync("SaveRdsCollectionLocalAdmins", new object[] {
users, users,
itemId}, this.SaveRdsCollectionLocalAdminsOperationCompleted, userState); collectionId}, this.SaveRdsCollectionLocalAdminsOperationCompleted, userState);
} }
private void OnSaveRdsCollectionLocalAdminsOperationCompleted(object arg) { private void OnSaveRdsCollectionLocalAdminsOperationCompleted(object arg) {

View file

@ -268,14 +268,14 @@ namespace WebsitePanel.EnterpriseServer
return RestartRdsServerInternal(itemId, fqdnName); return RestartRdsServerInternal(itemId, fqdnName);
} }
public static List<OrganizationUser> GetRdsCollectionLocalAdmins(int itemId) public static List<OrganizationUser> GetRdsCollectionLocalAdmins(int collectionId)
{ {
return GetRdsCollectionLocalAdminsInternal(itemId); return GetRdsCollectionLocalAdminsInternal(collectionId);
} }
public static ResultObject SaveRdsCollectionLocalAdmins(OrganizationUser[] users, int itemId) public static ResultObject SaveRdsCollectionLocalAdmins(OrganizationUser[] users, int collectionId)
{ {
return SaveRdsCollectionLocalAdminsInternal(users, itemId); return SaveRdsCollectionLocalAdminsInternal(users, collectionId);
} }
private static RdsCollection GetRdsCollectionInternal(int collectionId) private static RdsCollection GetRdsCollectionInternal(int collectionId)
@ -310,10 +310,12 @@ namespace WebsitePanel.EnterpriseServer
return collection; return collection;
} }
private static List<OrganizationUser> GetRdsCollectionLocalAdminsInternal(int itemId) private static List<OrganizationUser> GetRdsCollectionLocalAdminsInternal(int collectionId)
{ {
var result = new List<OrganizationUser>(); var result = new List<OrganizationUser>();
Organization org = OrganizationController.GetOrganization(itemId); var collection = ObjectUtils.FillObjectFromDataReader<RdsCollection>(DataProvider.GetRDSCollectionById(collectionId));
var servers = ObjectUtils.CreateListFromDataReader<RdsServer>(DataProvider.GetRDSServersByCollectionId(collection.Id)).ToList();
Organization org = OrganizationController.GetOrganization(collection.ItemId);
if (org == null) if (org == null)
{ {
@ -322,19 +324,20 @@ namespace WebsitePanel.EnterpriseServer
var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId)); var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
var organizationUsers = OrganizationController.GetOrganizationUsersPaged(itemId, null, null, null, 0, Int32.MaxValue).PageUsers; var organizationUsers = OrganizationController.GetOrganizationUsersPaged(collection.ItemId, null, null, null, 0, Int32.MaxValue).PageUsers;
var organizationAdmins = rds.GetRdsCollectionLocalAdmins(org.OrganizationId); var organizationAdmins = rds.GetRdsCollectionLocalAdmins(servers.First().FqdName);
return organizationUsers.Where(o => organizationAdmins.Select(a => a.ToLower()).Contains(o.SamAccountName.ToLower())).ToList(); return organizationUsers.Where(o => organizationAdmins.Select(a => a.ToLower()).Contains(o.DomainUserName.ToLower())).ToList();
} }
private static ResultObject SaveRdsCollectionLocalAdminsInternal(OrganizationUser[] users, int itemId) private static ResultObject SaveRdsCollectionLocalAdminsInternal(OrganizationUser[] users, int collectionId)
{ {
var result = TaskManager.StartResultTask<ResultObject>("REMOTE_DESKTOP_SERVICES", "SAVE_LOCAL_ADMINS"); var result = TaskManager.StartResultTask<ResultObject>("REMOTE_DESKTOP_SERVICES", "SAVE_LOCAL_ADMINS");
try try
{ {
Organization org = OrganizationController.GetOrganization(itemId); var collection = ObjectUtils.FillObjectFromDataReader<RdsCollection>(DataProvider.GetRDSCollectionById(collectionId));
Organization org = OrganizationController.GetOrganization(collection.ItemId);
if (org == null) if (org == null)
{ {
@ -344,7 +347,9 @@ namespace WebsitePanel.EnterpriseServer
} }
var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId)); var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
rds.SaveRdsCollectionLocalAdmins(users.Select(u => u.AccountName).ToArray(), org.OrganizationId); var servers = ObjectUtils.CreateListFromDataReader<RdsServer>(DataProvider.GetRDSServersByCollectionId(collection.Id)).ToList();
rds.SaveRdsCollectionLocalAdmins(users, servers.Select(s => s.FqdName).ToArray());
} }
catch (Exception ex) catch (Exception ex)
{ {

View file

@ -315,15 +315,15 @@ namespace WebsitePanel.EnterpriseServer
} }
[WebMethod] [WebMethod]
public List<OrganizationUser> GetRdsCollectionLocalAdmins(int itemId) public List<OrganizationUser> GetRdsCollectionLocalAdmins(int collectionId)
{ {
return RemoteDesktopServicesController.GetRdsCollectionLocalAdmins(itemId); return RemoteDesktopServicesController.GetRdsCollectionLocalAdmins(collectionId);
} }
[WebMethod] [WebMethod]
public ResultObject SaveRdsCollectionLocalAdmins(OrganizationUser[] users, int itemId) public ResultObject SaveRdsCollectionLocalAdmins(OrganizationUser[] users, int collectionId)
{ {
return RemoteDesktopServicesController.SaveRdsCollectionLocalAdmins(users, itemId); return RemoteDesktopServicesController.SaveRdsCollectionLocalAdmins(users, collectionId);
} }
} }
} }

View file

@ -31,6 +31,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using WebsitePanel.Providers.HostedSolution;
namespace WebsitePanel.Providers.RemoteDesktopServices namespace WebsitePanel.Providers.RemoteDesktopServices
{ {
@ -73,8 +74,8 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
string GetRdsServerStatus(string serverName); string GetRdsServerStatus(string serverName);
void ShutDownRdsServer(string serverName); void ShutDownRdsServer(string serverName);
void RestartRdsServer(string serverName); void RestartRdsServer(string serverName);
void SaveRdsCollectionLocalAdmins(List<string> users, string organizationId); void SaveRdsCollectionLocalAdmins(List<OrganizationUser> users, List<string> hosts);
List<string> GetRdsCollectionLocalAdmins(string organizationId); List<string> GetRdsCollectionLocalAdmins(string hostName);
void MoveRdsServerToTenantOU(string hostName, string organizationId); void MoveRdsServerToTenantOU(string hostName, string organizationId);
void RemoveRdsServerFromTenantOU(string hostName, string organizationId); void RemoveRdsServerFromTenantOU(string hostName, string organizationId);
} }

View file

@ -49,6 +49,7 @@ using System.Management.Automation.Runspaces;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.DirectoryServices; using System.DirectoryServices;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Collections;
namespace WebsitePanel.Providers.RemoteDesktopServices namespace WebsitePanel.Providers.RemoteDesktopServices
@ -66,8 +67,11 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
private const string RdsGroupFormat = "rds-{0}-{1}"; private const string RdsGroupFormat = "rds-{0}-{1}";
private const string RdsModuleName = "RemoteDesktopServices"; 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\""; 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\"";
private const string WspAdministratorsGroupName = "WSPAdministrators"; private const string WspAdministratorsGroupName = "WSP-Administrators";
private const string RdsServersOU = "RDSServers"; private const string WspAdministratorsGroupDescription = "WSP Administrators";
private const string RdsServersOU = "RDSServers";
private const uint ADS_GROUP_TYPE_UNIVERSAL_GROUP = 0x00000008;
private const uint ADS_GROUP_TYPE_SECURITY_ENABLED = 0x80000000;
#endregion #endregion
@ -954,101 +958,206 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
#region Local Admins #region Local Admins
public void SaveRdsCollectionLocalAdmins(List<string> users, string organizationId) public void SaveRdsCollectionLocalAdmins(List<OrganizationUser> users, List<string> hosts)
{ {
if (!CheckAdminsGroup(organizationId)) Runspace runspace = null;
{
CreateAdminsGroup(organizationId);
}
var orgPath = GetOrganizationPath(organizationId); try
var orgEntry = ActiveDirectoryUtils.GetADObject(orgPath);
var existingAdmins = ActiveDirectoryUtils.GetGroupObjects(WspAdministratorsGroupName, "user", orgEntry);
var adminsGroupPath = GetWspAdminsGroupPath(organizationId);
foreach (string userPath in existingAdmins)
{ {
ActiveDirectoryUtils.RemoveObjectFromGroup(userPath, adminsGroupPath); runspace = OpenRunspace();
} var index = ServerSettings.ADRootDomain.LastIndexOf(".");
var domainName = ServerSettings.ADRootDomain;
foreach (var user in users)
{
var userPath = GetUserPath(organizationId, user);
if (ActiveDirectoryUtils.AdObjectExists(userPath)) if (index > 0)
{ {
var userObject = ActiveDirectoryUtils.GetADObject(userPath); domainName = ServerSettings.ADRootDomain.Substring(0, index);
var samName = (string)ActiveDirectoryUtils.GetADObjectProperty(userObject, "sAMAccountName");
ActiveDirectoryUtils.AddObjectToGroup(userPath, adminsGroupPath);
} }
foreach (var hostName in hosts)
{
if (!CheckLocalAdminsGroupExists(hostName, runspace))
{
var errors = CreateLocalAdministratorsGroup(hostName, runspace);
if (errors.Any())
{
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);
}
foreach (var user in removedUsers)
{
RemoveLocalAdmin(hostName, user, runspace);
}
}
} }
finally
{
CloseRunspace(runspace);
}
} }
public List<string> GetRdsCollectionLocalAdmins(string organizationId) public List<string> GetRdsCollectionLocalAdmins(string hostName)
{ {
var adminsGroupPath = GetWspAdminsGroupPath(organizationId); Runspace runspace = null;
var orgPath = GetOrganizationPath(organizationId);
var orgEntry = ActiveDirectoryUtils.GetADObject(orgPath);
var rdsAdmins = ActiveDirectoryUtils.GetGroupObjects(WspAdministratorsGroupName, "user", orgEntry);
var rootPath = GetRootOUPath();
var rootEntry = ActiveDirectoryUtils.GetADObject(rootPath);
var collectionUsers = ActiveDirectoryUtils.GetGroupObjects(organizationId, "user", rootEntry);
var orgAdmins = collectionUsers.Intersect(rdsAdmins);
var result = new List<string>(); var result = new List<string>();
foreach (var admin in orgAdmins) try
{ {
var userObject = ActiveDirectoryUtils.GetADObject(admin); runspace = OpenRunspace();
var samName = (string)ActiveDirectoryUtils.GetADObjectProperty(userObject, "sAMAccountName");
result.Add(samName); if (CheckLocalAdminsGroupExists(hostName, runspace))
{
result = GetExistingLocalAdmins(hostName, runspace);
}
}
finally
{
CloseRunspace(runspace);
} }
return result; return result;
} }
private bool CheckAdminsGroup(string organizationId) private bool CheckLocalAdminsGroupExists(string hostName, Runspace runspace)
{ {
var adminsGroupPath = GetWspAdminsGroupPath(organizationId); var scripts = new List<string>
return ActiveDirectoryUtils.AdObjectExists(adminsGroupPath); {
string.Format("net localgroup {0}", WspAdministratorsGroupName)
};
object[] errors = null;
var result = ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors);
if (!errors.Any())
{
return true;
}
return false;
} }
private void CreateAdminsGroup(string organizationId) private object[] CreateLocalAdministratorsGroup(string hostName, Runspace runspace)
{ {
var adminsRootGroupPath = GetWspAdminsRootGroupPath(organizationId); var scripts = new List<string>
ActiveDirectoryUtils.CreateGroup(adminsRootGroupPath, WspAdministratorsGroupName);
string groupPath = string.Format("WinNT://{0}/{1}/{2},group", ServerSettings.ADRootDomain, PrimaryDomainController, WspAdministratorsGroupName);
using (var userGroup = new DirectoryEntry(groupPath))
{ {
string localAdministratorsPath = string.Format("WinNT://{0}/{1},group", PrimaryDomainController, "Administrators"); string.Format("$cn = [ADSI]\"WinNT://{0}\"", hostName),
string.Format("$group = $cn.Create(\"Group\", \"{0}\")", WspAdministratorsGroupName),
"$group.setinfo()",
string.Format("$group.description = \"{0}\"", WspAdministratorsGroupDescription),
"$group.setinfo()"
};
using (DirectoryEntry group = new DirectoryEntry(localAdministratorsPath)) object[] errors = null;
ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors);
if (!errors.Any())
{
scripts = new List<string>
{ {
group.Invoke("Add", groupPath); string.Format("$GroupObj = [ADSI]\"WinNT://{0}/Administrators\"", hostName),
group.CommitChanges(); string.Format("$GroupObj.Add(\"WinNT://{0}/{1}\")", hostName.ToLower().Replace(string.Format(".{0}", ServerSettings.ADRootDomain.ToLower()), ""), WspAdministratorsGroupName)
};
errors = null;
ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors);
}
return errors;
}
private List<string> GetExistingLocalAdmins(string hostName, Runspace runspace)
{
var result = new List<string>();
var scripts = new List<string>
{
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)
{
var scripts = new List<string>
{
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);
return errors;
}
private object[] RemoveLocalAdmin(string hostName, string user, Runspace runspace)
{
var userObject = user.Split('\\');
var scripts = new List<string>
{
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;
}
#endregion #endregion
#region SSL #region SSL
public void InstallCertificate(byte[] certificate, string password, string hostName) public void InstallCertificate(byte[] certificate, string password, string hostName)
{ {
var x509Cert = new X509Certificate2(certificate, password, X509KeyStorageFlags.Exportable); Runspace runspace = null;
try
{
var x509Cert = new X509Certificate2(certificate, password, X509KeyStorageFlags.Exportable);
runspace = OpenRunspace();
CopyCertificateFile(certificate, hostName, runspace);
}
finally
{
CloseRunspace(runspace);
}
} }
private string CopyCertificateFile(byte[] certificate, string hostName) private string CopyCertificateFile(byte[] certificate, string hostName, Runspace runspace)
{ {
var destinationPath = string.Format("\\{0}\\c$\\remoteCert.pfx", hostName); var destinationPath = string.Format("\\{0}\\c$\\remoteCert.pfx", hostName);
return destinationPath; return destinationPath;
} }
private void DeleteCertificate(string path) private void DeleteCertificate(string path, Runspace runspace)
{ {
} }
@ -1464,32 +1573,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
AppendDomainPath(sb, RootDomain); AppendDomainPath(sb, RootDomain);
return sb.ToString(); return sb.ToString();
} }
internal string GetWspAdminsRootGroupPath(string organizationId)
{
StringBuilder sb = new StringBuilder();
AppendProtocol(sb);
AppendDomainController(sb);
AppendOUPath(sb, organizationId);
AppendOUPath(sb, RootOU);
AppendDomainPath(sb, RootDomain);
return sb.ToString();
}
internal string GetWspAdminsGroupPath(string organizationId)
{
StringBuilder sb = new StringBuilder();
AppendProtocol(sb);
AppendDomainController(sb);
AppendCNPath(sb, WspAdministratorsGroupName);
AppendOUPath(sb, organizationId);
AppendOUPath(sb, RootOU);
AppendDomainPath(sb, RootDomain);
return sb.ToString();
}
internal string GetUsersGroupPath(string organizationId, string collection) internal string GetUsersGroupPath(string organizationId, string collection)
{ {
@ -1778,7 +1862,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
return ExecuteShellCommand(runSpace, invokeCommand, false, out errors); return ExecuteShellCommand(runSpace, invokeCommand, false, out errors);
} }
internal Collection<PSObject> ExecuteRemoteShellCommand(Runspace runSpace, string hostName, List<string> scripts, params string[] moduleImports) internal Collection<PSObject> ExecuteRemoteShellCommand(Runspace runSpace, string hostName, List<string> scripts, out object[] errors, params string[] moduleImports)
{ {
Command invokeCommand = new Command("Invoke-Command"); Command invokeCommand = new Command("Invoke-Command");
invokeCommand.Parameters.Add("ComputerName", hostName); invokeCommand.Parameters.Add("ComputerName", hostName);
@ -1792,7 +1876,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
invokeCommand.Parameters.Add("ScriptBlock", sb); invokeCommand.Parameters.Add("ScriptBlock", sb);
return ExecuteShellCommand(runSpace, invokeCommand, false); return ExecuteShellCommand(runSpace, invokeCommand, false, out errors);
} }
internal Collection<PSObject> ExecuteShellCommand(Runspace runSpace, Command cmd) internal Collection<PSObject> ExecuteShellCommand(Runspace runSpace, Command cmd)

View file

@ -18,6 +18,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices {
using System.Web.Services.Protocols; using System.Web.Services.Protocols;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using WebsitePanel.Providers.HostedSolution;
/// <remarks/> /// <remarks/>
@ -1506,17 +1507,17 @@ namespace WebsitePanel.Providers.RemoteDesktopServices {
/// <remarks/> /// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")] [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)] [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(string[] users, string organizationId) { public void SaveRdsCollectionLocalAdmins(OrganizationUser[] users, string[] hosts) {
this.Invoke("SaveRdsCollectionLocalAdmins", new object[] { this.Invoke("SaveRdsCollectionLocalAdmins", new object[] {
users, users,
organizationId}); hosts});
} }
/// <remarks/> /// <remarks/>
public System.IAsyncResult BeginSaveRdsCollectionLocalAdmins(string[] users, string organizationId, System.AsyncCallback callback, object asyncState) { public System.IAsyncResult BeginSaveRdsCollectionLocalAdmins(OrganizationUser[] users, string[] hosts, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("SaveRdsCollectionLocalAdmins", new object[] { return this.BeginInvoke("SaveRdsCollectionLocalAdmins", new object[] {
users, users,
organizationId}, callback, asyncState); hosts}, callback, asyncState);
} }
/// <remarks/> /// <remarks/>
@ -1525,18 +1526,18 @@ namespace WebsitePanel.Providers.RemoteDesktopServices {
} }
/// <remarks/> /// <remarks/>
public void SaveRdsCollectionLocalAdminsAsync(string[] users, string organizationId) { public void SaveRdsCollectionLocalAdminsAsync(OrganizationUser[] users, string[] hosts) {
this.SaveRdsCollectionLocalAdminsAsync(users, organizationId, null); this.SaveRdsCollectionLocalAdminsAsync(users, hosts, null);
} }
/// <remarks/> /// <remarks/>
public void SaveRdsCollectionLocalAdminsAsync(string[] users, string organizationId, object userState) { public void SaveRdsCollectionLocalAdminsAsync(OrganizationUser[] users, string[] hosts, object userState) {
if ((this.SaveRdsCollectionLocalAdminsOperationCompleted == null)) { if ((this.SaveRdsCollectionLocalAdminsOperationCompleted == null)) {
this.SaveRdsCollectionLocalAdminsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSaveRdsCollectionLocalAdminsOperationCompleted); this.SaveRdsCollectionLocalAdminsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSaveRdsCollectionLocalAdminsOperationCompleted);
} }
this.InvokeAsync("SaveRdsCollectionLocalAdmins", new object[] { this.InvokeAsync("SaveRdsCollectionLocalAdmins", new object[] {
users, users,
organizationId}, this.SaveRdsCollectionLocalAdminsOperationCompleted, userState); hosts}, this.SaveRdsCollectionLocalAdminsOperationCompleted, userState);
} }
private void OnSaveRdsCollectionLocalAdminsOperationCompleted(object arg) { private void OnSaveRdsCollectionLocalAdminsOperationCompleted(object arg) {
@ -1549,16 +1550,16 @@ namespace WebsitePanel.Providers.RemoteDesktopServices {
/// <remarks/> /// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")] [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)] [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 organizationId) { public string[] GetRdsCollectionLocalAdmins(string hostName) {
object[] results = this.Invoke("GetRdsCollectionLocalAdmins", new object[] { object[] results = this.Invoke("GetRdsCollectionLocalAdmins", new object[] {
organizationId}); hostName});
return ((string[])(results[0])); return ((string[])(results[0]));
} }
/// <remarks/> /// <remarks/>
public System.IAsyncResult BeginGetRdsCollectionLocalAdmins(string organizationId, System.AsyncCallback callback, object asyncState) { public System.IAsyncResult BeginGetRdsCollectionLocalAdmins(string hostName, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetRdsCollectionLocalAdmins", new object[] { return this.BeginInvoke("GetRdsCollectionLocalAdmins", new object[] {
organizationId}, callback, asyncState); hostName}, callback, asyncState);
} }
/// <remarks/> /// <remarks/>
@ -1568,17 +1569,17 @@ namespace WebsitePanel.Providers.RemoteDesktopServices {
} }
/// <remarks/> /// <remarks/>
public void GetRdsCollectionLocalAdminsAsync(string organizationId) { public void GetRdsCollectionLocalAdminsAsync(string hostName) {
this.GetRdsCollectionLocalAdminsAsync(organizationId, null); this.GetRdsCollectionLocalAdminsAsync(hostName, null);
} }
/// <remarks/> /// <remarks/>
public void GetRdsCollectionLocalAdminsAsync(string organizationId, object userState) { public void GetRdsCollectionLocalAdminsAsync(string hostName, object userState) {
if ((this.GetRdsCollectionLocalAdminsOperationCompleted == null)) { if ((this.GetRdsCollectionLocalAdminsOperationCompleted == null)) {
this.GetRdsCollectionLocalAdminsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetRdsCollectionLocalAdminsOperationCompleted); this.GetRdsCollectionLocalAdminsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetRdsCollectionLocalAdminsOperationCompleted);
} }
this.InvokeAsync("GetRdsCollectionLocalAdmins", new object[] { this.InvokeAsync("GetRdsCollectionLocalAdmins", new object[] {
organizationId}, this.GetRdsCollectionLocalAdminsOperationCompleted, userState); hostName}, this.GetRdsCollectionLocalAdminsOperationCompleted, userState);
} }
private void OnGetRdsCollectionLocalAdminsOperationCompleted(object arg) { private void OnGetRdsCollectionLocalAdminsOperationCompleted(object arg) {

View file

@ -42,6 +42,7 @@ using WebsitePanel.Providers;
using WebsitePanel.Providers.OS; using WebsitePanel.Providers.OS;
using WebsitePanel.Providers.RemoteDesktopServices; using WebsitePanel.Providers.RemoteDesktopServices;
using WebsitePanel.Server.Utils; using WebsitePanel.Server.Utils;
using WebsitePanel.Providers.HostedSolution;
namespace WebsitePanel.Server namespace WebsitePanel.Server
{ {
@ -565,12 +566,12 @@ namespace WebsitePanel.Server
} }
[WebMethod, SoapHeader("settings")] [WebMethod, SoapHeader("settings")]
public void SaveRdsCollectionLocalAdmins(List<string> users, string organizationId) public void SaveRdsCollectionLocalAdmins(List<OrganizationUser> users, List<string> hosts)
{ {
try try
{ {
Log.WriteStart("'{0}' SaveRdsCollectionLocalAdmins", ProviderSettings.ProviderName); Log.WriteStart("'{0}' SaveRdsCollectionLocalAdmins", ProviderSettings.ProviderName);
RDSProvider.SaveRdsCollectionLocalAdmins(users, organizationId); RDSProvider.SaveRdsCollectionLocalAdmins(users, hosts);
Log.WriteEnd("'{0}' SaveRdsCollectionLocalAdmins", ProviderSettings.ProviderName); Log.WriteEnd("'{0}' SaveRdsCollectionLocalAdmins", ProviderSettings.ProviderName);
} }
catch (Exception ex) catch (Exception ex)
@ -581,12 +582,12 @@ namespace WebsitePanel.Server
} }
[WebMethod, SoapHeader("settings")] [WebMethod, SoapHeader("settings")]
public List<string> GetRdsCollectionLocalAdmins(string organizationId) public List<string> GetRdsCollectionLocalAdmins(string hostName)
{ {
try try
{ {
Log.WriteStart("'{0}' GetRdsCollectionLocalAdmins", ProviderSettings.ProviderName); Log.WriteStart("'{0}' GetRdsCollectionLocalAdmins", ProviderSettings.ProviderName);
var result = RDSProvider.GetRdsCollectionLocalAdmins(organizationId); var result = RDSProvider.GetRdsCollectionLocalAdmins(hostName);
Log.WriteEnd("'{0}' GetRdsCollectionLocalAdmins", ProviderSettings.ProviderName); Log.WriteEnd("'{0}' GetRdsCollectionLocalAdmins", ProviderSettings.ProviderName);
return result; return result;

View file

@ -5659,6 +5659,9 @@
<data name="ERROR.RDSSERVER_NOT_ASSIGNED" xml:space="preserve"> <data name="ERROR.RDSSERVER_NOT_ASSIGNED" xml:space="preserve">
<value>RDS server not assigned to organization</value> <value>RDS server not assigned to organization</value>
</data> </data>
<data name="ERROR.RDSLOCALADMINS_NOT_ADDED" xml:space="preserve">
<value>Local admins not added</value>
</data>
<data name="ERROR.REMOTE_DESKTOP_SERVICES_LOG_OFF_USER" xml:space="preserve"> <data name="ERROR.REMOTE_DESKTOP_SERVICES_LOG_OFF_USER" xml:space="preserve">
<value>RDS User logging off error</value> <value>RDS User logging off error</value>
</data> </data>

View file

@ -30,7 +30,7 @@
</tr> </tr>
</table> </table>
<%--<wsp:CollapsiblePanel id="secSelectSertificate" runat="server" <wsp:CollapsiblePanel id="secSelectSertificate" runat="server"
TargetControlID="panelSelectSertificate" meta:resourcekey="secSelectSertificate" Text=""> TargetControlID="panelSelectSertificate" meta:resourcekey="secSelectSertificate" Text="">
</wsp:CollapsiblePanel> </wsp:CollapsiblePanel>
@ -48,7 +48,7 @@
</div> </div>
</div> </div>
</div> </div>
</asp:Panel> --%> </asp:Panel>
<fieldset id="RDSServersPanel" runat="server"> <fieldset id="RDSServersPanel" runat="server">
<legend><asp:Localize ID="locRDSServersSection" runat="server" meta:resourcekey="locRDSServersSection" Text="RDS Servers"></asp:Localize></legend> <legend><asp:Localize ID="locRDSServersSection" runat="server" meta:resourcekey="locRDSServersSection" Text="RDS Servers"></asp:Localize></legend>

View file

@ -75,6 +75,42 @@ namespace WebsitePanel.Portal.RDS {
/// </remarks> /// </remarks>
protected global::System.Web.UI.WebControls.RequiredFieldValidator valCollectionName; protected global::System.Web.UI.WebControls.RequiredFieldValidator valCollectionName;
/// <summary>
/// secSelectSertificate control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::WebsitePanel.Portal.CollapsiblePanel secSelectSertificate;
/// <summary>
/// panelSelectSertificate control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Panel panelSelectSertificate;
/// <summary>
/// upPFX control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.FileUpload upPFX;
/// <summary>
/// txtPFXInstallPassword control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.TextBox txtPFXInstallPassword;
/// <summary> /// <summary>
/// RDSServersPanel control. /// RDSServersPanel control.
/// </summary> /// </summary>

View file

@ -12,9 +12,8 @@ namespace WebsitePanel.Portal.RDS
protected void Page_Load(object sender, EventArgs e) protected void Page_Load(object sender, EventArgs e)
{ {
if (!IsPostBack) if (!IsPostBack)
{ {
var organizationUsers = ES.Services.Organizations.GetOrganizationUsersPaged(PanelRequest.ItemID, null, null, null, 0, Int32.MaxValue).PageUsers; var collectionLocalAdmins = ES.Services.RDS.GetRdsCollectionLocalAdmins(PanelRequest.CollectionID);
var collectionLocalAdmins = ES.Services.RDS.GetRdsCollectionLocalAdmins(PanelRequest.ItemID);
var collection = ES.Services.RDS.GetRdsCollection(PanelRequest.CollectionID); var collection = ES.Services.RDS.GetRdsCollection(PanelRequest.CollectionID);
litCollectionName.Text = collection.DisplayName; litCollectionName.Text = collection.DisplayName;
@ -26,11 +25,11 @@ namespace WebsitePanel.Portal.RDS
{ {
try try
{ {
ES.Services.RDS.SaveRdsCollectionLocalAdmins(users.GetUsers(), PanelRequest.ItemID); ES.Services.RDS.SaveRdsCollectionLocalAdmins(users.GetUsers(), PanelRequest.CollectionID);
} }
catch (Exception ex) catch (Exception ex)
{ {
messageBox.ShowErrorMessage(ex.Message); ShowErrorMessage("RDSLOCALADMINS_NOT_ADDED", ex);
return false; return false;
} }