RDS HelpDesk Admins Group

This commit is contained in:
vfedosevich 2015-02-26 23:13:23 -08:00
parent 6139b499a9
commit b3066aabfd
6 changed files with 92 additions and 43 deletions

View file

@ -663,8 +663,8 @@ namespace WebsitePanel.EnterpriseServer
} }
var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId)); var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
var servers = ObjectUtils.CreateListFromDataReader<RdsServer>(DataProvider.GetRDSServersByCollectionId(collection.Id)).ToArray();
rds.RemoveCollection(org.OrganizationId, collection.Name); rds.RemoveCollection(org.OrganizationId, collection.Name, servers);
DataProvider.DeleteRDSCollection(collection.Id); DataProvider.DeleteRDSCollection(collection.Id);
} }

View file

@ -43,7 +43,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
bool CreateCollection(string organizationId, RdsCollection collection); bool CreateCollection(string organizationId, RdsCollection collection);
bool AddRdsServersToDeployment(RdsServer[] servers); bool AddRdsServersToDeployment(RdsServer[] servers);
RdsCollection GetCollection(string collectionName); RdsCollection GetCollection(string collectionName);
bool RemoveCollection(string organizationId, string collectionName); bool RemoveCollection(string organizationId, string collectionName, List<RdsServer> servers);
bool SetUsersInCollection(string organizationId, string collectionName, List<string> users); bool SetUsersInCollection(string organizationId, string collectionName, List<string> users);
void AddSessionHostServerToCollection(string organizationId, string collectionName, RdsServer server); void AddSessionHostServerToCollection(string organizationId, string collectionName, RdsServer server);
void AddSessionHostServersToCollection(string organizationId, string collectionName, List<RdsServer> servers); void AddSessionHostServersToCollection(string organizationId, string collectionName, List<RdsServer> servers);

View file

