RDS Computer group removed from cap,policies name forming changed

This commit is contained in:
vfedosevich 2014-11-21 01:08:38 -08:00
parent d5bf70596d
commit 738334500d
3 changed files with 44 additions and 18 deletions

View file

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WebsitePanel.Providers.RemoteDesktopServices
{
public enum RdsPolicyTypes
{
RdCap,
RdRap
}
}

View file

@ -125,6 +125,7 @@
<Compile Include="RemoteDesktopServices\IRemoteDesktopServices.cs" /> <Compile Include="RemoteDesktopServices\IRemoteDesktopServices.cs" />
<Compile Include="RemoteDesktopServices\RdsCollection.cs" /> <Compile Include="RemoteDesktopServices\RdsCollection.cs" />
<Compile Include="RemoteDesktopServices\RdsCollectionPaged.cs" /> <Compile Include="RemoteDesktopServices\RdsCollectionPaged.cs" />
<Compile Include="RemoteDesktopServices\RdsPolicyTypes.cs" />
<Compile Include="RemoteDesktopServices\RdsServer.cs" /> <Compile Include="RemoteDesktopServices\RdsServer.cs" />
<Compile Include="RemoteDesktopServices\RdsServersPaged.cs" /> <Compile Include="RemoteDesktopServices\RdsServersPaged.cs" />
<Compile Include="RemoteDesktopServices\RemoteApplication.cs" /> <Compile Include="RemoteDesktopServices\RemoteApplication.cs" />

View file

@ -62,7 +62,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
private const string Users = "users"; private const string Users = "users";
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=\"0x1fb4\" conditiondata=\"{3}\" 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\"";
#endregion #endregion
#region Properties #region Properties
@ -194,21 +194,22 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
ActiveDirectoryUtils.CreateGroup(orgPath, GetUsersGroupName(collection.Name)); ActiveDirectoryUtils.CreateGroup(orgPath, GetUsersGroupName(collection.Name));
} }
var policyName = GetPolicyName(organizationId, collection.Name); var capPolicyName = GetPolicyName(organizationId, collection.Name, RdsPolicyTypes.RdCap);
var rapPolicyName = GetPolicyName(organizationId, collection.Name, RdsPolicyTypes.RdRap);
foreach (var gateway in Gateways) foreach (var gateway in Gateways)
{ {
if (!CentralNps) if (!CentralNps)
{ {
CreateRdCapForce(runSpace, gateway, policyName, collection.Name, new List<string> { GetUsersGroupName(collection.Name) }); CreateRdCapForce(runSpace, gateway, capPolicyName, collection.Name, new List<string> { GetUsersGroupName(collection.Name) });
} }
CreateRdRapForce(runSpace, gateway, policyName, collection.Name, new List<string> { GetUsersGroupName(collection.Name) }); CreateRdRapForce(runSpace, gateway, rapPolicyName, collection.Name, new List<string> { GetUsersGroupName(collection.Name) });
} }
if (CentralNps) if (CentralNps)
{ {
CreateCentralNpsPolicy(runSpace, CentralNpsHost, policyName, collection.Name, organizationId); CreateCentralNpsPolicy(runSpace, CentralNpsHost, capPolicyName, collection.Name, organizationId);
} }
//add user group to collection //add user group to collection
@ -280,21 +281,22 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
ExecuteShellCommand(runSpace, cmd, false); ExecuteShellCommand(runSpace, cmd, false);
var policyName = GetPolicyName(organizationId, collectionName); var capPolicyName = GetPolicyName(organizationId, collectionName, RdsPolicyTypes.RdCap);
var rapPolicyName = GetPolicyName(organizationId, collectionName, RdsPolicyTypes.RdRap);
foreach (var gateway in Gateways) foreach (var gateway in Gateways)
{ {
if (!CentralNps) if (!CentralNps)
{ {
RemoveRdCap(runSpace, gateway, policyName); RemoveRdCap(runSpace, gateway, capPolicyName);
} }
RemoveRdRap(runSpace, gateway, policyName); RemoveRdRap(runSpace, gateway, rapPolicyName);
} }
if (CentralNps) if (CentralNps)
{ {
RemoveNpsPolicy(runSpace, CentralNpsHost, policyName); RemoveNpsPolicy(runSpace, CentralNpsHost, capPolicyName);
} }
//Remove security group //Remove security group
@ -553,11 +555,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
var userGroupSid = (byte[])ActiveDirectoryUtils.GetADObjectProperty(userGroupAd, "objectSid"); var userGroupSid = (byte[])ActiveDirectoryUtils.GetADObjectProperty(userGroupAd, "objectSid");
var computerGroupAd = ActiveDirectoryUtils.GetADObject(GetComputerGroupPath(organizationId, collectionName)); var addCmdString = string.Format(AddNpsString, policyName.Replace(" ", "_"), count, ConvertByteToStringSid(userGroupSid));
var computerGroupSid = (byte[])ActiveDirectoryUtils.GetADObjectProperty(computerGroupAd, "objectSid");
var addCmdString = string.Format(AddNpsString, policyName.Replace(" ", "_"), count, ConvertByteToStringSid(userGroupSid), ConvertByteToStringSid(computerGroupSid));
Command addCmd = new Command(addCmdString); Command addCmd = new Command(addCmdString);
@ -582,13 +580,11 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
} }
var userGroupParametr = string.Format("@({0})",string.Join(",", groups.Select(x => string.Format("\"{0}@{1}\"", x, RootDomain)).ToArray())); var userGroupParametr = string.Format("@({0})",string.Join(",", groups.Select(x => string.Format("\"{0}@{1}\"", x, RootDomain)).ToArray()));
var computerGroupParameter = string.Format("\"{0}@{1}\"", GetComputersGroupName(collectionName), RootDomain);
Command rdCapCommand = new Command("New-Item"); Command rdCapCommand = new Command("New-Item");
rdCapCommand.Parameters.Add("Path", string.Format("\"{0}\"", CapPath)); rdCapCommand.Parameters.Add("Path", string.Format("\"{0}\"", CapPath));
rdCapCommand.Parameters.Add("Name", string.Format("\"{0}\"", policyName)); rdCapCommand.Parameters.Add("Name", string.Format("\"{0}\"", policyName));
rdCapCommand.Parameters.Add("UserGroups", userGroupParametr); rdCapCommand.Parameters.Add("UserGroups", userGroupParametr);
rdCapCommand.Parameters.Add("ComputerGroups", computerGroupParameter);
rdCapCommand.Parameters.Add("AuthMethod", 1); rdCapCommand.Parameters.Add("AuthMethod", 1);
ExecuteRemoteShellCommand(runSpace, gatewayHost, rdCapCommand, RdsModuleName); ExecuteRemoteShellCommand(runSpace, gatewayHost, rdCapCommand, RdsModuleName);
@ -936,9 +932,25 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
ExecuteRemoteShellCommand(runSpace, hostname, rdRapCommand, imports); ExecuteRemoteShellCommand(runSpace, hostname, rdRapCommand, imports);
} }
private string GetPolicyName(string organizationId, string collectionName) private string GetPolicyName(string organizationId, string collectionName, RdsPolicyTypes policyType)
{ {
return string.Format("rds-{0}-{1}", organizationId, collectionName); string policyName = string.Format("{0}-{1}-", organizationId, collectionName);
switch (policyType)
{
case RdsPolicyTypes.RdCap:
{
policyName += "RDCAP";
break;
}
case RdsPolicyTypes.RdRap:
{
policyName += "RDRAP";
break;
}
}
return policyName;
} }
private string GetComputersGroupName(string collectionName) private string GetComputersGroupName(string collectionName)