home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / windowsxp / ftgateoffice / ftgateoffice.exe / Main / ldif-import.fts < prev    next >
Encoding:
Text File  |  2001-11-29  |  18.4 KB  |  970 lines

  1. <%
  2. // ldif-import.fts v1.0
  3. // PURPOSE
  4. // Takes an ldif file and imports them as local mailboxes
  5. //
  6. // 
  7. // WARNING:
  8. // This script is supplied for reference only, it should be considered untested
  9. // with no warranty either written or implied. Use is strictly at you own risk.
  10. //
  11. #include <ftgate.fts>
  12. %>
  13. <HTML>
  14. <HEAD>
  15. <STYLE>
  16. STRONG
  17. {
  18.   color:        #660066;
  19.   font-weight:  bold;
  20. }
  21. BODY 
  22. {
  23.   font-family:  "Arial";
  24.   color:        #330033;
  25. }
  26.  
  27. </STYLE>
  28. </HEAD>
  29. <BODY>
  30. <TABLE WIDTH="100%">
  31. <TR><TD BGCOLOR="gold"><STRONG>FTGate LDIF Import v1.0</STRONG></TD></TR>
  32. </TABLE>
  33. <%
  34. if (form.config=="1")
  35. {
  36.     var defaultLang = "lang-en"
  37.  
  38.     const STATE_VERSION                    = 0
  39.     const STATE_DN                            = 1
  40.     const STATE_ATTRVAL_CHANGE    = 2
  41.     const STATE_ATTRVAL                    = 3
  42.     const STATE_CHANGE                    = 5
  43.     const STATE_CHANGE_CONTROL  = 7
  44.  
  45.     var error=false
  46.  
  47.     var changeAction=""
  48.     var changeAttribute=""
  49.     var changeType=""
  50.     var changeDomain=""
  51.     var changeMbx=""
  52.     var replaceFirst=true
  53.  
  54.     var first=false
  55.  
  56.     var newDomain = new array[1]
  57.     var domainCount=0
  58.  
  59.     var person=false
  60.     var alias=false
  61.  
  62.     var aliasMail=""
  63.     var aliasUid=""
  64.  
  65.     // defined in rfc2798
  66.     var domain=""
  67.     var mail=""
  68.     var uid=""
  69.     var displayName=""
  70.     var cn=""
  71.     var sn=""
  72.     var gn=""
  73.     var title=""
  74.     var ou=""
  75.     var description=""
  76.     var phone=""
  77.     var fax=""
  78.     var password=""
  79.  
  80.     function error(text, line)
  81.     {
  82.         error=true
  83.  
  84.         if (line!=-1)
  85.             text=text+" at line "+line
  86.  
  87.         output.writeln(text+"<BR>")
  88.     }
  89.  
  90.     function write(text)
  91.     {
  92.         output.writeln(text+"<BR>")
  93.     }
  94.  
  95.     function debug(text)
  96.     {
  97.         // Comment out to remove debug messages
  98.         write(text)
  99.     }
  100.  
  101.     function base64(content)
  102.     {
  103.         content=string(content)
  104.         if (content.slice(0,1)==":")
  105.         {
  106.             content = content.slice(1,content.length)
  107.             content = content.trim()
  108.             content = content.base64decode()
  109.         }
  110.  
  111.         return content
  112.     }
  113.  
  114.     function oldDomain(name)
  115.     {
  116.         var old=true
  117.         var count = 0
  118.  
  119.         for (count=0; count<domainCount; count++)
  120.         {
  121.             if (newDomain[count]==name)
  122.             {
  123.                 old=false
  124.                 break
  125.             }
  126.         }
  127.  
  128.         return old
  129.     }
  130.  
  131.     function newDomain(name, linenumber)
  132.     {
  133.         var ok = true
  134.  
  135.         var d = new server.domain
  136.         d.newlocaldomain(domain)
  137.         if (!d.domainname)
  138.         {
  139.             error("Create domain '"+domain+"' failed", lineNumber)
  140.             ok=false
  141.         }
  142.         else
  143.         {
  144.             write("Created local domain "+domain)
  145.             newDomain[domainCount]=domain
  146.             domainCount++
  147.         }
  148.         
  149.         return ok
  150.     }
  151.  
  152.     function processDN(content, lineNumber)
  153.     {
  154.         var o
  155.         content=base64(content)
  156.         content=string(content)
  157.  
  158.         var pos=content.indexof("=",0)
  159.         while (pos!=-1)
  160.         {
  161.             var attrib=content.slice(0, pos)
  162.             content=content.slice(pos+1,content.length)
  163.  
  164.             attrib=attrib.trim()
  165.             content=content.trim()
  166.             if (content.left(1)=="\"")
  167.             {
  168.                 pos=0
  169.                 content=content.slice(1,content.length)
  170.                 while ((pos<content.length)&&(content.slice(pos, pos+1)!="\""))
  171.                 {
  172.                     pos++
  173.                     if (content.slice(pos, pos+1)=="\\")
  174.                         pos=pos+2
  175.                 }
  176.  
  177.                 if (content.slice(pos, pos+1)=="\"")
  178.                     content = content.slice(0, pos)+content.slice(pos+1, content.length)
  179.         
  180.                 pos=content.indexof(",", number(pos))
  181.             }
  182.             else
  183.                 pos=content.indexof(",", 0)
  184.  
  185.             if (pos==-1)
  186.                 pos=content.length
  187.  
  188.             if (attrib=="dc")
  189.             {
  190.                 if (domain!="")
  191.                     domain=domain+"."
  192.                     
  193.                 domain=domain+content.slice(0, pos)
  194.             }
  195.             else if (attrib=="o")
  196.             {
  197.                 o=content.slice(0, pos)
  198.             }
  199.             else if (attrib=="ou")
  200.             {
  201.                 ou=content.slice(0, pos)
  202.             }
  203.             else if (attrib=="uid")
  204.             {
  205.                 uid=content.slice(0, pos)
  206.             }
  207.             else if (attrib=="cn")
  208.             {
  209.                 cn=content.slice(0, pos)
  210.             }
  211.  
  212.             content=content.slice(pos+1, content.length)
  213.             pos=content.indexof("=",0)
  214.         }
  215.  
  216.         if (domain=="")
  217.             domain=o
  218.  
  219.         return true
  220.     }
  221.  
  222.     function extractDomain(mail)
  223.     {
  224.         mail=string(mail)
  225.         var index=mail.indexof("@", 0)
  226.         return mail.slice(index+1, 999)
  227.     }
  228.  
  229.     function processRecord(lineNumber)
  230.     {
  231.         output.writeln("<FONT COLOR=\"red\">")
  232.  
  233.         if (person|alias)
  234.         {
  235.             while (true)
  236.             {
  237.                 // See if can work out the domain
  238.                 //
  239.                 if ((domain=="")||(domain==0))
  240.                     domain=extractDomain(mail)
  241.  
  242.                 if ((domain=="")||(domain==0))
  243.                 {
  244.                     error("no domain for record", linenumber)
  245.                     break
  246.                 }
  247.                 
  248.                 domain=domain.tolowercase()
  249.  
  250.                 var d = new server.domain
  251.                 d.domainname=domain
  252.                 if (d.domainname==domain)
  253.                 {    
  254.                     // the domain already exists
  255.                     // Make sure it's a local domain
  256.                     //
  257.                     d.domainname=d.domainname    // dereference if it's an alias
  258.                     if (d.description!="Local")
  259.                     {
  260.                         error("domain '"+d.domainname+"' is not Local", lineNumber)
  261.                         break
  262.                     }
  263.  
  264.                     // if we haven't already purged this domain then do so
  265.                     //
  266.                     if (oldDomain(domain))
  267.                     {
  268.                         d.deletedomain(domain)
  269.                         if (!newDomain(domain, linenumber))
  270.                             break
  271.                     }
  272.                 }
  273.                 else if (!newDomain(domain, linenumber))
  274.                     break
  275.  
  276.                 d.domainname=domain
  277.                 mail=mail.tolowercase()
  278.                 uid=uid.tolowercase()
  279.  
  280.                 if ((mail!="")||(uid!=""))
  281.                 {
  282.                     // get the mailbox
  283.                     //
  284.                     if (mail!="")
  285.                         mail = mail.slice(0,mail.indexof("@",0))
  286.                     else
  287.                         mail=uid
  288.  
  289.                     var m = new d.mailbox
  290.  
  291.                     if (cn=="")
  292.                         cn=displayName
  293.  
  294.                     m.name=mail
  295.                     if (m.name!=mail)
  296.                     {
  297.                         write("Created mailbox "+mail+"@"+domain+" for "+cn)
  298.                         d.newusermbx(mail)
  299.                         m.name=mail
  300.                     }
  301.  
  302.                     if (m.name==mail)
  303.                     {
  304.                         m.ldap.commonname=cn
  305.                         m.ldap.givenname=gn
  306.                         m.ldap.lastname=sn
  307.                         m.ldap.department=ou
  308.                         m.description=description
  309.                         if (title!="")
  310.                             m.ldap.jobtitle=title
  311.                         m.ldap.phone=phone
  312.                         m.ldap.fax=fax
  313.  
  314.                         if (password!="")
  315.                             m.password(password)
  316.  
  317.                         if (alias)
  318.                         {
  319.                             if (aliasMail!="")
  320.                                 aliasMail= aliasMail.left(aliasMail.indexof("@",0))
  321.                             else
  322.                                 aliasMail=aliasUid
  323.  
  324.                             if (aliasMail!="")
  325.                             {
  326.                                 m.newalias(aliasMail, m.name)
  327.                                 write("Created alias "+aliasMail+"@"+domain+" for "+mail+"@"+domain)
  328.                             }
  329.                         }
  330.                     }
  331.                     else
  332.                         error("Cannot create "+mail+"@"+domain, lineNumber)
  333.                 }
  334.  
  335.                 break
  336.             }
  337.         }
  338.  
  339.         person=false
  340.         alias=false
  341.  
  342.         aliasMail=""
  343.         aliasUid=""
  344.  
  345.         domain=""
  346.         mail=""
  347.         uid=""
  348.  
  349.         cn=""
  350.         displayName=""
  351.         sn=""
  352.         gn=""
  353.         description=""
  354.  
  355.         output.writeln("</FONT>")
  356.     }
  357.  
  358.     function parseAttribute(record, content, lineNumber)
  359.     {
  360.         var isDefaultLang = false
  361.  
  362.         record=string(record)
  363.         var pos = record.indexof(";",0)
  364.  
  365.         if (pos!=-1)
  366.         {
  367.             var options = record.slice(pos+1, record.length)
  368.             record = record.slice(0, pos)
  369.  
  370.             if (options.indexof(defaultLang)!=-1)
  371.                 isDefaultLang=true
  372.         }
  373.  
  374.         output.writeln("<FONT COLOR=\"green\">")
  375.         debug("record="+record)
  376.         output.writeln("</FONT>")
  377.         
  378.         if (record=="cn")
  379.         {
  380.             content=base64(content)
  381.             if ((cn=="")||(isDefaultLang))
  382.                 cn=content
  383.         }
  384.         else if ((record=="gn")||(record=="givenname"))
  385.         {
  386.             debug("gn")
  387.             content=base64(content)
  388.             if ((gn=="")||(isDefaultLang))
  389.                 gn=content
  390.         }
  391.         else if (record=="sn")
  392.         {
  393.             content=base64(content)
  394.             if ((sn=="")||(isDefaultLang))
  395.                 sn=content
  396.         }
  397.         else if (record=="title")
  398.         {
  399.             debug("in title="+content)
  400.             content=base64(content)
  401.             if ((title=="")||(isDefaultLang))
  402.             {
  403.                 debug("set title="+content)
  404.                 title=content
  405.             }
  406.         }
  407.         else if (record=="ou")
  408.         {
  409.             content=base64(content)
  410.             if ((ou=="")||(isDefaultLang))
  411.                 ou=content
  412.         }
  413.         else if ((record=="telephonenumber")||(record=="phone"))
  414.         {
  415.             content=base64(content)
  416.             if (phone=="")
  417.                 phone=content
  418.         }
  419.         else if ((record=="facsimiletelephonenumber")||(record=="fax"))
  420.         {
  421.             content=base64(content)
  422.             if (fax=="")
  423.                 fax=content
  424.         }
  425.         else if (record=="userpassword")
  426.         {
  427.             content=base64(content)
  428.             if (password=="")
  429.                 password=content
  430.         }
  431.         else if (record=="description")
  432.         {
  433.             debug("description")
  434.             content=base64(content)
  435.             if ((description=="")||(isDefaultLang))
  436.                 description=content
  437.         }
  438.         else if (record=="displayname")
  439.         {
  440.             content=base64(content)
  441.             if ((displayname=="")||(isDefaultLang))
  442.                 displayname=content
  443.         }
  444.         else if ((record=="mail")||(record=="rfc822mailbox"))
  445.         {
  446.             content=base64(content)
  447.             if (alias)
  448.                 aliasMail=content
  449.             else
  450.                 mail=content
  451.         }
  452.         else if ((record=="uid")||(record=="userid"))
  453.         {
  454.             content=base64(content)
  455.             if (alias)
  456.                 aliasUid=content
  457.             else
  458.                 uid=content
  459.         }
  460.         else if (record=="aliasedobjectname")
  461.         {
  462.             alias=true
  463.             aliasUid=uid
  464.             aliasMail=mail
  465.             domain=""
  466.             processDN(content, lineNumber)
  467.         }
  468.         else if (record=="objectclass")
  469.         {
  470.             content=base64(content)
  471.             content = string(content)
  472.             content = content.tolowercase()
  473.             if (content=="person")
  474.                 person=true
  475.         }
  476.     }
  477.  
  478.     function locateChange(linenumber)
  479.     {
  480.         changeDomain=domain
  481.         changeMbx=""
  482.  
  483.         while (true)
  484.         {
  485.             if (changeDomain=="")
  486.                 changeDomain=extractDomain(mail)
  487.  
  488.             if (changeDomain=="")
  489.             {
  490.                 error("no domain for record", linenumber)
  491.                 break
  492.             }
  493.             else
  494.             {
  495.                 changeDomain=changeDomain.tolowercase()
  496.  
  497.                 var d = new server.domain
  498.                 d.domainname=changeDomain
  499.                 if (d.domainname!=changeDomain)
  500.                 {
  501.                     error("Cannot locate domain '"+changeDomain+"'", linenumber)
  502.                     break
  503.                 }
  504.  
  505.                 // the domain exists
  506.                 d.domainname=d.domainname    // dereference if it's an alias
  507.                 if (d.description!="Local")
  508.                 {
  509.                     error("domain '"+d.domainname+"' is not Local", lineNumber)
  510.                     break
  511.                 }
  512.  
  513.                 if (cn=="")
  514.                     cn=displayName
  515.  
  516.                 mail=mail.tolowercase()
  517.                 uid=uid.tolowercase()
  518.  
  519.                 if ((mail!="")||(uid!=""))
  520.                 {
  521.                     // get the mailbox
  522.                     //
  523.                     if (mail!="")
  524.                         mail = mail.slice(0,mail.indexof("@",0))
  525.                     else
  526.                         mail=uid
  527.  
  528.                     var m = new d.mailbox
  529.  
  530.                     m.name=mail
  531.  
  532.                     if (m.name!=mail)
  533.                     {
  534.                         error("Cannot locate mailbox "+m.name+"@"+domain, linenumber)
  535.                         break
  536.                     }
  537.                     else
  538.                         changeMbx = mail
  539.                 }
  540.                 else if (cn!=""||ou!="")
  541.                 {
  542.                     var m = new d.mailbox
  543.  
  544.                     var ok = m.findfirst("*")
  545.                     while (ok)
  546.                     {
  547.                         if ((cn!="")&&(m.ldap.commonname==cn))
  548.                         {
  549.                             if ((ou!="")&&(m.ldap.department==ou))
  550.                                 break
  551.                             else if (ou=="")
  552.                                 break
  553.                         }
  554.                         else if ((cn=="")&&(ou!="")&&(m.ldap.department==ou))
  555.                             break
  556.  
  557.                         ok = m.findnext()
  558.                     }
  559.  
  560.                     if (!ok)
  561.                     {
  562.                         error("Cannot locate mailbox for "+cn, linenumber)
  563.                         break
  564.                     }
  565.                     else
  566.                         changeMbx=m.name
  567.                 }
  568.             }
  569.  
  570.             if (changeMbx)
  571.             {
  572.                 var d = new server.domain
  573.                 d.domainname=changeDomain
  574.                 var m = new d.mailbox
  575.                 m.name=changeMbx
  576.                 cn = m.ldap.commonname
  577.                 gn = m.ldap.givenname
  578.                 sn = m.ldap.lastname
  579.                 ou = m.ldap.department
  580.                 description = m.description
  581.                 title = m.ldap.jobtitle
  582.                 phone = m.ldap.phone
  583.                 fax = m.ldap.fax
  584.             }
  585.  
  586.             break
  587.         }
  588.     }
  589.  
  590.     function parseChange(action, content, lineNumber)
  591.     {
  592.         if (changetype=="add")
  593.         {
  594.             parseAttribute(action, content, lineNumber)
  595.         }
  596.         else if (changetype=="modify")
  597.         {
  598.             debug("modify changeAction="+changeAction)
  599.             if (changeAction=="")
  600.             {
  601.                 debug("action="+action+" content="+content)
  602.                 changeAction=action
  603.                 changeAttribute=content
  604.  
  605.                 if ((action=="replace")||(action=="delete"))
  606.                 {
  607.                     debug("replace or delete")
  608.                     replaceFirst=true
  609.  
  610.                     if (content=="cn")
  611.                         cn=""
  612.                     else if ((content=="gn")||(content=="givenname"))
  613.                         gn=""
  614.                     else if (content=="sn")
  615.                         sn=""
  616.                     else if (content=="title")
  617.                         title=""
  618.                     else if (content=="ou")
  619.                         ou=""
  620.                     else if ((content=="telephonenumber")||(content=="phone"))
  621.                     {
  622.                         phone=""
  623.                         debug("yphone="+phone)
  624.                     }
  625.                     else if ((content=="facsimiletelephonenumber")||(content=="fax"))
  626.                         fax=""
  627.                     else if (content=="displayname")
  628.                         displayname=""
  629.                     else if ((content=="mail")||(content=="rfc822mailbox"))
  630.                         mail=""
  631.                     else if ((content=="uid")||(content=="userid"))
  632.                         uid=""
  633.                 }
  634.                 else
  635.                     debug("modify")
  636.             }
  637.             else
  638.             {
  639.                 debug("changeAction="+changeAction+" replaceFirst="+replaceFirst)
  640.                 if ((changeAction=="replace")&&(replaceFirst))
  641.                     replaceFirst=false
  642.                 else
  643.                 {
  644.                     parseAttribute(action, content, lineNumber)
  645.                     changeAction=""
  646.                 }
  647.             }
  648.         }
  649.         else if (changetype=="delete")
  650.         {
  651.         }
  652.     }
  653.  
  654.     function processChange(lineNumber)
  655.     {
  656.         output.writeln("<FONT COLOR=\"red\">")
  657.  
  658.         if (changetype=="add")
  659.         {
  660.             processRecord(lineNumber)
  661.         }
  662.         else if (changetype=="modify")
  663.         {
  664.             while (true)
  665.             {
  666.                 var d = new server.domain
  667.                 d.domainname=changeDomain
  668.                 if (!d.domainname)
  669.                     break
  670.  
  671.                 var m=new d.mailbox
  672.                 m.name=changeMbx
  673.                 if (!m.name)
  674.                     break
  675.         
  676.                 m.ldap.commonname=cn
  677.                 m.ldap.givenname=gn
  678.                 m.ldap.lastname=sn
  679.                 m.ldap.department=ou
  680.                 m.description=description
  681.                 m.ldap.jobtitle=title
  682.                 m.ldap.phone=phone
  683.                 m.ldap.fax=fax
  684.  
  685.                 if (password!="")
  686.                     m.password(password)
  687.  
  688.                 mail=mail.tolowercase()
  689.                 uid=uid.tolowercase()
  690.  
  691.                 if ((mail!="")||(uid!=""))
  692.                 {
  693.                     // get the mailbox
  694.                     //
  695.                     if (mail!="")
  696.                         mail = mail.slice(0,mail.indexof("@",0))
  697.                     else
  698.                         mail=uid
  699.  
  700.                     if (mail!=m.name)
  701.                         m.rename(mail)
  702.                 }
  703.  
  704.                 break
  705.             }
  706.         }
  707.         else if ((changetype=="delete")&&(changeDomain!="")&&(changeMbx!=""))
  708.         {
  709.             debug("deleting")
  710.             while (true)
  711.             {
  712.                 var d = new server.domain
  713.                 d.domainname=changeDomain
  714.                 if (!d.domainname)
  715.                     break
  716.  
  717.                 debug("deleting "+changeMbx+"@"+d.domainname)
  718.                 d.deletemailbox(changeMbx)
  719.                 break
  720.             }
  721.         }
  722.  
  723.         changeType=""
  724.         changeAction=""
  725.         changeDomain=""
  726.         changeMbx=""
  727.  
  728.         aliasMail=""
  729.         aliasUid=""
  730.  
  731.         domain=""
  732.         mail=""
  733.         uid=""
  734.  
  735.         cn=""
  736.         displayName=""
  737.         sn=""
  738.         gn=""
  739.         description=""
  740.  
  741.         output.writeln("</FONT>")
  742.     }
  743.  
  744.     function importLDIF(filename)
  745.     {
  746.         var file = new server.file
  747.  
  748.         if (file.open(filename))
  749.         {
  750.             var state = STATE_VERSION
  751.             var ok = file.first()
  752.             var lineNumber=1
  753.             var recordLine=1
  754.             var debug=false
  755.  
  756.             while (ok)
  757.             {
  758.                 var line = string(file.text)
  759.                 line=line.trim()
  760.                 while ((ok)&&((line.slice(0,1)=="#")||(line=="")))
  761.                 {
  762.                     ok=file.next()
  763.                     line = string(file.text)
  764.                     line=line.trim()
  765.                 }
  766.  
  767.                 var next
  768.                 var newLine
  769.  
  770.                 ok = file.next()
  771.                 if (ok)
  772.                 {
  773.                     next = string(file.text)
  774.                     
  775.                     while ((ok)&&(next.left(1)==" "))
  776.                     {
  777.                         next=next.trim()
  778.                         line = line+next
  779.                         ok = file.next()
  780.                         next = string(file.text)
  781.                         newLine++
  782.                     }
  783.                 }
  784.                 next=next.trim()
  785.  
  786.                 var sep = line.indexof(":",0)
  787.                 if (sep==-1)
  788.                     sep = line.indexof("=",0)
  789.  
  790.                 if (sep!=-1)
  791.                 {
  792.                     var attribute = line.left(sep)
  793.                     attribute = attribute.tolowercase()
  794.  
  795.                     var content = line.slice(sep+1, line.length)
  796.                     content=content.trim()
  797.  
  798.                     if (content.slice(0,1)==":")
  799.                     {
  800.                         content=content.trim()
  801.  
  802.                         while ((ok)&&(next.indexof(":",0)==-1))
  803.                         {
  804.                             next=next.trim()
  805.                             content = content+next
  806.                             ok = file.next()
  807.                             next = string(file.text)
  808.                             newLine++
  809.                         }
  810.                     }
  811.  
  812.                     debug("state="+state+" content="+content)
  813.                     if (state==STATE_VERSION)
  814.                     {
  815.                         if ((attribute=="version")&&(content!=1))
  816.                         {
  817.                             error("Incompatible file version", lineNumber)
  818.                             break
  819.                         }
  820.                         else if (attribute=="dn")
  821.                         {
  822.                             recordLine=lineNumber
  823.                             ok=processDN(content, lineNumber)
  824.                             state=STATE_ATTRVAL_CHANGE
  825.                         }
  826.                     }
  827.                     else if (state==STATE_DN)
  828.                     {
  829.                         recordLine=lineNumber
  830.                         ok=processDN(content, lineNumber)
  831.                         state=STATE_ATTRVAL_CHANGE
  832.                     }
  833.                     else if (state==STATE_ATTRVAL_CHANGE)
  834.                     {
  835.                         if (attribute=="control")
  836.                         {
  837.                         }
  838.                         else if (attribute=="changetype")
  839.                         {
  840.                             state=STATE_CHANGE
  841.                             changetype=content
  842.                             if (ok==false)
  843.                             {
  844.                                 locateChange(recordLine)
  845.                                 processChange(recordLine)
  846.                             }
  847.                         }
  848.                         else
  849.                         {
  850.                             state=STATE_ATTRVAL
  851.                             if (attribute=="dn")
  852.                             {
  853.                                 processRecord(content, recordLine)
  854.                                 if (!processDN(content, lineNumber))
  855.                                     ok=false
  856.  
  857.                                 recordLine=lineNumber
  858.                             }
  859.                             else if (!parseAttribute(attribute, content, lineNumber))
  860.                                 ok=false
  861.                         }
  862.                     }
  863.                     else if (state==STATE_ATTRVAL)
  864.                     {
  865.                         if (attribute=="dn")
  866.                         {
  867.                             processRecord(recordLine)
  868.                             if (!processDN(content, lineNumber))
  869.                                 ok=false
  870.  
  871.                             recordLine=lineNumber
  872.                         }
  873.                         else
  874.                         {
  875.                             parseAttribute(attribute, content, lineNumber)
  876.                             if (ok==false)
  877.                                 processRecord(recordLine)
  878.                         }
  879.                     }
  880.                     else if (state==STATE_CHANGE)
  881.                     {
  882.                         debug("attrib="+attribute)
  883.                         if (attribute=="dn")
  884.                         {
  885.                             processChange(content, recordLine)
  886.                             if (!processDN(content, lineNumber))
  887.                                 ok=false
  888.  
  889.                             state=STATE_CHANGE_CONTROL
  890.                             recordLine=lineNumber
  891.                         }
  892.                         else if (attribute=="-")
  893.                         {
  894.                             changeAction=""
  895.                             if (ok==false)
  896.                                 processChange(recordLine)
  897.                         }
  898.                         else
  899.                         {
  900.                             parseChange(attribute, content, lineNumber)
  901.                             if (ok==false)
  902.                                 processChange(recordLine)
  903.                         }
  904.                     }
  905.                     else if (state==STATE_CHANGE_CONTROL)
  906.                     {
  907.                         if (attribute=="control")
  908.                         {
  909.                         }
  910.                         else if (attribute=="changetype")
  911.                         {
  912.                             state=STATE_CHANGE
  913.                             changetype=content
  914.  
  915.                             if (content!="add")
  916.                             {
  917.                                 var ok2=ok
  918.                                 locateChange(recordLine)
  919.                                 ok=ok2
  920.                                 debug("Ok4="+ok)
  921.                             }
  922.                         }
  923.                     }
  924.                     else
  925.                     {
  926.                         output.write("How did I get here?")
  927.                         break
  928.                     }
  929.  
  930.                     line = next
  931.                     lineNumber = newLine
  932.                 }
  933.                 else if ((state==STATE_CHANGE)&&(line.slice(0,1)=="-"))
  934.                 {
  935.                 }
  936.                 else
  937.                     ok=false
  938.  
  939.                 if (line=="-")
  940.                     debug=true
  941.             }
  942.  
  943.             file.close()
  944.         }
  945.         else
  946.             error("Failed to open file", 0-1)
  947.     }
  948.  
  949.     importLDIF(form.file)
  950. }
  951. else
  952. {
  953. %>
  954. <FORM NAME="ftgate" METHOD="POST">
  955. <INPUT TYPE="HIDDEN" NAME="config" VALUE="1">
  956. <TABLE BORDER="0">
  957. <TR>
  958.     <TD VALIGN="TOP"> Enter the name of the ldif file you wish to import then
  959.     click the Import button</TD>
  960. </TR>
  961. <TR>
  962.     <TD VALIGN="TOP"> File to import: <INPUT TYPE="FILE" SIZE="40" NAME="file"></TD>
  963. </TR>
  964. <TR>
  965.     <TD ALIGN="RIGHT"><INPUT TYPE="SUBMIT" VALUE=" Import "></TD>
  966. </TR>
  967. </TABLE>
  968. <%
  969. }
  970. %>