RDS fixes
This commit is contained in:
parent
fd8ca11f38
commit
743563baa2
3 changed files with 71 additions and 104 deletions
|
@ -71,8 +71,8 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
|
|||
private const string WspAdministratorsGroupDescription = "WSP RDS Collection Adminstrators";
|
||||
private const string RdsCollectionUsersGroupDescription = "WSP RDS Collection Users";
|
||||
private const string RdsCollectionComputersGroupDescription = "WSP RDS Collection Computers";
|
||||
private const string RdsServersOU = "RDSServers";
|
||||
private const string RdsServersRootOU = "RDSRootServers";
|
||||
private const string RdsServersOU = "RDSServersOU";
|
||||
private const string RdsServersRootOU = "RDSRootServersOU";
|
||||
private const string RDSHelpDeskComputerGroup = "Websitepanel-RDSHelpDesk-Computer";
|
||||
private const string RDSHelpDeskGroup = "WSP-HelpDeskAdministrators";
|
||||
private const string RDSHelpDeskGroupDescription = "WSP Help Desk Administrators";
|
||||
|
@ -339,11 +339,12 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
|
|||
}
|
||||
|
||||
//add user group to collection
|
||||
AddUserGroupsToCollection(runSpace, collection.Name, new List<string> { GetUsersGroupName(collection.Name) });
|
||||
AddUserGroupsToCollection(runSpace, collection.Name, new List<string> { GetUsersGroupName(collection.Name) });
|
||||
|
||||
//add session servers to group
|
||||
foreach (var rdsServer in collection.Servers)
|
||||
{
|
||||
{
|
||||
MoveRdsServerToTenantOU(rdsServer.Name, organizationId);
|
||||
AddAdGroupToLocalAdmins(runSpace, rdsServer.FqdName, helpDeskGroupSamAccountName);
|
||||
AddAdGroupToLocalAdmins(runSpace, rdsServer.FqdName, localAdminsGroupSamAccountName);
|
||||
AddComputerToCollectionAdComputerGroup(organizationId, collection.Name, rdsServer);
|
||||
|
@ -1281,28 +1282,22 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
|
|||
}
|
||||
|
||||
private void AddComputerToCollectionAdComputerGroup(string organizationId, string collectionName, RdsServer server)
|
||||
{
|
||||
var computerPath = GetComputerPath(server.Name, false);
|
||||
var computerGroupName = GetComputersGroupName( collectionName);
|
||||
{
|
||||
var computerGroupName = GetComputersGroupName( collectionName);
|
||||
var computerObject = GetComputerObject(server.Name);
|
||||
|
||||
if (!ActiveDirectoryUtils.AdObjectExists(computerPath))
|
||||
{
|
||||
computerPath = GetComputerPath(server.Name, true);
|
||||
}
|
||||
|
||||
if (ActiveDirectoryUtils.AdObjectExists(computerPath))
|
||||
{
|
||||
var computerObject = ActiveDirectoryUtils.GetADObject(computerPath);
|
||||
if (computerObject != null)
|
||||
{
|
||||
var samName = (string)ActiveDirectoryUtils.GetADObjectProperty(computerObject, "sAMAccountName");
|
||||
|
||||
if (!ActiveDirectoryUtils.IsComputerInGroup(samName, computerGroupName))
|
||||
{
|
||||
ActiveDirectoryUtils.AddObjectToGroup(computerPath, GetComputerGroupPath(organizationId, collectionName));
|
||||
ActiveDirectoryUtils.AddObjectToGroup(computerObject.Path, GetComputerGroupPath(organizationId, collectionName));
|
||||
}
|
||||
|
||||
if (!ActiveDirectoryUtils.IsComputerInGroup(samName, RDSHelpDeskComputerGroup))
|
||||
{
|
||||
ActiveDirectoryUtils.AddObjectToGroup(computerPath, GetHelpDeskGroupPath(RDSHelpDeskComputerGroup));
|
||||
ActiveDirectoryUtils.AddObjectToGroup(computerObject.Path, GetHelpDeskGroupPath(RDSHelpDeskComputerGroup));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1310,30 +1305,24 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
|
|||
}
|
||||
|
||||
private void RemoveComputerFromCollectionAdComputerGroup(string organizationId, string collectionName, RdsServer server)
|
||||
{
|
||||
var computerPath = GetComputerPath(server.Name, false);
|
||||
{
|
||||
var computerGroupName = GetComputersGroupName(collectionName);
|
||||
var computerObject = GetComputerObject(server.Name);
|
||||
|
||||
if (!ActiveDirectoryUtils.AdObjectExists(computerPath))
|
||||
{
|
||||
computerPath = GetComputerPath(server.Name, true);
|
||||
}
|
||||
|
||||
if (ActiveDirectoryUtils.AdObjectExists(computerPath))
|
||||
{
|
||||
var computerObject = ActiveDirectoryUtils.GetADObject(computerPath);
|
||||
if (computerObject != null)
|
||||
{
|
||||
var samName = (string)ActiveDirectoryUtils.GetADObjectProperty(computerObject, "sAMAccountName");
|
||||
|
||||
if (ActiveDirectoryUtils.IsComputerInGroup(samName, computerGroupName))
|
||||
{
|
||||
ActiveDirectoryUtils.RemoveObjectFromGroup(computerPath, GetComputerGroupPath(organizationId, collectionName));
|
||||
ActiveDirectoryUtils.RemoveObjectFromGroup(computerObject.Path, GetComputerGroupPath(organizationId, collectionName));
|
||||
}
|
||||
|
||||
if (ActiveDirectoryUtils.AdObjectExists(GetHelpDeskGroupPath(RDSHelpDeskComputerGroup)))
|
||||
{
|
||||
if (ActiveDirectoryUtils.IsComputerInGroup(samName, RDSHelpDeskComputerGroup))
|
||||
{
|
||||
ActiveDirectoryUtils.RemoveObjectFromGroup(computerPath, GetHelpDeskGroupPath(RDSHelpDeskComputerGroup));
|
||||
ActiveDirectoryUtils.RemoveObjectFromGroup(computerObject.Path, GetHelpDeskGroupPath(RDSHelpDeskComputerGroup));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1372,7 +1361,8 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
|
|||
{
|
||||
if (ActiveDirectoryUtils.AdObjectExists(computersRootPath) && !ActiveDirectoryUtils.AdObjectExists(GetRdsServersGroupPath()))
|
||||
{
|
||||
ActiveDirectoryUtils.CreateGroup(computersRootPath, RdsServersRootOU);
|
||||
//ActiveDirectoryUtils.CreateGroup(computersRootPath, RdsServersRootOU);
|
||||
ActiveDirectoryUtils.CreateOrganizationalUnit(RdsServersRootOU, computersRootPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1382,82 +1372,57 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
|
|||
|
||||
if (!ActiveDirectoryUtils.AdObjectExists(tenantComputerGroupPath))
|
||||
{
|
||||
ActiveDirectoryUtils.CreateGroup(GetOrganizationPath(organizationId), RdsServersOU);
|
||||
ActiveDirectoryUtils.CreateOrganizationalUnit(RdsServersOU, GetOrganizationPath(organizationId));
|
||||
}
|
||||
|
||||
hostName = hostName.ToLower().Replace(string.Format(".{0}", ServerSettings.ADRootDomain.ToLower()), "");
|
||||
var computerPath = GetComputerPath(hostName, true);
|
||||
hostName = hostName.ToLower().Replace(string.Format(".{0}", ServerSettings.ADRootDomain.ToLower()), "");
|
||||
var rootComputerPath = GetRdsServerPath(hostName);
|
||||
var tenantComputerPath = GetTenantComputerPath(hostName, organizationId);
|
||||
|
||||
if (!string.IsNullOrEmpty(ComputersRootOU))
|
||||
{
|
||||
CheckOrCreateComputersRoot(GetComputersRootPath());
|
||||
}
|
||||
}
|
||||
|
||||
var computerObject = GetComputerObject(hostName);
|
||||
|
||||
if(!ActiveDirectoryUtils.AdObjectExists(computerPath))
|
||||
if (computerObject != null)
|
||||
{
|
||||
computerPath = GetComputerPath(hostName, false);
|
||||
}
|
||||
|
||||
if (ActiveDirectoryUtils.AdObjectExists(computerPath))
|
||||
{
|
||||
var computerObject = ActiveDirectoryUtils.GetADObject(computerPath);
|
||||
var samName = (string)ActiveDirectoryUtils.GetADObjectProperty(computerObject, "sAMAccountName");
|
||||
|
||||
if (!string.IsNullOrEmpty(ComputersRootOU))
|
||||
{
|
||||
if (ActiveDirectoryUtils.IsComputerInGroup(samName, RdsServersRootOU))
|
||||
{
|
||||
ActiveDirectoryUtils.RemoveObjectFromGroup(computerPath, GetRdsServersGroupPath());
|
||||
}
|
||||
}
|
||||
|
||||
if (!ActiveDirectoryUtils.IsComputerInGroup(samName, RdsServersOU))
|
||||
{
|
||||
{
|
||||
DirectoryEntry group = new DirectoryEntry(tenantComputerGroupPath);
|
||||
group.Invoke("Add", computerObject.Path);
|
||||
|
||||
group.CommitChanges();
|
||||
computerObject.MoveTo(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveRdsServerFromTenantOU(string hostName, string organizationId)
|
||||
{
|
||||
var tenantComputerGroupPath = GetTenantComputerGroupPath(organizationId);
|
||||
hostName = hostName.ToLower().Replace(string.Format(".{0}", ServerSettings.ADRootDomain.ToLower()), "");
|
||||
var tenantComputerPath = GetTenantComputerPath(hostName, organizationId);
|
||||
var rootComputerPath = GetRdsServerPath(hostName);
|
||||
hostName = hostName.ToLower().Replace(string.Format(".{0}", ServerSettings.ADRootDomain.ToLower()), "");
|
||||
|
||||
if (!string.IsNullOrEmpty(ComputersRootOU))
|
||||
{
|
||||
CheckOrCreateComputersRoot(GetComputersRootPath());
|
||||
}
|
||||
}
|
||||
|
||||
var computerPath = GetComputerPath(hostName, true);
|
||||
|
||||
if (!ActiveDirectoryUtils.AdObjectExists(computerPath))
|
||||
if (!ActiveDirectoryUtils.AdObjectExists(tenantComputerGroupPath))
|
||||
{
|
||||
computerPath = GetComputerPath(hostName, false);
|
||||
ActiveDirectoryUtils.CreateOrganizationalUnit(RdsServersOU, GetOrganizationPath(organizationId));
|
||||
}
|
||||
|
||||
if (ActiveDirectoryUtils.AdObjectExists(computerPath))
|
||||
|
||||
var computerObject = GetComputerObject(hostName);
|
||||
|
||||
if (computerObject != null)
|
||||
{
|
||||
var computerObject = ActiveDirectoryUtils.GetADObject(computerPath);
|
||||
var samName = (string)ActiveDirectoryUtils.GetADObjectProperty(computerObject, "sAMAccountName");
|
||||
|
||||
if (ActiveDirectoryUtils.IsComputerInGroup(samName, RdsServersOU))
|
||||
{
|
||||
ActiveDirectoryUtils.RemoveObjectFromGroup(computerPath, tenantComputerGroupPath);
|
||||
}
|
||||
|
||||
|
||||
if (ActiveDirectoryUtils.AdObjectExists(GetComputersRootPath()) && !string.IsNullOrEmpty(ComputersRootOU) && !ActiveDirectoryUtils.IsComputerInGroup(samName, RdsServersRootOU))
|
||||
{
|
||||
DirectoryEntry group = new DirectoryEntry(GetRdsServersGroupPath());
|
||||
group.Invoke("Add", computerObject.Path);
|
||||
|
||||
group.CommitChanges();
|
||||
computerObject.MoveTo(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1744,26 +1709,17 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
|
|||
return sb.ToString();
|
||||
}
|
||||
|
||||
private string GetComputerPath(string objName, bool domainController)
|
||||
private DirectoryEntry GetComputerObject(string computerName)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// append provider
|
||||
AppendProtocol(sb);
|
||||
AppendDomainController(sb);
|
||||
AppendCNPath(sb, objName);
|
||||
if (domainController)
|
||||
DirectorySearcher deSearch = new DirectorySearcher
|
||||
{
|
||||
AppendOUPath(sb, AdDcComputers);
|
||||
}
|
||||
else
|
||||
{
|
||||
AppendCNPath(sb, Computers);
|
||||
|
||||
}
|
||||
AppendDomainPath(sb, RootDomain);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
Filter = string.Format("(&(objectCategory=computer)(name={0}))", computerName)
|
||||
};
|
||||
|
||||
SearchResult results = deSearch.FindOne();
|
||||
|
||||
return results.GetDirectoryEntry();
|
||||
}
|
||||
|
||||
private string GetTenantComputerPath(string objName, string organizationId)
|
||||
{
|
||||
|
@ -1772,7 +1728,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
|
|||
AppendProtocol(sb);
|
||||
AppendDomainController(sb);
|
||||
AppendCNPath(sb, objName);
|
||||
AppendCNPath(sb, RdsServersOU);
|
||||
AppendOUPath(sb, RdsServersOU);
|
||||
AppendOUPath(sb, organizationId);
|
||||
AppendOUPath(sb, RootOU);
|
||||
AppendDomainPath(sb, RootDomain);
|
||||
|
@ -1798,7 +1754,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
|
|||
|
||||
AppendProtocol(sb);
|
||||
AppendDomainController(sb);
|
||||
AppendCNPath(sb, RdsServersRootOU);
|
||||
AppendOUPath(sb, RdsServersRootOU);
|
||||
AppendOUPath(sb, ComputersRootOU);
|
||||
AppendDomainPath(sb, RootDomain);
|
||||
|
||||
|
@ -1812,7 +1768,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
|
|||
AppendProtocol(sb);
|
||||
AppendDomainController(sb);
|
||||
AppendCNPath(sb, name);
|
||||
AppendCNPath(sb, RdsServersRootOU);
|
||||
AppendOUPath(sb, RdsServersRootOU);
|
||||
AppendOUPath(sb, ComputersRootOU);
|
||||
AppendDomainPath(sb, RootDomain);
|
||||
|
||||
|
@ -1836,7 +1792,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
|
|||
|
||||
AppendProtocol(sb);
|
||||
AppendDomainController(sb);
|
||||
AppendCNPath(sb, RdsServersOU);
|
||||
AppendOUPath(sb, RdsServersOU);
|
||||
AppendOUPath(sb, organizationId);
|
||||
AppendOUPath(sb, RootOU);
|
||||
AppendDomainPath(sb, RootDomain);
|
||||
|
|
|
@ -77,6 +77,12 @@ namespace WebsitePanel.Portal.RDS
|
|||
{
|
||||
usersQuota.QuotaAvailable = tenantStats.AllocatedRdsUsers - tenantStats.CreatedRdsUsers;
|
||||
}
|
||||
|
||||
if (cntx.Quotas.ContainsKey(Quotas.RDS_USERS))
|
||||
{
|
||||
int rdsUsersCount = ES.Services.RDS.GetOrganizationRdsUsersCount(PanelRequest.ItemID);
|
||||
users.ButtonAddEnabled = (!(cntx.Quotas[Quotas.RDS_USERS].QuotaAllocatedValue <= rdsUsersCount) || (cntx.Quotas[Quotas.RDS_USERS].QuotaAllocatedValue == -1));
|
||||
}
|
||||
}
|
||||
|
||||
private bool SaveRdsUsers()
|
||||
|
|
|
@ -42,6 +42,18 @@ namespace WebsitePanel.Portal.RDS.UserControls
|
|||
{
|
||||
public const string DirectionString = "DirectionString";
|
||||
|
||||
public bool ButtonAddEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return btnAdd.Enabled;
|
||||
}
|
||||
set
|
||||
{
|
||||
btnAdd.Enabled = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected enum SelectedState
|
||||
{
|
||||
All,
|
||||
|
@ -74,14 +86,7 @@ namespace WebsitePanel.Portal.RDS.UserControls
|
|||
}";
|
||||
Page.ClientScript.RegisterClientScriptBlock(typeof(RDSCollectionUsers), "SelectAllCheckboxes",
|
||||
script, true);
|
||||
}
|
||||
|
||||
PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId);
|
||||
if (cntx.Quotas.ContainsKey(Quotas.RDS_USERS))
|
||||
{
|
||||
int rdsUsersCount = ES.Services.RDS.GetOrganizationRdsUsersCount(PanelRequest.ItemID);
|
||||
btnAdd.Enabled = (!(cntx.Quotas[Quotas.RDS_USERS].QuotaAllocatedValue <= rdsUsersCount) || (cntx.Quotas[Quotas.RDS_USERS].QuotaAllocatedValue == -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void btnAdd_Click(object sender, EventArgs e)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue