diff --git a/mRemoteV1/App/Import.cs b/mRemoteV1/App/Import.cs index 02eecf405..c565bc14b 100644 --- a/mRemoteV1/App/Import.cs +++ b/mRemoteV1/App/Import.cs @@ -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) diff --git a/mRemoteV1/Config/Import/ActiveDirectoryImporter.cs b/mRemoteV1/Config/Import/ActiveDirectoryImporter.cs index da9172292..fb79d1df0 100644 --- a/mRemoteV1/Config/Import/ActiveDirectoryImporter.cs +++ b/mRemoteV1/Config/Import/ActiveDirectoryImporter.cs @@ -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; diff --git a/mRemoteV1/Config/Serializers/ActiveDirectoryDeserializer.cs b/mRemoteV1/Config/Serializers/ActiveDirectoryDeserializer.cs index a7ff47c06..f98beb5f2 100644 --- a/mRemoteV1/Config/Serializers/ActiveDirectoryDeserializer.cs +++ b/mRemoteV1/Config/Serializers/ActiveDirectoryDeserializer.cs @@ -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; } diff --git a/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.Designer.cs b/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.Designer.cs index 1597396d6..1713a9584 100644 --- a/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.Designer.cs +++ b/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.Designer.cs @@ -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; } } diff --git a/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.cs b/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.cs index d5ab43022..f97dc9534 100644 --- a/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.cs +++ b/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.cs @@ -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)