@ -71,6 +71,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
private const string WspAdministratorsGroupDescription = "WSP Administrators"; private const string WspAdministratorsGroupDescription = "WSP Administrators";
private const string RdsServersOU = "RDSServers"; private const string RdsServersOU = "RDSServers";
private const string RDSHelpDeskComputerGroup = "Websitepanel-RDSHelpDesk-Computer"; private const string RDSHelpDeskComputerGroup = "Websitepanel-RDSHelpDesk-Computer";
private const string RDSHelpDeskAdminsGroup = "WSP-HelpdeskAdmins";
#endregion #endregion
@ -308,10 +309,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
//ActiveDirectoryUtils.AddObjectToGroup(GetComputerPath(ConnectionBroker), GetComputerGroupPath(organizationId, collection.Name)); //ActiveDirectoryUtils.AddObjectToGroup(GetComputerPath(ConnectionBroker), GetComputerGroupPath(organizationId, collection.Name));
} }
if (!ActiveDirectoryUtils.AdObjectExists(GetHelpDeskComputerGroupPath())) CheckOrCreateHelpDeskComputerGroup();
{
ActiveDirectoryUtils.CreateGroup(GetRootOUPath(), RDSHelpDeskComputerGroup);
}
if (!ActiveDirectoryUtils.AdObjectExists(GetUsersGroupPath(organizationId, collection.Name))) if (!ActiveDirectoryUtils.AdObjectExists(GetUsersGroupPath(organizationId, collection.Name)))
{ {
@ -343,6 +341,12 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
//add session servers to group //add session servers to group
foreach (var rdsServer in collection.Servers) foreach (var rdsServer in collection.Servers)
{ {
if (!CheckLocalAdminsGroupExists(rdsServer.FqdName, runSpace))
{
CreateLocalAdministratorsGroup(rdsServer.FqdName, runSpace);
}
AddHelpDeskAdminsGroupToLocalAdmins(runSpace, rdsServer.FqdName);
AddComputerToCollectionAdComputerGroup(organizationId, collection.Name, rdsServer); AddComputerToCollectionAdComputerGroup(organizationId, collection.Name, rdsServer);
} }
} }
@ -471,7 +475,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
return collection; return collection;
} }
public bool RemoveCollection(string organizationId, string collectionName) public bool RemoveCollection(string organizationId, string collectionName, List<RdsServer> servers)
{ {
var result = true; var result = true;
@ -506,7 +510,10 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
RemoveNpsPolicy(runSpace, CentralNpsHost, capPolicyName); RemoveNpsPolicy(runSpace, CentralNpsHost, capPolicyName);
} }
//Remove security group foreach(var server in servers)
{
RemoveComputerFromCollectionAdComputerGroup(organizationId, collectionName, server);
}
ActiveDirectoryUtils.DeleteADObject(GetComputerGroupPath(organizationId, collectionName)); ActiveDirectoryUtils.DeleteADObject(GetComputerGroupPath(organizationId, collectionName));
ActiveDirectoryUtils.DeleteADObject(GetUsersGroupPath(organizationId, collectionName)); ActiveDirectoryUtils.DeleteADObject(GetUsersGroupPath(organizationId, collectionName));
@ -565,11 +572,14 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
ExecuteShellCommand(runSpace, cmd, false); ExecuteShellCommand(runSpace, cmd, false);
if (!ActiveDirectoryUtils.AdObjectExists(GetHelpDeskComputerGroupPath())) CheckOrCreateHelpDeskComputerGroup();
if (!CheckLocalAdminsGroupExists(server.FqdName, runSpace))
{ {
ActiveDirectoryUtils.CreateGroup(GetRootOUPath(), RDSHelpDeskComputerGroup); CreateLocalAdministratorsGroup(server.FqdName, runSpace);
} }
AddHelpDeskAdminsGroupToLocalAdmins(runSpace, server.FqdName);
AddComputerToCollectionAdComputerGroup(organizationId, collectionName, server); AddComputerToCollectionAdComputerGroup(organizationId, collectionName, server);
} }
catch (Exception e) catch (Exception e)
@ -1009,6 +1019,8 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
{ {
RemoveLocalAdmin(hostName, user, runspace); RemoveLocalAdmin(hostName, user, runspace);
} }
AddHelpDeskAdminsGroupToLocalAdmins(runspace, hostName);
} }
} }
finally finally
@ -1141,6 +1153,53 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
#endregion #endregion
#region RDS Help Desk
private string GetHelpDeskGroupPath(string groupName)
{
StringBuilder sb = new StringBuilder();
AppendProtocol(sb);
AppendDomainController(sb);
AppendCNPath(sb, groupName);
AppendOUPath(sb, RootOU);
AppendDomainPath(sb, RootDomain);
return sb.ToString();
}
private void CheckOrCreateHelpDeskComputerGroup()
{
if (!ActiveDirectoryUtils.AdObjectExists(GetHelpDeskGroupPath(RDSHelpDeskComputerGroup)))
{
ActiveDirectoryUtils.CreateGroup(GetRootOUPath(), RDSHelpDeskComputerGroup);
}
}
private void AddHelpDeskAdminsGroupToLocalAdmins(Runspace runspace, string hostName)
{
var helpDeskAdminsGroupPath = GetHelpDeskGroupPath(RDSHelpDeskAdminsGroup);
if (!ActiveDirectoryUtils.AdObjectExists(helpDeskAdminsGroupPath))
{
ActiveDirectoryUtils.CreateGroup(GetRootOUPath(), RDSHelpDeskAdminsGroup);
}
var groupEntry = ActiveDirectoryUtils.GetADObject(helpDeskAdminsGroupPath);
var samAccountName = ActiveDirectoryUtils.GetADObjectProperty(groupEntry, "sAMAccountName");
var scripts = new List<string>
{
string.Format("$GroupObj = [ADSI]\"WinNT://{0}/{1}\"", hostName, WspAdministratorsGroupName),
string.Format("$GroupObj.Add(\"WinNT://{0}/{1}\")", ServerSettings.ADRootDomain, samAccountName)
};
object[] errors = null;
ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors);
}
#endregion
#region SSL #region SSL
public void InstallCertificate(byte[] certificate, string password, List<string> hostNames) public void InstallCertificate(byte[] certificate, string password, List<string> hostNames)
@ -1356,7 +1415,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
if (!ActiveDirectoryUtils.IsComputerInGroup(samName, RDSHelpDeskComputerGroup)) if (!ActiveDirectoryUtils.IsComputerInGroup(samName, RDSHelpDeskComputerGroup))
{ {
ActiveDirectoryUtils.AddObjectToGroup(computerPath, GetHelpDeskComputerGroupPath()); ActiveDirectoryUtils.AddObjectToGroup(computerPath, GetHelpDeskGroupPath(RDSHelpDeskComputerGroup));
} }
} }
@ -1383,11 +1442,11 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
ActiveDirectoryUtils.RemoveObjectFromGroup(computerPath, GetComputerGroupPath(organizationId, collectionName)); ActiveDirectoryUtils.RemoveObjectFromGroup(computerPath, GetComputerGroupPath(organizationId, collectionName));
} }
if (ActiveDirectoryUtils.AdObjectExists(GetHelpDeskComputerGroupPath())) if (ActiveDirectoryUtils.AdObjectExists(GetHelpDeskGroupPath(RDSHelpDeskComputerGroup)))
{ {
if (ActiveDirectoryUtils.IsComputerInGroup(samName, RDSHelpDeskComputerGroup)) if (ActiveDirectoryUtils.IsComputerInGroup(samName, RDSHelpDeskComputerGroup))
{ {
ActiveDirectoryUtils.RemoveObjectFromGroup(computerPath, GetHelpDeskComputerGroupPath()); ActiveDirectoryUtils.RemoveObjectFromGroup(computerPath, GetHelpDeskGroupPath(RDSHelpDeskComputerGroup));
} }
} }
} }
@ -1675,19 +1734,6 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
return sb.ToString(); return sb.ToString();
} }
internal string GetHelpDeskComputerGroupPath()
{
StringBuilder sb = new StringBuilder();
AppendProtocol(sb);
AppendDomainController(sb);
AppendCNPath(sb, RDSHelpDeskComputerGroup);
AppendOUPath(sb, RootOU);
AppendDomainPath(sb, RootDomain);
return sb.ToString();
}
internal string GetUsersGroupPath(string organizationId, string collection) internal string GetUsersGroupPath(string organizationId, string collection)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

