mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
recurively import OU, Sub-OU and servers
This commit is contained in:
@@ -92,8 +92,7 @@ namespace mRemoteNG.App
|
||||
{
|
||||
try
|
||||
{
|
||||
var importer = new ActiveDirectoryImporter();
|
||||
importer.Import(ldapPath, importDestinationContainer);
|
||||
ActiveDirectoryImporter.Import(ldapPath, importDestinationContainer);
|
||||
Runtime.SaveConnectionsAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace mRemoteNG.Config.Import
|
||||
Import(ldapPathAsString, destinationContainer);
|
||||
}
|
||||
|
||||
public void Import(string ldapPath, ContainerInfo destinationContainer)
|
||||
public static void Import(string ldapPath, ContainerInfo destinationContainer)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.DirectoryServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using mRemoteNG.App;
|
||||
using mRemoteNG.Config.Import;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Container;
|
||||
using mRemoteNG.Tree;
|
||||
@@ -45,19 +46,27 @@ namespace mRemoteNG.Config.Serializers
|
||||
{
|
||||
try
|
||||
{
|
||||
const string ldapFilter = "(objectClass=computer)";
|
||||
const string ldapFilter = "(|(objectClass=computer)(objectClass=organizationalUnit))";
|
||||
using (var ldapSearcher = new DirectorySearcher())
|
||||
{
|
||||
ldapSearcher.SearchRoot = new DirectoryEntry(ldapPath);
|
||||
ldapSearcher.Filter = ldapFilter;
|
||||
ldapSearcher.SearchScope = SearchScope.OneLevel;
|
||||
ldapSearcher.PropertiesToLoad.AddRange(new[] { "securityEquals", "cn" });
|
||||
ldapSearcher.PropertiesToLoad.AddRange(new[] { "securityEquals", "cn", "objectClass" });
|
||||
|
||||
var ldapResults = ldapSearcher.FindAll();
|
||||
foreach (SearchResult ldapResult in ldapResults)
|
||||
{
|
||||
using (var directoryEntry = ldapResult.GetDirectoryEntry())
|
||||
{
|
||||
if (directoryEntry.Properties["objectClass"].Contains("organizationalUnit"))
|
||||
{
|
||||
ActiveDirectoryImporter.Import(ldapResult.Path, parentContainer);
|
||||
continue;
|
||||
}
|
||||
|
||||
DeserializeConnection(directoryEntry, parentContainer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user