make sub OU import optional

This commit is contained in:
Sean Kaim
2016-11-10 17:53:32 -05:00
parent 8db0150c4a
commit bbfbbbf91e
5 changed files with 26 additions and 6 deletions

View File

@@ -88,11 +88,11 @@ namespace mRemoteNG.App
}
}
public static void ImportFromActiveDirectory(string ldapPath, ContainerInfo importDestinationContainer)
public static void ImportFromActiveDirectory(string ldapPath, ContainerInfo importDestinationContainer, bool importSubOU)
{
try
{
ActiveDirectoryImporter.Import(ldapPath, importDestinationContainer);
ActiveDirectoryImporter.Import(ldapPath, importDestinationContainer, importSubOU);
Runtime.SaveConnectionsAsync();
}
catch (Exception ex)

View File

@@ -16,11 +16,11 @@ namespace mRemoteNG.Config.Import
Import(ldapPathAsString, destinationContainer);
}
public static void Import(string ldapPath, ContainerInfo destinationContainer)
public static void Import(string ldapPath, ContainerInfo destinationContainer, bool importSubOU = false)
{
try
{
var deserializer = new ActiveDirectoryDeserializer(ldapPath);
var deserializer = new ActiveDirectoryDeserializer(ldapPath, importSubOU);
var connectionTreeModel = deserializer.Deserialize();
var importedRootNode = connectionTreeModel.RootNodes.First();
if (importedRootNode == null) return;

View File

@@ -14,10 +14,12 @@ namespace mRemoteNG.Config.Serializers
public class ActiveDirectoryDeserializer : IDeserializer
{
private readonly string _ldapPath;
private readonly bool _importSubOU;
public ActiveDirectoryDeserializer(string ldapPath)
public ActiveDirectoryDeserializer(string ldapPath, bool importSubOU)
{
_ldapPath = ldapPath;
_importSubOU = importSubOU;
}
public ConnectionTreeModel Deserialize()
@@ -61,6 +63,9 @@ namespace mRemoteNG.Config.Serializers
{
if (directoryEntry.Properties["objectClass"].Contains("organizationalUnit"))
{
// check/continue here so we don't create empty connection objects
if(!_importSubOU) continue;
ActiveDirectoryImporter.Import(ldapResult.Path, parentContainer);
continue;
}

View File

@@ -13,6 +13,7 @@ namespace mRemoteNG.UI.Window
this.btnChangeDomain = new System.Windows.Forms.Button();
this.ActiveDirectoryTree = new ADTree.ADtree();
this.btnClose = new System.Windows.Forms.Button();
this.chkSubOU = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// btnImport
@@ -65,6 +66,7 @@ namespace mRemoteNG.UI.Window
this.ActiveDirectoryTree.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.ActiveDirectoryTree.Domain = "tant-a01";
this.ActiveDirectoryTree.Location = new System.Drawing.Point(12, 52);
this.ActiveDirectoryTree.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.ActiveDirectoryTree.Name = "ActiveDirectoryTree";
this.ActiveDirectoryTree.SelectedNode = null;
this.ActiveDirectoryTree.Size = new System.Drawing.Size(506, 280);
@@ -82,10 +84,21 @@ namespace mRemoteNG.UI.Window
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// chkSubOU
//
this.chkSubOU.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.chkSubOU.Location = new System.Drawing.Point(248, 342);
this.chkSubOU.Name = "chkSubOU";
this.chkSubOU.Size = new System.Drawing.Size(108, 17);
this.chkSubOU.TabIndex = 6;
this.chkSubOU.Text = "Import Sub OUs";
this.chkSubOU.UseVisualStyleBackColor = true;
//
// ActiveDirectoryImportWindow
//
this.AcceptButton = this.btnImport;
this.ClientSize = new System.Drawing.Size(530, 373);
this.Controls.Add(this.chkSubOU);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.ActiveDirectoryTree);
this.Controls.Add(this.lblDomain);
@@ -110,5 +123,6 @@ namespace mRemoteNG.UI.Window
#endregion
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.CheckBox chkSubOU;
}
}

View File

@@ -38,7 +38,8 @@ namespace mRemoteNG.UI.Window
importDestination = selectedNode as ContainerInfo ?? selectedNode.Parent;
else
importDestination = Runtime.ConnectionTreeModel.RootNodes.First();
Import.ImportFromActiveDirectory(ActiveDirectoryTree.ADPath, importDestination);
Import.ImportFromActiveDirectory(ActiveDirectoryTree.ADPath, importDestination, chkSubOU.Checked);
}
private static void txtDomain_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)