View file

@ -424,18 +424,20 @@ 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/RemoveCollection", RequestNamespace="http://smbsaas/websitepanel/server/", ResponseNamespace="http://smbsaas/websitepanel/server/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/RemoveCollection", RequestNamespace="http://smbsaas/websitepanel/server/", ResponseNamespace="http://smbsaas/websitepanel/server/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public bool RemoveCollection(string organizationId, string collectionName) { public bool RemoveCollection(string organizationId, string collectionName, RdsServer[] servers) {
object[] results = this.Invoke("RemoveCollection", new object[] { object[] results = this.Invoke("RemoveCollection", new object[] {
organizationId, organizationId,
collectionName}); collectionName,
servers});
return ((bool)(results[0])); return ((bool)(results[0]));
} }
/// <remarks/> /// <remarks/>
public System.IAsyncResult BeginRemoveCollection(string organizationId, string collectionName, System.AsyncCallback callback, object asyncState) { public System.IAsyncResult BeginRemoveCollection(string organizationId, string collectionName, RdsServer[] servers, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("RemoveCollection", new object[] { return this.BeginInvoke("RemoveCollection", new object[] {
organizationId, organizationId,
collectionName}, callback, asyncState); collectionName,
servers}, callback, asyncState);
} }
/// <remarks/> /// <remarks/>
@ -445,18 +447,19 @@ namespace WebsitePanel.Providers.RemoteDesktopServices {
} }
/// <remarks/> /// <remarks/>
public void RemoveCollectionAsync(string organizationId, string collectionName) { public void RemoveCollectionAsync(string organizationId, string collectionName, RdsServer[] servers) {
this.RemoveCollectionAsync(organizationId, collectionName, null); this.RemoveCollectionAsync(organizationId, collectionName, servers, null);
} }
/// <remarks/> /// <remarks/>
public void RemoveCollectionAsync(string organizationId, string collectionName, object userState) { public void RemoveCollectionAsync(string organizationId, string collectionName, RdsServer[] servers, object userState) {
if ((this.RemoveCollectionOperationCompleted == null)) { if ((this.RemoveCollectionOperationCompleted == null)) {
this.RemoveCollectionOperationCompleted = new System.Threading.SendOrPostCallback(this.OnRemoveCollectionOperationCompleted); this.RemoveCollectionOperationCompleted = new System.Threading.SendOrPostCallback(this.OnRemoveCollectionOperationCompleted);
} }
this.InvokeAsync("RemoveCollection", new object[] { this.InvokeAsync("RemoveCollection", new object[] {
organizationId, organizationId,
collectionName}, this.RemoveCollectionOperationCompleted, userState); collectionName,
servers}, this.RemoveCollectionOperationCompleted, userState);
} }
private void OnRemoveCollectionOperationCompleted(object arg) { private void OnRemoveCollectionOperationCompleted(object arg) {

View file

@ -146,12 +146,12 @@ namespace WebsitePanel.Server
} }
[WebMethod, SoapHeader("settings")] [WebMethod, SoapHeader("settings")]
public bool RemoveCollection(string organizationId, string collectionName) public bool RemoveCollection(string organizationId, string collectionName, List<RdsServer> servers)
{ {
try try
{ {
Log.WriteStart("'{0}' RemoveCollection", ProviderSettings.ProviderName); Log.WriteStart("'{0}' RemoveCollection", ProviderSettings.ProviderName);
var result = RDSProvider.RemoveCollection(organizationId, collectionName); var result = RDSProvider.RemoveCollection(organizationId, collectionName, servers);
Log.WriteEnd("'{0}' RemoveCollection", ProviderSettings.ProviderName); Log.WriteEnd("'{0}' RemoveCollection", ProviderSettings.ProviderName);
return result; return result;
} }

View file

@ -33,7 +33,7 @@
<asp:TemplateField> <asp:TemplateField>
<ItemStyle Width="20px" /> <ItemStyle Width="20px" />
<ItemTemplate> <ItemTemplate>
<asp:Image ID="UsersImage" ImageUrl='<%# PortalUtils.GetThemedImage("user_16.png")%>' runat="server" Visible='<%# Eval("Users") != null %>'/> <asp:Image ID="UsersImage" ImageUrl='<%# PortalUtils.GetThemedImage("Exchange/accounting_mail_16.png")%>' runat="server" Visible='<%# Eval("Users") != null %>'/>
</ItemTemplate> </ItemTemplate>
</asp:TemplateField> </asp:TemplateField>
</Columns> </Columns>