将 CSV 转换为 LDIF 以导入 ldap?

发布于 2025-01-05 10:05:55 字数 382 浏览 1 评论 0原文

我有一个 MSSQL 数据库,表中有 13k 个用户,表中包含用户名、密码、fname、lname 等标题。我希望能够将这些数据转换为适当的 ldap 服务器。

目前我已完成以下操作: 在 mssql 服务器上创建一个作业,每小时以 csv 格式导出该表。该查询提取用户名、密码、fname、lastname 和 memberid。每小时将此数据通过 ftp 传输到我的 Linux LDAP 服务器。

有人可以推荐一种如何将此 csv 转换为 ldif 的方法,以便我可以运行 ldapmodify 并将所有这些条目放入我的 ldap 服务器中吗?我假设我可以编写一个解析器,但很想知道是否已经有一个产品可以以这种方式进行 csv 到 ldif 的转换,以及这个计划是否有意义或者是否有更好的方法来做到这一点?谢谢。

I have a MSSQL database with 13k users in a table with headers like username, password, fname, lname, etc. I would love to be able to turn this data into a proper ldap server.

Currently I've done the following: Create a job on the mssql server to export that table hourly in a csv. The query pulls username, password, fname, lastname,and memberid. ftp this data hourly to my linux ldap server.

Can someone recommend a method on how to turn this csv into ldif so I can run ldapmodify and put in all these entries into my ldap server? I'm assuming I can write a parser, but would love to know if there's already a product that can do csv to ldif conversion in this manner and if this plan makes any sense or if there's a better way to do this? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陪你搞怪i 2025-01-12 10:05:55

以防万一有人仍在寻找类似的东西,我制作了一个自动脚本将给定的 CSV 文件转换为 LDIF:

;###########################################################################################
;##### Load requirements
#include <File.au3>

;###########################################################################################
;####       Start the app

LDIF_Converter()


;###########################################################################################
;####       App function
Func LDIF_Converter()
    TrayTip("CSV2LDIF Converter","Konvertierung gestartet...",2000,1)

    Local $file = "import_ADS.ldif", $contacts = 0, $sFilePath = "3CXImport.csv"
    ; Remote old file
    FileDelete($file);
    ; Write Header
    FileWrite($file,"#Base structure for each person");
    Filewrite($file,@crlf)
    FileWrite($file,"dn: ou=Telefonbuch,dc=example,dc=com");
    Filewrite($file,@crlf)
    FileWrite($file,"ou: Telefonbuch");
    Filewrite($file,@crlf)
    FileWrite($file,"objectClass: organizationalUnit");
    Filewrite($file,@crlf)
    FileWrite($file,"objectClass: top");
    Filewrite($file,@crlf)
    Filewrite($file,@crlf)

    ; Read out CSV File
    _FileReadToArray($sFilePath, $contacts, $FRTA_NOCOUNT, ";")

    ; Write to File for each contact
    For $i = 0 To UBound ($contacts) - 1
        ; Clear contact cache
        $cache = ""
        ; Write object ID & comman attributes
        $cache = $cache & "dn: uid="&$i+1&",ou=Telefonbuch,dc=example,dc=com" & @CRLF
        $cache = $cache & "objectClass: inetOrgPerson" & @CRLF
        $cache = $cache & "objectClass: organizationalPerson" & @CRLF
        $cache = $cache & "objectClass: person" & @CRLF
        $cache = $cache & "objectClass: top" & @CRLF

        ; Check if company or person and set the corresponding CN
        if $contacts[$i][1] == "" Then
            $cn = $contacts[$i][0]
        Else
            $cn = $contacts[$i][1] & " " & $contacts[$i][2]
        EndIf

        ; Write common name
        $cache = $cache & "cn: "&$cn & @CRLF
        if $contacts[$i][1] == "" Then
            $sn = $contacts[$i][0]
        Else
            $sn = $contacts[$i][1] & " " & $contacts[$i][2]
        EndIf

        ; Write lastname/company
        $cache = $cache & "sn: "&$sn & @CRLF

        ; Write mobile number
        $mobile = StringRegExpReplace($contacts[$i][5],'[a-zA-Z;\\/:.,*?\"<>|& ]',"")
        if $mobile <> "" And $mobile <> " " Then
            $cache = $cache & "mobile: "& $mobile & @CRLF
        EndIf

        ; Write organisation
        if $contacts[$i][0] <> "" Then
            $cache = $cache & "o: "&$contacts[$i][0] & @CRLF
        EndIf

        ; Write telephone number
        $phone = StringRegExpReplace($contacts[$i][3],'[a-zA-Z;\\/:.,*?\"<>|& ]',"")
        if $phone <> "" And $phone <> " " Then
            $cache = $cache & "telephoneNumber: "& $phone & @CRLF
        EndIf

        ; Write fax number
        $fax = StringRegExpReplace($contacts[$i][4],'[a-zA-Z;\\/:.,*?\"<>|& ]',"")
        if $fax <> "" And $fax <> " " Then
            $cache = $cache & "facsimileTelephoneNumber: "& $fax & @CRLF
        EndIf

        ; Write email
        if $contacts[$i][6] <> "" Then
            $cache = $cache & "mail: "&$contacts[$i][6] & @CRLF
        EndIf

        ; Seperator for contacts
        $cache = $cache & @CRLF
        ; Write all in one file access
        FileWrite($file,$cache)
    Next
    TrayTip("CSV2LDIF Converter","Konvertiertierung abgeschlossen ",2000)
    sleep(2000)
