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

  1. <%
  2. // generateldap.fts v1.0
  3. //
  4. // PURPOSE: 
  5. // Generate LDAP entries from a CSV file
  6. //
  7. // USE:
  8. // This script should be run through a browser. The best way to do this is to
  9. // set up a virtual folder in the web admin interface:
  10. // url: \scriptlib, path=c:\program files\ftgateoffice\scriptlib
  11. // you can then access it by: http://127.0.0.1:8089/scriptlib/generateldap.fts?file=list.txt
  12. // 
  13. // The format for the csv file is:
  14. // common name
  15. // first name
  16. // last name
  17. // mailbox name
  18. // job title
  19. // organization
  20. // department
  21. // phone
  22. // fax
  23. // each separated by commas with no intervening spaces.
  24. // 
  25. // WARNING:
  26. // This script is supplied for reference only, it should be considered untested
  27. // with no warranty either written or implied. Use is strictly at you own risk.
  28. //
  29.  
  30. function trim(str)
  31. {
  32.     str=string(str)
  33.  
  34.     if (str.left(1)=="\"")
  35.         str = str.slice(1, str.length-2)
  36.  
  37.     return str
  38. }
  39.  
  40. output.writeln("<H1>CSV LDAP Import</H1>")
  41.  
  42. var ldap = new server.ldap
  43. var import = new server.file
  44.  
  45. output.writeln("creating LDAP entries<BR>")
  46. output.writeln("opening "+request.file+"<BR>")
  47.  
  48. if (import.open(request.file))
  49. {
  50.     var pos=0
  51.     var index
  52.     var line
  53.  
  54.     var cn
  55.     var gn
  56.     var sn
  57.     var mail
  58.     var title
  59.     var o
  60.     var ou
  61.     var phone
  62.     var fax
  63.  
  64.     output.writeln("processing file<P>")
  65.  
  66.     import.first()
  67.     while (import.text)
  68.     {
  69.         line=import.text
  70.  
  71.         pos=0
  72.         index = line.indexof(",",pos)
  73.         cn=trim(line.slice(pos,index))
  74.  
  75.         pos=index+1
  76.         index = line.indexof(",",pos)
  77.         gn=trim(line.slice(pos,index))
  78.  
  79.         pos=index+1
  80.         index = line.indexof(",",pos)
  81.         sn=trim(line.slice(pos,index))
  82.  
  83.         pos=index+1
  84.         index = line.indexof(",",pos)
  85.         mail=trim(line.slice(pos,index))
  86.  
  87.         pos=index+1
  88.         index = line.indexof(",",pos)
  89.         title=trim(line.slice(pos,index))
  90.  
  91.         pos=index+1
  92.         index = line.indexof(",",pos)
  93.         o=trim(line.slice(pos,index))
  94.  
  95.         pos=index+1
  96.         index = line.indexof(",",pos)
  97.         ou=trim(line.slice(pos,index))
  98.  
  99.         pos=index+1
  100.         index = line.indexof(",",pos)
  101.         phone=trim(line.slice(pos,index))
  102.  
  103.         pos=index+1
  104.         index = line.indexof("\r",pos)
  105.         fax=trim(line.slice(pos,line.length))
  106.  
  107.         pos=index+1
  108.  
  109.         // create the LDAP entry
  110.         //
  111.         ldap.entry.new(mail,cn,gn,sn,title,ou,o,phone,fax)
  112.         output.writeln("created entry for "+cn+", "+gn+" "+sn+"<BR>")
  113.  
  114.         import.next()
  115.     }
  116.  
  117.     import.close()
  118. }
  119. else
  120.     output.writeln("failed to open "+request.file)
  121.  
  122. %>