home *** CD-ROM | disk | FTP | other *** search
- <%
- // generateldap.fts v1.0
- //
- // PURPOSE:
- // Generate LDAP entries from a CSV file
- //
- // USE:
- // This script should be run through a browser. The best way to do this is to
- // set up a virtual folder in the web admin interface:
- // url: \scriptlib, path=c:\program files\ftgateoffice\scriptlib
- // you can then access it by: http://127.0.0.1:8089/scriptlib/generateldap.fts?file=list.txt
- //
- // The format for the csv file is:
- // common name
- // first name
- // last name
- // mailbox name
- // job title
- // organization
- // department
- // phone
- // fax
- // each separated by commas with no intervening spaces.
- //
- // WARNING:
- // This script is supplied for reference only, it should be considered untested
- // with no warranty either written or implied. Use is strictly at you own risk.
- //
-
- function trim(str)
- {
- str=string(str)
-
- if (str.left(1)=="\"")
- str = str.slice(1, str.length-2)
-
- return str
- }
-
- output.writeln("<H1>CSV LDAP Import</H1>")
-
- var ldap = new server.ldap
- var import = new server.file
-
- output.writeln("creating LDAP entries<BR>")
- output.writeln("opening "+request.file+"<BR>")
-
- if (import.open(request.file))
- {
- var pos=0
- var index
- var line
-
- var cn
- var gn
- var sn
- var mail
- var title
- var o
- var ou
- var phone
- var fax
-
- output.writeln("processing file<P>")
-
- import.first()
- while (import.text)
- {
- line=import.text
-
- pos=0
- index = line.indexof(",",pos)
- cn=trim(line.slice(pos,index))
-
- pos=index+1
- index = line.indexof(",",pos)
- gn=trim(line.slice(pos,index))
-
- pos=index+1
- index = line.indexof(",",pos)
- sn=trim(line.slice(pos,index))
-
- pos=index+1
- index = line.indexof(",",pos)
- mail=trim(line.slice(pos,index))
-
- pos=index+1
- index = line.indexof(",",pos)
- title=trim(line.slice(pos,index))
-
- pos=index+1
- index = line.indexof(",",pos)
- o=trim(line.slice(pos,index))
-
- pos=index+1
- index = line.indexof(",",pos)
- ou=trim(line.slice(pos,index))
-
- pos=index+1
- index = line.indexof(",",pos)
- phone=trim(line.slice(pos,index))
-
- pos=index+1
- index = line.indexof("\r",pos)
- fax=trim(line.slice(pos,line.length))
-
- pos=index+1
-
- // create the LDAP entry
- //
- ldap.entry.new(mail,cn,gn,sn,title,ou,o,phone,fax)
- output.writeln("created entry for "+cn+", "+gn+" "+sn+"<BR>")
-
- import.next()
- }
-
- import.close()
- }
- else
- output.writeln("failed to open "+request.file)
-
- %>