EndFunc

Just in case someone is still looking for something like that, I made an autoit script to convert a given CSV file into LDIF:

;###########################################################################################
;##### Load requirements
#include <File.au3>

;###########################################################################################
;####       Start the app

LDIF_Converter()


;###########################################################################################
;####       App function
Func LDIF_Converter()
    TrayTip("CSV2LDIF Converter","Konvertierung gestartet...",2000,1)

    Local $file = "import_ADS.ldif", $contacts = 0, $sFilePath = "3CXImport.csv"
    ; Remote old file
    FileDelete($file);
    ; Write Header
    FileWrite($file,"#Base structure for each person");
    Filewrite($file,@crlf)
    FileWrite($file,"dn: ou=Telefonbuch,dc=example,dc=com");
    Filewrite($file,@crlf)
    FileWrite($file,"ou: Telefonbuch");
    Filewrite($file,@crlf)
    FileWrite($file,"objectClass: organizationalUnit");
    Filewrite($file,@crlf)
    FileWrite($file,"objectClass: top");
    Filewrite($file,@crlf)
    Filewrite($file,@crlf)

    ; Read out CSV File
    _FileReadToArray($sFilePath, $contacts, $FRTA_NOCOUNT, ";")

    ; Write to File for each contact
    For $i = 0 To UBound ($contacts) - 1
        ; Clear contact cache
        $cache = ""
        ; Write object ID & comman attributes
        $cache = $cache & "dn: uid="&$i+1&",ou=Telefonbuch,dc=example,dc=com" & @CRLF
        $cache = $cache & "objectClass: inetOrgPerson" & @CRLF
        $cache = $cache & "objectClass: organizationalPerson" & @CRLF
        $cache = $cache & "objectClass: person" & @CRLF
        $cache = $cache & "objectClass: top" & @CRLF

        ; Check if company or person and set the corresponding CN
        if $contacts[$i][1] == "" Then
            $cn = $contacts[$i][0]
        Else
            $cn = $contacts[$i][1] & " " & $contacts[$i][2]
        EndIf

        ; Write common name
        $cache = $cache & "cn: "&$cn & @CRLF
        if $contacts[$i][1] == "" Then
            $sn = $contacts[$i][0]
        Else
            $sn = $contacts[$i][1] & " " & $contacts[$i][2]
        EndIf

        ; Write lastname/company
        $cache = $cache & "sn: "&$sn & @CRLF

        ; Write mobile number
        $mobile = StringRegExpReplace($contacts[$i][5],'[a-zA-Z;\\/:.,*?\"<>|& ]',"")
        if $mobile <> "" And $mobile <> " " Then
            $cache = $cache & "mobile: "& $mobile & @CRLF
        EndIf

        ; Write organisation
        if $contacts[$i][0] <> "" Then
            $cache = $cache & "o: "&$contacts[$i][0] & @CRLF
        EndIf

        ; Write telephone number
        $phone = StringRegExpReplace($contacts[$i][3],'[a-zA-Z;\\/:.,*?\"<>|& ]',"")
        if $phone <> "" And $phone <> " " Then
            $cache = $cache & "telephoneNumber: "& $phone & @CRLF
        EndIf

        ; Write fax number
        $fax = StringRegExpReplace($contacts[$i][4],'[a-zA-Z;\\/:.,*?\"<>|& ]',"")
        if $fax <> "" And $fax <> " " Then
            $cache = $cache & "facsimileTelephoneNumber: "& $fax & @CRLF
        EndIf

        ; Write email
        if $contacts[$i][6] <> "" Then
            $cache = $cache & "mail: "&$contacts[$i][6] & @CRLF
        EndIf

        ; Seperator for contacts
        $cache = $cache & @CRLF
        ; Write all in one file access
        FileWrite($file,$cache)
    Next
    TrayTip("CSV2LDIF Converter","Konvertiertierung abgeschlossen ",2000)
    sleep(2000)
EndFunc
陪你搞怪i 2025-01-12 10:05:55

简单的 Google 搜索显示了几个 CSV 到 LDIF 转换器。

例如scv2ldif2.pl。它是用 Perl 编写的,但您至少可以找到几个 Perl 的 Windows 实现(例如 Strawberry Perl

A simple Google search revealed several CSV to LDIF converters.

For example scv2ldif2.pl. It is in Perl, but you can find at least several Windows implementation of Perl (for example Strawberry Perl.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文