<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 11">
<meta name=Originator content="Microsoft Word 11">
<link rel=File-List href="manual_files/filelist.xml">
<title>ldap2ldif - by Vedanta Barooah</title>
<!--[if gte mso 9]><xml>
<o:DocumentProperties>
<o:Author>Vedanta Barooah</o:Author>
<o:LastAuthor>Vedanta Barooah</o:LastAuthor>
<o:Revision>2</o:Revision>
<o:TotalTime>9</o:TotalTime>
<o:Created>2005-06-12T16:39:00Z</o:Created>
<o:LastSaved>2005-06-12T16:48:00Z</o:LastSaved>
<o:Pages>1</o:Pages>
<o:Words>388</o:Words>
<o:Characters>2218</o:Characters>
<o:Company>HP</o:Company>
<o:Lines>18</o:Lines>
<o:Paragraphs>5</o:Paragraphs>
<o:CharactersWithSpaces>2601</o:CharactersWithSpaces>
<o:Version>11.5606</o:Version>
</o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:SpellingState>Clean</w:SpellingState>
<w:GrammarState>Clean</w:GrammarState>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
</w:LatentStyles>
</xml><![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Verdana;
panose-1:2 11 6 4 3 5 4 4 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:536871559 0 0 0 415 0;}
@font-face
{font-family:"Microsoft Sans Serif";
panose-1:2 11 6 4 2 2 2 2 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:553679495 -2147483648 8 0 66047 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;
text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;
text-underline:single;}
pre
{margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Courier New";
mso-fareast-font-family:"Times New Roman";}
span.SpellE
{mso-style-name:"";
mso-spl-e:yes;}
span.GramE
{mso-style-name:"";
mso-gram-e:yes;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple style='tab-interval:.5in'>
<div class=Section1><pre><b><u><span style='font-size:14.0pt;font-family:Verdana;
mso-bidi-font-family:"Microsoft Sans Serif"'>ldap2ldif - by Vedanta Barooah</span></u></b><u><span
style='font-size:14.0pt;font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'> (hide@address.com)<o:p></o:p></span></u></pre><pre><b><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></b></pre><pre><b><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>PURPOSE - Export data from LDAP directories to LDIF format</span></b><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>This class has been tested on directories with +60,000 <span
class=GramE>number</span> of entries. <o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>I was able to create an LDIF, though PHP gave warnings. Similar scripts in Java and Python failed.<o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></pre><pre><b><u><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>Class Documentation</span></u></b><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p></o:p></span></pre><pre><span
class=GramE><b><span style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>function</span></b></span><b><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'> ldap2ldif($<span
class=SpellE>serverName</span>='<span class=SpellE>localhost',$serverPort</span>='389')</span></b><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>Class constructor, takes the LDAP server and the LDAP server port as the first and the second <span
class=SpellE>param</span> respectively.<o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>Call without <span
class=SpellE>param</span> to connect to a LDAP server running on the same system on the default port.<o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>Examples:<o:p></o:p></span></pre><pre>// connect to <span
class=SpellE>ldap</span> server running on ldap.monkey.com on port 389<o:p></o:p></pre><pre>$exporter=new <span
class=GramE>ldap2ldif(</span>ldap.monkey.com);<o:p></o:p></pre><pre>// connect to <span
class=SpellE>ldap</span> server on this system with defaults<o:p></o:p></pre><pre>$exporter=new <span
class=GramE>ldap2ldif(</span>);<o:p></o:p></pre><pre><span style='font-family:
Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></pre><pre><span
class=GramE><b><span style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>function</span></b></span><b><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'> init($<span
class=SpellE>ldap_username</span>=<span class=SpellE>NULL,$ldap_password</span>=NULL)</span></b><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>Initialize a LDAP connection <o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>Examples:<o:p></o:p></span></pre><pre>// initialize connection anonymously<o:p></o:p></pre><pre>$exporter-><span
class=GramE>init(</span>);<o:p></o:p></pre><pre>// connect as admin of monkey.com with password banana<o:p></o:p></pre><pre>$exporter-><span
class=GramE>init(</span><span class=SpellE>cn</span>=<span class=SpellE>admin,o</span>=<span
class=SpellE>monkey.com,banana</span>);<o:p></o:p></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></pre><pre><span
class=GramE><b><span style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>function</span></b></span><b><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'> search($<span
class=SpellE>baseDN,$filter</span>="(<span class=SpellE>objectClass</span>=*)",$<span
class=SpellE>required_attributes</span>=<span class=SpellE>NULL,$limitRecords</span>=0)</span></b><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>Search the LDAP directory<o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>Examples:<o:p></o:p></span></pre><pre>// return all the entries in ldap.monkey.com<o:p></o:p></pre><pre>$exporter-<span
class=GramE>>(</span>o=monkey.com);<o:p></o:p></pre><pre>// search all the lizard types in group lizard under organization reptiles<o:p></o:p></pre><pre>$exporter-<span
class=GramE>>(</span><span class=SpellE>ou</span>=<span class=SpellE>lizard,o</span>=reptile.com);<o:p></o:p></pre><pre>// search for people with names starting with J<o:p></o:p></pre><pre>$exporter-<span
class=GramE>>(</span><span class=SpellE>ou</span>=<span class=SpellE>people,o</span>=<span
class=SpellE>vodoo.com,cn</span>=J*); <o:p></o:p></pre><pre>// search for people with names starting with Joe* but return only the common name and mail address<o:p></o:p></pre><pre>$exporter-<span
class=GramE>>(</span><span class=SpellE>ou</span>=<span class=SpellE>people,o</span>=<span
class=SpellE>vodoo.com,cn</span>=Joe*,array(<span class=SpellE>cn,mail</span>));<o:p></o:p></pre><pre>// search for people with names starting with Joe* but return only the common name and mail address also return not more than 100 records<o:p></o:p></pre><pre>$exporter-<span
class=GramE>>(</span><span class=SpellE>ou</span>=<span class=SpellE>people,o</span>=<span
class=SpellE>vodoo.com,cn</span>=Joe*,array(<span class=SpellE>cn,mail</span>),100);<o:p></o:p></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></pre><pre><span
class=GramE><b><span style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>function</span></b></span><b><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'> export($<span
class=SpellE>ldif_file_name</span>=NULL)</span></b><span style='font-family:
Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>Export the search result to LDIF<o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>Examples:<o:p></o:p></span></pre><pre>// print out the LDIF in browser, use <pre> tag for proper output in browser<o:p></o:p></pre><pre><span
class=GramE>print</span> $exporter->export();<o:p></o:p></pre><pre>// write the LDIF to a file<o:p></o:p></pre><pre>$exporter-><span
class=GramE>export(</span>'/<span class=SpellE>tmp/exported.ldif</span>');<o:p></o:p></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></pre><pre><span
class=GramE><b><span style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>function</span></b></span><b><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'> close()</span></b><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>Closes the LDAP connection<o:p></o:p></span></pre><pre>$exporter-><span
class=GramE>close(</span>);<o:p></o:p></pre><pre><span style='font-family:Verdana;
mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></pre><pre><b><u><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>Plans</span></u></b><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>This script is one among other similar utilities I am writing, <o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>LDAP <span
class=GramE>Tools :</span><o:p></o:p></span></pre><pre><span style='font-family:
Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>ldap2ldif: Convert LDAP data to LDIF (Completed)<o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>ldap2csv: Convert to Comma Separated Values<o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>ldap2table: Convert to HTML tables<o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>ldap2xls: Convert to MS Excel Format (ext. of ldap2table)<o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>ldap2vcf: Convert to VCARD <o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>ldap2dsml: Convert to DSML<o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'>Please send me bugs and suggestions at: <a
href="mailto:hide@address.com">hide@address.com</a><o:p></o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></pre><pre><span
style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></pre>
<p class=MsoNormal><span style='font-family:Verdana;mso-bidi-font-family:"Microsoft Sans Serif"'><o:p> </o:p></span></p>
</div>
</body>
</html>